Skip to contentSkip to conversation

base: soc: set machine name in soc_device_register if empty

PATCH In review Heiner Kallweit 2 participants 5 messages Mar 16, 2023 – Mar 17, 2023 Driver core

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 base: soc: set machine name in soc_device_register if empty

Several SoC drivers use the same of-based mechanism to populate the machine name. Therefore move this to the core and try to populate the machine name in soc_device_register if it's not set yet.

---
 drivers/base/soc.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/base/soc.c +15 -0
index 0fb1d4ab9..8dec5228f 100644
@@ -7,6 +7,7 @@
 
 #include <linux/sysfs.h>
 #include <linux/init.h>
+#include <linux/of.h>
 #include <linux/stat.h>
 #include <linux/slab.h>
 #include <linux/idr.h>
@@ -110,6 +111,18 @@ static void soc_release(struct device *dev)
 	kfree(soc_dev);
 }
 
+static void soc_device_set_machine(struct soc_device_attribute *soc_dev_attr)
+{
+	struct device_node *np;
+
+	if (soc_dev_attr->machine)
+		return;
+
+	np = of_find_node_by_path("/");
+	of_property_read_string(np, "model", &soc_dev_attr->machine);
+	of_node_put(np);
+}
+
 static struct soc_device_attribute *early_soc_dev_attr;
 
 struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr)
@@ -118,6 +131,8 @@ struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr
 	const struct attribute_group **soc_attr_groups;
 	int ret;
 
+	soc_device_set_machine(soc_dev_attr);
+
 	if (!soc_bus_registered) {
 		if (early_soc_dev_attr)
 			return ERR_PTR(-EBUSY);
Signature · 1 line
2.39.2
#1 lore raw
Quoted 41 lines · Heiner Kallweit

Several SoC drivers use the same of-based mechanism to populate the machine name. Therefore move this to the core and try to populate the machine name in soc_device_register if it's not set yet.

---
 drivers/base/soc.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/base/soc.c +13 -0
index 0fb1d4ab9..8dec5228f 100644
@@ -7,6 +7,7 @@
 
 #include <linux/sysfs.h>
 #include <linux/init.h>
+#include <linux/of.h>
 #include <linux/stat.h>
 #include <linux/slab.h>
 #include <linux/idr.h>
@@ -110,6 +111,18 @@ static void soc_release(struct device *dev)
 	kfree(soc_dev);
 }
 
+static void soc_device_set_machine(struct soc_device_attribute *soc_dev_attr)
+{
+	struct device_node *np;
+
+	if (soc_dev_attr->machine)
+		return;
+
+	np = of_find_node_by_path("/");
+	of_property_read_string(np, "model", &soc_dev_attr->machine);
+	of_node_put(np);
+}
+
 static struct soc_device_attribute *early_soc_dev_attr;
 
 struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr)

drivers/base/soc.c struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr · line 135

Quoted 5 lines
drivers/base/soc.c +2 -0
@@ -118,6 +131,8 @@ struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr
 	const struct attribute_group **soc_attr_groups;
 	int ret;
 
+	soc_device_set_machine(soc_dev_attr);
+

Does this mean some SoC drivers should also be changed at the same time if they are trying to do this?

And is "model" the correct of property for this? I thought that devices also had "model" as a valid entry, is this documented somewhere in the DTS schema that I couldn't find?

thanks,

greg k-h

#2 lore raw
Quoted 45 lines · Greg Kroah-Hartman
Quoted 44 lines · Heiner Kallweit

Several SoC drivers use the same of-based mechanism to populate the machine name. Therefore move this to the core and try to populate the machine name in soc_device_register if it's not set yet.

---
 drivers/base/soc.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/base/soc.c +13 -0
index 0fb1d4ab9..8dec5228f 100644
@@ -7,6 +7,7 @@
 
 #include <linux/sysfs.h>
 #include <linux/init.h>
+#include <linux/of.h>
 #include <linux/stat.h>
 #include <linux/slab.h>
 #include <linux/idr.h>
@@ -110,6 +111,18 @@ static void soc_release(struct device *dev)
 	kfree(soc_dev);
 }
 
+static void soc_device_set_machine(struct soc_device_attribute *soc_dev_attr)
+{
+	struct device_node *np;
+
+	if (soc_dev_attr->machine)
+		return;
+
+	np = of_find_node_by_path("/");
+	of_property_read_string(np, "model", &soc_dev_attr->machine);
+	of_node_put(np);
+}
+
 static struct soc_device_attribute *early_soc_dev_attr;
 
 struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr)
@@ -118,6 +131,8 @@ struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr
 	const struct attribute_group **soc_attr_groups;
 	int ret;
 
Quoted 6 lines

drivers/base/soc.c struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr · line 135

Quoted 2 lines
drivers/base/soc.c +2 -0
+	soc_device_set_machine(soc_dev_attr);
+

Does this mean some SoC drivers should also be changed at the same time if they are trying to do this?

The then duplicated code can be removed from SoC drivers afterwards. There's no need to do it at the same time.
This change just adds a fallback in case the SoC driver doesn't set "machine". Means if a SoC driver populates machine differently, then this is respected and not overwritten.

Quoted 4 lines

And is "model" the correct of property for this? I thought that devices also had "model" as a valid entry, is this documented somewhere in the DTS schema that I couldn't find?

"model" is used by basically all SoC drivers for this purpose, a quick grep reveals:

drivers/soc/samsung/exynos-chipid.c: of_property_read_string(root, "model", &soc_dev_attr->machine);
drivers/soc/fsl/guts.c: if (of_property_read_string(of_root, "model", &machine)) drivers/soc/amlogic/meson-mx-socinfo.c: of_property_read_string(np, "model", &soc_dev_attr->machine); drivers/soc/amlogic/meson-gx-socinfo.c: of_property_read_string(np, "model", &soc_dev_attr->machine);
drivers/soc/aspeed/aspeed-socinfo.c: of_property_read_string(np, "model", &machine);
drivers/soc/ti/k3-socinfo.c: of_property_read_string(node, "model", &soc_dev_attr->machine);
drivers/soc/loongson/loongson2_guts.c: if (of_property_read_string(root, "model", &machine))
drivers/soc/renesas/renesas-soc.c: of_property_read_string(np, "model", &soc_dev_attr->machine);

drivers/soc/imx/soc-imx.c:      ret = of_property_read_string(root, "model", &soc_dev_attr->machine);
drivers/soc/imx/soc-imx8m.c:    ret = of_property_read_string(of_root, "model", &soc_dev_attr->machine);

Some don't set machine at all.

Quoted 3 lines

thanks,

greg k-h

Heiner

#3 lore raw
Quoted 52 lines · Heiner Kallweit
Quoted 45 lines · Greg Kroah-Hartman
Quoted 44 lines · Heiner Kallweit

Several SoC drivers use the same of-based mechanism to populate the machine name. Therefore move this to the core and try to populate the machine name in soc_device_register if it's not set yet.

---
 drivers/base/soc.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/base/soc.c +13 -0
index 0fb1d4ab9..8dec5228f 100644
@@ -7,6 +7,7 @@
 
 #include <linux/sysfs.h>
 #include <linux/init.h>
+#include <linux/of.h>
 #include <linux/stat.h>
 #include <linux/slab.h>
 #include <linux/idr.h>
@@ -110,6 +111,18 @@ static void soc_release(struct device *dev)
 	kfree(soc_dev);
 }
 
+static void soc_device_set_machine(struct soc_device_attribute *soc_dev_attr)
+{
+	struct device_node *np;
+
+	if (soc_dev_attr->machine)
+		return;
+
+	np = of_find_node_by_path("/");
+	of_property_read_string(np, "model", &soc_dev_attr->machine);
+	of_node_put(np);
+}
+
 static struct soc_device_attribute *early_soc_dev_attr;
 
 struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr)
@@ -118,6 +131,8 @@ struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr
 	const struct attribute_group **soc_attr_groups;
 	int ret;
 
Quoted 6 lines

drivers/base/soc.c struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr · line 135

Quoted 2 lines
drivers/base/soc.c +2 -0
+	soc_device_set_machine(soc_dev_attr);
+

Does this mean some SoC drivers should also be changed at the same time if they are trying to do this?

Quoted 5 lines

The then duplicated code can be removed from SoC drivers afterwards. There's no need to do it at the same time.
This change just adds a fallback in case the SoC driver doesn't set "machine". Means if a SoC driver populates machine differently, then this is respected and not overwritten.

Please send this as a patch series that add this, and then removes this code from the SoC drivers so we can verify that it is all working properly.

Quoted 15 lines
Quoted 4 lines

And is "model" the correct of property for this? I thought that devices also had "model" as a valid entry, is this documented somewhere in the DTS schema that I couldn't find?

"model" is used by basically all SoC drivers for this purpose, a quick grep reveals:

drivers/soc/samsung/exynos-chipid.c: of_property_read_string(root, "model", &soc_dev_attr->machine);
drivers/soc/fsl/guts.c: if (of_property_read_string(of_root, "model", &machine)) drivers/soc/amlogic/meson-mx-socinfo.c: of_property_read_string(np, "model", &soc_dev_attr->machine); drivers/soc/amlogic/meson-gx-socinfo.c: of_property_read_string(np, "model", &soc_dev_attr->machine);
drivers/soc/aspeed/aspeed-socinfo.c: of_property_read_string(np, "model", &machine);
drivers/soc/ti/k3-socinfo.c: of_property_read_string(node, "model", &soc_dev_attr->machine);
drivers/soc/loongson/loongson2_guts.c: if (of_property_read_string(root, "model", &machine))
drivers/soc/renesas/renesas-soc.c: of_property_read_string(np, "model", &soc_dev_attr->machine);

Quoted 4 lines
drivers/soc/imx/soc-imx.c:      ret = of_property_read_string(root, "model", &soc_dev_attr->machine);
drivers/soc/imx/soc-imx8m.c:    ret = of_property_read_string(of_root, "model", &soc_dev_attr->machine);

Some don't set machine at all.

So will this break systems that were not previously doing this by showing an odd value?

thanks,

greg k-h

#4 lore raw
Quoted 59 lines · Greg Kroah-Hartman
Quoted 52 lines · Heiner Kallweit
Quoted 45 lines · Greg Kroah-Hartman
Quoted 44 lines · Heiner Kallweit

Several SoC drivers use the same of-based mechanism to populate the machine name. Therefore move this to the core and try to populate the machine name in soc_device_register if it's not set yet.

---
 drivers/base/soc.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
drivers/base/soc.c +13 -0
index 0fb1d4ab9..8dec5228f 100644
@@ -7,6 +7,7 @@
 
 #include <linux/sysfs.h>
 #include <linux/init.h>
+#include <linux/of.h>
 #include <linux/stat.h>
 #include <linux/slab.h>
 #include <linux/idr.h>
@@ -110,6 +111,18 @@ static void soc_release(struct device *dev)
 	kfree(soc_dev);
 }
 
+static void soc_device_set_machine(struct soc_device_attribute *soc_dev_attr)
+{
+	struct device_node *np;
+
+	if (soc_dev_attr->machine)
+		return;
+
+	np = of_find_node_by_path("/");
+	of_property_read_string(np, "model", &soc_dev_attr->machine);
+	of_node_put(np);
+}
+
 static struct soc_device_attribute *early_soc_dev_attr;
 
 struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr)
@@ -118,6 +131,8 @@ struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr
 	const struct attribute_group **soc_attr_groups;
 	int ret;
 
Quoted 6 lines

drivers/base/soc.c struct soc_device *soc_device_register(struct soc_device_attribute *soc_dev_attr · line 135

Quoted 2 lines
drivers/base/soc.c +2 -0
+	soc_device_set_machine(soc_dev_attr);
+

Does this mean some SoC drivers should also be changed at the same time if they are trying to do this?

Quoted 5 lines

The then duplicated code can be removed from SoC drivers afterwards. There's no need to do it at the same time.
This change just adds a fallback in case the SoC driver doesn't set "machine". Means if a SoC driver populates machine differently, then this is respected and not overwritten.

Quoted 4 lines

Please send this as a patch series that add this, and then removes this code from the SoC drivers so we can verify that it is all working properly.

OK, I'll make it a series incl. one use case where I have the hw to test.

Quoted 18 lines
Quoted 18 lines
Quoted 4 lines

And is "model" the correct of property for this? I thought that devices also had "model" as a valid entry, is this documented somewhere in the DTS schema that I couldn't find?

"model" is used by basically all SoC drivers for this purpose, a quick grep reveals:

drivers/soc/samsung/exynos-chipid.c: of_property_read_string(root, "model", &soc_dev_attr->machine);
drivers/soc/fsl/guts.c: if (of_property_read_string(of_root, "model", &machine)) drivers/soc/amlogic/meson-mx-socinfo.c: of_property_read_string(np, "model", &soc_dev_attr->machine); drivers/soc/amlogic/meson-gx-socinfo.c: of_property_read_string(np, "model", &soc_dev_attr->machine);
drivers/soc/aspeed/aspeed-socinfo.c: of_property_read_string(np, "model", &machine);
drivers/soc/ti/k3-socinfo.c: of_property_read_string(node, "model", &soc_dev_attr->machine);
drivers/soc/loongson/loongson2_guts.c: if (of_property_read_string(root, "model", &machine))
drivers/soc/renesas/renesas-soc.c: of_property_read_string(np, "model", &soc_dev_attr->machine);

drivers/soc/imx/soc-imx.c:      ret = of_property_read_string(root, "model", &soc_dev_attr->machine);
drivers/soc/imx/soc-imx8m.c:    ret = of_property_read_string(of_root, "model", &soc_dev_attr->machine);
Quoted 5 lines
Quoted 1 line

Some don't set machine at all.

So will this break systems that were not previously doing this by showing an odd value?

This change may populate "machine" in cases where "machine" isn't populated currently. AFAICS the only impact is that this value is exposed via sysfs. Odd values I'd expect only if the "model" property in DTS is odd. Not sure whether there's any such case, this would need to be fixed in the DTS.

Quoted 3 lines

thanks,

greg k-h