xref: /dragonfly/sys/platform/pc64/icu/icu_abi.c (revision 265a1428)
1 /*
2  * Copyright (c) 1991 The Regents of the University of California.
3  * Copyright (c) 2005,2008 The DragonFly Project.
4  * All rights reserved.
5  *
6  * This code is derived from software contributed to The DragonFly Project
7  * by Matthew Dillon <dillon@backplane.com>
8  *
9  * This code is derived from software contributed to Berkeley by
10  * William Jolitz.
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  *
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in
20  *    the documentation and/or other materials provided with the
21  *    distribution.
22  * 3. Neither the name of The DragonFly Project nor the names of its
23  *    contributors may be used to endorse or promote products derived
24  *    from this software without specific, prior written permission.
25  *
26  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
28  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
30  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
31  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
32  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
34  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
35  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
36  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
37  * SUCH DAMAGE.
38  */
39 
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
43 #include <sys/machintr.h>
44 #include <sys/interrupt.h>
45 #include <sys/rman.h>
46 #include <sys/bus.h>
47 
48 #include <machine/segments.h>
49 #include <machine/md_var.h>
50 #include <machine/intr_machdep.h>
51 #include <machine/globaldata.h>
52 #include <machine/smp.h>
53 #include <machine/msi_var.h>
54 
55 #include <machine_base/icu/elcr_var.h>
56 
57 #include <machine_base/icu/icu.h>
58 #include <machine_base/icu/icu_ipl.h>
59 #include <machine_base/apic/ioapic.h>
60 
61 extern inthand_t
62 	IDTVEC(icu_intr0),	IDTVEC(icu_intr1),
63 	IDTVEC(icu_intr2),	IDTVEC(icu_intr3),
64 	IDTVEC(icu_intr4),	IDTVEC(icu_intr5),
65 	IDTVEC(icu_intr6),	IDTVEC(icu_intr7),
66 	IDTVEC(icu_intr8),	IDTVEC(icu_intr9),
67 	IDTVEC(icu_intr10),	IDTVEC(icu_intr11),
68 	IDTVEC(icu_intr12),	IDTVEC(icu_intr13),
69 	IDTVEC(icu_intr14),	IDTVEC(icu_intr15);
70 
71 static inthand_t *icu_intr[ICU_HWI_VECTORS] = {
72 	&IDTVEC(icu_intr0),	&IDTVEC(icu_intr1),
73 	&IDTVEC(icu_intr2),	&IDTVEC(icu_intr3),
74 	&IDTVEC(icu_intr4),	&IDTVEC(icu_intr5),
75 	&IDTVEC(icu_intr6),	&IDTVEC(icu_intr7),
76 	&IDTVEC(icu_intr8),	&IDTVEC(icu_intr9),
77 	&IDTVEC(icu_intr10),	&IDTVEC(icu_intr11),
78 	&IDTVEC(icu_intr12),	&IDTVEC(icu_intr13),
79 	&IDTVEC(icu_intr14),	&IDTVEC(icu_intr15)
80 };
81 
82 static struct icu_irqmap {
83 	int			im_type;	/* ICU_IMT_ */
84 	enum intr_trigger	im_trig;
85 	int			im_msi_base;
86 	uint32_t		im_flags;	/* ICU_IMF_ */
87 } icu_irqmaps[MAXCPU][IDT_HWI_VECTORS];
88 
89 static struct lwkt_token icu_irqmap_tok =
90 	LWKT_TOKEN_INITIALIZER(icu_irqmap_token);
91 
92 #define ICU_IMT_UNUSED		0	/* KEEP THIS */
93 #define ICU_IMT_RESERVED	1
94 #define ICU_IMT_LEGACY		2
95 #define ICU_IMT_SYSCALL		3
96 #define ICU_IMT_MSI		4
97 #define ICU_IMT_MSIX		5
98 
99 #define ICU_IMT_ISHWI(map)	((map)->im_type != ICU_IMT_RESERVED && \
100 				 (map)->im_type != ICU_IMT_SYSCALL)
101 
102 #define ICU_IMF_CONF		0x1
103 
104 extern void	ICU_INTREN(int);
105 extern void	ICU_INTRDIS(int);
106 
107 extern int	imcr_present;
108 
109 static void	icu_abi_intr_enable(int);
110 static void	icu_abi_intr_disable(int);
111 static void	icu_abi_intr_setup(int, int);
112 static void	icu_abi_intr_teardown(int);
113 
114 static void	icu_abi_legacy_intr_config(int, enum intr_trigger,
115 		    enum intr_polarity);
116 static int	icu_abi_legacy_intr_cpuid(int);
117 static int	icu_abi_legacy_intr_find(int, enum intr_trigger,
118 		    enum intr_polarity);
119 static int	icu_abi_legacy_intr_find_bygsi(int, enum intr_trigger,
120 		    enum intr_polarity);
121 
122 static int	icu_abi_msi_alloc(int [], int, int);
123 static void	icu_abi_msi_release(const int [], int, int);
124 static void	icu_abi_msi_map(int, uint64_t *, uint32_t *, int);
125 static int	icu_abi_msix_alloc(int *, int);
126 static void	icu_abi_msix_release(int, int);
127 
128 static int	icu_abi_msi_alloc_intern(int, const char *,
129 		    int [], int, int);
130 static void	icu_abi_msi_release_intern(int, const char *,
131 		    const int [], int, int);
132 
133 static void	icu_abi_finalize(void);
134 static void	icu_abi_cleanup(void);
135 static void	icu_abi_setdefault(void);
136 static void	icu_abi_stabilize(void);
137 static void	icu_abi_initmap(void);
138 static void	icu_abi_rman_setup(struct rman *);
139 
140 struct machintr_abi MachIntrABI_ICU = {
141 	MACHINTR_ICU,
142 	.intr_disable	= icu_abi_intr_disable,
143 	.intr_enable	= icu_abi_intr_enable,
144 	.intr_setup	= icu_abi_intr_setup,
145 	.intr_teardown	= icu_abi_intr_teardown,
146 
147 	.legacy_intr_config = icu_abi_legacy_intr_config,
148 	.legacy_intr_cpuid = icu_abi_legacy_intr_cpuid,
149 	.legacy_intr_find = icu_abi_legacy_intr_find,
150 	.legacy_intr_find_bygsi = icu_abi_legacy_intr_find_bygsi,
151 
152 	.msi_alloc	= icu_abi_msi_alloc,
153 	.msi_release	= icu_abi_msi_release,
154 	.msi_map	= icu_abi_msi_map,
155 	.msix_alloc	= icu_abi_msix_alloc,
156 	.msix_release	= icu_abi_msix_release,
157 
158 	.finalize	= icu_abi_finalize,
159 	.cleanup	= icu_abi_cleanup,
160 	.setdefault	= icu_abi_setdefault,
161 	.stabilize	= icu_abi_stabilize,
162 	.initmap	= icu_abi_initmap,
163 	.rman_setup	= icu_abi_rman_setup
164 };
165 
166 static int	icu_abi_msi_start;	/* NOTE: for testing only */
167 
168 /*
169  * WARNING!  SMP builds can use the ICU now so this code must be MP safe.
170  */
171 
172 static void
173 icu_abi_intr_enable(int irq)
174 {
175 	const struct icu_irqmap *map;
176 
177 	KASSERT(irq >= 0 && irq < IDT_HWI_VECTORS,
178 	    ("icu enable, invalid irq %d", irq));
179 
180 	map = &icu_irqmaps[mycpuid][irq];
181 	KASSERT(ICU_IMT_ISHWI(map),
182 	    ("icu enable, not hwi irq %d, type %d, cpu%d",
183 	     irq, map->im_type, mycpuid));
184 	if (map->im_type != ICU_IMT_LEGACY)
185 		return;
186 
187 	ICU_INTREN(irq);
188 }
189 
190 static void
191 icu_abi_intr_disable(int irq)
192 {
193 	const struct icu_irqmap *map;
194 
195 	KASSERT(irq >= 0 && irq < IDT_HWI_VECTORS,
196 	    ("icu disable, invalid irq %d", irq));
197 
198 	map = &icu_irqmaps[mycpuid][irq];
199 	KASSERT(ICU_IMT_ISHWI(map),
200 	    ("icu disable, not hwi irq %d, type %d, cpu%d",
201 	     irq, map->im_type, mycpuid));
202 	if (map->im_type != ICU_IMT_LEGACY)
203 		return;
204 
205 	ICU_INTRDIS(irq);
206 }
207 
208 /*
209  * Called before interrupts are physically enabled
210  */
211 static void
212 icu_abi_stabilize(void)
213 {
214 	int intr;
215 
216 	for (intr = 0; intr < ICU_HWI_VECTORS; ++intr)
217 		ICU_INTRDIS(intr);
218 	ICU_INTREN(ICU_IRQ_SLAVE);
219 }
220 
221 /*
222  * Called after interrupts physically enabled but before the
223  * critical section is released.
224  */
225 static void
226 icu_abi_cleanup(void)
227 {
228 	bzero(mdcpu->gd_ipending, sizeof(mdcpu->gd_ipending));
229 }
230 
231 /*
232  * Called after stablize and cleanup; critical section is not
233  * held and interrupts are not physically disabled.
234  */
235 static void
236 icu_abi_finalize(void)
237 {
238 	KKASSERT(MachIntrABI.type == MACHINTR_ICU);
239 	KKASSERT(!ioapic_enable);
240 
241 	/*
242 	 * If an IMCR is present, programming bit 0 disconnects the 8259
243 	 * from the BSP.  The 8259 may still be connected to LINT0 on the
244 	 * BSP's LAPIC.
245 	 *
246 	 * If we are running SMP the LAPIC is active, try to use virtual
247 	 * wire mode so we can use other interrupt sources within the LAPIC
248 	 * in addition to the 8259.
249 	 */
250 	if (imcr_present) {
251 		outb(0x22, 0x70);
252 		outb(0x23, 0x01);
253 	}
254 }
255 
256 static void
257 icu_abi_intr_setup(int intr, int flags)
258 {
259 	const struct icu_irqmap *map;
260 	register_t ef;
261 
262 	KASSERT(intr >= 0 && intr < IDT_HWI_VECTORS,
263 	    ("icu setup, invalid irq %d", intr));
264 
265 	map = &icu_irqmaps[mycpuid][intr];
266 	KASSERT(ICU_IMT_ISHWI(map),
267 	    ("icu setup, not hwi irq %d, type %d, cpu%d",
268 	     intr, map->im_type, mycpuid));
269 	if (map->im_type != ICU_IMT_LEGACY)
270 		return;
271 
272 	ef = read_rflags();
273 	cpu_disable_intr();
274 
275 	ICU_INTREN(intr);
276 
277 	write_rflags(ef);
278 }
279 
280 static void
281 icu_abi_intr_teardown(int intr)
282 {
283 	const struct icu_irqmap *map;
284 	register_t ef;
285 
286 	KASSERT(intr >= 0 && intr < IDT_HWI_VECTORS,
287 	    ("icu teardown, invalid irq %d", intr));
288 
289 	map = &icu_irqmaps[mycpuid][intr];
290 	KASSERT(ICU_IMT_ISHWI(map),
291 	    ("icu teardown, not hwi irq %d, type %d, cpu%d",
292 	     intr, map->im_type, mycpuid));
293 	if (map->im_type != ICU_IMT_LEGACY)
294 		return;
295 
296 	ef = read_rflags();
297 	cpu_disable_intr();
298 
299 	ICU_INTRDIS(intr);
300 
301 	write_rflags(ef);
302 }
303 
304 static void
305 icu_abi_setdefault(void)
306 {
307 	int intr;
308 
309 	for (intr = 0; intr < ICU_HWI_VECTORS; ++intr) {
310 		if (intr == ICU_IRQ_SLAVE)
311 			continue;
312 		setidt_global(IDT_OFFSET + intr, icu_intr[intr],
313 		    SDT_SYSIGT, SEL_KPL, 0);
314 	}
315 }
316 
317 static void
318 icu_abi_initmap(void)
319 {
320 	int cpu;
321 
322 	kgetenv_int("hw.icu.msi_start", &icu_abi_msi_start);
323 	icu_abi_msi_start &= ~0x1f;	/* MUST be 32 aligned */
324 
325 	/*
326 	 * NOTE: ncpus is not ready yet
327 	 */
328 	for (cpu = 0; cpu < MAXCPU; ++cpu) {
329 		int i;
330 
331 		if (cpu != 0) {
332 			for (i = 0; i < ICU_HWI_VECTORS; ++i)
333 				icu_irqmaps[cpu][i].im_type = ICU_IMT_RESERVED;
334 		} else {
335 			for (i = 0; i < ICU_HWI_VECTORS; ++i)
336 				icu_irqmaps[cpu][i].im_type = ICU_IMT_LEGACY;
337 			icu_irqmaps[cpu][ICU_IRQ_SLAVE].im_type =
338 			    ICU_IMT_RESERVED;
339 
340 			if (elcr_found) {
341 				for (i = 0; i < ICU_HWI_VECTORS; ++i) {
342 					icu_irqmaps[cpu][i].im_trig =
343 					    elcr_read_trigger(i);
344 				}
345 			} else {
346 				/*
347 				 * NOTE: Trigger mode does not matter at all
348 				 */
349 				for (i = 0; i < ICU_HWI_VECTORS; ++i) {
350 					icu_irqmaps[cpu][i].im_trig =
351 					    INTR_TRIGGER_EDGE;
352 				}
353 			}
354 		}
355 
356 		for (i = 0; i < IDT_HWI_VECTORS; ++i)
357 			icu_irqmaps[cpu][i].im_msi_base = -1;
358 
359 		icu_irqmaps[cpu][IDT_OFFSET_SYSCALL - IDT_OFFSET].im_type =
360 		    ICU_IMT_SYSCALL;
361 	}
362 }
363 
364 static void
365 icu_abi_legacy_intr_config(int irq, enum intr_trigger trig,
366     enum intr_polarity pola __unused)
367 {
368 	struct icu_irqmap *map;
369 
370 	KKASSERT(trig == INTR_TRIGGER_EDGE || trig == INTR_TRIGGER_LEVEL);
371 
372 	KKASSERT(irq >= 0 && irq < IDT_HWI_VECTORS);
373 	map = &icu_irqmaps[0][irq];
374 
375 	KKASSERT(map->im_type == ICU_IMT_LEGACY);
376 
377 	/* TODO: Check whether it is configured or not */
378 	map->im_flags |= ICU_IMF_CONF;
379 
380 	if (trig == map->im_trig)
381 		return;
382 
383 	if (bootverbose) {
384 		kprintf("ICU: irq %d, %s -> %s\n", irq,
385 			intr_str_trigger(map->im_trig),
386 			intr_str_trigger(trig));
387 	}
388 	map->im_trig = trig;
389 
390 	if (!elcr_found) {
391 		if (bootverbose)
392 			kprintf("ICU: no ELCR, skip irq %d config\n", irq);
393 		return;
394 	}
395 	elcr_write_trigger(irq, map->im_trig);
396 }
397 
398 static int
399 icu_abi_legacy_intr_cpuid(int irq __unused)
400 {
401 	return 0;
402 }
403 
404 static void
405 icu_abi_rman_setup(struct rman *rm)
406 {
407 	int start, end, i;
408 
409 	KASSERT(rm->rm_cpuid >= 0 && rm->rm_cpuid < MAXCPU,
410 	    ("invalid rman cpuid %d", rm->rm_cpuid));
411 
412 	start = end = -1;
413 	for (i = 0; i < IDT_HWI_VECTORS; ++i) {
414 		const struct icu_irqmap *map = &icu_irqmaps[rm->rm_cpuid][i];
415 
416 		if (start < 0) {
417 			if (ICU_IMT_ISHWI(map))
418 				start = end = i;
419 		} else {
420 			if (ICU_IMT_ISHWI(map)) {
421 				end = i;
422 			} else {
423 				KKASSERT(end >= 0);
424 				if (bootverbose) {
425 					kprintf("ICU: rman cpu%d %d - %d\n",
426 					    rm->rm_cpuid, start, end);
427 				}
428 				if (rman_manage_region(rm, start, end)) {
429 					panic("rman_manage_region"
430 					    "(cpu%d %d - %d)", rm->rm_cpuid,
431 					    start, end);
432 				}
433 				start = end = -1;
434 			}
435 		}
436 	}
437 	if (start >= 0) {
438 		KKASSERT(end >= 0);
439 		if (bootverbose) {
440 			kprintf("ICU: rman cpu%d %d - %d\n",
441 			    rm->rm_cpuid, start, end);
442 		}
443 		if (rman_manage_region(rm, start, end)) {
444 			panic("rman_manage_region(cpu%d %d - %d)",
445 			    rm->rm_cpuid, start, end);
446 		}
447 	}
448 }
449 
450 static int
451 icu_abi_msi_alloc_intern(int type, const char *desc,
452     int intrs[], int count, int cpuid)
453 {
454 	int i, error;
455 
456 	KASSERT(cpuid >= 0 && cpuid < ncpus,
457 	    ("invalid cpuid %d", cpuid));
458 
459 	KASSERT(count > 0 && count <= 32, ("invalid count %d", count));
460 	KASSERT((count & (count - 1)) == 0,
461 	    ("count %d is not power of 2", count));
462 
463 	lwkt_gettoken(&icu_irqmap_tok);
464 
465 	/*
466 	 * NOTE:
467 	 * Since IDT_OFFSET is 32, which is the maximum valid 'count',
468 	 * we do not need to find out the first properly aligned
469 	 * interrupt vector.
470 	 */
471 
472 	error = EMSGSIZE;
473 	for (i = icu_abi_msi_start; i < IDT_HWI_VECTORS; i += count) {
474 		int j;
475 
476 		if (icu_irqmaps[cpuid][i].im_type != ICU_IMT_UNUSED)
477 			continue;
478 
479 		for (j = 1; j < count; ++j) {
480 			if (icu_irqmaps[cpuid][i + j].im_type != ICU_IMT_UNUSED)
481 				break;
482 		}
483 		if (j != count)
484 			continue;
485 
486 		for (j = 0; j < count; ++j) {
487 			struct icu_irqmap *map;
488 			int intr = i + j;
489 
490 			map = &icu_irqmaps[cpuid][intr];
491 			KASSERT(map->im_msi_base < 0,
492 			    ("intr %d, stale %s-base %d",
493 			     intr, desc, map->im_msi_base));
494 
495 			map->im_type = type;
496 			map->im_msi_base = i;
497 
498 			intrs[j] = intr;
499 			msi_setup(intr, cpuid);
500 
501 			if (bootverbose) {
502 				kprintf("alloc %s intr %d on cpu%d\n",
503 				    desc, intr, cpuid);
504 			}
505 		}
506 		error = 0;
507 		break;
508 	}
509 
510 	lwkt_reltoken(&icu_irqmap_tok);
511 
512 	return error;
513 }
514 
515 static void
516 icu_abi_msi_release_intern(int type, const char *desc,
517     const int intrs[], int count, int cpuid)
518 {
519 	int i, msi_base = -1, intr_next = -1, mask;
520 
521 	KASSERT(cpuid >= 0 && cpuid < ncpus,
522 	    ("invalid cpuid %d", cpuid));
523 
524 	KASSERT(count > 0 && count <= 32, ("invalid count %d", count));
525 
526 	mask = count - 1;
527 	KASSERT((count & mask) == 0, ("count %d is not power of 2", count));
528 
529 	lwkt_gettoken(&icu_irqmap_tok);
530 
531 	for (i = 0; i < count; ++i) {
532 		struct icu_irqmap *map;
533 		int intr = intrs[i];
534 
535 		KASSERT(intr >= 0 && intr < IDT_HWI_VECTORS,
536 		    ("invalid intr %d", intr));
537 
538 		map = &icu_irqmaps[cpuid][intr];
539 		KASSERT(map->im_type == type,
540 		    ("trying to release non-%s intr %d, type %d", desc,
541 		     intr, map->im_type));
542 		KASSERT(map->im_msi_base >= 0 && map->im_msi_base <= intr,
543 		    ("intr %d, invalid %s-base %d", intr, desc,
544 		     map->im_msi_base));
545 		KASSERT((map->im_msi_base & mask) == 0,
546 		    ("intr %d, %s-base %d is not properly aligned %d",
547 		     intr, desc, map->im_msi_base, count));
548 
549 		if (msi_base < 0) {
550 			msi_base = map->im_msi_base;
551 		} else {
552 			KASSERT(map->im_msi_base == msi_base,
553 			    ("intr %d, inconsistent %s-base, "
554 			     "was %d, now %d",
555 			     intr, desc, msi_base, map->im_msi_base));
556 		}
557 
558 		if (intr_next < intr)
559 			intr_next = intr;
560 
561 		map->im_type = ICU_IMT_UNUSED;
562 		map->im_msi_base = -1;
563 
564 		if (bootverbose) {
565 			kprintf("release %s intr %d on cpu%d\n",
566 			    desc, intr, cpuid);
567 		}
568 	}
569 
570 	KKASSERT(intr_next > 0);
571 	KKASSERT(msi_base >= 0);
572 
573 	++intr_next;
574 	if (intr_next < IDT_HWI_VECTORS) {
575 		const struct icu_irqmap *map = &icu_irqmaps[cpuid][intr_next];
576 
577 		if (map->im_type == type) {
578 			KASSERT(map->im_msi_base != msi_base,
579 			    ("more than %d %s was allocated", count, desc));
580 		}
581 	}
582 
583 	lwkt_reltoken(&icu_irqmap_tok);
584 }
585 
586 static int
587 icu_abi_msi_alloc(int intrs[], int count, int cpuid)
588 {
589 	return icu_abi_msi_alloc_intern(ICU_IMT_MSI, "MSI",
590 	    intrs, count, cpuid);
591 }
592 
593 static void
594 icu_abi_msi_release(const int intrs[], int count, int cpuid)
595 {
596 	icu_abi_msi_release_intern(ICU_IMT_MSI, "MSI",
597 	    intrs, count, cpuid);
598 }
599 
600 static int
601 icu_abi_msix_alloc(int *intr, int cpuid)
602 {
603 	return icu_abi_msi_alloc_intern(ICU_IMT_MSIX, "MSI-X",
604 	    intr, 1, cpuid);
605 }
606 
607 static void
608 icu_abi_msix_release(int intr, int cpuid)
609 {
610 	icu_abi_msi_release_intern(ICU_IMT_MSIX, "MSI-X",
611 	    &intr, 1, cpuid);
612 }
613 
614 static void
615 icu_abi_msi_map(int intr, uint64_t *addr, uint32_t *data, int cpuid)
616 {
617 	const struct icu_irqmap *map;
618 
619 	KASSERT(cpuid >= 0 && cpuid < ncpus,
620 	    ("invalid cpuid %d", cpuid));
621 
622 	KASSERT(intr >= 0 && intr < IDT_HWI_VECTORS,
623 	    ("invalid intr %d", intr));
624 
625 	lwkt_gettoken(&icu_irqmap_tok);
626 
627 	map = &icu_irqmaps[cpuid][intr];
628 	KASSERT(map->im_type == ICU_IMT_MSI ||
629 	    map->im_type == ICU_IMT_MSIX,
630 	    ("trying to map non-MSI/MSI-X intr %d, type %d", intr, map->im_type));
631 	KASSERT(map->im_msi_base >= 0 && map->im_msi_base <= intr,
632 	    ("intr %d, invalid %s-base %d", intr,
633 	     map->im_type == ICU_IMT_MSI ? "MSI" : "MSI-X",
634 	     map->im_msi_base));
635 
636 	msi_map(map->im_msi_base, addr, data, cpuid);
637 
638 	if (bootverbose) {
639 		kprintf("map %s intr %d on cpu%d\n",
640 		    map->im_type == ICU_IMT_MSI ? "MSI" : "MSI-X",
641 		    intr, cpuid);
642 	}
643 
644 	lwkt_reltoken(&icu_irqmap_tok);
645 }
646 
647 static int
648 icu_abi_legacy_intr_find(int irq, enum intr_trigger trig,
649     enum intr_polarity pola __unused)
650 {
651 	const struct icu_irqmap *map;
652 
653 #ifdef INVARIANTS
654 	if (trig == INTR_TRIGGER_CONFORM) {
655 		KKASSERT(pola == INTR_POLARITY_CONFORM);
656 	} else {
657 		KKASSERT(trig == INTR_TRIGGER_EDGE ||
658 		    trig == INTR_TRIGGER_LEVEL);
659 		KKASSERT(pola == INTR_POLARITY_HIGH ||
660 		    pola == INTR_POLARITY_LOW);
661 	}
662 #endif
663 
664 	if (irq < 0 || irq >= ICU_HWI_VECTORS)
665 		return -1;
666 
667 	map = &icu_irqmaps[0][irq];
668 	if (map->im_type == ICU_IMT_LEGACY) {
669 		if ((map->im_flags & ICU_IMF_CONF) &&
670 		    trig != INTR_TRIGGER_CONFORM) {
671 			if (map->im_trig != trig)
672 				return -1;
673 		}
674 		return irq;
675 	}
676 	return -1;
677 }
678 
679 static int
680 icu_abi_legacy_intr_find_bygsi(int gsi, enum intr_trigger trig,
681     enum intr_polarity pola)
682 {
683 	/* GSI and IRQ has 1:1 mapping */
684 	return icu_abi_legacy_intr_find(gsi, trig, pola);
685 }
686