]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
2d21ac55 | 2 | * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
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. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
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 | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
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. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * file: pe_init.c | |
30 | * i386 platform expert initialization. | |
31 | */ | |
32 | #include <sys/types.h> | |
33 | #include <mach/vm_param.h> | |
b0d623f7 | 34 | #include <machine/machine_routines.h> |
1c79356b A |
35 | #include <pexpert/protos.h> |
36 | #include <pexpert/pexpert.h> | |
37 | #include <pexpert/boot.h> | |
38 | #include <pexpert/device_tree.h> | |
39 | #include <pexpert/pe_images.h> | |
9bccf70c | 40 | #include <kern/sched_prim.h> |
0c530ab8 | 41 | #include <kern/debug.h> |
1c79356b | 42 | |
9bccf70c | 43 | #include "boot_images.h" |
1c79356b A |
44 | |
45 | /* extern references */ | |
46 | extern void pe_identify_machine(void * args); | |
7ddcb079 A |
47 | extern int |
48 | vc_display_lzss_icon(uint32_t dst_x, uint32_t dst_y, | |
49 | uint32_t image_width, uint32_t image_height, | |
50 | const uint8_t *compressed_image, | |
51 | uint32_t compressed_size, | |
52 | const uint8_t *clut); | |
1c79356b | 53 | |
1c79356b | 54 | /* private globals */ |
0b4e3aa0 | 55 | PE_state_t PE_state; |
1c79356b A |
56 | |
57 | /* Clock Frequency Info */ | |
58 | clock_frequency_info_t gPEClockFrequencyInfo; | |
59 | ||
2d21ac55 A |
60 | void *gPEEFISystemTable; |
61 | void *gPEEFIRuntimeServices; | |
0c530ab8 | 62 | |
7ddcb079 A |
63 | static boot_icon_element* norootIcon_lzss; |
64 | static const uint8_t* norootClut_lzss; | |
65 | ||
1c79356b A |
66 | int PE_initialize_console( PE_Video * info, int op ) |
67 | { | |
68 | static int last_console = -1; | |
1c79356b | 69 | |
2d21ac55 A |
70 | if (info) { |
71 | info->v_offset = 0; | |
72 | info->v_length = 0; | |
73 | info->v_display = GRAPHICS_MODE; | |
1c79356b | 74 | } |
1c79356b A |
75 | |
76 | switch ( op ) { | |
77 | ||
78 | case kPEDisableScreen: | |
2d21ac55 | 79 | initialize_screen(info, op); |
1c79356b | 80 | kprintf("kPEDisableScreen %d\n", last_console); |
0c530ab8 A |
81 | if (!console_is_serial()) |
82 | last_console = switch_to_serial_console(); | |
1c79356b A |
83 | break; |
84 | ||
85 | case kPEEnableScreen: | |
2d21ac55 | 86 | initialize_screen(info, op); |
060df5ea | 87 | if (info) PE_state.video = *info; |
1c79356b | 88 | kprintf("kPEEnableScreen %d\n", last_console); |
1c79356b A |
89 | if( last_console != -1) |
90 | switch_to_old_console( last_console); | |
1c79356b A |
91 | break; |
92 | ||
060df5ea A |
93 | case kPEBaseAddressChange: |
94 | if (info) PE_state.video = *info; | |
95 | /* fall thru */ | |
96 | ||
1c79356b | 97 | default: |
2d21ac55 | 98 | initialize_screen(info, op); |
1c79356b A |
99 | break; |
100 | } | |
101 | ||
102 | return 0; | |
103 | } | |
104 | ||
105 | void PE_init_iokit(void) | |
106 | { | |
91447636 | 107 | enum { kMaxBootVar = 128 }; |
9bccf70c | 108 | |
0b4e3aa0 A |
109 | typedef struct { |
110 | char name[32]; | |
111 | unsigned long length; | |
112 | unsigned long value[2]; | |
113 | } DriversPackageProp; | |
114 | ||
0c530ab8 | 115 | boolean_t bootClutInitialized = FALSE; |
7ddcb079 A |
116 | boolean_t noroot_rle_Initialized = FALSE; |
117 | ||
0c530ab8 | 118 | DTEntry entry; |
2d21ac55 | 119 | unsigned int size; |
b0d623f7 | 120 | uint32_t *map; |
2d21ac55 | 121 | boot_progress_element *bootPict; |
0c530ab8 | 122 | |
7ddcb079 A |
123 | norootIcon_lzss = NULL; |
124 | norootClut_lzss = NULL; | |
125 | ||
55e303ae A |
126 | PE_init_kprintf(TRUE); |
127 | PE_init_printf(TRUE); | |
128 | ||
0c530ab8 A |
129 | kprintf("Kernel boot args: '%s'\n", PE_boot_args()); |
130 | ||
0b4e3aa0 | 131 | /* |
0c530ab8 | 132 | * Fetch the CLUT and the noroot image. |
0b4e3aa0 A |
133 | */ |
134 | ||
2d21ac55 | 135 | if( kSuccess == DTLookupEntry(NULL, "/chosen/memory-map", &entry)) { |
7ddcb079 A |
136 | if( kSuccess == DTGetProperty(entry, "BootCLUT", (void **) &map, &size)) { |
137 | if (sizeof(appleClut8) <= map[1]) { | |
138 | bcopy( (void *)ml_static_ptovirt(map[0]), appleClut8, sizeof(appleClut8) ); | |
139 | bootClutInitialized = TRUE; | |
140 | } | |
141 | } | |
142 | ||
143 | if( kSuccess == DTGetProperty(entry, "Pict-FailedBoot", (void **) &map, &size)) { | |
144 | bootPict = (boot_progress_element *) ml_static_ptovirt(map[0]); | |
145 | default_noroot.width = bootPict->width; | |
146 | default_noroot.height = bootPict->height; | |
147 | default_noroot.dx = 0; | |
148 | default_noroot.dy = bootPict->yOffset; | |
149 | default_noroot_data = &bootPict->data[0]; | |
150 | noroot_rle_Initialized = TRUE; | |
151 | } | |
152 | ||
153 | if( kSuccess == DTGetProperty(entry, "FailedCLUT", (void **) &map, &size)) { | |
154 | norootClut_lzss = (uint8_t*) ml_static_ptovirt(map[0]); | |
155 | } | |
156 | ||
157 | if( kSuccess == DTGetProperty(entry, "FailedImage", (void **) &map, &size)) { | |
158 | norootIcon_lzss = (boot_icon_element *) ml_static_ptovirt(map[0]); | |
159 | if (norootClut_lzss == NULL) { | |
160 | printf("ERROR: No FailedCLUT provided for noroot icon!\n"); | |
161 | } | |
162 | } | |
4452a7af | 163 | } |
21362eb3 | 164 | |
0c530ab8 | 165 | if (!bootClutInitialized) { |
7ddcb079 | 166 | bcopy( (void *) (uintptr_t) bootClut, (void *) appleClut8, sizeof(appleClut8) ); |
0c530ab8 | 167 | } |
6601e61a | 168 | |
7ddcb079 A |
169 | if (!noroot_rle_Initialized) { |
170 | default_noroot.width = kFailedBootWidth; | |
171 | default_noroot.height = kFailedBootHeight; | |
172 | default_noroot.dx = 0; | |
173 | default_noroot.dy = kFailedBootOffset; | |
174 | default_noroot_data = failedBootPict; | |
0c530ab8 | 175 | } |
55e303ae A |
176 | |
177 | /* | |
178 | * Initialize the panic UI | |
179 | */ | |
180 | panic_ui_initialize( (unsigned char *) appleClut8 ); | |
1c79356b | 181 | |
9bccf70c A |
182 | /* |
183 | * Initialize the spinning wheel (progress indicator). | |
184 | */ | |
185 | vc_progress_initialize( &default_progress, default_progress_data, | |
186 | (unsigned char *) appleClut8 ); | |
1c79356b | 187 | |
2d21ac55 | 188 | (void) StartIOKit( PE_state.deviceTreeHead, PE_state.bootArgs, gPEEFIRuntimeServices, NULL); |
1c79356b A |
189 | } |
190 | ||
0c530ab8 | 191 | void PE_init_platform(boolean_t vm_initialized, void * _args) |
1c79356b | 192 | { |
0c530ab8 | 193 | boot_args *args = (boot_args *)_args; |
1c79356b | 194 | |
0c530ab8 | 195 | if (PE_state.initialized == FALSE) { |
1c79356b | 196 | PE_state.initialized = TRUE; |
0c530ab8 A |
197 | |
198 | // New EFI-style | |
199 | PE_state.bootArgs = _args; | |
b0d623f7 A |
200 | PE_state.deviceTreeHead = (void *) ml_static_ptovirt(args->deviceTreeP); |
201 | PE_state.video.v_baseAddr = args->Video.v_baseAddr; // remains physical address | |
0c530ab8 A |
202 | PE_state.video.v_rowBytes = args->Video.v_rowBytes; |
203 | PE_state.video.v_width = args->Video.v_width; | |
204 | PE_state.video.v_height = args->Video.v_height; | |
205 | PE_state.video.v_depth = args->Video.v_depth; | |
206 | PE_state.video.v_display = args->Video.v_display; | |
2d21ac55 A |
207 | strlcpy(PE_state.video.v_pixelFormat, "PPPPPPPP", |
208 | sizeof(PE_state.video.v_pixelFormat)); | |
0b4e3aa0 | 209 | } |
1c79356b | 210 | |
0c530ab8 | 211 | if (!vm_initialized) { |
6d2010ae | 212 | |
0c530ab8 A |
213 | if (PE_state.deviceTreeHead) { |
214 | DTInit(PE_state.deviceTreeHead); | |
b7266188 | 215 | } |
0c530ab8 A |
216 | |
217 | pe_identify_machine(args); | |
218 | } else { | |
0b4e3aa0 | 219 | pe_init_debug(); |
55e303ae | 220 | } |
b7266188 | 221 | |
1c79356b A |
222 | } |
223 | ||
224 | void PE_create_console( void ) | |
225 | { | |
0c530ab8 | 226 | if ( PE_state.video.v_display == GRAPHICS_MODE ) |
1c79356b A |
227 | PE_initialize_console( &PE_state.video, kPEGraphicsMode ); |
228 | else | |
229 | PE_initialize_console( &PE_state.video, kPETextMode ); | |
230 | } | |
231 | ||
232 | int PE_current_console( PE_Video * info ) | |
233 | { | |
234 | *info = PE_state.video; | |
235 | ||
1c79356b A |
236 | return (0); |
237 | } | |
238 | ||
91447636 | 239 | void PE_display_icon( __unused unsigned int flags, __unused const char * name ) |
1c79356b | 240 | { |
7ddcb079 A |
241 | if ( norootIcon_lzss && norootClut_lzss ) { |
242 | uint32_t width = norootIcon_lzss->width; | |
243 | uint32_t height = norootIcon_lzss->height; | |
244 | uint32_t x = ((PE_state.video.v_width - width) / 2); | |
245 | uint32_t y = ((PE_state.video.v_height - height) / 2) + norootIcon_lzss->y_offset_from_center; | |
246 | ||
247 | vc_display_lzss_icon(x, y, width, height, | |
248 | &norootIcon_lzss->data[0], | |
249 | norootIcon_lzss->data_size, | |
250 | norootClut_lzss); | |
251 | } | |
252 | else if ( default_noroot_data ) { | |
9bccf70c | 253 | vc_display_icon( &default_noroot, default_noroot_data ); |
7ddcb079 A |
254 | } else { |
255 | printf("ERROR: No data found for noroot icon!\n"); | |
256 | } | |
1c79356b A |
257 | } |
258 | ||
2d21ac55 A |
259 | boolean_t |
260 | PE_get_hotkey(__unused unsigned char key) | |
1c79356b A |
261 | { |
262 | return (FALSE); | |
263 | } | |
264 | ||
265 | static timebase_callback_func gTimebaseCallback; | |
266 | ||
267 | void PE_register_timebase_callback(timebase_callback_func callback) | |
268 | { | |
269 | gTimebaseCallback = callback; | |
270 | ||
271 | PE_call_timebase_callback(); | |
272 | } | |
273 | ||
274 | void PE_call_timebase_callback(void) | |
275 | { | |
276 | struct timebase_freq_t timebase_freq; | |
277 | unsigned long num, den, cnt; | |
278 | ||
279 | num = gPEClockFrequencyInfo.bus_clock_rate_num * gPEClockFrequencyInfo.bus_to_dec_rate_num; | |
280 | den = gPEClockFrequencyInfo.bus_clock_rate_den * gPEClockFrequencyInfo.bus_to_dec_rate_den; | |
281 | ||
282 | cnt = 2; | |
283 | while (cnt <= den) { | |
284 | if ((num % cnt) || (den % cnt)) { | |
285 | cnt++; | |
286 | continue; | |
287 | } | |
288 | ||
289 | num /= cnt; | |
290 | den /= cnt; | |
291 | } | |
292 | ||
293 | timebase_freq.timebase_num = num; | |
294 | timebase_freq.timebase_den = den; | |
295 | ||
296 | if (gTimebaseCallback) gTimebaseCallback(&timebase_freq); | |
297 | } | |
298 | ||
0b4e3aa0 A |
299 | /* |
300 | * The default (non-functional) PE_poll_input handler. | |
301 | */ | |
302 | static int | |
91447636 | 303 | PE_stub_poll_input(__unused unsigned int options, char * c) |
0b4e3aa0 A |
304 | { |
305 | *c = 0xff; | |
306 | return 1; /* 0 for success, 1 for unsupported */ | |
307 | } | |
308 | ||
309 | /* | |
310 | * Called by the kernel debugger to poll for keyboard input. | |
311 | * Keyboard drivers may replace the default stub function | |
312 | * with their polled-mode input function. | |
313 | */ | |
314 | int (*PE_poll_input)(unsigned int options, char * c) | |
315 | = PE_stub_poll_input; | |
55e303ae | 316 | |
b7266188 A |
317 | boolean_t |
318 | PE_reboot_on_panic(void) | |
319 | { | |
320 | return FALSE; | |
321 | } |