svn commit: r302129 - stable/10/sys/dev/hyperv/vmbus

Sepherosa Ziehau sephe at FreeBSD.org
Thu Jun 23 08:26:08 UTC 2016


Author: sephe
Date: Thu Jun 23 08:26:07 2016
New Revision: 302129
URL: https://svnweb.freebsd.org/changeset/base/302129

Log:
  MFC 300825,300827,300830,300831,300832,300834
  
  300825
      hyperv: Move CPUID related bits to hyperv_reg.h and give them clean name
  
      MFC after:  1 week
      Sponsored by:       Microsoft OSTC
      Differential Revision:      https://reviews.freebsd.org/D6565
  
  300827
      hyperv: Move timer related MSRs into hyperv_reg.h
  
      And avoid bit fields for event timer.
  
      MFC after:  1 week
      Sponsored by:       Microsoft OSTC
      Differential Revision:      https://reviews.freebsd.org/D6566
  
  300830
      hyperv/vmbus: Move MSR EOM to hyperv_reg.h
  
      MFC after:  1 week
      Sponsored by:       Microsoft OSTC
      Differential Revision:      https://reviews.freebsd.org/D6567
  
  300831
      hyperv: GC unneeded bits
  
      MFC after:  1 week
      Sponsored by:       Microsoft OSTC
      Differential Revision:      https://reviews.freebsd.org/D6568
  
  300832
      hyperv: Clean up Hyper-V timecounter a bit.
  
      MFC after:  1 week
      Sponsored by:       Microsoft OSTC
      Differential Revision:      https://reviews.freebsd.org/D6569
  
  300834
      hyperv: Test features before enabling optional functionalities
  
      MFC after:  1 week
      Sponsored by:       Microsoft OSTC
      Differential Revision:      https://reviews.freebsd.org/D6571

Added:
  stable/10/sys/dev/hyperv/vmbus/hyperv_var.h
     - copied unchanged from r300834, head/sys/dev/hyperv/vmbus/hyperv_var.h
Modified:
  stable/10/sys/dev/hyperv/vmbus/hv_et.c
  stable/10/sys/dev/hyperv/vmbus/hv_hv.c
  stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c
  stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h
  stable/10/sys/dev/hyperv/vmbus/hyperv_reg.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/hyperv/vmbus/hv_et.c
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/hv_et.c	Thu Jun 23 08:09:44 2016	(r302128)
+++ stable/10/sys/dev/hyperv/vmbus/hv_et.c	Thu Jun 23 08:26:07 2016	(r302129)
@@ -37,12 +37,28 @@ __FBSDID("$FreeBSD$");
 #include <sys/time.h>
 #include <sys/timeet.h>
 
-#include "hv_vmbus_priv.h"
+#include <dev/hyperv/vmbus/hv_vmbus_priv.h>
+#include <dev/hyperv/vmbus/hyperv_reg.h>
+#include <dev/hyperv/vmbus/hyperv_var.h>
 
 #define HV_TIMER_FREQUENCY		(10 * 1000 * 1000LL) /* 100ns period */
 #define HV_MAX_DELTA_TICKS		0xffffffffLL
 #define HV_MIN_DELTA_TICKS		1LL
 
+#define MSR_HV_STIMER0_CFG_SINT		\
+	((((uint64_t)HV_VMBUS_TIMER_SINT) << MSR_HV_STIMER_CFG_SINT_SHIFT) & \
+	 MSR_HV_STIMER_CFG_SINT_MASK)
+
+/*
+ * Two additionally required features:
+ * - SynIC is needed for interrupt generation.
+ * - Time reference counter is needed to set ABS reference count to
+ *   STIMER0_COUNT.
+ */
+#define CPUID_HV_ET_MASK		(CPUID_HV_MSR_TIME_REFCNT |	\
+					 CPUID_HV_MSR_SYNIC |		\
+					 CPUID_HV_MSR_SYNTIMER)
+
 static struct eventtimer *et;
 
 static inline uint64_t
@@ -57,18 +73,15 @@ sbintime2tick(sbintime_t time)
 static int
 hv_et_start(struct eventtimer *et, sbintime_t firsttime, sbintime_t periodtime)
 {
-	union hv_timer_config timer_cfg;
-	uint64_t current;
+	uint64_t current, config;
 
-	timer_cfg.as_uint64 = 0;
-	timer_cfg.auto_enable = 1;
-	timer_cfg.sintx = HV_VMBUS_TIMER_SINT;
+	config = MSR_HV_STIMER_CFG_AUTOEN | MSR_HV_STIMER0_CFG_SINT;
 
-	current = rdmsr(HV_X64_MSR_TIME_REF_COUNT);
+	current = rdmsr(MSR_HV_TIME_REF_COUNT);
 	current += sbintime2tick(firsttime);
 
-	wrmsr(HV_X64_MSR_STIMER0_CONFIG, timer_cfg.as_uint64);
-	wrmsr(HV_X64_MSR_STIMER0_COUNT, current);
+	wrmsr(MSR_HV_STIMER0_CONFIG, config);
+	wrmsr(MSR_HV_STIMER0_COUNT, current);
 
 	return (0);
 }
@@ -76,8 +89,8 @@ hv_et_start(struct eventtimer *et, sbint
 static int
 hv_et_stop(struct eventtimer *et)
 {
-	wrmsr(HV_X64_MSR_STIMER0_CONFIG, 0);
-	wrmsr(HV_X64_MSR_STIMER0_COUNT, 0);
+	wrmsr(MSR_HV_STIMER0_CONFIG, 0);
+	wrmsr(MSR_HV_STIMER0_COUNT, 0);
 
 	return (0);
 }
@@ -102,7 +115,8 @@ hv_et_intr(struct trapframe *frame)
 static void
 hv_et_identify(driver_t *driver, device_t parent)
 {
-	if (device_find_child(parent, "hv_et", -1) != NULL)
+	if (device_find_child(parent, "hv_et", -1) != NULL ||
+	    (hyperv_features & CPUID_HV_ET_MASK) != CPUID_HV_ET_MASK)
 		return;
 
 	device_add_child(parent, "hv_et", -1);

Modified: stable/10/sys/dev/hyperv/vmbus/hv_hv.c
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/hv_hv.c	Thu Jun 23 08:09:44 2016	(r302128)
+++ stable/10/sys/dev/hyperv/vmbus/hv_hv.c	Thu Jun 23 08:26:07 2016	(r302129)
@@ -46,12 +46,11 @@ __FBSDID("$FreeBSD$");
 #include <dev/hyperv/include/hyperv_busdma.h>
 #include <dev/hyperv/vmbus/hv_vmbus_priv.h>
 #include <dev/hyperv/vmbus/hyperv_reg.h>
+#include <dev/hyperv/vmbus/hyperv_var.h>
 #include <dev/hyperv/vmbus/vmbus_var.h>
 
 #define HV_NANOSECONDS_PER_SEC		1000000000L
 
-#define	HYPERV_INTERFACE		0x31237648	/* HV#1 */
-
 #define HYPERV_FREEBSD_BUILD		0ULL
 #define HYPERV_FREEBSD_VERSION		((uint64_t)__FreeBSD_version)
 #define HYPERV_FREEBSD_OSID		0ULL
@@ -76,25 +75,31 @@ struct hypercall_ctx {
 	struct hyperv_dma	hc_dma;
 };
 
-static struct hypercall_ctx	hypercall_context;
-
-static u_int hv_get_timecount(struct timecounter *tc);
+static u_int	hyperv_get_timecount(struct timecounter *tc);
 
-u_int	hyperv_features;
-u_int	hyperv_recommends;
+u_int		hyperv_features;
+u_int		hyperv_recommends;
 
 static u_int	hyperv_pm_features;
 static u_int	hyperv_features3;
 
-static struct timecounter hv_timecounter = {
-	hv_get_timecount, 0, ~0u, HV_NANOSECONDS_PER_SEC/100, "Hyper-V", HV_NANOSECONDS_PER_SEC/100
+static struct timecounter	hyperv_timecounter = {
+	.tc_get_timecount	= hyperv_get_timecount,
+	.tc_poll_pps		= NULL,
+	.tc_counter_mask	= 0xffffffff,
+	.tc_frequency		= HV_NANOSECONDS_PER_SEC/100,
+	.tc_name		= "Hyper-V",
+	.tc_quality		= 2000,
+	.tc_flags		= 0,
+	.tc_priv		= NULL
 };
 
+static struct hypercall_ctx	hypercall_context;
+
 static u_int
-hv_get_timecount(struct timecounter *tc)
+hyperv_get_timecount(struct timecounter *tc __unused)
 {
-	u_int now = rdmsr(HV_X64_MSR_TIME_REF_COUNT);
-	return (now);
+	return rdmsr(MSR_HV_TIME_REF_COUNT);
 }
 
 /**
@@ -204,26 +209,22 @@ static bool
 hyperv_identify(void)
 {
 	u_int regs[4];
-	unsigned int maxLeaf;
-	unsigned int op;
+	unsigned int maxleaf;
 
 	if (vm_guest != VM_GUEST_HV)
 		return (false);
 
-	op = HV_CPU_ID_FUNCTION_HV_VENDOR_AND_MAX_FUNCTION;
-	do_cpuid(op, regs);
-	maxLeaf = regs[0];
-	if (maxLeaf < HV_CPU_ID_FUNCTION_MS_HV_IMPLEMENTATION_LIMITS)
+	do_cpuid(CPUID_LEAF_HV_MAXLEAF, regs);
+	maxleaf = regs[0];
+	if (maxleaf < CPUID_LEAF_HV_LIMITS)
 		return (false);
 
-	op = HV_CPU_ID_FUNCTION_HV_INTERFACE;
-	do_cpuid(op, regs);
-	if (regs[0] != HYPERV_INTERFACE)
+	do_cpuid(CPUID_LEAF_HV_INTERFACE, regs);
+	if (regs[0] != CPUID_HV_IFACE_HYPERV)
 		return (false);
 
-	op = HV_CPU_ID_FUNCTION_MS_HV_FEATURES;
-	do_cpuid(op, regs);
-	if ((regs[0] & HV_FEATURE_MSR_HYPERCALL) == 0) {
+	do_cpuid(CPUID_LEAF_HV_FEATURES, regs);
+	if ((regs[0] & CPUID_HV_MSR_HYPERCALL) == 0) {
 		/*
 		 * Hyper-V w/o Hypercall is impossible; someone
 		 * is faking Hyper-V.
@@ -234,31 +235,30 @@ hyperv_identify(void)
 	hyperv_pm_features = regs[2];
 	hyperv_features3 = regs[3];
 
-	op = HV_CPU_ID_FUNCTION_MS_HV_VERSION;
-	do_cpuid(op, regs);
+	do_cpuid(CPUID_LEAF_HV_IDENTITY, regs);
 	printf("Hyper-V Version: %d.%d.%d [SP%d]\n",
 	    regs[1] >> 16, regs[1] & 0xffff, regs[0], regs[2]);
 
 	printf("  Features=0x%b\n", hyperv_features,
 	    "\020"
-	    "\001VPRUNTIME"	/* MSR_VP_RUNTIME */
-	    "\002TMREFCNT"	/* MSR_TIME_REF_COUNT */
+	    "\001VPRUNTIME"	/* MSR_HV_VP_RUNTIME */
+	    "\002TMREFCNT"	/* MSR_HV_TIME_REF_COUNT */
 	    "\003SYNIC"		/* MSRs for SynIC */
 	    "\004SYNTM"		/* MSRs for SynTimer */
-	    "\005APIC"		/* MSR_{EOI,ICR,TPR} */
-	    "\006HYPERCALL"	/* MSR_{GUEST_OS_ID,HYPERCALL} */
-	    "\007VPINDEX"	/* MSR_VP_INDEX */
-	    "\010RESET"		/* MSR_RESET */
-	    "\011STATS"		/* MSR_STATS_ */
-	    "\012REFTSC"	/* MSR_REFERENCE_TSC */
-	    "\013IDLE"		/* MSR_GUEST_IDLE */
-	    "\014TMFREQ"	/* MSR_{TSC,APIC}_FREQUENCY */
-	    "\015DEBUG");	/* MSR_SYNTH_DEBUG_ */
-	printf("  PM Features=max C%u, 0x%b\n",
-	    HV_PM_FEATURE_CSTATE(hyperv_pm_features),
-	    (hyperv_pm_features & ~HV_PM_FEATURE_CSTATE_MASK),
+	    "\005APIC"		/* MSR_HV_{EOI,ICR,TPR} */
+	    "\006HYPERCALL"	/* MSR_HV_{GUEST_OS_ID,HYPERCALL} */
+	    "\007VPINDEX"	/* MSR_HV_VP_INDEX */
+	    "\010RESET"		/* MSR_HV_RESET */
+	    "\011STATS"		/* MSR_HV_STATS_ */
+	    "\012REFTSC"	/* MSR_HV_REFERENCE_TSC */
+	    "\013IDLE"		/* MSR_HV_GUEST_IDLE */
+	    "\014TMFREQ"	/* MSR_HV_{TSC,APIC}_FREQUENCY */
+	    "\015DEBUG");	/* MSR_HV_SYNTH_DEBUG_ */
+	printf("  PM Features=0x%b [C%u]\n",
+	    (hyperv_pm_features & ~CPUPM_HV_CSTATE_MASK),
 	    "\020"
-	    "\005C3HPET");	/* HPET is required for C3 state */
+	    "\005C3HPET",	/* HPET is required for C3 state */
+	    CPUPM_HV_CSTATE(hyperv_pm_features));
 	printf("  Features3=0x%b\n", hyperv_features3,
 	    "\020"
 	    "\001MWAIT"		/* MWAIT */
@@ -276,24 +276,21 @@ hyperv_identify(void)
 	    "\015NPIEP"		/* NPIEP */
 	    "\016HVDIS");	/* disabling hypervisor */
 
-	op = HV_CPU_ID_FUNCTION_MS_HV_ENLIGHTENMENT_INFORMATION;
-	do_cpuid(op, regs);
+	do_cpuid(CPUID_LEAF_HV_RECOMMENDS, regs);
 	hyperv_recommends = regs[0];
 	if (bootverbose)
 		printf("  Recommends: %08x %08x\n", regs[0], regs[1]);
 
-	op = HV_CPU_ID_FUNCTION_MS_HV_IMPLEMENTATION_LIMITS;
-	do_cpuid(op, regs);
+	do_cpuid(CPUID_LEAF_HV_LIMITS, regs);
 	if (bootverbose) {
 		printf("  Limits: Vcpu:%d Lcpu:%d Int:%d\n",
 		    regs[0], regs[1], regs[2]);
 	}
 
-	if (maxLeaf >= HV_CPU_ID_FUNCTION_MS_HV_HARDWARE_FEATURE) {
-		op = HV_CPU_ID_FUNCTION_MS_HV_HARDWARE_FEATURE;
-		do_cpuid(op, regs);
+	if (maxleaf >= CPUID_LEAF_HV_HWFEATURES) {
+		do_cpuid(CPUID_LEAF_HV_HWFEATURES, regs);
 		if (bootverbose) {
-			printf("  HW Features: %08x AMD: %08x\n",
+			printf("  HW Features: %08x, AMD: %08x\n",
 			    regs[0], regs[3]);
 		}
 	}
@@ -314,9 +311,9 @@ hyperv_init(void *dummy __unused)
 	/* Set guest id */
 	wrmsr(MSR_HV_GUEST_OS_ID, MSR_HV_GUESTID_FREEBSD);
 
-	if (hyperv_features & HV_FEATURE_MSR_TIME_REFCNT) {
-		/* Register virtual timecount */
-		tc_init(&hv_timecounter);
+	if (hyperv_features & CPUID_HV_MSR_TIME_REFCNT) {
+		/* Register Hyper-V timecounter */
+		tc_init(&hyperv_timecounter);
 	}
 }
 SYSINIT(hyperv_initialize, SI_SUB_HYPERVISOR, SI_ORDER_FIRST, hyperv_init,

Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c	Thu Jun 23 08:09:44 2016	(r302128)
+++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c	Thu Jun 23 08:26:07 2016	(r302129)
@@ -62,6 +62,7 @@ __FBSDID("$FreeBSD$");
 #include <dev/hyperv/include/hyperv.h>
 #include <dev/hyperv/vmbus/hv_vmbus_priv.h>
 #include <dev/hyperv/vmbus/hyperv_reg.h>
+#include <dev/hyperv/vmbus/hyperv_var.h>
 #include <dev/hyperv/vmbus/vmbus_var.h>
 
 #include <contrib/dev/acpica/include/acpi.h>
@@ -118,7 +119,7 @@ handled:
 			 * This will cause message queue rescan to possibly
 			 * deliver another msg from the hypervisor
 			 */
-			wrmsr(HV_X64_MSR_EOM, 0);
+			wrmsr(MSR_HV_EOM, 0);
 		}
 	}
 }
@@ -170,7 +171,7 @@ hv_vmbus_isr(struct vmbus_softc *sc, str
 			 * This will cause message queue rescan to possibly
 			 * deliver another msg from the hypervisor
 			 */
-			wrmsr(HV_X64_MSR_EOM, 0);
+			wrmsr(MSR_HV_EOM, 0);
 		}
 	}
 
@@ -215,10 +216,21 @@ vmbus_synic_setup(void *xsc)
 	uint64_t val, orig;
 	uint32_t sint;
 
-	/*
-	 * Save virtual processor id.
-	 */
-	VMBUS_PCPU_GET(sc, vcpuid, cpu) = rdmsr(MSR_HV_VP_INDEX);
+	if (hyperv_features & CPUID_HV_MSR_VP_INDEX) {
+		/*
+		 * Save virtual processor id.
+		 */
+		VMBUS_PCPU_GET(sc, vcpuid, cpu) = rdmsr(MSR_HV_VP_INDEX);
+	} else {
+		/*
+		 * XXX
+		 * Virtual processoor id is only used by a pretty broken
+		 * channel selection code from storvsc.  It's nothing
+		 * critical even if CPUID_HV_MSR_VP_INDEX is not set; keep
+		 * moving on.
+		 */
+		VMBUS_PCPU_GET(sc, vcpuid, cpu) = cpu;
+	}
 
 	/*
 	 * Setup the SynIC message.
@@ -637,7 +649,8 @@ static int
 vmbus_probe(device_t dev)
 {
 	if (ACPI_ID_PROBE(device_get_parent(dev), dev, vmbus_ids) == NULL ||
-	    device_get_unit(dev) != 0 || vm_guest != VM_GUEST_HV)
+	    device_get_unit(dev) != 0 || vm_guest != VM_GUEST_HV ||
+	    (hyperv_features & CPUID_HV_MSR_SYNIC) == 0)
 		return (ENXIO);
 
 	device_set_desc(dev, "Hyper-V Vmbus");

Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h	Thu Jun 23 08:09:44 2016	(r302128)
+++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h	Thu Jun 23 08:26:07 2016	(r302129)
@@ -356,32 +356,6 @@ typedef struct {
 } hv_vmbus_connection;
 
 typedef union {
-	uint64_t as_uint64_t;
-	struct {
-		uint64_t build_number		: 16;
-		uint64_t service_version	: 8; /* Service Pack, etc. */
-		uint64_t minor_version		: 8;
-		uint64_t major_version		: 8;
-		/*
-		 * HV_GUEST_OS_MICROSOFT_IDS (If Vendor=MS)
-		 * HV_GUEST_OS_VENDOR
-		 */
-		uint64_t os_id			: 8;
-		uint64_t vendor_id		: 16;
-	} u;
-} hv_vmbus_x64_msr_guest_os_id_contents;
-
-
-typedef union {
-	uint64_t as_uint64_t;
-	struct {
-		uint64_t enable :1;
-		uint64_t reserved :11;
-		uint64_t guest_physical_address :52;
-	} u;
-} hv_vmbus_x64_msr_hypercall_contents;
-
-typedef union {
 	uint32_t as_uint32_t;
 	struct {
 		uint32_t group_enable :4;
@@ -443,108 +417,6 @@ typedef struct {
 } hv_vmbus_monitor_page;
 
 /*
- * The below CPUID leaves are present if VersionAndFeatures.HypervisorPresent
- * is set by CPUID(HV_CPU_ID_FUNCTION_VERSION_AND_FEATURES).
- */
-typedef enum {
-	HV_CPU_ID_FUNCTION_VERSION_AND_FEATURES			= 0x00000001,
-	HV_CPU_ID_FUNCTION_HV_VENDOR_AND_MAX_FUNCTION		= 0x40000000,
-	HV_CPU_ID_FUNCTION_HV_INTERFACE				= 0x40000001,
-	/*
-	 * The remaining functions depend on the value
-	 * of hv_cpu_id_function_interface
-	 */
-	HV_CPU_ID_FUNCTION_MS_HV_VERSION			= 0x40000002,
-	HV_CPU_ID_FUNCTION_MS_HV_FEATURES			= 0x40000003,
-	HV_CPU_ID_FUNCTION_MS_HV_ENLIGHTENMENT_INFORMATION	= 0x40000004,
-	HV_CPU_ID_FUNCTION_MS_HV_IMPLEMENTATION_LIMITS		= 0x40000005,
-	HV_CPU_ID_FUNCTION_MS_HV_HARDWARE_FEATURE		= 0x40000006
-} hv_vmbus_cpuid_function;
-
-#define	HV_FEATURE_MSR_TIME_REFCNT	0x0002	/* MSR_TIME_REF_COUNT */
-#define	HV_FEATURE_MSR_SYNIC		0x0004	/* MSRs for SynIC */
-#define	HV_FEATURE_MSR_SYNTIMER		0x0008	/* MSRs for SynTimer */
-#define	HV_FEATURE_MSR_APIC		0x0010	/* MSR_{EOI,ICR,TPR} */
-#define	HV_FEATURE_MSR_HYPERCALL	0x0020	/* MSR_{GUEST_OS_ID,HYPERCALL} */
-#define	HV_FEATURE_MSR_GUEST_IDLE	0x0400	/* MSR_GUEST_IDLE */
-
-#define	HV_PM_FEATURE_CSTATE_MASK	0x000f
-#define	HV_PM_FEATURE_C3_HPET		0x0010	/* C3 requires HPET */
-#define	HV_PM_FEATURE_CSTATE(f)		((f) & HV_PM_FEATURE_CSTATE_MASK)
-
-#define	HV_FEATURE3_MWAIT		0x0001	/* MWAIT */
-#define	HV_FEATURE3_XMM_HYPERCALL	0x0010	/* hypercall input through XMM regs */
-#define	HV_FEATURE3_GUEST_IDLE		0x0020	/* guest idle support */
-#define	HV_FEATURE3_NUMA		0x0080	/* NUMA distance query support */
-#define	HV_FEATURE3_TIME_FREQ		0x0100	/* timer frequency query (TSC, LAPIC) */
-#define	HV_FEATURE3_MSR_CRASH		0x0400	/* MSRs for guest crash */
-
-/*
- * Define the format of the SIMP register
- */
-typedef union {
-	uint64_t as_uint64_t;
-	struct {
-		uint64_t simp_enabled	: 1;
-		uint64_t preserved	: 11;
-		uint64_t base_simp_gpa	: 52;
-	} u;
-} hv_vmbus_synic_simp;
-
-/*
- * Define the format of the SIEFP register
- */
-typedef union {
-	uint64_t as_uint64_t;
-	struct {
-		uint64_t siefp_enabled	: 1;
-		uint64_t preserved	: 11;
-		uint64_t base_siefp_gpa	: 52;
-	} u;
-} hv_vmbus_synic_siefp;
-
-/*
- * Define synthetic interrupt source
- */
-typedef union {
-	uint64_t as_uint64_t;
-	struct {
-		uint64_t vector		: 8;
-		uint64_t reserved1	: 8;
-		uint64_t masked		: 1;
-		uint64_t auto_eoi	: 1;
-		uint64_t reserved2	: 46;
-	} u;
-} hv_vmbus_synic_sint;
-
-/*
- * Timer configuration register.
- */
-union hv_timer_config {
-	uint64_t as_uint64;
-	struct {
-		uint64_t enable:1;
-		uint64_t periodic:1;
-		uint64_t lazy:1;
-		uint64_t auto_enable:1;
-		uint64_t reserved_z0:12;
-		uint64_t sintx:4;
-		uint64_t reserved_z1:44;
-	};
-};
-
-/*
- * Define syn_ic control register
- */
-typedef union _hv_vmbus_synic_scontrol {
-    uint64_t as_uint64_t;
-    struct {
-        uint64_t enable		: 1;
-        uint64_t reserved	: 63;
-    } u;
-} hv_vmbus_synic_scontrol;
-
-/*
  *  Define the hv_vmbus_post_message hypercall input structure
  */
 typedef struct {
@@ -565,60 +437,6 @@ typedef union vmbus_event_flags {
 } hv_vmbus_synic_event_flags;
 CTASSERT(sizeof(hv_vmbus_synic_event_flags) == HV_EVENT_FLAGS_BYTE_COUNT);
 
-#define HV_X64_CPUID_MIN	(0x40000005)
-#define HV_X64_CPUID_MAX	(0x4000ffff)
-
-/*
- * Declare the MSR used to identify the guest OS
- */
-#define HV_X64_MSR_GUEST_OS_ID	(0x40000000)
-/*
- *  Declare the MSR used to setup pages used to communicate with the hypervisor
- */
-#define HV_X64_MSR_HYPERCALL	(0x40000001)
-/* MSR used to provide vcpu index */
-#define	HV_X64_MSR_VP_INDEX	(0x40000002)
-
-#define HV_X64_MSR_TIME_REF_COUNT      (0x40000020)
-
-/*
- * Define synthetic interrupt controller model specific registers
- */
-#define HV_X64_MSR_SCONTROL   (0x40000080)
-#define HV_X64_MSR_SVERSION   (0x40000081)
-#define HV_X64_MSR_SIEFP      (0x40000082)
-#define HV_X64_MSR_SIMP       (0x40000083)
-#define HV_X64_MSR_EOM        (0x40000084)
-
-#define HV_X64_MSR_SINT0      (0x40000090)
-#define HV_X64_MSR_SINT1      (0x40000091)
-#define HV_X64_MSR_SINT2      (0x40000092)
-#define HV_X64_MSR_SINT3      (0x40000093)
-#define HV_X64_MSR_SINT4      (0x40000094)
-#define HV_X64_MSR_SINT5      (0x40000095)
-#define HV_X64_MSR_SINT6      (0x40000096)
-#define HV_X64_MSR_SINT7      (0x40000097)
-#define HV_X64_MSR_SINT8      (0x40000098)
-#define HV_X64_MSR_SINT9      (0x40000099)
-#define HV_X64_MSR_SINT10     (0x4000009A)
-#define HV_X64_MSR_SINT11     (0x4000009B)
-#define HV_X64_MSR_SINT12     (0x4000009C)
-#define HV_X64_MSR_SINT13     (0x4000009D)
-#define HV_X64_MSR_SINT14     (0x4000009E)
-#define HV_X64_MSR_SINT15     (0x4000009F)
-
-/*
- * Synthetic Timer MSRs. Four timers per vcpu.
- */
-#define HV_X64_MSR_STIMER0_CONFIG		0x400000B0
-#define HV_X64_MSR_STIMER0_COUNT		0x400000B1
-#define HV_X64_MSR_STIMER1_CONFIG		0x400000B2
-#define HV_X64_MSR_STIMER1_COUNT		0x400000B3
-#define HV_X64_MSR_STIMER2_CONFIG		0x400000B4
-#define HV_X64_MSR_STIMER2_COUNT		0x400000B5
-#define HV_X64_MSR_STIMER3_CONFIG		0x400000B6
-#define HV_X64_MSR_STIMER3_COUNT		0x400000B7
-
 /*
  * Declare the various hypercall operations
  */
@@ -633,9 +451,6 @@ typedef enum {
 
 extern hv_vmbus_connection	hv_vmbus_g_connection;
 
-extern u_int			hyperv_features;
-extern u_int			hyperv_recommends;
-
 typedef void (*vmbus_msg_handler)(hv_vmbus_channel_msg_header *msg);
 
 typedef struct hv_vmbus_channel_msg_table_entry {

Modified: stable/10/sys/dev/hyperv/vmbus/hyperv_reg.h
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/hyperv_reg.h	Thu Jun 23 08:09:44 2016	(r302128)
+++ stable/10/sys/dev/hyperv/vmbus/hyperv_reg.h	Thu Jun 23 08:26:07 2016	(r302129)
@@ -29,6 +29,10 @@
 #ifndef _HYPERV_REG_H_
 #define _HYPERV_REG_H_
 
+/*
+ * Hyper-V Synthetic MSRs
+ */
+
 #define MSR_HV_GUEST_OS_ID		0x40000000
 #define MSR_HV_GUESTID_BUILD_MASK	0xffffULL
 #define MSR_HV_GUESTID_VERSION_MASK	0x0000ffffffff0000ULL
@@ -50,6 +54,8 @@
 
 #define MSR_HV_VP_INDEX			0x40000002
 
+#define MSR_HV_TIME_REF_COUNT		0x40000020
+
 #define MSR_HV_SCONTROL			0x40000080
 #define MSR_HV_SCTRL_ENABLE		0x0001ULL
 #define MSR_HV_SCTRL_RSVD_MASK		0xfffffffffffffffeULL
@@ -64,6 +70,8 @@
 #define MSR_HV_SIMP_RSVD_MASK		0x0ffeULL
 #define MSR_HV_SIMP_PGSHIFT		12
 
+#define MSR_HV_EOM			0x40000084
+
 #define MSR_HV_SINT0			0x40000090
 #define MSR_HV_SINT_VECTOR_MASK		0x00ffULL
 #define MSR_HV_SINT_RSVD1_MASK		0xff00ULL
@@ -73,4 +81,53 @@
 #define MSR_HV_SINT_RSVD_MASK		(MSR_HV_SINT_RSVD1_MASK |	\
 					 MSR_HV_SINT_RSVD2_MASK)
 
+#define MSR_HV_STIMER0_CONFIG		0x400000b0
+#define MSR_HV_STIMER_CFG_ENABLE	0x0001ULL
+#define MSR_HV_STIMER_CFG_PERIODIC	0x0002ULL
+#define MSR_HV_STIMER_CFG_LAZY		0x0004ULL
+#define MSR_HV_STIMER_CFG_AUTOEN	0x0008ULL
+#define MSR_HV_STIMER_CFG_SINT_MASK	0x000f0000ULL
+#define MSR_HV_STIMER_CFG_SINT_SHIFT	16
+
+#define MSR_HV_STIMER0_COUNT		0x400000b1
+
+/*
+ * CPUID leaves
+ */
+
+#define CPUID_LEAF_HV_MAXLEAF		0x40000000
+
+#define CPUID_LEAF_HV_INTERFACE		0x40000001
+#define CPUID_HV_IFACE_HYPERV		0x31237648	/* HV#1 */
+
+#define CPUID_LEAF_HV_IDENTITY		0x40000002
+
+#define CPUID_LEAF_HV_FEATURES		0x40000003
+/* EAX: features */
+#define CPUID_HV_MSR_TIME_REFCNT	0x0002	/* MSR_HV_TIME_REF_COUNT */
+#define CPUID_HV_MSR_SYNIC		0x0004	/* MSRs for SynIC */
+#define CPUID_HV_MSR_SYNTIMER		0x0008	/* MSRs for SynTimer */
+#define CPUID_HV_MSR_APIC		0x0010	/* MSR_HV_{EOI,ICR,TPR} */
+#define CPUID_HV_MSR_HYPERCALL		0x0020	/* MSR_HV_GUEST_OS_ID
+						 * MSR_HV_HYPERCALL */
+#define CPUID_HV_MSR_VP_INDEX		0x0040	/* MSR_HV_VP_INDEX */
+#define CPUID_HV_MSR_GUEST_IDLE		0x0400	/* MSR_HV_GUEST_IDLE */
+/* ECX: power management features */
+#define CPUPM_HV_CSTATE_MASK		0x000f	/* deepest C-state */
+#define CPUPM_HV_C3_HPET		0x0010	/* C3 requires HPET */
+#define CPUPM_HV_CSTATE(f)		((f) & CPUPM_HV_CSTATE_MASK)
+/* EDX: features3 */
+#define CPUID3_HV_MWAIT			0x0001	/* MWAIT */
+#define CPUID3_HV_XMM_HYPERCALL		0x0010	/* Hypercall input through
+						 * XMM regs */
+#define CPUID3_HV_GUEST_IDLE		0x0020	/* guest idle */
+#define CPUID3_HV_NUMA			0x0080	/* NUMA distance query */
+#define CPUID3_HV_TIME_FREQ		0x0100	/* timer frequency query
+						 * (TSC, LAPIC) */
+#define CPUID3_HV_MSR_CRASH		0x0400	/* MSRs for guest crash */
+
+#define CPUID_LEAF_HV_RECOMMENDS	0x40000004
+#define CPUID_LEAF_HV_LIMITS		0x40000005
+#define CPUID_LEAF_HV_HWFEATURES	0x40000006
+
 #endif	/* !_HYPERV_REG_H_ */

Copied: stable/10/sys/dev/hyperv/vmbus/hyperv_var.h (from r300834, head/sys/dev/hyperv/vmbus/hyperv_var.h)
==============================================================================
--- /dev/null	00:00:00 1970	(empty, because file is newly added)
+++ stable/10/sys/dev/hyperv/vmbus/hyperv_var.h	Thu Jun 23 08:26:07 2016	(r302129, copy of r300834, head/sys/dev/hyperv/vmbus/hyperv_var.h)
@@ -0,0 +1,35 @@
+/*-
+ * Copyright (c) 2016 Microsoft Corp.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice unmodified, this list of conditions, and the following
+ *    disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ * $FreeBSD$
+ */
+
+#ifndef _HYPERV_VAR_H_
+#define _HYPERV_VAR_H_
+
+extern u_int	hyperv_features;
+extern u_int	hyperv_recommends;
+
+#endif	/* !_HYPERV_VAR_H_ */


More information about the svn-src-all mailing list