diff mbox series

[v1,13/16] iommufd/viommu: Add iommufd_viommu_to_parent_domain helper

Message ID 3d61830fe978e1b5024ce1f36442dcd5ecc03362.1723061378.git.nicolinc@nvidia.com
State New
Headers show
Series iommufd: Add VIOMMU infrastructure (Part-1) | expand

Commit Message

Nicolin Chen Aug. 7, 2024, 8:10 p.m. UTC
Allow an IOMMU driver to convert a core-managed viommu to a nested parent
domain for the info that the domain holds.

Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
---
 drivers/iommu/iommufd/viommu.c | 8 ++++++++
 include/linux/iommufd.h        | 8 ++++++++
 2 files changed, 16 insertions(+)
diff mbox series

Patch

diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c
index 2304f199b033..39a7c04c4132 100644
--- a/drivers/iommu/iommufd/viommu.c
+++ b/drivers/iommu/iommufd/viommu.c
@@ -239,3 +239,11 @@  int iommufd_viommu_invalidate(struct iommufd_ucmd *ucmd)
 		return -EFAULT;
 	return rc;
 }
+
+struct iommu_domain *
+iommufd_viommu_to_parent_domain(struct iommufd_viommu *viommu)
+{
+	if (!viommu || !viommu->hwpt)
+		return NULL;
+	return viommu->hwpt->common.domain;
+}
diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h
index e0d7a53acbd5..c0ce12cb1374 100644
--- a/include/linux/iommufd.h
+++ b/include/linux/iommufd.h
@@ -91,6 +91,8 @@  int iommufd_vfio_compat_ioas_create(struct iommufd_ctx *ictx);
 int iommufd_vfio_compat_set_no_iommu(struct iommufd_ctx *ictx);
 struct device *
 iommufd_viommu_find_device(struct iommufd_viommu *viommu, u64 id);
+struct iommu_domain *
+iommufd_viommu_to_parent_domain(struct iommufd_viommu *viommu);
 #else /* !CONFIG_IOMMUFD */
 static inline struct iommufd_ctx *iommufd_ctx_from_file(struct file *file)
 {
@@ -137,5 +139,11 @@  iommufd_viommu_find_device(struct iommufd_viommu *viommu, u64 id)
 {
 	return NULL;
 }
+
+static inline struct iommu_domain *
+iommufd_viommu_to_parent_domain(struct iommufd_viommu *viommu)
+{
+	return NULL;
+}
 #endif /* CONFIG_IOMMUFD */
 #endif