]> git.saurik.com Git - apple/xnu.git/blame - osfmk/i386/machine_routines.h
xnu-2422.110.17.tar.gz
[apple/xnu.git] / osfmk / i386 / machine_routines.h
CommitLineData
1c79356b 1/*
b0d623f7 2 * Copyright (c) 2000-2009 Apple Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
29 * @OSF_COPYRIGHT@
30 */
31
32#ifndef _I386_MACHINE_ROUTINES_H_
33#define _I386_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
91447636 40#include <sys/cdefs.h>
9bccf70c 41#include <sys/appleapiopts.h>
1c79356b 42
91447636
A
43__BEGIN_DECLS
44
b0d623f7
A
45#ifdef XNU_KERNEL_PRIVATE
46
0c530ab8
A
47/* are we a 64 bit platform ? */
48
49boolean_t ml_is64bit(void);
50
51/* is this a 64bit thread? */
52
53boolean_t ml_thread_is64bit(thread_t);
54
55/* is this a 64bit thread? */
56
57boolean_t ml_state_is64bit(void *);
58
59/* set state of fpu save area for signal handling */
60
61void ml_fp_setvalid(boolean_t);
62
63void ml_cpu_set_ldt(int);
64
1c79356b
A
65/* Interrupt handling */
66
55e303ae
A
67/* Initialize Interrupts */
68void ml_init_interrupt(void);
69
1c79356b
A
70/* Generate a fake interrupt */
71void ml_cause_interrupt(void);
72
b0d623f7
A
73/* Initialize Interrupts */
74void ml_install_interrupt_handler(
75 void *nub,
76 int source,
77 void *target,
78 IOInterruptHandler handler,
79 void *refCon);
80
9bccf70c 81void ml_get_timebase(unsigned long long *timestamp);
0c530ab8 82void ml_init_lock_timeout(void);
bd504ef0 83void ml_init_delay_spin_threshold(int);
316670eb
A
84
85boolean_t ml_delay_should_spin(uint64_t interval);
d52fe63f 86
b0d623f7
A
87vm_offset_t
88ml_static_ptovirt(
89 vm_offset_t);
90
91void ml_static_mfree(
92 vm_offset_t,
93 vm_size_t);
94
95/* boot memory allocation */
96vm_offset_t ml_static_malloc(
97 vm_size_t size);
98
99/* virtual to physical on wired pages */
100vm_offset_t ml_vtophys(
101 vm_offset_t vaddr);
102
103vm_size_t ml_nofault_copy(
104 vm_offset_t virtsrc, vm_offset_t virtdst, vm_size_t size);
105
39236c6e
A
106boolean_t ml_validate_nofault(
107 vm_offset_t virtsrc, vm_size_t size);
108
b0d623f7
A
109/* Machine topology info */
110uint64_t ml_cpu_cache_size(unsigned int level);
111uint64_t ml_cpu_cache_sharing(unsigned int level);
112
113/* Initialize the maximum number of CPUs */
114void ml_init_max_cpus(
115 unsigned long max_cpus);
116
117extern void ml_cpu_up(void);
118extern void ml_cpu_down(void);
119
120void bzero_phys_nc(
121 addr64_t phys_address,
122 uint32_t length);
39236c6e
A
123#define NUM_LATENCY_QOS_TIERS (6)
124typedef struct {
125 int32_t timer_coalesce_rt_shift;
126 int32_t timer_coalesce_bg_shift;
127 int32_t timer_coalesce_kt_shift;
128 int32_t timer_coalesce_fp_shift;
129 int32_t timer_coalesce_ts_shift;
130
131 uint64_t timer_coalesce_rt_ns_max;
132 uint64_t timer_coalesce_bg_ns_max;
133 uint64_t timer_coalesce_kt_ns_max;
134 uint64_t timer_coalesce_fp_ns_max;
135 uint64_t timer_coalesce_ts_ns_max;
136
137 uint32_t latency_qos_scale[NUM_LATENCY_QOS_TIERS];
138 uint64_t latency_qos_ns_max[NUM_LATENCY_QOS_TIERS];
139 boolean_t latency_tier_rate_limited[NUM_LATENCY_QOS_TIERS];
140} timer_coalescing_priority_params_t;
141extern timer_coalescing_priority_params_t tcoal_prio_params;
142extern uint32_t interrupt_timer_coalescing_enabled;
143extern uint32_t idle_entry_timer_processing_hdeadline_threshold;
144
145#if TCOAL_INSTRUMENT
146#define TCOAL_DEBUG KERNEL_DEBUG_CONSTANT
147#else
148#define TCOAL_DEBUG(x, a, b, c, d, e) do { } while(0)
149#endif /* TCOAL_INSTRUMENT */
b0d623f7
A
150
151#if defined(PEXPERT_KERNEL_PRIVATE) || defined(MACH_KERNEL_PRIVATE)
152/* IO memory map services */
153
154/* Map memory map IO space */
155vm_offset_t ml_io_map(
156 vm_offset_t phys_addr,
157 vm_size_t size);
158
b0d623f7
A
159
160void ml_get_bouncepool_info(
161 vm_offset_t *phys_addr,
162 vm_size_t *size);
060df5ea
A
163/* Indicates if spinlock, IPI and other timeouts should be suspended */
164boolean_t machine_timeout_suspended(void);
b0d623f7
A
165#endif /* PEXPERT_KERNEL_PRIVATE || MACH_KERNEL_PRIVATE */
166
6d2010ae
A
167/* Warm up a CPU to receive an interrupt */
168kern_return_t ml_interrupt_prewarm(uint64_t deadline);
060df5ea 169
b0d623f7
A
170#endif /* XNU_KERNEL_PRIVATE */
171
172#ifdef KERNEL_PRIVATE
173
55e303ae
A
174/* Type for the Time Base Enable function */
175typedef void (*time_base_enable_t)(cpu_id_t cpu_id, boolean_t enable);
176
9bccf70c
A
177/* Type for the IPI Hander */
178typedef void (*ipi_handler_t)(void);
179
55e303ae
A
180/* Struct for ml_processor_register */
181struct ml_processor_info {
182 cpu_id_t cpu_id;
183 boolean_t boot_cpu;
184 vm_offset_t start_paddr;
185 boolean_t supports_nap;
186 unsigned long l2cr_value;
187 time_base_enable_t time_base_enable;
188};
189
190typedef struct ml_processor_info ml_processor_info_t;
191
91447636 192
9bccf70c 193/* Register a processor */
b0d623f7
A
194kern_return_t
195ml_processor_register(
196 cpu_id_t cpu_id,
197 uint32_t lapic_id,
198 processor_t *processor_out,
199 boolean_t boot_cpu,
200 boolean_t start );
0c530ab8 201
43866e37
A
202/* PCI config cycle probing */
203boolean_t ml_probe_read(
204 vm_offset_t paddr,
205 unsigned int *val);
55e303ae
A
206boolean_t ml_probe_read_64(
207 addr64_t paddr,
208 unsigned int *val);
43866e37
A
209
210/* Read physical address byte */
211unsigned int ml_phys_read_byte(
212 vm_offset_t paddr);
55e303ae
A
213unsigned int ml_phys_read_byte_64(
214 addr64_t paddr);
43866e37
A
215
216/* Read physical address half word */
217unsigned int ml_phys_read_half(
218 vm_offset_t paddr);
55e303ae
A
219unsigned int ml_phys_read_half_64(
220 addr64_t paddr);
43866e37
A
221
222/* Read physical address word*/
223unsigned int ml_phys_read(
224 vm_offset_t paddr);
55e303ae
A
225unsigned int ml_phys_read_64(
226 addr64_t paddr);
43866e37
A
227unsigned int ml_phys_read_word(
228 vm_offset_t paddr);
55e303ae
A
229unsigned int ml_phys_read_word_64(
230 addr64_t paddr);
43866e37
A
231
232/* Read physical address double word */
233unsigned long long ml_phys_read_double(
234 vm_offset_t paddr);
55e303ae
A
235unsigned long long ml_phys_read_double_64(
236 addr64_t paddr);
43866e37
A
237
238/* Write physical address byte */
239void ml_phys_write_byte(
240 vm_offset_t paddr, unsigned int data);
55e303ae
A
241void ml_phys_write_byte_64(
242 addr64_t paddr, unsigned int data);
43866e37
A
243
244/* Write physical address half word */
245void ml_phys_write_half(
246 vm_offset_t paddr, unsigned int data);
55e303ae
A
247void ml_phys_write_half_64(
248 addr64_t paddr, unsigned int data);
43866e37
A
249
250/* Write physical address word */
251void ml_phys_write(
252 vm_offset_t paddr, unsigned int data);
55e303ae
A
253void ml_phys_write_64(
254 addr64_t paddr, unsigned int data);
43866e37
A
255void ml_phys_write_word(
256 vm_offset_t paddr, unsigned int data);
55e303ae
A
257void ml_phys_write_word_64(
258 addr64_t paddr, unsigned int data);
43866e37
A
259
260/* Write physical address double word */
261void ml_phys_write_double(
262 vm_offset_t paddr, unsigned long long data);
55e303ae
A
263void ml_phys_write_double_64(
264 addr64_t paddr, unsigned long long data);
43866e37 265
43866e37
A
266/* Struct for ml_cpu_get_info */
267struct ml_cpu_info {
6d2010ae
A
268 uint32_t vector_unit;
269 uint32_t cache_line_size;
270 uint32_t l1_icache_size;
271 uint32_t l1_dcache_size;
272 uint32_t l2_settings;
273 uint32_t l2_cache_size;
274 uint32_t l3_settings;
275 uint32_t l3_cache_size;
43866e37
A
276};
277
278typedef struct ml_cpu_info ml_cpu_info_t;
279
280/* Get processor info */
91447636 281void ml_cpu_get_info(ml_cpu_info_t *ml_cpu_info);
43866e37 282
9bccf70c
A
283void ml_thread_policy(
284 thread_t thread,
285 unsigned policy_id,
286 unsigned policy_info);
1c79356b 287
9bccf70c
A
288#define MACHINE_GROUP 0x00000001
289#define MACHINE_NETWORK_GROUP 0x10000000
290#define MACHINE_NETWORK_WORKLOOP 0x00000001
291#define MACHINE_NETWORK_NETISR 0x00000002
1c79356b 292
43866e37
A
293/* Return the maximum number of CPUs set by ml_init_max_cpus() */
294int ml_get_max_cpus(
295 void);
296
2d21ac55
A
297/*
298 * The following are in pmCPU.c not machine_routines.c.
299 */
0c530ab8
A
300extern void ml_set_maxsnoop(uint32_t maxdelay);
301extern unsigned ml_get_maxsnoop(void);
302extern void ml_set_maxbusdelay(uint32_t mdelay);
303extern uint32_t ml_get_maxbusdelay(void);
593a1d5f
A
304extern void ml_set_maxintdelay(uint64_t mdelay);
305extern uint64_t ml_get_maxintdelay(void);
6d2010ae 306extern boolean_t ml_get_interrupt_prewake_applicable(void);
2d21ac55
A
307
308
0c530ab8
A
309extern uint64_t tmrCvt(uint64_t time, uint64_t conversion);
310
2d21ac55
A
311extern uint64_t ml_cpu_int_event_time(void);
312
b0d623f7
A
313#endif /* KERNEL_PRIVATE */
314
315/* Get Interrupts Enabled */
316boolean_t ml_get_interrupts_enabled(void);
317
318/* Set Interrupts Enabled */
319boolean_t ml_set_interrupts_enabled(boolean_t enable);
320
321/* Check if running at interrupt context */
322boolean_t ml_at_interrupt_context(void);
323
324/* Zero bytes starting at a physical address */
325void bzero_phys(
326 addr64_t phys_address,
327 uint32_t length);
328
329/* Bytes available on current stack */
330vm_offset_t ml_stack_remaining(void);
331
332#if CONFIG_COUNTERS
333void ml_get_csw_threads(thread_t * /*old*/, thread_t * /*new*/);
334#endif /* CONFIG_COUNTERS */
1c79356b 335
91447636
A
336__END_DECLS
337
6d2010ae 338#ifdef XNU_KERNEL_PRIVATE
316670eb 339
6d2010ae 340boolean_t ml_fpu_avx_enabled(void);
316670eb 341
6d2010ae
A
342void interrupt_latency_tracker_setup(void);
343void interrupt_reset_latency_stats(void);
344void interrupt_populate_latency_stats(char *, unsigned);
4b17d6b6 345void ml_get_power_state(boolean_t *, boolean_t *);
060df5ea 346
39236c6e
A
347void timer_queue_expire_local(void*);
348void timer_queue_expire_rescan(void*);
349void ml_timer_evaluate(void);
350boolean_t ml_timer_forced_evaluation(void);
351int ml_timer_get_user_idle_level(void);
352kern_return_t ml_timer_set_user_idle_level(int);
353
6d2010ae 354#endif /* XNU_KERNEL_PRIVATE */
1c79356b 355#endif /* _I386_MACHINE_ROUTINES_H_ */