Skip to contentSkip to conversation

PCI: of: Propagate firmware node

PATCH Superseded Andy Shevchenko 2 participants 5 messages Apr 12, 2023 – Apr 17, 2023 PCI

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 PCI: of: Propagate firmware node

Propagate firmware node by using a specific API call, i.e. device_set_node().

---
 drivers/pci/of.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
drivers/pci/of.c +7 -12
index 196834ed44fe..4bba00dfbfc5 100644
@@ -18,19 +18,18 @@
 #ifdef CONFIG_PCI
 void pci_set_of_node(struct pci_dev *dev)
 {
+	struct device_node *node;
+
 	if (!dev->bus->dev.of_node)
 		return;
-	dev->dev.of_node = of_pci_find_child_device(dev->bus->dev.of_node,
-						    dev->devfn);
-	if (dev->dev.of_node)
-		dev->dev.fwnode = &dev->dev.of_node->fwnode;
+	node = of_pci_find_child_device(dev->bus->dev.of_node, dev->devfn);
+	device_set_node(&dev->dev, of_fwnode_handle(node));
 }
 
 void pci_release_of_node(struct pci_dev *dev)
 {
 	of_node_put(dev->dev.of_node);
-	dev->dev.of_node = NULL;
-	dev->dev.fwnode = NULL;
+	device_set_node(&dev->dev, NULL);
 }
 
 void pci_set_bus_of_node(struct pci_bus *bus)
@@ -45,17 +44,13 @@ void pci_set_bus_of_node(struct pci_bus *bus)
 			bus->self->external_facing = true;
 	}
 
-	bus->dev.of_node = node;
-
-	if (bus->dev.of_node)
-		bus->dev.fwnode = &bus->dev.of_node->fwnode;
+	device_set_node(&bus->dev, of_fwnode_handle(node));
 }
 
 void pci_release_bus_of_node(struct pci_bus *bus)
 {
 	of_node_put(bus->dev.of_node);
-	bus->dev.of_node = NULL;
-	bus->dev.fwnode = NULL;
+	device_set_node(&bus->dev, NULL);
 }
 
 struct device_node * __weak pcibios_get_phb_of_node(struct pci_bus *bus)
Signature · 1 line
2.40.0.1.gaa8946217a0b
#1 lore raw
Quoted 1 line · Andy Shevchenko

Propagate firmware node by using a specific API call, i.e. device_set_node().

Can you add a line or two about *why* we should do this, e.g., is this headed toward some goal? Is it a simplification that's 100% equivalent (doesn't seem so, see below)?

Seems like there's an underlying long-term effort to unify things from OF and ACPI, which seems like a good thing, but at the moment it's a little confusing to follow. For instance pci_set_of_node() seems like it ought to be sort of analogous to pci_set_acpi_fwnode(), but they look nothing alike.

Quoted 13 lines
---
 drivers/pci/of.c | 19 +++++++------------
 1 file changed, 7 insertions(+), 12 deletions(-)
drivers/pci/of.c +0 -0
index 196834ed44fe..4bba00dfbfc5 100644
@@ -18,19 +18,18 @@
 #ifdef CONFIG_PCI
 void pci_set_of_node(struct pci_dev *dev)
 {

drivers/pci/of.c line 26

Quoted 10 lines
drivers/pci/of.c +4 -4
+	struct device_node *node;
+
 	if (!dev->bus->dev.of_node)
 		return;
-	dev->dev.of_node = of_pci_find_child_device(dev->bus->dev.of_node,
-						    dev->devfn);
-	if (dev->dev.of_node)
-		dev->dev.fwnode = &dev->dev.of_node->fwnode;
+	node = of_pci_find_child_device(dev->bus->dev.of_node, dev->devfn);
+	device_set_node(&dev->dev, of_fwnode_handle(node));

This doesn't seem 100% equivalent. If of_pci_find_child_device() returns NULL, the previous code doesn't set dev->dev.fwnode, but the new code does.

Quoted 34 lines
drivers/pci/of.c +3 -8
 }
 
 void pci_release_of_node(struct pci_dev *dev)
 {
 	of_node_put(dev->dev.of_node);
-	dev->dev.of_node = NULL;
-	dev->dev.fwnode = NULL;
+	device_set_node(&dev->dev, NULL);
 }
 
 void pci_set_bus_of_node(struct pci_bus *bus)
@@ -45,17 +44,13 @@ void pci_set_bus_of_node(struct pci_bus *bus)
 			bus->self->external_facing = true;
 	}
 
-	bus->dev.of_node = node;
-
-	if (bus->dev.of_node)
-		bus->dev.fwnode = &bus->dev.of_node->fwnode;
+	device_set_node(&bus->dev, of_fwnode_handle(node));
 }
 
 void pci_release_bus_of_node(struct pci_bus *bus)
 {
 	of_node_put(bus->dev.of_node);
-	bus->dev.of_node = NULL;
-	bus->dev.fwnode = NULL;
+	device_set_node(&bus->dev, NULL);
 }
 
 struct device_node * __weak pcibios_get_phb_of_node(struct pci_bus *bus)
Signature · 1 line
2.40.0.1.gaa8946217a0b
#2 lore raw
Quoted 5 lines · Bjorn Helgaas
Quoted 1 line · Andy Shevchenko

Propagate firmware node by using a specific API call, i.e. device_set_node().

Can you add a line or two about *why* we should do this, e.g., is this headed toward some goal?

Because dereferencing the fwnode in struct device is preventing us from modifications of how fwnode looks like in the future.

Quoted 2 lines

Is it a simplification that's 100%
equivalent (doesn't seem so, see below)?

To me it's an equivalent, I'll explain below.

Quoted 5 lines

Seems like there's an underlying long-term effort to unify things from OF and ACPI, which seems like a good thing, but at the moment it's a little confusing to follow. For instance pci_set_of_node() seems like it ought to be sort of analogous to pci_set_acpi_fwnode(), but they look nothing alike.

Unification to some extent, but here is not a point of this change.

...

Quoted 6 lines
Quoted 6 lines
drivers/pci/of.c +2 -2
+	struct device_node *node;
+
 	if (!dev->bus->dev.of_node)
 		return;
-	dev->dev.of_node = of_pci_find_child_device(dev->bus->dev.of_node,
-						    dev->devfn);
Quoted 8 lines

drivers/pci/of.c line 26

Quoted 4 lines
drivers/pci/of.c +2 -2
-	if (dev->dev.of_node)
-		dev->dev.fwnode = &dev->dev.of_node->fwnode;
+	node = of_pci_find_child_device(dev->bus->dev.of_node, dev->devfn);
+	device_set_node(&dev->dev, of_fwnode_handle(node));

This doesn't seem 100% equivalent. If of_pci_find_child_device() returns NULL, the previous code doesn't set dev->dev.fwnode, but the new code does.

Yes and this is not a problem. We create device with pci_alloc_dev() in both callers of the pci_setup_device() and the field is NULL anyway. So, the last condition there is a simple micro-optimisation.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 9 lines · Andy Shevchenko
Quoted 5 lines · Bjorn Helgaas
Quoted 1 line · Andy Shevchenko

Propagate firmware node by using a specific API call, i.e. device_set_node().

Can you add a line or two about *why* we should do this, e.g., is this headed toward some goal?

Because dereferencing the fwnode in struct device is preventing us from modifications of how fwnode looks like in the future.

How do you want to express this in the commit log? Something like this?

Insulate pci_set_of_node() and pci_set_bus_of_node() from possible changes to fwnode_handle implementation by using device_set_node() instead of open-coding dev->dev.fwnode assignments.

Quoted 30 lines
Quoted 2 lines

Is it a simplification that's 100%
equivalent (doesn't seem so, see below)?

To me it's an equivalent, I'll explain below.

Quoted 5 lines

Seems like there's an underlying long-term effort to unify things from OF and ACPI, which seems like a good thing, but at the moment it's a little confusing to follow. For instance pci_set_of_node() seems like it ought to be sort of analogous to pci_set_acpi_fwnode(), but they look nothing alike.

Unification to some extent, but here is not a point of this change.

...

Quoted 6 lines
Quoted 6 lines
drivers/pci/of.c +2 -2
+	struct device_node *node;
+
 	if (!dev->bus->dev.of_node)
 		return;
-	dev->dev.of_node = of_pci_find_child_device(dev->bus->dev.of_node,
-						    dev->devfn);
Quoted 8 lines

drivers/pci/of.c line 26

Quoted 4 lines
drivers/pci/of.c +2 -2
-	if (dev->dev.of_node)
-		dev->dev.fwnode = &dev->dev.of_node->fwnode;
+	node = of_pci_find_child_device(dev->bus->dev.of_node, dev->devfn);
+	device_set_node(&dev->dev, of_fwnode_handle(node));

This doesn't seem 100% equivalent. If of_pci_find_child_device() returns NULL, the previous code doesn't set dev->dev.fwnode, but the new code does.

Quoted 3 lines

Yes and this is not a problem. We create device with pci_alloc_dev() in both callers of the pci_setup_device() and the field is NULL anyway. So, the last condition there is a simple micro-optimisation.

OK, makes sense, thanks.

Bjorn

#4 lore raw
Quoted 3 lines · Bjorn Helgaas
Quoted 2 lines · Andy Shevchenko
Quoted 1 line · Bjorn Helgaas

On Wed, Apr 12, 2023 at 04:15:20PM +0300, Andy Shevchenko wrote:

...

Quoted 8 lines
Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Propagate firmware node by using a specific API call, i.e. device_set_node().

Can you add a line or two about *why* we should do this, e.g., is this headed toward some goal?

Because dereferencing the fwnode in struct device is preventing us from modifications of how fwnode looks like in the future.

Quoted 6 lines

How do you want to express this in the commit log? Something like this?

Insulate pci_set_of_node() and pci_set_bus_of_node() from possible changes to fwnode_handle implementation by using device_set_node() instead of open-coding dev->dev.fwnode assignments.

Sounds good to me, thanks for the draft. I will do it in v2 this way.

Signature · 2 lines
With Best Regards,
Andy Shevchenko