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>
34 #include <kern/debug.h>
36 #include "fakePPCStructs.h"
37 #include "fakePPCDeviceTree.h"
38 #include "boot_images.h"
40 /* extern references */
41 extern void pe_identify_machine(void * args
);
42 extern void initialize_screen(void *, unsigned int);
46 dt_data gMemoryMapNode
;
48 dt_data gRootpathProp
;
49 dt_data gCompatibleProp
;
51 /* Clock Frequency Info */
52 clock_frequency_info_t gPEClockFrequencyInfo
;
54 void *gPEEFISystemTable
= 0;
55 void *gPEEFIRuntimeServices
= 0;
57 int PE_initialize_console( PE_Video
* info
, int op
)
59 static int last_console
= -1;
64 * Refuse changes from outside pexpert.
65 * The video mode setup by the booter cannot be changed.
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
;
75 if (info
== &PE_state
.video
) {
76 bootInfo
.v_display
= info
->v_display
;
78 bootInfo
.v_display
= GRAPHICS_MODE
;
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();
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
);
101 initialize_screen((void *) bInfo
, op
);
108 void PE_init_iokit(void)
110 enum { kMaxBootVar
= 128 };
114 unsigned long length
;
115 unsigned long value
[2];
116 } DriversPackageProp
;
118 boolean_t bootClutInitialized
= FALSE
;
119 boolean_t norootInitialized
= FALSE
;
124 PE_init_kprintf(TRUE
);
125 PE_init_printf(TRUE
);
127 kprintf("Kernel boot args: '%s'\n", PE_boot_args());
130 * Fetch the CLUT and the noroot image.
132 boot_progress_element
* bootPict
;
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
;
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
;
151 if (!bootClutInitialized
) {
152 bcopy( (void *) (uintptr_t) bootClut
, (void *) appleClut8
, sizeof(appleClut8
) );
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
;
164 * Initialize the panic UI
166 panic_ui_initialize( (unsigned char *) appleClut8
);
169 * Initialize the spinning wheel (progress indicator).
171 vc_progress_initialize( &default_progress
, default_progress_data
,
172 (unsigned char *) appleClut8
);
174 (void) StartIOKit( PE_state
.deviceTreeHead
, PE_state
.bootArgs
, gPEEFIRuntimeServices
, 0);
177 void PE_init_platform(boolean_t vm_initialized
, void * _args
)
179 boot_args
*args
= (boot_args
*)_args
;
181 if (PE_state
.initialized
== FALSE
) {
182 PE_state
.initialized
= TRUE
;
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");
196 if (!vm_initialized
) {
198 outb(0x21, 0xff); /* Maskout all interrupts Pic1 */
199 outb(0xa1, 0xff); /* Maskout all interrupts Pic2 */
201 if (PE_state
.deviceTreeHead
) {
202 DTInit(PE_state
.deviceTreeHead
);
205 pe_identify_machine(args
);
215 void PE_create_console( void )
217 if ( PE_state
.video
.v_display
== GRAPHICS_MODE
)
218 PE_initialize_console( &PE_state
.video
, kPEGraphicsMode
);
220 PE_initialize_console( &PE_state
.video
, kPETextMode
);
223 int PE_current_console( PE_Video
* info
)
225 *info
= PE_state
.video
;
230 void PE_display_icon( __unused
unsigned int flags
, __unused
const char * name
)
232 if ( default_noroot_data
)
233 vc_display_icon( &default_noroot
, default_noroot_data
);
236 extern boolean_t
PE_get_hotkey( __unused
unsigned char key
)
241 static timebase_callback_func gTimebaseCallback
;
243 void PE_register_timebase_callback(timebase_callback_func callback
)
245 gTimebaseCallback
= callback
;
247 PE_call_timebase_callback();
250 void PE_call_timebase_callback(void)
252 struct timebase_freq_t timebase_freq
;
253 unsigned long num
, den
, cnt
;
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
;
260 if ((num
% cnt
) || (den
% cnt
)) {
269 timebase_freq
.timebase_num
= num
;
270 timebase_freq
.timebase_den
= den
;
272 if (gTimebaseCallback
) gTimebaseCallback(&timebase_freq
);
276 * The default (non-functional) PE_poll_input handler.
279 PE_stub_poll_input(__unused
unsigned int options
, char * c
)
282 return 1; /* 0 for success, 1 for unsupported */
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.
290 int (*PE_poll_input
)(unsigned int options
, char * c
)
291 = PE_stub_poll_input
;