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