2 * Copyright (c) 2000-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@
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 /* are we a 64 bit platform ? */
47 boolean_t
ml_is64bit(void);
49 /* is this a 64bit thread? */
51 boolean_t
ml_thread_is64bit(thread_t
);
53 /* is this a 64bit thread? */
55 boolean_t
ml_state_is64bit(void *);
57 /* set state of fpu save area for signal handling */
59 void ml_fp_setvalid(boolean_t
);
61 void ml_cpu_set_ldt(int);
63 /* Interrupt handling */
65 /* Initialize Interrupts */
66 void ml_init_interrupt(void);
68 /* Get Interrupts Enabled */
69 boolean_t
ml_get_interrupts_enabled(void);
71 /* Set Interrupts Enabled */
72 boolean_t
ml_set_interrupts_enabled(boolean_t enable
);
74 /* Check if running at interrupt context */
75 boolean_t
ml_at_interrupt_context(void);
77 /* Generate a fake interrupt */
78 void ml_cause_interrupt(void);
80 void ml_get_timebase(unsigned long long *timestamp
);
81 void ml_init_lock_timeout(void);
83 /* Type for the Time Base Enable function */
84 typedef void (*time_base_enable_t
)(cpu_id_t cpu_id
, boolean_t enable
);
86 /* Type for the IPI Hander */
87 typedef void (*ipi_handler_t
)(void);
89 /* Struct for ml_processor_register */
90 struct ml_processor_info
{
93 vm_offset_t start_paddr
;
94 boolean_t supports_nap
;
95 unsigned long l2cr_value
;
96 time_base_enable_t time_base_enable
;
99 typedef struct ml_processor_info ml_processor_info_t
;
102 /* Register a processor */
103 kern_return_t
ml_processor_register(
106 processor_t
*processor
,
107 ipi_handler_t
*ipi_handler
,
110 /* Initialize Interrupts */
111 void ml_install_interrupt_handler(
115 IOInterruptHandler handler
,
118 #ifdef __APPLE_API_UNSTABLE
123 #ifdef XNU_KERNEL_PRIVATE
129 /* PCI config cycle probing */
130 boolean_t
ml_probe_read(
133 boolean_t
ml_probe_read_64(
137 /* Read physical address byte */
138 unsigned int ml_phys_read_byte(
140 unsigned int ml_phys_read_byte_64(
143 /* Read physical address half word */
144 unsigned int ml_phys_read_half(
146 unsigned int ml_phys_read_half_64(
149 /* Read physical address word*/
150 unsigned int ml_phys_read(
152 unsigned int ml_phys_read_64(
154 unsigned int ml_phys_read_word(
156 unsigned int ml_phys_read_word_64(
159 /* Read physical address double word */
160 unsigned long long ml_phys_read_double(
162 unsigned long long ml_phys_read_double_64(
165 /* Write physical address byte */
166 void ml_phys_write_byte(
167 vm_offset_t paddr
, unsigned int data
);
168 void ml_phys_write_byte_64(
169 addr64_t paddr
, unsigned int data
);
171 /* Write physical address half word */
172 void ml_phys_write_half(
173 vm_offset_t paddr
, unsigned int data
);
174 void ml_phys_write_half_64(
175 addr64_t paddr
, unsigned int data
);
177 /* Write physical address word */
179 vm_offset_t paddr
, unsigned int data
);
180 void ml_phys_write_64(
181 addr64_t paddr
, unsigned int data
);
182 void ml_phys_write_word(
183 vm_offset_t paddr
, unsigned int data
);
184 void ml_phys_write_word_64(
185 addr64_t paddr
, unsigned int data
);
187 /* Write physical address double word */
188 void ml_phys_write_double(
189 vm_offset_t paddr
, unsigned long long data
);
190 void ml_phys_write_double_64(
191 addr64_t paddr
, unsigned long long data
);
193 void ml_static_mfree(
197 /* virtual to physical on wired pages */
198 vm_offset_t
ml_vtophys(
201 vm_size_t
ml_nofault_copy(
202 vm_offset_t virtsrc
, vm_offset_t virtdst
, vm_size_t size
);
204 /* Struct for ml_cpu_get_info */
206 unsigned long vector_unit
;
207 unsigned long cache_line_size
;
208 unsigned long l1_icache_size
;
209 unsigned long l1_dcache_size
;
210 unsigned long l2_settings
;
211 unsigned long l2_cache_size
;
212 unsigned long l3_settings
;
213 unsigned long l3_cache_size
;
216 typedef struct ml_cpu_info ml_cpu_info_t
;
218 /* Get processor info */
219 void ml_cpu_get_info(ml_cpu_info_t
*ml_cpu_info
);
221 /* Machine topology info */
222 uint64_t ml_cpu_cache_size(unsigned int level
);
223 uint64_t ml_cpu_cache_sharing(unsigned int level
);
225 #endif /* __APPLE_API_UNSTABLE */
227 #ifdef __APPLE_API_PRIVATE
228 #if defined(PEXPERT_KERNEL_PRIVATE) || defined(MACH_KERNEL_PRIVATE)
229 /* IO memory map services */
231 /* Map memory map IO space */
232 vm_offset_t
ml_io_map(
233 vm_offset_t phys_addr
,
236 /* boot memory allocation */
237 vm_offset_t
ml_static_malloc(
241 extern uint32_t bounce_pool_base
;
242 extern uint32_t bounce_pool_size
;
244 void ml_get_bouncepool_info(
245 vm_offset_t
*phys_addr
,
249 #endif /* PEXPERT_KERNEL_PRIVATE || MACH_KERNEL_PRIVATE */
251 /* Zero bytes starting at a physical address */
253 addr64_t phys_address
,
257 addr64_t phys_address
,
260 void ml_thread_policy(
263 unsigned policy_info
);
265 #define MACHINE_GROUP 0x00000001
266 #define MACHINE_NETWORK_GROUP 0x10000000
267 #define MACHINE_NETWORK_WORKLOOP 0x00000001
268 #define MACHINE_NETWORK_NETISR 0x00000002
270 /* Initialize the maximum number of CPUs */
271 void ml_init_max_cpus(
272 unsigned long max_cpus
);
274 /* Return the maximum number of CPUs set by ml_init_max_cpus() */
278 extern void ml_cpu_up(void);
279 extern void ml_cpu_down(void);
282 * The following are in pmCPU.c not machine_routines.c.
284 extern void ml_set_maxsnoop(uint32_t maxdelay
);
285 extern unsigned ml_get_maxsnoop(void);
286 extern void ml_set_maxbusdelay(uint32_t mdelay
);
287 extern uint32_t ml_get_maxbusdelay(void);
290 extern void ml_hpet_cfg(uint32_t cpu
, uint32_t hpetVect
);
292 extern uint64_t tmrCvt(uint64_t time
, uint64_t conversion
);
294 extern uint64_t ml_cpu_int_event_time(void);
296 #endif /* __APPLE_API_PRIVATE */
300 #endif /* _I386_MACHINE_ROUTINES_H_ */