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