]> git.saurik.com Git - apple/xnu.git/blob - pexpert/i386/pe_init.c
xnu-792.25.20.tar.gz
[apple/xnu.git] / pexpert / i386 / pe_init.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
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>
33 #include <kern/sched_prim.h>
34 #include <kern/debug.h>
35
36 #include "fakePPCStructs.h"
37 #include "fakePPCDeviceTree.h"
38 #include "boot_images.h"
39
40 /* extern references */
41 extern void pe_identify_machine(void * args);
42 extern void initialize_screen(void *, unsigned int);
43
44 /* private globals */
45 PE_state_t PE_state;
46 dt_data gMemoryMapNode;
47 dt_data gDriversProp;
48 dt_data gRootpathProp;
49 dt_data gCompatibleProp;
50
51 /* Clock Frequency Info */
52 clock_frequency_info_t gPEClockFrequencyInfo;
53
54 void *gPEEFISystemTable = 0;
55 void *gPEEFIRuntimeServices = 0;
56
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 */
67 if ( info )
68 {
69 bootInfo.v_baseAddr = info->v_baseAddr;
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;
74 bInfo = &bootInfo;
75 if (info == &PE_state.video) {
76 bootInfo.v_display = info->v_display;
77 } else {
78 bootInfo.v_display = GRAPHICS_MODE;
79 }
80 }
81 else
82 bInfo = 0;
83
84 switch ( op ) {
85
86 case kPEDisableScreen:
87 initialize_screen((void *) bInfo, op);
88 kprintf("kPEDisableScreen %d\n", last_console);
89 if (!console_is_serial())
90 last_console = switch_to_serial_console();
91 break;
92
93 case kPEEnableScreen:
94 initialize_screen((void *) bInfo, op);
95 kprintf("kPEEnableScreen %d\n", last_console);
96 if( last_console != -1)
97 switch_to_old_console( last_console);
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 {
110 enum { kMaxBootVar = 128 };
111
112 typedef struct {
113 char name[32];
114 unsigned long length;
115 unsigned long value[2];
116 } DriversPackageProp;
117
118 boolean_t bootClutInitialized = FALSE;
119 boolean_t norootInitialized = FALSE;
120 DTEntry entry;
121 int size;
122 void ** map;
123
124 PE_init_kprintf(TRUE);
125 PE_init_printf(TRUE);
126
127 kprintf("Kernel boot args: '%s'\n", PE_boot_args());
128
129 /*
130 * Fetch the CLUT and the noroot image.
131 */
132 boot_progress_element * bootPict;
133
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;
138 }
139
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 }
149 }
150
151 if (!bootClutInitialized) {
152 bcopy( (void *) (uintptr_t) bootClut, (void *) appleClut8, sizeof(appleClut8) );
153 }
154
155 if (!norootInitialized) {
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;
161 }
162
163 /*
164 * Initialize the panic UI
165 */
166 panic_ui_initialize( (unsigned char *) appleClut8 );
167
168 /*
169 * Initialize the spinning wheel (progress indicator).
170 */
171 vc_progress_initialize( &default_progress, default_progress_data,
172 (unsigned char *) appleClut8 );
173
174 (void) StartIOKit( PE_state.deviceTreeHead, PE_state.bootArgs, gPEEFIRuntimeServices, 0);
175 }
176
177 void PE_init_platform(boolean_t vm_initialized, void * _args)
178 {
179 boot_args *args = (boot_args *)_args;
180
181 if (PE_state.initialized == FALSE) {
182 PE_state.initialized = TRUE;
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");
194 }
195
196 if (!vm_initialized) {
197 /* Hack! FIXME.. */
198 outb(0x21, 0xff); /* Maskout all interrupts Pic1 */
199 outb(0xa1, 0xff); /* Maskout all interrupts Pic2 */
200
201 if (PE_state.deviceTreeHead) {
202 DTInit(PE_state.deviceTreeHead);
203 }
204
205 pe_identify_machine(args);
206 } else {
207 DTEntry entry;
208 void *ptr;
209 uint32_t size;
210
211 pe_init_debug();
212 }
213 }
214
215 void PE_create_console( void )
216 {
217 if ( PE_state.video.v_display == GRAPHICS_MODE )
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
227 return (0);
228 }
229
230 void PE_display_icon( __unused unsigned int flags, __unused const char * name )
231 {
232 if ( default_noroot_data )
233 vc_display_icon( &default_noroot, default_noroot_data );
234 }
235
236 extern boolean_t PE_get_hotkey( __unused unsigned char key )
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
275 /*
276 * The default (non-functional) PE_poll_input handler.
277 */
278 static int
279 PE_stub_poll_input(__unused unsigned int options, char * c)
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;
292
293
294