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