Today, the iommu layer gets the max_pasids by pci_max_pasids() or reading the "pasid-num-bits" property. This requires the non-PCI devices to have a "pasid-num-bits" property. Like the mock device used in iommufd selftest, otherwise the max_pasids check would fail in iommu layer. While there is an alternative, the iommu layer can allow the iommu driver to set the max_pasids in its probe_device() callback and populate it. This is simpler and has no impact on the existing cases. Suggested-by: Jason Gunthorpe <jgg@xxxxxxxxxx> Signed-off-by: Yi Liu <yi.l.liu@xxxxxxxxx> --- drivers/iommu/iommu.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c index 343683e646e0..dc85c251237f 100644 --- a/drivers/iommu/iommu.c +++ b/drivers/iommu/iommu.c @@ -368,9 +368,9 @@ static bool dev_has_iommu(struct device *dev) return dev->iommu && dev->iommu->iommu_dev; } -static u32 dev_iommu_get_max_pasids(struct device *dev) +static void dev_iommu_set_max_pasids(struct device *dev) { - u32 max_pasids = 0, bits = 0; + u32 max_pasids = dev->iommu->max_pasids, bits = 0; int ret; if (dev_is_pci(dev)) { @@ -383,7 +383,8 @@ static u32 dev_iommu_get_max_pasids(struct device *dev) max_pasids = 1UL << bits; } - return min_t(u32, max_pasids, dev->iommu->iommu_dev->max_pasids); + dev->iommu->max_pasids = min_t(u32, max_pasids, + dev->iommu->iommu_dev->max_pasids); } void dev_iommu_priv_set(struct device *dev, void *priv) @@ -433,7 +434,7 @@ static int iommu_init_device(struct device *dev, const struct iommu_ops *ops) } dev->iommu_group = group; - dev->iommu->max_pasids = dev_iommu_get_max_pasids(dev); + dev_iommu_set_max_pasids(dev); if (ops->is_attach_deferred) dev->iommu->attach_deferred = ops->is_attach_deferred(dev); return 0; -- 2.34.1