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