Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/arch Retire xen/x86/intr.c and use the new xen specific ...



details:   https://anonhg.NetBSD.org/src/rev/cfef2d7d3322
branches:  trunk
changeset: 827598:cfef2d7d3322
user:      cherry <cherry%NetBSD.org@localhost>
date:      Sat Nov 04 14:56:48 2017 +0000

description:
Retire xen/x86/intr.c and use the new xen specific glue in x86/x86/intr.c

The purpose of this change is to expose the x86/include/intr.h API
to drivers. Specifically the following functions:

   void *intr_establish_xname(...);
   void *intr_establish(...);
   void intr_disestablish(...);

while maintaining the old API from xen/include/evtchn.h, specifically
the following functions:

    int event_set_handler(...);
    int event_remove_handler(...);

This is so that if things break, we can keep using the old API until
everything stabilises. This is a stepping stone towards getting the
actual XEN event callback path rework code in place - which can be
done opaquely behind the intr.h API - NetBSD/XEN specific drivers that
have been ported to the intr.h API should then work without
significant further modifications.

diffstat:

 sys/arch/x86/include/intr.h         |   17 +-
 sys/arch/x86/isa/isa_machdep.c      |    6 +-
 sys/arch/x86/x86/intr.c             |  196 ++++++++++++++-
 sys/arch/x86/x86/ioapic.c           |   33 ++-
 sys/arch/xen/conf/files.xen         |    3 +-
 sys/arch/xen/include/evtchn.h       |    4 +-
 sys/arch/xen/include/intr.h         |    5 +-
 sys/arch/xen/x86/intr.c             |  466 ------------------------------------
 sys/arch/xen/xen/pci_intr_machdep.c |    6 +-
 sys/arch/xen/xen/pciide_machdep.c   |    6 +-
 10 files changed, 247 insertions(+), 495 deletions(-)

diffs (truncated from 1158 to 300 lines):

diff -r 38586646da47 -r cfef2d7d3322 sys/arch/x86/include/intr.h
--- a/sys/arch/x86/include/intr.h       Sat Nov 04 14:47:06 2017 +0000
+++ b/sys/arch/x86/include/intr.h       Sat Nov 04 14:56:48 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: intr.h,v 1.51 2017/07/16 14:02:48 cherry Exp $ */
+/*     $NetBSD: intr.h,v 1.52 2017/11/04 14:56:48 cherry Exp $ */
 
 /*-
  * Copyright (c) 1998, 2001, 2006, 2007, 2008 The NetBSD Foundation, Inc.
@@ -117,6 +117,18 @@
  */
 
 struct intrhand {
+#if defined(XEN)
+       /*
+        * Note: This is transitional and will go away.
+        *
+        * We ought to use a union here, but too much effort.
+        * We use this field to tear down the cookie handed to us
+        * via x86/intr.c:intr_disestablish();
+        * Interestingly, the intr_establish_xname() function returns
+        * a "void *" - so we abuse this for now.
+        */
+       int     pic_type; /* Overloading wrt struct pintrhand */
+#endif
        int     (*ih_fun)(void *);
        void    *ih_arg;
        int     ih_level;
@@ -124,10 +136,9 @@
        void    *ih_realarg;
        struct  intrhand *ih_next;
        struct  intrhand **ih_prevp;
-#if !defined(XEN)
        int     ih_pin;
        int     ih_slot;
-#else
+#if defined(XEN)
        struct  intrhand *ih_evt_next;
 #endif
        struct cpu_info *ih_cpu;
diff -r 38586646da47 -r cfef2d7d3322 sys/arch/x86/isa/isa_machdep.c
--- a/sys/arch/x86/isa/isa_machdep.c    Sat Nov 04 14:47:06 2017 +0000
+++ b/sys/arch/x86/isa/isa_machdep.c    Sat Nov 04 14:56:48 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: isa_machdep.c,v 1.36 2017/07/21 12:27:48 cherry Exp $  */
+/*     $NetBSD: isa_machdep.c,v 1.37 2017/11/04 14:56:48 cherry Exp $  */
 
 /*-
  * Copyright (c) 1996, 1997, 1998 The NetBSD Foundation, Inc.
@@ -65,7 +65,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.36 2017/07/21 12:27:48 cherry Exp $");
+__KERNEL_RCSID(0, "$NetBSD: isa_machdep.c,v 1.37 2017/11/04 14:56:48 cherry Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -245,7 +245,7 @@
 
        mpih |= APIC_IRQ_LEGACY_IRQ(irq);
 
-       evtch = xen_intr_map((int *)&mpih, type); /* XXX: legacy - xen just tosses irq back at us */
+       evtch = xen_pirq_alloc((intr_handle_t *)&mpih, type); /* XXX: legacy - xen just tosses irq back at us */
        if (evtch == -1)
                return NULL;
 #if NIOAPIC > 0
diff -r 38586646da47 -r cfef2d7d3322 sys/arch/x86/x86/intr.c
--- a/sys/arch/x86/x86/intr.c   Sat Nov 04 14:47:06 2017 +0000
+++ b/sys/arch/x86/x86/intr.c   Sat Nov 04 14:56:48 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: intr.c,v 1.105 2017/10/27 12:25:14 joerg Exp $ */
+/*     $NetBSD: intr.c,v 1.106 2017/11/04 14:56:48 cherry Exp $        */
 
 /*-
  * Copyright (c) 2007, 2008, 2009 The NetBSD Foundation, Inc.
@@ -133,7 +133,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.105 2017/10/27 12:25:14 joerg Exp $");
+__KERNEL_RCSID(0, "$NetBSD: intr.c,v 1.106 2017/11/04 14:56:48 cherry Exp $");
 
 #include "opt_intrdebug.h"
 #include "opt_multiprocessor.h"
@@ -188,6 +188,13 @@
 #define msipic_is_msi_pic(PIC) (false)
 #endif
 
+#if defined(XEN) /* XXX: Cleanup */
+#include <xen/xen.h>
+#include <xen/hypervisor.h>
+#include <xen/evtchn.h>
+#include <xen/xenfunc.h>
+#endif /* XEN */
+
 #ifdef DDB
 #include <ddb/db_output.h>
 #endif
@@ -220,6 +227,7 @@
 #endif
 #endif
 
+#if !defined(XEN)
 static int intr_allocate_slot_cpu(struct cpu_info *, struct pic *, int, int *,
                                  struct intrsource *);
 static int __noinline intr_allocate_slot(struct pic *, int, int,
@@ -232,6 +240,10 @@
 static void intr_disestablish_xcall(void *, void *);
 
 static const char *legacy_intr_string(int, char *, size_t, struct pic *);
+#if defined(XEN) /* XXX: nuke conditional after integration */
+static const char *xen_intr_string(int, char *, size_t, struct pic *);
+#endif /* XXX: XEN */
+#endif
 
 static inline bool redzone_const_or_false(bool);
 static inline int redzone_const_or_zero(int);
@@ -241,10 +253,12 @@
 static void intr_redistribute_xc_s2(void *, void *);
 static bool intr_redistribute(struct cpu_info *);
 
+#if !defined(XEN)
 static const char *create_intrid(int, struct pic *, int, char *, size_t);
-
+#endif /* XEN */
 static struct intrsource *intr_get_io_intrsource(const char *);
 static void intr_free_io_intrsource_direct(struct intrsource *);
+#if !defined(XEN)
 static int intr_num_handlers(struct intrsource *);
 
 static int intr_find_unused_slot(struct cpu_info *, int *);
@@ -252,6 +266,7 @@
 static void intr_deactivate_xcall(void *, void *);
 static void intr_get_affinity(struct intrsource *, kcpuset_t *);
 static int intr_set_affinity(struct intrsource *, const kcpuset_t *);
+#endif /* XEN */
 
 /*
  * Fill in default interrupt table (in case of spurious interrupt
@@ -260,6 +275,7 @@
 void
 intr_default_setup(void)
 {
+#if !defined(XEN)
        int i;
 
        /* icu vectors */
@@ -273,6 +289,9 @@
         */
        i8259_default_setup();
 
+#else
+       events_default_setup();
+#endif /* !XEN */
        mutex_init(&intr_distribute_lock, MUTEX_DEFAULT, IPL_NONE);
 }
 
@@ -471,6 +490,7 @@
 }
 #endif
 
+#if !defined(XEN)
 /*
  * Create an interrupt id such as "ioapic0 pin 9". This interrupt id is used
  * by MI code and intrctl(8).
@@ -478,7 +498,7 @@
 static const char *
 create_intrid(int legacy_irq, struct pic *pic, int pin, char *buf, size_t len)
 {
-       int ih;
+       int ih = 0;
 
 #if NPCI > 0
        if ((pic->pic_type == PIC_MSI) || (pic->pic_type == PIC_MSIX)) {
@@ -499,6 +519,15 @@
        }
 #endif
 
+#if defined(XEN)
+       evtchn_port_t port = pin; /* Port number */
+
+       if (pic->pic_type == PIC_XEN) {
+               ih = pin;
+               return xen_intr_string(port, buf, len, pic);
+       }
+#endif
+
        /*
         * If the device is pci, "legacy_irq" is alway -1. Least 8 bit of "ih"
         * is only used in intr_string() to show the irq number.
@@ -510,6 +539,7 @@
                return legacy_intr_string(ih, buf, len, pic);
        }
 
+#if NIOAPIC > 0 || NACPICA > 0
        ih = ((pic->pic_apicid << APIC_INT_APIC_SHIFT) & APIC_INT_APIC_MASK)
            | ((pin << APIC_INT_PIN_SHIFT) & APIC_INT_PIN_MASK);
        if (pic->pic_type == PIC_IOAPIC) {
@@ -517,8 +547,13 @@
        }
        ih |= pin;
        return intr_string(ih, buf, len);
+#endif
+
+       return NULL; /* No pic found! */
 }
 
+#endif /* XEN */
+
 /*
  * Find intrsource from io_interrupt_sources list.
  */
@@ -613,6 +648,7 @@
        intr_free_io_intrsource_direct(isp);
 }
 
+#if !defined(XEN)
 static int
 intr_allocate_slot_cpu(struct cpu_info *ci, struct pic *pic, int pin,
                       int *index, struct intrsource *chained)
@@ -815,7 +851,9 @@
        return ret;
 }
 #endif /* MULTIPROCESSOR */
+#endif /* XEN */
 
+#if defined(DOM0OPS) || !defined(XEN)
 struct pic *
 intr_findpic(int num)
 {
@@ -831,7 +869,8 @@
 
        return NULL;
 }
-
+#endif
+#if !defined(XEN)
 /*
  * Append device name to intrsource. If device A and device B share IRQ number,
  * the device name of the interrupt id is "device A, device B".
@@ -1168,12 +1207,96 @@
        return num;
 }
 
+#else /* XEN */
+void *
+intr_establish_xname(int legacy_irq, struct pic *pic, int pin,
+    int type, int level, int (*handler)(void *) , void *arg,
+    bool known_mpsafe, const char *xname)
+{
+       /* XXX xname registration not supported */
+       return intr_establish(legacy_irq, pic, pin, type, level, handler, arg,
+           known_mpsafe);
+}
+
+void *
+intr_establish(int legacy_irq, struct pic *pic, int pin,
+    int type, int level, int (*handler)(void *) , void *arg,
+    bool known_mpsafe)
+{
+       if (pic->pic_type == PIC_XEN) {
+               struct intrhand *rih;
+               event_set_handler(pin, handler,
+                   arg, IPL_CLOCK, "clock");
+
+               rih = kmem_zalloc(sizeof(struct intrhand),
+           cold ? KM_NOSLEEP : KM_SLEEP);
+               if (rih == NULL) {
+                       printf("%s: can't allocate handler info\n", __func__);
+                       return NULL;
+               }
+
+               /*
+                * XXX:
+                * This is just a copy for API conformance.
+                * The real ih is lost in the innards of
+                * event_set_handler(); where the details of
+                * biglock_wrapper etc are taken care of.
+                * All that goes away when we nuke event_set_handler()
+                * et. al. and unify with x86/intr.c
+                */
+               
+               rih->ih_pin = pin; /* port */
+               rih->ih_fun = handler;
+               rih->ih_arg = arg;
+               rih->pic_type = pic->pic_type;
+               return rih;
+       }       /* Else we assume pintr */
+
+#if NPCI > 0 || NISA > 0
+       struct pintrhand *pih;
+       int evtchn;
+       char evname[16];
+
+#ifdef DIAGNOSTIC
+       if (legacy_irq != -1 && (legacy_irq < 0 || legacy_irq > 15))
+               panic("intr_establish: bad legacy IRQ value");
+       if (legacy_irq == -1 && pic == &i8259_pic)
+               panic("intr_establish: non-legacy IRQ on i8259");



Home | Main Index | Thread Index | Old Index