qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Vivek Kasireddy <vivek.kasireddy@intel.com>
To: qemu-devel@nongnu.org
Cc: "Vivek Kasireddy" <vivek.kasireddy@intel.com>,
	"Alex Williamson" <alex@shazbot.org>,
	"Cédric Le Goater" <clg@redhat.com>
Subject: [PATCH v3 4/9] vfio/region: Add a helper to get region index from memory region
Date: Fri, 21 Nov 2025 22:46:25 -0800	[thread overview]
Message-ID: <20251122064936.2948632-5-vivek.kasireddy@intel.com> (raw)
In-Reply-To: <20251122064936.2948632-1-vivek.kasireddy@intel.com>

Having a way to figure out the region index (or bar) associated
with a memory region is helpful in various scenarios. For example,
this capability can be useful in retrieving the region info needed
for mapping a part of a VFIO region or creating a dmabuf.

Cc: Alex Williamson <alex@shazbot.org>
Cc: Cédric Le Goater <clg@redhat.com>
Signed-off-by: Vivek Kasireddy <vivek.kasireddy@intel.com>
---
 hw/vfio/region.c              | 14 ++++++++++++++
 include/hw/vfio/vfio-device.h | 10 ++++++++++
 2 files changed, 24 insertions(+)

diff --git a/hw/vfio/region.c b/hw/vfio/region.c
index b165ab0b93..046adfaa2c 100644
--- a/hw/vfio/region.c
+++ b/hw/vfio/region.c
@@ -398,3 +398,17 @@ void vfio_region_mmaps_set_enabled(VFIORegion *region, bool enabled)
     trace_vfio_region_mmaps_set_enabled(memory_region_name(region->mem),
                                         enabled);
 }
+
+int vfio_get_region_index_from_mr(MemoryRegion *mr)
+{
+    VFIORegion *region;
+
+    while (mr->container) {
+        if (mr->ops == &vfio_region_ops) {
+            region = mr->opaque;
+	    return region->nr;
+        }
+        mr = mr->container;
+    }
+    return -1;
+}
diff --git a/include/hw/vfio/vfio-device.h b/include/hw/vfio/vfio-device.h
index bb28123faf..44cacd3728 100644
--- a/include/hw/vfio/vfio-device.h
+++ b/include/hw/vfio/vfio-device.h
@@ -290,6 +290,16 @@ bool vfio_device_has_region_cap(VFIODevice *vbasedev, int region, uint16_t cap_t
 
 int vfio_device_get_irq_info(VFIODevice *vbasedev, int index,
                                 struct vfio_irq_info *info);
+
+/**
+ * Return the region index associated with a given MemoryRegion. The index
+ * can be useful in retrieving region info.
+ *
+ * @mr: MemoryRegion to use
+ *
+ * Returns the region index or -1 on error.
+ */
+int vfio_get_region_index_from_mr(MemoryRegion *mr);
 #endif
 
 /* Returns 0 on success, or a negative errno. */
-- 
2.50.1



  parent reply	other threads:[~2025-11-22  7:50 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-22  6:46 [PATCH v3 0/9] vfio: Implement VFIO_DEVICE_FEATURE_DMA_BUF and use it in virtio-gpu Vivek Kasireddy
2025-11-22  6:46 ` [PATCH v3 1/9] virtio-gpu: Recreate the resource's dmabuf if new backing is attached Vivek Kasireddy
2025-11-22  6:46 ` [PATCH v3 2/9] virtio-gpu: Find hva for Guest's DMA addr associated with a ram device Vivek Kasireddy
2025-11-22  6:46 ` [PATCH v3 3/9] vfio: Document vfio_device_get_region_info() Vivek Kasireddy
2025-11-22  6:46 ` Vivek Kasireddy [this message]
2025-11-22  6:46 ` [PATCH v3 5/9] vfio/device: Add a helper to lookup VFIODevice from memory region Vivek Kasireddy
2025-11-22  6:46 ` [PATCH v3 6/9] vfio/device: Add support for VFIO_DEVICE_FEATURE_DMA_BUF Vivek Kasireddy
2025-11-22  6:46 ` [PATCH v3 7/9] virtio-gpu: Rename udmabuf files and helpers to dmabuf Vivek Kasireddy
2025-11-22  6:46 ` [PATCH v3 8/9] virtio-gpu-dmabuf: Introduce ram_block_is_memfd_backed() helper Vivek Kasireddy
2025-11-22  6:46 ` [PATCH v3 9/9] virtio-gpu-dmabuf: Create dmabuf for blobs associated with VFIO devices Vivek Kasireddy
2025-11-22  7:25   ` Akihiko Odaki
2025-11-23  6:17     ` Kasireddy, Vivek
2025-11-23  8:36       ` Akihiko Odaki

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=20251122064936.2948632-5-vivek.kasireddy@intel.com \
    --to=vivek.kasireddy@intel.com \
    --cc=alex@shazbot.org \
    --cc=clg@redhat.com \
    --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).