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