Home | History | Annotate | Line # | Download | only in pci
ppb.c revision 1.59
      1  1.59   msaitoh /*	$NetBSD: ppb.c,v 1.59 2017/04/26 03:54:37 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.59   msaitoh __KERNEL_RCSID(0, "$NetBSD: ppb.c,v 1.59 2017/04/26 03:54:37 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.57   msaitoh static int	ppb_intr(void *);
     64  1.57   msaitoh static bool	ppb_resume(device_t, const pmf_qual_t *);
     65  1.57   msaitoh static bool	ppb_suspend(device_t, const pmf_qual_t *);
     66  1.57   msaitoh 
     67  1.57   msaitoh CFATTACH_DECL3_NEW(ppb, sizeof(struct ppb_softc),
     68  1.57   msaitoh     ppbmatch, ppbattach, ppbdetach, NULL, NULL, ppbchilddet,
     69  1.57   msaitoh     DVF_DETACH_SHUTDOWN);
     70  1.36  jmcneill 
     71  1.31   thorpej static int
     72  1.39    cegger ppbmatch(device_t parent, cfdata_t match, void *aux)
     73   1.1       cgd {
     74   1.1       cgd 	struct pci_attach_args *pa = aux;
     75   1.1       cgd 
     76   1.1       cgd 	/*
     77   1.1       cgd 	 * Check the ID register to see that it's a PCI bridge.
     78   1.1       cgd 	 * If it is, we assume that we can deal with it; it _should_
     79   1.1       cgd 	 * work in a standardized way...
     80   1.1       cgd 	 */
     81   1.1       cgd 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
     82   1.1       cgd 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_PCI)
     83  1.39    cegger 		return 1;
     84   1.1       cgd 
     85  1.43      matt #ifdef __powerpc__
     86  1.43      matt 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_PROCESSOR &&
     87  1.43      matt 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_PROCESSOR_POWERPC) {
     88  1.43      matt 		pcireg_t bhlc = pci_conf_read(pa->pa_pc, pa->pa_tag,
     89  1.43      matt 		    PCI_BHLC_REG);
     90  1.43      matt 		if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_FREESCALE
     91  1.43      matt 		    && PCI_HDRTYPE(bhlc) == PCI_HDRTYPE_RC)
     92  1.43      matt 		return 1;
     93  1.43      matt 	}
     94  1.43      matt #endif
     95  1.43      matt 
     96  1.50      matt #ifdef _MIPS_PADDR_T_64BIT
     97  1.50      matt 	/* The LDT HB acts just like a PPB.  */
     98  1.50      matt 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SIBYTE
     99  1.50      matt 	    && PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SIBYTE_BCM1250_LDTHB)
    100  1.50      matt 		return 1;
    101  1.50      matt #endif
    102  1.50      matt 
    103  1.39    cegger 	return 0;
    104   1.1       cgd }
    105   1.1       cgd 
    106  1.31   thorpej static void
    107  1.57   msaitoh ppb_print_pcie(device_t self)
    108  1.35     joerg {
    109  1.36  jmcneill 	struct ppb_softc *sc = device_private(self);
    110  1.35     joerg 	pcireg_t reg;
    111  1.55   msaitoh 	int off, capversion, devtype;
    112  1.35     joerg 
    113  1.36  jmcneill 	if (!pci_get_capability(sc->sc_pc, sc->sc_tag, PCI_CAP_PCIEXPRESS,
    114  1.35     joerg 				&off, &reg))
    115  1.35     joerg 		return; /* Not a PCIe device */
    116  1.35     joerg 
    117  1.55   msaitoh 	capversion = PCIE_XCAP_VER(reg);
    118  1.55   msaitoh 	devtype = PCIE_XCAP_TYPE(reg);
    119  1.53   msaitoh 	aprint_normal_dev(self, "PCI Express capability version ");
    120  1.55   msaitoh 	switch (capversion) {
    121  1.54   msaitoh 	case PCIE_XCAP_VER_1:
    122  1.53   msaitoh 		aprint_normal("1");
    123  1.45    cegger 		break;
    124  1.54   msaitoh 	case PCIE_XCAP_VER_2:
    125  1.53   msaitoh 		aprint_normal("2");
    126  1.44  jmcneill 		break;
    127  1.44  jmcneill 	default:
    128  1.55   msaitoh 		aprint_normal_dev(self, "unsupported (%d)\n", capversion);
    129  1.35     joerg 		return;
    130  1.35     joerg 	}
    131  1.44  jmcneill 	aprint_normal(" <");
    132  1.55   msaitoh 	switch (devtype) {
    133  1.52   msaitoh 	case PCIE_XCAP_TYPE_PCIE_DEV:
    134  1.44  jmcneill 		aprint_normal("PCI-E Endpoint device");
    135  1.44  jmcneill 		break;
    136  1.52   msaitoh 	case PCIE_XCAP_TYPE_PCI_DEV:
    137  1.44  jmcneill 		aprint_normal("Legacy PCI-E Endpoint device");
    138  1.44  jmcneill 		break;
    139  1.52   msaitoh 	case PCIE_XCAP_TYPE_ROOT:
    140  1.44  jmcneill 		aprint_normal("Root Port of PCI-E Root Complex");
    141  1.44  jmcneill 		break;
    142  1.52   msaitoh 	case PCIE_XCAP_TYPE_UP:
    143  1.44  jmcneill 		aprint_normal("Upstream Port of PCI-E Switch");
    144  1.44  jmcneill 		break;
    145  1.52   msaitoh 	case PCIE_XCAP_TYPE_DOWN:
    146  1.44  jmcneill 		aprint_normal("Downstream Port of PCI-E Switch");
    147  1.44  jmcneill 		break;
    148  1.52   msaitoh 	case PCIE_XCAP_TYPE_PCIE2PCI:
    149  1.44  jmcneill 		aprint_normal("PCI-E to PCI/PCI-X Bridge");
    150  1.44  jmcneill 		break;
    151  1.52   msaitoh 	case PCIE_XCAP_TYPE_PCI2PCIE:
    152  1.44  jmcneill 		aprint_normal("PCI/PCI-X to PCI-E Bridge");
    153  1.44  jmcneill 		break;
    154  1.44  jmcneill 	default:
    155  1.55   msaitoh 		aprint_normal("Device/Port Type %x", devtype);
    156  1.44  jmcneill 		break;
    157  1.44  jmcneill 	}
    158  1.50      matt 
    159  1.55   msaitoh 	switch (devtype) {
    160  1.52   msaitoh 	case PCIE_XCAP_TYPE_ROOT:
    161  1.52   msaitoh 	case PCIE_XCAP_TYPE_DOWN:
    162  1.52   msaitoh 	case PCIE_XCAP_TYPE_PCI2PCIE:
    163  1.53   msaitoh 		reg = pci_conf_read(sc->sc_pc, sc->sc_tag, off + PCIE_LCAP);
    164  1.53   msaitoh 		u_int mlw = __SHIFTOUT(reg, PCIE_LCAP_MAX_WIDTH);
    165  1.53   msaitoh 		u_int mls = __SHIFTOUT(reg, PCIE_LCAP_MAX_SPEED);
    166  1.53   msaitoh 
    167  1.50      matt 		if (mls < __arraycount(pcie_linkspeed_strings)) {
    168  1.53   msaitoh 			aprint_normal("> x%d @ %sGT/s\n",
    169  1.50      matt 			    mlw, pcie_linkspeed_strings[mls]);
    170  1.50      matt 		} else {
    171  1.53   msaitoh 			aprint_normal("> x%d @ %d.%dGT/s\n",
    172  1.50      matt 			    mlw, (mls * 25) / 10, (mls * 25) % 10);
    173  1.50      matt 		}
    174  1.50      matt 
    175  1.53   msaitoh 		reg = pci_conf_read(sc->sc_pc, sc->sc_tag, off + PCIE_LCSR);
    176  1.53   msaitoh 		if (reg & PCIE_LCSR_DLACTIVE) {	/* DLLA */
    177  1.53   msaitoh 			u_int lw = __SHIFTOUT(reg, PCIE_LCSR_NLW);
    178  1.53   msaitoh 			u_int ls = __SHIFTOUT(reg, PCIE_LCSR_LINKSPEED);
    179  1.53   msaitoh 
    180  1.50      matt 			if (lw != mlw || ls != mls) {
    181  1.50      matt 				if (ls < __arraycount(pcie_linkspeed_strings)) {
    182  1.51      yamt 					aprint_normal_dev(self,
    183  1.53   msaitoh 					    "link is x%d @ %sGT/s\n",
    184  1.50      matt 					    lw, pcie_linkspeed_strings[ls]);
    185  1.50      matt 				} else {
    186  1.50      matt 					aprint_normal_dev(self,
    187  1.53   msaitoh 					    "link is x%d @ %d.%dGT/s\n",
    188  1.50      matt 					    lw, (ls * 25) / 10, (ls * 25) % 10);
    189  1.50      matt 				}
    190  1.50      matt 			}
    191  1.50      matt 		}
    192  1.50      matt 		break;
    193  1.50      matt 	default:
    194  1.50      matt 		aprint_normal(">\n");
    195  1.50      matt 		break;
    196  1.50      matt 	}
    197  1.35     joerg }
    198  1.35     joerg 
    199  1.35     joerg static void
    200  1.37    dyoung ppbattach(device_t parent, device_t self, void *aux)
    201   1.1       cgd {
    202  1.37    dyoung 	struct ppb_softc *sc = device_private(self);
    203   1.1       cgd 	struct pci_attach_args *pa = aux;
    204   1.7       cgd 	pci_chipset_tag_t pc = pa->pa_pc;
    205   1.1       cgd 	struct pcibus_attach_args pba;
    206  1.57   msaitoh 	char const *intrstr;
    207  1.57   msaitoh 	char intrbuf[PCI_INTRSTR_LEN];
    208  1.57   msaitoh 	pcireg_t busdata, reg;
    209   1.1       cgd 
    210  1.49  drochner 	pci_aprint_devinfo(pa, NULL);
    211   1.1       cgd 
    212  1.21   thorpej 	sc->sc_pc = pc;
    213  1.21   thorpej 	sc->sc_tag = pa->pa_tag;
    214  1.39    cegger 	sc->sc_dev = self;
    215  1.21   thorpej 
    216   1.7       cgd 	busdata = pci_conf_read(pc, pa->pa_tag, PPB_REG_BUSINFO);
    217   1.1       cgd 
    218   1.7       cgd 	if (PPB_BUSINFO_SECONDARY(busdata) == 0) {
    219  1.37    dyoung 		aprint_normal_dev(self, "not configured by system firmware\n");
    220   1.1       cgd 		return;
    221   1.1       cgd 	}
    222   1.1       cgd 
    223  1.57   msaitoh 	ppb_print_pcie(self);
    224  1.35     joerg 
    225   1.1       cgd #if 0
    226   1.1       cgd 	/*
    227   1.1       cgd 	 * XXX can't do this, because we're not given our bus number
    228   1.7       cgd 	 * (we shouldn't need it), and because we've no way to
    229   1.7       cgd 	 * decompose our tag.
    230   1.1       cgd 	 */
    231   1.1       cgd 	/* sanity check. */
    232   1.7       cgd 	if (pa->pa_bus != PPB_BUSINFO_PRIMARY(busdata))
    233   1.1       cgd 		panic("ppbattach: bus in tag (%d) != bus in reg (%d)",
    234   1.7       cgd 		    pa->pa_bus, PPB_BUSINFO_PRIMARY(busdata));
    235   1.1       cgd #endif
    236   1.1       cgd 
    237  1.57   msaitoh 	/* Check for PCI Express capabilities and setup hotplug support. */
    238  1.57   msaitoh 	if (pci_get_capability(pc, pa->pa_tag, PCI_CAP_PCIEXPRESS,
    239  1.57   msaitoh 	    &sc->sc_pciecapoff, &reg) && (reg & PCIE_XCAP_SI)) {
    240  1.57   msaitoh #if 0
    241  1.57   msaitoh 		/*
    242  1.57   msaitoh 		 * XXX Initialize workqueue or something else for
    243  1.57   msaitoh 		 * HotPlug support.
    244  1.57   msaitoh 		 */
    245  1.57   msaitoh #endif
    246  1.57   msaitoh 
    247  1.57   msaitoh 		if (pci_intr_alloc(pa, &sc->sc_pihp, NULL, 0) == 0)
    248  1.57   msaitoh 			sc->sc_intrhand = pci_intr_establish_xname(pc,
    249  1.57   msaitoh 			    sc->sc_pihp[0], IPL_BIO, ppb_intr, sc,
    250  1.57   msaitoh 			    device_xname(sc->sc_dev));
    251  1.57   msaitoh 
    252  1.57   msaitoh 		if (sc->sc_intrhand) {
    253  1.57   msaitoh 			pcireg_t slcap, slcsr, val;
    254  1.57   msaitoh 
    255  1.57   msaitoh 			intrstr = pci_intr_string(pc, sc->sc_pihp[0], intrbuf,
    256  1.57   msaitoh 			    sizeof(intrbuf));
    257  1.57   msaitoh 			aprint_normal_dev(self, "%s\n", intrstr);
    258  1.57   msaitoh 
    259  1.57   msaitoh 			/* Clear any pending events */
    260  1.57   msaitoh 			slcsr = pci_conf_read(pc, pa->pa_tag,
    261  1.57   msaitoh 			    sc->sc_pciecapoff + PCIE_SLCSR);
    262  1.57   msaitoh 			pci_conf_write(pc, pa->pa_tag,
    263  1.57   msaitoh 			    sc->sc_pciecapoff + PCIE_SLCSR, slcsr);
    264  1.57   msaitoh 
    265  1.57   msaitoh 			/* Enable interrupt. */
    266  1.57   msaitoh 			slcap = pci_conf_read(pc, pa->pa_tag,
    267  1.57   msaitoh 			    sc->sc_pciecapoff + PCIE_SLCAP);
    268  1.57   msaitoh 			val = 0;
    269  1.57   msaitoh 			if (slcap & PCIE_SLCAP_ABP)
    270  1.57   msaitoh 				val |= PCIE_SLCSR_ABE;
    271  1.57   msaitoh 			if (slcap & PCIE_SLCAP_PCP)
    272  1.57   msaitoh 				val |= PCIE_SLCSR_PFE;
    273  1.57   msaitoh 			if (slcap & PCIE_SLCAP_MSP)
    274  1.57   msaitoh 				val |= PCIE_SLCSR_MSE;
    275  1.57   msaitoh 			if ((slcap & PCIE_SLCAP_NCCS) == 0)
    276  1.57   msaitoh 				val |= PCIE_SLCSR_CCE;
    277  1.57   msaitoh 			/* Attention indicator off by default */
    278  1.57   msaitoh 			if (slcap & PCIE_SLCAP_AIP) {
    279  1.57   msaitoh 				val |= __SHIFTIN(PCIE_SLCSR_IND_OFF,
    280  1.57   msaitoh 				    PCIE_SLCSR_AIC);
    281  1.57   msaitoh 			}
    282  1.57   msaitoh 			/* Power indicator */
    283  1.57   msaitoh 			if (slcap & PCIE_SLCAP_PIP) {
    284  1.57   msaitoh 				/*
    285  1.57   msaitoh 				 * Indicator off:
    286  1.57   msaitoh 				 *  a) card not present
    287  1.57   msaitoh 				 *  b) power fault
    288  1.57   msaitoh 				 *  c) MRL sensor off
    289  1.57   msaitoh 				 */
    290  1.57   msaitoh 				if (((slcsr & PCIE_SLCSR_PDS) == 0)
    291  1.57   msaitoh 				    || ((slcsr & PCIE_SLCSR_PFD) != 0)
    292  1.57   msaitoh 				    || (((slcap & PCIE_SLCAP_MSP) != 0)
    293  1.57   msaitoh 					&& ((slcsr & PCIE_SLCSR_MS) != 0)))
    294  1.57   msaitoh 					val |= __SHIFTIN(PCIE_SLCSR_IND_OFF,
    295  1.57   msaitoh 					    PCIE_SLCSR_PIC);
    296  1.57   msaitoh 				else
    297  1.57   msaitoh 					val |= __SHIFTIN(PCIE_SLCSR_IND_ON,
    298  1.57   msaitoh 					    PCIE_SLCSR_PIC);
    299  1.57   msaitoh 			}
    300  1.57   msaitoh 
    301  1.57   msaitoh 			val |= PCIE_SLCSR_DLLSCE | PCIE_SLCSR_HPE
    302  1.57   msaitoh 			    | PCIE_SLCSR_PDE;
    303  1.57   msaitoh 			slcsr = val;
    304  1.57   msaitoh 			pci_conf_write(pc, pa->pa_tag,
    305  1.57   msaitoh 			    sc->sc_pciecapoff + PCIE_SLCSR, slcsr);
    306  1.57   msaitoh 		}
    307  1.57   msaitoh 	}
    308  1.57   msaitoh 
    309  1.36  jmcneill 	if (!pmf_device_register(self, ppb_suspend, ppb_resume))
    310  1.36  jmcneill 		aprint_error_dev(self, "couldn't establish power handler\n");
    311  1.36  jmcneill 
    312   1.1       cgd 	/*
    313   1.1       cgd 	 * Attach the PCI bus than hangs off of it.
    314  1.19   thorpej 	 *
    315  1.19   thorpej 	 * XXX Don't pass-through Memory Read Multiple.  Should we?
    316  1.19   thorpej 	 * XXX Consult the spec...
    317   1.1       cgd 	 */
    318  1.12   thorpej 	pba.pba_iot = pa->pa_iot;
    319  1.12   thorpej 	pba.pba_memt = pa->pa_memt;
    320  1.15   mycroft 	pba.pba_dmat = pa->pa_dmat;
    321  1.26      fvdl 	pba.pba_dmat64 = pa->pa_dmat64;
    322   1.7       cgd 	pba.pba_pc = pc;
    323  1.19   thorpej 	pba.pba_flags = pa->pa_flags & ~PCI_FLAGS_MRM_OKAY;
    324   1.7       cgd 	pba.pba_bus = PPB_BUSINFO_SECONDARY(busdata);
    325  1.47    dyoung 	pba.pba_sub = PPB_BUSINFO_SUBORDINATE(busdata);
    326  1.21   thorpej 	pba.pba_bridgetag = &sc->sc_tag;
    327   1.7       cgd 	pba.pba_intrswiz = pa->pa_intrswiz;
    328   1.7       cgd 	pba.pba_intrtag = pa->pa_intrtag;
    329   1.1       cgd 
    330  1.57   msaitoh 	/* Attach event counters */
    331  1.57   msaitoh 	evcnt_attach_dynamic(&sc->sc_ev_intr, EVCNT_TYPE_INTR, NULL,
    332  1.57   msaitoh 	    device_xname(sc->sc_dev), "Interrupt");
    333  1.57   msaitoh 	evcnt_attach_dynamic(&sc->sc_ev_abp, EVCNT_TYPE_MISC, NULL,
    334  1.57   msaitoh 	    device_xname(sc->sc_dev), "Attention Button Pressed");
    335  1.57   msaitoh 	evcnt_attach_dynamic(&sc->sc_ev_pfd, EVCNT_TYPE_MISC, NULL,
    336  1.57   msaitoh 	    device_xname(sc->sc_dev), "Power Fault Detected");
    337  1.57   msaitoh 	evcnt_attach_dynamic(&sc->sc_ev_msc, EVCNT_TYPE_MISC, NULL,
    338  1.57   msaitoh 	    device_xname(sc->sc_dev), "MRL Sensor Changed");
    339  1.57   msaitoh 	evcnt_attach_dynamic(&sc->sc_ev_pdc, EVCNT_TYPE_MISC, NULL,
    340  1.57   msaitoh 	    device_xname(sc->sc_dev), "Presence Detect Changed");
    341  1.57   msaitoh 	evcnt_attach_dynamic(&sc->sc_ev_cc, EVCNT_TYPE_MISC, NULL,
    342  1.57   msaitoh 	    device_xname(sc->sc_dev), "Command Completed");
    343  1.57   msaitoh 	evcnt_attach_dynamic(&sc->sc_ev_lacs, EVCNT_TYPE_MISC, NULL,
    344  1.57   msaitoh 	    device_xname(sc->sc_dev), "Data Link Layer State Changed");
    345  1.57   msaitoh 
    346  1.29  drochner 	config_found_ia(self, "pcibus", &pba, pcibusprint);
    347   1.1       cgd }
    348  1.31   thorpej 
    349  1.37    dyoung static int
    350  1.37    dyoung ppbdetach(device_t self, int flags)
    351  1.37    dyoung {
    352  1.57   msaitoh 	struct ppb_softc *sc = device_private(self);
    353  1.59   msaitoh 	pcireg_t slcsr;
    354  1.37    dyoung 	int rc;
    355  1.37    dyoung 
    356  1.58       chs 	if ((rc = config_detach_children(self, flags)) != 0)
    357  1.58       chs 		return rc;
    358  1.58       chs 
    359  1.57   msaitoh 	/* Detach event counters */
    360  1.57   msaitoh 	evcnt_detach(&sc->sc_ev_intr);
    361  1.57   msaitoh 	evcnt_detach(&sc->sc_ev_abp);
    362  1.57   msaitoh 	evcnt_detach(&sc->sc_ev_pfd);
    363  1.57   msaitoh 	evcnt_detach(&sc->sc_ev_msc);
    364  1.57   msaitoh 	evcnt_detach(&sc->sc_ev_pdc);
    365  1.57   msaitoh 	evcnt_detach(&sc->sc_ev_cc);
    366  1.57   msaitoh 	evcnt_detach(&sc->sc_ev_lacs);
    367  1.57   msaitoh 
    368  1.59   msaitoh 	/* Clear any pending events and disable interrupt */
    369  1.59   msaitoh 	slcsr = pci_conf_read(sc->sc_pc, sc->sc_tag,
    370  1.59   msaitoh 	      sc->sc_pciecapoff + PCIE_SLCSR);
    371  1.59   msaitoh 	slcsr &= ~PCIE_SLCSR_NOTIFY_MASK;
    372  1.59   msaitoh 	pci_conf_write(sc->sc_pc, sc->sc_tag,
    373  1.59   msaitoh 		sc->sc_pciecapoff + PCIE_SLCSR, slcsr);
    374  1.59   msaitoh 
    375  1.59   msaitoh 	/* Disestablish the interrupt handler */
    376  1.59   msaitoh 	if (sc->sc_intrhand != NULL) {
    377  1.59   msaitoh 		pci_intr_disestablish(sc->sc_pc, sc->sc_intrhand);
    378  1.59   msaitoh 		pci_intr_release(sc->sc_pc, sc->sc_pihp, 1);
    379  1.59   msaitoh 	}
    380  1.59   msaitoh 
    381  1.37    dyoung 	pmf_device_deregister(self);
    382  1.37    dyoung 	return 0;
    383  1.37    dyoung }
    384  1.37    dyoung 
    385  1.36  jmcneill static bool
    386  1.42    dyoung ppb_resume(device_t dv, const pmf_qual_t *qual)
    387  1.36  jmcneill {
    388  1.36  jmcneill 	struct ppb_softc *sc = device_private(dv);
    389  1.36  jmcneill 	int off;
    390  1.36  jmcneill 	pcireg_t val;
    391  1.36  jmcneill 
    392  1.36  jmcneill         for (off = 0x40; off <= 0xff; off += 4) {
    393  1.36  jmcneill 		val = pci_conf_read(sc->sc_pc, sc->sc_tag, off);
    394  1.36  jmcneill 		if (val != sc->sc_pciconfext[(off - 0x40) / 4])
    395  1.36  jmcneill 			pci_conf_write(sc->sc_pc, sc->sc_tag, off,
    396  1.36  jmcneill 			    sc->sc_pciconfext[(off - 0x40)/4]);
    397  1.36  jmcneill 	}
    398  1.36  jmcneill 
    399  1.36  jmcneill 	return true;
    400  1.36  jmcneill }
    401  1.36  jmcneill 
    402  1.36  jmcneill static bool
    403  1.42    dyoung ppb_suspend(device_t dv, const pmf_qual_t *qual)
    404  1.36  jmcneill {
    405  1.36  jmcneill 	struct ppb_softc *sc = device_private(dv);
    406  1.36  jmcneill 	int off;
    407  1.36  jmcneill 
    408  1.36  jmcneill 	for (off = 0x40; off <= 0xff; off += 4)
    409  1.36  jmcneill 		sc->sc_pciconfext[(off - 0x40) / 4] =
    410  1.36  jmcneill 		    pci_conf_read(sc->sc_pc, sc->sc_tag, off);
    411  1.36  jmcneill 
    412  1.36  jmcneill 	return true;
    413  1.36  jmcneill }
    414  1.36  jmcneill 
    415  1.37    dyoung static void
    416  1.37    dyoung ppbchilddet(device_t self, device_t child)
    417  1.37    dyoung {
    418  1.37    dyoung 	/* we keep no references to child devices, so do nothing */
    419  1.37    dyoung }
    420  1.37    dyoung 
    421  1.57   msaitoh static int
    422  1.57   msaitoh ppb_intr(void *arg)
    423  1.57   msaitoh {
    424  1.57   msaitoh 	struct ppb_softc *sc = arg;
    425  1.57   msaitoh 	device_t dev = sc->sc_dev;
    426  1.57   msaitoh 	pcireg_t reg;
    427  1.57   msaitoh 
    428  1.57   msaitoh 	sc->sc_ev_intr.ev_count++;
    429  1.57   msaitoh 	reg = pci_conf_read(sc->sc_pc, sc->sc_tag,
    430  1.57   msaitoh 	    sc->sc_pciecapoff + PCIE_SLCSR);
    431  1.57   msaitoh 
    432  1.57   msaitoh 	/* Clear interrupts. */
    433  1.57   msaitoh 	pci_conf_write(sc->sc_pc, sc->sc_tag,
    434  1.57   msaitoh 	    sc->sc_pciecapoff + PCIE_SLCSR, reg);
    435  1.57   msaitoh 
    436  1.57   msaitoh 	/* Attention Button Pressed */
    437  1.57   msaitoh 	if (reg & PCIE_SLCSR_ABP) {
    438  1.57   msaitoh 		sc->sc_ev_abp.ev_count++;
    439  1.57   msaitoh 		if (ppb_printevent)
    440  1.57   msaitoh 			device_printf(dev, "Attention Button Pressed\n");
    441  1.57   msaitoh 	}
    442  1.57   msaitoh 
    443  1.57   msaitoh 	/* Power Fault Detected */
    444  1.57   msaitoh 	if (reg & PCIE_SLCSR_PFD) {
    445  1.57   msaitoh 		sc->sc_ev_pfd.ev_count++;
    446  1.57   msaitoh 		if (ppb_printevent)
    447  1.57   msaitoh 			device_printf(dev, "Power Fault Detected\n");
    448  1.57   msaitoh 	}
    449  1.57   msaitoh 
    450  1.57   msaitoh 	/* MRL Sensor Changed */
    451  1.57   msaitoh 	if (reg & PCIE_SLCSR_MSC) {
    452  1.57   msaitoh 		sc->sc_ev_msc.ev_count++;
    453  1.57   msaitoh 		if (ppb_printevent)
    454  1.57   msaitoh 			device_printf(dev, "MRL Sensor Changed\n");
    455  1.57   msaitoh 	}
    456  1.57   msaitoh 
    457  1.57   msaitoh 	/* Presence Detect Changed */
    458  1.57   msaitoh 	if (reg & PCIE_SLCSR_PDC) {
    459  1.57   msaitoh 		sc->sc_ev_pdc.ev_count++;
    460  1.57   msaitoh 		if (ppb_printevent)
    461  1.57   msaitoh 			device_printf(dev, "Presence Detect Changed\n");
    462  1.57   msaitoh 		if (reg & PCIE_SLCSR_PDS) {
    463  1.57   msaitoh 			/* XXX Insert */
    464  1.57   msaitoh 		} else {
    465  1.57   msaitoh 			/* XXX Remove */
    466  1.57   msaitoh 		}
    467  1.57   msaitoh 	}
    468  1.57   msaitoh 
    469  1.57   msaitoh 	/* Command Completed */
    470  1.57   msaitoh 	if (reg & PCIE_SLCSR_CC) {
    471  1.57   msaitoh 		sc->sc_ev_cc.ev_count++;
    472  1.57   msaitoh 		if (ppb_printevent)
    473  1.57   msaitoh 			device_printf(dev, "Command Completed\n");
    474  1.57   msaitoh 	}
    475  1.57   msaitoh 
    476  1.57   msaitoh 	/* Data Link Layer State Changed */
    477  1.57   msaitoh 	if (reg & PCIE_SLCSR_LACS) {
    478  1.57   msaitoh 		sc->sc_ev_lacs.ev_count++;
    479  1.57   msaitoh 		if (ppb_printevent)
    480  1.57   msaitoh 			device_printf(dev, "Data Link Layer State Changed\n");
    481  1.57   msaitoh 	}
    482  1.57   msaitoh 
    483  1.57   msaitoh 	return 0;
    484  1.57   msaitoh }
    485