]> git.saurik.com Git - apple/xnu.git/blame - pexpert/ppc/pe_init.c
xnu-1228.5.20.tar.gz
[apple/xnu.git] / pexpert / ppc / pe_init.c
CommitLineData
1c79356b 1/*
2d21ac55 2 * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
8f6c56a5 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28/*
29 * file: pe_init.c
30 * PPC platform expert initialization.
31 */
1c79356b
A
32#include <mach/time_value.h>
33#include <pexpert/protos.h>
34#include <pexpert/pexpert.h>
35#include <pexpert/ppc/interrupts.h>
36#include <pexpert/device_tree.h>
37#include <pexpert/pe_images.h>
38#include <kern/debug.h>
9bccf70c 39#include <kern/sched_prim.h>
0c530ab8 40#include <vm/pmap.h>
1c79356b 41
3a60a9f5 42
1c79356b
A
43/* extern references */
44void pe_identify_machine(void);
45
46/* private globals */
47PE_state_t PE_state;
48
49/* Clock Frequency Info */
50clock_frequency_info_t gPEClockFrequencyInfo;
51
52static int PE_stub_read_write_time_of_day(unsigned int options, long * secs)
53{
54 // believe it or, BSD crashes if invalid time returned. FIXME.
55 if( options == kPEReadTOD)
56 *secs = 0xb2383c72;
57
58 return 0;
59}
60
2d21ac55 61static int PE_stub_poll_input(__unused unsigned int options, char * c)
1c79356b
A
62{
63 *c = 0xff;
64
65 return 1;
66}
67
2d21ac55
A
68static int PE_stub_write_IIC(__unused unsigned char addr, __unused unsigned char reg,
69 __unused unsigned char data)
1c79356b
A
70{
71 return 1;
72}
73
74int (*PE_read_write_time_of_day)(unsigned int options, long * secs)
75 = PE_stub_read_write_time_of_day;
76int (*PE_poll_input)(unsigned int options, char * c)
77 = PE_stub_poll_input;
78
79int (*PE_write_IIC)(unsigned char addr, unsigned char reg,
80 unsigned char data)
81 = PE_stub_write_IIC;
82
83
84int PE_initialize_console( PE_Video * info, int op )
85{
86 static int last_console = -1;
2d21ac55
A
87
88 if (info) {
89 info->v_offset = 0;
90 info->v_length = 0;
91 info->v_display = 0;
92 }
1c79356b
A
93
94 switch( op ) {
95
96 case kPEDisableScreen:
2d21ac55 97 initialize_screen(info, op);
1c79356b
A
98 last_console = switch_to_serial_console();
99 kprintf("kPEDisableScreen %d\n",last_console);
100 break;
101
102 case kPEEnableScreen:
2d21ac55 103 initialize_screen(info, op);
1c79356b
A
104 kprintf("kPEEnableScreen %d\n",last_console);
105 if( last_console != -1)
106 switch_to_old_console( last_console);
107 break;
108
109 default:
2d21ac55 110 initialize_screen(info, op);
1c79356b
A
111 break;
112 }
113
114 return 0;
115}
116
1c79356b
A
117void PE_init_iokit(void)
118{
119 kern_return_t ret;
2d21ac55
A
120 DTEntry entry;
121 unsigned int size;
122 void ** map;
1c79356b
A
123
124 PE_init_kprintf(TRUE);
125 PE_init_printf(TRUE);
126
2d21ac55 127 if( kSuccess == DTLookupEntry(NULL, "/chosen/memory-map", &entry)) {
9bccf70c
A
128
129 boot_progress_element * bootPict;
130
131 if( kSuccess == DTGetProperty(entry, "BootCLUT", (void **) &map, &size))
132 bcopy( map[0], appleClut8, sizeof(appleClut8) );
133
134 if( kSuccess == DTGetProperty(entry, "Pict-FailedBoot", (void **) &map, &size)) {
135
136 bootPict = (boot_progress_element *) map[0];
137 default_noroot.width = bootPict->width;
138 default_noroot.height = bootPict->height;
139 default_noroot.dx = 0;
140 default_noroot.dy = bootPict->yOffset;
141 default_noroot_data = &bootPict->data[0];
142 }
1c79356b 143 }
55e303ae 144 panic_ui_initialize( (unsigned char *) appleClut8 );
9bccf70c 145 vc_progress_initialize( &default_progress, default_progress_data, (unsigned char *) appleClut8 );
1c79356b 146
55e303ae 147 ret = StartIOKit( PE_state.deviceTreeHead, PE_state.bootArgs, (void *)0, (void *)0);
1c79356b
A
148}
149
150void PE_init_platform(boolean_t vm_initialized, void *_args)
151{
3a60a9f5
A
152 DTEntry dsouth, dnorth, root, dcpu;
153 char *model;
2d21ac55 154 unsigned int msize, size;
3a60a9f5
A
155 uint32_t *south, *north, *pdata, *ddata;
156 int i;
157
158 boot_args *args = (boot_args *)_args;
1c79356b
A
159
160 if (PE_state.initialized == FALSE)
161 {
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;
2d21ac55
A
171 strlcpy(PE_state.video.v_pixelFormat, "PPPPPPPP",
172 sizeof(PE_state.video.v_pixelFormat));
1c79356b
A
173 }
174
175 if (!vm_initialized)
176 {
177 /*
178 * Setup the OpenFirmware Device Tree routines
179 * so the console can be found and the right I/O space
180 * can be used..
181 */
182 DTInit(PE_state.deviceTreeHead);
183
184 /* Setup gPEClockFrequencyInfo */
185 pe_identify_machine();
186 }
187 else
188 {
189 pe_init_debug();
3a60a9f5 190
1c79356b
A
191 }
192}
193
194void PE_create_console( void )
195{
55e303ae
A
196 if ( PE_state.video.v_display )
197 PE_initialize_console( &PE_state.video, kPEGraphicsMode );
198 else
199 PE_initialize_console( &PE_state.video, kPETextMode );
1c79356b
A
200}
201
202int PE_current_console( PE_Video * info )
203{
204 *info = PE_state.video;
2d21ac55 205
1c79356b
A
206 return( 0);
207}
208
2d21ac55
A
209void PE_display_icon( __unused unsigned int flags,
210 __unused const char * name )
1c79356b 211{
9bccf70c
A
212 if( default_noroot_data)
213 vc_display_icon( &default_noroot, default_noroot_data );
1c79356b
A
214}
215
2d21ac55
A
216boolean_t
217PE_get_hotkey(unsigned char key)
1c79356b
A
218{
219 unsigned char * adbKeymap;
2d21ac55
A
220 unsigned int size;
221 DTEntry entry;
1c79356b 222
2d21ac55 223 if( (kSuccess != DTLookupEntry(NULL, "/", &entry))
1c79356b
A
224 || (kSuccess != DTGetProperty( entry, "AAPL,adb-keymap",
225 (void **)&adbKeymap, &size))
226 || (size != 16))
227
228 return( FALSE);
229
230 if( key > 127)
231 return( FALSE);
232
233 return( adbKeymap[ key / 8 ] & (0x80 >> (key & 7)));
234}
235
236static timebase_callback_func gTimebaseCallback;
237
238void PE_register_timebase_callback(timebase_callback_func callback)
239{
240 gTimebaseCallback = callback;
241
242 PE_call_timebase_callback();
243}
244
245void PE_call_timebase_callback(void)
246{
247 struct timebase_freq_t timebase_freq;
248 unsigned long num, den, cnt;
249
90556fb8
A
250 num = gPEClockFrequencyInfo.timebase_frequency_num;
251 den = gPEClockFrequencyInfo.timebase_frequency_den;
1c79356b
A
252
253 cnt = 2;
254 while (cnt <= den) {
255 if ((num % cnt) || (den % cnt)) {
256 cnt++;
257 continue;
258 }
259
260 num /= cnt;
261 den /= cnt;
262 }
263
264 timebase_freq.timebase_num = num;
265 timebase_freq.timebase_den = den;
266
267 if (gTimebaseCallback) gTimebaseCallback(&timebase_freq);
268}