[PATCH v1 09/16] iommufd/viommu: Make iommufd_viommu_find_device a public API

Nicolin Chen
2024-08-07T20:11:39Z

Now, an IOMMU driver can use viommu to invalidate a device cache via the
viommu_cache_invalidate op. Very likely, this would require the driver to
lookup a virtual device ID for a physical device (or just its ID). Since
the core already has a helper, make it public.

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

diff --git a/drivers/iommu/iommufd/viommu.c b/drivers/iommu/iommufd/viommu.c
index ada9f968b9f6..2304f199b033 100644
--- a/drivers/iommu/iommufd/viommu.c
+++ b/drivers/iommu/iommufd/viommu.c
@@ -148,7 +148,7 @@ int iommufd_viommu_set_vdev_id(struct iommufd_ucmd *ucmd)
return rc;
}

-static struct device *
+struct device *
iommufd_viommu_find_device(struct iommufd_viommu *viommu, u64 id)
{
struct iommufd_vdev_id *vdev_id;
diff --git a/include/linux/iommufd.h b/include/linux/iommufd.h
index 7da5140fa1b0..e0d7a53acbd5 100644
--- a/include/linux/iommufd.h
+++ b/include/linux/iommufd.h
@@ -89,6 +89,8 @@ int iommufd_access_rw(struct iommufd_access *access, unsigned long iova,
int iommufd_vfio_compat_ioas_get_id(struct iommufd_ctx *ictx, u32 *out_ioas_id);
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);
#else /* !CONFIG_IOMMUFD */
static inline struct iommufd_ctx *iommufd_ctx_from_file(struct file *file)
{
@@ -129,5 +131,11 @@ static inline int iommufd_vfio_compat_set_no_iommu(struct iommufd_ctx *ictx)
{
return -EOPNOTSUPP;
}
+
+static inline struct device *
+iommufd_viommu_find_device(struct iommufd_viommu *viommu, u64 id)
+{
+ return NULL;
+}
#endif /* CONFIG_IOMMUFD */
#endif
--
2.43.0