1 /* $NetBSD: consinit.c,v 1.21 2010/04/28 19:17:04 dyoung Exp $ */ 2 3 /* 4 * Copyright (c) 1998 5 * Matthias Drochner. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 * 27 */ 28 29 #include <sys/cdefs.h> 30 __KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.21 2010/04/28 19:17:04 dyoung Exp $"); 31 32 #include "opt_kgdb.h" 33 34 #include <sys/param.h> 35 #include <sys/systm.h> 36 #include <sys/device.h> 37 #include <machine/bus.h> 38 #include <machine/bootinfo.h> 39 #include <arch/x86/include/genfb_machdep.h> 40 41 #include "genfb.h" 42 #include "vga.h" 43 #include "ega.h" 44 #include "pcdisplay.h" 45 #if (NVGA > 0) || (NEGA > 0) || (NPCDISPLAY > 0) 46 #include <dev/ic/mc6845reg.h> 47 #include <dev/ic/pcdisplayvar.h> 48 #if (NVGA > 0) 49 #include <dev/ic/vgareg.h> 50 #include <dev/ic/vgavar.h> 51 #endif 52 #if (NEGA > 0) 53 #include <dev/isa/egavar.h> 54 #endif 55 #if (NPCDISPLAY > 0) 56 #include <dev/isa/pcdisplayvar.h> 57 #endif 58 #endif 59 60 #include "pckbc.h" 61 #if (NPCKBC > 0) 62 #include <dev/isa/isareg.h> 63 #include <dev/ic/i8042reg.h> 64 #include <dev/ic/pckbcvar.h> 65 #include <dev/pckbport/pckbportvar.h> 66 #endif 67 #include "pckbd.h" /* for pckbc_machdep_cnattach */ 68 69 #if (NGENFB > 0) 70 #include <dev/wsfb/genfbvar.h> 71 #endif 72 73 #ifdef __i386__ 74 #include "xboxfb.h" 75 #if (NXBOXFB > 0) 76 #include <machine/xbox.h> 77 #endif 78 #endif 79 80 #include "com.h" 81 #if (NCOM > 0) 82 #include <sys/termios.h> 83 #include <dev/ic/comreg.h> 84 #include <dev/ic/comvar.h> 85 #endif 86 87 #include "ukbd.h" 88 #if (NUKBD > 0) 89 #include <dev/usb/ukbdvar.h> 90 #endif 91 92 #ifndef CONSDEVNAME 93 #define CONSDEVNAME "pc" 94 #endif 95 96 #if (NCOM > 0) 97 #ifndef CONADDR 98 #define CONADDR 0x3f8 99 #endif 100 #ifndef CONSPEED 101 #define CONSPEED TTYDEF_SPEED 102 #endif 103 #ifndef CONMODE 104 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ 105 #endif 106 int comcnmode = CONMODE; 107 #endif /* NCOM */ 108 109 const struct btinfo_console default_consinfo = { 110 {0, 0}, 111 CONSDEVNAME, 112 #if (NCOM > 0) 113 CONADDR, CONSPEED 114 #else 115 0, 0 116 #endif 117 }; 118 119 #ifdef KGDB 120 #ifndef KGDB_DEVNAME 121 #define KGDB_DEVNAME "com" 122 #endif 123 const char kgdb_devname[] = KGDB_DEVNAME; 124 125 #if (NCOM > 0) 126 #ifndef KGDB_DEVADDR 127 #define KGDB_DEVADDR 0x3f8 128 #endif 129 int comkgdbaddr = KGDB_DEVADDR; 130 #ifndef KGDB_DEVRATE 131 #define KGDB_DEVRATE TTYDEF_SPEED 132 #endif 133 int comkgdbrate = KGDB_DEVRATE; 134 #ifndef KGDB_DEVMODE 135 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ 136 #endif 137 int comkgdbmode = KGDB_DEVMODE; 138 #endif /* NCOM */ 139 140 #endif /* KGDB */ 141 142 /* 143 * consinit: 144 * initialize the system console. 145 * XXX - shouldn't deal with this initted thing, but then, 146 * it shouldn't be called from init386 either. 147 */ 148 void 149 consinit(void) 150 { 151 const struct btinfo_console *consinfo; 152 const struct btinfo_framebuffer *fbinfo; 153 static int initted; 154 155 if (initted) 156 return; 157 initted = 1; 158 159 #ifndef CONS_OVERRIDE 160 consinfo = lookup_bootinfo(BTINFO_CONSOLE); 161 if (!consinfo) 162 #endif 163 consinfo = &default_consinfo; 164 165 fbinfo = lookup_bootinfo(BTINFO_FRAMEBUFFER); 166 167 if (!strcmp(consinfo->devname, "pc")) { 168 int error; 169 #if (NGENFB > 0) 170 if (fbinfo && fbinfo->physaddr > 0) { 171 if (x86_genfb_cnattach() == -1) { 172 initted = 0; /* defer */ 173 return; 174 } 175 genfb_cnattach(); 176 goto dokbd; 177 } 178 genfb_disable(); 179 #endif 180 #if (NXBOXFB > 0) 181 switch (xboxfb_cnattach()) { 182 case 0: 183 goto dokbd; 184 case 1: 185 break; 186 case -1: 187 /* defer initialization until later */ 188 initted = 0; 189 return; 190 } 191 #endif 192 #if (NVGA > 0) 193 if (!vga_cnattach(x86_bus_space_io, x86_bus_space_mem, 194 -1, 1)) 195 goto dokbd; 196 #endif 197 #if (NEGA > 0) 198 if (!ega_cnattach(x86_bus_space_io, x86_bus_space_mem)) 199 goto dokbd; 200 #endif 201 #if (NPCDISPLAY > 0) 202 if (!pcdisplay_cnattach(x86_bus_space_io, x86_bus_space_mem)) 203 goto dokbd; 204 #endif 205 if (0) goto dokbd; /* XXX stupid gcc */ 206 dokbd: 207 error = ENODEV; 208 #if (NPCKBC > 0) 209 error = pckbc_cnattach(x86_bus_space_io, IO_KBD, KBCMDP, 210 PCKBC_KBD_SLOT); 211 #endif 212 #if (NUKBD > 0) 213 if (error) 214 error = ukbd_cnattach(); 215 #endif 216 if (error) 217 printf("WARNING: no console keyboard, error=%d\n", 218 error); 219 return; 220 } 221 #if (NCOM > 0) 222 if (!strcmp(consinfo->devname, "com")) { 223 int addr = consinfo->addr; 224 int speed = consinfo->speed; 225 226 if (addr == 0) 227 addr = CONADDR; 228 if (speed == 0) 229 speed = CONSPEED; 230 231 if (comcnattach(x86_bus_space_io, addr, speed, 232 COM_FREQ, COM_TYPE_NORMAL, comcnmode)) 233 panic("can't init serial console @%x", consinfo->addr); 234 235 return; 236 } 237 #endif 238 panic("invalid console device %s", consinfo->devname); 239 } 240 241 #ifdef KGDB 242 void 243 kgdb_port_init(void) 244 { 245 #if (NCOM > 0) 246 if(!strcmp(kgdb_devname, "com")) { 247 com_kgdb_attach(x86_bus_space_io, comkgdbaddr, comkgdbrate, 248 COM_FREQ, COM_TYPE_NORMAL, comkgdbmode); 249 } 250 #endif 251 } 252 #endif 253