Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 23 Jun 2016 07:53:58 +0000 (UTC)
From:      Sepherosa Ziehau <sephe@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r302127 - in stable/10/sys/dev/hyperv: include vmbus
Message-ID:  <201606230753.u5N7rwcG038183@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: sephe
Date: Thu Jun 23 07:53:58 2016
New Revision: 302127
URL: https://svnweb.freebsd.org/changeset/base/302127

Log:
  MFC 300647,300650,300651,300652,300653
  
  300647
      hyperv/vmbus: Move vcpuid into vmbus softc per-cpu data
  
      MFC after:  1 week
      Sponsored by:       Microsoft OSTC
      Differential Revision:      https://reviews.freebsd.org/D6521
  
  300650
      hyperv/vmbus: Move two global flags into vmbus softc
  
      And pack them into one flag field.
  
      MFC after:  1 week
      Sponsored by:       Microsoft OSTC
      Differential Revision:      https://reviews.freebsd.org/D6522
  
  300651
      hyperv/vmbus: Minor style and white space cleanup
  
      MFC after:  1 week
      Sponsored by:       Microsoft OSTC
      Differential Revision:      https://reviews.freebsd.org/D6523
  
  300652
      hyperv/vmbus: Pass vmbus softc to vmbus_synic_setup
  
      MFC after:  1 week
      Sponsored by:       Microsoft OSTC
      Differential Revision:      https://reviews.freebsd.org/D6527
  
  300653
      hyperv/vmbus: Nuke unnecessary MSR read
  
      MFC after:  1 week
      Sponsored by:       Microsoft OSTC
      Differential Revision:      https://reviews.freebsd.org/D6528

Modified:
  stable/10/sys/dev/hyperv/include/hyperv_busdma.h
  stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c
  stable/10/sys/dev/hyperv/vmbus/hv_hv.c
  stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c
  stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h
  stable/10/sys/dev/hyperv/vmbus/vmbus_var.h
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/dev/hyperv/include/hyperv_busdma.h
==============================================================================
--- stable/10/sys/dev/hyperv/include/hyperv_busdma.h	Thu Jun 23 07:36:03 2016	(r302126)
+++ stable/10/sys/dev/hyperv/include/hyperv_busdma.h	Thu Jun 23 07:53:58 2016	(r302127)
@@ -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;

Modified: stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c	Thu Jun 23 07:36:03 2016	(r302126)
+++ stable/10/sys/dev/hyperv/vmbus/hv_channel_mgmt.c	Thu Jun 23 07:53:58 2016	(r302127)
@@ -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_ch
 	}
 
 	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_
 		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){

Modified: stable/10/sys/dev/hyperv/vmbus/hv_hv.c
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/hv_hv.c	Thu Jun 23 07:36:03 2016	(r302126)
+++ stable/10/sys/dev/hyperv/vmbus/hv_hv.c	Thu Jun 23 07:53:58 2016	(r302127)
@@ -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
 };

Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c	Thu Jun 23 07:36:03 2016	(r302126)
+++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_drv_freebsd.c	Thu Jun 23 07:53:58 2016	(r302127)
@@ -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
 }
 
 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 *
 }
 
 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, de
 	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);

Modified: stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h	Thu Jun 23 07:36:03 2016	(r302126)
+++ stable/10/sys/dev/hyperv/vmbus/hv_vmbus_priv.h	Thu Jun 23 07:53:58 2016	(r302127)
@@ -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;

Modified: stable/10/sys/dev/hyperv/vmbus/vmbus_var.h
==============================================================================
--- stable/10/sys/dev/hyperv/vmbus/vmbus_var.h	Thu Jun 23 07:36:03 2016	(r302126)
+++ stable/10/sys/dev/hyperv/vmbus/vmbus_var.h	Thu Jun 23 07:53:58 2016	(r302127)
@@ -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 *



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