1 1.3 rmind /* $NetBSD: cons.c,v 1.3 2011/02/08 20:20:23 rmind Exp $ */ 2 1.1 garbled 3 1.1 garbled /* 4 1.3 rmind * Copyright (c) 1988 University of Utah. 5 1.1 garbled * Copyright (c) 1990, 1993 6 1.1 garbled * The Regents of the University of California. All rights reserved. 7 1.1 garbled * 8 1.1 garbled * This code is derived from software contributed to Berkeley by 9 1.1 garbled * the Systems Programming Group of the University of Utah Computer 10 1.1 garbled * Science Department. 11 1.1 garbled * 12 1.1 garbled * Redistribution and use in source and binary forms, with or without 13 1.1 garbled * modification, are permitted provided that the following conditions 14 1.1 garbled * are met: 15 1.1 garbled * 1. Redistributions of source code must retain the above copyright 16 1.1 garbled * notice, this list of conditions and the following disclaimer. 17 1.1 garbled * 2. Redistributions in binary form must reproduce the above copyright 18 1.1 garbled * notice, this list of conditions and the following disclaimer in the 19 1.1 garbled * documentation and/or other materials provided with the distribution. 20 1.1 garbled * 3. Neither the name of the University nor the names of its contributors 21 1.1 garbled * may be used to endorse or promote products derived from this software 22 1.1 garbled * without specific prior written permission. 23 1.1 garbled * 24 1.1 garbled * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 1.1 garbled * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 1.1 garbled * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 1.1 garbled * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 1.1 garbled * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 1.1 garbled * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 1.1 garbled * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 1.1 garbled * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 1.1 garbled * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 1.1 garbled * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 1.1 garbled * SUCH DAMAGE. 35 1.1 garbled * 36 1.1 garbled * from: Utah Hdr: cons.c 1.7 92/02/28 37 1.1 garbled * 38 1.1 garbled * @(#)cons.c 8.1 (Berkeley) 6/10/93 39 1.1 garbled */ 40 1.1 garbled 41 1.1 garbled #include <lib/libsa/stand.h> 42 1.1 garbled 43 1.1 garbled #include "boot.h" 44 1.1 garbled #include "cons.h" 45 1.1 garbled 46 1.1 garbled #ifdef CONS_SERIAL 47 1.1 garbled void siocnprobe(struct consdev *); 48 1.1 garbled void siocninit(struct consdev *); 49 1.1 garbled void siocnputchar(void *, int); 50 1.1 garbled int siocngetchar(void *); 51 1.1 garbled int siocnscan(void *); 52 1.1 garbled # include "ns16550.h" 53 1.1 garbled # ifndef COMPORT 54 1.1 garbled # define COMPORT COM1 55 1.1 garbled # endif 56 1.1 garbled # ifndef COMSPEED 57 1.1 garbled # define COMSPEED 9600 58 1.1 garbled # endif 59 1.1 garbled #endif 60 1.1 garbled 61 1.1 garbled struct consdev constab[] = { 62 1.1 garbled #ifdef CONS_SERIAL 63 1.1 garbled { "com", COMPORT, COMSPEED, 64 1.1 garbled siocnprobe, siocninit, siocngetchar, siocnputchar, siocnscan }, 65 1.1 garbled #endif 66 1.1 garbled { 0 } 67 1.1 garbled }; 68 1.1 garbled 69 1.1 garbled struct consdev *cn_tab; 70 1.1 garbled 71 1.1 garbled char * 72 1.1 garbled cninit(int *addr, int *speed) 73 1.1 garbled { 74 1.1 garbled register struct consdev *cp; 75 1.1 garbled 76 1.1 garbled cn_tab = NULL; 77 1.1 garbled for (cp = constab; cp->cn_probe; cp++) { 78 1.1 garbled (*cp->cn_probe)(cp); 79 1.1 garbled if (cp->cn_pri > CN_DEAD && 80 1.1 garbled (cn_tab == NULL || cp->cn_pri > cn_tab->cn_pri)) 81 1.1 garbled cn_tab = cp; 82 1.1 garbled } 83 1.1 garbled if (cn_tab) { 84 1.1 garbled (*cn_tab->cn_init)(cn_tab); 85 1.1 garbled *addr = cn_tab->address; 86 1.1 garbled *speed = cn_tab->speed; 87 1.1 garbled return (cn_tab->cn_name); 88 1.1 garbled } 89 1.1 garbled 90 1.1 garbled return (NULL); 91 1.1 garbled } 92 1.1 garbled 93 1.1 garbled int 94 1.1 garbled cngetc(void) 95 1.1 garbled { 96 1.1 garbled 97 1.1 garbled if (cn_tab) 98 1.1 garbled return ((*cn_tab->cn_getc)(cn_tab->cn_dev)); 99 1.1 garbled return (0); 100 1.1 garbled } 101 1.1 garbled 102 1.1 garbled void 103 1.1 garbled cnputc(int c) 104 1.1 garbled { 105 1.1 garbled 106 1.1 garbled if (cn_tab) 107 1.1 garbled (*cn_tab->cn_putc)(cn_tab->cn_dev, c); 108 1.1 garbled } 109 1.1 garbled 110 1.1 garbled int 111 1.1 garbled cnscan(void) 112 1.1 garbled { 113 1.1 garbled 114 1.1 garbled if (cn_tab) 115 1.1 garbled return ((*cn_tab->cn_scan)(cn_tab->cn_dev)); 116 1.2 tsutsui return -1; 117 1.1 garbled } 118 1.1 garbled 119 1.1 garbled #ifdef CONS_SERIAL 120 1.1 garbled /* 121 1.1 garbled * serial console 122 1.1 garbled */ 123 1.1 garbled void 124 1.1 garbled siocnprobe(struct consdev *cp) 125 1.1 garbled { 126 1.1 garbled 127 1.1 garbled cp->cn_pri = CN_REMOTE; 128 1.1 garbled } 129 1.1 garbled 130 1.1 garbled void 131 1.1 garbled siocninit(struct consdev *cp) 132 1.1 garbled { 133 1.1 garbled 134 1.1 garbled cp->cn_dev = (void *)NS16550_init(cp->address, cp->speed); 135 1.1 garbled } 136 1.1 garbled 137 1.1 garbled int 138 1.1 garbled siocngetchar(void *dev) 139 1.1 garbled { 140 1.1 garbled 141 1.1 garbled return (NS16550_getc((struct NS16550 *)dev)); 142 1.1 garbled } 143 1.1 garbled 144 1.1 garbled void 145 1.1 garbled siocnputchar(void *dev, register int c) 146 1.1 garbled { 147 1.1 garbled 148 1.1 garbled if (c == '\n') 149 1.1 garbled NS16550_putc((struct NS16550 *)dev, '\r'); 150 1.1 garbled NS16550_putc((struct NS16550 *)dev, c); 151 1.1 garbled } 152 1.1 garbled 153 1.1 garbled int 154 1.1 garbled siocnscan(void *dev) 155 1.1 garbled { 156 1.1 garbled 157 1.1 garbled return (NS16550_scankbd((struct NS16550 *)dev)); 158 1.1 garbled } 159 1.1 garbled #endif /* CONS_SERIAL */ 160