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 * PPC platform expert initialization.
26 #include <mach/boot_info.h>
27 #include <mach/time_value.h>
28 #include <pexpert/protos.h>
29 #include <pexpert/pexpert.h>
30 #include <pexpert/ppc/interrupts.h>
31 #include <pexpert/device_tree.h>
32 #include <pexpert/pe_images.h>
33 #include <kern/debug.h>
34 #include <kern/sched_prim.h>
36 /* extern references */
37 void pe_identify_machine(void);
42 /* Clock Frequency Info */
43 clock_frequency_info_t gPEClockFrequencyInfo
;
45 static int PE_stub_read_write_time_of_day(unsigned int options
, long * secs
)
47 // believe it or, BSD crashes if invalid time returned. FIXME.
48 if( options
== kPEReadTOD
)
54 static int PE_stub_poll_input(unsigned int options
, char * c
)
61 static int PE_stub_write_IIC(unsigned char addr
, unsigned char reg
,
67 int (*PE_read_write_time_of_day
)(unsigned int options
, long * secs
)
68 = PE_stub_read_write_time_of_day
;
69 int (*PE_poll_input
)(unsigned int options
, char * c
)
72 int (*PE_write_IIC
)(unsigned char addr
, unsigned char reg
,
77 int PE_initialize_console( PE_Video
* info
, int op
)
79 static int last_console
= -1;
84 bootInfo
.v_baseAddr
= info
->v_baseAddr
;
85 bootInfo
.v_rowBytes
= info
->v_rowBytes
;
86 bootInfo
.v_width
= info
->v_width
;
87 bootInfo
.v_height
= info
->v_height
;
88 bootInfo
.v_depth
= info
->v_depth
;
89 bootInfo
.v_display
= 0;
96 case kPEDisableScreen
:
97 initialize_screen((void *) bInfo
, op
);
98 last_console
= switch_to_serial_console();
99 kprintf("kPEDisableScreen %d\n",last_console
);
102 case kPEEnableScreen
:
103 initialize_screen((void *) bInfo
, op
);
104 kprintf("kPEEnableScreen %d\n",last_console
);
105 if( last_console
!= -1)
106 switch_to_old_console( last_console
);
110 initialize_screen((void *) bInfo
, op
);
117 void PE_init_iokit(void)
125 PE_init_kprintf(TRUE
);
126 PE_init_printf(TRUE
);
128 // init this now to get mace debugger for iokit startup
129 PE_init_ethernet_debugger();
132 if( kSuccess
== DTLookupEntry(0, "/chosen/memory-map", &entry
)) {
134 boot_progress_element
* bootPict
;
136 if( kSuccess
== DTGetProperty(entry
, "BootCLUT", (void **) &map
, &size
))
137 bcopy( map
[0], appleClut8
, sizeof(appleClut8
) );
139 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];
149 vc_progress_initialize( &default_progress
, default_progress_data
, (unsigned char *) appleClut8
);
151 PE_initialize_console( (PE_Video
*) 0, kPEAcquireScreen
);
153 ret
= StartIOKit( PE_state
.deviceTreeHead
, PE_state
.bootArgs
,
154 (void *)0, (void *)0);
157 void PE_init_platform(boolean_t vm_initialized
, void *_args
)
159 boot_args
*args
= (boot_args
*)_args
;
161 if (PE_state
.initialized
== FALSE
)
163 PE_state
.initialized
= TRUE
;
164 PE_state
.bootArgs
= _args
;
165 PE_state
.deviceTreeHead
= args
->deviceTreeP
;
166 PE_state
.video
.v_baseAddr
= args
->Video
.v_baseAddr
;
167 PE_state
.video
.v_rowBytes
= args
->Video
.v_rowBytes
;
168 PE_state
.video
.v_width
= args
->Video
.v_width
;
169 PE_state
.video
.v_height
= args
->Video
.v_height
;
170 PE_state
.video
.v_depth
= args
->Video
.v_depth
;
171 PE_state
.video
.v_display
= args
->Video
.v_display
;
172 strcpy( PE_state
.video
.v_pixelFormat
, "PPPPPPPP");
178 * Setup the OpenFirmware Device Tree routines
179 * so the console can be found and the right I/O space
182 DTInit(PE_state
.deviceTreeHead
);
184 /* Setup gPEClockFrequencyInfo */
185 pe_identify_machine();
193 void PE_create_console( void )
195 if (PE_state
.video
.v_display
)
196 PE_initialize_console( &PE_state
.video
, kPEGraphicsMode
);
198 PE_initialize_console( &PE_state
.video
, kPETextMode
);
201 int PE_current_console( PE_Video
* info
)
203 *info
= PE_state
.video
;
207 void PE_display_icon( unsigned int flags
,
210 if( default_noroot_data
)
211 vc_display_icon( &default_noroot
, default_noroot_data
);
214 extern boolean_t
PE_get_hotkey(
217 unsigned char * adbKeymap
;
221 if( (kSuccess
!= DTLookupEntry( 0, "/", &entry
))
222 || (kSuccess
!= DTGetProperty( entry
, "AAPL,adb-keymap",
223 (void **)&adbKeymap
, &size
))
231 return( adbKeymap
[ key
/ 8 ] & (0x80 >> (key
& 7)));
234 static timebase_callback_func gTimebaseCallback
;
236 void PE_register_timebase_callback(timebase_callback_func callback
)
238 gTimebaseCallback
= callback
;
240 PE_call_timebase_callback();
243 void PE_call_timebase_callback(void)
245 struct timebase_freq_t timebase_freq
;
246 unsigned long num
, den
, cnt
;
248 num
= gPEClockFrequencyInfo
.bus_clock_rate_num
* gPEClockFrequencyInfo
.bus_to_dec_rate_num
;
249 den
= gPEClockFrequencyInfo
.bus_clock_rate_den
* gPEClockFrequencyInfo
.bus_to_dec_rate_den
;
253 if ((num
% cnt
) || (den
% cnt
)) {
262 timebase_freq
.timebase_num
= num
;
263 timebase_freq
.timebase_den
= den
;
265 if (gTimebaseCallback
) gTimebaseCallback(&timebase_freq
);