]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/machine_routines.h
xnu-1504.9.17.tar.gz
[apple/xnu.git] / osfmk / i386 / machine_routines.h
1 /*
2 * Copyright (c) 2000-2009 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 #ifdef XNU_KERNEL_PRIVATE
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
71 /* Generate a fake interrupt */
72 void ml_cause_interrupt(void);
73
74 /* Initialize Interrupts */
75 void ml_install_interrupt_handler(
76 void *nub,
77 int source,
78 void *target,
79 IOInterruptHandler handler,
80 void *refCon);
81
82 void ml_get_timebase(unsigned long long *timestamp);
83 void ml_init_lock_timeout(void);
84
85 vm_offset_t
86 ml_static_ptovirt(
87 vm_offset_t);
88
89 void ml_static_mfree(
90 vm_offset_t,
91 vm_size_t);
92
93 /* boot memory allocation */
94 vm_offset_t ml_static_malloc(
95 vm_size_t size);
96
97 /* virtual to physical on wired pages */
98 vm_offset_t ml_vtophys(
99 vm_offset_t vaddr);
100
101 vm_size_t ml_nofault_copy(
102 vm_offset_t virtsrc, vm_offset_t virtdst, vm_size_t size);
103
104 /* Machine topology info */
105 uint64_t ml_cpu_cache_size(unsigned int level);
106 uint64_t ml_cpu_cache_sharing(unsigned int level);
107
108 /* Initialize the maximum number of CPUs */
109 void ml_init_max_cpus(
110 unsigned long max_cpus);
111
112 extern void ml_cpu_up(void);
113 extern void ml_cpu_down(void);
114
115 void bzero_phys_nc(
116 addr64_t phys_address,
117 uint32_t length);
118
119 #if defined(PEXPERT_KERNEL_PRIVATE) || defined(MACH_KERNEL_PRIVATE)
120 /* IO memory map services */
121
122 /* Map memory map IO space */
123 vm_offset_t ml_io_map(
124 vm_offset_t phys_addr,
125 vm_size_t size);
126
127
128 void ml_get_bouncepool_info(
129 vm_offset_t *phys_addr,
130 vm_size_t *size);
131
132
133 #endif /* PEXPERT_KERNEL_PRIVATE || MACH_KERNEL_PRIVATE */
134
135 #endif /* XNU_KERNEL_PRIVATE */
136
137 #ifdef KERNEL_PRIVATE
138
139 /* Type for the Time Base Enable function */
140 typedef void (*time_base_enable_t)(cpu_id_t cpu_id, boolean_t enable);
141
142 /* Type for the IPI Hander */
143 typedef void (*ipi_handler_t)(void);
144
145 /* Struct for ml_processor_register */
146 struct ml_processor_info {
147 cpu_id_t cpu_id;
148 boolean_t boot_cpu;
149 vm_offset_t start_paddr;
150 boolean_t supports_nap;
151 unsigned long l2cr_value;
152 time_base_enable_t time_base_enable;
153 };
154
155 typedef struct ml_processor_info ml_processor_info_t;
156
157
158 /* Register a processor */
159 kern_return_t
160 ml_processor_register(
161 cpu_id_t cpu_id,
162 uint32_t lapic_id,
163 processor_t *processor_out,
164 boolean_t boot_cpu,
165 boolean_t start );
166
167 /* PCI config cycle probing */
168 boolean_t ml_probe_read(
169 vm_offset_t paddr,
170 unsigned int *val);
171 boolean_t ml_probe_read_64(
172 addr64_t paddr,
173 unsigned int *val);
174
175 /* Read physical address byte */
176 unsigned int ml_phys_read_byte(
177 vm_offset_t paddr);
178 unsigned int ml_phys_read_byte_64(
179 addr64_t paddr);
180
181 /* Read physical address half word */
182 unsigned int ml_phys_read_half(
183 vm_offset_t paddr);
184 unsigned int ml_phys_read_half_64(
185 addr64_t paddr);
186
187 /* Read physical address word*/
188 unsigned int ml_phys_read(
189 vm_offset_t paddr);
190 unsigned int ml_phys_read_64(
191 addr64_t paddr);
192 unsigned int ml_phys_read_word(
193 vm_offset_t paddr);
194 unsigned int ml_phys_read_word_64(
195 addr64_t paddr);
196
197 /* Read physical address double word */
198 unsigned long long ml_phys_read_double(
199 vm_offset_t paddr);
200 unsigned long long ml_phys_read_double_64(
201 addr64_t paddr);
202
203 /* Write physical address byte */
204 void ml_phys_write_byte(
205 vm_offset_t paddr, unsigned int data);
206 void ml_phys_write_byte_64(
207 addr64_t paddr, unsigned int data);
208
209 /* Write physical address half word */
210 void ml_phys_write_half(
211 vm_offset_t paddr, unsigned int data);
212 void ml_phys_write_half_64(
213 addr64_t paddr, unsigned int data);
214
215 /* Write physical address word */
216 void ml_phys_write(
217 vm_offset_t paddr, unsigned int data);
218 void ml_phys_write_64(
219 addr64_t paddr, unsigned int data);
220 void ml_phys_write_word(
221 vm_offset_t paddr, unsigned int data);
222 void ml_phys_write_word_64(
223 addr64_t paddr, unsigned int data);
224
225 /* Write physical address double word */
226 void ml_phys_write_double(
227 vm_offset_t paddr, unsigned long long data);
228 void ml_phys_write_double_64(
229 addr64_t paddr, unsigned long long data);
230
231 /* Struct for ml_cpu_get_info */
232 struct ml_cpu_info {
233 unsigned long vector_unit;
234 unsigned long cache_line_size;
235 unsigned long l1_icache_size;
236 unsigned long l1_dcache_size;
237 unsigned long l2_settings;
238 unsigned long l2_cache_size;
239 unsigned long l3_settings;
240 unsigned long l3_cache_size;
241 };
242
243 typedef struct ml_cpu_info ml_cpu_info_t;
244
245 /* Get processor info */
246 void ml_cpu_get_info(ml_cpu_info_t *ml_cpu_info);
247
248 void ml_thread_policy(
249 thread_t thread,
250 unsigned policy_id,
251 unsigned policy_info);
252
253 #define MACHINE_GROUP 0x00000001
254 #define MACHINE_NETWORK_GROUP 0x10000000
255 #define MACHINE_NETWORK_WORKLOOP 0x00000001
256 #define MACHINE_NETWORK_NETISR 0x00000002
257
258 /* Return the maximum number of CPUs set by ml_init_max_cpus() */
259 int ml_get_max_cpus(
260 void);
261
262 /*
263 * The following are in pmCPU.c not machine_routines.c.
264 */
265 extern void ml_set_maxsnoop(uint32_t maxdelay);
266 extern unsigned ml_get_maxsnoop(void);
267 extern void ml_set_maxbusdelay(uint32_t mdelay);
268 extern uint32_t ml_get_maxbusdelay(void);
269 extern void ml_set_maxintdelay(uint64_t mdelay);
270 extern uint64_t ml_get_maxintdelay(void);
271
272
273 extern uint64_t tmrCvt(uint64_t time, uint64_t conversion);
274
275 extern uint64_t ml_cpu_int_event_time(void);
276
277 #endif /* KERNEL_PRIVATE */
278
279 /* Get Interrupts Enabled */
280 boolean_t ml_get_interrupts_enabled(void);
281
282 /* Set Interrupts Enabled */
283 boolean_t ml_set_interrupts_enabled(boolean_t enable);
284
285 /* Check if running at interrupt context */
286 boolean_t ml_at_interrupt_context(void);
287
288 /* Zero bytes starting at a physical address */
289 void bzero_phys(
290 addr64_t phys_address,
291 uint32_t length);
292
293 /* Bytes available on current stack */
294 vm_offset_t ml_stack_remaining(void);
295
296 #if CONFIG_COUNTERS
297 void ml_get_csw_threads(thread_t * /*old*/, thread_t * /*new*/);
298 #endif /* CONFIG_COUNTERS */
299
300 __END_DECLS
301
302 #endif /* _I386_MACHINE_ROUTINES_H_ */