Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

iommu: Streamline registration interface

Rather than have separate opaque setter functions that are easy to
overlook and lead to repetitive boilerplate in drivers, let's pass the
relevant initialisation parameters directly to iommu_device_register().

Acked-by: Will Deacon <will@kernel.org>
Signed-off-by: Robin Murphy <robin.murphy@arm.com>
Link: https://lore.kernel.org/r/ab001b87c533b6f4db71eb90db6f888953986c36.1617285386.git.robin.murphy@arm.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>

authored by

Robin Murphy and committed by
Joerg Roedel
2d471b20 c0aec668

+44 -98
+1 -2
drivers/iommu/amd/init.c
··· 1888 1888 1889 1889 iommu_device_sysfs_add(&iommu->iommu, &iommu->dev->dev, 1890 1890 amd_iommu_groups, "ivhd%d", iommu->index); 1891 - iommu_device_set_ops(&iommu->iommu, &amd_iommu_ops); 1892 - iommu_device_register(&iommu->iommu); 1891 + iommu_device_register(&iommu->iommu, &amd_iommu_ops, NULL); 1893 1892 1894 1893 return pci_enable_device(iommu->dev); 1895 1894 }
+1 -4
drivers/iommu/arm/arm-smmu-v3/arm-smmu-v3.c
··· 3666 3666 if (ret) 3667 3667 return ret; 3668 3668 3669 - iommu_device_set_ops(&smmu->iommu, &arm_smmu_ops); 3670 - iommu_device_set_fwnode(&smmu->iommu, dev->fwnode); 3671 - 3672 - ret = iommu_device_register(&smmu->iommu); 3669 + ret = iommu_device_register(&smmu->iommu, &arm_smmu_ops, dev); 3673 3670 if (ret) { 3674 3671 dev_err(dev, "Failed to register iommu\n"); 3675 3672 return ret;
+1 -4
drivers/iommu/arm/arm-smmu/arm-smmu.c
··· 2161 2161 return err; 2162 2162 } 2163 2163 2164 - iommu_device_set_ops(&smmu->iommu, &arm_smmu_ops); 2165 - iommu_device_set_fwnode(&smmu->iommu, dev->fwnode); 2166 - 2167 - err = iommu_device_register(&smmu->iommu); 2164 + err = iommu_device_register(&smmu->iommu, &arm_smmu_ops, dev); 2168 2165 if (err) { 2169 2166 dev_err(dev, "Failed to register iommu\n"); 2170 2167 return err;
+1 -4
drivers/iommu/arm/arm-smmu/qcom_iommu.c
··· 847 847 return ret; 848 848 } 849 849 850 - iommu_device_set_ops(&qcom_iommu->iommu, &qcom_iommu_ops); 851 - iommu_device_set_fwnode(&qcom_iommu->iommu, dev->fwnode); 852 - 853 - ret = iommu_device_register(&qcom_iommu->iommu); 850 + ret = iommu_device_register(&qcom_iommu->iommu, &qcom_iommu_ops, dev); 854 851 if (ret) { 855 852 dev_err(dev, "Failed to register iommu\n"); 856 853 return ret;
+1 -4
drivers/iommu/exynos-iommu.c
··· 630 630 if (ret) 631 631 return ret; 632 632 633 - iommu_device_set_ops(&data->iommu, &exynos_iommu_ops); 634 - iommu_device_set_fwnode(&data->iommu, &dev->of_node->fwnode); 635 - 636 - ret = iommu_device_register(&data->iommu); 633 + ret = iommu_device_register(&data->iommu, &exynos_iommu_ops, dev); 637 634 if (ret) 638 635 return ret; 639 636
+1 -3
drivers/iommu/fsl_pamu_domain.c
··· 474 474 if (ret) 475 475 return ret; 476 476 477 - iommu_device_set_ops(&pamu_iommu, &fsl_pamu_ops); 478 - 479 - ret = iommu_device_register(&pamu_iommu); 477 + ret = iommu_device_register(&pamu_iommu, &fsl_pamu_ops, NULL); 480 478 if (ret) { 481 479 iommu_device_sysfs_remove(&pamu_iommu); 482 480 pr_err("Can't register iommu device\n");
+1 -3
drivers/iommu/intel/dmar.c
··· 1140 1140 if (err) 1141 1141 goto err_unmap; 1142 1142 1143 - iommu_device_set_ops(&iommu->iommu, &intel_iommu_ops); 1144 - 1145 - err = iommu_device_register(&iommu->iommu); 1143 + err = iommu_device_register(&iommu->iommu, &intel_iommu_ops, NULL); 1146 1144 if (err) 1147 1145 goto err_unmap; 1148 1146 }
+1 -2
drivers/iommu/intel/iommu.c
··· 4396 4396 iommu_device_sysfs_add(&iommu->iommu, NULL, 4397 4397 intel_iommu_groups, 4398 4398 "%s", iommu->name); 4399 - iommu_device_set_ops(&iommu->iommu, &intel_iommu_ops); 4400 - iommu_device_register(&iommu->iommu); 4399 + iommu_device_register(&iommu->iommu, &intel_iommu_ops, NULL); 4401 4400 } 4402 4401 up_read(&dmar_global_lock); 4403 4402
+18 -1
drivers/iommu/iommu.c
··· 142 142 } 143 143 subsys_initcall(iommu_subsys_init); 144 144 145 - int iommu_device_register(struct iommu_device *iommu) 145 + /** 146 + * iommu_device_register() - Register an IOMMU hardware instance 147 + * @iommu: IOMMU handle for the instance 148 + * @ops: IOMMU ops to associate with the instance 149 + * @hwdev: (optional) actual instance device, used for fwnode lookup 150 + * 151 + * Return: 0 on success, or an error. 152 + */ 153 + int iommu_device_register(struct iommu_device *iommu, 154 + const struct iommu_ops *ops, struct device *hwdev) 146 155 { 156 + /* We need to be able to take module references appropriately */ 157 + if (WARN_ON(is_module_address((unsigned long)ops) && !ops->owner)) 158 + return -EINVAL; 159 + 160 + iommu->ops = ops; 161 + if (hwdev) 162 + iommu->fwnode = hwdev->fwnode; 163 + 147 164 spin_lock(&iommu_device_lock); 148 165 list_add_tail(&iommu->list, &iommu_device_list); 149 166 spin_unlock(&iommu_device_lock);
+1 -5
drivers/iommu/ipmmu-vmsa.c
··· 1076 1076 if (ret) 1077 1077 return ret; 1078 1078 1079 - iommu_device_set_ops(&mmu->iommu, &ipmmu_ops); 1080 - iommu_device_set_fwnode(&mmu->iommu, 1081 - &pdev->dev.of_node->fwnode); 1082 - 1083 - ret = iommu_device_register(&mmu->iommu); 1079 + ret = iommu_device_register(&mmu->iommu, &ipmmu_ops, &pdev->dev); 1084 1080 if (ret) 1085 1081 return ret; 1086 1082
+1 -4
drivers/iommu/msm_iommu.c
··· 792 792 goto fail; 793 793 } 794 794 795 - iommu_device_set_ops(&iommu->iommu, &msm_iommu_ops); 796 - iommu_device_set_fwnode(&iommu->iommu, &pdev->dev.of_node->fwnode); 797 - 798 - ret = iommu_device_register(&iommu->iommu); 795 + ret = iommu_device_register(&iommu->iommu, &msm_iommu_ops, &pdev->dev); 799 796 if (ret) { 800 797 pr_err("Could not register msm-smmu at %pa\n", &ioaddr); 801 798 goto fail;
+1 -4
drivers/iommu/mtk_iommu.c
··· 892 892 if (ret) 893 893 goto out_link_remove; 894 894 895 - iommu_device_set_ops(&data->iommu, &mtk_iommu_ops); 896 - iommu_device_set_fwnode(&data->iommu, &pdev->dev.of_node->fwnode); 897 - 898 - ret = iommu_device_register(&data->iommu); 895 + ret = iommu_device_register(&data->iommu, &mtk_iommu_ops, dev); 899 896 if (ret) 900 897 goto out_sysfs_remove; 901 898
+1 -3
drivers/iommu/mtk_iommu_v1.c
··· 616 616 if (ret) 617 617 return ret; 618 618 619 - iommu_device_set_ops(&data->iommu, &mtk_iommu_ops); 620 - 621 - ret = iommu_device_register(&data->iommu); 619 + ret = iommu_device_register(&data->iommu, &mtk_iommu_ops, dev); 622 620 if (ret) 623 621 goto out_sysfs_remove; 624 622
+1 -4
drivers/iommu/omap-iommu.c
··· 1235 1235 if (err) 1236 1236 goto out_group; 1237 1237 1238 - iommu_device_set_ops(&obj->iommu, &omap_iommu_ops); 1239 - iommu_device_set_fwnode(&obj->iommu, &of->fwnode); 1240 - 1241 - err = iommu_device_register(&obj->iommu); 1238 + err = iommu_device_register(&obj->iommu, &omap_iommu_ops, &pdev->dev); 1242 1239 if (err) 1243 1240 goto out_sysfs; 1244 1241 }
+1 -4
drivers/iommu/rockchip-iommu.c
··· 1196 1196 if (err) 1197 1197 goto err_put_group; 1198 1198 1199 - iommu_device_set_ops(&iommu->iommu, &rk_iommu_ops); 1200 - iommu_device_set_fwnode(&iommu->iommu, &dev->of_node->fwnode); 1201 - 1202 - err = iommu_device_register(&iommu->iommu); 1199 + err = iommu_device_register(&iommu->iommu, &rk_iommu_ops, dev); 1203 1200 if (err) 1204 1201 goto err_remove_sysfs; 1205 1202
+1 -3
drivers/iommu/s390-iommu.c
··· 333 333 if (rc) 334 334 goto out_err; 335 335 336 - iommu_device_set_ops(&zdev->iommu_dev, &s390_iommu_ops); 337 - 338 - rc = iommu_device_register(&zdev->iommu_dev); 336 + rc = iommu_device_register(&zdev->iommu_dev, &s390_iommu_ops, NULL); 339 337 if (rc) 340 338 goto out_sysfs; 341 339
+1 -4
drivers/iommu/sprd-iommu.c
··· 508 508 if (ret) 509 509 goto put_group; 510 510 511 - iommu_device_set_ops(&sdev->iommu, &sprd_iommu_ops); 512 - iommu_device_set_fwnode(&sdev->iommu, &dev->of_node->fwnode); 513 - 514 - ret = iommu_device_register(&sdev->iommu); 511 + ret = iommu_device_register(&sdev->iommu, &sprd_iommu_ops, dev); 515 512 if (ret) 516 513 goto remove_sysfs; 517 514
+1 -4
drivers/iommu/sun50i-iommu.c
··· 968 968 if (ret) 969 969 goto err_free_group; 970 970 971 - iommu_device_set_ops(&iommu->iommu, &sun50i_iommu_ops); 972 - iommu_device_set_fwnode(&iommu->iommu, &pdev->dev.of_node->fwnode); 973 - 974 - ret = iommu_device_register(&iommu->iommu); 971 + ret = iommu_device_register(&iommu->iommu, &sun50i_iommu_ops, &pdev->dev); 975 972 if (ret) 976 973 goto err_remove_sysfs; 977 974
+1 -4
drivers/iommu/tegra-gart.c
··· 353 353 if (err) 354 354 goto free_gart; 355 355 356 - iommu_device_set_ops(&gart->iommu, &gart_iommu_ops); 357 - iommu_device_set_fwnode(&gart->iommu, dev->fwnode); 358 - 359 - err = iommu_device_register(&gart->iommu); 356 + err = iommu_device_register(&gart->iommu, &gart_iommu_ops, dev); 360 357 if (err) 361 358 goto remove_sysfs; 362 359
+1 -4
drivers/iommu/tegra-smmu.c
··· 1145 1145 if (err) 1146 1146 return ERR_PTR(err); 1147 1147 1148 - iommu_device_set_ops(&smmu->iommu, &tegra_smmu_ops); 1149 - iommu_device_set_fwnode(&smmu->iommu, dev->fwnode); 1150 - 1151 - err = iommu_device_register(&smmu->iommu); 1148 + err = iommu_device_register(&smmu->iommu, &tegra_smmu_ops, dev); 1152 1149 if (err) 1153 1150 goto remove_sysfs; 1154 1151
+1 -4
drivers/iommu/virtio-iommu.c
··· 1066 1066 if (ret) 1067 1067 goto err_free_vqs; 1068 1068 1069 - iommu_device_set_ops(&viommu->iommu, &viommu_ops); 1070 - iommu_device_set_fwnode(&viommu->iommu, parent_dev->fwnode); 1071 - 1072 - iommu_device_register(&viommu->iommu); 1069 + iommu_device_register(&viommu->iommu, &viommu_ops, parent_dev); 1073 1070 1074 1071 #ifdef CONFIG_PCI 1075 1072 if (pci_bus_type.iommu_ops != &viommu_ops) {
+6 -24
include/linux/iommu.h
··· 350 350 void *priv; 351 351 }; 352 352 353 - int iommu_device_register(struct iommu_device *iommu); 353 + int iommu_device_register(struct iommu_device *iommu, 354 + const struct iommu_ops *ops, 355 + struct device *hwdev); 354 356 void iommu_device_unregister(struct iommu_device *iommu); 355 357 int iommu_device_sysfs_add(struct iommu_device *iommu, 356 358 struct device *parent, ··· 362 360 int iommu_device_link(struct iommu_device *iommu, struct device *link); 363 361 void iommu_device_unlink(struct iommu_device *iommu, struct device *link); 364 362 int iommu_deferred_attach(struct device *dev, struct iommu_domain *domain); 365 - 366 - static inline void iommu_device_set_ops(struct iommu_device *iommu, 367 - const struct iommu_ops *ops) 368 - { 369 - iommu->ops = ops; 370 - } 371 - 372 - static inline void iommu_device_set_fwnode(struct iommu_device *iommu, 373 - struct fwnode_handle *fwnode) 374 - { 375 - iommu->fwnode = fwnode; 376 - } 377 363 378 364 static inline struct iommu_device *dev_to_iommu_device(struct device *dev) 379 365 { ··· 848 858 return 0; 849 859 } 850 860 851 - static inline int iommu_device_register(struct iommu_device *iommu) 861 + static inline int iommu_device_register(struct iommu_device *iommu, 862 + const struct iommu_ops *ops, 863 + struct device *hwdev) 852 864 { 853 865 return -ENODEV; 854 - } 855 - 856 - static inline void iommu_device_set_ops(struct iommu_device *iommu, 857 - const struct iommu_ops *ops) 858 - { 859 - } 860 - 861 - static inline void iommu_device_set_fwnode(struct iommu_device *iommu, 862 - struct fwnode_handle *fwnode) 863 - { 864 866 } 865 867 866 868 static inline struct iommu_device *dev_to_iommu_device(struct device *dev)