Skip to contentSkip to conversation

remoteproc: uclass: Modify uc_pdata->name to use combination of device name and device's parent name

PATCH Superseded MD Danish Anwar 2 participants 3 messages Jul 19, 2024 – Aug 7, 2024 Remote processor (remoteproc)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 remoteproc: uclass: Modify uc_pdata->name to use combination of device name and device's parent name

uc_pdata->name is populated from device tree property "remoteproc-name". For those devcices that don't set "remoteproc-name", uc_pdata->name falls back to dev->name.

If two devices have same name, this will result into uc_pdata->name not being unique and rproc_init() will fail.

Fix this by using combination of dev->name and dev->parent->name instead of using just the dev->name to populate uc_pdata->name.

---
Cc: Andrew Davis <[email protected]>

Failure Example:
In k3-am64-main.dtsi, both pru0_0 [1] and pru1_0 [2] will have dev->name as "pru@34000" although their parent name is different.

pru0_0 has dev->name as "pru@34000" and parent name as "icssg@30000000" pru1_0 has dev->name as "pru@34000" and parent name as "icssg@30080000"

rproc_init() fails for pru1_0 as the the uc_pdata->name becomes same as the pru0_0. More details on this issue can be found here [3]. It was suggested to use a different combination if dev->name is not unique by Andrew Davis <[email protected]> [4]

Failure Logs:

	rproc_pre_probe: 'pru@34000': using fdt
	rproc_pre_probe: 'pru@34000': using fdt
	rproc_pre_probe: pru@34000 duplicate name 'pru@34000'
	_rproc_probe_dev: pru@34000: Failed to initialize - -22
	rproc_boot: rproc_init() failed: -22

To fix it, this commit uses combination of dev and dev's parent name.

After this commit,
pru0_0 uc->pdata->name = "pru@34000:icssg@30000000" pru1_0 uc->pdata->name = "pru@34000:icssg@30080000"

Both the names are unique, thus rproc_init() succeeds.

[1] https://elixir.bootlin.com/u-boot/v2024.07-rc3/source/dts/upstream/src/arm64/ti/k3-am64-main.dtsi#L1276
[2] https://elixir.bootlin.com/u-boot/v2024.07-rc3/source/dts/upstream/src/arm64/ti/k3-am64-main.dtsi#L1417
[3] https://lore.kernel.org/all/[email protected]/
[4] https://lore.kernel.org/all/[email protected]/

 drivers/remoteproc/rproc-uclass.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/remoteproc/rproc-uclass.c +9 -3
index 3ba2b40dca..e550292dda 100644
@@ -158,9 +158,15 @@ static int rproc_pre_probe(struct udevice *dev)
 		uc_pdata->driver_plat_data = pdata->driver_plat_data;
 	}
 
-	/* Else try using device Name */
-	if (!uc_pdata->name)
-		uc_pdata->name = dev->name;
+	/* Else try using a combination of device Name and devices's parent's name */
+	if (!uc_pdata->name) {
+		int rproc_name_size = 256;
+		char *buf;
+
+		buf = malloc(rproc_name_size);
+		snprintf(buf, rproc_name_size, "%s-%s", dev->name, dev->parent->name);
+		uc_pdata->name = buf;
+	}
 	if (!uc_pdata->name) {
 		debug("Unnamed device!");
 		return -EINVAL;
Signature · 1 line
2.34.1
#1 lore raw
Quoted 53 lines · MD Danish Anwar

uc_pdata->name is populated from device tree property "remoteproc-name". For those devcices that don't set "remoteproc-name", uc_pdata->name falls back to dev->name.

If two devices have same name, this will result into uc_pdata->name not being unique and rproc_init() will fail.

Fix this by using combination of dev->name and dev->parent->name instead of using just the dev->name to populate uc_pdata->name.

---
Cc: Andrew Davis <[email protected]>

Failure Example:
In k3-am64-main.dtsi, both pru0_0 [1] and pru1_0 [2] will have dev->name as "pru@34000" although their parent name is different.

pru0_0 has dev->name as "pru@34000" and parent name as "icssg@30000000" pru1_0 has dev->name as "pru@34000" and parent name as "icssg@30080000"

rproc_init() fails for pru1_0 as the the uc_pdata->name becomes same as the pru0_0. More details on this issue can be found here [3]. It was suggested to use a different combination if dev->name is not unique by Andrew Davis <[email protected]> [4]

Failure Logs:

	rproc_pre_probe: 'pru@34000': using fdt
	rproc_pre_probe: 'pru@34000': using fdt
	rproc_pre_probe: pru@34000 duplicate name 'pru@34000'
	_rproc_probe_dev: pru@34000: Failed to initialize - -22
	rproc_boot: rproc_init() failed: -22

To fix it, this commit uses combination of dev and dev's parent name.

After this commit,
pru0_0 uc->pdata->name = "pru@34000:icssg@30000000" pru1_0 uc->pdata->name = "pru@34000:icssg@30080000"

Both the names are unique, thus rproc_init() succeeds.

[1] https://elixir.bootlin.com/u-boot/v2024.07-rc3/source/dts/upstream/src/arm64/ti/k3-am64-main.dtsi#L1276
[2] https://elixir.bootlin.com/u-boot/v2024.07-rc3/source/dts/upstream/src/arm64/ti/k3-am64-main.dtsi#L1417
[3] https://lore.kernel.org/all/[email protected]/
[4] https://lore.kernel.org/all/[email protected]/

 drivers/remoteproc/rproc-uclass.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/remoteproc/rproc-uclass.c +0 -0
index 3ba2b40dca..e550292dda 100644

drivers/remoteproc/rproc-uclass.c static int rproc_pre_probe(struct udevice *dev) · line 163

Quoted 9 lines
drivers/remoteproc/rproc-uclass.c +3 -3
@@ -158,9 +158,15 @@ static int rproc_pre_probe(struct udevice *dev)
 		uc_pdata->driver_plat_data = pdata->driver_plat_data;
 	}
 
-	/* Else try using device Name */
-	if (!uc_pdata->name)
-		uc_pdata->name = dev->name;
+	/* Else try using a combination of device Name and devices's parent's name */
+	if (!uc_pdata->name) {
+		int rproc_name_size = 256;

Instead of hardcoding 256 why not use

		buf = malloc(strlen(dev->name) + strlen(dev->parent->name) + 2);	// 1 for null and one for '-'

drivers/remoteproc/rproc-uclass.c static int rproc_pre_probe(struct udevice *dev) · line 166

Quoted 3 lines
drivers/remoteproc/rproc-uclass.c +3 -0
+		char *buf;
+
+		buf = malloc(rproc_name_size);

need to check/error out for malloc failure.

Quoted 6 lines
drivers/remoteproc/rproc-uclass.c +3 -0
+		snprintf(buf, rproc_name_size, "%s-%s", dev->name, dev->parent->name);
+		uc_pdata->name = buf;
+	}
 	if (!uc_pdata->name) {
 		debug("Unnamed device!");
 		return -EINVAL;
Signature · 2 lines
cheers,
-roger
#2 lore raw
Quoted 67 lines · Roger Quadros
Quoted 53 lines · MD Danish Anwar

uc_pdata->name is populated from device tree property "remoteproc-name". For those devcices that don't set "remoteproc-name", uc_pdata->name falls back to dev->name.

If two devices have same name, this will result into uc_pdata->name not being unique and rproc_init() will fail.

Fix this by using combination of dev->name and dev->parent->name instead of using just the dev->name to populate uc_pdata->name.

---
Cc: Andrew Davis <[email protected]>

Failure Example:
In k3-am64-main.dtsi, both pru0_0 [1] and pru1_0 [2] will have dev->name as "pru@34000" although their parent name is different.

pru0_0 has dev->name as "pru@34000" and parent name as "icssg@30000000" pru1_0 has dev->name as "pru@34000" and parent name as "icssg@30080000"

rproc_init() fails for pru1_0 as the the uc_pdata->name becomes same as the pru0_0. More details on this issue can be found here [3]. It was suggested to use a different combination if dev->name is not unique by Andrew Davis <[email protected]> [4]

Failure Logs:

	rproc_pre_probe: 'pru@34000': using fdt
	rproc_pre_probe: 'pru@34000': using fdt
	rproc_pre_probe: pru@34000 duplicate name 'pru@34000'
	_rproc_probe_dev: pru@34000: Failed to initialize - -22
	rproc_boot: rproc_init() failed: -22

To fix it, this commit uses combination of dev and dev's parent name.

After this commit,
pru0_0 uc->pdata->name = "pru@34000:icssg@30000000" pru1_0 uc->pdata->name = "pru@34000:icssg@30080000"

Both the names are unique, thus rproc_init() succeeds.

[1] https://elixir.bootlin.com/u-boot/v2024.07-rc3/source/dts/upstream/src/arm64/ti/k3-am64-main.dtsi#L1276
[2] https://elixir.bootlin.com/u-boot/v2024.07-rc3/source/dts/upstream/src/arm64/ti/k3-am64-main.dtsi#L1417
[3] https://lore.kernel.org/all/[email protected]/
[4] https://lore.kernel.org/all/[email protected]/

 drivers/remoteproc/rproc-uclass.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
drivers/remoteproc/rproc-uclass.c +0 -0
index 3ba2b40dca..e550292dda 100644

drivers/remoteproc/rproc-uclass.c static int rproc_pre_probe(struct udevice *dev) · line 163

Quoted 9 lines
drivers/remoteproc/rproc-uclass.c +3 -3
@@ -158,9 +158,15 @@ static int rproc_pre_probe(struct udevice *dev)
 		uc_pdata->driver_plat_data = pdata->driver_plat_data;
 	}
 
-	/* Else try using device Name */
-	if (!uc_pdata->name)
-		uc_pdata->name = dev->name;
+	/* Else try using a combination of device Name and devices's parent's name */
+	if (!uc_pdata->name) {
+		int rproc_name_size = 256;

Instead of hardcoding 256 why not use

Quoted 7 lines
		buf = malloc(strlen(dev->name) + strlen(dev->parent->name) + 2);	// 1 for null and one for '-'

drivers/remoteproc/rproc-uclass.c static int rproc_pre_probe(struct udevice *dev) · line 166

Quoted 3 lines
drivers/remoteproc/rproc-uclass.c +3 -0
+		char *buf;
+
+		buf = malloc(rproc_name_size);

need to check/error out for malloc failure.

Sure Roger, I will make these changes and update the patch. Thanks for the review.

Quoted 8 lines
Quoted 7 lines
drivers/remoteproc/rproc-uclass.c +3 -0
+		snprintf(buf, rproc_name_size, "%s-%s", dev->name, dev->parent->name);
+		uc_pdata->name = buf;
+	}
 	if (!uc_pdata->name) {
 		debug("Unnamed device!");
 		return -EINVAL;
Signature · 2 lines
Thanks and Regards,
Danish