]>
Commit | Line | Data |
---|---|---|
5ba3f43e A |
1 | /* |
2 | * Copyright (c) 2007 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ | |
5 | * | |
6 | * This file contains Original Code and/or Modifications of Original Code | |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
14 | * | |
15 | * Please obtain a copy of the License at | |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
25 | * | |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
27 | */ | |
28 | /* | |
29 | * FILE_ID: vm_param.h | |
30 | */ | |
31 | ||
32 | /* | |
33 | * ARM machine dependent virtual memory parameters. | |
34 | */ | |
35 | ||
0a7de745 | 36 | #ifndef _MACH_ARM_VM_PARAM_H_ |
5ba3f43e A |
37 | #define _MACH_ARM_VM_PARAM_H_ |
38 | ||
39 | #if defined(KERNEL_PRIVATE) && __ARM_16K_PG__ | |
40 | #include <arm64/proc_reg.h> | |
41 | #endif | |
42 | ||
43 | #if !defined (KERNEL) && !defined (__ASSEMBLER__) | |
44 | #include <mach/vm_page_size.h> | |
45 | #endif | |
46 | ||
0a7de745 | 47 | #define BYTE_SIZE 8 /* byte size in bits */ |
5ba3f43e A |
48 | |
49 | #if defined (KERNEL) | |
50 | ||
51 | #ifndef __ASSEMBLER__ | |
52 | ||
0a7de745 A |
53 | #ifdef __arm__ |
54 | #define PAGE_SHIFT_CONST 12 | |
5ba3f43e | 55 | #elif defined(__arm64__) |
f427ee49 | 56 | extern int PAGE_SHIFT_CONST; |
5ba3f43e A |
57 | #else |
58 | #error Unsupported arch | |
59 | #endif | |
60 | ||
61 | #if defined(KERNEL_PRIVATE) && __ARM_16K_PG__ | |
0a7de745 | 62 | #define PAGE_SHIFT ARM_PGSHIFT |
5ba3f43e | 63 | #else |
0a7de745 | 64 | #define PAGE_SHIFT PAGE_SHIFT_CONST |
5ba3f43e | 65 | #endif |
0a7de745 A |
66 | #define PAGE_SIZE (1 << PAGE_SHIFT) |
67 | #define PAGE_MASK (PAGE_SIZE-1) | |
5ba3f43e | 68 | |
0a7de745 | 69 | #define VM_PAGE_SIZE PAGE_SIZE |
5ba3f43e | 70 | |
0a7de745 | 71 | #define machine_ptob(x) ((x) << PAGE_SHIFT) |
5ba3f43e A |
72 | |
73 | /* | |
74 | * Defined for the purpose of testing the pmap advertised page | |
75 | * size; this does not necessarily match the hardware page size. | |
76 | */ | |
0a7de745 A |
77 | #define TEST_PAGE_SIZE_16K ((PAGE_SHIFT_CONST == 14)) |
78 | #define TEST_PAGE_SIZE_4K ((PAGE_SHIFT_CONST == 12)) | |
5ba3f43e | 79 | |
0a7de745 | 80 | #endif /* !__ASSEMBLER__ */ |
5ba3f43e A |
81 | |
82 | #else | |
83 | ||
0a7de745 A |
84 | #define PAGE_SHIFT vm_page_shift |
85 | #define PAGE_SIZE vm_page_size | |
86 | #define PAGE_MASK vm_page_mask | |
5ba3f43e | 87 | |
0a7de745 | 88 | #define VM_PAGE_SIZE vm_page_size |
5ba3f43e | 89 | |
0a7de745 | 90 | #define machine_ptob(x) ((x) << PAGE_SHIFT) |
5ba3f43e A |
91 | |
92 | #endif | |
93 | ||
0a7de745 A |
94 | #define PAGE_MAX_SHIFT 14 |
95 | #define PAGE_MAX_SIZE (1 << PAGE_MAX_SHIFT) | |
96 | #define PAGE_MAX_MASK (PAGE_MAX_SIZE-1) | |
5ba3f43e | 97 | |
0a7de745 A |
98 | #define PAGE_MIN_SHIFT 12 |
99 | #define PAGE_MIN_SIZE (1 << PAGE_MIN_SHIFT) | |
100 | #define PAGE_MIN_MASK (PAGE_MIN_SIZE-1) | |
5ba3f43e | 101 | |
f427ee49 A |
102 | #define VM_MAX_PAGE_ADDRESS MACH_VM_MAX_ADDRESS |
103 | ||
5ba3f43e A |
104 | #ifndef __ASSEMBLER__ |
105 | ||
106 | #ifdef MACH_KERNEL_PRIVATE | |
107 | ||
0a7de745 A |
108 | #define VM32_SUPPORT 1 |
109 | #define VM32_MIN_ADDRESS ((vm32_offset_t) 0) | |
f427ee49 | 110 | #define VM32_MAX_ADDRESS ((vm32_offset_t) (VM_MAX_ADDRESS & 0xFFFFFFFF)) |
5ba3f43e A |
111 | |
112 | /* | |
113 | * kalloc() parameters: | |
114 | * | |
115 | * Historically kalloc's underlying zones were power-of-2 sizes, with a | |
116 | * KALLOC_MINSIZE of 16 bytes. Thus the allocator ensured that | |
117 | * (sizeof == alignof) >= 16 for all kalloc allocations. | |
118 | * | |
119 | * Today kalloc may use zones with intermediate (small) sizes, constrained by | |
120 | * KALLOC_MINSIZE and a minimum alignment, expressed by KALLOC_LOG2_MINALIGN. | |
121 | * | |
122 | * Note that most dynamically allocated data structures contain more than | |
123 | * one int/long/pointer member, so KALLOC_MINSIZE should probably start at 8. | |
124 | */ | |
125 | ||
126 | #if defined (__arm__) | |
127 | ||
0a7de745 A |
128 | #define KALLOC_MINSIZE 8 /* minimum allocation size */ |
129 | #define KALLOC_LOG2_MINALIGN 3 /* log2 minimum alignment */ | |
5ba3f43e A |
130 | |
131 | #elif defined(__arm64__) | |
132 | ||
0a7de745 A |
133 | #define KALLOC_MINSIZE 16 /* minimum allocation size */ |
134 | #define KALLOC_LOG2_MINALIGN 4 /* log2 minimum alignment */ | |
5ba3f43e A |
135 | |
136 | #else | |
137 | #error Unsupported arch | |
138 | #endif | |
139 | ||
f427ee49 A |
140 | #if defined (__arm__) |
141 | /* existing zone map size limit moved from osfmk/vm/vm_init.c */ | |
142 | #define ZONE_MAP_MAX (1024 * 1024 * 1536) /* 1.5GB for 32bit systems */ | |
143 | #elif defined(__arm64__) | |
144 | /* | |
145 | * Limits the physical pages in the zone map | |
146 | */ | |
147 | #define ZONE_MAP_MAX (31ULL << 30) /* 31GB for 64bit systems */ | |
148 | #else | |
149 | #error Unsupported arch | |
150 | #endif | |
151 | ||
5ba3f43e A |
152 | #endif |
153 | ||
154 | #if defined (__arm__) | |
155 | ||
0a7de745 A |
156 | #define VM_MIN_ADDRESS ((vm_address_t) 0x00000000) |
157 | #define VM_MAX_ADDRESS ((vm_address_t) 0x80000000) | |
5ba3f43e A |
158 | |
159 | /* system-wide values */ | |
0a7de745 A |
160 | #define MACH_VM_MIN_ADDRESS ((mach_vm_offset_t) 0) |
161 | #define MACH_VM_MAX_ADDRESS ((mach_vm_offset_t) VM_MAX_ADDRESS) | |
5ba3f43e A |
162 | |
163 | #elif defined (__arm64__) | |
164 | ||
0a7de745 A |
165 | #define VM_MIN_ADDRESS ((vm_address_t) 0x0000000000000000ULL) |
166 | #define VM_MAX_ADDRESS ((vm_address_t) 0x0000000080000000ULL) | |
5ba3f43e A |
167 | |
168 | /* system-wide values */ | |
cb323159 | 169 | #define MACH_VM_MIN_ADDRESS_RAW 0x0ULL |
f427ee49 A |
170 | #if defined(PLATFORM_MacOSX) || defined(PLATFORM_DriverKit) |
171 | #define MACH_VM_MAX_ADDRESS_RAW 0x00007FFFFE000000ULL | |
172 | #else | |
cb323159 | 173 | #define MACH_VM_MAX_ADDRESS_RAW 0x0000000FC0000000ULL |
f427ee49 A |
174 | #endif |
175 | ||
cb323159 A |
176 | #define MACH_VM_MIN_ADDRESS ((mach_vm_offset_t) MACH_VM_MIN_ADDRESS_RAW) |
177 | #define MACH_VM_MAX_ADDRESS ((mach_vm_offset_t) MACH_VM_MAX_ADDRESS_RAW) | |
178 | ||
2a1bd2d3 A |
179 | #define MACH_VM_MIN_GPU_CARVEOUT_ADDRESS_RAW 0x0000001000000000ULL |
180 | #define MACH_VM_MAX_GPU_CARVEOUT_ADDRESS_RAW 0x0000007000000000ULL | |
181 | #define MACH_VM_MIN_GPU_CARVEOUT_ADDRESS ((mach_vm_offset_t) MACH_VM_MIN_GPU_CARVEOUT_ADDRESS_RAW) | |
182 | #define MACH_VM_MAX_GPU_CARVEOUT_ADDRESS ((mach_vm_offset_t) MACH_VM_MAX_GPU_CARVEOUT_ADDRESS_RAW) | |
5ba3f43e | 183 | |
f427ee49 | 184 | #else /* defined(__arm64__) */ |
5ba3f43e A |
185 | #error architecture not supported |
186 | #endif | |
187 | ||
188 | #define VM_MAP_MIN_ADDRESS VM_MIN_ADDRESS | |
189 | #define VM_MAP_MAX_ADDRESS VM_MAX_ADDRESS | |
190 | ||
0a7de745 | 191 | #ifdef KERNEL |
5ba3f43e A |
192 | |
193 | #if defined (__arm__) | |
f427ee49 | 194 | #define VM_KERNEL_POINTER_SIGNIFICANT_BITS 31 |
0a7de745 A |
195 | #define VM_MIN_KERNEL_ADDRESS ((vm_address_t) 0x80000000) |
196 | #define VM_MAX_KERNEL_ADDRESS ((vm_address_t) 0xFFFEFFFF) | |
197 | #define VM_HIGH_KERNEL_WINDOW ((vm_address_t) 0xFFFE0000) | |
5ba3f43e A |
198 | #elif defined (__arm64__) |
199 | /* | |
200 | * The minimum and maximum kernel address; some configurations may | |
201 | * constrain the address space further. | |
202 | */ | |
f427ee49 A |
203 | #define TiB(x) ((0ULL + (x)) << 40) |
204 | #define GiB(x) ((0ULL + (x)) << 30) | |
205 | ||
206 | #if XNU_KERNEL_PRIVATE | |
207 | #if defined(ARM_LARGE_MEMORY) | |
208 | /* | |
209 | * +-----------------------+--------+--------+------------------------+ | |
210 | * | 0xffff_fe90_0000_0000 |-1472GB | 576GB | KASAN_SHADOW_MIN | | |
211 | * | | | | VM_MAX_KERNEL_ADDRESS | | |
212 | * +-----------------------+--------+--------+------------------------+ | |
213 | * | 0xffff_fe10_0000_0000 |-1984GB | 64GB | PMAP_HEAP_RANGE_START | | |
214 | * +-----------------------+--------+--------+------------------------+ | |
215 | * | 0xffff_fe00_0700_4000 | | | VM_KERNEL_LINK_ADDRESS | | |
216 | * +-----------------------+--------+--------+------------------------+ | |
217 | * | 0xffff_fe00_0000_0000 | -2TB | 0GB | VM_MIN_KERNEL_ADDRESS | | |
218 | * | | | | LOW_GLOBALS | | |
219 | * +-----------------------+--------+--------+------------------------+ | |
220 | */ | |
221 | #define VM_KERNEL_POINTER_SIGNIFICANT_BITS 41 | |
222 | ||
223 | // Kernel VA space starts at -2TB | |
224 | #define VM_MIN_KERNEL_ADDRESS ((vm_address_t) (0ULL - TiB(2))) | |
225 | ||
226 | // 1.25TB for static_memory_region, 512GB for kernel heap, 256GB for KASAN | |
227 | #define VM_MAX_KERNEL_ADDRESS ((vm_address_t) (VM_MIN_KERNEL_ADDRESS + GiB(64) + GiB(512) - 1)) | |
228 | #else // ARM_LARGE_MEMORY | |
229 | /* | |
230 | * +-----------------------+--------+--------+------------------------+ | |
231 | * | 0xffff_fffc_0000_0000 | -16GB | 112GB | KASAN_SHADOW_MIN | | |
232 | * | | | | VM_MAX_KERNEL_ADDRESS | | |
233 | * +-----------------------+--------+--------+------------------------+ | |
234 | * | 0xffff_fff0_0700_4000 | | | VM_KERNEL_LINK_ADDRESS | | |
235 | * +-----------------------+--------+--------+------------------------+ | |
236 | * | 0xffff_fff0_0000_0000 | -64GB | 64GB | LOW_GLOBALS | | |
237 | * | | | | PMAP_HEAP_RANGE_START | <= H8 | |
238 | * +-----------------------+--------+--------+------------------------+ | |
239 | * | 0xffff_ffe0_0000_0000 | -128GB | 0GB | VM_MIN_KERNEL_ADDRESS | | |
240 | * | | | | PMAP_HEAP_RANGE_START | >= H9 | |
241 | * +-----------------------+--------+--------+------------------------+ | |
242 | */ | |
d9a64523 | 243 | #define VM_KERNEL_POINTER_SIGNIFICANT_BITS 37 |
0a7de745 | 244 | #define VM_MIN_KERNEL_ADDRESS ((vm_address_t) 0xffffffe000000000ULL) |
cb323159 | 245 | #define VM_MAX_KERNEL_ADDRESS ((vm_address_t) 0xfffffffbffffffffULL) |
f427ee49 A |
246 | #endif // ARM_LARGE_MEMORY |
247 | ||
248 | #else // !XNU_KERNEL_PRIVATE | |
249 | // Inform kexts about largest possible kernel address space | |
250 | #define VM_MIN_KERNEL_ADDRESS ((vm_address_t) (0ULL - TiB(2))) | |
251 | #define VM_MAX_KERNEL_ADDRESS ((vm_address_t) 0xfffffffbffffffffULL) | |
252 | #endif // XNU_KERNEL_PRIVATE | |
5ba3f43e A |
253 | #else |
254 | #error architecture not supported | |
255 | #endif | |
256 | ||
f427ee49 | 257 | #define VM_MIN_KERNEL_AND_KEXT_ADDRESS VM_MIN_KERNEL_ADDRESS |
5ba3f43e | 258 | |
cb323159 A |
259 | #if __has_feature(ptrauth_calls) |
260 | #include <ptrauth.h> | |
261 | #define VM_KERNEL_STRIP_PTR(_v) (ptrauth_strip((void *)(uintptr_t)(_v), ptrauth_key_asia)) | |
262 | #else /* !ptrauth_calls */ | |
d9a64523 | 263 | #define VM_KERNEL_STRIP_PTR(_v) (_v) |
cb323159 | 264 | #endif /* ptrauth_calls */ |
d9a64523 | 265 | |
0a7de745 | 266 | #define VM_KERNEL_ADDRESS(_va) \ |
d9a64523 A |
267 | ((((vm_address_t)VM_KERNEL_STRIP_PTR(_va)) >= VM_MIN_KERNEL_ADDRESS) && \ |
268 | (((vm_address_t)VM_KERNEL_STRIP_PTR(_va)) <= VM_MAX_KERNEL_ADDRESS)) | |
5ba3f43e A |
269 | |
270 | #ifdef MACH_KERNEL_PRIVATE | |
271 | /* | |
272 | * Physical memory is mapped linearly at an offset virtual memory. | |
273 | */ | |
0a7de745 | 274 | extern unsigned long gVirtBase, gPhysBase, gPhysSize; |
5ba3f43e | 275 | |
0a7de745 | 276 | #define isphysmem(a) (((vm_address_t)(a) - gPhysBase) < gPhysSize) |
cb323159 | 277 | #define physmap_enclosed(a) isphysmem(a) |
5ba3f43e | 278 | |
f427ee49 A |
279 | /* |
280 | * gPhysBase/Size only represent kernel-managed memory. These globals represent | |
281 | * the actual DRAM base address and size as reported by iBoot through the device | |
282 | * tree. | |
283 | */ | |
284 | #include <stdint.h> | |
285 | extern uint64_t gDramBase, gDramSize; | |
286 | #define is_dram_addr(addr) (((uint64_t)(addr) - gDramBase) < gDramSize) | |
287 | ||
5ba3f43e A |
288 | #if KASAN |
289 | /* Increase the stack sizes to account for the redzones that get added to every | |
290 | * stack object. */ | |
0a7de745 | 291 | # define KERNEL_STACK_SIZE (4*4*4096) |
cb323159 A |
292 | #elif DEBUG |
293 | /** | |
294 | * Increase the stack size to account for less efficient use of stack space when | |
295 | * compiling with -O0. | |
296 | */ | |
297 | # define KERNEL_STACK_SIZE (2*4*4096) | |
5ba3f43e | 298 | #else |
f427ee49 A |
299 | /* |
300 | * KERNEL_STACK_MULTIPLIER can be defined externally to get a larger | |
301 | * kernel stack size. For example, adding "-DKERNEL_STACK_MULTIPLIER=2" | |
302 | * helps avoid kernel stack overflows when compiling with "-O0". | |
303 | */ | |
304 | #ifndef KERNEL_STACK_MULTIPLIER | |
305 | #define KERNEL_STACK_MULTIPLIER (1) | |
306 | #endif /* KERNEL_STACK_MULTIPLIER */ | |
307 | # define KERNEL_STACK_SIZE (4*4096*KERNEL_STACK_MULTIPLIER) | |
d9a64523 A |
308 | #endif |
309 | ||
0a7de745 | 310 | #define INTSTACK_SIZE (4*4096) |
d9a64523 A |
311 | |
312 | #ifdef __arm64__ | |
0a7de745 | 313 | #define EXCEPSTACK_SIZE (4*4096) |
d9a64523 | 314 | #else |
0a7de745 | 315 | #define FIQSTACK_SIZE (4096) |
5ba3f43e A |
316 | #endif |
317 | ||
318 | #if defined (__arm__) | |
0a7de745 | 319 | #define HIGH_EXC_VECTORS ((vm_address_t) 0xFFFF0000) |
5ba3f43e A |
320 | #endif |
321 | ||
d9a64523 A |
322 | /* |
323 | * TODO: We're hardcoding the expected virtual TEXT base here; | |
324 | * that gives us an ugly dependency on a linker argument in | |
325 | * the make files. Clean this up, so we don't hardcode it | |
326 | * twice; this is nothing but trouble. | |
327 | */ | |
328 | #if defined (__arm__) | |
329 | #define VM_KERNEL_LINK_ADDRESS ((vm_address_t) 0x80000000) | |
330 | #elif defined (__arm64__) | |
f427ee49 | 331 | /* VM_KERNEL_LINK_ADDRESS defined in makedefs/MakeInc.def for arm64 platforms */ |
d9a64523 A |
332 | #else |
333 | #error architecture not supported | |
334 | #endif | |
335 | ||
0a7de745 A |
336 | #endif /* MACH_KERNEL_PRIVATE */ |
337 | #endif /* KERNEL */ | |
5ba3f43e | 338 | |
0a7de745 | 339 | #endif /* !__ASSEMBLER__ */ |
5ba3f43e | 340 | |
0a7de745 | 341 | #define SWI_SYSCALL 0x80 |
5ba3f43e | 342 | |
0a7de745 | 343 | #endif /* _MACH_ARM_VM_PARAM_H_ */ |