]>
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 | */ | |
0a7de745 | 28 | #ifdef PRIVATE |
5ba3f43e A |
29 | |
30 | #ifndef _ARM_CPU_CAPABILITIES_H | |
31 | #define _ARM_CPU_CAPABILITIES_H | |
32 | ||
0a7de745 | 33 | #ifndef __ASSEMBLER__ |
5ba3f43e | 34 | #include <stdint.h> |
5ba3f43e A |
35 | #include <mach/vm_types.h> |
36 | #endif | |
0a7de745 | 37 | |
f427ee49 | 38 | |
cb323159 A |
39 | #define USER_TIMEBASE_NONE 0 |
40 | #define USER_TIMEBASE_SPEC 1 | |
41 | ||
5ba3f43e A |
42 | /* |
43 | * This is the authoritative way to determine from user mode what | |
44 | * implementation-specific processor features are available. | |
45 | * This API only supported for Apple internal use. | |
0a7de745 | 46 | * |
5ba3f43e A |
47 | */ |
48 | ||
49 | /* | |
50 | * Bit definitions for _cpu_capabilities: | |
51 | */ | |
0a7de745 A |
52 | #define kHasNeonFP16 0x00000008 // ARM v8.2 NEON FP16 supported |
53 | #define kCache32 0x00000010 // cache line size is 32 bytes | |
54 | #define kCache64 0x00000020 // cache line size is 64 bytes | |
55 | #define kCache128 0x00000040 // cache line size is 128 bytes | |
56 | #define kFastThreadLocalStorage 0x00000080 // TLS ptr is kept in a user-mode-readable register | |
57 | #define kHasNeon 0x00000100 // Advanced SIMD is supported | |
58 | #define kHasNeonHPFP 0x00000200 // Advanced SIMD half-precision | |
59 | #define kHasVfp 0x00000400 // VFP is supported | |
cb323159 | 60 | #define kHasUCNormalMemory 0x00000800 // Uncacheable normal memory type supported |
0a7de745 A |
61 | #define kHasEvent 0x00001000 // WFE/SVE and period event wakeup |
62 | #define kHasFMA 0x00002000 // Fused multiply add is supported | |
cb323159 | 63 | #define kHasARMv82FHM 0x00004000 // Optional ARMv8.2 FMLAL/FMLSL instructions (required in ARMv8.4) |
0a7de745 A |
64 | #define kUP 0x00008000 // set if (kNumCPUs == 1) |
65 | #define kNumCPUs 0x00FF0000 // number of CPUs (see _NumCPUs() below) | |
66 | #define kHasARMv8Crypto 0x01000000 // Optional ARMv8 Crypto extensions | |
67 | #define kHasARMv81Atomics 0x02000000 // ARMv8.1 Atomic instructions supported | |
68 | #define kHasARMv8Crc32 0x04000000 // Optional ARMv8 crc32 instructions (required in ARMv8.1) | |
f427ee49 A |
69 | #define kHasARMv82SHA512 0x80000000 // Optional ARMv8.2 SHA512 instructions |
70 | /* Extending into 64-bits from here: */ | |
71 | #define kHasARMv82SHA3 0x0000000100000000 // Optional ARMv8.2 SHA3 instructions | |
0a7de745 | 72 | |
cb323159 | 73 | #define kNumCPUsShift 16 // see _NumCPUs() below |
0a7de745 A |
74 | /* |
75 | * Bit definitions for multiuser_config: | |
76 | */ | |
77 | #define kIsMultiUserDevice 0x80000000 // this device is in multiuser mode | |
78 | #define kMultiUserCurrentUserMask 0x7fffffff // the current user UID of the multiuser device | |
79 | ||
80 | #ifndef __ASSEMBLER__ | |
5ba3f43e A |
81 | #include <sys/commpage.h> |
82 | ||
cb323159 | 83 | __BEGIN_DECLS |
f427ee49 | 84 | extern uint64_t _get_cpu_capabilities( void ); |
cb323159 | 85 | __END_DECLS |
5ba3f43e A |
86 | |
87 | __inline static | |
0a7de745 A |
88 | int |
89 | _NumCPUs( void ) | |
5ba3f43e A |
90 | { |
91 | return (_get_cpu_capabilities() & kNumCPUs) >> kNumCPUsShift; | |
92 | } | |
93 | ||
cb323159 | 94 | |
5ba3f43e A |
95 | typedef struct { |
96 | volatile uint64_t TimeBase; | |
97 | volatile uint32_t TimeStamp_sec; | |
98 | volatile uint32_t TimeStamp_usec; | |
99 | volatile uint32_t TimeBaseTicks_per_sec; | |
100 | volatile uint32_t TimeBaseTicks_per_usec; | |
0a7de745 A |
101 | volatile uint64_t TimeBase_magic; |
102 | volatile uint32_t TimeBase_add; | |
103 | volatile uint32_t TimeBase_shift; | |
5ba3f43e A |
104 | } commpage_timeofday_data_t; |
105 | ||
cb323159 | 106 | __BEGIN_DECLS |
0a7de745 | 107 | extern vm_address_t _get_commpage_priv_address(void); |
f427ee49 | 108 | extern vm_address_t _get_commpage_text_priv_address(void); |
cb323159 | 109 | __END_DECLS |
d9a64523 | 110 | |
5ba3f43e A |
111 | #endif /* __ASSEMBLER__ */ |
112 | ||
113 | ||
114 | /* | |
115 | * The shared kernel/user "comm page(s)": | |
116 | */ | |
117 | ||
d9a64523 | 118 | #if defined(__LP64__) |
5ba3f43e | 119 | |
0a7de745 | 120 | #define _COMM_PAGE64_BASE_ADDRESS (0x0000000FFFFFC000ULL) /* In TTBR0 */ |
f427ee49 A |
121 | #if defined(ARM_LARGE_MEMORY) |
122 | #define _COMM_HIGH_PAGE64_BASE_ADDRESS (0xFFFFFE00001FC000ULL) /* Just below the kernel, safely in TTBR1; only used for testing */ | |
123 | #else | |
0a7de745 | 124 | #define _COMM_HIGH_PAGE64_BASE_ADDRESS (0xFFFFFFF0001FC000ULL) /* Just below the kernel, safely in TTBR1; only used for testing */ |
f427ee49 | 125 | #endif |
5ba3f43e | 126 | |
0a7de745 A |
127 | #define _COMM_PAGE64_AREA_LENGTH (_COMM_PAGE32_AREA_LENGTH) |
128 | #define _COMM_PAGE64_AREA_USED (-1) | |
5ba3f43e | 129 | |
0a7de745 | 130 | #define _COMM_PAGE_PRIV(_addr_) ((_addr_) - (_COMM_PAGE_START_ADDRESS) + _get_commpage_priv_address()) |
5ba3f43e A |
131 | |
132 | #ifdef KERNEL_PRIVATE | |
0a7de745 A |
133 | #define _COMM_PAGE_RW_OFFSET (0) |
134 | #define _COMM_PAGE_AREA_LENGTH (PAGE_SIZE) | |
5ba3f43e | 135 | |
0a7de745 A |
136 | #define _COMM_PAGE_BASE_ADDRESS (_get_commpage_priv_address()) |
137 | #define _COMM_PAGE_START_ADDRESS (_get_commpage_priv_address()) | |
f427ee49 A |
138 | |
139 | /** | |
140 | * This represents the size of the memory region that the commpage is nested in. | |
141 | * On 4K page systems, this is 1GB, and on 16KB page systems this is technically | |
142 | * only 32MB, but to keep consistency across address spaces we always reserve | |
143 | * 1GB for the commpage on ARM devices. | |
144 | * | |
145 | * The commpage itself only takes up a single page, but its page tables are | |
146 | * being shared across every user process. Entries should not be allowed to | |
147 | * be created in those shared tables, which is why the VM uses these values to | |
148 | * reserve the entire nesting region in every user process address space. | |
149 | * | |
150 | * If the commpage base address changes, these values might also need to be | |
151 | * updated. | |
152 | */ | |
153 | #define _COMM_PAGE64_NESTING_START (0x0000000FC0000000ULL) | |
154 | #define _COMM_PAGE64_NESTING_SIZE (0x40000000ULL) /* 1GiB */ | |
155 | _Static_assert((_COMM_PAGE64_BASE_ADDRESS >= _COMM_PAGE64_NESTING_START) && | |
156 | (_COMM_PAGE64_BASE_ADDRESS < (_COMM_PAGE64_NESTING_START + _COMM_PAGE64_NESTING_SIZE)), | |
157 | "_COMM_PAGE64_BASE_ADDRESS is not within the nesting region. Commpage nesting " | |
158 | "region probably needs to be updated."); | |
159 | ||
5c9f4661 | 160 | #else /* KERNEL_PRIVATE */ |
0a7de745 | 161 | #define _COMM_PAGE_AREA_LENGTH (4096) |
5ba3f43e | 162 | |
0a7de745 A |
163 | #define _COMM_PAGE_BASE_ADDRESS _COMM_PAGE64_BASE_ADDRESS |
164 | #define _COMM_PAGE_START_ADDRESS _COMM_PAGE64_BASE_ADDRESS | |
5c9f4661 | 165 | #endif /* KERNEL_PRIVATE */ |
5ba3f43e | 166 | |
f427ee49 | 167 | #else /* __LP64__ */ |
5ba3f43e | 168 | |
0a7de745 A |
169 | #define _COMM_PAGE64_BASE_ADDRESS (-1) |
170 | #define _COMM_PAGE64_AREA_LENGTH (-1) | |
171 | #define _COMM_PAGE64_AREA_USED (-1) | |
5ba3f43e A |
172 | |
173 | // macro to change a user comm page address to one that is accessible from privileged mode | |
174 | // this macro is stubbed as PAN is not available on AARCH32, | |
175 | // but this may still be required for compatibility | |
0a7de745 | 176 | #define _COMM_PAGE_PRIV(_addr_) (_addr_) |
5ba3f43e A |
177 | |
178 | #ifdef KERNEL_PRIVATE | |
0a7de745 A |
179 | #define _COMM_PAGE_RW_OFFSET (_get_commpage_priv_address()-_COMM_PAGE_BASE_ADDRESS) |
180 | #define _COMM_PAGE_AREA_LENGTH (PAGE_SIZE) | |
f427ee49 | 181 | #else /* KERNEL_PRIVATE */ |
0a7de745 | 182 | #define _COMM_PAGE_AREA_LENGTH (4096) |
f427ee49 | 183 | #endif /* KERNEL_PRIVATE */ |
5ba3f43e | 184 | |
0a7de745 A |
185 | #define _COMM_PAGE_BASE_ADDRESS _COMM_PAGE32_BASE_ADDRESS |
186 | #define _COMM_PAGE_START_ADDRESS _COMM_PAGE32_BASE_ADDRESS | |
5ba3f43e | 187 | |
f427ee49 | 188 | #endif /* __LP64__ */ |
5ba3f43e | 189 | |
0a7de745 A |
190 | #define _COMM_PAGE32_BASE_ADDRESS (0xFFFF4000) /* Must be outside of normal map bounds */ |
191 | #define _COMM_PAGE32_AREA_LENGTH (_COMM_PAGE_AREA_LENGTH) | |
0a7de745 | 192 | #define _COMM_PAGE32_TEXT_START (-1) |
5ba3f43e | 193 | |
0a7de745 A |
194 | #define _COMM_PAGE32_OBJC_SIZE 0ULL |
195 | #define _COMM_PAGE32_OBJC_BASE 0ULL | |
196 | #define _COMM_PAGE64_OBJC_SIZE 0ULL | |
197 | #define _COMM_PAGE64_OBJC_BASE 0ULL | |
5ba3f43e | 198 | |
5ba3f43e A |
199 | /* |
200 | * data in the comm pages | |
201 | * apply _COMM_PAGE_PRIV macro to use these in privileged mode | |
202 | */ | |
0a7de745 | 203 | #define _COMM_PAGE_SIGNATURE (_COMM_PAGE_START_ADDRESS+0x000) // first few bytes are a signature |
cb323159 | 204 | #define _COMM_PAGE_SIGNATURELEN (0x10) |
f427ee49 A |
205 | #define _COMM_PAGE_CPU_CAPABILITIES64 (_COMM_PAGE_START_ADDRESS+0x010) /* uint64_t _cpu_capabilities */ |
206 | #define _COMM_PAGE_UNUSED (_COMM_PAGE_START_ADDRESS+0x018) /* 6 unused bytes */ | |
0a7de745 A |
207 | #define _COMM_PAGE_VERSION (_COMM_PAGE_START_ADDRESS+0x01E) // 16-bit version# |
208 | #define _COMM_PAGE_THIS_VERSION 3 // version of the commarea format | |
209 | ||
210 | #define _COMM_PAGE_CPU_CAPABILITIES (_COMM_PAGE_START_ADDRESS+0x020) // uint32_t _cpu_capabilities | |
211 | #define _COMM_PAGE_NCPUS (_COMM_PAGE_START_ADDRESS+0x022) // uint8_t number of configured CPUs | |
212 | #define _COMM_PAGE_USER_PAGE_SHIFT_32 (_COMM_PAGE_START_ADDRESS+0x024) // VM page shift for 32-bit processes | |
213 | #define _COMM_PAGE_USER_PAGE_SHIFT_64 (_COMM_PAGE_START_ADDRESS+0x025) // VM page shift for 64-bit processes | |
214 | #define _COMM_PAGE_CACHE_LINESIZE (_COMM_PAGE_START_ADDRESS+0x026) // uint16_t cache line size | |
f427ee49 A |
215 | #define _COMM_PAGE_UNUSED4 (_COMM_PAGE_START_ADDRESS+0x028) // used to be _COMM_PAGE_SCHED_GEN: uint32_t scheduler generation number (count of pre-emptions) |
216 | #define _COMM_PAGE_UNUSED3 (_COMM_PAGE_START_ADDRESS+0x02C) // used to be _COMM_PAGE_SPIN_COUNT: uint32_t max spin count for mutex's | |
0a7de745 A |
217 | #define _COMM_PAGE_MEMORY_PRESSURE (_COMM_PAGE_START_ADDRESS+0x030) // uint32_t copy of vm_memory_pressure |
218 | #define _COMM_PAGE_ACTIVE_CPUS (_COMM_PAGE_START_ADDRESS+0x034) // uint8_t number of active CPUs (hw.activecpu) | |
219 | #define _COMM_PAGE_PHYSICAL_CPUS (_COMM_PAGE_START_ADDRESS+0x035) // uint8_t number of physical CPUs (hw.physicalcpu_max) | |
220 | #define _COMM_PAGE_LOGICAL_CPUS (_COMM_PAGE_START_ADDRESS+0x036) // uint8_t number of logical CPUs (hw.logicalcpu_max) | |
221 | #define _COMM_PAGE_KERNEL_PAGE_SHIFT (_COMM_PAGE_START_ADDRESS+0x037) // uint8_t kernel vm page shift */ | |
222 | #define _COMM_PAGE_MEMORY_SIZE (_COMM_PAGE_START_ADDRESS+0x038) // uint64_t max memory size */ | |
223 | #define _COMM_PAGE_TIMEOFDAY_DATA (_COMM_PAGE_START_ADDRESS+0x040) // used by gettimeofday(). Currently, sizeof(commpage_timeofday_data_t) = 40. A new struct is used on gettimeofday but space is reserved on the commpage for compatibility | |
224 | #define _COMM_PAGE_CPUFAMILY (_COMM_PAGE_START_ADDRESS+0x080) // used by memcpy() resolver | |
225 | #define _COMM_PAGE_DEV_FIRM (_COMM_PAGE_START_ADDRESS+0x084) // uint32_t handle on PE_i_can_has_debugger | |
226 | #define _COMM_PAGE_TIMEBASE_OFFSET (_COMM_PAGE_START_ADDRESS+0x088) // uint64_t timebase offset for constructing mach_absolute_time() | |
227 | #define _COMM_PAGE_USER_TIMEBASE (_COMM_PAGE_START_ADDRESS+0x090) // uint8_t is userspace mach_absolute_time supported (can read the timebase) | |
228 | #define _COMM_PAGE_CONT_HWCLOCK (_COMM_PAGE_START_ADDRESS+0x091) // uint8_t is always-on hardware clock present for mach_continuous_time() | |
cb323159 A |
229 | #define _COMM_PAGE_DTRACE_DOF_ENABLED (_COMM_PAGE_START_ADDRESS+0x092) // uint8_t 0 if userspace DOF disable, 1 if enabled |
230 | #define _COMM_PAGE_UNUSED0 (_COMM_PAGE_START_ADDRESS+0x093) // 5 unused bytes | |
f427ee49 | 231 | #define _COMM_PAGE_CONT_TIMEBASE (_COMM_PAGE_START_ADDRESS+0x098) // uint64_t base for mach_continuous_time() relative to mach_absolute_time() |
0a7de745 | 232 | #define _COMM_PAGE_BOOTTIME_USEC (_COMM_PAGE_START_ADDRESS+0x0A0) // uint64_t boottime in microseconds |
f427ee49 | 233 | #define _COMM_PAGE_CONT_HW_TIMEBASE (_COMM_PAGE_START_ADDRESS+0x0A8) // uint64_t base for mach_continuous_time() relative to CNT[PV]CT |
5ba3f43e A |
234 | |
235 | // aligning to 64byte for cacheline size | |
0a7de745 A |
236 | #define _COMM_PAGE_APPROX_TIME (_COMM_PAGE_START_ADDRESS+0x0C0) // uint64_t last known mach_absolute_time() |
237 | #define _COMM_PAGE_APPROX_TIME_SUPPORTED (_COMM_PAGE_START_ADDRESS+0x0C8) // uint8_t is mach_approximate_time supported | |
238 | #define _COMM_PAGE_UNUSED1 (_COMM_PAGE_START_ADDRESS+0x0C9) // 55 unused bytes, align next mutable value to a separate cache line | |
5ba3f43e | 239 | |
0a7de745 A |
240 | #define _COMM_PAGE_KDEBUG_ENABLE (_COMM_PAGE_START_ADDRESS+0x100) // uint32_t export kdebug status bits to userspace |
241 | #define _COMM_PAGE_ATM_DIAGNOSTIC_CONFIG (_COMM_PAGE_START_ADDRESS+0x104) // uint32_t export "atm_diagnostic_config" to userspace | |
242 | #define _COMM_PAGE_MULTIUSER_CONFIG (_COMM_PAGE_START_ADDRESS+0x108) // uint32_t export "multiuser_config" to userspace | |
5ba3f43e A |
243 | |
244 | ||
0a7de745 A |
245 | #define _COMM_PAGE_NEWTIMEOFDAY_DATA (_COMM_PAGE_START_ADDRESS+0x120) // used by gettimeofday(). Currently, sizeof(new_commpage_timeofday_data_t) = 40. |
246 | #define _COMM_PAGE_REMOTETIME_PARAMS (_COMM_PAGE_START_ADDRESS+0x148) // used by mach_bridge_remote_time(). Currently, sizeof(struct bt_params) = 24 | |
f427ee49 | 247 | #define _COMM_PAGE_DYLD_FLAGS (_COMM_PAGE_START_ADDRESS+0x160) // uint64_t export kern.dyld_system_flags to userspace |
d26ffc64 | 248 | |
d9a64523 A |
249 | // aligning to 128 bytes for cacheline/fabric size |
250 | #define _COMM_PAGE_CPU_QUIESCENT_COUNTER (_COMM_PAGE_START_ADDRESS+0x180) // uint64_t, but reserve the whole 128 (0x80) bytes | |
251 | ||
f427ee49 A |
252 | #define _COMM_PAGE_END (_COMM_PAGE_START_ADDRESS+0xfff) // end of common page |
253 | ||
254 | #if defined(__LP64__) | |
255 | #if KERNEL_PRIVATE | |
256 | #define _COMM_PAGE64_TEXT_START_ADDRESS (_get_commpage_text_priv_address()) // Address through physical aperture | |
257 | #endif | |
258 | /* Offset in bytes from start of text comm page to get to these functions. Start | |
259 | * address to text comm page is from apple array */ | |
260 | #define _COMM_PAGE_TEXT_ATOMIC_ENQUEUE (0x0) | |
261 | #define _COMM_PAGE_TEXT_ATOMIC_DEQUEUE (0x4) | |
262 | ||
263 | #else /* __LP64__ */ | |
264 | /* No 32 bit text region */ | |
265 | #endif /* __LP64__ */ | |
5ba3f43e A |
266 | |
267 | #endif /* _ARM_CPU_CAPABILITIES_H */ | |
268 | #endif /* PRIVATE */ |