Skip to content

Commit c747e67

Browse files
nicolincjgunthorpe
authored andcommitted
iommufd/viommu: Add iommufd_viommu_find_dev helper
This avoids a bigger trouble of exposing struct iommufd_device and struct iommufd_vdevice in the public header. Link: https://patch.msgid.link/r/84fa7c624db4d4508067ccfdf42059533950180a.1730836308.git.nicolinc@nvidia.com Reviewed-by: Kevin Tian <[email protected]> Reviewed-by: Jason Gunthorpe <[email protected]> Signed-off-by: Nicolin Chen <[email protected]> Signed-off-by: Jason Gunthorpe <[email protected]>
1 parent 4f2e59c commit c747e67

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

drivers/iommu/iommufd/driver.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,18 @@ struct iommufd_object *_iommufd_object_alloc(struct iommufd_ctx *ictx,
3636
}
3737
EXPORT_SYMBOL_NS_GPL(_iommufd_object_alloc, IOMMUFD);
3838

39+
/* Caller should xa_lock(&viommu->vdevs) to protect the return value */
40+
struct device *iommufd_viommu_find_dev(struct iommufd_viommu *viommu,
41+
unsigned long vdev_id)
42+
{
43+
struct iommufd_vdevice *vdev;
44+
45+
lockdep_assert_held(&viommu->vdevs.xa_lock);
46+
47+
vdev = xa_load(&viommu->vdevs, vdev_id);
48+
return vdev ? vdev->dev : NULL;
49+
}
50+
EXPORT_SYMBOL_NS_GPL(iommufd_viommu_find_dev, IOMMUFD);
51+
3952
MODULE_DESCRIPTION("iommufd code shared with builtin modules");
4053
MODULE_LICENSE("GPL");

include/linux/iommufd.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,13 +185,21 @@ static inline int iommufd_vfio_compat_set_no_iommu(struct iommufd_ctx *ictx)
185185
struct iommufd_object *_iommufd_object_alloc(struct iommufd_ctx *ictx,
186186
size_t size,
187187
enum iommufd_object_type type);
188+
struct device *iommufd_viommu_find_dev(struct iommufd_viommu *viommu,
189+
unsigned long vdev_id);
188190
#else /* !CONFIG_IOMMUFD_DRIVER_CORE */
189191
static inline struct iommufd_object *
190192
_iommufd_object_alloc(struct iommufd_ctx *ictx, size_t size,
191193
enum iommufd_object_type type)
192194
{
193195
return ERR_PTR(-EOPNOTSUPP);
194196
}
197+
198+
static inline struct device *
199+
iommufd_viommu_find_dev(struct iommufd_viommu *viommu, unsigned long vdev_id)
200+
{
201+
return NULL;
202+
}
195203
#endif /* CONFIG_IOMMUFD_DRIVER_CORE */
196204

197205
/*

0 commit comments

Comments
 (0)