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