]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/machine_routines.h
098cbfebe36d9099905c1b6967eb13956fcea65a
[apple/xnu.git] / osfmk / i386 / machine_routines.h
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * @OSF_COPYRIGHT@
32 */
33
34 #ifndef _I386_MACHINE_ROUTINES_H_
35 #define _I386_MACHINE_ROUTINES_H_
36
37 #include <mach/mach_types.h>
38 #include <mach/boolean.h>
39 #include <kern/kern_types.h>
40 #include <pexpert/pexpert.h>
41
42 #include <sys/cdefs.h>
43 #include <sys/appleapiopts.h>
44
45 __BEGIN_DECLS
46
47 /* are we a 64 bit platform ? */
48
49 boolean_t ml_is64bit(void);
50
51 /* is this a 64bit thread? */
52
53 boolean_t ml_thread_is64bit(thread_t);
54
55 /* is this a 64bit thread? */
56
57 boolean_t ml_state_is64bit(void *);
58
59 /* set state of fpu save area for signal handling */
60
61 void ml_fp_setvalid(boolean_t);
62
63 void ml_cpu_set_ldt(int);
64
65 /* Interrupt handling */
66
67 /* Initialize Interrupts */
68 void ml_init_interrupt(void);
69
70 /* Get Interrupts Enabled */
71 boolean_t ml_get_interrupts_enabled(void);
72
73 /* Set Interrupts Enabled */
74 boolean_t ml_set_interrupts_enabled(boolean_t enable);
75
76 /* Check if running at interrupt context */
77 boolean_t ml_at_interrupt_context(void);
78
79 /* Generate a fake interrupt */
80 void ml_cause_interrupt(void);
81
82 void ml_get_timebase(unsigned long long *timestamp);
83 void ml_init_lock_timeout(void);
84
85 /* Type for the Time Base Enable function */
86 typedef void (*time_base_enable_t)(cpu_id_t cpu_id, boolean_t enable);
87
88 /* Type for the IPI Hander */
89 typedef void (*ipi_handler_t)(void);
90
91 /* Struct for ml_processor_register */
92 struct ml_processor_info {
93 cpu_id_t cpu_id;
94 boolean_t boot_cpu;
95 vm_offset_t start_paddr;
96 boolean_t supports_nap;
97 unsigned long l2cr_value;
98 time_base_enable_t time_base_enable;
99 };
100
101 typedef struct ml_processor_info ml_processor_info_t;
102
103
104 /* Register a processor */
105 kern_return_t ml_processor_register(
106 cpu_id_t cpu_id,
107 uint32_t lapic_id,
108 processor_t *processor,
109 ipi_handler_t *ipi_handler,
110 boolean_t boot_cpu);
111
112 /* Initialize Interrupts */
113 void ml_install_interrupt_handler(
114 void *nub,
115 int source,
116 void *target,
117 IOInterruptHandler handler,
118 void *refCon);
119
120 #ifdef __APPLE_API_UNSTABLE
121 vm_offset_t
122 ml_static_ptovirt(
123 vm_offset_t);
124
125 #ifdef XNU_KERNEL_PRIVATE
126 vm_offset_t
127 ml_boot_ptovirt(
128 vm_offset_t);
129 #endif
130
131 /* PCI config cycle probing */
132 boolean_t ml_probe_read(
133 vm_offset_t paddr,
134 unsigned int *val);
135 boolean_t ml_probe_read_64(
136 addr64_t paddr,
137 unsigned int *val);
138
139 /* Read physical address byte */
140 unsigned int ml_phys_read_byte(
141 vm_offset_t paddr);
142 unsigned int ml_phys_read_byte_64(
143 addr64_t paddr);
144
145 /* Read physical address half word */
146 unsigned int ml_phys_read_half(
147 vm_offset_t paddr);
148 unsigned int ml_phys_read_half_64(
149 addr64_t paddr);
150
151 /* Read physical address word*/
152 unsigned int ml_phys_read(
153 vm_offset_t paddr);
154 unsigned int ml_phys_read_64(
155 addr64_t paddr);
156 unsigned int ml_phys_read_word(
157 vm_offset_t paddr);
158 unsigned int ml_phys_read_word_64(
159 addr64_t paddr);
160
161 /* Read physical address double word */
162 unsigned long long ml_phys_read_double(
163 vm_offset_t paddr);
164 unsigned long long ml_phys_read_double_64(
165 addr64_t paddr);
166
167 /* Write physical address byte */
168 void ml_phys_write_byte(
169 vm_offset_t paddr, unsigned int data);
170 void ml_phys_write_byte_64(
171 addr64_t paddr, unsigned int data);
172
173 /* Write physical address half word */
174 void ml_phys_write_half(
175 vm_offset_t paddr, unsigned int data);
176 void ml_phys_write_half_64(
177 addr64_t paddr, unsigned int data);
178
179 /* Write physical address word */
180 void ml_phys_write(
181 vm_offset_t paddr, unsigned int data);
182 void ml_phys_write_64(
183 addr64_t paddr, unsigned int data);
184 void ml_phys_write_word(
185 vm_offset_t paddr, unsigned int data);
186 void ml_phys_write_word_64(
187 addr64_t paddr, unsigned int data);
188
189 /* Write physical address double word */
190 void ml_phys_write_double(
191 vm_offset_t paddr, unsigned long long data);
192 void ml_phys_write_double_64(
193 addr64_t paddr, unsigned long long data);
194
195 void ml_static_mfree(
196 vm_offset_t,
197 vm_size_t);
198
199 /* virtual to physical on wired pages */
200 vm_offset_t ml_vtophys(
201 vm_offset_t vaddr);
202
203 /* Struct for ml_cpu_get_info */
204 struct ml_cpu_info {
205 unsigned long vector_unit;
206 unsigned long cache_line_size;
207 unsigned long l1_icache_size;
208 unsigned long l1_dcache_size;
209 unsigned long l2_settings;
210 unsigned long l2_cache_size;
211 unsigned long l3_settings;
212 unsigned long l3_cache_size;
213 };
214
215 typedef struct ml_cpu_info ml_cpu_info_t;
216
217 /* Get processor info */
218 void ml_cpu_get_info(ml_cpu_info_t *ml_cpu_info);
219
220 #endif /* __APPLE_API_UNSTABLE */
221
222 #ifdef __APPLE_API_PRIVATE
223 #if defined(PEXPERT_KERNEL_PRIVATE) || defined(MACH_KERNEL_PRIVATE)
224 /* IO memory map services */
225
226 /* Map memory map IO space */
227 vm_offset_t ml_io_map(
228 vm_offset_t phys_addr,
229 vm_size_t size);
230
231 /* boot memory allocation */
232 vm_offset_t ml_static_malloc(
233 vm_size_t size);
234
235
236 extern uint32_t bounce_pool_base;
237 extern uint32_t bounce_pool_size;
238
239 void ml_get_bouncepool_info(
240 vm_offset_t *phys_addr,
241 vm_size_t *size);
242
243
244 #endif /* PEXPERT_KERNEL_PRIVATE || MACH_KERNEL_PRIVATE */
245
246 /* Zero bytes starting at a physical address */
247 void bzero_phys(
248 addr64_t phys_address,
249 uint32_t length);
250
251 void ml_thread_policy(
252 thread_t thread,
253 unsigned policy_id,
254 unsigned policy_info);
255
256 #define MACHINE_GROUP 0x00000001
257 #define MACHINE_NETWORK_GROUP 0x10000000
258 #define MACHINE_NETWORK_WORKLOOP 0x00000001
259 #define MACHINE_NETWORK_NETISR 0x00000002
260
261 /* Initialize the maximum number of CPUs */
262 void ml_init_max_cpus(
263 unsigned long max_cpus);
264
265 /* Return the maximum number of CPUs set by ml_init_max_cpus() */
266 int ml_get_max_cpus(
267 void);
268
269 extern void ml_cpu_up(void);
270 extern void ml_cpu_down(void);
271
272 extern int set_be_bit(void);
273 extern int clr_be_bit(void);
274 extern int be_tracing(void);
275
276 extern void ml_set_maxsnoop(uint32_t maxdelay);
277 extern unsigned ml_get_maxsnoop(void);
278 extern void ml_set_maxbusdelay(uint32_t mdelay);
279 extern uint32_t ml_get_maxbusdelay(void);
280 extern void ml_hpet_cfg(uint32_t cpu, uint32_t hpetVect);
281
282 extern uint64_t tmrCvt(uint64_t time, uint64_t conversion);
283
284 #endif /* __APPLE_API_PRIVATE */
285
286 __END_DECLS
287
288 #endif /* _I386_MACHINE_ROUTINES_H_ */