xref: /netbsd-src/sys/dev/pci/ppb.c (revision f3cfa6f6ce31685c6c4a758bc430e69eb99f50a4)
1 /*	$NetBSD: ppb.c,v 1.68 2019/03/01 09:26:00 msaitoh 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.68 2019/03/01 09:26:00 msaitoh Exp $");
35 
36 #ifdef _KERNEL_OPT
37 #include "opt_ppb.h"
38 #endif
39 
40 #ifdef _KERNEL_OPT
41 #include "opt_ppb.h"
42 #endif
43 
44 #include <sys/param.h>
45 #include <sys/systm.h>
46 #include <sys/kernel.h>
47 #include <sys/device.h>
48 #include <sys/evcnt.h>
49 
50 #include <dev/pci/pcireg.h>
51 #include <dev/pci/pcivar.h>
52 #include <dev/pci/ppbreg.h>
53 #include <dev/pci/ppbvar.h>
54 #include <dev/pci/pcidevs.h>
55 
56 #define	PCIE_SLCSR_ENABLE_MASK					\
57 	(PCIE_SLCSR_ABE | PCIE_SLCSR_PFE | PCIE_SLCSR_MSE |	\
58 	 PCIE_SLCSR_PDE | PCIE_SLCSR_CCE | PCIE_SLCSR_HPE |	\
59 	 PCIE_SLCSR_DLLSCE)
60 
61 #define	PCIE_SLCSR_STATCHG_MASK					\
62 	(PCIE_SLCSR_ABP | PCIE_SLCSR_PFD | PCIE_SLCSR_MSC |	\
63 	 PCIE_SLCSR_PDC | PCIE_SLCSR_CC | PCIE_SLCSR_LACS)
64 
65 static const char pcie_linkspeed_strings[4][5] = {
66 	"1.25", "2.5", "5.0", "8.0",
67 };
68 
69 int	ppb_printevent = 0; /* Print event type if the value is not 0 */
70 
71 static int	ppbmatch(device_t, cfdata_t, void *);
72 static void	ppbattach(device_t, device_t, void *);
73 static int	ppbdetach(device_t, int);
74 static void	ppbchilddet(device_t, device_t);
75 #ifdef PPB_USEINTR
76 static int	ppb_intr(void *);
77 #endif
78 static bool	ppb_resume(device_t, const pmf_qual_t *);
79 static bool	ppb_suspend(device_t, const pmf_qual_t *);
80 
81 CFATTACH_DECL3_NEW(ppb, sizeof(struct ppb_softc),
82     ppbmatch, ppbattach, ppbdetach, NULL, NULL, ppbchilddet,
83     DVF_DETACH_SHUTDOWN);
84 
85 static int
86 ppbmatch(device_t parent, cfdata_t match, void *aux)
87 {
88 	struct pci_attach_args *pa = aux;
89 
90 	/*
91 	 * Check the ID register to see that it's a PCI bridge.
92 	 * If it is, we assume that we can deal with it; it _should_
93 	 * work in a standardized way...
94 	 */
95 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_BRIDGE &&
96 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_BRIDGE_PCI)
97 		return 1;
98 
99 #ifdef __powerpc__
100 	if (PCI_CLASS(pa->pa_class) == PCI_CLASS_PROCESSOR &&
101 	    PCI_SUBCLASS(pa->pa_class) == PCI_SUBCLASS_PROCESSOR_POWERPC) {
102 		pcireg_t bhlc = pci_conf_read(pa->pa_pc, pa->pa_tag,
103 		    PCI_BHLC_REG);
104 		if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_FREESCALE
105 		    && PCI_HDRTYPE(bhlc) == PCI_HDRTYPE_RC)
106 		return 1;
107 	}
108 #endif
109 
110 #ifdef _MIPS_PADDR_T_64BIT
111 	/* The LDT HB acts just like a PPB.  */
112 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_SIBYTE
113 	    && PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_SIBYTE_BCM1250_LDTHB)
114 		return 1;
115 #endif
116 
117 	return 0;
118 }
119 
120 static void
121 ppb_print_pcie(device_t self)
122 {
123 	struct ppb_softc *sc = device_private(self);
124 	pcireg_t reg;
125 	int off, capversion, devtype;
126 
127 	if (!pci_get_capability(sc->sc_pc, sc->sc_tag, PCI_CAP_PCIEXPRESS,
128 				&off, &reg))
129 		return; /* Not a PCIe device */
130 
131 	capversion = PCIE_XCAP_VER(reg);
132 	devtype = PCIE_XCAP_TYPE(reg);
133 	aprint_normal_dev(self, "PCI Express capability version ");
134 	switch (capversion) {
135 	case PCIE_XCAP_VER_1:
136 		aprint_normal("1");
137 		break;
138 	case PCIE_XCAP_VER_2:
139 		aprint_normal("2");
140 		break;
141 	default:
142 		aprint_normal_dev(self, "unsupported (%d)\n", capversion);
143 		return;
144 	}
145 	aprint_normal(" <");
146 	switch (devtype) {
147 	case PCIE_XCAP_TYPE_PCIE_DEV:
148 		aprint_normal("PCI-E Endpoint device");
149 		break;
150 	case PCIE_XCAP_TYPE_PCI_DEV:
151 		aprint_normal("Legacy PCI-E Endpoint device");
152 		break;
153 	case PCIE_XCAP_TYPE_ROOT:
154 		aprint_normal("Root Port of PCI-E Root Complex");
155 		break;
156 	case PCIE_XCAP_TYPE_UP:
157 		aprint_normal("Upstream Port of PCI-E Switch");
158 		break;
159 	case PCIE_XCAP_TYPE_DOWN:
160 		aprint_normal("Downstream Port of PCI-E Switch");
161 		break;
162 	case PCIE_XCAP_TYPE_PCIE2PCI:
163 		aprint_normal("PCI-E to PCI/PCI-X Bridge");
164 		break;
165 	case PCIE_XCAP_TYPE_PCI2PCIE:
166 		aprint_normal("PCI/PCI-X to PCI-E Bridge");
167 		break;
168 	default:
169 		aprint_normal("Device/Port Type %x", devtype);
170 		break;
171 	}
172 
173 	switch (devtype) {
174 	case PCIE_XCAP_TYPE_ROOT:
175 	case PCIE_XCAP_TYPE_DOWN:
176 	case PCIE_XCAP_TYPE_PCI2PCIE:
177 		reg = pci_conf_read(sc->sc_pc, sc->sc_tag, off + PCIE_LCAP);
178 		u_int mlw = __SHIFTOUT(reg, PCIE_LCAP_MAX_WIDTH);
179 		u_int mls = __SHIFTOUT(reg, PCIE_LCAP_MAX_SPEED);
180 
181 		if (mls < __arraycount(pcie_linkspeed_strings)) {
182 			aprint_normal("> x%d @ %sGT/s\n",
183 			    mlw, pcie_linkspeed_strings[mls]);
184 		} else {
185 			aprint_normal("> x%d @ %d.%dGT/s\n",
186 			    mlw, (mls * 25) / 10, (mls * 25) % 10);
187 		}
188 
189 		reg = pci_conf_read(sc->sc_pc, sc->sc_tag, off + PCIE_LCSR);
190 		if (reg & PCIE_LCSR_DLACTIVE) {	/* DLLA */
191 			u_int lw = __SHIFTOUT(reg, PCIE_LCSR_NLW);
192 			u_int ls = __SHIFTOUT(reg, PCIE_LCSR_LINKSPEED);
193 
194 			if (lw != mlw || ls != mls) {
195 				if (ls < __arraycount(pcie_linkspeed_strings)) {
196 					aprint_normal_dev(self,
197 					    "link is x%d @ %sGT/s\n",
198 					    lw, pcie_linkspeed_strings[ls]);
199 				} else {
200 					aprint_normal_dev(self,
201 					    "link is x%d @ %d.%dGT/s\n",
202 					    lw, (ls * 25) / 10, (ls * 25) % 10);
203 				}
204 			}
205 		}
206 		break;
207 	default:
208 		aprint_normal(">\n");
209 		break;
210 	}
211 }
212 
213 static void
214 ppbattach(device_t parent, device_t self, void *aux)
215 {
216 	struct ppb_softc *sc = device_private(self);
217 	struct pci_attach_args *pa = aux;
218 	pci_chipset_tag_t pc = pa->pa_pc;
219 	struct pcibus_attach_args pba;
220 #ifdef PPB_USEINTR
221 	char const *intrstr;
222 	char intrbuf[PCI_INTRSTR_LEN];
223 #endif
224 	pcireg_t busdata, reg;
225 	bool second_configured = false;
226 
227 	pci_aprint_devinfo(pa, NULL);
228 
229 	sc->sc_pc = pc;
230 	sc->sc_tag = pa->pa_tag;
231 	sc->sc_dev = self;
232 
233 	busdata = pci_conf_read(pc, pa->pa_tag, PCI_BRIDGE_BUS_REG);
234 
235 	if (PCI_BRIDGE_BUS_NUM_SECONDARY(busdata) == 0) {
236 		aprint_normal_dev(self, "not configured by system firmware\n");
237 		return;
238 	}
239 
240 	ppb_print_pcie(self);
241 
242 #if 0
243 	/*
244 	 * XXX can't do this, because we're not given our bus number
245 	 * (we shouldn't need it), and because we've no way to
246 	 * decompose our tag.
247 	 */
248 	/* sanity check. */
249 	if (pa->pa_bus != PCI_BRIDGE_BUS_NUM_PRIMARY(busdata))
250 		panic("ppbattach: bus in tag (%d) != bus in reg (%d)",
251 		    pa->pa_bus, PCI_BRIDGE_BUS_NUM_PRIMARY(busdata));
252 #endif
253 
254 	/* Check for PCI Express capabilities and setup hotplug support. */
255 	if (pci_get_capability(pc, pa->pa_tag, PCI_CAP_PCIEXPRESS,
256 	    &sc->sc_pciecapoff, &reg) && (reg & PCIE_XCAP_SI)) {
257 		/*
258 		 * First, disable all interrupts because BIOS might
259 		 * enable them.
260 		 */
261 		reg = pci_conf_read(sc->sc_pc, sc->sc_tag,
262 		    sc->sc_pciecapoff + PCIE_SLCSR);
263 		if (reg & PCIE_SLCSR_ENABLE_MASK) {
264 			reg &= ~PCIE_SLCSR_ENABLE_MASK;
265 			pci_conf_write(sc->sc_pc, sc->sc_tag,
266 			    sc->sc_pciecapoff + PCIE_SLCSR, reg);
267 		}
268 #ifdef PPB_USEINTR
269 #if 0 /* notyet */
270 		/*
271 		 * XXX Initialize workqueue or something else for
272 		 * HotPlug support.
273 		 */
274 #endif
275 		if (pci_intr_alloc(pa, &sc->sc_pihp, NULL, 0) == 0)
276 			sc->sc_intrhand = pci_intr_establish_xname(pc,
277 			    sc->sc_pihp[0], IPL_BIO, ppb_intr, sc,
278 			    device_xname(sc->sc_dev));
279 #endif
280 	}
281 
282 #ifdef PPB_USEINTR
283 	if (sc->sc_intrhand != NULL) {
284 		pcireg_t slcap, slcsr, val;
285 
286 		intrstr = pci_intr_string(pc, sc->sc_pihp[0], intrbuf,
287 		    sizeof(intrbuf));
288 		aprint_normal_dev(self, "interrupting at %s\n", intrstr);
289 
290 		/* Clear any pending events */
291 		slcsr = pci_conf_read(pc, pa->pa_tag,
292 		    sc->sc_pciecapoff + PCIE_SLCSR);
293 		pci_conf_write(pc, pa->pa_tag,
294 		    sc->sc_pciecapoff + PCIE_SLCSR, slcsr);
295 
296 		/* Enable interrupt. */
297 		val = 0;
298 		slcap = pci_conf_read(pc, pa->pa_tag,
299 		    sc->sc_pciecapoff + PCIE_SLCAP);
300 		if (slcap & PCIE_SLCAP_ABP)
301 			val |= PCIE_SLCSR_ABE;
302 		if (slcap & PCIE_SLCAP_PCP)
303 			val |= PCIE_SLCSR_PFE;
304 		if (slcap & PCIE_SLCAP_MSP)
305 			val |= PCIE_SLCSR_MSE;
306 #if 0
307 		/*
308 		 * XXX Disable for a while because setting
309 		 * PCIE_SLCSR_CCE makes break device access on
310 		 * some environment.
311 		 */
312 		if ((slcap & PCIE_SLCAP_NCCS) == 0)
313 			val |= PCIE_SLCSR_CCE;
314 #endif
315 		/* Attention indicator off by default */
316 		if (slcap & PCIE_SLCAP_AIP) {
317 			val |= __SHIFTIN(PCIE_SLCSR_IND_OFF,
318 			    PCIE_SLCSR_AIC);
319 		}
320 		/* Power indicator */
321 		if (slcap & PCIE_SLCAP_PIP) {
322 			/*
323 			 * Indicator off:
324 			 *  a) card not present
325 			 *  b) power fault
326 			 *  c) MRL sensor off
327 			 */
328 			if (((slcsr & PCIE_SLCSR_PDS) == 0)
329 			    || ((slcsr & PCIE_SLCSR_PFD) != 0)
330 			    || (((slcap & PCIE_SLCAP_MSP) != 0)
331 				&& ((slcsr & PCIE_SLCSR_MS) != 0)))
332 				val |= __SHIFTIN(PCIE_SLCSR_IND_OFF,
333 				    PCIE_SLCSR_PIC);
334 			else
335 				val |= __SHIFTIN(PCIE_SLCSR_IND_ON,
336 				    PCIE_SLCSR_PIC);
337 		}
338 
339 		val |= PCIE_SLCSR_DLLSCE | PCIE_SLCSR_HPE | PCIE_SLCSR_PDE;
340 		slcsr = val;
341 		pci_conf_write(pc, pa->pa_tag,
342 		    sc->sc_pciecapoff + PCIE_SLCSR, slcsr);
343 
344 		/* Attach event counters */
345 		evcnt_attach_dynamic(&sc->sc_ev_intr, EVCNT_TYPE_INTR, NULL,
346 		    device_xname(sc->sc_dev), "Interrupt");
347 		evcnt_attach_dynamic(&sc->sc_ev_abp, EVCNT_TYPE_MISC, NULL,
348 		    device_xname(sc->sc_dev), "Attention Button Pressed");
349 		evcnt_attach_dynamic(&sc->sc_ev_pfd, EVCNT_TYPE_MISC, NULL,
350 		    device_xname(sc->sc_dev), "Power Fault Detected");
351 		evcnt_attach_dynamic(&sc->sc_ev_msc, EVCNT_TYPE_MISC, NULL,
352 		    device_xname(sc->sc_dev), "MRL Sensor Changed");
353 		evcnt_attach_dynamic(&sc->sc_ev_pdc, EVCNT_TYPE_MISC, NULL,
354 		    device_xname(sc->sc_dev), "Presence Detect Changed");
355 		evcnt_attach_dynamic(&sc->sc_ev_cc, EVCNT_TYPE_MISC, NULL,
356 		    device_xname(sc->sc_dev), "Command Completed");
357 		evcnt_attach_dynamic(&sc->sc_ev_lacs, EVCNT_TYPE_MISC, NULL,
358 		    device_xname(sc->sc_dev), "Data Link Layer State Changed");
359 	}
360 #endif /* PPB_USEINTR */
361 
362 	/* Configuration test */
363 	if (PCI_BRIDGE_BUS_NUM_SECONDARY(busdata) != 0) {
364 		uint32_t base, limit;
365 
366 		/* I/O region test */
367 		reg = pci_conf_read(pc, pa->pa_tag, PCI_BRIDGE_STATIO_REG);
368 		base = PCI_BRIDGE_STATIO_IOBASE_ADDR(reg);
369 		limit = PCI_BRIDGE_STATIO_IOLIMIT_ADDR(reg);
370 		if (PCI_BRIDGE_IO_32BITS(reg)) {
371 			reg = pci_conf_read(pc, pa->pa_tag,
372 			    PCI_BRIDGE_IOHIGH_REG);
373 			base |= __SHIFTOUT(reg, PCI_BRIDGE_IOHIGH_BASE) << 16;
374 			limit |= __SHIFTOUT(reg, PCI_BRIDGE_IOHIGH_LIMIT) <<16;
375 		}
376 		if (base < limit) {
377 			second_configured = true;
378 			goto configure;
379 		}
380 
381 		/* Non-prefetchable memory region test */
382 		reg = pci_conf_read(pc, pa->pa_tag, PCI_BRIDGE_MEMORY_REG);
383 		base = PCI_BRIDGE_MEMORY_BASE_ADDR(reg);
384 		limit = PCI_BRIDGE_MEMORY_LIMIT_ADDR(reg);
385 		if (base < limit) {
386 			second_configured = true;
387 			goto configure;
388 		}
389 
390 		/* Prefetchable memory region test */
391 		reg = pci_conf_read(pc, pa->pa_tag,
392 		    PCI_BRIDGE_PREFETCHMEM_REG);
393 		base = PCI_BRIDGE_PREFETCHMEM_BASE_ADDR(reg);
394 		limit = PCI_BRIDGE_PREFETCHMEM_LIMIT_ADDR(reg);
395 
396 		if (PCI_BRIDGE_PREFETCHMEM_64BITS(reg)) {
397 			reg = pci_conf_read(pc, pa->pa_tag,
398 			    PCI_BRIDGE_IOHIGH_REG);
399 			base |= (uint64_t)pci_conf_read(pc, pa->pa_tag,
400 			    PCI_BRIDGE_PREFETCHBASEUP32_REG) << 32;
401 			limit |= (uint64_t)pci_conf_read(pc, pa->pa_tag,
402 			    PCI_BRIDGE_PREFETCHLIMITUP32_REG) << 32;
403 		}
404 		if (base < limit) {
405 			second_configured = true;
406 			goto configure;
407 		}
408 	}
409 
410 configure:
411 	/*
412 	 * If the secondary bus is configured and the bus mastering is not
413 	 * enabled, enable it.
414 	 */
415 	if (second_configured) {
416 		reg = pci_conf_read(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG);
417 		if ((reg & PCI_COMMAND_MASTER_ENABLE) == 0)
418 			pci_conf_write(pc, pa->pa_tag, PCI_COMMAND_STATUS_REG,
419 			    reg | PCI_COMMAND_MASTER_ENABLE);
420 	}
421 
422 	if (!pmf_device_register(self, ppb_suspend, ppb_resume))
423 		aprint_error_dev(self, "couldn't establish power handler\n");
424 
425 	/*
426 	 * Attach the PCI bus that hangs off of it.
427 	 *
428 	 * XXX Don't pass-through Memory Read Multiple.  Should we?
429 	 * XXX Consult the spec...
430 	 */
431 	pba.pba_iot = pa->pa_iot;
432 	pba.pba_memt = pa->pa_memt;
433 	pba.pba_dmat = pa->pa_dmat;
434 	pba.pba_dmat64 = pa->pa_dmat64;
435 	pba.pba_pc = pc;
436 	pba.pba_flags = pa->pa_flags & ~PCI_FLAGS_MRM_OKAY;
437 	pba.pba_bus = PCI_BRIDGE_BUS_NUM_SECONDARY(busdata);
438 	pba.pba_sub = PCI_BRIDGE_BUS_NUM_SUBORDINATE(busdata);
439 	pba.pba_bridgetag = &sc->sc_tag;
440 	pba.pba_intrswiz = pa->pa_intrswiz;
441 	pba.pba_intrtag = pa->pa_intrtag;
442 
443 	config_found_ia(self, "pcibus", &pba, pcibusprint);
444 }
445 
446 static int
447 ppbdetach(device_t self, int flags)
448 {
449 #ifdef PPB_USEINTR
450 	struct ppb_softc *sc = device_private(self);
451 	pcireg_t slcsr;
452 #endif
453 	int rc;
454 
455 	if ((rc = config_detach_children(self, flags)) != 0)
456 		return rc;
457 
458 #ifdef PPB_USEINTR
459 	if (sc->sc_intrhand != NULL) {
460 		/* Detach event counters */
461 		evcnt_detach(&sc->sc_ev_intr);
462 		evcnt_detach(&sc->sc_ev_abp);
463 		evcnt_detach(&sc->sc_ev_pfd);
464 		evcnt_detach(&sc->sc_ev_msc);
465 		evcnt_detach(&sc->sc_ev_pdc);
466 		evcnt_detach(&sc->sc_ev_cc);
467 		evcnt_detach(&sc->sc_ev_lacs);
468 
469 		/* Clear any pending events and disable interrupt */
470 		slcsr = pci_conf_read(sc->sc_pc, sc->sc_tag,
471 		    sc->sc_pciecapoff + PCIE_SLCSR);
472 		slcsr &= ~PCIE_SLCSR_ENABLE_MASK;
473 		pci_conf_write(sc->sc_pc, sc->sc_tag,
474 		    sc->sc_pciecapoff + PCIE_SLCSR, slcsr);
475 
476 		/* Disestablish the interrupt handler */
477 		pci_intr_disestablish(sc->sc_pc, sc->sc_intrhand);
478 		pci_intr_release(sc->sc_pc, sc->sc_pihp, 1);
479 	}
480 #endif
481 
482 	pmf_device_deregister(self);
483 	return 0;
484 }
485 
486 static bool
487 ppb_resume(device_t dv, const pmf_qual_t *qual)
488 {
489 	struct ppb_softc *sc = device_private(dv);
490 	int off;
491 	pcireg_t val;
492 
493         for (off = 0x40; off <= 0xff; off += 4) {
494 		val = pci_conf_read(sc->sc_pc, sc->sc_tag, off);
495 		if (val != sc->sc_pciconfext[(off - 0x40) / 4])
496 			pci_conf_write(sc->sc_pc, sc->sc_tag, off,
497 			    sc->sc_pciconfext[(off - 0x40)/4]);
498 	}
499 
500 	return true;
501 }
502 
503 static bool
504 ppb_suspend(device_t dv, const pmf_qual_t *qual)
505 {
506 	struct ppb_softc *sc = device_private(dv);
507 	int off;
508 
509 	for (off = 0x40; off <= 0xff; off += 4)
510 		sc->sc_pciconfext[(off - 0x40) / 4] =
511 		    pci_conf_read(sc->sc_pc, sc->sc_tag, off);
512 
513 	return true;
514 }
515 
516 static void
517 ppbchilddet(device_t self, device_t child)
518 {
519 	/* we keep no references to child devices, so do nothing */
520 }
521 
522 #ifdef PPB_USEINTR
523 static int
524 ppb_intr(void *arg)
525 {
526 	struct ppb_softc *sc = arg;
527 	device_t dev = sc->sc_dev;
528 	pcireg_t reg;
529 
530 	reg = pci_conf_read(sc->sc_pc, sc->sc_tag,
531 	    sc->sc_pciecapoff + PCIE_SLCSR);
532 
533 	/*
534 	 * Not me. This check is only required for INTx.
535 	 * ppb_intr() would be spilted int ppb_intr_legacy() and ppb_intr_msi()
536 	 */
537 	if ((reg & PCIE_SLCSR_STATCHG_MASK) == 0)
538 		return 0;
539 
540 	/* Clear interrupts. */
541 	pci_conf_write(sc->sc_pc, sc->sc_tag,
542 	    sc->sc_pciecapoff + PCIE_SLCSR, reg);
543 
544 	sc->sc_ev_intr.ev_count++;
545 
546 	/* Attention Button Pressed */
547 	if (reg & PCIE_SLCSR_ABP) {
548 		sc->sc_ev_abp.ev_count++;
549 		if (ppb_printevent)
550 			device_printf(dev, "Attention Button Pressed\n");
551 	}
552 
553 	/* Power Fault Detected */
554 	if (reg & PCIE_SLCSR_PFD) {
555 		sc->sc_ev_pfd.ev_count++;
556 		if (ppb_printevent)
557 			device_printf(dev, "Power Fault Detected\n");
558 	}
559 
560 	/* MRL Sensor Changed */
561 	if (reg & PCIE_SLCSR_MSC) {
562 		sc->sc_ev_msc.ev_count++;
563 		if (ppb_printevent)
564 			device_printf(dev, "MRL Sensor Changed\n");
565 	}
566 
567 	/* Presence Detect Changed */
568 	if (reg & PCIE_SLCSR_PDC) {
569 		sc->sc_ev_pdc.ev_count++;
570 		if (ppb_printevent)
571 			device_printf(dev, "Presence Detect Changed\n");
572 		if (reg & PCIE_SLCSR_PDS) {
573 			/* XXX Insert */
574 		} else {
575 			/* XXX Remove */
576 		}
577 	}
578 
579 	/* Command Completed */
580 	if (reg & PCIE_SLCSR_CC) {
581 		sc->sc_ev_cc.ev_count++;
582 		if (ppb_printevent)
583 			device_printf(dev, "Command Completed\n");
584 	}
585 
586 	/* Data Link Layer State Changed */
587 	if (reg & PCIE_SLCSR_LACS) {
588 		sc->sc_ev_lacs.ev_count++;
589 		if (ppb_printevent)
590 			device_printf(dev, "Data Link Layer State Changed\n");
591 	}
592 
593 	return 1;
594 }
595 #endif /* PPB_USEINTR */
596