From patchwork Wed Oct 27 07:30:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Massot X-Patchwork-Id: 12586511 X-Patchwork-Delegate: geert@linux-m68k.org 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5F97DC433F5 for ; Wed, 27 Oct 2021 07:30:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 39BAE60E8C for ; Wed, 27 Oct 2021 07:30:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240377AbhJ0HdC (ORCPT ); Wed, 27 Oct 2021 03:33:02 -0400 Received: from mail.iot.bzh ([51.75.236.24]:7112 "EHLO frontal.iot.bzh" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238468AbhJ0HdB (ORCPT ); Wed, 27 Oct 2021 03:33:01 -0400 Received: from frontal.iot.bzh (localhost [127.0.0.1]) by frontal.iot.bzh (Proxmox) with ESMTP id 3BC9B25108; Wed, 27 Oct 2021 09:30:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iot.bzh; h=cc:cc :content-transfer-encoding:date:from:from:in-reply-to:message-id :mime-version:references:reply-to:subject:subject:to:to; s= iot.bzh; bh=jAf3R5ZyexAMPU3GUd0OTU1+8j7GJia+7fFU5b693MA=; b=A3d5 5r3k2hwmJoorMRVwb6PAq8eyUFrx/YCyukpb2Uv2sNTHsj1dxJz708foNWsvtkfV ODKWDWgdo+ZLprqPq48qtSnKxXBlAM9G+LAcFNWjqNwSH99jfbx8HRR+suBKodnF RlXgNdBwGcU0UOKqxf0L9JDYzd5hNrYKQQGTLElJ6AVwKOyBMr7p4VIiNx2npNpJ lL221C+RS2nE/q5fkofzqK6BYMf7bNuXxpB432MEjsnQn/fAPMHzpj1tMPlJXVcw YLGcApb/oC7fsq0UMd4iJnHSIAO6CRJ6DO6g8QiR34jr2YrByITCC+4BSCPFLJ8b aZPoesQiotyE7pBSMg== From: Julien Massot To: bjorn.andersson@linaro.org, mathieu.poirier@linaro.org, robh+dt@kernel.org, geert+renesas@glider.be Cc: linux-renesas-soc@vger.kernel.org, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, Julien Massot Subject: [RFC PATCH 1/3] dt-bindings: remoteproc: Add Renesas R-Car Date: Wed, 27 Oct 2021 09:30:18 +0200 Message-Id: <20211027073020.17055-2-julien.massot@iot.bzh> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211027073020.17055-1-julien.massot@iot.bzh> References: <20211027073020.17055-1-julien.massot@iot.bzh> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org Renesas R-Car SoCs may contains a Realtime processor. This patch adds binding for this remote processor. Signed-off-by: Julien Massot --- .../remoteproc/renesas,rcar-rproc.yaml | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 Documentation/devicetree/bindings/remoteproc/renesas,rcar-rproc.yaml diff --git a/Documentation/devicetree/bindings/remoteproc/renesas,rcar-rproc.yaml b/Documentation/devicetree/bindings/remoteproc/renesas,rcar-rproc.yaml new file mode 100644 index 000000000000..dbf95137ce88 --- /dev/null +++ b/Documentation/devicetree/bindings/remoteproc/renesas,rcar-rproc.yaml @@ -0,0 +1,66 @@ +# SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/remoteproc/renesas,rcar-rproc.yaml#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" + +title: Renesas R-Car remote processor controller bindings + +maintainers: + - Julien Massot + +description: | + This document defines the binding for the remoteproc component that loads and + boots firmwares on the Renesas R-Car family chipset. + R-Car gen3 family may have a realtime processor, this processor share peripheral + and RAM with the host processor with the same address map. + + +properties: + compatible: + const: renesas,rcar-cr7 + + resets: + maxItems: 1 + + power-domains: + maxItems: 1 + + memory-region: + description: + List of phandles to the reserved memory regions associated with the + remoteproc device. This is variable and describes the memories shared with + the remote processor (e.g. remoteproc firmware and carveouts, rpmsg + vrings, ...). + (see ../reserved-memory/reserved-memory.txt) + +required: + - compatible + - resets + - memory-region + - power-domains + +additionalProperties: false + +examples: + - | + #include + #include + reserved-memory { + ranges; + + cr7_ram: cr7_ram@40040000 { + no-map; + reg = <0x40040000 0x1fc0000>; + }; + }; + + cr7_rproc: cr7 { + compatible = "renesas,rcar-cr7"; + memory-region = <&cr7_ram>; + power-domains = <&sysc R8A7795_PD_CR7>; + resets = <&cpg 222>; + status = "okay"; + }; + +... From patchwork Wed Oct 27 07:30:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Massot X-Patchwork-Id: 12586509 X-Patchwork-Delegate: geert@linux-m68k.org 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A3DD6C433EF for ; Wed, 27 Oct 2021 07:30:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8696260E8C for ; Wed, 27 Oct 2021 07:30:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238468AbhJ0HdC (ORCPT ); Wed, 27 Oct 2021 03:33:02 -0400 Received: from mail.iot.bzh ([51.75.236.24]:20838 "EHLO frontal.iot.bzh" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237061AbhJ0HdC (ORCPT ); Wed, 27 Oct 2021 03:33:02 -0400 Received: from frontal.iot.bzh (localhost [127.0.0.1]) by frontal.iot.bzh (Proxmox) with ESMTP id 250DE24FE1; Wed, 27 Oct 2021 09:30:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iot.bzh; h=cc:cc :content-transfer-encoding:date:from:from:in-reply-to:message-id :mime-version:references:reply-to:subject:subject:to:to; s= iot.bzh; bh=i6U/AV191o/UNrCkLrmv+5mGLLuxNwffMSa6Ec7U2cA=; b=ampq dCm6aYjP7iuIzz2eTt3pdSAldgTRGs63jZpN7PFjVdG/dlUAmjJDGVE/UTDDaLMh zHxwNDJpUmeO9JOAJsXd9OdLFkxjShURtRwQrmn5iwo/xo0235ICSUcXNWjBCTWw 0rsYh/RnTGtwE1yJMyicEAxlrrEE+3WDWGLJelPs+LmVzs61ynu328sePxlCcznx 8cvr+OHUlxy+RNc0FFM+zyYHRkOmp7tIzix+k+Mli5dx3RCFD4HU6RBNh7vvwvoB z45+e969HUxa4Y8eBESm85zY85uwHxwS8t1WI/u0X5LCU84+rbjg1DSak9xjs5IL YA5+1D2F9V9cSz19Aw== From: Julien Massot To: bjorn.andersson@linaro.org, mathieu.poirier@linaro.org, robh+dt@kernel.org, geert+renesas@glider.be Cc: linux-renesas-soc@vger.kernel.org, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, Julien Massot Subject: [RFC PATCH 2/3] arm64: dts: renesas: r8a77951: Add CR7 realtime processor Date: Wed, 27 Oct 2021 09:30:19 +0200 Message-Id: <20211027073020.17055-3-julien.massot@iot.bzh> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211027073020.17055-1-julien.massot@iot.bzh> References: <20211027073020.17055-1-julien.massot@iot.bzh> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org r8a77951 as some other members of rcar gen3 soc series has a Cortex R7 processor. This processor shares the same mapped devices and memory mapping. Choose 0x40040000 area to store the Cortex-R7 firmware. Signed-off-by: Julien Massot --- arch/arm64/boot/dts/renesas/r8a77951-ulcb.dts | 16 ++++++++++++++++ arch/arm64/boot/dts/renesas/r8a77951.dtsi | 7 +++++++ 2 files changed, 23 insertions(+) diff --git a/arch/arm64/boot/dts/renesas/r8a77951-ulcb.dts b/arch/arm64/boot/dts/renesas/r8a77951-ulcb.dts index 06d4e948eb0f..26ab7e3cca18 100644 --- a/arch/arm64/boot/dts/renesas/r8a77951-ulcb.dts +++ b/arch/arm64/boot/dts/renesas/r8a77951-ulcb.dts @@ -34,6 +34,17 @@ memory@700000000 { device_type = "memory"; reg = <0x7 0x00000000 0x0 0x40000000>; }; + + reserved-memory { + #address-cells = <2>; + #size-cells = <2>; + ranges; + + cr7_ram: cr7_ram@40040000 { + no-map; + reg = <0x0 0x40040000 0x0 0x1fc0000>; + }; + }; }; &du { @@ -48,3 +59,8 @@ &du { clock-names = "du.0", "du.1", "du.2", "du.3", "dclkin.0", "dclkin.1", "dclkin.2", "dclkin.3"; }; + +&cr7_rproc { + memory-region = <&cr7_ram>; + status = "okay"; +}; diff --git a/arch/arm64/boot/dts/renesas/r8a77951.dtsi b/arch/arm64/boot/dts/renesas/r8a77951.dtsi index 1768a3e6bb8d..3ee247fc5aec 100644 --- a/arch/arm64/boot/dts/renesas/r8a77951.dtsi +++ b/arch/arm64/boot/dts/renesas/r8a77951.dtsi @@ -366,6 +366,13 @@ soc: soc { #size-cells = <2>; ranges; + cr7_rproc: cr7 { + compatible = "renesas,rcar-cr7"; + power-domains = <&sysc R8A7795_PD_CR7>; + resets = <&cpg 222>; + status = "disabled"; + }; + rwdt: watchdog@e6020000 { compatible = "renesas,r8a7795-wdt", "renesas,rcar-gen3-wdt"; reg = <0 0xe6020000 0 0x0c>; From patchwork Wed Oct 27 07:30:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julien Massot X-Patchwork-Id: 12586515 X-Patchwork-Delegate: geert@linux-m68k.org 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 18A6FC4332F for ; Wed, 27 Oct 2021 07:30:39 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F210860F9B for ; Wed, 27 Oct 2021 07:30:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231849AbhJ0HdD (ORCPT ); Wed, 27 Oct 2021 03:33:03 -0400 Received: from mail.iot.bzh ([51.75.236.24]:60850 "EHLO frontal.iot.bzh" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238603AbhJ0HdC (ORCPT ); Wed, 27 Oct 2021 03:33:02 -0400 Received: from frontal.iot.bzh (localhost [127.0.0.1]) by frontal.iot.bzh (Proxmox) with ESMTP id 1578024FE2; Wed, 27 Oct 2021 09:30:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iot.bzh; h=cc:cc :content-transfer-encoding:date:from:from:in-reply-to:message-id :mime-version:references:reply-to:subject:subject:to:to; s= iot.bzh; bh=PlkzwFHKIv+W5SPs+eRyf708VL+0d3D4aAucVWYgkQE=; b=AJ/I ZsyiirRm+/Ov1FYhoT5CWAuhScuPzNP10oMwpdurUY5QkTSQA5bpEDmC/eMeZVS8 Hxc4WhxPKXBTJUJF/Sl12bPUgicpJ3jr34W0nqxrGn5huAdXtJ/NnRHXZJuHZLYM B9ev6A0RR8l3FszR6cPPQg8y34Rv8SNaX+4/Ps7fLvNZQHoqHtOetBzuwKc1XXjM 2H32iQw5hpK78Gn021YKruz+50MIr5s2vWR0qNgQaIFM8oXb91FrRNKaehHFeW+B 5kloo1r/mxHB+yxhEOeHotzq6SCmLLKiJb8efoI6Z8vMCDmpBX9UrV2pvitozTtt mjDEndcHN2YkFeyaAw== From: Julien Massot To: bjorn.andersson@linaro.org, mathieu.poirier@linaro.org, robh+dt@kernel.org, geert+renesas@glider.be Cc: linux-renesas-soc@vger.kernel.org, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, Julien Massot Subject: [RFC PATCH 3/3] remoteproc: Add Renesas rcar driver Date: Wed, 27 Oct 2021 09:30:20 +0200 Message-Id: <20211027073020.17055-4-julien.massot@iot.bzh> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20211027073020.17055-1-julien.massot@iot.bzh> References: <20211027073020.17055-1-julien.massot@iot.bzh> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-renesas-soc@vger.kernel.org Renesas Gen3 platform includes a Cortex-r7 processor. Both: the application cores (A5x) and the realtime core (CR7) share access to the RAM and devices with the same address map, so device addresses are equal to the Linux physical addresses. In order to initialize this remote processor we need to: - power on the realtime core - put the firmware in a ram area - set the boot address for this firmware (reset vector) - Deassert the reset This initial driver allows to start and stop the Cortex R7 processor. Signed-off-by: Julien Massot --- drivers/remoteproc/Kconfig | 11 ++ drivers/remoteproc/Makefile | 1 + drivers/remoteproc/rcar_rproc.c | 229 ++++++++++++++++++++++++++++++++ 3 files changed, 241 insertions(+) create mode 100644 drivers/remoteproc/rcar_rproc.c diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig index 9a6eedc3994a..3e87eadbaf59 100644 --- a/drivers/remoteproc/Kconfig +++ b/drivers/remoteproc/Kconfig @@ -261,6 +261,17 @@ config QCOM_WCNSS_PIL verified and booted with the help of the Peripheral Authentication System (PAS) in TrustZone. +config RCAR_REMOTEPROC + tristate "Renesas RCAR remoteproc support" + depends on ARCH_RENESAS + depends on REMOTEPROC + help + Say y here to support R-Car realtime processor via the + remote processor framework. An elf firmware can be loaded + thanks to sysfs remoteproc entries. The remote processor + can be started and stopped. + This can be either built-in or a loadable module. + config ST_REMOTEPROC tristate "ST remoteproc support" depends on ARCH_STI diff --git a/drivers/remoteproc/Makefile b/drivers/remoteproc/Makefile index bb26c9e4ef9c..bb290cc08e99 100644 --- a/drivers/remoteproc/Makefile +++ b/drivers/remoteproc/Makefile @@ -30,6 +30,7 @@ obj-$(CONFIG_QCOM_SYSMON) += qcom_sysmon.o obj-$(CONFIG_QCOM_WCNSS_PIL) += qcom_wcnss_pil.o qcom_wcnss_pil-y += qcom_wcnss.o qcom_wcnss_pil-y += qcom_wcnss_iris.o +obj-$(CONFIG_RCAR_REMOTEPROC) += rcar_rproc.o obj-$(CONFIG_ST_REMOTEPROC) += st_remoteproc.o obj-$(CONFIG_ST_SLIM_REMOTEPROC) += st_slim_rproc.o obj-$(CONFIG_STM32_RPROC) += stm32_rproc.o diff --git a/drivers/remoteproc/rcar_rproc.c b/drivers/remoteproc/rcar_rproc.c new file mode 100644 index 000000000000..ae0bfc8d4e85 --- /dev/null +++ b/drivers/remoteproc/rcar_rproc.c @@ -0,0 +1,229 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (C) IoT.bzh 2021 + */ + +#include +#include +#include +#include +#include +#include +#include + +#include "remoteproc_internal.h" + +struct rcar_rproc { + struct device *dev; + struct rproc *rproc; + struct reset_control *rst; +}; + +static int rcar_rproc_mem_alloc(struct rproc *rproc, + struct rproc_mem_entry *mem) +{ + struct device *dev = rproc->dev.parent; + void *va; + + dev_dbg(dev, "map memory: %p+%zx\n", &mem->dma, mem->len); + va = ioremap_wc(mem->dma, mem->len); + if (IS_ERR_OR_NULL(va)) { + dev_err(dev, "Unable to map memory region: %pa+%lx\n", + &mem->dma, mem->len); + return -ENOMEM; + } + + /* Update memory entry va */ + mem->va = va; + + return 0; +} + +static int rcar_rproc_mem_release(struct rproc *rproc, + struct rproc_mem_entry *mem) +{ + dev_dbg(rproc->dev.parent, "unmap memory: %pa\n", &mem->dma); + iounmap(mem->va); + + return 0; +} + +static int rcar_rproc_prepare(struct rproc *rproc) +{ + struct device *dev = rproc->dev.parent; + struct device_node *np = dev->of_node; + struct of_phandle_iterator it; + struct rproc_mem_entry *mem; + struct reserved_mem *rmem; + u64 da; + + /* Register associated reserved memory regions */ + of_phandle_iterator_init(&it, np, "memory-region", NULL, 0); + while (of_phandle_iterator_next(&it) == 0) { + + rmem = of_reserved_mem_lookup(it.node); + if (!rmem) { + dev_err(dev, "unable to acquire memory-region\n"); + return -EINVAL; + } + + /* No need to translate pa to da, R-Car use same map */ + da = rmem->base; + + mem = rproc_mem_entry_init(dev, NULL, + (dma_addr_t)rmem->base, + rmem->size, da, + rcar_rproc_mem_alloc, + rcar_rproc_mem_release, + it.node->name); + + if (!mem) + return -ENOMEM; + + rproc_add_carveout(rproc, mem); + } + + return 0; +} + +static int rcar_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw) +{ + int ret; + + ret = rproc_elf_load_rsc_table(rproc, fw); + if (ret) + dev_info(&rproc->dev, "No resource table in elf\n"); + + return 0; +} + +static int rcar_rproc_start(struct rproc *rproc) +{ + struct rcar_rproc *priv = rproc->priv; + int err; + + if (!rproc->bootaddr) + return -EINVAL; + + err = rcar_rst_set_rproc_boot_addr(rproc->bootaddr); + if (err) { + dev_err(&rproc->dev, "failed to set rproc boot addr\n"); + return err; + } + + err = reset_control_deassert(priv->rst); + if (err) + dev_err(&rproc->dev, "failed to deassert reset\n"); + + return err; +} + +static int rcar_rproc_stop(struct rproc *rproc) +{ + struct rcar_rproc *priv = rproc->priv; + int err; + + err = reset_control_assert(priv->rst); + if (err) + dev_err(&rproc->dev, "failed to assert reset\n"); + + return err; +} + +static struct rproc_ops rcar_rproc_ops = { + .prepare = rcar_rproc_prepare, + .start = rcar_rproc_start, + .stop = rcar_rproc_stop, + .load = rproc_elf_load_segments, + .parse_fw = rcar_rproc_parse_fw, + .find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table, + .sanity_check = rproc_elf_sanity_check, + .get_boot_addr = rproc_elf_get_boot_addr, + +}; + +static int rcar_rproc_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct device_node *np = dev->of_node; + struct rcar_rproc *priv; + struct rproc *rproc; + int ret; + + rproc = rproc_alloc(dev, np->name, &rcar_rproc_ops, + NULL, sizeof(*priv)); + if (!rproc) + return -ENOMEM; + + priv = rproc->priv; + priv->rproc = rproc; + priv->dev = dev; + + priv->rst = devm_reset_control_get_exclusive(&pdev->dev, NULL); + if (IS_ERR(priv->rst)) { + ret = PTR_ERR(priv->rst); + dev_err(dev, "fail to acquire rproc reset\n"); + goto free_rproc; + } + + pm_runtime_enable(priv->dev); + ret = pm_runtime_get_sync(priv->dev); + if (ret) { + dev_err(&rproc->dev, "failed to power up\n"); + goto free_rproc; + } + + dev_set_drvdata(dev, rproc); + + /* Manually start the rproc */ + rproc->auto_boot = false; + + ret = rproc_add(rproc); + if (ret) { + dev_err(dev, "rproc_add failed\n"); + goto pm_disable; + } + + return 0; + +pm_disable: + pm_runtime_disable(priv->dev); +free_rproc: + rproc_free(rproc); + + return ret; +} + +static int rcar_rproc_remove(struct platform_device *pdev) +{ + struct rproc *rproc = platform_get_drvdata(pdev); + struct rcar_rproc *priv = rproc->priv; + + rproc_del(rproc); + pm_runtime_disable(priv->dev); + rproc_free(rproc); + + return 0; +} + +static const struct of_device_id rcar_rproc_of_match[] = { + { .compatible = "renesas,rcar-cr7" }, + {}, +}; + +MODULE_DEVICE_TABLE(of, rcar_rproc_of_match); + +static struct platform_driver rcar_rproc_driver = { + .probe = rcar_rproc_probe, + .remove = rcar_rproc_remove, + .driver = { + .name = "rcar-rproc", + .of_match_table = rcar_rproc_of_match, + }, +}; + +module_platform_driver(rcar_rproc_driver); + +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("Renesas Gen3 R-Car remote processor control driver"); +MODULE_AUTHOR("Julien Massot ");