1 /* $NetBSD: consinit.c,v 1.8 2007/01/29 01:52:46 hubertf Exp $ */ 2 /* NetBSD: consinit.c,v 1.4 2004/03/13 17:31:34 bjh21 Exp */ 3 4 /* 5 * Copyright (c) 1998 6 * Matthias Drochner. All rights reserved. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 * 28 */ 29 30 #include <sys/cdefs.h> 31 __KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.8 2007/01/29 01:52:46 hubertf Exp $"); 32 33 #include "opt_kgdb.h" 34 35 #include <sys/param.h> 36 #include <sys/systm.h> 37 #include <sys/device.h> 38 #include <machine/bus.h> 39 #include <machine/bootinfo.h> 40 41 #include "xencons.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 #endif 66 #include "pckbd.h" /* for pckbc_machdep_cnattach */ 67 68 #include "ukbd.h" 69 #if (NUKBD > 0) 70 #include <dev/usb/ukbdvar.h> 71 #endif 72 73 #ifndef __x86_64__ 74 #include "pc.h" 75 #endif 76 #if (NPC > 0) 77 #include <machine/pccons.h> 78 #endif 79 80 #include "opt_xen.h" 81 #if (XEN > 0) 82 #include <machine/xen.h> 83 #include <dev/pckbport/pckbportvar.h> 84 #include <machine/hypervisor.h> 85 #endif 86 87 #include "com.h" 88 #if (NCOM > 0) 89 #include <sys/termios.h> 90 #include <dev/ic/comreg.h> 91 #include <dev/ic/comvar.h> 92 #endif 93 94 #ifndef CONSDEVNAME 95 #define CONSDEVNAME "pc" 96 #endif 97 98 #if (NCOM > 0) 99 #ifndef CONADDR 100 #define CONADDR 0x3f8 101 #endif 102 #ifndef CONSPEED 103 #define CONSPEED TTYDEF_SPEED 104 #endif 105 #ifndef CONMODE 106 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ 107 #endif 108 int comcnmode = CONMODE; 109 #endif /* NCOM */ 110 111 const struct btinfo_console default_consinfo = { 112 {0, 0}, 113 CONSDEVNAME, 114 #if (NCOM > 0) 115 CONADDR, CONSPEED 116 #else 117 0, 0 118 #endif 119 }; 120 121 #ifdef KGDB 122 #ifndef KGDB_DEVNAME 123 #define KGDB_DEVNAME "com" 124 #endif 125 const char kgdb_devname[] = KGDB_DEVNAME; 126 127 #if (NCOM > 0) 128 #ifndef KGDB_DEVADDR 129 #define KGDB_DEVADDR 0x3f8 130 #endif 131 int comkgdbaddr = KGDB_DEVADDR; 132 #ifndef KGDB_DEVRATE 133 #define KGDB_DEVRATE TTYDEF_SPEED 134 #endif 135 int comkgdbrate = KGDB_DEVRATE; 136 #ifndef KGDB_DEVMODE 137 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ 138 #endif 139 int comkgdbmode = KGDB_DEVMODE; 140 #endif /* NCOM */ 141 142 #endif /* KGDB */ 143 144 /* 145 * consinit: 146 * initialize the system console. 147 * XXX - shouldn't deal with this initted thing, but then, 148 * it shouldn't be called from init386 either. 149 */ 150 void 151 consinit() 152 { 153 static int initted = 0; 154 union xen_cmdline_parseinfo xcp; 155 156 if (initted) { 157 return; 158 } 159 initted = 1; 160 xen_parse_cmdline(XEN_PARSE_CONSOLE, &xcp); 161 162 #if (NVGA > 0) 163 if (xen_start_info.flags & SIF_PRIVILEGED) { 164 #ifdef CONS_OVERRIDE 165 if (strcmp(default_consinfo.devname, "tty0") == 0 || 166 strcmp(default_consinfo.devname, "pc") == 0) { 167 #else 168 if (strcmp(xcp.xcp_console, "tty0") == 0 || /* linux name */ 169 strcmp(xcp.xcp_console, "pc") == 0) { /* NetBSD name */ 170 #endif /* CONS_OVERRIDE */ 171 int error; 172 vga_cnattach(X86_BUS_SPACE_IO, X86_BUS_SPACE_MEM, 173 -1, 1); 174 error = ENODEV; 175 #if (NPCKBC > 0) 176 error = pckbc_cnattach(X86_BUS_SPACE_IO, IO_KBD, KBCMDP, 177 PCKBC_KBD_SLOT); 178 #endif 179 #if (NUKBD > 0) 180 if (error) 181 error = ukbd_cnattach(); 182 #endif 183 if (error) 184 printf("WARNING: no console keyboard, " 185 "error=%d\n", error); 186 return; 187 } 188 } 189 #endif /* NVGA */ 190 #if NXENCONS > 0 191 xenconscn_attach(); 192 return; 193 #endif /* NXENCONS */ 194 panic("consinit: no console"); 195 } 196 197 #if (NPCKBC > 0) && (NPCKBD == 0) 198 /* 199 * glue code to support old console code with the 200 * mi keyboard controller driver 201 */ 202 int 203 pckbport_machdep_cnattach(kbctag, kbcslot) 204 pckbport_tag_t kbctag; 205 pckbport_slot_t kbcslot; 206 { 207 #if (NPC > 0) && (NPCCONSKBD > 0) 208 return (pcconskbd_cnattach(kbctag, kbcslot)); 209 #else 210 return (ENXIO); 211 #endif 212 } 213 #endif 214 215 #ifdef KGDB 216 void 217 kgdb_port_init() 218 { 219 #if (NCOM > 0) 220 if(!strcmp(kgdb_devname, "com")) { 221 bus_space_tag_t tag = X86_BUS_SPACE_IO; 222 223 com_kgdb_attach(tag, comkgdbaddr, comkgdbrate, COM_FREQ, 224 COM_TYPE_NORMAL, comkgdbmode); 225 } 226 #endif 227 } 228 #endif 229