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