Home | History | Annotate | Line # | Download | only in x86
consinit.c revision 1.3.2.3
      1  1.3.2.3  skrll /*	$NetBSD: consinit.c,v 1.3.2.3 2004/09/18 14:42:53 skrll Exp $	*/
      2  1.3.2.2  skrll /*	NetBSD: consinit.c,v 1.4 2004/03/13 17:31:34 bjh21 Exp 	*/
      3  1.3.2.2  skrll 
      4  1.3.2.2  skrll /*
      5  1.3.2.2  skrll  * Copyright (c) 1998
      6  1.3.2.2  skrll  *	Matthias Drochner.  All rights reserved.
      7  1.3.2.2  skrll  *
      8  1.3.2.2  skrll  * Redistribution and use in source and binary forms, with or without
      9  1.3.2.2  skrll  * modification, are permitted provided that the following conditions
     10  1.3.2.2  skrll  * are met:
     11  1.3.2.2  skrll  * 1. Redistributions of source code must retain the above copyright
     12  1.3.2.2  skrll  *    notice, this list of conditions and the following disclaimer.
     13  1.3.2.2  skrll  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.3.2.2  skrll  *    notice, this list of conditions and the following disclaimer in the
     15  1.3.2.2  skrll  *    documentation and/or other materials provided with the distribution.
     16  1.3.2.2  skrll  *
     17  1.3.2.2  skrll  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18  1.3.2.2  skrll  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19  1.3.2.2  skrll  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  1.3.2.2  skrll  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21  1.3.2.2  skrll  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22  1.3.2.2  skrll  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23  1.3.2.2  skrll  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  1.3.2.2  skrll  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25  1.3.2.2  skrll  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     26  1.3.2.2  skrll  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  1.3.2.2  skrll  *
     28  1.3.2.2  skrll  */
     29  1.3.2.2  skrll 
     30  1.3.2.2  skrll #include <sys/cdefs.h>
     31  1.3.2.3  skrll __KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.3.2.3 2004/09/18 14:42:53 skrll Exp $");
     32  1.3.2.2  skrll 
     33  1.3.2.2  skrll #include "opt_kgdb.h"
     34  1.3.2.2  skrll 
     35  1.3.2.2  skrll #include <sys/param.h>
     36  1.3.2.2  skrll #include <sys/systm.h>
     37  1.3.2.2  skrll #include <sys/device.h>
     38  1.3.2.2  skrll #include <machine/bus.h>
     39  1.3.2.2  skrll #include <machine/bootinfo.h>
     40  1.3.2.2  skrll 
     41  1.3.2.2  skrll #include "vga.h"
     42  1.3.2.2  skrll #include "ega.h"
     43  1.3.2.2  skrll #include "pcdisplay.h"
     44  1.3.2.2  skrll #if (NVGA > 0) || (NEGA > 0) || (NPCDISPLAY > 0)
     45  1.3.2.2  skrll #include <dev/ic/mc6845reg.h>
     46  1.3.2.2  skrll #include <dev/ic/pcdisplayvar.h>
     47  1.3.2.2  skrll #if (NVGA > 0)
     48  1.3.2.2  skrll #include <dev/ic/vgareg.h>
     49  1.3.2.2  skrll #include <dev/ic/vgavar.h>
     50  1.3.2.2  skrll #endif
     51  1.3.2.2  skrll #if (NEGA > 0)
     52  1.3.2.2  skrll #include <dev/isa/egavar.h>
     53  1.3.2.2  skrll #endif
     54  1.3.2.2  skrll #if (NPCDISPLAY > 0)
     55  1.3.2.2  skrll #include <dev/isa/pcdisplayvar.h>
     56  1.3.2.2  skrll #endif
     57  1.3.2.2  skrll #endif
     58  1.3.2.2  skrll 
     59  1.3.2.2  skrll #include "pckbc.h"
     60  1.3.2.2  skrll #if (NPCKBC > 0)
     61  1.3.2.2  skrll #include <dev/isa/isareg.h>
     62  1.3.2.2  skrll #include <dev/ic/i8042reg.h>
     63  1.3.2.2  skrll #include <dev/ic/pckbcvar.h>
     64  1.3.2.2  skrll #endif
     65  1.3.2.2  skrll #include "pckbd.h" /* for pckbc_machdep_cnattach */
     66  1.3.2.2  skrll 
     67  1.3.2.2  skrll #ifndef __x86_64__
     68  1.3.2.2  skrll #include "pc.h"
     69  1.3.2.2  skrll #endif
     70  1.3.2.2  skrll #if (NPC > 0)
     71  1.3.2.2  skrll #include <machine/pccons.h>
     72  1.3.2.2  skrll #endif
     73  1.3.2.2  skrll 
     74  1.3.2.2  skrll #include "opt_xen.h"
     75  1.3.2.2  skrll #if (XEN > 0)
     76  1.3.2.2  skrll #include "vga_xen.h"
     77  1.3.2.2  skrll #include "xenkbc.h"
     78  1.3.2.2  skrll #include <machine/xen.h>
     79  1.3.2.2  skrll #include <dev/pckbport/pckbportvar.h>
     80  1.3.2.2  skrll #include <machine/xenkbcvar.h>
     81  1.3.2.2  skrll #include <machine/vga_xenvar.h>
     82  1.3.2.2  skrll #include <machine/hypervisor.h>
     83  1.3.2.2  skrll #endif
     84  1.3.2.2  skrll 
     85  1.3.2.2  skrll #include "com.h"
     86  1.3.2.2  skrll #if (NCOM > 0)
     87  1.3.2.2  skrll #include <sys/termios.h>
     88  1.3.2.2  skrll #include <dev/ic/comreg.h>
     89  1.3.2.2  skrll #include <dev/ic/comvar.h>
     90  1.3.2.2  skrll #endif
     91  1.3.2.2  skrll 
     92  1.3.2.2  skrll #include "ukbd.h"
     93  1.3.2.2  skrll #if (NUKBD > 0)
     94  1.3.2.2  skrll #include <dev/usb/ukbdvar.h>
     95  1.3.2.2  skrll #endif
     96  1.3.2.2  skrll 
     97  1.3.2.2  skrll #ifndef CONSDEVNAME
     98  1.3.2.2  skrll #define CONSDEVNAME "pc"
     99  1.3.2.2  skrll #endif
    100  1.3.2.2  skrll 
    101  1.3.2.2  skrll #if (NCOM > 0)
    102  1.3.2.2  skrll #ifndef CONADDR
    103  1.3.2.2  skrll #define CONADDR 0x3f8
    104  1.3.2.2  skrll #endif
    105  1.3.2.2  skrll #ifndef CONSPEED
    106  1.3.2.2  skrll #define CONSPEED TTYDEF_SPEED
    107  1.3.2.2  skrll #endif
    108  1.3.2.2  skrll #ifndef CONMODE
    109  1.3.2.2  skrll #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    110  1.3.2.2  skrll #endif
    111  1.3.2.2  skrll int comcnmode = CONMODE;
    112  1.3.2.2  skrll #endif /* NCOM */
    113  1.3.2.2  skrll 
    114  1.3.2.2  skrll const struct btinfo_console default_consinfo = {
    115  1.3.2.2  skrll 	{0, 0},
    116  1.3.2.2  skrll 	CONSDEVNAME,
    117  1.3.2.2  skrll #if (NCOM > 0)
    118  1.3.2.2  skrll 	CONADDR, CONSPEED
    119  1.3.2.2  skrll #else
    120  1.3.2.2  skrll 	0, 0
    121  1.3.2.2  skrll #endif
    122  1.3.2.2  skrll };
    123  1.3.2.2  skrll 
    124  1.3.2.2  skrll #ifdef KGDB
    125  1.3.2.2  skrll #ifndef KGDB_DEVNAME
    126  1.3.2.2  skrll #define KGDB_DEVNAME "com"
    127  1.3.2.2  skrll #endif
    128  1.3.2.2  skrll const char kgdb_devname[] = KGDB_DEVNAME;
    129  1.3.2.2  skrll 
    130  1.3.2.2  skrll #if (NCOM > 0)
    131  1.3.2.2  skrll #ifndef KGDB_DEVADDR
    132  1.3.2.2  skrll #define KGDB_DEVADDR 0x3f8
    133  1.3.2.2  skrll #endif
    134  1.3.2.2  skrll int comkgdbaddr = KGDB_DEVADDR;
    135  1.3.2.2  skrll #ifndef KGDB_DEVRATE
    136  1.3.2.2  skrll #define KGDB_DEVRATE TTYDEF_SPEED
    137  1.3.2.2  skrll #endif
    138  1.3.2.2  skrll int comkgdbrate = KGDB_DEVRATE;
    139  1.3.2.2  skrll #ifndef KGDB_DEVMODE
    140  1.3.2.2  skrll #define KGDB_DEVMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
    141  1.3.2.2  skrll #endif
    142  1.3.2.2  skrll int comkgdbmode = KGDB_DEVMODE;
    143  1.3.2.2  skrll #endif /* NCOM */
    144  1.3.2.2  skrll 
    145  1.3.2.2  skrll #endif /* KGDB */
    146  1.3.2.2  skrll 
    147  1.3.2.2  skrll /*
    148  1.3.2.2  skrll  * consinit:
    149  1.3.2.2  skrll  * initialize the system console.
    150  1.3.2.2  skrll  * XXX - shouldn't deal with this initted thing, but then,
    151  1.3.2.2  skrll  * it shouldn't be called from init386 either.
    152  1.3.2.2  skrll  */
    153  1.3.2.2  skrll void
    154  1.3.2.2  skrll consinit()
    155  1.3.2.2  skrll {
    156  1.3.2.2  skrll 	const struct btinfo_console *consinfo;
    157  1.3.2.2  skrll 	static int initted;
    158  1.3.2.2  skrll 
    159  1.3.2.2  skrll 	if (initted)
    160  1.3.2.2  skrll 		return;
    161  1.3.2.2  skrll 	initted = 1;
    162  1.3.2.2  skrll 
    163  1.3.2.2  skrll #if (XEN > 0)
    164  1.3.2.2  skrll #if (NVGA_XEN > 0) && (NXENKBC > 0)
    165  1.3.2.2  skrll #ifndef CONS_OVERRIDE
    166  1.3.2.2  skrll 	if (xen_start_info.flags & SIF_CONSOLE) {
    167  1.3.2.2  skrll 		union xen_cmdline_parseinfo xcp;
    168  1.3.2.2  skrll 
    169  1.3.2.2  skrll 		xen_parse_cmdline(XEN_PARSE_CONSOLE, &xcp);
    170  1.3.2.2  skrll 		if (strcmp(xcp.xcp_console, "xencons") == 0) {
    171  1.3.2.2  skrll 			xenconscn_attach();
    172  1.3.2.2  skrll 			return;
    173  1.3.2.2  skrll 		}
    174  1.3.2.2  skrll 	}
    175  1.3.2.2  skrll #endif
    176  1.3.2.2  skrll 	if ((xen_start_info.flags & SIF_CONSOLE) &&
    177  1.3.2.2  skrll 	    strcmp(default_consinfo.devname, "xencons") != 0) {
    178  1.3.2.2  skrll 		if ((xen_start_info.flags & SIF_PRIVILEGED) == 0)
    179  1.3.2.2  skrll 			panic("Console access without privileged status");
    180  1.3.2.2  skrll 
    181  1.3.2.2  skrll 		vga_xen_cnattach(X86_BUS_SPACE_IO, X86_BUS_SPACE_MEM);
    182  1.3.2.2  skrll 		xenkbc_cnattach(PCKBPORT_KBD_SLOT);
    183  1.3.2.2  skrll 		return;
    184  1.3.2.2  skrll 	}
    185  1.3.2.2  skrll #endif
    186  1.3.2.2  skrll 	xenconscn_attach();
    187  1.3.2.2  skrll 	return;
    188  1.3.2.2  skrll #endif
    189  1.3.2.2  skrll 
    190  1.3.2.2  skrll #ifndef CONS_OVERRIDE
    191  1.3.2.2  skrll 	consinfo = lookup_bootinfo(BTINFO_CONSOLE);
    192  1.3.2.2  skrll 	if (!consinfo)
    193  1.3.2.2  skrll #endif
    194  1.3.2.2  skrll 		consinfo = &default_consinfo;
    195  1.3.2.2  skrll 
    196  1.3.2.2  skrll #if (NPC > 0) || (NVGA > 0) || (NEGA > 0) || (NPCDISPLAY > 0)
    197  1.3.2.2  skrll 	if (!strcmp(consinfo->devname, "pc")) {
    198  1.3.2.2  skrll #if (NVGA > 0)
    199  1.3.2.2  skrll 		if (!vga_cnattach(X86_BUS_SPACE_IO, X86_BUS_SPACE_MEM,
    200  1.3.2.2  skrll 				  -1, 1))
    201  1.3.2.2  skrll 			goto dokbd;
    202  1.3.2.2  skrll #endif
    203  1.3.2.2  skrll #if (NEGA > 0)
    204  1.3.2.2  skrll 		if (!ega_cnattach(X86_BUS_SPACE_IO, X86_BUS_SPACE_MEM))
    205  1.3.2.2  skrll 			goto dokbd;
    206  1.3.2.2  skrll #endif
    207  1.3.2.2  skrll #if (NPCDISPLAY > 0)
    208  1.3.2.2  skrll 		if (!pcdisplay_cnattach(X86_BUS_SPACE_IO, X86_BUS_SPACE_MEM))
    209  1.3.2.2  skrll 			goto dokbd;
    210  1.3.2.2  skrll #endif
    211  1.3.2.2  skrll #if (NPC > 0)
    212  1.3.2.2  skrll 		pccnattach();
    213  1.3.2.2  skrll #endif
    214  1.3.2.2  skrll 		if (0) goto dokbd; /* XXX stupid gcc */
    215  1.3.2.2  skrll dokbd:
    216  1.3.2.2  skrll #if (NPCKBC > 0)
    217  1.3.2.2  skrll 		pckbc_cnattach(X86_BUS_SPACE_IO, IO_KBD, KBCMDP,
    218  1.3.2.2  skrll 		    PCKBC_KBD_SLOT);
    219  1.3.2.2  skrll #endif
    220  1.3.2.2  skrll #if NPCKBC == 0 && NUKBD > 0
    221  1.3.2.2  skrll 		ukbd_cnattach();
    222  1.3.2.2  skrll #endif
    223  1.3.2.2  skrll 		return;
    224  1.3.2.2  skrll 	}
    225  1.3.2.2  skrll #endif /* PC | VT | VGA | PCDISPLAY */
    226  1.3.2.2  skrll #if (NCOM > 0)
    227  1.3.2.2  skrll 	if (!strcmp(consinfo->devname, "com")) {
    228  1.3.2.2  skrll 		bus_space_tag_t tag = X86_BUS_SPACE_IO;
    229  1.3.2.2  skrll 
    230  1.3.2.2  skrll 		if (comcnattach(tag, consinfo->addr, consinfo->speed,
    231  1.3.2.2  skrll 				COM_FREQ, COM_TYPE_NORMAL, comcnmode))
    232  1.3.2.2  skrll 			panic("can't init serial console @%x", consinfo->addr);
    233  1.3.2.2  skrll 
    234  1.3.2.2  skrll 		return;
    235  1.3.2.2  skrll 	}
    236  1.3.2.2  skrll #endif
    237  1.3.2.2  skrll 	panic("invalid console device %s", consinfo->devname);
    238  1.3.2.2  skrll }
    239  1.3.2.2  skrll 
    240  1.3.2.2  skrll #if (NPCKBC > 0) && (NPCKBD == 0)
    241  1.3.2.2  skrll /*
    242  1.3.2.2  skrll  * glue code to support old console code with the
    243  1.3.2.2  skrll  * mi keyboard controller driver
    244  1.3.2.2  skrll  */
    245  1.3.2.2  skrll int
    246  1.3.2.2  skrll pckbport_machdep_cnattach(kbctag, kbcslot)
    247  1.3.2.2  skrll 	pckbport_tag_t kbctag;
    248  1.3.2.2  skrll 	pckbport_slot_t kbcslot;
    249  1.3.2.2  skrll {
    250  1.3.2.2  skrll #if (NPC > 0) && (NPCCONSKBD > 0)
    251  1.3.2.2  skrll 	return (pcconskbd_cnattach(kbctag, kbcslot));
    252  1.3.2.2  skrll #else
    253  1.3.2.2  skrll 	return (ENXIO);
    254  1.3.2.2  skrll #endif
    255  1.3.2.2  skrll }
    256  1.3.2.2  skrll #endif
    257  1.3.2.2  skrll 
    258  1.3.2.2  skrll #ifdef KGDB
    259  1.3.2.2  skrll void
    260  1.3.2.2  skrll kgdb_port_init()
    261  1.3.2.2  skrll {
    262  1.3.2.2  skrll #if (NCOM > 0)
    263  1.3.2.2  skrll 	if(!strcmp(kgdb_devname, "com")) {
    264  1.3.2.2  skrll 		bus_space_tag_t tag = X86_BUS_SPACE_IO;
    265  1.3.2.2  skrll 
    266  1.3.2.2  skrll 		com_kgdb_attach(tag, comkgdbaddr, comkgdbrate, COM_FREQ,
    267  1.3.2.2  skrll 		    COM_TYPE_NORMAL, comkgdbmode);
    268  1.3.2.2  skrll 	}
    269  1.3.2.2  skrll #endif
    270  1.3.2.2  skrll }
    271  1.3.2.2  skrll #endif
    272