Merge branch 'vendor/OPENPAM'
[dragonfly.git] / sys / platform / pc32 / icu / icu_abi.c
1 /*
2  * Copyright (c) 2005 The DragonFly Project.  All rights reserved.
3  * Copyright (c) 1991 The Regents of the University of California.
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 <sys/thread2.h>
56
57 #include <machine_base/icu/elcr_var.h>
58
59 #include <machine_base/icu/icu.h>
60 #include <machine_base/icu/icu_ipl.h>
61 #include <machine_base/apic/ioapic.h>
62
63 extern inthand_t
64         IDTVEC(icu_intr0),      IDTVEC(icu_intr1),
65         IDTVEC(icu_intr2),      IDTVEC(icu_intr3),
66         IDTVEC(icu_intr4),      IDTVEC(icu_intr5),
67         IDTVEC(icu_intr6),      IDTVEC(icu_intr7),
68         IDTVEC(icu_intr8),      IDTVEC(icu_intr9),
69         IDTVEC(icu_intr10),     IDTVEC(icu_intr11),
70         IDTVEC(icu_intr12),     IDTVEC(icu_intr13),
71         IDTVEC(icu_intr14),     IDTVEC(icu_intr15);
72
73 static inthand_t *icu_intr[ICU_HWI_VECTORS] = {
74         &IDTVEC(icu_intr0),     &IDTVEC(icu_intr1),
75         &IDTVEC(icu_intr2),     &IDTVEC(icu_intr3),
76         &IDTVEC(icu_intr4),     &IDTVEC(icu_intr5),
77         &IDTVEC(icu_intr6),     &IDTVEC(icu_intr7),
78         &IDTVEC(icu_intr8),     &IDTVEC(icu_intr9),
79         &IDTVEC(icu_intr10),    &IDTVEC(icu_intr11),
80         &IDTVEC(icu_intr12),    &IDTVEC(icu_intr13),
81         &IDTVEC(icu_intr14),    &IDTVEC(icu_intr15)
82 };
83
84 static struct icu_irqmap {
85         int                     im_type;        /* ICU_IMT_ */
86         enum intr_trigger       im_trig;
87         int                     im_msi_base;
88 } icu_irqmaps[MAXCPU][IDT_HWI_VECTORS];
89
90 static struct lwkt_token icu_irqmap_tok =
91         LWKT_TOKEN_INITIALIZER(icu_irqmap_token);
92
93 #define ICU_IMT_UNUSED          0       /* KEEP THIS */
94 #define ICU_IMT_RESERVED        1
95 #define ICU_IMT_LEGACY          2
96 #define ICU_IMT_SYSCALL         3
97 #define ICU_IMT_SHADOW          4
98 #define ICU_IMT_MSI             5
99 #define ICU_IMT_MSIX            6
100
101 #define ICU_IMT_ISHWI(map)      ((map)->im_type != ICU_IMT_RESERVED && \
102                                  (map)->im_type != ICU_IMT_SYSCALL && \
103                                  (map)->im_type != ICU_IMT_SHADOW)
104
105 extern void     ICU_INTREN(int);
106 extern void     ICU_INTRDIS(int);
107
108 extern int      imcr_present;
109
110 static void     icu_abi_intr_enable(int);
111 static void     icu_abi_intr_disable(int);
112 static void     icu_abi_intr_setup(int, int);
113 static void     icu_abi_intr_teardown(int);
114
115 static void     icu_abi_legacy_intr_config(int, enum intr_trigger,
116                     enum intr_polarity);
117 static int      icu_abi_legacy_intr_cpuid(int);
118
119 static int      icu_abi_msi_alloc(int [], int, int);
120 static void     icu_abi_msi_release(const int [], int, int);
121 static void     icu_abi_msi_map(int, uint64_t *, uint32_t *, int);
122 static int      icu_abi_msix_alloc(int *, int);
123 static void     icu_abi_msix_release(int, int);
124
125 static int      icu_abi_msi_alloc_intern(int, const char *,
126                     int [], int, int);
127 static void     icu_abi_msi_release_intern(int, const char *,
128                     const int [], int, int);
129
130 static void     icu_abi_finalize(void);
131 static void     icu_abi_cleanup(void);
132 static void     icu_abi_setdefault(void);
133 static void     icu_abi_stabilize(void);
134 static void     icu_abi_initmap(void);
135 static void     icu_abi_rman_setup(struct rman *);
136
137 struct machintr_abi MachIntrABI_ICU = {
138         MACHINTR_ICU,
139         .intr_disable   = icu_abi_intr_disable,
140         .intr_enable    = icu_abi_intr_enable,
141         .intr_setup     = icu_abi_intr_setup,
142         .intr_teardown  = icu_abi_intr_teardown,
143
144         .legacy_intr_config = icu_abi_legacy_intr_config,
145         .legacy_intr_cpuid = icu_abi_legacy_intr_cpuid,
146
147         .msi_alloc      = icu_abi_msi_alloc,
148         .msi_release    = icu_abi_msi_release,
149         .msi_map        = icu_abi_msi_map,
150         .msix_alloc     = icu_abi_msix_alloc,
151         .msix_release   = icu_abi_msix_release,
152
153         .finalize       = icu_abi_finalize,
154         .cleanup        = icu_abi_cleanup,
155         .setdefault     = icu_abi_setdefault,
156         .stabilize      = icu_abi_stabilize,
157         .initmap        = icu_abi_initmap,
158         .rman_setup     = icu_abi_rman_setup
159 };
160
161 static int      icu_abi_msi_start;      /* NOTE: for testing only */
162
163 /*
164  * WARNING!  SMP builds can use the ICU now so this code must be MP safe.
165  */
166
167 static void
168 icu_abi_intr_enable(int irq)
169 {
170         const struct icu_irqmap *map;
171
172         KASSERT(irq >= 0 && irq < IDT_HWI_VECTORS,
173             ("icu enable, invalid irq %d", irq));
174
175         map = &icu_irqmaps[mycpuid][irq];
176         KASSERT(ICU_IMT_ISHWI(map),
177             ("icu enable, not hwi irq %d, type %d, cpu%d",
178              irq, map->im_type, mycpuid));
179         if (map->im_type != ICU_IMT_LEGACY)
180                 return;
181
182         ICU_INTREN(irq);
183 }
184
185 static void
186 icu_abi_intr_disable(int irq)
187 {
188         const struct icu_irqmap *map;
189
190         KASSERT(irq >= 0 && irq < IDT_HWI_VECTORS,
191             ("icu disable, invalid irq %d", irq));
192
193         map = &icu_irqmaps[mycpuid][irq];
194         KASSERT(ICU_IMT_ISHWI(map),
195             ("icu disable, not hwi irq %d, type %d, cpu%d",
196              irq, map->im_type, mycpuid));
197         if (map->im_type != ICU_IMT_LEGACY)
198                 return;
199
200         ICU_INTRDIS(irq);
201 }
202
203 /*
204  * Called before interrupts are physically enabled
205  */
206 static void
207 icu_abi_stabilize(void)
208 {
209         int intr;
210
211         for (intr = 0; intr < ICU_HWI_VECTORS; ++intr)
212                 ICU_INTRDIS(intr);
213         ICU_INTREN(ICU_IRQ_SLAVE);
214 }
215
216 /*
217  * Called after interrupts physically enabled but before the
218  * critical section is released.
219  */
220 static void
221 icu_abi_cleanup(void)
222 {
223         bzero(mdcpu->gd_ipending, sizeof(mdcpu->gd_ipending));
224 }
225
226 /*
227  * Called after stablize and cleanup; critical section is not
228  * held and interrupts are not physically disabled.
229  */
230 static void
231 icu_abi_finalize(void)
232 {
233         KKASSERT(MachIntrABI.type == MACHINTR_ICU);
234         KKASSERT(!ioapic_enable);
235
236         /*
237          * If an IMCR is present, programming bit 0 disconnects the 8259
238          * from the BSP.  The 8259 may still be connected to LINT0 on the
239          * BSP's LAPIC.
240          *
241          * If we are running SMP the LAPIC is active, try to use virtual
242          * wire mode so we can use other interrupt sources within the LAPIC
243          * in addition to the 8259.
244          */
245         if (imcr_present) {
246                 outb(0x22, 0x70);
247                 outb(0x23, 0x01);
248         }
249 }
250
251 static void
252 icu_abi_intr_setup(int intr, int flags __unused)
253 {
254         const struct icu_irqmap *map;
255         u_long ef;
256
257         KASSERT(intr >= 0 && intr < IDT_HWI_VECTORS,
258             ("icu setup, invalid irq %d", intr));
259
260         map = &icu_irqmaps[mycpuid][intr];
261         KASSERT(ICU_IMT_ISHWI(map),
262             ("icu setup, not hwi irq %d, type %d, cpu%d",
263              intr, map->im_type, mycpuid));
264         if (map->im_type != ICU_IMT_LEGACY)
265                 return;
266
267         ef = read_eflags();
268         cpu_disable_intr();
269
270         ICU_INTREN(intr);
271
272         write_eflags(ef);
273 }
274
275 static void
276 icu_abi_intr_teardown(int intr)
277 {
278         const struct icu_irqmap *map;
279         u_long ef;
280
281         KASSERT(intr >= 0 && intr < IDT_HWI_VECTORS,
282             ("icu teardown, invalid irq %d", intr));
283
284         map = &icu_irqmaps[mycpuid][intr];
285         KASSERT(ICU_IMT_ISHWI(map),
286             ("icu teardown, not hwi irq %d, type %d, cpu%d",
287              intr, map->im_type, mycpuid));
288         if (map->im_type != ICU_IMT_LEGACY)
289                 return;
290
291         ef = read_eflags();
292         cpu_disable_intr();
293
294         ICU_INTRDIS(intr);
295
296         write_eflags(ef);
297 }
298
299 static void
300 icu_abi_setdefault(void)
301 {
302         int intr;
303
304         for (intr = 0; intr < ICU_HWI_VECTORS; ++intr) {
305                 if (intr == ICU_IRQ_SLAVE)
306                         continue;
307                 setidt(IDT_OFFSET + intr, icu_intr[intr], SDT_SYS386IGT,
308                        SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
309         }
310 }
311
312 static void
313 icu_abi_initmap(void)
314 {
315         int cpu;
316
317         kgetenv_int("hw.icu.msi_start", &icu_abi_msi_start);
318         icu_abi_msi_start &= ~0x1f;     /* MUST be 32 aligned */
319
320         /*
321          * NOTE: ncpus is not ready yet
322          */
323         for (cpu = 0; cpu < MAXCPU; ++cpu) {
324                 int i;
325
326                 if (cpu != 0) {
327                         for (i = 0; i < ICU_HWI_VECTORS; ++i)
328                                 icu_irqmaps[cpu][i].im_type = ICU_IMT_RESERVED;
329                 } else {
330                         for (i = 0; i < ICU_HWI_VECTORS; ++i)
331                                 icu_irqmaps[cpu][i].im_type = ICU_IMT_LEGACY;
332                         icu_irqmaps[cpu][ICU_IRQ_SLAVE].im_type =
333                             ICU_IMT_RESERVED;
334
335                         if (elcr_found) {
336                                 for (i = 0; i < ICU_HWI_VECTORS; ++i) {
337                                         icu_irqmaps[cpu][i].im_trig =
338                                             elcr_read_trigger(i);
339                                 }
340                         } else {
341                                 /*
342                                  * NOTE: Trigger mode does not matter at all
343                                  */
344                                 for (i = 0; i < ICU_HWI_VECTORS; ++i) {
345                                         icu_irqmaps[cpu][i].im_trig =
346                                             INTR_TRIGGER_EDGE;
347                                 }
348                         }
349                 }
350
351                 for (i = 0; i < IDT_HWI_VECTORS; ++i)
352                         icu_irqmaps[cpu][i].im_msi_base = -1;
353
354                 icu_irqmaps[cpu][IDT_OFFSET_SYSCALL - IDT_OFFSET].im_type =
355                     ICU_IMT_SYSCALL;
356         }
357 }
358
359 static void
360 icu_abi_legacy_intr_config(int irq, enum intr_trigger trig,
361     enum intr_polarity pola __unused)
362 {
363         struct icu_irqmap *map;
364
365         KKASSERT(trig == INTR_TRIGGER_EDGE || trig == INTR_TRIGGER_LEVEL);
366
367         KKASSERT(irq >= 0 && irq < IDT_HWI_VECTORS);
368         map = &icu_irqmaps[0][irq];
369
370         KKASSERT(map->im_type == ICU_IMT_LEGACY);
371
372         /* TODO: Check whether it is configured or not */
373
374         if (trig == map->im_trig)
375                 return;
376
377         if (bootverbose) {
378                 kprintf("ICU: irq %d, %s -> %s\n", irq,
379                         intr_str_trigger(map->im_trig),
380                         intr_str_trigger(trig));
381         }
382         map->im_trig = trig;
383
384         if (!elcr_found) {
385                 if (bootverbose)
386                         kprintf("ICU: no ELCR, skip irq %d config\n", irq);
387                 return;
388         }
389         elcr_write_trigger(irq, map->im_trig);
390 }
391
392 static int
393 icu_abi_legacy_intr_cpuid(int irq __unused)
394 {
395         return 0;
396 }
397
398 static void
399 icu_abi_rman_setup(struct rman *rm)
400 {
401         int start, end, i;
402
403         KASSERT(rm->rm_cpuid >= 0 && rm->rm_cpuid < MAXCPU,
404             ("invalid rman cpuid %d", rm->rm_cpuid));
405
406         start = end = -1;
407         for (i = 0; i < IDT_HWI_VECTORS; ++i) {
408                 const struct icu_irqmap *map = &icu_irqmaps[rm->rm_cpuid][i];
409
410                 if (start < 0) {
411                         if (ICU_IMT_ISHWI(map))
412                                 start = end = i;
413                 } else {
414                         if (ICU_IMT_ISHWI(map)) {
415                                 end = i;
416                         } else {
417                                 KKASSERT(end >= 0);
418                                 if (bootverbose) {
419                                         kprintf("ICU: rman cpu%d %d - %d\n",
420                                             rm->rm_cpuid, start, end);
421                                 }
422                                 if (rman_manage_region(rm, start, end)) {
423                                         panic("rman_manage_region"
424                                             "(cpu%d %d - %d)", rm->rm_cpuid,
425                                             start, end);
426                                 }
427                                 start = end = -1;
428                         }
429                 }
430         }
431         if (start >= 0) {
432                 KKASSERT(end >= 0);
433                 if (bootverbose) {
434                         kprintf("ICU: rman cpu%d %d - %d\n",
435                             rm->rm_cpuid, start, end);
436                 }
437                 if (rman_manage_region(rm, start, end)) {
438                         panic("rman_manage_region(cpu%d %d - %d)",
439                             rm->rm_cpuid, start, end);
440                 }
441         }
442 }
443
444 static int
445 icu_abi_msi_alloc_intern(int type, const char *desc,
446     int intrs[], int count, int cpuid)
447 {
448         int i, error;
449
450         KASSERT(cpuid >= 0 && cpuid < ncpus,
451             ("invalid cpuid %d", cpuid));
452
453         KASSERT(count > 0 && count <= 32, ("invalid count %d", count));
454         KASSERT((count & (count - 1)) == 0,
455             ("count %d is not power of 2", count));
456
457         lwkt_gettoken(&icu_irqmap_tok);
458
459         /*
460          * NOTE:
461          * Since IDT_OFFSET is 32, which is the maximum valid 'count',
462          * we do not need to find out the first properly aligned
463          * interrupt vector.
464          */
465
466         error = EMSGSIZE;
467         for (i = icu_abi_msi_start; i < IDT_HWI_VECTORS; i += count) {
468                 int j;
469
470                 if (icu_irqmaps[cpuid][i].im_type != ICU_IMT_UNUSED)
471                         continue;
472
473                 for (j = 1; j < count; ++j) {
474                         if (icu_irqmaps[cpuid][i + j].im_type != ICU_IMT_UNUSED)
475                                 break;
476                 }
477                 if (j != count)
478                         continue;
479
480                 for (j = 0; j < count; ++j) {
481                         int intr = i + j, cpu;
482
483                         for (cpu = 0; cpu < ncpus; ++cpu) {
484                                 struct icu_irqmap *map;
485
486                                 map = &icu_irqmaps[cpu][intr];
487                                 KASSERT(map->im_msi_base < 0,
488                                     ("intr %d cpu%d, stale %s-base %d",
489                                      intr, cpu, desc, map->im_msi_base));
490                                 KASSERT(map->im_type == ICU_IMT_UNUSED,
491                                     ("intr %d cpu%d, already allocated",
492                                      intr, cpu));
493
494                                 if (cpu == cpuid) {
495                                         map->im_type = type;
496                                         map->im_msi_base = i;
497                                 } else {
498                                         map->im_type = ICU_IMT_SHADOW;
499                                 }
500                         }
501
502                         intrs[j] = intr;
503                         msi_setup(intr);
504
505                         if (bootverbose) {
506                                 kprintf("alloc %s intr %d on cpu%d\n",
507                                     desc, intr, cpuid);
508                         }
509                 }
510                 error = 0;
511                 break;
512         }
513
514         lwkt_reltoken(&icu_irqmap_tok);
515
516         return error;
517 }
518
519 static void
520 icu_abi_msi_release_intern(int type, const char *desc,
521     const int intrs[], int count, int cpuid)
522 {
523         int i, msi_base = -1, intr_next = -1, mask;
524
525         KASSERT(cpuid >= 0 && cpuid < ncpus,
526             ("invalid cpuid %d", cpuid));
527
528         KASSERT(count > 0 && count <= 32, ("invalid count %d", count));
529
530         mask = count - 1;
531         KASSERT((count & mask) == 0, ("count %d is not power of 2", count));
532
533         lwkt_gettoken(&icu_irqmap_tok);
534
535         for (i = 0; i < count; ++i) {
536                 int intr = intrs[i], cpu;
537
538                 KASSERT(intr >= 0 && intr < IDT_HWI_VECTORS,
539                     ("invalid intr %d", intr));
540
541                 for (cpu = 0; cpu < ncpus; ++cpu) {
542                         struct icu_irqmap *map;
543
544                         map = &icu_irqmaps[cpu][intr];
545
546                         if (cpu == cpuid) {
547                                 KASSERT(map->im_type == type,
548                                     ("trying to release non-%s intr %d cpu%d, "
549                                      "type %d", desc, intr, cpu,
550                                      map->im_type));
551                                 KASSERT(map->im_msi_base >= 0 &&
552                                     map->im_msi_base <= intr,
553                                     ("intr %d cpu%d, invalid %s-base %d",
554                                      intr, cpu, desc, map->im_msi_base));
555                                 KASSERT((map->im_msi_base & mask) == 0,
556                                     ("intr %d cpu%d, %s-base %d is "
557                                      "not properly aligned %d",
558                                      intr, cpu, desc, map->im_msi_base, count));
559
560                                 if (msi_base < 0) {
561                                         msi_base = map->im_msi_base;
562                                 } else {
563                                         KASSERT(map->im_msi_base == msi_base,
564                                             ("intr %d cpu%d, "
565                                              "inconsistent %s-base, "
566                                              "was %d, now %d",
567                                              intr, cpu, desc,
568                                              msi_base, map->im_msi_base));
569                                 }
570                                 map->im_msi_base = -1;
571                         } else {
572                                 KASSERT(map->im_type == ICU_IMT_SHADOW,
573                                     ("trying to release non-%ssh intr %d cpu%d, "
574                                      "type %d", desc, intr, cpu,
575                                      map->im_type));
576                                 KASSERT(map->im_msi_base < 0,
577                                     ("intr %d cpu%d, invalid %ssh-base %d",
578                                      intr, cpu, desc, map->im_msi_base));
579                         }
580                         map->im_type = ICU_IMT_UNUSED;
581                 }
582
583                 if (intr_next < intr)
584                         intr_next = intr;
585
586                 if (bootverbose) {
587                         kprintf("release %s intr %d on cpu%d\n",
588                             desc, intr, cpuid);
589                 }
590         }
591
592         KKASSERT(intr_next > 0);
593         KKASSERT(msi_base >= 0);
594
595         ++intr_next;
596         if (intr_next < IDT_HWI_VECTORS) {
597                 int cpu;
598
599                 for (cpu = 0; cpu < ncpus; ++cpu) {
600                         const struct icu_irqmap *map =
601                             &icu_irqmaps[cpu][intr_next];
602
603                         if (map->im_type == type) {
604                                 KASSERT(map->im_msi_base != msi_base,
605                                     ("more than %d %s was allocated",
606                                      count, desc));
607                         }
608                 }
609         }
610
611         lwkt_reltoken(&icu_irqmap_tok);
612 }
613
614 static int
615 icu_abi_msi_alloc(int intrs[], int count, int cpuid)
616 {
617         return icu_abi_msi_alloc_intern(ICU_IMT_MSI, "MSI",
618             intrs, count, cpuid);
619 }
620
621 static void
622 icu_abi_msi_release(const int intrs[], int count, int cpuid)
623 {
624         icu_abi_msi_release_intern(ICU_IMT_MSI, "MSI",
625             intrs, count, cpuid);
626 }
627
628 static int
629 icu_abi_msix_alloc(int *intr, int cpuid)
630 {
631         return icu_abi_msi_alloc_intern(ICU_IMT_MSIX, "MSI-X",
632             intr, 1, cpuid);
633 }
634
635 static void
636 icu_abi_msix_release(int intr, int cpuid)
637 {
638         icu_abi_msi_release_intern(ICU_IMT_MSIX, "MSI-X",
639             &intr, 1, cpuid);
640 }
641
642 static void
643 icu_abi_msi_map(int intr, uint64_t *addr, uint32_t *data, int cpuid)
644 {
645         const struct icu_irqmap *map;
646
647         KASSERT(cpuid >= 0 && cpuid < ncpus,
648             ("invalid cpuid %d", cpuid));
649
650         KASSERT(intr >= 0 && intr < IDT_HWI_VECTORS,
651             ("invalid intr %d", intr));
652
653         lwkt_gettoken(&icu_irqmap_tok);
654
655         map = &icu_irqmaps[cpuid][intr];
656         KASSERT(map->im_type == ICU_IMT_MSI ||
657             map->im_type == ICU_IMT_MSIX,
658             ("trying to map non-MSI/MSI-X intr %d, type %d", intr, map->im_type));
659         KASSERT(map->im_msi_base >= 0 && map->im_msi_base <= intr,
660             ("intr %d, invalid %s-base %d", intr,
661              map->im_type == ICU_IMT_MSI ? "MSI" : "MSI-X",
662              map->im_msi_base));
663
664         msi_map(map->im_msi_base, addr, data, cpuid);
665
666         if (bootverbose) {
667                 kprintf("map %s intr %d on cpu%d\n",
668                     map->im_type == ICU_IMT_MSI ? "MSI" : "MSI-X",
669                     intr, cpuid);
670         }
671
672         lwkt_reltoken(&icu_irqmap_tok);
673 }