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