qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 2/3] virtio: Added function to calculate number of b


From: David Gibson
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

From: Alexey Kardashevskiy <address@hidden>

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 <address@hidden>
Signed-off-by: David Gibson <address@hidden>
---
 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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]