]> git.saurik.com Git - apple/xnu.git/blob - pexpert/ppc/pe_init.c
xnu-792.10.96.tar.gz
[apple/xnu.git] / pexpert / ppc / pe_init.c
1 /*
2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * file: pe_init.c
24 * PPC platform expert initialization.
25 */
26 #include <mach/time_value.h>
27 #include <pexpert/protos.h>
28 #include <pexpert/pexpert.h>
29 #include <pexpert/ppc/interrupts.h>
30 #include <pexpert/device_tree.h>
31 #include <pexpert/pe_images.h>
32 #include <kern/debug.h>
33 #include <kern/sched_prim.h>
34 #include <vm/pmap.h>
35
36
37 /* extern references */
38 void pe_identify_machine(void);
39
40 /* private globals */
41 PE_state_t PE_state;
42
43 /* Clock Frequency Info */
44 clock_frequency_info_t gPEClockFrequencyInfo;
45
46 static int PE_stub_read_write_time_of_day(unsigned int options, long * secs)
47 {
48 // believe it or, BSD crashes if invalid time returned. FIXME.
49 if( options == kPEReadTOD)
50 *secs = 0xb2383c72;
51
52 return 0;
53 }
54
55 static int PE_stub_poll_input(unsigned int options, char * c)
56 {
57 *c = 0xff;
58
59 return 1;
60 }
61
62 static int PE_stub_write_IIC(unsigned char addr, unsigned char reg,
63 unsigned char data)
64 {
65 return 1;
66 }
67
68 int (*PE_read_write_time_of_day)(unsigned int options, long * secs)
69 = PE_stub_read_write_time_of_day;
70 int (*PE_poll_input)(unsigned int options, char * c)
71 = PE_stub_poll_input;
72
73 int (*PE_write_IIC)(unsigned char addr, unsigned char reg,
74 unsigned char data)
75 = PE_stub_write_IIC;
76
77
78 int PE_initialize_console( PE_Video * info, int op )
79 {
80 static int last_console = -1;
81 Boot_Video bootInfo;
82 Boot_Video * bInfo;
83
84 if( info) {
85 bootInfo.v_baseAddr = info->v_baseAddr;
86 bootInfo.v_rowBytes = info->v_rowBytes;
87 bootInfo.v_width = info->v_width;
88 bootInfo.v_height = info->v_height;
89 bootInfo.v_depth = info->v_depth;
90 bootInfo.v_display = 0;
91 bInfo = &bootInfo;
92 } else
93 bInfo = 0;
94
95 switch( op ) {
96
97 case kPEDisableScreen:
98 initialize_screen((void *) bInfo, op);
99 last_console = switch_to_serial_console();
100 kprintf("kPEDisableScreen %d\n",last_console);
101 break;
102
103 case kPEEnableScreen:
104 initialize_screen((void *) bInfo, op);
105 kprintf("kPEEnableScreen %d\n",last_console);
106 if( last_console != -1)
107 switch_to_old_console( last_console);
108 break;
109
110 default:
111 initialize_screen((void *) bInfo, op);
112 break;
113 }
114
115 return 0;
116 }
117
118 void PE_init_iokit(void)
119 {
120 kern_return_t ret;
121 DTEntry entry;
122 int size;
123 void ** map;
124
125 PE_init_kprintf(TRUE);
126 PE_init_printf(TRUE);
127
128 if( kSuccess == DTLookupEntry(0, "/chosen/memory-map", &entry)) {
129
130 boot_progress_element * bootPict;
131
132 if( kSuccess == DTGetProperty(entry, "BootCLUT", (void **) &map, &size))
133 bcopy( map[0], appleClut8, sizeof(appleClut8) );
134
135 if( kSuccess == DTGetProperty(entry, "Pict-FailedBoot", (void **) &map, &size)) {
136
137 bootPict = (boot_progress_element *) map[0];
138 default_noroot.width = bootPict->width;
139 default_noroot.height = bootPict->height;
140 default_noroot.dx = 0;
141 default_noroot.dy = bootPict->yOffset;
142 default_noroot_data = &bootPict->data[0];
143 }
144 }
145 panic_ui_initialize( (unsigned char *) appleClut8 );
146 vc_progress_initialize( &default_progress, default_progress_data, (unsigned char *) appleClut8 );
147
148 ret = StartIOKit( PE_state.deviceTreeHead, PE_state.bootArgs, (void *)0, (void *)0);
149 }
150
151 void PE_init_platform(boolean_t vm_initialized, void *_args)
152 {
153 DTEntry dsouth, dnorth, root, dcpu;
154 char *model;
155 int msize, size;
156 uint32_t *south, *north, *pdata, *ddata;
157 int i;
158
159 boot_args *args = (boot_args *)_args;
160
161 if (PE_state.initialized == FALSE)
162 {
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");
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();
190
191 }
192 }
193
194 void PE_create_console( void )
195 {
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 );
200 }
201
202 int PE_current_console( PE_Video * info )
203 {
204 *info = PE_state.video;
205 info->v_baseAddr = 0;
206 return( 0);
207 }
208
209 void PE_display_icon( unsigned int flags,
210 const char * name )
211 {
212 if( default_noroot_data)
213 vc_display_icon( &default_noroot, default_noroot_data );
214 }
215
216 extern boolean_t PE_get_hotkey(
217 unsigned char key)
218 {
219 unsigned char * adbKeymap;
220 int size;
221 DTEntry entry;
222
223 if( (kSuccess != DTLookupEntry( 0, "/", &entry))
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
236 static timebase_callback_func gTimebaseCallback;
237
238 void PE_register_timebase_callback(timebase_callback_func callback)
239 {
240 gTimebaseCallback = callback;
241
242 PE_call_timebase_callback();
243 }
244
245 void PE_call_timebase_callback(void)
246 {
247 struct timebase_freq_t timebase_freq;
248 unsigned long num, den, cnt;
249
250 num = gPEClockFrequencyInfo.timebase_frequency_num;
251 den = gPEClockFrequencyInfo.timebase_frequency_den;
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 }