Home | History | Annotate | Line # | Download | only in boot
cons.c revision 1.4
      1  1.4  garbled /*	$NetBSD: cons.c,v 1.4 2006/04/10 17:58:59 garbled Exp $	*/
      2  1.1   nonaka 
      3  1.1   nonaka /*
      4  1.1   nonaka  * Copyright (c) 1990, 1993
      5  1.1   nonaka  *	The Regents of the University of California.  All rights reserved.
      6  1.2      agc  *
      7  1.2      agc  * This code is derived from software contributed to Berkeley by
      8  1.2      agc  * the Systems Programming Group of the University of Utah Computer
      9  1.2      agc  * Science Department.
     10  1.2      agc  *
     11  1.2      agc  * Redistribution and use in source and binary forms, with or without
     12  1.2      agc  * modification, are permitted provided that the following conditions
     13  1.2      agc  * are met:
     14  1.2      agc  * 1. Redistributions of source code must retain the above copyright
     15  1.2      agc  *    notice, this list of conditions and the following disclaimer.
     16  1.2      agc  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.2      agc  *    notice, this list of conditions and the following disclaimer in the
     18  1.2      agc  *    documentation and/or other materials provided with the distribution.
     19  1.2      agc  * 3. Neither the name of the University nor the names of its contributors
     20  1.2      agc  *    may be used to endorse or promote products derived from this software
     21  1.2      agc  *    without specific prior written permission.
     22  1.2      agc  *
     23  1.2      agc  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  1.2      agc  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  1.2      agc  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.2      agc  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  1.2      agc  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  1.2      agc  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  1.2      agc  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  1.2      agc  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  1.2      agc  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  1.2      agc  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  1.2      agc  * SUCH DAMAGE.
     34  1.2      agc  *
     35  1.2      agc  * from: Utah Hdr: cons.c 1.7 92/02/28
     36  1.2      agc  *
     37  1.2      agc  *	@(#)cons.c	8.1 (Berkeley) 6/10/93
     38  1.2      agc  */
     39  1.2      agc /*
     40  1.2      agc  * Copyright (c) 1988 University of Utah.
     41  1.1   nonaka  *
     42  1.1   nonaka  * This code is derived from software contributed to Berkeley by
     43  1.1   nonaka  * the Systems Programming Group of the University of Utah Computer
     44  1.1   nonaka  * Science Department.
     45  1.1   nonaka  *
     46  1.1   nonaka  * Redistribution and use in source and binary forms, with or without
     47  1.1   nonaka  * modification, are permitted provided that the following conditions
     48  1.1   nonaka  * are met:
     49  1.1   nonaka  * 1. Redistributions of source code must retain the above copyright
     50  1.1   nonaka  *    notice, this list of conditions and the following disclaimer.
     51  1.1   nonaka  * 2. Redistributions in binary form must reproduce the above copyright
     52  1.1   nonaka  *    notice, this list of conditions and the following disclaimer in the
     53  1.1   nonaka  *    documentation and/or other materials provided with the distribution.
     54  1.1   nonaka  * 3. All advertising materials mentioning features or use of this software
     55  1.1   nonaka  *    must display the following acknowledgement:
     56  1.1   nonaka  *	This product includes software developed by the University of
     57  1.1   nonaka  *	California, Berkeley and its contributors.
     58  1.1   nonaka  * 4. Neither the name of the University nor the names of its contributors
     59  1.1   nonaka  *    may be used to endorse or promote products derived from this software
     60  1.1   nonaka  *    without specific prior written permission.
     61  1.1   nonaka  *
     62  1.1   nonaka  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     63  1.1   nonaka  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     64  1.1   nonaka  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     65  1.1   nonaka  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     66  1.1   nonaka  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     67  1.1   nonaka  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     68  1.1   nonaka  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     69  1.1   nonaka  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     70  1.1   nonaka  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     71  1.1   nonaka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     72  1.1   nonaka  * SUCH DAMAGE.
     73  1.1   nonaka  *
     74  1.1   nonaka  * from: Utah Hdr: cons.c 1.7 92/02/28
     75  1.1   nonaka  *
     76  1.1   nonaka  *	@(#)cons.c	8.1 (Berkeley) 6/10/93
     77  1.1   nonaka  */
     78  1.1   nonaka 
     79  1.1   nonaka #include <lib/libsa/stand.h>
     80  1.1   nonaka 
     81  1.1   nonaka #include "boot.h"
     82  1.1   nonaka #include "cons.h"
     83  1.1   nonaka 
     84  1.1   nonaka #ifdef CONS_VGA
     85  1.1   nonaka void vgacnprobe __P((struct consdev *));
     86  1.1   nonaka void vgacninit __P((struct consdev *));
     87  1.1   nonaka void vgacnputchar __P((void *, int));
     88  1.1   nonaka int vgacngetchar __P((void *));
     89  1.1   nonaka int vgacnscan __P((void *));
     90  1.1   nonaka #endif
     91  1.1   nonaka 
     92  1.1   nonaka #ifdef CONS_SERIAL
     93  1.1   nonaka void siocnprobe __P((struct consdev *));
     94  1.1   nonaka void siocninit __P((struct consdev *));
     95  1.1   nonaka void siocnputchar __P((void *, int));
     96  1.1   nonaka int siocngetchar __P((void *));
     97  1.1   nonaka int siocnscan __P((void *));
     98  1.1   nonaka # include "ns16550.h"
     99  1.1   nonaka # ifndef COMPORT
    100  1.1   nonaka #  define COMPORT COM1
    101  1.1   nonaka # endif
    102  1.1   nonaka # ifndef COMSPEED
    103  1.1   nonaka #  define COMSPEED 9600
    104  1.1   nonaka # endif
    105  1.1   nonaka #endif
    106  1.1   nonaka 
    107  1.1   nonaka struct consdev constab[] = {
    108  1.1   nonaka #ifdef CONS_VGA
    109  1.1   nonaka 	{ "vga", 0xc0000000, 0,
    110  1.1   nonaka 	    vgacnprobe, vgacninit, vgacngetchar, vgacnputchar, vgacnscan },
    111  1.1   nonaka #endif
    112  1.1   nonaka #ifdef CONS_SERIAL
    113  1.1   nonaka 	{ "com", COMPORT, COMSPEED,
    114  1.1   nonaka 	    siocnprobe, siocninit, siocngetchar, siocnputchar, siocnscan },
    115  1.1   nonaka #endif
    116  1.1   nonaka 	{ 0 }
    117  1.1   nonaka };
    118  1.1   nonaka 
    119  1.1   nonaka struct consdev *cn_tab;
    120  1.1   nonaka 
    121  1.1   nonaka char *
    122  1.1   nonaka cninit(addr, speed)
    123  1.1   nonaka 	int *addr;
    124  1.1   nonaka 	int *speed;
    125  1.1   nonaka {
    126  1.1   nonaka 	register struct consdev *cp;
    127  1.1   nonaka 
    128  1.1   nonaka 	cn_tab = NULL;
    129  1.1   nonaka 	for (cp = constab; cp->cn_probe; cp++) {
    130  1.1   nonaka 		(*cp->cn_probe)(cp);
    131  1.1   nonaka 		if (cp->cn_pri > CN_DEAD &&
    132  1.1   nonaka 		    (cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri))
    133  1.1   nonaka 			cn_tab = cp;
    134  1.1   nonaka 	}
    135  1.1   nonaka 	if (cn_tab) {
    136  1.1   nonaka 		(*cn_tab->cn_init)(cn_tab);
    137  1.1   nonaka 		*addr = cn_tab->address;
    138  1.1   nonaka 		*speed = cn_tab->speed;
    139  1.1   nonaka 		return (cn_tab->cn_name);
    140  1.1   nonaka 	}
    141  1.1   nonaka 
    142  1.1   nonaka 	return (NULL);
    143  1.1   nonaka }
    144  1.1   nonaka 
    145  1.1   nonaka int
    146  1.1   nonaka cngetc()
    147  1.1   nonaka {
    148  1.1   nonaka 
    149  1.1   nonaka 	if (cn_tab)
    150  1.1   nonaka 		return ((*cn_tab->cn_getc)(cn_tab->cn_dev));
    151  1.1   nonaka 	return (0);
    152  1.1   nonaka }
    153  1.1   nonaka 
    154  1.1   nonaka void
    155  1.1   nonaka cnputc(c)
    156  1.1   nonaka 	int c;
    157  1.1   nonaka {
    158  1.1   nonaka 
    159  1.1   nonaka 	if (cn_tab)
    160  1.1   nonaka 		(*cn_tab->cn_putc)(cn_tab->cn_dev, c);
    161  1.1   nonaka }
    162  1.1   nonaka 
    163  1.1   nonaka int
    164  1.1   nonaka cnscan()
    165  1.1   nonaka {
    166  1.1   nonaka 
    167  1.1   nonaka 	if (cn_tab)
    168  1.1   nonaka 		return ((*cn_tab->cn_scan)(cn_tab->cn_dev));
    169  1.1   nonaka 	return (0);
    170  1.1   nonaka }
    171  1.1   nonaka 
    172  1.1   nonaka #ifdef CONS_VGA
    173  1.1   nonaka /*
    174  1.1   nonaka  * VGA console
    175  1.1   nonaka  */
    176  1.1   nonaka void
    177  1.1   nonaka vgacnprobe(cp)
    178  1.1   nonaka 	struct consdev *cp;
    179  1.1   nonaka {
    180  1.1   nonaka 	cp->cn_pri = CN_NORMAL;
    181  1.1   nonaka }
    182  1.1   nonaka 
    183  1.1   nonaka void
    184  1.1   nonaka vgacninit(cp)
    185  1.1   nonaka 	struct consdev *cp;
    186  1.1   nonaka {
    187  1.1   nonaka 
    188  1.1   nonaka 	vga_reset((u_char *)cp->address);
    189  1.1   nonaka 	vga_init((u_char *)cp->address);
    190  1.1   nonaka 	kbdreset();
    191  1.1   nonaka }
    192  1.1   nonaka 
    193  1.1   nonaka int
    194  1.1   nonaka vgacngetchar(dev)
    195  1.1   nonaka 	void *dev;
    196  1.1   nonaka {
    197  1.1   nonaka 
    198  1.1   nonaka 	return (kbd_getc());
    199  1.1   nonaka }
    200  1.1   nonaka 
    201  1.1   nonaka void
    202  1.1   nonaka vgacnputchar(dev, c)
    203  1.1   nonaka 	void *dev;
    204  1.1   nonaka 	register int c;
    205  1.1   nonaka {
    206  1.1   nonaka 
    207  1.1   nonaka 	vga_putc(c);
    208  1.1   nonaka }
    209  1.1   nonaka 
    210  1.1   nonaka int
    211  1.1   nonaka vgacnscan(dev)
    212  1.1   nonaka 	void *dev;
    213  1.1   nonaka {
    214  1.1   nonaka 
    215  1.1   nonaka 	return (kbd(1));
    216  1.1   nonaka }
    217  1.1   nonaka #endif /* CONS_VGA */
    218  1.1   nonaka 
    219  1.1   nonaka #ifdef CONS_SERIAL
    220  1.1   nonaka /*
    221  1.1   nonaka  * serial console
    222  1.1   nonaka  */
    223  1.1   nonaka void
    224  1.1   nonaka siocnprobe(cp)
    225  1.1   nonaka 	struct consdev *cp;
    226  1.1   nonaka {
    227  1.1   nonaka 
    228  1.1   nonaka 	cp->cn_pri = CN_REMOTE;
    229  1.1   nonaka }
    230  1.1   nonaka 
    231  1.1   nonaka void
    232  1.1   nonaka siocninit(cp)
    233  1.1   nonaka 	struct consdev *cp;
    234  1.1   nonaka {
    235  1.1   nonaka 
    236  1.1   nonaka 	cp->cn_dev = (void *)NS16550_init(cp->address, cp->speed);
    237  1.1   nonaka }
    238  1.1   nonaka 
    239  1.1   nonaka int
    240  1.1   nonaka siocngetchar(dev)
    241  1.1   nonaka 	void *dev;
    242  1.1   nonaka {
    243  1.1   nonaka 
    244  1.1   nonaka 	return (NS16550_getc((struct NS16550 *)dev));
    245  1.1   nonaka }
    246  1.1   nonaka 
    247  1.1   nonaka void
    248  1.1   nonaka siocnputchar(dev, c)
    249  1.1   nonaka 	void *dev;
    250  1.1   nonaka 	register int c;
    251  1.1   nonaka {
    252  1.1   nonaka 
    253  1.1   nonaka 	if (c == '\n')
    254  1.1   nonaka 		NS16550_putc((struct NS16550 *)dev, '\r');
    255  1.1   nonaka 	NS16550_putc((struct NS16550 *)dev, c);
    256  1.1   nonaka }
    257  1.1   nonaka 
    258  1.1   nonaka int
    259  1.1   nonaka siocnscan(dev)
    260  1.1   nonaka 	void *dev;
    261  1.1   nonaka {
    262  1.1   nonaka 
    263  1.1   nonaka 	return (NS16550_scankbd((struct NS16550 *)dev));
    264  1.1   nonaka }
    265  1.1   nonaka #endif /* CONS_SERIAL */
    266