2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
32 * i386 platform expert initialization.
34 #include <sys/types.h>
35 #include <mach/vm_param.h>
36 #include <pexpert/protos.h>
37 #include <pexpert/pexpert.h>
38 #include <pexpert/boot.h>
39 #include <pexpert/device_tree.h>
40 #include <pexpert/pe_images.h>
41 #include <kern/sched_prim.h>
42 #include <kern/debug.h>
44 #include "fakePPCStructs.h"
45 #include "fakePPCDeviceTree.h"
46 #include "boot_images.h"
48 /* extern references */
49 extern void pe_identify_machine(void * args
);
50 extern void initialize_screen(void *, unsigned int);
54 dt_data gMemoryMapNode
;
56 dt_data gRootpathProp
;
57 dt_data gCompatibleProp
;
59 /* Clock Frequency Info */
60 clock_frequency_info_t gPEClockFrequencyInfo
;
62 void *gPEEFISystemTable
= 0;
63 void *gPEEFIRuntimeServices
= 0;
65 int PE_initialize_console( PE_Video
* info
, int op
)
67 static int last_console
= -1;
72 * Refuse changes from outside pexpert.
73 * The video mode setup by the booter cannot be changed.
77 bootInfo
.v_baseAddr
= info
->v_baseAddr
;
78 bootInfo
.v_rowBytes
= info
->v_rowBytes
;
79 bootInfo
.v_width
= info
->v_width
;
80 bootInfo
.v_height
= info
->v_height
;
81 bootInfo
.v_depth
= info
->v_depth
;
83 if (info
== &PE_state
.video
) {
84 bootInfo
.v_display
= info
->v_display
;
86 bootInfo
.v_display
= GRAPHICS_MODE
;
94 case kPEDisableScreen
:
95 initialize_screen((void *) bInfo
, op
);
96 kprintf("kPEDisableScreen %d\n", last_console
);
97 if (!console_is_serial())
98 last_console
= switch_to_serial_console();
101 case kPEEnableScreen
:
102 initialize_screen((void *) bInfo
, op
);
103 kprintf("kPEEnableScreen %d\n", last_console
);
104 if( last_console
!= -1)
105 switch_to_old_console( last_console
);
109 initialize_screen((void *) bInfo
, op
);
116 void PE_init_iokit(void)
118 enum { kMaxBootVar
= 128 };
122 unsigned long length
;
123 unsigned long value
[2];
124 } DriversPackageProp
;
126 boolean_t bootClutInitialized
= FALSE
;
127 boolean_t norootInitialized
= FALSE
;
132 PE_init_kprintf(TRUE
);
133 PE_init_printf(TRUE
);
135 kprintf("Kernel boot args: '%s'\n", PE_boot_args());
138 * Fetch the CLUT and the noroot image.
140 boot_progress_element
* bootPict
;
142 if( kSuccess
== DTLookupEntry(0, "/chosen/memory-map", &entry
)) {
143 if( kSuccess
== DTGetProperty(entry
, "BootCLUT", (void **) &map
, &size
)) {
144 bcopy( map
[0], appleClut8
, sizeof(appleClut8
) );
145 bootClutInitialized
= TRUE
;
148 if( kSuccess
== DTGetProperty(entry
, "Pict-FailedBoot", (void **) &map
, &size
)) {
149 bootPict
= (boot_progress_element
*) map
[0];
150 default_noroot
.width
= bootPict
->width
;
151 default_noroot
.height
= bootPict
->height
;
152 default_noroot
.dx
= 0;
153 default_noroot
.dy
= bootPict
->yOffset
;
154 default_noroot_data
= &bootPict
->data
[0];
155 norootInitialized
= TRUE
;
159 if (!bootClutInitialized
) {
160 bcopy( (void *) (uintptr_t) bootClut
, (void *) appleClut8
, sizeof(appleClut8
) );
163 if (!norootInitialized
) {
164 default_noroot
.width
= kFailedBootWidth
;
165 default_noroot
.height
= kFailedBootHeight
;
166 default_noroot
.dx
= 0;
167 default_noroot
.dy
= kFailedBootOffset
;
168 default_noroot_data
= failedBootPict
;
172 * Initialize the panic UI
174 panic_ui_initialize( (unsigned char *) appleClut8
);
177 * Initialize the spinning wheel (progress indicator).
179 vc_progress_initialize( &default_progress
, default_progress_data
,
180 (unsigned char *) appleClut8
);
182 (void) StartIOKit( PE_state
.deviceTreeHead
, PE_state
.bootArgs
, gPEEFIRuntimeServices
, 0);
185 void PE_init_platform(boolean_t vm_initialized
, void * _args
)
187 boot_args
*args
= (boot_args
*)_args
;
189 if (PE_state
.initialized
== FALSE
) {
190 PE_state
.initialized
= TRUE
;
193 PE_state
.bootArgs
= _args
;
194 PE_state
.deviceTreeHead
= args
->deviceTreeP
;
195 PE_state
.video
.v_baseAddr
= args
->Video
.v_baseAddr
;
196 PE_state
.video
.v_rowBytes
= args
->Video
.v_rowBytes
;
197 PE_state
.video
.v_width
= args
->Video
.v_width
;
198 PE_state
.video
.v_height
= args
->Video
.v_height
;
199 PE_state
.video
.v_depth
= args
->Video
.v_depth
;
200 PE_state
.video
.v_display
= args
->Video
.v_display
;
201 strcpy( PE_state
.video
.v_pixelFormat
, "PPPPPPPP");
204 if (!vm_initialized
) {
206 outb(0x21, 0xff); /* Maskout all interrupts Pic1 */
207 outb(0xa1, 0xff); /* Maskout all interrupts Pic2 */
209 if (PE_state
.deviceTreeHead
) {
210 DTInit(PE_state
.deviceTreeHead
);
213 pe_identify_machine(args
);
223 void PE_create_console( void )
225 if ( PE_state
.video
.v_display
== GRAPHICS_MODE
)
226 PE_initialize_console( &PE_state
.video
, kPEGraphicsMode
);
228 PE_initialize_console( &PE_state
.video
, kPETextMode
);
231 int PE_current_console( PE_Video
* info
)
233 *info
= PE_state
.video
;
238 void PE_display_icon( __unused
unsigned int flags
, __unused
const char * name
)
240 if ( default_noroot_data
)
241 vc_display_icon( &default_noroot
, default_noroot_data
);
244 extern boolean_t
PE_get_hotkey( __unused
unsigned char key
)
249 static timebase_callback_func gTimebaseCallback
;
251 void PE_register_timebase_callback(timebase_callback_func callback
)
253 gTimebaseCallback
= callback
;
255 PE_call_timebase_callback();
258 void PE_call_timebase_callback(void)
260 struct timebase_freq_t timebase_freq
;
261 unsigned long num
, den
, cnt
;
263 num
= gPEClockFrequencyInfo
.bus_clock_rate_num
* gPEClockFrequencyInfo
.bus_to_dec_rate_num
;
264 den
= gPEClockFrequencyInfo
.bus_clock_rate_den
* gPEClockFrequencyInfo
.bus_to_dec_rate_den
;
268 if ((num
% cnt
) || (den
% cnt
)) {
277 timebase_freq
.timebase_num
= num
;
278 timebase_freq
.timebase_den
= den
;
280 if (gTimebaseCallback
) gTimebaseCallback(&timebase_freq
);
284 * The default (non-functional) PE_poll_input handler.
287 PE_stub_poll_input(__unused
unsigned int options
, char * c
)
290 return 1; /* 0 for success, 1 for unsupported */
294 * Called by the kernel debugger to poll for keyboard input.
295 * Keyboard drivers may replace the default stub function
296 * with their polled-mode input function.
298 int (*PE_poll_input
)(unsigned int options
, char * c
)
299 = PE_stub_poll_input
;