]>
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 | |
1c79356b A |
57 | int PE_initialize_console( PE_Video * info, int op ) |
58 | { | |
59 | static int last_console = -1; | |
1c79356b | 60 | |
2d21ac55 A |
61 | if (info) { |
62 | info->v_offset = 0; | |
63 | info->v_length = 0; | |
64 | info->v_display = GRAPHICS_MODE; | |
1c79356b | 65 | } |
1c79356b A |
66 | |
67 | switch ( op ) { | |
68 | ||
69 | case kPEDisableScreen: | |
2d21ac55 | 70 | initialize_screen(info, op); |
1c79356b | 71 | kprintf("kPEDisableScreen %d\n", last_console); |
0c530ab8 A |
72 | if (!console_is_serial()) |
73 | last_console = switch_to_serial_console(); | |
1c79356b A |
74 | break; |
75 | ||
76 | case kPEEnableScreen: | |
2d21ac55 | 77 | initialize_screen(info, op); |
b0d623f7 | 78 | if (info) PE_state.video = *info; |
1c79356b | 79 | kprintf("kPEEnableScreen %d\n", last_console); |
1c79356b A |
80 | if( last_console != -1) |
81 | switch_to_old_console( last_console); | |
1c79356b A |
82 | break; |
83 | ||
84 | default: | |
2d21ac55 | 85 | initialize_screen(info, op); |
1c79356b A |
86 | break; |
87 | } | |
88 | ||
89 | return 0; | |
90 | } | |
91 | ||
92 | void PE_init_iokit(void) | |
93 | { | |
91447636 | 94 | enum { kMaxBootVar = 128 }; |
9bccf70c | 95 | |
0b4e3aa0 A |
96 | typedef struct { |
97 | char name[32]; | |
98 | unsigned long length; | |
99 | unsigned long value[2]; | |
100 | } DriversPackageProp; | |
101 | ||
0c530ab8 A |
102 | boolean_t bootClutInitialized = FALSE; |
103 | boolean_t norootInitialized = FALSE; | |
104 | DTEntry entry; | |
2d21ac55 | 105 | unsigned int size; |
b0d623f7 | 106 | uint32_t *map; |
2d21ac55 | 107 | boot_progress_element *bootPict; |
0c530ab8 | 108 | |
55e303ae A |
109 | PE_init_kprintf(TRUE); |
110 | PE_init_printf(TRUE); | |
111 | ||
0c530ab8 A |
112 | kprintf("Kernel boot args: '%s'\n", PE_boot_args()); |
113 | ||
0b4e3aa0 | 114 | /* |
0c530ab8 | 115 | * Fetch the CLUT and the noroot image. |
0b4e3aa0 A |
116 | */ |
117 | ||
2d21ac55 | 118 | if( kSuccess == DTLookupEntry(NULL, "/chosen/memory-map", &entry)) { |
0c530ab8 | 119 | if( kSuccess == DTGetProperty(entry, "BootCLUT", (void **) &map, &size)) { |
b0d623f7 A |
120 | if (sizeof(appleClut8) <= map[1]) { |
121 | bcopy( (void *)ml_static_ptovirt(map[0]), appleClut8, sizeof(appleClut8) ); | |
122 | bootClutInitialized = TRUE; | |
123 | } | |
124 | } | |
6601e61a | 125 | |
0c530ab8 | 126 | if( kSuccess == DTGetProperty(entry, "Pict-FailedBoot", (void **) &map, &size)) { |
b0d623f7 | 127 | bootPict = (boot_progress_element *) ml_static_ptovirt(map[0]); |
0c530ab8 A |
128 | default_noroot.width = bootPict->width; |
129 | default_noroot.height = bootPict->height; | |
130 | default_noroot.dx = 0; | |
131 | default_noroot.dy = bootPict->yOffset; | |
132 | default_noroot_data = &bootPict->data[0]; | |
133 | norootInitialized = TRUE; | |
134 | } | |
4452a7af | 135 | } |
21362eb3 | 136 | |
0c530ab8 | 137 | if (!bootClutInitialized) { |
6601e61a | 138 | bcopy( (void *) (uintptr_t) bootClut, (void *) appleClut8, sizeof(appleClut8) ); |
0c530ab8 | 139 | } |
6601e61a | 140 | |
0c530ab8 | 141 | if (!norootInitialized) { |
9bccf70c A |
142 | default_noroot.width = kFailedBootWidth; |
143 | default_noroot.height = kFailedBootHeight; | |
144 | default_noroot.dx = 0; | |
145 | default_noroot.dy = kFailedBootOffset; | |
146 | default_noroot_data = failedBootPict; | |
0c530ab8 | 147 | } |
55e303ae A |
148 | |
149 | /* | |
150 | * Initialize the panic UI | |
151 | */ | |
152 | panic_ui_initialize( (unsigned char *) appleClut8 ); | |
1c79356b | 153 | |
9bccf70c A |
154 | /* |
155 | * Initialize the spinning wheel (progress indicator). | |
156 | */ | |
157 | vc_progress_initialize( &default_progress, default_progress_data, | |
158 | (unsigned char *) appleClut8 ); | |
1c79356b | 159 | |
2d21ac55 | 160 | (void) StartIOKit( PE_state.deviceTreeHead, PE_state.bootArgs, gPEEFIRuntimeServices, NULL); |
1c79356b A |
161 | } |
162 | ||
0c530ab8 | 163 | void PE_init_platform(boolean_t vm_initialized, void * _args) |
1c79356b | 164 | { |
0c530ab8 | 165 | boot_args *args = (boot_args *)_args; |
1c79356b | 166 | |
0c530ab8 | 167 | if (PE_state.initialized == FALSE) { |
1c79356b | 168 | PE_state.initialized = TRUE; |
0c530ab8 A |
169 | |
170 | // New EFI-style | |
171 | PE_state.bootArgs = _args; | |
b0d623f7 A |
172 | PE_state.deviceTreeHead = (void *) ml_static_ptovirt(args->deviceTreeP); |
173 | PE_state.video.v_baseAddr = args->Video.v_baseAddr; // remains physical address | |
0c530ab8 A |
174 | PE_state.video.v_rowBytes = args->Video.v_rowBytes; |
175 | PE_state.video.v_width = args->Video.v_width; | |
176 | PE_state.video.v_height = args->Video.v_height; | |
177 | PE_state.video.v_depth = args->Video.v_depth; | |
178 | PE_state.video.v_display = args->Video.v_display; | |
2d21ac55 A |
179 | strlcpy(PE_state.video.v_pixelFormat, "PPPPPPPP", |
180 | sizeof(PE_state.video.v_pixelFormat)); | |
0b4e3aa0 | 181 | } |
1c79356b | 182 | |
0c530ab8 | 183 | if (!vm_initialized) { |
1c79356b A |
184 | /* Hack! FIXME.. */ |
185 | outb(0x21, 0xff); /* Maskout all interrupts Pic1 */ | |
186 | outb(0xa1, 0xff); /* Maskout all interrupts Pic2 */ | |
0c530ab8 A |
187 | if (PE_state.deviceTreeHead) { |
188 | DTInit(PE_state.deviceTreeHead); | |
b7266188 | 189 | } |
0c530ab8 A |
190 | |
191 | pe_identify_machine(args); | |
192 | } else { | |
0b4e3aa0 | 193 | pe_init_debug(); |
55e303ae | 194 | } |
b7266188 | 195 | |
1c79356b A |
196 | } |
197 | ||
198 | void PE_create_console( void ) | |
199 | { | |
0c530ab8 | 200 | if ( PE_state.video.v_display == GRAPHICS_MODE ) |
1c79356b A |
201 | PE_initialize_console( &PE_state.video, kPEGraphicsMode ); |
202 | else | |
203 | PE_initialize_console( &PE_state.video, kPETextMode ); | |
204 | } | |
205 | ||
206 | int PE_current_console( PE_Video * info ) | |
207 | { | |
208 | *info = PE_state.video; | |
209 | ||
1c79356b A |
210 | return (0); |
211 | } | |
212 | ||
91447636 | 213 | void PE_display_icon( __unused unsigned int flags, __unused const char * name ) |
1c79356b | 214 | { |
9bccf70c A |
215 | if ( default_noroot_data ) |
216 | vc_display_icon( &default_noroot, default_noroot_data ); | |
1c79356b A |
217 | } |
218 | ||
2d21ac55 A |
219 | boolean_t |
220 | PE_get_hotkey(__unused unsigned char key) | |
1c79356b A |
221 | { |
222 | return (FALSE); | |
223 | } | |
224 | ||
225 | static timebase_callback_func gTimebaseCallback; | |
226 | ||
227 | void PE_register_timebase_callback(timebase_callback_func callback) | |
228 | { | |
229 | gTimebaseCallback = callback; | |
230 | ||
231 | PE_call_timebase_callback(); | |
232 | } | |
233 | ||
234 | void PE_call_timebase_callback(void) | |
235 | { | |
236 | struct timebase_freq_t timebase_freq; | |
237 | unsigned long num, den, cnt; | |
238 | ||
239 | num = gPEClockFrequencyInfo.bus_clock_rate_num * gPEClockFrequencyInfo.bus_to_dec_rate_num; | |
240 | den = gPEClockFrequencyInfo.bus_clock_rate_den * gPEClockFrequencyInfo.bus_to_dec_rate_den; | |
241 | ||
242 | cnt = 2; | |
243 | while (cnt <= den) { | |
244 | if ((num % cnt) || (den % cnt)) { | |
245 | cnt++; | |
246 | continue; | |
247 | } | |
248 | ||
249 | num /= cnt; | |
250 | den /= cnt; | |
251 | } | |
252 | ||
253 | timebase_freq.timebase_num = num; | |
254 | timebase_freq.timebase_den = den; | |
255 | ||
256 | if (gTimebaseCallback) gTimebaseCallback(&timebase_freq); | |
257 | } | |
258 | ||
0b4e3aa0 A |
259 | /* |
260 | * The default (non-functional) PE_poll_input handler. | |
261 | */ | |
262 | static int | |
91447636 | 263 | PE_stub_poll_input(__unused unsigned int options, char * c) |
0b4e3aa0 A |
264 | { |
265 | *c = 0xff; | |
266 | return 1; /* 0 for success, 1 for unsupported */ | |
267 | } | |
268 | ||
269 | /* | |
270 | * Called by the kernel debugger to poll for keyboard input. | |
271 | * Keyboard drivers may replace the default stub function | |
272 | * with their polled-mode input function. | |
273 | */ | |
274 | int (*PE_poll_input)(unsigned int options, char * c) | |
275 | = PE_stub_poll_input; | |
55e303ae | 276 | |
b7266188 A |
277 | boolean_t |
278 | PE_reboot_on_panic(void) | |
279 | { | |
280 | return FALSE; | |
281 | } |