]> git.saurik.com Git - apple/xnu.git/blob - pexpert/i386/pe_init.c
xnu-792.13.8.tar.gz
[apple/xnu.git] / pexpert / i386 / pe_init.c
1 /*
2 * Copyright (c) 2000 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 * i386 platform expert initialization.
33 */
34 #include <sys/types.h>
35 #include <mach/vm_param.h>
36 #include <pexpert/protos.h>
37 #include <pexpert/pexpert.h>
38 #include <pexpert/boot.h>
39 #include <pexpert/device_tree.h>
40 #include <pexpert/pe_images.h>
41 #include <kern/sched_prim.h>
42 #include <kern/debug.h>
43
44 #include "fakePPCStructs.h"
45 #include "fakePPCDeviceTree.h"
46 #include "boot_images.h"
47
48 /* extern references */
49 extern void pe_identify_machine(void * args);
50 extern void initialize_screen(void *, unsigned int);
51
52 /* private globals */
53 PE_state_t PE_state;
54 dt_data gMemoryMapNode;
55 dt_data gDriversProp;
56 dt_data gRootpathProp;
57 dt_data gCompatibleProp;
58
59 /* Clock Frequency Info */
60 clock_frequency_info_t gPEClockFrequencyInfo;
61
62 void *gPEEFISystemTable = 0;
63 void *gPEEFIRuntimeServices = 0;
64
65 int PE_initialize_console( PE_Video * info, int op )
66 {
67 static int last_console = -1;
68 Boot_Video bootInfo;
69 Boot_Video * bInfo;
70
71 /*
72 * Refuse changes from outside pexpert.
73 * The video mode setup by the booter cannot be changed.
74 */
75 if ( info )
76 {
77 bootInfo.v_baseAddr = info->v_baseAddr;
78 bootInfo.v_rowBytes = info->v_rowBytes;
79 bootInfo.v_width = info->v_width;
80 bootInfo.v_height = info->v_height;
81 bootInfo.v_depth = info->v_depth;
82 bInfo = &bootInfo;
83 if (info == &PE_state.video) {
84 bootInfo.v_display = info->v_display;
85 } else {
86 bootInfo.v_display = GRAPHICS_MODE;
87 }
88 }
89 else
90 bInfo = 0;
91
92 switch ( op ) {
93
94 case kPEDisableScreen:
95 initialize_screen((void *) bInfo, op);
96 kprintf("kPEDisableScreen %d\n", last_console);
97 if (!console_is_serial())
98 last_console = switch_to_serial_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 enum { kMaxBootVar = 128 };
119
120 typedef struct {
121 char name[32];
122 unsigned long length;
123 unsigned long value[2];
124 } DriversPackageProp;
125
126 boolean_t bootClutInitialized = FALSE;
127 boolean_t norootInitialized = FALSE;
128 DTEntry entry;
129 int size;
130 void ** map;
131
132 PE_init_kprintf(TRUE);
133 PE_init_printf(TRUE);
134
135 kprintf("Kernel boot args: '%s'\n", PE_boot_args());
136
137 /*
138 * Fetch the CLUT and the noroot image.
139 */
140 boot_progress_element * bootPict;
141
142 if( kSuccess == DTLookupEntry(0, "/chosen/memory-map", &entry)) {
143 if( kSuccess == DTGetProperty(entry, "BootCLUT", (void **) &map, &size)) {
144 bcopy( map[0], appleClut8, sizeof(appleClut8) );
145 bootClutInitialized = TRUE;
146 }
147
148 if( kSuccess == DTGetProperty(entry, "Pict-FailedBoot", (void **) &map, &size)) {
149 bootPict = (boot_progress_element *) map[0];
150 default_noroot.width = bootPict->width;
151 default_noroot.height = bootPict->height;
152 default_noroot.dx = 0;
153 default_noroot.dy = bootPict->yOffset;
154 default_noroot_data = &bootPict->data[0];
155 norootInitialized = TRUE;
156 }
157 }
158
159 if (!bootClutInitialized) {
160 bcopy( (void *) (uintptr_t) bootClut, (void *) appleClut8, sizeof(appleClut8) );
161 }
162
163 if (!norootInitialized) {
164 default_noroot.width = kFailedBootWidth;
165 default_noroot.height = kFailedBootHeight;
166 default_noroot.dx = 0;
167 default_noroot.dy = kFailedBootOffset;
168 default_noroot_data = failedBootPict;
169 }
170
171 /*
172 * Initialize the panic UI
173 */
174 panic_ui_initialize( (unsigned char *) appleClut8 );
175
176 /*
177 * Initialize the spinning wheel (progress indicator).
178 */
179 vc_progress_initialize( &default_progress, default_progress_data,
180 (unsigned char *) appleClut8 );
181
182 (void) StartIOKit( PE_state.deviceTreeHead, PE_state.bootArgs, gPEEFIRuntimeServices, 0);
183 }
184
185 void PE_init_platform(boolean_t vm_initialized, void * _args)
186 {
187 boot_args *args = (boot_args *)_args;
188
189 if (PE_state.initialized == FALSE) {
190 PE_state.initialized = TRUE;
191
192 // New EFI-style
193 PE_state.bootArgs = _args;
194 PE_state.deviceTreeHead = args->deviceTreeP;
195 PE_state.video.v_baseAddr = args->Video.v_baseAddr;
196 PE_state.video.v_rowBytes = args->Video.v_rowBytes;
197 PE_state.video.v_width = args->Video.v_width;
198 PE_state.video.v_height = args->Video.v_height;
199 PE_state.video.v_depth = args->Video.v_depth;
200 PE_state.video.v_display = args->Video.v_display;
201 strcpy( PE_state.video.v_pixelFormat, "PPPPPPPP");
202 }
203
204 if (!vm_initialized) {
205 /* Hack! FIXME.. */
206 outb(0x21, 0xff); /* Maskout all interrupts Pic1 */
207 outb(0xa1, 0xff); /* Maskout all interrupts Pic2 */
208
209 if (PE_state.deviceTreeHead) {
210 DTInit(PE_state.deviceTreeHead);
211 }
212
213 pe_identify_machine(args);
214 } else {
215 DTEntry entry;
216 void *ptr;
217 uint32_t size;
218
219 pe_init_debug();
220 }
221 }
222
223 void PE_create_console( void )
224 {
225 if ( PE_state.video.v_display == GRAPHICS_MODE )
226 PE_initialize_console( &PE_state.video, kPEGraphicsMode );
227 else
228 PE_initialize_console( &PE_state.video, kPETextMode );
229 }
230
231 int PE_current_console( PE_Video * info )
232 {
233 *info = PE_state.video;
234
235 return (0);
236 }
237
238 void PE_display_icon( __unused unsigned int flags, __unused const char * name )
239 {
240 if ( default_noroot_data )
241 vc_display_icon( &default_noroot, default_noroot_data );
242 }
243
244 extern boolean_t PE_get_hotkey( __unused unsigned char key )
245 {
246 return (FALSE);
247 }
248
249 static timebase_callback_func gTimebaseCallback;
250
251 void PE_register_timebase_callback(timebase_callback_func callback)
252 {
253 gTimebaseCallback = callback;
254
255 PE_call_timebase_callback();
256 }
257
258 void PE_call_timebase_callback(void)
259 {
260 struct timebase_freq_t timebase_freq;
261 unsigned long num, den, cnt;
262
263 num = gPEClockFrequencyInfo.bus_clock_rate_num * gPEClockFrequencyInfo.bus_to_dec_rate_num;
264 den = gPEClockFrequencyInfo.bus_clock_rate_den * gPEClockFrequencyInfo.bus_to_dec_rate_den;
265
266 cnt = 2;
267 while (cnt <= den) {
268 if ((num % cnt) || (den % cnt)) {
269 cnt++;
270 continue;
271 }
272
273 num /= cnt;
274 den /= cnt;
275 }
276
277 timebase_freq.timebase_num = num;
278 timebase_freq.timebase_den = den;
279
280 if (gTimebaseCallback) gTimebaseCallback(&timebase_freq);
281 }
282
283 /*
284 * The default (non-functional) PE_poll_input handler.
285 */
286 static int
287 PE_stub_poll_input(__unused unsigned int options, char * c)
288 {
289 *c = 0xff;
290 return 1; /* 0 for success, 1 for unsupported */
291 }
292
293 /*
294 * Called by the kernel debugger to poll for keyboard input.
295 * Keyboard drivers may replace the default stub function
296 * with their polled-mode input function.
297 */
298 int (*PE_poll_input)(unsigned int options, char * c)
299 = PE_stub_poll_input;
300
301
302