]> git.saurik.com Git - apple/xnu.git/blob - pexpert/ppc/pe_init.c
02b5251d65e24a40d24f6d43901b4a5c8af22ad0
[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/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
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 void PE_init_iokit(void)
117 {
118 kern_return_t ret;
119 DTEntry entry;
120 int size;
121 void ** map;
122
123 PE_init_kprintf(TRUE);
124 PE_init_printf(TRUE);
125
126 if( kSuccess == DTLookupEntry(0, "/chosen/memory-map", &entry)) {
127
128 boot_progress_element * bootPict;
129
130 if( kSuccess == DTGetProperty(entry, "BootCLUT", (void **) &map, &size))
131 bcopy( map[0], appleClut8, sizeof(appleClut8) );
132
133 if( kSuccess == DTGetProperty(entry, "Pict-FailedBoot", (void **) &map, &size)) {
134
135 bootPict = (boot_progress_element *) map[0];
136 default_noroot.width = bootPict->width;
137 default_noroot.height = bootPict->height;
138 default_noroot.dx = 0;
139 default_noroot.dy = bootPict->yOffset;
140 default_noroot_data = &bootPict->data[0];
141 }
142 }
143 panic_ui_initialize( (unsigned char *) appleClut8 );
144 vc_progress_initialize( &default_progress, default_progress_data, (unsigned char *) appleClut8 );
145
146 ret = StartIOKit( PE_state.deviceTreeHead, PE_state.bootArgs, (void *)0, (void *)0);
147 }
148
149 void PE_init_platform(boolean_t vm_initialized, void *_args)
150 {
151 boot_args *args = (boot_args *)_args;
152
153 if (PE_state.initialized == FALSE)
154 {
155 PE_state.initialized = TRUE;
156 PE_state.bootArgs = _args;
157 PE_state.deviceTreeHead = args->deviceTreeP;
158 PE_state.video.v_baseAddr = args->Video.v_baseAddr;
159 PE_state.video.v_rowBytes = args->Video.v_rowBytes;
160 PE_state.video.v_width = args->Video.v_width;
161 PE_state.video.v_height = args->Video.v_height;
162 PE_state.video.v_depth = args->Video.v_depth;
163 PE_state.video.v_display = args->Video.v_display;
164 strcpy( PE_state.video.v_pixelFormat, "PPPPPPPP");
165 }
166
167 if (!vm_initialized)
168 {
169 /*
170 * Setup the OpenFirmware Device Tree routines
171 * so the console can be found and the right I/O space
172 * can be used..
173 */
174 DTInit(PE_state.deviceTreeHead);
175
176 /* Setup gPEClockFrequencyInfo */
177 pe_identify_machine();
178 }
179 else
180 {
181 pe_init_debug();
182 }
183 }
184
185 void PE_create_console( void )
186 {
187 if ( PE_state.video.v_display )
188 PE_initialize_console( &PE_state.video, kPEGraphicsMode );
189 else
190 PE_initialize_console( &PE_state.video, kPETextMode );
191 }
192
193 int PE_current_console( PE_Video * info )
194 {
195 *info = PE_state.video;
196 info->v_baseAddr = 0;
197 return( 0);
198 }
199
200 void PE_display_icon( unsigned int flags,
201 const char * name )
202 {
203 if( default_noroot_data)
204 vc_display_icon( &default_noroot, default_noroot_data );
205 }
206
207 extern boolean_t PE_get_hotkey(
208 unsigned char key)
209 {
210 unsigned char * adbKeymap;
211 int size;
212 DTEntry entry;
213
214 if( (kSuccess != DTLookupEntry( 0, "/", &entry))
215 || (kSuccess != DTGetProperty( entry, "AAPL,adb-keymap",
216 (void **)&adbKeymap, &size))
217 || (size != 16))
218
219 return( FALSE);
220
221 if( key > 127)
222 return( FALSE);
223
224 return( adbKeymap[ key / 8 ] & (0x80 >> (key & 7)));
225 }
226
227 static timebase_callback_func gTimebaseCallback;
228
229 void PE_register_timebase_callback(timebase_callback_func callback)
230 {
231 gTimebaseCallback = callback;
232
233 PE_call_timebase_callback();
234 }
235
236 void PE_call_timebase_callback(void)
237 {
238 struct timebase_freq_t timebase_freq;
239 unsigned long num, den, cnt;
240
241 num = gPEClockFrequencyInfo.timebase_frequency_num;
242 den = gPEClockFrequencyInfo.timebase_frequency_den;
243
244 cnt = 2;
245 while (cnt <= den) {
246 if ((num % cnt) || (den % cnt)) {
247 cnt++;
248 continue;
249 }
250
251 num /= cnt;
252 den /= cnt;
253 }
254
255 timebase_freq.timebase_num = num;
256 timebase_freq.timebase_den = den;
257
258 if (gTimebaseCallback) gTimebaseCallback(&timebase_freq);
259 }