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