Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 27 May 2016 05:58:53 +0000 (UTC)
From:      Sepherosa Ziehau <sephe@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r300825 - head/sys/dev/hyperv/vmbus
Message-ID:  <201605270558.u4R5wrAU016545@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: sephe
Date: Fri May 27 05:58:53 2016
New Revision: 300825
URL: https://svnweb.freebsd.org/changeset/base/300825

Log:
  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

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

Modified: head/sys/dev/hyperv/vmbus/hv_hv.c
==============================================================================
--- head/sys/dev/hyperv/vmbus/hv_hv.c	Fri May 27 05:31:14 2016	(r300824)
+++ head/sys/dev/hyperv/vmbus/hv_hv.c	Fri May 27 05:58:53 2016	(r300825)
@@ -50,8 +50,6 @@ __FBSDID("$FreeBSD$");
 
 #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
@@ -204,26 +202,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 +228,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 +269,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,7 +304,7 @@ 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) {
+	if (hyperv_features & CPUID_HV_MSR_TIME_REFCNT) {
 		/* Register virtual timecount */
 		tc_init(&hv_timecounter);
 	}

Modified: head/sys/dev/hyperv/vmbus/hv_vmbus_priv.h
==============================================================================
--- head/sys/dev/hyperv/vmbus/hv_vmbus_priv.h	Fri May 27 05:31:14 2016	(r300824)
+++ head/sys/dev/hyperv/vmbus/hv_vmbus_priv.h	Fri May 27 05:58:53 2016	(r300825)
@@ -443,43 +443,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 {

Modified: head/sys/dev/hyperv/vmbus/hyperv_reg.h
==============================================================================
--- head/sys/dev/hyperv/vmbus/hyperv_reg.h	Fri May 27 05:31:14 2016	(r300824)
+++ head/sys/dev/hyperv/vmbus/hyperv_reg.h	Fri May 27 05:58:53 2016	(r300825)
@@ -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
@@ -73,4 +77,42 @@
 #define MSR_HV_SINT_RSVD_MASK		(MSR_HV_SINT_RSVD1_MASK |	\
 					 MSR_HV_SINT_RSVD2_MASK)
 
+/*
+ * 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_GUEST_IDLE		0x0400	/* MSR_VH_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_ */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605270558.u4R5wrAU016545>