ofw_consinit.c revision 1.4.4.3 1 1.4.4.3 matt /* $NetBSD: ofw_consinit.c,v 1.4.4.3 2008/01/09 01:47:52 matt Exp $ */
2 1.4.4.2 matt
3 1.4.4.2 matt /*-
4 1.4.4.2 matt * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 1.4.4.2 matt * All rights reserved.
6 1.4.4.2 matt *
7 1.4.4.2 matt * This code is derived from software contributed to The NetBSD Foundation
8 1.4.4.2 matt * by Tim Rightnour
9 1.4.4.2 matt *
10 1.4.4.2 matt * Redistribution and use in source and binary forms, with or without
11 1.4.4.2 matt * modification, are permitted provided that the following conditions
12 1.4.4.2 matt * are met:
13 1.4.4.2 matt * 1. Redistributions of source code must retain the above copyright
14 1.4.4.2 matt * notice, this list of conditions and the following disclaimer.
15 1.4.4.2 matt * 2. Redistributions in binary form must reproduce the above copyright
16 1.4.4.2 matt * notice, this list of conditions and the following disclaimer in the
17 1.4.4.2 matt * documentation and/or other materials provided with the distribution.
18 1.4.4.2 matt * 3. All advertising materials mentioning features or use of this software
19 1.4.4.2 matt * must display the following acknowledgement:
20 1.4.4.2 matt * This product includes software developed by the NetBSD
21 1.4.4.2 matt * Foundation, Inc. and its contributors.
22 1.4.4.2 matt * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.4.4.2 matt * contributors may be used to endorse or promote products derived
24 1.4.4.2 matt * from this software without specific prior written permission.
25 1.4.4.2 matt *
26 1.4.4.2 matt * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.4.4.2 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.4.4.2 matt * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.4.4.2 matt * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.4.4.2 matt * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.4.4.2 matt * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.4.4.2 matt * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.4.4.2 matt * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.4.4.2 matt * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.4.4.2 matt * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.4.4.2 matt * POSSIBILITY OF SUCH DAMAGE.
37 1.4.4.2 matt */
38 1.4.4.2 matt
39 1.4.4.2 matt #include <sys/cdefs.h>
40 1.4.4.3 matt __KERNEL_RCSID(0, "$NetBSD: ofw_consinit.c,v 1.4.4.3 2008/01/09 01:47:52 matt Exp $");
41 1.4.4.2 matt
42 1.4.4.2 matt #include <sys/param.h>
43 1.4.4.2 matt #include <sys/buf.h>
44 1.4.4.2 matt #include <sys/tty.h>
45 1.4.4.2 matt
46 1.4.4.2 matt #include <machine/autoconf.h>
47 1.4.4.2 matt #include <machine/trap.h>
48 1.4.4.2 matt #include <machine/bus.h>
49 1.4.4.2 matt
50 1.4.4.2 matt #include <powerpc/ofw_cons.h>
51 1.4.4.2 matt
52 1.4.4.2 matt #include <dev/cons.h>
53 1.4.4.2 matt #include <dev/ofw/openfirm.h>
54 1.4.4.2 matt
55 1.4.4.2 matt #include <dev/wscons/wsksymvar.h>
56 1.4.4.2 matt #include <dev/wscons/wscons_callbacks.h>
57 1.4.4.2 matt
58 1.4.4.2 matt #include <machine/stdarg.h>
59 1.4.4.2 matt
60 1.4.4.2 matt #include "akbd.h"
61 1.4.4.2 matt #include "adbkbd.h"
62 1.4.4.3 matt #include "wsdisplay.h"
63 1.4.4.2 matt #include "ofb.h"
64 1.4.4.2 matt #include "isa.h"
65 1.4.4.2 matt
66 1.4.4.2 matt #include "zsc.h"
67 1.4.4.2 matt #if NZSC > 0
68 1.4.4.2 matt #include <machine/z8530var.h>
69 1.4.4.2 matt #endif
70 1.4.4.2 matt
71 1.4.4.2 matt #include "adb.h"
72 1.4.4.2 matt #if (NADB > 0)
73 1.4.4.2 matt #include <macppc/dev/adbvar.h>
74 1.4.4.2 matt #endif
75 1.4.4.2 matt
76 1.4.4.2 matt #include "ukbd.h"
77 1.4.4.2 matt #if (NUKBD > 0)
78 1.4.4.2 matt #include <dev/usb/ukbdvar.h>
79 1.4.4.2 matt struct usb_kbd_ihandles {
80 1.4.4.2 matt struct usb_kbd_ihandles *next;
81 1.4.4.2 matt int ihandle;
82 1.4.4.2 matt };
83 1.4.4.2 matt #endif
84 1.4.4.2 matt
85 1.4.4.2 matt #include "zstty.h"
86 1.4.4.2 matt #if (NZSTTY > 0)
87 1.4.4.2 matt #include <dev/ic/z8530reg.h>
88 1.4.4.2 matt extern struct consdev consdev_zs;
89 1.4.4.2 matt #endif
90 1.4.4.2 matt
91 1.4.4.2 matt #include "pckbc.h"
92 1.4.4.2 matt #if (NPCKBC > 0)
93 1.4.4.2 matt #include <dev/isa/isareg.h>
94 1.4.4.2 matt #include <dev/ic/i8042reg.h>
95 1.4.4.2 matt #include <dev/ic/pckbcvar.h>
96 1.4.4.2 matt #endif
97 1.4.4.2 matt
98 1.4.4.2 matt extern int console_node, console_instance;
99 1.4.4.2 matt
100 1.4.4.2 matt int chosen, stdin, stdout;
101 1.4.4.2 matt int ofkbd_ihandle;
102 1.4.4.2 matt
103 1.4.4.2 matt static void cninit_kd(void);
104 1.4.4.2 matt static void ofwoea_bootstrap_console(void);
105 1.4.4.2 matt static int ofwbootcons_cngetc(dev_t);
106 1.4.4.2 matt static void ofwbootcons_cnputc(dev_t, int);
107 1.4.4.2 matt
108 1.4.4.2 matt /*#define OFDEBUG*/
109 1.4.4.2 matt
110 1.4.4.2 matt struct consdev consdev_ofwbootcons = {
111 1.4.4.2 matt NULL, NULL,
112 1.4.4.2 matt ofwbootcons_cngetc,
113 1.4.4.2 matt ofwbootcons_cnputc,
114 1.4.4.2 matt nullcnpollc,
115 1.4.4.2 matt NULL, NULL, NULL, NODEV, CN_INTERNAL,
116 1.4.4.2 matt };
117 1.4.4.2 matt
118 1.4.4.2 matt #ifdef OFDEBUG
119 1.4.4.2 matt void ofprint(const char *, ...);
120 1.4.4.2 matt
121 1.4.4.2 matt void ofprint(const char *blah, ...)
122 1.4.4.2 matt {
123 1.4.4.2 matt va_list va;
124 1.4.4.2 matt char buf[256];
125 1.4.4.2 matt int len;
126 1.4.4.2 matt
127 1.4.4.2 matt va_start(va, blah);
128 1.4.4.2 matt len = vsnprintf(buf, sizeof(buf), blah, va);
129 1.4.4.2 matt OF_write(console_instance, buf, len);
130 1.4.4.2 matt }
131 1.4.4.2 matt
132 1.4.4.2 matt #define OFPRINTF ofprint
133 1.4.4.2 matt #else
134 1.4.4.2 matt #define OFPRINTF while(0) printf
135 1.4.4.2 matt #endif
136 1.4.4.2 matt
137 1.4.4.2 matt void
138 1.4.4.2 matt cninit(void)
139 1.4.4.2 matt {
140 1.4.4.3 matt char name[32];
141 1.4.4.2 matt
142 1.4.4.2 matt ofwoea_bootstrap_console();
143 1.4.4.2 matt
144 1.4.4.2 matt OFPRINTF("console node: %08x\n", console_node);
145 1.4.4.2 matt
146 1.4.4.2 matt if (console_node == -1)
147 1.4.4.2 matt goto nocons;
148 1.4.4.2 matt
149 1.4.4.3 matt memset(name, 0, sizeof(name));
150 1.4.4.3 matt if (OF_getprop(console_node, "device_type", name, sizeof(name)) == -1)
151 1.4.4.2 matt goto nocons;
152 1.4.4.2 matt
153 1.4.4.3 matt OFPRINTF("console type: %s\n", name);
154 1.4.4.2 matt
155 1.4.4.3 matt if (strcmp(name, "serial") == 0) {
156 1.4.4.2 matt struct consdev *cp;
157 1.4.4.2 matt
158 1.4.4.2 matt #ifdef PMAC_G5
159 1.4.4.2 matt /* The MMU hasn't been initialized yet, use failsafe for now */
160 1.4.4.2 matt cp = &failsafe_cons;
161 1.4.4.2 matt cn_tab = cp;
162 1.4.4.2 matt (*cp->cn_probe)(cp);
163 1.4.4.2 matt (*cp->cn_init)(cp);
164 1.4.4.2 matt aprint_verbose("Early G5 console initialized\n");
165 1.4.4.2 matt return;
166 1.4.4.2 matt #endif /* PMAC_G5 */
167 1.4.4.2 matt
168 1.4.4.2 matt #if (NZSTTY > 0) && !defined(MAMBO)
169 1.4.4.2 matt OF_getprop(console_node, "name", name, sizeof(name));
170 1.4.4.2 matt if (strcmp(name, "ch-a") == 0 || strcmp(name, "ch-b") == 0) {
171 1.4.4.2 matt cp = &consdev_zs;
172 1.4.4.2 matt (*cp->cn_probe)(cp);
173 1.4.4.2 matt (*cp->cn_init)(cp);
174 1.4.4.2 matt cn_tab = cp;
175 1.4.4.2 matt }
176 1.4.4.2 matt return;
177 1.4.4.2 matt #endif /* NZTTY */
178 1.4.4.2 matt
179 1.4.4.3 matt /* fallback to OFW boot console */
180 1.4.4.3 matt cp = &consdev_ofwbootcons;
181 1.4.4.3 matt cn_tab = cp;
182 1.4.4.2 matt return;
183 1.4.4.2 matt }
184 1.4.4.3 matt else
185 1.4.4.3 matt cninit_kd();
186 1.4.4.2 matt nocons:
187 1.4.4.2 matt return;
188 1.4.4.2 matt }
189 1.4.4.2 matt
190 1.4.4.2 matt
191 1.4.4.2 matt static void
192 1.4.4.2 matt cninit_kd(void)
193 1.4.4.2 matt {
194 1.4.4.2 matt int kstdin, node;
195 1.4.4.2 matt char name[16];
196 1.4.4.2 matt #if (NAKBD > 0) || (NADBKBD > 0)
197 1.4.4.2 matt int akbd;
198 1.4.4.2 matt #endif
199 1.4.4.2 matt #if NUKBD > 0
200 1.4.4.2 matt struct usb_kbd_ihandles *ukbds;
201 1.4.4.2 matt int ukbd;
202 1.4.4.2 matt #endif
203 1.4.4.2 matt
204 1.4.4.2 matt /*
205 1.4.4.2 matt * Attach the console output now (so we can see debugging messages,
206 1.4.4.2 matt * if any).
207 1.4.4.2 matt */
208 1.4.4.3 matt #if NWSDISPLAY > 0
209 1.4.4.3 matt rascons_cnattach();
210 1.4.4.2 matt #endif
211 1.4.4.2 matt
212 1.4.4.2 matt /*
213 1.4.4.2 matt * We must determine which keyboard type we have.
214 1.4.4.2 matt */
215 1.4.4.2 matt if (OF_getprop(chosen, "stdin", &kstdin, sizeof(kstdin))
216 1.4.4.2 matt != sizeof(kstdin)) {
217 1.4.4.2 matt printf("WARNING: no `stdin' property in /chosen\n");
218 1.4.4.2 matt return;
219 1.4.4.2 matt }
220 1.4.4.2 matt
221 1.4.4.2 matt node = OF_instance_to_package(kstdin);
222 1.4.4.2 matt memset(name, 0, sizeof(name));
223 1.4.4.2 matt OF_getprop(node, "name", name, sizeof(name));
224 1.4.4.2 matt if (strcmp(name, "keyboard") != 0) {
225 1.4.4.2 matt printf("WARNING: stdin is not a keyboard: %s\n", name);
226 1.4.4.2 matt return;
227 1.4.4.2 matt }
228 1.4.4.2 matt
229 1.4.4.2 matt #if NAKBD > 0
230 1.4.4.2 matt memset(name, 0, sizeof(name));
231 1.4.4.2 matt OF_getprop(OF_parent(node), "name", name, sizeof(name));
232 1.4.4.2 matt if (strcmp(name, "adb") == 0) {
233 1.4.4.2 matt printf("console keyboard type: ADB\n");
234 1.4.4.2 matt akbd_cnattach();
235 1.4.4.2 matt goto kbd_found;
236 1.4.4.2 matt }
237 1.4.4.2 matt #endif
238 1.4.4.2 matt #if NADBKBD > 0
239 1.4.4.2 matt memset(name, 0, sizeof(name));
240 1.4.4.2 matt OF_getprop(OF_parent(node), "name", name, sizeof(name));
241 1.4.4.2 matt if (strcmp(name, "adb") == 0) {
242 1.4.4.2 matt printf("console keyboard type: ADB\n");
243 1.4.4.2 matt adbkbd_cnattach();
244 1.4.4.2 matt goto kbd_found;
245 1.4.4.2 matt }
246 1.4.4.2 matt #endif
247 1.4.4.2 matt #if NPCKBC > 0
248 1.4.4.2 matt memset(name, 0, sizeof(name));
249 1.4.4.2 matt OF_getprop(OF_parent(node), "name", name, sizeof(name));
250 1.4.4.2 matt if (strcmp(name, "keyboard") == 0) {
251 1.4.4.2 matt printf("console keyboard type: PC Keyboard\n");
252 1.4.4.2 matt pckbc_cnattach(&genppc_isa_io_space_tag, IO_KBD, KBCMDP,
253 1.4.4.2 matt PCKBC_KBD_SLOT);
254 1.4.4.2 matt goto kbd_found;
255 1.4.4.2 matt }
256 1.4.4.2 matt #endif
257 1.4.4.2 matt
258 1.4.4.2 matt /*
259 1.4.4.2 matt * It is not obviously an ADB/PC keyboard. Could be USB,
260 1.4.4.2 matt * or ADB on some firmware versions (e.g.: iBook G4)
261 1.4.4.2 matt * This is not enough, we have a few more problems:
262 1.4.4.2 matt *
263 1.4.4.2 matt * (1) The stupid Macintosh firmware uses a
264 1.4.4.2 matt * `psuedo-hid' (no typo) or `pseudo-hid',
265 1.4.4.2 matt * which apparently merges all keyboards
266 1.4.4.2 matt * input into a single input stream.
267 1.4.4.2 matt * Because of this, we can't actually
268 1.4.4.2 matt * determine which controller or keyboard
269 1.4.4.2 matt * is really the console keyboard!
270 1.4.4.2 matt *
271 1.4.4.2 matt * (2) Even if we could, the keyboard can be USB,
272 1.4.4.2 matt * and this requires a lot of the kernel to
273 1.4.4.2 matt * be running in order for it to work.
274 1.4.4.2 matt *
275 1.4.4.2 matt * (3) If the keyboard is behind isa, we don't have enough
276 1.4.4.2 matt * kernel setup to use it yet, so punt to the ofroutines.
277 1.4.4.2 matt *
278 1.4.4.2 matt * So, what we do is this:
279 1.4.4.2 matt *
280 1.4.4.2 matt * (1) First check for OpenFirmware implementation
281 1.4.4.2 matt * that will not let us distinguish between
282 1.4.4.2 matt * USB and ADB. In that situation, try attaching
283 1.4.4.2 matt * anything as we can, and hope things get better
284 1.4.4.2 matt * at autoconfiguration time.
285 1.4.4.2 matt *
286 1.4.4.2 matt * (2) Assume the keyboard is USB.
287 1.4.4.2 matt * Tell the ukbd driver that it is the console.
288 1.4.4.2 matt * At autoconfiguration time, it will attach the
289 1.4.4.2 matt * first USB keyboard instance as the console
290 1.4.4.2 matt * keyboard.
291 1.4.4.2 matt *
292 1.4.4.2 matt * (3) Until then, so that we have _something_, we
293 1.4.4.2 matt * use the OpenFirmware I/O facilities to read
294 1.4.4.2 matt * the keyboard.
295 1.4.4.2 matt */
296 1.4.4.2 matt
297 1.4.4.2 matt /*
298 1.4.4.2 matt * stdin is /pseudo-hid/keyboard. There is no
299 1.4.4.2 matt * `adb-kbd-ihandle or `usb-kbd-ihandles methods
300 1.4.4.2 matt * available. Try attaching as ADB.
301 1.4.4.2 matt *
302 1.4.4.2 matt * XXX This must be called before pmap_bootstrap().
303 1.4.4.2 matt */
304 1.4.4.2 matt if (strcmp(name, "pseudo-hid") == 0) {
305 1.4.4.2 matt printf("console keyboard type: unknown, assuming ADB\n");
306 1.4.4.2 matt #if NAKBD > 0
307 1.4.4.2 matt akbd_cnattach();
308 1.4.4.2 matt #endif
309 1.4.4.2 matt #if NADBKBD > 0
310 1.4.4.2 matt adbkbd_cnattach();
311 1.4.4.2 matt #endif
312 1.4.4.2 matt goto kbd_found;
313 1.4.4.2 matt }
314 1.4.4.2 matt
315 1.4.4.2 matt /*
316 1.4.4.2 matt * stdin is /psuedo-hid/keyboard. Test `adb-kbd-ihandle and
317 1.4.4.2 matt * `usb-kbd-ihandles to figure out the real keyboard(s).
318 1.4.4.2 matt *
319 1.4.4.2 matt * XXX This must be called before pmap_bootstrap().
320 1.4.4.2 matt */
321 1.4.4.2 matt
322 1.4.4.2 matt #if NUKBD > 0
323 1.4.4.2 matt if (OF_call_method("`usb-kbd-ihandles", stdin, 0, 1, &ukbds) >= 0 &&
324 1.4.4.2 matt ukbds != NULL && ukbds->ihandle != 0 &&
325 1.4.4.2 matt OF_instance_to_package(ukbds->ihandle) != -1) {
326 1.4.4.2 matt printf("usb-kbd-ihandles matches\n");
327 1.4.4.2 matt printf("console keyboard type: USB\n");
328 1.4.4.2 matt ukbd_cnattach();
329 1.4.4.2 matt goto kbd_found;
330 1.4.4.2 matt }
331 1.4.4.2 matt /* Try old method name. */
332 1.4.4.2 matt if (OF_call_method("`usb-kbd-ihandle", kstdin, 0, 1, &ukbd) >= 0 &&
333 1.4.4.2 matt ukbd != 0 &&
334 1.4.4.2 matt OF_instance_to_package(ukbd) != -1) {
335 1.4.4.2 matt printf("usb-kbd-ihandle matches\n");
336 1.4.4.2 matt printf("console keyboard type: USB\n");
337 1.4.4.2 matt kstdin = ukbd;
338 1.4.4.2 matt ukbd_cnattach();
339 1.4.4.2 matt goto kbd_found;
340 1.4.4.2 matt }
341 1.4.4.2 matt #endif
342 1.4.4.2 matt
343 1.4.4.2 matt #if (NAKBD > 0) || (NADBKBD > 0)
344 1.4.4.2 matt if (OF_call_method("`adb-kbd-ihandle", kstdin, 0, 1, &akbd) >= 0 &&
345 1.4.4.2 matt akbd != 0 &&
346 1.4.4.2 matt OF_instance_to_package(akbd) != -1) {
347 1.4.4.2 matt printf("adb-kbd-ihandle matches\n");
348 1.4.4.2 matt printf("console keyboard type: ADB\n");
349 1.4.4.2 matt kstdin = akbd;
350 1.4.4.2 matt #if NAKBD > 0
351 1.4.4.2 matt akbd_cnattach();
352 1.4.4.2 matt #endif
353 1.4.4.2 matt #if NADBKBD > 0
354 1.4.4.2 matt adbkbd_cnattach();
355 1.4.4.2 matt #endif
356 1.4.4.2 matt goto kbd_found;
357 1.4.4.2 matt }
358 1.4.4.2 matt #endif
359 1.4.4.2 matt
360 1.4.4.2 matt #if NUKBD > 0
361 1.4.4.2 matt /*
362 1.4.4.2 matt * XXX Old firmware does not have `usb-kbd-ihandles method. Assume
363 1.4.4.2 matt * XXX USB keyboard anyway.
364 1.4.4.2 matt */
365 1.4.4.2 matt printf("defaulting to USB...");
366 1.4.4.2 matt printf("console keyboard type: USB\n");
367 1.4.4.2 matt ukbd_cnattach();
368 1.4.4.2 matt goto kbd_found;
369 1.4.4.2 matt #endif
370 1.4.4.2 matt
371 1.4.4.2 matt /*
372 1.4.4.2 matt * No keyboard is found. Just return.
373 1.4.4.2 matt */
374 1.4.4.2 matt printf("no console keyboard\n");
375 1.4.4.2 matt return;
376 1.4.4.2 matt
377 1.4.4.2 matt kbd_found:;
378 1.4.4.2 matt #if NAKBD + NUKBD + NADBKBD > 0
379 1.4.4.2 matt /*
380 1.4.4.2 matt * XXX This is a little gross, but we don't get to call
381 1.4.4.2 matt * XXX wskbd_cnattach() twice.
382 1.4.4.2 matt */
383 1.4.4.2 matt ofkbd_ihandle = kstdin;
384 1.4.4.2 matt #if NWSDISPLAY > 0
385 1.4.4.2 matt wsdisplay_set_cons_kbd(ofkbd_cngetc, NULL, NULL);
386 1.4.4.2 matt #endif
387 1.4.4.2 matt #endif
388 1.4.4.2 matt }
389 1.4.4.2 matt
390 1.4.4.2 matt /*
391 1.4.4.2 matt * Bootstrap console keyboard routines, using OpenFirmware I/O.
392 1.4.4.2 matt */
393 1.4.4.2 matt int
394 1.4.4.2 matt ofkbd_cngetc(dev_t dev)
395 1.4.4.2 matt {
396 1.4.4.2 matt u_char c = '\0';
397 1.4.4.2 matt int len;
398 1.4.4.2 matt
399 1.4.4.2 matt do {
400 1.4.4.2 matt len = OF_read(ofkbd_ihandle, &c, 1);
401 1.4.4.2 matt } while (len != 1);
402 1.4.4.2 matt
403 1.4.4.2 matt return c;
404 1.4.4.2 matt }
405 1.4.4.2 matt
406 1.4.4.2 matt /*
407 1.4.4.2 matt * Bootstrap console support functions
408 1.4.4.2 matt */
409 1.4.4.2 matt
410 1.4.4.2 matt static int
411 1.4.4.2 matt ofwbootcons_cngetc(dev_t dev)
412 1.4.4.2 matt {
413 1.4.4.2 matt unsigned char ch = '\0';
414 1.4.4.2 matt int l;
415 1.4.4.2 matt
416 1.4.4.2 matt while ((l = OF_read(stdin, &ch, 1)) != 1)
417 1.4.4.2 matt if (l != -2 && l != 0)
418 1.4.4.2 matt return -1;
419 1.4.4.2 matt return ch;
420 1.4.4.2 matt }
421 1.4.4.2 matt
422 1.4.4.2 matt static void
423 1.4.4.2 matt ofwbootcons_cnputc(dev_t dev, int c)
424 1.4.4.2 matt {
425 1.4.4.2 matt char ch = c;
426 1.4.4.2 matt
427 1.4.4.2 matt OF_write(stdout, &ch, 1);
428 1.4.4.2 matt }
429 1.4.4.2 matt
430 1.4.4.2 matt void
431 1.4.4.2 matt ofwoea_consinit(void)
432 1.4.4.2 matt {
433 1.4.4.2 matt static int initted = 0;
434 1.4.4.2 matt
435 1.4.4.2 matt if (initted)
436 1.4.4.2 matt return;
437 1.4.4.2 matt
438 1.4.4.2 matt initted = 1;
439 1.4.4.2 matt cninit();
440 1.4.4.2 matt }
441 1.4.4.2 matt
442 1.4.4.2 matt static void
443 1.4.4.2 matt ofwoea_bootstrap_console(void)
444 1.4.4.2 matt {
445 1.4.4.2 matt int node;
446 1.4.4.2 matt
447 1.4.4.2 matt chosen = OF_finddevice("/chosen");
448 1.4.4.2 matt if (chosen == -1)
449 1.4.4.2 matt goto nocons;
450 1.4.4.2 matt
451 1.4.4.2 matt if (OF_getprop(chosen, "stdout", &stdout,
452 1.4.4.2 matt sizeof(stdout)) != sizeof(stdout))
453 1.4.4.2 matt goto nocons;
454 1.4.4.2 matt if (OF_getprop(chosen, "stdin", &stdin,
455 1.4.4.2 matt sizeof(stdin)) != sizeof(stdin))
456 1.4.4.2 matt goto nocons;
457 1.4.4.2 matt node = OF_instance_to_package(stdout);
458 1.4.4.2 matt console_node = node;
459 1.4.4.2 matt console_instance = stdout;
460 1.4.4.2 matt
461 1.4.4.2 matt return;
462 1.4.4.2 matt nocons:
463 1.4.4.2 matt panic("No /chosen could be found!\n");
464 1.4.4.2 matt console_node = -1;
465 1.4.4.2 matt return;
466 1.4.4.2 matt }
467