2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
23 * @APPLE_LICENSE_HEADER_END@
27 * i386 platform expert initialization.
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>
36 #include <kern/sched_prim.h>
38 #include "fakePPCStructs.h"
39 #include "fakePPCDeviceTree.h"
40 #include "boot_images.h"
42 /* extern references */
43 extern void pe_identify_machine(void * args
);
44 extern void initialize_screen(void *, unsigned int);
46 /* Local references */
47 static vm_offset_t
mapframebuffer(caddr_t
,int);
48 static vm_offset_t PE_fb_vaddr
= 0;
49 static int PE_fb_mode
= TEXT_MODE
;
53 dt_data gMemoryMapNode
;
56 /* Clock Frequency Info */
57 clock_frequency_info_t gPEClockFrequencyInfo
;
59 int PE_initialize_console( PE_Video
* info
, int op
)
61 static int last_console
= -1;
66 * Refuse changes from outside pexpert.
67 * The video mode setup by the booter cannot be changed.
69 if ( info
&& (info
== &PE_state
.video
) )
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
;
84 case kPEDisableScreen
:
85 initialize_screen((void *) bInfo
, op
);
87 last_console
= switch_to_serial_console();
89 kprintf("kPEDisableScreen %d\n", last_console
);
93 initialize_screen((void *) bInfo
, op
);
94 kprintf("kPEEnableScreen %d\n", last_console
);
96 if( last_console
!= -1)
97 switch_to_old_console( last_console
);
102 initialize_screen((void *) bInfo
, op
);
109 void PE_init_iokit(void)
113 KernelBootArgs_t
*kap
= (KernelBootArgs_t
*)PE_state
.bootArgs
;
117 unsigned long length
;
118 unsigned long value
[2];
119 } DriversPackageProp
;
121 PE_init_kprintf(TRUE
);
122 PE_init_printf(TRUE
);
125 * Update the fake device tree with the driver information provided by
129 gDriversProp
.length
= kap
->numBootDrivers
* sizeof(DriversPackageProp
);
130 gMemoryMapNode
.length
= 2 * sizeof(long);
132 dt
= (long *) createdt( fakePPCDeviceTree
,
133 &((boot_args
*)PE_state
.fakePPCBootArgs
)->deviceTreeLength
);
137 DriversPackageProp
* prop
= (DriversPackageProp
*) gDriversProp
.address
;
139 /* Copy driver info in kernBootStruct to fake device tree */
141 for ( i
= 0; i
< kap
->numBootDrivers
; i
++, prop
++ )
143 switch ( kap
->driverConfig
[i
].type
)
145 case kBootDriverTypeKEXT
:
146 sprintf(prop
->name
, "Driver-%lx", kap
->driverConfig
[i
].address
);
149 case kBootDriverTypeMKEXT
:
150 sprintf(prop
->name
, "DriversPackage-%lx", kap
->driverConfig
[i
].address
);
154 sprintf(prop
->name
, "DriverBogus-%lx", kap
->driverConfig
[i
].address
);
157 prop
->length
= sizeof(prop
->value
);
158 prop
->value
[0] = kap
->driverConfig
[i
].address
;
159 prop
->value
[1] = kap
->driverConfig
[i
].size
;
162 *gMemoryMapNode
.address
= kap
->numBootDrivers
+ 1;
165 /* Setup powermac_info and powermac_machine_info structures */
167 ((boot_args
*)PE_state
.fakePPCBootArgs
)->deviceTreeP
= (unsigned long *) dt
;
168 ((boot_args
*)PE_state
.fakePPCBootArgs
)->topOfKernelData
= (unsigned int) kalloc(0x2000);
171 * Setup the OpenFirmware Device Tree routines
172 * so the console can be found and the right I/O space
178 * Fetch the CLUT and the noroot image.
180 bcopy( (void *) bootClut
, appleClut8
, sizeof(appleClut8
) );
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
;
189 * Initialize the panic UI
191 panic_ui_initialize( (unsigned char *) appleClut8
);
194 * Initialize the spinning wheel (progress indicator).
196 vc_progress_initialize( &default_progress
, default_progress_data
,
197 (unsigned char *) appleClut8
);
199 (void) StartIOKit( (void*)dt
, PE_state
.bootArgs
, 0, 0);
202 void PE_init_platform(boolean_t vm_initialized
, void * args
)
204 if (PE_state
.initialized
== FALSE
)
206 KernelBootArgs_t
*kap
= (KernelBootArgs_t
*) args
;
208 PE_state
.initialized
= TRUE
;
209 PE_state
.bootArgs
= args
;
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
;
217 PE_state
.fakePPCBootArgs
= (boot_args
*)&fakePPCBootArgs
;
218 ((boot_args
*)PE_state
.fakePPCBootArgs
)->machineType
= 386;
220 if (PE_fb_mode
== TEXT_MODE
)
222 /* Force a text display if the booter did not setup a
225 PE_state
.video
.v_display
= 0;
232 outb(0x21, 0xff); /* Maskout all interrupts Pic1 */
233 outb(0xa1, 0xff); /* Maskout all interrupts Pic2 */
235 pe_identify_machine(args
);
243 void PE_create_console( void )
245 if ( (PE_fb_vaddr
== 0) && (PE_state
.video
.v_baseAddr
!= 0) )
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
);
254 if ( PE_state
.video
.v_display
)
255 PE_initialize_console( &PE_state
.video
, kPEGraphicsMode
);
257 PE_initialize_console( &PE_state
.video
, kPETextMode
);
260 int PE_current_console( PE_Video
* info
)
262 *info
= PE_state
.video
;
264 if ( PE_fb_mode
== TEXT_MODE
)
267 * FIXME: Prevent the IOBootFrameBuffer from starting up
268 * when we are in Text mode.
270 info
->v_baseAddr
= 0;
273 * Scale the size of the text screen from characters
276 info
->v_width
*= 8; // CHARWIDTH
277 info
->v_height
*= 16; // CHARHEIGHT
283 void PE_display_icon( unsigned int flags
, const char * name
)
285 if ( default_noroot_data
)
286 vc_display_icon( &default_noroot
, default_noroot_data
);
289 extern boolean_t
PE_get_hotkey( unsigned char key
)
294 static timebase_callback_func gTimebaseCallback
;
296 void PE_register_timebase_callback(timebase_callback_func callback
)
298 gTimebaseCallback
= callback
;
300 PE_call_timebase_callback();
303 void PE_call_timebase_callback(void)
305 struct timebase_freq_t timebase_freq
;
306 unsigned long num
, den
, cnt
;
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
;
313 if ((num
% cnt
) || (den
% cnt
)) {
322 timebase_freq
.timebase_num
= num
;
323 timebase_freq
.timebase_den
= den
;
325 if (gTimebaseCallback
) gTimebaseCallback(&timebase_freq
);
329 * map the framebuffer into kernel vm and return the (virtual)
333 mapframebuffer( caddr_t physaddr
, /* start of framebuffer */
334 int length
) /* num bytes to map */
338 if (physaddr
!= (caddr_t
)trunc_page(physaddr
))
339 panic("Framebuffer not on page boundary");
340 vmaddr
= io_map((vm_offset_t
)physaddr
, length
);
342 panic("can't alloc VM for framebuffer");
348 * The default (non-functional) PE_poll_input handler.
351 PE_stub_poll_input(unsigned int options
, char * c
)
354 return 1; /* 0 for success, 1 for unsupported */
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.
362 int (*PE_poll_input
)(unsigned int options
, char * c
)
363 = PE_stub_poll_input
;