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