summaryrefslogtreecommitdiffstats
path: root/sys/dev/hyperv
diff options
context:
space:
mode:
Diffstat (limited to 'sys/dev/hyperv')
-rw-r--r--sys/dev/hyperv/include/hyperv_busdma.h4
-rw-r--r--sys/dev/hyperv/vmbus/hv_channel_mgmt.c7
-rw-r--r--sys/dev/hyperv/vmbus/hv_hv.c7
-rw-r--r--sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c70
-rw-r--r--sys/dev/hyperv/vmbus/hv_vmbus_priv.h10
-rw-r--r--sys/dev/hyperv/vmbus/vmbus_var.h6
6 files changed, 36 insertions, 68 deletions
diff --git a/sys/dev/hyperv/include/hyperv_busdma.h b/sys/dev/hyperv/include/hyperv_busdma.h
index f4ea8cf..a27d2db 100644
--- a/sys/dev/hyperv/include/hyperv_busdma.h
+++ b/sys/dev/hyperv/include/hyperv_busdma.h
@@ -29,6 +29,10 @@
#ifndef _HYPERV_BUSDMA_H_
#define _HYPERV_BUSDMA_H_
+#include <sys/param.h>
+#include <sys/bus.h>
+#include <machine/bus.h>
+
struct hyperv_dma {
bus_addr_t hv_paddr;
bus_dma_tag_t hv_dtag;
diff --git a/sys/dev/hyperv/vmbus/hv_channel_mgmt.c b/sys/dev/hyperv/vmbus/hv_channel_mgmt.c
index b342948..11ed340 100644
--- a/sys/dev/hyperv/vmbus/hv_channel_mgmt.c
+++ b/sys/dev/hyperv/vmbus/hv_channel_mgmt.c
@@ -35,7 +35,8 @@ __FBSDID("$FreeBSD$");
#include <sys/mbuf.h>
#include <sys/mutex.h>
-#include "hv_vmbus_priv.h"
+#include <dev/hyperv/vmbus/hv_vmbus_priv.h>
+#include <dev/hyperv/vmbus/vmbus_var.h>
/*
* Internal functions
@@ -310,7 +311,7 @@ vmbus_channel_cpu_set(struct hv_vmbus_channel *chan, int cpu)
}
chan->target_cpu = cpu;
- chan->target_vcpu = hv_vmbus_g_context.hv_vcpu_index[cpu];
+ chan->target_vcpu = VMBUS_PCPU_GET(vmbus_get_softc(), vcpuid, cpu);
if (bootverbose) {
printf("vmbus_chan%u: assigned to cpu%u [vcpu%u]\n",
@@ -751,7 +752,7 @@ vmbus_select_outgoing_channel(struct hv_vmbus_channel *primary)
return outgoing_channel;
}
- cur_vcpu = hv_vmbus_g_context.hv_vcpu_index[smp_pro_id];
+ cur_vcpu = VMBUS_PCPU_GET(vmbus_get_softc(), vcpuid, smp_pro_id);
TAILQ_FOREACH(new_channel, &primary->sc_list_anchor, sc_list_entry) {
if (new_channel->state != HV_CHANNEL_OPENED_STATE){
diff --git a/sys/dev/hyperv/vmbus/hv_hv.c b/sys/dev/hyperv/vmbus/hv_hv.c
index 5bcd00f..289b577 100644
--- a/sys/dev/hyperv/vmbus/hv_hv.c
+++ b/sys/dev/hyperv/vmbus/hv_hv.c
@@ -96,13 +96,6 @@ u_int hyperv_recommends;
static u_int hyperv_pm_features;
static u_int hyperv_features3;
-/**
- * Globals
- */
-hv_vmbus_context hv_vmbus_g_context = {
- .syn_ic_initialized = FALSE,
-};
-
static struct timecounter hv_timecounter = {
hv_get_timecount, 0, ~0u, HV_NANOSECONDS_PER_SEC/100, "Hyper-V", HV_NANOSECONDS_PER_SEC/100
};
diff --git a/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c b/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c
index 1fec33c..1c3429f 100644
--- a/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c
+++ b/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c
@@ -68,8 +68,6 @@ __FBSDID("$FreeBSD$");
struct vmbus_softc *vmbus_sc;
-static int vmbus_inited;
-
static char *vmbus_ids[] = { "VMBUS", NULL };
extern inthand_t IDTVEC(rsvd), IDTVEC(hv_vmbus_callback);
@@ -209,25 +207,18 @@ hv_vector_handler(struct trapframe *trap_frame)
}
static void
-vmbus_synic_setup(void *arg __unused)
+vmbus_synic_setup(void *xsc)
{
- struct vmbus_softc *sc = vmbus_get_softc();
+ struct vmbus_softc *sc = xsc;
int cpu;
- uint64_t hv_vcpu_index;
hv_vmbus_synic_simp simp;
hv_vmbus_synic_siefp siefp;
hv_vmbus_synic_scontrol sctrl;
hv_vmbus_synic_sint shared_sint;
- uint64_t version;
cpu = PCPU_GET(cpuid);
/*
- * TODO: Check the version
- */
- version = rdmsr(HV_X64_MSR_SVERSION);
-
- /*
* Setup the Synic's message page
*/
simp.as_uint64_t = rdmsr(HV_X64_MSR_SIMP);
@@ -265,14 +256,11 @@ vmbus_synic_setup(void *arg __unused)
wrmsr(HV_X64_MSR_SCONTROL, sctrl.as_uint64_t);
- hv_vmbus_g_context.syn_ic_initialized = TRUE;
-
/*
* Set up the cpuid mapping from Hyper-V to FreeBSD.
* The array is indexed using FreeBSD cpuid.
*/
- hv_vcpu_index = rdmsr(HV_X64_MSR_VP_INDEX);
- hv_vmbus_g_context.hv_vcpu_index[cpu] = (uint32_t)hv_vcpu_index;
+ VMBUS_PCPU_GET(sc, vcpuid, cpu) = rdmsr(HV_X64_MSR_VP_INDEX);
}
static void
@@ -282,9 +270,6 @@ vmbus_synic_teardown(void *arg)
hv_vmbus_synic_simp simp;
hv_vmbus_synic_siefp siefp;
- if (!hv_vmbus_g_context.syn_ic_initialized)
- return;
-
shared_sint.as_uint64_t = rdmsr(
HV_X64_MSR_SINT0 + HV_VMBUS_MESSAGE_SINT);
@@ -532,16 +517,11 @@ vmbus_intr_teardown(struct vmbus_softc *sc)
}
static int
-vmbus_read_ivar(
- device_t dev,
- device_t child,
- int index,
- uintptr_t* result)
+vmbus_read_ivar(device_t dev, device_t child, int index, uintptr_t *result)
{
struct hv_device *child_dev_ctx = device_get_ivars(child);
switch (index) {
-
case HV_VMBUS_IVAR_TYPE:
*result = (uintptr_t) &child_dev_ctx->class_id;
return (0);
@@ -559,14 +539,9 @@ vmbus_read_ivar(
}
static int
-vmbus_write_ivar(
- device_t dev,
- device_t child,
- int index,
- uintptr_t value)
+vmbus_write_ivar(device_t dev, device_t child, int index, uintptr_t value)
{
switch (index) {
-
case HV_VMBUS_IVAR_TYPE:
case HV_VMBUS_IVAR_INSTANCE:
case HV_VMBUS_IVAR_DEVCTX:
@@ -597,19 +572,16 @@ vmbus_child_pnpinfo_str(device_t dev, device_t child, char *buf, size_t buflen)
return (0);
}
-struct hv_device*
-hv_vmbus_child_device_create(
- hv_guid type,
- hv_guid instance,
- hv_vmbus_channel* channel)
+struct hv_device *
+hv_vmbus_child_device_create(hv_guid type, hv_guid instance,
+ hv_vmbus_channel *channel)
{
- hv_device* child_dev;
+ hv_device *child_dev;
/*
* Allocate the new child device
*/
- child_dev = malloc(sizeof(hv_device), M_DEVBUF,
- M_WAITOK | M_ZERO);
+ child_dev = malloc(sizeof(hv_device), M_DEVBUF, M_WAITOK | M_ZERO);
child_dev->channel = channel;
memcpy(&child_dev->class_id, &type, sizeof(hv_guid));
@@ -690,14 +662,12 @@ vmbus_probe(device_t dev)
static int
vmbus_bus_init(void)
{
- struct vmbus_softc *sc;
+ struct vmbus_softc *sc = vmbus_get_softc();
int ret;
- if (vmbus_inited)
+ if (sc->vmbus_flags & VMBUS_FLAG_ATTACHED)
return (0);
-
- vmbus_inited = 1;
- sc = vmbus_get_softc();
+ sc->vmbus_flags |= VMBUS_FLAG_ATTACHED;
/*
* Allocate DMA stuffs.
@@ -713,10 +683,13 @@ vmbus_bus_init(void)
if (ret != 0)
goto cleanup;
+ /*
+ * Setup SynIC.
+ */
if (bootverbose)
- printf("VMBUS: Calling smp_rendezvous, smp_started = %d\n",
- smp_started);
- smp_rendezvous(NULL, vmbus_synic_setup, NULL, NULL);
+ device_printf(sc->vmbus_dev, "smp_started = %d\n", smp_started);
+ smp_rendezvous(NULL, vmbus_synic_setup, NULL, sc);
+ sc->vmbus_flags |= VMBUS_FLAG_SYNIC;
/*
* Connect to VMBus in the root partition
@@ -802,7 +775,10 @@ vmbus_detach(device_t dev)
hv_vmbus_release_unattached_channels();
hv_vmbus_disconnect();
- smp_rendezvous(NULL, vmbus_synic_teardown, NULL, NULL);
+ if (sc->vmbus_flags & VMBUS_FLAG_SYNIC) {
+ sc->vmbus_flags &= ~VMBUS_FLAG_SYNIC;
+ smp_rendezvous(NULL, vmbus_synic_teardown, NULL, NULL);
+ }
vmbus_intr_teardown(sc);
vmbus_dma_free(sc);
diff --git a/sys/dev/hyperv/vmbus/hv_vmbus_priv.h b/sys/dev/hyperv/vmbus/hv_vmbus_priv.h
index be4c695..a1eb808 100644
--- a/sys/dev/hyperv/vmbus/hv_vmbus_priv.h
+++ b/sys/dev/hyperv/vmbus/hv_vmbus_priv.h
@@ -200,15 +200,6 @@ enum {
struct vmbus_message;
union vmbus_event_flags;
-typedef struct {
- hv_bool_uint8_t syn_ic_initialized;
-
- /*
- * For FreeBSD cpuid to Hyper-V vcpuid mapping.
- */
- uint32_t hv_vcpu_index[MAXCPU];
-} hv_vmbus_context;
-
/*
* Define hypervisor message types
*/
@@ -640,7 +631,6 @@ typedef enum {
* Global variables
*/
-extern hv_vmbus_context hv_vmbus_g_context;
extern hv_vmbus_connection hv_vmbus_g_connection;
extern u_int hyperv_features;
diff --git a/sys/dev/hyperv/vmbus/vmbus_var.h b/sys/dev/hyperv/vmbus/vmbus_var.h
index 888ff38..34a015f 100644
--- a/sys/dev/hyperv/vmbus/vmbus_var.h
+++ b/sys/dev/hyperv/vmbus/vmbus_var.h
@@ -30,12 +30,12 @@
#define _VMBUS_VAR_H_
#include <sys/param.h>
-#include <sys/bus_dma.h>
#include <dev/hyperv/include/hyperv_busdma.h>
struct vmbus_pcpu_data {
u_long *intr_cnt; /* Hyper-V interrupt counter */
struct vmbus_message *message; /* shared messages */
+ uint32_t vcpuid; /* virtual cpuid */
int event_flag_cnt; /* # of event flags */
union vmbus_event_flags *event_flag; /* shared event flags */
@@ -54,8 +54,12 @@ struct vmbus_softc {
/* Rarely used fields */
device_t vmbus_dev;
int vmbus_idtvec;
+ uint32_t vmbus_flags; /* see VMBUS_FLAG_ */
};
+#define VMBUS_FLAG_ATTACHED 0x0001 /* vmbus was attached */
+#define VMBUS_FLAG_SYNIC 0x0002 /* SynIC was setup */
+
extern struct vmbus_softc *vmbus_sc;
static __inline struct vmbus_softc *
OpenPOWER on IntegriCloud