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 #ifndef ARM_CPU_DATA_INTERNAL
34 #define ARM_CPU_DATA_INTERNAL
36 #include <mach_assert.h>
37 #include <kern/assert.h>
38 #include <kern/kern_types.h>
39 #include <kern/processor.h>
40 #include <pexpert/pexpert.h>
41 #include <arm/dbgwrap.h>
42 #include <arm/proc_reg.h>
43 #include <arm/thread.h>
47 #include <machine/monotonic.h>
48 #endif /* MONOTONIC */
50 #define NSEC_PER_HZ (NSEC_PER_SEC / 100)
52 typedef struct reset_handler_data
{
53 vm_offset_t assist_reset_handler
; /* Assist handler phys address */
54 vm_offset_t cpu_data_entries
; /* CpuDataEntries phys address */
56 vm_offset_t boot_args
; /* BootArgs phys address */
58 } reset_handler_data_t
;
60 extern reset_handler_data_t ResetHandlerData
;
64 #define MAX_CPUS CPU_COUNT
72 /* Put the static check for cpumap_t here as it's defined in <kern/processor.h> */
73 static_assert(sizeof(cpumap_t
) * CHAR_BIT
>= MAX_CPUS
, "cpumap_t bitvector is too small for current MAX_CPUS value");
76 #define CPUWINDOWS_BASE_MASK 0xFFF00000UL
78 #define CPUWINDOWS_BASE_MASK 0xFFFFFFFFFFF00000UL
80 #define CPUWINDOWS_BASE (VM_MAX_KERNEL_ADDRESS & CPUWINDOWS_BASE_MASK)
81 #define CPUWINDOWS_TOP (CPUWINDOWS_BASE + (MAX_CPUS * CPUWINDOWS_MAX * PAGE_SIZE))
83 typedef struct cpu_data_entry
{
84 void *cpu_data_paddr
; /* Cpu data physical address */
85 struct cpu_data
*cpu_data_vaddr
; /* Cpu data virtual address */
87 uint32_t cpu_data_offset_8
;
88 uint32_t cpu_data_offset_12
;
91 #error Check cpu_data_entry padding for this architecture
96 typedef struct rtclock_timer
{
106 * The wake variants of these counters are reset to 0 when the CPU wakes.
109 uint64_t irq_ex_cnt_wake
;
111 uint64_t ipi_cnt_wake
;
113 uint64_t timer_cnt_wake
;
115 uint64_t pmi_cnt_wake
;
116 #endif /* MONOTONIC */
117 uint64_t undef_ex_cnt
;
118 uint64_t unaligned_cnt
;
120 uint64_t data_ex_cnt
;
121 uint64_t instr_ex_cnt
;
124 typedef struct cpu_data
{
125 unsigned short cpu_number
;
126 unsigned short cpu_flags
;
127 vm_offset_t istackptr
;
128 vm_offset_t intstack_top
;
130 vm_offset_t excepstackptr
;
131 vm_offset_t excepstack_top
;
132 boolean_t cluster_master
;
134 vm_offset_t fiqstackptr
;
135 vm_offset_t fiqstack_top
;
137 boolean_t interrupts_enabled
;
138 thread_t cpu_active_thread
;
139 vm_offset_t cpu_active_stack
;
140 unsigned int cpu_ident
;
142 unsigned volatile int cpu_signal
;
143 void *cpu_cache_dispatch
;
144 ast_t cpu_pending_ast
;
145 struct processor
*cpu_processor
;
152 uint64_t cpu_base_timebase
;
153 uint64_t cpu_timebase
;
164 #define cpu_base_timebase_low cbtb.split.low
165 #define cpu_base_timebase_high cbtb.split.high
176 #define cpu_timebase_low ctb.split.low
177 #define cpu_timebase_high ctb.split.high
180 uint32_t cpu_decrementer
;
181 void *cpu_get_decrementer_func
;
182 void *cpu_set_decrementer_func
;
183 void *cpu_get_fiq_handler
;
185 void *cpu_tbd_hardware_addr
;
186 void *cpu_tbd_hardware_val
;
188 void *cpu_console_buf
;
190 void *cpu_idle_notify
;
191 uint64_t cpu_idle_latency
;
192 uint64_t cpu_idle_pop
;
194 #if __arm__ || __ARM_KERNEL_PROTECT__
195 vm_offset_t cpu_exc_vectors
;
196 #endif /* __ARM_KERNEL_PROTECT__ */
197 vm_offset_t cpu_reset_handler
;
198 uint32_t cpu_reset_type
;
199 uintptr_t cpu_reset_assist
;
202 IOInterruptHandler interrupt_handler
;
204 unsigned int interrupt_source
;
205 void *interrupt_target
;
206 void *interrupt_refCon
;
208 void *idle_timer_notify
;
209 void *idle_timer_refcon
;
210 uint64_t idle_timer_deadline
;
212 uint64_t quantum_timer_deadline
;
214 rtclock_timer_t rtclock_timer
;
215 struct _rtclock_data_
*rtclock_datap
;
217 arm_debug_state_t
*cpu_user_debug
; /* Current debug state */
218 vm_offset_t cpu_debug_interface_map
;
220 volatile int debugger_active
;
224 void *cpu_imm_xcall_p0
;
225 void *cpu_imm_xcall_p1
;
227 #if __ARM_SMP__ && defined(ARMA7)
228 volatile uint32_t cpu_CLW_active
;
229 volatile uint64_t cpu_CLWFlush_req
;
230 volatile uint64_t cpu_CLWFlush_last
;
231 volatile uint64_t cpu_CLWClean_req
;
232 volatile uint64_t cpu_CLWClean_last
;
237 vm_offset_t coresight_base
[CORESIGHT_REGIONS
];
240 /* CCC ARMv8 registers */
241 uint64_t cpu_regmap_paddr
;
243 uint32_t cpu_phys_id
;
244 uint32_t cpu_l2_access_penalty
;
245 void *platform_error_handler
;
249 #define ARM_CPU_ON_SLEEP_PATH 0x50535553UL
250 volatile unsigned int cpu_sleep_token
;
251 unsigned int cpu_sleep_token_last
;
255 volatile int PAB_active
; /* Tells the console if we are dumping backtraces */
258 /* double-buffered performance counter data */
259 uint64_t *cpu_kpc_buf
[2];
260 /* PMC shadow and reload value buffers */
261 uint64_t *cpu_kpc_shadow
;
262 uint64_t *cpu_kpc_reload
;
265 struct mt_cpu cpu_monotonic
;
266 #endif /* MONOTONIC */
267 cluster_type_t cpu_cluster_type
;
268 uint32_t cpu_cluster_id
;
270 uint32_t cpu_l2_size
;
272 uint32_t cpu_l3_size
;
274 struct pmap_cpu_data cpu_pmap_cpu_data
;
275 dbgwrap_thread_state_t halt_state
;
279 CPU_HALTED_WITH_STATE
281 #if defined(HAS_APPLE_PAC)
283 #endif /* defined(HAS_APPLE_PAC) */
289 #define SleepState 0x0800
290 #define StartedState 0x1000
292 extern cpu_data_entry_t CpuDataEntries
[MAX_CPUS
];
293 extern cpu_data_t BootCpuData
;
294 extern boot_args
*BootArgs
;
297 extern unsigned int *ExceptionLowVectorsBase
;
298 extern unsigned int *ExceptionVectorsTable
;
300 extern unsigned int LowResetVectorBase
;
301 extern unsigned int LowResetVectorEnd
;
303 extern uint8_t SleepToken
[8];
305 extern unsigned int LowExceptionVectorBase
;
310 extern cpu_data_t
*cpu_datap(int cpu
);
311 extern cpu_data_t
*cpu_data_alloc(boolean_t is_boot
);
312 extern void cpu_stack_alloc(cpu_data_t
*);
313 extern void cpu_data_init(cpu_data_t
*cpu_data_ptr
);
314 extern void cpu_data_free(cpu_data_t
*cpu_data_ptr
);
315 extern kern_return_t
cpu_data_register(cpu_data_t
*cpu_data_ptr
);
316 extern cpu_data_t
*processor_to_cpu_datap( processor_t processor
);
319 typedef struct sysreg_restore
{
323 extern sysreg_restore_t sysreg_restore
;
324 #endif /* __arm64__ */
326 #endif /* ARM_CPU_DATA_INTERNAL */