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 36 #ifndef _MACH_ARM_VM_PARAM_H_ 37 #define _MACH_ARM_VM_PARAM_H_ 38 39 #if defined (__arm__) || defined (__arm64__) 40 41 #if defined(XNU_KERNEL_PRIVATE) && defined(__arm64__) 42 #include <arm64/proc_reg.h> 43 #endif 44 45 #if defined(KERNEL_PRIVATE) && __ARM_16K_PG__ 46 #include <arm64/proc_reg.h> 47 #endif 48 49 #if !defined (KERNEL) && !defined (__ASSEMBLER__) 50 #include <mach/vm_page_size.h> 51 #endif 52 53 #define BYTE_SIZE 8 /* byte size in bits */ 54 55 #if defined (KERNEL) 56 57 #ifndef __ASSEMBLER__ 58 59 #ifdef __arm__ 60 #define PAGE_SHIFT_CONST 12 61 #elif defined(__arm64__) 62 extern int PAGE_SHIFT_CONST; 63 #else 64 #error Unsupported arch 65 #endif 66 67 #if defined(KERNEL_PRIVATE) && __ARM_16K_PG__ 68 #define PAGE_SHIFT ARM_PGSHIFT 69 #else 70 #define PAGE_SHIFT PAGE_SHIFT_CONST 71 #endif 72 #define PAGE_SIZE (1 << PAGE_SHIFT) 73 #define PAGE_MASK (PAGE_SIZE-1) 74 75 #define VM_PAGE_SIZE PAGE_SIZE 76 77 #define machine_ptob(x) ((x) << PAGE_SHIFT) 78 79 /* 80 * Defined for the purpose of testing the pmap advertised page 81 * size; this does not necessarily match the hardware page size. 82 */ 83 #define TEST_PAGE_SIZE_16K ((PAGE_SHIFT_CONST == 14)) 84 #define TEST_PAGE_SIZE_4K ((PAGE_SHIFT_CONST == 12)) 85 86 #endif /* !__ASSEMBLER__ */ 87 88 #else 89 90 #define PAGE_SHIFT vm_page_shift 91 #define PAGE_SIZE vm_page_size 92 #define PAGE_MASK vm_page_mask 93 94 #define VM_PAGE_SIZE vm_page_size 95 96 #define machine_ptob(x) ((x) << PAGE_SHIFT) 97 98 #endif 99 100 #define PAGE_MAX_SHIFT 14 101 #define PAGE_MAX_SIZE (1 << PAGE_MAX_SHIFT) 102 #define PAGE_MAX_MASK (PAGE_MAX_SIZE-1) 103 104 #define PAGE_MIN_SHIFT 12 105 #define PAGE_MIN_SIZE (1 << PAGE_MIN_SHIFT) 106 #define PAGE_MIN_MASK (PAGE_MIN_SIZE-1) 107 108 #define VM_MAX_PAGE_ADDRESS MACH_VM_MAX_ADDRESS 109 110 #ifndef __ASSEMBLER__ 111 112 #ifdef MACH_KERNEL_PRIVATE 113 114 #define VM32_SUPPORT 1 115 #define VM32_MIN_ADDRESS ((vm32_offset_t) 0) 116 #define VM32_MAX_ADDRESS ((vm32_offset_t) (VM_MAX_ADDRESS & 0xFFFFFFFF)) 117 118 #endif /* MACH_KERNEL_PRIVATE */ 119 120 #if defined (__arm__) 121 122 #define VM_MIN_ADDRESS ((vm_address_t) 0x00000000) 123 #define VM_MAX_ADDRESS ((vm_address_t) 0x80000000) 124 125 /* system-wide values */ 126 #define MACH_VM_MIN_ADDRESS ((mach_vm_offset_t) 0) 127 #define MACH_VM_MAX_ADDRESS ((mach_vm_offset_t) VM_MAX_ADDRESS) 128 129 #elif defined (__arm64__) 130 131 #define VM_MIN_ADDRESS ((vm_address_t) 0x0000000000000000ULL) 132 #define VM_MAX_ADDRESS ((vm_address_t) 0x0000000080000000ULL) 133 134 /* system-wide values */ 135 #define MACH_VM_MIN_ADDRESS_RAW 0x0ULL 136 #if defined(PLATFORM_MacOSX) || defined(PLATFORM_DriverKit) 137 #define MACH_VM_MAX_ADDRESS_RAW 0x00007FFFFE000000ULL 138 #else 139 #define MACH_VM_MAX_ADDRESS_RAW 0x0000000FC0000000ULL 140 #endif 141 142 #define MACH_VM_MIN_ADDRESS ((mach_vm_offset_t) MACH_VM_MIN_ADDRESS_RAW) 143 #define MACH_VM_MAX_ADDRESS ((mach_vm_offset_t) MACH_VM_MAX_ADDRESS_RAW) 144 145 #define MACH_VM_MIN_GPU_CARVEOUT_ADDRESS_RAW 0x0000001000000000ULL 146 #define MACH_VM_MAX_GPU_CARVEOUT_ADDRESS_RAW 0x0000007000000000ULL 147 #define MACH_VM_MIN_GPU_CARVEOUT_ADDRESS ((mach_vm_offset_t) MACH_VM_MIN_GPU_CARVEOUT_ADDRESS_RAW) 148 #define MACH_VM_MAX_GPU_CARVEOUT_ADDRESS ((mach_vm_offset_t) MACH_VM_MAX_GPU_CARVEOUT_ADDRESS_RAW) 149 150 #else /* defined(__arm64__) */ 151 #error architecture not supported 152 #endif 153 154 #define VM_MAP_MIN_ADDRESS VM_MIN_ADDRESS 155 #define VM_MAP_MAX_ADDRESS VM_MAX_ADDRESS 156 157 #ifdef KERNEL 158 159 /* 160 * kalloc() parameters: 161 * 162 * Historically kalloc's underlying zones were power-of-2 sizes, with a 163 * KALLOC_MINSIZE of 16 bytes. Thus the allocator ensured that 164 * (sizeof == alignof) >= 16 for all kalloc allocations. 165 * 166 * Today kalloc may use zones with intermediate (small) sizes, constrained by 167 * KALLOC_MINSIZE and a minimum alignment, expressed by KALLOC_LOG2_MINALIGN. 168 * 169 * Note that most dynamically allocated data structures contain more than 170 * one int/long/pointer member, so KALLOC_MINSIZE should probably start at 8. 171 */ 172 173 #if defined (__arm__) 174 #define VM_KERNEL_POINTER_SIGNIFICANT_BITS 31 175 #define VM_MIN_KERNEL_ADDRESS ((vm_address_t) 0x80000000) 176 #define VM_MAX_KERNEL_ADDRESS ((vm_address_t) 0xFFFEFFFF) 177 #define VM_HIGH_KERNEL_WINDOW ((vm_address_t) 0xFFFE0000) 178 179 #if XNU_KERNEL_PRIVATE 180 #define KALLOC_MINSIZE 8 /* minimum allocation size */ 181 #define KALLOC_LOG2_MINALIGN 3 /* log2 minimum alignment */ 182 183 #define ZONE_MAP_MAX (1024 * 1024 * 1536) /* 1.5GB for 32bit systems */ 184 #endif 185 #elif defined (__arm64__) 186 /* 187 * The minimum and maximum kernel address; some configurations may 188 * constrain the address space further. 189 */ 190 #define TiB(x) ((0ULL + (x)) << 40) 191 #define GiB(x) ((0ULL + (x)) << 30) 192 193 #define KALLOC_MINSIZE 16 /* minimum allocation size */ 194 #define KALLOC_LOG2_MINALIGN 4 /* log2 minimum alignment */ 195 196 #if XNU_KERNEL_PRIVATE 197 #if defined(ARM_LARGE_MEMORY) 198 /* 199 * +-----------------------+--------+--------+------------------------+ 200 * | 0xffff_fe90_0000_0000 |-1472GB | 576GB | KASAN_SHADOW_MIN | 201 * | | | | VM_MAX_KERNEL_ADDRESS | 202 * +-----------------------+--------+--------+------------------------+ 203 * | 0xffff_fe10_0000_0000 |-1984GB | 64GB | PMAP_HEAP_RANGE_START | 204 * +-----------------------+--------+--------+------------------------+ 205 * | 0xffff_fe00_0700_4000 | | | VM_KERNEL_LINK_ADDRESS | 206 * +-----------------------+--------+--------+------------------------+ 207 * | 0xffff_fe00_0000_0000 | -2TB | 0GB | VM_MIN_KERNEL_ADDRESS | 208 * | | | | LOW_GLOBALS | 209 * +-----------------------+--------+--------+------------------------+ 210 */ 211 #define VM_KERNEL_POINTER_SIGNIFICANT_BITS 41 212 213 // Kernel VA space starts at -2TB 214 #define VM_MIN_KERNEL_ADDRESS ((vm_address_t) (0ULL - TiB(2))) 215 216 // 1.25TB for static_memory_region, 512GB for kernel heap, 256GB for KASAN 217 #define VM_MAX_KERNEL_ADDRESS ((vm_address_t) (VM_MIN_KERNEL_ADDRESS + GiB(64) + GiB(512) - 1)) 218 219 #define ZONE_MAP_MAX GiB(32) 220 #define ZONE_MAP_VA_SIZE_LP64 GiB(128) 221 #else // ARM_LARGE_MEMORY 222 /* 223 * +-----------------------+--------+--------+------------------------+ 224 * | 0xffff_fffc_0000_0000 | -16GB | 112GB | KASAN_SHADOW_MIN | 225 * | | | | VM_MAX_KERNEL_ADDRESS | 226 * +-----------------------+--------+--------+------------------------+ 227 * | 0xffff_fff0_0700_4000 | | | VM_KERNEL_LINK_ADDRESS | 228 * +-----------------------+--------+--------+------------------------+ 229 * | 0xffff_fff0_0000_0000 | -64GB | 64GB | LOW_GLOBALS | 230 * | | | | PMAP_HEAP_RANGE_START | <= H8 231 * +-----------------------+--------+--------+------------------------+ 232 * | 0xffff_ffe0_0000_0000 | -128GB | 0GB | VM_MIN_KERNEL_ADDRESS | 233 * | | | | PMAP_HEAP_RANGE_START | >= H9 234 * +-----------------------+--------+--------+------------------------+ 235 */ 236 #define VM_KERNEL_POINTER_SIGNIFICANT_BITS 37 237 #define VM_MIN_KERNEL_ADDRESS ((vm_address_t) 0xffffffe000000000ULL) 238 #define VM_MAX_KERNEL_ADDRESS ((vm_address_t) 0xfffffffbffffffffULL) 239 240 #define ZONE_MAP_MAX GiB(8) 241 #define ZONE_MAP_VA_SIZE_LP64 GiB(24) 242 #endif // ARM_LARGE_MEMORY 243 244 #else // !XNU_KERNEL_PRIVATE 245 // Inform kexts about largest possible kernel address space 246 #define VM_KERNEL_POINTER_SIGNIFICANT_BITS 41 247 #define VM_MIN_KERNEL_ADDRESS ((vm_address_t) (0ULL - TiB(2))) 248 #define VM_MAX_KERNEL_ADDRESS ((vm_address_t) 0xfffffffbffffffffULL) 249 #endif // XNU_KERNEL_PRIVATE 250 #else 251 #error architecture not supported 252 #endif 253 254 #define VM_MIN_KERNEL_AND_KEXT_ADDRESS VM_MIN_KERNEL_ADDRESS 255 256 #if defined (__arm64__) 257 /* Top-Byte-Ignore */ 258 #define TBI_MASK 0xff00000000000000ULL 259 #define tbi_clear(addr) ((typeof (addr))(((uintptr_t)(addr)) &~ (TBI_MASK))) 260 #define tbi_fill(addr) ((typeof (addr))(((uintptr_t)(addr)) | (TBI_MASK))) 261 #endif /* __arm64__ */ 262 263 #if CONFIG_KERNEL_TBI 264 /* 265 * 'strip' in PAC sense, therefore replacing the stripped bits sign extending 266 * the sign bit. 267 */ 268 #define VM_KERNEL_TBI_FILL(_v) (tbi_fill(_v)) 269 #define VM_KERNEL_TBI_CLEAR(_v) (tbi_clear(_v)) 270 #define VM_KERNEL_STRIP_TBI(_v) (VM_KERNEL_TBI_FILL(_v)) 271 #else /* CONFIG_KERNEL_TBI */ 272 #define VM_KERNEL_TBI_FILL(_v) (_v) 273 #define VM_KERNEL_TBI_CLEAR(_v) (_v) 274 #define VM_KERNEL_STRIP_TBI(_v) (_v) 275 #endif /* CONFIG_KERNE_TBI */ 276 277 #if __has_feature(ptrauth_calls) 278 #include <ptrauth.h> 279 #define VM_KERNEL_STRIP_PAC(_v) (ptrauth_strip((void *)(uintptr_t)(_v), ptrauth_key_asia)) 280 #else /* !ptrauth_calls */ 281 #define VM_KERNEL_STRIP_PAC(_v) (_v) 282 #endif /* ptrauth_calls */ 283 284 #define VM_KERNEL_STRIP_PTR(_va) ((VM_KERNEL_STRIP_TBI(VM_KERNEL_STRIP_PAC(_va)))) 285 #define VM_KERNEL_STRIP_UPTR(_va) ((vm_address_t)VM_KERNEL_STRIP_PTR((uintptr_t)(_va))) 286 #define VM_KERNEL_ADDRESS(_va) \ 287 ((VM_KERNEL_STRIP_UPTR(_va) >= VM_MIN_KERNEL_ADDRESS) && \ 288 (VM_KERNEL_STRIP_UPTR(_va) <= VM_MAX_KERNEL_ADDRESS)) 289 290 #ifdef MACH_KERNEL_PRIVATE 291 /* 292 * Physical memory is mapped linearly at an offset virtual memory. 293 */ 294 extern unsigned long gVirtBase, gPhysBase, gPhysSize; 295 296 #define isphysmem(a) (((vm_address_t)(a) - gPhysBase) < gPhysSize) 297 #define physmap_enclosed(a) isphysmem(a) 298 299 /* 300 * gPhysBase/Size only represent kernel-managed memory. These globals represent 301 * the actual DRAM base address and size as reported by iBoot through the device 302 * tree. 303 */ 304 #include <stdint.h> 305 extern uint64_t gDramBase, gDramSize; 306 #define is_dram_addr(addr) (((uint64_t)(addr) - gDramBase) < gDramSize) 307 308 #endif /* MACH_KERNEL_PRIVATE */ 309 310 #ifdef XNU_KERNEL_PRIVATE 311 312 #if KASAN 313 /* Increase the stack sizes to account for the redzones that get added to every 314 * stack object. */ 315 # define KERNEL_STACK_SIZE (4*4*4096) 316 #elif DEBUG 317 /** 318 * Increase the stack size to account for less efficient use of stack space when 319 * compiling with -O0. 320 */ 321 # define KERNEL_STACK_SIZE (2*4*4096) 322 #else 323 /* 324 * KERNEL_STACK_MULTIPLIER can be defined externally to get a larger 325 * kernel stack size. For example, adding "-DKERNEL_STACK_MULTIPLIER=2" 326 * helps avoid kernel stack overflows when compiling with "-O0". 327 */ 328 #ifndef KERNEL_STACK_MULTIPLIER 329 #define KERNEL_STACK_MULTIPLIER (1) 330 #endif /* KERNEL_STACK_MULTIPLIER */ 331 # define KERNEL_STACK_SIZE (4*4096*KERNEL_STACK_MULTIPLIER) 332 #endif /* XNU_KERNEL_PRIVATE */ 333 334 #define INTSTACK_SIZE (4*4096) 335 336 #ifdef __arm64__ 337 #define EXCEPSTACK_SIZE (4*4096) 338 #else 339 #define FIQSTACK_SIZE (4096) 340 #endif 341 342 #if defined (__arm__) 343 #define HIGH_EXC_VECTORS ((vm_address_t) 0xFFFF0000) 344 #endif 345 346 /* 347 * TODO: We're hardcoding the expected virtual TEXT base here; 348 * that gives us an ugly dependency on a linker argument in 349 * the make files. Clean this up, so we don't hardcode it 350 * twice; this is nothing but trouble. 351 */ 352 #if defined (__arm__) 353 #define VM_KERNEL_LINK_ADDRESS ((vm_address_t) 0x80000000) 354 #elif defined (__arm64__) 355 /* VM_KERNEL_LINK_ADDRESS defined in makedefs/MakeInc.def for arm64 platforms */ 356 #else 357 #error architecture not supported 358 #endif 359 360 #endif /* MACH_KERNEL_PRIVATE */ 361 #endif /* KERNEL */ 362 363 #endif /* !__ASSEMBLER__ */ 364 365 #define SWI_SYSCALL 0x80 366 367 #endif /* defined (__arm__) || defined (__arm64__) */ 368 369 #endif /* _MACH_ARM_VM_PARAM_H_ */ 370