From patchwork Fri Jun 5 08:33:44 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin GAIGNARD X-Patchwork-Id: 11589205 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F051C92A for ; Fri, 5 Jun 2020 08:34:59 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id CD9A72074B for ; Fri, 5 Jun 2020 08:34:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="smcpEFZN"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=st.com header.i=@st.com header.b="giXx+qn2" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CD9A72074B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=st.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=1p6TxovejWrVILZMHTpQ89JPbuF9B0xUlzrPej98pA8=; b=smcpEFZNl6kJnL Ibl/nW4LTJi/Nyscr+b/UW8Vzk5FJulv8oihCI3ISQhafwG9xgxm2spabjoMJ/BMZAKKL+deb8dHI hcxb/h4TKn/qWjg+OQ4g2W2AA35j5n5SL6MseXgcIjZchYrxzrhTqwL4kOdSCSR1hmago9NIO4W21 ot1HHdWZec8ln//KdC3POnV5IaJjEU0eec2mk7KRJD7Zv2yThyCmP0uMwZBLFMUQngmp9eYacDptG +Mb2ZcQWYYQ7FruJD2cfOArKAuWuTFFivBYbRS//EkrSpeCYKDKvAIMHhUx+eJIycKZXwEa2wyu9q rYrjcfW/wrHFmvzJJCvQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jh7oW-0004bz-By; Fri, 05 Jun 2020 08:34:56 +0000 Received: from mx08-00178001.pphosted.com ([91.207.212.93] helo=mx07-00178001.pphosted.com) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jh7nl-0003ef-8r for linux-arm-kernel@lists.infradead.org; Fri, 05 Jun 2020 08:34:13 +0000 Received: from pps.filterd (m0046660.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0558Wf3B029843; Fri, 5 Jun 2020 10:33:53 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=7+MnleNJkiEaO/P1tUZdrf9rpTSD5jzSpmCxlBfmTnI=; b=giXx+qn2MJVw97M8A3ITV3iPXJykZsf/gyxFedRPDkio8UuQ3+jj59T43IW3jIUSsuUm QMrH51YrYRMMbNPr9IaFKq0uUj7JUvqXLezzmvwiltic2Ad9wrL/1EhBParyMZuBUc/E /GVrMJVbj+HTaKAntn3RoAKZO9oOMrLERnefxSngfrOu2M2bXpyH3cZN0E98EdTrMDt+ YT99L6Al9dQjyHnTolgtbfZe+CQ12MzKXO1zlE+GaM6gzzGcbRwMMZpOY1Qg1ziwL5V8 GpFiBqFq7ko+hEBhSg8cuUzP5EXMDUhQMW+i1jLOHURzCQn/4hMGZwhWJCw8AKG4CKU5 /w== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 31fasma4ex-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 05 Jun 2020 10:33:53 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 3D65010002A; Fri, 5 Jun 2020 10:33:52 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag3node3.st.com [10.75.127.9]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 2C5852B21C0; Fri, 5 Jun 2020 10:33:52 +0200 (CEST) Received: from localhost (10.75.127.44) by SFHDAG3NODE3.st.com (10.75.127.9) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 5 Jun 2020 10:33:51 +0200 From: Benjamin Gaignard To: , , , , Subject: [PATCH v4 1/5] dt-bindings: bus: Add firewall bindings Date: Fri, 5 Jun 2020 10:33:44 +0200 Message-ID: <20200605083348.13880-2-benjamin.gaignard@st.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20200605083348.13880-1-benjamin.gaignard@st.com> References: <20200605083348.13880-1-benjamin.gaignard@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.44] X-ClientProxiedBy: SFHDAG5NODE1.st.com (10.75.127.13) To SFHDAG3NODE3.st.com (10.75.127.9) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.687 definitions=2020-06-05_01:2020-06-04, 2020-06-05 signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200605_013409_604548_6ED585B0 X-CRM114-Status: GOOD ( 13.80 ) X-Spam-Score: -0.9 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [91.207.212.93 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Benjamin Gaignard , tomase@xilinx.com, linux-kernel@vger.kernel.org, stefano.stabellini@xilinx.com, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Add schemas for firewall consumer and provider. Signed-off-by: Benjamin Gaignard Reviewed-by: Linus Walleij --- .../bindings/bus/stm32/firewall-consumer.yaml | 36 ++++++++++++++++++++++ .../bindings/bus/stm32/firewall-provider.yaml | 18 +++++++++++ 2 files changed, 54 insertions(+) create mode 100644 Documentation/devicetree/bindings/bus/stm32/firewall-consumer.yaml create mode 100644 Documentation/devicetree/bindings/bus/stm32/firewall-provider.yaml diff --git a/Documentation/devicetree/bindings/bus/stm32/firewall-consumer.yaml b/Documentation/devicetree/bindings/bus/stm32/firewall-consumer.yaml new file mode 100644 index 000000000000..d3d76f99b38d --- /dev/null +++ b/Documentation/devicetree/bindings/bus/stm32/firewall-consumer.yaml @@ -0,0 +1,36 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/bus/stm32/firewall-consumer.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Common Bus Firewall consumer binding + +description: | + Firewall properties provide the possible firewall bus controller + configurations for a device. + Bus firewall controllers are typically used to control if a hardware + block can perform read or write operations on bus. + The contents of the firewall bus configuration properties are defined by + the binding for the individual firewall controller device. + + The first configuration 'firewall-0' or the one named 'default' is + applied before probing the device itself. + +maintainers: + - Benjamin Gaignard + +# always select the core schema +select: true + +properties: + firewall-0: true + + firewall-names: true + +patternProperties: + "firewall-[0-9]": + $ref: "/schemas/types.yaml#/definitions/phandle-array" + +dependencies: + firewall-names: [ firewall-0 ] diff --git a/Documentation/devicetree/bindings/bus/stm32/firewall-provider.yaml b/Documentation/devicetree/bindings/bus/stm32/firewall-provider.yaml new file mode 100644 index 000000000000..299824c620ea --- /dev/null +++ b/Documentation/devicetree/bindings/bus/stm32/firewall-provider.yaml @@ -0,0 +1,18 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/bus/stm32/firewall-provider.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Common Bus Firewall provider binding + +maintainers: + - Benjamin Gaignard + +properties: + '#firewall-cells': + $ref: /schemas/types.yaml#/definitions/uint32 + description: Number of cells in a bus firewall specifier + +required: + - '#firewall-cells' From patchwork Fri Jun 5 08:33:45 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin GAIGNARD X-Patchwork-Id: 11589209 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E8CD8912 for ; Fri, 5 Jun 2020 08:35:42 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id A9F0D20663 for ; Fri, 5 Jun 2020 08:35:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ku3YG1Jg"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=st.com header.i=@st.com header.b="PVnIiIhj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A9F0D20663 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=st.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Q7MKmO6C/K9RRIfRCDUrh5ngFAoStkH/uo3C7NRdsNs=; b=ku3YG1JgZ0QpVV VQ9dNMy+xrBxa2D8uNkrkItUbRyb98865jg/YMA6yagfpaQOvjMB7exe2ed7w0Wdzqa7GSMstpWxk kKSWvYbA6FL+++ysaCJ6x2mkgoOPe8KxD/0KIl+dh0S8DtRUTrOpvmIvskG4dVUWiOoe4nIWvnoZE jzCEzk3nbxtrX7ZzU04a16ttI+qcoBNSF9fNptUV9+ISFEgwklv77Hzz4nfZ5Zx3GicMXILIwwyuu lA+GPbef8w+Ugwde6q3b0RRqcT7L5nco27uFtEZFCxGFbyefYbSIwP4Verq4FbK2T5S9sUeXhoAVl IjfeN/Mm/clgaQ6MZvhg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jh7pB-0007WV-M7; Fri, 05 Jun 2020 08:35:37 +0000 Received: from mx07-00178001.pphosted.com ([62.209.51.94]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jh7nl-0003el-Aj for linux-arm-kernel@lists.infradead.org; Fri, 05 Jun 2020 08:34:13 +0000 Received: from pps.filterd (m0046668.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0558WT2R027499; Fri, 5 Jun 2020 10:33:54 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=PXXZtQ5Os6lwz0ufC9ZTnIj88Nqg0GFEDPYR/vcbKrc=; b=PVnIiIhjXyzc9gNXvK+niWGo0x4SED7UWsIWV3rTHWxqzhLjfL/G7wHC0Ck3g2A1w0lS XgVMvswSAMa4KPmgnONiH93OHsvE3JghPCArOyHR2TwTxMTSNow3LamEYNPHoTDjQmKZ ElejmrgbKhEHSpdHZcAOGNAUj77qbbHSV7g20zlmVpHBrrRdQn3IAuwr5xwcxBBrgOos 8chHymy6j4Os7SBl+pBYfCk8vOrt/33QewvGAlRHpc6eTM3LAQWAqqjqhFqerFmBjqiZ foBoj6bn3aiFWc8jN0Ppub0LnhbY6YDBseFfoLM6o1LlvaS826F113pCG9o6O2zHWXH6 gA== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 31fasma5p7-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 05 Jun 2020 10:33:54 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id A765E10002A; Fri, 5 Jun 2020 10:33:53 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag3node3.st.com [10.75.127.9]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 98C302B21C0; Fri, 5 Jun 2020 10:33:53 +0200 (CEST) Received: from localhost (10.75.127.47) by SFHDAG3NODE3.st.com (10.75.127.9) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 5 Jun 2020 10:33:52 +0200 From: Benjamin Gaignard To: , , , , Subject: [PATCH v4 2/5] bus: stm32: Introduce firewall controller helpers Date: Fri, 5 Jun 2020 10:33:45 +0200 Message-ID: <20200605083348.13880-3-benjamin.gaignard@st.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20200605083348.13880-1-benjamin.gaignard@st.com> References: <20200605083348.13880-1-benjamin.gaignard@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.47] X-ClientProxiedBy: SFHDAG6NODE2.st.com (10.75.127.17) To SFHDAG3NODE3.st.com (10.75.127.9) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.687 definitions=2020-06-05_01:2020-06-04, 2020-06-05 signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200605_013409_666631_C87E3D02 X-CRM114-Status: GOOD ( 25.00 ) X-Spam-Score: -0.9 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [62.209.51.94 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Benjamin Gaignard , tomase@xilinx.com, linux-kernel@vger.kernel.org, stefano.stabellini@xilinx.com, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The goal of these helpers are to offer an interface for the hardware blocks controlling bus accesses rights. Bus firewall controllers are typically used to control if a hardware block can perform read or write operations on bus. Smarter firewall controllers could be able to define accesses rights per hardware blocks to control where they can read or write. Firewall controller configurations are provided in device node, parsed by the helpers and send to the driver to apply them. Each controller may need different number and type of inputs to configure the firewall so device-tree properties size have to be define by using "#firewall-cells". Firewall configurations properties have to be named "firewall-X" on device node. "firewall-names" keyword can also be used to give a name to a specific configuration. Example of device-tree: ctrl0: firewall@0 { #firewall-cells = <2>; }; foo: foo@0 { firewall-names = "default", "setting1"; firewall-0 = <&ctrl0 1 2>; firewall-1 = <&ctrl0 3 4>; }; Configurations could be applied with functions like firewall_set_config_by_index() or firewall_set_config_by_name(). firewall_set_default_config() function will apply the configuration named "default" (if existing) or the configuration with index 0 (i.e. firewall-0). Drivers could register/unregister themselves be calling firewall_register/firewall_unregister functions. Signed-off-by: Benjamin Gaignard --- version 4: - use bus API drivers/bus/Kconfig | 2 + drivers/bus/Makefile | 2 + drivers/bus/stm32/Kconfig | 3 + drivers/bus/stm32/Makefile | 1 + drivers/bus/stm32/firewall.c | 251 +++++++++++++++++++++++++++++++++++++++++++ drivers/bus/stm32/firewall.h | 66 ++++++++++++ 6 files changed, 325 insertions(+) create mode 100644 drivers/bus/stm32/Kconfig create mode 100644 drivers/bus/stm32/Makefile create mode 100644 drivers/bus/stm32/firewall.c create mode 100644 drivers/bus/stm32/firewall.h diff --git a/drivers/bus/Kconfig b/drivers/bus/Kconfig index 6d4e4497b59b..843b356322d9 100644 --- a/drivers/bus/Kconfig +++ b/drivers/bus/Kconfig @@ -203,4 +203,6 @@ config DA8XX_MSTPRI source "drivers/bus/fsl-mc/Kconfig" source "drivers/bus/mhi/Kconfig" +source "drivers/bus/stm32/Kconfig" + endmenu diff --git a/drivers/bus/Makefile b/drivers/bus/Makefile index 05f32cd694a4..5e0e34b10235 100644 --- a/drivers/bus/Makefile +++ b/drivers/bus/Makefile @@ -37,3 +37,5 @@ obj-$(CONFIG_DA8XX_MSTPRI) += da8xx-mstpri.o # MHI obj-$(CONFIG_MHI_BUS) += mhi/ + +obj-$(CONFIG_MACH_STM32MP157) += stm32/ \ No newline at end of file diff --git a/drivers/bus/stm32/Kconfig b/drivers/bus/stm32/Kconfig new file mode 100644 index 000000000000..57221e833e2d --- /dev/null +++ b/drivers/bus/stm32/Kconfig @@ -0,0 +1,3 @@ +config FIREWALL_CONTROLLERS + bool "Support of bus firewall controllers" + depends on OF diff --git a/drivers/bus/stm32/Makefile b/drivers/bus/stm32/Makefile new file mode 100644 index 000000000000..eb6b978d6450 --- /dev/null +++ b/drivers/bus/stm32/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_FIREWALL_CONTROLLERS) += firewall.o diff --git a/drivers/bus/stm32/firewall.c b/drivers/bus/stm32/firewall.c new file mode 100644 index 000000000000..234571b8ad11 --- /dev/null +++ b/drivers/bus/stm32/firewall.c @@ -0,0 +1,251 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) STMicroelectronics 2020 - All Rights Reserved + * Author: Benjamin Gaignard for STMicroelectronics. + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "firewall.h" + +struct firewall_device { + struct device dev; + struct firewall_ops *ops; +}; + +struct device firewall_bus = { + .init_name = "firewall", +}; + +static inline struct firewall_device *to_firewall_device(struct device *d) +{ + return container_of(d, struct firewall_device, dev); +} + +static struct bus_type firewall_bus_type = { + .name = "firewall", +}; + +static struct firewall_device *firewall_from_node(struct device_node *np) +{ + struct device *dev; + + dev = bus_find_device_by_of_node(&firewall_bus_type, np); + + return dev ? to_firewall_device(dev) : NULL; +} + +/** + * firewall_dt_has_default + * + * Check if the device node provide firewall configuration + * + * @np: device node with possible firewall configuration + * + * Return: true is firewall-0 property exist in the device node + */ +static bool firewall_dt_has_default(struct device_node *np) +{ + struct property *prop; + int size; + + if (!np) + return false; + + prop = of_find_property(np, "firewall-0", &size); + + return prop ? true : false; +} + +/** + * firewall_set_config_by_index + * + * Set a firewall controller configuration based on given index. + * + * @np: device node with firewall configuration to apply. + * @index: the index of the configuration in device node. + * + * Return: 0 if OK, -EPROBE_DEFER if waiting for firewall controller to be + * registered or negative value on other errors. + */ +int firewall_set_config_by_index(struct device_node *np, int index) +{ + char *propname; + int configs, i, err = 0; + + if (!np) + return 0; + + propname = kasprintf(GFP_KERNEL, "firewall-%d", index); + configs = of_count_phandle_with_args(np, propname, "#firewall-cells"); + if (configs < 0) { + err = -EINVAL; + goto error; + } + + for (i = 0; i < configs; i++) { + struct firewall_device *firewall; + struct of_phandle_args args; + + err = of_parse_phandle_with_args(np, propname, + "#firewall-cells", + i, &args); + if (err) + goto error; + + /* Test if the controller is (or will be) available */ + if (!of_device_is_available(args.np)) { + of_node_put(args.np); + continue; + } + + firewall = firewall_from_node(args.np); + of_node_put(args.np); + + /* Firewall is not yet registered */ + if (!firewall) { + err = -EPROBE_DEFER; + goto error; + } + + err = firewall->ops->set_config(&firewall->dev, &args); + if (err) + goto error; + } + +error: + kfree(propname); + return err; +} +EXPORT_SYMBOL_GPL(firewall_set_config_by_index); + +/** + * firewall_set_config_by_name + * + * Set a firwall controller configuration based on given name. + * + * @np: device node with firewall configuration to apply. + * @name: the name of the configuration in device node. + * + * Return: 0 if OK, -EPROBE_DEFER if waiting for firewall controller to be + * registered or negative value on other errors. + */ +int firewall_set_config_by_name(struct device_node *np, char *name) +{ + const char *configname; + int count, i; + + count = of_property_count_strings(np, "firewall-names"); + for (i = 0; i < count; i++) { + int err; + + err = of_property_read_string_index(np, + "firewall-names", + i, &configname); + if (err) + return err; + + if (strcmp(name, configname)) + continue; + + return firewall_set_config_by_index(np, i); + } + + return -EINVAL; +} +EXPORT_SYMBOL_GPL(firewall_set_config_by_name); + +/** + * firewall_set_default_config + * + * Set the default configuration for device. + * First try to apply configuration named "default", if it fails + * or doesn't exist, try to apply firewall-0 configuration. + * + * @np: device node with firewall configuration to apply. + * + * Return: 0 if OK, -EPROBE_DEFER if waiting for firewall controller to be + * registered or negative value on other errors. + */ +int firewall_set_default_config(struct device_node *np) +{ + int ret; + + /* Nothing to do if device node doesn't contain at least + * one configuration + */ + if (!firewall_dt_has_default(np)) + return 0; + + ret = firewall_set_config_by_name(np, "default"); + if (!ret || (ret == -EPROBE_DEFER)) + return ret; + + return firewall_set_config_by_index(np, 0); +} +EXPORT_SYMBOL_GPL(firewall_set_default_config); + +/** + * firewall_register + * + * Register a firewall controller. + * + * @np: node implementing firewall controller. + * @ops: firewall controller operations. + * + * Return: a pointer on the device if OK or NULL on error. + */ +struct device *firewall_register(struct device_node *np, + struct firewall_ops *ops) +{ + struct firewall_device *firewall; + + if (!np || !ops || !ops->set_config) + return NULL; + + firewall = kzalloc(sizeof(*firewall), GFP_KERNEL); + if (!firewall) + return NULL; + + device_initialize(&firewall->dev); + firewall->dev.init_name = devm_kstrdup(&firewall->dev, + np->name, GFP_KERNEL); + firewall->dev.bus = &firewall_bus_type; + firewall->dev.parent = &firewall_bus; + firewall->dev.of_node = np; + firewall->ops = ops; + + if (device_add(&firewall->dev)) { + kfree(firewall); + return NULL; + } + + return &firewall->dev; +} +EXPORT_SYMBOL_GPL(firewall_register); + +static int __init firewall_init(void) +{ + int ret; + + ret = device_register(&firewall_bus); + if (ret) { + put_device(&firewall_bus); + return ret; + } + + ret = bus_register(&firewall_bus_type); + if (ret) + device_unregister(&firewall_bus); + + return ret; +} + +/* Init early since drivers really need to configure firewall early */ +core_initcall(firewall_init); diff --git a/drivers/bus/stm32/firewall.h b/drivers/bus/stm32/firewall.h new file mode 100644 index 000000000000..ea38f9f7e4ee --- /dev/null +++ b/drivers/bus/stm32/firewall.h @@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) STMicroelectronics 2020 - All Rights Reserved + * Author: Benjamin Gaignard for STMicroelectronics. + */ + +#ifndef _FIREWALL_H_ +#define _FIREWALL_H_ + +#include +#include + +/** + * struct firewall_ops + * + * Firewall controller operations structure to be filled by drivers. + */ +struct firewall_ops { + /** + * @set_config: + * + * Driver callback to set a firewall configuration on a controller. + * Configuration arguments are provided in out_args parameter. + * + * Return: 0 on success, a negative error code on failure. + */ + int (*set_config)(struct device *dev, struct of_phandle_args *out_args); +}; + +#ifdef CONFIG_FIREWALL_CONTROLLERS + +int firewall_set_config_by_index(struct device_node *np, int index); +int firewall_set_config_by_name(struct device_node *np, char *name); +int firewall_set_default_config(struct device_node *np); + +struct device *firewall_register(struct device_node *np, + struct firewall_ops *ops); + +#else + +static inline int firewall_set_config_by_index(struct device_node *np, + int index) +{ + return 0; +} + +static inline int firewall_set_config_by_name(struct device_node *np, + char *name) +{ + return 0; +} + +static inline int firewall_set_default_config(struct device_node *np) +{ + return 0; +} + +static inline struct device *firewall_register(struct device_node *np, + struct firewall_ops *ops) +{ + return NULL; +} + +#endif + +#endif /* _FIREWALL_H_ */ From patchwork Fri Jun 5 08:33:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin GAIGNARD X-Patchwork-Id: 11589203 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 170E3618 for ; Fri, 5 Jun 2020 08:34:46 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id E354D2074B for ; Fri, 5 Jun 2020 08:34:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="SPq1/TSN"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=st.com header.i=@st.com header.b="D5bGoFQj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E354D2074B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=st.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=yaTY7REPjTZGxgPGWGRsBoUtYxi2n89OpsOqFgEe/+I=; b=SPq1/TSN8zLOto ihJvcrtCu3mfdO4Vg8Ql/AeMULAgrEWnHBkyczwXfq652qM3Epgf3Hwe8n4oaY5IaDnn3VN/rpHvj 0f2DoHz6zvP+S+o0E8q/00qf0T8xCIc5mzmFL8FqsxZPXfQwKzCoYOttd6SrMOlC+RgRyZeHk2Vxq kMPbwEwTOYe9mfmTYztmyfpGSp2aKO/MBqg+VfGffUe2m+lgsW7bMeRl9WyAR1eGUKnSDlQG+q38i dEeM+7OwZAqVZ8w9dIVau77ce1g9eI8oNqLB5HbMtNfGRHTuH1J/uy/eJosOIULbZ51wXOca40Cu7 gU0qK+5+inJ1uL7eD55Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jh7oE-00047r-JA; Fri, 05 Jun 2020 08:34:38 +0000 Received: from mx08-00178001.pphosted.com ([91.207.212.93] helo=mx07-00178001.pphosted.com) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jh7nl-0003ei-4Y for linux-arm-kernel@lists.infradead.org; Fri, 05 Jun 2020 08:34:12 +0000 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0558WAXu010401; Fri, 5 Jun 2020 10:33:55 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=Qtjkenp1luntosfDrmrcRmxaJE1CtXuduIjGsuWvcRw=; b=D5bGoFQjnIOpItvQVGzcf66EUVa9d1feHtWPoJlLdeCtHlhcJF3BOiVxSgddvpzIp9mf xGV62uI8DCdgK/0A6vhsl43q3C3vXt6LxpEMNL/jSlTbIN7Oq29LfkmvL2+wuksorBOn 9USe7oVVwxuLmITL43FerH2IsuI5lXZ6Izsv41VkWD7T49l/r/8AziijSQVqvj5npKMr 5KqNU4EdH9ToO81YR4OCuR6uYOWEozTllBtcI+3NuGUTpqWbrkP9TV1K5vWdXKZMU+0P AydrDRRyZF2WG8iBTS4i0xhdQPJnQSzqdgme+Mthh2YSjIFKg8eHbCRiSCY5jKhaBTsQ Zg== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 31faset4ns-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 05 Jun 2020 10:33:55 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id AC6FC100039; Fri, 5 Jun 2020 10:33:54 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag3node3.st.com [10.75.127.9]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id A082E2B21C0; Fri, 5 Jun 2020 10:33:54 +0200 (CEST) Received: from localhost (10.75.127.45) by SFHDAG3NODE3.st.com (10.75.127.9) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 5 Jun 2020 10:33:54 +0200 From: Benjamin Gaignard To: , , , , Subject: [PATCH v4 3/5] dt-bindings: bus: Add STM32 ETZPC firewall controller Date: Fri, 5 Jun 2020 10:33:46 +0200 Message-ID: <20200605083348.13880-4-benjamin.gaignard@st.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20200605083348.13880-1-benjamin.gaignard@st.com> References: <20200605083348.13880-1-benjamin.gaignard@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.45] X-ClientProxiedBy: SFHDAG5NODE1.st.com (10.75.127.13) To SFHDAG3NODE3.st.com (10.75.127.9) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.687 definitions=2020-06-05_01:2020-06-04, 2020-06-05 signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200605_013409_529533_984585F0 X-CRM114-Status: GOOD ( 12.65 ) X-Spam-Score: -0.9 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [91.207.212.93 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Benjamin Gaignard , tomase@xilinx.com, linux-kernel@vger.kernel.org, stefano.stabellini@xilinx.com, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Document STM32 ETZPC firewall controller bindings Signed-off-by: Benjamin Gaignard --- .../bindings/bus/stm32/st,stm32-etzpc.yaml | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 Documentation/devicetree/bindings/bus/stm32/st,stm32-etzpc.yaml diff --git a/Documentation/devicetree/bindings/bus/stm32/st,stm32-etzpc.yaml b/Documentation/devicetree/bindings/bus/stm32/st,stm32-etzpc.yaml new file mode 100644 index 000000000000..d92865fda40c --- /dev/null +++ b/Documentation/devicetree/bindings/bus/stm32/st,stm32-etzpc.yaml @@ -0,0 +1,46 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/bus/stm32/st,stm32-etzpc.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: STM32 Extended TrustZone Protection controller + +maintainers: + - Benjamin Gaignard + +description: STMicroelectronics's STM32 firewall bus controller implementation + +allOf: + - $ref: "firewall-provider.yaml#" + - $ref: /schemas/simple-bus.yaml# + +properties: + compatible: + contains: + enum: + - st,stm32-etzpc-bus + + reg: + maxItems: 1 + + '#firewall-cells': + const: 2 + +required: + - compatible + - reg + - '#firewall-cells' + +examples: + - | + soc@5c007000 { + compatible = "st,stm32-etzpc-bus", "simple-bus"; + reg = <0x5c007000 0x400>; + #firewall-cells = <2>; + #address-cells = <1>; + #size-cells = <1>; + ranges; + }; + +... From patchwork Fri Jun 5 08:33:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin GAIGNARD X-Patchwork-Id: 11589207 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 112F992A for ; Fri, 5 Jun 2020 08:35:29 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 8B38920663 for ; Fri, 5 Jun 2020 08:35:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="OPjCeMqh"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=st.com header.i=@st.com header.b="rtXi0L3t" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8B38920663 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=st.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=R7TnuG7HG+g5xhGgquwKkJ3buZv1MjLxZJ1otFHHwbo=; b=OPjCeMqhhdjiV6 HRpSOHPoN/8OGCeA3IXORNNse2hOXvwis6mB4WlGjatLei1ZWRemabRggWjQkkDOvd2NY3GPkexx8 4LFK5Kwi5B/zN3lrQtcdt4hldsDqyXghZcJQzJa5ajXMJCUbmivEtaeT2TjdqV+FeJJKF1rZqhknP vCKkVcjzf10x+aqrhFj3wiuyijPTjHEc7NdSFqlW1RHrmg7DeH+y23E8j0mK1YG3hd0E+/N3EdXD3 jDqEKmpQqh5Gj5Ep/pzonyNZ6xYw2HSzSuDkEXehKE6yPPXS5/t23yy+5tZM6/EbbUWK2bJa0fD9I +Wo3HRVnwkGwxgXtY0vw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jh7ov-0007Fs-4p; Fri, 05 Jun 2020 08:35:21 +0000 Received: from mx08-00178001.pphosted.com ([91.207.212.93] helo=mx07-00178001.pphosted.com) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jh7nl-0003ej-53 for linux-arm-kernel@lists.infradead.org; Fri, 05 Jun 2020 08:34:13 +0000 Received: from pps.filterd (m0046661.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0558WAv7010468; Fri, 5 Jun 2020 10:33:56 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=Noyc1sz1H7BSum1HD5Fbfe/NwPdfyZxzQktyj1gbcR4=; b=rtXi0L3t/MClH5Dxfjg+P0+0WQTeimCI7uY3sEGrqWRgkplqKrjTW1+azHLMAzKNonuT fkeoJLEoZuRKV53vmQj46g/AF4c09VhoU6rJKNnJ8J+hSsUOeMouVYJ9UtnS/PzIbqCs fEfkp5NYxstLoJIrg6RI0//aRyqyiZDyjToCJVbD7oRoTad3r74mPaRDRZ/jRfor8X1P Rk+Ur1j1ue8aG43EdgcqzzaBUivgm9ZSN1L6pi4Crkd10ikxNtHethTushitQwy+w9LW LaZBuygiOdvmk1oTkO80dX6JnlnlQCBofjKy8lSBQOgKSnm1sDtA6aPk0+BncsbyUD36 pg== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 31faset4ny-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 05 Jun 2020 10:33:56 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 042DE100038; Fri, 5 Jun 2020 10:33:56 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag3node3.st.com [10.75.127.9]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id ECEAA2B21C1; Fri, 5 Jun 2020 10:33:55 +0200 (CEST) Received: from localhost (10.75.127.44) by SFHDAG3NODE3.st.com (10.75.127.9) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 5 Jun 2020 10:33:55 +0200 From: Benjamin Gaignard To: , , , , Subject: [PATCH v4 4/5] bus: stm32: Add stm32 ETZPC firewall bus controller Date: Fri, 5 Jun 2020 10:33:47 +0200 Message-ID: <20200605083348.13880-5-benjamin.gaignard@st.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20200605083348.13880-1-benjamin.gaignard@st.com> References: <20200605083348.13880-1-benjamin.gaignard@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.44] X-ClientProxiedBy: SFHDAG4NODE2.st.com (10.75.127.11) To SFHDAG3NODE3.st.com (10.75.127.9) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.687 definitions=2020-06-05_01:2020-06-04, 2020-06-05 signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200605_013409_520274_A0E6D4F2 X-CRM114-Status: GOOD ( 20.67 ) X-Spam-Score: -0.9 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [91.207.212.93 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Benjamin Gaignard , tomase@xilinx.com, linux-kernel@vger.kernel.org, stefano.stabellini@xilinx.com, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Add STM32 Extended TrustZone Protection bus controller. For each of device-tree nodes it will check and apply firewall configuration. If it doesn't match the device will not be probed by platform bus. A device could be configured to be accessible by trusted world, co-processor or non-secure world. Signed-off-by: Benjamin Gaignard --- drivers/bus/stm32/Kconfig | 8 ++ drivers/bus/stm32/Makefile | 1 + drivers/bus/stm32/stm32-etzpc.c | 163 ++++++++++++++++++++++++++++ include/dt-bindings/bus/stm32/stm32-etzpc.h | 90 +++++++++++++++ 4 files changed, 262 insertions(+) create mode 100644 drivers/bus/stm32/stm32-etzpc.c create mode 100644 include/dt-bindings/bus/stm32/stm32-etzpc.h diff --git a/drivers/bus/stm32/Kconfig b/drivers/bus/stm32/Kconfig index 57221e833e2d..5dc6e2504de5 100644 --- a/drivers/bus/stm32/Kconfig +++ b/drivers/bus/stm32/Kconfig @@ -1,3 +1,11 @@ config FIREWALL_CONTROLLERS bool "Support of bus firewall controllers" depends on OF + +config STM32_ETZPC + bool "STM32 ETZPC bus controller" + depends on MACH_STM32MP157 + select FIREWALL_CONTROLLERS + help + Select y to enable STM32 Extended TrustZone Protection + Controller (ETZPC) diff --git a/drivers/bus/stm32/Makefile b/drivers/bus/stm32/Makefile index eb6b978d6450..d42e99b5865e 100644 --- a/drivers/bus/stm32/Makefile +++ b/drivers/bus/stm32/Makefile @@ -1 +1,2 @@ obj-$(CONFIG_FIREWALL_CONTROLLERS) += firewall.o +obj-$(CONFIG_STM32_ETZPC) += stm32-etzpc.o diff --git a/drivers/bus/stm32/stm32-etzpc.c b/drivers/bus/stm32/stm32-etzpc.c new file mode 100644 index 000000000000..ad0e16eea66b --- /dev/null +++ b/drivers/bus/stm32/stm32-etzpc.c @@ -0,0 +1,163 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) STMicroelectronics 2020 - All Rights Reserved + * Author: Benjamin Gaignard for STMicroelectronics. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "firewall.h" + +#define ETZPC_DECPROT 0x010 +#define ETZPC_NUM_LOCKS 94 + +struct stm32_etzpc { + struct regmap_field *fields[ETZPC_NUM_LOCKS]; +}; + +static int stm32_etzpc_set_config(struct device *dev, + struct of_phandle_args *out_args) +{ + struct stm32_etzpc *etzpc = dev_get_drvdata(dev); + int index = out_args->args[0]; + unsigned int value = out_args->args[1]; + u32 status; + + if (out_args->args_count != 2) + return -EINVAL; + + if (index >= ETZPC_NUM_LOCKS) + return -EINVAL; + + if (value > STM32_ETZPC_NON_SECURE) + return -EINVAL; + + regmap_field_force_write(etzpc->fields[index], value); + + /* Hardware could denied the new value, read it back to check it */ + regmap_field_read(etzpc->fields[index], &status); + + if (value != status) { + pr_info("failed to set configuration: index %d, value %d\n", + index, value); + return -EINVAL; + } + + return 0; +} + +static struct firewall_ops stm32_etzpc_ops = { + .set_config = stm32_etzpc_set_config, +}; + +static const struct regmap_config stm32_etzpc_regmap_cfg = { + .reg_bits = 32, + .val_bits = 32, + .reg_stride = sizeof(u32), + .max_register = 0x3FF, +}; + +static void stm32_etzpc_populate(struct device *parent) +{ + struct device_node *child; + + if (!parent) + return; + + for_each_available_child_of_node(dev_of_node(parent), child) { + if (firewall_set_default_config(child)) { + /* + * Failed to set firewall configuration mark the node + * as populated so platform bus won't probe it + */ + of_node_set_flag(child, OF_POPULATED); + dev_info(parent, "%s: Bad firewall configuration\n", + child->name); + } + } +} + +static int stm32_etzpc_probe(struct platform_device *pdev) +{ + struct stm32_etzpc *etzpc; + struct device *firewall; + struct regmap *regmap; + struct resource *res; + void __iomem *mmio; + int i; + + etzpc = devm_kzalloc(&pdev->dev, sizeof(*etzpc), GFP_KERNEL); + if (!etzpc) + return -ENOMEM; + + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); + mmio = devm_ioremap_resource(&pdev->dev, res); + if (IS_ERR(mmio)) + return PTR_ERR(mmio); + + regmap = devm_regmap_init_mmio(&pdev->dev, mmio, + &stm32_etzpc_regmap_cfg); + + for (i = 0; i < ETZPC_NUM_LOCKS; i++) { + struct reg_field field; + + /* + * Each hardware block status is defined by + * a 2 bits field and all of them are packed into + * 32 bits registers. Do some computation to get + * register offset and the shift. + */ + field.reg = ETZPC_DECPROT + (i >> 4) * sizeof(u32); + field.lsb = (i % 0x10) << 1; + field.msb = field.lsb + 1; + + etzpc->fields[i] = devm_regmap_field_alloc(&pdev->dev, + regmap, field); + } + + platform_set_drvdata(pdev, etzpc); + + firewall = firewall_register(dev_of_node(&pdev->dev), + &stm32_etzpc_ops); + if (!firewall) + return -EINVAL; + + dev_set_drvdata(firewall, etzpc); + + stm32_etzpc_populate(&pdev->dev); + + return 0; +} + +static const struct of_device_id stm32_etzpc_of_match[] = { + { .compatible = "st,stm32-etzpc-bus" }, + { /* end node */ } +}; +MODULE_DEVICE_TABLE(of, stm32_etzpc_of_match); + +static struct platform_driver stm32_etzpc_driver = { + .probe = stm32_etzpc_probe, + .driver = { + .name = "stm32-etzpc", + .of_match_table = stm32_etzpc_of_match, + }, +}; + +static int __init stm32_etzpc_init(void) +{ + return platform_driver_register(&stm32_etzpc_driver); +} +arch_initcall(stm32_etzpc_init); + +MODULE_AUTHOR("Benjamin Gaignard "); +MODULE_DESCRIPTION("STMicroelectronics STM32 Bus Firewall Controller"); diff --git a/include/dt-bindings/bus/stm32/stm32-etzpc.h b/include/dt-bindings/bus/stm32/stm32-etzpc.h new file mode 100644 index 000000000000..9c4783b9783c --- /dev/null +++ b/include/dt-bindings/bus/stm32/stm32-etzpc.h @@ -0,0 +1,90 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) STMicroelectronics 2020 - All Rights Reserved + * Author: Benjamin Gaignard for STMicroelectronics. + */ + +#ifndef _STM32_ETZPC_H_ +#define _STM32_ETZPC_H_ + +/* ETZPC configurations: trust-zone, non-secure or coprocessor*/ +#define STM32_ETZPC_TRUST 1 +#define STM32_ETPCZ_COPRO 2 +#define STM32_ETZPC_NON_SECURE 3 + +/* ETZPC hard blocks index */ +#define STM32_ETZPC_USART1 3 +#define STM32_ETZPC_SPI6 4 +#define STM32_ETZPC_I2C4 5 +#define STM32_ETZPC_RNG1 7 +#define STM32_ETZPC_HASH1 8 +#define STM32_ETZPC_CRYP1 9 +#define STM32_ETZPC_I2C6 12 +#define STM32_ETZPC_TIM2 16 +#define STM32_ETZPC_TIM3 17 +#define STM32_ETZPC_TIM4 18 +#define STM32_ETZPC_TIM5 19 +#define STM32_ETZPC_TIM6 20 +#define STM32_ETZPC_TIM7 21 +#define STM32_ETZPC_TIM12 22 +#define STM32_ETZPC_TIM13 23 +#define STM32_ETZPC_TIM14 24 +#define STM32_ETZPC_LPTIM1 25 +#define STM32_ETZPC_SPI2 27 +#define STM32_ETZPC_SPI3 28 +#define STM32_ETZPC_USART2 30 +#define STM32_ETZPC_USART3 31 +#define STM32_ETZPC_USART4 32 +#define STM32_ETZPC_USART5 33 +#define STM32_ETZPC_I2C1 34 +#define STM32_ETZPC_I2C2 35 +#define STM32_ETZPC_I2C3 36 +#define STM32_ETZPC_I2C5 37 +#define STM32_ETZPC_CEC 38 +#define STM32_ETZPC_DAC 39 +#define STM32_ETZPC_UART7 40 +#define STM32_ETZPC_UART8 41 +#define STM32_ETZPC_MDIOS 44 +#define STM32_ETZPC_TIM1 48 +#define STM32_ETZPC_TIM8 49 +#define STM32_ETZPC_USART6 51 +#define STM32_ETZPC_SPI1 52 +#define STM32_ETZPC_SPI4 53 +#define STM32_ETZPC_TIM15 54 +#define STM32_ETZPC_TIM16 55 +#define STM32_ETZPC_TIM17 56 +#define STM32_ETZPC_SPI5 57 +#define STM32_ETZPC_SAI1 58 +#define STM32_ETZPC_SAI2 59 +#define STM32_ETZPC_SAI3 60 +#define STM32_ETZPC_DFSDM 61 +#define STM32_ETZPC_TT_FDCAN 62 +#define STM32_ETZPC_LPTIM2 64 +#define STM32_ETZPC_LPTIM3 65 +#define STM32_ETZPC_LPTIM4 66 +#define STM32_ETZPC_LPTIM5 67 +#define STM32_ETZPC_SAI4 68 +#define STM32_ETZPC_VREFBUF 69 +#define STM32_ETZPC_DCMI 70 +#define STM32_ETZPC_CRC2 71 +#define STM32_ETZPC_ADC 72 +#define STM32_ETZPC_HASH2 73 +#define STM32_ETZPC_RNG2 74 +#define STM32_ETZPC_CRYP2 75 +#define STM32_ETZPC_SRAM1 80 +#define STM32_ETZPC_SRAM2 81 +#define STM32_ETZPC_SRAM3 82 +#define STM32_ETZPC_SRAM4 83 +#define STM32_ETZPC_RETRAM 84 +#define STM32_ETZPC_OTG 85 +#define STM32_ETZPC_SDMMC3 86 +#define STM32_ETZPC_DLYBSD3 87 +#define STM32_ETZPC_DMA1 88 +#define STM32_ETZPC_DMA2 89 +#define STM32_ETZPC_DMAMUX 90 +#define STM32_ETZPC_FMC 91 +#define STM32_ETZPC_QSPI 92 +#define STM32_ETZPC_DLYBQ 93 +#define STM32_ETZPC_ETH1 94 + +#endif /* _STM32_ETZPC_H_ */ From patchwork Fri Jun 5 08:33:48 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin GAIGNARD X-Patchwork-Id: 11589199 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C81BC618 for ; Fri, 5 Jun 2020 08:34:17 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 8CF832074B for ; Fri, 5 Jun 2020 08:34:17 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ZMMglN4O"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=st.com header.i=@st.com header.b="nL0pF5rG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8CF832074B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=st.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=sbVDwj5AtkRSp4HKom3Tdl/iqoZCXNaxmboSanOhO78=; b=ZMMglN4OCPq4i0 xpKjmemhrST98AX6TdOFPlxPGWmghOmLvD3LgWIFbez0kdPkM4wU/hGyFNgLzxS68c8KI/Q48I+0M ELEbNXy9mfG8Oce7C3EwNVzXL1dIwg7TQJCCNX+p6Nb3h6S8PoLoTfi9fN0Hl8T1lntxlajhInjbR UNMCq1l6NogG4JXwHP61mKqjRYrNaAFaduHc4BAPDn/YBOOSqRQOLN/CtbUXLzVVnP0XeG/7Oh1HB w4ifCfDo0vYnK7N0BkppD1d09m0bu2uEA3eSTx5NxzXixWyLnG1TZqy7NxKgW1EzvSCfy5miO/oZJ iPtq4elBX8hq0gWMS+GA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jh7np-0003gn-3y; Fri, 05 Jun 2020 08:34:13 +0000 Received: from mx07-00178001.pphosted.com ([62.209.51.94]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jh7nl-0003eg-3u for linux-arm-kernel@lists.infradead.org; Fri, 05 Jun 2020 08:34:11 +0000 Received: from pps.filterd (m0046037.ppops.net [127.0.0.1]) by mx07-00178001.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id 0558Vbfp007720; Fri, 5 Jun 2020 10:33:57 +0200 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=st.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-type; s=STMicroelectronics; bh=iGCDghN3T5Y00zNouGbtPQSvGhwl/OIHxAZ2MQmEADQ=; b=nL0pF5rGY/jyCNuJ0G2qPbh4gN6O3khPft35loOo04bnl3OFdlRNleY8BhAympZK8jar j7od9FNVKlF1uIOGoNZ/h59WOpGa97iI2E6yCvudb/wcSaIZnP1Jyd3CO/Nq/oqKtkuD sfIUPDfsrLvCuRa/9IbJhzreTtyjkLTCPTlaSP2Fl5IO/ftV9z5khLbP65v3+2XRsJ91 ZnvwKmoT932kj3Nf7z0gZ9qqUG/nPf/2EAgLVcx6gH4scyqXDvWwSDsn4ISzHac+Nv2L RQsJlKjVGFYgLZ5g5RFMS4vq/acD48U8LJlll/rlFRlFf/xZzk+OOnwPEMA32cYItFs6 Sw== Received: from beta.dmz-eu.st.com (beta.dmz-eu.st.com [164.129.1.35]) by mx07-00178001.pphosted.com with ESMTP id 31fat4j5ms-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Fri, 05 Jun 2020 10:33:57 +0200 Received: from euls16034.sgp.st.com (euls16034.sgp.st.com [10.75.44.20]) by beta.dmz-eu.st.com (STMicroelectronics) with ESMTP id 1C04910002A; Fri, 5 Jun 2020 10:33:57 +0200 (CEST) Received: from Webmail-eu.st.com (sfhdag3node3.st.com [10.75.127.9]) by euls16034.sgp.st.com (STMicroelectronics) with ESMTP id 0DDBF2B21C0; Fri, 5 Jun 2020 10:33:57 +0200 (CEST) Received: from localhost (10.75.127.45) by SFHDAG3NODE3.st.com (10.75.127.9) with Microsoft SMTP Server (TLS) id 15.0.1347.2; Fri, 5 Jun 2020 10:33:56 +0200 From: Benjamin Gaignard To: , , , , Subject: [PATCH v4 5/5] ARM: dts: stm32: Use ETZPC firewall bus Date: Fri, 5 Jun 2020 10:33:48 +0200 Message-ID: <20200605083348.13880-6-benjamin.gaignard@st.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20200605083348.13880-1-benjamin.gaignard@st.com> References: <20200605083348.13880-1-benjamin.gaignard@st.com> MIME-Version: 1.0 X-Originating-IP: [10.75.127.45] X-ClientProxiedBy: SFHDAG5NODE3.st.com (10.75.127.15) To SFHDAG3NODE3.st.com (10.75.127.9) X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.216, 18.0.687 definitions=2020-06-05_01:2020-06-04, 2020-06-05 signatures=0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200605_013409_516691_060902B1 X-CRM114-Status: GOOD ( 13.45 ) X-Spam-Score: -0.9 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at https://www.dnswl.org/, low trust [62.209.51.94 listed in list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Benjamin Gaignard , tomase@xilinx.com, linux-kernel@vger.kernel.org, stefano.stabellini@xilinx.com, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Allow STM32 ETZPC to check firewall configuration before populating the platform bus. Signed-off-by: Benjamin Gaignard --- arch/arm/boot/dts/stm32mp151.dtsi | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/arm/boot/dts/stm32mp151.dtsi b/arch/arm/boot/dts/stm32mp151.dtsi index 3ea05ba48215..0290eb6f3c35 100644 --- a/arch/arm/boot/dts/stm32mp151.dtsi +++ b/arch/arm/boot/dts/stm32mp151.dtsi @@ -4,6 +4,7 @@ * Author: Ludovic Barre for STMicroelectronics. */ #include +#include #include #include @@ -110,8 +111,10 @@ status = "disabled"; }; - soc { - compatible = "simple-bus"; + etzpc_bus: soc@5c007000 { + compatible = "st,stm32-etzpc-bus", "simple-bus"; + reg = <0x5c007000 0x400>; + #firewall-cells = <2>; #address-cells = <1>; #size-cells = <1>; interrupt-parent = <&intc>;