yeahuh / rpms / qemu-kvm

Forked from rpms/qemu-kvm 2 years ago
Clone
a19a21
From f53c2c68db7780353a915072f8c953a74149b1f7 Mon Sep 17 00:00:00 2001
a19a21
From: Cornelia Huck <cohuck@redhat.com>
a19a21
Date: Tue, 19 Jan 2021 12:50:42 -0500
a19a21
Subject: [PATCH 3/7] vfio: Create shared routine for scanning info
a19a21
 capabilities
a19a21
MIME-Version: 1.0
a19a21
Content-Type: text/plain; charset=UTF-8
a19a21
Content-Transfer-Encoding: 8bit
a19a21
a19a21
RH-Author: Cornelia Huck <cohuck@redhat.com>
a19a21
Message-id: <20210119125046.472811-4-cohuck@redhat.com>
a19a21
Patchwork-id: 100678
a19a21
O-Subject: [RHEL-8.4.0 qemu-kvm PATCH 3/7] vfio: Create shared routine for scanning info capabilities
a19a21
Bugzilla: 1905391
a19a21
RH-Acked-by: David Hildenbrand <david@redhat.com>
a19a21
RH-Acked-by: Auger Eric <eric.auger@redhat.com>
a19a21
RH-Acked-by: Thomas Huth <thuth@redhat.com>
a19a21
a19a21
From: Matthew Rosato <mjrosato@linux.ibm.com>
a19a21
a19a21
Rather than duplicating the same loop in multiple locations,
a19a21
create a static function to do the work.
a19a21
a19a21
Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
a19a21
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
a19a21
Reviewed-by: Cornelia Huck <cohuck@redhat.com>
a19a21
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
a19a21
(cherry picked from commit 3ab7a0b40d4be5ade3b61d4afd1518193b199423)
a19a21
Signed-off-by: Cornelia Huck <cohuck@redhat.com>
a19a21
Signed-off-by: Danilo C. L. de Paula <ddepaula@redhat.com>
a19a21
---
a19a21
 hw/vfio/common.c | 21 +++++++++++++--------
a19a21
 1 file changed, 13 insertions(+), 8 deletions(-)
a19a21
a19a21
diff --git a/hw/vfio/common.c b/hw/vfio/common.c
a19a21
index 5ca11488d67..77d62d2dcdf 100644
a19a21
--- a/hw/vfio/common.c
a19a21
+++ b/hw/vfio/common.c
a19a21
@@ -826,17 +826,12 @@ static void vfio_listener_release(VFIOContainer *container)
a19a21
     }
a19a21
 }
a19a21
 
a19a21
-struct vfio_info_cap_header *
a19a21
-vfio_get_region_info_cap(struct vfio_region_info *info, uint16_t id)
a19a21
+static struct vfio_info_cap_header *
a19a21
+vfio_get_cap(void *ptr, uint32_t cap_offset, uint16_t id)
a19a21
 {
a19a21
     struct vfio_info_cap_header *hdr;
a19a21
-    void *ptr = info;
a19a21
-
a19a21
-    if (!(info->flags & VFIO_REGION_INFO_FLAG_CAPS)) {
a19a21
-        return NULL;
a19a21
-    }
a19a21
 
a19a21
-    for (hdr = ptr + info->cap_offset; hdr != ptr; hdr = ptr + hdr->next) {
a19a21
+    for (hdr = ptr + cap_offset; hdr != ptr; hdr = ptr + hdr->next) {
a19a21
         if (hdr->id == id) {
a19a21
             return hdr;
a19a21
         }
a19a21
@@ -845,6 +840,16 @@ vfio_get_region_info_cap(struct vfio_region_info *info, uint16_t id)
a19a21
     return NULL;
a19a21
 }
a19a21
 
a19a21
+struct vfio_info_cap_header *
a19a21
+vfio_get_region_info_cap(struct vfio_region_info *info, uint16_t id)
a19a21
+{
a19a21
+    if (!(info->flags & VFIO_REGION_INFO_FLAG_CAPS)) {
a19a21
+        return NULL;
a19a21
+    }
a19a21
+
a19a21
+    return vfio_get_cap((void *)info, info->cap_offset, id);
a19a21
+}
a19a21
+
a19a21
 static int vfio_setup_region_sparse_mmaps(VFIORegion *region,
a19a21
                                           struct vfio_region_info *info)
a19a21
 {
a19a21
-- 
a19a21
2.27.0
a19a21