From 156b97fa1f4366966b8cb50be6e720a58e50e959 Mon Sep 17 00:00:00 2001 From: Ruslan Bukin Date: Fri, 12 Dec 2014 11:19:10 +0000 Subject: [PATCH] Add virtio bus 'poll' method allowing us to inform backend we are going to poll virtqueue. Use on BERI soft-core to invalidate cpu caches. Reviewed by: bryanv Sponsored by: DARPA, AFRL --- sys/dev/beri/virtio/virtio_mmio_platform.c | 10 ++++++++++ sys/dev/virtio/mmio/virtio_mmio.c | 13 +++++++++++++ sys/dev/virtio/mmio/virtio_mmio_if.m | 7 +++++++ sys/dev/virtio/virtio_bus_if.m | 5 +++++ sys/dev/virtio/virtqueue.c | 5 ++++- 5 files changed, 39 insertions(+), 1 deletion(-) diff --git a/sys/dev/beri/virtio/virtio_mmio_platform.c b/sys/dev/beri/virtio/virtio_mmio_platform.c index 0c58747d8b5b..86244babc448 100644 --- a/sys/dev/beri/virtio/virtio_mmio_platform.c +++ b/sys/dev/beri/virtio/virtio_mmio_platform.c @@ -234,12 +234,22 @@ platform_setup_intr(device_t dev, device_t mmio_dev, return (0); } +static int +platform_poll(device_t dev) +{ + + mips_dcache_wbinv_all(); + + return (0); +} + static device_method_t virtio_mmio_platform_methods[] = { DEVMETHOD(device_probe, virtio_mmio_platform_probe), DEVMETHOD(device_attach, virtio_mmio_platform_attach), /* virtio_mmio_if.h */ DEVMETHOD(virtio_mmio_note, platform_note), + DEVMETHOD(virtio_mmio_poll, platform_poll), DEVMETHOD(virtio_mmio_setup_intr, platform_setup_intr), DEVMETHOD_END }; diff --git a/sys/dev/virtio/mmio/virtio_mmio.c b/sys/dev/virtio/mmio/virtio_mmio.c index 5c6a0e18a4af..c41eafc9c0e1 100644 --- a/sys/dev/virtio/mmio/virtio_mmio.c +++ b/sys/dev/virtio/mmio/virtio_mmio.c @@ -114,6 +114,7 @@ static int vtmmio_alloc_virtqueues(device_t, int, int, struct vq_alloc_info *); static int vtmmio_setup_intr(device_t, enum intr_type); static void vtmmio_stop(device_t); +static void vtmmio_poll(device_t); static int vtmmio_reinit(device_t, uint64_t); static void vtmmio_reinit_complete(device_t); static void vtmmio_notify_virtqueue(device_t, uint16_t); @@ -182,6 +183,7 @@ static device_method_t vtmmio_methods[] = { DEVMETHOD(virtio_bus_alloc_virtqueues, vtmmio_alloc_virtqueues), DEVMETHOD(virtio_bus_setup_intr, vtmmio_setup_intr), DEVMETHOD(virtio_bus_stop, vtmmio_stop), + DEVMETHOD(virtio_bus_poll, vtmmio_poll), DEVMETHOD(virtio_bus_reinit, vtmmio_reinit), DEVMETHOD(virtio_bus_reinit_complete, vtmmio_reinit_complete), DEVMETHOD(virtio_bus_notify_vq, vtmmio_notify_virtqueue), @@ -550,6 +552,17 @@ vtmmio_stop(device_t dev) vtmmio_reset(device_get_softc(dev)); } +static void +vtmmio_poll(device_t dev) +{ + struct vtmmio_softc *sc; + + sc = device_get_softc(dev); + + if (sc->platform != NULL) + VIRTIO_MMIO_POLL(sc->platform); +} + static int vtmmio_reinit(device_t dev, uint64_t features) { diff --git a/sys/dev/virtio/mmio/virtio_mmio_if.m b/sys/dev/virtio/mmio/virtio_mmio_if.m index 8514c307b994..499c619c8e92 100644 --- a/sys/dev/virtio/mmio/virtio_mmio_if.m +++ b/sys/dev/virtio/mmio/virtio_mmio_if.m @@ -66,6 +66,13 @@ METHOD int note { int val; } DEFAULT virtio_mmio_note; +# +# Inform backend we are going to poll virtqueue. +# +METHOD int poll { + device_t dev; +}; + # # Setup backend-specific interrupts. # diff --git a/sys/dev/virtio/virtio_bus_if.m b/sys/dev/virtio/virtio_bus_if.m index 74341ffe3751..cbf6069d242f 100644 --- a/sys/dev/virtio/virtio_bus_if.m +++ b/sys/dev/virtio/virtio_bus_if.m @@ -87,3 +87,8 @@ METHOD void write_device_config { void *src; int len; }; + +METHOD void poll { + device_t dev; +}; + diff --git a/sys/dev/virtio/virtqueue.c b/sys/dev/virtio/virtqueue.c index 94016087f8bf..e25d39e6b5d7 100644 --- a/sys/dev/virtio/virtqueue.c +++ b/sys/dev/virtio/virtqueue.c @@ -567,8 +567,11 @@ virtqueue_poll(struct virtqueue *vq, uint32_t *len) { void *cookie; - while ((cookie = virtqueue_dequeue(vq, len)) == NULL) + VIRTIO_BUS_POLL(vq->vq_dev); + while ((cookie = virtqueue_dequeue(vq, len)) == NULL) { cpu_spinwait(); + VIRTIO_BUS_POLL(vq->vq_dev); + } return (cookie); }