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