mc68851.h revision 1.2 1 1.2 gwr /* $NetBSD: mc68851.h,v 1.2 1997/01/16 21:47:31 gwr Exp $ */
2 1.1 gwr
3 1.1 gwr /*-
4 1.1 gwr * Copyright (c) 1997 The NetBSD Foundation, Inc.
5 1.1 gwr * All rights reserved.
6 1.1 gwr *
7 1.1 gwr * This code is derived from software contributed to The NetBSD Foundation
8 1.1 gwr * by Jeremy Cooper.
9 1.1 gwr *
10 1.1 gwr * Redistribution and use in source and binary forms, with or without
11 1.1 gwr * modification, are permitted provided that the following conditions
12 1.1 gwr * are met:
13 1.1 gwr * 1. Redistributions of source code must retain the above copyright
14 1.1 gwr * notice, this list of conditions and the following disclaimer.
15 1.1 gwr * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 gwr * notice, this list of conditions and the following disclaimer in the
17 1.1 gwr * documentation and/or other materials provided with the distribution.
18 1.1 gwr * 3. All advertising materials mentioning features or use of this software
19 1.1 gwr * must display the following acknowledgement:
20 1.1 gwr * This product includes software developed by the NetBSD
21 1.1 gwr * Foundation, Inc. and its contributors.
22 1.1 gwr * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1 gwr * contributors may be used to endorse or promote products derived
24 1.1 gwr * from this software without specific prior written permission.
25 1.1 gwr *
26 1.1 gwr * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1 gwr * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1 gwr * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1 gwr * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1 gwr * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1 gwr * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1 gwr * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1 gwr * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1 gwr * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1 gwr * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1 gwr * POSSIBILITY OF SUCH DAMAGE.
37 1.1 gwr */
38 1.1 gwr
39 1.2 gwr /*
40 1.2 gwr * This file should contain the machine-independent definitions
41 1.2 gwr * related to the Motorola MC68881 Memory Management Unit (MMU).
42 1.2 gwr * Things that depend on the contents of the Translation Control
43 1.2 gwr * (TC) register should be in <machine/pte.h>, not here.
44 1.2 gwr */
45 1.2 gwr
46 1.1 gwr #ifndef _SUN3X_MC68851_H
47 1.1 gwr #define _SUN3X_MC68851_H
48 1.1 gwr
49 1.1 gwr /**************************** MMU STRUCTURES ****************************
50 1.1 gwr * MMU structures define the format of data used by the MC68851. *
51 1.1 gwr ************************************************************************
52 1.1 gwr * A virtual address is translated into a physical address by dividing its
53 1.1 gwr * bits into four fields. The first three fields are used as indexes into
54 1.1 gwr * descriptor tables and the last field (the 13 lowest significant
55 1.1 gwr * bits) is an offset to be added to the base address found at the final
56 1.1 gwr * table. The first three fields are named TIA, TIB and TIC respectively.
57 1.1 gwr * 31 12 0
58 1.1 gwr * +-.-.-.-.-.-.-+-.-.-.-.-.-+-.-.-.-.-.-+-.-.-.-.-.-.-.-.-.-.-.-.-+
59 1.1 gwr * | TIA | TIB | TIC | OFFSET |
60 1.1 gwr * +-.-.-.-.-.-.-+-.-.-.-.-.-+-.-.-.-.-.-+-.-.-.-.-.-.-.-.-.-.-.-.-+
61 1.1 gwr */
62 1.1 gwr #define MMU_TIA_SHIFT (13+6+6)
63 1.1 gwr #define MMU_TIA_MASK (0xfe000000)
64 1.1 gwr #define MMU_TIA_RANGE (0x02000000)
65 1.1 gwr #define MMU_TIB_SHIFT (13+6)
66 1.1 gwr #define MMU_TIB_MASK (0x01f80000)
67 1.1 gwr #define MMU_TIB_RANGE (0x00080000)
68 1.1 gwr #define MMU_TIC_SHIFT (13)
69 1.1 gwr #define MMU_TIC_MASK (0x0007e000)
70 1.1 gwr #define MMU_TIC_RANGE (0x00002000)
71 1.1 gwr #define MMU_PAGE_SHIFT (13)
72 1.1 gwr #define MMU_PAGE_MASK (0xffffe000)
73 1.1 gwr #define MMU_PAGE_SIZE (0x00002000)
74 1.1 gwr
75 1.1 gwr /* Macros which extract each of these fields out of a given
76 1.1 gwr * VA.
77 1.1 gwr */
78 1.1 gwr #define MMU_TIA(va) \
79 1.1 gwr ((unsigned long) ((va) & MMU_TIA_MASK) >> MMU_TIA_SHIFT)
80 1.1 gwr #define MMU_TIB(va) \
81 1.1 gwr ((unsigned long) ((va) & MMU_TIB_MASK) >> MMU_TIB_SHIFT)
82 1.1 gwr #define MMU_TIC(va) \
83 1.1 gwr ((unsigned long) ((va) & MMU_TIC_MASK) >> MMU_TIC_SHIFT)
84 1.1 gwr
85 1.1 gwr /* The widths of the TIA, TIB, and TIC fields determine the size (in
86 1.1 gwr * elements) of the tables they index.
87 1.1 gwr */
88 1.1 gwr #define MMU_A_TBL_SIZE (128)
89 1.1 gwr #define MMU_B_TBL_SIZE (64)
90 1.1 gwr #define MMU_C_TBL_SIZE (64)
91 1.1 gwr
92 1.1 gwr /* Rounding macros.
93 1.1 gwr * The MMU_ROUND macros are named misleadingly. MMU_ROUND_A actually
94 1.1 gwr * rounds an address to the nearest B table boundary, and so on.
95 1.1 gwr * MMU_ROUND_C() is synonmous with sun3x_round_page().
96 1.1 gwr */
97 1.1 gwr #define MMU_ROUND_A(pa)\
98 1.1 gwr ((unsigned long) (pa) & MMU_TIA_MASK)
99 1.1 gwr #define MMU_ROUND_UP_A(pa)\
100 1.1 gwr ((unsigned long) (pa + MMU_TIA_RANGE - 1) & MMU_TIA_MASK)
101 1.1 gwr #define MMU_ROUND_B(pa)\
102 1.1 gwr ((unsigned long) (pa) & (MMU_TIA_MASK|MMU_TIB_MASK))
103 1.1 gwr #define MMU_ROUND_UP_B(pa)\
104 1.1 gwr ((unsigned long) (pa + MMU_TIB_RANGE - 1) & (MMU_TIA_MASK|MMU_TIB_MASK))
105 1.1 gwr #define MMU_ROUND_C(pa)\
106 1.1 gwr ((unsigned long) (pa) & MMU_PAGE_MASK)
107 1.1 gwr #define MMU_ROUND_UP_C(pa)\
108 1.1 gwr ((unsigned long) (pa + MMU_PAGE_SIZE - 1) & MMU_PAGE_MASK)
109 1.1 gwr
110 1.2 gwr
111 1.2 gwr /** MC68851 Root Pointer
112 1.2 gwr */
113 1.2 gwr struct mmu_rootptr {
114 1.2 gwr u_long limit; /* and type */
115 1.2 gwr u_long paddr;
116 1.2 gwr };
117 1.2 gwr
118 1.1 gwr
119 1.1 gwr /** MC68851 Long Format Table Descriptor
120 1.1 gwr * The root table for a sun3x pmap is a 128 element array of 'long format
121 1.1 gwr * table descriptors'. The structure of a long format table descriptor is:
122 1.1 gwr *
123 1.1 gwr * 63 48
124 1.1 gwr * +---+---.---.---.---.---.---.---.---.---.---.---.---.---.---.---+
125 1.1 gwr * |L/U| LIMIT |
126 1.1 gwr * +---+---.---+---.---.---+---+---+---+---+---+---+---+---+---.---+
127 1.1 gwr * | RAL | WAL |SG | S | 0 | 0 | 0 | 0 | U |WP |DT (10)|
128 1.1 gwr * +---.---.---+---.---.---+---+---+---+---+---+---+---+---+---.---+
129 1.1 gwr * | TABLE PHYSICAL ADDRESS (BITS 31-16) |
130 1.1 gwr * +---.---.---.---.---.---.---.---.---.---.---.---+---.---.---.---+
131 1.1 gwr * | TABLE PHYSICAL ADDRESS (15-4) | UNUSED |
132 1.1 gwr * +---.---.---.---.---.---.---.---.---.---.---.---+---.---.---.---+
133 1.1 gwr * 15 0
134 1.1 gwr *
135 1.1 gwr * Note: keep the unused bits set to zero so that no masking of the
136 1.1 gwr * base address is needed.
137 1.1 gwr */
138 1.1 gwr struct mmu_long_dte_struct { /* 'dte' stands for 'descriptor table entry' */
139 1.1 gwr union {
140 1.1 gwr struct {
141 1.1 gwr char lu_flag:1; /* Lower/Upper Limit flag */
142 1.1 gwr int limit:15; /* Table Size limit */
143 1.1 gwr char ral:3; /* Read Access Level */
144 1.1 gwr char wal:3; /* Write Access Level */
145 1.1 gwr char sg:1; /* Shared Globally flag */
146 1.1 gwr char supv:1; /* Supervisor Only flag */
147 1.1 gwr char rsvd:4; /* Reserved (All zeros) */
148 1.1 gwr char u:1; /* Used flag */
149 1.1 gwr char wp:1; /* Write Protect flag */
150 1.1 gwr char dt:2; /* Descriptor Type */
151 1.1 gwr /* Bit masks for fields above */
152 1.1 gwr #define MMU_LONG_DTE_LU 0x80000000
153 1.1 gwr #define MMU_LONG_DTE_LIMIT 0x7fff0000
154 1.1 gwr #define MMU_LONG_DTE_RAL 0x0000e000
155 1.1 gwr #define MMU_LONG_DTE_WAL 0x00001c00
156 1.1 gwr #define MMU_LONG_DTE_SG 0x00000200
157 1.1 gwr #define MMU_LONG_DTE_SUPV 0x00000100
158 1.1 gwr #define MMU_LONG_DTE_USED 0x00000008
159 1.1 gwr #define MMU_LONG_DTE_WP 0x00000004
160 1.1 gwr #define MMU_LONG_DTE_DT 0x00000003
161 1.1 gwr } attr_struct;
162 1.1 gwr u_long raw; /* struct above, addressable as a long */
163 1.1 gwr } attr;
164 1.1 gwr union {
165 1.1 gwr struct {
166 1.1 gwr int base_addr:28; /* Physical base address
167 1.1 gwr char unused:4; * of the table pointed to
168 1.1 gwr * by this entry.
169 1.1 gwr */
170 1.1 gwr /* Bit masks for fields above */
171 1.1 gwr #define MMU_LONG_DTE_BASEADDR 0xfffffff0
172 1.1 gwr } addr_struct;
173 1.1 gwr u_long raw; /* struct above, addressable as a long */
174 1.1 gwr } addr;
175 1.1 gwr };
176 1.1 gwr typedef struct mmu_long_dte_struct mmu_long_dte_t;
177 1.1 gwr typedef struct mmu_long_dte_struct *mmu_long_dtbl_t;
178 1.1 gwr
179 1.1 gwr /** MC68851 Long Format Page Descriptor
180 1.1 gwr * Although not likely to be used in this implementation, a level
181 1.1 gwr * 'A' table may contain long format PAGE descriptors. A long format
182 1.1 gwr * page descriptor is the same size as a long format table descriptor.
183 1.1 gwr * Its discriminating feature to the MMU is its descriptor field: 01.
184 1.1 gwr * 63 48
185 1.1 gwr * +---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---+
186 1.1 gwr * | UNUSED |
187 1.1 gwr * +---.---.---+---.---.---+---+---+---+---+---+---+---+---+---.---+
188 1.1 gwr * | RAL | WAL |SG | S | G |CI | L | M | U |WP |DT (01)|
189 1.1 gwr * +---.---.---+---.---.---+---+---+---+---+---+---+---+---+---.---+
190 1.1 gwr * | TABLE PHYSICAL ADDRESS (BITS 31-16) |
191 1.1 gwr * +---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---+
192 1.1 gwr * |TABLE PHYS. ADDRESS (15-8) | UNUSED |
193 1.1 gwr * +---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---+
194 1.1 gwr * 15 0
195 1.1 gwr */
196 1.1 gwr struct mmu_long_pte_struct { /* 'pte' stands for 'page table entry' */
197 1.1 gwr union {
198 1.1 gwr struct {
199 1.1 gwr int unused:16; /* Unused */
200 1.1 gwr char ral:3; /* Read Access Level */
201 1.1 gwr char wal:3; /* Write Access Level */
202 1.1 gwr char sg:1; /* Shared Globally flag */
203 1.1 gwr char supv:1; /* Supervisor Only flag */
204 1.1 gwr char g:1; /* Gate allowed */
205 1.1 gwr char ci:1; /* Cache inhibit */
206 1.1 gwr char l:1; /* Lock entry */
207 1.1 gwr char m:1; /* Modified flag */
208 1.1 gwr char u:1; /* Used flag */
209 1.1 gwr char wp:1; /* Write Protect flag */
210 1.1 gwr char dt:2; /* Descriptor Type */
211 1.1 gwr /* Bit masks for fields above */
212 1.1 gwr #define MMU_LONG_PTE_RAL 0x0000e000
213 1.1 gwr #define MMU_LONG_PTE_WAL 0x00001c00
214 1.1 gwr #define MMU_LONG_PTE_SG 0x00000200
215 1.1 gwr #define MMU_LONG_PTE_SUPV 0x00000100
216 1.1 gwr #define MMU_LONG_PTE_GATE 0x00000080
217 1.1 gwr #define MMU_LONG_PTE_CI 0x00000040
218 1.1 gwr #define MMU_LONG_PTE_LOCK 0x00000020
219 1.1 gwr #define MMU_LONG_PTE_M 0x00000010
220 1.1 gwr #define MMU_LONG_PTE_USED 0x00000008
221 1.1 gwr #define MMU_LONG_PTE_WP 0x00000004
222 1.1 gwr #define MMU_LONG_PTE_DT 0x00000003
223 1.1 gwr } attr_struct;
224 1.1 gwr u_long raw; /* struct above, addressable as a long */
225 1.1 gwr } attr;
226 1.1 gwr union {
227 1.1 gwr struct {
228 1.1 gwr long base_addr:24; /* Physical base address
229 1.1 gwr char unused:8; * of page this entry
230 1.1 gwr * points to.
231 1.1 gwr */
232 1.1 gwr /* Bit masks for fields above */
233 1.1 gwr #define MMU_LONG_PTE_BASEADDR 0xffffff00
234 1.1 gwr } addr_struct;
235 1.1 gwr u_long raw; /* struct above, addressable as a long */
236 1.1 gwr } addr;
237 1.1 gwr };
238 1.1 gwr typedef struct mmu_long_pte_struct mmu_long_pte_t;
239 1.1 gwr typedef struct mmu_long_pte_struct *mmu_long_ptbl_t;
240 1.1 gwr
241 1.1 gwr /* Every entry in the level A table (except for the page entries
242 1.1 gwr * described above) points to a level B table. Level B tables are
243 1.1 gwr * arrays of 'short format' table descriptors. Their structure
244 1.1 gwr * is smaller than an A table descriptor and is as follows:
245 1.1 gwr *
246 1.1 gwr * 31 16
247 1.1 gwr * +---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---+
248 1.1 gwr * | TABLE PHYSICAL BASE ADDRESS (BITS 31-16) |
249 1.1 gwr * +---.---.---.---.---.---.---.---.---.---.---.---+---+---+---.---+
250 1.1 gwr * | TABLE PHYSICAL BASE ADDRESS (15-4) | U |WP |DT (10)|
251 1.1 gwr * +---.---.---.---.---.---.---.---.---.---.---.---+---+---+---.---+
252 1.1 gwr * 15 0
253 1.1 gwr */
254 1.1 gwr struct mmu_short_dte_struct { /* 'dte' stands for 'descriptor table entry' */
255 1.1 gwr union {
256 1.1 gwr struct {
257 1.1 gwr long base_addr:28;
258 1.1 gwr char u:1;
259 1.1 gwr char wp:1;
260 1.1 gwr char dt:2;
261 1.1 gwr #define MMU_SHORT_DTE_BASEADDR 0xfffffff0
262 1.1 gwr #define MMU_SHORT_DTE_USED 0x00000008
263 1.1 gwr #define MMU_SHORT_DTE_WP 0x00000004
264 1.1 gwr #define MMU_SHORT_DTE_DT 0x00000003
265 1.1 gwr } attr_struct;
266 1.1 gwr u_long raw;
267 1.1 gwr } attr;
268 1.1 gwr };
269 1.1 gwr typedef struct mmu_short_dte_struct mmu_short_dte_t;
270 1.1 gwr typedef struct mmu_short_dte_struct *mmu_short_dtbl_t;
271 1.1 gwr
272 1.1 gwr /* Every entry in a level B table points to a level C table. Level C tables
273 1.1 gwr * contain arrays of short format page 'entry' descriptors. A short format
274 1.1 gwr * page 'entry' is the same size as a short format page 'table'
275 1.1 gwr * descriptor (a B table entry). Thus B and C tables can be allocated
276 1.1 gwr * interchangeably from the same pool. However, we will keep them separate.
277 1.1 gwr *
278 1.1 gwr * The descriptor type (DT) field of a Page Table Entry (PTE) is '01'. This
279 1.1 gwr * indicates to the MMU that the address contained in the PTE's 'base
280 1.1 gwr * address' field is the base address for a physical page in memory to which
281 1.1 gwr * the VA should be mapped, and not a base address for a yet another
282 1.1 gwr * descriptor table, thus ending the table walk.
283 1.1 gwr *
284 1.1 gwr * 31 16
285 1.1 gwr * +---.---.---.---.---.---.---.---.---.---.---.---.---.---.---.---+
286 1.1 gwr * | TABLE PHYSICAL BASE ADDRESS (BITS 31-16) |
287 1.1 gwr * +---.---.---.---.---.---.---.---+---+---+---+---+---+---+---.---+
288 1.1 gwr * |TABLE PHYS. BASE ADDRESS (15-8)| G |CI | L | M | U |WP |DT (10)|
289 1.1 gwr * +---.---.---.---.---.---.---.---+---+---+---+---+---+---+---.---+
290 1.1 gwr * 15 0
291 1.1 gwr */
292 1.1 gwr struct mmu_short_pte_struct { /* 'pte' stands for 'page table entry' */
293 1.1 gwr union {
294 1.1 gwr struct {
295 1.1 gwr long base_addr:24;
296 1.1 gwr char g:1;
297 1.1 gwr char ci:1;
298 1.1 gwr char l:1;
299 1.1 gwr char m:1;
300 1.1 gwr char u:1;
301 1.1 gwr char wp:1;
302 1.1 gwr char dt:2;
303 1.1 gwr #define MMU_SHORT_PTE_BASEADDR 0xffffff00
304 1.1 gwr #define MMU_SHORT_PTE_UN2 0x00000080
305 1.1 gwr #define MMU_SHORT_PTE_CI 0x00000040
306 1.1 gwr #define MMU_SHORT_PTE_UN1 0x00000020
307 1.1 gwr #define MMU_SHORT_PTE_M 0x00000010
308 1.1 gwr #define MMU_SHORT_PTE_USED 0x00000008
309 1.1 gwr #define MMU_SHORT_PTE_WP 0x00000004
310 1.1 gwr #define MMU_SHORT_PTE_DT 0x00000003
311 1.1 gwr } attr_struct;
312 1.1 gwr u_long raw;
313 1.1 gwr } attr;
314 1.1 gwr };
315 1.1 gwr typedef struct mmu_short_pte_struct mmu_short_pte_t;
316 1.1 gwr typedef struct mmu_short_pte_struct *mmu_short_ptbl_t;
317 1.1 gwr
318 1.1 gwr /* These are bit masks and other values that are common to all types of
319 1.1 gwr * descriptors.
320 1.1 gwr */
321 1.1 gwr /* Page table descriptors have a 'Descriptor Type' field describing the
322 1.1 gwr * format of the tables they point to. It is two bits wide and is one of:
323 1.1 gwr */
324 1.1 gwr #define MMU_DT_INVALID 0x0 /* Invalid descriptor entry */
325 1.1 gwr #define MMU_DT_PAGE 0x1 /* Descriptor describes a page entry */
326 1.1 gwr #define MMU_DT_SHORT 0x2 /* describes a short format table */
327 1.1 gwr #define MMU_DT_LONG 0x3 /* describes a long format table */
328 1.1 gwr #define MMU_DT_MASK 0x00000003 /* Bit location of the DT field */
329 1.1 gwr
330 1.1 gwr /* Various macros for manipulating and setting MMU descriptor
331 1.1 gwr * characteristics.
332 1.1 gwr */
333 1.1 gwr /* returns true if a descriptor is valid. */
334 1.1 gwr #define MMU_VALID_DT(dte) ((dte).attr.raw & MMU_DT_MASK)
335 1.1 gwr /* returns true if a descriptor is invalid */
336 1.1 gwr #define MMU_INVALID_DT(dte) (!((dte).attr.raw & MMU_DT_MASK))
337 1.1 gwr /* returns true if a descriptor has been referenced */
338 1.1 gwr #define MMU_PTE_USED(pte) ((pte).attr.raw & MMU_SHORT_PTE_USED)
339 1.1 gwr /* returns true if a descriptor has been modified */
340 1.1 gwr #define MMU_PTE_MODIFIED(pte) ((pte).attr.raw & MMU_SHORT_PTE_M)
341 1.1 gwr /* extracts the physical address from a pte */
342 1.1 gwr #define MMU_PTE_PA(pte) ((pte).attr.raw & MMU_SHORT_PTE_BASEADDR)
343 1.1 gwr /* extracts the physical address from a dte */
344 1.1 gwr #define MMU_DTE_PA(dte) ((dte).attr.raw & MMU_SHORT_DTE_BASEADDR)
345 1.1 gwr
346 1.1 gwr #endif /* _SUN3X_MC68851_H */
347