Home | History | Annotate | Line # | Download | only in dev
consinit.c revision 1.25.12.1
      1  1.25.12.1      yamt /*	$NetBSD: consinit.c,v 1.25.12.1 2012/10/30 17:20:23 yamt 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.13     lukem 
     31       1.13     lukem #include <sys/cdefs.h>
     32  1.25.12.1      yamt __KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.25.12.1 2012/10/30 17:20:23 yamt Exp $");
     33        1.1       eeh 
     34        1.1       eeh #include "opt_ddb.h"
     35        1.5       eeh #include "pcons.h"
     36       1.20       jdc #include "ukbd.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/cpu.h>
     54        1.1       eeh #include <machine/eeprom.h>
     55        1.1       eeh #include <machine/psl.h>
     56        1.1       eeh #include <machine/z8530var.h>
     57        1.9       mrg #include <machine/sparc64.h>
     58        1.1       eeh 
     59        1.1       eeh #include <dev/cons.h>
     60        1.1       eeh 
     61        1.1       eeh #include <sparc64/dev/cons.h>
     62        1.1       eeh 
     63       1.20       jdc #include <dev/usb/ukbdvar.h>
     64       1.20       jdc 
     65       1.21       cdi static void prom_cnprobe(struct consdev *);
     66       1.21       cdi static void prom_cninit(struct consdev *);
     67       1.21       cdi int  prom_cngetc(dev_t);
     68       1.21       cdi static void prom_cnputc(dev_t, int);
     69       1.21       cdi static void prom_cnpollc(dev_t, int);
     70        1.1       eeh 
     71        1.1       eeh /*
     72        1.1       eeh  * The console is set to this one initially,
     73        1.1       eeh  * which lets us use the PROM until consinit()
     74        1.1       eeh  * is called to select a real console.
     75        1.1       eeh  */
     76        1.1       eeh struct consdev consdev_prom = {
     77       1.22    martin 	.cn_probe = prom_cnprobe,
     78       1.22    martin 	.cn_init = prom_cninit,
     79       1.22    martin 	.cn_getc = prom_cngetc,
     80       1.22    martin 	.cn_putc = prom_cnputc,
     81       1.22    martin 	.cn_pollc = prom_cnpollc,
     82        1.1       eeh };
     83        1.1       eeh 
     84        1.1       eeh void
     85       1.21       cdi prom_cnprobe(struct consdev *cd)
     86        1.1       eeh {
     87        1.5       eeh #if NPCONS > 0
     88        1.5       eeh 	int maj;
     89       1.12   gehenna 	extern const struct cdevsw pcons_cdevsw;
     90        1.1       eeh 
     91       1.12   gehenna 	maj = cdevsw_lookup_major(&pcons_cdevsw);
     92        1.5       eeh 	cd->cn_dev = makedev(maj, 0);
     93        1.5       eeh 	cd->cn_pri = CN_INTERNAL;
     94        1.5       eeh #endif
     95        1.1       eeh }
     96        1.1       eeh 
     97        1.5       eeh int
     98       1.21       cdi prom_cngetc(dev_t dev)
     99        1.1       eeh {
    100        1.5       eeh 	unsigned char ch = '\0';
    101        1.5       eeh 	int l;
    102        1.7       eeh #ifdef DDB
    103        1.7       eeh 	static int nplus = 0;
    104        1.7       eeh #endif
    105       1.15        pk 
    106       1.17        pk 	while ((l = prom_read(prom_stdin(), &ch, 1)) != 1)
    107        1.5       eeh 		/* void */;
    108        1.7       eeh #ifdef DDB
    109        1.7       eeh 	if (ch == '+') {
    110        1.7       eeh 		if (nplus++ > 3) Debugger();
    111        1.7       eeh 	} else nplus = 0;
    112        1.7       eeh #endif
    113        1.5       eeh 	if (ch == '\r')
    114        1.5       eeh 		ch = '\n';
    115        1.5       eeh 	return ch;
    116        1.5       eeh }
    117        1.1       eeh 
    118        1.5       eeh static void
    119       1.21       cdi prom_cninit(struct consdev *cn)
    120        1.5       eeh {
    121        1.1       eeh }
    122        1.1       eeh 
    123        1.1       eeh /*
    124        1.1       eeh  * PROM console output putchar.
    125        1.1       eeh  */
    126        1.1       eeh static void
    127       1.21       cdi prom_cnputc(dev_t dev, int c)
    128        1.1       eeh {
    129        1.1       eeh 	int s;
    130        1.1       eeh 	char c0 = (c & 0x7f);
    131        1.1       eeh 
    132        1.1       eeh 	s = splhigh();
    133       1.17        pk 	prom_write(prom_stdout(), &c0, 1);
    134        1.1       eeh 	splx(s);
    135        1.1       eeh }
    136        1.1       eeh 
    137        1.5       eeh void
    138       1.21       cdi prom_cnpollc(dev_t dev, int on)
    139        1.5       eeh {
    140        1.5       eeh 	if (on) {
    141        1.5       eeh                 /* Entering debugger. */
    142        1.5       eeh #if NFB > 0
    143        1.5       eeh                 fb_unblank();
    144       1.15        pk #endif
    145        1.5       eeh 	} else {
    146        1.5       eeh                 /* Resuming kernel. */
    147        1.5       eeh 	}
    148        1.5       eeh #if NPCONS > 0
    149        1.5       eeh 	pcons_cnpollc(dev, on);
    150       1.15        pk #endif
    151        1.5       eeh }
    152        1.5       eeh 
    153        1.1       eeh /*****************************************************************/
    154        1.1       eeh 
    155        1.1       eeh #ifdef	DEBUG
    156        1.8       eeh #define	DBPRINT(x)	prom_printf x
    157        1.1       eeh #else
    158        1.1       eeh #define	DBPRINT(x)
    159        1.1       eeh #endif
    160        1.1       eeh 
    161       1.15        pk int prom_stdin_node;
    162       1.15        pk int prom_stdout_node;
    163       1.15        pk 
    164        1.1       eeh /*
    165        1.1       eeh  * This function replaces sys/dev/cninit.c
    166        1.1       eeh  * Determine which device is the console using
    167        1.1       eeh  * the PROM "input source" and "output sink".
    168        1.1       eeh  */
    169        1.1       eeh void
    170       1.25    cegger consinit(void)
    171        1.1       eeh {
    172       1.15        pk 	int chosen;
    173        1.1       eeh 	char buffer[128];
    174       1.18  christos 	const char *consname = "unknown";
    175       1.15        pk 
    176        1.1       eeh 	DBPRINT(("consinit()\r\n"));
    177       1.15        pk 
    178       1.15        pk 	if (cn_tab != &consdev_prom)
    179       1.15        pk 		return;
    180       1.15        pk 
    181       1.17        pk 	chosen = prom_finddevice("/chosen");
    182       1.15        pk 
    183       1.17        pk 	if ((prom_stdin_node = prom_instance_to_package(prom_stdin())) == 0) {
    184        1.1       eeh 		printf("WARNING: no PROM stdin\n");
    185       1.15        pk 	}
    186       1.15        pk 	DBPRINT(("stdin node = %x\r\n", prom_stdin_node));
    187       1.15        pk 
    188       1.17        pk 	if ((prom_stdout_node = prom_instance_to_package(prom_stdout())) == 0)
    189        1.1       eeh 		printf("WARNING: no PROM stdout\n");
    190       1.16    petrov 	DBPRINT(("stdout package = %x\r\n", prom_stdout_node));
    191       1.15        pk 
    192       1.11       eeh 	DBPRINT(("buffer @ %p\r\n", buffer));
    193       1.15        pk 
    194       1.15        pk 	if (prom_stdin_node != 0 &&
    195       1.17        pk 	    (prom_getproplen(prom_stdin_node, "keyboard") >= 0)) {
    196       1.20       jdc #if NUKBD > 0
    197       1.20       jdc 		if ((OF_instance_to_path(prom_stdin(), buffer, sizeof(buffer)) >= 0) &&
    198       1.20       jdc 		    (strstr(buffer, "/usb@") != NULL)) {
    199       1.20       jdc 			/*
    200       1.20       jdc 		 	* If we have a USB keyboard, it will show up as (e.g.)
    201       1.20       jdc 		 	*   /pci@1f,0/usb@c,3/keyboard@1	(Blade 100)
    202       1.20       jdc 		 	*/
    203       1.20       jdc 			consname = "usb-keyboard/display";
    204       1.20       jdc 			ukbd_cnattach();
    205       1.20       jdc 		} else
    206        1.1       eeh #endif
    207       1.20       jdc 			consname = "sun-keyboard/display";
    208       1.20       jdc 	} else if (prom_stdin_node != 0 &&
    209       1.17        pk 		   (OF_instance_to_path(prom_stdin(), buffer, sizeof(buffer)) >= 0)) {
    210        1.1       eeh 		consname = buffer;
    211        1.1       eeh 	}
    212       1.23    martin 	DBPRINT(("console is %s\n", consname));
    213       1.15        pk 
    214        1.5       eeh 	/* Initialize PROM console */
    215        1.5       eeh 	(*cn_tab->cn_probe)(cn_tab);
    216        1.5       eeh 	(*cn_tab->cn_init)(cn_tab);
    217        1.1       eeh }
    218