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