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