summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorsephe <sephe@FreeBSD.org>2016-10-12 08:58:03 +0000
committersephe <sephe@FreeBSD.org>2016-10-12 08:58:03 +0000
commit7dd33f81301acec83d984e2a503c7a8b0c778bb6 (patch)
treed07d965afb563ff6e7476e14371b2a21e492b784
parenta4803967b1407528456e8f9b84a06b0b84459994 (diff)
downloadFreeBSD-src-7dd33f81301acec83d984e2a503c7a8b0c778bb6.zip
FreeBSD-src-7dd33f81301acec83d984e2a503c7a8b0c778bb6.tar.gz
MFC 303421,303422,303470-303473
303421 hyperv/vmbus: Avoid unnecessary mb() Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D7333 303422 hyperv/vmbus: Inclusion cleanup Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D7334 303470 hyperv/vmbus: Reindent function declarations. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D7344 303471 hyperv/vmbus: Forward declare static functions Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D7346 303472 hyperv/vmbus: Move driver glue to the beginning of the files Just as most of other drivers do. And move sysinit function close to its SYSINIT. Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D7347 303473 hyperv/vmbus: Revoke unnecessary exposure of vmbus softc Sponsored by: Microsoft Differential Revision: https://reviews.freebsd.org/D7348
-rw-r--r--sys/dev/hyperv/include/hyperv.h32
-rw-r--r--sys/dev/hyperv/include/hyperv_busdma.h12
-rw-r--r--sys/dev/hyperv/include/vmbus.h72
-rw-r--r--sys/dev/hyperv/netvsc/hv_net_vsc.h1
-rw-r--r--sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c1
-rw-r--r--sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c1
-rw-r--r--sys/dev/hyperv/utilities/hv_heartbeat.c1
-rw-r--r--sys/dev/hyperv/utilities/hv_shutdown.c1
-rw-r--r--sys/dev/hyperv/utilities/hv_timesync.c2
-rw-r--r--sys/dev/hyperv/vmbus/hyperv.c23
-rw-r--r--sys/dev/hyperv/vmbus/vmbus.c149
-rw-r--r--sys/dev/hyperv/vmbus/vmbus_br.c24
-rw-r--r--sys/dev/hyperv/vmbus/vmbus_chan.c44
-rw-r--r--sys/dev/hyperv/vmbus/vmbus_chanvar.h9
-rw-r--r--sys/dev/hyperv/vmbus/vmbus_et.c49
-rw-r--r--sys/dev/hyperv/vmbus/vmbus_var.h47
16 files changed, 229 insertions, 239 deletions
diff --git a/sys/dev/hyperv/include/hyperv.h b/sys/dev/hyperv/include/hyperv.h
index a502a64..f356856 100644
--- a/sys/dev/hyperv/include/hyperv.h
+++ b/sys/dev/hyperv/include/hyperv.h
@@ -28,43 +28,21 @@
* $FreeBSD$
*/
-/**
- * HyperV definitions for messages that are sent between instances of the
- * Channel Management Library in separate partitions, or in some cases,
- * back to itself.
- */
-
-#ifndef __HYPERV_H__
-#define __HYPERV_H__
+#ifndef _HYPERV_H_
+#define _HYPERV_H_
#include <sys/param.h>
-#include <sys/mbuf.h>
-#include <sys/queue.h>
-#include <sys/malloc.h>
-#include <sys/kthread.h>
-#include <sys/taskqueue.h>
-#include <sys/systm.h>
-#include <sys/lock.h>
-#include <sys/sema.h>
-#include <sys/smp.h>
-#include <sys/mutex.h>
-#include <sys/bus.h>
-#include <sys/sysctl.h>
+
#include <vm/vm.h>
-#include <vm/vm_param.h>
#include <vm/pmap.h>
-#include <amd64/include/xen/synch_bitops.h>
-#include <amd64/include/atomic.h>
-#include <dev/hyperv/include/hyperv_busdma.h>
-
struct hyperv_guid {
uint8_t hv_guid[16];
} __packed;
#define HYPERV_GUID_STRLEN 40
-int hyperv_guid2str(const struct hyperv_guid *, char *, size_t);
+int hyperv_guid2str(const struct hyperv_guid *, char *, size_t);
/**
* @brief Get physical address from virtual
@@ -77,4 +55,4 @@ hv_get_phys_addr(void *virt)
return (ret);
}
-#endif /* __HYPERV_H__ */
+#endif /* _HYPERV_H_ */
diff --git a/sys/dev/hyperv/include/hyperv_busdma.h b/sys/dev/hyperv/include/hyperv_busdma.h
index a27d2db..ff01b3e 100644
--- a/sys/dev/hyperv/include/hyperv_busdma.h
+++ b/sys/dev/hyperv/include/hyperv_busdma.h
@@ -39,11 +39,11 @@ struct hyperv_dma {
bus_dmamap_t hv_dmap;
};
-void hyperv_dma_map_paddr(void *arg, bus_dma_segment_t *segs, int nseg,
- int error);
-void *hyperv_dmamem_alloc(bus_dma_tag_t parent_dtag, bus_size_t alignment,
- bus_addr_t boundary, bus_size_t size, struct hyperv_dma *dma,
- int flags);
-void hyperv_dmamem_free(struct hyperv_dma *dma, void *ptr);
+void hyperv_dma_map_paddr(void *arg, bus_dma_segment_t *segs,
+ int nseg, int error);
+void *hyperv_dmamem_alloc(bus_dma_tag_t parent_dtag,
+ bus_size_t alignment, bus_addr_t boundary, bus_size_t size,
+ struct hyperv_dma *dma, int flags);
+void hyperv_dmamem_free(struct hyperv_dma *dma, void *ptr);
#endif /* !_HYPERV_BUSDMA_H_ */
diff --git a/sys/dev/hyperv/include/vmbus.h b/sys/dev/hyperv/include/vmbus.h
index 7c06580..47b7985 100644
--- a/sys/dev/hyperv/include/vmbus.h
+++ b/sys/dev/hyperv/include/vmbus.h
@@ -30,6 +30,8 @@
#define _VMBUS_H_
#include <sys/param.h>
+#include <sys/bus.h>
+#include <machine/bus.h>
/*
* VMBUS version is 32 bit, upper 16 bit for major_number and lower
@@ -115,45 +117,47 @@ vmbus_get_channel(device_t dev)
return device_get_ivars(dev);
}
-int vmbus_chan_open(struct vmbus_channel *chan,
- int txbr_size, int rxbr_size, const void *udata, int udlen,
- vmbus_chan_callback_t cb, void *cbarg);
-void vmbus_chan_close(struct vmbus_channel *chan);
+int vmbus_chan_open(struct vmbus_channel *chan,
+ int txbr_size, int rxbr_size, const void *udata, int udlen,
+ vmbus_chan_callback_t cb, void *cbarg);
+void vmbus_chan_close(struct vmbus_channel *chan);
-int vmbus_chan_gpadl_connect(struct vmbus_channel *chan,
- bus_addr_t paddr, int size, uint32_t *gpadl);
-int vmbus_chan_gpadl_disconnect(struct vmbus_channel *chan,
- uint32_t gpadl);
+int vmbus_chan_gpadl_connect(struct vmbus_channel *chan,
+ bus_addr_t paddr, int size, uint32_t *gpadl);
+int vmbus_chan_gpadl_disconnect(struct vmbus_channel *chan,
+ uint32_t gpadl);
-void vmbus_chan_cpu_set(struct vmbus_channel *chan, int cpu);
-void vmbus_chan_cpu_rr(struct vmbus_channel *chan);
+void vmbus_chan_cpu_set(struct vmbus_channel *chan, int cpu);
+void vmbus_chan_cpu_rr(struct vmbus_channel *chan);
struct vmbus_channel *
- vmbus_chan_cpu2chan(struct vmbus_channel *chan, int cpu);
-void vmbus_chan_set_readbatch(struct vmbus_channel *chan, bool on);
+ vmbus_chan_cpu2chan(struct vmbus_channel *chan, int cpu);
+void vmbus_chan_set_readbatch(struct vmbus_channel *chan, bool on);
struct vmbus_channel **
- vmbus_subchan_get(struct vmbus_channel *pri_chan, int subchan_cnt);
-void vmbus_subchan_rel(struct vmbus_channel **subchan, int subchan_cnt);
-void vmbus_subchan_drain(struct vmbus_channel *pri_chan);
-
-int vmbus_chan_recv(struct vmbus_channel *chan, void *data, int *dlen,
- uint64_t *xactid);
-int vmbus_chan_recv_pkt(struct vmbus_channel *chan,
- struct vmbus_chanpkt_hdr *pkt, int *pktlen);
-
-int vmbus_chan_send(struct vmbus_channel *chan, uint16_t type,
- uint16_t flags, void *data, int dlen, uint64_t xactid);
-int vmbus_chan_send_sglist(struct vmbus_channel *chan,
- struct vmbus_gpa sg[], int sglen, void *data, int dlen,
- uint64_t xactid);
-int vmbus_chan_send_prplist(struct vmbus_channel *chan,
- struct vmbus_gpa_range *prp, int prp_cnt, void *data, int dlen,
- uint64_t xactid);
-
-uint32_t vmbus_chan_id(const struct vmbus_channel *chan);
-uint32_t vmbus_chan_subidx(const struct vmbus_channel *chan);
-bool vmbus_chan_is_primary(const struct vmbus_channel *chan);
+ vmbus_subchan_get(struct vmbus_channel *pri_chan,
+ int subchan_cnt);
+void vmbus_subchan_rel(struct vmbus_channel **subchan,
+ int subchan_cnt);
+void vmbus_subchan_drain(struct vmbus_channel *pri_chan);
+
+int vmbus_chan_recv(struct vmbus_channel *chan, void *data, int *dlen,
+ uint64_t *xactid);
+int vmbus_chan_recv_pkt(struct vmbus_channel *chan,
+ struct vmbus_chanpkt_hdr *pkt, int *pktlen);
+
+int vmbus_chan_send(struct vmbus_channel *chan, uint16_t type,
+ uint16_t flags, void *data, int dlen, uint64_t xactid);
+int vmbus_chan_send_sglist(struct vmbus_channel *chan,
+ struct vmbus_gpa sg[], int sglen, void *data, int dlen,
+ uint64_t xactid);
+int vmbus_chan_send_prplist(struct vmbus_channel *chan,
+ struct vmbus_gpa_range *prp, int prp_cnt, void *data,
+ int dlen, uint64_t xactid);
+
+uint32_t vmbus_chan_id(const struct vmbus_channel *chan);
+uint32_t vmbus_chan_subidx(const struct vmbus_channel *chan);
+bool vmbus_chan_is_primary(const struct vmbus_channel *chan);
const struct hyperv_guid *
- vmbus_chan_guid_inst(const struct vmbus_channel *chan);
+ vmbus_chan_guid_inst(const struct vmbus_channel *chan);
#endif /* !_VMBUS_H_ */
diff --git a/sys/dev/hyperv/netvsc/hv_net_vsc.h b/sys/dev/hyperv/netvsc/hv_net_vsc.h
index eabbfcb..69d81c2 100644
--- a/sys/dev/hyperv/netvsc/hv_net_vsc.h
+++ b/sys/dev/hyperv/netvsc/hv_net_vsc.h
@@ -44,6 +44,7 @@
#include <sys/malloc.h>
#include <sys/queue.h>
#include <sys/taskqueue.h>
+#include <sys/sema.h>
#include <sys/sx.h>
#include <machine/bus.h>
diff --git a/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c b/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c
index d26aeac..0b94e20 100644
--- a/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c
+++ b/sys/dev/hyperv/netvsc/hv_netvsc_drv_freebsd.c
@@ -70,6 +70,7 @@ __FBSDID("$FreeBSD$");
#include <sys/queue.h>
#include <sys/lock.h>
#include <sys/sx.h>
+#include <sys/smp.h>
#include <sys/sysctl.h>
#include <sys/buf_ring.h>
diff --git a/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c b/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c
index 3518e4c..5667721 100644
--- a/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c
+++ b/sys/dev/hyperv/storvsc/hv_storvsc_drv_freebsd.c
@@ -52,6 +52,7 @@ __FBSDID("$FreeBSD$");
#include <sys/bus.h>
#include <sys/mutex.h>
#include <sys/callout.h>
+#include <sys/smp.h>
#include <vm/vm.h>
#include <vm/pmap.h>
#include <vm/uma.h>
diff --git a/sys/dev/hyperv/utilities/hv_heartbeat.c b/sys/dev/hyperv/utilities/hv_heartbeat.c
index 46493ee..be0f3e6 100644
--- a/sys/dev/hyperv/utilities/hv_heartbeat.c
+++ b/sys/dev/hyperv/utilities/hv_heartbeat.c
@@ -33,6 +33,7 @@
#include <sys/module.h>
#include <sys/timetc.h>
#include <sys/syscallsubr.h>
+#include <sys/systm.h>
#include <dev/hyperv/include/hyperv.h>
#include <dev/hyperv/include/vmbus.h>
diff --git a/sys/dev/hyperv/utilities/hv_shutdown.c b/sys/dev/hyperv/utilities/hv_shutdown.c
index 44c1916..352df91 100644
--- a/sys/dev/hyperv/utilities/hv_shutdown.c
+++ b/sys/dev/hyperv/utilities/hv_shutdown.c
@@ -38,6 +38,7 @@
#include <sys/reboot.h>
#include <sys/timetc.h>
#include <sys/syscallsubr.h>
+#include <sys/systm.h>
#include <dev/hyperv/include/hyperv.h>
#include <dev/hyperv/include/vmbus.h>
diff --git a/sys/dev/hyperv/utilities/hv_timesync.c b/sys/dev/hyperv/utilities/hv_timesync.c
index b46e4c7..7ac4fb6 100644
--- a/sys/dev/hyperv/utilities/hv_timesync.c
+++ b/sys/dev/hyperv/utilities/hv_timesync.c
@@ -38,6 +38,8 @@
#include <sys/reboot.h>
#include <sys/timetc.h>
#include <sys/syscallsubr.h>
+#include <sys/systm.h>
+#include <sys/taskqueue.h>
#include <dev/hyperv/include/hyperv.h>
#include <dev/hyperv/include/vmbus.h>
diff --git a/sys/dev/hyperv/vmbus/hyperv.c b/sys/dev/hyperv/vmbus/hyperv.c
index 02cde9d..2df313b 100644
--- a/sys/dev/hyperv/vmbus/hyperv.c
+++ b/sys/dev/hyperv/vmbus/hyperv.c
@@ -34,23 +34,14 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/kernel.h>
-#include <sys/malloc.h>
-#include <sys/pcpu.h>
+#include <sys/systm.h>
#include <sys/timetc.h>
-#include <machine/bus.h>
-#include <machine/md_var.h>
-#include <vm/vm.h>
-#include <vm/vm_param.h>
-#include <vm/pmap.h>
#include <dev/hyperv/include/hyperv.h>
#include <dev/hyperv/include/hyperv_busdma.h>
#include <dev/hyperv/vmbus/hyperv_machdep.h>
#include <dev/hyperv/vmbus/hyperv_reg.h>
#include <dev/hyperv/vmbus/hyperv_var.h>
-#if 0
-#include <dev/hyperv/vmbus/vmbus_var.h>
-#endif
#define HYPERV_FREEBSD_BUILD 0ULL
#define HYPERV_FREEBSD_VERSION ((uint64_t)__FreeBSD_version)
@@ -76,13 +67,15 @@ struct hypercall_ctx {
struct hyperv_dma hc_dma;
};
-static u_int hyperv_get_timecount(struct timecounter *tc);
+static u_int hyperv_get_timecount(struct timecounter *);
+static bool hyperv_identify(void);
+static void hypercall_memfree(void);
-u_int hyperv_features;
-u_int hyperv_recommends;
+u_int hyperv_features;
+u_int hyperv_recommends;
-static u_int hyperv_pm_features;
-static u_int hyperv_features3;
+static u_int hyperv_pm_features;
+static u_int hyperv_features3;
static struct timecounter hyperv_timecounter = {
.tc_get_timecount = hyperv_get_timecount,
diff --git a/sys/dev/hyperv/vmbus/vmbus.c b/sys/dev/hyperv/vmbus/vmbus.c
index 13befd4..27e72fe 100644
--- a/sys/dev/hyperv/vmbus/vmbus.c
+++ b/sys/dev/hyperv/vmbus/vmbus.c
@@ -38,26 +38,18 @@ __FBSDID("$FreeBSD$");
#include <sys/lock.h>
#include <sys/malloc.h>
#include <sys/module.h>
+#include <sys/mutex.h>
#include <sys/proc.h>
+#include <sys/smp.h>
#include <sys/sysctl.h>
-#include <sys/syslog.h>
#include <sys/systm.h>
-#include <sys/rtprio.h>
-#include <sys/interrupt.h>
-#include <sys/sx.h>
#include <sys/taskqueue.h>
-#include <sys/mutex.h>
-#include <sys/smp.h>
-#include <machine/resource.h>
-#include <sys/rman.h>
-
-#include <machine/stdarg.h>
#include <machine/intr_machdep.h>
-#include <machine/md_var.h>
-#include <machine/segments.h>
-#include <sys/pcpu.h>
#include <machine/apicvar.h>
+#include <machine/md_var.h>
+
+#include <contrib/dev/acpica/include/acpi.h>
#include <dev/hyperv/include/hyperv.h>
#include <dev/hyperv/vmbus/hyperv_reg.h>
@@ -66,7 +58,6 @@ __FBSDID("$FreeBSD$");
#include <dev/hyperv/vmbus/vmbus_var.h>
#include <dev/hyperv/vmbus/vmbus_chanvar.h>
-#include <contrib/dev/acpica/include/acpi.h>
#include "acpi_if.h"
#include "vmbus_if.h"
@@ -92,6 +83,17 @@ struct vmbus_msghc_ctx {
#define VMBUS_MSGHC_CTXF_DESTROY 0x0001
+static int vmbus_probe(device_t);
+static int vmbus_attach(device_t);
+static int vmbus_detach(device_t);
+static int vmbus_read_ivar(device_t, device_t, int,
+ uintptr_t *);
+static int vmbus_child_pnpinfo_str(device_t, device_t,
+ char *, size_t);
+static uint32_t vmbus_get_version_method(device_t, device_t);
+static int vmbus_probe_guid_method(device_t, device_t,
+ const struct hyperv_guid *);
+
static int vmbus_init(struct vmbus_softc *);
static int vmbus_connect(struct vmbus_softc *, uint32_t);
static int vmbus_req_channels(struct vmbus_softc *sc);
@@ -104,8 +106,17 @@ static void vmbus_scan_done(struct vmbus_softc *,
const struct vmbus_message *);
static void vmbus_chanmsg_handle(struct vmbus_softc *,
const struct vmbus_message *);
-
+static void vmbus_msg_task(void *, int);
+static void vmbus_synic_setup(void *);
+static void vmbus_synic_teardown(void *);
static int vmbus_sysctl_version(SYSCTL_HANDLER_ARGS);
+static int vmbus_dma_alloc(struct vmbus_softc *);
+static void vmbus_dma_free(struct vmbus_softc *);
+static int vmbus_intr_setup(struct vmbus_softc *);
+static void vmbus_intr_teardown(struct vmbus_softc *);
+static int vmbus_doattach(struct vmbus_softc *);
+static void vmbus_event_proc_dummy(struct vmbus_softc *,
+ int);
static struct vmbus_msghc_ctx *vmbus_msghc_ctx_create(bus_dma_tag_t);
static void vmbus_msghc_ctx_destroy(
@@ -116,7 +127,7 @@ static void vmbus_msghc_free(struct vmbus_msghc *);
static struct vmbus_msghc *vmbus_msghc_get1(struct vmbus_msghc_ctx *,
uint32_t);
-struct vmbus_softc *vmbus_sc;
+static struct vmbus_softc *vmbus_sc;
extern inthand_t IDTVEC(rsvd), IDTVEC(vmbus_isr);
@@ -133,6 +144,46 @@ vmbus_chanmsg_handlers[VMBUS_CHANMSG_TYPE_MAX] = {
VMBUS_CHANMSG_PROC_WAKEUP(CONNECT_RESP)
};
+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_child_pnpinfo_str, vmbus_child_pnpinfo_str),
+
+ /* Vmbus interface */
+ DEVMETHOD(vmbus_get_version, vmbus_get_version_method),
+ DEVMETHOD(vmbus_probe_guid, vmbus_probe_guid_method),
+
+ DEVMETHOD_END
+};
+
+static driver_t vmbus_driver = {
+ "vmbus",
+ vmbus_methods,
+ sizeof(struct vmbus_softc)
+};
+
+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);
+
+static __inline struct vmbus_softc *
+vmbus_get_softc(void)
+{
+ return vmbus_sc;
+}
+
static struct vmbus_msghc *
vmbus_msghc_alloc(bus_dma_tag_t parent_dtag)
{
@@ -1316,24 +1367,6 @@ vmbus_attach(device_t dev)
return (0);
}
-static void
-vmbus_sysinit(void *arg __unused)
-{
- struct vmbus_softc *sc = vmbus_get_softc();
-
- if (vm_guest != VM_GUEST_HV || sc == NULL)
- return;
-
- /*
- * If the system has already booted and thread
- * scheduling is possible, as indicated by the
- * global cold set to zero, we just call the driver
- * initialization directly.
- */
- if (!cold)
- vmbus_doattach(sc);
-}
-
static int
vmbus_detach(device_t dev)
{
@@ -1363,44 +1396,26 @@ vmbus_detach(device_t dev)
return (0);
}
-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_child_pnpinfo_str, vmbus_child_pnpinfo_str),
-
- /* Vmbus interface */
- DEVMETHOD(vmbus_get_version, vmbus_get_version_method),
- DEVMETHOD(vmbus_probe_guid, vmbus_probe_guid_method),
-
- DEVMETHOD_END
-};
-
-static driver_t vmbus_driver = {
- "vmbus",
- vmbus_methods,
- sizeof(struct vmbus_softc)
-};
-
-static devclass_t vmbus_devclass;
+static void
+vmbus_sysinit(void *arg __unused)
+{
+ struct vmbus_softc *sc = vmbus_get_softc();
-DRIVER_MODULE(vmbus, acpi, vmbus_driver, vmbus_devclass, NULL, NULL);
-MODULE_DEPEND(vmbus, acpi, 1, 1, 1);
-MODULE_VERSION(vmbus, 1);
+ if (vm_guest != VM_GUEST_HV || sc == NULL)
+ return;
+ /*
+ * If the system has already booted and thread
+ * scheduling is possible, as indicated by the
+ * global cold set to zero, we just call the driver
+ * initialization directly.
+ */
+ if (!cold)
+ vmbus_doattach(sc);
+}
/*
* 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/vmbus_br.c b/sys/dev/hyperv/vmbus/vmbus_br.c
index 95ba553..d9bd787 100644
--- a/sys/dev/hyperv/vmbus/vmbus_br.c
+++ b/sys/dev/hyperv/vmbus/vmbus_br.c
@@ -44,6 +44,10 @@ __FBSDID("$FreeBSD$");
/* Increase bufing index */
#define VMBUS_BR_IDXINC(idx, inc, sz) (((idx) + (inc)) % (sz))
+static int vmbus_br_sysctl_state(SYSCTL_HANDLER_ARGS);
+static int vmbus_br_sysctl_state_bin(SYSCTL_HANDLER_ARGS);
+static void vmbus_br_setup(struct vmbus_br *, void *, int);
+
static int
vmbus_br_sysctl_state(SYSCTL_HANDLER_ARGS)
{
@@ -212,9 +216,7 @@ vmbus_txbr_need_signal(const struct vmbus_txbr *tbr, uint32_t old_windex)
if (tbr->txbr_imask)
return (FALSE);
- /* XXX only compiler fence is needed */
- /* Read memory barrier */
- rmb();
+ __compiler_membar();
/*
* This is the only case we need to signal when the
@@ -311,15 +313,10 @@ vmbus_txbr_write(struct vmbus_txbr *tbr, const struct iovec iov[], int iovlen,
sizeof(save_windex));
/*
- * XXX only compiler fence is needed.
- * Full memory barrier before upding the write index.
- */
- mb();
-
- /*
* Update the write index _after_ the channel packet
* is copied.
*/
+ __compiler_membar();
tbr->txbr_windex = windex;
mtx_unlock_spin(&tbr->txbr_lock);
@@ -399,16 +396,9 @@ vmbus_rxbr_read(struct vmbus_rxbr *rbr, void *data, int dlen, uint32_t skip)
rindex = VMBUS_BR_IDXINC(rindex, sizeof(uint64_t), br_dsize);
/*
- * XXX only compiler fence is needed.
- * Make sure all reads are done before we update the read index since
- * the writer may start writing to the read area once the read index
- * is updated.
- */
- wmb();
-
- /*
* Update the read index _after_ the channel packet is fetched.
*/
+ __compiler_membar();
rbr->rxbr_rindex = rindex;
mtx_unlock_spin(&rbr->rxbr_lock);
diff --git a/sys/dev/hyperv/vmbus/vmbus_chan.c b/sys/dev/hyperv/vmbus/vmbus_chan.c
index a163d43..a763547 100644
--- a/sys/dev/hyperv/vmbus/vmbus_chan.c
+++ b/sys/dev/hyperv/vmbus/vmbus_chan.c
@@ -31,19 +31,14 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/kernel.h>
-#include <sys/malloc.h>
-#include <sys/systm.h>
-#include <sys/mbuf.h>
#include <sys/lock.h>
+#include <sys/malloc.h>
#include <sys/mutex.h>
+#include <sys/smp.h>
#include <sys/sysctl.h>
+#include <sys/systm.h>
#include <machine/atomic.h>
-#include <machine/bus.h>
-
-#include <vm/vm.h>
-#include <vm/vm_param.h>
-#include <vm/pmap.h>
#include <dev/hyperv/include/hyperv_busdma.h>
#include <dev/hyperv/vmbus/hyperv_var.h>
@@ -52,17 +47,28 @@ __FBSDID("$FreeBSD$");
#include <dev/hyperv/vmbus/vmbus_brvar.h>
#include <dev/hyperv/vmbus/vmbus_chanvar.h>
-static void vmbus_chan_update_evtflagcnt(struct vmbus_softc *,
- const struct vmbus_channel *);
-
-static void vmbus_chan_task(void *, int);
-static void vmbus_chan_task_nobatch(void *, int);
-static void vmbus_chan_detach_task(void *, int);
-
-static void vmbus_chan_msgproc_choffer(struct vmbus_softc *,
- const struct vmbus_message *);
-static void vmbus_chan_msgproc_chrescind(struct vmbus_softc *,
- const struct vmbus_message *);
+static void vmbus_chan_update_evtflagcnt(
+ struct vmbus_softc *,
+ const struct vmbus_channel *);
+static void vmbus_chan_close_internal(
+ struct vmbus_channel *);
+static int vmbus_chan_sysctl_mnf(SYSCTL_HANDLER_ARGS);
+static void vmbus_chan_sysctl_create(
+ struct vmbus_channel *);
+static struct vmbus_channel *vmbus_chan_alloc(struct vmbus_softc *);
+static void vmbus_chan_free(struct vmbus_channel *);
+static int vmbus_chan_add(struct vmbus_channel *);
+static void vmbus_chan_cpu_default(struct vmbus_channel *);
+
+static void vmbus_chan_task(void *, int);
+static void vmbus_chan_task_nobatch(void *, int);
+static void vmbus_chan_detach_task(void *, int);
+
+static void vmbus_chan_msgproc_choffer(struct vmbus_softc *,
+ const struct vmbus_message *);
+static void vmbus_chan_msgproc_chrescind(
+ struct vmbus_softc *,
+ const struct vmbus_message *);
/*
* Vmbus channel message processing.
diff --git a/sys/dev/hyperv/vmbus/vmbus_chanvar.h b/sys/dev/hyperv/vmbus/vmbus_chanvar.h
index 3f128b4..68a134d3 100644
--- a/sys/dev/hyperv/vmbus/vmbus_chanvar.h
+++ b/sys/dev/hyperv/vmbus/vmbus_chanvar.h
@@ -155,9 +155,10 @@ struct vmbus_channel {
struct vmbus_softc;
struct vmbus_message;
-void vmbus_event_proc(struct vmbus_softc *, int);
-void vmbus_event_proc_compat(struct vmbus_softc *, int);
-void vmbus_chan_msgproc(struct vmbus_softc *, const struct vmbus_message *);
-void vmbus_chan_destroy_all(struct vmbus_softc *);
+void vmbus_event_proc(struct vmbus_softc *, int);
+void vmbus_event_proc_compat(struct vmbus_softc *, int);
+void vmbus_chan_msgproc(struct vmbus_softc *,
+ const struct vmbus_message *);
+void vmbus_chan_destroy_all(struct vmbus_softc *);
#endif /* !_VMBUS_CHANVAR_H_ */
diff --git a/sys/dev/hyperv/vmbus/vmbus_et.c b/sys/dev/hyperv/vmbus/vmbus_et.c
index 391fa1f..77d31c8 100644
--- a/sys/dev/hyperv/vmbus/vmbus_et.c
+++ b/sys/dev/hyperv/vmbus/vmbus_et.c
@@ -32,9 +32,8 @@ __FBSDID("$FreeBSD$");
#include <sys/kernel.h>
#include <sys/module.h>
#include <sys/proc.h>
-#include <sys/systm.h>
#include <sys/smp.h>
-#include <sys/time.h>
+#include <sys/systm.h>
#include <sys/timeet.h>
#include <machine/cpu.h>
@@ -59,8 +58,35 @@ __FBSDID("$FreeBSD$");
CPUID_HV_MSR_SYNIC | \
CPUID_HV_MSR_SYNTIMER)
+static void vmbus_et_identify(driver_t *, device_t);
+static int vmbus_et_probe(device_t);
+static int vmbus_et_attach(device_t);
+static int vmbus_et_detach(device_t);
+static int vmbus_et_start(struct eventtimer *, sbintime_t,
+ sbintime_t);
+
static struct eventtimer vmbus_et;
+static device_method_t vmbus_et_methods[] = {
+ DEVMETHOD(device_identify, vmbus_et_identify),
+ DEVMETHOD(device_probe, vmbus_et_probe),
+ DEVMETHOD(device_attach, vmbus_et_attach),
+ DEVMETHOD(device_detach, vmbus_et_detach),
+
+ DEVMETHOD_END
+};
+
+static driver_t vmbus_et_driver = {
+ VMBUS_ET_NAME,
+ vmbus_et_methods,
+ 0
+};
+
+static devclass_t vmbus_et_devclass;
+
+DRIVER_MODULE(hv_et, vmbus, vmbus_et_driver, vmbus_et_devclass, NULL, NULL);
+MODULE_VERSION(hv_et, 1);
+
static __inline uint64_t
hyperv_sbintime2count(sbintime_t time)
{
@@ -177,22 +203,3 @@ vmbus_et_detach(device_t dev)
{
return (et_deregister(&vmbus_et));
}
-
-static device_method_t vmbus_et_methods[] = {
- DEVMETHOD(device_identify, vmbus_et_identify),
- DEVMETHOD(device_probe, vmbus_et_probe),
- DEVMETHOD(device_attach, vmbus_et_attach),
- DEVMETHOD(device_detach, vmbus_et_detach),
-
- DEVMETHOD_END
-};
-
-static driver_t vmbus_et_driver = {
- VMBUS_ET_NAME,
- vmbus_et_methods,
- 0
-};
-
-static devclass_t vmbus_et_devclass;
-DRIVER_MODULE(hv_et, vmbus, vmbus_et_driver, vmbus_et_devclass, NULL, NULL);
-MODULE_VERSION(hv_et, 1);
diff --git a/sys/dev/hyperv/vmbus/vmbus_var.h b/sys/dev/hyperv/vmbus/vmbus_var.h
index 794b339..c278c15 100644
--- a/sys/dev/hyperv/vmbus/vmbus_var.h
+++ b/sys/dev/hyperv/vmbus/vmbus_var.h
@@ -120,20 +120,6 @@ struct vmbus_softc {
#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 *
-vmbus_get_softc(void)
-{
- return vmbus_sc;
-}
-
-static __inline device_t
-vmbus_get_device(void)
-{
- return vmbus_sc->vmbus_dev;
-}
-
#define VMBUS_PCPU_GET(sc, field, cpu) (sc)->vmbus_pcpu[(cpu)].field
#define VMBUS_PCPU_PTR(sc, field, cpu) &(sc)->vmbus_pcpu[(cpu)].field
@@ -142,20 +128,23 @@ struct trapframe;
struct vmbus_message;
struct vmbus_msghc;
-void vmbus_handle_intr(struct trapframe *);
-int vmbus_add_child(struct vmbus_channel *);
-int vmbus_delete_child(struct vmbus_channel *);
-void vmbus_et_intr(struct trapframe *);
-uint32_t vmbus_gpadl_alloc(struct vmbus_softc *);
-
-struct vmbus_msghc *vmbus_msghc_get(struct vmbus_softc *, size_t);
-void vmbus_msghc_put(struct vmbus_softc *, struct vmbus_msghc *);
-void *vmbus_msghc_dataptr(struct vmbus_msghc *);
-int vmbus_msghc_exec_noresult(struct vmbus_msghc *);
-int vmbus_msghc_exec(struct vmbus_softc *, struct vmbus_msghc *);
-const struct vmbus_message *vmbus_msghc_wait_result(struct vmbus_softc *,
- struct vmbus_msghc *);
-void vmbus_msghc_wakeup(struct vmbus_softc *, const struct vmbus_message *);
-void vmbus_msghc_reset(struct vmbus_msghc *, size_t);
+void vmbus_handle_intr(struct trapframe *);
+int vmbus_add_child(struct vmbus_channel *);
+int vmbus_delete_child(struct vmbus_channel *);
+void vmbus_et_intr(struct trapframe *);
+uint32_t vmbus_gpadl_alloc(struct vmbus_softc *);
+
+struct vmbus_msghc *
+ vmbus_msghc_get(struct vmbus_softc *, size_t);
+void vmbus_msghc_put(struct vmbus_softc *, struct vmbus_msghc *);
+void *vmbus_msghc_dataptr(struct vmbus_msghc *);
+int vmbus_msghc_exec_noresult(struct vmbus_msghc *);
+int vmbus_msghc_exec(struct vmbus_softc *, struct vmbus_msghc *);
+const struct vmbus_message *
+ vmbus_msghc_wait_result(struct vmbus_softc *,
+ struct vmbus_msghc *);
+void vmbus_msghc_wakeup(struct vmbus_softc *,
+ const struct vmbus_message *);
+void vmbus_msghc_reset(struct vmbus_msghc *, size_t);
#endif /* !_VMBUS_VAR_H_ */
OpenPOWER on IntegriCloud