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>
35 /* extern references */
36 void pe_identify_machine(void);
41 /* Clock Frequency Info */
42 clock_frequency_info_t gPEClockFrequencyInfo
;
44 static int PE_stub_read_write_time_of_day(unsigned int options
, long * secs
)
46 // believe it or, BSD crashes if invalid time returned. FIXME.
47 if( options
== kPEReadTOD
)
53 static int PE_stub_poll_input(unsigned int options
, char * c
)
60 static int PE_stub_write_IIC(unsigned char addr
, unsigned char reg
,
66 int (*PE_read_write_time_of_day
)(unsigned int options
, long * secs
)
67 = PE_stub_read_write_time_of_day
;
68 int (*PE_poll_input
)(unsigned int options
, char * c
)
71 int (*PE_write_IIC
)(unsigned char addr
, unsigned char reg
,
76 int PE_initialize_console( PE_Video
* info
, int op
)
78 static int last_console
= -1;
83 bootInfo
.v_baseAddr
= info
->v_baseAddr
;
84 bootInfo
.v_rowBytes
= info
->v_rowBytes
;
85 bootInfo
.v_width
= info
->v_width
;
86 bootInfo
.v_height
= info
->v_height
;
87 bootInfo
.v_depth
= info
->v_depth
;
88 bootInfo
.v_display
= 0;
95 case kPEDisableScreen
:
96 initialize_screen((void *) bInfo
, op
);
97 last_console
= switch_to_serial_console();
98 kprintf("kPEDisableScreen %d\n",last_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 static boolean_t
find_image( const char * name
,
118 unsigned char ** data
,
119 unsigned char ** clut
)
126 // This is a little flawed now the device tree data
128 if( (kSuccess
== DTLookupEntry(0, "/AAPL,images", &entry
))
129 && (kSuccess
== DTLookupEntry(entry
, name
, &entry
)) ) {
131 ok
= ( (kSuccess
== DTGetProperty(entry
, "desc",
133 && (kSuccess
== DTGetProperty(entry
, "data",
134 (void **)data
, &size
)));
136 if( clut
&& (kSuccess
!= DTGetProperty(entry
, "clut",
137 (void **)clut
, &size
)))
146 void PE_init_iokit(void)
150 unsigned char * data
;
151 unsigned char * clut
;
153 PE_init_kprintf(TRUE
);
154 PE_init_printf(TRUE
);
156 // init this now to get mace debugger for iokit startup
157 PE_init_ethernet_debugger();
159 if( !find_image( "progress", &desc
, &data
, &clut
)) {
161 desc
= &default_progress
;
162 data
= default_progress_data
;
164 vc_progress_initialize( desc
, data
, clut
);
166 PE_initialize_console( (PE_Video
*) 0, kPEAcquireScreen
);
168 ret
= StartIOKit( PE_state
.deviceTreeHead
, PE_state
.bootArgs
,
169 (void *)0, (void *)0);
172 void PE_init_platform(boolean_t vm_initialized
, void *_args
)
174 boot_args
*args
= (boot_args
*)_args
;
176 if (PE_state
.initialized
== FALSE
)
178 PE_state
.initialized
= TRUE
;
179 PE_state
.bootArgs
= _args
;
180 PE_state
.deviceTreeHead
= args
->deviceTreeP
;
181 PE_state
.video
.v_baseAddr
= args
->Video
.v_baseAddr
;
182 PE_state
.video
.v_rowBytes
= args
->Video
.v_rowBytes
;
183 PE_state
.video
.v_width
= args
->Video
.v_width
;
184 PE_state
.video
.v_height
= args
->Video
.v_height
;
185 PE_state
.video
.v_depth
= args
->Video
.v_depth
;
186 PE_state
.video
.v_display
= args
->Video
.v_display
;
187 strcpy( PE_state
.video
.v_pixelFormat
, "PPPPPPPP");
193 * Setup the OpenFirmware Device Tree routines
194 * so the console can be found and the right I/O space
197 DTInit(PE_state
.deviceTreeHead
);
199 /* Setup gPEClockFrequencyInfo */
200 pe_identify_machine();
208 void PE_create_console( void )
210 if (PE_state
.video
.v_display
)
211 PE_initialize_console( &PE_state
.video
, kPEGraphicsMode
);
213 PE_initialize_console( &PE_state
.video
, kPETextMode
);
216 int PE_current_console( PE_Video
* info
)
218 *info
= PE_state
.video
;
222 void PE_display_icon( unsigned int flags
,
226 unsigned char * data
;
228 if( !find_image( name
, &desc
, &data
, 0)) {
229 desc
= &default_roroot
;
230 data
= default_noroot_data
;
232 vc_display_icon( desc
, data
);
235 extern boolean_t
PE_get_hotkey(
238 unsigned char * adbKeymap
;
242 if( (kSuccess
!= DTLookupEntry( 0, "/", &entry
))
243 || (kSuccess
!= DTGetProperty( entry
, "AAPL,adb-keymap",
244 (void **)&adbKeymap
, &size
))
252 return( adbKeymap
[ key
/ 8 ] & (0x80 >> (key
& 7)));
255 static timebase_callback_func gTimebaseCallback
;
257 void PE_register_timebase_callback(timebase_callback_func callback
)
259 gTimebaseCallback
= callback
;
261 PE_call_timebase_callback();
264 void PE_call_timebase_callback(void)
266 struct timebase_freq_t timebase_freq
;
267 unsigned long num
, den
, cnt
;
269 num
= gPEClockFrequencyInfo
.bus_clock_rate_num
* gPEClockFrequencyInfo
.bus_to_dec_rate_num
;
270 den
= gPEClockFrequencyInfo
.bus_clock_rate_den
* gPEClockFrequencyInfo
.bus_to_dec_rate_den
;
274 if ((num
% cnt
) || (den
% cnt
)) {
283 timebase_freq
.timebase_num
= num
;
284 timebase_freq
.timebase_den
= den
;
286 if (gTimebaseCallback
) gTimebaseCallback(&timebase_freq
);