Add two wrappers host_iommu_device_iommufd_pasid_[at|de]tach_hwpt to
wrap the two callbacks.
Use assert to ensure the corresponding callbacks exist.
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
---
include/system/iommufd.h | 40 ++++++++++++++++++++++++++++++++++++++++
backends/iommufd.c | 23 +++++++++++++++++++++++
2 files changed, 63 insertions(+)
diff --git a/include/system/iommufd.h b/include/system/iommufd.h
index 80d72469a9..615be10aed 100644
--- a/include/system/iommufd.h
+++ b/include/system/iommufd.h
@@ -145,10 +145,50 @@ struct HostIOMMUDeviceIOMMUFDClass {
* Returns: true on success, false on failure.
*/
bool (*detach_hwpt)(HostIOMMUDeviceIOMMUFD *idev, Error **errp);
+ /**
+ * @attach_hwpt: attach host IOMMU device's pasid to IOMMUFD hardware page
+ * table. VFIO and VDPA device can have different implementation.
+ *
+ * Mandatory callback.
+ *
+ * @idev: host IOMMU device backed by IOMMUFD backend.
+ *
+ * @pasid: pasid of host IOMMU device.
+ *
+ * @hwpt_id: ID of IOMMUFD hardware page table.
+ *
+ * @errp: pass an Error out when attachment fails.
+ *
+ * Returns: true on success, false on failure.
+ */
+ bool (*pasid_attach_hwpt)(HostIOMMUDeviceIOMMUFD *idev, uint32_t pasid,
+ uint32_t hwpt_id, Error **errp);
+ /**
+ * @detach_hwpt: detach host IOMMU device's from IOMMUFD hardware page
+ * table. VFIO and VDPA device can have different implementation.
+ *
+ * Mandatory callback.
+ *
+ * @idev: host IOMMU device backed by IOMMUFD backend.
+ *
+ * @pasid: pasid of host IOMMU device.
+ *
+ * @errp: pass an Error out when attachment fails.
+ *
+ * Returns: true on success, false on failure.
+ */
+ bool (*pasid_detach_hwpt)(HostIOMMUDeviceIOMMUFD *idev, uint32_t pasid,
+ Error **errp);
};
bool host_iommu_device_iommufd_attach_hwpt(HostIOMMUDeviceIOMMUFD *idev,
uint32_t hwpt_id, Error **errp);
bool host_iommu_device_iommufd_detach_hwpt(HostIOMMUDeviceIOMMUFD *idev,
Error **errp);
+bool host_iommu_device_iommufd_pasid_attach_hwpt(HostIOMMUDeviceIOMMUFD *idev,
+ uint32_t pasid,
+ uint32_t hwpt_id,
+ Error **errp);
+bool host_iommu_device_iommufd_pasid_detach_hwpt(HostIOMMUDeviceIOMMUFD *idev,
+ uint32_t pasid, Error **errp);
#endif
diff --git a/backends/iommufd.c b/backends/iommufd.c
index 13822df82f..93d3612471 100644
--- a/backends/iommufd.c
+++ b/backends/iommufd.c
@@ -539,6 +539,29 @@ static int hiod_iommufd_get_cap(HostIOMMUDevice *hiod, int cap, Error **errp)
}
}
+bool host_iommu_device_iommufd_pasid_attach_hwpt(HostIOMMUDeviceIOMMUFD *idev,
+ uint32_t pasid,
+ uint32_t hwpt_id,
+ Error **errp)
+{
+ HostIOMMUDeviceIOMMUFDClass *idevc =
+ HOST_IOMMU_DEVICE_IOMMUFD_GET_CLASS(idev);
+
+ g_assert(idevc->pasid_attach_hwpt);
+ return idevc->pasid_attach_hwpt(idev, pasid, hwpt_id, errp);
+}
+
+bool host_iommu_device_iommufd_pasid_detach_hwpt(HostIOMMUDeviceIOMMUFD *idev,
+ uint32_t pasid,
+ Error **errp)
+{
+ HostIOMMUDeviceIOMMUFDClass *idevc =
+ HOST_IOMMU_DEVICE_IOMMUFD_GET_CLASS(idev);
+
+ g_assert(idevc->pasid_detach_hwpt);
+ return idevc->pasid_detach_hwpt(idev, pasid, errp);
+}
+
static bool hiod_iommufd_get_pasid_info(HostIOMMUDevice *hiod,
PasidInfo *pasid_info)
{
--
2.47.3