1/* $NetBSD: cons.c,v 1.7 2008/03/01 05:21:50 tsutsui 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. Neither the name of the University nor the names of its contributors 21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * 36 * from: Utah Hdr: cons.c 1.7 92/02/28 37 * 38 * @(#)cons.c 8.1 (Berkeley) 6/10/93 39 */ 40 41#include <lib/libsa/stand.h> 42 43#include "boot.h" 44#include "cons.h" 45 46#ifdef CONS_VGA 47void vgacnprobe(struct consdev *); 48void vgacninit(struct consdev *); 49void vgacnputchar(void *, int); 50int vgacngetchar(void *); 51int vgacnscan(void *); 52#endif 53 54#ifdef CONS_SERIAL 55void siocnprobe(struct consdev *); 56void siocninit(struct consdev *); 57void siocnputchar(void *, int); 58int siocngetchar(void *); 59int siocnscan(void *); 60# include "ns16550.h" 61# ifndef COMPORT 62# define COMPORT COM1 63# endif 64# ifndef COMSPEED 65# define COMSPEED 9600 66# endif 67#endif 68 69struct consdev constab[] = { 70#ifdef CONS_VGA 71 { "vga", 0xc0000000, 0, 72 vgacnprobe, vgacninit, vgacngetchar, vgacnputchar, vgacnscan }, 73#endif 74#ifdef CONS_SERIAL 75 { "com", COMPORT, COMSPEED, 76 siocnprobe, siocninit, siocngetchar, siocnputchar, siocnscan }, 77#endif 78 { 0 } 79}; 80 81struct consdev *cn_tab; 82 83char * 84cninit(int *addr, int *speed) 85{ 86 register struct consdev *cp; 87 88 cn_tab = NULL; 89 for (cp = constab; cp->cn_probe; cp++) { 90 (*cp->cn_probe)(cp); 91 if (cp->cn_pri > CN_DEAD && 92 (cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri)) 93 cn_tab = cp; 94 } 95 if (cn_tab) { 96 (*cn_tab->cn_init)(cn_tab); 97 *addr = cn_tab->address; 98 *speed = cn_tab->speed; 99 return (cn_tab->cn_name); 100 } 101 102 return (NULL); 103} 104 105int 106cngetc(void) 107{ 108 109 if (cn_tab) 110 return ((*cn_tab->cn_getc)(cn_tab->cn_dev)); 111 return (0); 112} 113 114void 115cnputc(int c) 116{ 117 118 if (cn_tab) 119 (*cn_tab->cn_putc)(cn_tab->cn_dev, c); 120} 121 122int 123cnscan(void) 124{ 125 126 if (cn_tab) 127 return ((*cn_tab->cn_scan)(cn_tab->cn_dev)); 128 return -1; 129} 130 131#ifdef CONS_VGA 132/* 133 * VGA console 134 */ 135void 136vgacnprobe(struct consdev *cp) 137{ 138 cp->cn_pri = CN_NORMAL; 139} 140 141void 142vgacninit(struct consdev *cp) 143{ 144 145 vga_init((u_char *)cp->address); 146 kbdreset(); 147} 148 149int 150vgacngetchar(void *dev) 151{ 152 153 return (kbd_getc()); 154} 155 156void 157vgacnputchar(void *dev, register int c) 158{ 159 160 vga_putc(c); 161} 162 163int 164vgacnscan(void *dev) 165{ 166 167 return (kbd(1)); 168} 169#endif /* CONS_VGA */ 170 171#ifdef CONS_SERIAL 172/* 173 * serial console 174 */ 175void 176siocnprobe(struct consdev *cp) 177{ 178 179 cp->cn_pri = CN_REMOTE; 180} 181 182void 183siocninit(struct consdev *cp) 184{ 185 186 cp->cn_dev = (void *)NS16550_init(cp->address, cp->speed); 187} 188 189int 190siocngetchar(void *dev) 191{ 192 193 return (NS16550_getc((struct NS16550 *)dev)); 194} 195 196void 197siocnputchar(void *dev, register int c) 198{ 199 200 if (c == '\n') 201 NS16550_putc((struct NS16550 *)dev, '\r'); 202 NS16550_putc((struct NS16550 *)dev, c); 203} 204 205int 206siocnscan(void *dev) 207{ 208 209 return (NS16550_scankbd((struct NS16550 *)dev)); 210} 211#endif /* CONS_SERIAL */ 212