Date: Mon, 23 May 2016 05:11:38 +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: r300455 - head/sys/dev/hyperv/vmbus Message-ID: <201605230511.u4N5Bcp8082230@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: sephe Date: Mon May 23 05:11:38 2016 New Revision: 300455 URL: https://svnweb.freebsd.org/changeset/base/300455 Log: hyperv: Move guest id setup to early place And - Rework the guest id composition. - Nuke useless saved guest_id. MFC after: 1 week Sponsored by: Microsoft OSTC Differential Revision: https://reviews.freebsd.org/D6430 Modified: head/sys/dev/hyperv/vmbus/hv_hv.c head/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Modified: head/sys/dev/hyperv/vmbus/hv_hv.c ============================================================================== --- head/sys/dev/hyperv/vmbus/hv_hv.c Mon May 23 05:11:31 2016 (r300454) +++ head/sys/dev/hyperv/vmbus/hv_hv.c Mon May 23 05:11:38 2016 (r300455) @@ -50,6 +50,35 @@ __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))) + static u_int hv_get_timecount(struct timecounter *tc); u_int hyperv_features; @@ -143,13 +172,6 @@ hv_vmbus_init(void) goto cleanup; /* - * Write our OS info - */ - uint64_t os_guest_info = HV_FREEBSD_GUEST_ID; - wrmsr(HV_X64_MSR_GUEST_OS_ID, os_guest_info); - hv_vmbus_g_context.guest_id = os_guest_info; - - /* * See if the hypercall page is already set */ hypercall_msr.as_uint64_t = rdmsr(HV_X64_MSR_HYPERCALL); @@ -192,16 +214,13 @@ hv_vmbus_init(void) void hv_vmbus_cleanup(void) { - hv_vmbus_x64_msr_hypercall_contents hypercall_msr; + if (hv_vmbus_g_context.hypercall_page != NULL) { + hv_vmbus_x64_msr_hypercall_contents hypercall_msr; - if (hv_vmbus_g_context.guest_id == HV_FREEBSD_GUEST_ID) { - if (hv_vmbus_g_context.hypercall_page != NULL) { hypercall_msr.as_uint64_t = 0; - wrmsr(HV_X64_MSR_HYPERCALL, - hypercall_msr.as_uint64_t); + wrmsr(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64_t); free(hv_vmbus_g_context.hypercall_page, M_DEVBUF); hv_vmbus_g_context.hypercall_page = NULL; - } } } @@ -508,6 +527,9 @@ hyperv_init(void *dummy __unused) return; } + /* Write guest id */ + wrmsr(HV_X64_MSR_GUEST_OS_ID, HYPERV_GUESTID(0)); + if (hyperv_features & HV_FEATURE_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 Mon May 23 05:11:31 2016 (r300454) +++ head/sys/dev/hyperv/vmbus/hv_vmbus_priv.h Mon May 23 05:11:38 2016 (r300455) @@ -198,7 +198,6 @@ enum { #define HV_HYPERCALL_PARAM_ALIGN sizeof(uint64_t) typedef struct { - uint64_t guest_id; void* hypercall_page; hv_bool_uint8_t syn_ic_initialized; @@ -763,44 +762,6 @@ void hv_et_intr(struct trapframe*); /* Wait for device creation */ void vmbus_scan(void); -/* - * 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; Linux is 0x100, FreeBSD is 0x200 - * 55:48 - Distro specific identification - * 47:16 - FreeBSD kernel version number - * 15:0 - Distro specific identification - * - */ - -#define HV_FREEBSD_VENDOR_ID 0x8200 -#define HV_FREEBSD_GUEST_ID hv_generate_guest_id(0,0) - -static inline uint64_t hv_generate_guest_id( - uint8_t distro_id_part1, - uint16_t distro_id_part2) -{ - uint64_t guest_id; - guest_id = (((uint64_t)HV_FREEBSD_VENDOR_ID) << 48); - guest_id |= (((uint64_t)(distro_id_part1)) << 48); - guest_id |= (((uint64_t)(__FreeBSD_version)) << 16); /* in param.h */ - guest_id |= ((uint64_t)(distro_id_part2)); - return guest_id; -} - typedef struct { unsigned int vector; void *page_buffers[2 * MAXCPU];
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201605230511.u4N5Bcp8082230>