]> git.saurik.com Git - apple/xnu.git/blob - pexpert/pexpert/pexpert.h
e9e6c463da3b5a726da9d8574a097960f2842c38
[apple/xnu.git] / pexpert / pexpert / pexpert.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 #ifndef _PEXPERT_PEXPERT_H_
29 #define _PEXPERT_PEXPERT_H_
30
31 #include <sys/cdefs.h>
32
33 #ifdef KERNEL
34 #include <IOKit/IOInterrupts.h>
35 #include <kern/kern_types.h>
36 #endif
37
38 __BEGIN_DECLS
39 #include <mach/boolean.h>
40 #include <mach/kern_return.h>
41 #include <mach/machine/vm_types.h>
42
43 #ifdef PEXPERT_KERNEL_PRIVATE
44 #include <pexpert/protos.h>
45 #endif
46 #include <pexpert/boot.h>
47
48 #if defined(PEXPERT_KERNEL_PRIVATE) || defined(IOKIT_KERNEL_PRIVATE)
49 typedef void *cpu_id_t;
50 #else
51 typedef void *cpu_id_t;
52 #endif
53
54
55 void PE_enter_debugger(
56 const char *cause);
57
58 void PE_init_platform(
59 boolean_t vm_initialized,
60 void *args);
61
62 /*
63 * Copies the requested number of bytes from the "random-seed" property in
64 * the device tree, and zeros the corresponding bytes in the device tree.
65 * Returns the number of bytes actually copied.
66 */
67 uint32_t PE_get_random_seed(
68 unsigned char * dst_random_seed,
69 uint32_t request_size);
70
71 uint32_t PE_i_can_has_debugger(
72 uint32_t *);
73
74
75 #if KERNEL_PRIVATE
76
77 /*
78 * Kexts should consult this bitmask to change behavior, since the kernel
79 * may be configured as RELEASE but have MACH_ASSERT enabled, or boot args
80 * may have changed the kernel behavior for statistics and kexts should
81 * participate similarly
82 */
83
84 #define kPEICanHasAssertions 0x00000001 /* Exceptional conditions should panic() instead of printf() */
85 #define kPEICanHasStatistics 0x00000002 /* Gather expensive statistics (that don't otherwise change behavior */
86 #define kPEICanHasDiagnosticAPI 0x00000004 /* Vend API to userspace or kexts that introspect kernel state */
87
88 extern uint32_t PE_i_can_has_kernel_configuration(void);
89
90 #endif /* KERNEL_PRIVATE */
91
92 void PE_init_kprintf(
93 boolean_t vm_initialized);
94
95 extern int32_t gPESerialBaud;
96
97 extern uint8_t gPlatformECID[8];
98
99 extern uint32_t gPlatformMemoryID;
100
101 unsigned int PE_init_taproot(vm_offset_t *taddr);
102
103 extern void (*PE_kputc)(char c);
104
105 void PE_init_printf(
106 boolean_t vm_initialized);
107
108 extern void (*PE_putc)(char c);
109
110 void PE_init_iokit(
111 void);
112
113 struct clock_frequency_info_t {
114 unsigned long bus_clock_rate_hz;
115 unsigned long cpu_clock_rate_hz;
116 unsigned long dec_clock_rate_hz;
117 unsigned long bus_clock_rate_num;
118 unsigned long bus_clock_rate_den;
119 unsigned long bus_to_cpu_rate_num;
120 unsigned long bus_to_cpu_rate_den;
121 unsigned long bus_to_dec_rate_num;
122 unsigned long bus_to_dec_rate_den;
123 unsigned long timebase_frequency_hz;
124 unsigned long timebase_frequency_num;
125 unsigned long timebase_frequency_den;
126 unsigned long long bus_frequency_hz;
127 unsigned long long bus_frequency_min_hz;
128 unsigned long long bus_frequency_max_hz;
129 unsigned long long cpu_frequency_hz;
130 unsigned long long cpu_frequency_min_hz;
131 unsigned long long cpu_frequency_max_hz;
132 unsigned long long prf_frequency_hz;
133 unsigned long long prf_frequency_min_hz;
134 unsigned long long prf_frequency_max_hz;
135 unsigned long long mem_frequency_hz;
136 unsigned long long mem_frequency_min_hz;
137 unsigned long long mem_frequency_max_hz;
138 unsigned long long fix_frequency_hz;
139 };
140
141 typedef struct clock_frequency_info_t clock_frequency_info_t;
142
143 extern clock_frequency_info_t gPEClockFrequencyInfo;
144
145 struct timebase_freq_t {
146 unsigned long timebase_num;
147 unsigned long timebase_den;
148 };
149
150 typedef void (*timebase_callback_func)(struct timebase_freq_t *timebase_freq);
151
152 void PE_register_timebase_callback(timebase_callback_func callback);
153
154 void PE_call_timebase_callback(void);
155
156 #ifdef KERNEL
157 void PE_install_interrupt_handler(
158 void *nub, int source,
159 void *target, IOInterruptHandler handler, void *refCon);
160 #endif
161
162 #ifndef _FN_KPRINTF
163 #define _FN_KPRINTF
164 void kprintf(const char *fmt, ...) __printflike(1,2);
165 #endif
166
167 #if KERNEL_PRIVATE
168 void _consume_kprintf_args(int, ...);
169 #endif
170
171 #if CONFIG_NO_KPRINTF_STRINGS
172 #if KERNEL_PRIVATE
173 #define kprintf(x, ...) _consume_kprintf_args( 0, ## __VA_ARGS__ )
174 #else
175 #define kprintf(x, ...) do {} while (0)
176 #endif
177 #endif
178
179 void init_display_putc(unsigned char *baseaddr, int rowbytes, int height);
180 void display_putc(char c);
181
182 enum {
183 kPEReadTOD,
184 kPEWriteTOD
185 };
186 extern int (*PE_read_write_time_of_day)(
187 unsigned int options,
188 long * secs);
189
190 enum {
191 kPEWaitForInput = 0x00000001,
192 kPERawInput = 0x00000002
193 };
194 extern int (*PE_poll_input)(
195 unsigned int options,
196 char * c);
197
198 extern int (*PE_write_IIC)(
199 unsigned char addr,
200 unsigned char reg,
201 unsigned char data);
202
203 /* Private Stuff - eventually put in pexpertprivate.h */
204 enum {
205 kDebugTypeNone = 0,
206 kDebugTypeDisplay = 1,
207 kDebugTypeSerial = 2
208 };
209
210 /* Scale factor values for PE_Video.v_scale */
211 enum {
212 kPEScaleFactorUnknown = 0,
213 kPEScaleFactor1x = 1,
214 kPEScaleFactor2x = 2
215 };
216
217 struct PE_Video {
218 unsigned long v_baseAddr; /* Base address of video memory */
219 unsigned long v_rowBytes; /* Number of bytes per pixel row */
220 unsigned long v_width; /* Width */
221 unsigned long v_height; /* Height */
222 unsigned long v_depth; /* Pixel Depth */
223 unsigned long v_display; /* Text or Graphics */
224 char v_pixelFormat[64];
225 unsigned long v_offset; /* offset into video memory to start at */
226 unsigned long v_length; /* length of video memory (0 for v_rowBytes * v_height) */
227 unsigned char v_rotate; /* Rotation: 0:normal, 1:right 90, 2:left 180, 3:left 90 */
228 unsigned char v_scale; /* Scale Factor for both X & Y */
229 char reserved1[2];
230 #ifdef __LP64__
231 long reserved2;
232 #else
233 long v_baseAddrHigh;
234 #endif
235 };
236
237 typedef struct PE_Video PE_Video;
238
239 extern void initialize_screen(PE_Video *, unsigned int);
240
241 extern void dim_screen(void);
242
243 extern int PE_current_console(
244 PE_Video *info);
245
246 extern void PE_create_console(
247 void);
248
249 extern int PE_initialize_console(
250 PE_Video *newInfo,
251 int op);
252
253 #define kPEGraphicsMode 1
254 #define kPETextMode 2
255 #define kPETextScreen 3
256 #define kPEAcquireScreen 4
257 #define kPEReleaseScreen 5
258 #define kPEEnableScreen 6
259 #define kPEDisableScreen 7
260 #define kPEBaseAddressChange 8
261 #define kPERefreshBootGraphics 9
262
263 extern void PE_display_icon( unsigned int flags,
264 const char * name );
265
266 typedef struct PE_state {
267 boolean_t initialized;
268 PE_Video video;
269 void *deviceTreeHead;
270 void *bootArgs;
271 } PE_state_t;
272
273 extern PE_state_t PE_state;
274
275 extern char * PE_boot_args(
276 void);
277
278 #if !defined(__LP64__) && !defined(__arm__)
279 extern boolean_t PE_parse_boot_arg(
280 const char *arg_string,
281 void *arg_ptr) __deprecated;
282 #endif
283
284 extern boolean_t PE_parse_boot_argn(
285 const char *arg_string,
286 void *arg_ptr,
287 int max_arg);
288
289 #if XNU_KERNEL_PRIVATE
290 extern boolean_t PE_parse_boot_arg_str(
291 const char *arg_string,
292 char * arg_ptr,
293 int size);
294 #endif /* XNU_KERNEL_PRIVATE */
295
296 extern boolean_t PE_get_default(
297 const char *property_name,
298 void *property_ptr,
299 unsigned int max_property);
300
301 #define PE_default_value(_key, _variable, _default) \
302 do { \
303 if (!PE_get_default((_key), &(_variable), sizeof(_variable))) \
304 _variable = _default; \
305 } while(0)
306
307 enum {
308 kPEOptionKey = 0x3a,
309 kPECommandKey = 0x37,
310 kPEControlKey = 0x36,
311 kPEShiftKey = 0x38
312 };
313
314 extern boolean_t PE_get_hotkey(
315 unsigned char key);
316
317 extern kern_return_t PE_cpu_start(
318 cpu_id_t target,
319 vm_offset_t start_paddr,
320 vm_offset_t arg_paddr);
321
322 extern void PE_cpu_halt(
323 cpu_id_t target);
324
325 extern void PE_cpu_signal(
326 cpu_id_t source,
327 cpu_id_t target);
328
329 extern void PE_cpu_signal_deferred(
330 cpu_id_t source,
331 cpu_id_t target);
332
333 extern void PE_cpu_signal_cancel(
334 cpu_id_t source,
335 cpu_id_t target);
336
337 extern void PE_cpu_machine_init(
338 cpu_id_t target,
339 boolean_t bootb);
340
341 extern void PE_cpu_machine_quiesce(
342 cpu_id_t target);
343
344 extern void pe_init_debug(void);
345
346 extern boolean_t PE_imgsrc_mount_supported(void);
347
348
349 #if KERNEL_PRIVATE
350 boolean_t PE_reboot_on_panic(void);
351 void PE_sync_panic_buffers(void);
352 #endif
353
354 __END_DECLS
355
356 #endif /* _PEXPERT_PEXPERT_H_ */