Skip to content

Commit ec56016

Browse files
AngeloGioacchino Del Regnowilldeacon
authored andcommitted
iommu/qcom: Index contexts by asid number to allow asid 0
This driver was indexing the contexts by asid-1, which is probably done under the assumption that the first ASID is always 1. Unfortunately this is not always true: at least for MSM8956 and MSM8976's GPU IOMMU, the gpu_user context's ASID number is zero. To allow using a zero asid number, index the contexts by `asid` instead of by `asid - 1`. While at it, also enhance human readability by renaming the `num_ctxs` member of struct qcom_iommu_dev to `max_asid`. Signed-off-by: AngeloGioacchino Del Regno <[email protected]> Reviewed-by: Konrad Dybcio <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent 9f3fef2 commit ec56016

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

drivers/iommu/arm/arm-smmu/qcom_iommu.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ struct qcom_iommu_dev {
5151
struct clk_bulk_data clks[CLK_NUM];
5252
void __iomem *local_base;
5353
u32 sec_id;
54-
u8 num_ctxs;
55-
struct qcom_iommu_ctx *ctxs[]; /* indexed by asid-1 */
54+
u8 max_asid;
55+
struct qcom_iommu_ctx *ctxs[]; /* indexed by asid */
5656
};
5757

5858
struct qcom_iommu_ctx {
@@ -94,7 +94,7 @@ static struct qcom_iommu_ctx * to_ctx(struct qcom_iommu_domain *d, unsigned asid
9494
struct qcom_iommu_dev *qcom_iommu = d->iommu;
9595
if (!qcom_iommu)
9696
return NULL;
97-
return qcom_iommu->ctxs[asid - 1];
97+
return qcom_iommu->ctxs[asid];
9898
}
9999

100100
static inline void
@@ -534,12 +534,10 @@ static int qcom_iommu_of_xlate(struct device *dev, struct of_phandle_args *args)
534534
qcom_iommu = platform_get_drvdata(iommu_pdev);
535535

536536
/* make sure the asid specified in dt is valid, so we don't have
537-
* to sanity check this elsewhere, since 'asid - 1' is used to
538-
* index into qcom_iommu->ctxs:
537+
* to sanity check this elsewhere:
539538
*/
540-
if (WARN_ON(asid < 1) ||
541-
WARN_ON(asid > qcom_iommu->num_ctxs) ||
542-
WARN_ON(qcom_iommu->ctxs[asid - 1] == NULL)) {
539+
if (WARN_ON(asid > qcom_iommu->max_asid) ||
540+
WARN_ON(qcom_iommu->ctxs[asid] == NULL)) {
543541
put_device(&iommu_pdev->dev);
544542
return -EINVAL;
545543
}
@@ -694,7 +692,7 @@ static int qcom_iommu_ctx_probe(struct platform_device *pdev)
694692

695693
dev_dbg(dev, "found asid %u\n", ctx->asid);
696694

697-
qcom_iommu->ctxs[ctx->asid - 1] = ctx;
695+
qcom_iommu->ctxs[ctx->asid] = ctx;
698696

699697
return 0;
700698
}
@@ -706,7 +704,7 @@ static void qcom_iommu_ctx_remove(struct platform_device *pdev)
706704

707705
platform_set_drvdata(pdev, NULL);
708706

709-
qcom_iommu->ctxs[ctx->asid - 1] = NULL;
707+
qcom_iommu->ctxs[ctx->asid] = NULL;
710708
}
711709

712710
static const struct of_device_id ctx_of_match[] = {
@@ -753,11 +751,11 @@ static int qcom_iommu_device_probe(struct platform_device *pdev)
753751
for_each_child_of_node(dev->of_node, child)
754752
max_asid = max(max_asid, get_asid(child));
755753

756-
qcom_iommu = devm_kzalloc(dev, struct_size(qcom_iommu, ctxs, max_asid),
754+
qcom_iommu = devm_kzalloc(dev, struct_size(qcom_iommu, ctxs, max_asid + 1),
757755
GFP_KERNEL);
758756
if (!qcom_iommu)
759757
return -ENOMEM;
760-
qcom_iommu->num_ctxs = max_asid;
758+
qcom_iommu->max_asid = max_asid;
761759
qcom_iommu->dev = dev;
762760

763761
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);

0 commit comments

Comments
 (0)