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