diff mbox series

[v3,09/10] vfio: Add routine for finding VFIO_DEVICE_GET_INFO capabilities

Message ID 1602097455-15658-10-git-send-email-mjrosato@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series Retrieve zPCI hardware information from VFIO | expand

Commit Message

Matthew Rosato Oct. 7, 2020, 7:04 p.m. UTC
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>
---
 hw/vfio/common.c              | 10 ++++++++++
 include/hw/vfio/vfio-common.h |  2 ++
 2 files changed, 12 insertions(+)

Comments

Cornelia Huck Oct. 9, 2020, 9:53 a.m. UTC | #1
On Wed,  7 Oct 2020 15:04:14 -0400
Matthew Rosato <mjrosato@linux.ibm.com> wrote:

> 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>
> ---
>  hw/vfio/common.c              | 10 ++++++++++
>  include/hw/vfio/vfio-common.h |  2 ++
>  2 files changed, 12 insertions(+)

Reviewed-by: Cornelia Huck <cohuck@redhat.com>
diff mbox series

Patch

diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index e47a4d7..7cda9d2 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -849,6 +849,16 @@  vfio_get_region_info_cap(struct vfio_region_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);
+}
+
 static int vfio_setup_region_sparse_mmaps(VFIORegion *region,
                                           struct vfio_region_info *info)
 {
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index c78f3ff..3c236ed 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -191,6 +191,8 @@  int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,
 bool vfio_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_type);
 struct vfio_info_cap_header *
 vfio_get_region_info_cap(struct vfio_region_info *info, uint16_t id);
+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;