xref: /netbsd-src/sys/arch/xen/x86/pintr.c (revision e0ffc84538903155472197740d03a34565d6f872)
1e3cb69cbScherry /*	NetBSD: intr.c,v 1.15 2004/04/10 14:49:55 kochi Exp 	*/
2e3cb69cbScherry 
3e3cb69cbScherry /*
4e3cb69cbScherry  * Copyright 2002 (c) Wasabi Systems, Inc.
5e3cb69cbScherry  * All rights reserved.
6e3cb69cbScherry  *
7e3cb69cbScherry  * Written by Frank van der Linden for Wasabi Systems, Inc.
8e3cb69cbScherry  *
9e3cb69cbScherry  * Redistribution and use in source and binary forms, with or without
10e3cb69cbScherry  * modification, are permitted provided that the following conditions
11e3cb69cbScherry  * are met:
12e3cb69cbScherry  * 1. Redistributions of source code must retain the above copyright
13e3cb69cbScherry  *    notice, this list of conditions and the following disclaimer.
14e3cb69cbScherry  * 2. Redistributions in binary form must reproduce the above copyright
15e3cb69cbScherry  *    notice, this list of conditions and the following disclaimer in the
16e3cb69cbScherry  *    documentation and/or other materials provided with the distribution.
17e3cb69cbScherry  * 3. All advertising materials mentioning features or use of this software
18e3cb69cbScherry  *    must display the following acknowledgement:
19e3cb69cbScherry  *      This product includes software developed for the NetBSD Project by
20e3cb69cbScherry  *      Wasabi Systems, Inc.
21e3cb69cbScherry  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22e3cb69cbScherry  *    or promote products derived from this software without specific prior
23e3cb69cbScherry  *    written permission.
24e3cb69cbScherry  *
25e3cb69cbScherry  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26e3cb69cbScherry  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27e3cb69cbScherry  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28e3cb69cbScherry  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
29e3cb69cbScherry  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30e3cb69cbScherry  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31e3cb69cbScherry  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32e3cb69cbScherry  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33e3cb69cbScherry  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34e3cb69cbScherry  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35e3cb69cbScherry  * POSSIBILITY OF SUCH DAMAGE.
36e3cb69cbScherry  */
37e3cb69cbScherry 
38e3cb69cbScherry /*-
39e3cb69cbScherry  * Copyright (c) 1991 The Regents of the University of California.
40e3cb69cbScherry  * All rights reserved.
41e3cb69cbScherry  *
42e3cb69cbScherry  * This code is derived from software contributed to Berkeley by
43e3cb69cbScherry  * William Jolitz.
44e3cb69cbScherry  *
45e3cb69cbScherry  * Redistribution and use in source and binary forms, with or without
46e3cb69cbScherry  * modification, are permitted provided that the following conditions
47e3cb69cbScherry  * are met:
48e3cb69cbScherry  * 1. Redistributions of source code must retain the above copyright
49e3cb69cbScherry  *    notice, this list of conditions and the following disclaimer.
50e3cb69cbScherry  * 2. Redistributions in binary form must reproduce the above copyright
51e3cb69cbScherry  *    notice, this list of conditions and the following disclaimer in the
52e3cb69cbScherry  *    documentation and/or other materials provided with the distribution.
53e3cb69cbScherry  * 3. Neither the name of the University nor the names of its contributors
54e3cb69cbScherry  *    may be used to endorse or promote products derived from this software
55e3cb69cbScherry  *    without specific prior written permission.
56e3cb69cbScherry  *
57e3cb69cbScherry  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
58e3cb69cbScherry  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
59e3cb69cbScherry  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
60e3cb69cbScherry  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
61e3cb69cbScherry  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
62e3cb69cbScherry  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
63e3cb69cbScherry  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
64e3cb69cbScherry  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
65e3cb69cbScherry  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
66e3cb69cbScherry  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
67e3cb69cbScherry  * SUCH DAMAGE.
68e3cb69cbScherry  *
69e3cb69cbScherry  *     @(#)isa.c       7.2 (Berkeley) 5/13/91
70e3cb69cbScherry  */
71e3cb69cbScherry /*-
72e3cb69cbScherry  * Copyright (c) 1993, 1994 Charles Hannum.
73e3cb69cbScherry  *
74e3cb69cbScherry  * Redistribution and use in source and binary forms, with or without
75e3cb69cbScherry  * modification, are permitted provided that the following conditions
76e3cb69cbScherry  * are met:
77e3cb69cbScherry  * 1. Redistributions of source code must retain the above copyright
78e3cb69cbScherry  *    notice, this list of conditions and the following disclaimer.
79e3cb69cbScherry  * 2. Redistributions in binary form must reproduce the above copyright
80e3cb69cbScherry  *    notice, this list of conditions and the following disclaimer in the
81e3cb69cbScherry  *    documentation and/or other materials provided with the distribution.
82e3cb69cbScherry  * 3. All advertising materials mentioning features or use of this software
83e3cb69cbScherry  *    must display the following acknowledgement:
84e3cb69cbScherry  *     This product includes software developed by the University of
85e3cb69cbScherry  *     California, Berkeley and its contributors.
86e3cb69cbScherry  * 4. Neither the name of the University nor the names of its contributors
87e3cb69cbScherry  *    may be used to endorse or promote products derived from this software
88e3cb69cbScherry  *    without specific prior written permission.
89e3cb69cbScherry  *
90e3cb69cbScherry  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
91e3cb69cbScherry  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
92e3cb69cbScherry  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
93e3cb69cbScherry  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
94e3cb69cbScherry  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
95e3cb69cbScherry  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
96e3cb69cbScherry  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
97e3cb69cbScherry  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
98e3cb69cbScherry  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
99e3cb69cbScherry  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
100e3cb69cbScherry  * SUCH DAMAGE.
101e3cb69cbScherry  *
102e3cb69cbScherry  *     @(#)isa.c       7.2 (Berkeley) 5/13/91
103e3cb69cbScherry  */
104e3cb69cbScherry 
105e3cb69cbScherry #include <sys/cdefs.h>
106*e0ffc845Sbouyer __KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.24 2022/05/26 11:06:14 bouyer Exp $");
107e3cb69cbScherry 
108e3cb69cbScherry #include "opt_multiprocessor.h"
109e3cb69cbScherry #include "opt_xen.h"
110e3cb69cbScherry #include "isa.h"
111e3cb69cbScherry #include "pci.h"
1121947fd1bSjdolecek #include "opt_pci.h"
113e3cb69cbScherry 
114e3cb69cbScherry #include <sys/param.h>
115e3cb69cbScherry #include <sys/systm.h>
116e3cb69cbScherry #include <sys/kernel.h>
117e3cb69cbScherry #include <sys/syslog.h>
118e3cb69cbScherry #include <sys/device.h>
119e3cb69cbScherry #include <sys/proc.h>
120e3cb69cbScherry #include <sys/errno.h>
121e3cb69cbScherry #include <sys/cpu.h>
122e3cb69cbScherry 
123e3cb69cbScherry #include <uvm/uvm_extern.h>
124e3cb69cbScherry 
125e3cb69cbScherry #include <machine/i8259.h>
126e3cb69cbScherry #include <machine/pio.h>
127e3cb69cbScherry #include <xen/evtchn.h>
128e3cb69cbScherry #include <xen/intr.h>
129e3cb69cbScherry 
1301947fd1bSjdolecek #include <dev/pci/pcivar.h>
1311947fd1bSjdolecek 
132d5100c23Sjdolecek #ifdef __HAVE_PCI_MSI_MSIX
133d5100c23Sjdolecek #include <x86/pci/msipic.h>
134d5100c23Sjdolecek #endif
135d5100c23Sjdolecek 
136e3cb69cbScherry #include "acpica.h"
137e3cb69cbScherry #include "ioapic.h"
138e3cb69cbScherry #include "opt_mpbios.h"
139e3cb69cbScherry 
140e3cb69cbScherry #if NIOAPIC > 0
141e3cb69cbScherry /* XXX: todo - compat with lapic.c and XEN for x2apic */
142e3cb69cbScherry bool x2apic_mode __read_mostly = false;
143e3cb69cbScherry /* for x86/i8259.c */
144c4e6273bScherry struct intrstub legacy_stubs[NUM_LEGACY_IRQS] = {{0,0,0}};
145e3cb69cbScherry /* for x86/ioapic.c */
146c4e6273bScherry struct intrstub ioapic_edge_stubs[MAX_INTR_SOURCES] = {{0,0,0}};
147c4e6273bScherry struct intrstub ioapic_level_stubs[MAX_INTR_SOURCES] = {{0,0,0}};
148c4e6273bScherry struct intrstub x2apic_edge_stubs[MAX_INTR_SOURCES] = {{0,0,0}};
149c4e6273bScherry struct intrstub x2apic_level_stubs[MAX_INTR_SOURCES] = {{0,0,0}};
150e3cb69cbScherry #include <machine/i82093var.h>
151c4e6273bScherry #endif /* NIOAPIC */
152c4e6273bScherry 
153d5100c23Sjdolecek // XXX NR_EVENT_CHANNELS is 2048, use some sparse structure?
1540ae0d1b1Sjdolecek short irq2port[NR_EVENT_CHANNELS] = {0}; /* actually port + 1, so that 0 is invaid */
155c4e6273bScherry 
156e3cb69cbScherry #if NACPICA > 0
157e3cb69cbScherry #include <machine/mpconfig.h>
158e3cb69cbScherry #include <machine/mpacpi.h>
159e3cb69cbScherry #endif
160e3cb69cbScherry #ifdef MPBIOS
161e3cb69cbScherry #include <machine/mpbiosvar.h>
162e3cb69cbScherry #endif
163e3cb69cbScherry 
164e3cb69cbScherry #if NPCI > 0
165e3cb69cbScherry #include <dev/pci/ppbreg.h>
166e3cb69cbScherry #endif
167e3cb69cbScherry 
168e3cb69cbScherry #if defined(DOM0OPS) || NPCI > 0
1696bd27cf6Sjdolecek 
170e36c697cSjdolecek #ifdef __HAVE_PCI_MSI_MSIX
17130654f1bSbouyer int
xen_map_msi_pirq(struct pic * pic,int count)17230654f1bSbouyer xen_map_msi_pirq(struct pic *pic, int count)
1736bd27cf6Sjdolecek {
1746bd27cf6Sjdolecek 	struct physdev_map_pirq map_irq;
17530654f1bSbouyer 	const struct msipic_pci_info *msi_i = msipic_get_pci_info(pic);
17630654f1bSbouyer 	int i;
1776bd27cf6Sjdolecek 	int ret;
1786bd27cf6Sjdolecek 
1796bd27cf6Sjdolecek 	if (count == -1)
18030654f1bSbouyer 		count = msi_i->mp_veccnt;
1816bd27cf6Sjdolecek 	KASSERT(count > 0);
1826bd27cf6Sjdolecek 
18330654f1bSbouyer 	KASSERT(pic->pic_type == PIC_MSI);
18430654f1bSbouyer 
1856bd27cf6Sjdolecek 	memset(&map_irq, 0, sizeof(map_irq));
1866bd27cf6Sjdolecek 	map_irq.domid = DOMID_SELF;
1876bd27cf6Sjdolecek 	map_irq.type = MAP_PIRQ_TYPE_MSI_SEG;
1886bd27cf6Sjdolecek 	map_irq.index = -1;
1896bd27cf6Sjdolecek 	map_irq.pirq = -1;
19030654f1bSbouyer 	map_irq.bus = msi_i->mp_bus;
19130654f1bSbouyer  	map_irq.devfn = (msi_i->mp_dev << 3) | msi_i->mp_fun;
19230654f1bSbouyer 	aprint_debug("xen_map_msi_pirq bus %d devfn 0x%x (%d %d) entry_nr %d",
19330654f1bSbouyer 	    map_irq.bus, map_irq.devfn, msi_i->mp_dev, msi_i->mp_fun,
19430654f1bSbouyer 	    map_irq.entry_nr);
1956bd27cf6Sjdolecek 	map_irq.entry_nr = count;
19630654f1bSbouyer 	if (msi_i->mp_veccnt > 1) {
1976bd27cf6Sjdolecek 		map_irq.type = MAP_PIRQ_TYPE_MULTI_MSI;
1986bd27cf6Sjdolecek 	}
1996bd27cf6Sjdolecek 
2006bd27cf6Sjdolecek 	ret = HYPERVISOR_physdev_op(PHYSDEVOP_map_pirq, &map_irq);
2016bd27cf6Sjdolecek 
2026bd27cf6Sjdolecek 	if (ret == 0) {
2036bd27cf6Sjdolecek 		KASSERT(map_irq.entry_nr == count);
20430654f1bSbouyer 		aprint_debug(" pirq(s)");
20530654f1bSbouyer 		for (i = 0; i < count; i++) {
20630654f1bSbouyer 			msi_i->mp_xen_pirq[i] = map_irq.pirq + i;
20730654f1bSbouyer 			aprint_debug(" %d", msi_i->mp_xen_pirq[i]);
2086bd27cf6Sjdolecek 		}
20930654f1bSbouyer 		aprint_debug("\n");
21030654f1bSbouyer 	} else {
211*e0ffc845Sbouyer 		aprint_debug(" fail %d\n", ret);
21230654f1bSbouyer 	}
2136bd27cf6Sjdolecek 	return ret;
2146bd27cf6Sjdolecek }
2156bd27cf6Sjdolecek 
2166bd27cf6Sjdolecek int
xen_map_msix_pirq(struct pic * pic,int count)21730654f1bSbouyer xen_map_msix_pirq(struct pic *pic, int count)
2186bd27cf6Sjdolecek {
21930654f1bSbouyer 	struct physdev_map_pirq map_irq;
22030654f1bSbouyer 	const struct msipic_pci_info *msi_i = msipic_get_pci_info(pic);
22130654f1bSbouyer 	int i;
22230654f1bSbouyer 	int ret;
2236bd27cf6Sjdolecek 
22430654f1bSbouyer 	if (count == -1)
22530654f1bSbouyer 		count = msi_i->mp_veccnt;
22630654f1bSbouyer 	KASSERT(count > 0);
2276bd27cf6Sjdolecek 
22830654f1bSbouyer 	KASSERT(pic->pic_type == PIC_MSIX);
22930654f1bSbouyer 
23030654f1bSbouyer 	memset(&map_irq, 0, sizeof(map_irq));
23130654f1bSbouyer 	map_irq.domid = DOMID_SELF;
23230654f1bSbouyer 	map_irq.type = MAP_PIRQ_TYPE_MSI_SEG;
23330654f1bSbouyer 	map_irq.index = -1;
23430654f1bSbouyer 	map_irq.pirq = -1;
23530654f1bSbouyer 	map_irq.bus = msi_i->mp_bus;
23630654f1bSbouyer  	map_irq.devfn = (msi_i->mp_dev << 3) | msi_i->mp_fun;
237f3af8bcbSbouyer  	map_irq.table_base = msi_i->mp_table_base;
238f3af8bcbSbouyer 
2394e696c3dSbouyer 	aprint_debug("xen_map_msix_pirq bus %d devfn 0x%x (%d %d) count %d",
24030654f1bSbouyer 	    map_irq.bus, map_irq.devfn, msi_i->mp_dev, msi_i->mp_fun,
2414e696c3dSbouyer 	    count);
24230654f1bSbouyer 
24330654f1bSbouyer 	for (i = 0; i < count; i++) {
24430654f1bSbouyer 		map_irq.entry_nr = i;
24530654f1bSbouyer 		map_irq.pirq = -1;
24630654f1bSbouyer 		aprint_debug(" map %d", i);
24730654f1bSbouyer 		ret = HYPERVISOR_physdev_op(PHYSDEVOP_map_pirq, &map_irq);
24830654f1bSbouyer 		if (ret) {
249*e0ffc845Sbouyer 			aprint_debug(" fail %d\n", ret);
25030654f1bSbouyer 			goto fail;
25130654f1bSbouyer 		}
25230654f1bSbouyer 		msi_i->mp_xen_pirq[i] = map_irq.pirq;
25330654f1bSbouyer 		aprint_debug("->%d", msi_i->mp_xen_pirq[i]);
25430654f1bSbouyer 	}
25530654f1bSbouyer 	aprint_debug("\n");
25630654f1bSbouyer 	return 0;
25730654f1bSbouyer 
25830654f1bSbouyer fail:
25930654f1bSbouyer 	i--;
26030654f1bSbouyer 	while(i >= 0) {
2616bd27cf6Sjdolecek 		struct physdev_unmap_pirq unmap_irq;
2626bd27cf6Sjdolecek 		unmap_irq.domid = DOMID_SELF;
26330654f1bSbouyer 		unmap_irq.pirq = msi_i->mp_xen_pirq[i];
2646bd27cf6Sjdolecek 
2656bd27cf6Sjdolecek 		(void)HYPERVISOR_physdev_op(PHYSDEVOP_unmap_pirq, &unmap_irq);
26630654f1bSbouyer 		msi_i->mp_xen_pirq[i] = 0;
2676bd27cf6Sjdolecek 	}
2686bd27cf6Sjdolecek 	return ret;
2696bd27cf6Sjdolecek }
27030654f1bSbouyer 
27130654f1bSbouyer void
xen_pci_msi_release(struct pic * pic,int count)27230654f1bSbouyer xen_pci_msi_release(struct pic *pic, int count)
27330654f1bSbouyer {
27430654f1bSbouyer 	const struct msipic_pci_info *msi_i = msipic_get_pci_info(pic);
27530654f1bSbouyer 	KASSERT(count == msi_i->mp_veccnt);
27630654f1bSbouyer 	for (int i = 0; i < count; i++) {
27730654f1bSbouyer 		struct physdev_unmap_pirq unmap_irq;
27830654f1bSbouyer 		unmap_irq.domid = DOMID_SELF;
27930654f1bSbouyer 		unmap_irq.pirq = msi_i->mp_xen_pirq[i];
28030654f1bSbouyer 
28130654f1bSbouyer 		(void)HYPERVISOR_physdev_op(PHYSDEVOP_unmap_pirq, &unmap_irq);
28230654f1bSbouyer 		msi_i->mp_xen_pirq[i] = 0;
28330654f1bSbouyer 	}
28430654f1bSbouyer }
28530654f1bSbouyer 
286e36c697cSjdolecek #endif /* __HAVE_PCI_MSI_MSIX */
2876bd27cf6Sjdolecek 
288e3cb69cbScherry /*
2896cc641e8Scherry  * This function doesn't "allocate" anything. It merely translates our
2906cc641e8Scherry  * understanding of PIC to the XEN 'gsi' namespace. In the case of
2916cc641e8Scherry  * MSIs, pirq == irq. In the case of everything else, the hypervisor
2926cc641e8Scherry  * doesn't really care, so we just use the native conventions that
2936cc641e8Scherry  * have been setup during boot by mpbios.c/mpacpi.c
294e3cb69cbScherry  */
2956cc641e8Scherry int
xen_pic_to_gsi(struct pic * pic,int pin)2966cc641e8Scherry xen_pic_to_gsi(struct pic *pic, int pin)
29703d3e06aSbouyer {
298d5100c23Sjdolecek 	int ret;
2996cc641e8Scherry 	int gsi;
3006cc641e8Scherry 
3016cc641e8Scherry 	KASSERT(pic != NULL);
3026cc641e8Scherry 
3036cc641e8Scherry 	/*
3046cc641e8Scherry 	 * We assume that mpbios/mpacpi have done the right thing.
3056cc641e8Scherry 	 * If so, legacy_irq should identity map correctly to gsi.
3066cc641e8Scherry 	 */
3076cc641e8Scherry 	gsi = pic->pic_vecbase + pin;
308d5100c23Sjdolecek 	KASSERT(gsi < NR_EVENT_CHANNELS);
3096cc641e8Scherry 
3106cc641e8Scherry 	switch (pic->pic_type) {
3116cc641e8Scherry 	case PIC_I8259:
3126cc641e8Scherry 		KASSERT(gsi < 16);
313d5100c23Sjdolecek 		/* FALLTHROUGH */
3146cc641e8Scherry 	case PIC_IOAPIC:
315d5100c23Sjdolecek 	    {
316d5100c23Sjdolecek 		KASSERT(gsi < 255);
317d5100c23Sjdolecek 
3183726b4a3Sjdolecek 		if (irq2port[gsi] != 0) {
3193726b4a3Sjdolecek 			/* Already mapped the shared interrupt */
3203726b4a3Sjdolecek 			break;
3213726b4a3Sjdolecek 		}
3223726b4a3Sjdolecek 
323039d6c36Sjdolecek 		struct physdev_irq irq_op;
324039d6c36Sjdolecek 		memset(&irq_op, 0, sizeof(irq_op));
325039d6c36Sjdolecek 		irq_op.irq = gsi;
326039d6c36Sjdolecek 		ret = HYPERVISOR_physdev_op(PHYSDEVOP_alloc_irq_vector,
327039d6c36Sjdolecek 		    &irq_op);
328039d6c36Sjdolecek 		if (ret < 0) {
329039d6c36Sjdolecek 			panic("physdev_op(PHYSDEVOP_alloc_irq_vector) %d"
330039d6c36Sjdolecek 			    " fail %d", gsi, ret);
331039d6c36Sjdolecek 		}
33230654f1bSbouyer 		aprint_debug("xen_pic_to_gsi %s pin %d gsi %d allocated %d\n",
33330654f1bSbouyer 		    (pic->pic_type == PIC_IOAPIC) ? "ioapic" : "i8259",
33430654f1bSbouyer 		    pin, gsi, irq_op.vector);
33530654f1bSbouyer 
336039d6c36Sjdolecek 		KASSERT(irq_op.vector == gsi);
3376cc641e8Scherry 		break;
338d5100c23Sjdolecek 	    }
339d5100c23Sjdolecek 	case PIC_MSI:
340d5100c23Sjdolecek 	case PIC_MSIX:
341d5100c23Sjdolecek #ifdef __HAVE_PCI_MSI_MSIX
34230654f1bSbouyer 	{
34330654f1bSbouyer 		const struct msipic_pci_info *msi_i = msipic_get_pci_info(pic);
34430654f1bSbouyer 		KASSERT(pin < msi_i->mp_veccnt);
34530654f1bSbouyer 		gsi = msi_i->mp_xen_pirq[pin];
34630654f1bSbouyer 		aprint_debug("xen_pic_to_gsi %s pin %d gsi %d\n",
34730654f1bSbouyer 		    (pic->pic_type == PIC_MSI) ? "MSI" : "MSIX",
34830654f1bSbouyer 		    pin, gsi);
349d5100c23Sjdolecek 		break;
35030654f1bSbouyer 	}
351d5100c23Sjdolecek #endif
352d5100c23Sjdolecek 	default:
353d5100c23Sjdolecek 		panic("unknown pic_type %d", pic->pic_type);
3546cc641e8Scherry 		break;
35503d3e06aSbouyer 	}
3566cc641e8Scherry 
3576cc641e8Scherry 	return gsi;
35803d3e06aSbouyer }
3596cc641e8Scherry 
3606cc641e8Scherry 
361e3cb69cbScherry #endif /* defined(DOM0OPS) || NPCI > 0 */
362