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