On 2/6/26 15:48, Shameer Kolothum wrote:
From: Nicolin Chen <[email protected]>

Add a helper to allocate an iommufd backed HW queue for a vIOMMU.

While at it, define a struct IOMMUFDHWqueue for use by vendor
implementations.

Signed-off-by: Nicolin Chen <[email protected]>
Reviewed-by: Eric Auger <[email protected]>
Signed-off-by: Shameer Kolothum <[email protected]>
---
  backends/iommufd.c       | 32 ++++++++++++++++++++++++++++++++
  backends/trace-events    |  1 +
  include/system/iommufd.h | 12 ++++++++++++


Could you please add to your .gitconfig :

[diff]
        orderFile = /path/to/qemu/scripts/git.orderfile


  3 files changed, 45 insertions(+)

diff --git a/backends/iommufd.c b/backends/iommufd.c
index 8ab26eb786..c6b79da0d4 100644
--- a/backends/iommufd.c
+++ b/backends/iommufd.c
@@ -546,6 +546,38 @@ bool iommufd_backend_alloc_veventq(IOMMUFDBackend *be, 
uint32_t viommu_id,
      return true;
  }
+bool iommufd_backend_alloc_hw_queue(IOMMUFDBackend *be, uint32_t viommu_id,
+                                    enum iommu_hw_queue_type queue_type,
+                                    uint32_t index, uint64_t addr,
+                                    uint64_t length, uint32_t *out_hw_queue_id,
+                                    Error **errp)
+{
+    int ret;
+    struct iommu_hw_queue_alloc alloc_hw_queue = {
+        .size = sizeof(alloc_hw_queue),
+        .flags = 0,
+        .viommu_id = viommu_id,
+        .type = queue_type,
+        .index = index,
+        .nesting_parent_iova = addr,
+        .length = length,
+    };
+
+    ret = ioctl(be->fd, IOMMU_HW_QUEUE_ALLOC, &alloc_hw_queue);
+
+    trace_iommufd_backend_alloc_hw_queue(be->fd, viommu_id, queue_type,
+                                         index, addr, length,
+                                         alloc_hw_queue.out_hw_queue_id, ret);
+    if (ret) {
+        error_setg_errno(errp, errno, "IOMMU_HW_QUEUE_ALLOC failed");
+        return false;
+    }
+
+    g_assert(out_hw_queue_id);
+    *out_hw_queue_id = alloc_hw_queue.out_hw_queue_id;
+    return true;
+}
+
  bool host_iommu_device_iommufd_attach_hwpt(HostIOMMUDeviceIOMMUFD *idev,
                                             uint32_t hwpt_id, Error **errp)
  {
diff --git a/backends/trace-events b/backends/trace-events
index 332888a576..3e70338750 100644
--- a/backends/trace-events
+++ b/backends/trace-events
@@ -24,6 +24,7 @@ iommufd_backend_invalidate_cache(int iommufd, uint32_t id, 
uint32_t data_type, u
  iommufd_backend_alloc_viommu(int iommufd, uint32_t dev_id, uint32_t type, uint32_t hwpt_id, 
uint32_t data_len, uint64_t data_ptr, uint32_t viommu_id, int ret) " iommufd=%d type=%u 
dev_id=%u hwpt_id=%u data_len=%u data_ptr=0x%"PRIx64" viommu_id=%u (%d)"
  iommufd_backend_alloc_vdev(int iommufd, uint32_t dev_id, uint32_t viommu_id, uint64_t virt_id, 
uint32_t vdev_id, int ret) " iommufd=%d dev_id=%u viommu_id=%u virt_id=0x%"PRIx64" 
vdev_id=%u (%d)"
  iommufd_viommu_alloc_eventq(int iommufd, uint32_t viommu_id, uint32_t type, uint32_t 
veventq_id, uint32_t veventq_fd, int ret) " iommufd=%d viommu_id=%u type=%u 
veventq_id=%u veventq_fd=%u (%d)"
+iommufd_backend_alloc_hw_queue(int iommufd, uint32_t viommu_id, uint32_t queue_type, uint32_t index, 
uint64_t addr, uint64_t size, uint32_t queue_id, int ret) " iommufd=%d viommu_id=%u queue_type=%u 
index=%u addr=0x%"PRIx64" size=0x%"PRIx64" queue_id=%u (%d)"
# igvm-cfg.c
  igvm_reset_enter(int type) "type=%u"
diff --git a/include/system/iommufd.h b/include/system/iommufd.h
index 5ef23ad9e1..f72ad545f8 100644
--- a/include/system/iommufd.h
+++ b/include/system/iommufd.h
@@ -63,6 +63,12 @@ typedef struct IOMMUFDVeventq {
      uint32_t veventq_fd;
  } IOMMUFDVeventq;
+/* HW queue object for a vIOMMU-specific HW-accelerated queue */
+typedef struct IOMMUFDHWqueue {
+    IOMMUFDViommu *viommu;
+    uint32_t hw_queue_id;
+} IOMMUFDHWqueue;
+
  bool iommufd_backend_connect(IOMMUFDBackend *be, Error **errp);
  void iommufd_backend_disconnect(IOMMUFDBackend *be);
@@ -99,6 +105,12 @@ bool iommufd_backend_alloc_veventq(IOMMUFDBackend *be, uint32_t viommu_id,
                                     uint32_t *out_veventq_id,
                                     uint32_t *out_veventq_fd, Error **errp);
+bool iommufd_backend_alloc_hw_queue(IOMMUFDBackend *be, uint32_t viommu_id,
+                                    enum iommu_hw_queue_type queue_type,

Please use a uint32_t for the queue_type parameter. 'enum iommu_hw_queue_type'
is a Linux-only type and build will break on other platform.

Thanks,

C.



+                                    uint32_t index, uint64_t addr,
+                                    uint64_t length, uint32_t *out_hw_queue_id,
+                                    Error **errp);
+
  bool iommufd_backend_set_dirty_tracking(IOMMUFDBackend *be, uint32_t hwpt_id,
                                          bool start, Error **errp);
  bool iommufd_backend_get_dirty_bitmap(IOMMUFDBackend *be, uint32_t hwpt_id,


Reply via email to