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