1 /* $NetBSD: console.c,v 1.15 2009/03/18 10:22:30 cegger Exp $ */ 2 3 /*- 4 * Copyright (c) 2001, 2002 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by UCHIYAMA Yasushi. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: console.c,v 1.15 2009/03/18 10:22:30 cegger Exp $"); 34 35 #include "opt_kgdb.h" 36 #include "biconsdev.h" 37 #include "hpcfb.h" 38 #include "scif.h" 39 #include "hd64461uart.h" 40 #include "hd64465uart.h" 41 #include "hd64461video.h" 42 #include "wskbd.h" 43 #include "pfckbd.h" 44 45 #include <sys/param.h> 46 #include <sys/systm.h> 47 #include <sys/conf.h> 48 #include <dev/cons.h> /* consdev */ 49 50 #include <machine/bootinfo.h> 51 52 #include <dev/wscons/wsdisplayvar.h> 53 #include <dev/rasops/rasops.h> 54 #include <dev/hpc/bicons.h> 55 #include <dev/hpc/biconsvar.h> 56 #include <dev/hpc/hpcfbvar.h> 57 #include <sh3/dev/scifvar.h> 58 #include <hpcsh/dev/pfckbdvar.h> 59 #include <hpcsh/dev/hd64461/hd64461uartvar.h> 60 #include <hpcsh/dev/hd64465/hd64465uartvar.h> 61 62 /* Serial console */ 63 #define scifcnpollc nullcnpollc 64 cons_decl(scif); 65 #define hd64461uartcnputc comcnputc 66 #define hd64461uartcngetc comcngetc 67 #define hd64461uartcnpollc comcnpollc 68 cons_decl(hd64461uart); 69 #define hd64465uartcnputc comcnputc 70 #define hd64465uartcngetc comcngetc 71 #define hd64465uartcnpollc comcnpollc 72 cons_decl(hd64465uart); 73 74 /* Builtin video console */ 75 #if NBICONSDEV > 0 76 #define biconscnpollc nullcnpollc 77 cons_decl(bicons); 78 #endif 79 80 /* HD64461 video module */ 81 #if NHD64461VIDEO > 0 82 cons_decl(hd64461video_); 83 #if NWSKBD > 0 84 #include <dev/wscons/wskbdvar.h> 85 #define hd64461video_cngetc wskbd_cngetc 86 #else /* NWSKBD == 0 */ 87 int 88 hd64461video_cngetc(dev_t dev) 89 { 90 printf("no input method. reboot me.\n"); 91 for (;;) 92 continue; 93 /* NOTREACHED */ 94 } 95 #endif /* NWSKBD == 0 */ 96 #define hd64461video_cnputc wsdisplay_cnputc 97 #define hd64461video_cnpollc nullcnpollc 98 #endif /* NHD64461VIDEO > 0 */ 99 100 struct consdev constab[] = { 101 #if NBICONSDEV > 0 102 cons_init(bicons), 103 #endif 104 #if NHD64461VIDEO > 0 105 cons_init(hd64461video_), 106 #endif 107 #if NSCIF > 0 108 cons_init(scif), 109 #endif 110 #if NHD64461UART > 0 111 cons_init(hd64461uart), 112 #endif 113 #if NHD64465UART > 0 114 cons_init(hd64465uart), 115 #endif 116 { NULL } /* terminator */ 117 }; 118 119 #define CN_ENABLE(x) set_console(x ## cninit, x ## cnprobe) 120 121 static int initialized; 122 static int attach_kbd __attribute__((__unused__)) = 0; 123 static void set_console(void (*)(struct consdev *), void (*)(struct consdev *)); 124 static void disable_console(void); 125 static void cn_nonprobe(struct consdev *); 126 #if NBICONSDEV > 0 127 static void enable_bicons(void); 128 #endif 129 130 void 131 consinit(void) 132 { 133 if (initialized) 134 return; 135 136 /* select console */ 137 disable_console(); 138 139 switch (bootinfo->bi_cnuse) { 140 case BI_CNUSE_BUILTIN: 141 #if NBICONSDEV > 0 142 enable_bicons(); 143 #endif 144 break; 145 case BI_CNUSE_HD64461VIDEO: 146 #if NHD64461VIDEO > 0 147 CN_ENABLE(hd64461video_); 148 attach_kbd = 1; 149 #endif 150 break; 151 case BI_CNUSE_SCIF: 152 #if NSCIF > 0 153 CN_ENABLE(scif); 154 #endif 155 break; 156 case BI_CNUSE_HD64461COM: 157 #if NHD64461UART > 0 158 CN_ENABLE(hd64461uart); 159 #endif 160 break; 161 case BI_CNUSE_HD64465COM: 162 #if NHD64465UART > 0 163 CN_ENABLE(hd64465uart); 164 #endif 165 break; 166 } 167 168 #if NBICONSDEV > 0 169 if (!initialized) { /* use builtin console instead */ 170 enable_bicons(); 171 } 172 #endif 173 174 if (initialized) { 175 cninit(); 176 } 177 178 #if NPFCKBD > 0 179 if (attach_kbd) 180 pfckbd_cnattach(); 181 #endif 182 183 #if NHPCFB > 0 && NBICONSDEV > 0 184 if (cn_tab->cn_putc == biconscnputc) 185 hpcfb_cnattach(0); 186 #endif 187 188 #ifdef KGDB 189 #if NSCIF > 0 190 scif_kgdb_init(); 191 #endif 192 #if NHD64461UART > 0 193 hd64461uart_kgdb_init(); 194 #endif 195 #if NHD64465UART > 0 196 hd64465uart_kgdb_init(); 197 #endif 198 #endif /* KGDB */ 199 } 200 201 static void 202 set_console(void (*init_func)(struct consdev *), 203 void (*probe_func)(struct consdev *)) 204 { 205 struct consdev *cp; 206 207 for (cp = constab; cp->cn_probe; cp++) { 208 if (cp->cn_init == init_func) { 209 cp->cn_probe = probe_func; 210 initialized = 1; 211 break; 212 } 213 } 214 } 215 216 static void 217 disable_console(void) 218 { 219 struct consdev *cp; 220 221 for (cp = constab; cp->cn_probe; cp++) 222 cp->cn_probe = cn_nonprobe; 223 } 224 225 static void 226 cn_nonprobe(struct consdev *cp) 227 { 228 229 cp->cn_pri = CN_DEAD; 230 } 231 232 #if NBICONSDEV > 0 233 static void 234 enable_bicons(void) 235 { 236 237 bootinfo->bi_cnuse = BI_CNUSE_BUILTIN; 238 bicons_set_priority(CN_INTERNAL); 239 CN_ENABLE(bicons); 240 attach_kbd = 1; 241 } 242 #endif /* NBICONSDEV > 0 */ 243