summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sys/dev/hyperv/vmbus/hv_connection.c9
-rw-r--r--sys/dev/hyperv/vmbus/hv_hv.c54
-rw-r--r--sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c50
-rw-r--r--sys/dev/hyperv/vmbus/hv_vmbus_priv.h39
4 files changed, 74 insertions, 78 deletions
diff --git a/sys/dev/hyperv/vmbus/hv_connection.c b/sys/dev/hyperv/vmbus/hv_connection.c
index be49eee..f0f4812 100644
--- a/sys/dev/hyperv/vmbus/hv_connection.c
+++ b/sys/dev/hyperv/vmbus/hv_connection.c
@@ -152,7 +152,8 @@ hv_vmbus_negotiate_version(hv_vmbus_channel_msg_info *msg_info,
* Send a connect request on the partition service connection
*/
int
-hv_vmbus_connect(void) {
+hv_vmbus_connect(void)
+{
int ret = 0;
uint32_t version;
hv_vmbus_channel_msg_info* msg_info = NULL;
@@ -274,7 +275,8 @@ hv_vmbus_connect(void) {
* Send a disconnect request on the partition service connection
*/
int
-hv_vmbus_disconnect(void) {
+hv_vmbus_disconnect(void)
+{
int ret = 0;
hv_vmbus_channel_unload msg;
@@ -398,7 +400,8 @@ int hv_vmbus_post_message(void *buffer, size_t bufferLen)
* Send an event notification to the parent
*/
int
-hv_vmbus_set_event(hv_vmbus_channel *channel) {
+hv_vmbus_set_event(hv_vmbus_channel *channel)
+{
int ret = 0;
uint32_t child_rel_id = channel->offer_msg.child_rel_id;
diff --git a/sys/dev/hyperv/vmbus/hv_hv.c b/sys/dev/hyperv/vmbus/hv_hv.c
index 70a5608..03afe2f 100644
--- a/sys/dev/hyperv/vmbus/hv_hv.c
+++ b/sys/dev/hyperv/vmbus/hv_hv.c
@@ -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;
- }
}
}
@@ -501,8 +520,15 @@ hyperv_identify(void)
static void
hyperv_init(void *dummy __unused)
{
- if (!hyperv_identify())
+ if (!hyperv_identify()) {
+ /* Not Hyper-V; reset guest id to the generic one. */
+ if (vm_guest == VM_GUEST_HV)
+ vm_guest = VM_GUEST_VM;
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 */
diff --git a/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c b/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c
index 9663e77..65b22c1 100644
--- a/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c
+++ b/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c
@@ -346,12 +346,13 @@ hv_vmbus_child_device_unregister(struct hv_device *child_dev)
}
static int
-vmbus_probe(device_t dev) {
+vmbus_probe(device_t dev)
+{
if (ACPI_ID_PROBE(device_get_parent(dev), dev, vmbus_ids) == NULL ||
device_get_unit(dev) != 0)
return (ENXIO);
- device_set_desc(dev, "Vmbus Devices");
+ device_set_desc(dev, "Hyper-V Vmbus");
return (BUS_PROBE_DEFAULT);
}
@@ -624,7 +625,7 @@ vmbus_attach(device_t dev)
}
static void
-vmbus_init(void)
+vmbus_sysinit(void *arg __unused)
{
if (vm_guest != VM_GUEST_HV || vmbus_get_softc() == NULL)
return;
@@ -670,22 +671,23 @@ vmbus_detach(device_t dev)
}
static device_method_t vmbus_methods[] = {
- /** Device interface */
- DEVMETHOD(device_probe, vmbus_probe),
- DEVMETHOD(device_attach, vmbus_attach),
- DEVMETHOD(device_detach, vmbus_detach),
- DEVMETHOD(device_shutdown, bus_generic_shutdown),
- DEVMETHOD(device_suspend, bus_generic_suspend),
- DEVMETHOD(device_resume, bus_generic_resume),
-
- /** Bus interface */
- DEVMETHOD(bus_add_child, bus_generic_add_child),
- DEVMETHOD(bus_print_child, bus_generic_print_child),
- DEVMETHOD(bus_read_ivar, vmbus_read_ivar),
- DEVMETHOD(bus_write_ivar, vmbus_write_ivar),
- DEVMETHOD(bus_child_pnpinfo_str, vmbus_child_pnpinfo_str),
-
- { 0, 0 } };
+ /* Device interface */
+ DEVMETHOD(device_probe, vmbus_probe),
+ DEVMETHOD(device_attach, vmbus_attach),
+ DEVMETHOD(device_detach, vmbus_detach),
+ DEVMETHOD(device_shutdown, bus_generic_shutdown),
+ DEVMETHOD(device_suspend, bus_generic_suspend),
+ DEVMETHOD(device_resume, bus_generic_resume),
+
+ /* Bus interface */
+ DEVMETHOD(bus_add_child, bus_generic_add_child),
+ DEVMETHOD(bus_print_child, bus_generic_print_child),
+ DEVMETHOD(bus_read_ivar, vmbus_read_ivar),
+ DEVMETHOD(bus_write_ivar, vmbus_write_ivar),
+ DEVMETHOD(bus_child_pnpinfo_str, vmbus_child_pnpinfo_str),
+
+ DEVMETHOD_END
+};
static driver_t vmbus_driver = {
"vmbus",
@@ -693,12 +695,16 @@ static driver_t vmbus_driver = {
sizeof(struct vmbus_softc)
};
-devclass_t vmbus_devclass;
+static devclass_t vmbus_devclass;
DRIVER_MODULE(vmbus, acpi, vmbus_driver, vmbus_devclass, NULL, NULL);
MODULE_DEPEND(vmbus, acpi, 1, 1, 1);
MODULE_VERSION(vmbus, 1);
-/* We want to be started after SMP is initialized */
-SYSINIT(vmb_init, SI_SUB_SMP + 1, SI_ORDER_FIRST, vmbus_init, NULL);
+/*
+ * NOTE:
+ * We have to start as the last step of SI_SUB_SMP, i.e. after SMP is
+ * initialized.
+ */
+SYSINIT(vmbus_initialize, SI_SUB_SMP, SI_ORDER_ANY, vmbus_sysinit, NULL);
diff --git a/sys/dev/hyperv/vmbus/hv_vmbus_priv.h b/sys/dev/hyperv/vmbus/hv_vmbus_priv.h
index adf1a68..34f5606 100644
--- a/sys/dev/hyperv/vmbus/hv_vmbus_priv.h
+++ b/sys/dev/hyperv/vmbus/hv_vmbus_priv.h
@@ -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];
OpenPOWER on IntegriCloud