Home | History | Annotate | Line # | Download | only in dev
consinit.c revision 1.2
      1  1.2  thorpej /*	$NetBSD: consinit.c,v 1.2 2000/03/06 21:36:11 thorpej Exp $	*/
      2  1.1      eeh 
      3  1.1      eeh /*-
      4  1.1      eeh  * Copyright (c) 1999 Eduardo E. Horvath
      5  1.1      eeh  * All rights reserved.
      6  1.1      eeh  *
      7  1.1      eeh  * Redistribution and use in source and binary forms, with or without
      8  1.1      eeh  * modification, are permitted provided that the following conditions
      9  1.1      eeh  * are met:
     10  1.1      eeh  * 1. Redistributions of source code must retain the above copyright
     11  1.1      eeh  *    notice, this list of conditions and the following disclaimer.
     12  1.1      eeh  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.1      eeh  *    notice, this list of conditions and the following disclaimer in the
     14  1.1      eeh  *    documentation and/or other materials provided with the distribution.
     15  1.1      eeh  * 3. The name of the author may not be used to endorse or promote products
     16  1.1      eeh  *    derived from this software without specific prior written permission.
     17  1.1      eeh  *
     18  1.1      eeh  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     19  1.1      eeh  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     20  1.1      eeh  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     21  1.1      eeh  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     22  1.1      eeh  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     23  1.1      eeh  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     24  1.1      eeh  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     25  1.1      eeh  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     26  1.1      eeh  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     27  1.1      eeh  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     28  1.1      eeh  * SUCH DAMAGE.
     29  1.1      eeh  */
     30  1.1      eeh 
     31  1.1      eeh /*
     32  1.1      eeh  * Default console driver.  Uses the PROM or whatever
     33  1.1      eeh  * driver(s) are appropriate.
     34  1.1      eeh  */
     35  1.1      eeh 
     36  1.1      eeh #include "opt_ddb.h"
     37  1.1      eeh 
     38  1.1      eeh #include <sys/param.h>
     39  1.1      eeh #include <sys/systm.h>
     40  1.1      eeh #include <sys/conf.h>
     41  1.1      eeh #include <sys/device.h>
     42  1.1      eeh #include <sys/file.h>
     43  1.1      eeh #include <sys/ioctl.h>
     44  1.1      eeh #include <sys/kernel.h>
     45  1.1      eeh #include <sys/proc.h>
     46  1.1      eeh #include <sys/tty.h>
     47  1.1      eeh #include <sys/time.h>
     48  1.1      eeh #include <sys/syslog.h>
     49  1.1      eeh 
     50  1.1      eeh #include <machine/autoconf.h>
     51  1.1      eeh #include <machine/openfirm.h>
     52  1.1      eeh #include <machine/bsd_openprom.h>
     53  1.1      eeh #include <machine/conf.h>
     54  1.1      eeh #include <machine/cpu.h>
     55  1.1      eeh #include <machine/eeprom.h>
     56  1.1      eeh #include <machine/psl.h>
     57  1.1      eeh #include <machine/z8530var.h>
     58  1.1      eeh 
     59  1.1      eeh #include <dev/cons.h>
     60  1.1      eeh 
     61  1.1      eeh #include <sparc64/sparc64/vaddrs.h>
     62  1.1      eeh #include <sparc64/sparc64/auxreg.h>
     63  1.1      eeh #include <sparc64/dev/cons.h>
     64  1.1      eeh 
     65  1.1      eeh 
     66  1.1      eeh 
     67  1.1      eeh static void prom_cninit __P((struct consdev *));
     68  1.1      eeh static int  prom_cngetc __P((dev_t));
     69  1.1      eeh static void prom_cnputc __P((dev_t, int));
     70  1.1      eeh 
     71  1.1      eeh int stdin = NULL, stdout = NULL;
     72  1.1      eeh 
     73  1.1      eeh /*
     74  1.1      eeh  * The console is set to this one initially,
     75  1.1      eeh  * which lets us use the PROM until consinit()
     76  1.1      eeh  * is called to select a real console.
     77  1.1      eeh  */
     78  1.1      eeh struct consdev consdev_prom = {
     79  1.1      eeh 	nullcnprobe,
     80  1.1      eeh 	prom_cninit,
     81  1.1      eeh 	prom_cngetc,
     82  1.1      eeh 	prom_cnputc,
     83  1.1      eeh 	nullcnpollc,
     84  1.2  thorpej 	NULL,
     85  1.1      eeh };
     86  1.1      eeh 
     87  1.1      eeh /*
     88  1.1      eeh  * The console table pointer is statically initialized
     89  1.1      eeh  * to point to the PROM (output only) table, so that
     90  1.1      eeh  * early calls to printf will work.
     91  1.1      eeh  */
     92  1.1      eeh struct consdev *cn_tab = &consdev_prom;
     93  1.1      eeh 
     94  1.1      eeh void
     95  1.1      eeh nullcnprobe(cn)
     96  1.1      eeh 	struct consdev *cn;
     97  1.1      eeh {
     98  1.1      eeh }
     99  1.1      eeh 
    100  1.1      eeh static void
    101  1.1      eeh prom_cninit(cn)
    102  1.1      eeh 	struct consdev *cn;
    103  1.1      eeh {
    104  1.1      eeh 	if (!stdin) {
    105  1.1      eeh 		int node = OF_finddevice("/chosen");
    106  1.1      eeh 		OF_getprop(node, "stdin",  &stdin, sizeof(stdin));
    107  1.1      eeh 	}
    108  1.1      eeh 	if (!stdout) {
    109  1.1      eeh 		int node = OF_finddevice("/chosen");
    110  1.1      eeh 		OF_getprop(node, "stdout",  &stdout, sizeof(stdout));
    111  1.1      eeh 	}
    112  1.1      eeh }
    113  1.1      eeh 
    114  1.1      eeh /*
    115  1.1      eeh  * PROM console input putchar.
    116  1.1      eeh  * (dummy - this is output only)
    117  1.1      eeh  */
    118  1.1      eeh static int
    119  1.1      eeh prom_cngetc(dev)
    120  1.1      eeh 	dev_t dev;
    121  1.1      eeh {
    122  1.1      eeh 	char c0;
    123  1.1      eeh 
    124  1.1      eeh 	if (!stdin) {
    125  1.1      eeh 		int node = OF_finddevice("/chosen");
    126  1.1      eeh 		OF_getprop(node, "stdin",  &stdin, sizeof(stdin));
    127  1.1      eeh 	}
    128  1.1      eeh 	if (OF_read(stdin, &c0, 1) == 1)
    129  1.1      eeh 		return (c0);
    130  1.1      eeh 	return -1;
    131  1.1      eeh }
    132  1.1      eeh 
    133  1.1      eeh /*
    134  1.1      eeh  * PROM console output putchar.
    135  1.1      eeh  */
    136  1.1      eeh static void
    137  1.1      eeh prom_cnputc(dev, c)
    138  1.1      eeh 	dev_t dev;
    139  1.1      eeh 	int c;
    140  1.1      eeh {
    141  1.1      eeh 	int s;
    142  1.1      eeh 	char c0 = (c & 0x7f);
    143  1.1      eeh 
    144  1.1      eeh 	if (!stdout) {
    145  1.1      eeh 		int node = OF_finddevice("/chosen");
    146  1.1      eeh 		OF_getprop(node, "stdout",  &stdout, sizeof(stdout));
    147  1.1      eeh 	}
    148  1.1      eeh 
    149  1.1      eeh 	s = splhigh();
    150  1.1      eeh 	OF_write(stdout, &c0, 1);
    151  1.1      eeh 	splx(s);
    152  1.1      eeh }
    153  1.1      eeh 
    154  1.1      eeh /*****************************************************************/
    155  1.1      eeh 
    156  1.1      eeh #ifdef	DEBUG
    157  1.1      eeh #define	DBPRINT(x)	printf x
    158  1.1      eeh #else
    159  1.1      eeh #define	DBPRINT(x)
    160  1.1      eeh #endif
    161  1.1      eeh 
    162  1.1      eeh /*
    163  1.1      eeh  * This function replaces sys/dev/cninit.c
    164  1.1      eeh  * Determine which device is the console using
    165  1.1      eeh  * the PROM "input source" and "output sink".
    166  1.1      eeh  */
    167  1.1      eeh void
    168  1.1      eeh consinit()
    169  1.1      eeh {
    170  1.1      eeh 	register int chosen;
    171  1.1      eeh 	char buffer[128];
    172  1.1      eeh 	extern int stdinnode, fbnode;
    173  1.1      eeh 	char *consname = "unknown";
    174  1.1      eeh 
    175  1.1      eeh 	DBPRINT(("consinit()\r\n"));
    176  1.1      eeh 	if (cn_tab != &consdev_prom) return;
    177  1.1      eeh 
    178  1.1      eeh 	DBPRINT(("setting up stdin\r\n"));
    179  1.1      eeh 	chosen = OF_finddevice("/chosen");
    180  1.1      eeh 	OF_getprop(chosen, "stdin",  &stdin, sizeof(stdin));
    181  1.1      eeh 	DBPRINT(("stdin instance = %x\r\n", stdin));
    182  1.1      eeh 
    183  1.1      eeh 	if ((stdinnode = OF_instance_to_package(stdin)) == 0) {
    184  1.1      eeh 		printf("WARNING: no PROM stdin\n");
    185  1.1      eeh 	}
    186  1.1      eeh 
    187  1.1      eeh 	DBPRINT(("setting up stdout\r\n"));
    188  1.1      eeh 	OF_getprop(chosen, "stdout", &stdout, sizeof(stdout));
    189  1.1      eeh 
    190  1.1      eeh 	DBPRINT(("stdout instance = %x\r\n", stdout));
    191  1.1      eeh 
    192  1.1      eeh 	if ((fbnode = OF_instance_to_package(stdout)) == 0)
    193  1.1      eeh 		printf("WARNING: no PROM stdout\n");
    194  1.1      eeh 
    195  1.1      eeh 	DBPRINT(("stdout package = %x\r\n", fbnode));
    196  1.1      eeh 
    197  1.1      eeh 	if (stdinnode && (OF_getproplen(stdinnode,"keyboard") >= 0)) {
    198  1.1      eeh #if NKBD > 0
    199  1.1      eeh 		printf("cninit: kdb/display not configured\n");
    200  1.1      eeh #endif
    201  1.1      eeh 		consname = "keyboard/display";
    202  1.1      eeh 	} else if (fbnode &&
    203  1.1      eeh 		   (OF_instance_to_path(stdinnode, buffer, sizeof(buffer) >= 0))) {
    204  1.1      eeh 		consname = buffer;
    205  1.1      eeh 	}
    206  1.1      eeh 	printf("console is %s\n", consname);
    207  1.1      eeh 
    208  1.1      eeh 	/* Defer the rest to the device attach */
    209  1.1      eeh }
    210  1.1      eeh 
    211