Home | History | Annotate | Line # | Download | only in dev
mainbus.c revision 1.3
      1 /*	$NetBSD: mainbus.c,v 1.3 2001/06/22 06:02:55 thorpej 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 "opt_algor_p4032.h"
     40 #include "opt_algor_p5064.h"
     41 #include "opt_algor_p6032.h"
     42 
     43 #include "opt_pci.h"
     44 
     45 #include <sys/param.h>
     46 #include <sys/systm.h>
     47 #include <sys/conf.h>
     48 #include <sys/reboot.h>
     49 #include <sys/device.h>
     50 #include <sys/malloc.h>
     51 #include <sys/extent.h>
     52 
     53 #include <machine/bus.h>
     54 #include <machine/autoconf.h>
     55 
     56 #include <dev/pci/pcivar.h>
     57 #include <dev/pci/pciconf.h>
     58 
     59 #include "locators.h"
     60 #include "pci.h"
     61 
     62 int	mainbus_match(struct device *, struct cfdata *, void *);
     63 void	mainbus_attach(struct device *, struct device *, void *);
     64 
     65 struct cfattach mainbus_ca = {
     66 	sizeof(struct device), mainbus_match, mainbus_attach,
     67 };
     68 
     69 int	mainbus_print(void *, const char *);
     70 int	mainbus_submatch(struct device *, struct cfdata *, void *);
     71 
     72 /* There can be only one. */
     73 int	mainbus_found;
     74 
     75 struct mainbusdev {
     76 	const char *md_name;
     77 	bus_addr_t md_addr;
     78 	int md_irq;
     79 };
     80 
     81 #if defined(ALGOR_P4032)
     82 #include <algor/algor/algor_p4032reg.h>
     83 #include <algor/algor/algor_p4032var.h>
     84 
     85 struct mainbusdev mainbusdevs[] = {
     86 	{ "cpu",		-1,			-1 },
     87 	{ "mcclock",		P4032_RTC,		P4032_IRQ_RTC },
     88 	{ "com",		P4032_COM1,		P4032_IRQ_COM1 },
     89 	{ "com",		P4032_COM2,		P4032_IRQ_COM2 },
     90 	{ "lpt",		P4032_LPT,		P4032_IRQ_LPT },
     91 	{ "pckbc",		P4032_PCKBC,		P4032_IRQ_PCKBC },
     92 	{ "fdc",		P4032_FDC,		P4032_IRQ_FLOPPY },
     93 	{ "vtpbc",		P4032_V962PBC,		-1 },
     94 
     95 	{ NULL,			0,			0 },
     96 };
     97 #endif /* ALGOR_P4032 */
     98 
     99 #if defined(ALGOR_P5064)
    100 #include <algor/algor/algor_p5064reg.h>
    101 #include <algor/algor/algor_p5064var.h>
    102 
    103 struct mainbusdev mainbusdevs[] = {
    104 	{ "cpu",		-1,			-1 },
    105 	{ "vtpbc",		P5064_V360EPC,		-1 },
    106 
    107 	{ NULL,			0,			0 },
    108 };
    109 #endif /* ALGOR_P5064 */
    110 
    111 #if defined(ALGOR_P6032)
    112 #include <algor/algor/algor_p6032reg.h>
    113 #include <algor/algor/algor_p6032var.h>
    114 
    115 struct mainbusdev mainbusdevs[] = {
    116 	{ "cpu",		-1,			-1 },
    117 	{ "bonito",		BONITO_REG_BASE,	-1 },
    118 
    119 	{ NULL,			0,			0 },
    120 };
    121 #endif /* ALGOR_P6032 */
    122 
    123 int
    124 mainbus_match(struct device *parent, struct cfdata *cf, void *aux)
    125 {
    126 
    127 	if (mainbus_found)
    128 		return (0);
    129 
    130 	return (1);
    131 }
    132 
    133 void
    134 mainbus_attach(struct device *parent, struct device *self, void *aux)
    135 {
    136 	struct mainbus_attach_args ma;
    137 	struct mainbusdev *md;
    138 	bus_space_tag_t st;
    139 #if defined(PCI_NETBSD_CONFIGURE)
    140 	struct extent *ioext, *memext;
    141 	pci_chipset_tag_t pc;
    142 #endif
    143 
    144 	mainbus_found = 1;
    145 
    146 	printf("\n");
    147 
    148 #if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
    149 #if defined(ALGOR_P4032)
    150 	/*
    151 	 * Reserve the bottom 64K of the I/O space for ISA devices.
    152 	 */
    153 	ioext  = extent_create("pciio",  0x00010000, 0x000effff,
    154 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
    155 	memext = extent_create("pcimem", 0x01000000, 0x07ffffff,
    156 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
    157 
    158 	pc = &p4032_configuration.ac_pc;
    159 #elif defined(ALGOR_P5064)
    160 	/*
    161 	 * Reserve the bottom 512K of the I/O space for ISA devices.
    162 	 * According to the PMON sources, this is a work-around for
    163 	 * a bug in the ISA bridge.
    164 	 */
    165 	ioext  = extent_create("pciio",  0x00080000, 0x00ffffff,
    166 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
    167 	memext = extent_create("pcimem", 0x01000000, 0x07ffffff,
    168 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
    169 
    170 	pc = &p5064_configuration.ac_pc;
    171 #elif defined(ALGOR_P6032)
    172 	/*
    173 	 * Reserve the bottom 64K of the I/O spcae for ISA devices.
    174 	 */
    175 	ioext  = extent_create("pciio",  0x00010000, 0x000effff,
    176 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
    177 	memext = extent_create("pcimem", 0x01000000, 0x0affffff,
    178 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
    179 
    180 	pc = &p6032_configuration.ac_pc;
    181 #endif /* ALGOR_P4032 || ALGOR_P5064 || ALGOR_P6032 */
    182 
    183 	pci_configure_bus(pc, ioext, memext, NULL);
    184 	extent_destroy(ioext);
    185 	extent_destroy(memext);
    186 #endif /* NPCI > 0 && defined(PCI_NETBSD_CONFIGURE) */
    187 
    188 #if defined(ALGOR_P4032)
    189 	st = &p4032_configuration.ac_lociot;
    190 #elif defined(ALGOR_P5064)
    191 	st = NULL;
    192 #elif defined(ALGOR_P6032)
    193 	st = NULL;
    194 #endif
    195 
    196 	for (md = mainbusdevs; md->md_name != NULL; md++) {
    197 		ma.ma_name = md->md_name;
    198 		ma.ma_st = st;
    199 		ma.ma_addr = md->md_addr;
    200 		ma.ma_irq = md->md_irq;
    201 		(void) config_found_sm(self, &ma, mainbus_print,
    202 		    mainbus_submatch);
    203 	}
    204 }
    205 
    206 int
    207 mainbus_print(void *aux, const char *pnp)
    208 {
    209 	struct mainbus_attach_args *ma = aux;
    210 
    211 	if (pnp)
    212 		printf("%s at %s", ma->ma_name, pnp);
    213 	if (ma->ma_addr != (bus_addr_t) -1)
    214 		printf(" %s 0x%lx", mainbuscf_locnames[MAINBUSCF_ADDR],
    215 		    ma->ma_addr);
    216 
    217 	return (UNCONF);
    218 }
    219 
    220 int
    221 mainbus_submatch(struct device *parent, struct cfdata *cf, void *aux)
    222 {
    223 	struct mainbus_attach_args *ma = aux;
    224 
    225 	if (cf->cf_loc[MAINBUSCF_ADDR] != MAINBUSCF_ADDR_DEFAULT &&
    226 	    cf->cf_loc[MAINBUSCF_ADDR] != ma->ma_addr)
    227 		return (0);
    228 
    229 	return ((*cf->cf_attach->ca_match)(parent, cf, aux));
    230 }
    231