Home | History | Annotate | Line # | Download | only in x86
consinit.c revision 1.4
      1 /*	$NetBSD: consinit.c,v 1.4 2005/03/09 22:39:21 bouyer 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.4 2005/03/09 22:39:21 bouyer 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 #ifndef __x86_64__
     69 #include "pc.h"
     70 #endif
     71 #if (NPC > 0)
     72 #include <machine/pccons.h>
     73 #endif
     74 
     75 #include "opt_xen.h"
     76 #if (XEN > 0)
     77 #include <machine/xen.h>
     78 #include <dev/pckbport/pckbportvar.h>
     79 #include <machine/hypervisor.h>
     80 #endif
     81 
     82 #include "com.h"
     83 #if (NCOM > 0)
     84 #include <sys/termios.h>
     85 #include <dev/ic/comreg.h>
     86 #include <dev/ic/comvar.h>
     87 #endif
     88 
     89 #include "ukbd.h"
     90 #if (NUKBD > 0)
     91 #include <dev/usb/ukbdvar.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 			vga_cnattach(X86_BUS_SPACE_IO, X86_BUS_SPACE_MEM,
    172 			    -1, 1);
    173 			pckbc_cnattach(X86_BUS_SPACE_IO, IO_KBD, KBCMDP,
    174 			    PCKBC_KBD_SLOT);
    175 			return;
    176 		}
    177 	}
    178 #endif /* NVGA */
    179 #if NXENCONS > 0
    180 	xenconscn_attach();
    181 	return;
    182 #endif /* NXENCONS */
    183 	panic("consinit: no console");
    184 }
    185 
    186 #if (NPCKBC > 0) && (NPCKBD == 0)
    187 /*
    188  * glue code to support old console code with the
    189  * mi keyboard controller driver
    190  */
    191 int
    192 pckbport_machdep_cnattach(kbctag, kbcslot)
    193 	pckbport_tag_t kbctag;
    194 	pckbport_slot_t kbcslot;
    195 {
    196 #if (NPC > 0) && (NPCCONSKBD > 0)
    197 	return (pcconskbd_cnattach(kbctag, kbcslot));
    198 #else
    199 	return (ENXIO);
    200 #endif
    201 }
    202 #endif
    203 
    204 #ifdef KGDB
    205 void
    206 kgdb_port_init()
    207 {
    208 #if (NCOM > 0)
    209 	if(!strcmp(kgdb_devname, "com")) {
    210 		bus_space_tag_t tag = X86_BUS_SPACE_IO;
    211 
    212 		com_kgdb_attach(tag, comkgdbaddr, comkgdbrate, COM_FREQ,
    213 		    COM_TYPE_NORMAL, comkgdbmode);
    214 	}
    215 #endif
    216 }
    217 #endif
    218