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