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 * PPC platform expert initialization.
29 #include <mach/boot_info.h>
30 #include <mach/time_value.h>
31 #include <pexpert/protos.h>
32 #include <pexpert/pexpert.h>
33 #include <pexpert/ppc/interrupts.h>
34 #include <pexpert/device_tree.h>
35 #include <pexpert/pe_images.h>
36 #include <kern/debug.h>
37 #include <kern/sched_prim.h>
39 /* extern references */
40 void pe_identify_machine(void);
45 /* Clock Frequency Info */
46 clock_frequency_info_t gPEClockFrequencyInfo
;
48 static int PE_stub_read_write_time_of_day(unsigned int options
, long * secs
)
50 // believe it or, BSD crashes if invalid time returned. FIXME.
51 if( options
== kPEReadTOD
)
57 static int PE_stub_poll_input(unsigned int options
, char * c
)
64 static int PE_stub_write_IIC(unsigned char addr
, unsigned char reg
,
70 int (*PE_read_write_time_of_day
)(unsigned int options
, long * secs
)
71 = PE_stub_read_write_time_of_day
;
72 int (*PE_poll_input
)(unsigned int options
, char * c
)
75 int (*PE_write_IIC
)(unsigned char addr
, unsigned char reg
,
80 int PE_initialize_console( PE_Video
* info
, int op
)
82 static int last_console
= -1;
87 bootInfo
.v_baseAddr
= info
->v_baseAddr
;
88 bootInfo
.v_rowBytes
= info
->v_rowBytes
;
89 bootInfo
.v_width
= info
->v_width
;
90 bootInfo
.v_height
= info
->v_height
;
91 bootInfo
.v_depth
= info
->v_depth
;
92 bootInfo
.v_display
= 0;
99 case kPEDisableScreen
:
100 initialize_screen((void *) bInfo
, op
);
101 last_console
= switch_to_serial_console();
102 kprintf("kPEDisableScreen %d\n",last_console
);
105 case kPEEnableScreen
:
106 initialize_screen((void *) bInfo
, op
);
107 kprintf("kPEEnableScreen %d\n",last_console
);
108 if( last_console
!= -1)
109 switch_to_old_console( last_console
);
113 initialize_screen((void *) bInfo
, op
);
120 void PE_init_iokit(void)
128 PE_init_kprintf(TRUE
);
129 PE_init_printf(TRUE
);
131 if( kSuccess
== DTLookupEntry(0, "/chosen/memory-map", &entry
)) {
133 boot_progress_element
* bootPict
;
135 if( kSuccess
== DTGetProperty(entry
, "BootCLUT", (void **) &map
, &size
))
136 bcopy( map
[0], appleClut8
, sizeof(appleClut8
) );
138 if( kSuccess
== DTGetProperty(entry
, "Pict-FailedBoot", (void **) &map
, &size
)) {
140 bootPict
= (boot_progress_element
*) map
[0];
141 default_noroot
.width
= bootPict
->width
;
142 default_noroot
.height
= bootPict
->height
;
143 default_noroot
.dx
= 0;
144 default_noroot
.dy
= bootPict
->yOffset
;
145 default_noroot_data
= &bootPict
->data
[0];
148 vc_progress_initialize( &default_progress
, default_progress_data
, (unsigned char *) appleClut8
);
150 PE_initialize_console( (PE_Video
*) 0, kPEAcquireScreen
);
152 ret
= StartIOKit( PE_state
.deviceTreeHead
, PE_state
.bootArgs
,
153 (void *)0, (void *)0);
156 void PE_init_platform(boolean_t vm_initialized
, void *_args
)
158 boot_args
*args
= (boot_args
*)_args
;
160 if (PE_state
.initialized
== FALSE
)
162 PE_state
.initialized
= TRUE
;
163 PE_state
.bootArgs
= _args
;
164 PE_state
.deviceTreeHead
= args
->deviceTreeP
;
165 PE_state
.video
.v_baseAddr
= args
->Video
.v_baseAddr
;
166 PE_state
.video
.v_rowBytes
= args
->Video
.v_rowBytes
;
167 PE_state
.video
.v_width
= args
->Video
.v_width
;
168 PE_state
.video
.v_height
= args
->Video
.v_height
;
169 PE_state
.video
.v_depth
= args
->Video
.v_depth
;
170 PE_state
.video
.v_display
= args
->Video
.v_display
;
171 strcpy( PE_state
.video
.v_pixelFormat
, "PPPPPPPP");
177 * Setup the OpenFirmware Device Tree routines
178 * so the console can be found and the right I/O space
181 DTInit(PE_state
.deviceTreeHead
);
183 /* Setup gPEClockFrequencyInfo */
184 pe_identify_machine();
192 void PE_create_console( void )
194 if (PE_state
.video
.v_display
)
195 PE_initialize_console( &PE_state
.video
, kPEGraphicsMode
);
197 PE_initialize_console( &PE_state
.video
, kPETextMode
);
200 int PE_current_console( PE_Video
* info
)
202 *info
= PE_state
.video
;
203 info
->v_baseAddr
= 0;
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
.timebase_frequency_num
;
249 den
= gPEClockFrequencyInfo
.timebase_frequency_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
);