From patchwork Tue Nov 15 10:11: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: 20283 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2626561wru; Tue, 15 Nov 2022 02:12:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf63sbOaIPzAgxP6C7kc9u0J8tLF/8l+cQMFwmaT2gy8BSTo8Pjn/0tR7MUrhoFC7VamRmnb X-Received: by 2002:a17:906:412:b0:78d:85fe:4951 with SMTP id d18-20020a170906041200b0078d85fe4951mr12758453eja.593.1668507151866; Tue, 15 Nov 2022 02:12:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668507151; cv=none; d=google.com; s=arc-20160816; b=oxQtti9mupWEmfRniJckvcv6GJlHMbqQyYvYPSKCP5lNb2TwmDOhMw7Zvb5vFNRGzR CQ5xR1ePB7B7PiI4gd3lKnB89s0vkhXkWbRXwo9nyjLSV9qCmKA4Z7ZChlRM33NH+307 n5pG4SVaQfIUQZH7BTnNyGeASSRdbz/Q1uxECEevy3ZbuS1bcc4ZCRLIlsMNEwkRlYrG QENxv1LrqmL+fxjsF+NN+ULZvncxJomYD6I+PUS6cDB0H2EmGCRUYpwpcIDeuFFQzJTL sJjiddnZDNHIJ9TAUDY6QnSzlfPvz62stXl5I4r040a4MLUx5P0c4DsQROSACubZOres lJRQ== 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=NfBgTtD294Syf19P5TEZLHXl1EmS+js1r4r+M1tq4WI=; b=ka4S8LLaGKn88BGhL4lZ/8SC/Y8/ZdABV9aOhmHqHiHhugM/ie9kWmdJQsEigNx5uK qbsbu25ec4k9rum/9r4OXEk+I+8npYvh6TIQ405wCKhkE4dOCTu2QkmfZT415pg7qu1S Kda6u5E4+W9LVYbqoiQrFdMpaL4l0zdvE48KiuRTFTSwl9E+EMdbXmwGtQlWO82Zn+k4 q4LDtqZmoDUYDvQ+EDvK7uneHcIb8WZjc16Vsdoktp8c7v7+/jA1iizY3cNOYpBPoA7W V3MV6gmhvDw3o+Z+dCf3vDpzt8/+f8khnVLWA0fnxVI847xl6inKCxS6rSK/eRN2fc/x ED1Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=lbWCja0P; 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 hr22-20020a1709073f9600b0078d3a35e181si10558705ejc.871.2022.11.15.02.12.07; Tue, 15 Nov 2022 02:12:31 -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=lbWCja0P; 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 S238274AbiKOKLl (ORCPT + 99 others); Tue, 15 Nov 2022 05:11:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238262AbiKOKLh (ORCPT ); Tue, 15 Nov 2022 05:11:37 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2DFF5F82; Tue, 15 Nov 2022 02:11: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 6901D6602980; Tue, 15 Nov 2022 10:11:33 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1668507094; bh=NHdspCLp4Pq3hK88QRXd3z7hZRds4FeUTB1LzXblsv8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lbWCja0PZqnIvmCSwCgIigaRxo2WvBLvsVsUSfRGzVy9DwF8HbAmznUKxZfZZOOQQ mygWfD7EyzHZnchZwVcskuwwgz+2tlHQKiMHEGHrkUul478JFlL3s+3wJp4IVFMTFu RaxPXSKcMMASOqwm25YQ4+Q8EAahav06y5n7LyArSi7woPwymtQbppJfUHpf5UusKN l6KPbGW9FC45541w8cXP6QLpRNwrxUC79gVPDBoDetTKY5acf41Djz8OGgs38noCPK afgzqpjc5nu4QgzB4opsNxd3vdW59tPH1X29HBWaiUHDn+VNexmv2dd1DI1bWzVATq 5YyrgphgxBFaQ== 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 , Krzysztof Kozlowski Subject: [PATCH v3 1/6] dt-bindings: iommu: qcom,iommu: Document qcom,ctx-num property Date: Tue, 15 Nov 2022 11:11:17 +0100 Message-Id: <20221115101122.155440-2-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221115101122.155440-1-angelogioacchino.delregno@collabora.com> References: <20221115101122.155440-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?1749556555181012387?= X-GMAIL-MSGID: =?utf-8?q?1749556555181012387?= 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 Tue Nov 15 10:11: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: 20285 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2626733wru; Tue, 15 Nov 2022 02:13:00 -0800 (PST) X-Google-Smtp-Source: AA0mqf65vP1VVS+k/x1osXnzUlBm9PERgCpSaAb4Ug1VbsVbkW7NZ7opVnCRdYYoRS7d52y8QPak X-Received: by 2002:a17:906:7707:b0:78d:9324:6f18 with SMTP id q7-20020a170906770700b0078d93246f18mr13753615ejm.664.1668507180572; Tue, 15 Nov 2022 02:13:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668507180; cv=none; d=google.com; s=arc-20160816; b=Oqr77SVE4qng1FRUg9NFtFTqpY2V6lUvjSFMis+tJA/UewridpJEwtHJVP/BcvBeWD 33PrGMSua/eZaQD5ZjVRVk/yaQliWvo6V903PnqsTvGDz1taLxofJ9RKudYZ1Ee6hh68 DECNvGAHxAnrdxVbe0Mmcz4pQME9okI+UnC89PgM7WmzPAA7hJUM0SrQL15CJcXeFZsL INtu+7A5cmLdfh35Qf+kGj7CZKQANy/xWOIS1wlhOOdVOXOwYNIQ83D7P8jUN/Z38jE4 ErflNjWu0tCXMMgwyrmRj/ETwNeLqS7Zjd0t2Rxdx0i3XlPVLsIiptsz4kBw3O0IiLiV pC0w== 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=Ussgexmr+Ze9kWC9Ztg53b6hnGLUX+Vo+Sfjgl46ZZVFZTUIjNhZkq/O5ef4Q3g2Lx GONf5vF/Y/42nA/ZUYHjyNV5ieCogc+QtwRJNFqqUtOfKuMZRPkIZHDA1b5x36TIyYle X+d2KrClCGMqlzS6zRa8lPJcIqbdGwPw+GzPNCStRCecCLLh9QUlHcI0rkGujq9R2/iH iS67uhOOSnb2kTTA2S2zJrejoJILiMK7J848PRkJOmzAbGroPTlFK+brLysgm0WY7NaE w7Ni4dBsxFqH/+WqltD62XRN5aJWNCtTgppCGVEcXj5Ag6OJTSX6jAXlJT7Tra1QS6cr Y0UA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=SJr0Wkgo; 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 s2-20020a1709062ec200b0078dc5b2b6c4si8456090eji.666.2022.11.15.02.12.35; Tue, 15 Nov 2022 02:13:00 -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=SJr0Wkgo; 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 S238281AbiKOKLp (ORCPT + 99 others); Tue, 15 Nov 2022 05:11:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60404 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238267AbiKOKLh (ORCPT ); Tue, 15 Nov 2022 05:11:37 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D9C22F0B; Tue, 15 Nov 2022 02:11: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 A58C766029AE; Tue, 15 Nov 2022 10:11:34 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1668507095; bh=JcV01OqQI7OdtwJTtMaesEof4OedrSHFsOnwvt1LCKw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SJr0WkgoBF3KvKtN586V/Vto5GR8uIk0+49Hv/W61piKmhFrGjeBxpbKynVBnd07a uVOuvG8PXWxxN4YTTIcExNs1/nMGbpF2TCgaJ7jrhmULnnn1VfRf0yAXhHBwA3aSeD Bytifi64josXifWhvSlgzNsn5yoaanXYHONplATUYvrxIlXAT3qCTSmxLjStbHJsN5 iSPzSXgk//gX1J6aYCAa3O9ZLXIWbdd4cHMjQhyMQJkyO/Bgp3t7edCJx3/G/HAN19 KsHNVRWdR45usbbQtJE0svcbt5DDK4ep99HcOqKt+fDhYRSW8BeHx1SlzRUZMKAZY7 2xDTpNChr6+7g== 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 v3 2/6] iommu/qcom: Use the asid read from device-tree if specified Date: Tue, 15 Nov 2022 11:11:18 +0100 Message-Id: <20221115101122.155440-3-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221115101122.155440-1-angelogioacchino.delregno@collabora.com> References: <20221115101122.155440-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?1749556585428834335?= X-GMAIL-MSGID: =?utf-8?q?1749556585428834335?= 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 Tue Nov 15 10:11: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: 20284 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2626681wru; Tue, 15 Nov 2022 02:12:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf4NtbTB6wNXFpT5JM12vWD0ShXfk38ZkNyA1UDMMKcsuRin0c6C74Hi1RUpQiWwy7w7fZQR X-Received: by 2002:a17:907:962a:b0:7ae:39b4:7208 with SMTP id gb42-20020a170907962a00b007ae39b47208mr13177923ejc.766.1668507171331; Tue, 15 Nov 2022 02:12:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668507171; cv=none; d=google.com; s=arc-20160816; b=Rxqt0il/729TW046iUdqvszaBQUjOsq33s6GGWLN8TnaBeHjssGc5PlAAe8PrJS2Y5 G5TVKkAQcCdX8CeipXXhVSH3bSMFivW7YToFL9mctXWOcoqMA3H2Va5ibdI1ON2OJxOv i5RDJFW14B/DIZu5lcKpZnGCmznK1DBr0ep47AaNmGa7lPqig+QPdDUG/xtbQZFJL+2X RWQ3fC3TsnOd/cM0K7+VYf8rIwHRazjJecU+Ig4ZECWBeUGMlwtpv+TSIU8pxObgdYT/ zurNH6sUpsZ2NvCmAC2l/LdoSj8UhS8SxRafTIGvKnjcYxd1enpAod1cp/gm/qiq+kd+ aVog== 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=BVydm18JEnXeiIzGhYMUwcTaqbenVEG4bSWLJV40ssg=; b=ucSnRfWLhPkgJ94NcrTDPLtWswxdm8bYgaJyh6B6f+pOnuXtoFHyL0vRMV5vblKmW/ A2HOfXdsf3ilNkdOvN7VJvzZ3oYnYlo0FZdYZDT/Q3JlTDn0ZSrM6QCFzMrfMGXv83ZQ rBMmU8J1NrwALjVxJIIhNrPfZzltEULXNnlqCLn/8oTC/gElJwNlG078JlrKagftcg4m PIv2uyOp3kZGIx+WfRgyCQaB6frMko8cvHZQc8b1LX1iT+Cy4A2YeEbCZA0sXjfFvnG3 zUrEPzMdtLMz8pnmXWKUTENdbQV156uuQogpOLTONxAAwvcLu0TuY0fsH+3m3USqWLn2 Ei0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=lY8ogjAK; 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 go38-20020a1709070da600b007ae4f8de35esi11544041ejc.860.2022.11.15.02.12.28; Tue, 15 Nov 2022 02:12:51 -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=lY8ogjAK; 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 S238303AbiKOKLr (ORCPT + 99 others); Tue, 15 Nov 2022 05:11:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238275AbiKOKLi (ORCPT ); Tue, 15 Nov 2022 05:11:38 -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 263E66416; Tue, 15 Nov 2022 02:11:38 -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 D87C86602A13; Tue, 15 Nov 2022 10:11:35 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1668507096; bh=ZyyLPRrFzO2HVcobnI5VF8p7tvZDI9hyhowu+PLNJZE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lY8ogjAKhbMXwE1IRAzHKjBnY6w+MXTSWwTVh7rjLMewR2tg23pI25YQ6EInVA82+ mEgYyxW00ERGsqOPEzkNLDSmYro9H/F0/eFgbu+ofAWEy16MZEGhkMfy+KhAQ5pTDf tteDH5fQPAJEctL8pYfjdLrcOG/TS7V2YcAIzLLKFBsUTHCG/IBUr1MIiTuXP5dW/7 5MNZ7kvym5HwE7ttGh9JLHXdZHBLtRJPKV6fk20tBy73OFuqLseyrdJ4E6wUvLJIUi B21SXMdK1vnptUIUpcbcUiH8geGGEv8frgMRSC0VV3XbrvayK6SRdlOjH6vaTDSWoU 79cRZ3ZwXs3RA== 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 v3 3/6] iommu/qcom: Properly reset the IOMMU context Date: Tue, 15 Nov 2022 11:11:19 +0100 Message-Id: <20221115101122.155440-4-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221115101122.155440-1-angelogioacchino.delregno@collabora.com> References: <20221115101122.155440-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?1749556575411727766?= X-GMAIL-MSGID: =?utf-8?q?1749556575411727766?= 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 | 20 ++++++++++++++++++-- 1 file changed, 18 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..49f4308f1bd2 100644 --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c @@ -223,6 +223,20 @@ 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_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 +287,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 +417,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 Tue Nov 15 10:11:20 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: 20287 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2626770wru; Tue, 15 Nov 2022 02:13:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf6+pfH4r0Sgcb59A/dBRz1zfBmEn3ZeAJDAJqgMAIeGVE598uyDqrzCmoQQAGE4BSFualS2 X-Received: by 2002:a17:906:3e92:b0:7ae:b2e3:ce15 with SMTP id a18-20020a1709063e9200b007aeb2e3ce15mr12994772ejj.136.1668507185027; Tue, 15 Nov 2022 02:13:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668507185; cv=none; d=google.com; s=arc-20160816; b=vjmXMc88cJzknspJbfKmALG9uXbQtyQosQSkyhC5srjAe4XwhCTBeHQj5wwIFZrmib Mnyp5nH0rga+AV/XokzK1CpxFLbijBLqVwH0+YzEl2xT37Fspd/njNk97eMkOmXBYGFp tVoggwJXP4wtxYAZ+J5nkyg75EtWkk7pslNx1dOhaAkaPjWQKTwhOEcjAdUdT0LTmvu7 UyhXnkyKpP5RFnS/7UDv55AjqFHDEWuI2mOMt/3ApI/1DoNW58yjEZBQymr0oPXtmtwK +7Dr+W92ZFZPjJ7k9nvwolRV6NdG1w60FhEGtew9b1xmRnGsRJz2FH0Bvu70UBGrsuWe 5lCg== 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=x6c7F9Zto6+6XXrAxS0P9KAlVzi3pXK3EuZryJLRu/E=; b=QsetpRHxEGVTLFm7kyeLZx30itIWjZaYtYoLUla8O2Rm4mPCcGBIu7QtKnH0htbobJ g7G3Zr1tDnN4Hd0pfLdC2vP6HvqW+R0h7tD8e32hpdUDnw5we4aOg3FwgPTzra9eEZa+ HDCoFLBeB0yh2dr+HBwHbiPMhtjrMMF+luAht0m41VMobKpbQZo4UgKfCR8XgDjZRLLt ZlQML2xHd4xUEon1Mu6Dgd4QN5rBoz/pMSelY6rajgaw/B28mwrsZp1nkgaVIJ6gpgNm +z6xWSrOM1a4lO9/9b8oB+SZQi+K5E0kWKwxaWaY9ERzzHTmUQuB6x4m7siHOUiF1mEu 8RFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=bz1oK+Li; 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 k4-20020a1709063e0400b0078277d265bcsi8894619eji.204.2022.11.15.02.12.39; Tue, 15 Nov 2022 02:13:05 -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=bz1oK+Li; 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 S238373AbiKOKLz (ORCPT + 99 others); Tue, 15 Nov 2022 05:11:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238283AbiKOKLk (ORCPT ); Tue, 15 Nov 2022 05:11:40 -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 3AA95D88; Tue, 15 Nov 2022 02:11:39 -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 159826602A0B; Tue, 15 Nov 2022 10:11:37 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1668507098; bh=N1mKhVUV01NUb+7PkgRk9SjnldpaGZ/+V+1gVCVqXzo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bz1oK+LiSMFDkOxh5ALtdt4gGBrzdxJqBydMYV7KP51k5HvPzhMBn3gPlJPsPFoxu cefNzdCrm0RqXTTlSpBoDjjx4jvl2//i1jBhRrcu5AmyzFp6TMrcjsd7orirnyZZ2m KnV8B/YeQuN/QFFlL1FXbe7EX2Vpjh0qSUT5GaMM5KOjXgyUz5FpyH6ieMsWHcDaVO sAQbQaM3M960uyShk+GpusCOqEMli1hJTZdKQ1VMmZoA4mzDFzKpK8cys/ci1dRPz5 yWrFZiLJz/uHHlgE1M+uOrBwMMz8lGWLIFuuo0JkY+HCtuXnufEmHccYIgabGkYbOM kbA+pSBcO6edw== 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 v3 4/6] iommu/qcom: Index contexts by asid number to allow asid 0 Date: Tue, 15 Nov 2022 11:11:20 +0100 Message-Id: <20221115101122.155440-5-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221115101122.155440-1-angelogioacchino.delregno@collabora.com> References: <20221115101122.155440-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?1749556589905685226?= X-GMAIL-MSGID: =?utf-8?q?1749556589905685226?= 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 49f4308f1bd2..94f51cafee17 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 @@ -563,12 +563,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; } @@ -726,7 +724,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; } @@ -738,7 +736,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; } @@ -779,7 +777,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: @@ -787,11 +785,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 Tue Nov 15 10:11:21 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: 20286 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2626736wru; Tue, 15 Nov 2022 02:13:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf71kLtOvTLc4aqlWrXp5HvohYzXBWTUj+R8NHIy0amb7/0OxJ2QnV1fZMOPezd8aELDO5zM X-Received: by 2002:aa7:d3c6:0:b0:463:c64e:bc75 with SMTP id o6-20020aa7d3c6000000b00463c64ebc75mr14493091edr.205.1668507180945; Tue, 15 Nov 2022 02:13:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668507180; cv=none; d=google.com; s=arc-20160816; b=1I8I1eumu1vjUspq7VhJptO6FvT+rz6JcYnl+buc69TBlmLmq19++26i3XG9jC2CzB yMGea4BHmETarwb/IHA6a5n46NNCzRJboooVHb5R8tLc4o9fRpuLtqv6lUQJbHRh0FbN nue0kBXaQwsuTVPkTtYqyr7nH/IFBaquo1LVuOuuQbTMJlLus5ziLnREzTTlL6v13Hnk 1yFjRUid0KOxv6OxZ4yNjOSEXoH6pckRVArmfy7+n4n/LB9Nq2+MHXn6igttBR6wiwVB c+9EfX+L/7SeNqfCceGSOZpXsPGOdXTLK10wFg24J5WJZ9QXnu7ij+GRfntowjumNPHm O2zA== 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=B62K/Z6/R6gzNC1LreddV++368xlN2QmOO5zbb8a9ig=; b=RppxljGzJs8kxLg6EMufh4gFhPSzHDnWeOjGJ+kJjw7dUHrJEuxZb3U8mZbSPuIB3W M6eLMtrlcsNtjz4MCQB3874WIgZATW0Mh4AmnnCQ/wQXIst61yE8Fyw3qmQcUnYEzfDr 7eUtJWngBh+Ta7tO1omzrTKsjoirRyfnpvpcCvJc3Dvnk6vsxYUgpgdvyE9qRgYtDUWF /v4vY+40fnFqE3F+/lclkrb0sRl1/RAznbIxD3YlaELpo2VNdiO4rxbBADE1OzS7xKNa k36B//QvHqwK2d9GZxqxrkzOm3vj92sh6ztxdHftyA/Uh6fXWtwG2W00tLyeec6ufAbw xILw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=R9f0SOhb; 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 ne39-20020a1709077ba700b007ade8dd3517si12499503ejc.936.2022.11.15.02.12.35; Tue, 15 Nov 2022 02:13:00 -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=R9f0SOhb; 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 S238340AbiKOKLv (ORCPT + 99 others); Tue, 15 Nov 2022 05:11:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60462 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238292AbiKOKLl (ORCPT ); Tue, 15 Nov 2022 05:11:41 -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 6AC49EE1F; Tue, 15 Nov 2022 02:11:40 -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 459CA6602A42; Tue, 15 Nov 2022 10:11:38 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1668507099; bh=kUmZntOaNS58hkdHxPrKPiFeJBwDFkyN8sXE3Rzt6Xw=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=R9f0SOhbFqDIhwFe9Bs0a+DQ7S6lr8+SQj/vjvIjhlQZs+tpDyXZH6Lr7sDiqWj7L yeq0DiUsiNpw6TigMh5ubF0Y0hCmZW23CP+YSVwM0qyi3e7vhiHTODhCMfr/zZIXQR kj9/+sn1yAz+ZrIgT3G8tAPIaozxme0LbdqdQIENM/LdqnzUxDh42ysOMJFGVO/yii 9HVZ/ceu02M7bugjqmTmzddvRKv+/sGCvUJAh+RcviMwGvr4LXAEPjB1a6Ar609fvB AAXBZBJh2YOFEcvqbcM0fEFPm33PB+MddZMgNih7b+AJ1o+/ySyls8O42VH985hO8+ QHCH/Wp1hUsow== 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 v3 5/6] dt-bindings: iommu: qcom,iommu: Document QSMMUv2 and MSM8976 compatibles Date: Tue, 15 Nov 2022 11:11:21 +0100 Message-Id: <20221115101122.155440-6-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221115101122.155440-1-angelogioacchino.delregno@collabora.com> References: <20221115101122.155440-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?1749556585740716330?= X-GMAIL-MSGID: =?utf-8?q?1749556585740716330?= Add compatible strings for "qcom,msm-iommu-v2" for the inner node, Add compatible string "qcom,msm-iommu-v2" for the inner node, along with "qcom,msm8976-iommu" as a first user of it and "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 Reviewed-by: Krzysztof Kozlowski --- Documentation/devicetree/bindings/iommu/qcom,iommu.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Documentation/devicetree/bindings/iommu/qcom,iommu.txt b/Documentation/devicetree/bindings/iommu/qcom,iommu.txt index 7d4e0a18b08e..a8b42fa45e2d 100644 --- a/Documentation/devicetree/bindings/iommu/qcom,iommu.txt +++ b/Documentation/devicetree/bindings/iommu/qcom,iommu.txt @@ -13,6 +13,12 @@ to non-secure vs secure interrupt line. Followed by "qcom,msm-iommu-v1". + Or it should be one of: + + "qcom,msm8976-iommu" + + Followed by "qcom,msm-iommu-v2". + - clock-names : Should be a pair of "iface" (required for IOMMUs register group access) and "bus" (required for the IOMMUs underlying bus access). @@ -36,6 +42,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 Tue Nov 15 10:11:22 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: 20288 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2626813wru; Tue, 15 Nov 2022 02:13:12 -0800 (PST) X-Google-Smtp-Source: AA0mqf6ZgTR1rbLoDIAV4AOVd8lNiK+whgAW61Tr7Q0Bb9BGSVqTKpOkBbCL3JQvZHmCnhZ17+bH X-Received: by 2002:a17:907:7889:b0:78e:11ea:8528 with SMTP id ku9-20020a170907788900b0078e11ea8528mr13281404ejc.190.1668507192052; Tue, 15 Nov 2022 02:13:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668507192; cv=none; d=google.com; s=arc-20160816; b=GDkYtn1nNtkB9m4zbk/3yvYbLJ6hzsPhWviy2Aa7vyLtPBoDXpwi64Bspohnh/qDRX cH6UNLr7dRUj8DXFDxIVx7eEobxe8DtqQd+WiXx9oUSzobHYN9OEsrTqDA4Vz4RKzQR2 tG2WTbZUH0Q7As9nfZ6Ph+kidEs9YkQFN3nIof+BXzSnNkBd79cjbku44bHz53mqqDd0 fVENI3Snr9jTMeXk4WIZ5n71QjQmIVwLQdq7DiQqFmQN/9qTxGeow2peyFEgBaWeLtUM k41BA6OFmDZ2ThkNPgWImVvZUOTmCmt0eXGgFZ1Ztj0znx3TgV0hHO/Zp5Rc74loiqwp 6vww== 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=+2yBaoMOcV5yt0snIxI2AFbdcYAROcc5DzJEmbHg+g0=; b=cqhWJ7l7Gi9/XfJEWG2ZQR6YT7TfO/a0TDevD0D5x1Es40IkNSMsMiq8oY/VS98MHL S9FrCHHSu8i7yqDRCxDXlpSVwL6It/3Tk3GV0/OR2/kcxXr3U9IfRF2GwS+CIVj/KyyO hXQVCti5Y3w8BWn44L0VZJwj0/56CCkIgpIAP4IL83DAfOgXgCq1gQ6Kbx+JmFBsODTo P6BvsN8FNiknDqzUbyawP0fmlfCTGeYbuDHiep7WTJZrpT1EYy9O9JthMJIM2CDPkMgX 8xKSKZug4gLuVKsilDe4Qmri5i2ZwJtqs878mnTK1ToxiZUmYBZI0HK0K7yZ6FJiW1m1 yPlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=kKPZyci6; 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 f8-20020a056402354800b0046054d6b3a8si11069620edd.302.2022.11.15.02.12.44; Tue, 15 Nov 2022 02:13: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=kKPZyci6; 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 S238320AbiKOKMJ (ORCPT + 99 others); Tue, 15 Nov 2022 05:12:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238296AbiKOKLm (ORCPT ); Tue, 15 Nov 2022 05:11:42 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 983C9F3E; Tue, 15 Nov 2022 02:11:41 -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 751E66602980; Tue, 15 Nov 2022 10:11:39 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1668507100; bh=nr11OW0GjXZZd+uqu9pF2DuJ8K92kyYL5cWgAQ18zqQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kKPZyci6AotvDeCWL9iM2NEBpE7Z8BD20eVo35ib98AltVwiFBcwZmfIMnMFF1XPr 5vlVtGEjd11fz+YRLkMmUhn97qlpsdkc4DL6NhgMm7Mkwyq1oicoTZ7ILmmgDzuhjM ze0fKEDW33y8MZR0UepcThvIbFu3/lAeZE00q+cOipZQ8Lcqot9TRVnTyQN8HPCKck pMryKWdgZqXUNVnkCcUcU72ywyTz5g2+BhbOUwbY61ixF1hwqgKC+NR2GZoEY2LovL adOi8bpXpHWwZ9iuBZ2twoRkkWBhNpLm4nS9wufTfY8QLx9jZPPZJENuxux6eG7vRa qdyNF8dFcgZWw== 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 v3 6/6] iommu/qcom: Add support for QSMMUv2 and QSMMU-500 secured contexts Date: Tue, 15 Nov 2022 11:11:22 +0100 Message-Id: <20221115101122.155440-7-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221115101122.155440-1-angelogioacchino.delregno@collabora.com> References: <20221115101122.155440-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?1749556597383292276?= X-GMAIL-MSGID: =?utf-8?q?1749556597383292276?= 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 Reviewed-by: Dmitry Baryshkov --- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c index 94f51cafee17..db7d7cf5cc7d 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; }; @@ -287,6 +288,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 */ @@ -418,7 +425,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; } @@ -699,10 +707,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, @@ -744,6 +756,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 */ } }; @@ -761,7 +775,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; } @@ -909,6 +924,7 @@ static const struct dev_pm_ops qcom_iommu_pm_ops = { static const struct of_device_id qcom_iommu_of_match[] = { { .compatible = "qcom,msm-iommu-v1" }, + { .compatible = "qcom,msm-iommu-v2" }, { /* sentinel */ } };