pte.h revision 1.1.2.4 1 1.1.2.4 nathanw /* $NetBSD: pte.h,v 1.1.2.4 2002/04/17 00:02:31 nathanw Exp $ */
2 1.1.2.2 nathanw
3 1.1.2.2 nathanw /*
4 1.1.2.4 nathanw * Copyright (c) 2001, 2002 Wasabi Systems, Inc.
5 1.1.2.2 nathanw * All rights reserved.
6 1.1.2.2 nathanw *
7 1.1.2.4 nathanw * Written by Jason R. Thorpe for Wasabi Systems, Inc.
8 1.1.2.4 nathanw *
9 1.1.2.2 nathanw * Redistribution and use in source and binary forms, with or without
10 1.1.2.2 nathanw * modification, are permitted provided that the following conditions
11 1.1.2.2 nathanw * are met:
12 1.1.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
13 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer.
14 1.1.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
16 1.1.2.2 nathanw * documentation and/or other materials provided with the distribution.
17 1.1.2.2 nathanw * 3. All advertising materials mentioning features or use of this software
18 1.1.2.2 nathanw * must display the following acknowledgement:
19 1.1.2.4 nathanw * This product includes software developed for the NetBSD Project by
20 1.1.2.4 nathanw * Wasabi Systems, Inc.
21 1.1.2.4 nathanw * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1.2.4 nathanw * or promote products derived from this software without specific prior
23 1.1.2.4 nathanw * written permission.
24 1.1.2.4 nathanw *
25 1.1.2.4 nathanw * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1.2.4 nathanw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1.2.4 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1.2.4 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1.2.4 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1.2.4 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1.2.4 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1.2.4 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1.2.4 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1.2.4 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1.2.4 nathanw * POSSIBILITY OF SUCH DAMAGE.
36 1.1.2.4 nathanw */
37 1.1.2.2 nathanw
38 1.1.2.4 nathanw #ifndef _ARM_PTE_H_
39 1.1.2.4 nathanw #define _ARM_PTE_H_
40 1.1.2.4 nathanw
41 1.1.2.4 nathanw /*
42 1.1.2.4 nathanw * The ARM MMU architecture was introduced with ARM v3 (previous ARM
43 1.1.2.4 nathanw * architecture versions used an optional off-CPU memory controller
44 1.1.2.4 nathanw * to perform address translation).
45 1.1.2.4 nathanw *
46 1.1.2.4 nathanw * The ARM MMU consists of a TLB and translation table walking logic.
47 1.1.2.4 nathanw * There is typically one TLB per memory interface (or, put another
48 1.1.2.4 nathanw * way, one TLB per software-visible cache).
49 1.1.2.4 nathanw *
50 1.1.2.4 nathanw * The ARM MMU is capable of mapping memory in the following chunks:
51 1.1.2.4 nathanw *
52 1.1.2.4 nathanw * 1M Sections (L1 table)
53 1.1.2.4 nathanw *
54 1.1.2.4 nathanw * 64K Large Pages (L2 table)
55 1.1.2.4 nathanw *
56 1.1.2.4 nathanw * 4K Small Pages (L2 table)
57 1.1.2.4 nathanw *
58 1.1.2.4 nathanw * 1K Tiny Pages (L2 table)
59 1.1.2.4 nathanw *
60 1.1.2.4 nathanw * There are two types of L2 tables: Coarse Tables and Fine Tables.
61 1.1.2.4 nathanw * Coarse Tables can map Large and Small Pages. Fine Tables can
62 1.1.2.4 nathanw * map Tiny Pages.
63 1.1.2.4 nathanw *
64 1.1.2.4 nathanw * Coarse Tables can define 4 Subpages within Large and Small pages.
65 1.1.2.4 nathanw * Subpages define different permissions for each Subpage within
66 1.1.2.4 nathanw * a Page.
67 1.1.2.4 nathanw *
68 1.1.2.4 nathanw * Coarse Tables are 1K in length. Fine tables are 4K in length.
69 1.1.2.4 nathanw *
70 1.1.2.4 nathanw * The Translation Table Base register holds the pointer to the
71 1.1.2.4 nathanw * L1 Table. The L1 Table is a 16K contiguous chunk of memory
72 1.1.2.4 nathanw * aligned to a 16K boundary. Each entry in the L1 Table maps
73 1.1.2.4 nathanw * 1M of virtual address space, either via a Section mapping or
74 1.1.2.4 nathanw * via an L2 Table.
75 1.1.2.4 nathanw *
76 1.1.2.4 nathanw * In addition, the Fast Context Switching Extension (FCSE) is available
77 1.1.2.4 nathanw * on some ARM v4 and ARM v5 processors. FCSE is a way of eliminating
78 1.1.2.4 nathanw * TLB/cache flushes on context switch by use of a smaller address space
79 1.1.2.4 nathanw * and a "process ID" that modifies the virtual address before being
80 1.1.2.4 nathanw * presented to the translation logic.
81 1.1.2.4 nathanw */
82 1.1.2.2 nathanw
83 1.1.2.2 nathanw #ifndef _LOCORE
84 1.1.2.4 nathanw typedef uint32_t pd_entry_t; /* L1 table entry */
85 1.1.2.4 nathanw typedef uint32_t pt_entry_t; /* L2 table entry */
86 1.1.2.4 nathanw #endif /* _LOCORE */
87 1.1.2.4 nathanw
88 1.1.2.4 nathanw #define L1_S_SIZE 0x00100000 /* 1M */
89 1.1.2.4 nathanw #define L1_S_OFFSET (L1_S_SIZE - 1)
90 1.1.2.4 nathanw #define L1_S_FRAME (~L1_S_OFFSET)
91 1.1.2.4 nathanw #define L1_S_SHIFT 20
92 1.1.2.4 nathanw
93 1.1.2.4 nathanw #define L2_L_SIZE 0x00010000 /* 64K */
94 1.1.2.4 nathanw #define L2_L_OFFSET (L2_L_SIZE - 1)
95 1.1.2.4 nathanw #define L2_L_FRAME (~L2_L_OFFSET)
96 1.1.2.4 nathanw #define L2_L_SHIFT 16
97 1.1.2.4 nathanw
98 1.1.2.4 nathanw #define L2_S_SIZE 0x00001000 /* 4K */
99 1.1.2.4 nathanw #define L2_S_OFFSET (L2_S_SIZE - 1)
100 1.1.2.4 nathanw #define L2_S_FRAME (~L2_S_OFFSET)
101 1.1.2.4 nathanw #define L2_S_SHIFT 12
102 1.1.2.4 nathanw
103 1.1.2.4 nathanw #define L2_T_SIZE 0x00000400 /* 1K */
104 1.1.2.4 nathanw #define L2_T_OFFSET (L2_T_SIZE - 1)
105 1.1.2.4 nathanw #define L2_T_FRAME (~L2_T_OFFSET)
106 1.1.2.4 nathanw #define L2_T_SHIFT 10
107 1.1.2.4 nathanw
108 1.1.2.4 nathanw /*
109 1.1.2.4 nathanw * The NetBSD VM implementation only works on whole pages (4K),
110 1.1.2.4 nathanw * whereas the ARM MMU's Coarse tables are sized in terms of 1K
111 1.1.2.4 nathanw * (16K L1 table, 1K L2 table).
112 1.1.2.4 nathanw *
113 1.1.2.4 nathanw * So, we allocate L2 tables 4 at a time, thus yielding a 4K L2
114 1.1.2.4 nathanw * table.
115 1.1.2.4 nathanw */
116 1.1.2.4 nathanw #define L1_ADDR_BITS 0xfff00000 /* L1 PTE address bits */
117 1.1.2.4 nathanw #define L2_ADDR_BITS 0x000ff000 /* L2 PTE address bits */
118 1.1.2.4 nathanw
119 1.1.2.4 nathanw #define L1_TABLE_SIZE 0x4000 /* 16K */
120 1.1.2.4 nathanw #define L2_TABLE_SIZE 0x1000 /* 4K */
121 1.1.2.2 nathanw
122 1.1.2.4 nathanw /*
123 1.1.2.4 nathanw * ARM L1 Descriptors
124 1.1.2.4 nathanw */
125 1.1.2.4 nathanw
126 1.1.2.4 nathanw #define L1_TYPE_INV 0x00 /* Invalid (fault) */
127 1.1.2.4 nathanw #define L1_TYPE_C 0x01 /* Coarse L2 */
128 1.1.2.4 nathanw #define L1_TYPE_S 0x02 /* Section */
129 1.1.2.4 nathanw #define L1_TYPE_F 0x03 /* Fine L2 */
130 1.1.2.4 nathanw #define L1_TYPE_MASK 0x03 /* mask of type bits */
131 1.1.2.4 nathanw
132 1.1.2.4 nathanw /* L1 Section Descriptor */
133 1.1.2.4 nathanw #define L1_S_B 0x00000004 /* bufferable Section */
134 1.1.2.4 nathanw #define L1_S_C 0x00000008 /* cacheable Section */
135 1.1.2.4 nathanw #define L1_S_IMP 0x00000010 /* implementation defined */
136 1.1.2.4 nathanw #define L1_S_DOM(x) ((x) << 5) /* domain */
137 1.1.2.4 nathanw #define L1_S_DOM_MASK L1_S_DOM(0xf)
138 1.1.2.4 nathanw #define L1_S_AP(x) ((x) << 10) /* access permissions */
139 1.1.2.4 nathanw #define L1_S_ADDR_MASK 0xfff00000 /* phys address of section */
140 1.1.2.4 nathanw
141 1.1.2.4 nathanw #define L1_S_XSCALE_P 0x00000200 /* ECC enable for this section */
142 1.1.2.4 nathanw #define L1_S_XSCALE_TEX(x) ((x) << 12) /* Type Extension */
143 1.1.2.4 nathanw
144 1.1.2.4 nathanw /* L1 Coarse Descriptor */
145 1.1.2.4 nathanw #define L1_C_IMP0 0x00000004 /* implementation defined */
146 1.1.2.4 nathanw #define L1_C_IMP1 0x00000008 /* implementation defined */
147 1.1.2.4 nathanw #define L1_C_IMP2 0x00000010 /* implementation defined */
148 1.1.2.4 nathanw #define L1_C_DOM(x) ((x) << 5) /* domain */
149 1.1.2.4 nathanw #define L1_C_DOM_MASK L1_C_DOM(0xf)
150 1.1.2.4 nathanw #define L1_C_ADDR_MASK 0xfffffc00 /* phys address of L2 Table */
151 1.1.2.4 nathanw
152 1.1.2.4 nathanw #define L1_C_XSCALE_P 0x00000200 /* ECC enable for this section */
153 1.1.2.4 nathanw
154 1.1.2.4 nathanw /* L1 Fine Descriptor */
155 1.1.2.4 nathanw #define L1_F_IMP0 0x00000004 /* implementation defined */
156 1.1.2.4 nathanw #define L1_F_IMP1 0x00000008 /* implementation defined */
157 1.1.2.4 nathanw #define L1_F_IMP2 0x00000010 /* implementation defined */
158 1.1.2.4 nathanw #define L1_F_DOM(x) ((x) << 5) /* domain */
159 1.1.2.4 nathanw #define L1_F_DOM_MASK L1_F_DOM(0xf)
160 1.1.2.4 nathanw #define L1_F_ADDR_MASK 0xfffff000 /* phys address of L2 Table */
161 1.1.2.4 nathanw
162 1.1.2.4 nathanw #define L1_F_XSCALE_P 0x00000200 /* ECC enable for this section */
163 1.1.2.4 nathanw
164 1.1.2.4 nathanw /*
165 1.1.2.4 nathanw * ARM L2 Descriptors
166 1.1.2.4 nathanw */
167 1.1.2.4 nathanw
168 1.1.2.4 nathanw #define L2_TYPE_INV 0x00 /* Invalid (fault) */
169 1.1.2.4 nathanw #define L2_TYPE_L 0x01 /* Large Page */
170 1.1.2.4 nathanw #define L2_TYPE_S 0x02 /* Small Page */
171 1.1.2.4 nathanw #define L2_TYPE_T 0x03 /* Tiny Page */
172 1.1.2.4 nathanw #define L2_TYPE_MASK 0x03 /* mask of type bits */
173 1.1.2.4 nathanw
174 1.1.2.4 nathanw /*
175 1.1.2.4 nathanw * This L2 Descriptor type is available on XScale processors
176 1.1.2.4 nathanw * when using a Coarse L1 Descriptor. The Extended Small
177 1.1.2.4 nathanw * Descriptor has the same format as the XScale Tiny Descriptor,
178 1.1.2.4 nathanw * but describes a 4K page, rather than a 1K page.
179 1.1.2.4 nathanw */
180 1.1.2.4 nathanw #define L2_TYPE_XSCALE_XS 0x03 /* XScale Extended Small Page */
181 1.1.2.4 nathanw
182 1.1.2.4 nathanw #define L2_B 0x00000004 /* Bufferable page */
183 1.1.2.4 nathanw #define L2_C 0x00000008 /* Cacheable page */
184 1.1.2.4 nathanw #define L2_AP0(x) ((x) << 4) /* access permissions (sp 0) */
185 1.1.2.4 nathanw #define L2_AP1(x) ((x) << 6) /* access permissions (sp 1) */
186 1.1.2.4 nathanw #define L2_AP2(x) ((x) << 8) /* access permissions (sp 2) */
187 1.1.2.4 nathanw #define L2_AP3(x) ((x) << 10) /* access permissions (sp 3) */
188 1.1.2.4 nathanw #define L2_AP(x) (L2_AP0(x) | L2_AP1(x) | L2_AP2(x) | L2_AP3(x))
189 1.1.2.4 nathanw
190 1.1.2.4 nathanw #define L2_XSCALE_L_TEX(x) ((x) << 12) /* Type Extension */
191 1.1.2.4 nathanw #define L2_XSCALE_T_TEX(x) ((x) << 6) /* Type Extension */
192 1.1.2.2 nathanw
193 1.1.2.4 nathanw /*
194 1.1.2.4 nathanw * Access Permissions for L1 and L2 Descriptors.
195 1.1.2.4 nathanw */
196 1.1.2.4 nathanw #define AP_W 0x01 /* writable */
197 1.1.2.4 nathanw #define AP_U 0x02 /* user */
198 1.1.2.2 nathanw
199 1.1.2.4 nathanw /*
200 1.1.2.4 nathanw * Short-hand for common AP_* constants.
201 1.1.2.4 nathanw *
202 1.1.2.4 nathanw * Note: These values assume the S (System) bit is set and
203 1.1.2.4 nathanw * the R (ROM) bit is clear in CP15 register 1.
204 1.1.2.4 nathanw */
205 1.1.2.4 nathanw #define AP_KR 0x00 /* kernel read */
206 1.1.2.4 nathanw #define AP_KRW 0x01 /* kernel read/write */
207 1.1.2.4 nathanw #define AP_KRWUR 0x02 /* kernel read/write usr read */
208 1.1.2.4 nathanw #define AP_KRWURW 0x03 /* kernel read/write usr read/write */
209 1.1.2.4 nathanw
210 1.1.2.4 nathanw /*
211 1.1.2.4 nathanw * Domain Types for the Domain Access Control Register.
212 1.1.2.4 nathanw */
213 1.1.2.4 nathanw #define DOMAIN_FAULT 0x00 /* no access */
214 1.1.2.4 nathanw #define DOMAIN_CLIENT 0x01 /* client */
215 1.1.2.4 nathanw #define DOMAIN_RESERVED 0x02 /* reserved */
216 1.1.2.4 nathanw #define DOMAIN_MANAGER 0x03 /* manager */
217 1.1.2.4 nathanw
218 1.1.2.4 nathanw /*
219 1.1.2.4 nathanw * Type Extension bits for XScale processors.
220 1.1.2.4 nathanw *
221 1.1.2.4 nathanw * Behavior of C and B when X == 0:
222 1.1.2.4 nathanw *
223 1.1.2.4 nathanw * C B Cacheable Bufferable Write Policy Line Allocate Policy
224 1.1.2.4 nathanw * 0 0 N N - -
225 1.1.2.4 nathanw * 0 1 N Y - -
226 1.1.2.4 nathanw * 1 0 Y Y Write-through Read Allocate
227 1.1.2.4 nathanw * 1 1 Y Y Write-back Read Allocate
228 1.1.2.4 nathanw *
229 1.1.2.4 nathanw * Behavior of C and B when X == 1:
230 1.1.2.4 nathanw * C B Cacheable Bufferable Write Policy Line Allocate Policy
231 1.1.2.4 nathanw * 0 0 - - - - DO NOT USE
232 1.1.2.4 nathanw * 0 1 N Y - -
233 1.1.2.4 nathanw * 1 0 Mini-Data - - -
234 1.1.2.4 nathanw * 1 1 Y Y Write-back R/W Allocate
235 1.1.2.4 nathanw */
236 1.1.2.4 nathanw #define TEX_XSCALE_X 0x01 /* X modifies C and B */
237 1.1.2.2 nathanw
238 1.1.2.4 nathanw #endif /* _ARM_PTE_H_ */
239