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