From patchwork Fri Nov 11 14:59:12 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: 18870 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp789415wru; Fri, 11 Nov 2022 07:01:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Qeb1yVaVwHnjxoDryvU5PeJ8JtnvwZBwrq7SN7Or+tjw6FgwN6ZQnZSdltHEIp/gEDvrZ X-Received: by 2002:aa7:da55:0:b0:464:718c:b271 with SMTP id w21-20020aa7da55000000b00464718cb271mr1760390eds.287.1668178909214; Fri, 11 Nov 2022 07:01:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668178909; cv=none; d=google.com; s=arc-20160816; b=umXnDUsMrg6ZCuR/zONYSllx8IPRXr5b7an4F2Mx1eGwiejv6bMQ4MxfvYM0B1EKKU ZSSwsmwSHx6E887zqTHaHM5VPLNe1GUMhcF3vF++shI/2xitmm2jf8sViBrY51mg5Qc+ kXoD7ZHrF3bla/oqMZu9EKMLVAuw974ON+Dqw/83gBC2UJzirCtHrEPZCo2WMS2+/eu9 qoaKGrhgzyi9E8EXJsn0+k5hthK7rnP+a8T8IMbENclJOc70GHCiLALsNyrhw1Pz9T0a W5DqjoWZr2u1FtleirbS5dmdFZtve3KNsAQscmIphRQJ8658BYRbGGIxZoeclr53Q77Y McRg== 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=k2MSh5y8q3fhC3HHh7E2RjPcNkX4co5blRM6Z/FOmjQ=; b=jTsfBvlI8CIA7GLqFfyzdZm87k142p3c/0LupUgKYGUju1HgxIJjzgrUb+zDZc7Xkr y02/5O0wSFDr0BlAlEcdHlnpj8pUPYubyTAjOoGznt4psL7S0A37mJzhqxvlTi6v/xZO eH6C60uIy/G90FyMLYSus7xBCNlI/JyVdRhee8rD2gExmidwTjL2Dn+24BL5Wd2ovk1r YPtdtYzV9nWzCmmqe7WAy18S+ew/NH9qmoJUwlpUP6YXaiSEUe8kLUK5AiBOyqR6lhEV TDB5ftSYxaktAz1volbBciStJGbXvmmb962/uE4RGGSVZhN84DmSjoq9ImwRlrVE+92y ffBg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="c/TK7nM7"; 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 q9-20020a056402518900b0045d9ceae6d8si2658744edd.492.2022.11.11.07.01.23; Fri, 11 Nov 2022 07:01:49 -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="c/TK7nM7"; 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 S234810AbiKKPAK (ORCPT + 99 others); Fri, 11 Nov 2022 10:00:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59740 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234820AbiKKO7b (ORCPT ); Fri, 11 Nov 2022 09:59:31 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30E7F64A02; Fri, 11 Nov 2022 06:59:29 -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 BA0F96602A53; Fri, 11 Nov 2022 14:59:26 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1668178767; bh=+s8U+ysOQ3GldrqmWhai/Lpf4c/N59+UHllqmAZ7ue4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=c/TK7nM727YT6ta5popYpO7ux/3o1JbfwxfHFijgAW4tIxOZo8QD3lwGpBigrTacY ydlA5EFtIYMTHKJNozdVS6O/nQ6hfdvvuYKsjdKeowv4FJZLa3Pfltpk5JAumDpkWB IOTTv57a+GESrRJgxIVKQ/qZ2ArpVfHvCGbciGUvbG7GVBOYXTD3yWsW90zqCEHGto TbMAUMqCOWL0SEcHBhDXjykvzJOG3FKLJSdMWZqaCwQqQEiRyvTqOjdqEbyEUfONx2 4Gy6ThSCSDbPMWD0xJM6iV1NesHlH6xX4Y6grDtk6cuteweyp2Lj+/FK2E55F0N1nl Tly/ertgIkr8Q== 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 1/8] dt-bindings: iommu: qcom,iommu: Document qcom,ctx-num property Date: Fri, 11 Nov 2022 15:59:12 +0100 Message-Id: <20221111145919.221159-2-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?1749212368307219048?= X-GMAIL-MSGID: =?utf-8?q?1749212368307219048?= Add a new "qcom,ctx-num" property to force an ASID number on IOMMU contexts where required. Signed-off-by: Marijn Suijten [Marijn: Rebased over next-20221111] Signed-off-by: AngeloGioacchino Del Regno Acked-by: Krzysztof Kozlowski --- Documentation/devicetree/bindings/iommu/qcom,iommu.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/iommu/qcom,iommu.txt b/Documentation/devicetree/bindings/iommu/qcom,iommu.txt index 059139abce35..7d4e0a18b08e 100644 --- a/Documentation/devicetree/bindings/iommu/qcom,iommu.txt +++ b/Documentation/devicetree/bindings/iommu/qcom,iommu.txt @@ -46,6 +46,7 @@ to non-secure vs secure interrupt line. for routing of context bank irq's to secure vs non- secure lines. (Ie. if the iommu contains secure context banks) +- qcom,ctx-num : The ASID number associated to the context bank ** Examples: 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) From patchwork Fri Nov 11 14:59:14 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: 18875 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp791588wru; Fri, 11 Nov 2022 07:04:29 -0800 (PST) X-Google-Smtp-Source: AA0mqf58XQk1NdVGcGF0QsVkpBQjcZIABBHpGtAjI7plNpNhcGUHd9E5gs+IURBDJWWVWg9mGrKV X-Received: by 2002:a05:6402:22ba:b0:462:2410:9720 with SMTP id cx26-20020a05640222ba00b0046224109720mr1806611edb.84.1668179069329; Fri, 11 Nov 2022 07:04:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668179069; cv=none; d=google.com; s=arc-20160816; b=ZL85dpSHJQ3iOKlm4ppR5E9/+E7/9UaY9TIN6V6sklrVkL7QSG2/F6wgAhl47wzHvX uKgkDXcTv9DFM60QObT7VOPa2zlFfv3eGi5RT5JgGHnpd+NRCcTV/SLceluGGpMvT/eI EZ4J2HVXsGhcms9mQmc1MjEp/+OKcjlTTSsH6GjR4GbOGoFWaLU4x4wEm4CQRJEqX+fa Z7bIMCCQ2Fvo334L8srBIGqA7XoZsw2Z8kvl+FJCOUXPNWgJDxvMpl5BiOW28WzYMAFB fOMYfDnzlsngKxB/Odl3sgQYBxn3QcwfNb6mvonGIYKJ1o2SnPLkf7r+TnYzeXMZaE2k M+1g== 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=0+zPwZdryFZedJX3Xjriv1wC/1H16gYtvyoZDOMwW6U=; b=PjIKR+4bNtxfm6hWOJZdVkQkw4KeSXfFx7iEKXH81YSN0EgqxbnHD5paGsPSh2ulaT z9RT+VajVl06HYNkQXWm5K3yCGdkJTigZE0QPM1GndVrbm1WdronryOoshXvaRL4AEl8 bVrN28Z8+eXjIFqt+rxirr68bnqqyPwQ/oIETrqybrRVTehhwwymhTr2y7aZhbviLaWJ FwwgRV7wb4zUT6rDpkDXp5N3F6OUa4APyQ6yZpFnSYTP7ixzDfgpdXHWWviJgGnf1fw0 NZ1hxFJqAQDp/FJ71SN5oyntzG9tXkJeg2i+nDIzzBYx5kEGtuNWcj4gRURctezH53d7 CZNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=YuAw4h1U; 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 hu9-20020a170907a08900b007ae0db0c454si2301040ejc.635.2022.11.11.07.04.03; Fri, 11 Nov 2022 07:04:29 -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=YuAw4h1U; 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 S234882AbiKKPAe (ORCPT + 99 others); Fri, 11 Nov 2022 10:00:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234696AbiKKO7d (ORCPT ); Fri, 11 Nov 2022 09:59:33 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B34B8654C5; Fri, 11 Nov 2022 06:59:31 -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 171966602A5B; Fri, 11 Nov 2022 14:59:29 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1668178770; bh=v/SdConwcLDUdB+vnhsUHtZDsg7PCN+jxysiLSvSwfo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YuAw4h1USZuYNtGIaP6keEe/eLKOeSIf/5tQleLSFTXcIT42TOAqp9qF+GDluirO4 sCWOD1UqLTGVjNYDYV7Q1Qp5Mk0gj2FKqAWqhssUdLm4rLmktjE7r5amdn7qTJAUoe 8/1M807zf/RQTpzuJ1hD/XnJUcdnATFONhHpa5NuP1Vbvrn/lJWcoWEw9pryXo+aCO PsP4MwitdKWT28YOvZW6YFTPrDkfwXCPHuknDNKEmX5CkSOyTtWRT4lG5HFYhYzI5d 53A/IdpRUNXN2e14DtX3IAI5LbusGdPKLIprYyzqRGNRvnCrqXIYLgX46jGtiIjx7J 3ZwBwtb3e2pZA== 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 3/8] iommu/arm-smmu: Add definition for ARM_SMMU_CB_FSRRESTORE Date: Fri, 11 Nov 2022 15:59:14 +0100 Message-Id: <20221111145919.221159-4-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?1749212535851225349?= X-GMAIL-MSGID: =?utf-8?q?1749212535851225349?= In preparation for adding a proper context bank reset sequence in qcom_iommu, add a definition for the implementation defined Fault Status Restore register (FSRRESTORE). Signed-off-by: AngeloGioacchino Del Regno --- drivers/iommu/arm/arm-smmu/arm-smmu.h | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/iommu/arm/arm-smmu/arm-smmu.h b/drivers/iommu/arm/arm-smmu/arm-smmu.h index 703fd5817ec1..5015138799c5 100644 --- a/drivers/iommu/arm/arm-smmu/arm-smmu.h +++ b/drivers/iommu/arm/arm-smmu/arm-smmu.h @@ -219,6 +219,7 @@ enum arm_smmu_cbar_type { ARM_SMMU_FSR_TF | \ ARM_SMMU_FSR_IGN) +#define ARM_SMMU_CB_FSRRESTORE 0x5c #define ARM_SMMU_CB_FAR 0x60 #define ARM_SMMU_CB_FSYNR0 0x68 From patchwork Fri Nov 11 14:59:15 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: 18873 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp790573wru; Fri, 11 Nov 2022 07:03:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf7KeFyUS/Tr2DuVreDfcw7aUKBoxgp+jiLlHArmZhRCnhEIkY68ZtW+y1+bdf5z56YkbFpZ X-Received: by 2002:a17:906:26c3:b0:76c:42b4:dea4 with SMTP id u3-20020a17090626c300b0076c42b4dea4mr2035724ejc.515.1668178992436; Fri, 11 Nov 2022 07:03:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668178992; cv=none; d=google.com; s=arc-20160816; b=Ggb3TRkoyFtYyNuWRVK8YgQovdFjB3VnjSCzSxr+QAtKb6OnmM8Agkmvnz4f42nVKg JRKsUTG4akb8pSn7/ulZsNu0CxJM/cQzF9wwOYE/WntObwIIHJn4qO+K3L/rM28t6lCC +uOP/9P15/UA7y4/ovE23LJx/gz9aGa/aUPQDYVjHWEjm7MyqqSoJDj4tdP1BhzH5vtA yrHEehCE8tcXyJihLjEOCzQNsf2hPxq256q12Ad1gwm3ua0wH81HV6AbDbBXrZVtSuVN rjkr9+ViO2zn2vjbpGUkTnkQVdjflyNlo5He9PBpuWYEy4InP0pfmzkC7FGUa0z6IRGk 2eRw== 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=QmwvskWpCdfLRJqepaAQfkpGH4rpeFNdHUqELeORIJE=; b=OhpiVqz3y4E/85OlH/XEeDS1mbGg8gW4n8UXCOG7cj66AKmSPsz4693HXju9yolomr Q7PGeKHMKrbDFfTAUQ/XTKQSdM7TCvVxo0WxgUAyBaQer6fZB0+eW9VbelR9KsfAFsWw Xl5hJtNgVaYSeXcs9OoQVKi8cid5PRi1K4oX8I8KIaqm2oSJINq7OiFWlXB+KgQ3xEty iHW5Q0XNzhld/Uxi5YA5PCNf1sxhzVXyd+iCNlYlOswedlO31vzIfCccDKGDYcVcfXmY 2KsQlPrh+TLs6RslStRcBmnPfgwD16a+BzmmG/DggPNRdVJnys0tD7gUEZgL1cfNFhSD /l7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Ji175R1a; 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 jg8-20020a170907970800b007ade22f401bsi2329914ejc.759.2022.11.11.07.02.46; Fri, 11 Nov 2022 07:03:12 -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=Ji175R1a; 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 S234906AbiKKPAt (ORCPT + 99 others); Fri, 11 Nov 2022 10:00:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59558 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234799AbiKKO7d (ORCPT ); Fri, 11 Nov 2022 09:59:33 -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 D84E063BBB; Fri, 11 Nov 2022 06:59:32 -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 BBF3A6602A59; Fri, 11 Nov 2022 14:59:30 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1668178771; bh=Uu2Iue2Zm6k/+FEoq7MKfKY9a5FHnfb6lp6TkxmYFRg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Ji175R1aNfzKHK18s5KugJr20pgxwV4WtDoVyta3R+nVqDqYA7oX45rhWJwWSKV5v za6ubSoO341xTJ8UREvfDtV3Qv+YWHdRJNBi/I8TtI0ArwiyIjL95dJJJeDmPFJlYM O2N8yu9BkQFeL9wviuJFSznOyp2Y7MeZV0t+IicNWxtGlu8+XEuC839am895RzrIoC Fxvd8jZ1qQnSUpyBHtbS9VQgfjvsvDK1yoOH98ipA2n5+lQoU1C5zYKjT4lBKhMZVj Se8mclKCE4OOB4BtJ3wqm48ZhoIkodBwWT1N3bkM+7FG8xbPXpgSgpYjsEC9ky3nCY IqvGQrHibJazw== 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 4/8] iommu/qcom: Properly reset the IOMMU context Date: Fri, 11 Nov 2022 15:59:15 +0100 Message-Id: <20221111145919.221159-5-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?1749212454989014817?= X-GMAIL-MSGID: =?utf-8?q?1749212454989014817?= Avoid context faults by resetting the context(s) entirely at detach_dev() time and also do the same before programming the context for domain initialization. Signed-off-by: Marijn Suijten [Marijn: Rebased over next-20221111] Signed-off-by: AngeloGioacchino Del Regno --- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c index 491a8093f3d6..2249430d99d0 100644 --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c @@ -223,6 +223,21 @@ static irqreturn_t qcom_iommu_fault(int irq, void *dev) return IRQ_HANDLED; } +static void qcom_iommu_reset_ctx(struct qcom_iommu_ctx *ctx) +{ + iommu_writel(ctx, ARM_SMMU_CB_FAR, 0); + iommu_writel(ctx, ARM_SMMU_CB_FSRRESTORE, 0); + iommu_writel(ctx, ARM_SMMU_CB_FSR, ARM_SMMU_FSR_FAULT); + iommu_writel(ctx, ARM_SMMU_CB_S1_MAIR1, 0); + iommu_writel(ctx, ARM_SMMU_CB_PAR, 0); + iommu_writel(ctx, ARM_SMMU_CB_S1_MAIR0, 0); + iommu_writel(ctx, ARM_SMMU_CB_SCTLR, 0); + iommu_writel(ctx, ARM_SMMU_CB_TCR2, 0); + iommu_writel(ctx, ARM_SMMU_CB_TCR, 0); + iommu_writeq(ctx, ARM_SMMU_CB_TTBR0, 0); + iommu_writeq(ctx, ARM_SMMU_CB_TTBR1, 0); +} + static int qcom_iommu_init_domain(struct iommu_domain *domain, struct qcom_iommu_dev *qcom_iommu, struct device *dev) @@ -273,6 +288,8 @@ static int qcom_iommu_init_domain(struct iommu_domain *domain, ctx->secure_init = true; } + qcom_iommu_reset_ctx(ctx); + /* TTBRs */ iommu_writeq(ctx, ARM_SMMU_CB_TTBR0, pgtbl_cfg.arm_lpae_s1_cfg.ttbr | @@ -401,8 +418,8 @@ static void qcom_iommu_detach_dev(struct iommu_domain *domain, struct device *de for (i = 0; i < fwspec->num_ids; i++) { struct qcom_iommu_ctx *ctx = to_ctx(qcom_domain, fwspec->ids[i]); - /* Disable the context bank: */ - iommu_writel(ctx, ARM_SMMU_CB_SCTLR, 0); + /* Disable and reset the context bank */ + qcom_iommu_reset_ctx(ctx); ctx->domain = NULL; } From patchwork Fri Nov 11 14:59:16 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: 18874 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp791568wru; Fri, 11 Nov 2022 07:04:27 -0800 (PST) X-Google-Smtp-Source: AA0mqf72b2s2BCNLN5JGg/huWqUYapZhnLOz39bNt93OxvS7XZtumC6H2G3deCXVAPucZiBpSPs+ X-Received: by 2002:aa7:df90:0:b0:461:37c2:e85c with SMTP id b16-20020aa7df90000000b0046137c2e85cmr1752338edy.74.1668179067108; Fri, 11 Nov 2022 07:04:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668179067; cv=none; d=google.com; s=arc-20160816; b=QeauBSj+5ImBeRNGNKIqVSDWVmWjnd6qURL/S3wuTxxaagGYczPwItzhpquhn6hjP0 TuOUcjaTSIYLrO2qJN00t/9o/CWeGRG7vOrIJEs/gHtxYi895DzxnbWEMm1zEthozyGA keeHYZTW2PGmojvr0lXuV3HRBTIn6pVvsslbztZR3rDmezzwHXGLejsUwH5LWlxokqfp y/vFKYgsOHR6PVHc2gpKWPaR9M041ogcbekPO9Ftc83Yak2056M+maTISdaqkilx7KYX G4S9YxPaANICMaI/UfGFzNSompBE/mSH0R4KVv7TWRcLFqDqllWSQnGc6LX4hkJyLjd2 iOEg== 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=P6WXci3XGYP7Z6X4MSurdLlQ4meH/UB10LNR+gZRxyE=; b=y8Hw6bPp78b4GGe2xpI/2z3GtPGcaCpCkLdNk2wbsaWsnEBXylCs7iuh9K5Y071Qbw WIYpvs/GS77/GN63JXC/pZ90Pv4vauJWy6o72pO1ojMJ1fCqegvf2WpgtCQ07QW5Tjc8 yM9iPyHA0ohapZXd0XtGAROMP0MSQHgfBRHyWoIHtW5NMqMDFvc70RtLFM8jb3RhJ/bo 91t1DzSwLV8VqHT++OZ8Ip7T0FqbpTPfrjRpGSurZGnVZIC+tECZR9c/6zZc4zEay0qk PU7fnfd8h/gxPFkbCZ205kY1TEJbcsnsav7ehxDtqtrJHPAgOMN5K8vnA5gHbOOlS8oQ DkoA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b="lR5EW/TS"; 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 di17-20020a170906731100b007adcee4e54asi2493760ejc.408.2022.11.11.07.04.01; Fri, 11 Nov 2022 07:04:27 -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="lR5EW/TS"; 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 S234911AbiKKPAy (ORCPT + 99 others); Fri, 11 Nov 2022 10:00:54 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234787AbiKKO7e (ORCPT ); Fri, 11 Nov 2022 09:59:34 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 03C96654C8; Fri, 11 Nov 2022 06:59:34 -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 DF17E6600363; Fri, 11 Nov 2022 14:59:31 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1668178772; bh=iWU+YXrVAaFg0WilUSbRnrUGjBKxsz6l9DOOZYQ/lIs=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lR5EW/TSg90FAg9D3kItncUTqmw9E5SFt/juBtcH/5VhFOtRZjTV5nvr8+MOt5QG7 3rUb2LvAfKbBAIukOk7lR8WE5XQOE1WttZ6iptKiscNxYlTedAi1Q6rbZjGI/dOg3c h+dbu8d2EVCE5xunFz9dJLvT2pUfTMjjaVHn4ahlrzJ6EI+xIVXIoYIjPmUYZhCyld tabIt7NuR6WL6Vr3yoz0e+fvtABf6htpC3eSJoNrzQpEhDUhGcQ2MiAkDA5pPMxBS8 3tRXH0N0UAMZ8rV1w0ZY1xWPvkPGBSOTopViJ+s/1IIoah+O7TCMa7bxpH7HEkZDuP CYScKPC2sx8mg== 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 5/8] iommu/qcom: Index contexts by asid number to allow asid 0 Date: Fri, 11 Nov 2022 15:59:16 +0100 Message-Id: <20221111145919.221159-6-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?1749212533501397022?= X-GMAIL-MSGID: =?utf-8?q?1749212533501397022?= 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`. Signed-off-by: Marijn Suijten [Marijn: Rebased over next-20221111] Signed-off-by: AngeloGioacchino Del Regno --- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c index 2249430d99d0..6688b7264fd3 100644 --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c @@ -52,7 +52,7 @@ struct qcom_iommu_dev { void __iomem *local_base; u32 sec_id; u8 num_ctxs; - struct qcom_iommu_ctx *ctxs[]; /* indexed by asid-1 */ + struct qcom_iommu_ctx *ctxs[]; /* indexed by asid */ }; struct qcom_iommu_ctx { @@ -94,7 +94,7 @@ static struct qcom_iommu_ctx * to_ctx(struct qcom_iommu_domain *d, unsigned asid struct qcom_iommu_dev *qcom_iommu = d->iommu; if (!qcom_iommu) return NULL; - return qcom_iommu->ctxs[asid - 1]; + return qcom_iommu->ctxs[asid]; } static inline void @@ -564,12 +564,10 @@ static int qcom_iommu_of_xlate(struct device *dev, struct of_phandle_args *args) qcom_iommu = platform_get_drvdata(iommu_pdev); /* make sure the asid specified in dt is valid, so we don't have - * to sanity check this elsewhere, since 'asid - 1' is used to - * index into qcom_iommu->ctxs: + * to sanity check this elsewhere: */ - if (WARN_ON(asid < 1) || - WARN_ON(asid > qcom_iommu->num_ctxs) || - WARN_ON(qcom_iommu->ctxs[asid - 1] == NULL)) { + if (WARN_ON(asid >= qcom_iommu->num_ctxs) || + WARN_ON(qcom_iommu->ctxs[asid] == NULL)) { put_device(&iommu_pdev->dev); return -EINVAL; } @@ -727,7 +725,7 @@ static int qcom_iommu_ctx_probe(struct platform_device *pdev) dev_dbg(dev, "found asid %u\n", ctx->asid); - qcom_iommu->ctxs[ctx->asid - 1] = ctx; + qcom_iommu->ctxs[ctx->asid] = ctx; return 0; } @@ -739,7 +737,7 @@ static int qcom_iommu_ctx_remove(struct platform_device *pdev) platform_set_drvdata(pdev, NULL); - qcom_iommu->ctxs[ctx->asid - 1] = NULL; + qcom_iommu->ctxs[ctx->asid] = NULL; return 0; } @@ -780,7 +778,7 @@ static int qcom_iommu_device_probe(struct platform_device *pdev) struct device *dev = &pdev->dev; struct resource *res; struct clk *clk; - int ret, max_asid = 0; + int ret, num_ctxs, max_asid = 0; /* find the max asid (which is 1:1 to ctx bank idx), so we know how * many child ctx devices we have: @@ -788,11 +786,13 @@ static int qcom_iommu_device_probe(struct platform_device *pdev) for_each_child_of_node(dev->of_node, child) max_asid = max(max_asid, get_asid(child)); - qcom_iommu = devm_kzalloc(dev, struct_size(qcom_iommu, ctxs, max_asid), + num_ctxs = max_asid + 1; + + qcom_iommu = devm_kzalloc(dev, struct_size(qcom_iommu, ctxs, num_ctxs), GFP_KERNEL); if (!qcom_iommu) return -ENOMEM; - qcom_iommu->num_ctxs = max_asid; + qcom_iommu->num_ctxs = num_ctxs; qcom_iommu->dev = dev; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); From patchwork Fri Nov 11 14:59:17 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: 18872 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp790451wru; Fri, 11 Nov 2022 07:03:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf42sEUR8p6QWKaHeh7XPi1Wtt+SJF+2p7U1sCb0DSPchP1Tzipb0wqTPTUA+3a2n8VUZRAW X-Received: by 2002:a17:907:6f1a:b0:78d:981a:d997 with SMTP id sy26-20020a1709076f1a00b0078d981ad997mr2177724ejc.654.1668178983435; Fri, 11 Nov 2022 07:03:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668178983; cv=none; d=google.com; s=arc-20160816; b=wtowtBTujwbegaMn0/9Cjm7djOUwMwco7kCQIUeLOMR4Mr43bi9s5NzM8rCe3ZBtSS gap38kbE9554D1QbEaFx6yy8QGpcqPXr0Zi7uF3t+z2tzEDKPK1i3y5flUxgHgey1qQ1 X4DPoax43MasfkBZ8j0HWIA3/0DuGozIAjKhOe1GDhBU1MO9shBMsabQcZJq87hWQH1V 3iVcWXLdpVO0VNtkCJcILpf98tvhsoo0Vn1BrIhLDcLTzqkzfQC51iI3Js7s3sC0JTiB EI3yrE+IPNArWIMaafSP9gN168qvDWMFczUHpNg/V5vPKcA7zyhr7w6cC8OfC76wRTGX 92/Q== 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=ydx3SgsyBedCjzkqhu8lqw3oyrOe7eYzDpIRwMViHNU=; b=Bk72eGu7uuePMMR57wvCJBMkGk0vRO5xgsOpyeP1JQ7Vvp6e6UNkEfjQiDFgv0UqJs xS4mRbxExqg1rxNqb0ewY9O6RV8E/kBl+MD4g8l0OL/f1COAmHE3wD4f3LI5zZculm3B SU2XTUgWE9fLyVnolJStQbTwu6RtzSki5mc+kd1OpRI6XilstYgMydFtNm2JuK/VqClQ MiClokAmhqGPZYd5oDMBraK+EHOo1kNuH0dT6+lopdgYhBZTIxgaGRNttdC2ehTqGGQ3 mMOXH4QsSOIhlK9rfyGu5FCGdHZOr9l6iY5E2u2KYQroi2u0WQ6vKjQueMytpWI2GVSE sX9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=KLC3FLGq; 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 sz15-20020a1709078b0f00b007ae9bc0b977si1978054ejc.486.2022.11.11.07.02.37; Fri, 11 Nov 2022 07:03:03 -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=KLC3FLGq; 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 S234796AbiKKPAk (ORCPT + 99 others); Fri, 11 Nov 2022 10:00:40 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59562 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234129AbiKKO7f (ORCPT ); Fri, 11 Nov 2022 09:59:35 -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 2CD3B64A0E; Fri, 11 Nov 2022 06:59:35 -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 10174660294A; Fri, 11 Nov 2022 14:59:33 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1668178774; bh=Zf7m6jLp2JACg2AkUZYo4eLC63C+UuS3mbPUkyrlclQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KLC3FLGq6Luk28XxzE46NQzfgpRr7EuFwLt1NaEKJAJq/ypfp8oFHw6Gujat2Bng+ 6S50tj+58MW8iCogD31vRyMV9qC/2M5pNiIBPNL1tvg+BJX9ytsNRrVtts3Y5JHN3T i3BwPfVLZpwO8U3a7Oq5hGSxGdSdh3SA/WvIysNVoDy1Q/nvMoiyG65SNrlSVozBPk yeyX5g277WrBU4F7FGXX0LjCG9vuqLAJQsDNBOj4OjUAQ7XHttvE3P2T3s3RhX0HoL qwQ+H8Coid6uO5z+VRJZvEQGFnJUEt3e2To05SpDVpMunP7/IuZo0m8wPE8EZsNTHD hgMBbrrOp6Gjg== 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 6/8] dt-bindings: iommu: qcom,iommu: Document QSMMU v2 compatibles Date: Fri, 11 Nov 2022 15:59:17 +0100 Message-Id: <20221111145919.221159-7-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?1749212446215377501?= X-GMAIL-MSGID: =?utf-8?q?1749212446215377501?= Add compatible strings for "qcom,msm-iommu-v2" for the inner node, "qcom,msm-iommu-v2-ns" and "qcom,msm-iommu-v2-sec" for the context bank nodes to support Qualcomm's secure fw "SMMU v2" implementation. Signed-off-by: AngeloGioacchino Del Regno Acked-by: Krzysztof Kozlowski --- Documentation/devicetree/bindings/iommu/qcom,iommu.txt | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/iommu/qcom,iommu.txt b/Documentation/devicetree/bindings/iommu/qcom,iommu.txt index 7d4e0a18b08e..b762772f80e7 100644 --- a/Documentation/devicetree/bindings/iommu/qcom,iommu.txt +++ b/Documentation/devicetree/bindings/iommu/qcom,iommu.txt @@ -11,7 +11,10 @@ to non-secure vs secure interrupt line. "qcom,msm8916-iommu" - Followed by "qcom,msm-iommu-v1". + Followed by one of: + + - "qcom,msm-iommu-v1" + - "qcom,msm-iommu-v2" - clock-names : Should be a pair of "iface" (required for IOMMUs register group access) and "bus" (required for @@ -36,6 +39,8 @@ to non-secure vs secure interrupt line. - compatible : Should be one of: - "qcom,msm-iommu-v1-ns" : non-secure context bank - "qcom,msm-iommu-v1-sec" : secure context bank + - "qcom,msm-iommu-v2-ns" : non-secure QSMMUv2/QSMMU500 context bank + - "qcom,msm-iommu-v2-sec" : secure QSMMUv2/QSMMU500 context bank - reg : Base address and size of context bank within the iommu - interrupts : The context fault irq. From patchwork Fri Nov 11 14:59:18 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: 18876 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp792014wru; Fri, 11 Nov 2022 07:04:59 -0800 (PST) X-Google-Smtp-Source: AA0mqf6lB1Rim7gqt03Dhg8hg1TR3tn+s7fAF7JkjbsCIREvuNraENGdGmDXJcjdDekQ5+uM41lN X-Received: by 2002:a17:906:2ac3:b0:7ad:b152:90f2 with SMTP id m3-20020a1709062ac300b007adb15290f2mr2185927eje.345.1668179099180; Fri, 11 Nov 2022 07:04:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668179099; cv=none; d=google.com; s=arc-20160816; b=VxgXoiAIuNAnOaXQPWrT1PgwniQm24slBw64uQhiJUZjm3G6u5xP3BkPmeoep9nG15 sSGtLSAMpLWtcYDPycb6Pg40MDYP0Zn/UeiRiun6qc+55ThpvWr7Vl0O9GJFpy0ZajqU rqUhO3wjGzZ6r3XzoHU6qWyaUI1GdDafnQysB04tdhlrH0RRvhRq8ukgVB8xoZEZytH3 PnvsukxAYIxSjc1ymixycBw3/P5hLaDDayRPF2aJkRIo/GaX4yQv0k8kAS5GOG7m3llo 9Zwg3iiYaaThjXOJILBNtLPhDAF0xr3rTBkUiKVpRdrPnOBqBPa8SsSbArS93mO5u8XH GDiw== 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=0DsrmCwM3HOKuItfNm96V4HHFhrt3Dypg/IxNvJyEFk=; b=MPSpZ3IDdFhp3wTAiOqDwPaeWWh0rSnI9rBMnnJn6Y+NKsfXH8owKO/NNd9i/NcBhG N4pze1Ge/vRUbg2j/DlMDjRnUZVVD/aVsg9Bj+kWSjl+VV6zSVnaUvesfbxbhmLaoylK Kdhw8y3YjiI8JbgNVv4EJaWESA1toSljuJaqD4cs6rPNRTOZKebqtBxDl0B9oz4iigtN HFaUJ7fFiTMMSdkI5iBn1jlhVMhJ3fd8Razr3tB2uhQ8sCbO+x7E8knQhDpbM87YyqSx p0aVtI0zfcEPootI27fkEp8R8+dNZeVhnZVWwp8rHiTVWljuMGzuS60JD72dAM6bK2Y2 lKNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=ZuGFHmDO; 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 oz30-20020a1709077d9e00b0073d5a794b43si2075343ejc.985.2022.11.11.07.04.32; Fri, 11 Nov 2022 07:04:59 -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=ZuGFHmDO; 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 S234830AbiKKPAo (ORCPT + 99 others); Fri, 11 Nov 2022 10:00:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59762 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234756AbiKKO7h (ORCPT ); Fri, 11 Nov 2022 09:59:37 -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 4E39564A38; Fri, 11 Nov 2022 06:59:36 -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 3437F6602A5C; Fri, 11 Nov 2022 14:59:34 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1668178775; bh=GQN6ERvuiLeBME4E9PHfrENT8OT9+fY5tavNmYzDg7s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZuGFHmDOJ85qI8uA7XdzX1JaGFrQ/kj5rSVO8at9MpUc7Iem9RIlI6BbmKVAtxpgA F2a7rPwScBrRojpOphQbjRoGSJCf/4WhfUSAIiWnbqWCv3luVFfIB0WuT9Pc3g0FGI 2pniFBUOxln1oS4PwHnhbFV2x0uRZMQgYNq1tLLZ3JP5CdLiWjF5mzJYq9KvJlYj55 tzP6nRe0A3XRXhplKdSMrxT+X7UHL7A4njhcrE895wvAQXslUUnRs6WSajyJryTCLd QDQuiGPdfVR7eORGQK/roWYMWVxkwvYM+i01kbewvQZhn1A/Elfp5HEO0wPFeWJ7eW 5amX0Kp6Hdd2w== 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 7/8] iommu/qcom: Add support for QSMMUv2 and QSMMU-500 secured contexts Date: Fri, 11 Nov 2022 15:59:18 +0100 Message-Id: <20221111145919.221159-8-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?1749212567517753491?= X-GMAIL-MSGID: =?utf-8?q?1749212567517753491?= On some SoCs like MSM8956, MSM8976 and others, secure contexts are also secured: these get programmed by the bootloader or TZ (as usual) but their "interesting" registers are locked out by the hypervisor, disallowing direct register writes from Linux and, in many cases, completely disallowing the reprogramming of TTBR, TCR, MAIR and other registers including, but not limited to, resetting contexts. This is referred downstream as a "v2" IOMMU but this is effectively a "v2 firmware configuration" instead. Luckily, the described behavior of version 2 is effective only on secure contexts and not on non-secure ones: add support for that, finally getting a completely working IOMMU on at least MSM8956/76. Signed-off-by: Marijn Suijten [Marijn: Rebased over next-20221111] Signed-off-by: AngeloGioacchino Del Regno --- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c index 6688b7264fd3..956b2eee8d58 100644 --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c @@ -59,6 +59,7 @@ struct qcom_iommu_ctx { struct device *dev; void __iomem *base; bool secure_init; + bool secured_ctx; u8 asid; /* asid and ctx bank # are 1:1 */ struct iommu_domain *domain; }; @@ -288,6 +289,12 @@ static int qcom_iommu_init_domain(struct iommu_domain *domain, ctx->secure_init = true; } + /* Secured QSMMU-500/QSMMU-v2 contexts cannot be programmed */ + if (ctx->secured_ctx) { + ctx->domain = domain; + continue; + } + qcom_iommu_reset_ctx(ctx); /* TTBRs */ @@ -419,7 +426,8 @@ static void qcom_iommu_detach_dev(struct iommu_domain *domain, struct device *de struct qcom_iommu_ctx *ctx = to_ctx(qcom_domain, fwspec->ids[i]); /* Disable and reset the context bank */ - qcom_iommu_reset_ctx(ctx); + if (!ctx->secured_ctx) + qcom_iommu_reset_ctx(ctx); ctx->domain = NULL; } @@ -700,10 +708,14 @@ static int qcom_iommu_ctx_probe(struct platform_device *pdev) if (irq < 0) return -ENODEV; + if (of_device_is_compatible(dev->of_node, "qcom,msm-iommu-v2-sec")) + ctx->secured_ctx = true; + /* clear IRQs before registering fault handler, just in case the * boot-loader left us a surprise: */ - iommu_writel(ctx, ARM_SMMU_CB_FSR, iommu_readl(ctx, ARM_SMMU_CB_FSR)); + if (!ctx->secured_ctx) + iommu_writel(ctx, ARM_SMMU_CB_FSR, iommu_readl(ctx, ARM_SMMU_CB_FSR)); ret = devm_request_irq(dev, irq, qcom_iommu_fault, @@ -745,6 +757,8 @@ static int qcom_iommu_ctx_remove(struct platform_device *pdev) static const struct of_device_id ctx_of_match[] = { { .compatible = "qcom,msm-iommu-v1-ns" }, { .compatible = "qcom,msm-iommu-v1-sec" }, + { .compatible = "qcom,msm-iommu-v2-ns" }, + { .compatible = "qcom,msm-iommu-v2-sec" }, { /* sentinel */ } }; @@ -762,7 +776,8 @@ static bool qcom_iommu_has_secure_context(struct qcom_iommu_dev *qcom_iommu) struct device_node *child; for_each_child_of_node(qcom_iommu->dev->of_node, child) { - if (of_device_is_compatible(child, "qcom,msm-iommu-v1-sec")) { + if (of_device_is_compatible(child, "qcom,msm-iommu-v1-sec") || + of_device_is_compatible(child, "qcom,msm-iommu-v2-sec")) { of_node_put(child); return true; } From patchwork Fri Nov 11 14:59:19 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: 18877 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp793082wru; Fri, 11 Nov 2022 07:06:16 -0800 (PST) X-Google-Smtp-Source: AA0mqf5a7imDlQGoX6+nJy+0pQLon87BmCA9l9A7heve488/7mf80JW6TybTfO1zu7jTkAwOgP7e X-Received: by 2002:a05:6402:1bdc:b0:463:7312:a94 with SMTP id ch28-20020a0564021bdc00b0046373120a94mr1872547edb.178.1668179176059; Fri, 11 Nov 2022 07:06:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668179176; cv=none; d=google.com; s=arc-20160816; b=F7LxyYAyZ0QheTQKTAzKF1DcSpaEbLyGungFWZlnCiuLGzERZe8cZaAWE+E6kSTVqf RB7sK7YiUEQnPPou2jWWBDOUzjk/OF5qPsW7ODTlLkpM+7Tm7LqnO3LuShYD0D2mGdr/ oBCm8Kk5uuTdhXspcjF6r8FcYnGPhchUHnDyO49CvXRuFd6ihSBxc9wA81ro01nqN/I9 eZBxEVSW3UJWpmAS0jRIEI0tczjEchw7yUtOJJO+LJYzs7WJLSGMpLpThdNWEv+T6G12 ocLS58NzQQtXAaTuyoNoO02Rw8y5Hsxm7WULNf3zY8SX39xIR/qgsavQIrK1Pj2cO6Bj keYg== 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=zTjMv1tR5S+sqdZ2bLPWou9dpoD759JZuvYV61ajfzs=; b=Wh0h9O9fwHGDHn1JUJGeDZXfmJ2gUGH4rMaKAiMytmm+nGX1TcsCAf1QBurGSi75MV Nof3u0Qhakji7UcAGjfiCWffpIV1NQxpxAr5/lQxoEKFIPlCn1A8geSE/f7IzdUCPRM/ gZAPnos4YECjCuFfLvJ8OCACrhWnDKEMf9Vj/aMRyGkZojXhjGOKj6dreZNpItvihOGd 31TeYbWnxXjRMkyoRvvlOU9hZNuNWysqum7o1NYtY+ETh7IoePeYMDWucjxdjuBwCDMW 05rNysdZnwawd2FZi/hpk6i08htcxtDOVvKeqpvtAlH2LX6IzOVoeBYqOoiUhAqCSDOJ i/rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=avd20egh; 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 ht15-20020a170907608f00b0078d805901b1si2019931ejc.489.2022.11.11.07.05.47; Fri, 11 Nov 2022 07:06:16 -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=avd20egh; 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 S234839AbiKKPBC (ORCPT + 99 others); Fri, 11 Nov 2022 10:01:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234755AbiKKO7i (ORCPT ); Fri, 11 Nov 2022 09:59:38 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6C44654D5; Fri, 11 Nov 2022 06:59:37 -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 588EC6602A6A; Fri, 11 Nov 2022 14:59:35 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1668178776; bh=MdaH8KbjjoGPf2cEN4UiKaUO79dviS/rWyElqvdnnE4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=avd20eghOS5K6gOklGt3Sm3Gek5pwuQ/Aprzihhp3r8z/4UR6W7kxHJx5sNNeobr7 9kClPGQaLigcVaBg+USNAimBjhTtD/X6KVpD5IufbPeVEDrpeKJ30eW29jkVzFYuyf 6Ap7rYhLr9CnWU63kHmHTS/Vo8ez9Iph7bPpmkUV0ZcP1+EBN/NxK7aPTBvddXs6fk sU7L9eoyP7DTvVKvwZ2gL8xAv/x1U4w/lGTegKMjgutPNlQWOGdxncqZ+pZAeo3zaD J1s0vvFOJi/FvhDNn+LZbTm6XwM9CYcwiNaHtZE1zwy4ENckVOBuKUWuaxWYYesS7f hBGGpZCQPyOYQ== 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 8/8] dt-bindings: iommu: qcom,iommu: Document MSM8976 compatible Date: Fri, 11 Nov 2022 15:59:19 +0100 Message-Id: <20221111145919.221159-9-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?1749212647612933853?= X-GMAIL-MSGID: =?utf-8?q?1749212647612933853?= Add "qcom,msm8976-iommu" to support IOMMUs on this SoC. Signed-off-by: AngeloGioacchino Del Regno --- Documentation/devicetree/bindings/iommu/qcom,iommu.txt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/iommu/qcom,iommu.txt b/Documentation/devicetree/bindings/iommu/qcom,iommu.txt index b762772f80e7..b7a5822ac00d 100644 --- a/Documentation/devicetree/bindings/iommu/qcom,iommu.txt +++ b/Documentation/devicetree/bindings/iommu/qcom,iommu.txt @@ -9,7 +9,8 @@ to non-secure vs secure interrupt line. - compatible : Should be one of: - "qcom,msm8916-iommu" + - "qcom,msm8916-iommu" + - "qcom,msm8976-iommu" Followed by one of: