From patchwork Wed Sep 4 10:00:10 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 13790376 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 53539CA0ED3 for ; Wed, 4 Sep 2024 10:23:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=7HUlfn1xmn+4ZGiB6aVKgQXPt7LJ9m0S52DW4howHBI=; b=yAyMy/K1kpDtbkx35lddUyNiwe o56G8cyv7Qud6vYuF6nHDUj++xyMjpycaTUpX0FaGO+F/8B1UzoV+YZaLWntqarsDrwzwszaag3qY Bh+R5Ytqv7Jcc4OM1NOLG5v9shhedBHZTS94DY3RE3UH+SMg5Le/H+QaAHS3NlMK46UfOyfGvxuQF Kc/O/woENR5w7f3uUJ+AkQyfAbcw2gzM2oKx366p85sWjydeSSOuCugwbMOx3g6+f6xvo049TV9rE 3yuXT1FwHtYYh1+zuq5xHGAicUOBzFjy3HXHuPZlqHEY7h5V/XAZDB8/T/99XE8WezD2fE1oQM/fS 47ANmhkg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slnAt-00000003tu3-31fo; Wed, 04 Sep 2024 10:23:44 +0000 Received: from mta-64-227.siemens.flowmailer.net ([185.136.64.227]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slmoL-00000003npb-2o36 for linux-arm-kernel@lists.infradead.org; Wed, 04 Sep 2024 10:00:27 +0000 Received: by mta-64-227.siemens.flowmailer.net with ESMTPSA id 20240904100021d9302827222aafbc92 for ; Wed, 04 Sep 2024 12:00:21 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=jan.kiszka@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc:References:In-Reply-To; bh=7HUlfn1xmn+4ZGiB6aVKgQXPt7LJ9m0S52DW4howHBI=; b=iGgNXnCYTeYsxqIrYKA39V2cry8w29Px9iGsiHUsbnmoXDLQzy8SItcKk3sH1/ugtTRV3t hur96c9ZxdztAVbi39ExtTQdUtbdK9Xh7DKqVAWHu1myHprlQmYFYsWGbi5CqyblWfwcDYw8 fh6cis22PKfOFyrz+vfhwn0541pkybNblrMBR4rA0l4Mdpcvww6fzGrZFcoTQm5ficPOz+yI PkkPcxNM/YjgrqP0wIFO7AWiOF8HoURudf8mmWOXmHU9l3YFujf9fW0HdtudVhaoJJPKI7cU peHeXWY3ZWD9kMvpmGvithI1AxyZOVti9LwEGkUQufofvyMgVq+9IRfA==; From: Jan Kiszka To: Nishanth Menon , Santosh Shilimkar , Vignesh Raghavendra , Tero Kristo , Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, Siddharth Vadapalli , Bao Cheng Su , Hua Qian Li , Diogo Ivo , Krzysztof Kozlowski Subject: [PATCH v4 1/7] dt-bindings: soc: ti: Add AM65 peripheral virtualization unit Date: Wed, 4 Sep 2024 12:00:10 +0200 Message-ID: <4689ffb3d0ba97167234661e61ab26eb8d637aa2.1725444016.git.jan.kiszka@siemens.com> In-Reply-To: References: MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-294854:519-21489:flowmailer X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_030026_184511_1C6FA414 X-CRM114-Status: GOOD ( 11.93 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Jan Kiszka The PVU allows to define a limited set of mappings for incoming DMA requests to the system memory. It is not a real IOMMU, thus hooked up under the TI SoC bindings. Signed-off-by: Jan Kiszka Reviewed-by: Krzysztof Kozlowski --- .../bindings/soc/ti/ti,am654-pvu.yaml | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml diff --git a/Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml b/Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml new file mode 100644 index 000000000000..e4a5fc47d674 --- /dev/null +++ b/Documentation/devicetree/bindings/soc/ti/ti,am654-pvu.yaml @@ -0,0 +1,51 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright (c) Siemens AG, 2024 +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/soc/ti/ti,am654-pvu.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: TI AM654 Peripheral Virtualization Unit + +maintainers: + - Jan Kiszka + +properties: + compatible: + enum: + - ti,am654-pvu + + reg: + maxItems: 2 + + reg-names: + items: + - const: cfg + - const: tlbif + + interrupts: + items: + - description: fault interrupt + + interrupt-names: + items: + - const: pvu + +required: + - compatible + - reg + - interrupts + - interrupt-names + +additionalProperties: false + +examples: + - | + iommu@30f80000 { + compatible = "ti,am654-pvu"; + reg = <0x30f80000 0x1000>, + <0x36000000 0x100000>; + reg-names = "cfg", "tlbif"; + interrupts-extended = <&intr_main_navss 390>; + interrupt-names = "pvu"; + }; From patchwork Wed Sep 4 10:00:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 13790377 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 91DA7CA0ED3 for ; Wed, 4 Sep 2024 10:24:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=DgtS7ahOE4MmAw5xSeUX02j6OJr0If6h53x4evkGsRY=; b=mmoSAdnOuCcqlEczfg+LLum7fg NuqVsD2QZ+Jwx8ObQdSgBSrCXUnK2JjmCC7IAfxgW5haaNkBH9VZ23t6WnUW9DMkKRPAJvVOXhD9c 1yhSz+L+KjQ/qzpd27/np33oAuLFNOmXne2rP1gQWt1gxq6WUAN8NbEKYG7vs172kWzLtq0IpdHjs 9Wc2xtLp6t9amKmVf0w6y2VJKU/D4tdNCOf7BzqXmy8ecf1DzTCiuxkySKcQYaf5bywLSdUjXyzmr WqrCMnQEZLTAbvp4RoZhKa/cWdFpGFDhtUJuzDCeR0y97aJg1/u4pEptmLQYMaQQawkWMz99Qtp37 zpA9Pw5A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slnBn-00000003u89-2YGd; Wed, 04 Sep 2024 10:24:39 +0000 Received: from mta-64-227.siemens.flowmailer.net ([185.136.64.227]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slmoM-00000003npq-0EbJ for linux-arm-kernel@lists.infradead.org; Wed, 04 Sep 2024 10:00:29 +0000 Received: by mta-64-227.siemens.flowmailer.net with ESMTPSA id 20240904100023877f69722229615a0d for ; Wed, 04 Sep 2024 12:00:23 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=jan.kiszka@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc:References:In-Reply-To; bh=DgtS7ahOE4MmAw5xSeUX02j6OJr0If6h53x4evkGsRY=; b=ZYqANC6yv53JMNQc1BESjX33GDse/bTga2qA6nyBOhYUH17sQrE0BTlAckXT8emomitcMx jOcH6EeqSlZzHtpGieD8TVnC9h5cBdVn5XOQiEzZV4LU73kQc/Bsvg02VxQx3HHSEndaE3GC oNwpas0zDHc5gWoB30bEgWc772QAaIMu8iaUF38MHyGsqzjL2I0UDjQx9Pwjlt4x8S30CbQE 1rUcWYkToCHNXqAUbLBemGeNcngesgijSM98UTwZJGMzdp19UO62bahlha3tXPDEfO+Usyx3 zLDgcXWJQ8LGdWuCCj9/EGFEZNCMnJn5LgTzWrmLRC7IrvS0khKvou9g==; From: Jan Kiszka To: Nishanth Menon , Santosh Shilimkar , Vignesh Raghavendra , Tero Kristo , Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, Siddharth Vadapalli , Bao Cheng Su , Hua Qian Li , Diogo Ivo , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas Subject: [PATCH v4 2/7] dt-bindings: PCI: ti,am65: Extend for use with PVU Date: Wed, 4 Sep 2024 12:00:11 +0200 Message-ID: <28d31a14fe9cc1867f023ebaddd6074459d15e40.1725444016.git.jan.kiszka@siemens.com> In-Reply-To: References: MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-294854:519-21489:flowmailer X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_030026_272224_42FB943F X-CRM114-Status: GOOD ( 12.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Jan Kiszka The PVU on the AM65 SoC is capable of restricting DMA from PCIe devices to specific regions of host memory. Add the optional property "memory-regions" to point to such regions of memory when PVU is used. Since the PVU deals with system physical addresses, utilizing the PVU with PCIe devices also requires setting up the VMAP registers to map the Requester ID of the PCIe device to the CBA Virtual ID, which in turn is mapped to the system physical address. Hence, describe the VMAP registers which are optionally unless the PVU shall used for PCIe. Signed-off-by: Jan Kiszka --- CC: Lorenzo Pieralisi CC: "Krzysztof Wilczyński" CC: Bjorn Helgaas CC: linux-pci@vger.kernel.org --- .../bindings/pci/ti,am65-pci-host.yaml | 52 ++++++++++++++----- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/Documentation/devicetree/bindings/pci/ti,am65-pci-host.yaml b/Documentation/devicetree/bindings/pci/ti,am65-pci-host.yaml index 0a9d10532cc8..d8182bad92de 100644 --- a/Documentation/devicetree/bindings/pci/ti,am65-pci-host.yaml +++ b/Documentation/devicetree/bindings/pci/ti,am65-pci-host.yaml @@ -19,16 +19,6 @@ properties: - ti,am654-pcie-rc - ti,keystone-pcie - reg: - maxItems: 4 - - reg-names: - items: - - const: app - - const: dbics - - const: config - - const: atu - interrupts: maxItems: 1 @@ -84,12 +74,48 @@ if: enum: - ti,am654-pcie-rc then: + properties: + reg: + minItems: 4 + maxItems: 6 + + reg-names: + minItems: 4 + items: + - const: app + - const: dbics + - const: config + - const: atu + - const: vmap_lp + - const: vmap_hp + + memory-region: + minItems: 1 + description: | + phandle to one or more restricted DMA pools to be used for all devices + behind this controller. The regions should be defined according to + reserved-memory/shared-dma-pool.yaml. + items: + maxItems: 1 + required: - dma-coherent - power-domains - msi-map - num-viewport +else: + properties: + reg: + maxItems: 4 + + reg-names: + items: + - const: app + - const: dbics + - const: config + - const: atu + unevaluatedProperties: false examples: @@ -104,8 +130,10 @@ examples: reg = <0x5500000 0x1000>, <0x5501000 0x1000>, <0x10000000 0x2000>, - <0x5506000 0x1000>; - reg-names = "app", "dbics", "config", "atu"; + <0x5506000 0x1000>, + <0x2900000 0x1000>, + <0x2908000 0x1000>; + reg-names = "app", "dbics", "config", "atu", "vmap_lp", "vmap_hp"; power-domains = <&k3_pds 120 TI_SCI_PD_EXCLUSIVE>; #address-cells = <3>; #size-cells = <2>; From patchwork Wed Sep 4 10:00:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 13790378 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id F40A1CA0ED3 for ; Wed, 4 Sep 2024 10:25:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=T9kLsZvbQcAB7W7U0c5RGg3jN6Tk3KlP6s2az5OPFco=; b=YEtlajiGIIPrDXY+xHgt5FdNMm 7x+OGM63YwaNEWvkBKjHZJdlvQHP+XYpf2nfKbhTcEl7euZ3ICKeZr4A/ta9VgCTBABwRTDDgNyil B0jwOKU0KuQLWtl1LY5QI0Tl20U9IHlFelGTDpvffaYpzYKkdOtk6WKhHuFcvgesI7qp60d7+a5LE 2tu7f47BrYJSdx6FDz7JxfyEChVErdn7xOQK1Oo1QCqLXcidu4kWu/R37GJBjU9RhQwNCnx3BvLf0 ctKqW1ymYv9sLCBwZ6I8E+Q743GeWuiOXKCpBGYvz/+QaxoyH/gKcrlTy7oM0tl6BbSPYxAn3WVMU F9WaDY2Q==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slnCj-00000003uQt-29XO; Wed, 04 Sep 2024 10:25:37 +0000 Received: from mta-64-226.siemens.flowmailer.net ([185.136.64.226]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slmoO-00000003nq1-3NB2 for linux-arm-kernel@lists.infradead.org; Wed, 04 Sep 2024 10:00:31 +0000 Received: by mta-64-226.siemens.flowmailer.net with ESMTPSA id 202409041000243e491abf7748d59168 for ; Wed, 04 Sep 2024 12:00:24 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=jan.kiszka@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc:References:In-Reply-To; bh=T9kLsZvbQcAB7W7U0c5RGg3jN6Tk3KlP6s2az5OPFco=; b=OSBgpa9PX3F8RQYdsqKsynEvgsDqxiba1U/wtBLKVbe0BmYaPPvBb6iTBUuK9N4Hjk0Zi4 /ME9U0UFPoQjpT/w4NqL6DNndKMwBW10m4H6ajazZndFLwx6xlJm/cXfpJmb5z/lGRIbrHpk XCnJQlPwGQIEwPTkwt2OUASWMF+Jt6viZVD72Uq1khZuZnjlPdXNOJDaApQWpjVgdD0YYk7A ecFn3XwL99uuOr5NWSQ6o3wsHKEljqH4BeV/KJVnOeCIrBsNINbi5/J9NVaiotlmULIXS4O3 Hdkw61y2qlLank6YObkEFusViS+YENvUZZurXuAYyYruhW0W/+FY5Qug==; From: Jan Kiszka To: Nishanth Menon , Santosh Shilimkar , Vignesh Raghavendra , Tero Kristo , Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, Siddharth Vadapalli , Bao Cheng Su , Hua Qian Li , Diogo Ivo Subject: [PATCH v4 3/7] soc: ti: Add IOMPU-like PVU driver Date: Wed, 4 Sep 2024 12:00:12 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-294854:519-21489:flowmailer X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_030029_163220_A84C2B27 X-CRM114-Status: GOOD ( 27.33 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Jan Kiszka The TI Peripheral Virtualization Unit (PVU) permits to define a limited set of mappings for DMA requests on the system memory. Unlike with an IOMMU, there is no fallback to a memory-backed page table, only a fixed set of register-backed TLBs. Emulating an IOMMU behavior appears to be the more fragile the more fragmentation of pending requests occur. Therefore, this driver does not expose the PVU as an IOMMU. It rather introduces a simple, static interface to devices that are under restricted-dma-pool constraints. They can register their pools with the PVUs, enabling only those pools to work for DMA. As also MSI is issued as DMA, the PVU already register the related translator region of the AM654 as valid DMA target. This driver is the essential building block for limiting DMA from untrusted devices to clearly defined memory regions in the absence of a real IOMMU (SMMU). Co-developed-by: Diogo Ivo Signed-off-by: Jan Kiszka --- drivers/soc/ti/Kconfig | 4 + drivers/soc/ti/Makefile | 1 + drivers/soc/ti/ti-pvu.c | 487 ++++++++++++++++++++++++++++++++++++++++ include/linux/ti-pvu.h | 16 ++ 4 files changed, 508 insertions(+) create mode 100644 drivers/soc/ti/ti-pvu.c create mode 100644 include/linux/ti-pvu.h diff --git a/drivers/soc/ti/Kconfig b/drivers/soc/ti/Kconfig index 1a93001c9e36..af7173ad84de 100644 --- a/drivers/soc/ti/Kconfig +++ b/drivers/soc/ti/Kconfig @@ -82,6 +82,10 @@ config TI_PRUSS processors on various TI SoCs. It's safe to say N here if you're not interested in the PRU or if you are unsure. +config TI_PVU + bool "TI Peripheral Virtualization Unit driver" + depends on ARCH_K3 && DMA_RESTRICTED_POOL + endif # SOC_TI config TI_SCI_INTA_MSI_DOMAIN diff --git a/drivers/soc/ti/Makefile b/drivers/soc/ti/Makefile index cb800a745e66..ecff3fd8c433 100644 --- a/drivers/soc/ti/Makefile +++ b/drivers/soc/ti/Makefile @@ -12,3 +12,4 @@ obj-$(CONFIG_TI_K3_RINGACC) += k3-ringacc.o obj-$(CONFIG_TI_K3_SOCINFO) += k3-socinfo.o obj-$(CONFIG_TI_PRUSS) += pruss.o obj-$(CONFIG_POWER_AVS_OMAP) += smartreflex.o +obj-$(CONFIG_TI_PVU) += ti-pvu.o diff --git a/drivers/soc/ti/ti-pvu.c b/drivers/soc/ti/ti-pvu.c new file mode 100644 index 000000000000..5b71d503051f --- /dev/null +++ b/drivers/soc/ti/ti-pvu.c @@ -0,0 +1,487 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * TI Peripheral Virtualization Unit driver for static DMA isolation + * + * Copyright (c) 2024, Siemens AG + */ + +#include +#include +#include +#include +#include +#include + +#define PVU_CONFIG 0x4 +#define PVU_ENABLE 0x10 +#define PVU_VIRTID_MAP1 0x14 +#define PVU_VIRTID_MAP2 0x18 +#define PVU_EXCEPTION_LOGGING_CONTROL 0x120 +#define PVU_EXCEPTION_LOGGING_HEADER0 0x124 +#define PVU_EXCEPTION_LOGGING_HEADER1 0x128 +#define PVU_EXCEPTION_LOGGING_DATA0 0x12c +#define PVU_EXCEPTION_LOGGING_DATA1 0x130 +#define PVU_EXCEPTION_LOGGING_DATA2 0x134 +#define PVU_EXCEPTION_LOGGING_DATA2_SECURE BIT(0) +#define PVU_EXCEPTION_LOGGING_DATA2_PRIV BIT(1) +#define PVU_EXCEPTION_LOGGING_DATA2_CACHEABLE BIT(2) +#define PVU_EXCEPTION_LOGGING_DATA2_DEBUG BIT(3) +#define PVU_EXCEPTION_LOGGING_DATA2_READ BIT(4) +#define PVU_EXCEPTION_LOGGING_DATA2_WRITE BIT(5) +#define PVU_EXCEPTION_LOGGING_DATA3 0x138 +#define PVU_EXCEPTION_ENABLE_SET 0x148 +#define PVU_EOI_REG 0x150 + +#define PVU_CHAIN 0x0 +#define PVU_CHAIN_EN BIT(31) +#define PVU_CHAIN_LOG_DIS BIT(30) +#define PVU_CHAIN_FAULT BIT(29) +#define PVU_CHAIN_MASK 0xfff +#define PVU_ENTRY0 0x20 +#define PVU_ENTRY1 0x24 +#define PVU_ENTRY1_RESERVED_MASK 0xffff0000 +#define PVU_ENTRY1_VBASE_H_MASK 0xffff +#define PVU_ENTRY2 0x28 +#define PVU_ENTRY2_RESERVED_MASK 0x1fd00080 +#define PVU_ENTRY2_INVALID (0U << 30) +#define PVU_ENTRY2_VALID (2U << 30) +#define PVU_ENTRY2_MODE_MASK 0xc0000000 +#define PVU_ENTRY2_PSIZE_SHIFT 16 +#define PVU_ENTRY2_PSIZE_MASK 0xf +#define PVU_ENTRY2_PERM_SX BIT(15) +#define PVU_ENTRY2_PERM_SW BIT(14) +#define PVU_ENTRY2_PERM_SR BIT(13) +#define PVU_ENTRY2_PERM_UX BIT(12) +#define PVU_ENTRY2_PERM_UW BIT(11) +#define PVU_ENTRY2_PERM_UR BIT(10) +#define PVU_ENTRY2_MEM_WRITETHROUGH (2 << 8) +#define PVU_ENTRY2_OUTER_SHARABLE BIT(4) +#define PVU_ENTRY2_IS_NOALLOC (0 << 2) +#define PVU_ENTRY2_OS_NOALLOC (0 << 0) +#define PVU_ENTRY4 0x30 +#define PVU_ENTRY5 0x34 +#define PVU_ENTRY5_RESERVED_MASK 0xffff0000 +#define PVU_ENTRY5_PBASE_H_MASK 0xffff +#define PVU_ENTRY6 0x38 +#define PVU_ENTRY6_RESERVED_MASK 0xffffffe0 + +#define NUM_VIRTIDS 1 + +static const struct regmap_config pvu_cfg_regmap_cfg = { + .name = "pvu-cfg", + .reg_bits = 32, + .reg_stride = 4, + .val_bits = 32, + .max_register = PVU_EOI_REG, +}; + +enum pvu_cfg_regfields { + PVU_TLBS, + PVU_TLB_ENTRIES, + PVU_ENABLED, + PVU_DMA_CNT, + PVU_DMA_CL0, + PVU_DMA_CL1, + PVU_DMA_CL2, + PVU_DMA_CL3, + PVU_MAX_VIRTID, + PVU_EXC_SRC_ID, + PVU_EXC_CODE, + PVU_EXC_ADDR_L, + PVU_EXC_ADDR_H, + PVU_EXC_PRIV_ID, + PVU_EXC_PROPS, + PVU_EXC_ROUTE_ID, + PVU_EXC_BYTE_CNT, + PVU_EXC_ENABLE, + PVU_EOI, + PVU_MAX_CFG_FIELDS, +}; + +static const struct reg_field pvu_cfg_reg_fields[] = { + [PVU_TLBS] = REG_FIELD(PVU_CONFIG, 0, 15), + [PVU_TLB_ENTRIES] = REG_FIELD(PVU_CONFIG, 16, 23), + [PVU_ENABLED] = REG_FIELD(PVU_ENABLE, 0, 0), + [PVU_DMA_CNT] = REG_FIELD(PVU_VIRTID_MAP1, 0, 11), + [PVU_DMA_CL0] = REG_FIELD(PVU_VIRTID_MAP1, 16, 17), + [PVU_DMA_CL1] = REG_FIELD(PVU_VIRTID_MAP1, 18, 19), + [PVU_DMA_CL2] = REG_FIELD(PVU_VIRTID_MAP1, 20, 21), + [PVU_DMA_CL3] = REG_FIELD(PVU_VIRTID_MAP1, 22, 23), + [PVU_MAX_VIRTID] = REG_FIELD(PVU_VIRTID_MAP2, 0, 11), + [PVU_EXC_SRC_ID] = REG_FIELD(PVU_EXCEPTION_LOGGING_HEADER0, 8, 23), + [PVU_EXC_CODE] = REG_FIELD(PVU_EXCEPTION_LOGGING_HEADER1, 16, 23), + [PVU_EXC_ADDR_L] = REG_FIELD(PVU_EXCEPTION_LOGGING_DATA0, 0, 31), + [PVU_EXC_ADDR_H] = REG_FIELD(PVU_EXCEPTION_LOGGING_DATA1, 0, 15), + [PVU_EXC_PRIV_ID] = REG_FIELD(PVU_EXCEPTION_LOGGING_DATA2, 0, 7), + [PVU_EXC_PROPS] = REG_FIELD(PVU_EXCEPTION_LOGGING_DATA2, 8, 13), + [PVU_EXC_ROUTE_ID] = REG_FIELD(PVU_EXCEPTION_LOGGING_DATA2, 16, 27), + [PVU_EXC_BYTE_CNT] = REG_FIELD(PVU_EXCEPTION_LOGGING_DATA3, 0, 9), + [PVU_EXC_ENABLE] = REG_FIELD(PVU_EXCEPTION_ENABLE_SET, 0, 0), + [PVU_EOI] = REG_FIELD(PVU_EOI_REG, 0, 15), +}; + +struct ti_pvu { + struct list_head entry; + struct platform_device *pdev; + struct regmap *cfg; + struct regmap_field *cfg_fields[PVU_MAX_CFG_FIELDS]; + void __iomem *tlbif_base; + unsigned int num_tlbs; + unsigned int num_entries; +}; + +static const char *pvu_excp_code_string[] = { + "PVU miss", + "maximum VirtID violation", + "", + "read permission violation", + "write permission violation", + "execute permission violation", + "prefetch permission violation", + "", +}; + +static const u64 pvu_page_size[] = { + 4 * 1024ULL, + 16 * 1024ULL, + 64 * 1024ULL, + 2 * 1024 * 1024ULL, + 32 * 1024 * 1024ULL, + 512 * 1024 * 1024ULL, + 1 * 1024 * 1024 * 1024ULL, + 16 * 1024 * 1024 * 1024ULL +}; + +static DEFINE_MUTEX(ti_pvu_lock); +static LIST_HEAD(ti_pvu_list); + +static unsigned int pvu_field_read(struct ti_pvu *pvu, enum pvu_cfg_regfields f) +{ + int ret; + unsigned int val; + + ret = regmap_field_read(pvu->cfg_fields[f], &val); + if (ret) + dev_err(&pvu->pdev->dev, "failed to read field\n"); + + return val; +} + +static void pvu_field_write(struct ti_pvu *pvu, enum pvu_cfg_regfields f, + unsigned int val) +{ + int ret; + + ret = regmap_field_write(pvu->cfg_fields[f], val); + if (ret) + dev_err(&pvu->pdev->dev, "failed to write field\n"); +} + +static irqreturn_t pvu_fault_isr(int irq, void *dev_id) +{ + u32 code, bytes, route_id, priv_id, props; + struct ti_pvu *pvu = dev_id; + const char *code_str; + u64 address; + + code = pvu_field_read(pvu, PVU_EXC_CODE); + code_str = pvu_excp_code_string[ + min(code, (u32)ARRAY_SIZE(pvu_excp_code_string) - 1)]; + + dev_err(&pvu->pdev->dev, "fault detected, code %d (%s)\n", + code, code_str); + + address = pvu_field_read(pvu, PVU_EXC_ADDR_L); + address |= (u64)pvu_field_read(pvu, PVU_EXC_ADDR_H) << 32; + + bytes = pvu_field_read(pvu, PVU_EXC_BYTE_CNT); + + route_id = pvu_field_read(pvu, PVU_EXC_ROUTE_ID); + priv_id = pvu_field_read(pvu, PVU_EXC_PRIV_ID); + props = pvu_field_read(pvu, PVU_EXC_PROPS); + + dev_err(&pvu->pdev->dev, + " address 0x%016llx size %d route-ID %d priv-ID %d flags %c%c%c%c%c%c\n", + address, bytes, route_id, priv_id, + (props & PVU_EXCEPTION_LOGGING_DATA2_WRITE) ? 'W' : '-', + (props & PVU_EXCEPTION_LOGGING_DATA2_READ) ? 'R' : '-', + (props & PVU_EXCEPTION_LOGGING_DATA2_DEBUG) ? 'D' : '-', + (props & PVU_EXCEPTION_LOGGING_DATA2_CACHEABLE) ? 'C' : '-', + (props & PVU_EXCEPTION_LOGGING_DATA2_PRIV) ? 'P' : '-', + (props & PVU_EXCEPTION_LOGGING_DATA2_SECURE) ? 'S' : '-'); + + pvu_field_write(pvu, PVU_EOI, 0); + + return IRQ_HANDLED; +} + +static int pvu_get_free_entry(struct ti_pvu *pvu) +{ + unsigned int n; + u32 val; + + for (n = 0; n < pvu->num_entries; n++) { + val = readl(pvu->tlbif_base + n * 0x20 + PVU_ENTRY2); + if ((val & PVU_ENTRY2_MODE_MASK) == PVU_ENTRY2_INVALID) + return n; + } + return -ENOSPC; +} + +static void pvu_write_entry(struct ti_pvu *pvu, unsigned int entry, + u64 addr, u32 psize) +{ + void __iomem *entry_base = pvu->tlbif_base + entry * 0x20; + u32 val; + + writel((u32)addr, entry_base + PVU_ENTRY0); + + val = readl(entry_base + PVU_ENTRY1); + val &= PVU_ENTRY1_RESERVED_MASK; + val |= (addr >> 32) & PVU_ENTRY1_VBASE_H_MASK; + writel(val, entry_base + PVU_ENTRY1); + + writel((u32)addr, entry_base + PVU_ENTRY4); + + val = readl(entry_base + PVU_ENTRY5); + val &= PVU_ENTRY5_RESERVED_MASK; + val |= (addr >> 32) & PVU_ENTRY5_PBASE_H_MASK; + writel(val, entry_base + PVU_ENTRY5); + + val = readl(entry_base + PVU_ENTRY6); + val &= PVU_ENTRY6_RESERVED_MASK; + writel(val, entry_base + PVU_ENTRY6); + + val = readl(entry_base + PVU_ENTRY2); + val &= PVU_ENTRY2_RESERVED_MASK; + val |= psize << PVU_ENTRY2_PSIZE_SHIFT; + val |= PVU_ENTRY2_VALID | + PVU_ENTRY2_PERM_UR | PVU_ENTRY2_PERM_SR | + PVU_ENTRY2_PERM_UW | PVU_ENTRY2_PERM_SW | + PVU_ENTRY2_PERM_UX | PVU_ENTRY2_PERM_SX | + PVU_ENTRY2_MEM_WRITETHROUGH | PVU_ENTRY2_OUTER_SHARABLE | + PVU_ENTRY2_IS_NOALLOC | PVU_ENTRY2_OS_NOALLOC; + writel(val, entry_base + PVU_ENTRY2); +} + +static int pvu_create_region(struct ti_pvu *pvu, u64 addr, u64 size) +{ + u64 page_size; + int psize; + int entry; + + while (size > 0) { + entry = pvu_get_free_entry(pvu); + if (entry < 0) { + dev_err(&pvu->pdev->dev, "ran out of TLB entries\n"); + return -ENOSPC; + } + + for (psize = ARRAY_SIZE(pvu_page_size) - 1; psize >= 0; psize--) { + page_size = pvu_page_size[psize]; + if (size >= page_size && (addr & (page_size - 1)) == 0) + break; + } + if (psize < 0) { + dev_err(&pvu->pdev->dev, "unaligned region provided\n"); + return -EINVAL; + } + + pvu_write_entry(pvu, entry, addr, psize); + dev_info(&pvu->pdev->dev, + "created TLB entry 0.%d: 0x%08llx, psize %d (0x%08llx)\n", + entry, addr, psize, page_size); + + size -= page_size; + addr += page_size; + } + + return 0; +} + +static void pvu_remove_region(struct ti_pvu *pvu, u64 addr, u64 size) +{ + void __iomem *entry_base; + unsigned int n, psize; + u64 entry_addr; + u32 entry2; + + for (n = 0; n < pvu->num_entries; n++) { + entry_base = pvu->tlbif_base + n * 0x20; + entry2 = readl(entry_base + PVU_ENTRY2); + if ((entry2 & PVU_ENTRY2_MODE_MASK) != PVU_ENTRY2_VALID) + continue; + + entry_addr = readl(entry_base + PVU_ENTRY0); + entry_addr |= (u64)(readl(entry_base + PVU_ENTRY1) & + PVU_ENTRY1_VBASE_H_MASK) << 32; + + psize = (entry2 >> PVU_ENTRY2_PSIZE_SHIFT) & + PVU_ENTRY2_PSIZE_MASK; + if (psize >= ARRAY_SIZE(pvu_page_size)) + continue; + + if (entry_addr >= addr && + (entry_addr + pvu_page_size[psize]) <= (addr + size)) { + entry2 &= ~PVU_ENTRY2_MODE_MASK; + entry2 |= PVU_ENTRY2_INVALID; + writel(entry2, entry_base + PVU_ENTRY2); + + dev_info(&pvu->pdev->dev, + "removed TLB entry 0.%d\n", n); + } + } +} + +int ti_pvu_create_region(unsigned int virt_id, const struct resource *region) +{ + struct ti_pvu *pvu; + int err = 0; + + if (virt_id >= NUM_VIRTIDS) + return -EINVAL; + + mutex_lock(&ti_pvu_lock); + + list_for_each_entry(pvu, &ti_pvu_list, entry) { + err = pvu_create_region(pvu, region->start, + region->end + 1 - region->start); + if (err) + break; + } + + mutex_unlock(&ti_pvu_lock); + + return err; +} + +int ti_pvu_remove_region(unsigned int virt_id, const struct resource *region) +{ + struct ti_pvu *pvu; + + if (virt_id >= NUM_VIRTIDS) + return -EINVAL; + + mutex_lock(&ti_pvu_lock); + + list_for_each_entry(pvu, &ti_pvu_list, entry) { + pvu_remove_region(pvu, region->start, + region->end + 1 - region->start); + } + + mutex_unlock(&ti_pvu_lock); + + return 0; +} + +static int ti_pvu_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *its_node; + void __iomem *base; + struct ti_pvu *pvu; + u32 val; + int ret; + + pvu = devm_kzalloc(dev, sizeof(*pvu), GFP_KERNEL); + if (!pvu) + return -ENOMEM; + + pvu->pdev = pdev; + + base = devm_platform_ioremap_resource_byname(pdev, "cfg"); + if (IS_ERR(base)) + return PTR_ERR(base); + + pvu->cfg = devm_regmap_init_mmio(dev, base, &pvu_cfg_regmap_cfg); + if (IS_ERR(pvu->cfg)) + return dev_err_probe(dev, PTR_ERR(pvu->cfg), "failed to init cfg regmap"); + + ret = devm_regmap_field_bulk_alloc(dev, pvu->cfg, pvu->cfg_fields, + pvu_cfg_reg_fields, PVU_MAX_CFG_FIELDS); + if (ret) + return dev_err_probe(dev, ret, "failed to alloc cfg regmap fields"); + + pvu->num_tlbs = pvu_field_read(pvu, PVU_TLBS); + pvu->num_entries = pvu_field_read(pvu, PVU_TLB_ENTRIES); + dev_info(dev, "TLBs: %d, entries per TLB: %d\n", pvu->num_tlbs, + pvu->num_entries); + + pvu->tlbif_base = devm_platform_ioremap_resource_byname(pdev, "tlbif"); + if (IS_ERR(pvu->tlbif_base)) + return PTR_ERR(pvu->tlbif_base); + + its_node = of_find_compatible_node(0, 0, "arm,gic-v3-its"); + if (its_node) { + u32 pre_its_window[2]; + + ret = of_property_read_u32_array(its_node, + "socionext,synquacer-pre-its", + pre_its_window, + ARRAY_SIZE(pre_its_window)); + if (ret) { + dev_err(dev, "failed to read pre-its property\n"); + return ret; + } + + ret = pvu_create_region(pvu, pre_its_window[0], + pre_its_window[1]); + if (ret) + return ret; + } + + val = readl(pvu->tlbif_base + PVU_CHAIN); + val |= PVU_CHAIN_EN; + writel(val, pvu->tlbif_base + PVU_CHAIN); + + pvu_field_write(pvu, PVU_DMA_CNT, 0); + pvu_field_write(pvu, PVU_DMA_CL0, 0); + pvu_field_write(pvu, PVU_DMA_CL1, 0); + pvu_field_write(pvu, PVU_DMA_CL2, 0); + pvu_field_write(pvu, PVU_DMA_CL3, 0); + pvu_field_write(pvu, PVU_MAX_VIRTID, NUM_VIRTIDS); + + ret = platform_get_irq(pdev, 0); + if (ret < 0) + return dev_err_probe(dev, ret, "failed to get irq\n"); + + ret = devm_request_irq(dev, ret, pvu_fault_isr, 0, dev_name(dev), pvu); + if (ret) + return dev_err_probe(dev, ret, "failed to request irq\n"); + + pvu_field_write(pvu, PVU_EXC_ENABLE, 1); + pvu_field_write(pvu, PVU_ENABLED, 1); + + dev_set_drvdata(dev, pvu); + + mutex_lock(&ti_pvu_lock); + list_add(&pvu->entry, &ti_pvu_list); + mutex_unlock(&ti_pvu_lock); + + return 0; +} + +static void ti_pvu_remove(struct platform_device *pdev) +{ + struct ti_pvu *pvu = dev_get_drvdata(&pdev->dev); + + mutex_lock(&ti_pvu_lock); + list_del(&pvu->entry); + mutex_unlock(&ti_pvu_lock); +} + +static const struct of_device_id ti_pvu_of_match[] = { + { .compatible = "ti,am654-pvu", }, + {}, +}; +MODULE_DEVICE_TABLE(of, ti_pvu_of_match); + +static struct platform_driver ti_pvu_driver = { + .driver = { + .name = "ti-pvu", + .of_match_table = ti_pvu_of_match, + }, + .probe = ti_pvu_probe, + .remove_new = ti_pvu_remove, +}; +module_platform_driver(ti_pvu_driver); diff --git a/include/linux/ti-pvu.h b/include/linux/ti-pvu.h new file mode 100644 index 000000000000..acd4d9e0dc86 --- /dev/null +++ b/include/linux/ti-pvu.h @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * TI Peripheral Virtualization Unit driver for static DMA isolation + * + * Copyright (c) 2024, Siemens AG + */ + +#ifndef _LINUX_TI_PVU_H +#define _LINUX_TI_PVU_H + +#include + +int ti_pvu_create_region(unsigned int virt_id, const struct resource *region); +int ti_pvu_remove_region(unsigned int virt_id, const struct resource *region); + +#endif /* _LINUX_TI_PVU_H */ From patchwork Wed Sep 4 10:00:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 13790379 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 89357CD3431 for ; Wed, 4 Sep 2024 10:26:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: Content-Type:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc: To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=nJ23+pLVcV1YLo+DOWiwMwlffZaSUayxfrEBlEY2X7Q=; b=ZY3NJSGhfQaKXpvFjSCP/7cfj8 zS7rH6Fl+8oW9Jb0rL7KxK6AikM8+892Uro+GtpB0gWO7+MBjAWdvYs90pVHmst2yWTkJbSEEo8ou t1PppSlrOMDKjwmStB33LhWh+4HT45tBWnr4pdEOqpl2Jkyg7P0RtORicDmv8otgwlHtN5b+g6PDR EFIj/4T9pdMAiGqYetMPv5OsWhtzdIAVWLzR4HMHDhcZrcVr/VSzswlg8gw8GwvSrb/WY7zxnF9iv BnEgXca/d7bhKqwUFhuqDJrf+O6B9AIkn55ennCSKDmh+ioPx67k30LtCZMg1iuFO7vxluis0w+qf 5rZiWthA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slnDm-00000003upd-1OtV; Wed, 04 Sep 2024 10:26:42 +0000 Received: from mta-64-225.siemens.flowmailer.net ([185.136.64.225]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slmoQ-00000003nqq-2LkE for linux-arm-kernel@lists.infradead.org; Wed, 04 Sep 2024 10:00:32 +0000 Received: by mta-64-225.siemens.flowmailer.net with ESMTPSA id 2024090410002515b7893a6e7d4b8a74 for ; Wed, 04 Sep 2024 12:00:26 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=jan.kiszka@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc:References:In-Reply-To; bh=nJ23+pLVcV1YLo+DOWiwMwlffZaSUayxfrEBlEY2X7Q=; b=dqP4zkN4JrdHhH1kfYOs+e10N+3AYUeKMvEA3j1QhsHEgLY1tK5Zq51hTq4oryFfG2VAr/ 1i0llKkvsIMNasRvZql/HSkV5Pt+mRuXfBz6/FnKC1BbY9zzibzfxP/EikCXSAIxGUzE+402 TTqlILAlwzYRgPfEl6mfL0IsMFQRh187H+MKMxEe+sp6Bvho2sQHnIxFcyoDJT2lAt8JRNb4 qohDJoHbVeMSEsPjQV4tDG3NCtA/I1bzGzxyjsuSlC46zqmq67qy8uKAa9bdXhcL5R2iR77E ssSxCsxDi4M0ip3Qsqb8qmsRtqUdEMlbLGzQ7Q/SijhV+iRiotXkENUg==; From: Jan Kiszka To: Nishanth Menon , Santosh Shilimkar , Vignesh Raghavendra , Tero Kristo , Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, Siddharth Vadapalli , Bao Cheng Su , Hua Qian Li , Diogo Ivo , Lorenzo Pieralisi , =?utf-8?q?Krzysztof_Wilczy=C5=84ski?= , Bjorn Helgaas Subject: [PATCH v4 4/7] PCI: keystone: Add supported for PVU-based DMA isolation on AM654 Date: Wed, 4 Sep 2024 12:00:13 +0200 Message-ID: <361441d35d781b3c474b05921634bcae08d1a7b4.1725444016.git.jan.kiszka@siemens.com> In-Reply-To: References: MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-294854:519-21489:flowmailer X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_030030_769860_542CC3DC X-CRM114-Status: GOOD ( 20.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Jan Kiszka The AM654 lacks an IOMMU, thus does not support isolating DMA requests from untrusted PCI devices to selected memory regions this way. Use static PVU-based protection instead. For this, we use the availability of restricted-dma-pool memory regions as trigger and register those as valid DMA targets with the PVU. In addition, we need to enable the mapping of requester IDs to VirtIDs in the PCI RC. We only use a single VirtID so far, catching all devices. This may be extended later on. Signed-off-by: Jan Kiszka --- CC: Lorenzo Pieralisi CC: "Krzysztof Wilczyński" CC: Bjorn Helgaas CC: linux-pci@vger.kernel.org --- drivers/pci/controller/dwc/pci-keystone.c | 101 ++++++++++++++++++++++ 1 file changed, 101 insertions(+) diff --git a/drivers/pci/controller/dwc/pci-keystone.c b/drivers/pci/controller/dwc/pci-keystone.c index 2219b1a866fa..96b871656da4 100644 --- a/drivers/pci/controller/dwc/pci-keystone.c +++ b/drivers/pci/controller/dwc/pci-keystone.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -26,6 +27,7 @@ #include #include #include +#include #include "../../pci.h" #include "pcie-designware.h" @@ -111,6 +113,16 @@ #define PCI_DEVICE_ID_TI_AM654X 0xb00c +#define KS_PCI_VIRTID 0 + +#define PCIE_VMAP_xP_CTRL 0x0 +#define PCIE_VMAP_xP_REQID 0x4 +#define PCIE_VMAP_xP_VIRTID 0x8 + +#define PCIE_VMAP_xP_CTRL_EN BIT(0) + +#define PCIE_VMAP_xP_VIRTID_VID_MASK 0xfff + struct ks_pcie_of_data { enum dw_pcie_device_mode mode; const struct dw_pcie_host_ops *host_ops; @@ -1125,6 +1137,89 @@ static const struct of_device_id ks_pcie_of_match[] = { { }, }; +#ifdef CONFIG_TI_PVU +static const char *ks_vmap_res[] = {"vmap_lp", "vmap_hp"}; + +static int ks_init_restricted_dma(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct of_phandle_iterator it; + bool init_vmap = false; + struct resource phys; + struct resource *res; + void __iomem *base; + unsigned int n; + u32 val; + int err; + + of_for_each_phandle(&it, err, dev->of_node, "memory-region", + NULL, 0) { + if (!of_device_is_compatible(it.node, "restricted-dma-pool")) + continue; + + err = of_address_to_resource(it.node, 0, &phys); + if (err < 0) { + dev_err(dev, "failed to parse memory region %pOF: %d\n", + it.node, err); + continue; + } + + err = ti_pvu_create_region(KS_PCI_VIRTID, &phys); + if (err < 0) + return err; + + init_vmap = true; + } + + if (init_vmap) { + for (n = 0; n < ARRAY_SIZE(ks_vmap_res); n++) { + res = platform_get_resource_byname(pdev, IORESOURCE_MEM, + ks_vmap_res[n]); + base = devm_pci_remap_cfg_resource(dev, res); + if (IS_ERR(base)) + return PTR_ERR(base); + + writel(0, base + PCIE_VMAP_xP_REQID); + + val = readl(base + PCIE_VMAP_xP_VIRTID); + val &= ~PCIE_VMAP_xP_VIRTID_VID_MASK; + val |= KS_PCI_VIRTID; + writel(val, base + PCIE_VMAP_xP_VIRTID); + + val = readl(base + PCIE_VMAP_xP_CTRL); + val |= PCIE_VMAP_xP_CTRL_EN; + writel(val, base + PCIE_VMAP_xP_CTRL); + } + } + + return 0; +} + +static void ks_release_restricted_dma(struct platform_device *pdev) +{ + struct of_phandle_iterator it; + struct resource phys; + int err; + + of_for_each_phandle(&it, err, pdev->dev.of_node, "memory-region", + NULL, 0) { + if (of_device_is_compatible(it.node, "restricted-dma-pool") && + of_address_to_resource(it.node, 0, &phys) == 0) + ti_pvu_remove_region(KS_PCI_VIRTID, &phys); + + } +} +#else +static inline int ks_init_restricted_dma(struct platform_device *pdev) +{ + return 0; +} + +static inline void ks_release_restricted_dma(struct platform_device *pdev) +{ +} +#endif + static int ks_pcie_probe(struct platform_device *pdev) { const struct dw_pcie_host_ops *host_ops; @@ -1273,6 +1368,10 @@ static int ks_pcie_probe(struct platform_device *pdev) if (ret < 0) goto err_get_sync; + ret = ks_init_restricted_dma(pdev); + if (ret < 0) + goto err_get_sync; + switch (mode) { case DW_PCIE_RC_TYPE: if (!IS_ENABLED(CONFIG_PCI_KEYSTONE_HOST)) { @@ -1354,6 +1453,8 @@ static void ks_pcie_remove(struct platform_device *pdev) int num_lanes = ks_pcie->num_lanes; struct device *dev = &pdev->dev; + ks_release_restricted_dma(pdev); + pm_runtime_put(dev); pm_runtime_disable(dev); ks_pcie_disable_phy(ks_pcie); From patchwork Wed Sep 4 10:00:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 13790381 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 194BDCD3431 for ; Wed, 4 Sep 2024 10:28:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=lEToRIXgwmYCaLisxjDuneMdvn7veaPhbgDLaE9G4uY=; b=j/Em28q1y6Bz5e+VFleMy7zJ6W MuCc+sv+slDPs2neLtM6978l8IZDp1mKfTPfhCLTYGqrzPro/btOUai8sQ3gqhOoWpF3Hr8i3EH1K Ymbj1CpTNbbWHy4ZIpbF/vDN9JUTGPBiyKcaRAQ0cQKXmsniF/Sjt9d8jd923Im9vWHLDdMHP5+UN JtwaG7oGvk6a1qdUtOs0dZxV15fTeIwlR3GWmh8rJOiBwx6b06zC3yl+99JxRFq628pXFc4f6gpfX 5w/WbtExjFXjDwkg9MiqmCu31+YOGB/2p4YVxtG3X1fCbqXtyuFlfasAf2Sc0hdA/DXF86fggP7jg InPzjrZA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slnFZ-00000003vD4-1CmS; Wed, 04 Sep 2024 10:28:33 +0000 Received: from mta-64-228.siemens.flowmailer.net ([185.136.64.228]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slmoQ-00000003nqv-3l6m for linux-arm-kernel@lists.infradead.org; Wed, 04 Sep 2024 10:00:32 +0000 Received: by mta-64-228.siemens.flowmailer.net with ESMTPSA id 20240904100026e9228c5f4fddb45d16 for ; Wed, 04 Sep 2024 12:00:27 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=jan.kiszka@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc:References:In-Reply-To; bh=lEToRIXgwmYCaLisxjDuneMdvn7veaPhbgDLaE9G4uY=; b=iHHOmMoVcZFuR+nky3DJJ5bQVU/pwKB1ZiLGben6Aw2OOlNx3oKT/cGsei2xoGzjLyHzrS LmYTbLt4D11d3747JqhRi+d/aigd4e47RrnL5SjpRYQkzrgTymG1iljtI1eXIUCwzZWLmQmw U99uzEQuPaJA5YOQBQlpKFrBGJ2Eep1RNdi1JTMyHTGYeyjsyJF4j/s1R+Ij+g6JMNAK5GEQ R+f5T4GCmxQbk9Tg3ZcemAwsP+hoZ1uENRVbxmRkyDtR/56mCKq919+F2vpfpEHs479g38fm Ah19/ak3PiyEPJD+3Z7xj7dJebiCTIjWODcqq7cBK7SBbcpYSWETd+yQ==; From: Jan Kiszka To: Nishanth Menon , Santosh Shilimkar , Vignesh Raghavendra , Tero Kristo , Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, Siddharth Vadapalli , Bao Cheng Su , Hua Qian Li , Diogo Ivo Subject: [PATCH v4 5/7] arm64: dts: ti: k3-am65-main: Add PVU nodes Date: Wed, 4 Sep 2024 12:00:14 +0200 Message-ID: <7a4695fd0d076a535cf34a736f0660082901e1b5.1725444016.git.jan.kiszka@siemens.com> In-Reply-To: References: MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-294854:519-21489:flowmailer X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_030031_107906_F6334C0B X-CRM114-Status: UNSURE ( 8.72 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Jan Kiszka Add nodes for the two PVUs of the AM65. Keep them disabled, though, because the board has to additionally define DMA pools and the devices to be isolated. Signed-off-by: Jan Kiszka --- arch/arm64/boot/dts/ti/k3-am65-main.dtsi | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/arch/arm64/boot/dts/ti/k3-am65-main.dtsi b/arch/arm64/boot/dts/ti/k3-am65-main.dtsi index ba43325c0eec..2582dad68dff 100644 --- a/arch/arm64/boot/dts/ti/k3-am65-main.dtsi +++ b/arch/arm64/boot/dts/ti/k3-am65-main.dtsi @@ -841,6 +841,26 @@ main_cpts_mux: refclk-mux { assigned-clock-parents = <&k3_clks 118 5>; }; }; + + ti_pvu0: iommu@30f80000 { + compatible = "ti,am654-pvu"; + reg = <0 0x30f80000 0 0x1000>, + <0 0x36000000 0 0x100000>; + reg-names = "cfg", "tlbif"; + interrupts-extended = <&intr_main_navss 390>; + interrupt-names = "pvu"; + status = "disabled"; + }; + + ti_pvu1: iommu@30f81000 { + compatible = "ti,am654-pvu"; + reg = <0 0x30f81000 0 0x1000>, + <0 0x36100000 0 0x100000>; + reg-names = "cfg", "tlbif"; + interrupts-extended = <&intr_main_navss 389>; + interrupt-names = "pvu"; + status = "disabled"; + }; }; main_gpio0: gpio@600000 { From patchwork Wed Sep 4 10:00:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 13790382 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 914E5CD3431 for ; Wed, 4 Sep 2024 10:29:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=AbNAvrLHi+QFmGP7oAo1eWelX8ED/CVynTahfKnv7FE=; b=ypSb0hDrSs8PEjGRfmOR3UWKST 25wXMPBbDfEzRLYJWX6nXtffgGZmUqyKw5j6a5QLe72WZDd9pCKrGTBi796JkEDRaxVeRS/Ez+jw4 VrADRVLPF9pW/XIMbl5uuFKunZQUIkhWpE81ifIpkx4sZORA7kahcbtXlK86v/xgzaQd8YXoo7e0P 6VpUp+YszsMzbHNqKpzU9yJ04XKJfQo0KQaXGp/RWQ2KNX54Umu+MK9ji3NlAzGsA0eC1jK/mfxD+ s+iNZRrgGvMzhUUH63uXNJB/CDlaZ17l3x3a1jVajvF0fSwbieu+z6xle7AeQTJT3vTqc5JhVbuHE 5/Qw0nEw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slnGY-00000003vZe-3YbF; Wed, 04 Sep 2024 10:29:34 +0000 Received: from mta-64-226.siemens.flowmailer.net ([185.136.64.226]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slmoQ-00000003nr8-2gWM for linux-arm-kernel@lists.infradead.org; Wed, 04 Sep 2024 10:00:32 +0000 Received: by mta-64-226.siemens.flowmailer.net with ESMTPSA id 20240904100028b571bb6681edfa9419 for ; Wed, 04 Sep 2024 12:00:28 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=jan.kiszka@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc:References:In-Reply-To; bh=AbNAvrLHi+QFmGP7oAo1eWelX8ED/CVynTahfKnv7FE=; b=fy8KvrRRPTuqAzpz19tWI6aTV7M9778AEYVbi7QxYEWDINEx9ghyNz1vvSrkwwKlY2ithS PTh+4UErPshQ96exrmtEUYSaCgs5h4lhsnDSlLLF9tG1/oRY4b4O+nReyHWn9MCMLUepcGiu ghkX5/xwPkLImrB7F6KsZz8RbLhhoMl4QCTDYQYRovlVjBYAluvfwhwFGAWdNfmDoA707O7i aCU23zBVn51wxpsylnQwKvhKG5lPOiJx/BYc2ca3wya7UwkZfrkAYF+554Xp1SpxgzDbiS73 E7DsAkuDkcw0a5VRw/Mw4PpBDLOlvsXwpz3dxYOKY07OHk34fqHnQdcQ==; From: Jan Kiszka To: Nishanth Menon , Santosh Shilimkar , Vignesh Raghavendra , Tero Kristo , Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, Siddharth Vadapalli , Bao Cheng Su , Hua Qian Li , Diogo Ivo Subject: [PATCH v4 6/7] arm64: dts: ti: k3-am65-main: Add VMAP registers to PCI root complexes Date: Wed, 4 Sep 2024 12:00:15 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-294854:519-21489:flowmailer X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_030030_854930_1FFF5231 X-CRM114-Status: UNSURE ( 7.75 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Jan Kiszka Rewrap the long lines at this chance. Signed-off-by: Jan Kiszka --- arch/arm64/boot/dts/ti/k3-am65-main.dtsi | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/arch/arm64/boot/dts/ti/k3-am65-main.dtsi b/arch/arm64/boot/dts/ti/k3-am65-main.dtsi index 2582dad68dff..08a11ab38fbd 100644 --- a/arch/arm64/boot/dts/ti/k3-am65-main.dtsi +++ b/arch/arm64/boot/dts/ti/k3-am65-main.dtsi @@ -895,8 +895,13 @@ main_gpio1: gpio@601000 { pcie0_rc: pcie@5500000 { compatible = "ti,am654-pcie-rc"; - reg = <0x0 0x5500000 0x0 0x1000>, <0x0 0x5501000 0x0 0x1000>, <0x0 0x10000000 0x0 0x2000>, <0x0 0x5506000 0x0 0x1000>; - reg-names = "app", "dbics", "config", "atu"; + reg = <0x0 0x5500000 0x0 0x1000>, + <0x0 0x5501000 0x0 0x1000>, + <0x0 0x10000000 0x0 0x2000>, + <0x0 0x5506000 0x0 0x1000>, + <0x0 0x2900000 0x0 0x1000>, + <0x0 0x2908000 0x0 0x1000>; + reg-names = "app", "dbics", "config", "atu", "vmap_lp", "vmap_hp"; power-domains = <&k3_pds 120 TI_SCI_PD_EXCLUSIVE>; #address-cells = <3>; #size-cells = <2>; @@ -916,8 +921,13 @@ pcie0_rc: pcie@5500000 { pcie1_rc: pcie@5600000 { compatible = "ti,am654-pcie-rc"; - reg = <0x0 0x5600000 0x0 0x1000>, <0x0 0x5601000 0x0 0x1000>, <0x0 0x18000000 0x0 0x2000>, <0x0 0x5606000 0x0 0x1000>; - reg-names = "app", "dbics", "config", "atu"; + reg = <0x0 0x5600000 0x0 0x1000>, + <0x0 0x5601000 0x0 0x1000>, + <0x0 0x18000000 0x0 0x2000>, + <0x0 0x5606000 0x0 0x1000>, + <0x0 0x2910000 0x0 0x1000>, + <0x0 0x2918000 0x0 0x1000>; + reg-names = "app", "dbics", "config", "atu", "vmap_lp", "vmap_hp"; power-domains = <&k3_pds 121 TI_SCI_PD_EXCLUSIVE>; #address-cells = <3>; #size-cells = <2>; From patchwork Wed Sep 4 10:00:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jan Kiszka X-Patchwork-Id: 13790380 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id CA304CA0ED3 for ; Wed, 4 Sep 2024 10:27:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=IMjvXkR2et0GfXj5KTooParfgTgH6azkWUIJJLU1FK8=; b=GqSnaCZROkwiS7aaPfih7DKzTW ktF0xB9Qs9I1cxrHnz/N+0tuYleVamtxnld9aHGOONLFpcpNhItulgfejJBcgbXUn++JAyuBoXBzr ojSHdnepDElJW892oUPSG9pWKhQhrSFFfKbRTrCkV+dpofKwFP94Y7KU/LPIudzMZ53xqYI5ppI78 lPTvQ+uM2Hj7E9NfdL7kI3oR9AMgZbLtczwzE+IrUAMUs+wGzqycHqX6hcQWPsDzLncQ5y9OaTC9e 7S+gM1P/o+XG5zxBcF+M5kpOLLzkTEWiUtiJGl0P7K31PyQifeWAVqcAlBuF15Hp7lZO/WtRyAfZD 8MzAcxGA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1slnEg-00000003uzl-2u4e; Wed, 04 Sep 2024 10:27:38 +0000 Received: from mta-64-227.siemens.flowmailer.net ([185.136.64.227]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1slmoQ-00000003npq-2lYu for linux-arm-kernel@lists.infradead.org; Wed, 04 Sep 2024 10:00:32 +0000 Received: by mta-64-227.siemens.flowmailer.net with ESMTPSA id 20240904100029876f27700b94817018 for ; Wed, 04 Sep 2024 12:00:29 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; s=fm1; d=siemens.com; i=jan.kiszka@siemens.com; h=Date:From:Subject:To:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:Cc:References:In-Reply-To; bh=IMjvXkR2et0GfXj5KTooParfgTgH6azkWUIJJLU1FK8=; b=CXPPA8phomGv/pVwygg2mkoKMI4dKVKC0XmZ2SpQD3pbOJHFBtSBQnkfgGgP8b6I1UwGgs YVgGpdPU61l+pmAOBLC7Sf7Kkzj8zcUuEbtDb5oHcHx2HMA+SUlDd3ITtfEeVHloPoDoPTZG af7dXffQb9sHiUYYRRxGCAes86H0y/29AgDogZfzImRVYOA1Yjx6vzsHm70GWZxLk4CX2jB7 3yLCz3AfLR4ClhK2f8C/r7yFu1YFj3rBhEFw/EfuzNeTbjNFujbCnOAduSBS7a7a8JshhYB8 EK+xuKeA/8AwwcqgK4XVgY5TvX8nGQp6M5BYGwsvoT0tA/1J/jV4GJjQ==; From: Jan Kiszka To: Nishanth Menon , Santosh Shilimkar , Vignesh Raghavendra , Tero Kristo , Rob Herring , Krzysztof Kozlowski , Conor Dooley , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: linux-arm-kernel@lists.infradead.org, linux-pci@vger.kernel.org, Siddharth Vadapalli , Bao Cheng Su , Hua Qian Li , Diogo Ivo Subject: [PATCH v4 7/7] arm64: dts: ti: iot2050: Enforce DMA isolation for devices behind PCI RC on Advanced Date: Wed, 4 Sep 2024 12:00:16 +0200 Message-ID: In-Reply-To: References: MIME-Version: 1.0 X-Flowmailer-Platform: Siemens Feedback-ID: 519:519-294854:519-21489:flowmailer X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240904_030030_923674_E82E83C0 X-CRM114-Status: GOOD ( 10.89 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Jan Kiszka Reserve a 64M memory region and ensure that all PCI devices do their DMA only inside that region. This is configured via a restricted-dma-pool and enforced with the help of the first PVU. The pool size may be adjusted via DT fixup during boot by the firmware. The location is chosen to allow up to 512M for special needs without causing conflicts. Applying this isolation which is not totally free in terms of overhead and memory consumption makes only sense for variants that support secure booting. These are the advanced-class variants. Signed-off-by: Jan Kiszka --- .../ti/k3-am6548-iot2050-advanced-common.dtsi | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/ti/k3-am6548-iot2050-advanced-common.dtsi b/arch/arm64/boot/dts/ti/k3-am6548-iot2050-advanced-common.dtsi index ae842b85b70d..dc75e3ea9a6b 100644 --- a/arch/arm64/boot/dts/ti/k3-am6548-iot2050-advanced-common.dtsi +++ b/arch/arm64/boot/dts/ti/k3-am6548-iot2050-advanced-common.dtsi @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) Siemens AG, 2018-2021 + * Copyright (c) Siemens AG, 2018-2024 * * Authors: * Le Jin @@ -20,6 +20,25 @@ memory@80000000 { /* 2G RAM */ reg = <0x00000000 0x80000000 0x00000000 0x80000000>; }; + + reserved-memory { + pci_restricted_dma_region: restricted-dma@c0000000 { + compatible = "restricted-dma-pool"; + reg = <0 0xc0000000 0 0x4000000>; + }; + }; +}; + +&pcie0_rc { + memory-region = <&pci_restricted_dma_region>; +}; + +&pcie1_rc { + memory-region = <&pci_restricted_dma_region>; +}; + +&ti_pvu0 { + status = "okay"; }; &main_pmx0 {