]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/mach/arm/vm_param.h
c9d7b44f1dde58fcba13f79165aedd960a261456
2 * Copyright (c) 2007 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
33 * ARM machine dependent virtual memory parameters.
36 #ifndef _MACH_ARM_VM_PARAM_H_
37 #define _MACH_ARM_VM_PARAM_H_
39 #if defined(KERNEL_PRIVATE) && __ARM_16K_PG__
40 #include <arm64/proc_reg.h>
43 #if !defined (KERNEL) && !defined (__ASSEMBLER__)
44 #include <mach/vm_page_size.h>
47 #define BYTE_SIZE 8 /* byte size in bits */
54 #define PAGE_SHIFT_CONST 12
55 #elif defined(__arm64__)
56 extern int PAGE_SHIFT_CONST
;
58 #error Unsupported arch
61 #if defined(KERNEL_PRIVATE) && __ARM_16K_PG__
62 #define PAGE_SHIFT ARM_PGSHIFT
64 #define PAGE_SHIFT PAGE_SHIFT_CONST
66 #define PAGE_SIZE (1 << PAGE_SHIFT)
67 #define PAGE_MASK (PAGE_SIZE-1)
69 #define VM_PAGE_SIZE PAGE_SIZE
71 #define machine_ptob(x) ((x) << PAGE_SHIFT)
74 * Defined for the purpose of testing the pmap advertised page
75 * size; this does not necessarily match the hardware page size.
77 #define TEST_PAGE_SIZE_16K ((PAGE_SHIFT_CONST == 14))
78 #define TEST_PAGE_SIZE_4K ((PAGE_SHIFT_CONST == 12))
80 #endif /* !__ASSEMBLER__ */
84 #define PAGE_SHIFT vm_page_shift
85 #define PAGE_SIZE vm_page_size
86 #define PAGE_MASK vm_page_mask
88 #define VM_PAGE_SIZE vm_page_size
90 #define machine_ptob(x) ((x) << PAGE_SHIFT)
94 #define PAGE_MAX_SHIFT 14
95 #define PAGE_MAX_SIZE (1 << PAGE_MAX_SHIFT)
96 #define PAGE_MAX_MASK (PAGE_MAX_SIZE-1)
98 #define PAGE_MIN_SHIFT 12
99 #define PAGE_MIN_SIZE (1 << PAGE_MIN_SHIFT)
100 #define PAGE_MIN_MASK (PAGE_MIN_SIZE-1)
102 #define VM_MAX_PAGE_ADDRESS MACH_VM_MAX_ADDRESS
104 #ifndef __ASSEMBLER__
106 #ifdef MACH_KERNEL_PRIVATE
108 #define VM32_SUPPORT 1
109 #define VM32_MIN_ADDRESS ((vm32_offset_t) 0)
110 #define VM32_MAX_ADDRESS ((vm32_offset_t) (VM_MAX_ADDRESS & 0xFFFFFFFF))
113 * kalloc() parameters:
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.
119 * Today kalloc may use zones with intermediate (small) sizes, constrained by
120 * KALLOC_MINSIZE and a minimum alignment, expressed by KALLOC_LOG2_MINALIGN.
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.
126 #if defined (__arm__)
128 #define KALLOC_MINSIZE 8 /* minimum allocation size */
129 #define KALLOC_LOG2_MINALIGN 3 /* log2 minimum alignment */
131 #elif defined(__arm64__)
133 #define KALLOC_MINSIZE 16 /* minimum allocation size */
134 #define KALLOC_LOG2_MINALIGN 4 /* log2 minimum alignment */
137 #error Unsupported arch
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__)
145 * Limits the physical pages in the zone map
147 #define ZONE_MAP_MAX (31ULL << 30) /* 31GB for 64bit systems */
149 #error Unsupported arch
154 #if defined (__arm__)
156 #define VM_MIN_ADDRESS ((vm_address_t) 0x00000000)
157 #define VM_MAX_ADDRESS ((vm_address_t) 0x80000000)
159 /* system-wide values */
160 #define MACH_VM_MIN_ADDRESS ((mach_vm_offset_t) 0)
161 #define MACH_VM_MAX_ADDRESS ((mach_vm_offset_t) VM_MAX_ADDRESS)
163 #elif defined (__arm64__)
165 #define VM_MIN_ADDRESS ((vm_address_t) 0x0000000000000000ULL)
166 #define VM_MAX_ADDRESS ((vm_address_t) 0x0000000080000000ULL)
168 /* system-wide values */
169 #define MACH_VM_MIN_ADDRESS_RAW 0x0ULL
170 #if defined(PLATFORM_MacOSX) || defined(PLATFORM_DriverKit)
171 #define MACH_VM_MAX_ADDRESS_RAW 0x00007FFFFE000000ULL
173 #define MACH_VM_MAX_ADDRESS_RAW 0x0000000FC0000000ULL
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)
180 #else /* defined(__arm64__) */
181 #error architecture not supported
184 #define VM_MAP_MIN_ADDRESS VM_MIN_ADDRESS
185 #define VM_MAP_MAX_ADDRESS VM_MAX_ADDRESS
189 #if defined (__arm__)
190 #define VM_KERNEL_POINTER_SIGNIFICANT_BITS 31
191 #define VM_MIN_KERNEL_ADDRESS ((vm_address_t) 0x80000000)
192 #define VM_MAX_KERNEL_ADDRESS ((vm_address_t) 0xFFFEFFFF)
193 #define VM_HIGH_KERNEL_WINDOW ((vm_address_t) 0xFFFE0000)
194 #elif defined (__arm64__)
196 * The minimum and maximum kernel address; some configurations may
197 * constrain the address space further.
199 #define TiB(x) ((0ULL + (x)) << 40)
200 #define GiB(x) ((0ULL + (x)) << 30)
202 #if XNU_KERNEL_PRIVATE
203 #if defined(ARM_LARGE_MEMORY)
205 * +-----------------------+--------+--------+------------------------+
206 * | 0xffff_fe90_0000_0000 |-1472GB | 576GB | KASAN_SHADOW_MIN |
207 * | | | | VM_MAX_KERNEL_ADDRESS |
208 * +-----------------------+--------+--------+------------------------+
209 * | 0xffff_fe10_0000_0000 |-1984GB | 64GB | PMAP_HEAP_RANGE_START |
210 * +-----------------------+--------+--------+------------------------+
211 * | 0xffff_fe00_0700_4000 | | | VM_KERNEL_LINK_ADDRESS |
212 * +-----------------------+--------+--------+------------------------+
213 * | 0xffff_fe00_0000_0000 | -2TB | 0GB | VM_MIN_KERNEL_ADDRESS |
214 * | | | | LOW_GLOBALS |
215 * +-----------------------+--------+--------+------------------------+
217 #define VM_KERNEL_POINTER_SIGNIFICANT_BITS 41
219 // Kernel VA space starts at -2TB
220 #define VM_MIN_KERNEL_ADDRESS ((vm_address_t) (0ULL - TiB(2)))
222 // 1.25TB for static_memory_region, 512GB for kernel heap, 256GB for KASAN
223 #define VM_MAX_KERNEL_ADDRESS ((vm_address_t) (VM_MIN_KERNEL_ADDRESS + GiB(64) + GiB(512) - 1))
224 #else // ARM_LARGE_MEMORY
226 * +-----------------------+--------+--------+------------------------+
227 * | 0xffff_fffc_0000_0000 | -16GB | 112GB | KASAN_SHADOW_MIN |
228 * | | | | VM_MAX_KERNEL_ADDRESS |
229 * +-----------------------+--------+--------+------------------------+
230 * | 0xffff_fff0_0700_4000 | | | VM_KERNEL_LINK_ADDRESS |
231 * +-----------------------+--------+--------+------------------------+
232 * | 0xffff_fff0_0000_0000 | -64GB | 64GB | LOW_GLOBALS |
233 * | | | | PMAP_HEAP_RANGE_START | <= H8
234 * +-----------------------+--------+--------+------------------------+
235 * | 0xffff_ffe0_0000_0000 | -128GB | 0GB | VM_MIN_KERNEL_ADDRESS |
236 * | | | | PMAP_HEAP_RANGE_START | >= H9
237 * +-----------------------+--------+--------+------------------------+
239 #define VM_KERNEL_POINTER_SIGNIFICANT_BITS 37
240 #define VM_MIN_KERNEL_ADDRESS ((vm_address_t) 0xffffffe000000000ULL)
241 #define VM_MAX_KERNEL_ADDRESS ((vm_address_t) 0xfffffffbffffffffULL)
242 #endif // ARM_LARGE_MEMORY
244 #else // !XNU_KERNEL_PRIVATE
245 // Inform kexts about largest possible kernel address space
246 #define VM_MIN_KERNEL_ADDRESS ((vm_address_t) (0ULL - TiB(2)))
247 #define VM_MAX_KERNEL_ADDRESS ((vm_address_t) 0xfffffffbffffffffULL)
248 #endif // XNU_KERNEL_PRIVATE
250 #error architecture not supported
253 #define VM_MIN_KERNEL_AND_KEXT_ADDRESS VM_MIN_KERNEL_ADDRESS
255 #if __has_feature(ptrauth_calls)
257 #define VM_KERNEL_STRIP_PTR(_v) (ptrauth_strip((void *)(uintptr_t)(_v), ptrauth_key_asia))
258 #else /* !ptrauth_calls */
259 #define VM_KERNEL_STRIP_PTR(_v) (_v)
260 #endif /* ptrauth_calls */
262 #define VM_KERNEL_ADDRESS(_va) \
263 ((((vm_address_t)VM_KERNEL_STRIP_PTR(_va)) >= VM_MIN_KERNEL_ADDRESS) && \
264 (((vm_address_t)VM_KERNEL_STRIP_PTR(_va)) <= VM_MAX_KERNEL_ADDRESS))
266 #ifdef MACH_KERNEL_PRIVATE
268 * Physical memory is mapped linearly at an offset virtual memory.
270 extern unsigned long gVirtBase
, gPhysBase
, gPhysSize
;
272 #define isphysmem(a) (((vm_address_t)(a) - gPhysBase) < gPhysSize)
273 #define physmap_enclosed(a) isphysmem(a)
276 * gPhysBase/Size only represent kernel-managed memory. These globals represent
277 * the actual DRAM base address and size as reported by iBoot through the device
281 extern uint64_t gDramBase
, gDramSize
;
282 #define is_dram_addr(addr) (((uint64_t)(addr) - gDramBase) < gDramSize)
285 /* Increase the stack sizes to account for the redzones that get added to every
287 # define KERNEL_STACK_SIZE (4*4*4096)
290 * Increase the stack size to account for less efficient use of stack space when
291 * compiling with -O0.
293 # define KERNEL_STACK_SIZE (2*4*4096)
296 * KERNEL_STACK_MULTIPLIER can be defined externally to get a larger
297 * kernel stack size. For example, adding "-DKERNEL_STACK_MULTIPLIER=2"
298 * helps avoid kernel stack overflows when compiling with "-O0".
300 #ifndef KERNEL_STACK_MULTIPLIER
301 #define KERNEL_STACK_MULTIPLIER (1)
302 #endif /* KERNEL_STACK_MULTIPLIER */
303 # define KERNEL_STACK_SIZE (4*4096*KERNEL_STACK_MULTIPLIER)
306 #define INTSTACK_SIZE (4*4096)
309 #define EXCEPSTACK_SIZE (4*4096)
311 #define FIQSTACK_SIZE (4096)
314 #if defined (__arm__)
315 #define HIGH_EXC_VECTORS ((vm_address_t) 0xFFFF0000)
319 * TODO: We're hardcoding the expected virtual TEXT base here;
320 * that gives us an ugly dependency on a linker argument in
321 * the make files. Clean this up, so we don't hardcode it
322 * twice; this is nothing but trouble.
324 #if defined (__arm__)
325 #define VM_KERNEL_LINK_ADDRESS ((vm_address_t) 0x80000000)
326 #elif defined (__arm64__)
327 /* VM_KERNEL_LINK_ADDRESS defined in makedefs/MakeInc.def for arm64 platforms */
329 #error architecture not supported
332 #endif /* MACH_KERNEL_PRIVATE */
335 #endif /* !__ASSEMBLER__ */
337 #define SWI_SYSCALL 0x80
339 #endif /* _MACH_ARM_VM_PARAM_H_ */