qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: qemu-devel@nongnu.org
Cc: allen.m.kay@intel.com, kraxel@redhat.com, kvm@vger.kernel.org
Subject: [Qemu-devel] [PATCH v6 2/8] vfio: Create device specific region info helper
Date: Tue, 17 May 2016 14:19:31 -0600	[thread overview]
Message-ID: <20160517201931.6175.88846.stgit@gimli.home> (raw)
In-Reply-To: <20160517201613.6175.45578.stgit@gimli.home>

Given a device specific region type and sub-type, find it.  Also
cleanup return point on error in vfio_get_region_info() so that we
always return 0 with a valid pointer or -errno and NULL.

Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
 hw/vfio/common.c              |   36 ++++++++++++++++++++++++++++++++++++
 include/hw/vfio/vfio-common.h |    2 ++
 trace-events                  |    4 ++--
 3 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/hw/vfio/common.c b/hw/vfio/common.c
index eb6f04e..ae2c13b 100644
--- a/hw/vfio/common.c
+++ b/hw/vfio/common.c
@@ -1142,6 +1142,7 @@ retry:
 
     if (ioctl(vbasedev->fd, VFIO_DEVICE_GET_REGION_INFO, *info)) {
         g_free(*info);
+        *info = NULL;
         return -errno;
     }
 
@@ -1155,6 +1156,41 @@ retry:
     return 0;
 }
 
+int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,
+                             uint32_t subtype, struct vfio_region_info **info)
+{
+    int i;
+
+    for (i = 0; i < vbasedev->num_regions; i++) {
+        struct vfio_info_cap_header *hdr;
+        struct vfio_region_info_cap_type *cap_type;
+
+        if (vfio_get_region_info(vbasedev, i, info)) {
+            continue;
+        }
+
+        hdr = vfio_get_region_info_cap(*info, VFIO_REGION_INFO_CAP_TYPE);
+        if (!hdr) {
+            g_free(*info);
+            continue;
+        }
+
+        cap_type = container_of(hdr, struct vfio_region_info_cap_type, header);
+
+        trace_vfio_get_dev_region(vbasedev->name, i,
+                                  cap_type->type, cap_type->subtype);
+
+        if (cap_type->type == type && cap_type->subtype == subtype) {
+            return 0;
+        }
+
+        g_free(*info);
+    }
+
+    *info = NULL;
+    return -ENODEV;
+}
+
 /*
  * Interfaces for IBM EEH (Enhanced Error Handling)
  */
diff --git a/include/hw/vfio/vfio-common.h b/include/hw/vfio/vfio-common.h
index eb0e1b0..a947f9c 100644
--- a/include/hw/vfio/vfio-common.h
+++ b/include/hw/vfio/vfio-common.h
@@ -154,5 +154,7 @@ extern QLIST_HEAD(vfio_as_head, VFIOAddressSpace) vfio_address_spaces;
 #ifdef CONFIG_LINUX
 int vfio_get_region_info(VFIODevice *vbasedev, int index,
                          struct vfio_region_info **info);
+int vfio_get_dev_region_info(VFIODevice *vbasedev, uint32_t type,
+                             uint32_t subtype, struct vfio_region_info **info);
 #endif
 #endif /* !HW_VFIO_VFIO_COMMON_H */
diff --git a/trace-events b/trace-events
index 99c5132..32e7a78 100644
--- a/trace-events
+++ b/trace-events
@@ -1714,8 +1714,7 @@ vfio_quirk_ati_bonaire_reset_timeout(const char *name) "%s"
 vfio_quirk_ati_bonaire_reset_done(const char *name) "%s"
 vfio_quirk_ati_bonaire_reset(const char *name) "%s"
 
-
-# hw/vfio/vfio-common.c
+# hw/vfio/common.c
 vfio_region_write(const char *name, int index, uint64_t addr, uint64_t data, unsigned size) " (%s:region%d+0x%"PRIx64", 0x%"PRIx64 ", %d)"
 vfio_region_read(char *name, int index, uint64_t addr, unsigned size, uint64_t data) " (%s:region%d+0x%"PRIx64", %d) = 0x%"PRIx64
 vfio_iommu_map_notify(uint64_t iova_start, uint64_t iova_end) "iommu map @ %"PRIx64" - %"PRIx64
@@ -1736,6 +1735,7 @@ vfio_region_finalize(const char *name, int index) "Device %s, region %d"
 vfio_region_mmaps_set_enabled(const char *name, bool enabled) "Region %s mmaps enabled: %d"
 vfio_region_sparse_mmap_header(const char *name, int index, int nr_areas) "Device %s region %d: %d sparse mmap entries"
 vfio_region_sparse_mmap_entry(int i, off_t start, off_t end) "sparse entry %d [0x%lx - 0x%lx]"
+vfio_get_dev_region(const char *name, int index, uint32_t type, uint32_t subtype) "%s index %d, %08x/%0x8"
 
 # hw/vfio/platform.c
 vfio_platform_base_device_init(char *name, int groupid) "%s belongs to group #%d"

  parent reply	other threads:[~2016-05-18  1:39 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-17 20:19 [Qemu-devel] [PATCH v6 0/8] Series short description Alex Williamson
2016-05-17 20:19 ` [Qemu-devel] [PATCH v6 1/8] vfio: Enable sparse mmap capability Alex Williamson
2016-05-17 20:19 ` Alex Williamson [this message]
2016-05-17 20:19 ` [Qemu-devel] [PATCH v6 3/8] vfio/pci: Fix return of vfio_populate_vga() Alex Williamson
2016-05-17 20:19 ` [Qemu-devel] [PATCH v6 4/8] vfio/pci: Consolidate VGA setup Alex Williamson
2016-05-17 20:19 ` [Qemu-devel] [PATCH v6 5/8] vfio/pci: Setup BAR quirks after capabilities probing Alex Williamson
2016-05-17 20:19 ` [Qemu-devel] [PATCH v6 6/8] vfio/pci: Intel graphics legacy mode assignment Alex Williamson
2016-05-18 14:21   ` Gerd Hoffmann
2016-05-18 16:50     ` Alex Williamson
2016-05-17 20:20 ` [Qemu-devel] [PATCH v6 7/8] vfio/pci: Add a separate option for IGD OpRegion support Alex Williamson
2016-05-17 20:20 ` [Qemu-devel] [PATCH v6 8/8] vfio/pci: Add IGD documentation Alex Williamson
2016-05-18  2:23   ` Eric Blake
2016-05-18 18:35     ` Alex Williamson
2016-05-18 19:28       ` Eric Blake
2016-05-17 20:42 ` [Qemu-devel] vfio IGD assignment (was Re: [PATCH v6 0/8] Series short description) Alex Williamson
2016-05-18 14:24   ` Gerd Hoffmann
2016-05-18 18:45     ` Alex Williamson
2016-05-19  9:00       ` Gerd Hoffmann
2016-05-20 12:19       ` Gerd Hoffmann
2016-05-20 15:08         ` Alex Williamson
2016-05-23 13:34           ` Gerd Hoffmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160517201931.6175.88846.stgit@gimli.home \
    --to=alex.williamson@redhat.com \
    --cc=allen.m.kay@intel.com \
    --cc=kraxel@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=qemu-devel@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).