From: Mathieu Poirier <mathieu.poirier@linaro.org>
To: Julien Massot <julien.massot@iot.bzh>
Cc: bjorn.andersson@linaro.org, robh+dt@kernel.org,
geert+renesas@glider.be, linux-renesas-soc@vger.kernel.org,
linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org
Subject: Re: [PATCH v1 3/3] remoteproc: Add Renesas rcar driver
Date: Mon, 22 Nov 2021 11:37:58 -0700 [thread overview]
Message-ID: <20211122183758.GC2686563@p14s> (raw)
In-Reply-To: <20211115135032.129227-4-julien.massot@iot.bzh>
Hi,
On Mon, Nov 15, 2021 at 02:50:32PM +0100, Julien Massot wrote:
> 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 <julien.massot@iot.bzh>
> ---
>
> Change since RFC:
> - Improve Kconfig description.
> - Use consistent device for pr_* messages.
> - Drop unused dev and rproc member of struct rcar_rproc.
>
> ---
> drivers/remoteproc/Kconfig | 12 ++
> drivers/remoteproc/Makefile | 1 +
> drivers/remoteproc/rcar_rproc.c | 226 ++++++++++++++++++++++++++++++++
> 3 files changed, 239 insertions(+)
> create mode 100644 drivers/remoteproc/rcar_rproc.c
>
> diff --git a/drivers/remoteproc/Kconfig b/drivers/remoteproc/Kconfig
> index 9a6eedc3994a..5b0c617d45f6 100644
> --- a/drivers/remoteproc/Kconfig
> +++ b/drivers/remoteproc/Kconfig
> @@ -261,6 +261,18 @@ config QCOM_WCNSS_PIL
> verified and booted with the help of the Peripheral Authentication
> System (PAS) in TrustZone.
>
> +config RCAR_REMOTEPROC
> + tristate "Renesas R-CAR Gen3 remoteproc support"
> + depends on ARCH_RENESAS
> + depends on REMOTEPROC
You should be able to remove the dependency on REMOTEPROC since this is already in
the "if REMOTEPROC" block.
> + 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.
> + If compiled as module (M), the module name is rcar_rproc.
> +
> 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..795089dc4337
> --- /dev/null
> +++ b/drivers/remoteproc/rcar_rproc.c
> @@ -0,0 +1,226 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (C) IoT.bzh 2021
> + */
> +
> +#include <linux/module.h>
> +#include <linux/of_device.h>
> +#include <linux/of_reserved_mem.h>
> +#include <linux/pm_runtime.h>
> +#include <linux/remoteproc.h>
> +#include <linux/reset.h>
> +#include <linux/soc/renesas/rcar-rst.h>
> +
> +#include "remoteproc_internal.h"
> +
> +struct rcar_rproc {
> + struct reset_control *rst;
> +};
> +
> +static int rcar_rproc_mem_alloc(struct rproc *rproc,
> + struct rproc_mem_entry *mem)
> +{
> + struct device *dev = &rproc->dev;
> + void *va;
> +
> + dev_dbg(dev, "map memory: %pa+%lx\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",
The sparse checker doesn't like %lx so probably be better to go with just %x.
Apologies for suggesting to use %lx.
> + &mem->dma, mem->len);
> + return -ENOMEM;
> + }
> +
> + /* Update memory entry va */
> + mem->va = va;
Talking about the sparse checker, you will see complaints about @va not being of
type "void __iomem *". You can ignore those as this would likely require to
refactor the rproc_mem_entry structure, which is outside the scope of this work.
> +
> + return 0;
> +}
> +
> +static int rcar_rproc_mem_release(struct rproc *rproc,
> + struct rproc_mem_entry *mem)
> +{
> + dev_dbg(&rproc->dev, "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(&rproc->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->rst = devm_reset_control_get_exclusive(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(dev);
> + ret = pm_runtime_get_sync(dev);
> + if (ret) {
> + dev_err(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(dev);
> +free_rproc:
> + rproc_free(rproc);
> +
> + return ret;
> +}
> +
> +static int rcar_rproc_remove(struct platform_device *pdev)
> +{
> + struct device *dev = &pdev->dev;
> + struct rproc *rproc = platform_get_drvdata(pdev);
> +
> + rproc_del(rproc);
> + pm_runtime_disable(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,
> + },
> +};
This set is just as clean as the RFC. If it wasn't for the DTS bindings that
need to be ack'ed by Rob, I probably would have made the above modifications and
applied this patch.
Thanks,
Mathieu
> +
> +module_platform_driver(rcar_rproc_driver);
> +
> +MODULE_LICENSE("GPL v2");
> +MODULE_DESCRIPTION("Renesas Gen3 R-Car remote processor control driver");
> +MODULE_AUTHOR("Julien Massot <julien.massot@iot.bzh>");
> --
> 2.31.1
>
>
next prev parent reply other threads:[~2021-11-22 18:38 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-15 13:50 [PATCH v1 0/3] Initial Renesas R-Car remoteproc support Julien Massot
2021-11-15 13:50 ` [PATCH v1 1/3] dt-bindings: remoteproc: Add Renesas R-Car Julien Massot
2021-11-29 22:01 ` Rob Herring
2021-11-30 8:51 ` Julien Massot
2021-11-15 13:50 ` [PATCH v1 2/3] arm64: dts: renesas: r8a77951: Add CR7 realtime processor Julien Massot
2022-01-10 13:00 ` Geert Uytterhoeven
2021-11-15 13:50 ` [PATCH v1 3/3] remoteproc: Add Renesas rcar driver Julien Massot
2021-11-15 14:12 ` Biju Das
2021-11-15 14:41 ` Julien Massot
2021-11-15 15:17 ` Biju Das
2021-11-22 18:37 ` Mathieu Poirier [this message]
2021-11-24 11:07 ` Julien Massot
2021-11-24 17:35 ` Mathieu Poirier
2021-11-15 18:10 ` [PATCH v1 0/3] Initial Renesas R-Car remoteproc support Mathieu Poirier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211122183758.GC2686563@p14s \
--to=mathieu.poirier@linaro.org \
--cc=bjorn.andersson@linaro.org \
--cc=devicetree@vger.kernel.org \
--cc=geert+renesas@glider.be \
--cc=julien.massot@iot.bzh \
--cc=linux-remoteproc@vger.kernel.org \
--cc=linux-renesas-soc@vger.kernel.org \
--cc=robh+dt@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).