From: Dongli Zhang <dongli.zhang@oracle.com>
To: qemu-block@nongnu.org, qemu-devel@nongnu.org
Cc: kwolf@redhat.com, fam@euphon.net, berrange@redhat.com,
ehabkost@redhat.com, mst@redhat.com, jasowang@redhat.com,
joe.jin@oracle.com, armbru@redhat.com, dgilbert@redhat.com,
stefanha@redhat.com, pbonzini@redhat.com, mreitz@redhat.com
Subject: [PATCH 2/6] virtio: introduce helper function for kick/call device event
Date: Thu, 25 Mar 2021 22:44:29 -0700 [thread overview]
Message-ID: <20210326054433.11762-3-dongli.zhang@oracle.com> (raw)
In-Reply-To: <20210326054433.11762-1-dongli.zhang@oracle.com>
This is to introduce the helper function for virtio device to kick or
call.
Signed-off-by: Dongli Zhang <dongli.zhang@oracle.com>
---
hw/virtio/virtio.c | 64 ++++++++++++++++++++++++++++++++++++++
include/hw/virtio/virtio.h | 3 ++
2 files changed, 67 insertions(+)
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 07f4e60b30..e081041a75 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -30,6 +30,8 @@
#include "sysemu/runstate.h"
#include "standard-headers/linux/virtio_ids.h"
+/* #define DEBUG_VIRTIO_EVENT */
+
/*
* The alignment to use between consumer and producer parts of vring.
* x86 pagesize again. This is the default, used by transports like PCI
@@ -2572,6 +2574,68 @@ void virtio_notify(VirtIODevice *vdev, VirtQueue *vq)
virtio_irq(vq);
}
+static void virtio_device_event_call(VirtQueue *vq, bool eventfd,
+ Error **errp)
+{
+#ifdef DEBUG_VIRTIO_EVENT
+ printf("The 'call' event is triggered for path=%s, queue=%d, irqfd=%d.\n",
+ object_get_canonical_path(OBJECT(vq->vdev)),
+ vq->queue_index, eventfd);
+#endif
+
+ if (eventfd) {
+ virtio_set_isr(vq->vdev, 0x1);
+ event_notifier_set(&vq->guest_notifier);
+ } else {
+ virtio_irq(vq);
+ }
+}
+
+static void virtio_device_event_kick(VirtQueue *vq, bool eventfd,
+ Error **errp)
+{
+#ifdef DEBUG_VIRTIO_EVENT
+ printf("The 'kick' event is triggered for path=%s, queue=%d.\n",
+ object_get_canonical_path(OBJECT(vq->vdev)), vq->queue_index);
+#endif
+
+ virtio_queue_notify(vq->vdev, virtio_get_queue_index(vq));
+}
+
+typedef void (VirtIOEvent)(VirtQueue *vq, bool eventfd, Error **errp);
+
+static VirtIOEvent *virtio_event_funcs[DEVICE_EVENT_MAX] = {
+ [DEVICE_EVENT_CALL] = virtio_device_event_call,
+ [DEVICE_EVENT_KICK] = virtio_device_event_kick
+};
+
+void virtio_device_event(DeviceState *dev, int event, int queue,
+ bool eventfd, Error **errp)
+{
+ struct VirtIODevice *vdev = VIRTIO_DEVICE(dev);
+ int num = virtio_get_num_queues(vdev);
+ VirtQueue *vq;
+
+ assert(event < DEVICE_EVENT_MAX);
+
+ if (vdev->broken) {
+ error_setg(errp, "Broken device");
+ return;
+ }
+
+ if (queue < 0 || queue >= num) {
+ error_setg(errp, "Invalid queue %d", queue);
+ return;
+ }
+
+ vq = &vdev->vq[queue];
+
+ if (virtio_event_funcs[event])
+ virtio_event_funcs[event](vq, eventfd, errp);
+ else
+ error_setg(errp, "The event is not supported");
+}
+
void virtio_notify_config(VirtIODevice *vdev)
{
if (!(vdev->status & VIRTIO_CONFIG_S_DRIVER_OK))
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index b7ece7a6a8..21bb13ffa6 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -210,6 +210,9 @@ void virtqueue_get_avail_bytes(VirtQueue *vq, unsigned int *in_bytes,
void virtio_notify_irqfd(VirtIODevice *vdev, VirtQueue *vq);
void virtio_notify(VirtIODevice *vdev, VirtQueue *vq);
+void virtio_device_event(DeviceState *dev, int event, int queue,
+ bool eventfd, Error **errp);
+
int virtio_save(VirtIODevice *vdev, QEMUFile *f);
extern const VMStateInfo virtio_vmstate_info;
--
2.17.1
next prev parent reply other threads:[~2021-03-26 5:47 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-26 5:44 [PATCH 0/6] Add debug interface to kick/call on purpose Dongli Zhang
2021-03-26 5:44 ` [PATCH 1/6] qdev: introduce qapi/hmp command for kick/call event Dongli Zhang
2021-04-07 13:40 ` Eduardo Habkost
2021-04-08 5:49 ` Dongli Zhang
2021-03-26 5:44 ` Dongli Zhang [this message]
2021-03-26 5:44 ` [PATCH 3/6] virtio-blk-pci: implement device event interface for kick/call Dongli Zhang
2021-03-26 5:44 ` [PATCH 4/6] virtio-scsi-pci: " Dongli Zhang
2021-03-26 5:44 ` [PATCH 5/6] vhost-scsi-pci: " Dongli Zhang
2021-03-26 5:44 ` [PATCH 6/6] virtio-net-pci: " Dongli Zhang
2021-03-26 7:24 ` [PATCH 0/6] Add debug interface to kick/call on purpose Jason Wang
2021-03-26 21:16 ` Dongli Zhang
2021-03-29 3:56 ` Jason Wang
2021-03-30 7:29 ` Dongli Zhang
2021-04-02 3:47 ` Jason Wang
2021-04-05 20:00 ` Dongli Zhang
2021-04-06 1:55 ` Jason Wang
2021-04-06 8:43 ` Dongli Zhang
2021-04-06 23:27 ` Dongli Zhang
2021-04-07 2:20 ` Jason Wang
2021-04-08 5:51 ` Dongli Zhang
2021-04-08 5:59 ` Jason Wang
2021-04-07 2:18 ` Jason Wang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210326054433.11762-3-dongli.zhang@oracle.com \
--to=dongli.zhang@oracle.com \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=dgilbert@redhat.com \
--cc=ehabkost@redhat.com \
--cc=fam@euphon.net \
--cc=jasowang@redhat.com \
--cc=joe.jin@oracle.com \
--cc=kwolf@redhat.com \
--cc=mreitz@redhat.com \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).