Home | History | Annotate | Line # | Download | only in boot
cons.c revision 1.2
      1 /*	$NetBSD: cons.c,v 1.2 2003/08/07 16:29:21 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 <lib/libsa/stand.h>
     80 
     81 #include "boot.h"
     82 #include "cons.h"
     83 
     84 #ifdef CONS_FB
     85 void fbcnprobe __P((struct consdev *));
     86 void fbcninit __P((struct consdev *));
     87 void fbcnputchar __P((void *, int));
     88 int fbcngetchar __P((void *));
     89 int fbcnscan __P((void *));
     90 #endif
     91 
     92 #ifdef CONS_VGA
     93 void vgacnprobe __P((struct consdev *));
     94 void vgacninit __P((struct consdev *));
     95 void vgacnputchar __P((void *, int));
     96 int vgacngetchar __P((void *));
     97 int vgacnscan __P((void *));
     98 #endif
     99 
    100 #ifdef CONS_SERIAL
    101 void siocnprobe __P((struct consdev *));
    102 void siocninit __P((struct consdev *));
    103 void siocnputchar __P((void *, int));
    104 int siocngetchar __P((void *));
    105 int siocnscan __P((void *));
    106 # include "ns16550.h"
    107 # ifndef COMPORT
    108 #  define COMPORT COM1
    109 # endif
    110 # ifndef COMSPEED
    111 #  define COMSPEED 9600
    112 # endif
    113 #endif
    114 
    115 struct consdev constab[] = {
    116 #ifdef CONS_FB
    117 	{ "fb", 0xc0800000, 0,
    118 	    fbcnprobe, fbcninit, fbcngetchar, fbcnputchar, fbcnscan },
    119 #endif
    120 #ifdef CONS_VGA
    121 	{ "vga", 0xc0000000, 0,
    122 	    vgacnprobe, vgacninit, vgacngetchar, vgacnputchar, vgacnscan },
    123 #endif
    124 #ifdef CONS_SERIAL
    125 	{ "com", COMPORT, COMSPEED,
    126 	    siocnprobe, siocninit, siocngetchar, siocnputchar, siocnscan },
    127 #endif
    128 	{ 0 }
    129 };
    130 
    131 struct consdev *cn_tab;
    132 
    133 char *
    134 cninit(addr, speed)
    135 	int *addr;
    136 	int *speed;
    137 {
    138 	register struct consdev *cp;
    139 
    140 	cn_tab = NULL;
    141 	for (cp = constab; cp->cn_probe; cp++) {
    142 		(*cp->cn_probe)(cp);
    143 		if (cp->cn_pri > CN_DEAD &&
    144 		    (cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri))
    145 			cn_tab = cp;
    146 	}
    147 	if (cn_tab) {
    148 		(*cn_tab->cn_init)(cn_tab);
    149 		*addr = cn_tab->address;
    150 		*speed = cn_tab->speed;
    151 		return (cn_tab->cn_name);
    152 	}
    153 
    154 	return (NULL);
    155 }
    156 
    157 int
    158 cngetc()
    159 {
    160 
    161 	if (cn_tab)
    162 		return ((*cn_tab->cn_getc)(cn_tab->cn_dev));
    163 	return (0);
    164 }
    165 
    166 void
    167 cnputc(c)
    168 	int c;
    169 {
    170 
    171 	if (cn_tab)
    172 		(*cn_tab->cn_putc)(cn_tab->cn_dev, c);
    173 }
    174 
    175 int
    176 cnscan()
    177 {
    178 
    179 	if (cn_tab)
    180 		return ((*cn_tab->cn_scan)(cn_tab->cn_dev));
    181 	return (0);
    182 }
    183 
    184 #ifdef CONS_FB
    185 /*
    186  * frame buffer console
    187  */
    188 void
    189 fbcnprobe(cp)
    190 	struct consdev *cp;
    191 {
    192 
    193 	cp->cn_pri = CN_INTERNAL;
    194 }
    195 
    196 void
    197 fbcninit(cp)
    198 	struct consdev *cp;
    199 {
    200 
    201 	video_init((u_char *)cp->address);
    202 	kbdreset();
    203 }
    204 
    205 int
    206 fbcngetchar(dev)
    207 	void *dev;
    208 {
    209 
    210 	return (kbd_getc());
    211 }
    212 
    213 void
    214 fbcnputchar(dev, c)
    215 	void *dev;
    216 	register int c;
    217 {
    218 
    219 	video_putc(c);
    220 }
    221 
    222 int
    223 fbcnscan(dev)
    224 	void *dev;
    225 {
    226 
    227 	return (kbd(1));
    228 }
    229 #endif /* CONS_FB */
    230 
    231 #ifdef CONS_VGA
    232 /*
    233  * VGA console
    234  */
    235 void
    236 vgacnprobe(cp)
    237 	struct consdev *cp;
    238 {
    239 	cp->cn_pri = CN_NORMAL;
    240 }
    241 
    242 void
    243 vgacninit(cp)
    244 	struct consdev *cp;
    245 {
    246 
    247 	vga_reset((u_char *)cp->address);
    248 	vga_init((u_char *)cp->address);
    249 	kbdreset();
    250 }
    251 
    252 int
    253 vgacngetchar(dev)
    254 	void *dev;
    255 {
    256 
    257 	return (kbd_getc());
    258 }
    259 
    260 void
    261 vgacnputchar(dev, c)
    262 	void *dev;
    263 	register int c;
    264 {
    265 
    266 	vga_putc(c);
    267 }
    268 
    269 int
    270 vgacnscan(dev)
    271 	void *dev;
    272 {
    273 
    274 	return (kbd(1));
    275 }
    276 #endif /* CONS_VGA */
    277 
    278 #ifdef CONS_SERIAL
    279 /*
    280  * serial console
    281  */
    282 void
    283 siocnprobe(cp)
    284 	struct consdev *cp;
    285 {
    286 
    287 	cp->cn_pri = CN_REMOTE;
    288 }
    289 
    290 void
    291 siocninit(cp)
    292 	struct consdev *cp;
    293 {
    294 
    295 	cp->cn_dev = (void *)NS16550_init(cp->address, cp->speed);
    296 }
    297 
    298 int
    299 siocngetchar(dev)
    300 	void *dev;
    301 {
    302 
    303 	return (NS16550_getc((struct NS16550 *)dev));
    304 }
    305 
    306 void
    307 siocnputchar(dev, c)
    308 	void *dev;
    309 	register int c;
    310 {
    311 
    312 	if (c == '\n')
    313 		NS16550_putc((struct NS16550 *)dev, '\r');
    314 	NS16550_putc((struct NS16550 *)dev, c);
    315 }
    316 
    317 int
    318 siocnscan(dev)
    319 	void *dev;
    320 {
    321 
    322 	return (NS16550_scankbd((struct NS16550 *)dev));
    323 }
    324 #endif /* CONS_SERIAL */
    325