aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/iommu/arm-smmu.c
diff options
context:
space:
mode:
authorWill Deacon <will.deacon@arm.com>2016-02-17 12:41:57 -0500
committerWill Deacon <will.deacon@arm.com>2016-02-18 10:02:44 -0500
commitbc7f2ce0a7b54ba7703f81995fe434f0926424d2 (patch)
tree1e27c323f9c3becd069a36abb54ff2fb2ca7d93b /drivers/iommu/arm-smmu.c
parent25a1c96cd22c949b50d6f0269c23e1c5cb55e5a5 (diff)
iommu/arm-smmu: Don't fail device attach if already attached to a domain
The ARM SMMU attach_dev implementations returns -EEXIST if the device being attached is already attached to a domain. This doesn't play nicely with the default domain, resulting in splats such as: WARNING: at drivers/iommu/iommu.c:1257 Modules linked in: CPU: 3 PID: 1939 Comm: virtio-net-tx Tainted: G S 4.5.0-rc4+ #1 Hardware name: FVP Base (DT) task: ffffffc87a9d0000 ti: ffffffc07a278000 task.ti: ffffffc07a278000 PC is at __iommu_detach_group+0x68/0xe8 LR is at __iommu_detach_group+0x48/0xe8 This patch fixes the problem by forcefully detaching the device from its old domain, if present, when attaching to a new one. The unused ->detach_dev callback is also removed the iommu_ops structures. Signed-off-by: Will Deacon <will.deacon@arm.com>
Diffstat (limited to 'drivers/iommu/arm-smmu.c')
-rw-r--r--drivers/iommu/arm-smmu.c33
1 files changed, 14 insertions, 19 deletions
diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
index 7012531abe62..f21332a15040 100644
--- a/drivers/iommu/arm-smmu.c
+++ b/drivers/iommu/arm-smmu.c
@@ -1131,6 +1131,16 @@ static void arm_smmu_domain_remove_master(struct arm_smmu_domain *smmu_domain,
1131 arm_smmu_master_free_smrs(smmu, cfg); 1131 arm_smmu_master_free_smrs(smmu, cfg);
1132} 1132}
1133 1133
1134static void arm_smmu_detach_dev(struct device *dev,
1135 struct arm_smmu_master_cfg *cfg)
1136{
1137 struct iommu_domain *domain = dev->archdata.iommu;
1138 struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
1139
1140 dev->archdata.iommu = NULL;
1141 arm_smmu_domain_remove_master(smmu_domain, cfg);
1142}
1143
1134static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev) 1144static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
1135{ 1145{
1136 int ret; 1146 int ret;
@@ -1144,11 +1154,6 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
1144 return -ENXIO; 1154 return -ENXIO;
1145 } 1155 }
1146 1156
1147 if (dev->archdata.iommu) {
1148 dev_err(dev, "already attached to IOMMU domain\n");
1149 return -EEXIST;
1150 }
1151
1152 /* Ensure that the domain is finalised */ 1157 /* Ensure that the domain is finalised */
1153 ret = arm_smmu_init_domain_context(domain, smmu); 1158 ret = arm_smmu_init_domain_context(domain, smmu);
1154 if (IS_ERR_VALUE(ret)) 1159 if (IS_ERR_VALUE(ret))
@@ -1170,25 +1175,16 @@ static int arm_smmu_attach_dev(struct iommu_domain *domain, struct device *dev)
1170 if (!cfg) 1175 if (!cfg)
1171 return -ENODEV; 1176 return -ENODEV;
1172 1177
1178 /* Detach the dev from its current domain */
1179 if (dev->archdata.iommu)
1180 arm_smmu_detach_dev(dev, cfg);
1181
1173 ret = arm_smmu_domain_add_master(smmu_domain, cfg); 1182 ret = arm_smmu_domain_add_master(smmu_domain, cfg);
1174 if (!ret) 1183 if (!ret)
1175 dev->archdata.iommu = domain; 1184 dev->archdata.iommu = domain;
1176 return ret; 1185 return ret;
1177} 1186}
1178 1187
1179static void arm_smmu_detach_dev(struct iommu_domain *domain, struct device *dev)
1180{
1181 struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
1182 struct arm_smmu_master_cfg *cfg;
1183
1184 cfg = find_smmu_master_cfg(dev);
1185 if (!cfg)
1186 return;
1187
1188 dev->archdata.iommu = NULL;
1189 arm_smmu_domain_remove_master(smmu_domain, cfg);
1190}
1191
1192static int arm_smmu_map(struct iommu_domain *domain, unsigned long iova, 1188static int arm_smmu_map(struct iommu_domain *domain, unsigned long iova,
1193 phys_addr_t paddr, size_t size, int prot) 1189 phys_addr_t paddr, size_t size, int prot)
1194{ 1190{
@@ -1464,7 +1460,6 @@ static struct iommu_ops arm_smmu_ops = {
1464 .domain_alloc = arm_smmu_domain_alloc, 1460 .domain_alloc = arm_smmu_domain_alloc,
1465 .domain_free = arm_smmu_domain_free, 1461 .domain_free = arm_smmu_domain_free,
1466 .attach_dev = arm_smmu_attach_dev, 1462 .attach_dev = arm_smmu_attach_dev,
1467 .detach_dev = arm_smmu_detach_dev,
1468 .map = arm_smmu_map, 1463 .map = arm_smmu_map,
1469 .unmap = arm_smmu_unmap, 1464 .unmap = arm_smmu_unmap,
1470 .map_sg = default_iommu_map_sg, 1465 .map_sg = default_iommu_map_sg,