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