]> git.karo-electronics.de Git - linux-beck.git/commitdiff
iommu/arm-smmu: put iommu_domain pointer in dev->archdata.iommu
authorWill Deacon <will.deacon@arm.com>
Thu, 17 Jul 2014 10:23:51 +0000 (11:23 +0100)
committerWill Deacon <will.deacon@arm.com>
Tue, 16 Sep 2014 18:14:37 +0000 (19:14 +0100)
In preparation for nested translation support, stick a pointer to the
iommu_domain in dev->archdata.iommu. This makes it much easier to grab
hold of the physical group configuration (e.g. cbndx) when dealing with
vSMMU accesses from a guest.

Signed-off-by: Will Deacon <will.deacon@arm.com>
drivers/iommu/arm-smmu.c

index 38f8d670afb3e4fc01d77ec7cf74b805ee18fee6..e8d3111522037ddac70bdb898b16ba1b36b4039f 100644 (file)
@@ -1213,6 +1213,11 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
                return -ENXIO;
        }
 
+       if (dev->archdata.iommu) {
+               dev_err(dev, "already attached to IOMMU domain\n");
+               return -EEXIST;
+       }
+
        /*
         * Sanity check the domain. We don't support domains across
         * different SMMUs.
@@ -1239,7 +1244,10 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
        if (!cfg)
                return -ENODEV;
 
-       return arm_smmu_domain_add_master(smmu_domain, cfg);
+       ret = arm_smmu_domain_add_master(smmu_domain, cfg);
+       if (!ret)
+               dev->archdata.iommu = domain;
+       return ret;
 }
 
 static void arm_smmu_detach_dev(struct iommu_domain *domain, struct device *dev)
@@ -1248,8 +1256,11 @@ static void arm_smmu_detach_dev(struct iommu_domain *domain, struct device *dev)
        struct arm_smmu_master_cfg *cfg;
 
        cfg = find_smmu_master_cfg(dev);
-       if (cfg)
-               arm_smmu_domain_remove_master(smmu_domain, cfg);
+       if (!cfg)
+               return;
+
+       dev->archdata.iommu = NULL;
+       arm_smmu_domain_remove_master(smmu_domain, cfg);
 }
 
 static bool arm_smmu_pte_is_contiguous_range(unsigned long addr,