From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:59244) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WB5uZ-0000oL-6w for qemu-devel@nongnu.org; Wed, 05 Feb 2014 12:05:24 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WB5uU-0005kY-Dx for qemu-devel@nongnu.org; Wed, 05 Feb 2014 12:05:19 -0500 Received: from mail-pb0-x235.google.com ([2607:f8b0:400e:c01::235]:53379) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WB5uU-0005kS-7s for qemu-devel@nongnu.org; Wed, 05 Feb 2014 12:05:14 -0500 Received: by mail-pb0-f53.google.com with SMTP id md12so610178pbc.12 for ; Wed, 05 Feb 2014 09:05:13 -0800 (PST) From: Ying-Shiuan Pan Date: Thu, 6 Feb 2014 01:03:38 +0800 Message-Id: <1391619819-10525-4-git-send-email-yingshiuan.pan@gmail.com> In-Reply-To: <1391619819-10525-1-git-send-email-yingshiuan.pan@gmail.com> References: <1391619819-10525-1-git-send-email-yingshiuan.pan@gmail.com> Subject: [Qemu-devel] [PATCH 3/4] virtio-mmio: start ioeventfd when status gets DRIVER_OK List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: wbarak@gmail.com, Ying-Shiuan Pan , yspan@itri.org.tw Signed-off-by: Ying-Shiuan Pan --- hw/virtio/virtio-mmio.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/hw/virtio/virtio-mmio.c b/hw/virtio/virtio-mmio.c index f95b7dd..11964ee 100644 --- a/hw/virtio/virtio-mmio.c +++ b/hw/virtio/virtio-mmio.c @@ -122,6 +122,42 @@ static int virtio_mmio_set_host_notifier_internal(VirtIOMMIOProxy *proxy, return r; } +static void virtio_mmio_start_ioeventfd(VirtIOMMIOProxy *proxy) +{ + VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); + int n, r; + + if (proxy->ioeventfd_disabled || + proxy->ioeventfd_started) { + return; + } + + for (n = 0; n < VIRTIO_PCI_QUEUE_MAX; n++) { + if (!virtio_queue_get_num(vdev, n)) { + continue; + } + + r = virtio_mmio_set_host_notifier_internal(proxy, n, true, true); + if (r < 0) { + goto assign_error; + } + } + proxy->ioeventfd_started = true; + return; + +assign_error: + while (--n >= 0) { + if (!virtio_queue_get_num(vdev, n)) { + continue; + } + + r = virtio_mmio_set_host_notifier_internal(proxy, n, false, false); + assert(r >= 0); + } + proxy->ioeventfd_started = false; + error_report("%s: failed. Fallback to a userspace (slower).", __func__); +} + static void virtio_mmio_stop_ioeventfd(VirtIOMMIOProxy *proxy) { int r; @@ -320,7 +356,16 @@ static void virtio_mmio_write(void *opaque, hwaddr offset, uint64_t value, virtio_update_irq(vdev); break; case VIRTIO_MMIO_STATUS: + if (!(value & VIRTIO_CONFIG_S_DRIVER_OK)) { + virtio_mmio_stop_ioeventfd(proxy); + } + virtio_set_status(vdev, value & 0xff); + + if (value & VIRTIO_CONFIG_S_DRIVER_OK) { + virtio_mmio_start_ioeventfd(proxy); + } + if (vdev->status == 0) { virtio_reset(vdev); } -- 1.8.1.2