Home | History | Annotate | Line # | Download | only in pci
ppb.c revision 1.60
      1  1.60   msaitoh /*	$NetBSD: ppb.c,v 1.60 2017/04/26 08:00:03 msaitoh Exp $	*/
      2   1.1       cgd 
      3   1.1       cgd /*
      4  1.17       cgd  * Copyright (c) 1996, 1998 Christopher G. Demetriou.  All rights reserved.
      5   1.1       cgd  *
      6   1.1       cgd  * Redistribution and use in source and binary forms, with or without
      7   1.1       cgd  * modification, are permitted provided that the following conditions
      8   1.1       cgd  * are met:
      9   1.1       cgd  * 1. Redistributions of source code must retain the above copyright
     10   1.1       cgd  *    notice, this list of conditions and the following disclaimer.
     11   1.1       cgd  * 2. Redistributions in binary form must reproduce the above copyright
     12   1.1       cgd  *    notice, this list of conditions and the following disclaimer in the
     13   1.1       cgd  *    documentation and/or other materials provided with the distribution.
     14   1.1       cgd  * 3. All advertising materials mentioning features or use of this software
     15   1.1       cgd  *    must display the following acknowledgement:
     16   1.1       cgd  *      This product includes software developed by Christopher G. Demetriou
     17   1.1       cgd  *	for the NetBSD Project.
     18   1.1       cgd  * 4. The name of the author may not be used to endorse or promote products
     19   1.1       cgd  *    derived from this software without specific prior written permission
     20   1.1       cgd  *
     21   1.1       cgd  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     22   1.1       cgd  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     23   1.1       cgd  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     24   1.1       cgd  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     25   1.1       cgd  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     26   1.1       cgd  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     27   1.1       cgd  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     28   1.1       cgd  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29   1.1       cgd  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     30   1.1       cgd  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     31   1.1       cgd  */
     32  1.20     lukem 
     33  1.20     lukem #include <sys/cdefs.h>
     34  1.60   msaitoh __KERNEL_RCSID(0, "$NetBSD: ppb.c,v 1.60 2017/04/26 08:00:03 msaitoh Exp $");
     35   1.1       cgd 
     36   1.1       cgd #include <sys/param.h>
     37   1.1       cgd #include <sys/systm.h>
     38   1.1       cgd #include <sys/kernel.h>
     39   1.1       cgd #include <sys/device.h>
     40  1.57   msaitoh #include <sys/evcnt.h>
     41   1.1       cgd 
     42   1.1       cgd #include <dev/pci/pcireg.h>
     43   1.1       cgd #include <dev/pci/pcivar.h>
     44   1.1       cgd #include <dev/pci/ppbreg.h>
     45  1.56   msaitoh #include <dev/pci/ppbvar.h>
     46  1.36  jmcneill #include <dev/pci/pcidevs.h>
     47   1.1       cgd 
     48  1.52   msaitoh #define	PCIE_SLCSR_NOTIFY_MASK					\
     49  1.52   msaitoh 	(PCIE_SLCSR_ABE | PCIE_SLCSR_PFE | PCIE_SLCSR_MSE |	\
     50  1.59   msaitoh 	 PCIE_SLCSR_PDE | PCIE_SLCSR_CCE | PCIE_SLCSR_HPE |	\
     51  1.59   msaitoh 	 PCIE_SLCSR_DLLSCE)
     52  1.44  jmcneill 
     53  1.50      matt static const char pcie_linkspeed_strings[4][5] = {
     54  1.50      matt 	"1.25", "2.5", "5.0", "8.0",
     55  1.50      matt };
     56  1.50      matt 
     57  1.57   msaitoh int	ppb_printevent = 0; /* Print event type if the value is not 0 */
     58  1.57   msaitoh 
     59  1.57   msaitoh static int	ppbmatch(device_t, cfdata_t, void *);
     60  1.57   msaitoh static void	ppbattach(device_t, device_t, void *);
     61  1.57   msaitoh static int	ppbdetach(device_t, int);
     62  1.57   msaitoh static void	ppbchilddet(device_t, device_t);
     63  1.60   msaitoh #ifdef PPB_USEINTR
     64  1.57   msaitoh static int	ppb_intr(void *);
     65  1.60   msaitoh #endif
     66  1.57   msaitoh static bool	ppb_resume(device_t, const pmf_qual_t *);
     67  1.57   msaitoh static bool	ppb_suspend(device_t, const pmf_qual_t *);
     68  1.57   msaitoh 
     69  1.57   msaitoh CFATTACH_DECL3_NEW(ppb, sizeof(struct ppb_softc),
     70  1.57   msaitoh     ppbmatch, ppbattach, ppbdetach, NULL, NULL, ppbchilddet,
     71  1.57   msaitoh     DVF_DETACH_SHUTDOWN);
     72  1.36  jmcneill 
     73  1.31   thorpej static int
     74  1.39    cegger ppbmatch(device_t parent, cfdata_t match, void *aux)
     75   1.1       cgd {
     76   1.1       cgd 	struct pci_attach_args *pa = aux;
     77   1.1       cgd 
     78   1.1       cgd 	/*
     79   1.1       cgd 	 * Check the ID register to see that it's a PCI bridge.
     80   1.1       cgd 	 * If it is, we assume that we can deal with it; it _should_
     81   1.1       cgd 	 * work in a standardized way...
     82   1.1       cgd 	 */
     83   1.1       cgd 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
     84   1.1       cgd 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_PCI)
     85  1.39    cegger 		return 1;
     86   1.1       cgd 
     87  1.43      matt #ifdef __powerpc__
     88  1.43      matt 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_PROCESSOR &&
     89  1.43      matt 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_PROCESSOR_POWERPC) {
     90  1.43      matt 		pcireg_t bhlc = pci_conf_read(pa->pa_pc, pa->pa_tag,
     91  1.43      matt 		    PCI_BHLC_REG);
     92  1.43      matt 		if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_FREESCALE
     93  1.43      matt 		    && PCI_HDRTYPE(bhlc) == PCI_HDRTYPE_RC)
     94  1.43      matt 		return 1;
     95  1.43      matt 	}
     96  1.43      matt #endif
     97  1.43      matt 
     98  1.50      matt #ifdef _MIPS_PADDR_T_64BIT
     99  1.50      matt 	/* The LDT HB acts just like a PPB.  */
    100  1.50      matt 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SIBYTE
    101  1.50      matt 	    && PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SIBYTE_BCM1250_LDTHB)
    102  1.50      matt 		return 1;
    103  1.50      matt #endif
    104  1.50      matt 
    105  1.39    cegger 	return 0;
    106   1.1       cgd }
    107   1.1       cgd 
    108  1.31   thorpej static void
    109  1.57   msaitoh ppb_print_pcie(device_t self)
    110  1.35     joerg {
    111  1.36  jmcneill 	struct ppb_softc *sc = device_private(self);
    112  1.35     joerg 	pcireg_t reg;
    113  1.55   msaitoh 	int off, capversion, devtype;
    114  1.35     joerg 
    115  1.36  jmcneill 	if (!pci_get_capability(sc->sc_pc, sc->sc_tag, PCI_CAP_PCIEXPRESS,
    116  1.35     joerg 				&off, &reg))
    117  1.35     joerg 		return; /* Not a PCIe device */
    118  1.35     joerg 
    119  1.55   msaitoh 	capversion = PCIE_XCAP_VER(reg);
    120  1.55   msaitoh 	devtype = PCIE_XCAP_TYPE(reg);
    121  1.53   msaitoh 	aprint_normal_dev(self, "PCI Express capability version ");
    122  1.55   msaitoh 	switch (capversion) {
    123  1.54   msaitoh 	case PCIE_XCAP_VER_1:
    124  1.53   msaitoh 		aprint_normal("1");
    125  1.45    cegger 		break;
    126  1.54   msaitoh 	case PCIE_XCAP_VER_2:
    127  1.53   msaitoh 		aprint_normal("2");
    128  1.44  jmcneill 		break;
    129  1.44  jmcneill 	default:
    130  1.55   msaitoh 		aprint_normal_dev(self, "unsupported (%d)\n", capversion);
    131  1.35     joerg 		return;
    132  1.35     joerg 	}
    133  1.44  jmcneill 	aprint_normal(" <");
    134  1.55   msaitoh 	switch (devtype) {
    135  1.52   msaitoh 	case PCIE_XCAP_TYPE_PCIE_DEV:
    136  1.44  jmcneill 		aprint_normal("PCI-E Endpoint device");
    137  1.44  jmcneill 		break;
    138  1.52   msaitoh 	case PCIE_XCAP_TYPE_PCI_DEV:
    139  1.44  jmcneill 		aprint_normal("Legacy PCI-E Endpoint device");
    140  1.44  jmcneill 		break;
    141  1.52   msaitoh 	case PCIE_XCAP_TYPE_ROOT:
    142  1.44  jmcneill 		aprint_normal("Root Port of PCI-E Root Complex");
    143  1.44  jmcneill 		break;
    144  1.52   msaitoh 	case PCIE_XCAP_TYPE_UP:
    145  1.44  jmcneill 		aprint_normal("Upstream Port of PCI-E Switch");
    146  1.44  jmcneill 		break;
    147  1.52   msaitoh 	case PCIE_XCAP_TYPE_DOWN:
    148  1.44  jmcneill 		aprint_normal("Downstream Port of PCI-E Switch");
    149  1.44  jmcneill 		break;
    150  1.52   msaitoh 	case PCIE_XCAP_TYPE_PCIE2PCI:
    151  1.44  jmcneill 		aprint_normal("PCI-E to PCI/PCI-X Bridge");
    152  1.44  jmcneill 		break;
    153  1.52   msaitoh 	case PCIE_XCAP_TYPE_PCI2PCIE:
    154  1.44  jmcneill 		aprint_normal("PCI/PCI-X to PCI-E Bridge");
    155  1.44  jmcneill 		break;
    156  1.44  jmcneill 	default:
    157  1.55   msaitoh 		aprint_normal("Device/Port Type %x", devtype);
    158  1.44  jmcneill 		break;
    159  1.44  jmcneill 	}
    160  1.50      matt 
    161  1.55   msaitoh 	switch (devtype) {
    162  1.52   msaitoh 	case PCIE_XCAP_TYPE_ROOT:
    163  1.52   msaitoh 	case PCIE_XCAP_TYPE_DOWN:
    164  1.52   msaitoh 	case PCIE_XCAP_TYPE_PCI2PCIE:
    165  1.53   msaitoh 		reg = pci_conf_read(sc->sc_pc, sc->sc_tag, off + PCIE_LCAP);
    166  1.53   msaitoh 		u_int mlw = __SHIFTOUT(reg, PCIE_LCAP_MAX_WIDTH);
    167  1.53   msaitoh 		u_int mls = __SHIFTOUT(reg, PCIE_LCAP_MAX_SPEED);
    168  1.53   msaitoh 
    169  1.50      matt 		if (mls < __arraycount(pcie_linkspeed_strings)) {
    170  1.53   msaitoh 			aprint_normal("> x%d @ %sGT/s\n",
    171  1.50      matt 			    mlw, pcie_linkspeed_strings[mls]);
    172  1.50      matt 		} else {
    173  1.53   msaitoh 			aprint_normal("> x%d @ %d.%dGT/s\n",
    174  1.50      matt 			    mlw, (mls * 25) / 10, (mls * 25) % 10);
    175  1.50      matt 		}
    176  1.50      matt 
    177  1.53   msaitoh 		reg = pci_conf_read(sc->sc_pc, sc->sc_tag, off + PCIE_LCSR);
    178  1.53   msaitoh 		if (reg & PCIE_LCSR_DLACTIVE) {	/* DLLA */
    179  1.53   msaitoh 			u_int lw = __SHIFTOUT(reg, PCIE_LCSR_NLW);
    180  1.53   msaitoh 			u_int ls = __SHIFTOUT(reg, PCIE_LCSR_LINKSPEED);
    181  1.53   msaitoh 
    182  1.50      matt 			if (lw != mlw || ls != mls) {
    183  1.50      matt 				if (ls < __arraycount(pcie_linkspeed_strings)) {
    184  1.51      yamt 					aprint_normal_dev(self,
    185  1.53   msaitoh 					    "link is x%d @ %sGT/s\n",
    186  1.50      matt 					    lw, pcie_linkspeed_strings[ls]);
    187  1.50      matt 				} else {
    188  1.50      matt 					aprint_normal_dev(self,
    189  1.53   msaitoh 					    "link is x%d @ %d.%dGT/s\n",
    190  1.50      matt 					    lw, (ls * 25) / 10, (ls * 25) % 10);
    191  1.50      matt 				}
    192  1.50      matt 			}
    193  1.50      matt 		}
    194  1.50      matt 		break;
    195  1.50      matt 	default:
    196  1.50      matt 		aprint_normal(">\n");
    197  1.50      matt 		break;
    198  1.50      matt 	}
    199  1.35     joerg }
    200  1.35     joerg 
    201  1.35     joerg static void
    202  1.37    dyoung ppbattach(device_t parent, device_t self, void *aux)
    203   1.1       cgd {
    204  1.37    dyoung 	struct ppb_softc *sc = device_private(self);
    205   1.1       cgd 	struct pci_attach_args *pa = aux;
    206   1.7       cgd 	pci_chipset_tag_t pc = pa->pa_pc;
    207   1.1       cgd 	struct pcibus_attach_args pba;
    208  1.60   msaitoh #ifdef PPB_USEINTR
    209  1.57   msaitoh 	char const *intrstr;
    210  1.57   msaitoh 	char intrbuf[PCI_INTRSTR_LEN];
    211  1.60   msaitoh #endif
    212  1.57   msaitoh 	pcireg_t busdata, reg;
    213   1.1       cgd 
    214  1.49  drochner 	pci_aprint_devinfo(pa, NULL);
    215   1.1       cgd 
    216  1.21   thorpej 	sc->sc_pc = pc;
    217  1.21   thorpej 	sc->sc_tag = pa->pa_tag;
    218  1.39    cegger 	sc->sc_dev = self;
    219  1.21   thorpej 
    220   1.7       cgd 	busdata = pci_conf_read(pc, pa->pa_tag, PPB_REG_BUSINFO);
    221   1.1       cgd 
    222   1.7       cgd 	if (PPB_BUSINFO_SECONDARY(busdata) == 0) {
    223  1.37    dyoung 		aprint_normal_dev(self, "not configured by system firmware\n");
    224   1.1       cgd 		return;
    225   1.1       cgd 	}
    226   1.1       cgd 
    227  1.57   msaitoh 	ppb_print_pcie(self);
    228  1.35     joerg 
    229   1.1       cgd #if 0
    230   1.1       cgd 	/*
    231   1.1       cgd 	 * XXX can't do this, because we're not given our bus number
    232   1.7       cgd 	 * (we shouldn't need it), and because we've no way to
    233   1.7       cgd 	 * decompose our tag.
    234   1.1       cgd 	 */
    235   1.1       cgd 	/* sanity check. */
    236   1.7       cgd 	if (pa->pa_bus != PPB_BUSINFO_PRIMARY(busdata))
    237   1.1       cgd 		panic("ppbattach: bus in tag (%d) != bus in reg (%d)",
    238   1.7       cgd 		    pa->pa_bus, PPB_BUSINFO_PRIMARY(busdata));
    239   1.1       cgd #endif
    240   1.1       cgd 
    241  1.57   msaitoh 	/* Check for PCI Express capabilities and setup hotplug support. */
    242  1.57   msaitoh 	if (pci_get_capability(pc, pa->pa_tag, PCI_CAP_PCIEXPRESS,
    243  1.57   msaitoh 	    &sc->sc_pciecapoff, &reg) && (reg & PCIE_XCAP_SI)) {
    244  1.60   msaitoh #ifdef PPB_USEINTR
    245  1.57   msaitoh #if 0
    246  1.57   msaitoh 		/*
    247  1.57   msaitoh 		 * XXX Initialize workqueue or something else for
    248  1.57   msaitoh 		 * HotPlug support.
    249  1.57   msaitoh 		 */
    250  1.57   msaitoh #endif
    251  1.57   msaitoh 
    252  1.57   msaitoh 		if (pci_intr_alloc(pa, &sc->sc_pihp, NULL, 0) == 0)
    253  1.57   msaitoh 			sc->sc_intrhand = pci_intr_establish_xname(pc,
    254  1.57   msaitoh 			    sc->sc_pihp[0], IPL_BIO, ppb_intr, sc,
    255  1.57   msaitoh 			    device_xname(sc->sc_dev));
    256  1.57   msaitoh 
    257  1.57   msaitoh 		if (sc->sc_intrhand) {
    258  1.57   msaitoh 			pcireg_t slcap, slcsr, val;
    259  1.57   msaitoh 
    260  1.57   msaitoh 			intrstr = pci_intr_string(pc, sc->sc_pihp[0], intrbuf,
    261  1.57   msaitoh 			    sizeof(intrbuf));
    262  1.57   msaitoh 			aprint_normal_dev(self, "%s\n", intrstr);
    263  1.57   msaitoh 
    264  1.57   msaitoh 			/* Clear any pending events */
    265  1.57   msaitoh 			slcsr = pci_conf_read(pc, pa->pa_tag,
    266  1.57   msaitoh 			    sc->sc_pciecapoff + PCIE_SLCSR);
    267  1.57   msaitoh 			pci_conf_write(pc, pa->pa_tag,
    268  1.57   msaitoh 			    sc->sc_pciecapoff + PCIE_SLCSR, slcsr);
    269  1.57   msaitoh 
    270  1.57   msaitoh 			/* Enable interrupt. */
    271  1.57   msaitoh 			slcap = pci_conf_read(pc, pa->pa_tag,
    272  1.57   msaitoh 			    sc->sc_pciecapoff + PCIE_SLCAP);
    273  1.57   msaitoh 			val = 0;
    274  1.57   msaitoh 			if (slcap & PCIE_SLCAP_ABP)
    275  1.57   msaitoh 				val |= PCIE_SLCSR_ABE;
    276  1.57   msaitoh 			if (slcap & PCIE_SLCAP_PCP)
    277  1.57   msaitoh 				val |= PCIE_SLCSR_PFE;
    278  1.57   msaitoh 			if (slcap & PCIE_SLCAP_MSP)
    279  1.57   msaitoh 				val |= PCIE_SLCSR_MSE;
    280  1.57   msaitoh 			if ((slcap & PCIE_SLCAP_NCCS) == 0)
    281  1.57   msaitoh 				val |= PCIE_SLCSR_CCE;
    282  1.57   msaitoh 			/* Attention indicator off by default */
    283  1.57   msaitoh 			if (slcap & PCIE_SLCAP_AIP) {
    284  1.57   msaitoh 				val |= __SHIFTIN(PCIE_SLCSR_IND_OFF,
    285  1.57   msaitoh 				    PCIE_SLCSR_AIC);
    286  1.57   msaitoh 			}
    287  1.57   msaitoh 			/* Power indicator */
    288  1.57   msaitoh 			if (slcap & PCIE_SLCAP_PIP) {
    289  1.57   msaitoh 				/*
    290  1.57   msaitoh 				 * Indicator off:
    291  1.57   msaitoh 				 *  a) card not present
    292  1.57   msaitoh 				 *  b) power fault
    293  1.57   msaitoh 				 *  c) MRL sensor off
    294  1.57   msaitoh 				 */
    295  1.57   msaitoh 				if (((slcsr & PCIE_SLCSR_PDS) == 0)
    296  1.57   msaitoh 				    || ((slcsr & PCIE_SLCSR_PFD) != 0)
    297  1.57   msaitoh 				    || (((slcap & PCIE_SLCAP_MSP) != 0)
    298  1.57   msaitoh 					&& ((slcsr & PCIE_SLCSR_MS) != 0)))
    299  1.57   msaitoh 					val |= __SHIFTIN(PCIE_SLCSR_IND_OFF,
    300  1.57   msaitoh 					    PCIE_SLCSR_PIC);
    301  1.57   msaitoh 				else
    302  1.57   msaitoh 					val |= __SHIFTIN(PCIE_SLCSR_IND_ON,
    303  1.57   msaitoh 					    PCIE_SLCSR_PIC);
    304  1.57   msaitoh 			}
    305  1.57   msaitoh 
    306  1.57   msaitoh 			val |= PCIE_SLCSR_DLLSCE | PCIE_SLCSR_HPE
    307  1.57   msaitoh 			    | PCIE_SLCSR_PDE;
    308  1.57   msaitoh 			slcsr = val;
    309  1.57   msaitoh 			pci_conf_write(pc, pa->pa_tag,
    310  1.57   msaitoh 			    sc->sc_pciecapoff + PCIE_SLCSR, slcsr);
    311  1.57   msaitoh 		}
    312  1.60   msaitoh #else
    313  1.60   msaitoh 		reg = pci_conf_read(sc->sc_pc, sc->sc_tag,
    314  1.60   msaitoh 		    sc->sc_pciecapoff + PCIE_SLCSR);
    315  1.60   msaitoh 		if (reg & PCIE_SLCSR_NOTIFY_MASK) {
    316  1.60   msaitoh 			aprint_debug_dev(self,
    317  1.60   msaitoh 			    "disabling notification events\n");
    318  1.60   msaitoh 			reg &= ~PCIE_SLCSR_NOTIFY_MASK;
    319  1.60   msaitoh 			pci_conf_write(sc->sc_pc, sc->sc_tag,
    320  1.60   msaitoh 			    sc->sc_pciecapoff + PCIE_SLCSR, reg);
    321  1.60   msaitoh 		}
    322  1.60   msaitoh #endif /* PPB_USEINTR */
    323  1.57   msaitoh 	}
    324  1.57   msaitoh 
    325  1.36  jmcneill 	if (!pmf_device_register(self, ppb_suspend, ppb_resume))
    326  1.36  jmcneill 		aprint_error_dev(self, "couldn't establish power handler\n");
    327  1.36  jmcneill 
    328   1.1       cgd 	/*
    329   1.1       cgd 	 * Attach the PCI bus than hangs off of it.
    330  1.19   thorpej 	 *
    331  1.19   thorpej 	 * XXX Don't pass-through Memory Read Multiple.  Should we?
    332  1.19   thorpej 	 * XXX Consult the spec...
    333   1.1       cgd 	 */
    334  1.12   thorpej 	pba.pba_iot = pa->pa_iot;
    335  1.12   thorpej 	pba.pba_memt = pa->pa_memt;
    336  1.15   mycroft 	pba.pba_dmat = pa->pa_dmat;
    337  1.26      fvdl 	pba.pba_dmat64 = pa->pa_dmat64;
    338   1.7       cgd 	pba.pba_pc = pc;
    339  1.19   thorpej 	pba.pba_flags = pa->pa_flags & ~PCI_FLAGS_MRM_OKAY;
    340   1.7       cgd 	pba.pba_bus = PPB_BUSINFO_SECONDARY(busdata);
    341  1.47    dyoung 	pba.pba_sub = PPB_BUSINFO_SUBORDINATE(busdata);
    342  1.21   thorpej 	pba.pba_bridgetag = &sc->sc_tag;
    343   1.7       cgd 	pba.pba_intrswiz = pa->pa_intrswiz;
    344   1.7       cgd 	pba.pba_intrtag = pa->pa_intrtag;
    345   1.1       cgd 
    346  1.60   msaitoh #ifdef PPB_USEINTR
    347  1.57   msaitoh 	/* Attach event counters */
    348  1.57   msaitoh 	evcnt_attach_dynamic(&sc->sc_ev_intr, EVCNT_TYPE_INTR, NULL,
    349  1.57   msaitoh 	    device_xname(sc->sc_dev), "Interrupt");
    350  1.57   msaitoh 	evcnt_attach_dynamic(&sc->sc_ev_abp, EVCNT_TYPE_MISC, NULL,
    351  1.57   msaitoh 	    device_xname(sc->sc_dev), "Attention Button Pressed");
    352  1.57   msaitoh 	evcnt_attach_dynamic(&sc->sc_ev_pfd, EVCNT_TYPE_MISC, NULL,
    353  1.57   msaitoh 	    device_xname(sc->sc_dev), "Power Fault Detected");
    354  1.57   msaitoh 	evcnt_attach_dynamic(&sc->sc_ev_msc, EVCNT_TYPE_MISC, NULL,
    355  1.57   msaitoh 	    device_xname(sc->sc_dev), "MRL Sensor Changed");
    356  1.57   msaitoh 	evcnt_attach_dynamic(&sc->sc_ev_pdc, EVCNT_TYPE_MISC, NULL,
    357  1.57   msaitoh 	    device_xname(sc->sc_dev), "Presence Detect Changed");
    358  1.57   msaitoh 	evcnt_attach_dynamic(&sc->sc_ev_cc, EVCNT_TYPE_MISC, NULL,
    359  1.57   msaitoh 	    device_xname(sc->sc_dev), "Command Completed");
    360  1.57   msaitoh 	evcnt_attach_dynamic(&sc->sc_ev_lacs, EVCNT_TYPE_MISC, NULL,
    361  1.57   msaitoh 	    device_xname(sc->sc_dev), "Data Link Layer State Changed");
    362  1.60   msaitoh #endif
    363  1.57   msaitoh 
    364  1.29  drochner 	config_found_ia(self, "pcibus", &pba, pcibusprint);
    365   1.1       cgd }
    366  1.31   thorpej 
    367  1.37    dyoung static int
    368  1.37    dyoung ppbdetach(device_t self, int flags)
    369  1.37    dyoung {
    370  1.60   msaitoh #ifdef PPB_USEINTR
    371  1.57   msaitoh 	struct ppb_softc *sc = device_private(self);
    372  1.59   msaitoh 	pcireg_t slcsr;
    373  1.60   msaitoh #endif
    374  1.37    dyoung 	int rc;
    375  1.37    dyoung 
    376  1.58       chs 	if ((rc = config_detach_children(self, flags)) != 0)
    377  1.58       chs 		return rc;
    378  1.58       chs 
    379  1.60   msaitoh #ifdef PPB_USEINTR
    380  1.57   msaitoh 	/* Detach event counters */
    381  1.57   msaitoh 	evcnt_detach(&sc->sc_ev_intr);
    382  1.57   msaitoh 	evcnt_detach(&sc->sc_ev_abp);
    383  1.57   msaitoh 	evcnt_detach(&sc->sc_ev_pfd);
    384  1.57   msaitoh 	evcnt_detach(&sc->sc_ev_msc);
    385  1.57   msaitoh 	evcnt_detach(&sc->sc_ev_pdc);
    386  1.57   msaitoh 	evcnt_detach(&sc->sc_ev_cc);
    387  1.57   msaitoh 	evcnt_detach(&sc->sc_ev_lacs);
    388  1.57   msaitoh 
    389  1.59   msaitoh 	/* Clear any pending events and disable interrupt */
    390  1.59   msaitoh 	slcsr = pci_conf_read(sc->sc_pc, sc->sc_tag,
    391  1.59   msaitoh 	      sc->sc_pciecapoff + PCIE_SLCSR);
    392  1.59   msaitoh 	slcsr &= ~PCIE_SLCSR_NOTIFY_MASK;
    393  1.59   msaitoh 	pci_conf_write(sc->sc_pc, sc->sc_tag,
    394  1.59   msaitoh 		sc->sc_pciecapoff + PCIE_SLCSR, slcsr);
    395  1.59   msaitoh 
    396  1.59   msaitoh 	/* Disestablish the interrupt handler */
    397  1.59   msaitoh 	if (sc->sc_intrhand != NULL) {
    398  1.59   msaitoh 		pci_intr_disestablish(sc->sc_pc, sc->sc_intrhand);
    399  1.59   msaitoh 		pci_intr_release(sc->sc_pc, sc->sc_pihp, 1);
    400  1.59   msaitoh 	}
    401  1.60   msaitoh #endif
    402  1.59   msaitoh 
    403  1.37    dyoung 	pmf_device_deregister(self);
    404  1.37    dyoung 	return 0;
    405  1.37    dyoung }
    406  1.37    dyoung 
    407  1.36  jmcneill static bool
    408  1.42    dyoung ppb_resume(device_t dv, const pmf_qual_t *qual)
    409  1.36  jmcneill {
    410  1.36  jmcneill 	struct ppb_softc *sc = device_private(dv);
    411  1.36  jmcneill 	int off;
    412  1.36  jmcneill 	pcireg_t val;
    413  1.36  jmcneill 
    414  1.36  jmcneill         for (off = 0x40; off <= 0xff; off += 4) {
    415  1.36  jmcneill 		val = pci_conf_read(sc->sc_pc, sc->sc_tag, off);
    416  1.36  jmcneill 		if (val != sc->sc_pciconfext[(off - 0x40) / 4])
    417  1.36  jmcneill 			pci_conf_write(sc->sc_pc, sc->sc_tag, off,
    418  1.36  jmcneill 			    sc->sc_pciconfext[(off - 0x40)/4]);
    419  1.36  jmcneill 	}
    420  1.36  jmcneill 
    421  1.36  jmcneill 	return true;
    422  1.36  jmcneill }
    423  1.36  jmcneill 
    424  1.36  jmcneill static bool
    425  1.42    dyoung ppb_suspend(device_t dv, const pmf_qual_t *qual)
    426  1.36  jmcneill {
    427  1.36  jmcneill 	struct ppb_softc *sc = device_private(dv);
    428  1.36  jmcneill 	int off;
    429  1.36  jmcneill 
    430  1.36  jmcneill 	for (off = 0x40; off <= 0xff; off += 4)
    431  1.36  jmcneill 		sc->sc_pciconfext[(off - 0x40) / 4] =
    432  1.36  jmcneill 		    pci_conf_read(sc->sc_pc, sc->sc_tag, off);
    433  1.36  jmcneill 
    434  1.36  jmcneill 	return true;
    435  1.36  jmcneill }
    436  1.36  jmcneill 
    437  1.37    dyoung static void
    438  1.37    dyoung ppbchilddet(device_t self, device_t child)
    439  1.37    dyoung {
    440  1.37    dyoung 	/* we keep no references to child devices, so do nothing */
    441  1.37    dyoung }
    442  1.37    dyoung 
    443  1.60   msaitoh #ifdef PPB_USEINTR
    444  1.57   msaitoh static int
    445  1.57   msaitoh ppb_intr(void *arg)
    446  1.57   msaitoh {
    447  1.57   msaitoh 	struct ppb_softc *sc = arg;
    448  1.57   msaitoh 	device_t dev = sc->sc_dev;
    449  1.57   msaitoh 	pcireg_t reg;
    450  1.57   msaitoh 
    451  1.57   msaitoh 	sc->sc_ev_intr.ev_count++;
    452  1.57   msaitoh 	reg = pci_conf_read(sc->sc_pc, sc->sc_tag,
    453  1.57   msaitoh 	    sc->sc_pciecapoff + PCIE_SLCSR);
    454  1.57   msaitoh 
    455  1.57   msaitoh 	/* Clear interrupts. */
    456  1.57   msaitoh 	pci_conf_write(sc->sc_pc, sc->sc_tag,
    457  1.57   msaitoh 	    sc->sc_pciecapoff + PCIE_SLCSR, reg);
    458  1.57   msaitoh 
    459  1.57   msaitoh 	/* Attention Button Pressed */
    460  1.57   msaitoh 	if (reg & PCIE_SLCSR_ABP) {
    461  1.57   msaitoh 		sc->sc_ev_abp.ev_count++;
    462  1.57   msaitoh 		if (ppb_printevent)
    463  1.57   msaitoh 			device_printf(dev, "Attention Button Pressed\n");
    464  1.57   msaitoh 	}
    465  1.57   msaitoh 
    466  1.57   msaitoh 	/* Power Fault Detected */
    467  1.57   msaitoh 	if (reg & PCIE_SLCSR_PFD) {
    468  1.57   msaitoh 		sc->sc_ev_pfd.ev_count++;
    469  1.57   msaitoh 		if (ppb_printevent)
    470  1.57   msaitoh 			device_printf(dev, "Power Fault Detected\n");
    471  1.57   msaitoh 	}
    472  1.57   msaitoh 
    473  1.57   msaitoh 	/* MRL Sensor Changed */
    474  1.57   msaitoh 	if (reg & PCIE_SLCSR_MSC) {
    475  1.57   msaitoh 		sc->sc_ev_msc.ev_count++;
    476  1.57   msaitoh 		if (ppb_printevent)
    477  1.57   msaitoh 			device_printf(dev, "MRL Sensor Changed\n");
    478  1.57   msaitoh 	}
    479  1.57   msaitoh 
    480  1.57   msaitoh 	/* Presence Detect Changed */
    481  1.57   msaitoh 	if (reg & PCIE_SLCSR_PDC) {
    482  1.57   msaitoh 		sc->sc_ev_pdc.ev_count++;
    483  1.57   msaitoh 		if (ppb_printevent)
    484  1.57   msaitoh 			device_printf(dev, "Presence Detect Changed\n");
    485  1.57   msaitoh 		if (reg & PCIE_SLCSR_PDS) {
    486  1.57   msaitoh 			/* XXX Insert */
    487  1.57   msaitoh 		} else {
    488  1.57   msaitoh 			/* XXX Remove */
    489  1.57   msaitoh 		}
    490  1.57   msaitoh 	}
    491  1.57   msaitoh 
    492  1.57   msaitoh 	/* Command Completed */
    493  1.57   msaitoh 	if (reg & PCIE_SLCSR_CC) {
    494  1.57   msaitoh 		sc->sc_ev_cc.ev_count++;
    495  1.57   msaitoh 		if (ppb_printevent)
    496  1.57   msaitoh 			device_printf(dev, "Command Completed\n");
    497  1.57   msaitoh 	}
    498  1.57   msaitoh 
    499  1.57   msaitoh 	/* Data Link Layer State Changed */
    500  1.57   msaitoh 	if (reg & PCIE_SLCSR_LACS) {
    501  1.57   msaitoh 		sc->sc_ev_lacs.ev_count++;
    502  1.57   msaitoh 		if (ppb_printevent)
    503  1.57   msaitoh 			device_printf(dev, "Data Link Layer State Changed\n");
    504  1.57   msaitoh 	}
    505  1.57   msaitoh 
    506  1.57   msaitoh 	return 0;
    507  1.57   msaitoh }
    508  1.60   msaitoh #endif /* PPB_USEINTR */
    509