1/*
2 * Copyright (c) 2000-2009 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 * @OSF_COPYRIGHT@
30 */
31
32#ifndef	_ARM_MACHINE_ROUTINES_H_
33#define	_ARM_MACHINE_ROUTINES_H_
34
35#include <mach/mach_types.h>
36#include <mach/boolean.h>
37#include <kern/kern_types.h>
38#include <pexpert/pexpert.h>
39
40#include <sys/cdefs.h>
41#include <sys/appleapiopts.h>
42
43__BEGIN_DECLS
44// why
45void bcopy_phys(addr64_t src64, addr64_t dst64, vm_size_t bytes);
46
47#ifdef XNU_KERNEL_PRIVATE
48
49/* are we a 64 bit platform ? */
50
51boolean_t ml_is64bit(void);
52
53/* is this a 64bit thread? */
54
55boolean_t ml_thread_is64bit(thread_t);
56
57/* is this a 64bit thread? */
58
59boolean_t ml_state_is64bit(void *);
60
61/* set state of fpu save area for signal handling */
62
63void ml_fp_setvalid(boolean_t);
64
65void ml_cpu_set_ldt(int);
66
67/* Interrupt handling */
68
69/* Initialize Interrupts */
70void ml_init_interrupt(void);
71
72/* Generate a fake interrupt */
73void ml_cause_interrupt(void);
74
75/* Initialize Interrupts */
76void ml_install_interrupt_handler(void *nub, int source, void *target,
77                                  IOInterruptHandler handler, void *refCon);
78
79void ml_get_timebase(unsigned long long *timestamp);
80void ml_init_lock_timeout(void);
81void ml_init_delay_spin_threshold(void);
82
83boolean_t ml_delay_should_spin(uint64_t interval);
84
85vm_offset_t ml_static_ptovirt(vm_offset_t);
86
87void ml_static_mfree(vm_offset_t, vm_size_t);
88
89/* boot memory allocation */
90vm_offset_t ml_static_malloc(vm_size_t size);
91
92/* virtual to physical on wired pages */
93vm_offset_t ml_vtophys(vm_offset_t vaddr);
94
95vm_size_t ml_nofault_copy(vm_offset_t virtsrc, vm_offset_t virtdst,
96                          vm_size_t size);
97
98/* Machine topology info */
99uint64_t ml_cpu_cache_size(unsigned int level);
100uint64_t ml_cpu_cache_sharing(unsigned int level);
101
102/* Initialize the maximum number of CPUs */
103void ml_init_max_cpus(unsigned long max_cpus);
104
105extern void ml_cpu_up(void);
106extern void ml_cpu_down(void);
107
108void bzero_phys_nc(addr64_t phys_address, uint32_t length);
109
110#if	defined(PEXPERT_KERNEL_PRIVATE) || defined(MACH_KERNEL_PRIVATE)
111/* IO memory map services */
112
113/* Map memory map IO space */
114vm_offset_t ml_io_map(vm_offset_t phys_addr, vm_size_t size);
115
116void ml_get_bouncepool_info(vm_offset_t * phys_addr, vm_size_t * size);
117/* Indicates if spinlock, IPI and other timeouts should be suspended */
118boolean_t machine_timeout_suspended(void);
119#endif                          /* PEXPERT_KERNEL_PRIVATE || MACH_KERNEL_PRIVATE  */
120
121/* Warm up a CPU to receive an interrupt */
122kern_return_t ml_interrupt_prewarm(uint64_t deadline);
123
124#endif                          /* XNU_KERNEL_PRIVATE */
125
126#ifdef KERNEL_PRIVATE
127
128/* Type for the Time Base Enable function */
129typedef void (*time_base_enable_t) (cpu_id_t cpu_id, boolean_t enable);
130
131/* Type for the IPI Hander */
132typedef void (*ipi_handler_t) (void);
133
134/* Struct for ml_processor_register */
135struct ml_processor_info {
136    cpu_id_t cpu_id;
137    boolean_t boot_cpu;
138    vm_offset_t start_paddr;
139    boolean_t supports_nap;
140    unsigned long l2cr_value;
141    time_base_enable_t time_base_enable;
142};
143
144typedef struct ml_processor_info ml_processor_info_t;
145
146/* Register a processor */
147kern_return_t ml_processor_register(cpu_id_t cpu_id,
148                                    processor_t * processor_out,
149                                    ipi_handler_t * ipi_handler);
150
151/* PCI config cycle probing */
152boolean_t ml_probe_read(vm_offset_t paddr, unsigned int *val);
153boolean_t ml_probe_read_64(addr64_t paddr, unsigned int *val);
154
155/* Read physical address byte */
156unsigned int ml_phys_read_byte(vm_offset_t paddr);
157unsigned int ml_phys_read_byte_64(addr64_t paddr);
158
159/* Read physical address half word */
160unsigned int ml_phys_read_half(vm_offset_t paddr);
161unsigned int ml_phys_read_half_64(addr64_t paddr);
162
163/* Read physical address word*/
164unsigned int ml_phys_read(vm_offset_t paddr);
165unsigned int ml_phys_read_64(addr64_t paddr);
166unsigned int ml_phys_read_word(vm_offset_t paddr);
167unsigned int ml_phys_read_word_64(addr64_t paddr);
168
169/* Read physical address double word */
170unsigned long long ml_phys_read_double(vm_offset_t paddr);
171unsigned long long ml_phys_read_double_64(addr64_t paddr);
172
173/* Write physical address byte */
174void ml_phys_write_byte(vm_offset_t paddr, unsigned int data);
175void ml_phys_write_byte_64(addr64_t paddr, unsigned int data);
176
177/* Write physical address half word */
178void ml_phys_write_half(vm_offset_t paddr, unsigned int data);
179void ml_phys_write_half_64(addr64_t paddr, unsigned int data);
180
181/* Write physical address word */
182void ml_phys_write(vm_offset_t paddr, unsigned int data);
183void ml_phys_write_64(addr64_t paddr, unsigned int data);
184void ml_phys_write_word(vm_offset_t paddr, unsigned int data);
185void ml_phys_write_word_64(addr64_t paddr, unsigned int data);
186
187/* Write physical address double word */
188void ml_phys_write_double(vm_offset_t paddr, unsigned long long data);
189void ml_phys_write_double_64(addr64_t paddr, unsigned long long data);
190
191/* Struct for ml_cpu_get_info */
192struct ml_cpu_info {
193    uint32_t vector_unit;
194    uint32_t cache_line_size;
195    uint32_t l1_icache_size;
196    uint32_t l1_dcache_size;
197    uint32_t l2_settings;
198    uint32_t l2_cache_size;
199    uint32_t l3_settings;
200    uint32_t l3_cache_size;
201};
202
203typedef struct ml_cpu_info ml_cpu_info_t;
204
205/* Get processor info */
206void ml_cpu_get_info(ml_cpu_info_t * ml_cpu_info);
207
208void ml_thread_policy(thread_t thread, unsigned policy_id,
209                      unsigned policy_info);
210
211#define MACHINE_GROUP					0x00000001
212#define MACHINE_NETWORK_GROUP			0x10000000
213#define MACHINE_NETWORK_WORKLOOP		0x00000001
214#define MACHINE_NETWORK_NETISR			0x00000002
215
216/* Return the maximum number of CPUs set by ml_init_max_cpus() */
217int ml_get_max_cpus(void);
218
219/*
220 * The following are in pmCPU.c not machine_routines.c.
221 */
222extern void ml_set_maxsnoop(uint32_t maxdelay);
223extern unsigned ml_get_maxsnoop(void);
224extern void ml_set_maxbusdelay(uint32_t mdelay);
225extern uint32_t ml_get_maxbusdelay(void);
226extern void ml_set_maxintdelay(uint64_t mdelay);
227extern uint64_t ml_get_maxintdelay(void);
228extern boolean_t ml_get_interrupt_prewake_applicable(void);
229
230extern uint64_t tmrCvt(uint64_t time, uint64_t conversion);
231
232extern uint64_t ml_cpu_int_event_time(void);
233
234#endif                          /* KERNEL_PRIVATE */
235
236/* Get Interrupts Enabled */
237boolean_t ml_get_interrupts_enabled(void);
238
239/* Set Interrupts Enabled */
240boolean_t ml_set_interrupts_enabled(boolean_t enable);
241
242/* Check if running at interrupt context */
243boolean_t ml_at_interrupt_context(void);
244
245/* Zero bytes starting at a physical address */
246void bzero_phys(addr64_t phys_address, uint32_t length);
247
248/* Bytes available on current stack */
249vm_offset_t ml_stack_remaining(void);
250
251#if CONFIG_COUNTERS
252void ml_get_csw_threads(thread_t * /*old */ , thread_t * /*new */ );
253#endif                          /* CONFIG_COUNTERS */
254
255__END_DECLS
256#ifdef	XNU_KERNEL_PRIVATE
257    boolean_t ml_fpu_avx_enabled(void);
258
259void interrupt_latency_tracker_setup(void);
260void interrupt_reset_latency_stats(void);
261void interrupt_populate_latency_stats(char *, unsigned);
262
263#endif                          /* XNU_KERNEL_PRIVATE */
264#endif                          /* _ARM_MACHINE_ROUTINES_H_ */
265