]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/machine_routines.h
xnu-1228.0.2.tar.gz
[apple/xnu.git] / osfmk / i386 / machine_routines.h
1 /*
2 * Copyright (c) 2000-2007 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 _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
40 #include <sys/cdefs.h>
41 #include <sys/appleapiopts.h>
42
43 __BEGIN_DECLS
44
45 /* are we a 64 bit platform ? */
46
47 boolean_t ml_is64bit(void);
48
49 /* is this a 64bit thread? */
50
51 boolean_t ml_thread_is64bit(thread_t);
52
53 /* is this a 64bit thread? */
54
55 boolean_t ml_state_is64bit(void *);
56
57 /* set state of fpu save area for signal handling */
58
59 void ml_fp_setvalid(boolean_t);
60
61 void ml_cpu_set_ldt(int);
62
63 /* Interrupt handling */
64
65 /* Initialize Interrupts */
66 void ml_init_interrupt(void);
67
68 /* Get Interrupts Enabled */
69 boolean_t ml_get_interrupts_enabled(void);
70
71 /* Set Interrupts Enabled */
72 boolean_t ml_set_interrupts_enabled(boolean_t enable);
73
74 /* Check if running at interrupt context */
75 boolean_t ml_at_interrupt_context(void);
76
77 /* Generate a fake interrupt */
78 void ml_cause_interrupt(void);
79
80 void ml_get_timebase(unsigned long long *timestamp);
81 void ml_init_lock_timeout(void);
82
83 /* Type for the Time Base Enable function */
84 typedef void (*time_base_enable_t)(cpu_id_t cpu_id, boolean_t enable);
85
86 /* Type for the IPI Hander */
87 typedef void (*ipi_handler_t)(void);
88
89 /* Struct for ml_processor_register */
90 struct ml_processor_info {
91 cpu_id_t cpu_id;
92 boolean_t boot_cpu;
93 vm_offset_t start_paddr;
94 boolean_t supports_nap;
95 unsigned long l2cr_value;
96 time_base_enable_t time_base_enable;
97 };
98
99 typedef struct ml_processor_info ml_processor_info_t;
100
101
102 /* Register a processor */
103 kern_return_t ml_processor_register(
104 cpu_id_t cpu_id,
105 uint32_t lapic_id,
106 processor_t *processor,
107 ipi_handler_t *ipi_handler,
108 boolean_t boot_cpu);
109
110 /* Initialize Interrupts */
111 void ml_install_interrupt_handler(
112 void *nub,
113 int source,
114 void *target,
115 IOInterruptHandler handler,
116 void *refCon);
117
118 #ifdef __APPLE_API_UNSTABLE
119 vm_offset_t
120 ml_static_ptovirt(
121 vm_offset_t);
122
123 #ifdef XNU_KERNEL_PRIVATE
124 vm_offset_t
125 ml_boot_ptovirt(
126 vm_offset_t);
127 #endif
128
129 /* PCI config cycle probing */
130 boolean_t ml_probe_read(
131 vm_offset_t paddr,
132 unsigned int *val);
133 boolean_t ml_probe_read_64(
134 addr64_t paddr,
135 unsigned int *val);
136
137 /* Read physical address byte */
138 unsigned int ml_phys_read_byte(
139 vm_offset_t paddr);
140 unsigned int ml_phys_read_byte_64(
141 addr64_t paddr);
142
143 /* Read physical address half word */
144 unsigned int ml_phys_read_half(
145 vm_offset_t paddr);
146 unsigned int ml_phys_read_half_64(
147 addr64_t paddr);
148
149 /* Read physical address word*/
150 unsigned int ml_phys_read(
151 vm_offset_t paddr);
152 unsigned int ml_phys_read_64(
153 addr64_t paddr);
154 unsigned int ml_phys_read_word(
155 vm_offset_t paddr);
156 unsigned int ml_phys_read_word_64(
157 addr64_t paddr);
158
159 /* Read physical address double word */
160 unsigned long long ml_phys_read_double(
161 vm_offset_t paddr);
162 unsigned long long ml_phys_read_double_64(
163 addr64_t paddr);
164
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);
170
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);
176
177 /* Write physical address word */
178 void ml_phys_write(
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);
186
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);
192
193 void ml_static_mfree(
194 vm_offset_t,
195 vm_size_t);
196
197 /* virtual to physical on wired pages */
198 vm_offset_t ml_vtophys(
199 vm_offset_t vaddr);
200
201 vm_size_t ml_nofault_copy(
202 vm_offset_t virtsrc, vm_offset_t virtdst, vm_size_t size);
203
204 /* Struct for ml_cpu_get_info */
205 struct ml_cpu_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;
214 };
215
216 typedef struct ml_cpu_info ml_cpu_info_t;
217
218 /* Get processor info */
219 void ml_cpu_get_info(ml_cpu_info_t *ml_cpu_info);
220
221 /* Machine topology info */
222 uint64_t ml_cpu_cache_size(unsigned int level);
223 uint64_t ml_cpu_cache_sharing(unsigned int level);
224
225 #endif /* __APPLE_API_UNSTABLE */
226
227 #ifdef __APPLE_API_PRIVATE
228 #if defined(PEXPERT_KERNEL_PRIVATE) || defined(MACH_KERNEL_PRIVATE)
229 /* IO memory map services */
230
231 /* Map memory map IO space */
232 vm_offset_t ml_io_map(
233 vm_offset_t phys_addr,
234 vm_size_t size);
235
236 /* boot memory allocation */
237 vm_offset_t ml_static_malloc(
238 vm_size_t size);
239
240
241 extern uint32_t bounce_pool_base;
242 extern uint32_t bounce_pool_size;
243
244 void ml_get_bouncepool_info(
245 vm_offset_t *phys_addr,
246 vm_size_t *size);
247
248
249 #endif /* PEXPERT_KERNEL_PRIVATE || MACH_KERNEL_PRIVATE */
250
251 /* Zero bytes starting at a physical address */
252 void bzero_phys(
253 addr64_t phys_address,
254 uint32_t length);
255
256 void bzero_phys_nc(
257 addr64_t phys_address,
258 uint32_t length);
259
260 void ml_thread_policy(
261 thread_t thread,
262 unsigned policy_id,
263 unsigned policy_info);
264
265 #define MACHINE_GROUP 0x00000001
266 #define MACHINE_NETWORK_GROUP 0x10000000
267 #define MACHINE_NETWORK_WORKLOOP 0x00000001
268 #define MACHINE_NETWORK_NETISR 0x00000002
269
270 /* Initialize the maximum number of CPUs */
271 void ml_init_max_cpus(
272 unsigned long max_cpus);
273
274 /* Return the maximum number of CPUs set by ml_init_max_cpus() */
275 int ml_get_max_cpus(
276 void);
277
278 extern void ml_cpu_up(void);
279 extern void ml_cpu_down(void);
280
281 /*
282 * The following are in pmCPU.c not machine_routines.c.
283 */
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);
288
289
290 extern void ml_hpet_cfg(uint32_t cpu, uint32_t hpetVect);
291
292 extern uint64_t tmrCvt(uint64_t time, uint64_t conversion);
293
294 extern uint64_t ml_cpu_int_event_time(void);
295
296 #endif /* __APPLE_API_PRIVATE */
297
298 __END_DECLS
299
300 #endif /* _I386_MACHINE_ROUTINES_H_ */