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