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