1 /* $NetBSD: mtrr.h,v 1.2 2014/03/18 18:20:42 riastradh Exp $ */ 2 3 /*- 4 * Copyright (c) 2013 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Taylor R. Campbell. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #ifndef _ASM_MTRR_H_ 33 #define _ASM_MTRR_H_ 34 35 #ifdef _KERNEL_OPT 36 #include "opt_mtrr.h" 37 #endif 38 39 #include <machine/mtrr.h> 40 41 #define MTRR_TYPE_WRCOMB MTRR_TYPE_WC 42 43 static inline int 44 mtrr_add(unsigned long base, unsigned long size, int type, 45 bool increment __unused) 46 { 47 #ifdef MTRR 48 struct mtrr mtrr; 49 int n = 1; 50 51 mtrr.base = base; 52 mtrr.len = size; 53 mtrr.type = type; 54 mtrr.flags = MTRR_VALID; 55 56 /* XXX errno NetBSD->Linux */ 57 return -mtrr_set(&mtrr, &n, NULL, MTRR_GETSET_KERNEL); 58 #else 59 return 0; 60 #endif 61 } 62 63 static inline int 64 mtrr_del(int handle __unused, unsigned long base, unsigned long size) 65 { 66 #ifdef MTRR 67 struct mtrr mtrr; 68 int n = 1; 69 70 mtrr.base = base; 71 mtrr.len = size; 72 mtrr.type = 0; 73 mtrr.flags = 0; /* not MTRR_VALID */ 74 75 /* XXX errno NetBSD->Linux */ 76 return -mtrr_set(&mtrr, &n, NULL, MTRR_GETSET_KERNEL); 77 #else 78 return 0; 79 #endif 80 } 81 82 #endif /* _ASM_MTRR_H_ */ 83