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