From patchwork Fri Nov 11 14:59:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 18871 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp790150wru; Fri, 11 Nov 2022 07:02:40 -0800 (PST) X-Google-Smtp-Source: AA0mqf4IrmZ3don657KqhAECZnvumkqTbYf7Dvc21/Kv3g9y4F3VjyXpdQeP2ADu9HdOFllUUN/Y X-Received: by 2002:a17:907:d091:b0:78e:11ea:852e with SMTP id vc17-20020a170907d09100b0078e11ea852emr2264560ejc.183.1668178959885; Fri, 11 Nov 2022 07:02:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668178959; cv=none; d=google.com; s=arc-20160816; b=Jms8nO0Ws4/XtGSd+Xg2JNQKLc/Y5VXVAE/tWhUw54A/yiQhcd4cv1OmusAIANfGaO SFzHSF4MWMAGeNng/sUR7Gx3pX2JEEbaeJBho8QahEHp3r+At87IWrjD1Ke62yNDaxt/ CWjD1lOi7GUQ9Bo6KKyKT9vuWZJLyo1auGEuwWwrlYN2uaY6gn+QkOIbyalZhsbW3wcM gWt4yBkUPo39ujX4INJfslUGNVbvggdK9xfEOyVnSoERy7T3ayo2gG+BjNchH/jTAGSr tmMMvfANq6ZuCpuuMitLu9SACu5WMFVSUO+G0bCHMLWOa8BqzQXXvAKokpPp9FX4bNZ4 f0Ng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=rNJRFw6AnDd4epmr97/KmjVOVTLbs6ewwE3YPdKB3yQ=; b=WgZ8xI2QVKn11opDe4JFVHgLM2EqaSqcbZuBSVPY0MJVIm82EWI/0lszMbRH9KW8j/ h+x6NOoBZnC2YwfUIIrNMmiY+ObTFuocNXdNLpMTCkeuZX+zneQOF2T0xvUFDgGheNNR Lux4orAouSRrkDIO4t2z2anY+Q406Y09aafQGHNhjKfITPDASg/NYb8DxkLjrRUA1G1j llvRlK4npimGCKmKaolEEzCWdeOK/glcDbMeJbiEJCfS6zpntrB+LHspUbdKJeLIyBd/ PgIN1GiZ/E2BOzFlJS1RY1aXvqkxci95d1BkbnWHDHjjtfeDdWD3bY9XzmwyWkT8Kr72 4mqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=LRUOTRGO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id sh32-20020a1709076ea000b007adbe7695a5si2384232ejc.935.2022.11.11.07.02.09; Fri, 11 Nov 2022 07:02:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=LRUOTRGO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234874AbiKKPA3 (ORCPT + 99 others); Fri, 11 Nov 2022 10:00:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59804 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234821AbiKKO7b (ORCPT ); Fri, 11 Nov 2022 09:59:31 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 13F4763BA5; Fri, 11 Nov 2022 06:59:30 -0800 (PST) Received: from IcarusMOD.eternityproject.eu (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id E33896602A58; Fri, 11 Nov 2022 14:59:27 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1668178768; bh=JcV01OqQI7OdtwJTtMaesEof4OedrSHFsOnwvt1LCKw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=LRUOTRGO0uBnM8bPfeMDf0RIaTYPy1DIRPgczuBYj4PdtZ824iTT86trL0ve86ylM JggF9OamOyqMeUqyZhRyaM5jHwoHvXr6Ur7eHUUI8Oiord9SoYP7BJm18qE/C1AV+Z zRc/uPyI0OvgLrP1up2zxIAmcChju+he4wL+e7NuF3WVG5wxaYYQzN2aacupkkPZWK BPSxGM27H8MFABoCPYNg4I/bKdWdBjNGX8ZdDDdVCFoGxh8JIlBSuUX8AgsTz5JS9V JpLD948++zXnahTwhzNdbkSs/SSSM6YcSiKgXkvonmm0OqSjwWftKiNkrO4Oa3jFIi Awk9q8+pSzcug== From: AngeloGioacchino Del Regno To: agross@kernel.org Cc: andersson@kernel.org, konrad.dybcio@linaro.org, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, robdclark@gmail.com, linux-arm-msm@vger.kernel.org, iommu@lists.linux.dev, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, marijn.suijten@somainline.org, kernel@collabora.com, luca@z3ntu.xyz, a39.skl@gmail.com, phone-devel@vger.kernel.org, ~postmarketos/upstreaming@lists.sr.ht, AngeloGioacchino Del Regno Subject: [PATCH v2 2/8] iommu/qcom: Use the asid read from device-tree if specified Date: Fri, 11 Nov 2022 15:59:13 +0100 Message-Id: <20221111145919.221159-3-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221111145919.221159-1-angelogioacchino.delregno@collabora.com> References: <20221111145919.221159-1-angelogioacchino.delregno@collabora.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749212420523484599?= X-GMAIL-MSGID: =?utf-8?q?1749212420523484599?= As specified in this driver, the context banks are 0x1000 apart but on some SoCs the context number does not necessarily match this logic, hence we end up using the wrong ASID: keeping in mind that this IOMMU implementation relies heavily on SCM (TZ) calls, it is mandatory that we communicate the right context number. Since this is all about how context banks are mapped in firmware, which may be board dependent (as a different firmware version may eventually change the expected context bank numbers), introduce a new property "qcom,ctx-num": when found, the ASID will be forced as read from the devicetree. When "qcom,ctx-num" is not found, this driver retains the previous behavior as to avoid breaking older devicetrees or systems that do not require forcing ASID numbers. Signed-off-by: Marijn Suijten [Marijn: Rebased over next-20221111] Signed-off-by: AngeloGioacchino Del Regno --- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c index bfd7b51eb5db..491a8093f3d6 100644 --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c @@ -551,7 +551,8 @@ static int qcom_iommu_of_xlate(struct device *dev, struct of_phandle_args *args) * index into qcom_iommu->ctxs: */ if (WARN_ON(asid < 1) || - WARN_ON(asid > qcom_iommu->num_ctxs)) { + WARN_ON(asid > qcom_iommu->num_ctxs) || + WARN_ON(qcom_iommu->ctxs[asid - 1] == NULL)) { put_device(&iommu_pdev->dev); return -EINVAL; } @@ -638,7 +639,8 @@ static int qcom_iommu_sec_ptbl_init(struct device *dev) static int get_asid(const struct device_node *np) { - u32 reg; + u32 reg, val; + int asid; /* read the "reg" property directly to get the relative address * of the context bank, and calculate the asid from that: @@ -646,7 +648,17 @@ static int get_asid(const struct device_node *np) if (of_property_read_u32_index(np, "reg", 0, ®)) return -ENODEV; - return reg / 0x1000; /* context banks are 0x1000 apart */ + /* + * Context banks are 0x1000 apart but, in some cases, the ASID + * number doesn't match to this logic and needs to be passed + * from the DT configuration explicitly. + */ + if (of_property_read_u32(np, "qcom,ctx-num", &val)) + asid = reg / 0x1000; + else + asid = val; + + return asid; } static int qcom_iommu_ctx_probe(struct platform_device *pdev)