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