]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
37839358 A |
6 | * The contents of this file constitute Original Code as defined in and |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
1c79356b | 11 | * |
37839358 A |
12 | * This Original Code and all software distributed under the License are |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
37839358 A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
1c79356b A |
19 | * |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * file: pe_init.c | |
24 | * i386 platform expert initialization. | |
25 | */ | |
26 | #include <sys/types.h> | |
27 | #include <mach/vm_param.h> | |
28 | #include <pexpert/protos.h> | |
29 | #include <pexpert/pexpert.h> | |
30 | #include <pexpert/boot.h> | |
31 | #include <pexpert/device_tree.h> | |
32 | #include <pexpert/pe_images.h> | |
9bccf70c | 33 | #include <kern/sched_prim.h> |
c0fea474 | 34 | #include <kern/debug.h> |
1c79356b A |
35 | |
36 | #include "fakePPCStructs.h" | |
37 | #include "fakePPCDeviceTree.h" | |
9bccf70c | 38 | #include "boot_images.h" |
1c79356b A |
39 | |
40 | /* extern references */ | |
41 | extern void pe_identify_machine(void * args); | |
42 | extern void initialize_screen(void *, unsigned int); | |
43 | ||
1c79356b | 44 | /* private globals */ |
0b4e3aa0 A |
45 | PE_state_t PE_state; |
46 | dt_data gMemoryMapNode; | |
47 | dt_data gDriversProp; | |
91447636 A |
48 | dt_data gRootpathProp; |
49 | dt_data gCompatibleProp; | |
1c79356b A |
50 | |
51 | /* Clock Frequency Info */ | |
52 | clock_frequency_info_t gPEClockFrequencyInfo; | |
53 | ||
c0fea474 A |
54 | void *gPEEFISystemTable = 0; |
55 | void *gPEEFIRuntimeServices = 0; | |
56 | ||
1c79356b A |
57 | int PE_initialize_console( PE_Video * info, int op ) |
58 | { | |
59 | static int last_console = -1; | |
60 | Boot_Video bootInfo; | |
61 | Boot_Video * bInfo; | |
62 | ||
63 | /* | |
64 | * Refuse changes from outside pexpert. | |
65 | * The video mode setup by the booter cannot be changed. | |
66 | */ | |
91447636 | 67 | if ( info ) |
1c79356b | 68 | { |
91447636 | 69 | bootInfo.v_baseAddr = info->v_baseAddr; |
1c79356b A |
70 | bootInfo.v_rowBytes = info->v_rowBytes; |
71 | bootInfo.v_width = info->v_width; | |
72 | bootInfo.v_height = info->v_height; | |
73 | bootInfo.v_depth = info->v_depth; | |
1c79356b | 74 | bInfo = &bootInfo; |
91447636 | 75 | if (info == &PE_state.video) { |
c0fea474 | 76 | bootInfo.v_display = info->v_display; |
91447636 A |
77 | } else { |
78 | bootInfo.v_display = GRAPHICS_MODE; | |
79 | } | |
1c79356b A |
80 | } |
81 | else | |
82 | bInfo = 0; | |
83 | ||
84 | switch ( op ) { | |
85 | ||
86 | case kPEDisableScreen: | |
87 | initialize_screen((void *) bInfo, op); | |
1c79356b | 88 | kprintf("kPEDisableScreen %d\n", last_console); |
c0fea474 A |
89 | if (!console_is_serial()) |
90 | last_console = switch_to_serial_console(); | |
1c79356b A |
91 | break; |
92 | ||
93 | case kPEEnableScreen: | |
94 | initialize_screen((void *) bInfo, op); | |
95 | kprintf("kPEEnableScreen %d\n", last_console); | |
1c79356b A |
96 | if( last_console != -1) |
97 | switch_to_old_console( last_console); | |
1c79356b A |
98 | break; |
99 | ||
100 | default: | |
101 | initialize_screen((void *) bInfo, op); | |
102 | break; | |
103 | } | |
104 | ||
105 | return 0; | |
106 | } | |
107 | ||
108 | void PE_init_iokit(void) | |
109 | { | |
91447636 | 110 | enum { kMaxBootVar = 128 }; |
9bccf70c | 111 | |
0b4e3aa0 A |
112 | typedef struct { |
113 | char name[32]; | |
114 | unsigned long length; | |
115 | unsigned long value[2]; | |
116 | } DriversPackageProp; | |
117 | ||
c0fea474 A |
118 | boolean_t bootClutInitialized = FALSE; |
119 | boolean_t norootInitialized = FALSE; | |
120 | DTEntry entry; | |
121 | int size; | |
122 | void ** map; | |
123 | ||
55e303ae A |
124 | PE_init_kprintf(TRUE); |
125 | PE_init_printf(TRUE); | |
126 | ||
c0fea474 A |
127 | kprintf("Kernel boot args: '%s'\n", PE_boot_args()); |
128 | ||
0b4e3aa0 | 129 | /* |
c0fea474 | 130 | * Fetch the CLUT and the noroot image. |
0b4e3aa0 | 131 | */ |
c0fea474 | 132 | boot_progress_element * bootPict; |
0b4e3aa0 | 133 | |
c0fea474 A |
134 | if( kSuccess == DTLookupEntry(0, "/chosen/memory-map", &entry)) { |
135 | if( kSuccess == DTGetProperty(entry, "BootCLUT", (void **) &map, &size)) { | |
136 | bcopy( map[0], appleClut8, sizeof(appleClut8) ); | |
137 | bootClutInitialized = TRUE; | |
0b4e3aa0 A |
138 | } |
139 | ||
c0fea474 A |
140 | if( kSuccess == DTGetProperty(entry, "Pict-FailedBoot", (void **) &map, &size)) { |
141 | bootPict = (boot_progress_element *) map[0]; | |
142 | default_noroot.width = bootPict->width; | |
143 | default_noroot.height = bootPict->height; | |
144 | default_noroot.dx = 0; | |
145 | default_noroot.dy = bootPict->yOffset; | |
146 | default_noroot_data = &bootPict->data[0]; | |
147 | norootInitialized = TRUE; | |
148 | } | |
0b4e3aa0 | 149 | } |
1c79356b | 150 | |
c0fea474 | 151 | if (!bootClutInitialized) { |
91447636 | 152 | bcopy( (void *) (uintptr_t) bootClut, (void *) appleClut8, sizeof(appleClut8) ); |
c0fea474 | 153 | } |
9bccf70c | 154 | |
c0fea474 | 155 | if (!norootInitialized) { |
9bccf70c A |
156 | default_noroot.width = kFailedBootWidth; |
157 | default_noroot.height = kFailedBootHeight; | |
158 | default_noroot.dx = 0; | |
159 | default_noroot.dy = kFailedBootOffset; | |
160 | default_noroot_data = failedBootPict; | |
c0fea474 | 161 | } |
55e303ae A |
162 | |
163 | /* | |
164 | * Initialize the panic UI | |
165 | */ | |
166 | panic_ui_initialize( (unsigned char *) appleClut8 ); | |
1c79356b | 167 | |
9bccf70c A |
168 | /* |
169 | * Initialize the spinning wheel (progress indicator). | |
170 | */ | |
171 | vc_progress_initialize( &default_progress, default_progress_data, | |
172 | (unsigned char *) appleClut8 ); | |
1c79356b | 173 | |
c0fea474 | 174 | (void) StartIOKit( PE_state.deviceTreeHead, PE_state.bootArgs, gPEEFIRuntimeServices, 0); |
1c79356b A |
175 | } |
176 | ||
c0fea474 | 177 | void PE_init_platform(boolean_t vm_initialized, void * _args) |
1c79356b | 178 | { |
c0fea474 | 179 | boot_args *args = (boot_args *)_args; |
1c79356b | 180 | |
c0fea474 | 181 | if (PE_state.initialized == FALSE) { |
1c79356b | 182 | PE_state.initialized = TRUE; |
c0fea474 A |
183 | |
184 | // New EFI-style | |
185 | PE_state.bootArgs = _args; | |
186 | PE_state.deviceTreeHead = args->deviceTreeP; | |
187 | PE_state.video.v_baseAddr = args->Video.v_baseAddr; | |
188 | PE_state.video.v_rowBytes = args->Video.v_rowBytes; | |
189 | PE_state.video.v_width = args->Video.v_width; | |
190 | PE_state.video.v_height = args->Video.v_height; | |
191 | PE_state.video.v_depth = args->Video.v_depth; | |
192 | PE_state.video.v_display = args->Video.v_display; | |
193 | strcpy( PE_state.video.v_pixelFormat, "PPPPPPPP"); | |
0b4e3aa0 | 194 | } |
1c79356b | 195 | |
c0fea474 | 196 | if (!vm_initialized) { |
1c79356b A |
197 | /* Hack! FIXME.. */ |
198 | outb(0x21, 0xff); /* Maskout all interrupts Pic1 */ | |
199 | outb(0xa1, 0xff); /* Maskout all interrupts Pic2 */ | |
200 | ||
c0fea474 A |
201 | if (PE_state.deviceTreeHead) { |
202 | DTInit(PE_state.deviceTreeHead); | |
55e303ae | 203 | } |
c0fea474 A |
204 | |
205 | pe_identify_machine(args); | |
206 | } else { | |
207 | DTEntry entry; | |
208 | void *ptr; | |
209 | uint32_t size; | |
210 | ||
0b4e3aa0 | 211 | pe_init_debug(); |
55e303ae | 212 | } |
1c79356b A |
213 | } |
214 | ||
215 | void PE_create_console( void ) | |
216 | { | |
c0fea474 | 217 | if ( PE_state.video.v_display == GRAPHICS_MODE ) |
1c79356b A |
218 | PE_initialize_console( &PE_state.video, kPEGraphicsMode ); |
219 | else | |
220 | PE_initialize_console( &PE_state.video, kPETextMode ); | |
221 | } | |
222 | ||
223 | int PE_current_console( PE_Video * info ) | |
224 | { | |
225 | *info = PE_state.video; | |
226 | ||
1c79356b A |
227 | return (0); |
228 | } | |
229 | ||
91447636 | 230 | void PE_display_icon( __unused unsigned int flags, __unused const char * name ) |
1c79356b | 231 | { |
9bccf70c A |
232 | if ( default_noroot_data ) |
233 | vc_display_icon( &default_noroot, default_noroot_data ); | |
1c79356b A |
234 | } |
235 | ||
91447636 | 236 | extern boolean_t PE_get_hotkey( __unused unsigned char key ) |
1c79356b A |
237 | { |
238 | return (FALSE); | |
239 | } | |
240 | ||
241 | static timebase_callback_func gTimebaseCallback; | |
242 | ||
243 | void PE_register_timebase_callback(timebase_callback_func callback) | |
244 | { | |
245 | gTimebaseCallback = callback; | |
246 | ||
247 | PE_call_timebase_callback(); | |
248 | } | |
249 | ||
250 | void PE_call_timebase_callback(void) | |
251 | { | |
252 | struct timebase_freq_t timebase_freq; | |
253 | unsigned long num, den, cnt; | |
254 | ||
255 | num = gPEClockFrequencyInfo.bus_clock_rate_num * gPEClockFrequencyInfo.bus_to_dec_rate_num; | |
256 | den = gPEClockFrequencyInfo.bus_clock_rate_den * gPEClockFrequencyInfo.bus_to_dec_rate_den; | |
257 | ||
258 | cnt = 2; | |
259 | while (cnt <= den) { | |
260 | if ((num % cnt) || (den % cnt)) { | |
261 | cnt++; | |
262 | continue; | |
263 | } | |
264 | ||
265 | num /= cnt; | |
266 | den /= cnt; | |
267 | } | |
268 | ||
269 | timebase_freq.timebase_num = num; | |
270 | timebase_freq.timebase_den = den; | |
271 | ||
272 | if (gTimebaseCallback) gTimebaseCallback(&timebase_freq); | |
273 | } | |
274 | ||
0b4e3aa0 A |
275 | /* |
276 | * The default (non-functional) PE_poll_input handler. | |
277 | */ | |
278 | static int | |
91447636 | 279 | PE_stub_poll_input(__unused unsigned int options, char * c) |
0b4e3aa0 A |
280 | { |
281 | *c = 0xff; | |
282 | return 1; /* 0 for success, 1 for unsupported */ | |
283 | } | |
284 | ||
285 | /* | |
286 | * Called by the kernel debugger to poll for keyboard input. | |
287 | * Keyboard drivers may replace the default stub function | |
288 | * with their polled-mode input function. | |
289 | */ | |
290 | int (*PE_poll_input)(unsigned int options, char * c) | |
291 | = PE_stub_poll_input; | |
55e303ae A |
292 | |
293 | ||
294 |