Home | History | Annotate | Line # | Download | only in pci
ppb.c revision 1.21.2.2
      1  1.21.2.2  thorpej /*	$NetBSD: ppb.c,v 1.21.2.2 2002/05/16 01:01:31 thorpej Exp $	*/
      2  1.21.2.2  thorpej 
      3  1.21.2.2  thorpej /*
      4  1.21.2.2  thorpej  * Copyright (c) 1996, 1998 Christopher G. Demetriou.  All rights reserved.
      5  1.21.2.2  thorpej  *
      6  1.21.2.2  thorpej  * Redistribution and use in source and binary forms, with or without
      7  1.21.2.2  thorpej  * modification, are permitted provided that the following conditions
      8  1.21.2.2  thorpej  * are met:
      9  1.21.2.2  thorpej  * 1. Redistributions of source code must retain the above copyright
     10  1.21.2.2  thorpej  *    notice, this list of conditions and the following disclaimer.
     11  1.21.2.2  thorpej  * 2. Redistributions in binary form must reproduce the above copyright
     12  1.21.2.2  thorpej  *    notice, this list of conditions and the following disclaimer in the
     13  1.21.2.2  thorpej  *    documentation and/or other materials provided with the distribution.
     14  1.21.2.2  thorpej  * 3. All advertising materials mentioning features or use of this software
     15  1.21.2.2  thorpej  *    must display the following acknowledgement:
     16  1.21.2.2  thorpej  *      This product includes software developed by Christopher G. Demetriou
     17  1.21.2.2  thorpej  *	for the NetBSD Project.
     18  1.21.2.2  thorpej  * 4. The name of the author may not be used to endorse or promote products
     19  1.21.2.2  thorpej  *    derived from this software without specific prior written permission
     20  1.21.2.2  thorpej  *
     21  1.21.2.2  thorpej  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22  1.21.2.2  thorpej  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23  1.21.2.2  thorpej  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24  1.21.2.2  thorpej  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25  1.21.2.2  thorpej  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26  1.21.2.2  thorpej  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27  1.21.2.2  thorpej  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28  1.21.2.2  thorpej  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  1.21.2.2  thorpej  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30  1.21.2.2  thorpej  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31  1.21.2.2  thorpej  */
     32  1.21.2.2  thorpej 
     33  1.21.2.2  thorpej #include <sys/cdefs.h>
     34  1.21.2.2  thorpej __KERNEL_RCSID(0, "$NetBSD: ppb.c,v 1.21.2.2 2002/05/16 01:01:31 thorpej Exp $");
     35  1.21.2.2  thorpej 
     36  1.21.2.2  thorpej #include <sys/param.h>
     37  1.21.2.2  thorpej #include <sys/systm.h>
     38  1.21.2.2  thorpej #include <sys/kernel.h>
     39  1.21.2.2  thorpej #include <sys/device.h>
     40  1.21.2.2  thorpej 
     41  1.21.2.2  thorpej #include <dev/pci/pcireg.h>
     42  1.21.2.2  thorpej #include <dev/pci/pcivar.h>
     43  1.21.2.2  thorpej #include <dev/pci/ppbreg.h>
     44  1.21.2.2  thorpej 
     45  1.21.2.2  thorpej struct ppb_softc {
     46  1.21.2.2  thorpej 	struct device sc_dev;		/* generic device glue */
     47  1.21.2.2  thorpej 	pci_chipset_tag_t sc_pc;	/* our PCI chipset... */
     48  1.21.2.2  thorpej 	pcitag_t sc_tag;		/* ...and tag. */
     49  1.21.2.2  thorpej };
     50  1.21.2.2  thorpej 
     51  1.21.2.2  thorpej int	ppbmatch __P((struct device *, struct cfdata *, void *));
     52  1.21.2.2  thorpej void	ppbattach __P((struct device *, struct device *, void *));
     53  1.21.2.2  thorpej 
     54  1.21.2.2  thorpej struct cfattach ppb_ca = {
     55  1.21.2.2  thorpej 	sizeof(struct ppb_softc), ppbmatch, ppbattach
     56  1.21.2.2  thorpej };
     57  1.21.2.2  thorpej 
     58  1.21.2.2  thorpej int	ppbprint __P((void *, const char *pnp));
     59  1.21.2.2  thorpej 
     60  1.21.2.2  thorpej int
     61  1.21.2.2  thorpej ppbmatch(parent, match, aux)
     62  1.21.2.2  thorpej 	struct device *parent;
     63  1.21.2.2  thorpej 	struct cfdata *match;
     64  1.21.2.2  thorpej 	void *aux;
     65  1.21.2.2  thorpej {
     66  1.21.2.2  thorpej 	struct pci_attach_args *pa = aux;
     67  1.21.2.2  thorpej 
     68  1.21.2.2  thorpej 	/*
     69  1.21.2.2  thorpej 	 * Check the ID register to see that it's a PCI bridge.
     70  1.21.2.2  thorpej 	 * If it is, we assume that we can deal with it; it _should_
     71  1.21.2.2  thorpej 	 * work in a standardized way...
     72  1.21.2.2  thorpej 	 */
     73  1.21.2.2  thorpej 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
     74  1.21.2.2  thorpej 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_PCI)
     75  1.21.2.2  thorpej 		return (1);
     76  1.21.2.2  thorpej 
     77  1.21.2.2  thorpej 	return (0);
     78  1.21.2.2  thorpej }
     79  1.21.2.2  thorpej 
     80  1.21.2.2  thorpej void
     81  1.21.2.2  thorpej ppbattach(parent, self, aux)
     82  1.21.2.2  thorpej 	struct device *parent, *self;
     83  1.21.2.2  thorpej 	void *aux;
     84  1.21.2.2  thorpej {
     85  1.21.2.2  thorpej 	struct ppb_softc *sc = (void *) self;
     86  1.21.2.2  thorpej 	struct pci_attach_args *pa = aux;
     87  1.21.2.2  thorpej 	pci_chipset_tag_t pc = pa->pa_pc;
     88  1.21.2.2  thorpej 	struct pcibus_attach_args pba;
     89  1.21.2.2  thorpej 	pcireg_t busdata;
     90  1.21.2.2  thorpej 	char devinfo[256];
     91  1.21.2.2  thorpej 
     92  1.21.2.2  thorpej 	pci_devinfo(pa->pa_id, pa->pa_class, 0, devinfo);
     93  1.21.2.2  thorpej 	printf(": %s (rev. 0x%02x)\n", devinfo, PCI_REVISION(pa->pa_class));
     94  1.21.2.2  thorpej 
     95  1.21.2.2  thorpej 	sc->sc_pc = pc;
     96  1.21.2.2  thorpej 	sc->sc_tag = pa->pa_tag;
     97  1.21.2.2  thorpej 
     98  1.21.2.2  thorpej 	busdata = pci_conf_read(pc, pa->pa_tag, PPB_REG_BUSINFO);
     99  1.21.2.2  thorpej 
    100  1.21.2.2  thorpej 	if (PPB_BUSINFO_SECONDARY(busdata) == 0) {
    101  1.21.2.2  thorpej 		printf("%s: not configured by system firmware\n",
    102  1.21.2.2  thorpej 		    self->dv_xname);
    103  1.21.2.2  thorpej 		return;
    104  1.21.2.2  thorpej 	}
    105  1.21.2.2  thorpej 
    106  1.21.2.2  thorpej #if 0
    107  1.21.2.2  thorpej 	/*
    108  1.21.2.2  thorpej 	 * XXX can't do this, because we're not given our bus number
    109  1.21.2.2  thorpej 	 * (we shouldn't need it), and because we've no way to
    110  1.21.2.2  thorpej 	 * decompose our tag.
    111  1.21.2.2  thorpej 	 */
    112  1.21.2.2  thorpej 	/* sanity check. */
    113  1.21.2.2  thorpej 	if (pa->pa_bus != PPB_BUSINFO_PRIMARY(busdata))
    114  1.21.2.2  thorpej 		panic("ppbattach: bus in tag (%d) != bus in reg (%d)",
    115  1.21.2.2  thorpej 		    pa->pa_bus, PPB_BUSINFO_PRIMARY(busdata));
    116  1.21.2.2  thorpej #endif
    117  1.21.2.2  thorpej 
    118  1.21.2.2  thorpej 	/*
    119  1.21.2.2  thorpej 	 * Attach the PCI bus than hangs off of it.
    120  1.21.2.2  thorpej 	 *
    121  1.21.2.2  thorpej 	 * XXX Don't pass-through Memory Read Multiple.  Should we?
    122  1.21.2.2  thorpej 	 * XXX Consult the spec...
    123  1.21.2.2  thorpej 	 */
    124  1.21.2.2  thorpej 	pba.pba_busname = "pci";	/* XXX should be pci_ppb attachment */
    125  1.21.2.2  thorpej 	pba.pba_iot = pa->pa_iot;
    126  1.21.2.2  thorpej 	pba.pba_memt = pa->pa_memt;
    127  1.21.2.2  thorpej 	pba.pba_dmat = pa->pa_dmat;
    128  1.21.2.2  thorpej 	pba.pba_pc = pc;
    129  1.21.2.2  thorpej 	pba.pba_flags = pa->pa_flags & ~PCI_FLAGS_MRM_OKAY;
    130  1.21.2.2  thorpej 	pba.pba_bus = PPB_BUSINFO_SECONDARY(busdata);
    131  1.21.2.2  thorpej 	pba.pba_bridgetag = &sc->sc_tag;
    132  1.21.2.2  thorpej 	pba.pba_intrswiz = pa->pa_intrswiz;
    133  1.21.2.2  thorpej 	pba.pba_intrtag = pa->pa_intrtag;
    134  1.21.2.2  thorpej 
    135  1.21.2.2  thorpej 	config_found(self, &pba, ppbprint);
    136  1.21.2.2  thorpej }
    137  1.21.2.2  thorpej 
    138  1.21.2.2  thorpej int
    139  1.21.2.2  thorpej ppbprint(aux, pnp)
    140  1.21.2.2  thorpej 	void *aux;
    141  1.21.2.2  thorpej 	const char *pnp;
    142  1.21.2.2  thorpej {
    143  1.21.2.2  thorpej 	struct pcibus_attach_args *pba = aux;
    144  1.21.2.2  thorpej 
    145  1.21.2.2  thorpej 	/* only PCIs can attach to PPBs; easy. */
    146  1.21.2.2  thorpej 	if (pnp)
    147  1.21.2.2  thorpej 		printf("pci at %s", pnp);
    148  1.21.2.2  thorpej 	printf(" bus %d", pba->pba_bus);
    149  1.21.2.2  thorpej 	return (UNCONF);
    150  1.21.2.2  thorpej }
    151