2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
24 * i386 platform expert initialization.
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>
35 #include "fakePPCStructs.h"
36 #include "fakePPCDeviceTree.h"
37 #include "boot_images.h"
39 /* extern references */
40 extern void pe_identify_machine(void * args
);
41 extern void initialize_screen(void *, unsigned int);
43 /* Local references */
44 static int PE_fb_mode
= TEXT_MODE
;
48 dt_data gMemoryMapNode
;
50 dt_data gRootpathProp
;
51 dt_data gCompatibleProp
;
53 /* Clock Frequency Info */
54 clock_frequency_info_t gPEClockFrequencyInfo
;
56 int PE_initialize_console( PE_Video
* info
, int op
)
58 static int last_console
= -1;
63 * Refuse changes from outside pexpert.
64 * The video mode setup by the booter cannot be changed.
68 bootInfo
.v_baseAddr
= info
->v_baseAddr
;
69 bootInfo
.v_rowBytes
= info
->v_rowBytes
;
70 bootInfo
.v_width
= info
->v_width
;
71 bootInfo
.v_height
= info
->v_height
;
72 bootInfo
.v_depth
= info
->v_depth
;
74 if (info
== &PE_state
.video
) {
75 bootInfo
.v_display
= PE_fb_mode
;
77 bootInfo
.v_display
= GRAPHICS_MODE
;
85 case kPEDisableScreen
:
86 initialize_screen((void *) bInfo
, op
);
88 last_console
= switch_to_serial_console();
90 kprintf("kPEDisableScreen %d\n", last_console
);
94 initialize_screen((void *) bInfo
, op
);
95 kprintf("kPEEnableScreen %d\n", last_console
);
97 if( last_console
!= -1)
98 switch_to_old_console( last_console
);
103 initialize_screen((void *) bInfo
, op
);
110 void PE_init_iokit(void)
114 KernelBootArgs_t
*kap
= (KernelBootArgs_t
*)PE_state
.bootArgs
;
115 enum { kMaxBootVar
= 128 };
116 char *rdValue
, *platformValue
;
120 unsigned long length
;
121 unsigned long value
[2];
122 } DriversPackageProp
;
124 PE_init_kprintf(TRUE
);
125 PE_init_printf(TRUE
);
128 * Update the fake device tree with the driver information provided by
132 gDriversProp
.length
= kap
->numBootDrivers
* sizeof(DriversPackageProp
);
133 gMemoryMapNode
.length
= 2 * sizeof(long);
135 rdValue
= kalloc(kMaxBootVar
);
136 if ( PE_parse_boot_arg("rd", rdValue
) ) {
137 if (*rdValue
== '*') {
138 gRootpathProp
.address
= (rdValue
+ 1);
140 gRootpathProp
.address
= rdValue
;
142 strcat(rdValue
, ",");
144 gRootpathProp
.address
= rdValue
;
147 strcat(rdValue
, kap
->bootFile
);
148 gRootpathProp
.length
= strlen(rdValue
) + 1;
150 platformValue
= kalloc(kMaxBootVar
);
151 if ( ! PE_parse_boot_arg("platform", platformValue
) ) {
152 strcpy(platformValue
, kDefaultPlatformName
);
154 gCompatibleProp
.address
= platformValue
;
155 gCompatibleProp
.length
= strlen(platformValue
) + 1;
157 dt
= (long *) createdt( fakePPCDeviceTree
,
158 &((boot_args
*)PE_state
.fakePPCBootArgs
)->deviceTreeLength
);
160 kfree(rdValue
, kMaxBootVar
);
161 kfree(platformValue
, kMaxBootVar
);
166 DriversPackageProp
* prop
= (DriversPackageProp
*) gDriversProp
.address
;
168 /* Copy driver info in kernBootStruct to fake device tree */
170 for ( i
= 0; i
< kap
->numBootDrivers
; i
++, prop
++ )
172 switch ( kap
->driverConfig
[i
].type
)
174 case kBootDriverTypeKEXT
:
175 sprintf(prop
->name
, "Driver-%lx", kap
->driverConfig
[i
].address
);
178 case kBootDriverTypeMKEXT
:
179 sprintf(prop
->name
, "DriversPackage-%lx", kap
->driverConfig
[i
].address
);
183 sprintf(prop
->name
, "DriverBogus-%lx", kap
->driverConfig
[i
].address
);
186 prop
->length
= sizeof(prop
->value
);
187 prop
->value
[0] = kap
->driverConfig
[i
].address
;
188 prop
->value
[1] = kap
->driverConfig
[i
].size
;
191 *((long *)gMemoryMapNode
.address
) = kap
->numBootDrivers
+ 1;
194 /* Setup powermac_info and powermac_machine_info structures */
196 ((boot_args
*)PE_state
.fakePPCBootArgs
)->deviceTreeP
= (unsigned long *) dt
;
197 ((boot_args
*)PE_state
.fakePPCBootArgs
)->topOfKernelData
= (unsigned long) kalloc(0x2000);
200 * Setup the OpenFirmware Device Tree routines
201 * so the console can be found and the right I/O space
207 * Fetch the CLUT and the noroot image.
209 bcopy( (void *) (uintptr_t) bootClut
, (void *) appleClut8
, sizeof(appleClut8
) );
211 default_noroot
.width
= kFailedBootWidth
;
212 default_noroot
.height
= kFailedBootHeight
;
213 default_noroot
.dx
= 0;
214 default_noroot
.dy
= kFailedBootOffset
;
215 default_noroot_data
= failedBootPict
;
218 * Initialize the panic UI
220 panic_ui_initialize( (unsigned char *) appleClut8
);
223 * Initialize the spinning wheel (progress indicator).
225 vc_progress_initialize( &default_progress
, default_progress_data
,
226 (unsigned char *) appleClut8
);
228 (void) StartIOKit( (void*)dt
, PE_state
.bootArgs
, 0, 0);
231 void PE_init_platform(boolean_t vm_initialized
, void * args
)
233 if (PE_state
.initialized
== FALSE
)
235 KernelBootArgs_t
*kap
= (KernelBootArgs_t
*) args
;
237 PE_state
.initialized
= TRUE
;
238 PE_state
.bootArgs
= args
;
239 PE_state
.video
.v_baseAddr
= kap
->video
.v_baseAddr
;
240 PE_state
.video
.v_rowBytes
= kap
->video
.v_rowBytes
;
241 PE_state
.video
.v_height
= kap
->video
.v_height
;
242 PE_state
.video
.v_width
= kap
->video
.v_width
;
243 PE_state
.video
.v_depth
= kap
->video
.v_depth
;
244 PE_state
.video
.v_display
= kap
->video
.v_display
;
245 PE_fb_mode
= kap
->graphicsMode
;
246 PE_state
.fakePPCBootArgs
= (boot_args
*)&fakePPCBootArgs
;
247 ((boot_args
*)PE_state
.fakePPCBootArgs
)->machineType
= 386;
249 if (PE_fb_mode
== TEXT_MODE
)
251 /* Force a text display if the booter did not setup a
254 PE_state
.video
.v_display
= 0;
261 outb(0x21, 0xff); /* Maskout all interrupts Pic1 */
262 outb(0xa1, 0xff); /* Maskout all interrupts Pic2 */
264 pe_identify_machine(args
);
272 void PE_create_console( void )
274 if ( PE_state
.video
.v_display
)
275 PE_initialize_console( &PE_state
.video
, kPEGraphicsMode
);
277 PE_initialize_console( &PE_state
.video
, kPETextMode
);
280 int PE_current_console( PE_Video
* info
)
282 *info
= PE_state
.video
;
284 if ( PE_fb_mode
== TEXT_MODE
)
287 * FIXME: Prevent the IOBootFrameBuffer from starting up
288 * when we are in Text mode.
290 info
->v_baseAddr
= 0;
293 * Scale the size of the text screen from characters
296 info
->v_width
*= 8; // CHARWIDTH
297 info
->v_height
*= 16; // CHARHEIGHT
303 void PE_display_icon( __unused
unsigned int flags
, __unused
const char * name
)
305 if ( default_noroot_data
)
306 vc_display_icon( &default_noroot
, default_noroot_data
);
309 extern boolean_t
PE_get_hotkey( __unused
unsigned char key
)
314 static timebase_callback_func gTimebaseCallback
;
316 void PE_register_timebase_callback(timebase_callback_func callback
)
318 gTimebaseCallback
= callback
;
320 PE_call_timebase_callback();
323 void PE_call_timebase_callback(void)
325 struct timebase_freq_t timebase_freq
;
326 unsigned long num
, den
, cnt
;
328 num
= gPEClockFrequencyInfo
.bus_clock_rate_num
* gPEClockFrequencyInfo
.bus_to_dec_rate_num
;
329 den
= gPEClockFrequencyInfo
.bus_clock_rate_den
* gPEClockFrequencyInfo
.bus_to_dec_rate_den
;
333 if ((num
% cnt
) || (den
% cnt
)) {
342 timebase_freq
.timebase_num
= num
;
343 timebase_freq
.timebase_den
= den
;
345 if (gTimebaseCallback
) gTimebaseCallback(&timebase_freq
);
349 * The default (non-functional) PE_poll_input handler.
352 PE_stub_poll_input(__unused
unsigned int options
, char * c
)
355 return 1; /* 0 for success, 1 for unsupported */
359 * Called by the kernel debugger to poll for keyboard input.
360 * Keyboard drivers may replace the default stub function
361 * with their polled-mode input function.
363 int (*PE_poll_input
)(unsigned int options
, char * c
)
364 = PE_stub_poll_input
;