Source-Changes-HG archive

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

[src/trunk]: src/sys Added drivers for Hyper-V Synthetic Keyboard and Video d...



details:   https://anonhg.NetBSD.org/src/rev/168e154afd93
branches:  trunk
changeset: 451467:168e154afd93
user:      nonaka <nonaka%NetBSD.org@localhost>
date:      Fri May 24 14:28:48 2019 +0000

description:
Added drivers for Hyper-V Synthetic Keyboard and Video device.

diffstat:

 sys/arch/amd64/conf/GENERIC     |    7 +-
 sys/arch/i386/conf/GENERIC      |    7 +-
 sys/arch/x86/include/autoconf.h |    4 +-
 sys/arch/x86/pci/pci_machdep.c  |    9 +-
 sys/arch/x86/x86/consinit.c     |   16 +-
 sys/arch/x86/x86/hyperv.c       |  233 +++++++++++++-
 sys/arch/x86/x86/hypervvar.h    |   37 ++
 sys/arch/x86/x86/identcpu.c     |   18 +-
 sys/arch/x86/x86/x86_autoconf.c |   14 +-
 sys/arch/xen/x86/autoconf.c     |    5 +-
 sys/dev/acpi/vmbus_acpi.c       |    6 +-
 sys/dev/hyperv/files.hyperv     |    9 +-
 sys/dev/hyperv/genfb_vmbus.c    |  158 +++++++++
 sys/dev/hyperv/genfb_vmbusvar.h |   40 ++
 sys/dev/hyperv/hvkbd.c          |  644 ++++++++++++++++++++++++++++++++++++++++
 sys/dev/hyperv/hvkbdvar.h       |    8 +
 sys/dev/hyperv/hypervvar.h      |    3 +-
 sys/dev/hyperv/vmbus.c          |    8 +-
 sys/dev/hyperv/vmbusvar.h       |    6 +-
 sys/dev/wscons/wsconsio.h       |    3 +-
 20 files changed, 1197 insertions(+), 38 deletions(-)

diffs (truncated from 1657 to 300 lines):

diff -r 70ef19df07c6 -r 168e154afd93 sys/arch/amd64/conf/GENERIC
--- a/sys/arch/amd64/conf/GENERIC       Fri May 24 10:37:39 2019 +0000
+++ b/sys/arch/amd64/conf/GENERIC       Fri May 24 14:28:48 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.527 2019/05/06 02:24:37 sevan Exp $
+# $NetBSD: GENERIC,v 1.528 2019/05/24 14:28:48 nonaka Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@
 
 options        INCLUDE_CONFIG_FILE     # embed config file in kernel binary
 
-#ident         "GENERIC-$Revision: 1.527 $"
+#ident         "GENERIC-$Revision: 1.528 $"
 
 maxusers       64              # estimated number of users
 
@@ -1067,6 +1067,9 @@
 
 # Hyper-V devices
 vmbus*         at acpi?                # Hyper-V VMBus
+genfb*         at vmbus?               # Hyper-V Synthetic Video Framebuffer
+hvkbd*         at vmbus?               # Hyper-V Synthetic Keyboard
+wskbd*         at hvkbd? console ? mux 1
 hvn*           at vmbus?               # Hyper-V NetVSC
 hvs*           at vmbus?               # Hyper-V StorVSC
 hvheartbeat*   at vmbus?               # Hyper-V Heartbeat Service
diff -r 70ef19df07c6 -r 168e154afd93 sys/arch/i386/conf/GENERIC
--- a/sys/arch/i386/conf/GENERIC        Fri May 24 10:37:39 2019 +0000
+++ b/sys/arch/i386/conf/GENERIC        Fri May 24 14:28:48 2019 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: GENERIC,v 1.1206 2019/05/06 02:24:37 sevan Exp $
+# $NetBSD: GENERIC,v 1.1207 2019/05/24 14:28:48 nonaka Exp $
 #
 # GENERIC machine description file
 #
@@ -22,7 +22,7 @@
 
 options        INCLUDE_CONFIG_FILE     # embed config file in kernel binary
 
-#ident         "GENERIC-$Revision: 1.1206 $"
+#ident         "GENERIC-$Revision: 1.1207 $"
 
 maxusers       64              # estimated number of users
 
@@ -1406,6 +1406,9 @@
 
 # Hyper-V devices
 vmbus*         at acpi?                # Hyper-V VMBus
+genfb*         at vmbus?               # Hyper-V Synthetic Video Framebuffer
+hvkbd*         at vmbus?               # Hyper-V Synthetic Keyboard
+wskbd*         at hvkbd? console ? mux 1
 hvn*           at vmbus?               # Hyper-V NetVSC
 hvs*           at vmbus?               # Hyper-V StorVSC
 hvheartbeat*   at vmbus?               # Hyper-V Heartbeat Service
diff -r 70ef19df07c6 -r 168e154afd93 sys/arch/x86/include/autoconf.h
--- a/sys/arch/x86/include/autoconf.h   Fri May 24 10:37:39 2019 +0000
+++ b/sys/arch/x86/include/autoconf.h   Fri May 24 14:28:48 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: autoconf.h,v 1.5 2018/12/22 07:45:58 cherry Exp $ */
+/* $NetBSD: autoconf.h,v 1.6 2019/05/24 14:28:48 nonaka Exp $ */
 #ifndef _X86_AUTOCONF_H_
 #define _X86_AUTOCONF_H_
 
@@ -20,6 +20,8 @@
 #endif
 };
 
+extern int x86_found_console;
+
 void device_pci_props_register(device_t, void *);
 device_t device_pci_register(device_t, void *);
 device_t device_isa_register(device_t, void *);
diff -r 70ef19df07c6 -r 168e154afd93 sys/arch/x86/pci/pci_machdep.c
--- a/sys/arch/x86/pci/pci_machdep.c    Fri May 24 10:37:39 2019 +0000
+++ b/sys/arch/x86/pci/pci_machdep.c    Fri May 24 14:28:48 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: pci_machdep.c,v 1.85 2019/05/17 18:34:33 christos Exp $        */
+/*     $NetBSD: pci_machdep.c,v 1.86 2019/05/24 14:28:48 nonaka Exp $  */
 
 /*-
  * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -73,7 +73,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.85 2019/05/17 18:34:33 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: pci_machdep.c,v 1.86 2019/05/24 14:28:48 nonaka Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -1117,7 +1117,6 @@
 device_t
 device_pci_register(device_t dev, void *aux)
 {
-       static bool found_console = false;
        device_t parent = device_parent(dev);
 
        device_pci_props_register(dev, aux);
@@ -1171,7 +1170,7 @@
                }
        }
        if (parent && device_is_a(parent, "pci") &&
-           found_console == false) {
+           x86_found_console == false) {
                struct pci_attach_args *pa = aux;
 
                if (PCI_CLASS(pa->pa_class) == PCI_CLASS_DISPLAY) {
@@ -1209,7 +1208,7 @@
                        vga_posth = vga_post_init(pa->pa_bus, pa->pa_device,
                            pa->pa_function);
 #endif
-                       found_console = true;
+                       x86_found_console = true;
                        return NULL;
                }
        }
diff -r 70ef19df07c6 -r 168e154afd93 sys/arch/x86/x86/consinit.c
--- a/sys/arch/x86/x86/consinit.c       Fri May 24 10:37:39 2019 +0000
+++ b/sys/arch/x86/x86/consinit.c       Fri May 24 14:28:48 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: consinit.c,v 1.28 2015/01/11 19:54:23 is Exp $ */
+/*     $NetBSD: consinit.c,v 1.29 2019/05/24 14:28:48 nonaka Exp $     */
 
 /*
  * Copyright (c) 1998
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.28 2015/01/11 19:54:23 is Exp $");
+__KERNEL_RCSID(0, "$NetBSD: consinit.c,v 1.29 2019/05/24 14:28:48 nonaka Exp $");
 
 #include "opt_kgdb.h"
 #include "opt_puc.h"
@@ -36,6 +36,7 @@
 #include <sys/systm.h>
 #include <sys/device.h>
 #include <sys/bus.h>
+#include <sys/cpu.h>
 #include <machine/bootinfo.h>
 #include <arch/x86/include/genfb_machdep.h>
 
@@ -90,6 +91,13 @@
 #include <dev/usb/ukbdvar.h>
 #endif
 
+#ifndef XEN
+#include "hvkbd.h"
+#if NHVKBD > 0
+#include <dev/hyperv/hvkbdvar.h>
+#endif
+#endif
+
 #ifndef CONSDEVNAME
 #define CONSDEVNAME "pc"
 #endif
@@ -205,6 +213,10 @@
                error = pckbc_cnattach(x86_bus_space_io, IO_KBD, KBCMDP,
                    PCKBC_KBD_SLOT, 0);
 #endif
+#if (NHVKBD > 0)
+               if (error && vm_guest == VM_GUEST_HV)
+                       error = hvkbd_cnattach();
+#endif
 #if (NUKBD > 0)
                if (error)
                        error = ukbd_cnattach();
diff -r 70ef19df07c6 -r 168e154afd93 sys/arch/x86/x86/hyperv.c
--- a/sys/arch/x86/x86/hyperv.c Fri May 24 10:37:39 2019 +0000
+++ b/sys/arch/x86/x86/hyperv.c Fri May 24 14:28:48 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: hyperv.c,v 1.1 2019/02/15 08:54:01 nonaka Exp $        */
+/*     $NetBSD: hyperv.c,v 1.2 2019/05/24 14:28:48 nonaka Exp $        */
 
 /*-
  * Copyright (c) 2009-2012,2016-2017 Microsoft Corp.
@@ -33,7 +33,7 @@
  */
 #include <sys/cdefs.h>
 #ifdef __KERNEL_RCSID
-__KERNEL_RCSID(0, "$NetBSD: hyperv.c,v 1.1 2019/02/15 08:54:01 nonaka Exp $");
+__KERNEL_RCSID(0, "$NetBSD: hyperv.c,v 1.2 2019/05/24 14:28:48 nonaka Exp $");
 #endif
 #ifdef __FBSDID
 __FBSDID("$FreeBSD: head/sys/dev/hyperv/vmbus/hyperv.c 331757 2018-03-30 02:25:12Z emaste $");
@@ -41,6 +41,9 @@
 
 #ifdef _KERNEL_OPT
 #include "lapic.h"
+#include "genfb.h"
+#include "opt_ddb.h"
+#include "wsdisplay.h"
 #endif
 
 #include <sys/param.h>
@@ -57,13 +60,27 @@
 
 #include <uvm/uvm_extern.h>
 
+#include <machine/autoconf.h>
+#include <machine/bootinfo.h>
 #include <machine/cpufunc.h>
 #include <machine/cputypes.h>
 #include <machine/cpuvar.h>
 #include <machine/cpu_counter.h>
+#include <x86/efi.h>
+
+#include <dev/wsfb/genfbvar.h>
+#include <arch/x86/include/genfb_machdep.h>
 
 #include <x86/x86/hypervreg.h>
+#include <x86/x86/hypervvar.h>
 #include <dev/hyperv/vmbusvar.h>
+#include <dev/hyperv/genfb_vmbusvar.h>
+
+#ifdef DDB
+#include <machine/db_machdep.h>
+#include <ddb/db_sym.h>
+#include <ddb/db_extern.h>
+#endif
 
 struct hyperv_softc {
        device_t                sc_dev;
@@ -299,6 +316,26 @@
        } while (now < end);
 }
 
+static void
+delay_msr(unsigned int n)
+{
+       uint64_t end, now;
+       u_int last, u;
+
+       now = 0;
+       end = HYPERV_TIMER_FREQ * n / 1000000ULL;
+       last = (u_int)rdmsr(MSR_HV_TIME_REF_COUNT);
+       do {
+               x86_pause();
+               u = (u_int)rdmsr(MSR_HV_TIME_REF_COUNT);
+               if (u < last)
+                       now += 0xffffffff - last + u + 1;
+               else
+                       now += u - last;
+               last = u;
+       } while (now < end);
+}
+
 static __inline uint64_t
 hyperv_hypercall_md(volatile void *hc_addr, uint64_t in_val, uint64_t in_paddr,
     uint64_t out_paddr)
@@ -341,18 +378,17 @@
 }
 
 static bool
-hyperv_identify(void)
+hyperv_probe(u_int *maxleaf, u_int *features, u_int *pm_features,
+    u_int *features3)
 {
-       char buf[256];
        u_int regs[4];
-       u_int maxleaf;
 
        if (vm_guest != VM_GUEST_HV)
                return false;
 
        x86_cpuid(CPUID_LEAF_HV_MAXLEAF, regs);
-       maxleaf = regs[0];
-       if (maxleaf < CPUID_LEAF_HV_LIMITS)
+       *maxleaf = regs[0];
+       if (*maxleaf < CPUID_LEAF_HV_LIMITS)
                return false;
 
        x86_cpuid(CPUID_LEAF_HV_INTERFACE, regs);
@@ -368,9 +404,23 @@
                return false;
        }
 
-       hyperv_features = regs[0];
-       hyperv_pm_features = regs[2];
-       hyperv_features3 = regs[3];
+       *features = regs[0];
+       *pm_features = regs[2];
+       *features3 = regs[3];
+
+       return true;
+}
+
+static bool
+hyperv_identify(void)
+{
+       char buf[256];
+       u_int regs[4];
+       u_int maxleaf;
+
+       if (!hyperv_probe(&maxleaf, &hyperv_features, &hyperv_pm_features,
+           &hyperv_features3))
+               return false;
 



Home | Main Index | Thread Index | Old Index