Home | History | Annotate | Line # | Download | only in x86
consinit.c revision 1.3.2.4
      1 /*	$NetBSD: consinit.c,v 1.3.2.4 2004/09/21 13:24:45 skrll 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.3.2.4 2004/09/21 13:24:45 skrll 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 "vga.h"
     42 #include "ega.h"
     43 #include "pcdisplay.h"
     44 #if (NVGA > 0) || (NEGA > 0) || (NPCDISPLAY > 0)
     45 #include <dev/ic/mc6845reg.h>
     46 #include <dev/ic/pcdisplayvar.h>
     47 #if (NVGA > 0)
     48 #include <dev/ic/vgareg.h>
     49 #include <dev/ic/vgavar.h>
     50 #endif
     51 #if (NEGA > 0)
     52 #include <dev/isa/egavar.h>
     53 #endif
     54 #if (NPCDISPLAY > 0)
     55 #include <dev/isa/pcdisplayvar.h>
     56 #endif
     57 #endif
     58 
     59 #include "pckbc.h"
     60 #if (NPCKBC > 0)
     61 #include <dev/isa/isareg.h>
     62 #include <dev/ic/i8042reg.h>
     63 #include <dev/ic/pckbcvar.h>
     64 #endif
     65 #include "pckbd.h" /* for pckbc_machdep_cnattach */
     66 
     67 #ifndef __x86_64__
     68 #include "pc.h"
     69 #endif
     70 #if (NPC > 0)
     71 #include <machine/pccons.h>
     72 #endif
     73 
     74 #include "opt_xen.h"
     75 #if (XEN > 0)
     76 #include "vga_xen.h"
     77 #include "xenkbc.h"
     78 #include <machine/xen.h>
     79 #include <dev/pckbport/pckbportvar.h>
     80 #include <machine/xenkbcvar.h>
     81 #include <machine/vga_xenvar.h>
     82 #include <machine/hypervisor.h>
     83 #endif
     84 
     85 #include "com.h"
     86 #if (NCOM > 0)
     87 #include <sys/termios.h>
     88 #include <dev/ic/comreg.h>
     89 #include <dev/ic/comvar.h>
     90 #endif
     91 
     92 #include "ukbd.h"
     93 #if (NUKBD > 0)
     94 #include <dev/usb/ukbdvar.h>
     95 #endif
     96 
     97 #ifndef CONSDEVNAME
     98 #define CONSDEVNAME "pc"
     99 #endif
    100 
    101 #if (NCOM > 0)
    102 #ifndef CONADDR
    103 #define CONADDR 0x3f8
    104 #endif
    105 #ifndef CONSPEED
    106 #define CONSPEED TTYDEF_SPEED
    107 #endif
    108 #ifndef CONMODE
    109 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    110 #endif
    111 int comcnmode = CONMODE;
    112 #endif /* NCOM */
    113 
    114 const struct btinfo_console default_consinfo = {
    115 	{0, 0},
    116 	CONSDEVNAME,
    117 #if (NCOM > 0)
    118 	CONADDR, CONSPEED
    119 #else
    120 	0, 0
    121 #endif
    122 };
    123 
    124 #ifdef KGDB
    125 #ifndef KGDB_DEVNAME
    126 #define KGDB_DEVNAME "com"
    127 #endif
    128 const char kgdb_devname[] = KGDB_DEVNAME;
    129 
    130 #if (NCOM > 0)
    131 #ifndef KGDB_DEVADDR
    132 #define KGDB_DEVADDR 0x3f8
    133 #endif
    134 int comkgdbaddr = KGDB_DEVADDR;
    135 #ifndef KGDB_DEVRATE
    136 #define KGDB_DEVRATE TTYDEF_SPEED
    137 #endif
    138 int comkgdbrate = KGDB_DEVRATE;
    139 #ifndef KGDB_DEVMODE
    140 #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    141 #endif
    142 int comkgdbmode = KGDB_DEVMODE;
    143 #endif /* NCOM */
    144 
    145 #endif /* KGDB */
    146 
    147 /*
    148  * consinit:
    149  * initialize the system console.
    150  * XXX - shouldn't deal with this initted thing, but then,
    151  * it shouldn't be called from init386 either.
    152  */
    153 void
    154 consinit()
    155 {
    156 	const struct btinfo_console *consinfo;
    157 	static int initted;
    158 
    159 	if (initted)
    160 		return;
    161 	initted = 1;
    162 
    163 #if (XEN > 0)
    164 #if (NVGA_XEN > 0) && (NXENKBC > 0)
    165 #ifndef CONS_OVERRIDE
    166 	if (xen_start_info.flags & SIF_CONSOLE) {
    167 		union xen_cmdline_parseinfo xcp;
    168 
    169 		xen_parse_cmdline(XEN_PARSE_CONSOLE, &xcp);
    170 		if (strcmp(xcp.xcp_console, "xencons") == 0) {
    171 			xenconscn_attach();
    172 			return;
    173 		}
    174 	}
    175 #endif
    176 	if ((xen_start_info.flags & SIF_CONSOLE) &&
    177 	    strcmp(default_consinfo.devname, "xencons") != 0) {
    178 		if ((xen_start_info.flags & SIF_PRIVILEGED) == 0)
    179 			panic("Console access without privileged status");
    180 
    181 		vga_xen_cnattach(X86_BUS_SPACE_IO, X86_BUS_SPACE_MEM);
    182 		xenkbc_cnattach(PCKBPORT_KBD_SLOT);
    183 		return;
    184 	}
    185 #endif
    186 	xenconscn_attach();
    187 	return;
    188 #endif
    189 
    190 #ifndef CONS_OVERRIDE
    191 	consinfo = lookup_bootinfo(BTINFO_CONSOLE);
    192 	if (!consinfo)
    193 #endif
    194 		consinfo = &default_consinfo;
    195 
    196 #if (NPC > 0) || (NVGA > 0) || (NEGA > 0) || (NPCDISPLAY > 0)
    197 	if (!strcmp(consinfo->devname, "pc")) {
    198 #if (NVGA > 0)
    199 		if (!vga_cnattach(X86_BUS_SPACE_IO, X86_BUS_SPACE_MEM,
    200 				  -1, 1))
    201 			goto dokbd;
    202 #endif
    203 #if (NEGA > 0)
    204 		if (!ega_cnattach(X86_BUS_SPACE_IO, X86_BUS_SPACE_MEM))
    205 			goto dokbd;
    206 #endif
    207 #if (NPCDISPLAY > 0)
    208 		if (!pcdisplay_cnattach(X86_BUS_SPACE_IO, X86_BUS_SPACE_MEM))
    209 			goto dokbd;
    210 #endif
    211 #if (NPC > 0)
    212 		pccnattach();
    213 #endif
    214 		if (0) goto dokbd; /* XXX stupid gcc */
    215 dokbd:
    216 #if (NPCKBC > 0)
    217 		pckbc_cnattach(X86_BUS_SPACE_IO, IO_KBD, KBCMDP,
    218 		    PCKBC_KBD_SLOT);
    219 #endif
    220 #if NPCKBC == 0 && NUKBD > 0
    221 		ukbd_cnattach();
    222 #endif
    223 		return;
    224 	}
    225 #endif /* PC | VT | VGA | PCDISPLAY */
    226 #if (NCOM > 0)
    227 	if (!strcmp(consinfo->devname, "com")) {
    228 		bus_space_tag_t tag = X86_BUS_SPACE_IO;
    229 
    230 		if (comcnattach(tag, consinfo->addr, consinfo->speed,
    231 				COM_FREQ, COM_TYPE_NORMAL, comcnmode))
    232 			panic("can't init serial console @%x", consinfo->addr);
    233 
    234 		return;
    235 	}
    236 #endif
    237 	panic("invalid console device %s", consinfo->devname);
    238 }
    239 
    240 #if (NPCKBC > 0) && (NPCKBD == 0)
    241 /*
    242  * glue code to support old console code with the
    243  * mi keyboard controller driver
    244  */
    245 int
    246 pckbport_machdep_cnattach(kbctag, kbcslot)
    247 	pckbport_tag_t kbctag;
    248 	pckbport_slot_t kbcslot;
    249 {
    250 #if (NPC > 0) && (NPCCONSKBD > 0)
    251 	return (pcconskbd_cnattach(kbctag, kbcslot));
    252 #else
    253 	return (ENXIO);
    254 #endif
    255 }
    256 #endif
    257 
    258 #ifdef KGDB
    259 void
    260 kgdb_port_init()
    261 {
    262 #if (NCOM > 0)
    263 	if(!strcmp(kgdb_devname, "com")) {
    264 		bus_space_tag_t tag = X86_BUS_SPACE_IO;
    265 
    266 		com_kgdb_attach(tag, comkgdbaddr, comkgdbrate, COM_FREQ,
    267 		    COM_TYPE_NORMAL, comkgdbmode);
    268 	}
    269 #endif
    270 }
    271 #endif
    272