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
This commit is contained in:
sephe 2016-05-23 05:11:38 +00:00
parent 0847498039
commit f5153143b6
2 changed files with 35 additions and 52 deletions

View File

@ -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;
@ -142,13 +171,6 @@ hv_vmbus_init(void)
if (vm_guest != VM_GUEST_HV)
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
*/
@ -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);

View File

@ -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];