diff mbox series

[PULL,v2,29/32] vfio: Add routine for finding VFIO_DEVICE_GET_INFO capabilities

Message ID 160390342802.12234.14639355240743707589.stgit@gimli.home
State New
Headers show
Series VFIO updates 2020-10-28 (for QEMU 5.2 soft-freeze) | expand

Commit Message

Alex Williamson Oct. 28, 2020, 4:43 p.m. UTC
From: Matthew Rosato <mjrosato@linux.ibm.com>

Now that VFIO_DEVICE_GET_INFO supports capability chains, add a helper
function to find specific capabilities in the chain.

Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
 hw/vfio/common.c              |   10 ++++++++++
 include/hw/vfio/vfio-common.h |    2 ++
 2 files changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index b9780ba6e9e1..60217c20f9ff 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -1159,6 +1159,16 @@  vfio_get_iommu_type1_info_cap(struct vfio_iommu_type1_info *info, uint16_t id)
     return vfio_get_cap((void *)info, info->cap_offset, id);
 }
 
+struct vfio_info_cap_header *
+vfio_get_device_info_cap(struct vfio_device_info *info, uint16_t id)
+{
+    if (!(info->flags & VFIO_DEVICE_FLAGS_CAPS)) {
+        return NULL;
+    }
+
+    return vfio_get_cap((void *)info, info->cap_offset, id);
+}
+
 bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info *info,
                              unsigned int *avail)
 {
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index 1d14946a9d66..baeb4dcff102 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -216,6 +216,8 @@  struct vfio_info_cap_header *
 vfio_get_region_info_cap(struct vfio_region_info *info, uint16_t id);
 bool vfio_get_info_dma_avail(struct vfio_iommu_type1_info *info,
                              unsigned int *avail);
+struct vfio_info_cap_header *
+vfio_get_device_info_cap(struct vfio_device_info *info, uint16_t id);
 #endif
 extern const MemoryListener vfio_prereg_listener;