Home | History | Annotate | Line # | Download | only in dev
mainbus.c revision 1.1
      1 /*	$NetBSD: mainbus.c,v 1.1 2001/05/28 16:22:16 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 #if defined(ALGOR_P5064)
     76 #include <algor/algor/algor_p5064reg.h>
     77 #include <algor/algor/algor_p5064var.h>
     78 
     79 struct mainbus_attach_args mainbusdevs[] = {
     80 	{ "cpu",		-1 },
     81 	{ "vtpbc",		P5064_V360EPC },
     82 
     83 	{ NULL,			0 },
     84 };
     85 #endif /* ALGOR_P5064 */
     86 
     87 int
     88 mainbus_match(struct device *parent, struct cfdata *cf, void *aux)
     89 {
     90 
     91 	if (mainbus_found)
     92 		return (0);
     93 
     94 	return (1);
     95 }
     96 
     97 void
     98 mainbus_attach(struct device *parent, struct device *self, void *aux)
     99 {
    100 	struct mainbus_attach_args *ma;
    101 #if defined(PCI_NETBSD_CONFIGURE)
    102 	struct extent *ioext, *memext;
    103 	pci_chipset_tag_t pc;
    104 #endif
    105 
    106 	mainbus_found = 1;
    107 
    108 	printf("\n");
    109 
    110 #if NPCI > 0 && defined(PCI_NETBSD_CONFIGURE)
    111 #if defined(ALGOR_P5064)
    112 	/*
    113 	 * Reserve the bottom 512K of the I/O space for ISA devices.
    114 	 * According to the PMON sources, this is a work-around for
    115 	 * a bug in the ISA bridge.
    116 	 */
    117 	ioext  = extent_create("pciio",  0x00080000, 0x00ffffff,
    118 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
    119 	memext = extent_create("pcimem", 0x01000000, 0x07ffffff,
    120 	    M_DEVBUF, NULL, 0, EX_NOWAIT);
    121 
    122 	pc = &p5064_configuration.ac_pc;
    123 #endif /* ALGOR_P5064 */
    124 
    125 	pci_configure_bus(pc, ioext, memext, NULL);
    126 	extent_destroy(ioext);
    127 	extent_destroy(memext);
    128 #endif /* NPCI > 0 && defined(PCI_NETBSD_CONFIGURE) */
    129 
    130 	for (ma = mainbusdevs; ma->ma_name != NULL; ma++)
    131 		(void) config_found_sm(self, ma, mainbus_print,
    132 		    mainbus_submatch);
    133 }
    134 
    135 int
    136 mainbus_print(void *aux, const char *pnp)
    137 {
    138 	struct mainbus_attach_args *ma = aux;
    139 
    140 	if (pnp)
    141 		printf("%s at %s", ma->ma_name, pnp);
    142 	if (ma->ma_addr != (bus_addr_t) -1)
    143 		printf(" %s 0x%lx", mainbuscf_locnames[MAINBUSCF_ADDR],
    144 		    ma->ma_addr);
    145 
    146 	return (UNCONF);
    147 }
    148 
    149 int
    150 mainbus_submatch(struct device *parent, struct cfdata *cf, void *aux)
    151 {
    152 	struct mainbus_attach_args *ma = aux;
    153 
    154 	if (cf->cf_loc[MAINBUSCF_ADDR] != MAINBUSCF_ADDR_DEFAULT &&
    155 	    cf->cf_loc[MAINBUSCF_ADDR] != ma->ma_addr)
    156 		return (0);
    157 
    158 	return ((*cf->cf_attach->ca_match)(parent, cf, aux));
    159 }
    160