Home | History | Annotate | Line # | Download | only in oea
ofw_consinit.c revision 1.1.2.1
      1  1.1.2.1  garbled /* $NetBSD: ofw_consinit.c,v 1.1.2.1 2007/06/06 17:38:35 garbled 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.1  garbled __KERNEL_RCSID(0, "$NetBSD: ofw_consinit.c,v 1.1.2.1 2007/06/06 17:38:35 garbled 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.1  garbled #include "akbd.h"
     59  1.1.2.1  garbled #include "adbkbd.h"
     60  1.1.2.1  garbled #include "ofb.h"
     61  1.1.2.1  garbled 
     62  1.1.2.1  garbled #include "zsc.h"
     63  1.1.2.1  garbled #if NZSC > 0
     64  1.1.2.1  garbled #include <machine/z8530var.h>
     65  1.1.2.1  garbled #endif
     66  1.1.2.1  garbled 
     67  1.1.2.1  garbled #include "adb.h"
     68  1.1.2.1  garbled #if (NADB > 0)
     69  1.1.2.1  garbled #include <macppc/dev/adbvar.h>
     70  1.1.2.1  garbled #endif
     71  1.1.2.1  garbled 
     72  1.1.2.1  garbled #include "ukbd.h"
     73  1.1.2.1  garbled #if (NUKBD > 0)
     74  1.1.2.1  garbled #include <dev/usb/ukbdvar.h>
     75  1.1.2.1  garbled struct usb_kbd_ihandles {
     76  1.1.2.1  garbled 	struct usb_kbd_ihandles *next;
     77  1.1.2.1  garbled 	int ihandle;
     78  1.1.2.1  garbled };
     79  1.1.2.1  garbled #endif
     80  1.1.2.1  garbled 
     81  1.1.2.1  garbled #include "zstty.h"
     82  1.1.2.1  garbled #if (NZSTTY > 0)
     83  1.1.2.1  garbled #include <dev/ic/z8530reg.h>
     84  1.1.2.1  garbled extern struct consdev consdev_zs;
     85  1.1.2.1  garbled #endif
     86  1.1.2.1  garbled 
     87  1.1.2.1  garbled #include "pckbc.h"
     88  1.1.2.1  garbled #if (NPCKBC > 0)
     89  1.1.2.1  garbled #include <dev/isa/isareg.h>
     90  1.1.2.1  garbled #include <dev/ic/i8042reg.h>
     91  1.1.2.1  garbled #include <dev/ic/pckbcvar.h>
     92  1.1.2.1  garbled #endif
     93  1.1.2.1  garbled 
     94  1.1.2.1  garbled #include "com.h"
     95  1.1.2.1  garbled #if (NCOM > 0)
     96  1.1.2.1  garbled #include <sys/termios.h>
     97  1.1.2.1  garbled #include <dev/ic/comreg.h>
     98  1.1.2.1  garbled #include <dev/ic/comvar.h>
     99  1.1.2.1  garbled #endif
    100  1.1.2.1  garbled 
    101  1.1.2.1  garbled extern int console_node, console_instance;
    102  1.1.2.1  garbled extern struct consdev consdev_ofcons;
    103  1.1.2.1  garbled 
    104  1.1.2.1  garbled int chosen;
    105  1.1.2.1  garbled int ofkbd_ihandle;
    106  1.1.2.1  garbled 
    107  1.1.2.1  garbled static void cninit_kd(void);
    108  1.1.2.1  garbled static void ofwoea_bootstrap_console(void);
    109  1.1.2.1  garbled 
    110  1.1.2.1  garbled void
    111  1.1.2.1  garbled cninit(void)
    112  1.1.2.1  garbled {
    113  1.1.2.1  garbled 	char type[16];
    114  1.1.2.1  garbled 
    115  1.1.2.1  garbled 	ofwoea_bootstrap_console();
    116  1.1.2.1  garbled 
    117  1.1.2.1  garbled 	if (console_node == -1)
    118  1.1.2.1  garbled 		goto nocons;
    119  1.1.2.1  garbled 
    120  1.1.2.1  garbled 	memset(type, 0, sizeof(type));
    121  1.1.2.1  garbled 	if (OF_getprop(console_node, "device_type", type, sizeof(type)) == -1)
    122  1.1.2.1  garbled 		goto nocons;
    123  1.1.2.1  garbled 
    124  1.1.2.1  garbled 	if (strcmp(type, "display") == 0) {
    125  1.1.2.1  garbled 		cninit_kd();
    126  1.1.2.1  garbled 		return;
    127  1.1.2.1  garbled 	}
    128  1.1.2.1  garbled 
    129  1.1.2.1  garbled 	if (strcmp(type, "serial") == 0) {
    130  1.1.2.1  garbled 		struct consdev *cp;
    131  1.1.2.1  garbled 		char name[32];
    132  1.1.2.1  garbled 
    133  1.1.2.1  garbled #if defined(PMAC_G5)
    134  1.1.2.1  garbled 		/* The MMU hasn't been initialized yet, use failsafe for now */
    135  1.1.2.1  garbled 		cp = &failsafe_cons;
    136  1.1.2.1  garbled 		cn_tab = cp;
    137  1.1.2.1  garbled 		(*cp->cn_probe)(cp);
    138  1.1.2.1  garbled 		(*cp->cn_init)(cp);
    139  1.1.2.1  garbled 		aprint_verbose("Early G5 console initialized\n");
    140  1.1.2.1  garbled #elif defined(MAMBO)
    141  1.1.2.1  garbled 		goto fallback;
    142  1.1.2.1  garbled #else
    143  1.1.2.1  garbled 		OF_getprop(console_node, "name", name, sizeof(name));
    144  1.1.2.1  garbled #if NZSTTY > 0
    145  1.1.2.1  garbled 		if (strcmp(name, "ch-a") == 0 || strcmp(name, "ch-b") == 0) {
    146  1.1.2.1  garbled 			cp = &consdev_zs;
    147  1.1.2.1  garbled 			(*cp->cn_probe)(cp);
    148  1.1.2.1  garbled 			(*cp->cn_init)(cp);
    149  1.1.2.1  garbled 			cn_tab = cp;
    150  1.1.2.1  garbled 		}
    151  1.1.2.1  garbled 		return;
    152  1.1.2.1  garbled #endif /* NZTTY */
    153  1.1.2.1  garbled #if (NCOM > 0 && 0)
    154  1.1.2.1  garbled 		if (strcmp(name, "serial") == 0) {
    155  1.1.2.1  garbled 			bus_space_tag_t tag = &genppc_isa_io_space_tag;
    156  1.1.2.1  garbled 			u_int32_t freq, reg[3];
    157  1.1.2.1  garbled 
    158  1.1.2.1  garbled 			if (OF_getprop(console_node, "clock-frequency", &freq,
    159  1.1.2.1  garbled 			    sizeof(freq)) != sizeof(freq))
    160  1.1.2.1  garbled 				goto fallback;
    161  1.1.2.1  garbled 			if (OF_getprop(console_node, "reg", reg, sizeof(reg))
    162  1.1.2.1  garbled 			    != sizeof(reg))
    163  1.1.2.1  garbled 				goto fallback;
    164  1.1.2.1  garbled 
    165  1.1.2.1  garbled 			/* We assume 9600.  Sorry. */
    166  1.1.2.1  garbled 			if (comcnattach(tag, reg[1], 9600,
    167  1.1.2.1  garbled 			    freq, COM_TYPE_NORMAL,
    168  1.1.2.1  garbled 			    ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8)))
    169  1.1.2.1  garbled 				goto fallback;
    170  1.1.2.1  garbled 		}
    171  1.1.2.1  garbled #endif /* NCOM */
    172  1.1.2.1  garbled #endif /* MAMBO || PMACG5 */
    173  1.1.2.1  garbled #if 0
    174  1.1.2.1  garbled #if (NCOM > 0 || MAMBO)
    175  1.1.2.1  garbled fallback:
    176  1.1.2.1  garbled 		/* fallback to ofcons */
    177  1.1.2.1  garbled 		if (strcmp(name, "serial") == 0) {
    178  1.1.2.1  garbled 			cp = &consdev_ofcons;
    179  1.1.2.1  garbled 			cn_tab = cp;
    180  1.1.2.1  garbled 			(*cp->cn_probe)(cp);
    181  1.1.2.1  garbled 			(*cp->cn_init)(cp);
    182  1.1.2.1  garbled 		}
    183  1.1.2.1  garbled 		return;
    184  1.1.2.1  garbled #endif
    185  1.1.2.1  garbled #endif
    186  1.1.2.1  garbled 	}
    187  1.1.2.1  garbled nocons:
    188  1.1.2.1  garbled 	return;
    189  1.1.2.1  garbled }
    190  1.1.2.1  garbled 
    191  1.1.2.1  garbled 
    192  1.1.2.1  garbled static void
    193  1.1.2.1  garbled cninit_kd(void)
    194  1.1.2.1  garbled {
    195  1.1.2.1  garbled 	int stdin, node;
    196  1.1.2.1  garbled 	char name[16];
    197  1.1.2.1  garbled #if (NAKBD > 0) || (NADBKBD > 0)
    198  1.1.2.1  garbled 	int akbd;
    199  1.1.2.1  garbled #endif
    200  1.1.2.1  garbled #if NUKBD > 0
    201  1.1.2.1  garbled 	struct usb_kbd_ihandles *ukbds;
    202  1.1.2.1  garbled 	int ukbd;
    203  1.1.2.1  garbled #endif
    204  1.1.2.1  garbled 
    205  1.1.2.1  garbled 	/*
    206  1.1.2.1  garbled 	 * Attach the console output now (so we can see debugging messages,
    207  1.1.2.1  garbled 	 * if any).
    208  1.1.2.1  garbled 	 */
    209  1.1.2.1  garbled 	ofb_cnattach();
    210  1.1.2.1  garbled 
    211  1.1.2.1  garbled 	/*
    212  1.1.2.1  garbled 	 * We must determine which keyboard type we have.
    213  1.1.2.1  garbled 	 */
    214  1.1.2.1  garbled 	if (OF_getprop(chosen, "stdin", &stdin, sizeof(stdin))
    215  1.1.2.1  garbled 	    != sizeof(stdin)) {
    216  1.1.2.1  garbled 		printf("WARNING: no `stdin' property in /chosen\n");
    217  1.1.2.1  garbled 		return;
    218  1.1.2.1  garbled 	}
    219  1.1.2.1  garbled 
    220  1.1.2.1  garbled 	node = OF_instance_to_package(stdin);
    221  1.1.2.1  garbled 	memset(name, 0, sizeof(name));
    222  1.1.2.1  garbled 	OF_getprop(node, "name", name, sizeof(name));
    223  1.1.2.1  garbled 	if (strcmp(name, "keyboard") != 0) {
    224  1.1.2.1  garbled 		printf("WARNING: stdin is not a keyboard: %s\n", name);
    225  1.1.2.1  garbled 		return;
    226  1.1.2.1  garbled 	}
    227  1.1.2.1  garbled 
    228  1.1.2.1  garbled #if NAKBD > 0
    229  1.1.2.1  garbled 	memset(name, 0, sizeof(name));
    230  1.1.2.1  garbled 	OF_getprop(OF_parent(node), "name", name, sizeof(name));
    231  1.1.2.1  garbled 	if (strcmp(name, "adb") == 0) {
    232  1.1.2.1  garbled 		printf("console keyboard type: ADB\n");
    233  1.1.2.1  garbled 		akbd_cnattach();
    234  1.1.2.1  garbled 		goto kbd_found;
    235  1.1.2.1  garbled 	}
    236  1.1.2.1  garbled #endif
    237  1.1.2.1  garbled #if NADBKBD > 0
    238  1.1.2.1  garbled 	memset(name, 0, sizeof(name));
    239  1.1.2.1  garbled 	OF_getprop(OF_parent(node), "name", name, sizeof(name));
    240  1.1.2.1  garbled 	if (strcmp(name, "adb") == 0) {
    241  1.1.2.1  garbled 		printf("console keyboard type: ADB\n");
    242  1.1.2.1  garbled 		adbkbd_cnattach();
    243  1.1.2.1  garbled 		goto kbd_found;
    244  1.1.2.1  garbled 	}
    245  1.1.2.1  garbled #endif
    246  1.1.2.1  garbled #if NPCKBC > 0
    247  1.1.2.1  garbled 	memset(name, 0, sizeof(name));
    248  1.1.2.1  garbled 	OF_getprop(OF_parent(node), "name", name, sizeof(name));
    249  1.1.2.1  garbled 	if (strcmp(name, "keyboard") == 0) {
    250  1.1.2.1  garbled 		printf("console keyboard type: PC Keyboard\n");
    251  1.1.2.1  garbled 		pckbc_cnattach(&genppc_isa_io_space_tag, IO_KBD, KBCMDP,
    252  1.1.2.1  garbled 		    PCKBC_KBD_SLOT);
    253  1.1.2.1  garbled 		goto kbd_found;
    254  1.1.2.1  garbled 	}
    255  1.1.2.1  garbled #endif
    256  1.1.2.1  garbled 
    257  1.1.2.1  garbled 	/*
    258  1.1.2.1  garbled 	 * It is not obviously an ADB/PC keyboard. Could be USB,
    259  1.1.2.1  garbled 	 * or ADB on some firmware versions (e.g.: iBook G4)
    260  1.1.2.1  garbled 	 * This is not enough, we have a few more problems:
    261  1.1.2.1  garbled 	 *
    262  1.1.2.1  garbled 	 *	(1) The stupid Macintosh firmware uses a
    263  1.1.2.1  garbled 	 *	    `psuedo-hid' (no typo) or `pseudo-hid',
    264  1.1.2.1  garbled 	 *	    which apparently merges all keyboards
    265  1.1.2.1  garbled 	 *	    input into a single input stream.
    266  1.1.2.1  garbled 	 *	    Because of this, we can't actually
    267  1.1.2.1  garbled 	 *	    determine which controller or keyboard
    268  1.1.2.1  garbled 	 *	    is really the console keyboard!
    269  1.1.2.1  garbled 	 *
    270  1.1.2.1  garbled 	 *	(2) Even if we could, the keyboard can be USB,
    271  1.1.2.1  garbled 	 *	    and this requires a lot of the kernel to
    272  1.1.2.1  garbled 	 *	    be running in order for it to work.
    273  1.1.2.1  garbled 	 *
    274  1.1.2.1  garbled 	 *      (3) If the keyboard is behind isa, we don't have enough
    275  1.1.2.1  garbled 	 * 	    kernel setup to use it yet, so punt to the ofroutines.
    276  1.1.2.1  garbled 	 *
    277  1.1.2.1  garbled 	 * So, what we do is this:
    278  1.1.2.1  garbled 	 *
    279  1.1.2.1  garbled 	 *	(1) First check for OpenFirmware implementation
    280  1.1.2.1  garbled 	 *	    that will not let us distinguish between
    281  1.1.2.1  garbled 	 *	    USB and ADB. In that situation, try attaching
    282  1.1.2.1  garbled 	 *	    anything as we can, and hope things get better
    283  1.1.2.1  garbled 	 *	    at autoconfiguration time.
    284  1.1.2.1  garbled 	 *
    285  1.1.2.1  garbled 	 *	(2) Assume the keyboard is USB.
    286  1.1.2.1  garbled 	 *	    Tell the ukbd driver that it is the console.
    287  1.1.2.1  garbled 	 *	    At autoconfiguration time, it will attach the
    288  1.1.2.1  garbled 	 *	    first USB keyboard instance as the console
    289  1.1.2.1  garbled 	 *	    keyboard.
    290  1.1.2.1  garbled 	 *
    291  1.1.2.1  garbled 	 *	(3) Until then, so that we have _something_, we
    292  1.1.2.1  garbled 	 *	    use the OpenFirmware I/O facilities to read
    293  1.1.2.1  garbled 	 *	    the keyboard.
    294  1.1.2.1  garbled 	 */
    295  1.1.2.1  garbled 
    296  1.1.2.1  garbled 	/*
    297  1.1.2.1  garbled 	 * stdin is /pseudo-hid/keyboard.  There is no
    298  1.1.2.1  garbled 	 * `adb-kbd-ihandle or `usb-kbd-ihandles methods
    299  1.1.2.1  garbled 	 * available. Try attaching as ADB.
    300  1.1.2.1  garbled 	 *
    301  1.1.2.1  garbled 	 * XXX This must be called before pmap_bootstrap().
    302  1.1.2.1  garbled 	 */
    303  1.1.2.1  garbled 	if (strcmp(name, "pseudo-hid") == 0) {
    304  1.1.2.1  garbled 		printf("console keyboard type: unknown, assuming ADB\n");
    305  1.1.2.1  garbled #if NAKBD > 0
    306  1.1.2.1  garbled 		akbd_cnattach();
    307  1.1.2.1  garbled #endif
    308  1.1.2.1  garbled #if NADBKBD > 0
    309  1.1.2.1  garbled 		adbkbd_cnattach();
    310  1.1.2.1  garbled #endif
    311  1.1.2.1  garbled 		goto kbd_found;
    312  1.1.2.1  garbled 	}
    313  1.1.2.1  garbled 
    314  1.1.2.1  garbled 	/*
    315  1.1.2.1  garbled 	 * stdin is /psuedo-hid/keyboard.  Test `adb-kbd-ihandle and
    316  1.1.2.1  garbled 	 * `usb-kbd-ihandles to figure out the real keyboard(s).
    317  1.1.2.1  garbled 	 *
    318  1.1.2.1  garbled 	 * XXX This must be called before pmap_bootstrap().
    319  1.1.2.1  garbled 	 */
    320  1.1.2.1  garbled 
    321  1.1.2.1  garbled #if NUKBD > 0
    322  1.1.2.1  garbled 	if (OF_call_method("`usb-kbd-ihandles", stdin, 0, 1, &ukbds) >= 0 &&
    323  1.1.2.1  garbled 	    ukbds != NULL && ukbds->ihandle != 0 &&
    324  1.1.2.1  garbled 	    OF_instance_to_package(ukbds->ihandle) != -1) {
    325  1.1.2.1  garbled 		printf("usb-kbd-ihandles matches\n");
    326  1.1.2.1  garbled 		printf("console keyboard type: USB\n");
    327  1.1.2.1  garbled 		ukbd_cnattach();
    328  1.1.2.1  garbled 		goto kbd_found;
    329  1.1.2.1  garbled 	}
    330  1.1.2.1  garbled 	/* Try old method name. */
    331  1.1.2.1  garbled 	if (OF_call_method("`usb-kbd-ihandle", stdin, 0, 1, &ukbd) >= 0 &&
    332  1.1.2.1  garbled 	    ukbd != 0 &&
    333  1.1.2.1  garbled 	    OF_instance_to_package(ukbd) != -1) {
    334  1.1.2.1  garbled 		printf("usb-kbd-ihandle matches\n");
    335  1.1.2.1  garbled 		printf("console keyboard type: USB\n");
    336  1.1.2.1  garbled 		stdin = ukbd;
    337  1.1.2.1  garbled 		ukbd_cnattach();
    338  1.1.2.1  garbled 		goto kbd_found;
    339  1.1.2.1  garbled 	}
    340  1.1.2.1  garbled #endif
    341  1.1.2.1  garbled 
    342  1.1.2.1  garbled #if (NAKBD > 0) || (NADBKBD > 0)
    343  1.1.2.1  garbled 	if (OF_call_method("`adb-kbd-ihandle", stdin, 0, 1, &akbd) >= 0 &&
    344  1.1.2.1  garbled 	    akbd != 0 &&
    345  1.1.2.1  garbled 	    OF_instance_to_package(akbd) != -1) {
    346  1.1.2.1  garbled 		printf("adb-kbd-ihandle matches\n");
    347  1.1.2.1  garbled 		printf("console keyboard type: ADB\n");
    348  1.1.2.1  garbled 		stdin = akbd;
    349  1.1.2.1  garbled #if NAKBD > 0
    350  1.1.2.1  garbled 		akbd_cnattach();
    351  1.1.2.1  garbled #endif
    352  1.1.2.1  garbled #if NADBKBD > 0
    353  1.1.2.1  garbled 		adbkbd_cnattach();
    354  1.1.2.1  garbled #endif
    355  1.1.2.1  garbled 		goto kbd_found;
    356  1.1.2.1  garbled 	}
    357  1.1.2.1  garbled #endif
    358  1.1.2.1  garbled 
    359  1.1.2.1  garbled #if NUKBD > 0
    360  1.1.2.1  garbled 	/*
    361  1.1.2.1  garbled 	 * XXX Old firmware does not have `usb-kbd-ihandles method.  Assume
    362  1.1.2.1  garbled 	 * XXX USB keyboard anyway.
    363  1.1.2.1  garbled 	 */
    364  1.1.2.1  garbled 	printf("defaulting to USB...");
    365  1.1.2.1  garbled 	printf("console keyboard type: USB\n");
    366  1.1.2.1  garbled 	ukbd_cnattach();
    367  1.1.2.1  garbled 	goto kbd_found;
    368  1.1.2.1  garbled #endif
    369  1.1.2.1  garbled 
    370  1.1.2.1  garbled 	/*
    371  1.1.2.1  garbled 	 * No keyboard is found.  Just return.
    372  1.1.2.1  garbled 	 */
    373  1.1.2.1  garbled 	printf("no console keyboard\n");
    374  1.1.2.1  garbled 	return;
    375  1.1.2.1  garbled 
    376  1.1.2.1  garbled kbd_found:;
    377  1.1.2.1  garbled #if NAKBD + NUKBD + NADBKBD > 0
    378  1.1.2.1  garbled 	/*
    379  1.1.2.1  garbled 	 * XXX This is a little gross, but we don't get to call
    380  1.1.2.1  garbled 	 * XXX wskbd_cnattach() twice.
    381  1.1.2.1  garbled 	 */
    382  1.1.2.1  garbled 	ofkbd_ihandle = stdin;
    383  1.1.2.1  garbled #if NWSDISPLAY > 0
    384  1.1.2.1  garbled 	wsdisplay_set_cons_kbd(ofkbd_cngetc, NULL, NULL);
    385  1.1.2.1  garbled #endif
    386  1.1.2.1  garbled #endif
    387  1.1.2.1  garbled }
    388  1.1.2.1  garbled 
    389  1.1.2.1  garbled /*
    390  1.1.2.1  garbled  * Bootstrap console keyboard routines, using OpenFirmware I/O.
    391  1.1.2.1  garbled  */
    392  1.1.2.1  garbled int
    393  1.1.2.1  garbled ofkbd_cngetc(dev_t dev)
    394  1.1.2.1  garbled {
    395  1.1.2.1  garbled 	u_char c = '\0';
    396  1.1.2.1  garbled 	int len;
    397  1.1.2.1  garbled 
    398  1.1.2.1  garbled 	do {
    399  1.1.2.1  garbled 		len = OF_read(ofkbd_ihandle, &c, 1);
    400  1.1.2.1  garbled 	} while (len != 1);
    401  1.1.2.1  garbled 
    402  1.1.2.1  garbled 	return c;
    403  1.1.2.1  garbled }
    404  1.1.2.1  garbled 
    405  1.1.2.1  garbled void
    406  1.1.2.1  garbled ofwoea_consinit(void)
    407  1.1.2.1  garbled {
    408  1.1.2.1  garbled 	static int initted = 0;
    409  1.1.2.1  garbled 
    410  1.1.2.1  garbled 	if (initted)
    411  1.1.2.1  garbled 		return;
    412  1.1.2.1  garbled 
    413  1.1.2.1  garbled 	initted = 1;
    414  1.1.2.1  garbled 	cninit();
    415  1.1.2.1  garbled }
    416  1.1.2.1  garbled 
    417  1.1.2.1  garbled static void
    418  1.1.2.1  garbled ofwoea_bootstrap_console(void)
    419  1.1.2.1  garbled {
    420  1.1.2.1  garbled 	int stdout, node;
    421  1.1.2.1  garbled 
    422  1.1.2.1  garbled 	chosen = OF_finddevice("/chosen");
    423  1.1.2.1  garbled 	if (chosen == -1)
    424  1.1.2.1  garbled 		goto nocons;
    425  1.1.2.1  garbled 
    426  1.1.2.1  garbled 	if (OF_getprop(chosen, "stdout", &stdout,
    427  1.1.2.1  garbled 	    sizeof(stdout)) != sizeof(stdout))
    428  1.1.2.1  garbled 		goto nocons;
    429  1.1.2.1  garbled 	node = OF_instance_to_package(stdout);
    430  1.1.2.1  garbled 	console_node = node;
    431  1.1.2.1  garbled 	console_instance = stdout;
    432  1.1.2.1  garbled 
    433  1.1.2.1  garbled nocons:
    434  1.1.2.1  garbled 	aprint_error("No /chosen could be found!\n");
    435  1.1.2.1  garbled 	console_node = -1;
    436  1.1.2.1  garbled 	return;
    437  1.1.2.1  garbled }
    438