Home | History | Annotate | Line # | Download | only in dev
mainbus.c revision 1.15
      1 /*	$NetBSD: mainbus.c,v 1.15 2005/06/28 18:29:58 drochner Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2001 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/cdefs.h>
     40 __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.15 2005/06/28 18:29:58 drochner Exp $");
     41 
     42 #include "opt_algor_p4032.h"
     43 #include "opt_algor_p5064.h"
     44 #include "opt_algor_p6032.h"
     45 
     46 #include "opt_pci.h"
     47 
     48 #include <sys/param.h>
     49 #include <sys/systm.h>
     50 #include <sys/conf.h>
     51 #include <sys/reboot.h>
     52 #include <sys/device.h>
     53 #include <sys/malloc.h>
     54 #include <sys/extent.h>
     55 
     56 #include <machine/bus.h>
     57 #include <machine/autoconf.h>
     58 
     59 #include <mips/cache.h>
     60 
     61 #include <dev/pci/pcivar.h>
     62 #include <dev/pci/pciconf.h>
     63 
     64 #if defined(PCI_NETBSD_CONFIGURE) && defined(PCI_NETBSD_ENABLE_IDE)
     65 #if defined(ALGOR_P5064) || defined(ALGOR_P6032)
     66 #include <dev/pci/pciide_piix_reg.h>
     67 #endif /* ALGOR_P5064 || ALGOR_P6032 */
     68 #endif /* PCI_NETBSD_CONFIGURE && PCI_NETBSD_ENABLE_IDE */
     69 
     70 #include "locators.h"
     71 #include "pci.h"
     72 
     73 int	mainbus_match(struct device *, struct cfdata *, void *);
     74 void	mainbus_attach(struct device *, struct device *, void *);
     75 
     76 CFATTACH_DECL(mainbus, sizeof(struct device),
     77     mainbus_match, mainbus_attach, NULL, NULL);
     78 
     79 int	mainbus_print(void *, const char *);
     80 int	mainbus_submatch(struct device *, struct cfdata *,
     81 			 const locdesc_t *, void *);
     82 
     83 /* There can be only one. */
     84 int	mainbus_found;
     85 
     86 struct mainbusdev {
     87 	const char *md_name;
     88 	bus_addr_t md_addr;
     89 	int md_irq;
     90 };
     91 
     92 #if defined(ALGOR_P4032)
     93 #include <algor/algor/algor_p4032reg.h>
     94 #include <algor/algor/algor_p4032var.h>
     95 
     96 struct mainbusdev mainbusdevs[] = {
     97 	{ "cpu",		-1,			-1 },
     98 	{ "mcclock",		P4032_RTC,		P4032_IRQ_RTC },
     99 	{ "com",		P4032_COM1,		P4032_IRQ_COM1 },
    100 	{ "com",		P4032_COM2,		P4032_IRQ_COM2 },
    101 	{ "lpt",		P4032_LPT,		P4032_IRQ_LPT },
    102 	{ "pckbc",		P4032_PCKBC,		P4032_IRQ_PCKBC },
    103 	{ "fdc",		P4032_FDC,		P4032_IRQ_FLOPPY },
    104 	{ "vtpbc",		P4032_V962PBC,		-1 },
    105 
    106 	{ NULL,			0,			0 },
    107 };
    108 #endif /* ALGOR_P4032 */
    109 
    110 #if defined(ALGOR_P5064)
    111 #include <algor/algor/algor_p5064reg.h>
    112 #include <algor/algor/algor_p5064var.h>
    113 
    114 struct mainbusdev mainbusdevs[] = {
    115 	{ "cpu",		-1,			-1 },
    116 	{ "vtpbc",		P5064_V360EPC,		-1 },
    117 
    118 	{ NULL,			0,			0 },
    119 };
    120 #endif /* ALGOR_P5064 */
    121 
    122 #if defined(ALGOR_P6032)
    123 #include <algor/algor/algor_p6032reg.h>
    124 #include <algor/algor/algor_p6032var.h>
    125 
    126 struct mainbusdev mainbusdevs[] = {
    127 	{ "cpu",		-1,			-1 },
    128 	{ "bonito",		BONITO_REG_BASE,	-1 },
    129 
    130 	{ NULL,			0,			0 },
    131 };
    132 #endif /* ALGOR_P6032 */
    133 
    134 int
    135 mainbus_match(struct device *parent, struct cfdata *cf, void *aux)
    136 {
    137 
    138 	if (mainbus_found)
    139 		return (0);
    140 
    141 	return (1);
    142 }
    143 
    144 void
    145 mainbus_attach(struct device *parent, struct device *self, void *aux)
    146 {
    147 	struct mainbus_attach_args ma;
    148 	struct mainbusdev *md;
    149 	bus_space_tag_t st;
    150 #if defined(PCI_NETBSD_CONFIGURE)
    151 	struct extent *ioext, *memext;
    152 	pci_chipset_tag_t pc;
    153 #if defined(PCI_NETBSD_ENABLE_IDE)
    154 	pcitag_t idetag;
    155 	pcireg_t idetim;
    156 #endif
    157 #endif
    158 
    159 	mainbus_found = 1;
    160 
    161 	printf("\n");
    162 
    163 #if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
    164 #if defined(ALGOR_P4032)
    165 	/*
    166 	 * Reserve the bottom 64K of the I/O space for ISA devices.
    167 	 */
    168 	ioext  = extent_create("pciio",  0x00010000, 0x000effff,
    169 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
    170 	memext = extent_create("pcimem", 0x01000000, 0x07ffffff,
    171 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
    172 
    173 	pc = &p4032_configuration.ac_pc;
    174 #elif defined(ALGOR_P5064)
    175 	/*
    176 	 * Reserve the bottom 512K of the I/O space for ISA devices.
    177 	 * According to the PMON sources, this is a work-around for
    178 	 * a bug in the ISA bridge.
    179 	 */
    180 	ioext  = extent_create("pciio",  0x00080000, 0x00ffffff,
    181 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
    182 	memext = extent_create("pcimem", 0x01000000, 0x07ffffff,
    183 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
    184 
    185 	pc = &p5064_configuration.ac_pc;
    186 #if defined(PCI_NETBSD_ENABLE_IDE)
    187 	idetag = pci_make_tag(pc, 0, 2, 1);
    188 #endif
    189 #elif defined(ALGOR_P6032)
    190 	/*
    191 	 * Reserve the bottom 64K of the I/O space for ISA devices.
    192 	 */
    193 	ioext  = extent_create("pciio",  0x00010000, 0x000effff,
    194 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
    195 	memext = extent_create("pcimem", 0x01000000, 0x0affffff,
    196 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
    197 
    198 	pc = &p6032_configuration.ac_pc;
    199 #if defined(PCI_NETBSD_ENABLE_IDE)
    200 	idetag = pci_make_tag(pc, 0, 17, 1);
    201 #endif
    202 #endif /* ALGOR_P4032 || ALGOR_P5064 || ALGOR_P6032 */
    203 
    204 	pci_configure_bus(pc, ioext, memext, NULL, 0, mips_dcache_align);
    205 	extent_destroy(ioext);
    206 	extent_destroy(memext);
    207 
    208 #if defined(PCI_NETBSD_ENABLE_IDE)
    209 	/*
    210 	 * Perhaps PMON has not enabled the IDE controller.  Easy to
    211 	 * fix -- just set the ENABLE bits for each channel in the
    212 	 * IDETIM register.  Just clear all the bits for the channel
    213 	 * except for the ENABLE bits -- the `pciide' driver will
    214 	 * properly configure it later.
    215 	 */
    216 	idetim = 0;
    217 	if (PCI_NETBSD_ENABLE_IDE & 0x01)
    218 		idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE, 0);
    219 	if (PCI_NETBSD_ENABLE_IDE & 0x02)
    220 		idetim = PIIX_IDETIM_SET(idetim, PIIX_IDETIM_IDE, 1);
    221 	pci_conf_write(pc, idetag, PIIX_IDETIM, idetim);
    222 #endif
    223 #endif /* NPCI > 0 && defined(PCI_NETBSD_CONFIGURE) */
    224 
    225 #if defined(ALGOR_P4032)
    226 	st = &p4032_configuration.ac_lociot;
    227 #elif defined(ALGOR_P5064)
    228 	st = NULL;
    229 #elif defined(ALGOR_P6032)
    230 	st = NULL;
    231 #endif
    232 
    233 	for (md = mainbusdevs; md->md_name != NULL; md++) {
    234 		ma.ma_name = md->md_name;
    235 		ma.ma_st = st;
    236 		ma.ma_addr = md->md_addr;
    237 		ma.ma_irq = md->md_irq;
    238 		(void) config_found_sm_loc(self, "mainbus", NULL, &ma,
    239 		    mainbus_print, mainbus_submatch);
    240 	}
    241 }
    242 
    243 int
    244 mainbus_print(void *aux, const char *pnp)
    245 {
    246 	struct mainbus_attach_args *ma = aux;
    247 
    248 	if (pnp)
    249 		aprint_normal("%s at %s", ma->ma_name, pnp);
    250 	if (ma->ma_addr != (bus_addr_t) -1)
    251 		aprint_normal(" %s 0x%lx", mainbuscf_locnames[MAINBUSCF_ADDR],
    252 		    ma->ma_addr);
    253 
    254 	return (UNCONF);
    255 }
    256 
    257 int
    258 mainbus_submatch(struct device *parent, struct cfdata *cf,
    259 		 const locdesc_t *, void *aux)
    260 {
    261 	struct mainbus_attach_args *ma = aux;
    262 
    263 	if (cf->cf_loc[MAINBUSCF_ADDR] != MAINBUSCF_ADDR_DEFAULT &&
    264 	    cf->cf_loc[MAINBUSCF_ADDR] != ma->ma_addr)
    265 		return (0);
    266 
    267 	return (config_match(parent, cf, aux));
    268 }
    269