Setup Hyper-V hypercall page and an IDT vector.
authormikeb <mikeb@openbsd.org>
Wed, 22 Jun 2016 01:12:38 +0000 (01:12 +0000)
committermikeb <mikeb@openbsd.org>
Wed, 22 Jun 2016 01:12:38 +0000 (01:12 +0000)
ok mlarkin, kettenis, deraadt

sys/arch/amd64/amd64/intr.c
sys/arch/amd64/amd64/lapic.c
sys/arch/amd64/amd64/locore.S
sys/arch/amd64/amd64/vector.S
sys/arch/amd64/include/i82489var.h
sys/arch/amd64/include/intrdefs.h

index 8ee1182..1569884 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: intr.c,v 1.47 2015/12/08 19:45:55 mikeb Exp $ */
+/*     $OpenBSD: intr.c,v 1.48 2016/06/22 01:12:38 mikeb Exp $ */
 /*     $NetBSD: intr.c,v 1.3 2003/03/03 22:16:20 fvdl Exp $    */
 
 /*
@@ -55,6 +55,7 @@
 #include "ioapic.h"
 #include "lapic.h"
 #include "xen.h"
+#include "hyperv.h"
 
 #if NIOAPIC > 0
 #include <machine/mpbiosvar.h>
@@ -553,6 +554,9 @@ struct intrhand fake_ipi_intrhand;
 #if NXEN > 0
 struct intrhand fake_xen_intrhand;
 #endif
+#if NHYPERV > 0
+struct intrhand fake_hyperv_intrhand;
+#endif
 
 #if NLAPIC > 0 && defined(MULTIPROCESSOR) && 0
 static char *x86_ipi_names[X86_NIPI] = X86_IPI_NAMES;
@@ -629,6 +633,17 @@ cpu_intr_init(struct cpu_info *ci)
        isp->is_pic = &local_pic;
        ci->ci_isources[LIR_XEN] = isp;
 #endif
+#if NHYPERV > 0
+       isp = malloc(sizeof (struct intrsource), M_DEVBUF, M_NOWAIT|M_ZERO);
+       if (isp == NULL)
+               panic("can't allocate fixed interrupt source");
+       isp->is_recurse = Xrecurse_hyperv_upcall;
+       isp->is_resume = Xresume_hyperv_upcall;
+       fake_hyperv_intrhand.ih_level = IPL_NET;
+       isp->is_handlers = &fake_hyperv_intrhand;
+       isp->is_pic = &local_pic;
+       ci->ci_isources[LIR_HYPERV] = isp;
+#endif
 #endif /* NLAPIC */
 
        intr_calculatemasks(ci);
index 18b51a4..ad5ebb6 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: lapic.c,v 1.43 2016/03/06 22:41:24 naddy Exp $        */
+/*     $OpenBSD: lapic.c,v 1.44 2016/06/22 01:12:38 mikeb Exp $        */
 /* $NetBSD: lapic.c,v 1.2 2003/05/08 01:04:35 fvdl Exp $ */
 
 /*-
@@ -56,6 +56,7 @@
 
 #include "ioapic.h"
 #include "xen.h"
+#include "hyperv.h"
 
 #if NIOAPIC > 0
 #include <machine/i82093var.h>
@@ -359,6 +360,11 @@ lapic_boot_init(paddr_t lapic_base)
        idt_allocmap[LAPIC_XEN_VECTOR] = 1;
        idt_vec_set(LAPIC_XEN_VECTOR, Xintr_xen_upcall);
 #endif
+#if NHYPERV > 0
+       /* Hyper-V Interrupt Vector */
+       idt_allocmap[LAPIC_HYPERV_VECTOR] = 1;
+       idt_vec_set(LAPIC_HYPERV_VECTOR, Xintr_hyperv_upcall);
+#endif
 
        evcount_attach(&clk_count, "clock", &clk_irq);
 #ifdef MULTIPROCESSOR
index a147f3d..52ae39c 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: locore.S,v 1.80 2016/06/06 06:02:02 deraadt Exp $     */
+/*     $OpenBSD: locore.S,v 1.81 2016/06/22 01:12:38 mikeb Exp $       */
 /*     $NetBSD: locore.S,v 1.13 2004/03/25 18:33:17 drochner Exp $     */
 
 /*
 #include "ksyms.h"
 #include "acpi.h"
 #include "xen.h"
+#include "hyperv.h"
 
 #include <sys/errno.h>
 #include <sys/syscall.h>
@@ -1195,3 +1196,12 @@ _C_LABEL(codepatch_end):
 _C_LABEL(xen_hypercall_page):
        .skip   0x1000, 0xcc
 #endif /* NXEN > 0 */
+
+#if NHYPERV > 0
+       /* Hypercall page needs to be page aligned */
+       .text
+       .align  NBPG, 0xcc
+       .globl  _C_LABEL(hv_hypercall_page)
+_C_LABEL(hv_hypercall_page):
+       .skip   0x1000, 0xcc
+#endif /* NXEN > 0 */
index 81759f9..137ede9 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: vector.S,v 1.45 2016/03/03 12:32:23 mpi Exp $ */
+/*     $OpenBSD: vector.S,v 1.46 2016/06/22 01:12:38 mikeb Exp $       */
 /*     $NetBSD: vector.S,v 1.5 2004/06/28 09:13:11 fvdl Exp $  */
 
 /*
@@ -84,6 +84,7 @@
 #include "lapic.h"
 #include "assym.h"
 #include "xen.h"
+#include "hyperv.h"
 
 /*****************************************************************************/
 
@@ -468,6 +469,40 @@ IDTVEC(resume_xen_upcall)
 3:
        INTRFASTEXIT
 #endif /* NXEN > 0 */
+
+#if NHYPERV > 0
+/*
+ * Hyperv event channel upcall interrupt handler.
+ * Only used when the hypervisor supports direct vector callbacks.
+ */
+IDTVEC(recurse_hyperv_upcall)
+       INTR_RECURSE_HWFRAME
+       pushq   $0
+       subq    $8,%rsp                 /* unused __if_trapno */
+       INTRENTRY
+       jmp     1f
+IDTVEC(intr_hyperv_upcall)
+       pushq   $0
+       subq    $8,%rsp                 /* unused __if_trapno */
+       INTRENTRY
+       movl    CPUVAR(ILEVEL),%ebx
+       cmpl    $IPL_NET,%ebx
+       jae     2f
+IDTVEC(resume_hyperv_upcall)
+1:
+       incl    CPUVAR(IDEPTH)
+       movl    $IPL_NET,CPUVAR(ILEVEL)
+       sti
+       cld
+       pushq   %rbx
+       call    _C_LABEL(hv_intr)
+       jmp     _C_LABEL(Xdoreti)
+2:
+       movq    $(1 << LIR_HYPERV),%rax
+       orq     %rax,CPUVAR(IPENDING)
+3:
+       INTRFASTEXIT
+#endif /* NHYPERV > 0 */
 #endif /* NLAPIC > 0 */
 
 #define voidop(num)
index e67c97b..746e343 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: i82489var.h,v 1.16 2015/12/08 19:45:55 mikeb Exp $    */
+/*     $OpenBSD: i82489var.h,v 1.17 2016/06/22 01:12:38 mikeb Exp $    */
 /*     $NetBSD: i82489var.h,v 1.1 2003/02/26 21:26:10 fvdl Exp $       */
 
 /*-
@@ -107,6 +107,14 @@ extern void Xresume_xen_upcall(void);
 extern void Xrecurse_xen_upcall(void);
 #define LAPIC_XEN_VECTOR               0x70
 
+/*
+ * Vector used for Hyper-V Interrupts.
+ */
+extern void Xintr_hyperv_upcall(void);
+extern void Xresume_hyperv_upcall(void);
+extern void Xrecurse_hyperv_upcall(void);
+#define LAPIC_HYPERV_VECTOR            0x71
+
 struct cpu_info;
 
 extern void lapic_boot_init(paddr_t);
index 27d41d5..2cfe0ba 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: intrdefs.h,v 1.15 2015/12/08 19:45:55 mikeb Exp $     */
+/*     $OpenBSD: intrdefs.h,v 1.16 2016/06/22 01:12:38 mikeb Exp $     */
 /*     $NetBSD: intrdefs.h,v 1.2 2003/05/04 22:01:56 fvdl Exp $        */
 
 #ifndef _AMD64_INTRDEFS_H
@@ -55,6 +55,7 @@
 #define        SIR_TTY         59
 
 #define        LIR_XEN         58
+#define        LIR_HYPERV      57
 
 /*
  * Maximum # of interrupt sources per CPU. 64 to fit in one word.