]> git.saurik.com Git - apple/xnu.git/blob - pexpert/ppc/pe_init.c
xnu-517.9.4.tar.gz
[apple/xnu.git] / pexpert / ppc / pe_init.c
1 /*
2 * Copyright (c) 2000 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/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>
34 #include <kern/sched_prim.h>
35
36 /* extern references */
37 void pe_identify_machine(void);
38
39 /* private globals */
40 PE_state_t PE_state;
41
42 /* Clock Frequency Info */
43 clock_frequency_info_t gPEClockFrequencyInfo;
44
45 static int PE_stub_read_write_time_of_day(unsigned int options, long * secs)
46 {
47 // believe it or, BSD crashes if invalid time returned. FIXME.
48 if( options == kPEReadTOD)
49 *secs = 0xb2383c72;
50
51 return 0;
52 }
53
54 static int PE_stub_poll_input(unsigned int options, char * c)
55 {
56 *c = 0xff;
57
58 return 1;
59 }
60
61 static int PE_stub_write_IIC(unsigned char addr, unsigned char reg,
62 unsigned char data)
63 {
64 return 1;
65 }
66
67 int (*PE_read_write_time_of_day)(unsigned int options, long * secs)
68 = PE_stub_read_write_time_of_day;
69 int (*PE_poll_input)(unsigned int options, char * c)
70 = PE_stub_poll_input;
71
72 int (*PE_write_IIC)(unsigned char addr, unsigned char reg,
73 unsigned char data)
74 = PE_stub_write_IIC;
75
76
77 int PE_initialize_console( PE_Video * info, int op )
78 {
79 static int last_console = -1;
80 Boot_Video bootInfo;
81 Boot_Video * bInfo;
82
83 if( info) {
84 bootInfo.v_baseAddr = info->v_baseAddr;
85 bootInfo.v_rowBytes = info->v_rowBytes;
86 bootInfo.v_width = info->v_width;
87 bootInfo.v_height = info->v_height;
88 bootInfo.v_depth = info->v_depth;
89 bootInfo.v_display = 0;
90 bInfo = &bootInfo;
91 } else
92 bInfo = 0;
93
94 switch( op ) {
95
96 case kPEDisableScreen:
97 initialize_screen((void *) bInfo, op);
98 last_console = switch_to_serial_console();
99 kprintf("kPEDisableScreen %d\n",last_console);
100 break;
101
102 case kPEEnableScreen:
103 initialize_screen((void *) bInfo, op);
104 kprintf("kPEEnableScreen %d\n",last_console);
105 if( last_console != -1)
106 switch_to_old_console( last_console);
107 break;
108
109 default:
110 initialize_screen((void *) bInfo, op);
111 break;
112 }
113
114 return 0;
115 }
116
117 void PE_init_iokit(void)
118 {
119 kern_return_t ret;
120 DTEntry entry;
121 int size;
122 void ** map;
123
124 PE_init_kprintf(TRUE);
125 PE_init_printf(TRUE);
126
127 if( kSuccess == DTLookupEntry(0, "/chosen/memory-map", &entry)) {
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 }
143 }
144 panic_ui_initialize( (unsigned char *) appleClut8 );
145 vc_progress_initialize( &default_progress, default_progress_data, (unsigned char *) appleClut8 );
146
147 ret = StartIOKit( PE_state.deviceTreeHead, PE_state.bootArgs, (void *)0, (void *)0);
148 }
149
150 void PE_init_platform(boolean_t vm_initialized, void *_args)
151 {
152 boot_args *args = (boot_args *)_args;
153
154 if (PE_state.initialized == FALSE)
155 {
156 PE_state.initialized = TRUE;
157 PE_state.bootArgs = _args;
158 PE_state.deviceTreeHead = args->deviceTreeP;
159 PE_state.video.v_baseAddr = args->Video.v_baseAddr;
160 PE_state.video.v_rowBytes = args->Video.v_rowBytes;
161 PE_state.video.v_width = args->Video.v_width;
162 PE_state.video.v_height = args->Video.v_height;
163 PE_state.video.v_depth = args->Video.v_depth;
164 PE_state.video.v_display = args->Video.v_display;
165 strcpy( PE_state.video.v_pixelFormat, "PPPPPPPP");
166 }
167
168 if (!vm_initialized)
169 {
170 /*
171 * Setup the OpenFirmware Device Tree routines
172 * so the console can be found and the right I/O space
173 * can be used..
174 */
175 DTInit(PE_state.deviceTreeHead);
176
177 /* Setup gPEClockFrequencyInfo */
178 pe_identify_machine();
179 }
180 else
181 {
182 pe_init_debug();
183 }
184 }
185
186 void PE_create_console( void )
187 {
188 if ( PE_state.video.v_display )
189 PE_initialize_console( &PE_state.video, kPEGraphicsMode );
190 else
191 PE_initialize_console( &PE_state.video, kPETextMode );
192 }
193
194 int PE_current_console( PE_Video * info )
195 {
196 *info = PE_state.video;
197 info->v_baseAddr = 0;
198 return( 0);
199 }
200
201 void PE_display_icon( unsigned int flags,
202 const char * name )
203 {
204 if( default_noroot_data)
205 vc_display_icon( &default_noroot, default_noroot_data );
206 }
207
208 extern boolean_t PE_get_hotkey(
209 unsigned char key)
210 {
211 unsigned char * adbKeymap;
212 int size;
213 DTEntry entry;
214
215 if( (kSuccess != DTLookupEntry( 0, "/", &entry))
216 || (kSuccess != DTGetProperty( entry, "AAPL,adb-keymap",
217 (void **)&adbKeymap, &size))
218 || (size != 16))
219
220 return( FALSE);
221
222 if( key > 127)
223 return( FALSE);
224
225 return( adbKeymap[ key / 8 ] & (0x80 >> (key & 7)));
226 }
227
228 static timebase_callback_func gTimebaseCallback;
229
230 void PE_register_timebase_callback(timebase_callback_func callback)
231 {
232 gTimebaseCallback = callback;
233
234 PE_call_timebase_callback();
235 }
236
237 void PE_call_timebase_callback(void)
238 {
239 struct timebase_freq_t timebase_freq;
240 unsigned long num, den, cnt;
241
242 num = gPEClockFrequencyInfo.timebase_frequency_num;
243 den = gPEClockFrequencyInfo.timebase_frequency_den;
244
245 cnt = 2;
246 while (cnt <= den) {
247 if ((num % cnt) || (den % cnt)) {
248 cnt++;
249 continue;
250 }
251
252 num /= cnt;
253 den /= cnt;
254 }
255
256 timebase_freq.timebase_num = num;
257 timebase_freq.timebase_den = den;
258
259 if (gTimebaseCallback) gTimebaseCallback(&timebase_freq);
260 }