Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 26 May 2016 03:50:52 +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: r300708 - head/sys/dev/hyperv/vmbus
Message-ID:  <201605260350.u4Q3oqAg037266@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: sephe
Date: Thu May 26 03:50:52 2016
New Revision: 300708
URL: https://svnweb.freebsd.org/changeset/base/300708

Log:
  hyperv: Rework guest id settings according to Hyper-V spec
  
  MFC after:	1 week
  Sponsored by:	Microsoft OSTC
  Differential Revision:	https://reviews.freebsd.org/D6553

Modified:
  head/sys/dev/hyperv/vmbus/hv_hv.c
  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	Thu May 26 02:55:41 2016	(r300707)
+++ head/sys/dev/hyperv/vmbus/hv_hv.c	Thu May 26 03:50:52 2016	(r300708)
@@ -52,34 +52,24 @@ __FBSDID("$FreeBSD$");
 
 #define	HYPERV_INTERFACE		0x31237648	/* HV#1 */
 
-/*
- * The guest OS needs to register the guest ID with the hypervisor.
- * The guest ID is a 64 bit entity and the structure of this ID is
- * specified in the Hyper-V specification:
- *
- * http://msdn.microsoft.com/en-us/library/windows/
- * hardware/ff542653%28v=vs.85%29.aspx
- *
- * While the current guideline does not specify how FreeBSD guest ID(s)
- * need to be generated, our plan is to publish the guidelines for
- * FreeBSD and other guest operating systems that currently are hosted
- * on Hyper-V. The implementation here conforms to this yet
- * unpublished guidelines.
- *
- * Bit(s)
- * 63    - Indicates if the OS is Open Source or not; 1 is Open Source
- * 62:56 - Os Type: FreeBSD is 0x02
- * 55:48 - Distro specific identification
- * 47:16 - FreeBSD kernel version number
- * 15:0  - Distro specific identification
- */
-#define HYPERV_GUESTID_OSS		(0x1ULL << 63)
-#define HYPERV_GUESTID_FREEBSD		(0x02ULL << 56)
-#define HYPERV_GUESTID(id)				\
-	(HYPERV_GUESTID_OSS | HYPERV_GUESTID_FREEBSD |	\
-	 (((uint64_t)(((id) & 0xff0000) >> 16)) << 48) |\
-	 (((uint64_t)__FreeBSD_version) << 16) |	\
-	 ((uint64_t)((id) & 0x00ffff)))
+#define HYPERV_FREEBSD_BUILD		0ULL
+#define HYPERV_FREEBSD_VERSION		((uint64_t)__FreeBSD_version)
+#define HYPERV_FREEBSD_OSID		0ULL
+
+#define MSR_HV_GUESTID_BUILD_FREEBSD	\
+	(HYPERV_FREEBSD_BUILD & MSR_HV_GUESTID_BUILD_MASK)
+#define MSR_HV_GUESTID_VERSION_FREEBSD	\
+	((HYPERV_FREEBSD_VERSION << MSR_HV_GUESTID_VERSION_SHIFT) & \
+	 MSR_HV_GUESTID_VERSION_MASK)
+#define MSR_HV_GUESTID_OSID_FREEBSD	\
+	((HYPERV_FREEBSD_OSID << MSR_HV_GUESTID_OSID_SHIFT) & \
+	 MSR_HV_GUESTID_OSID_MASK)
+
+#define MSR_HV_GUESTID_FREEBSD		\
+	(MSR_HV_GUESTID_BUILD_FREEBSD |	\
+	 MSR_HV_GUESTID_VERSION_FREEBSD | \
+	 MSR_HV_GUESTID_OSID_FREEBSD |	\
+	 MSR_HV_GUESTID_OSTYPE_FREEBSD)
 
 struct hypercall_ctx {
 	void			*hc_addr;
@@ -321,8 +311,8 @@ hyperv_init(void *dummy __unused)
 		return;
 	}
 
-	/* Write guest id */
-	wrmsr(HV_X64_MSR_GUEST_OS_ID, HYPERV_GUESTID(0));
+	/* Set guest id */
+	wrmsr(MSR_HV_GUEST_OS_ID, MSR_HV_GUESTID_FREEBSD);
 
 	if (hyperv_features & HV_FEATURE_MSR_TIME_REFCNT) {
 		/* Register virtual timecount */

Modified: head/sys/dev/hyperv/vmbus/hyperv_reg.h
==============================================================================
--- head/sys/dev/hyperv/vmbus/hyperv_reg.h	Thu May 26 02:55:41 2016	(r300707)
+++ head/sys/dev/hyperv/vmbus/hyperv_reg.h	Thu May 26 03:50:52 2016	(r300708)
@@ -29,6 +29,20 @@
 #ifndef _HYPERV_REG_H_
 #define _HYPERV_REG_H_
 
+#define MSR_HV_GUEST_OS_ID		0x40000000
+#define MSR_HV_GUESTID_BUILD_MASK	0xffffULL
+#define MSR_HV_GUESTID_VERSION_MASK	0x0000ffffffff0000ULL
+#define MSR_HV_GUESTID_VERSION_SHIFT	16
+#define MSR_HV_GUESTID_OSID_MASK	0x00ff000000000000ULL
+#define MSR_HV_GUESTID_OSID_SHIFT	48
+#define MSR_HV_GUESTID_OSTYPE_MASK	0x7f00000000000000ULL
+#define MSR_HV_GUESTID_OSTYPE_SHIFT	56
+#define MSR_HV_GUESTID_OPENSRC		0x8000000000000000ULL
+#define MSR_HV_GUESTID_OSTYPE_LINUX	\
+	((0x01ULL << MSR_HV_GUESTID_OSTYPE_SHIFT) | MSR_HV_GUESTID_OPENSRC)
+#define MSR_HV_GUESTID_OSTYPE_FREEBSD	\
+	((0x02ULL << MSR_HV_GUESTID_OSTYPE_SHIFT) | MSR_HV_GUESTID_OPENSRC)
+
 #define MSR_HV_HYPERCALL		0x40000001
 #define MSR_HV_HYPERCALL_ENABLE		0x0001ULL
 #define MSR_HV_HYPERCALL_RSVD_MASK	0x0ffeULL



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