]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/machine_routines.h
82b0bc240bac4bf7ca5691dcb1cfad8f87fbd68d
[apple/xnu.git] / osfmk / i386 / machine_routines.h
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, 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 /* Interrupt handling */
46
47 /* Initialize Interrupts */
48 void ml_init_interrupt(void);
49
50 /* Get Interrupts Enabled */
51 boolean_t ml_get_interrupts_enabled(void);
52
53 /* Set Interrupts Enabled */
54 boolean_t ml_set_interrupts_enabled(boolean_t enable);
55
56 /* Check if running at interrupt context */
57 boolean_t ml_at_interrupt_context(void);
58
59 /* Generate a fake interrupt */
60 void ml_cause_interrupt(void);
61
62 void ml_get_timebase(unsigned long long *timestamp);
63
64 /* Type for the Time Base Enable function */
65 typedef void (*time_base_enable_t)(cpu_id_t cpu_id, boolean_t enable);
66
67 /* Type for the IPI Hander */
68 typedef void (*ipi_handler_t)(void);
69
70 /* Struct for ml_processor_register */
71 struct ml_processor_info {
72 cpu_id_t cpu_id;
73 boolean_t boot_cpu;
74 vm_offset_t start_paddr;
75 boolean_t supports_nap;
76 unsigned long l2cr_value;
77 time_base_enable_t time_base_enable;
78 };
79
80 typedef struct ml_processor_info ml_processor_info_t;
81
82
83 /* Register a processor */
84 kern_return_t ml_processor_register(
85 cpu_id_t cpu_id,
86 uint32_t lapic_id,
87 processor_t *processor,
88 ipi_handler_t *ipi_handler,
89 boolean_t boot_cpu);
90
91 /* Initialize Interrupts */
92 void ml_install_interrupt_handler(
93 void *nub,
94 int source,
95 void *target,
96 IOInterruptHandler handler,
97 void *refCon);
98
99 #ifdef __APPLE_API_UNSTABLE
100 vm_offset_t
101 ml_static_ptovirt(
102 vm_offset_t);
103
104 /* PCI config cycle probing */
105 boolean_t ml_probe_read(
106 vm_offset_t paddr,
107 unsigned int *val);
108 boolean_t ml_probe_read_64(
109 addr64_t paddr,
110 unsigned int *val);
111
112 /* Read physical address byte */
113 unsigned int ml_phys_read_byte(
114 vm_offset_t paddr);
115 unsigned int ml_phys_read_byte_64(
116 addr64_t paddr);
117
118 /* Read physical address half word */
119 unsigned int ml_phys_read_half(
120 vm_offset_t paddr);
121 unsigned int ml_phys_read_half_64(
122 addr64_t paddr);
123
124 /* Read physical address word*/
125 unsigned int ml_phys_read(
126 vm_offset_t paddr);
127 unsigned int ml_phys_read_64(
128 addr64_t paddr);
129 unsigned int ml_phys_read_word(
130 vm_offset_t paddr);
131 unsigned int ml_phys_read_word_64(
132 addr64_t paddr);
133
134 /* Read physical address double word */
135 unsigned long long ml_phys_read_double(
136 vm_offset_t paddr);
137 unsigned long long ml_phys_read_double_64(
138 addr64_t paddr);
139
140 /* Write physical address byte */
141 void ml_phys_write_byte(
142 vm_offset_t paddr, unsigned int data);
143 void ml_phys_write_byte_64(
144 addr64_t paddr, unsigned int data);
145
146 /* Write physical address half word */
147 void ml_phys_write_half(
148 vm_offset_t paddr, unsigned int data);
149 void ml_phys_write_half_64(
150 addr64_t paddr, unsigned int data);
151
152 /* Write physical address word */
153 void ml_phys_write(
154 vm_offset_t paddr, unsigned int data);
155 void ml_phys_write_64(
156 addr64_t paddr, unsigned int data);
157 void ml_phys_write_word(
158 vm_offset_t paddr, unsigned int data);
159 void ml_phys_write_word_64(
160 addr64_t paddr, unsigned int data);
161
162 /* Write physical address double word */
163 void ml_phys_write_double(
164 vm_offset_t paddr, unsigned long long data);
165 void ml_phys_write_double_64(
166 addr64_t paddr, unsigned long long data);
167
168 void ml_static_mfree(
169 vm_offset_t,
170 vm_size_t);
171
172 /* virtual to physical on wired pages */
173 vm_offset_t ml_vtophys(
174 vm_offset_t vaddr);
175
176 /* Struct for ml_cpu_get_info */
177 struct ml_cpu_info {
178 unsigned long vector_unit;
179 unsigned long cache_line_size;
180 unsigned long l1_icache_size;
181 unsigned long l1_dcache_size;
182 unsigned long l2_settings;
183 unsigned long l2_cache_size;
184 unsigned long l3_settings;
185 unsigned long l3_cache_size;
186 };
187
188 typedef struct ml_cpu_info ml_cpu_info_t;
189
190 /* Get processor info */
191 void ml_cpu_get_info(ml_cpu_info_t *ml_cpu_info);
192
193 #endif /* __APPLE_API_UNSTABLE */
194
195 #ifdef __APPLE_API_PRIVATE
196 #if defined(PEXPERT_KERNEL_PRIVATE) || defined(MACH_KERNEL_PRIVATE)
197 /* IO memory map services */
198
199 /* Map memory map IO space */
200 vm_offset_t ml_io_map(
201 vm_offset_t phys_addr,
202 vm_size_t size);
203
204 /* boot memory allocation */
205 vm_offset_t ml_static_malloc(
206 vm_size_t size);
207
208 #endif /* PEXPERT_KERNEL_PRIVATE || MACH_KERNEL_PRIVATE */
209
210 /* Zero bytes starting at a physical address */
211 void bzero_phys(
212 addr64_t phys_address,
213 uint32_t length);
214
215 void ml_thread_policy(
216 thread_t thread,
217 unsigned policy_id,
218 unsigned policy_info);
219
220 #define MACHINE_GROUP 0x00000001
221 #define MACHINE_NETWORK_GROUP 0x10000000
222 #define MACHINE_NETWORK_WORKLOOP 0x00000001
223 #define MACHINE_NETWORK_NETISR 0x00000002
224
225 /* Initialize the maximum number of CPUs */
226 void ml_init_max_cpus(
227 unsigned long max_cpus);
228
229 /* Return the maximum number of CPUs set by ml_init_max_cpus() */
230 int ml_get_max_cpus(
231 void);
232
233 extern void ml_cpu_up(void);
234 extern void ml_cpu_down(void);
235
236 extern int set_be_bit(void);
237 extern int clr_be_bit(void);
238 extern int be_tracing(void);
239
240 #endif /* __APPLE_API_PRIVATE */
241
242 __END_DECLS
243
244 #endif /* _I386_MACHINE_ROUTINES_H_ */