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)
49typedef void *cpu_id_t;
50#else
51typedef void *cpu_id_t;
52#endif
53
54
55void PE_enter_debugger(
56	const char *cause);
57
58void 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 */
67uint32_t PE_get_random_seed(
68	unsigned char * dst_random_seed,
69	uint32_t request_size);
70
71
72void PE_init_kprintf(
73	boolean_t vm_initialized);
74
75extern int32_t gPESerialBaud;
76
77unsigned int PE_init_taproot(vm_offset_t *taddr);
78
79extern void (*PE_kputc)(char c);
80
81void PE_init_printf(
82	boolean_t vm_initialized);
83
84extern void (*PE_putc)(char c);
85
86void PE_init_iokit(
87	void);
88
89struct clock_frequency_info_t {
90  unsigned long bus_clock_rate_hz;
91  unsigned long cpu_clock_rate_hz;
92  unsigned long dec_clock_rate_hz;
93  unsigned long bus_clock_rate_num;
94  unsigned long bus_clock_rate_den;
95  unsigned long bus_to_cpu_rate_num;
96  unsigned long bus_to_cpu_rate_den;
97  unsigned long bus_to_dec_rate_num;
98  unsigned long bus_to_dec_rate_den;
99  unsigned long timebase_frequency_hz;
100  unsigned long timebase_frequency_num;
101  unsigned long timebase_frequency_den;
102  unsigned long long bus_frequency_hz;
103  unsigned long long bus_frequency_min_hz;
104  unsigned long long bus_frequency_max_hz;
105  unsigned long long cpu_frequency_hz;
106  unsigned long long cpu_frequency_min_hz;
107  unsigned long long cpu_frequency_max_hz;
108  unsigned long long prf_frequency_hz;
109  unsigned long long prf_frequency_min_hz;
110  unsigned long long prf_frequency_max_hz;
111  unsigned long long mem_frequency_hz;
112  unsigned long long mem_frequency_min_hz;
113  unsigned long long mem_frequency_max_hz;
114  unsigned long long fix_frequency_hz;
115};
116
117typedef struct clock_frequency_info_t clock_frequency_info_t;
118
119extern clock_frequency_info_t gPEClockFrequencyInfo;
120
121struct timebase_freq_t {
122  unsigned long timebase_num;
123  unsigned long timebase_den;
124};
125
126typedef void (*timebase_callback_func)(struct timebase_freq_t *timebase_freq);
127
128void PE_register_timebase_callback(timebase_callback_func callback);
129
130void PE_call_timebase_callback(void);
131
132#ifdef KERNEL
133void PE_install_interrupt_handler(
134	void *nub, int source,
135        void *target, IOInterruptHandler handler, void *refCon);
136#endif
137
138#ifndef _FN_KPRINTF
139#define	_FN_KPRINTF
140void kprintf(const char *fmt, ...) __printflike(1,2);
141#endif
142
143#if KERNEL_PRIVATE
144void _consume_kprintf_args(int, ...);
145#endif
146
147#if CONFIG_NO_KPRINTF_STRINGS
148#if KERNEL_PRIVATE
149#define kprintf(x, ...) _consume_kprintf_args( 0, ## __VA_ARGS__ )
150#else
151#define kprintf(x, ...) do {} while (0)
152#endif
153#endif
154
155void init_display_putc(unsigned char *baseaddr, int rowbytes, int height);
156void display_putc(char c);
157
158enum {
159    kPEReadTOD,
160    kPEWriteTOD
161};
162extern int (*PE_read_write_time_of_day)(
163	unsigned int options,
164	long * secs);
165
166enum {
167    kPEWaitForInput 	= 0x00000001,
168    kPERawInput		= 0x00000002
169};
170extern int (*PE_poll_input)(
171	unsigned int options,
172	char * c);
173
174extern int (*PE_write_IIC)(
175	unsigned char addr,
176	unsigned char reg,
177	unsigned char data);
178
179/* Private Stuff - eventually put in pexpertprivate.h */
180enum {
181    kDebugTypeNone    = 0,
182    kDebugTypeDisplay = 1,
183    kDebugTypeSerial  = 2
184};
185
186/*  Scale factor values for PE_Video.v_scale */
187enum {
188   kPEScaleFactorUnknown = 0,
189   kPEScaleFactor1x      = 1,
190   kPEScaleFactor2x      = 2
191};
192
193struct PE_Video {
194        unsigned long   v_baseAddr;     /* Base address of video memory */
195        unsigned long   v_rowBytes;     /* Number of bytes per pixel row */
196        unsigned long   v_width;        /* Width */
197        unsigned long   v_height;       /* Height */
198        unsigned long   v_depth;        /* Pixel Depth */
199        unsigned long   v_display;      /* Text or Graphics */
200	char		v_pixelFormat[64];
201	unsigned long	v_offset;	/* offset into video memory to start at */
202	unsigned long	v_length;	/* length of video memory (0 for v_rowBytes * v_height) */
203	unsigned char	v_rotate;	/* Rotation: 0:normal, 1:right 90, 2:left 180, 3:left 90 */
204	unsigned char	v_scale;	/* Scale Factor for both X & Y */
205	char		reserved1[2];
206#ifdef __LP64__
207	long		reserved2;
208#else
209	long		v_baseAddrHigh;
210#endif
211};
212
213typedef struct PE_Video       PE_Video;
214
215extern void initialize_screen(PE_Video *, unsigned int);
216
217extern void dim_screen(void);
218
219extern int PE_current_console(
220	PE_Video *info);
221
222extern void PE_create_console(
223        void);
224
225extern int PE_initialize_console(
226	PE_Video *newInfo,
227	int op);
228
229#define kPEGraphicsMode		1
230#define kPETextMode		2
231#define kPETextScreen		3
232#define kPEAcquireScreen	4
233#define kPEReleaseScreen	5
234#define kPEEnableScreen	 	6
235#define kPEDisableScreen	7
236#define kPEBaseAddressChange	8
237#define kPERefreshBootGraphics	9
238
239extern void PE_display_icon( unsigned int flags,
240			     const char * name );
241
242typedef struct PE_state {
243	boolean_t	initialized;
244	PE_Video	video;
245	void		*deviceTreeHead;
246	void		*bootArgs;
247} PE_state_t;
248
249extern PE_state_t PE_state;
250
251extern char * PE_boot_args(
252	void);
253
254#if !defined(__LP64__) && !defined(__arm__)
255extern boolean_t PE_parse_boot_arg(
256	const char	*arg_string,
257	void    	*arg_ptr) __deprecated;
258#endif
259
260extern boolean_t PE_parse_boot_argn(
261	const char	*arg_string,
262	void    	*arg_ptr,
263	int			max_arg);
264
265extern boolean_t PE_get_default(
266	const char	*property_name,
267	void		*property_ptr,
268	unsigned int max_property);
269
270#define PE_default_value(_key, _variable, _default)	\
271	do {															  \
272		if (!PE_get_default((_key), &(_variable), sizeof(_variable))) \
273			_variable = _default;									  \
274	} while(0)
275
276enum {
277    kPEOptionKey	= 0x3a,
278    kPECommandKey	= 0x37,
279    kPEControlKey	= 0x36,
280    kPEShiftKey		= 0x38
281};
282
283extern boolean_t PE_get_hotkey(
284	unsigned char	key);
285
286extern kern_return_t PE_cpu_start(
287	cpu_id_t target,
288	vm_offset_t start_paddr,
289	vm_offset_t arg_paddr);
290
291extern void PE_cpu_halt(
292	cpu_id_t target);
293
294extern void PE_cpu_signal(
295	cpu_id_t source,
296	cpu_id_t target);
297
298extern void PE_cpu_machine_init(
299	cpu_id_t target,
300	boolean_t bootb);
301
302extern void PE_cpu_machine_quiesce(
303	cpu_id_t target);
304
305extern void pe_init_debug(void);
306
307extern boolean_t PE_imgsrc_mount_supported(void);
308
309
310#if KERNEL_PRIVATE
311boolean_t PE_reboot_on_panic(void);
312#endif
313
314__END_DECLS
315
316#endif /* _PEXPERT_PEXPERT_H_ */
317