Author: sephe
Date: Thu Apr  7 07:12:57 2016
New Revision: 297641
URL: https://svnweb.freebsd.org/changeset/base/297641

Log:
  hyperv: Use lapic_{alloc,free}_ipi to allocate private interrupt vector
  
  Suggested by: jhb
  Reviewed by:  Dexuan Cui <decui microsoft com>, Jun Su <junsu microsoft com>
  Sponsored by: Microsoft OSTC
  Differential Revision:        https://reviews.freebsd.org/D5850

Modified:
  head/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c
  head/sys/dev/hyperv/vmbus/hv_vmbus_priv.h

Modified: head/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c
==============================================================================
--- head/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c    Thu Apr  7 07:12:14 
2016        (r297640)
+++ head/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c    Thu Apr  7 07:12:57 
2016        (r297641)
@@ -391,80 +391,9 @@ vmbus_probe(device_t dev) {
 }
 
 #ifdef HYPERV
-extern inthand_t IDTVEC(rsvd), IDTVEC(hv_vmbus_callback);
-
-/**
- * @brief Find a free IDT slot and setup the interrupt handler.
- */
-static int
-vmbus_vector_alloc(void)
-{
-       int vector;
-       uintptr_t func;
-       struct gate_descriptor *ip;
-
-       /*
-        * Search backwards form the highest IDT vector available for use
-        * as vmbus channel callback vector. We install 'hv_vmbus_callback'
-        * handler at that vector and use it to interrupt vcpus.
-        */
-       vector = APIC_SPURIOUS_INT;
-       while (--vector >= APIC_IPI_INTS) {
-               ip = &idt[vector];
-               func = ((long)ip->gd_hioffset << 16 | ip->gd_looffset);
-               if (func == (uintptr_t)&IDTVEC(rsvd)) {
-#ifdef __i386__
-                       setidt(vector , IDTVEC(hv_vmbus_callback), 
SDT_SYS386IGT,
-                           SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));
-#else
-                       setidt(vector , IDTVEC(hv_vmbus_callback), SDT_SYSIGT,
-                           SEL_KPL, 0);
+extern inthand_t IDTVEC(hv_vmbus_callback);
 #endif
 
-                       return (vector);
-               }
-       }
-       return (0);
-}
-
-/**
- * @brief Restore the IDT slot to rsvd.
- */
-static void
-vmbus_vector_free(int vector)
-{
-        uintptr_t func;
-        struct gate_descriptor *ip;
-
-       if (vector == 0)
-               return;
-
-        KASSERT(vector >= APIC_IPI_INTS && vector < APIC_SPURIOUS_INT,
-            ("invalid vector %d", vector));
-
-        ip = &idt[vector];
-        func = ((long)ip->gd_hioffset << 16 | ip->gd_looffset);
-        KASSERT(func == (uintptr_t)&IDTVEC(hv_vmbus_callback),
-            ("invalid vector %d", vector));
-
-        setidt(vector, IDTVEC(rsvd), SDT_SYSIGT, SEL_KPL, 0);
-}
-
-#else /* HYPERV */
-
-static int
-vmbus_vector_alloc(void)
-{
-       return(0);
-}
-
-static void
-vmbus_vector_free(int vector)
-{
-}
-
-#endif /* HYPERV */
-
 /**
  * @brief Main vmbus driver initialization routine.
  *
@@ -497,12 +426,15 @@ vmbus_bus_init(void)
                return (ret);
        }
 
+#ifdef HYPERV
        /*
         * Find a free IDT slot for vmbus callback.
         */
-       hv_vmbus_g_context.hv_cb_vector = vmbus_vector_alloc();
-
-       if (hv_vmbus_g_context.hv_cb_vector == 0) {
+       hv_vmbus_g_context.hv_cb_vector = 
lapic_ipi_alloc(IDTVEC(hv_vmbus_callback));
+#else
+       hv_vmbus_g_context.hv_cb_vector = -1;
+#endif
+       if (hv_vmbus_g_context.hv_cb_vector < 0) {
                if(bootverbose)
                        printf("Error VMBUS: Cannot find free IDT slot for "
                            "vmbus callback!\n");
@@ -595,7 +527,7 @@ vmbus_bus_init(void)
                }
        }
 
-       vmbus_vector_free(hv_vmbus_g_context.hv_cb_vector);
+       lapic_ipi_free(hv_vmbus_g_context.hv_cb_vector);
 
        cleanup:
        hv_vmbus_cleanup();
@@ -663,7 +595,7 @@ vmbus_bus_exit(void)
                }
        }
 
-       vmbus_vector_free(hv_vmbus_g_context.hv_cb_vector);
+       lapic_ipi_free(hv_vmbus_g_context.hv_cb_vector);
 
        return;
 }

Modified: head/sys/dev/hyperv/vmbus/hv_vmbus_priv.h
==============================================================================
--- head/sys/dev/hyperv/vmbus/hv_vmbus_priv.h   Thu Apr  7 07:12:14 2016        
(r297640)
+++ head/sys/dev/hyperv/vmbus/hv_vmbus_priv.h   Thu Apr  7 07:12:57 2016        
(r297641)
@@ -208,10 +208,10 @@ typedef struct {
        struct taskqueue                *hv_msg_tq[MAXCPU];
        struct task                     hv_msg_task[MAXCPU];
        /*
-        * Host use this vector to intrrupt guest for vmbus channel
+        * Host use this vector to interrupt guest for vmbus channel
         * event and msg.
         */
-       unsigned int                    hv_cb_vector;
+       int                             hv_cb_vector;
 } hv_vmbus_context;
 
 /*
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to