bcm53xx_pax.c revision 1.12 1 /*-
2 * Copyright (c) 2012 The NetBSD Foundation, Inc.
3 * All rights reserved.
4 *
5 * This code is derived from software contributed to The NetBSD Foundation
6 * by Matt Thomas of 3am Software Foundry.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
18 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
19 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
20 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
21 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
28 */
29
30 #define _ARM32_BUS_DMA_PRIVATE
31 #define PCIE_PRIVATE
32
33 #include "locators.h"
34
35 #include <sys/cdefs.h>
36
37 __KERNEL_RCSID(1, "$NetBSD: bcm53xx_pax.c,v 1.12 2014/02/23 21:19:06 matt Exp $");
38
39 #include <sys/param.h>
40 #include <sys/bus.h>
41 #include <sys/device.h>
42 #include <sys/extent.h>
43 #include <sys/intr.h>
44 #include <sys/kmem.h>
45 #include <sys/systm.h>
46
47 #include <dev/pci/pcireg.h>
48 #include <dev/pci/pcivar.h>
49 #include <dev/pci/pciconf.h>
50
51 #include <arm/locore.h>
52
53 #include <arm/broadcom/bcm53xx_reg.h>
54 #include <arm/broadcom/bcm53xx_var.h>
55
56 #ifndef __HAVE_PCI_CONF_HOOK
57 #error __HAVE_PCI_CONF_HOOK must be defined
58 #endif
59
60 static const struct {
61 paddr_t owin_base;
62 psize_t owin_size;
63 } bcmpax_owins[] = {
64 [0] = { BCM53XX_PCIE0_OWIN_PBASE, BCM53XX_PCIE0_OWIN_SIZE },
65 [1] = { BCM53XX_PCIE1_OWIN_PBASE, BCM53XX_PCIE1_OWIN_SIZE },
66 [2] = { BCM53XX_PCIE2_OWIN_PBASE, BCM53XX_PCIE2_OWIN_SIZE },
67 };
68
69 static int bcmpax_ccb_match(device_t, cfdata_t, void *);
70 static void bcmpax_ccb_attach(device_t, device_t, void *);
71
72 struct bcmpax_intrhand {
73 TAILQ_ENTRY(bcmpax_intrhand) ih_link;
74 int (*ih_func)(void *);
75 void *ih_arg;
76 int ih_ipl;
77 };
78
79 TAILQ_HEAD(bcmpax_ihqh, bcmpax_intrhand);
80
81 struct bcmpax_softc {
82 device_t sc_dev;
83 bus_space_tag_t sc_bst;
84 bus_space_handle_t sc_bsh;
85 bus_dma_tag_t sc_dmat;
86 kmutex_t *sc_lock;
87 kmutex_t *sc_cfg_lock;
88 bool sc_linkup;
89 int sc_pba_flags;
90 uint32_t sc_intrgen;
91 struct arm32_pci_chipset sc_pc;
92 struct bcmpax_ihqh sc_intrs;
93 void *sc_ih[6];
94 int sc_port;
95 char sc_intrstring[4][32];
96 };
97
98 static inline uint32_t
99 bcmpax_read_4(struct bcmpax_softc *sc, bus_size_t o)
100 {
101 return bus_space_read_4(sc->sc_bst, sc->sc_bsh, o);
102 }
103
104 static inline void
105 bcmpax_write_4(struct bcmpax_softc *sc, bus_size_t o, uint32_t v)
106 {
107 bus_space_write_4(sc->sc_bst, sc->sc_bsh, o, v);
108 }
109
110 static void bcmpax_attach_hook(device_t, device_t, struct pcibus_attach_args *);
111 static int bcmpax_bus_maxdevs(void *, int);
112 static pcitag_t bcmpax_make_tag(void *, int, int, int);
113 static void bcmpax_decompose_tag(void *, pcitag_t, int *, int *, int *);
114 static pcireg_t bcmpax_conf_read(void *, pcitag_t, int);
115 static void bcmpax_conf_write(void *, pcitag_t, int, pcireg_t);
116
117 static int bcmpax_intr_map(const struct pci_attach_args *, pci_intr_handle_t *);
118 static const char *bcmpax_intr_string(void *, pci_intr_handle_t);
119 static const struct evcnt *bcmpax_intr_evcnt(void *, pci_intr_handle_t);
120 static void *bcmpax_intr_establish(void *, pci_intr_handle_t, int,
121 int (*)(void *), void *);
122 static void bcmpax_intr_disestablish(void *, void *);
123
124 static int bcmpax_conf_hook(void *, int, int, int, pcireg_t);
125 static void bcmpax_conf_interrupt(void *, int, int, int, int, int *);
126
127 static int bcmpax_intr(void *);
128
129 CFATTACH_DECL_NEW(bcmpax_ccb, sizeof(struct bcmpax_softc),
130 bcmpax_ccb_match, bcmpax_ccb_attach, NULL, NULL);
131
132 static int
133 bcmpax_ccb_match(device_t parent, cfdata_t cf, void *aux)
134 {
135 struct bcmccb_attach_args * const ccbaa = aux;
136 const struct bcm_locators * const loc = &ccbaa->ccbaa_loc;
137
138 if (strcmp(cf->cf_name, loc->loc_name))
139 return 0;
140
141 #ifdef DIAGNOSTIC
142 const int port = cf->cf_loc[BCMCCBCF_PORT];
143 #endif
144 KASSERT(port == BCMCCBCF_PORT_DEFAULT || port == loc->loc_port);
145
146 return 1;
147 }
148
149 static int
150 bcmpax_iwin_init(struct bcmpax_softc *sc)
151 {
152 #if 0
153 uint32_t megs = (physical_end + 0xfffff - physical_start) >> 20;
154 uint32_t iwin_megs = min(256, megs);
155 #if 1
156 bus_addr_t iwin1_start = physical_start;
157 #else
158 bus_addr_t iwin1_start = 0;
159 #endif
160 #if 1
161 bcmpax_write_4(sc, PCIE_IARR_1_LOWER, iwin1_start | min(megs, 128));
162 bcmpax_write_4(sc, PCIE_FUNC0_IMAP1, iwin1_start | 1);
163 #else
164 bcmpax_write_4(sc, PCIE_FUNC0_IMAP1, iwin1_start | min(megs, 128));
165 bcmpax_write_4(sc, PCIE_IARR_1_LOWER, iwin1_start | 1);
166 #endif
167 bcmpax_conf_write(sc, 0, PCI_MAPREG_START+4, iwin1_start);
168 if (iwin_megs > 128) {
169 bus_addr_t iwin2_start = iwin1_start + 128*1024*1024;
170 #if 1
171 bcmpax_write_4(sc, PCIE_IARR_2_LOWER, iwin2_start | min(megs - 128, 128));
172 bcmpax_write_4(sc, PCIE_FUNC0_IMAP2, iwin2_start | 1);
173 #else
174 bcmpax_write_4(sc, PCIE_FUNC0_IMAP2, iwin2_start | min(megs - 128, 128));
175 bcmpax_write_4(sc, PCIE_IARR_2_LOWER, iwin2_start | 1);
176 #endif
177 bcmpax_conf_write(sc, 0, PCI_MAPREG_START+8, iwin2_start);
178 }
179
180 if (megs <= iwin_megs) {
181 /*
182 * We could can DMA to all of memory so we don't need to subregion!
183 */
184 return 0;
185 }
186
187 return bus_dmatag_subregion(sc->sc_dmat, physical_start,
188 physical_start + (iwin_megs << 20) - 1, &sc->sc_dmat, 0);
189 #else
190 bcmpax_write_4(sc, PCIE_IARR_1_LOWER, 0);
191 bcmpax_write_4(sc, PCIE_FUNC0_IMAP1, 0);
192 bcmpax_write_4(sc, PCIE_IARR_2_LOWER, 0);
193 bcmpax_write_4(sc, PCIE_FUNC0_IMAP2, 0);
194 return 0;
195 #endif
196 }
197
198 static void
199 bcmpax_ccb_attach(device_t parent, device_t self, void *aux)
200 {
201 struct bcmpax_softc * const sc = device_private(self);
202 struct bcmccb_attach_args * const ccbaa = aux;
203 const struct bcm_locators * const loc = &ccbaa->ccbaa_loc;
204 const char * const xname = device_xname(self);
205 cfdata_t cf = device_cfdata(self);
206
207 sc->sc_dev = self;
208 sc->sc_dmat = &bcm53xx_coherent_dma_tag;
209 #ifdef _ARM32_NEED_BUS_DMA_BOUNCE
210 if (cf->cf_flags & 2) {
211 sc->sc_dmat = &bcm53xx_bounce_dma_tag;
212 }
213 #endif
214
215 for (u_int i = 0; i < 4; i++) {
216 snprintf(sc->sc_intrstring[i], sizeof(sc->sc_intrstring[i]),
217 "%s int%c", xname, 'a' + i);
218 }
219
220 sc->sc_bst = ccbaa->ccbaa_ccb_bst;
221 bus_space_subregion(sc->sc_bst, ccbaa->ccbaa_ccb_bsh,
222 loc->loc_offset, loc->loc_size, &sc->sc_bsh);
223
224 /*
225 * Kick the hardware into RC mode.
226 */
227 bcmpax_write_4(sc, PCIE_CLK_CONTROL, 3);
228 delay(250);
229 bcmpax_write_4(sc, PCIE_CLK_CONTROL, 1);
230
231 uint32_t v = bcmpax_read_4(sc, PCIE_STRAP_STATUS);
232 const bool enabled = (v & STRAP_PCIE_IF_ENABLE) != 0;
233 const bool is_v2_p = (v & STRAP_PCIE_USER_FOR_CE_GEN1) == 0;
234 const bool is_x2_p = (v & STRAP_PCIE_USER_FOR_CE_1LANE) == 0;
235 const bool is_rc_p = (v & STRAP_PCIE_USER_RC_MODE) != 0;
236
237 aprint_naive("\n");
238 aprint_normal(": PCI Express V%u %u-lane %s Controller%s\n",
239 is_v2_p ? 2 : 1,
240 is_x2_p ? 2 : 1,
241 is_rc_p ? "RC" : "EP",
242 enabled ? "" : "(disabled)");
243 if (!enabled || !is_rc_p)
244 return;
245
246 sc->sc_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_VM);
247 sc->sc_cfg_lock = mutex_obj_alloc(MUTEX_DEFAULT, IPL_VM);
248
249 TAILQ_INIT(&sc->sc_intrs);
250
251 sc->sc_pc.pc_conf_v = sc;
252 sc->sc_pc.pc_attach_hook = bcmpax_attach_hook;
253 sc->sc_pc.pc_bus_maxdevs = bcmpax_bus_maxdevs;
254 sc->sc_pc.pc_make_tag = bcmpax_make_tag;
255 sc->sc_pc.pc_decompose_tag = bcmpax_decompose_tag;
256 sc->sc_pc.pc_conf_read = bcmpax_conf_read;
257 sc->sc_pc.pc_conf_write = bcmpax_conf_write;
258
259 sc->sc_pc.pc_intr_v = sc;
260 sc->sc_pc.pc_intr_map = bcmpax_intr_map;
261 sc->sc_pc.pc_intr_string = bcmpax_intr_string;
262 sc->sc_pc.pc_intr_evcnt = bcmpax_intr_evcnt;
263 sc->sc_pc.pc_intr_establish = bcmpax_intr_establish;
264 sc->sc_pc.pc_intr_disestablish = bcmpax_intr_disestablish;
265
266 sc->sc_pc.pc_conf_hook = bcmpax_conf_hook;
267 sc->sc_pc.pc_conf_interrupt = bcmpax_conf_interrupt;
268
269 sc->sc_pba_flags |= PCI_FLAGS_MRL_OKAY;
270 sc->sc_pba_flags |= PCI_FLAGS_MRM_OKAY;
271 sc->sc_pba_flags |= PCI_FLAGS_MWI_OKAY;
272 // sc->sc_pba_flags |= PCI_FLAGS_MSI_OKAY;
273 // sc->sc_pba_flags |= PCI_FLAGS_MSIX_OKAY;
274
275 for (size_t i = 0; i < loc->loc_nintrs; i++) {
276 sc->sc_ih[i] = intr_establish(loc->loc_intrs[0] + i, IPL_VM,
277 IST_LEVEL, bcmpax_intr, sc);
278 if (sc->sc_ih[i] == NULL) {
279 aprint_error_dev(self,
280 "failed to establish interrupt #%zu (%zu)\n", i,
281 loc->loc_intrs[0] + i);
282 while (i-- > 0) {
283 intr_disestablish(sc->sc_ih[i]);
284 }
285 return;
286 }
287 }
288 aprint_normal_dev(self, "interrupting on irqs %d-%d\n",
289 loc->loc_intrs[0], loc->loc_intrs[0] + loc->loc_nintrs - 1);
290
291 /*
292 * Enable INTA-INTD
293 */
294 bcmpax_write_4(sc, PCIE_SYS_RC_INTX_EN, 0x0f);
295
296 int offset;
297 const bool ok = pci_get_capability(&sc->sc_pc, 0, PCI_CAP_PCIEXPRESS,
298 &offset, NULL);
299 KASSERT(ok);
300
301 /*
302 * This will force the device to negotiate to a max of gen1.
303 */
304 if (cf->cf_flags & 1) {
305 bcmpax_conf_write(sc, 0, offset + PCIE_LCSR2, 1);
306 }
307
308 /*
309 * Now we wait (.25 sec) for the link to come up.
310 */
311 offset += PCIE_LCSR;
312 for (size_t timo = 0;; timo++) {
313 const pcireg_t lcsr = bcmpax_conf_read(sc, 0, offset);
314 sc->sc_linkup = __SHIFTOUT(lcsr, PCIE_LCSR_NLW) != 0
315 && (1 || (lcsr & PCIE_LCSR_DLACTIVE) != 0);
316 if (sc->sc_linkup || timo == 250) {
317 aprint_debug_dev(self,
318 "lcsr=%#x nlw=%jd linkup=%d, timo=%zu\n",
319 lcsr, __SHIFTOUT(lcsr, PCIE_LCSR_NLW),
320 sc->sc_linkup, timo);
321 break;
322 }
323 DELAY(1000);
324 }
325
326 if (sc->sc_linkup) {
327 /*
328 * Enable the inbound (device->memory) map.
329 */
330 int error = bcmpax_iwin_init(sc);
331 if (error) {
332 aprint_error_dev(sc->sc_dev,
333 "failed to subregion dma tag: %d\n", error);
334 return;
335 }
336
337 aprint_normal_dev(self, "iwin[1]=%#x/%#x iwin[2]=%#x/%#x\n",
338 bcmpax_read_4(sc, PCIE_FUNC0_IMAP1),
339 bcmpax_read_4(sc, PCIE_IARR_1_LOWER),
340 bcmpax_read_4(sc, PCIE_FUNC0_IMAP2),
341 bcmpax_read_4(sc, PCIE_IARR_2_LOWER));
342
343 paddr_t base = bcmpax_owins[loc->loc_port].owin_base;
344 psize_t size = bcmpax_owins[loc->loc_port].owin_size;
345 KASSERT((size & ~PCIE_OARR_ADDR) == 0);
346 if (size > 0) {
347 bcmpax_write_4(sc, PCIE_OARR_0, base);
348 bcmpax_write_4(sc, PCIE_OMAP_0_LOWER, base | 1);
349 }
350 if (size > __LOWEST_SET_BIT(PCIE_OARR_ADDR)) {
351 paddr_t base1 = base + __LOWEST_SET_BIT(PCIE_OARR_ADDR);
352 bcmpax_write_4(sc, PCIE_OARR_1, base1);
353 bcmpax_write_4(sc, PCIE_OMAP_1_LOWER, base1 | 1);
354 }
355
356 struct extent *memext = extent_create("pcimem", base,
357 base + size, NULL, 0, EX_NOWAIT);
358
359 error = pci_configure_bus(&sc->sc_pc,
360 NULL, memext, NULL, 0, arm_pcache.dcache_line_size);
361
362 extent_destroy(memext);
363
364 if (error) {
365 aprint_normal_dev(self, "configuration failed\n");
366 return;
367 }
368 }
369
370 struct pcibus_attach_args pba;
371 memset(&pba, 0, sizeof(pba));
372
373 pba.pba_flags = sc->sc_pba_flags;
374 pba.pba_flags |= PCI_FLAGS_MEM_OKAY;
375 pba.pba_memt = sc->sc_bst;
376 pba.pba_dmat = sc->sc_dmat;
377 pba.pba_pc = &sc->sc_pc;
378 pba.pba_bus = 0;
379
380 config_found_ia(self, "pcibus", &pba, pcibusprint);
381 }
382
383 static void
384 bcmpax_attach_hook(device_t parent, device_t self,
385 struct pcibus_attach_args *pba)
386 {
387 }
388
389 static int
390 bcmpax_bus_maxdevs(void *v, int bus)
391 {
392 struct bcmpax_softc * const sc = v;
393
394 if (__predict_true(sc->sc_linkup))
395 return bus > 1 ? 32 : 1;
396
397 return bus ? 0 : 1;
398 }
399
400 static void
401 bcmpax_decompose_tag(void *v, pcitag_t tag, int *busp, int *devp, int *funcp)
402 {
403 if (busp)
404 *busp = __SHIFTOUT(tag, CFG_ADDR_BUS);
405 if (devp)
406 *devp = __SHIFTOUT(tag, CFG_ADDR_DEV);
407 if (funcp)
408 *funcp = __SHIFTOUT(tag, CFG_ADDR_FUNC);
409 }
410
411 static pcitag_t
412 bcmpax_make_tag(void *v, int bus, int dev, int func)
413 {
414 return __SHIFTIN(bus, CFG_ADDR_BUS)
415 | __SHIFTIN(dev, CFG_ADDR_DEV)
416 | __SHIFTIN(func, CFG_ADDR_FUNC)
417 | (bus == 0 ? CFG_ADDR_TYPE0 : CFG_ADDR_TYPE1);
418 }
419
420 static inline bus_size_t
421 bcmpax_conf_addr_write(struct bcmpax_softc *sc, pcitag_t tag)
422 {
423 if ((tag & (CFG_ADDR_BUS|CFG_ADDR_DEV)) == 0) {
424 uint32_t reg = __SHIFTOUT(tag, CFG_ADDR_REG);
425 uint32_t func = __SHIFTOUT(tag, CFG_ADDR_FUNC);
426 bcmpax_write_4(sc, PCIE_CFG_IND_ADDR,
427 __SHIFTIN(func, CFG_IND_ADDR_FUNC)
428 | __SHIFTIN(reg, CFG_IND_ADDR_REG));
429 __asm __volatile("dsb");
430 return PCIE_CFG_IND_DATA;
431 }
432 if (sc->sc_linkup) {
433 bcmpax_write_4(sc, PCIE_CFG_ADDR, tag);
434 __asm __volatile("dsb");
435 return PCIE_CFG_DATA;
436 }
437 return 0;
438 }
439
440 static pcireg_t
441 bcmpax_conf_read(void *v, pcitag_t tag, int reg)
442 {
443 struct bcmpax_softc * const sc = v;
444
445 /*
446 * Even in RC mode, the PCI Express Root Complex return itself
447 * as BCM Ethernet Controller!. We could change ppb.c to match it
448 * but we'll just lie and say we are a PPB bridge.
449 */
450 if ((tag & (CFG_ADDR_BUS|CFG_ADDR_DEV|CFG_ADDR_FUNC)) == 0
451 && reg == PCI_CLASS_REG) {
452 return PCI_CLASS_CODE(PCI_CLASS_BRIDGE,
453 PCI_SUBCLASS_BRIDGE_PCI, 0);
454 }
455
456 //printf("%s: tag %#lx reg %#x:", __func__, tag, reg);
457
458 mutex_enter(sc->sc_cfg_lock);
459 bus_size_t data_reg = bcmpax_conf_addr_write(sc, tag | reg);
460
461 //printf(" [from %#lx]:\n", data_reg);
462
463 pcireg_t rv;
464 if (data_reg)
465 rv = bcmpax_read_4(sc, data_reg);
466 else
467 rv = 0xffffffff;
468
469 mutex_exit(sc->sc_cfg_lock);
470
471 //printf(" %#x\n", rv);
472
473 return rv;
474 }
475
476 static void
477 bcmpax_conf_write(void *v, pcitag_t tag, int reg, pcireg_t val)
478 {
479 struct bcmpax_softc * const sc = v;
480
481 mutex_enter(sc->sc_cfg_lock);
482 bus_size_t data_reg = bcmpax_conf_addr_write(sc, tag | reg);
483
484 //printf("%s: tag %#lx reg %#x:", __func__, tag, reg);
485
486 if (data_reg) {
487 //printf(" [to %#lx]:\n", data_reg);
488 bcmpax_write_4(sc, data_reg, val);
489 //printf(" %#x\n", val);
490 }
491
492 mutex_exit(sc->sc_cfg_lock);
493 }
494
495 static void
496 bcmpax_conf_interrupt(void *v, int bus, int dev, int ipin, int swiz, int *ilinep)
497 {
498 *ilinep = 5; /* (ipin + swiz) & 3; */
499 }
500
501 static int
502 bcmpax_conf_hook(void *v, int bus, int dev, int func, pcireg_t id)
503 {
504 if (func > 0)
505 return 0;
506
507 return PCI_CONF_ENABLE_MEM | PCI_CONF_MAP_MEM | PCI_CONF_ENABLE_BM;
508 }
509
510 static int
511 bcmpax_intr(void *v)
512 {
513 struct bcmpax_softc * const sc = v;
514
515 while (bcmpax_read_4(sc, PCIE_SYS_RC_INTX_CSR)) {
516 struct bcmpax_intrhand *ih;
517 mutex_enter(sc->sc_lock);
518 const uint32_t lastgen = sc->sc_intrgen;
519 TAILQ_FOREACH(ih, &sc->sc_intrs, ih_link) {
520 int (* const func)(void *) = ih->ih_func;
521 void * const arg = ih->ih_arg;
522 mutex_exit(sc->sc_lock);
523 int rv = (*func)(arg);
524 if (rv) {
525 return rv;
526 }
527 mutex_enter(sc->sc_lock);
528 /*
529 * Check to see if the interrupt list changed.
530 * If so, restart from the beginning.
531 */
532 if (lastgen != sc->sc_intrgen)
533 break;
534 }
535 mutex_exit(sc->sc_lock);
536 }
537
538 return 0;
539 }
540
541 static int
542 bcmpax_intr_map(const struct pci_attach_args *pa, pci_intr_handle_t *pihp)
543 {
544 if (pa->pa_intrpin == 0)
545 return EINVAL;
546
547 *pihp = pa->pa_intrpin;
548 return 0;
549 }
550
551 static const char *
552 bcmpax_intr_string(void *v, pci_intr_handle_t pih)
553 {
554 struct bcmpax_softc * const sc = v;
555
556 if (pih)
557 return sc->sc_intrstring[pih - PCI_INTERRUPT_PIN_A];
558
559 return NULL;
560 }
561
562 static const struct evcnt *
563 bcmpax_intr_evcnt(void *v, pci_intr_handle_t pih)
564 {
565 return NULL;
566 }
567
568 static void *
569 bcmpax_intr_establish(void *v, pci_intr_handle_t pih, int ipl,
570 int (*func)(void *), void *arg)
571 {
572 struct bcmpax_softc * const sc = v;
573
574 KASSERT(!cpu_intr_p());
575 KASSERT(!cpu_softintr_p());
576 KASSERT(ipl == IPL_VM);
577 KASSERT(func != NULL);
578 KASSERT(arg != NULL);
579
580 if (pih == 0)
581 return NULL;
582
583 struct bcmpax_intrhand * const ih = kmem_alloc(sizeof(*ih), KM_SLEEP);
584
585 ih->ih_func = func;
586 ih->ih_arg = arg;
587
588 mutex_enter(sc->sc_lock);
589 TAILQ_INSERT_TAIL(&sc->sc_intrs, ih, ih_link);
590 mutex_exit(sc->sc_lock);
591
592 return ih;
593 }
594
595 static void
596 bcmpax_intr_disestablish(void *v, void *vih)
597 {
598 struct bcmpax_softc * const sc = v;
599 struct bcmpax_intrhand * const ih = vih;
600
601 mutex_enter(sc->sc_lock);
602 TAILQ_REMOVE(&sc->sc_intrs, ih, ih_link);
603 sc->sc_intrgen++;
604 mutex_exit(sc->sc_lock);
605
606 kmem_free(ih, sizeof(*ih));
607 }
608