From: Mathieu Poirier <mathieu.poirier@linaro.org>
To: Francesco Valla <francesco@valla.it>
Cc: Bjorn Andersson <andersson@kernel.org>,
Kees Cook <kees@kernel.org>,
"Gustavo A. R. Silva" <gustavoars@kernel.org>,
Rob Herring <robh@kernel.org>,
Krzysztof Kozlowski <krzk+dt@kernel.org>,
Conor Dooley <conor+dt@kernel.org>,
Jonathan Corbet <corbet@lwn.net>,
Shuah Khan <skhan@linuxfoundation.org>,
Randy Dunlap <rdunlap@infradead.org>, Frank Li <Frank.Li@nxp.com>,
Sascha Hauer <s.hauer@pengutronix.de>,
Pengutronix Kernel Team <kernel@pengutronix.de>,
Fabio Estevam <festevam@gmail.com>, Peng Fan <peng.fan@nxp.com>,
Robin Murphy <robin.murphy@arm.com>,
linux-remoteproc@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-hardening@vger.kernel.org, devicetree@vger.kernel.org,
linux-doc@vger.kernel.org, imx@lists.linux.dev,
linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH RFC v2 07/11] remoteproc: assign fwnode during vdev registration
Date: Tue, 17 Nov 2026 10:28:38 -0600 [thread overview]
Message-ID: <avyAtmxdbfEBbZ87@p14s> (raw)
In-Reply-To: <20261102-remoteproc_virtio_map-v2-7-26b300e01c62@valla.it>
On Mon, Nov 02, 2026 at 12:26:44AM +0100, Francesco Valla wrote:
> The virtio subsystem already supports a fwnode describing a vdev; search
> for a specific node during vdev registration and supply it to the
> rproc-virtio platform device that is being registered.
>
> A memory-region specified inside that node is also used for the virtio
> device if a carveout was not supplied for it through the parent device's
> node.
>
> Signed-off-by: Francesco Valla <francesco@valla.it>
> ---
> drivers/remoteproc/remoteproc_core.c | 48 +++++++++++++++++++++++++++++++---
> drivers/remoteproc/remoteproc_virtio.c | 41 +++++++++++++++++++++++++++++
> 2 files changed, 85 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
> index c946ecd980a5..e833853ae7f6 100644
> --- a/drivers/remoteproc/remoteproc_core.c
> +++ b/drivers/remoteproc/remoteproc_core.c
> @@ -440,6 +440,33 @@ void rproc_remove_rvdev(struct rproc_vdev *rvdev)
> if (rvdev)
> list_del(&rvdev->node);
> }
> +
> +static struct fwnode_handle *rproc_get_vdev_fwnode(struct device *dev, u32 idx)
> +{
> + struct fwnode_handle *group, *child;
> + u32 reg;
> + int ret;
> +
> + group = device_get_named_child_node(dev, "virtio");
> + if (!fwnode_device_is_available(group)) {
> + fwnode_handle_put(group);
> + return NULL;
> + }
> +
> + fwnode_for_each_available_child_node(group, child) {
> + ret = fwnode_property_read_u32(child, "reg", ®);
> + if (ret)
> + continue;
> +
> + if (idx == reg)
> + break;
> + }
> +
> + fwnode_handle_put(group);
> +
> + return child;
> +}
> +
> /**
> * rproc_handle_vdev() - handle a vdev fw resource
> * @rproc: the remote processor
> @@ -475,7 +502,16 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr,
> struct device *dev = &rproc->dev;
> size_t rsc_size;
> struct rproc_vdev_data rvdev_data;
> + struct platform_device_info pdev_info = {
> + .parent = dev,
> + .name = "rproc-virtio",
> + .id = PLATFORM_DEVID_AUTO,
> + .data = &rvdev_data,
> + .size_data = sizeof(rvdev_data),
> + };
> struct platform_device *pdev;
> + struct fwnode_handle *fwnode;
> + int ret = 0;
>
> /* make sure resource isn't truncated */
> rsc_size = struct_size(rsc, vring, rsc->num_of_vrings);
> @@ -498,20 +534,24 @@ static int rproc_handle_vdev(struct rproc *rproc, void *ptr,
> rvdev_data.rsc_offset = offset;
> rvdev_data.rsc = rsc;
>
> + fwnode = rproc_get_vdev_fwnode(dev->parent, rvdev_data.index);
> + pdev_info.fwnode = fwnode;
> +
> /*
> * When there is more than one remote processor, rproc->nb_vdev number is
> * same for each separate instances of "rproc". If rvdev_data.index is used
> * as device id, then we get duplication in sysfs, so need to use
> * PLATFORM_DEVID_AUTO to auto select device id.
> */
> - pdev = platform_device_register_data(dev, "rproc-virtio", PLATFORM_DEVID_AUTO, &rvdev_data,
> - sizeof(rvdev_data));
> + pdev = platform_device_register_full(&pdev_info);
> if (IS_ERR(pdev)) {
> dev_err(dev, "failed to create rproc-virtio device\n");
> - return PTR_ERR(pdev);
> + ret = PTR_ERR(pdev);
> }
>
> - return 0;
> + fwnode_handle_put(fwnode);
> +
> + return ret;
> }
>
> /**
> diff --git a/drivers/remoteproc/remoteproc_virtio.c b/drivers/remoteproc/remoteproc_virtio.c
> index 1496659ddff9..950d65480be5 100644
> --- a/drivers/remoteproc/remoteproc_virtio.c
> +++ b/drivers/remoteproc/remoteproc_virtio.c
> @@ -13,10 +13,12 @@
> #include <linux/dma-map-ops.h>
> #include <linux/dma-mapping.h>
> #include <linux/export.h>
> +#include <linux/of.h>
> #include <linux/of_reserved_mem.h>
> #include <linux/platform_device.h>
> #include <linux/remoteproc.h>
> #include <linux/rsc_table.h>
> +#include <linux/swiotlb.h>
> #include <linux/virtio.h>
> #include <linux/virtio_config.h>
> #include <linux/virtio_ids.h>
> @@ -394,6 +396,23 @@ static void rproc_virtio_dev_release(struct device *dev)
> put_device(&rvdev->pdev->dev);
> }
>
> +/*
> + * Attach the memory region declared inside the vdev's own devicetree node.
> + *
> + * A restricted-dma-pool region is attached by of_dma_configure() when the
> + * platform device is probed, but it is released together with the virtio
> + * device (see rproc_virtio_dev_release()); attach it again if needed, e.g.
> + * when the remote processor is restarted during a crash recovery.
> + * Any other kind of region (e.g., shared-dma-pool) is attached only here.
> + */
> +static int rproc_virtio_init_vdev_mem(struct device *dev)
> +{
> + if (is_swiotlb_for_alloc(dev))
> + return 0;
> +
> + return of_reserved_mem_device_init_by_idx(dev, dev->of_node, 0);
> +}
> +
> /**
> * rproc_add_virtio_dev() - register an rproc-induced virtio device
> * @rvdev: the remote vdev
> @@ -410,6 +429,7 @@ static int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id)
> struct device *dev = &rvdev->pdev->dev;
> struct virtio_device *vdev;
> struct rproc_mem_entry *mem;
> + bool has_mem_region;
> int ret;
>
> if (rproc->ops->kick == NULL) {
> @@ -417,11 +437,24 @@ static int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id)
> return -EINVAL;
> }
>
> + has_mem_region = of_property_present(dev->of_node, "memory-region");
> +
> /* Try to find dedicated vdev buffer carveout */
> mem = rproc_find_carveout_by_name(rproc, "vdev%dbuffer", rvdev->index);
> if (mem) {
> phys_addr_t pa;
>
> + if (has_mem_region) {
> + /*
> + * The carveout takes precedence: drop the region that
> + * of_dma_configure() might have attached at probe time.
I don't understand this part - why would someone configure vdevXbuffer with the
same name at the rproc and rproc-virtio level? This should be an error.
> + */
> + dev_warn(dev,
> + "vdev%dbuffer carveout found, ignoring memory-region\n",
> + rvdev->index);
> + of_reserved_mem_device_release(dev);
Who would have called of_reserved_mem_device_init_by_XYZ()? The remoteproc core
or virtio core?
> + }
> +
> if (mem->of_resm_idx != -1) {
> struct device_node *np = rproc->dev.parent->of_node;
>
> @@ -451,6 +484,14 @@ static int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id)
> return ret;
> }
> }
> + } else if (has_mem_region) {
> + /* Use the memory region declared in the vdev's own node */
> + ret = rproc_virtio_init_vdev_mem(dev);
> + if (ret) {
> + dev_err(dev, "Can't associate vdev memory-region: %d\n",
> + ret);
> + return ret;
> + }
Mixing the initialisation of the legacy rproc-virtio and authentic rproc-virtio
devices is very confusing. I think there is value in splitting them, even if it
entails some code duplication.
Thanks,
Mathieu
> } else {
> struct device_node *np = rproc->dev.parent->of_node;
>
>
> --
> 2.56.0
>
next prev parent reply other threads:[~2026-11-17 16:28 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-01 23:26 [PATCH RFC v2 00/11] remoteproc: add support for any virtio device Francesco Valla
2026-11-01 23:26 ` [PATCH RFC v2 01/11] remoteproc: virtio: cleanup rproc_add_virtio_dev error path Francesco Valla
2026-11-01 23:26 ` [PATCH RFC v2 02/11] remoteproc: virtio: replace commas with semicolons Francesco Valla
2026-11-01 23:26 ` [PATCH RFC v2 03/11] remoteproc: virtio: support dynamic number of vrings Francesco Valla
2026-11-01 23:26 ` [PATCH RFC v2 04/11] remoteproc: report VIRTIO_F_VERSION_1 for non-rproc-specific vdevs Francesco Valla
2026-11-10 15:46 ` Mathieu Poirier
2026-11-10 16:58 ` Francesco Valla
2026-11-01 23:26 ` [PATCH RFC v2 05/11] remoteproc: virtio: report VIRTIO_F_ACCESS_PLATFORM when required Francesco Valla
2026-11-16 17:16 ` Mathieu Poirier
2026-11-01 23:26 ` [PATCH RFC v2 06/11] dt-bindings: remoteproc: add remoteproc-virtio Francesco Valla
2026-11-01 23:26 ` [PATCH RFC v2 07/11] remoteproc: assign fwnode during vdev registration Francesco Valla
2026-11-02 0:02 ` sashiko-bot
2026-11-17 16:28 ` Mathieu Poirier [this message]
2026-11-01 23:26 ` [PATCH RFC v2 08/11] Documentation: remoteproc: expand virtio support section Francesco Valla
2026-11-01 23:26 ` [PATCH RFC v2 09/11] remoteproc: imx_rproc: always use non-blocking mailboxes Francesco Valla
2026-11-02 0:03 ` sashiko-bot
2026-11-01 23:26 ` [PATCH RFC v2 10/11] dt-bindings: remoteproc: imx-rproc: support virtio Francesco Valla
2026-11-01 23:26 ` [PATCH RFC v2 11/11] PoC: arm64: dts: imx93-11x11-frdm: add multiple vdevs Francesco Valla
2026-11-02 0:16 ` sashiko-bot
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=avyAtmxdbfEBbZ87@p14s \
--to=mathieu.poirier@linaro.org \
--cc=Frank.Li@nxp.com \
--cc=andersson@kernel.org \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=festevam@gmail.com \
--cc=francesco@valla.it \
--cc=gustavoars@kernel.org \
--cc=imx@lists.linux.dev \
--cc=kees@kernel.org \
--cc=kernel@pengutronix.de \
--cc=krzk+dt@kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-hardening@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-remoteproc@vger.kernel.org \
--cc=peng.fan@nxp.com \
--cc=rdunlap@infradead.org \
--cc=robh@kernel.org \
--cc=robin.murphy@arm.com \
--cc=s.hauer@pengutronix.de \
--cc=skhan@linuxfoundation.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