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