From: "Michael S. Tsirkin" <mst@redhat.com>
To: qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>,
Anthony Liguori <aliguori@us.ibm.com>,
Peter Maydell <peter.maydell@linaro.org>
Subject: [Qemu-devel] [PATCH v2 11/11] virtio: use ring structure from linux-headers
Date: Sun, 26 May 2013 18:23:41 +0300 [thread overview]
Message-ID: <1369581694-1655-12-git-send-email-mst@redhat.com> (raw)
In-Reply-To: <1369581694-1655-1-git-send-email-mst@redhat.com>
We already have ring structure in virtio-ring.h for use by dataplane.
Use it in virtio.h as well, renaming some conflicting functions.
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/virtio/virtio.c | 23 +++++------------------
include/hw/virtio/virtio.h | 45 +++------------------------------------------
2 files changed, 8 insertions(+), 60 deletions(-)
diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 8176c14..20bb6c2 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -145,7 +145,7 @@ static inline uint16_t vring_avail_ring(VirtQueue *vq, int i)
return lduw_phys(pa);
}
-static inline uint16_t vring_used_event(VirtQueue *vq)
+static inline uint16_t vring_used_event_idx(VirtQueue *vq)
{
return vring_avail_ring(vq, vq->vring.num);
}
@@ -192,7 +192,7 @@ static inline void vring_used_flags_unset_bit(VirtQueue *vq, int mask)
stw_phys(pa, lduw_phys(pa) & ~mask);
}
-static inline void vring_avail_event(VirtQueue *vq, uint16_t val)
+static inline void vring_avail_event_idx(VirtQueue *vq, uint16_t val)
{
hwaddr pa;
if (!vq->notification) {
@@ -206,7 +206,7 @@ void virtio_queue_set_notification(VirtQueue *vq, int enable)
{
vq->notification = enable;
if (vq->vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX)) {
- vring_avail_event(vq, vring_avail_idx(vq));
+ vring_avail_event_idx(vq, vring_avail_idx(vq));
} else if (enable) {
vring_used_flags_unset_bit(vq, VRING_USED_F_NO_NOTIFY);
} else {
@@ -448,7 +448,7 @@ int virtqueue_pop(VirtQueue *vq, VirtQueueElement *elem)
i = head = virtqueue_get_head(vq, vq->last_avail_idx++);
if (vq->vdev->guest_features & (1 << VIRTIO_RING_F_EVENT_IDX)) {
- vring_avail_event(vq, vring_avail_idx(vq));
+ vring_avail_event_idx(vq, vring_avail_idx(vq));
}
if (vring_desc_flags(desc_pa, i) & VRING_DESC_F_INDIRECT) {
@@ -740,19 +740,6 @@ void virtio_irq(VirtQueue *vq)
virtio_notify_vector(vq->vdev, vq->vector);
}
-/* Assuming a given event_idx value from the other size, if
- * we have just incremented index from old to new_idx,
- * should we trigger an event? */
-static inline int vring_need_event(uint16_t event, uint16_t new, uint16_t old)
-{
- /* Note: Xen has similar logic for notification hold-off
- * in include/xen/interface/io/ring.h with req_event and req_prod
- * corresponding to event_idx + 1 and new respectively.
- * Note also that req_event and req_prod in Xen start at 1,
- * event indexes in virtio start at 0. */
- return (uint16_t)(new - event - 1) < (uint16_t)(new - old);
-}
-
static bool vring_notify(VirtIODevice *vdev, VirtQueue *vq)
{
uint16_t old, new;
@@ -773,7 +760,7 @@ static bool vring_notify(VirtIODevice *vdev, VirtQueue *vq)
vq->signalled_used_valid = true;
old = vq->signalled_used;
new = vq->signalled_used = vring_used_idx(vq);
- return !v || vring_need_event(vring_used_event(vq), new, old);
+ return !v || vring_need_event(vring_used_event_idx(vq), new, old);
}
void virtio_notify(VirtIODevice *vdev, VirtQueue *vq)
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index a6c5c53..3ea634d 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -22,50 +22,11 @@
#ifdef CONFIG_VIRTFS
#include "hw/virtio/virtio-9p.h"
#endif
+#include "linux/virtio_config.h"
+#include "linux/virtio_ring.h"
-/* from Linux's linux/virtio_config.h */
-
-/* Status byte for guest to report progress, and synchronize features. */
-/* We have seen device and processed generic fields (VIRTIO_CONFIG_F_VIRTIO) */
-#define VIRTIO_CONFIG_S_ACKNOWLEDGE 1
-/* We have found a driver for the device. */
-#define VIRTIO_CONFIG_S_DRIVER 2
-/* Driver has used its parts of the config, and is happy */
-#define VIRTIO_CONFIG_S_DRIVER_OK 4
-/* We've given up on this device. */
-#define VIRTIO_CONFIG_S_FAILED 0x80
-
-/* Some virtio feature bits (currently bits 28 through 31) are reserved for the
- * transport being used (eg. virtio_ring), the rest are per-device feature bits. */
-#define VIRTIO_TRANSPORT_F_START 28
-#define VIRTIO_TRANSPORT_F_END 32
-
-/* We notify when the ring is completely used, even if the guest is suppressing
- * callbacks */
-#define VIRTIO_F_NOTIFY_ON_EMPTY 24
-/* We support indirect buffer descriptors */
-#define VIRTIO_RING_F_INDIRECT_DESC 28
-/* The Guest publishes the used index for which it expects an interrupt
- * at the end of the avail ring. Host should ignore the avail->flags field. */
-/* The Host publishes the avail index for which it expects a kick
- * at the end of the used ring. Guest should ignore the used->flags field. */
-#define VIRTIO_RING_F_EVENT_IDX 29
/* A guest should never accept this. It implies negotiation is broken. */
-#define VIRTIO_F_BAD_FEATURE 30
-
-/* from Linux's linux/virtio_ring.h */
-
-/* This marks a buffer as continuing via the next field. */
-#define VRING_DESC_F_NEXT 1
-/* This marks a buffer as write-only (otherwise read-only). */
-#define VRING_DESC_F_WRITE 2
-/* This means the buffer contains a list of buffer descriptors. */
-#define VRING_DESC_F_INDIRECT 4
-
-/* This means don't notify other side when buffer added. */
-#define VRING_USED_F_NO_NOTIFY 1
-/* This means don't interrupt guest when buffer consumed. */
-#define VRING_AVAIL_F_NO_INTERRUPT 1
+#define VIRTIO_F_BAD_FEATURE 30
struct VirtQueue;
--
MST
next prev parent reply other threads:[~2013-05-26 15:23 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-26 15:22 [Qemu-devel] [PATCH v2 00/11] qemu: use virtio linux headers in portable code Michael S. Tsirkin
2013-05-26 15:22 ` [Qemu-devel] [PATCH v2 01/11] make: pull in linux-headers on all platforms Michael S. Tsirkin
2013-05-26 15:22 ` [Qemu-devel] [PATCH v2 02/11] scripts/update-linux-headers.sh: add virtio Michael S. Tsirkin
2013-05-26 15:22 ` [Qemu-devel] [PATCH v2 03/11] virtio-9p: switch to linux-headers Michael S. Tsirkin
2013-05-26 15:23 ` [Qemu-devel] [PATCH v2 04/11] virtio-net, eth: use linux-headers Michael S. Tsirkin
2013-05-26 15:23 ` [Qemu-devel] [PATCH v2 05/11] virtio-blk: switch to linux-headers Michael S. Tsirkin
2013-05-26 15:23 ` [Qemu-devel] [PATCH v2 06/11] virtio-balloon: " Michael S. Tsirkin
2013-05-26 15:23 ` [Qemu-devel] [PATCH v2 07/11] virtio-rng: " Michael S. Tsirkin
2013-05-26 15:23 ` [Qemu-devel] [PATCH v2 08/11] virtio-console: " Michael S. Tsirkin
2013-05-26 15:23 ` [Qemu-devel] [PATCH v2 09/11] virtio: add virtio_ids from linux-headers Michael S. Tsirkin
2013-05-26 15:23 ` [Qemu-devel] [PATCH v2 10/11] virtio-pci: switch to linux-headers Michael S. Tsirkin
2013-05-26 15:23 ` Michael S. Tsirkin [this message]
2013-05-26 15:43 ` [Qemu-devel] [PATCH v2 00/11] qemu: use virtio linux headers in portable code Peter Maydell
2013-05-26 17:51 ` Michael S. Tsirkin
2013-05-26 18:00 ` Peter Maydell
2013-05-26 18:10 ` Michael S. Tsirkin
2013-05-26 18:26 ` Paolo Bonzini
2013-05-26 18:37 ` Michael S. Tsirkin
2013-05-26 18:53 ` Paolo Bonzini
2013-05-26 20:02 ` Michael S. Tsirkin
2013-05-26 20:20 ` Paolo Bonzini
2013-05-26 20:49 ` Anthony Liguori
2013-05-26 21:42 ` Michael S. Tsirkin
2013-05-27 0:55 ` Anthony Liguori
2013-05-27 15:02 ` Michael S. Tsirkin
2013-05-27 16:14 ` Anthony Liguori
2013-05-28 6:23 ` Michael S. Tsirkin
2013-05-29 0:14 ` Rusty Russell
2013-05-29 13:05 ` Anthony Liguori
2013-05-29 14:09 ` Michael S. Tsirkin
2013-05-29 14:58 ` Anthony Liguori
2013-05-27 11:15 ` Rusty Russell
2013-05-28 2:55 ` Anthony Liguori
2013-05-29 0:17 ` Rusty Russell
2013-05-29 5:17 ` Bryan Venteicher
2013-05-27 10:19 ` Peter Maydell
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=1369581694-1655-12-git-send-email-mst@redhat.com \
--to=mst@redhat.com \
--cc=aliguori@us.ibm.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
/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).