diff mbox

[V3,10/14] virtio: introduce virtio_queue_get_index()

Message ID 1425534531-6305-11-git-send-email-jasowang@redhat.com
State New
Headers show

Commit Message

Jason Wang March 5, 2015, 5:48 a.m. UTC
This patch introduces a helper that can get the queue index of a
VirtQueue. This is useful when traversing the list of VirtQueues.

Cc: Anthony Liguori <aliguori@amazon.com>
Cc: Michael S. Tsirkin <mst@redhat.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
---
 hw/virtio/virtio.c         | 5 +++++
 include/hw/virtio/virtio.h | 1 +
 2 files changed, 6 insertions(+)

Comments

Fam Zheng March 5, 2015, 6:12 a.m. UTC | #1
On Thu, 03/05 13:48, Jason Wang wrote:
> This patch introduces a helper that can get the queue index of a
> VirtQueue. This is useful when traversing the list of VirtQueues.
> 
> Cc: Anthony Liguori <aliguori@amazon.com>
> Cc: Michael S. Tsirkin <mst@redhat.com>
> Signed-off-by: Jason Wang <jasowang@redhat.com>
> ---
>  hw/virtio/virtio.c         | 5 +++++
>  include/hw/virtio/virtio.h | 1 +
>  2 files changed, 6 insertions(+)
> 
> diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
> index 5e6b879..bd32518 100644
> --- a/hw/virtio/virtio.c
> +++ b/hw/virtio/virtio.c
> @@ -725,6 +725,11 @@ hwaddr virtio_queue_get_addr(VirtIODevice *vdev, int n)
>      return vdev->vq[n].pa;
>  }
>  
> +int virtio_queue_get_index(VirtIODevice *vdev, VirtQueue *vq)
> +{
> +    return vq - vdev->vq;

Probably assert the return value is within [0, virtio_get_queue_max(vdev))?

Fam

> +}
> +
>  void virtio_queue_set_num(VirtIODevice *vdev, int n, int num)
>  {
>      /* Don't allow guest to flip queue between existent and
> diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
> index ceab8e8..37aa9c4 100644
> --- a/include/hw/virtio/virtio.h
> +++ b/include/hw/virtio/virtio.h
> @@ -217,6 +217,7 @@ void virtio_config_writew(VirtIODevice *vdev, uint32_t addr, uint32_t data);
>  void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data);
>  void virtio_queue_set_addr(VirtIODevice *vdev, int n, hwaddr addr);
>  hwaddr virtio_queue_get_addr(VirtIODevice *vdev, int n);
> +int virtio_queue_get_index(VirtIODevice *vdev, VirtQueue *vq);
>  void virtio_queue_set_num(VirtIODevice *vdev, int n, int num);
>  int virtio_queue_get_num(VirtIODevice *vdev, int n);
>  void virtio_queue_set_align(VirtIODevice *vdev, int n, int align);
> -- 
> 2.1.0
> 
>
Jason Wang March 6, 2015, 2:49 a.m. UTC | #2
On Thu, Mar 5, 2015 at 2:12 PM, Fam Zheng <famz@redhat.com> wrote:
> On Thu, 03/05 13:48, Jason Wang wrote:
>>  This patch introduces a helper that can get the queue index of a
>>  VirtQueue. This is useful when traversing the list of VirtQueues.
>>  
>>  Cc: Anthony Liguori <aliguori@amazon.com>
>>  Cc: Michael S. Tsirkin <mst@redhat.com>
>>  Signed-off-by: Jason Wang <jasowang@redhat.com>
>>  ---
>>   hw/virtio/virtio.c         | 5 +++++
>>   include/hw/virtio/virtio.h | 1 +
>>   2 files changed, 6 insertions(+)
>>  
>>  diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
>>  index 5e6b879..bd32518 100644
>>  --- a/hw/virtio/virtio.c
>>  +++ b/hw/virtio/virtio.c
>>  @@ -725,6 +725,11 @@ hwaddr virtio_queue_get_addr(VirtIODevice 
>> *vdev, int n)
>>       return vdev->vq[n].pa;
>>   }
>>   
>>  +int virtio_queue_get_index(VirtIODevice *vdev, VirtQueue *vq)
>>  +{
>>  +    return vq - vdev->vq;
> 
> Probably assert the return value is within [0, 
> virtio_get_queue_max(vdev))?
> 
> Fam

Not sure this is necessary. If we add one such here, we probably needs 
to add more elsewhere.
diff mbox

Patch

diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c
index 5e6b879..bd32518 100644
--- a/hw/virtio/virtio.c
+++ b/hw/virtio/virtio.c
@@ -725,6 +725,11 @@  hwaddr virtio_queue_get_addr(VirtIODevice *vdev, int n)
     return vdev->vq[n].pa;
 }
 
+int virtio_queue_get_index(VirtIODevice *vdev, VirtQueue *vq)
+{
+    return vq - vdev->vq;
+}
+
 void virtio_queue_set_num(VirtIODevice *vdev, int n, int num)
 {
     /* Don't allow guest to flip queue between existent and
diff --git a/include/hw/virtio/virtio.h b/include/hw/virtio/virtio.h
index ceab8e8..37aa9c4 100644
--- a/include/hw/virtio/virtio.h
+++ b/include/hw/virtio/virtio.h
@@ -217,6 +217,7 @@  void virtio_config_writew(VirtIODevice *vdev, uint32_t addr, uint32_t data);
 void virtio_config_writel(VirtIODevice *vdev, uint32_t addr, uint32_t data);
 void virtio_queue_set_addr(VirtIODevice *vdev, int n, hwaddr addr);
 hwaddr virtio_queue_get_addr(VirtIODevice *vdev, int n);
+int virtio_queue_get_index(VirtIODevice *vdev, VirtQueue *vq);
 void virtio_queue_set_num(VirtIODevice *vdev, int n, int num);
 int virtio_queue_get_num(VirtIODevice *vdev, int n);
 void virtio_queue_set_align(VirtIODevice *vdev, int n, int align);