Home | History | Annotate | Line # | Download | only in x86
pintr.c revision 1.1
      1  1.1  cherry /*	NetBSD: intr.c,v 1.15 2004/04/10 14:49:55 kochi Exp 	*/
      2  1.1  cherry 
      3  1.1  cherry /*
      4  1.1  cherry  * Copyright 2002 (c) Wasabi Systems, Inc.
      5  1.1  cherry  * All rights reserved.
      6  1.1  cherry  *
      7  1.1  cherry  * Written by Frank van der Linden for Wasabi Systems, Inc.
      8  1.1  cherry  *
      9  1.1  cherry  * Redistribution and use in source and binary forms, with or without
     10  1.1  cherry  * modification, are permitted provided that the following conditions
     11  1.1  cherry  * are met:
     12  1.1  cherry  * 1. Redistributions of source code must retain the above copyright
     13  1.1  cherry  *    notice, this list of conditions and the following disclaimer.
     14  1.1  cherry  * 2. Redistributions in binary form must reproduce the above copyright
     15  1.1  cherry  *    notice, this list of conditions and the following disclaimer in the
     16  1.1  cherry  *    documentation and/or other materials provided with the distribution.
     17  1.1  cherry  * 3. All advertising materials mentioning features or use of this software
     18  1.1  cherry  *    must display the following acknowledgement:
     19  1.1  cherry  *      This product includes software developed for the NetBSD Project by
     20  1.1  cherry  *      Wasabi Systems, Inc.
     21  1.1  cherry  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
     22  1.1  cherry  *    or promote products derived from this software without specific prior
     23  1.1  cherry  *    written permission.
     24  1.1  cherry  *
     25  1.1  cherry  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
     26  1.1  cherry  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     27  1.1  cherry  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     28  1.1  cherry  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
     29  1.1  cherry  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     30  1.1  cherry  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     31  1.1  cherry  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     32  1.1  cherry  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     33  1.1  cherry  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     34  1.1  cherry  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     35  1.1  cherry  * POSSIBILITY OF SUCH DAMAGE.
     36  1.1  cherry  */
     37  1.1  cherry 
     38  1.1  cherry /*-
     39  1.1  cherry  * Copyright (c) 1991 The Regents of the University of California.
     40  1.1  cherry  * All rights reserved.
     41  1.1  cherry  *
     42  1.1  cherry  * This code is derived from software contributed to Berkeley by
     43  1.1  cherry  * William Jolitz.
     44  1.1  cherry  *
     45  1.1  cherry  * Redistribution and use in source and binary forms, with or without
     46  1.1  cherry  * modification, are permitted provided that the following conditions
     47  1.1  cherry  * are met:
     48  1.1  cherry  * 1. Redistributions of source code must retain the above copyright
     49  1.1  cherry  *    notice, this list of conditions and the following disclaimer.
     50  1.1  cherry  * 2. Redistributions in binary form must reproduce the above copyright
     51  1.1  cherry  *    notice, this list of conditions and the following disclaimer in the
     52  1.1  cherry  *    documentation and/or other materials provided with the distribution.
     53  1.1  cherry  * 3. Neither the name of the University nor the names of its contributors
     54  1.1  cherry  *    may be used to endorse or promote products derived from this software
     55  1.1  cherry  *    without specific prior written permission.
     56  1.1  cherry  *
     57  1.1  cherry  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     58  1.1  cherry  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     59  1.1  cherry  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     60  1.1  cherry  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     61  1.1  cherry  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     62  1.1  cherry  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     63  1.1  cherry  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     64  1.1  cherry  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     65  1.1  cherry  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     66  1.1  cherry  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     67  1.1  cherry  * SUCH DAMAGE.
     68  1.1  cherry  *
     69  1.1  cherry  *     @(#)isa.c       7.2 (Berkeley) 5/13/91
     70  1.1  cherry  */
     71  1.1  cherry /*-
     72  1.1  cherry  * Copyright (c) 1993, 1994 Charles Hannum.
     73  1.1  cherry  *
     74  1.1  cherry  * Redistribution and use in source and binary forms, with or without
     75  1.1  cherry  * modification, are permitted provided that the following conditions
     76  1.1  cherry  * are met:
     77  1.1  cherry  * 1. Redistributions of source code must retain the above copyright
     78  1.1  cherry  *    notice, this list of conditions and the following disclaimer.
     79  1.1  cherry  * 2. Redistributions in binary form must reproduce the above copyright
     80  1.1  cherry  *    notice, this list of conditions and the following disclaimer in the
     81  1.1  cherry  *    documentation and/or other materials provided with the distribution.
     82  1.1  cherry  * 3. All advertising materials mentioning features or use of this software
     83  1.1  cherry  *    must display the following acknowledgement:
     84  1.1  cherry  *     This product includes software developed by the University of
     85  1.1  cherry  *     California, Berkeley and its contributors.
     86  1.1  cherry  * 4. Neither the name of the University nor the names of its contributors
     87  1.1  cherry  *    may be used to endorse or promote products derived from this software
     88  1.1  cherry  *    without specific prior written permission.
     89  1.1  cherry  *
     90  1.1  cherry  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     91  1.1  cherry  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     92  1.1  cherry  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     93  1.1  cherry  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     94  1.1  cherry  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     95  1.1  cherry  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     96  1.1  cherry  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     97  1.1  cherry  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     98  1.1  cherry  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     99  1.1  cherry  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    100  1.1  cherry  * SUCH DAMAGE.
    101  1.1  cherry  *
    102  1.1  cherry  *     @(#)isa.c       7.2 (Berkeley) 5/13/91
    103  1.1  cherry  */
    104  1.1  cherry 
    105  1.1  cherry #include <sys/cdefs.h>
    106  1.1  cherry __KERNEL_RCSID(0, "$NetBSD: pintr.c,v 1.1 2017/11/04 09:22:16 cherry Exp $");
    107  1.1  cherry 
    108  1.1  cherry #include "opt_multiprocessor.h"
    109  1.1  cherry #include "opt_xen.h"
    110  1.1  cherry #include "isa.h"
    111  1.1  cherry #include "pci.h"
    112  1.1  cherry 
    113  1.1  cherry #include <sys/param.h>
    114  1.1  cherry #include <sys/systm.h>
    115  1.1  cherry #include <sys/kernel.h>
    116  1.1  cherry #include <sys/syslog.h>
    117  1.1  cherry #include <sys/device.h>
    118  1.1  cherry #include <sys/malloc.h>
    119  1.1  cherry #include <sys/proc.h>
    120  1.1  cherry #include <sys/errno.h>
    121  1.1  cherry #include <sys/cpu.h>
    122  1.1  cherry 
    123  1.1  cherry #include <uvm/uvm_extern.h>
    124  1.1  cherry 
    125  1.1  cherry #include <machine/i8259.h>
    126  1.1  cherry #include <machine/pio.h>
    127  1.1  cherry #include <xen/evtchn.h>
    128  1.1  cherry #include <xen/intr.h>
    129  1.1  cherry 
    130  1.1  cherry #include "acpica.h"
    131  1.1  cherry #include "ioapic.h"
    132  1.1  cherry #include "opt_mpbios.h"
    133  1.1  cherry 
    134  1.1  cherry #if NIOAPIC > 0
    135  1.1  cherry /* XXX: todo - compat with lapic.c and XEN for x2apic */
    136  1.1  cherry bool x2apic_mode __read_mostly = false;
    137  1.1  cherry /* for x86/i8259.c */
    138  1.1  cherry struct intrstub i8259_stubs[NUM_LEGACY_IRQS] = {{0,0}};
    139  1.1  cherry /* for x86/ioapic.c */
    140  1.1  cherry struct intrstub ioapic_edge_stubs[MAX_INTR_SOURCES] = {{0,0}};
    141  1.1  cherry struct intrstub ioapic_level_stubs[MAX_INTR_SOURCES] = {{0,0}};
    142  1.1  cherry struct intrstub x2apic_edge_stubs[MAX_INTR_SOURCES] = {{0,0}};
    143  1.1  cherry struct intrstub x2apic_level_stubs[MAX_INTR_SOURCES] = {{0,0}};
    144  1.1  cherry #include <machine/i82093var.h>
    145  1.1  cherry int irq2port[NR_EVENT_CHANNELS] = {0};
    146  1.1  cherry int irq2vect[256] = {0};
    147  1.1  cherry int vect2irq[256] = {0};
    148  1.1  cherry #endif /* NIOAPIC */
    149  1.1  cherry #if NACPICA > 0
    150  1.1  cherry #include <machine/mpconfig.h>
    151  1.1  cherry #include <machine/mpacpi.h>
    152  1.1  cherry #endif
    153  1.1  cherry #ifdef MPBIOS
    154  1.1  cherry #include <machine/mpbiosvar.h>
    155  1.1  cherry #endif
    156  1.1  cherry 
    157  1.1  cherry #if NPCI > 0
    158  1.1  cherry #include <dev/pci/ppbreg.h>
    159  1.1  cherry #endif
    160  1.1  cherry 
    161  1.1  cherry #if defined(DOM0OPS) || NPCI > 0
    162  1.1  cherry int
    163  1.1  cherry xen_pirq_alloc(intr_handle_t *pirq, int type)
    164  1.1  cherry {
    165  1.1  cherry 	int irq = *pirq;
    166  1.1  cherry #if NIOAPIC > 0
    167  1.1  cherry 	extern struct cpu_info phycpu_info_primary; /* XXX */
    168  1.1  cherry 	/*
    169  1.1  cherry 	 * The hypervisor has already allocated vectors and IRQs for the
    170  1.1  cherry 	 * devices. Reusing the same IRQ doesn't work because as we bind
    171  1.1  cherry 	 * them for each devices, we can't then change the route entry
    172  1.1  cherry 	 * of the next device if this one used this IRQ. The easiest is
    173  1.1  cherry 	 * to allocate IRQs top-down, starting with a high number.
    174  1.1  cherry 	 * 250 and 230 have been tried, but got rejected by Xen.
    175  1.1  cherry 	 *
    176  1.1  cherry 	 * Xen 3.5 also rejects 200. Try out all values until Xen accepts
    177  1.1  cherry 	 * or none is available.
    178  1.1  cherry 	 */
    179  1.1  cherry 	static int xen_next_irq = 200;
    180  1.1  cherry 	struct ioapic_softc *ioapic = ioapic_find(APIC_IRQ_APIC(*pirq));
    181  1.1  cherry 	struct pic *pic = &ioapic->sc_pic;
    182  1.1  cherry 	int pin = APIC_IRQ_PIN(*pirq);
    183  1.1  cherry 	physdev_op_t op;
    184  1.1  cherry 
    185  1.1  cherry 	if (*pirq & APIC_INT_VIA_APIC) {
    186  1.1  cherry 		irq = vect2irq[ioapic->sc_pins[pin].ip_vector];
    187  1.1  cherry 		if (ioapic->sc_pins[pin].ip_vector == 0 || irq == 0) {
    188  1.1  cherry 			/* allocate IRQ */
    189  1.1  cherry 			irq = APIC_IRQ_LEGACY_IRQ(*pirq);
    190  1.1  cherry 			if (irq <= 0 || irq > 15)
    191  1.1  cherry 				irq = xen_next_irq--;
    192  1.1  cherry retry:
    193  1.1  cherry 			/* allocate vector and route interrupt */
    194  1.1  cherry 			op.cmd = PHYSDEVOP_ASSIGN_VECTOR;
    195  1.1  cherry 			op.u.irq_op.irq = irq;
    196  1.1  cherry 			if (HYPERVISOR_physdev_op(&op) < 0) {
    197  1.1  cherry 				irq = xen_next_irq--;
    198  1.1  cherry 				if (xen_next_irq == 15)
    199  1.1  cherry 					panic("PHYSDEVOP_ASSIGN_VECTOR irq %d", irq);
    200  1.1  cherry 				goto retry;
    201  1.1  cherry 			}
    202  1.1  cherry 			irq2vect[irq] = op.u.irq_op.vector;
    203  1.1  cherry 			vect2irq[op.u.irq_op.vector] = irq;
    204  1.1  cherry 			pic->pic_addroute(pic, &phycpu_info_primary, pin,
    205  1.1  cherry 			    op.u.irq_op.vector, type);
    206  1.1  cherry 		}
    207  1.1  cherry 		*pirq &= ~0xff;
    208  1.1  cherry 		*pirq |= irq;
    209  1.1  cherry 	}
    210  1.1  cherry #endif /* NIOAPIC */
    211  1.1  cherry 	return irq2port[irq];
    212  1.1  cherry }
    213  1.1  cherry #endif /* defined(DOM0OPS) || NPCI > 0 */
    214