iommu: arm-smmu: Fix dynamic domain context bank assignment
Fix an issue where the context bank for a dynamic domain is always set
to 0xFF. The expected call flow is:
0) iommu_domain_alloc()
1) iommu_domain_set_attr(DOMAIN_ATTR_DYNAMIC)
2) iommu_domain_set_attr(DOMAIN_ATTR_CONTEXT_BANK)
3) iommu_attach_device/group()
Change-Id: I134c2fdbea9d9efc7306d7dbe03abb5dae431371
Signed-off-by: Patrick Daly <pdaly@codeaurora.org>
diff --git a/drivers/iommu/arm-smmu.c b/drivers/iommu/arm-smmu.c
index 1d5c514..e7189ab 100644
--- a/drivers/iommu/arm-smmu.c
+++ b/drivers/iommu/arm-smmu.c
@@ -3298,14 +3298,23 @@
struct device *dev)
{
struct iommu_fwspec *fwspec = dev->iommu_fwspec;
+ struct arm_smmu_domain *smmu_domain = to_smmu_domain(domain);
u32 i, idx;
int cb = -EINVAL;
bool dynamic;
- /* Dynamic domains must set cbndx through domain attribute */
+ /*
+ * Dynamic domains have already set cbndx through domain attribute.
+ * Verify that they picked a valid value.
+ */
dynamic = is_dynamic_domain(domain);
- if (dynamic)
- return INVALID_CBNDX;
+ if (dynamic) {
+ cb = smmu_domain->cfg.cbndx;
+ if (cb < smmu->num_context_banks)
+ return cb;
+ else
+ return -EINVAL;
+ }
mutex_lock(&smmu->stream_map_mutex);
for_each_cfg_sme(fwspec, i, idx) {