]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
43866e37 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
43866e37 A |
8 | * This file contains Original Code and/or Modifications of Original Code |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
14 | * | |
15 | * The Original Code and all software distributed under the License are | |
16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
43866e37 A |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
1c79356b A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | /* | |
26 | * file: pe_init.c | |
27 | * PPC platform expert initialization. | |
28 | */ | |
29 | #include <mach/boot_info.h> | |
30 | #include <mach/time_value.h> | |
31 | #include <pexpert/protos.h> | |
32 | #include <pexpert/pexpert.h> | |
33 | #include <pexpert/ppc/interrupts.h> | |
34 | #include <pexpert/device_tree.h> | |
35 | #include <pexpert/pe_images.h> | |
36 | #include <kern/debug.h> | |
9bccf70c | 37 | #include <kern/sched_prim.h> |
1c79356b A |
38 | |
39 | /* extern references */ | |
40 | void pe_identify_machine(void); | |
41 | ||
42 | /* private globals */ | |
43 | PE_state_t PE_state; | |
44 | ||
45 | /* Clock Frequency Info */ | |
46 | clock_frequency_info_t gPEClockFrequencyInfo; | |
47 | ||
48 | static int PE_stub_read_write_time_of_day(unsigned int options, long * secs) | |
49 | { | |
50 | // believe it or, BSD crashes if invalid time returned. FIXME. | |
51 | if( options == kPEReadTOD) | |
52 | *secs = 0xb2383c72; | |
53 | ||
54 | return 0; | |
55 | } | |
56 | ||
57 | static int PE_stub_poll_input(unsigned int options, char * c) | |
58 | { | |
59 | *c = 0xff; | |
60 | ||
61 | return 1; | |
62 | } | |
63 | ||
64 | static int PE_stub_write_IIC(unsigned char addr, unsigned char reg, | |
65 | unsigned char data) | |
66 | { | |
67 | return 1; | |
68 | } | |
69 | ||
70 | int (*PE_read_write_time_of_day)(unsigned int options, long * secs) | |
71 | = PE_stub_read_write_time_of_day; | |
72 | int (*PE_poll_input)(unsigned int options, char * c) | |
73 | = PE_stub_poll_input; | |
74 | ||
75 | int (*PE_write_IIC)(unsigned char addr, unsigned char reg, | |
76 | unsigned char data) | |
77 | = PE_stub_write_IIC; | |
78 | ||
79 | ||
80 | int PE_initialize_console( PE_Video * info, int op ) | |
81 | { | |
82 | static int last_console = -1; | |
83 | Boot_Video bootInfo; | |
84 | Boot_Video * bInfo; | |
85 | ||
86 | if( info) { | |
87 | bootInfo.v_baseAddr = info->v_baseAddr; | |
88 | bootInfo.v_rowBytes = info->v_rowBytes; | |
89 | bootInfo.v_width = info->v_width; | |
90 | bootInfo.v_height = info->v_height; | |
91 | bootInfo.v_depth = info->v_depth; | |
92 | bootInfo.v_display = 0; | |
93 | bInfo = &bootInfo; | |
94 | } else | |
95 | bInfo = 0; | |
96 | ||
97 | switch( op ) { | |
98 | ||
99 | case kPEDisableScreen: | |
100 | initialize_screen((void *) bInfo, op); | |
101 | last_console = switch_to_serial_console(); | |
102 | kprintf("kPEDisableScreen %d\n",last_console); | |
103 | break; | |
104 | ||
105 | case kPEEnableScreen: | |
106 | initialize_screen((void *) bInfo, op); | |
107 | kprintf("kPEEnableScreen %d\n",last_console); | |
108 | if( last_console != -1) | |
109 | switch_to_old_console( last_console); | |
110 | break; | |
111 | ||
112 | default: | |
113 | initialize_screen((void *) bInfo, op); | |
114 | break; | |
115 | } | |
116 | ||
117 | return 0; | |
118 | } | |
119 | ||
1c79356b A |
120 | void PE_init_iokit(void) |
121 | { | |
122 | kern_return_t ret; | |
9bccf70c A |
123 | DTEntry entry; |
124 | int size; | |
9bccf70c | 125 | void ** map; |
1c79356b A |
126 | |
127 | PE_init_kprintf(TRUE); | |
128 | PE_init_printf(TRUE); | |
129 | ||
9bccf70c A |
130 | if( kSuccess == DTLookupEntry(0, "/chosen/memory-map", &entry)) { |
131 | ||
132 | boot_progress_element * bootPict; | |
133 | ||
134 | if( kSuccess == DTGetProperty(entry, "BootCLUT", (void **) &map, &size)) | |
135 | bcopy( map[0], appleClut8, sizeof(appleClut8) ); | |
136 | ||
137 | if( kSuccess == DTGetProperty(entry, "Pict-FailedBoot", (void **) &map, &size)) { | |
138 | ||
139 | bootPict = (boot_progress_element *) map[0]; | |
140 | default_noroot.width = bootPict->width; | |
141 | default_noroot.height = bootPict->height; | |
142 | default_noroot.dx = 0; | |
143 | default_noroot.dy = bootPict->yOffset; | |
144 | default_noroot_data = &bootPict->data[0]; | |
145 | } | |
1c79356b | 146 | } |
55e303ae | 147 | panic_ui_initialize( (unsigned char *) appleClut8 ); |
9bccf70c | 148 | vc_progress_initialize( &default_progress, default_progress_data, (unsigned char *) appleClut8 ); |
1c79356b | 149 | |
55e303ae | 150 | ret = StartIOKit( PE_state.deviceTreeHead, PE_state.bootArgs, (void *)0, (void *)0); |
1c79356b A |
151 | } |
152 | ||
153 | void PE_init_platform(boolean_t vm_initialized, void *_args) | |
154 | { | |
155 | boot_args *args = (boot_args *)_args; | |
156 | ||
157 | if (PE_state.initialized == FALSE) | |
158 | { | |
159 | PE_state.initialized = TRUE; | |
160 | PE_state.bootArgs = _args; | |
161 | PE_state.deviceTreeHead = args->deviceTreeP; | |
162 | PE_state.video.v_baseAddr = args->Video.v_baseAddr; | |
163 | PE_state.video.v_rowBytes = args->Video.v_rowBytes; | |
164 | PE_state.video.v_width = args->Video.v_width; | |
165 | PE_state.video.v_height = args->Video.v_height; | |
166 | PE_state.video.v_depth = args->Video.v_depth; | |
167 | PE_state.video.v_display = args->Video.v_display; | |
168 | strcpy( PE_state.video.v_pixelFormat, "PPPPPPPP"); | |
169 | } | |
170 | ||
171 | if (!vm_initialized) | |
172 | { | |
173 | /* | |
174 | * Setup the OpenFirmware Device Tree routines | |
175 | * so the console can be found and the right I/O space | |
176 | * can be used.. | |
177 | */ | |
178 | DTInit(PE_state.deviceTreeHead); | |
179 | ||
180 | /* Setup gPEClockFrequencyInfo */ | |
181 | pe_identify_machine(); | |
182 | } | |
183 | else | |
184 | { | |
185 | pe_init_debug(); | |
186 | } | |
187 | } | |
188 | ||
189 | void PE_create_console( void ) | |
190 | { | |
55e303ae A |
191 | if ( PE_state.video.v_display ) |
192 | PE_initialize_console( &PE_state.video, kPEGraphicsMode ); | |
193 | else | |
194 | PE_initialize_console( &PE_state.video, kPETextMode ); | |
1c79356b A |
195 | } |
196 | ||
197 | int PE_current_console( PE_Video * info ) | |
198 | { | |
199 | *info = PE_state.video; | |
55e303ae | 200 | info->v_baseAddr = 0; |
1c79356b A |
201 | return( 0); |
202 | } | |
203 | ||
204 | void PE_display_icon( unsigned int flags, | |
205 | const char * name ) | |
206 | { | |
9bccf70c A |
207 | if( default_noroot_data) |
208 | vc_display_icon( &default_noroot, default_noroot_data ); | |
1c79356b A |
209 | } |
210 | ||
211 | extern boolean_t PE_get_hotkey( | |
212 | unsigned char key) | |
213 | { | |
214 | unsigned char * adbKeymap; | |
215 | int size; | |
216 | DTEntry entry; | |
217 | ||
218 | if( (kSuccess != DTLookupEntry( 0, "/", &entry)) | |
219 | || (kSuccess != DTGetProperty( entry, "AAPL,adb-keymap", | |
220 | (void **)&adbKeymap, &size)) | |
221 | || (size != 16)) | |
222 | ||
223 | return( FALSE); | |
224 | ||
225 | if( key > 127) | |
226 | return( FALSE); | |
227 | ||
228 | return( adbKeymap[ key / 8 ] & (0x80 >> (key & 7))); | |
229 | } | |
230 | ||
231 | static timebase_callback_func gTimebaseCallback; | |
232 | ||
233 | void PE_register_timebase_callback(timebase_callback_func callback) | |
234 | { | |
235 | gTimebaseCallback = callback; | |
236 | ||
237 | PE_call_timebase_callback(); | |
238 | } | |
239 | ||
240 | void PE_call_timebase_callback(void) | |
241 | { | |
242 | struct timebase_freq_t timebase_freq; | |
243 | unsigned long num, den, cnt; | |
244 | ||
90556fb8 A |
245 | num = gPEClockFrequencyInfo.timebase_frequency_num; |
246 | den = gPEClockFrequencyInfo.timebase_frequency_den; | |
1c79356b A |
247 | |
248 | cnt = 2; | |
249 | while (cnt <= den) { | |
250 | if ((num % cnt) || (den % cnt)) { | |
251 | cnt++; | |
252 | continue; | |
253 | } | |
254 | ||
255 | num /= cnt; | |
256 | den /= cnt; | |
257 | } | |
258 | ||
259 | timebase_freq.timebase_num = num; | |
260 | timebase_freq.timebase_den = den; | |
261 | ||
262 | if (gTimebaseCallback) gTimebaseCallback(&timebase_freq); | |
263 | } |