qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: David Gibson <david@gibson.dropbear.id.au>
To: agraf@suse.de, qemu-devel@nongnu.org
Cc: aik@ozlabs.ru, paulus@samba.org
Subject: [Qemu-devel] [PATCH 2/3] virtio: Added function to calculate number of bytes required to allocate a VRing
Date: Tue, 17 May 2011 16:47:05 +1000	[thread overview]
Message-ID: <1305614826-1815-3-git-send-email-david@gibson.dropbear.id.au> (raw)
In-Reply-To: <1305614826-1815-1-git-send-email-david@gibson.dropbear.id.au>

From: Alexey Kardashevskiy <aik@ozlabs.ru>

The existing function virtio_queue_get_ring_size returns number of bytes
for vring only when it is already initialized.

In order to know how much memory new vring requires, new function
virtio_queue_get_mem_size has been introduced. It is a copy
of the vring_size function from the linux kernel (include/linux/virtio_ring.h).

Signed-off-by: Alexey Kardashevskiy <aik@ozlabs.ru>
Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
---
 hw/virtio.c |    8 ++++++++
 hw/virtio.h |    1 +
 2 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/hw/virtio.c b/hw/virtio.c
index 6e8814c..ff05b25 100644
--- a/hw/virtio.c
+++ b/hw/virtio.c
@@ -574,6 +574,14 @@ int virtio_queue_get_num(VirtIODevice *vdev, int n)
     return vdev->vq[n].vring.num;
 }
 
+int virtio_queue_get_mem_size(VirtIODevice *vdev, int n, int align)
+{
+    int num = virtio_queue_get_num(vdev, n);
+    return ((sizeof(VRingDesc)*num + sizeof(uint16_t)*(2 + num)
+            + align - 1) & ~(align - 1))
+            + sizeof(uint16_t)*2 + sizeof(VRingUsedElem)*num;
+}
+
 void virtio_queue_notify_vq(VirtQueue *vq)
 {
     if (vq->vring.desc) {
diff --git a/hw/virtio.h b/hw/virtio.h
index bc72289..114a877 100644
--- a/hw/virtio.h
+++ b/hw/virtio.h
@@ -182,6 +182,7 @@ void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data);
 void virtio_queue_set_addr(VirtIODevice *vdev, int n, target_phys_addr_t addr);
 target_phys_addr_t virtio_queue_get_addr(VirtIODevice *vdev, int n);
 int virtio_queue_get_num(VirtIODevice *vdev, int n);
+int virtio_queue_get_mem_size(VirtIODevice *vdev, int n, int align);
 void virtio_queue_notify(VirtIODevice *vdev, int n);
 uint16_t virtio_queue_vector(VirtIODevice *vdev, int n);
 void virtio_queue_set_vector(VirtIODevice *vdev, int n, uint16_t vector);
-- 
1.7.4.4

  parent reply	other threads:[~2011-05-17  6:48 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-05-17  6:47 [Qemu-devel] pSseries platform updates, cleanup and virtio support David Gibson
2011-05-17  6:47 ` [Qemu-devel] [PATCH 1/3] pSeries: Clean up write-only variables David Gibson
2011-05-17  6:47 ` David Gibson [this message]
2011-05-17  6:58   ` [Qemu-devel] [PATCH 2/3] virtio: Added function to calculate number of bytes required to allocate a VRing Alexander Graf
2011-05-17  6:47 ` [Qemu-devel] [PATCH 3/3] powerpc-virtio: virtio support introduced (block, network, serial, balloon, 9p-fs), both fullemu and power-kvm David Gibson
2011-05-17  7:06   ` Alexander Graf
2011-05-18  3:27     ` David Gibson
2011-05-18  8:58       ` Michael S. Tsirkin
2011-05-18  9:35       ` Alexander Graf

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=1305614826-1815-3-git-send-email-david@gibson.dropbear.id.au \
    --to=david@gibson.dropbear.id.au \
    --cc=agraf@suse.de \
    --cc=aik@ozlabs.ru \
    --cc=paulus@samba.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).