]> git.saurik.com Git - apple/xnu.git/blame - pexpert/i386/pe_init.c
xnu-517.3.15.tar.gz
[apple/xnu.git] / pexpert / i386 / pe_init.c
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
43866e37 6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
1c79356b 7 *
43866e37
A
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
43866e37
A
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
1c79356b
A
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25/*
26 * file: pe_init.c
27 * i386 platform expert initialization.
28 */
29#include <sys/types.h>
30#include <mach/vm_param.h>
31#include <pexpert/protos.h>
32#include <pexpert/pexpert.h>
33#include <pexpert/boot.h>
34#include <pexpert/device_tree.h>
35#include <pexpert/pe_images.h>
9bccf70c 36#include <kern/sched_prim.h>
1c79356b
A
37
38#include "fakePPCStructs.h"
39#include "fakePPCDeviceTree.h"
9bccf70c 40#include "boot_images.h"
1c79356b
A
41
42/* extern references */
43extern void pe_identify_machine(void * args);
44extern void initialize_screen(void *, unsigned int);
45
46/* Local references */
47static vm_offset_t mapframebuffer(caddr_t,int);
48static vm_offset_t PE_fb_vaddr = 0;
49static int PE_fb_mode = TEXT_MODE;
50
51/* private globals */
0b4e3aa0
A
52PE_state_t PE_state;
53dt_data gMemoryMapNode;
54dt_data gDriversProp;
1c79356b
A
55
56/* Clock Frequency Info */
57clock_frequency_info_t gPEClockFrequencyInfo;
58
59int PE_initialize_console( PE_Video * info, int op )
60{
61 static int last_console = -1;
62 Boot_Video bootInfo;
63 Boot_Video * bInfo;
64
65 /*
66 * Refuse changes from outside pexpert.
67 * The video mode setup by the booter cannot be changed.
68 */
69 if ( info && (info == &PE_state.video) )
70 {
71 bootInfo.v_baseAddr = PE_fb_vaddr;
72 bootInfo.v_rowBytes = info->v_rowBytes;
73 bootInfo.v_width = info->v_width;
74 bootInfo.v_height = info->v_height;
75 bootInfo.v_depth = info->v_depth;
76 bootInfo.v_display = PE_fb_mode;
77 bInfo = &bootInfo;
78 }
79 else
80 bInfo = 0;
81
82 switch ( op ) {
83
84 case kPEDisableScreen:
85 initialize_screen((void *) bInfo, op);
86#ifdef FIXME
87 last_console = switch_to_serial_console();
88#endif
89 kprintf("kPEDisableScreen %d\n", last_console);
90 break;
91
92 case kPEEnableScreen:
93 initialize_screen((void *) bInfo, op);
94 kprintf("kPEEnableScreen %d\n", last_console);
95#ifdef FIXME
96 if( last_console != -1)
97 switch_to_old_console( last_console);
98#endif
99 break;
100
101 default:
102 initialize_screen((void *) bInfo, op);
103 break;
104 }
105
106 return 0;
107}
108
109void PE_init_iokit(void)
110{
9bccf70c
A
111 long * dt;
112 int i;
55e303ae 113 KernelBootArgs_t *kap = (KernelBootArgs_t *)PE_state.bootArgs;
9bccf70c 114
0b4e3aa0
A
115 typedef struct {
116 char name[32];
117 unsigned long length;
118 unsigned long value[2];
119 } DriversPackageProp;
120
55e303ae
A
121 PE_init_kprintf(TRUE);
122 PE_init_printf(TRUE);
123
0b4e3aa0
A
124 /*
125 * Update the fake device tree with the driver information provided by
126 * the booter.
127 */
128
55e303ae 129 gDriversProp.length = kap->numBootDrivers * sizeof(DriversPackageProp);
0b4e3aa0
A
130 gMemoryMapNode.length = 2 * sizeof(long);
131
132 dt = (long *) createdt( fakePPCDeviceTree,
133 &((boot_args*)PE_state.fakePPCBootArgs)->deviceTreeLength );
134
135 if ( dt )
136 {
137 DriversPackageProp * prop = (DriversPackageProp *) gDriversProp.address;
0b4e3aa0
A
138
139 /* Copy driver info in kernBootStruct to fake device tree */
140
55e303ae 141 for ( i = 0; i < kap->numBootDrivers; i++, prop++ )
0b4e3aa0 142 {
55e303ae 143 switch ( kap->driverConfig[i].type )
0b4e3aa0
A
144 {
145 case kBootDriverTypeKEXT:
55e303ae 146 sprintf(prop->name, "Driver-%lx", kap->driverConfig[i].address);
0b4e3aa0
A
147 break;
148
149 case kBootDriverTypeMKEXT:
55e303ae 150 sprintf(prop->name, "DriversPackage-%lx", kap->driverConfig[i].address);
0b4e3aa0
A
151 break;
152
153 default:
55e303ae 154 sprintf(prop->name, "DriverBogus-%lx", kap->driverConfig[i].address);
0b4e3aa0
A
155 break;
156 }
157 prop->length = sizeof(prop->value);
55e303ae
A
158 prop->value[0] = kap->driverConfig[i].address;
159 prop->value[1] = kap->driverConfig[i].size;
0b4e3aa0
A
160 }
161
55e303ae 162 *gMemoryMapNode.address = kap->numBootDrivers + 1;
0b4e3aa0 163 }
1c79356b
A
164
165 /* Setup powermac_info and powermac_machine_info structures */
166
167 ((boot_args*)PE_state.fakePPCBootArgs)->deviceTreeP = (unsigned long *) dt;
168 ((boot_args*)PE_state.fakePPCBootArgs)->topOfKernelData = (unsigned int) kalloc(0x2000);
169
170 /*
171 * Setup the OpenFirmware Device Tree routines
172 * so the console can be found and the right I/O space
173 * can be used..
174 */
175 DTInit(dt);
176
177 /*
9bccf70c 178 * Fetch the CLUT and the noroot image.
1c79356b 179 */
55e303ae 180 bcopy( (void *) bootClut, appleClut8, sizeof(appleClut8) );
9bccf70c
A
181
182 default_noroot.width = kFailedBootWidth;
183 default_noroot.height = kFailedBootHeight;
184 default_noroot.dx = 0;
185 default_noroot.dy = kFailedBootOffset;
186 default_noroot_data = failedBootPict;
55e303ae
A
187
188 /*
189 * Initialize the panic UI
190 */
191 panic_ui_initialize( (unsigned char *) appleClut8 );
1c79356b 192
9bccf70c
A
193 /*
194 * Initialize the spinning wheel (progress indicator).
195 */
196 vc_progress_initialize( &default_progress, default_progress_data,
197 (unsigned char *) appleClut8 );
1c79356b 198
55e303ae 199 (void) StartIOKit( (void*)dt, PE_state.bootArgs, 0, 0);
1c79356b
A
200}
201
202void PE_init_platform(boolean_t vm_initialized, void * args)
203{
204 if (PE_state.initialized == FALSE)
205 {
55e303ae 206 KernelBootArgs_t *kap = (KernelBootArgs_t *) args;
1c79356b
A
207
208 PE_state.initialized = TRUE;
209 PE_state.bootArgs = args;
55e303ae
A
210 PE_state.video.v_baseAddr = kap->video.v_baseAddr;
211 PE_state.video.v_rowBytes = kap->video.v_rowBytes;
212 PE_state.video.v_height = kap->video.v_height;
213 PE_state.video.v_width = kap->video.v_width;
214 PE_state.video.v_depth = kap->video.v_depth;
215 PE_state.video.v_display = kap->video.v_display;
216 PE_fb_mode = kap->graphicsMode;
1c79356b
A
217 PE_state.fakePPCBootArgs = (boot_args *)&fakePPCBootArgs;
218 ((boot_args *)PE_state.fakePPCBootArgs)->machineType = 386;
219
220 if (PE_fb_mode == TEXT_MODE)
221 {
222 /* Force a text display if the booter did not setup a
223 * VESA frame buffer.
224 */
225 PE_state.video.v_display = 0;
226 }
0b4e3aa0 227 }
1c79356b 228
55e303ae
A
229 if (!vm_initialized)
230 {
1c79356b
A
231 /* Hack! FIXME.. */
232 outb(0x21, 0xff); /* Maskout all interrupts Pic1 */
233 outb(0xa1, 0xff); /* Maskout all interrupts Pic2 */
234
0b4e3aa0 235 pe_identify_machine(args);
55e303ae
A
236 }
237 else
238 {
0b4e3aa0 239 pe_init_debug();
55e303ae 240 }
1c79356b
A
241}
242
243void PE_create_console( void )
244{
245 if ( (PE_fb_vaddr == 0) && (PE_state.video.v_baseAddr != 0) )
246 {
247 PE_fb_vaddr = mapframebuffer((caddr_t) PE_state.video.v_baseAddr,
248 (PE_fb_mode == TEXT_MODE) ?
249 /* text mode */ PE_state.video.v_rowBytes :
250 /* grfx mode */ PE_state.video.v_rowBytes *
251 PE_state.video.v_height);
252 }
253
55e303ae 254 if ( PE_state.video.v_display )
1c79356b
A
255 PE_initialize_console( &PE_state.video, kPEGraphicsMode );
256 else
257 PE_initialize_console( &PE_state.video, kPETextMode );
258}
259
260int PE_current_console( PE_Video * info )
261{
262 *info = PE_state.video;
263
264 if ( PE_fb_mode == TEXT_MODE )
265 {
266 /*
267 * FIXME: Prevent the IOBootFrameBuffer from starting up
268 * when we are in Text mode.
269 */
270 info->v_baseAddr = 0;
0b4e3aa0
A
271
272 /*
273 * Scale the size of the text screen from characters
274 * to pixels.
275 */
276 info->v_width *= 8; // CHARWIDTH
277 info->v_height *= 16; // CHARHEIGHT
1c79356b
A
278 }
279
280 return (0);
281}
282
9bccf70c 283void PE_display_icon( unsigned int flags, const char * name )
1c79356b 284{
9bccf70c
A
285 if ( default_noroot_data )
286 vc_display_icon( &default_noroot, default_noroot_data );
1c79356b
A
287}
288
289extern boolean_t PE_get_hotkey( unsigned char key )
290{
291 return (FALSE);
292}
293
294static timebase_callback_func gTimebaseCallback;
295
296void PE_register_timebase_callback(timebase_callback_func callback)
297{
298 gTimebaseCallback = callback;
299
300 PE_call_timebase_callback();
301}
302
303void PE_call_timebase_callback(void)
304{
305 struct timebase_freq_t timebase_freq;
306 unsigned long num, den, cnt;
307
308 num = gPEClockFrequencyInfo.bus_clock_rate_num * gPEClockFrequencyInfo.bus_to_dec_rate_num;
309 den = gPEClockFrequencyInfo.bus_clock_rate_den * gPEClockFrequencyInfo.bus_to_dec_rate_den;
310
311 cnt = 2;
312 while (cnt <= den) {
313 if ((num % cnt) || (den % cnt)) {
314 cnt++;
315 continue;
316 }
317
318 num /= cnt;
319 den /= cnt;
320 }
321
322 timebase_freq.timebase_num = num;
323 timebase_freq.timebase_den = den;
324
325 if (gTimebaseCallback) gTimebaseCallback(&timebase_freq);
326}
327
328/*
329 * map the framebuffer into kernel vm and return the (virtual)
330 * address.
331 */
332static vm_offset_t
333mapframebuffer( caddr_t physaddr, /* start of framebuffer */
334 int length) /* num bytes to map */
335{
336 vm_offset_t vmaddr;
337
338 if (physaddr != (caddr_t)trunc_page(physaddr))
339 panic("Framebuffer not on page boundary");
1c79356b
A
340 vmaddr = io_map((vm_offset_t)physaddr, length);
341 if (vmaddr == 0)
342 panic("can't alloc VM for framebuffer");
343
344 return vmaddr;
345}
0b4e3aa0
A
346
347/*
348 * The default (non-functional) PE_poll_input handler.
349 */
350static int
351PE_stub_poll_input(unsigned int options, char * c)
352{
353 *c = 0xff;
354 return 1; /* 0 for success, 1 for unsupported */
355}
356
357/*
358 * Called by the kernel debugger to poll for keyboard input.
359 * Keyboard drivers may replace the default stub function
360 * with their polled-mode input function.
361 */
362int (*PE_poll_input)(unsigned int options, char * c)
363 = PE_stub_poll_input;
55e303ae
A
364
365
366