iommu: Add set_platform_dma_ops callbacks
authorLu Baolu <baolu.lu@linux.intel.com>
Tue, 10 Jan 2023 02:54:06 +0000 (10:54 +0800)
committerJoerg Roedel <jroedel@suse.de>
Fri, 13 Jan 2023 15:39:16 +0000 (16:39 +0100)
For those IOMMU drivers that don't provide default domain support, add an
implementation of set_platform_dma_ops callback so that the IOMMU core
could return the DMA control to platform DMA ops. At the same time, with
the set_platform_dma_ops implemented, there is no need for detach_dev.
Remove it to avoid dead code.

Reviewed-by: Jason Gunthorpe <jgg@nvidia.com>
Signed-off-by: Lu Baolu <baolu.lu@linux.intel.com>
Link: https://lore.kernel.org/r/20230110025408.667767-4-baolu.lu@linux.intel.com
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/fsl_pamu_domain.c
drivers/iommu/msm_iommu.c
drivers/iommu/mtk_iommu_v1.c
drivers/iommu/omap-iommu.c
drivers/iommu/s390-iommu.c
drivers/iommu/tegra-gart.c
drivers/iommu/tegra-smmu.c

index 4408ac3c49b610e13a3b7158b61f7e117a917394..e123161c211a53365b407778f6d81adbad0f5ceb 100644 (file)
@@ -283,9 +283,9 @@ static int fsl_pamu_attach_device(struct iommu_domain *domain,
        return ret;
 }
 
-static void fsl_pamu_detach_device(struct iommu_domain *domain,
-                                  struct device *dev)
+static void fsl_pamu_set_platform_dma(struct device *dev)
 {
+       struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
        struct fsl_dma_domain *dma_domain = to_fsl_dma_domain(domain);
        const u32 *prop;
        int len;
@@ -452,9 +452,9 @@ static const struct iommu_ops fsl_pamu_ops = {
        .domain_alloc   = fsl_pamu_domain_alloc,
        .probe_device   = fsl_pamu_probe_device,
        .device_group   = fsl_pamu_device_group,
+       .set_platform_dma_ops = fsl_pamu_set_platform_dma;
        .default_domain_ops = &(const struct iommu_domain_ops) {
                .attach_dev     = fsl_pamu_attach_device,
-               .detach_dev     = fsl_pamu_detach_device,
                .iova_to_phys   = fsl_pamu_iova_to_phys,
                .free           = fsl_pamu_domain_free,
        }
index c60624910872c6856009c222dcf848a74199d8b8..454f6331c889799e8bb0cc3a0b147e860b438804 100644 (file)
@@ -443,9 +443,9 @@ fail:
        return ret;
 }
 
-static void msm_iommu_detach_dev(struct iommu_domain *domain,
-                                struct device *dev)
+static void msm_iommu_set_platform_dma(struct device *dev)
 {
+       struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
        struct msm_priv *priv = to_msm_priv(domain);
        unsigned long flags;
        struct msm_iommu_dev *iommu;
@@ -678,11 +678,11 @@ static struct iommu_ops msm_iommu_ops = {
        .domain_alloc = msm_iommu_domain_alloc,
        .probe_device = msm_iommu_probe_device,
        .device_group = generic_device_group,
+       .set_platform_dma_ops = msm_iommu_set_platform_dma,
        .pgsize_bitmap = MSM_IOMMU_PGSIZES,
        .of_xlate = qcom_iommu_of_xlate,
        .default_domain_ops = &(const struct iommu_domain_ops) {
                .attach_dev     = msm_iommu_attach_dev,
-               .detach_dev     = msm_iommu_detach_dev,
                .map_pages      = msm_iommu_map,
                .unmap_pages    = msm_iommu_unmap,
                /*
index 69682ee068d2bd88205c00fb12f1bfeda8dfa640..78d0a84c704f3296f5aa7420fc814601d89b76f2 100644 (file)
@@ -319,7 +319,7 @@ static int mtk_iommu_v1_attach_device(struct iommu_domain *domain, struct device
        return 0;
 }
 
-static void mtk_iommu_v1_detach_device(struct iommu_domain *domain, struct device *dev)
+static void mtk_iommu_v1_set_platform_dma(struct device *dev)
 {
        struct mtk_iommu_v1_data *data = dev_iommu_priv_get(dev);
 
@@ -585,10 +585,10 @@ static const struct iommu_ops mtk_iommu_v1_ops = {
        .def_domain_type = mtk_iommu_v1_def_domain_type,
        .device_group   = generic_device_group,
        .pgsize_bitmap  = MT2701_IOMMU_PAGE_SIZE,
+       .set_platform_dma_ops = mtk_iommu_v1_set_platform_dma,
        .owner          = THIS_MODULE,
        .default_domain_ops = &(const struct iommu_domain_ops) {
                .attach_dev     = mtk_iommu_v1_attach_device,
-               .detach_dev     = mtk_iommu_v1_detach_device,
                .map_pages      = mtk_iommu_v1_map,
                .unmap_pages    = mtk_iommu_v1_unmap,
                .iova_to_phys   = mtk_iommu_v1_iova_to_phys,
index 2fd7702c6709690a770325ac52fa890ecae7410d..3ab078112a7c76d7b387bbd63d40f9c5c9c41b5d 100644 (file)
@@ -1556,9 +1556,9 @@ static void _omap_iommu_detach_dev(struct omap_iommu_domain *omap_domain,
        omap_domain->dev = NULL;
 }
 
-static void omap_iommu_detach_dev(struct iommu_domain *domain,
-                                 struct device *dev)
+static void omap_iommu_set_platform_dma(struct device *dev)
 {
+       struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
        struct omap_iommu_domain *omap_domain = to_omap_domain(domain);
 
        spin_lock(&omap_domain->lock);
@@ -1737,10 +1737,10 @@ static const struct iommu_ops omap_iommu_ops = {
        .probe_device   = omap_iommu_probe_device,
        .release_device = omap_iommu_release_device,
        .device_group   = omap_iommu_device_group,
+       .set_platform_dma_ops = omap_iommu_set_platform_dma,
        .pgsize_bitmap  = OMAP_IOMMU_PGSIZES,
        .default_domain_ops = &(const struct iommu_domain_ops) {
                .attach_dev     = omap_iommu_attach_dev,
-               .detach_dev     = omap_iommu_detach_dev,
                .map            = omap_iommu_map,
                .unmap          = omap_iommu_unmap,
                .iova_to_phys   = omap_iommu_iova_to_phys,
index ed33c6cce0836288df998fefe5745d743c8f41c1..5591dab99446ab342d00b7c69f3ab9f35ecb9c61 100644 (file)
@@ -144,13 +144,10 @@ static int s390_iommu_attach_device(struct iommu_domain *domain,
        return 0;
 }
 
-static void s390_iommu_detach_device(struct iommu_domain *domain,
-                                    struct device *dev)
+static void s390_iommu_set_platform_dma(struct device *dev)
 {
        struct zpci_dev *zdev = to_zpci_dev(dev);
 
-       WARN_ON(zdev->s390_domain != to_s390_domain(domain));
-
        __s390_iommu_detach_device(zdev);
        zpci_dma_init_device(zdev);
 }
@@ -435,11 +432,11 @@ static const struct iommu_ops s390_iommu_ops = {
        .probe_device = s390_iommu_probe_device,
        .release_device = s390_iommu_release_device,
        .device_group = generic_device_group,
+       .set_platform_dma_ops = s390_iommu_set_platform_dma,
        .pgsize_bitmap = SZ_4K,
        .get_resv_regions = s390_iommu_get_resv_regions,
        .default_domain_ops = &(const struct iommu_domain_ops) {
                .attach_dev     = s390_iommu_attach_device,
-               .detach_dev     = s390_iommu_detach_device,
                .map_pages      = s390_iommu_map_pages,
                .unmap_pages    = s390_iommu_unmap_pages,
                .flush_iotlb_all = s390_iommu_flush_iotlb_all,
index ed53279d1106c437a3eb0dde68ff9beef7e3f3fd..a482ff838b53311e0285b84fedd265f79ac272a0 100644 (file)
@@ -124,9 +124,9 @@ static int gart_iommu_attach_dev(struct iommu_domain *domain,
        return ret;
 }
 
-static void gart_iommu_detach_dev(struct iommu_domain *domain,
-                                 struct device *dev)
+static void gart_iommu_set_platform_dma(struct device *dev)
 {
+       struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
        struct gart_device *gart = gart_handle;
 
        spin_lock(&gart->dom_lock);
@@ -270,11 +270,11 @@ static const struct iommu_ops gart_iommu_ops = {
        .domain_alloc   = gart_iommu_domain_alloc,
        .probe_device   = gart_iommu_probe_device,
        .device_group   = generic_device_group,
+       .set_platform_dma_ops = gart_iommu_set_platform_dma,
        .pgsize_bitmap  = GART_IOMMU_PGSIZES,
        .of_xlate       = gart_iommu_of_xlate,
        .default_domain_ops = &(const struct iommu_domain_ops) {
                .attach_dev     = gart_iommu_attach_dev,
-               .detach_dev     = gart_iommu_detach_dev,
                .map            = gart_iommu_map,
                .unmap          = gart_iommu_unmap,
                .iova_to_phys   = gart_iommu_iova_to_phys,
index 5b1af40221ec1490767ca990a69d44398a67c52f..4c4ac22d5fb17ea0785d802fb6d945b41b3ad629 100644 (file)
@@ -511,8 +511,9 @@ disable:
        return err;
 }
 
-static void tegra_smmu_detach_dev(struct iommu_domain *domain, struct device *dev)
+static void tegra_smmu_set_platform_dma(struct device *dev)
 {
+       struct iommu_domain *domain = iommu_get_domain_for_dev(dev);
        struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
        struct tegra_smmu_as *as = to_smmu_as(domain);
        struct tegra_smmu *smmu = as->smmu;
@@ -965,11 +966,11 @@ static const struct iommu_ops tegra_smmu_ops = {
        .domain_alloc = tegra_smmu_domain_alloc,
        .probe_device = tegra_smmu_probe_device,
        .device_group = tegra_smmu_device_group,
+       .set_platform_dma_ops = tegra_smmu_set_platform_dma,
        .of_xlate = tegra_smmu_of_xlate,
        .pgsize_bitmap = SZ_4K,
        .default_domain_ops = &(const struct iommu_domain_ops) {
                .attach_dev     = tegra_smmu_attach_dev,
-               .detach_dev     = tegra_smmu_detach_dev,
                .map            = tegra_smmu_map,
                .unmap          = tegra_smmu_unmap,
                .iova_to_phys   = tegra_smmu_iova_to_phys,