[Top][All Lists]
[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
- [Qemu-devel] pSseries platform updates, cleanup and virtio support, David Gibson, 2011/05/17
- [Qemu-devel] [PATCH 1/3] pSeries: Clean up write-only variables, David Gibson, 2011/05/17
- [Qemu-devel] [PATCH 2/3] virtio: Added function to calculate number of bytes required to allocate a VRing,
David Gibson <=
- [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
- Re: [Qemu-devel] [PATCH 3/3] powerpc-virtio: virtio support introduced (block, network, serial, balloon, 9p-fs), both fullemu and power-kvm, Alexander Graf, 2011/05/17
- Re: [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
- Re: [Qemu-devel] [PATCH 3/3] powerpc-virtio: virtio support introduced (block, network, serial, balloon, 9p-fs), both fullemu and power-kvm, Michael S. Tsirkin, 2011/05/18
- Re: [Qemu-devel] [PATCH 3/3] powerpc-virtio: virtio support introduced (block, network, serial, balloon, 9p-fs), both fullemu and power-kvm, Alexander Graf, 2011/05/18