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