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