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