]> git.saurik.com Git - apple/xnu.git/blob - pexpert/i386/pe_init.c
xnu-792.18.15.tar.gz
[apple/xnu.git] / pexpert / i386 / pe_init.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 /*
29 * file: pe_init.c
30 * i386 platform expert initialization.
31 */
32 #include <sys/types.h>
33 #include <mach/vm_param.h>
34 #include <pexpert/protos.h>
35 #include <pexpert/pexpert.h>
36 #include <pexpert/boot.h>
37 #include <pexpert/device_tree.h>
38 #include <pexpert/pe_images.h>
39 #include <kern/sched_prim.h>
40 #include <kern/debug.h>
41
42 #include "fakePPCStructs.h"
43 #include "fakePPCDeviceTree.h"
44 #include "boot_images.h"
45
46 /* extern references */
47 extern void pe_identify_machine(void * args);
48 extern void initialize_screen(void *, unsigned int);
49
50 /* private globals */
51 PE_state_t PE_state;
52 dt_data gMemoryMapNode;
53 dt_data gDriversProp;
54 dt_data gRootpathProp;
55 dt_data gCompatibleProp;
56
57 /* Clock Frequency Info */
58 clock_frequency_info_t gPEClockFrequencyInfo;
59
60 void *gPEEFISystemTable = 0;
61 void *gPEEFIRuntimeServices = 0;
62
63 int PE_initialize_console( PE_Video * info, int op )
64 {
65 static int last_console = -1;
66 Boot_Video bootInfo;
67 Boot_Video * bInfo;
68
69 /*
70 * Refuse changes from outside pexpert.
71 * The video mode setup by the booter cannot be changed.
72 */
73 if ( info )
74 {
75 bootInfo.v_baseAddr = info->v_baseAddr;
76 bootInfo.v_rowBytes = info->v_rowBytes;
77 bootInfo.v_width = info->v_width;
78 bootInfo.v_height = info->v_height;
79 bootInfo.v_depth = info->v_depth;
80 bInfo = &bootInfo;
81 if (info == &PE_state.video) {
82 bootInfo.v_display = info->v_display;
83 } else {
84 bootInfo.v_display = GRAPHICS_MODE;
85 }
86 }
87 else
88 bInfo = 0;
89
90 switch ( op ) {
91
92 case kPEDisableScreen:
93 initialize_screen((void *) bInfo, op);
94 kprintf("kPEDisableScreen %d\n", last_console);
95 if (!console_is_serial())
96 last_console = switch_to_serial_console();
97 break;
98
99 case kPEEnableScreen:
100 initialize_screen((void *) bInfo, op);
101 kprintf("kPEEnableScreen %d\n", last_console);
102 if( last_console != -1)
103 switch_to_old_console( last_console);
104 break;
105
106 default:
107 initialize_screen((void *) bInfo, op);
108 break;
109 }
110
111 return 0;
112 }
113
114 void PE_init_iokit(void)
115 {
116 enum { kMaxBootVar = 128 };
117
118 typedef struct {
119 char name[32];
120 unsigned long length;
121 unsigned long value[2];
122 } DriversPackageProp;
123
124 boolean_t bootClutInitialized = FALSE;
125 boolean_t norootInitialized = FALSE;
126 DTEntry entry;
127 int size;
128 void ** map;
129
130 PE_init_kprintf(TRUE);
131 PE_init_printf(TRUE);
132
133 kprintf("Kernel boot args: '%s'\n", PE_boot_args());
134
135 /*
136 * Fetch the CLUT and the noroot image.
137 */
138 boot_progress_element * bootPict;
139
140 if( kSuccess == DTLookupEntry(0, "/chosen/memory-map", &entry)) {
141 if( kSuccess == DTGetProperty(entry, "BootCLUT", (void **) &map, &size)) {
142 bcopy( map[0], appleClut8, sizeof(appleClut8) );
143 bootClutInitialized = TRUE;
144 }
145
146 if( kSuccess == DTGetProperty(entry, "Pict-FailedBoot", (void **) &map, &size)) {
147 bootPict = (boot_progress_element *) map[0];
148 default_noroot.width = bootPict->width;
149 default_noroot.height = bootPict->height;
150 default_noroot.dx = 0;
151 default_noroot.dy = bootPict->yOffset;
152 default_noroot_data = &bootPict->data[0];
153 norootInitialized = TRUE;
154 }
155 }
156
157 if (!bootClutInitialized) {
158 bcopy( (void *) (uintptr_t) bootClut, (void *) appleClut8, sizeof(appleClut8) );
159 }
160
161 if (!norootInitialized) {
162 default_noroot.width = kFailedBootWidth;
163 default_noroot.height = kFailedBootHeight;
164 default_noroot.dx = 0;
165 default_noroot.dy = kFailedBootOffset;
166 default_noroot_data = failedBootPict;
167 }
168
169 /*
170 * Initialize the panic UI
171 */
172 panic_ui_initialize( (unsigned char *) appleClut8 );
173
174 /*
175 * Initialize the spinning wheel (progress indicator).
176 */
177 vc_progress_initialize( &default_progress, default_progress_data,
178 (unsigned char *) appleClut8 );
179
180 (void) StartIOKit( PE_state.deviceTreeHead, PE_state.bootArgs, gPEEFIRuntimeServices, 0);
181 }
182
183 void PE_init_platform(boolean_t vm_initialized, void * _args)
184 {
185 boot_args *args = (boot_args *)_args;
186
187 if (PE_state.initialized == FALSE) {
188 PE_state.initialized = TRUE;
189
190 // New EFI-style
191 PE_state.bootArgs = _args;
192 PE_state.deviceTreeHead = args->deviceTreeP;
193 PE_state.video.v_baseAddr = args->Video.v_baseAddr;
194 PE_state.video.v_rowBytes = args->Video.v_rowBytes;
195 PE_state.video.v_width = args->Video.v_width;
196 PE_state.video.v_height = args->Video.v_height;
197 PE_state.video.v_depth = args->Video.v_depth;
198 PE_state.video.v_display = args->Video.v_display;
199 strcpy( PE_state.video.v_pixelFormat, "PPPPPPPP");
200 }
201
202 if (!vm_initialized) {
203 /* Hack! FIXME.. */
204 outb(0x21, 0xff); /* Maskout all interrupts Pic1 */
205 outb(0xa1, 0xff); /* Maskout all interrupts Pic2 */
206
207 if (PE_state.deviceTreeHead) {
208 DTInit(PE_state.deviceTreeHead);
209 }
210
211 pe_identify_machine(args);
212 } else {
213 DTEntry entry;
214 void *ptr;
215 uint32_t size;
216
217 pe_init_debug();
218 }
219 }
220
221 void PE_create_console( void )
222 {
223 if ( PE_state.video.v_display == GRAPHICS_MODE )
224 PE_initialize_console( &PE_state.video, kPEGraphicsMode );
225 else
226 PE_initialize_console( &PE_state.video, kPETextMode );
227 }
228
229 int PE_current_console( PE_Video * info )
230 {
231 *info = PE_state.video;
232
233 return (0);
234 }
235
236 void PE_display_icon( __unused unsigned int flags, __unused const char * name )
237 {
238 if ( default_noroot_data )
239 vc_display_icon( &default_noroot, default_noroot_data );
240 }
241
242 extern boolean_t PE_get_hotkey( __unused unsigned char key )
243 {
244 return (FALSE);
245 }
246
247 static timebase_callback_func gTimebaseCallback;
248
249 void PE_register_timebase_callback(timebase_callback_func callback)
250 {
251 gTimebaseCallback = callback;
252
253 PE_call_timebase_callback();
254 }
255
256 void PE_call_timebase_callback(void)
257 {
258 struct timebase_freq_t timebase_freq;
259 unsigned long num, den, cnt;
260
261 num = gPEClockFrequencyInfo.bus_clock_rate_num * gPEClockFrequencyInfo.bus_to_dec_rate_num;
262 den = gPEClockFrequencyInfo.bus_clock_rate_den * gPEClockFrequencyInfo.bus_to_dec_rate_den;
263
264 cnt = 2;
265 while (cnt <= den) {
266 if ((num % cnt) || (den % cnt)) {
267 cnt++;
268 continue;
269 }
270
271 num /= cnt;
272 den /= cnt;
273 }
274
275 timebase_freq.timebase_num = num;
276 timebase_freq.timebase_den = den;
277
278 if (gTimebaseCallback) gTimebaseCallback(&timebase_freq);
279 }
280
281 /*
282 * The default (non-functional) PE_poll_input handler.
283 */
284 static int
285 PE_stub_poll_input(__unused unsigned int options, char * c)
286 {
287 *c = 0xff;
288 return 1; /* 0 for success, 1 for unsupported */
289 }
290
291 /*
292 * Called by the kernel debugger to poll for keyboard input.
293 * Keyboard drivers may replace the default stub function
294 * with their polled-mode input function.
295 */
296 int (*PE_poll_input)(unsigned int options, char * c)
297 = PE_stub_poll_input;
298
299
300