2 * Copyright (c) 2000-2009 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@
32 #ifndef _I386_MACHINE_ROUTINES_H_
33 #define _I386_MACHINE_ROUTINES_H_
35 #include <mach/mach_types.h>
36 #include <mach/boolean.h>
37 #include <kern/kern_types.h>
38 #include <pexpert/pexpert.h>
40 #include <sys/cdefs.h>
41 #include <sys/appleapiopts.h>
45 #ifdef XNU_KERNEL_PRIVATE
47 /* are we a 64 bit platform ? */
49 boolean_t
ml_is64bit(void);
51 /* is this a 64bit thread? */
53 boolean_t
ml_thread_is64bit(thread_t
);
55 /* is this a 64bit thread? */
57 boolean_t
ml_state_is64bit(void *);
59 /* set state of fpu save area for signal handling */
61 void ml_fp_setvalid(boolean_t
);
63 void ml_cpu_set_ldt(int);
65 /* Interrupt handling */
67 /* Initialize Interrupts */
68 void ml_init_interrupt(void);
70 /* Generate a fake interrupt */
71 void ml_cause_interrupt(void);
73 /* Initialize Interrupts */
74 void ml_install_interrupt_handler(
78 IOInterruptHandler handler
,
81 void ml_get_timebase(unsigned long long *timestamp
);
82 void ml_init_lock_timeout(void);
83 void ml_init_delay_spin_threshold(int);
85 boolean_t
ml_delay_should_spin(uint64_t interval
);
95 /* boot memory allocation */
96 vm_offset_t
ml_static_malloc(
99 /* virtual to physical on wired pages */
100 vm_offset_t
ml_vtophys(
103 vm_size_t
ml_nofault_copy(
104 vm_offset_t virtsrc
, vm_offset_t virtdst
, vm_size_t size
);
106 boolean_t
ml_validate_nofault(
107 vm_offset_t virtsrc
, vm_size_t size
);
109 /* Machine topology info */
110 uint64_t ml_cpu_cache_size(unsigned int level
);
111 uint64_t ml_cpu_cache_sharing(unsigned int level
);
113 /* Initialize the maximum number of CPUs */
114 void ml_init_max_cpus(
115 unsigned long max_cpus
);
117 extern void ml_cpu_up(void);
118 extern void ml_cpu_down(void);
121 addr64_t phys_address
,
123 #define NUM_LATENCY_QOS_TIERS (6)
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
;
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
;
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
;
141 extern timer_coalescing_priority_params_t tcoal_prio_params
;
142 extern uint32_t interrupt_timer_coalescing_enabled
;
143 extern uint32_t idle_entry_timer_processing_hdeadline_threshold
;
146 #define TCOAL_DEBUG KERNEL_DEBUG_CONSTANT
148 #define TCOAL_DEBUG(x, a, b, c, d, e) do { } while(0)
149 #endif /* TCOAL_INSTRUMENT */
151 #if defined(PEXPERT_KERNEL_PRIVATE) || defined(MACH_KERNEL_PRIVATE)
152 /* IO memory map services */
154 /* Map memory map IO space */
155 vm_offset_t
ml_io_map(
156 vm_offset_t phys_addr
,
160 void ml_get_bouncepool_info(
161 vm_offset_t
*phys_addr
,
163 /* Indicates if spinlock, IPI and other timeouts should be suspended */
164 boolean_t
machine_timeout_suspended(void);
165 #endif /* PEXPERT_KERNEL_PRIVATE || MACH_KERNEL_PRIVATE */
167 /* Warm up a CPU to receive an interrupt */
168 kern_return_t
ml_interrupt_prewarm(uint64_t deadline
);
170 #endif /* XNU_KERNEL_PRIVATE */
172 #ifdef KERNEL_PRIVATE
174 /* Type for the Time Base Enable function */
175 typedef void (*time_base_enable_t
)(cpu_id_t cpu_id
, boolean_t enable
);
177 /* Type for the IPI Hander */
178 typedef void (*ipi_handler_t
)(void);
180 /* Struct for ml_processor_register */
181 struct ml_processor_info
{
184 vm_offset_t start_paddr
;
185 boolean_t supports_nap
;
186 unsigned long l2cr_value
;
187 time_base_enable_t time_base_enable
;
190 typedef struct ml_processor_info ml_processor_info_t
;
193 /* Register a processor */
195 ml_processor_register(
198 processor_t
*processor_out
,
202 /* PCI config cycle probing */
203 boolean_t
ml_probe_read(
206 boolean_t
ml_probe_read_64(
210 /* Read physical address byte */
211 unsigned int ml_phys_read_byte(
213 unsigned int ml_phys_read_byte_64(
216 /* Read physical address half word */
217 unsigned int ml_phys_read_half(
219 unsigned int ml_phys_read_half_64(
222 /* Read physical address word*/
223 unsigned int ml_phys_read(
225 unsigned int ml_phys_read_64(
227 unsigned int ml_phys_read_word(
229 unsigned int ml_phys_read_word_64(
232 /* Read physical address double word */
233 unsigned long long ml_phys_read_double(
235 unsigned long long ml_phys_read_double_64(
238 /* Write physical address byte */
239 void ml_phys_write_byte(
240 vm_offset_t paddr
, unsigned int data
);
241 void ml_phys_write_byte_64(
242 addr64_t paddr
, unsigned int data
);
244 /* Write physical address half word */
245 void ml_phys_write_half(
246 vm_offset_t paddr
, unsigned int data
);
247 void ml_phys_write_half_64(
248 addr64_t paddr
, unsigned int data
);
250 /* Write physical address word */
252 vm_offset_t paddr
, unsigned int data
);
253 void ml_phys_write_64(
254 addr64_t paddr
, unsigned int data
);
255 void ml_phys_write_word(
256 vm_offset_t paddr
, unsigned int data
);
257 void ml_phys_write_word_64(
258 addr64_t paddr
, unsigned int data
);
260 /* Write physical address double word */
261 void ml_phys_write_double(
262 vm_offset_t paddr
, unsigned long long data
);
263 void ml_phys_write_double_64(
264 addr64_t paddr
, unsigned long long data
);
266 /* Struct for ml_cpu_get_info */
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
;
278 typedef struct ml_cpu_info ml_cpu_info_t
;
280 /* Get processor info */
281 void ml_cpu_get_info(ml_cpu_info_t
*ml_cpu_info
);
283 void ml_thread_policy(
286 unsigned policy_info
);
288 #define MACHINE_GROUP 0x00000001
289 #define MACHINE_NETWORK_GROUP 0x10000000
290 #define MACHINE_NETWORK_WORKLOOP 0x00000001
291 #define MACHINE_NETWORK_NETISR 0x00000002
293 /* Return the maximum number of CPUs set by ml_init_max_cpus() */
298 * The following are in pmCPU.c not machine_routines.c.
300 extern void ml_set_maxsnoop(uint32_t maxdelay
);
301 extern unsigned ml_get_maxsnoop(void);
302 extern void ml_set_maxbusdelay(uint32_t mdelay
);
303 extern uint32_t ml_get_maxbusdelay(void);
304 extern void ml_set_maxintdelay(uint64_t mdelay
);
305 extern uint64_t ml_get_maxintdelay(void);
306 extern boolean_t
ml_get_interrupt_prewake_applicable(void);
309 extern uint64_t tmrCvt(uint64_t time
, uint64_t conversion
);
311 extern uint64_t ml_cpu_int_event_time(void);
313 #endif /* KERNEL_PRIVATE */
315 /* Get Interrupts Enabled */
316 boolean_t
ml_get_interrupts_enabled(void);
318 /* Set Interrupts Enabled */
319 boolean_t
ml_set_interrupts_enabled(boolean_t enable
);
321 /* Check if running at interrupt context */
322 boolean_t
ml_at_interrupt_context(void);
324 /* Zero bytes starting at a physical address */
326 addr64_t phys_address
,
329 /* Bytes available on current stack */
330 vm_offset_t
ml_stack_remaining(void);
333 void ml_get_csw_threads(thread_t
* /*old*/, thread_t
* /*new*/);
334 #endif /* CONFIG_COUNTERS */
338 #ifdef XNU_KERNEL_PRIVATE
340 boolean_t
ml_fpu_avx_enabled(void);
342 void interrupt_latency_tracker_setup(void);
343 void interrupt_reset_latency_stats(void);
344 void interrupt_populate_latency_stats(char *, unsigned);
345 void ml_get_power_state(boolean_t
*, boolean_t
*);
347 void timer_queue_expire_local(void*);
348 void timer_queue_expire_rescan(void*);
349 void ml_timer_evaluate(void);
350 boolean_t
ml_timer_forced_evaluation(void);
351 int ml_timer_get_user_idle_level(void);
352 kern_return_t
ml_timer_set_user_idle_level(int);
354 #endif /* XNU_KERNEL_PRIVATE */
355 #endif /* _I386_MACHINE_ROUTINES_H_ */