Annotation of sys/arch/amd64/include/mtrr.h, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: mtrr.h,v 1.1 2004/01/28 01:39:39 mickey Exp $ */
! 2: /* $NetBSD: mtrr.h,v 1.1 2003/02/26 21:26:11 fvdl Exp $ */
! 3:
! 4: /*-
! 5: * Copyright (c) 2000 The NetBSD Foundation, Inc.
! 6: * All rights reserved.
! 7: *
! 8: * This code is derived from software contributed to The NetBSD Foundation
! 9: * by Bill Sommerfeld
! 10: *
! 11: * Redistribution and use in source and binary forms, with or without
! 12: * modification, are permitted provided that the following conditions
! 13: * are met:
! 14: * 1. Redistributions of source code must retain the above copyright
! 15: * notice, this list of conditions and the following disclaimer.
! 16: * 2. Redistributions in binary form must reproduce the above copyright
! 17: * notice, this list of conditions and the following disclaimer in the
! 18: * documentation and/or other materials provided with the distribution.
! 19: * 3. All advertising materials mentioning features or use of this software
! 20: * must display the following acknowledgement:
! 21: * This product includes software developed by the NetBSD
! 22: * Foundation, Inc. and its contributors.
! 23: * 4. Neither the name of The NetBSD Foundation nor the names of its
! 24: * contributors may be used to endorse or promote products derived
! 25: * from this software without specific prior written permission.
! 26: *
! 27: * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
! 28: * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
! 29: * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
! 30: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
! 31: * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
! 32: * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
! 33: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
! 34: * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
! 35: * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
! 36: * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
! 37: * POSSIBILITY OF SUCH DAMAGE.
! 38: */
! 39:
! 40: #ifndef _X86_MTRR_H_
! 41: #define _X86_MTRR_H_
! 42:
! 43: #define MTRR_I686_FIXED_IDX64K 0
! 44: #define MTRR_I686_FIXED_IDX16K 1
! 45: #define MTRR_I686_FIXED_IDX4K 3
! 46:
! 47: #define MTRR_I686_NVAR 8
! 48:
! 49: #define MTRR_I686_64K_START 0x00000
! 50: #define MTRR_I686_16K_START 0x80000
! 51: #define MTRR_I686_4K_START 0xc0000
! 52:
! 53: #define MTRR_I686_NFIXED_64K 1
! 54: #define MTRR_I686_NFIXED_16K 2
! 55: #define MTRR_I686_NFIXED_4K 8
! 56: #define MTRR_I686_NFIXED 11
! 57: #define MTRR_I686_NFIXED_SOFT_64K (MTRR_I686_NFIXED_64K * 8)
! 58: #define MTRR_I686_NFIXED_SOFT_16K (MTRR_I686_NFIXED_16K * 8)
! 59: #define MTRR_I686_NFIXED_SOFT_4K (MTRR_I686_NFIXED_4K * 8)
! 60: #define MTRR_I686_NFIXED_SOFT (MTRR_I686_NFIXED * 8)
! 61:
! 62: #define MTRR_I686_ENABLE_MASK 0x0800
! 63: #define MTRR_I686_FIXED_ENABLE_MASK 0x0400
! 64:
! 65: #define MTRR_I686_CAP_VCNT_MASK 0x00ff
! 66: #define MTRR_I686_CAP_FIX_MASK 0x0100
! 67: #define MTRR_I686_CAP_WC_MASK 0x0400
! 68:
! 69: #define MTRR_TYPE_UC 0
! 70: #define MTRR_TYPE_WC 1
! 71: #define MTRR_TYPE_UNDEF1 2
! 72: #define MTRR_TYPE_UNDEF2 3
! 73: #define MTRR_TYPE_WT 4
! 74: #define MTRR_TYPE_WP 5
! 75: #define MTRR_TYPE_WB 6
! 76:
! 77: struct mtrr_state {
! 78: uint32_t msraddr;
! 79: uint64_t msrval;
! 80: };
! 81:
! 82: #define MTRR_PRIVATE 0x0001 /* 'own' range, reset at exit */
! 83: #define MTRR_FIXED 0x0002 /* use fixed range mtrr */
! 84: #define MTRR_VALID 0x0004 /* entry is valid */
! 85:
! 86: #define MTRR_CANTSET MTRR_FIXED
! 87:
! 88: #define MTRR_I686_MASK_VALID (1 << 11)
! 89:
! 90: /*
! 91: * AMD K6 MTRRs.
! 92: *
! 93: * There are two of these MTRR-like registers in the UWCRR.
! 94: */
! 95:
! 96: #define MTRR_K6_ADDR_SHIFT 17
! 97: #define MTRR_K6_ADDR (0x7fffU << MTRR_K6_ADDR_SHIFT)
! 98: #define MTRR_K6_MASK_SHIFT 2
! 99: #define MTRR_K6_MASK (0x7fffU << MTRR_K6_MASK_SHIFT)
! 100: #define MTRR_K6_WC (1U << 1) /* write-combine */
! 101: #define MTRR_K6_UC (1U << 0) /* uncached */
! 102:
! 103: #define MTRR_K6_NVAR 2
! 104:
! 105: #ifdef _KERNEL
! 106:
! 107: #define mtrr_base_value(mtrrp) \
! 108: (((uint64_t)(mtrrp)->base) | ((uint64_t)(mtrrp)->type))
! 109: #define mtrr_mask_value(mtrrp) \
! 110: ((~((mtrrp)->len - 1) & 0x0000000ffffff000))
! 111:
! 112:
! 113: #define mtrr_len(val) \
! 114: ((~((val) & 0x0000000ffffff000)+1) & 0x0000000ffffff000)
! 115: #define mtrr_base(val) ((val) & 0x0000000ffffff000)
! 116: #define mtrr_type(val) ((uint8_t)((val) & 0x00000000000000ff))
! 117: #define mtrr_valid(val) (((val) & MTRR_I686_MASK_VALID) != 0)
! 118:
! 119: struct proc;
! 120: struct mtrr;
! 121:
! 122: void i686_mtrr_init_first(void);
! 123: void k6_mtrr_init_first(void);
! 124:
! 125: struct mtrr_funcs {
! 126: void (*init_cpu)(struct cpu_info *ci);
! 127: void (*reload_cpu)(struct cpu_info *ci);
! 128: void (*clean)(struct proc *p);
! 129: int (*set)(struct mtrr *, int *n, struct proc *p, int flags);
! 130: int (*get)(struct mtrr *, int *n, struct proc *p, int flags);
! 131: void (*commit)(void);
! 132: void (*dump)(const char *tag);
! 133: };
! 134:
! 135: extern struct mtrr_funcs i686_mtrr_funcs;
! 136: extern struct mtrr_funcs k6_mtrr_funcs;
! 137: extern struct mtrr_funcs *mtrr_funcs;
! 138:
! 139: #define mtrr_init_cpu(ci) mtrr_funcs->init_cpu(ci)
! 140: #define mtrr_reload_cpu(ci) mtrr_funcs->reload_cpu(ci)
! 141: #define mtrr_clean(p) mtrr_funcs->clean(p)
! 142: #define mtrr_set(mp,n,p,f) mtrr_funcs->set(mp,n,p,f)
! 143: #define mtrr_get(mp,n,p,f) mtrr_funcs->get(mp,n,p,f)
! 144: #define mtrr_dump(s) mtrr_funcs->dump(s)
! 145: #define mtrr_commit() mtrr_funcs->commit()
! 146:
! 147: #define MTRR_GETSET_USER 0x0001
! 148: #define MTRR_GETSET_KERNEL 0x0002
! 149:
! 150: #endif /* _KERNEL */
! 151:
! 152: struct mtrr {
! 153: uint64_t base; /* physical base address */
! 154: uint64_t len;
! 155: uint8_t type;
! 156: int flags;
! 157: pid_t owner; /* valid if MTRR_PRIVATE set in flags */
! 158: };
! 159:
! 160: #endif /* _X86_MTRR_H_ */
CVSweb