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