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@
30 #ifndef _ARM_CPU_CAPABILITIES_H
31 #define _ARM_CPU_CAPABILITIES_H
36 #include <mach/vm_types.h>
41 * This is the authoritative way to determine from user mode what
42 * implementation-specific processor features are available.
43 * This API only supported for Apple internal use.
48 * Bit definitions for _cpu_capabilities:
50 #define kCache32 0x00000010 // cache line size is 32 bytes
51 #define kCache64 0x00000020 // cache line size is 64 bytes
52 #define kCache128 0x00000040 // cache line size is 128 bytes
53 #define kFastThreadLocalStorage 0x00000080 // TLS ptr is kept in a user-mode-readable register
54 #define kHasNeon 0x00000100 // Advanced SIMD is supported
55 #define kHasNeonHPFP 0x00000200 // Advanced SIMD half-precision
56 #define kHasVfp 0x00000400 // VFP is supported
57 #define kHasEvent 0x00001000 // WFE/SVE and period event wakeup
58 #define kHasFMA 0x00002000 // Fused multiply add is supported
59 #define kUP 0x00008000 // set if (kNumCPUs == 1)
60 #define kNumCPUs 0x00FF0000 // number of CPUs (see _NumCPUs() below)
61 #define kHasARMv8Crypto 0x01000000 // Optional ARMv8 Crypto extensions
62 #define kHasARMv81Atomics 0x02000000 // ARMv8.1 Atomic instructions supported
64 #define kNumCPUsShift 16 // see _NumCPUs() below
67 * Bit definitions for multiuser_config:
69 #define kIsMultiUserDevice 0x80000000 // this device is in multiuser mode
70 #define kMultiUserCurrentUserMask 0x7fffffff // the current user UID of the multiuser device
73 #include <sys/commpage.h>
75 extern int _get_cpu_capabilities( void );
80 return (_get_cpu_capabilities() & kNumCPUs
) >> kNumCPUsShift
;
84 volatile uint64_t TimeBase
;
85 volatile uint32_t TimeStamp_sec
;
86 volatile uint32_t TimeStamp_usec
;
87 volatile uint32_t TimeBaseTicks_per_sec
;
88 volatile uint32_t TimeBaseTicks_per_usec
;
89 volatile uint64_t TimeBase_magic
;
90 volatile uint32_t TimeBase_add
;
91 volatile uint32_t TimeBase_shift
;
92 } commpage_timeofday_data_t
;
94 #endif /* __ASSEMBLER__ */
98 * The shared kernel/user "comm page(s)":
101 #if defined(__arm64__)
103 #define _COMM_PAGE64_BASE_ADDRESS (0xfffffff0001fc000ULL) /* Just below the kernel, safely in TTBR1 */
104 #define _COMM_PRIV_PAGE64_BASE_ADDRESS (_COMM_PAGE64_BASE_ADDRESS - (PAGE_SIZE)) /* Privileged RO in kernel mode */
106 #define _COMM_PAGE64_AREA_LENGTH (_COMM_PAGE32_AREA_LENGTH)
107 #define _COMM_PAGE64_AREA_USED (-1)
109 // macro to change a user comm page address to one that is accessible from privileged mode
110 // we can no longer access user memory in privileged mode once PAN is enabled
111 #define _COMM_PAGE_PRIV(_addr_) ((_addr_) - (_COMM_PAGE_START_ADDRESS) + (_COMM_PRIV_PAGE64_BASE_ADDRESS))
113 #ifdef KERNEL_PRIVATE
114 extern vm_address_t sharedpage_rw_addr
;
115 #define _COMM_PAGE_RW_OFFSET (0)
116 #define _COMM_PAGE_AREA_LENGTH (PAGE_SIZE)
118 #define _COMM_PAGE_BASE_ADDRESS (sharedpage_rw_addr)
119 #define _COMM_PAGE_START_ADDRESS (sharedpage_rw_addr)
121 #define _COMM_PAGE_AREA_LENGTH (4096)
123 #define _COMM_PAGE_BASE_ADDRESS _COMM_PAGE64_BASE_ADDRESS
124 #define _COMM_PAGE_START_ADDRESS _COMM_PAGE64_BASE_ADDRESS
127 #elif defined(__arm__)
129 #define _COMM_PAGE64_BASE_ADDRESS (-1)
130 #define _COMM_PAGE64_AREA_LENGTH (-1)
131 #define _COMM_PAGE64_AREA_USED (-1)
133 // macro to change a user comm page address to one that is accessible from privileged mode
134 // this macro is stubbed as PAN is not available on AARCH32,
135 // but this may still be required for compatibility
136 #define _COMM_PAGE_PRIV(_addr_) (_addr_)
138 #ifdef KERNEL_PRIVATE
139 extern vm_address_t sharedpage_rw_addr
;
140 #define _COMM_PAGE_RW_OFFSET (sharedpage_rw_addr-_COMM_PAGE_BASE_ADDRESS)
141 #define _COMM_PAGE_AREA_LENGTH (PAGE_SIZE)
143 #define _COMM_PAGE_AREA_LENGTH (4096)
146 #define _COMM_PAGE_BASE_ADDRESS _COMM_PAGE32_BASE_ADDRESS
147 #define _COMM_PAGE_START_ADDRESS _COMM_PAGE32_BASE_ADDRESS
150 #error Unknown architecture.
153 #define _COMM_PAGE32_BASE_ADDRESS (0xFFFF4000) /* Must be outside of normal map bounds */
154 #define _COMM_PAGE32_AREA_LENGTH (_COMM_PAGE_AREA_LENGTH)
156 #define _COMM_PAGE_TEXT_START (-1)
157 #define _COMM_PAGE32_TEXT_START (-1)
158 #define _COMM_PAGE64_TEXT_START (-1)
159 #define _COMM_PAGE_PFZ_START_OFFSET (-1)
160 #define _COMM_PAGE_PFZ_END_OFFSET (-1)
162 #define _COMM_PAGE32_OBJC_SIZE 0ULL
163 #define _COMM_PAGE32_OBJC_BASE 0ULL
164 #define _COMM_PAGE64_OBJC_SIZE 0ULL
165 #define _COMM_PAGE64_OBJC_BASE 0ULL
168 * data in the comm pages
169 * apply _COMM_PAGE_PRIV macro to use these in privileged mode
171 #define _COMM_PAGE_SIGNATURE (_COMM_PAGE_START_ADDRESS+0x000) // first few bytes are a signature
172 #define _COMM_PAGE_VERSION (_COMM_PAGE_START_ADDRESS+0x01E) // 16-bit version#
173 #define _COMM_PAGE_THIS_VERSION 3 // version of the commarea format
175 #define _COMM_PAGE_CPU_CAPABILITIES (_COMM_PAGE_START_ADDRESS+0x020) // uint32_t _cpu_capabilities
176 #define _COMM_PAGE_NCPUS (_COMM_PAGE_START_ADDRESS+0x022) // uint8_t number of configured CPUs
177 #define _COMM_PAGE_USER_PAGE_SHIFT_32 (_COMM_PAGE_START_ADDRESS+0x024) // VM page shift for 32-bit processes
178 #define _COMM_PAGE_USER_PAGE_SHIFT_64 (_COMM_PAGE_START_ADDRESS+0x025) // VM page shift for 64-bit processes
179 #define _COMM_PAGE_CACHE_LINESIZE (_COMM_PAGE_START_ADDRESS+0x026) // uint16_t cache line size
180 #define _COMM_PAGE_SCHED_GEN (_COMM_PAGE_START_ADDRESS+0x028) // uint32_t scheduler generation number (count of pre-emptions)
181 #define _COMM_PAGE_SPIN_COUNT (_COMM_PAGE_START_ADDRESS+0x02C) // uint32_t max spin count for mutex's
182 #define _COMM_PAGE_MEMORY_PRESSURE (_COMM_PAGE_START_ADDRESS+0x030) // uint32_t copy of vm_memory_pressure
183 #define _COMM_PAGE_ACTIVE_CPUS (_COMM_PAGE_START_ADDRESS+0x034) // uint8_t number of active CPUs (hw.activecpu)
184 #define _COMM_PAGE_PHYSICAL_CPUS (_COMM_PAGE_START_ADDRESS+0x035) // uint8_t number of physical CPUs (hw.physicalcpu_max)
185 #define _COMM_PAGE_LOGICAL_CPUS (_COMM_PAGE_START_ADDRESS+0x036) // uint8_t number of logical CPUs (hw.logicalcpu_max)
186 #define _COMM_PAGE_KERNEL_PAGE_SHIFT (_COMM_PAGE_START_ADDRESS+0x037) // uint8_t kernel vm page shift */
187 #define _COMM_PAGE_MEMORY_SIZE (_COMM_PAGE_START_ADDRESS+0x038) // uint64_t max memory size */
188 #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
189 #define _COMM_PAGE_CPUFAMILY (_COMM_PAGE_START_ADDRESS+0x080) // used by memcpy() resolver
190 #define _COMM_PAGE_DEV_FIRM (_COMM_PAGE_START_ADDRESS+0x084) // uint32_t handle on PE_i_can_has_debugger
191 #define _COMM_PAGE_TIMEBASE_OFFSET (_COMM_PAGE_START_ADDRESS+0x088) // uint64_t timebase offset for constructing mach_absolute_time()
192 #define _COMM_PAGE_USER_TIMEBASE (_COMM_PAGE_START_ADDRESS+0x090) // uint8_t is userspace mach_absolute_time supported (can read the timebase)
193 #define _COMM_PAGE_CONT_HWCLOCK (_COMM_PAGE_START_ADDRESS+0x091) // uint8_t is always-on hardware clock present for mach_continuous_time()
194 #define _COMM_PAGE_UNUSED0 (_COMM_PAGE_START_ADDRESS+0x092) // 6 unused bytes
195 #define _COMM_PAGE_CONT_TIMEBASE (_COMM_PAGE_START_ADDRESS+0x098) // uint64_t base for mach_continuous_time()
196 #define _COMM_PAGE_BOOTTIME_USEC (_COMM_PAGE_START_ADDRESS+0x0A0) // uint64_t boottime in microseconds
198 // aligning to 64byte for cacheline size
199 #define _COMM_PAGE_APPROX_TIME (_COMM_PAGE_START_ADDRESS+0x0C0) // uint64_t last known mach_absolute_time()
200 #define _COMM_PAGE_APPROX_TIME_SUPPORTED (_COMM_PAGE_START_ADDRESS+0x0C8) // uint8_t is mach_approximate_time supported
201 #define _COMM_PAGE_UNUSED1 (_COMM_PAGE_START_ADDRESS+0x0C9) // 55 unused bytes, align next mutable value to a separate cache line
203 #define _COMM_PAGE_KDEBUG_ENABLE (_COMM_PAGE_START_ADDRESS+0x100) // uint32_t export kdebug status bits to userspace
204 #define _COMM_PAGE_ATM_DIAGNOSTIC_CONFIG (_COMM_PAGE_START_ADDRESS+0x104) // uint32_t export "atm_diagnostic_config" to userspace
205 #define _COMM_PAGE_MULTIUSER_CONFIG (_COMM_PAGE_START_ADDRESS+0x108) // uint32_t export "multiuser_config" to userspace
208 #define _COMM_PAGE_NEWTIMEOFDAY_DATA (_COMM_PAGE_START_ADDRESS+0x120) // used by gettimeofday(). Currently, sizeof(new_commpage_timeofday_data_t) = 40.
209 #define _COMM_PAGE_END (_COMM_PAGE_START_ADDRESS+0x1000) // end of common page
211 #endif /* _ARM_CPU_CAPABILITIES_H */