pte.h revision 1.8.6.3 1 1.8.6.3 nathanw /* $NetBSD: pte.h,v 1.8.6.3 2002/04/01 07:43:08 nathanw Exp $ */
2 1.8.6.2 nathanw
3 1.8.6.2 nathanw /*
4 1.8.6.2 nathanw * Copyright (c) 1996-1999 Eduardo Horvath
5 1.8.6.2 nathanw *
6 1.8.6.2 nathanw * Redistribution and use in source and binary forms, with or without
7 1.8.6.2 nathanw * modification, are permitted provided that the following conditions
8 1.8.6.2 nathanw * are met:
9 1.8.6.2 nathanw * 1. Redistributions of source code must retain the above copyright
10 1.8.6.2 nathanw * notice, this list of conditions and the following disclaimer.
11 1.8.6.2 nathanw *
12 1.8.6.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
13 1.8.6.2 nathanw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14 1.8.6.2 nathanw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15 1.8.6.2 nathanw * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE
16 1.8.6.2 nathanw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17 1.8.6.2 nathanw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18 1.8.6.2 nathanw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19 1.8.6.2 nathanw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20 1.8.6.2 nathanw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21 1.8.6.2 nathanw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22 1.8.6.2 nathanw * SUCH DAMAGE.
23 1.8.6.2 nathanw *
24 1.8.6.2 nathanw */
25 1.8.6.2 nathanw
26 1.8.6.2 nathanw #if defined(_KERNEL_OPT)
27 1.8.6.2 nathanw #include "opt_sparc_arch.h"
28 1.8.6.2 nathanw #endif
29 1.8.6.2 nathanw
30 1.8.6.2 nathanw /*
31 1.8.6.2 nathanw * Address translation works as follows:
32 1.8.6.2 nathanw *
33 1.8.6.2 nathanw **
34 1.8.6.2 nathanw * For sun4u:
35 1.8.6.2 nathanw *
36 1.8.6.2 nathanw * Take your pick; it's all S/W anyway. We'll start by emulating a sun4.
37 1.8.6.2 nathanw * Oh, here's the sun4u TTE for reference:
38 1.8.6.2 nathanw *
39 1.8.6.2 nathanw * struct sun4u_tte {
40 1.8.6.2 nathanw * u_int64 tag_g:1, (global flag)
41 1.8.6.2 nathanw * tag_ctxt:15, (context for mapping)
42 1.8.6.2 nathanw * tag_unassigned:6,
43 1.8.6.2 nathanw * tag_va:42; (virtual address bits<64:22>)
44 1.8.6.2 nathanw * u_int64 data_v:1, (valid bit)
45 1.8.6.2 nathanw * data_size:2, (page size [8K*8**<SIZE>])
46 1.8.6.2 nathanw * data_nfo:1, (no-fault only)
47 1.8.6.2 nathanw * data_ie:1, (invert endianness [inefficient])
48 1.8.6.2 nathanw * data_soft2:2, (reserved for S/W)
49 1.8.6.2 nathanw * data_pa:36, (physical address)
50 1.8.6.2 nathanw * data_soft:6, (reserved for S/W)
51 1.8.6.2 nathanw * data_lock:1, (lock into TLB)
52 1.8.6.2 nathanw * data_cacheable:2, (cacheability control)
53 1.8.6.2 nathanw * data_e:1, (explicit accesses only)
54 1.8.6.2 nathanw * data_priv:1, (privileged page)
55 1.8.6.2 nathanw * data_w:1, (writeable)
56 1.8.6.2 nathanw * data_g:1; (same as tag_g)
57 1.8.6.2 nathanw * };
58 1.8.6.2 nathanw */
59 1.8.6.2 nathanw
60 1.8.6.2 nathanw /* virtual address to virtual page number */
61 1.8.6.2 nathanw #define VA_SUN4_VPG(va) (((int)(va) >> 13) & 31)
62 1.8.6.2 nathanw #define VA_SUN4C_VPG(va) (((int)(va) >> 12) & 63)
63 1.8.6.2 nathanw #define VA_SUN4U_VPG(va) (((int)(va) >> 13) & 31)
64 1.8.6.2 nathanw
65 1.8.6.2 nathanw /* virtual address to offset within page */
66 1.8.6.2 nathanw #define VA_SUN4_OFF(va) (((int)(va)) & 0x1FFF)
67 1.8.6.2 nathanw #define VA_SUN4C_OFF(va) (((int)(va)) & 0xFFF)
68 1.8.6.2 nathanw #define VA_SUN4U_OFF(va) (((int)(va)) & 0x1FFF)
69 1.8.6.2 nathanw
70 1.8.6.2 nathanw /* When we go to 64-bit VAs we need to handle the hole */
71 1.8.6.2 nathanw #define VA_VPG(va) VA_SUN4U_VPG(va)
72 1.8.6.2 nathanw #define VA_OFF(va) VA_SUN4U_OFF(va)
73 1.8.6.2 nathanw
74 1.8.6.2 nathanw #define PG_SHIFT4U 13
75 1.8.6.2 nathanw #define MMU_PAGE_ALIGN 8192
76 1.8.6.2 nathanw
77 1.8.6.2 nathanw /* If you know where a tte is in the tsb, how do you find its va? */
78 1.8.6.2 nathanw #define TSBVA(i) ((tsb[(i)].tag.f.tag_va<<22)|(((i)<<13)&0x3ff000))
79 1.8.6.2 nathanw
80 1.8.6.2 nathanw #ifndef _LOCORE
81 1.8.6.2 nathanw /*
82 1.8.6.2 nathanw * This is the spitfire TTE.
83 1.8.6.2 nathanw *
84 1.8.6.2 nathanw * We could use bitmasks and shifts to construct this if
85 1.8.6.2 nathanw * we had a 64-bit compiler w/64-bit longs. Otherwise it's
86 1.8.6.2 nathanw * a real pain to do this in C.
87 1.8.6.2 nathanw */
88 1.8.6.2 nathanw #if 0
89 1.8.6.2 nathanw /* We don't use bitfeilds anyway. */
90 1.8.6.2 nathanw struct sun4u_tag_fields {
91 1.8.6.2 nathanw u_int64_t tag_g:1, /* global flag */
92 1.8.6.2 nathanw tag_ctxt:15, /* context for mapping */
93 1.8.6.2 nathanw tag_unassigned:6,
94 1.8.6.2 nathanw tag_va:42; /* virtual address bits<64:22> */
95 1.8.6.2 nathanw };
96 1.8.6.2 nathanw union sun4u_tag { struct sun4u_tag_fields f; int64_t tag; };
97 1.8.6.2 nathanw struct sun4u_data_fields {
98 1.8.6.2 nathanw u_int64_t data_v:1, /* valid bit */
99 1.8.6.2 nathanw data_size:2, /* page size [8K*8**<SIZE>] */
100 1.8.6.2 nathanw data_nfo:1, /* no-fault only */
101 1.8.6.2 nathanw data_ie:1, /* invert endianness [inefficient] */
102 1.8.6.2 nathanw data_soft2:2, /* reserved for S/W */
103 1.8.6.2 nathanw data_pa:36, /* physical address */
104 1.8.6.2 nathanw data_accessed:1,/* S/W accessed bit */
105 1.8.6.2 nathanw data_modified:1,/* S/W modified bit */
106 1.8.6.2 nathanw data_realw:1, /* S/W real writable bit (to manage modified) */
107 1.8.6.2 nathanw data_tsblock:1, /* S/W TSB locked entry */
108 1.8.6.2 nathanw data_exec:1, /* S/W Executable */
109 1.8.6.2 nathanw data_onlyexec:1,/* S/W Executable only */
110 1.8.6.2 nathanw data_lock:1, /* lock into TLB */
111 1.8.6.2 nathanw data_cacheable:2, /* cacheability control */
112 1.8.6.2 nathanw data_e:1, /* explicit accesses only */
113 1.8.6.2 nathanw data_priv:1, /* privileged page */
114 1.8.6.2 nathanw data_w:1, /* writeable */
115 1.8.6.2 nathanw data_g:1; /* same as tag_g */
116 1.8.6.2 nathanw };
117 1.8.6.2 nathanw union sun4u_data { struct sun4u_data_fields f; int64_t data; };
118 1.8.6.2 nathanw struct sun4u_tte {
119 1.8.6.2 nathanw union sun4u_tag tag;
120 1.8.6.2 nathanw union sun4u_data data;
121 1.8.6.2 nathanw };
122 1.8.6.2 nathanw #else
123 1.8.6.2 nathanw struct sun4u_tte {
124 1.8.6.2 nathanw int64_t tag;
125 1.8.6.2 nathanw int64_t data;
126 1.8.6.2 nathanw };
127 1.8.6.2 nathanw #endif
128 1.8.6.2 nathanw typedef struct sun4u_tte pte_t;
129 1.8.6.2 nathanw
130 1.8.6.2 nathanw /* Assembly routine to flush a mapping */
131 1.8.6.2 nathanw extern void tlb_flush_pte __P((vaddr_t addr, int ctx));
132 1.8.6.2 nathanw extern void tlb_flush_ctx __P((int ctx));
133 1.8.6.2 nathanw
134 1.8.6.2 nathanw #endif /* _LOCORE */
135 1.8.6.2 nathanw
136 1.8.6.2 nathanw /* TSB tag masks */
137 1.8.6.2 nathanw #define CTX_MASK ((1<<13)-1)
138 1.8.6.2 nathanw #define TSB_TAG_CTX_SHIFT 48
139 1.8.6.2 nathanw #define TSB_TAG_VA_SHIFT 22
140 1.8.6.2 nathanw #define TSB_TAG_G 0x8000000000000000LL
141 1.8.6.2 nathanw
142 1.8.6.2 nathanw #define TSB_TAG_CTX(t) ((((int64_t)(t))>>TSB_TAG_CTX_SHIFT)&CTX_MASK)
143 1.8.6.2 nathanw #define TSB_TAG_VA(t) ((((int64_t)(t))<<TSB_TAG_VA_SHIFT))
144 1.8.6.2 nathanw #define TSB_TAG(g,ctx,va) ((((u_int64_t)((g)!=0))<<63)|(((u_int64_t)(ctx)&CTX_MASK)<<TSB_TAG_CTX_SHIFT)|(((u_int64_t)va)>>TSB_TAG_VA_SHIFT))
145 1.8.6.2 nathanw
146 1.8.6.2 nathanw /* Page sizes */
147 1.8.6.2 nathanw #define PGSZ_8K 0
148 1.8.6.2 nathanw #define PGSZ_64K 1
149 1.8.6.2 nathanw #define PGSZ_512K 2
150 1.8.6.2 nathanw #define PGSZ_4M 3
151 1.8.6.2 nathanw
152 1.8.6.2 nathanw #define PGSZ_SHIFT 61
153 1.8.6.2 nathanw
154 1.8.6.2 nathanw /*
155 1.8.6.2 nathanw * Why couldn't Sun pick better page sizes?
156 1.8.6.2 nathanw *
157 1.8.6.2 nathanw * Page sizes are 2**(12+(3*sz)), except for 8K which
158 1.8.6.2 nathanw * is 2**12+1 instead of 2**12.
159 1.8.6.2 nathanw */
160 1.8.6.2 nathanw #define PG_SZ(s) (1<<(12+(s?(3*s):1)))
161 1.8.6.2 nathanw #define TLB_SZ(s) (((uint64_t)(s))<<PGSZ_SHIFT)
162 1.8.6.2 nathanw
163 1.8.6.2 nathanw /* TLB data masks */
164 1.8.6.2 nathanw #define TLB_V 0x8000000000000000LL
165 1.8.6.2 nathanw #define TLB_8K TLB_SZ(PGSZ_8K)
166 1.8.6.2 nathanw #define TLB_64K TLB_SZ(PGSZ_64K)
167 1.8.6.2 nathanw #define TLB_512K TLB_SZ(PGSZ_512K)
168 1.8.6.2 nathanw #define TLB_4M TLB_SZ(PGSZ_4M)
169 1.8.6.2 nathanw #define TLB_SZ_MASK 0x6000000000000000LL
170 1.8.6.2 nathanw #define TLB_NFO 0x1000000000000000LL
171 1.8.6.2 nathanw #define TLB_IE 0x0800000000000000LL
172 1.8.6.2 nathanw #define TLB_SOFT2_MASK 0x07fe000000000000LL
173 1.8.6.2 nathanw #define TLB_DIAG_MASK 0x0001fe0000000000LL
174 1.8.6.2 nathanw #define TLB_PA_MASK 0x000001ffffffe000LL
175 1.8.6.2 nathanw #define TLB_SOFT_MASK 0x0000000000001f80LL
176 1.8.6.2 nathanw /* S/W bits */
177 1.8.6.2 nathanw /* Access & TSB locked bits are swapped so I can set access w/one insn */
178 1.8.6.2 nathanw /* #define TLB_ACCESS 0x0000000000001000LL */
179 1.8.6.2 nathanw #define TLB_ACCESS 0x0000000000000200LL
180 1.8.6.2 nathanw #define TLB_MODIFY 0x0000000000000800LL
181 1.8.6.2 nathanw #define TLB_REAL_W 0x0000000000000400LL
182 1.8.6.2 nathanw /* #define TLB_TSB_LOCK 0x0000000000000200LL */
183 1.8.6.2 nathanw #define TLB_TSB_LOCK 0x0000000000001000LL
184 1.8.6.2 nathanw #define TLB_EXEC 0x0000000000000100LL
185 1.8.6.2 nathanw #define TLB_EXEC_ONLY 0x0000000000000080LL
186 1.8.6.2 nathanw /* H/W bits */
187 1.8.6.2 nathanw #define TLB_L 0x0000000000000040LL
188 1.8.6.2 nathanw #define TLB_CACHE_MASK 0x0000000000000030LL
189 1.8.6.2 nathanw #define TLB_CP 0x0000000000000020LL
190 1.8.6.2 nathanw #define TLB_CV 0x0000000000000010LL
191 1.8.6.2 nathanw #define TLB_E 0x0000000000000008LL
192 1.8.6.2 nathanw #define TLB_P 0x0000000000000004LL
193 1.8.6.2 nathanw #define TLB_W 0x0000000000000002LL
194 1.8.6.2 nathanw #define TLB_G 0x0000000000000001LL
195 1.8.6.2 nathanw
196 1.8.6.3 nathanw /* Use a bit in the SOFT2 area to indicate a locked mapping. */
197 1.8.6.3 nathanw #define TLB_WIRED 0x0010000000000000LL
198 1.8.6.3 nathanw
199 1.8.6.2 nathanw /*
200 1.8.6.2 nathanw * The following bits are used by locore so they should
201 1.8.6.2 nathanw * be duplicates of the above w/o the "long long"
202 1.8.6.2 nathanw */
203 1.8.6.2 nathanw /* S/W bits */
204 1.8.6.2 nathanw /* #define TTE_ACCESS 0x0000000000001000 */
205 1.8.6.2 nathanw #define TTE_ACCESS 0x0000000000000200
206 1.8.6.2 nathanw #define TTE_MODIFY 0x0000000000000800
207 1.8.6.2 nathanw #define TTE_REAL_W 0x0000000000000400
208 1.8.6.2 nathanw /* #define TTE_TSB_LOCK 0x0000000000000200 */
209 1.8.6.2 nathanw #define TTE_TSB_LOCK 0x0000000000001000
210 1.8.6.2 nathanw #define TTE_EXEC 0x0000000000000100
211 1.8.6.2 nathanw #define TTE_EXEC_ONLY 0x0000000000000080
212 1.8.6.2 nathanw /* H/W bits */
213 1.8.6.2 nathanw #define TTE_L 0x0000000000000040
214 1.8.6.2 nathanw #define TTE_CACHE_MASK 0x0000000000000030
215 1.8.6.2 nathanw #define TTE_CP 0x0000000000000020
216 1.8.6.2 nathanw #define TTE_CV 0x0000000000000010
217 1.8.6.2 nathanw #define TTE_E 0x0000000000000008
218 1.8.6.2 nathanw #define TTE_P 0x0000000000000004
219 1.8.6.2 nathanw #define TTE_W 0x0000000000000002
220 1.8.6.2 nathanw #define TTE_G 0x0000000000000001
221 1.8.6.2 nathanw
222 1.8.6.2 nathanw #define TTE_DATA_BITS "\177\20" \
223 1.8.6.2 nathanw "b\77V\0" "f\75\2SIZE\0" "b\77V\0" "f\75\2SIZE\0" \
224 1.8.6.2 nathanw "=\0008K\0" "=\00164K\0" "=\002512K\0" "=\0034M\0" \
225 1.8.6.2 nathanw "b\74NFO\0" "b\73IE\0" "f\62\10SOFT2\0" \
226 1.8.6.2 nathanw "f\51\10DIAG\0" "f\15\33PA<40:13>\0" "f\7\5SOFT\0" \
227 1.8.6.2 nathanw "b\6L\0" "b\5CP\0" "b\4CV\0" \
228 1.8.6.2 nathanw "b\3E\0" "b\2P\0" "b\1W\0" "b\0G\0"
229 1.8.6.2 nathanw
230 1.8.6.2 nathanw #define TSB_DATA(g,sz,pa,priv,write,cache,aliased,valid,ie) \
231 1.8.6.2 nathanw (((valid)?TLB_V:0LL)|TLB_SZ(sz)|(((u_int64_t)(pa))&TLB_PA_MASK)|\
232 1.8.6.2 nathanw ((cache)?((aliased)?TLB_CP:TLB_CACHE_MASK):TLB_E)|\
233 1.8.6.2 nathanw ((priv)?TLB_P:0LL)|((write)?TLB_W:0LL)|((g)?TLB_G:0LL)|((ie)?TLB_IE:0LL))
234 1.8.6.2 nathanw
235 1.8.6.2 nathanw #define MMU_CACHE_VIRT 0x3
236 1.8.6.2 nathanw #define MMU_CACHE_PHYS 0x2
237 1.8.6.2 nathanw #define MMU_CACHE_NONE 0x0
238 1.8.6.2 nathanw
239 1.8.6.2 nathanw /* This needs to be updated for sun4u IOMMUs */
240 1.8.6.2 nathanw /*
241 1.8.6.2 nathanw * IOMMU PTE bits.
242 1.8.6.2 nathanw */
243 1.8.6.2 nathanw #define IOPTE_PPN_MASK 0x07ffff00
244 1.8.6.2 nathanw #define IOPTE_PPN_SHIFT 8
245 1.8.6.2 nathanw #define IOPTE_RSVD 0x000000f1
246 1.8.6.2 nathanw #define IOPTE_WRITE 0x00000004
247 1.8.6.2 nathanw #define IOPTE_VALID 0x00000002
248 1.8.6.2 nathanw
249 1.8.6.2 nathanw /*
250 1.8.6.2 nathanw * This is purely for compatibility with the old SPARC machines.
251 1.8.6.2 nathanw */
252 1.8.6.2 nathanw #define NBPRG (1 << 24) /* bytes per region */
253 1.8.6.2 nathanw #define RGSHIFT 24 /* log2(NBPRG) */
254 1.8.6.2 nathanw #define NSEGRG (NBPRG / NBPSG) /* segments per region */
255 1.8.6.2 nathanw
256 1.8.6.2 nathanw #define NBPSG (1 << 18) /* bytes per segment */
257 1.8.6.2 nathanw #define SGSHIFT 18 /* log2(NBPSG) */
258 1.8.6.2 nathanw
259 1.8.6.2 nathanw /* there is no `struct pte'; we just use `int'; this is for non-4M only */
260 1.8.6.2 nathanw #define PG_V 0x80000000
261 1.8.6.2 nathanw #define PG_PFNUM 0x0007ffff /* n.b.: only 16 bits on sun4c */
262 1.8.6.2 nathanw
263 1.8.6.2 nathanw /* virtual address to virtual region number */
264 1.8.6.2 nathanw #define VA_VREG(va) (((unsigned int)(va) >> RGSHIFT) & 255)
265 1.8.6.2 nathanw
266 1.8.6.2 nathanw /* virtual address to virtual segment number */
267 1.8.6.2 nathanw #define VA_VSEG(va) (((unsigned int)(va) >> SGSHIFT) & 63)
268 1.8.6.2 nathanw
269 1.8.6.2 nathanw #ifndef _LOCORE
270 1.8.6.2 nathanw typedef u_short pmeg_t; /* 10 bits needed per Sun-4 segmap entry */
271 1.8.6.2 nathanw #endif
272 1.8.6.2 nathanw
273 1.8.6.2 nathanw /*
274 1.8.6.2 nathanw * Here are the bit definitions for 4M/SRMMU pte's
275 1.8.6.2 nathanw */
276 1.8.6.2 nathanw /* MMU TABLE ENTRIES */
277 1.8.6.2 nathanw #define SRMMU_TETYPE 0x3 /* mask for table entry type */
278 1.8.6.2 nathanw #define SRMMU_TEPTE 0x2 /* Page Table Entry */
279 1.8.6.2 nathanw /* PTE FIELDS */
280 1.8.6.2 nathanw #define SRMMU_PPNMASK 0xFFFFFF00
281 1.8.6.2 nathanw #define SRMMU_PPNPASHIFT 0x4 /* shift to put ppn into PAddr */
282