Home | History | Annotate | Line # | Download | only in prep
      1 /*	$NetBSD: consinit.c,v 1.8 2012/10/13 17:58:53 jdc Exp $	*/
      2 
      3 /*
      4  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
      5  * Copyright (C) 1995, 1996 TooLs GmbH.
      6  * 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  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *	This product includes software developed by TooLs GmbH.
     19  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     28  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     29  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     30  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     31  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 
     34 #include <sys/cdefs.h>
     35 __KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.8 2012/10/13 17:58:53 jdc Exp $");
     36 
     37 #include <sys/param.h>
     38 #include <sys/systm.h>
     39 
     40 #include <machine/bootinfo.h>
     41 #include <sys/bus.h>
     42 #include <machine/intr.h>
     43 
     44 #include <dev/cons.h>
     45 
     46 #include "gten.h"
     47 #if (NGTEN > 0)
     48 #include <machine/gtenvar.h>
     49 #endif
     50 
     51 /* Implied by gten support. */
     52 #if (NGTEN > 0)
     53 #include <dev/pci/pcivar.h>
     54 #endif
     55 
     56 #include "vga.h"
     57 #if (NVGA > 0)
     58 #include <dev/ic/mc6845reg.h>
     59 #include <dev/ic/pcdisplayvar.h>
     60 #include <dev/ic/vgareg.h>
     61 #include <dev/ic/vgavar.h>
     62 #endif
     63 
     64 #include "pckbc.h"
     65 #if (NPCKBC > 0)
     66 #include <dev/isa/isareg.h>
     67 #include <dev/ic/i8042reg.h>
     68 #include <dev/ic/pckbcvar.h>
     69 #endif
     70 
     71 #include "com.h"
     72 #if (NCOM > 0)
     73 #include <sys/termios.h>
     74 #include <dev/ic/comreg.h>
     75 #include <dev/ic/comvar.h>
     76 #endif
     77 
     78 /*
     79  * consinit
     80  * Initialize system console.
     81  */
     82 void
     83 consinit(void)
     84 {
     85 	struct btinfo_console *consinfo;
     86 	static int initted = 0;
     87 #if (NGTEN > 0)
     88 	struct prep_pci_chipset pc;
     89 #endif
     90 
     91 	if (initted)
     92 		return;
     93 	initted = 1;
     94 
     95 	consinfo = (struct btinfo_console *)lookup_bootinfo(BTINFO_CONSOLE);
     96 	if (!consinfo)
     97 		panic("not found console information in bootinfo");
     98 
     99 #if (NPFB > 0)
    100 	if (!strcmp(consinfo->devname, "fb")) {
    101 		pfb_cnattach(consinfo->addr);
    102 #if (NPCKBC > 0)
    103 		pckbc_cnattach(&genppc_isa_io_space_tag, IO_KBD, KBCMDP,
    104 		    PCKBC_KBD_SLOT, 0);
    105 #endif
    106 		return;
    107 	}
    108 #endif
    109 
    110 #if (NVGA > 0) || (NGTEN > 0)
    111 	if (!strcmp(consinfo->devname, "vga")) {
    112 #if (NGTEN > 0)
    113 		prep_pci_get_chipset_tag(&pc);
    114 #endif
    115 #if (NGTEN > 0)
    116 		if (!gten_cnattach(&pc, &prep_mem_space_tag))
    117 			goto dokbd;
    118 #endif
    119 #if (NVGA > 0)
    120 		if (!vga_cnattach(&prep_io_space_tag, &prep_mem_space_tag,
    121 				-1, 1))
    122 			goto dokbd;
    123 #endif
    124 dokbd:
    125 #if (NPCKBC > 0)
    126 		pckbc_cnattach(&genppc_isa_io_space_tag, IO_KBD, KBCMDP,
    127 		    PCKBC_KBD_SLOT, 0);
    128 #endif
    129 		return;
    130 	}
    131 #endif /* VGA | GTEN */
    132 
    133 #if (NCOM > 0)
    134 	if (!strcmp(consinfo->devname, "com")) {
    135 		bus_space_tag_t tag = &genppc_isa_io_space_tag;
    136 
    137 		if(comcnattach(tag, consinfo->addr, consinfo->speed, COM_FREQ,
    138 		    COM_TYPE_NORMAL,
    139 		    ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8)))
    140 			panic("can't init serial console");
    141 
    142 		return;
    143 	}
    144 #endif
    145 	panic("invalid console device %s", consinfo->devname);
    146 }
    147