All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] remoteproc: core: support fixed device index from DT aliases
@ 2026-01-27 13:05 Arnaud Pouliquen
  2026-01-27 17:13 ` Mathieu Poirier
  0 siblings, 1 reply; 3+ messages in thread
From: Arnaud Pouliquen @ 2026-01-27 13:05 UTC (permalink / raw)
  To: Bjorn Andersson, Mathieu Poirier
  Cc: linux-remoteproc, linux-kernel, linux-stm32, arnaud.pouliquen

On systems with multiple remote processors, the remoteproc device
enumeration is not stable as it depends on the probe ordering.
As a result, the /sys/class/remoteproc/remoteproc<x> entries do not
always refer to the same remote processor instance, which complicates
userspace applications.

Inspired by the SPI implementation, this commit allows board-specific
numbering to be defined in device tree while still supporting dynamically
registered remote processors.

For instance, on STM32MP25 Soc this can be used by defining:

    aliases {
        remoteproc0 = &m33_rproc;
        remoteproc1 = &m0_rproc;
    };

When a "remoteproc<x>" DT alias is present, use it to assign a fixed
"/sys/class/remoteproc/remoteproc<x>" entry.
If no remoteproc alias is defined, keep the legacy index allocation.
If only some remoteproc instances have an alias, allocate dynamic
index starting after the highest alias index declared.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
---
Notes:

- This patch is submitted as an RFC in this first version.
  The main reason is that support for the Cortex-M33 and Cortex-M0 on
  the STM32MP25 SoC is not yet upstream. The primary objective is to
  trigger discussion on the concept; if there is agreement, I can drop
  the RFC tag in a next version.

- The keystone_remoteproc driver also uses DT aliases. As it uses the
  "rproc" alias only to construct the firmware name, it should remain
  compatible with this change.
---
 drivers/remoteproc/remoteproc_core.c | 25 +++++++++++++++++++++++--
 1 file changed, 23 insertions(+), 2 deletions(-)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index aada2780b343..8da6c410870a 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -2461,6 +2461,8 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
 			  const char *firmware, int len)
 {
 	struct rproc *rproc;
+	int index = -ENODEV;
+	int first_dynamic;
 
 	if (!dev || !name || !ops)
 		return NULL;
@@ -2481,8 +2483,27 @@ struct rproc *rproc_alloc(struct device *dev, const char *name,
 	rproc->dev.driver_data = rproc;
 	idr_init(&rproc->notifyids);
 
-	/* Assign a unique device index and name */
-	rproc->index = ida_alloc(&rproc_dev_index, GFP_KERNEL);
+	/*
+	 * Assign a unique device index and name
+	 * Look for a static index coming from the "remoteproc" DT alias
+	 * (e.g. "remoteproc0"). If none is found, start allocating
+	 * dynamic IDs after the highest alias in use.
+	 */
+	if (dev->of_node)
+		index = of_alias_get_id(dev->of_node, "remoteproc");
+	if (index < 0) {
+		first_dynamic = of_alias_get_highest_id("remoteproc");
+		if (first_dynamic < 0)
+			first_dynamic = 0;
+		else
+			first_dynamic++;
+		rproc->index = ida_alloc_range(&rproc_dev_index, first_dynamic,
+					       ~0, GFP_KERNEL);
+	} else {
+		rproc->index = ida_alloc_range(&rproc_dev_index, index,
+					       index, GFP_KERNEL);
+	}
+
 	if (rproc->index < 0) {
 		dev_err(dev, "ida_alloc failed: %d\n", rproc->index);
 		goto put_device;

base-commit: 63804fed149a6750ffd28610c5c1c98cce6bd377
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-01-27 17:48 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-27 13:05 [RFC PATCH] remoteproc: core: support fixed device index from DT aliases Arnaud Pouliquen
2026-01-27 17:13 ` Mathieu Poirier
2026-01-27 17:48   ` Arnaud POULIQUEN

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.