Home | History | Annotate | Line # | Download | only in oea
ofw_consinit.c revision 1.1.6.3
      1  1.1.6.3     joerg /* $NetBSD: ofw_consinit.c,v 1.1.6.3 2007/11/06 19:25:06 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.3     joerg __KERNEL_RCSID(0, "$NetBSD: ofw_consinit.c,v 1.1.6.3 2007/11/06 19:25:06 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 extern int console_node, console_instance;
     98  1.1.6.1     joerg 
     99  1.1.6.2  jmcneill int chosen, stdin, stdout;
    100  1.1.6.1     joerg int ofkbd_ihandle;
    101  1.1.6.1     joerg 
    102  1.1.6.1     joerg static void cninit_kd(void);
    103  1.1.6.1     joerg static void ofwoea_bootstrap_console(void);
    104  1.1.6.2  jmcneill static int ofwbootcons_cngetc(dev_t);
    105  1.1.6.2  jmcneill static void ofwbootcons_cnputc(dev_t, int);
    106  1.1.6.1     joerg 
    107  1.1.6.1     joerg /*#define OFDEBUG*/
    108  1.1.6.1     joerg 
    109  1.1.6.2  jmcneill struct consdev consdev_ofwbootcons = {
    110  1.1.6.2  jmcneill 	NULL, NULL,
    111  1.1.6.2  jmcneill 	ofwbootcons_cngetc,
    112  1.1.6.2  jmcneill 	ofwbootcons_cnputc,
    113  1.1.6.2  jmcneill 	nullcnpollc,
    114  1.1.6.2  jmcneill 	NULL, NULL, NULL, NODEV, CN_INTERNAL,
    115  1.1.6.2  jmcneill };
    116  1.1.6.2  jmcneill 
    117  1.1.6.1     joerg #ifdef OFDEBUG
    118  1.1.6.1     joerg void ofprint(const char *, ...);
    119  1.1.6.1     joerg 
    120  1.1.6.1     joerg void ofprint(const char *blah, ...)
    121  1.1.6.1     joerg {
    122  1.1.6.1     joerg 	va_list va;
    123  1.1.6.1     joerg 	char buf[256];
    124  1.1.6.1     joerg 	int len;
    125  1.1.6.1     joerg 
    126  1.1.6.1     joerg 	va_start(va, blah);
    127  1.1.6.1     joerg 	len = vsnprintf(buf, sizeof(buf), blah, va);
    128  1.1.6.1     joerg 	OF_write(console_instance, buf, len);
    129  1.1.6.1     joerg }
    130  1.1.6.1     joerg 
    131  1.1.6.1     joerg #define OFPRINTF ofprint
    132  1.1.6.1     joerg #else
    133  1.1.6.1     joerg #define OFPRINTF while(0) printf
    134  1.1.6.1     joerg #endif
    135  1.1.6.1     joerg 
    136  1.1.6.1     joerg void
    137  1.1.6.1     joerg cninit(void)
    138  1.1.6.1     joerg {
    139  1.1.6.1     joerg 	char type[16];
    140  1.1.6.1     joerg 
    141  1.1.6.1     joerg 	ofwoea_bootstrap_console();
    142  1.1.6.1     joerg 
    143  1.1.6.1     joerg 	OFPRINTF("console node: %08x\n", console_node);
    144  1.1.6.1     joerg 
    145  1.1.6.1     joerg 	if (console_node == -1)
    146  1.1.6.1     joerg 		goto nocons;
    147  1.1.6.1     joerg 
    148  1.1.6.1     joerg 	memset(type, 0, sizeof(type));
    149  1.1.6.1     joerg 	if (OF_getprop(console_node, "device_type", type, sizeof(type)) == -1)
    150  1.1.6.1     joerg 		goto nocons;
    151  1.1.6.1     joerg 
    152  1.1.6.1     joerg 	OFPRINTF("console type: %s\n", type);
    153  1.1.6.1     joerg 	if (strcmp(type, "display") == 0) {
    154  1.1.6.1     joerg 		cninit_kd();
    155  1.1.6.1     joerg 		return;
    156  1.1.6.1     joerg 	}
    157  1.1.6.1     joerg 
    158  1.1.6.1     joerg 	if (strcmp(type, "serial") == 0) {
    159  1.1.6.1     joerg 		struct consdev *cp;
    160  1.1.6.1     joerg 		char name[32];
    161  1.1.6.1     joerg 
    162  1.1.6.2  jmcneill #ifdef 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.2  jmcneill 		return;
    170  1.1.6.2  jmcneill #endif /* PMAC_G5 */
    171  1.1.6.2  jmcneill 
    172  1.1.6.2  jmcneill #if (NZSTTY > 0) && !defined(MAMBO)
    173  1.1.6.1     joerg 		OF_getprop(console_node, "name", name, sizeof(name));
    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 
    183  1.1.6.2  jmcneill 		OF_getprop(console_node, "name", name, sizeof(name));
    184  1.1.6.2  jmcneill 		/* fallback to ofwbootcons */
    185  1.1.6.1     joerg 		if (strcmp(name, "serial") == 0) {
    186  1.1.6.2  jmcneill 			cp = &consdev_ofwbootcons;
    187  1.1.6.1     joerg 			cn_tab = cp;
    188  1.1.6.1     joerg 		}
    189  1.1.6.1     joerg 		return;
    190  1.1.6.1     joerg 	}
    191  1.1.6.1     joerg nocons:
    192  1.1.6.1     joerg 	return;
    193  1.1.6.1     joerg }
    194  1.1.6.1     joerg 
    195  1.1.6.1     joerg 
    196  1.1.6.1     joerg static void
    197  1.1.6.1     joerg cninit_kd(void)
    198  1.1.6.1     joerg {
    199  1.1.6.2  jmcneill 	int kstdin, node;
    200  1.1.6.1     joerg 	char name[16];
    201  1.1.6.1     joerg #if (NAKBD > 0) || (NADBKBD > 0)
    202  1.1.6.1     joerg 	int akbd;
    203  1.1.6.1     joerg #endif
    204  1.1.6.1     joerg #if NUKBD > 0
    205  1.1.6.1     joerg 	struct usb_kbd_ihandles *ukbds;
    206  1.1.6.1     joerg 	int ukbd;
    207  1.1.6.1     joerg #endif
    208  1.1.6.1     joerg 
    209  1.1.6.1     joerg 	/*
    210  1.1.6.1     joerg 	 * Attach the console output now (so we can see debugging messages,
    211  1.1.6.1     joerg 	 * if any).
    212  1.1.6.1     joerg 	 */
    213  1.1.6.3     joerg #if NOFB > 0
    214  1.1.6.1     joerg 	ofb_cnattach();
    215  1.1.6.3     joerg #endif
    216  1.1.6.1     joerg 
    217  1.1.6.1     joerg 	/*
    218  1.1.6.1     joerg 	 * We must determine which keyboard type we have.
    219  1.1.6.1     joerg 	 */
    220  1.1.6.2  jmcneill 	if (OF_getprop(chosen, "stdin", &kstdin, sizeof(kstdin))
    221  1.1.6.2  jmcneill 	    != sizeof(kstdin)) {
    222  1.1.6.1     joerg 		printf("WARNING: no `stdin' property in /chosen\n");
    223  1.1.6.1     joerg 		return;
    224  1.1.6.1     joerg 	}
    225  1.1.6.1     joerg 
    226  1.1.6.2  jmcneill 	node = OF_instance_to_package(kstdin);
    227  1.1.6.1     joerg 	memset(name, 0, sizeof(name));
    228  1.1.6.1     joerg 	OF_getprop(node, "name", name, sizeof(name));
    229  1.1.6.1     joerg 	if (strcmp(name, "keyboard") != 0) {
    230  1.1.6.1     joerg 		printf("WARNING: stdin is not a keyboard: %s\n", name);
    231  1.1.6.1     joerg 		return;
    232  1.1.6.1     joerg 	}
    233  1.1.6.1     joerg 
    234  1.1.6.1     joerg #if NAKBD > 0
    235  1.1.6.1     joerg 	memset(name, 0, sizeof(name));
    236  1.1.6.1     joerg 	OF_getprop(OF_parent(node), "name", name, sizeof(name));
    237  1.1.6.1     joerg 	if (strcmp(name, "adb") == 0) {
    238  1.1.6.1     joerg 		printf("console keyboard type: ADB\n");
    239  1.1.6.1     joerg 		akbd_cnattach();
    240  1.1.6.1     joerg 		goto kbd_found;
    241  1.1.6.1     joerg 	}
    242  1.1.6.1     joerg #endif
    243  1.1.6.1     joerg #if NADBKBD > 0
    244  1.1.6.1     joerg 	memset(name, 0, sizeof(name));
    245  1.1.6.1     joerg 	OF_getprop(OF_parent(node), "name", name, sizeof(name));
    246  1.1.6.1     joerg 	if (strcmp(name, "adb") == 0) {
    247  1.1.6.1     joerg 		printf("console keyboard type: ADB\n");
    248  1.1.6.1     joerg 		adbkbd_cnattach();
    249  1.1.6.1     joerg 		goto kbd_found;
    250  1.1.6.1     joerg 	}
    251  1.1.6.1     joerg #endif
    252  1.1.6.1     joerg #if NPCKBC > 0
    253  1.1.6.1     joerg 	memset(name, 0, sizeof(name));
    254  1.1.6.1     joerg 	OF_getprop(OF_parent(node), "name", name, sizeof(name));
    255  1.1.6.1     joerg 	if (strcmp(name, "keyboard") == 0) {
    256  1.1.6.1     joerg 		printf("console keyboard type: PC Keyboard\n");
    257  1.1.6.1     joerg 		pckbc_cnattach(&genppc_isa_io_space_tag, IO_KBD, KBCMDP,
    258  1.1.6.1     joerg 		    PCKBC_KBD_SLOT);
    259  1.1.6.1     joerg 		goto kbd_found;
    260  1.1.6.1     joerg 	}
    261  1.1.6.1     joerg #endif
    262  1.1.6.1     joerg 
    263  1.1.6.1     joerg 	/*
    264  1.1.6.1     joerg 	 * It is not obviously an ADB/PC keyboard. Could be USB,
    265  1.1.6.1     joerg 	 * or ADB on some firmware versions (e.g.: iBook G4)
    266  1.1.6.1     joerg 	 * This is not enough, we have a few more problems:
    267  1.1.6.1     joerg 	 *
    268  1.1.6.1     joerg 	 *	(1) The stupid Macintosh firmware uses a
    269  1.1.6.1     joerg 	 *	    `psuedo-hid' (no typo) or `pseudo-hid',
    270  1.1.6.1     joerg 	 *	    which apparently merges all keyboards
    271  1.1.6.1     joerg 	 *	    input into a single input stream.
    272  1.1.6.1     joerg 	 *	    Because of this, we can't actually
    273  1.1.6.1     joerg 	 *	    determine which controller or keyboard
    274  1.1.6.1     joerg 	 *	    is really the console keyboard!
    275  1.1.6.1     joerg 	 *
    276  1.1.6.1     joerg 	 *	(2) Even if we could, the keyboard can be USB,
    277  1.1.6.1     joerg 	 *	    and this requires a lot of the kernel to
    278  1.1.6.1     joerg 	 *	    be running in order for it to work.
    279  1.1.6.1     joerg 	 *
    280  1.1.6.1     joerg 	 *      (3) If the keyboard is behind isa, we don't have enough
    281  1.1.6.1     joerg 	 * 	    kernel setup to use it yet, so punt to the ofroutines.
    282  1.1.6.1     joerg 	 *
    283  1.1.6.1     joerg 	 * So, what we do is this:
    284  1.1.6.1     joerg 	 *
    285  1.1.6.1     joerg 	 *	(1) First check for OpenFirmware implementation
    286  1.1.6.1     joerg 	 *	    that will not let us distinguish between
    287  1.1.6.1     joerg 	 *	    USB and ADB. In that situation, try attaching
    288  1.1.6.1     joerg 	 *	    anything as we can, and hope things get better
    289  1.1.6.1     joerg 	 *	    at autoconfiguration time.
    290  1.1.6.1     joerg 	 *
    291  1.1.6.1     joerg 	 *	(2) Assume the keyboard is USB.
    292  1.1.6.1     joerg 	 *	    Tell the ukbd driver that it is the console.
    293  1.1.6.1     joerg 	 *	    At autoconfiguration time, it will attach the
    294  1.1.6.1     joerg 	 *	    first USB keyboard instance as the console
    295  1.1.6.1     joerg 	 *	    keyboard.
    296  1.1.6.1     joerg 	 *
    297  1.1.6.1     joerg 	 *	(3) Until then, so that we have _something_, we
    298  1.1.6.1     joerg 	 *	    use the OpenFirmware I/O facilities to read
    299  1.1.6.1     joerg 	 *	    the keyboard.
    300  1.1.6.1     joerg 	 */
    301  1.1.6.1     joerg 
    302  1.1.6.1     joerg 	/*
    303  1.1.6.1     joerg 	 * stdin is /pseudo-hid/keyboard.  There is no
    304  1.1.6.1     joerg 	 * `adb-kbd-ihandle or `usb-kbd-ihandles methods
    305  1.1.6.1     joerg 	 * available. Try attaching as ADB.
    306  1.1.6.1     joerg 	 *
    307  1.1.6.1     joerg 	 * XXX This must be called before pmap_bootstrap().
    308  1.1.6.1     joerg 	 */
    309  1.1.6.1     joerg 	if (strcmp(name, "pseudo-hid") == 0) {
    310  1.1.6.1     joerg 		printf("console keyboard type: unknown, assuming ADB\n");
    311  1.1.6.1     joerg #if NAKBD > 0
    312  1.1.6.1     joerg 		akbd_cnattach();
    313  1.1.6.1     joerg #endif
    314  1.1.6.1     joerg #if NADBKBD > 0
    315  1.1.6.1     joerg 		adbkbd_cnattach();
    316  1.1.6.1     joerg #endif
    317  1.1.6.1     joerg 		goto kbd_found;
    318  1.1.6.1     joerg 	}
    319  1.1.6.1     joerg 
    320  1.1.6.1     joerg 	/*
    321  1.1.6.1     joerg 	 * stdin is /psuedo-hid/keyboard.  Test `adb-kbd-ihandle and
    322  1.1.6.1     joerg 	 * `usb-kbd-ihandles to figure out the real keyboard(s).
    323  1.1.6.1     joerg 	 *
    324  1.1.6.1     joerg 	 * XXX This must be called before pmap_bootstrap().
    325  1.1.6.1     joerg 	 */
    326  1.1.6.1     joerg 
    327  1.1.6.1     joerg #if NUKBD > 0
    328  1.1.6.1     joerg 	if (OF_call_method("`usb-kbd-ihandles", stdin, 0, 1, &ukbds) >= 0 &&
    329  1.1.6.1     joerg 	    ukbds != NULL && ukbds->ihandle != 0 &&
    330  1.1.6.1     joerg 	    OF_instance_to_package(ukbds->ihandle) != -1) {
    331  1.1.6.1     joerg 		printf("usb-kbd-ihandles matches\n");
    332  1.1.6.1     joerg 		printf("console keyboard type: USB\n");
    333  1.1.6.1     joerg 		ukbd_cnattach();
    334  1.1.6.1     joerg 		goto kbd_found;
    335  1.1.6.1     joerg 	}
    336  1.1.6.1     joerg 	/* Try old method name. */
    337  1.1.6.2  jmcneill 	if (OF_call_method("`usb-kbd-ihandle", kstdin, 0, 1, &ukbd) >= 0 &&
    338  1.1.6.1     joerg 	    ukbd != 0 &&
    339  1.1.6.1     joerg 	    OF_instance_to_package(ukbd) != -1) {
    340  1.1.6.1     joerg 		printf("usb-kbd-ihandle matches\n");
    341  1.1.6.1     joerg 		printf("console keyboard type: USB\n");
    342  1.1.6.2  jmcneill 		kstdin = ukbd;
    343  1.1.6.1     joerg 		ukbd_cnattach();
    344  1.1.6.1     joerg 		goto kbd_found;
    345  1.1.6.1     joerg 	}
    346  1.1.6.1     joerg #endif
    347  1.1.6.1     joerg 
    348  1.1.6.1     joerg #if (NAKBD > 0) || (NADBKBD > 0)
    349  1.1.6.2  jmcneill 	if (OF_call_method("`adb-kbd-ihandle", kstdin, 0, 1, &akbd) >= 0 &&
    350  1.1.6.1     joerg 	    akbd != 0 &&
    351  1.1.6.1     joerg 	    OF_instance_to_package(akbd) != -1) {
    352  1.1.6.1     joerg 		printf("adb-kbd-ihandle matches\n");
    353  1.1.6.1     joerg 		printf("console keyboard type: ADB\n");
    354  1.1.6.2  jmcneill 		kstdin = akbd;
    355  1.1.6.1     joerg #if NAKBD > 0
    356  1.1.6.1     joerg 		akbd_cnattach();
    357  1.1.6.1     joerg #endif
    358  1.1.6.1     joerg #if NADBKBD > 0
    359  1.1.6.1     joerg 		adbkbd_cnattach();
    360  1.1.6.1     joerg #endif
    361  1.1.6.1     joerg 		goto kbd_found;
    362  1.1.6.1     joerg 	}
    363  1.1.6.1     joerg #endif
    364  1.1.6.1     joerg 
    365  1.1.6.1     joerg #if NUKBD > 0
    366  1.1.6.1     joerg 	/*
    367  1.1.6.1     joerg 	 * XXX Old firmware does not have `usb-kbd-ihandles method.  Assume
    368  1.1.6.1     joerg 	 * XXX USB keyboard anyway.
    369  1.1.6.1     joerg 	 */
    370  1.1.6.1     joerg 	printf("defaulting to USB...");
    371  1.1.6.1     joerg 	printf("console keyboard type: USB\n");
    372  1.1.6.1     joerg 	ukbd_cnattach();
    373  1.1.6.1     joerg 	goto kbd_found;
    374  1.1.6.1     joerg #endif
    375  1.1.6.1     joerg 
    376  1.1.6.1     joerg 	/*
    377  1.1.6.1     joerg 	 * No keyboard is found.  Just return.
    378  1.1.6.1     joerg 	 */
    379  1.1.6.1     joerg 	printf("no console keyboard\n");
    380  1.1.6.1     joerg 	return;
    381  1.1.6.1     joerg 
    382  1.1.6.1     joerg kbd_found:;
    383  1.1.6.1     joerg #if NAKBD + NUKBD + NADBKBD > 0
    384  1.1.6.1     joerg 	/*
    385  1.1.6.1     joerg 	 * XXX This is a little gross, but we don't get to call
    386  1.1.6.1     joerg 	 * XXX wskbd_cnattach() twice.
    387  1.1.6.1     joerg 	 */
    388  1.1.6.2  jmcneill 	ofkbd_ihandle = kstdin;
    389  1.1.6.1     joerg #if NWSDISPLAY > 0
    390  1.1.6.1     joerg 	wsdisplay_set_cons_kbd(ofkbd_cngetc, NULL, NULL);
    391  1.1.6.1     joerg #endif
    392  1.1.6.1     joerg #endif
    393  1.1.6.1     joerg }
    394  1.1.6.1     joerg 
    395  1.1.6.1     joerg /*
    396  1.1.6.1     joerg  * Bootstrap console keyboard routines, using OpenFirmware I/O.
    397  1.1.6.1     joerg  */
    398  1.1.6.1     joerg int
    399  1.1.6.1     joerg ofkbd_cngetc(dev_t dev)
    400  1.1.6.1     joerg {
    401  1.1.6.1     joerg 	u_char c = '\0';
    402  1.1.6.1     joerg 	int len;
    403  1.1.6.1     joerg 
    404  1.1.6.1     joerg 	do {
    405  1.1.6.1     joerg 		len = OF_read(ofkbd_ihandle, &c, 1);
    406  1.1.6.1     joerg 	} while (len != 1);
    407  1.1.6.1     joerg 
    408  1.1.6.1     joerg 	return c;
    409  1.1.6.1     joerg }
    410  1.1.6.1     joerg 
    411  1.1.6.2  jmcneill /*
    412  1.1.6.2  jmcneill  * Bootstrap console support functions
    413  1.1.6.2  jmcneill  */
    414  1.1.6.2  jmcneill 
    415  1.1.6.2  jmcneill static int
    416  1.1.6.2  jmcneill ofwbootcons_cngetc(dev_t dev)
    417  1.1.6.2  jmcneill {
    418  1.1.6.2  jmcneill 	unsigned char ch = '\0';
    419  1.1.6.2  jmcneill 	int l;
    420  1.1.6.2  jmcneill 
    421  1.1.6.2  jmcneill 	while ((l = OF_read(stdin, &ch, 1)) != 1)
    422  1.1.6.2  jmcneill 		if (l != -2 && l != 0)
    423  1.1.6.2  jmcneill 			return -1;
    424  1.1.6.2  jmcneill 	return ch;
    425  1.1.6.2  jmcneill }
    426  1.1.6.2  jmcneill 
    427  1.1.6.2  jmcneill static void
    428  1.1.6.2  jmcneill ofwbootcons_cnputc(dev_t dev, int c)
    429  1.1.6.2  jmcneill {
    430  1.1.6.2  jmcneill 	char ch = c;
    431  1.1.6.2  jmcneill 
    432  1.1.6.2  jmcneill 	OF_write(stdout, &ch, 1);
    433  1.1.6.2  jmcneill }
    434  1.1.6.2  jmcneill 
    435  1.1.6.1     joerg void
    436  1.1.6.1     joerg ofwoea_consinit(void)
    437  1.1.6.1     joerg {
    438  1.1.6.1     joerg 	static int initted = 0;
    439  1.1.6.1     joerg 
    440  1.1.6.1     joerg 	if (initted)
    441  1.1.6.1     joerg 		return;
    442  1.1.6.1     joerg 
    443  1.1.6.1     joerg 	initted = 1;
    444  1.1.6.1     joerg 	cninit();
    445  1.1.6.1     joerg }
    446  1.1.6.1     joerg 
    447  1.1.6.1     joerg static void
    448  1.1.6.1     joerg ofwoea_bootstrap_console(void)
    449  1.1.6.1     joerg {
    450  1.1.6.2  jmcneill 	int node;
    451  1.1.6.1     joerg 
    452  1.1.6.1     joerg 	chosen = OF_finddevice("/chosen");
    453  1.1.6.1     joerg 	if (chosen == -1)
    454  1.1.6.1     joerg 		goto nocons;
    455  1.1.6.1     joerg 
    456  1.1.6.1     joerg 	if (OF_getprop(chosen, "stdout", &stdout,
    457  1.1.6.1     joerg 	    sizeof(stdout)) != sizeof(stdout))
    458  1.1.6.1     joerg 		goto nocons;
    459  1.1.6.2  jmcneill 	if (OF_getprop(chosen, "stdin", &stdin,
    460  1.1.6.2  jmcneill 	    sizeof(stdin)) != sizeof(stdin))
    461  1.1.6.2  jmcneill 		goto nocons;
    462  1.1.6.1     joerg 	node = OF_instance_to_package(stdout);
    463  1.1.6.1     joerg 	console_node = node;
    464  1.1.6.1     joerg 	console_instance = stdout;
    465  1.1.6.1     joerg 
    466  1.1.6.1     joerg 	return;
    467  1.1.6.1     joerg nocons:
    468  1.1.6.1     joerg 	panic("No /chosen could be found!\n");
    469  1.1.6.1     joerg 	console_node = -1;
    470  1.1.6.1     joerg 	return;
    471  1.1.6.1     joerg }
    472