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