Home | History | Annotate | Line # | Download | only in dev
bonito_mainbus.c revision 1.8
      1 /*	$NetBSD: bonito_mainbus.c,v 1.8 2003/07/14 22:57:47 lukem 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 <sys/cdefs.h>
     40 __KERNEL_RCSID(0, "$NetBSD: bonito_mainbus.c,v 1.8 2003/07/14 22:57:47 lukem Exp $");
     41 
     42 #include "opt_algor_p6032.h"
     43 
     44 #include <sys/param.h>
     45 #include <sys/systm.h>
     46 #include <sys/conf.h>
     47 #include <sys/reboot.h>
     48 #include <sys/device.h>
     49 
     50 #include <machine/bus.h>
     51 #include <machine/autoconf.h>
     52 
     53 #include <mips/bonito/bonitoreg.h>
     54 
     55 #ifdef ALGOR_P6032
     56 #include <algor/algor/algor_p6032var.h>
     57 #endif
     58 
     59 struct bonito_softc {
     60 	struct device sc_dev;
     61 	struct bonito_config *sc_bonito;
     62 };
     63 
     64 int	bonito_mainbus_match(struct device *, struct cfdata *, void *);
     65 void	bonito_mainbus_attach(struct device *, struct device *, void *);
     66 
     67 CFATTACH_DECL(bonito_mainbus, sizeof(struct bonito_softc),
     68     bonito_mainbus_match, bonito_mainbus_attach, NULL, NULL);
     69 extern struct cfdriver bonito_cd;
     70 
     71 int	bonito_mainbus_print(void *, const char *);
     72 
     73 int
     74 bonito_mainbus_match(struct device *parent, struct cfdata *cf, void *aux)
     75 {
     76 	struct mainbus_attach_args *ma = aux;
     77 
     78 	if (strcmp(ma->ma_name, bonito_cd.cd_name) == 0)
     79 		return (1);
     80 
     81 	return (0);
     82 }
     83 
     84 void
     85 bonito_mainbus_attach(struct device *parent, struct device *self, void *aux)
     86 {
     87 	struct bonito_softc *sc = (void *) self;
     88 	struct pcibus_attach_args pba;
     89 	struct bonito_config *bc;
     90 	pcireg_t rev;
     91 
     92 	/*
     93 	 * There is only one PCI controller on an Algorithmics board.
     94 	 */
     95 #if defined(ALGOR_P6032)
     96 	bc = &p6032_configuration.ac_bonito;
     97 #endif
     98 	sc->sc_bonito = bc;
     99 
    100 	rev = PCI_REVISION(REGVAL(BONITO_PCICLASS));
    101 
    102 	printf(": BONITO Memory and PCI controller, %s rev. %d.%d\n",
    103 	    BONITO_REV_FPGA(rev) ? "FPGA" : "ASIC",
    104 	    BONITO_REV_MAJOR(rev), BONITO_REV_MINOR(rev));
    105 
    106 	pba.pba_busname = "pci";
    107 	pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
    108 	pba.pba_bus = 0;
    109 	pba.pba_bridgetag = NULL;
    110 
    111 #if defined(ALGOR_P6032)
    112 	    {
    113 		struct p6032_config *acp = &p6032_configuration;
    114 
    115 		pba.pba_iot = &acp->ac_iot;
    116 		pba.pba_memt = &acp->ac_memt;
    117 		pba.pba_dmat = &acp->ac_pci_dmat;
    118 		pba.pba_dmat64 = NULL;
    119 		pba.pba_pc = &acp->ac_pc;
    120 	    }
    121 #endif /* ALGOR_P6032 */
    122 
    123 	(void) config_found(self, &pba, bonito_mainbus_print);
    124 }
    125 
    126 int
    127 bonito_mainbus_print(void *aux, const char *pnp)
    128 {
    129 	struct pcibus_attach_args *pba = aux;
    130 
    131 	/* only PCIs can attach to BONITOs; easy. */
    132 	if (pnp)
    133 		aprint_normal("%s at %s", pba->pba_busname, pnp);
    134 	aprint_normal(" bus %d", pba->pba_bus);
    135 
    136 	return (UNCONF);
    137 }
    138