Home | History | Annotate | Line # | Download | only in dev
mainbus.c revision 1.2
      1 /*	$NetBSD: mainbus.c,v 1.2 2001/06/01 16:00:04 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 int
    112 mainbus_match(struct device *parent, struct cfdata *cf, void *aux)
    113 {
    114 
    115 	if (mainbus_found)
    116 		return (0);
    117 
    118 	return (1);
    119 }
    120 
    121 void
    122 mainbus_attach(struct device *parent, struct device *self, void *aux)
    123 {
    124 	struct mainbus_attach_args ma;
    125 	struct mainbusdev *md;
    126 	bus_space_tag_t st;
    127 #if defined(PCI_NETBSD_CONFIGURE)
    128 	struct extent *ioext, *memext;
    129 	pci_chipset_tag_t pc;
    130 #endif
    131 
    132 	mainbus_found = 1;
    133 
    134 	printf("\n");
    135 
    136 #if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
    137 #if defined(ALGOR_P4032)
    138 	/*
    139 	 * Reserve the bottom 64K of the I/O space for ISA devices.
    140 	 */
    141 	ioext  = extent_create("pciio",  0x00010000, 0x000effff,
    142 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
    143 	memext = extent_create("pcimem", 0x01000000, 0x07ffffff,
    144 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
    145 
    146 	pc = &p4032_configuration.ac_pc;
    147 #elif defined(ALGOR_P5064)
    148 	/*
    149 	 * Reserve the bottom 512K of the I/O space for ISA devices.
    150 	 * According to the PMON sources, this is a work-around for
    151 	 * a bug in the ISA bridge.
    152 	 */
    153 	ioext  = extent_create("pciio",  0x00080000, 0x00ffffff,
    154 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
    155 	memext = extent_create("pcimem", 0x01000000, 0x07ffffff,
    156 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
    157 
    158 	pc = &p5064_configuration.ac_pc;
    159 #endif /* ALGOR_P4032 || ALGOR_P5064 */
    160 
    161 	pci_configure_bus(pc, ioext, memext, NULL);
    162 	extent_destroy(ioext);
    163 	extent_destroy(memext);
    164 #endif /* NPCI > 0 && defined(PCI_NETBSD_CONFIGURE) */
    165 
    166 #if defined(ALGOR_P4032)
    167 	st = &p4032_configuration.ac_lociot;
    168 #elif defined(ALGOR_P5064)
    169 	st = NULL;
    170 #endif
    171 
    172 	for (md = mainbusdevs; md->md_name != NULL; md++) {
    173 		ma.ma_name = md->md_name;
    174 		ma.ma_st = st;
    175 		ma.ma_addr = md->md_addr;
    176 		ma.ma_irq = md->md_irq;
    177 		(void) config_found_sm(self, &ma, mainbus_print,
    178 		    mainbus_submatch);
    179 	}
    180 }
    181 
    182 int
    183 mainbus_print(void *aux, const char *pnp)
    184 {
    185 	struct mainbus_attach_args *ma = aux;
    186 
    187 	if (pnp)
    188 		printf("%s at %s", ma->ma_name, pnp);
    189 	if (ma->ma_addr != (bus_addr_t) -1)
    190 		printf(" %s 0x%lx", mainbuscf_locnames[MAINBUSCF_ADDR],
    191 		    ma->ma_addr);
    192 
    193 	return (UNCONF);
    194 }
    195 
    196 int
    197 mainbus_submatch(struct device *parent, struct cfdata *cf, void *aux)
    198 {
    199 	struct mainbus_attach_args *ma = aux;
    200 
    201 	if (cf->cf_loc[MAINBUSCF_ADDR] != MAINBUSCF_ADDR_DEFAULT &&
    202 	    cf->cf_loc[MAINBUSCF_ADDR] != ma->ma_addr)
    203 		return (0);
    204 
    205 	return ((*cf->cf_attach->ca_match)(parent, cf, aux));
    206 }
    207