From patchwork Thu Jun 22 09:27:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 111588 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4944749vqr; Thu, 22 Jun 2023 02:52:19 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6xahuF+WpS7kU/KfDTAxofPO0KiMtALAnc5vyYjb5229897FMxaY9ChTkkZ7J60TQWe0o8 X-Received: by 2002:a9d:69cd:0:b0:6b4:662a:d20d with SMTP id v13-20020a9d69cd000000b006b4662ad20dmr11478015oto.2.1687427539019; Thu, 22 Jun 2023 02:52:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687427538; cv=none; d=google.com; s=arc-20160816; b=Fu8xRszfcMKwf3I36WP0MIYFRYvPtCFEX5KwNb6Dbi8rbiIvU3chYa3bEa/9DTED8r bFbR/ZNxCe5bXZw295izt/Sg3l+EdUdkIIQ1t+boNwjBST0mmVinwIEjAer2OHRMvkCH 16l6jdDGMRdwDzrE7zo+Z9jX3tj05yB0+nRTlW+byKfH/lqa6QY2AIZusLHjYa6YRgVM ehBWk4946EArASOZj7oruKYf7NlVUjS9VMug/iug/7AKlPgHkE3UqpnvpOJBTYvLs0kZ AGHAy8tXJ903+WCJaK9N4d3GdZ1U6dzd9CO28LaN3ZC1w+VHO/GhPuS2Z+XBO8Kf2LwV DGrg== 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=c0KRk87XAtZrJrWHQHqeMLA62Db6+J6/FwlA7GC5itA=; b=w6Hy76ICHRzBleF0QMQc6KCWbu2tpNC/i82Zu8cLMEDJU336y49d4f+WdLKgAQG9wC QbgPpcOPG+zUSy0IyEu6y2ToykoPNseDHWl3gDBLtiHWS9H7tGgrFs9nTuxqDEmgETwU pNDrebAob/d/pfCecDzrkqvJc6t+H+ekILKLJJPSvuldZZdn4Fj2z5ab3cBAChZzOyFv O2wLbLzi2uQDUrsFHwT1AU9qMSKiA7eHSh7AZNNoSIvDeW23THaKGvcp+0usisJk/TT0 0/6AnzUr4kej3sPkJUYNAfHopuEVwelwYdrja8jwRVWEp3Bk5jUeV9xjKc2Usm+ULQOV 8xXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=PDQrVoks; 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=QUARANTINE sp=QUARANTINE 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 s26-20020a63925a000000b00553ebb05d14si5504337pgn.111.2023.06.22.02.52.06; Thu, 22 Jun 2023 02:52:18 -0700 (PDT) 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=PDQrVoks; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232400AbjFVJed (ORCPT + 99 others); Thu, 22 Jun 2023 05:34:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231991AbjFVJdi (ORCPT ); Thu, 22 Jun 2023 05:33:38 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9FF65268A; Thu, 22 Jun 2023 02:27:58 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:c5f8:7372:f042:90a2]) (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 569016607074; Thu, 22 Jun 2023 10:27:56 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1687426077; bh=fpJa5/i7ldd76fzTKhs5pEq675tqrNBKbMuRtH+2cEM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PDQrVoksQoaveDYzL5XafpXdVJMFaVhnz5DYCBKUIV7azGZHKZn2LmSUSy5uYZNbG 1qdJ7W7nL6/ov5F1B3RCBocVeBcv77FqVLZwT3TnU4QEmVaOhFlbD18pcKAjmqFIKR 9aKdYlx64bo+YZU0XI0LmZ9KHqod1Anx5FEATyyX+GlpvNawYKn4uhSELASGKfZyiQ DAIN4PTPsm7MvCBfnFKmq5G8clpnGstxQcDM/ipC2IO0sEG5KH7qV5Ko7G8zjGAu86 sSjkE8LE2K50HiPpLldLvNmxDIitqG/qNP0h3nwt5ImX9NkvCvfRHdt28VOiQqpTsp 4XicTV7w097lw== From: AngeloGioacchino Del Regno To: agross@kernel.org Cc: andersson@kernel.org, luca@z3ntu.xyz, konrad.dybcio@linaro.org, dmitry.baryshkov@linaro.org, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.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, AngeloGioacchino Del Regno , kernel@collabora.com Subject: [PATCH v5 1/6] dt-bindings: iommu: qcom,iommu: Add qcom,ctx-asid property Date: Thu, 22 Jun 2023 11:27:37 +0200 Message-Id: <20230622092742.74819-2-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230622092742.74819-1-angelogioacchino.delregno@collabora.com> References: <20230622092742.74819-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, T_SCC_BODY_TEXT_LINE 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?1769396019381837984?= X-GMAIL-MSGID: =?utf-8?q?1769396019381837984?= Add a new "qcom,ctx-asid" property to force an ASID number on IOMMU contexts where required. Signed-off-by: AngeloGioacchino Del Regno Reviewed-by: Rob Herring --- Documentation/devicetree/bindings/iommu/qcom,iommu.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Documentation/devicetree/bindings/iommu/qcom,iommu.yaml b/Documentation/devicetree/bindings/iommu/qcom,iommu.yaml index d9fabdf930d9..f7a64ad8a005 100644 --- a/Documentation/devicetree/bindings/iommu/qcom,iommu.yaml +++ b/Documentation/devicetree/bindings/iommu/qcom,iommu.yaml @@ -71,6 +71,11 @@ patternProperties: reg: maxItems: 1 + qcom,ctx-asid: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + The ASID number associated to the context bank. + required: - compatible - interrupts From patchwork Thu Jun 22 09:27:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 111581 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4944231vqr; Thu, 22 Jun 2023 02:50:59 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ66VjxiCekiqZxq/pYDQ48xThpFq8ge1T/lYZ9Tr1com6NBYRCYhYIWja5E0KfQu6vSYBlS X-Received: by 2002:a92:d090:0:b0:338:d170:6e32 with SMTP id h16-20020a92d090000000b00338d1706e32mr18634034ilh.7.1687427459598; Thu, 22 Jun 2023 02:50:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687427459; cv=none; d=google.com; s=arc-20160816; b=tTwGPns1XSZWXnVsdq3806mZAoXbvMYTgnG+9/bVrnBDxXD4soeGjI6cEvnjv34OFv bRUjxQSKGnO/TTBaCbGrw6meM974x0G68+CtawxcuJVKk7UyvGYVs5DGErK1nIgwroJV EcpTN/D4/PPEWKc0IjrGv7HvOyOaGNEIfixc3WTrrP8cKK3YqEUrvDS27ebwwY4QwJ/L 4qbWeadIMxkRL6X8vKDvpDmFA93vqcsZnYJXyRNwJ9K/RFRs7NpQuFRnpcW3BGuR0zAp LfRbNy6fBr69ja/myfOWi3tb4ni88/Hl4bicc2vyTtH9DpdCtxT6HRUNPv0+NWia6WTD lLxA== 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=8i/CEMt+caQXI4CQ6N0u4G0S/6Yq2Gtzmk3eKpoXTjI=; b=FbBosNyH0TQj86aZIetHW6wPOc+ak2z9MQs+Jlvx5Ayby8EOKV4bXquQENB672jTRp rtNgsbFZICC9pj8y0jZ30wAJhRcS3xEmNm/bD+jjubQsSjhq5+LSoOpmD77WnhJIGDGU BS7iigBtf/SMk/QVriJDnD7sZOSM+UsKn02eKnWnToV+ExHheH31Trl0wQFJh3m9zcpi CLZZhvaK+6jY5v+MUD4QFAtbiO1pwS4sfuM4zXTuff3t/ju/MLvKdcu0wFojN+LTLLS+ NfcjX77cC0PqibYSeTHDhd51HjGFLlTiaIBzx5s+7X18BYwal+4Mxws3fwO11qxjmbDn gydg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=m37hezI9; 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=QUARANTINE sp=QUARANTINE 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 e65-20020a636944000000b00553c4551a08si5979621pgc.887.2023.06.22.02.50.47; Thu, 22 Jun 2023 02:50:59 -0700 (PDT) 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=m37hezI9; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232408AbjFVJeh (ORCPT + 99 others); Thu, 22 Jun 2023 05:34:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39486 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232068AbjFVJdl (ORCPT ); Thu, 22 Jun 2023 05:33:41 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0B9A92697; Thu, 22 Jun 2023 02:28:00 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:c5f8:7372:f042:90a2]) (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 8FDE06607075; Thu, 22 Jun 2023 10:27:57 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1687426078; bh=cjwGV4PBGa2G0fyxMUorKbKCregA7+FHFAZQsfL0PRY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=m37hezI9O+FIW53mDrj1fpvmgKyTxgIcCC1DpCNs+GjhhVfb9UFw6hqoRzc2LXMPM Qkbk2d6MFxwk+xySVz2XHuURvTzHhfepVbWdVnG1LKvnOgHxuZa2XVi04qbn3yFSCw ATIyD6sh7+zFrrdRKjGqRHKWQSZv5PRjFYf4V1r/yizDBMFJiuSwsL6YG8HfUsBrE1 f0QYSj1rl+PSL08dCY3htW3h2Z+LpQQVOzyMyZNUSUz5EZegHDwS7dHgaRr0NfCeGi T3bVFrUlnA19w8/Z7YyRUod2UZpQG3B5dIA4XyKMt1RD1F8Mc191qdn8UmeYSyKNkG wsQImsYA5NYmQ== From: AngeloGioacchino Del Regno To: agross@kernel.org Cc: andersson@kernel.org, luca@z3ntu.xyz, konrad.dybcio@linaro.org, dmitry.baryshkov@linaro.org, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.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, AngeloGioacchino Del Regno , kernel@collabora.com, Marijn Suijten Subject: [PATCH v5 2/6] iommu/qcom: Use the asid read from device-tree if specified Date: Thu, 22 Jun 2023 11:27:38 +0200 Message-Id: <20230622092742.74819-3-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230622092742.74819-1-angelogioacchino.delregno@collabora.com> References: <20230622092742.74819-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, T_SCC_BODY_TEXT_LINE 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?1769395935324351793?= X-GMAIL-MSGID: =?utf-8?q?1769395935324351793?= 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-asid": when found, the ASID will be forced as read from the devicetree. When "qcom,ctx-asid" 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 Reviewed-by: Konrad Dybcio --- 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 a503ed758ec3..8face57c4180 100644 --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c @@ -531,7 +531,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; } @@ -617,7 +618,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: @@ -625,7 +627,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-asid", &val)) + asid = val; + else + asid = reg / 0x1000; + + return asid; } static int qcom_iommu_ctx_probe(struct platform_device *pdev) From patchwork Thu Jun 22 09:27:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 111576 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4938625vqr; Thu, 22 Jun 2023 02:36:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4FQfizmjF8LxFjp+ItnxZ/pxPjMvZAaC/iZ5NSQ2Z0GwjAJU4yiDuXOE6OJZDfBxnOQh6V X-Received: by 2002:a9d:6d98:0:b0:6b2:9391:7e74 with SMTP id x24-20020a9d6d98000000b006b293917e74mr13819346otp.23.1687426562727; Thu, 22 Jun 2023 02:36:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687426562; cv=none; d=google.com; s=arc-20160816; b=QGBK6uaLYesCawOJW9kwOMI9NoNsGligA1NgGgG/qsTRz9AXR5gDPnQ6KH8PX8L+U8 7+HISnkw99ti5I3AZreSRXw/05J7C60x6rtZGiqalaNhAHWrZn0EhXLh2Yh0WW0sys+U wHKNAjZUF+stZL3hM6xsiJVw8RO52ATSydjCBOtU1+B0cCETGNmWnxuO4oqae0UzfO+L Vwtak9ydz2/c1x133YRS6T3hXu/KqZRMvKoDrLn2PsoBwPT0SNyCF0F99vykSezNVHHK rmu4mR9XQ2FtUmTfa7ULKMhaPLrzAHTC7MggqliUoRNiteBEOrMRu0Sz/ka2ox0BFyo+ qjZg== 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=pvxfYFpm7NrYQ4wUKk84ULmkrAkuUF5dCRvvJT/alqo=; b=tXU2hZKtSBAKOA1W9C0X7fssZ1xfisfIwylPHsK7GY4lYDeVL7gj4gPK+QYuXsZecX A0cN22UFXI8EqWxIsnGvrWn5vAjXDlwJFmUF6/2RNrJtxDsYxSfQJRCnzcwfanxfMB7/ ZgrrrF+rjjia/l3Rtdrzg3Lj0kX5mz84JYujMrTaWqeVY1kfo5n+i0v6EdqBYB/KRUp5 F0e6amnbktszPgLhANYQTC5qne72HR2zbNZJvaOYy8GecHP3oMTmUlhizThYc8Vzxyj9 3E90RrAm0WmXSsOFdWPDHgGEnngqMNHhyTIxpr1wXbc4gJd4Uxzi5bGQ+ZWPBjWnw7gs WGQQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=YV5h54SS; 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=QUARANTINE sp=QUARANTINE 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 e124-20020a636982000000b0053ef95fa919si6149866pgc.458.2023.06.22.02.35.50; Thu, 22 Jun 2023 02:36:02 -0700 (PDT) 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=YV5h54SS; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232242AbjFVJel (ORCPT + 99 others); Thu, 22 Jun 2023 05:34:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232294AbjFVJdn (ORCPT ); Thu, 22 Jun 2023 05:33:43 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0C9AC269A; Thu, 22 Jun 2023 02:28:01 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:c5f8:7372:f042:90a2]) (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 D40B46607076; Thu, 22 Jun 2023 10:27:58 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1687426079; bh=6+3tbpupafFXA1rZOX62kA5wZpU6l7nAzHW/LEoVbSo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YV5h54SSiaMStnZD8ND7+jqH4UJmBv5qedqLEP4ElMGJuf5tXM9PL1bEg1ZPnWF3N zKIJKRBxV8dY/apgMYDjkZ+tVwscI8IXbd02AEDPrhzHNUblBYQchg8xzWRxcmO6u/ 9MPh5GCiYyrCl7IPgwiM4LZnWL3TyLfV//cqd6ugDQI107ABq/5u/02BguVqu9QXyY PEF8qYu/U1iAhdrf/HKXdLD/CRUTQU1saehIf+OBS3TV7IXNm3TaK7D3F/R2chkQXs 2C7bRmdp3GC6b/M7tqhVagMKDOB8U5nnrehQnSmZ8pVpCHC/hXEt3vv7lTZ4+LRTB3 TBLvvh+LtKe0g== From: AngeloGioacchino Del Regno To: agross@kernel.org Cc: andersson@kernel.org, luca@z3ntu.xyz, konrad.dybcio@linaro.org, dmitry.baryshkov@linaro.org, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.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, AngeloGioacchino Del Regno , kernel@collabora.com Subject: [PATCH v5 3/6] iommu/qcom: Disable and reset context bank before programming Date: Thu, 22 Jun 2023 11:27:39 +0200 Message-Id: <20230622092742.74819-4-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230622092742.74819-1-angelogioacchino.delregno@collabora.com> References: <20230622092742.74819-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, T_SCC_BODY_TEXT_LINE 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?1769394995264268727?= X-GMAIL-MSGID: =?utf-8?q?1769394995264268727?= Writing the new TTBRs, TCRs and MAIRs on a previously enabled context bank may trigger a context fault, resulting in firmware driven AP resets: change the domain initialization programming sequence to disable the context bank(s) and to also clear the related fault address (CB_FAR) and fault status (CB_FSR) registers before writing new values to TTBR0/1, TCR/TCR2, MAIR0/1. Fixes: 0ae349a0f33f ("iommu/qcom: Add qcom_iommu") Signed-off-by: AngeloGioacchino Del Regno Reviewed-by: Konrad Dybcio --- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c index 8face57c4180..f1bd7c035db8 100644 --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c @@ -273,6 +273,13 @@ static int qcom_iommu_init_domain(struct iommu_domain *domain, ctx->secure_init = true; } + /* Disable context bank before programming */ + iommu_writel(ctx, ARM_SMMU_CB_SCTLR, 0); + + /* Clear context bank fault address fault status registers */ + iommu_writel(ctx, ARM_SMMU_CB_FAR, 0); + iommu_writel(ctx, ARM_SMMU_CB_FSR, ARM_SMMU_FSR_FAULT); + /* TTBRs */ iommu_writeq(ctx, ARM_SMMU_CB_TTBR0, pgtbl_cfg.arm_lpae_s1_cfg.ttbr | From patchwork Thu Jun 22 09:27:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 111577 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4938626vqr; Thu, 22 Jun 2023 02:36:03 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5n6xNusEeN40bvZcvWsedjS7cSAAEKaNFqWP9x8Y3HZSryAYPF8Gw4fsLK53kIO3hpD/85 X-Received: by 2002:a05:6a20:9385:b0:10c:4ff5:38b7 with SMTP id x5-20020a056a20938500b0010c4ff538b7mr9090386pzh.6.1687426562757; Thu, 22 Jun 2023 02:36:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687426562; cv=none; d=google.com; s=arc-20160816; b=YipFuah44jo7hnBv2huM7J50bIh4XjAC/zl2m0WYew9uoY5pSACuKy+Jejk2Vdcb2L pgIHVYZ1ctYHr5AwHcrs7tH1SbERsle5Dn9vSeHM2xlhrBPcygRQV4bAxyyPeeyGFjr3 CE0OHePlac0Hdw08cpzXOJgH/l1D32JlJ23kxmdXvTPiqG8ofjP4abYD7/SaCtPgwmaC 7Pm0uf/v6NSUOz3ZvT0EA5wo+YGjvl9rOQj92e5ZHQHbTNT3En4eRgkJ9oIh3t2X3Y7r 4/3n1003s3YIwk4FIef2a9zYoIuo4Uhew1E1fADIhFkBMdXueHir+a1UdGmfwH95exof L4iw== 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=uD01/Us/kNN8dexpaf6Eg6YDBfK5k8VPCQKWGU6I0f4=; b=m1QUE8BQUEuZKGeYvYxFdvac8Emp5YsW4McfFY/5RNaG78nixl2B8OkLTCzu7mUSIj 1N/GZfhk91CAlJN8XSJHOEwae+5ibZPXxtrbDt+RFwn1ovtNCYLcfxw5KJqmONeTHlN+ wqNllU3EZDPQlLyhiAD08G9s5zDTl2QURZKS/xLRjcL3V4wWl8fv5BNx2gzj0axO6Z8G s1KjCv2dVOAZ1YCLCdS/po+s7KDSU68tGO7s/Wa/KMRjewPeHbXMrF/XNt6B4pAVb9XC Ikduc16trU3UHbN4YDTUuTsslPZHyKvAEl0EuoUoiyewK/tFvHbfzBnyR0lp5atcWoSZ s50g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=hjpr1ZOf; 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=QUARANTINE sp=QUARANTINE 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 b22-20020a637156000000b005538cfa80e3si6007132pgn.310.2023.06.22.02.35.50; Thu, 22 Jun 2023 02:36:02 -0700 (PDT) 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=hjpr1ZOf; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232429AbjFVJeq (ORCPT + 99 others); Thu, 22 Jun 2023 05:34:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36484 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232174AbjFVJdn (ORCPT ); Thu, 22 Jun 2023 05:33:43 -0400 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 442F9269F; Thu, 22 Jun 2023 02:28:02 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:c5f8:7372:f042:90a2]) (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 1B33A6607073; Thu, 22 Jun 2023 10:28:00 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1687426081; bh=CngEEwFWw5udIT5tiX3hlaCWhy4SYtKzrubNQdXxupI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hjpr1ZOfp2SXOJIs7zShgoYvD+7NxZTzrN02RusmiW3IlVvIw1bJjaubw7M3/qvd3 SvFjuo+LlqtOn6ZgEK1QIEg/kuL4TWUJdsy+lOPkofvqK6oywLdSd4BIxLRT4B8dxi FRT6osdAe1ieG4iUoB1CB+SA7npGuvQyvjsO1Gutu3jqcPmeb5xKhFlNna1m3zk4Kz 6vJrtnwbGNfRnscEO5vugE0QHCSbZtUpttU+VgrMCZbWksuEbYuW+d5KzuwiCQnMCY hdaIhOI5megPxHNI96aZtaQnlaGLH3jLJsH8iOIl9ebBwKP/H8wZaz5d87kK8SsTPm vjC8tHyXqqgnA== From: AngeloGioacchino Del Regno To: agross@kernel.org Cc: andersson@kernel.org, luca@z3ntu.xyz, konrad.dybcio@linaro.org, dmitry.baryshkov@linaro.org, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.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, AngeloGioacchino Del Regno , kernel@collabora.com Subject: [PATCH v5 4/6] iommu/qcom: Index contexts by asid number to allow asid 0 Date: Thu, 22 Jun 2023 11:27:40 +0200 Message-Id: <20230622092742.74819-5-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230622092742.74819-1-angelogioacchino.delregno@collabora.com> References: <20230622092742.74819-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, T_SCC_BODY_TEXT_LINE 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?1769394995265882552?= X-GMAIL-MSGID: =?utf-8?q?1769394995265882552?= This driver was indexing the contexts by asid-1, which is probably done under the assumption that the first ASID is always 1. Unfortunately this is not always true: at least for MSM8956 and MSM8976's GPU IOMMU, the gpu_user context's ASID number is zero. To allow using a zero asid number, index the contexts by `asid` instead of by `asid - 1`. While at it, also enhance human readability by renaming the `num_ctxs` member of struct qcom_iommu_dev to `max_asid`. Signed-off-by: AngeloGioacchino Del Regno Reviewed-by: Konrad Dybcio --- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c index f1bd7c035db8..9786fd094e7d 100644 --- a/drivers/iommu/arm/arm-smmu/qcom_iommu.c +++ b/drivers/iommu/arm/arm-smmu/qcom_iommu.c @@ -51,8 +51,8 @@ struct qcom_iommu_dev { struct clk_bulk_data clks[CLK_NUM]; void __iomem *local_base; u32 sec_id; - u8 num_ctxs; - struct qcom_iommu_ctx *ctxs[]; /* indexed by asid-1 */ + u8 max_asid; + 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 @@ -534,12 +534,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->max_asid) || + WARN_ON(qcom_iommu->ctxs[asid] == NULL)) { put_device(&iommu_pdev->dev); return -EINVAL; } @@ -696,7 +694,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; } @@ -708,7 +706,7 @@ static void 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; } static const struct of_device_id ctx_of_match[] = { @@ -755,11 +753,11 @@ 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), + qcom_iommu = devm_kzalloc(dev, struct_size(qcom_iommu, ctxs, max_asid + 1), GFP_KERNEL); if (!qcom_iommu) return -ENOMEM; - qcom_iommu->num_ctxs = max_asid; + qcom_iommu->max_asid = max_asid; qcom_iommu->dev = dev; res = platform_get_resource(pdev, IORESOURCE_MEM, 0); From patchwork Thu Jun 22 09:27:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 111597 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4946672vqr; Thu, 22 Jun 2023 02:57:33 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5teYJepXtuP1/YWwhiIghBI9OMAdOjDOdXwzkUUN3phdU1rwsMElPnKAQGk7e124YtVe/F X-Received: by 2002:a05:6808:4291:b0:39e:ae2e:60e2 with SMTP id dq17-20020a056808429100b0039eae2e60e2mr18769026oib.32.1687427852899; Thu, 22 Jun 2023 02:57:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687427852; cv=none; d=google.com; s=arc-20160816; b=LVLQHV6Tq+m2MljNimzM2RQGFrGPEl3q2JiimgXTPM/zq0b8tFyYqd3mhm2bRXEkhA /Ah4icduxEL3QG1xU3XMDImoOWw9BEUSCicZzDYiW/IjdSLXuS2x+maNGriMPtZ3iL1a QizWar8fLEN5iuO1h9vQEnZjnQdul5ngev5ikeD7iZ7lgNz0MjSOAJDVU3ySSqq9j4zp uPfJuhtf8qTG+dGb6xi+lEXcdMqKSzbTR0dqyYcGtSIus8MEmeBD5n0x5DI/dfN2rOxV mwBWSv/h/FityAyeMZ0qLZDwvk19Q959oPcxKFhjuzaaDmg3PB9/IFoi0pDDENwLJaDx YQUg== 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=x1yCsTNHcRjMdCsDO3/pfYfuUQfPZGcKKpXZt1WhFhw=; b=GKvtzbZxYdX8Ew92pJdiix4+JNUz6a9t5sGrzh18XIleBviypB93yc9qZMSk98pojE wQHBw54E5bf9Kh86KQw7QPyGFvgC5FDTtqgmca+joiJ9wK9qyGp3y0TPg6d7HHJXD//1 NQc6Rm/ulIt8pDCn/mn/xcPNgjLVP37l1NR2eHPNIyz6Wj0fmIc0CcrX04LuuJIqr32o 7UgzHxY3yOkLAFNdq0ra7iyyBe/EtWDhWDN9gSu4oqSGbGTpb0n+gnJ7fOChxw/jf9WU fCsvTKhK/bfi/4Cp0+5N4geXmUJLqb965DOnu5frPs1gV+Z+YMR1Fo9UdNfHC8j/ArCJ C1Dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=avQ2eD8+; 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=QUARANTINE sp=QUARANTINE 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 72-20020a17090a0fce00b0025bdaaf0d17si6096404pjz.33.2023.06.22.02.57.20; Thu, 22 Jun 2023 02:57:32 -0700 (PDT) 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=avQ2eD8+; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229924AbjFVJf0 (ORCPT + 99 others); Thu, 22 Jun 2023 05:35:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38532 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232023AbjFVJdo (ORCPT ); Thu, 22 Jun 2023 05:33:44 -0400 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 9737326A5; Thu, 22 Jun 2023 02:28:03 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:c5f8:7372:f042:90a2]) (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 530306607077; Thu, 22 Jun 2023 10:28:01 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1687426082; bh=RBuC46hmr6lxKxb743CP1Q/DCSEVEyNhNzronT5Rcf8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=avQ2eD8+QLW/pSP/VeHhlTNyOEll/57wPMy2CbFD8IGdoztlxnwYMdaP9822YNOM6 vYmE0gJl6jkfI5A9KtOeQrfkErg5v2AOGzFujZPAov5o97R1z0iZagIoGsVKOmTVlU y07POElGMPobsaei9cido+LNo86givZNdWUR2C+sfwWXQhJfmgvVrHzj6si88dgbQl MyvCdVXV0z+/gHwBsisiK15+8PI5mT2tkgKyFsSSOkj5JWS6en3yvKvPzFTIimV+VJ vDU1Qru7u0JzusEDWHFWmNNNCQvgt3fqF50+N/C5O1oproOZNT4OH/K107hCIiOj6G iv6q3gXGjPObg== From: AngeloGioacchino Del Regno To: agross@kernel.org Cc: andersson@kernel.org, luca@z3ntu.xyz, konrad.dybcio@linaro.org, dmitry.baryshkov@linaro.org, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.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, AngeloGioacchino Del Regno , kernel@collabora.com, Rob Herring Subject: [PATCH v5 5/6] dt-bindings: iommu: qcom,iommu: Add QSMMUv2 and MSM8976 compatibles Date: Thu, 22 Jun 2023 11:27:41 +0200 Message-Id: <20230622092742.74819-6-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230622092742.74819-1-angelogioacchino.delregno@collabora.com> References: <20230622092742.74819-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, T_SCC_BODY_TEXT_LINE 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?1769396348591429441?= X-GMAIL-MSGID: =?utf-8?q?1769396348591429441?= 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: Rob Herring --- .../devicetree/bindings/iommu/qcom,iommu.yaml | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/Documentation/devicetree/bindings/iommu/qcom,iommu.yaml b/Documentation/devicetree/bindings/iommu/qcom,iommu.yaml index f7a64ad8a005..a74eb899c381 100644 --- a/Documentation/devicetree/bindings/iommu/qcom,iommu.yaml +++ b/Documentation/devicetree/bindings/iommu/qcom,iommu.yaml @@ -17,11 +17,16 @@ description: | properties: compatible: - items: - - enum: - - qcom,msm8916-iommu - - qcom,msm8953-iommu - - const: qcom,msm-iommu-v1 + oneOf: + - items: + - enum: + - qcom,msm8916-iommu + - qcom,msm8953-iommu + - const: qcom,msm-iommu-v1 + - items: + - enum: + - qcom,msm8976-iommu + - const: qcom,msm-iommu-v2 clocks: items: @@ -64,6 +69,8 @@ patternProperties: enum: - qcom,msm-iommu-v1-ns - qcom,msm-iommu-v1-sec + - qcom,msm-iommu-v2-ns + - qcom,msm-iommu-v2-sec interrupts: maxItems: 1 From patchwork Thu Jun 22 09:27:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AngeloGioacchino Del Regno X-Patchwork-Id: 111594 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp4946068vqr; Thu, 22 Jun 2023 02:55:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6JS4UZRy7Qvz0gLvByovZtN+KI2a7RjXNNKg6ccWtS9051QLF4/pT5MS7BKGqzMFXpvjQo X-Received: by 2002:a17:902:d702:b0:1b3:9d13:34b3 with SMTP id w2-20020a170902d70200b001b39d1334b3mr13637598ply.37.1687427756031; Thu, 22 Jun 2023 02:55:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687427756; cv=none; d=google.com; s=arc-20160816; b=b2AI/P13msWoTz5Urbjcs3iC63NGir3FTq81PZZ7fQ6YgORPW8HAOw1wSovNbCk1y9 h+gCR+ahSt61UT7/VmXw+2U09GoO6Hv6CJ7z53gnfYpKTLS8eLTvk4qH1zqSnLYFLnRe +Do8GmMC3dYVnyAxY147a37i/yO4hrAeoyJszy5KgC+fl/SJ+swbGVz1PyaqVbUzZVdG uRds6HLT85Lmyomq72Ls01cRdzue5umRBcSX79dTqywjksU4SzE1jH7znI9kNd7A0y15 TQs7iql3zU/HEcbdCtBsZFlm7pHWXq/hnNmaMfKHqQpeMbVThPB8dWRJu1hCjkR8gFQ0 5XMQ== 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=lwXF+xwgCJiLrd14z+aLV8LMeLMErE26F5xYFIZOGZg=; b=MIyPrcnb9/4yObm/Ru3EgSgzN7eIADYcwCJsxk7YgydyzG4mAgmkjjbnS1aseFTIhc jdJN/M4xzBX/pZ5QDFFuwRLKOG+gpNJYfCINl7u/KPZ+q0yq9OSmvORp/DrDNywcfUdm e7f1opSFte6T1cKsjDSWGOih4n+LkX/zkWmTQL/Ct2k61ULDDLFeHa8vhtAaDukcJRPk X0QpUAAQznWuBDC/QJWnVmpGlVDIyecF86KBaIC8jClJKrDGDlwL5TN00LT/OQH7UWlV gwO5otV4FeTXEzp2qx9PpXzLUZqerFLJxaC5ktMy6jsKvU8fPgicfejVHUhjjaq/8K1P 6RFQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@collabora.com header.s=mail header.b=Z5de8s7e; 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=QUARANTINE sp=QUARANTINE 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 g10-20020a170902934a00b001b55192fa0asi5891589plp.46.2023.06.22.02.55.42; Thu, 22 Jun 2023 02:55:56 -0700 (PDT) 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=Z5de8s7e; 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=QUARANTINE sp=QUARANTINE dis=NONE) header.from=collabora.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230244AbjFVJfa (ORCPT + 99 others); Thu, 22 Jun 2023 05:35:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231981AbjFVJdt (ORCPT ); Thu, 22 Jun 2023 05:33:49 -0400 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 D49F426A8; Thu, 22 Jun 2023 02:28:04 -0700 (PDT) Received: from IcarusMOD.eternityproject.eu (unknown [IPv6:2001:b07:2ed:14ed:c5f8:7372:f042:90a2]) (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 95AB16607074; Thu, 22 Jun 2023 10:28:02 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1687426083; bh=+uExxuo8h2T7GFt5bvQIbcFkvr4CRRqph4Cl584xqkA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Z5de8s7eMgTJLSc+T/gQAJNvv3j/FMZjGX3zvP0Qkxiywmzs0jc/NNFsFn3AVKEXv 8/WAefQTLGjGtUYCZp1PfYdEoe3gv9l+PMiXDWbvCz20p401MbzX63b5N7cfUjVG4P edPajuFNXIeKlB77nDynZTmTpNtt0fUa0xAIOgmKmLNlacq3oyNZoSqEi1COlar2vy 4jGMArZcLhBf6Sap8ASzNeIVngRggp7J2bSMxqiaIcTxBbPkqvg+8/95hFRVCP3ALK PLOaZ7nTioO3MiBqwgwBEijhe4V0K7uEeSyi5vX5AJPZeStj7ZdJbEQ/DhpUowaoO4 dgUAVzQMrID9w== From: AngeloGioacchino Del Regno To: agross@kernel.org Cc: andersson@kernel.org, luca@z3ntu.xyz, konrad.dybcio@linaro.org, dmitry.baryshkov@linaro.org, joro@8bytes.org, will@kernel.org, robin.murphy@arm.com, robh+dt@kernel.org, krzysztof.kozlowski+dt@linaro.org, conor+dt@kernel.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, AngeloGioacchino Del Regno , kernel@collabora.com, Marijn Suijten Subject: [PATCH v5 6/6] iommu/qcom: Add support for QSMMUv2 and QSMMU-500 secured contexts Date: Thu, 22 Jun 2023 11:27:42 +0200 Message-Id: <20230622092742.74819-7-angelogioacchino.delregno@collabora.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230622092742.74819-1-angelogioacchino.delregno@collabora.com> References: <20230622092742.74819-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, T_SCC_BODY_TEXT_LINE 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?1769396246664768976?= X-GMAIL-MSGID: =?utf-8?q?1769396246664768976?= 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 Reviewed-by: Konrad Dybcio --- drivers/iommu/arm/arm-smmu/qcom_iommu.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/drivers/iommu/arm/arm-smmu/qcom_iommu.c b/drivers/iommu/arm/arm-smmu/qcom_iommu.c index 9786fd094e7d..7b6241f36698 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; }; @@ -273,6 +274,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; + } + /* Disable context bank before programming */ iommu_writel(ctx, ARM_SMMU_CB_SCTLR, 0); @@ -669,10 +676,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, @@ -712,6 +723,8 @@ static void 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 */ } }; @@ -729,7 +742,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; } @@ -873,6 +887,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 */ } };