1 /* $NetBSD: consinit.c,v 1.17 2023/07/22 19:13:17 mrg 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.17 2023/07/22 19:13:17 mrg 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 <sys/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 #include "opt_xen.h" 74 #if (XEN > 0) 75 #include <xen/xen.h> 76 #include <dev/pckbport/pckbportvar.h> 77 #include <xen/hypervisor.h> 78 #include "xen_def_cons.h" 79 #endif 80 81 #include "com.h" 82 #if (NCOM > 0) 83 #include <sys/termios.h> 84 #include <dev/ic/comreg.h> 85 #include <dev/ic/comvar.h> 86 #endif 87 88 #ifndef CONSDEVNAME 89 #define CONSDEVNAME "pc" 90 #endif 91 92 #if (NCOM > 0) 93 #ifndef CONADDR 94 #define CONADDR 0x3f8 95 #endif 96 #ifndef CONSPEED 97 #define CONSPEED TTYDEF_SPEED 98 #endif 99 #ifndef CONMODE 100 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ 101 #endif 102 int comcnmode = CONMODE; 103 #endif /* NCOM */ 104 105 const struct btinfo_console default_consinfo = { 106 {0, 0}, 107 CONSDEVNAME, 108 #if (NCOM > 0) 109 CONADDR, CONSPEED 110 #else 111 0, 0 112 #endif 113 }; 114 115 #ifdef KGDB 116 #ifndef KGDB_DEVNAME 117 #define KGDB_DEVNAME "com" 118 #endif 119 const char kgdb_devname[] = KGDB_DEVNAME; 120 121 #if (NCOM > 0) 122 #ifndef KGDB_DEVADDR 123 #define KGDB_DEVADDR 0x3f8 124 #endif 125 int comkgdbaddr = KGDB_DEVADDR; 126 #ifndef KGDB_DEVRATE 127 #define KGDB_DEVRATE TTYDEF_SPEED 128 #endif 129 int comkgdbrate = KGDB_DEVRATE; 130 #ifndef KGDB_DEVMODE 131 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */ 132 #endif 133 int comkgdbmode = KGDB_DEVMODE; 134 #endif /* NCOM */ 135 136 #endif /* KGDB */ 137 138 /* 139 * consinit: 140 * initialize the system console. 141 * XXX - shouldn't deal with this initted thing, but then, 142 * it shouldn't be called from init386 either. 143 */ 144 void 145 consinit(void) 146 { 147 static int initted = 0; 148 union xen_cmdline_parseinfo xcp; 149 150 if (initted) { 151 return; 152 } 153 initted = 1; 154 xen_parse_cmdline(XEN_PARSE_CONSOLE, &xcp); 155 156 #if (NVGA > 0) 157 if (xendomain_is_privileged()) { 158 #ifdef CONS_OVERRIDE 159 if (strcmp(default_consinfo.devname, "tty0") == 0 || 160 strcmp(default_consinfo.devname, "pc") == 0) { 161 #else 162 if (strcmp(xcp.xcp_console, "tty0") == 0 || /* linux name */ 163 strcmp(xcp.xcp_console, "pc") == 0) { /* NetBSD name */ 164 #endif /* CONS_OVERRIDE */ 165 int error; 166 vga_cnattach(x86_bus_space_io, x86_bus_space_mem, 167 -1, 1); 168 error = ENODEV; 169 #if (NPCKBC > 0) 170 error = pckbc_cnattach(x86_bus_space_io, IO_KBD, KBCMDP, 171 PCKBC_KBD_SLOT, 0); 172 #endif 173 #if (NUKBD > 0) 174 if (error) 175 error = ukbd_cnattach(); 176 #endif 177 if (error) 178 printf("WARNING: no console keyboard, " 179 "error=%d\n", error); 180 return; 181 } 182 } 183 #endif /* NVGA */ 184 #if NXENCONS > 0 185 xenconscn_attach(); 186 return; 187 #endif /* NXENCONS */ 188 panic("consinit: no console"); 189 } 190 191 #ifdef KGDB 192 void 193 kgdb_port_init(void) 194 { 195 #if (NCOM > 0) 196 if(!strcmp(kgdb_devname, "com")) { 197 bus_space_tag_t tag = x86_bus_space_io; 198 199 com_kgdb_attach(tag, comkgdbaddr, comkgdbrate, COM_FREQ, 200 COM_TYPE_NORMAL, comkgdbmode); 201 } 202 #endif 203 } 204 #endif 205