Skip to contentSkip to conversation

PCI: Simplify bus range parsing

PATCH Applied Bjorn Helgaas 2 participants 11 messages Jan 13, 2025 – Jan 15, 2025

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

v2 cover PCI: Simplify bus range parsing

From: Bjorn Helgaas <[email protected]>

Unexport of_pci_parse_bus_range() since it's only used in drivers/pci/of.c.

Drop the "No bus range found" message since host bridges typically lead to [bus 00-ff], and we already default to that if there is no "bus-range" DT property, so there's no point in requiring it in DT or complaining if it's not there.

Drop bus range parameters from devm_of_pci_get_host_bridge_resources() since they're always the same values.

Update a sparc comment that referred to of_pci_get_host_bridge_resources(), which no longer exists.

Bjorn Helgaas (4):
PCI: Unexport of_pci_parse_bus_range()
PCI: of: Drop 'No bus range found' message
PCI: of: Simplify devm_of_pci_get_host_bridge_resources() interface sparc/PCI: Update reference to devm_of_pci_get_host_bridge_resources()

 arch/sparc/kernel/pci_common.c |  2 +-
 drivers/pci/of.c               | 22 ++++++++++------------
 drivers/pci/pci.h              |  7 -------
 3 files changed, 11 insertions(+), 20 deletions(-)

Changes since v1
(https://lore.kernel.org/r/[email protected]):
- Fix compile error
- Drop 'No bus range found' message
- Add Ack from Andreas for the sparc/PCI comment update
- Add Reviewed-by from Rob for the unexport patch

#1 lore raw

PATCH v2 1/4 PCI: Unexport of_pci_parse_bus_range()

From: Bjorn Helgaas <[email protected]>

of_pci_parse_bus_range() is only used in drivers/pci/of.c, so make it static and unexport it.

---
 drivers/pci/of.c  | 4 ++--
 drivers/pci/pci.h | 7 -------
 2 files changed, 2 insertions(+), 9 deletions(-)
drivers/pci/of.c +2 -2
index 52f770bcc481..2f579b691f8e 100644
@@ -190,7 +190,8 @@ EXPORT_SYMBOL_GPL(of_pci_get_devfn);
  *
  * Returns 0 on success or a negative error-code on failure.
  */
-int of_pci_parse_bus_range(struct device_node *node, struct resource *res)
+static int of_pci_parse_bus_range(struct device_node *node,
+				  struct resource *res)
 {
 	u32 bus_range[2];
 	int error;
@@ -207,7 +208,6 @@ int of_pci_parse_bus_range(struct device_node *node, struct resource *res)
 
 	return 0;
 }
-EXPORT_SYMBOL_GPL(of_pci_parse_bus_range);
 
 /**
  * of_get_pci_domain_nr - Find the host bridge domain number
drivers/pci/pci.h +0 -7
index 2e40fc63ba31..35faf4770a14 100644
@@ -797,7 +797,6 @@ static inline u64 pci_rebar_size_to_bytes(int size)
 struct device_node;
 
 #ifdef CONFIG_OF
-int of_pci_parse_bus_range(struct device_node *node, struct resource *res);
 int of_get_pci_domain_nr(struct device_node *node);
 int of_pci_get_max_link_speed(struct device_node *node);
 u32 of_pci_get_slot_power_limit(struct device_node *node,
@@ -813,12 +812,6 @@ int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge);
 bool of_pci_supply_present(struct device_node *np);
 
 #else
-static inline int
-of_pci_parse_bus_range(struct device_node *node, struct resource *res)
-{
-	return -EINVAL;
-}
-
 static inline int
 of_get_pci_domain_nr(struct device_node *node)
 {
Signature · 1 line
2.34.1
Reviewed-by on v2 1/4
#2 lore raw

Re: [PATCH v2 1/4] PCI: Unexport of_pci_parse_bus_range()

Hi,

Quoted 8 lines · Bjorn Helgaas

From: Bjorn Helgaas <[email protected]>

of_pci_parse_bus_range() is only used in drivers/pci/of.c, so make it static and unexport it.

---

Looks good

Quoted 51 lines
  drivers/pci/of.c  | 4 ++--
  drivers/pci/pci.h | 7 -------
  2 files changed, 2 insertions(+), 9 deletions(-)
drivers/pci/of.c +2 -2
index 52f770bcc481..2f579b691f8e 100644
@@ -190,7 +190,8 @@ EXPORT_SYMBOL_GPL(of_pci_get_devfn);
   *
   * Returns 0 on success or a negative error-code on failure.
   */
-int of_pci_parse_bus_range(struct device_node *node, struct resource *res)
+static int of_pci_parse_bus_range(struct device_node *node,
+				  struct resource *res)
  {
  	u32 bus_range[2];
  	int error;
@@ -207,7 +208,6 @@ int of_pci_parse_bus_range(struct device_node *node, struct resource *res)
 
  	return 0;
  }
-EXPORT_SYMBOL_GPL(of_pci_parse_bus_range);
 
  /**
   * of_get_pci_domain_nr - Find the host bridge domain number
drivers/pci/pci.h +0 -7
index 2e40fc63ba31..35faf4770a14 100644
@@ -797,7 +797,6 @@ static inline u64 pci_rebar_size_to_bytes(int size)
  struct device_node;
 
  #ifdef CONFIG_OF
-int of_pci_parse_bus_range(struct device_node *node, struct resource *res);
  int of_get_pci_domain_nr(struct device_node *node);
  int of_pci_get_max_link_speed(struct device_node *node);
  u32 of_pci_get_slot_power_limit(struct device_node *node,
@@ -813,12 +812,6 @@ int devm_of_pci_bridge_init(struct device *dev, struct pci_host_bridge *bridge);
  bool of_pci_supply_present(struct device_node *np);
 
  #else
-static inline int
-of_pci_parse_bus_range(struct device_node *node, struct resource *res)
-{
-	return -EINVAL;
-}
-
  static inline int
  of_get_pci_domain_nr(struct device_node *node)
  {
Signature · 2 lines
Sathyanarayanan Kuppuswamy
Linux Kernel Developer
#3 lore raw

PATCH v2 2/4 PCI: of: Drop 'No bus range found' message

In reply to Bjorn Helgaas

From: Bjorn Helgaas <[email protected]>

The typical bus range for a host bridge is [bus 00-ff], and devm_of_pci_get_host_bridge_resources() defaults to that unless DT contains a "bus-range" property.

devm_of_pci_get_host_bridge_resources() previously emitted a message when there was no "bus-range" property, but that seems unnecessary for this common situation. Remove the message.

---
 drivers/pci/of.c | 2 --
 1 file changed, 2 deletions(-)
drivers/pci/of.c +0 -2
index 2f579b691f8e..48b9274b846e 100644
@@ -346,8 +346,6 @@ static int devm_of_pci_get_host_bridge_resources(struct device *dev,
 		bus_range->start = busno;
 		bus_range->end = bus_max;
 		bus_range->flags = IORESOURCE_BUS;
-		dev_info(dev, "  No bus range found for %pOF, using %pR\n",
-			 dev_node, bus_range);
 	} else {
 		if (bus_range->end > bus_range->start + bus_max)
 			bus_range->end = bus_range->start + bus_max;
Signature · 1 line
2.34.1
Reviewed-by on v2 2/4
#4 lore raw

Re: [PATCH v2 2/4] PCI: of: Drop 'No bus range found' message

Quoted 6 lines · Bjorn Helgaas

From: Bjorn Helgaas <[email protected]>

The typical bus range for a host bridge is [bus 00-ff], and devm_of_pci_get_host_bridge_resources() defaults to that unless DT contains a "bus-range" property.

Quoted 6 lines

devm_of_pci_get_host_bridge_resources() previously emitted a message when there was no "bus-range" property, but that seems unnecessary for this common situation. Remove the message.

---

Quoted 16 lines
  drivers/pci/of.c | 2 --
  1 file changed, 2 deletions(-)
drivers/pci/of.c +0 -2
index 2f579b691f8e..48b9274b846e 100644
@@ -346,8 +346,6 @@ static int devm_of_pci_get_host_bridge_resources(struct device *dev,
  		bus_range->start = busno;
  		bus_range->end = bus_max;
  		bus_range->flags = IORESOURCE_BUS;
-		dev_info(dev, "  No bus range found for %pOF, using %pR\n",
-			 dev_node, bus_range);
  	} else {
  		if (bus_range->end > bus_range->start + bus_max)
  			bus_range->end = bus_range->start + bus_max;
Signature · 2 lines
Sathyanarayanan Kuppuswamy
Linux Kernel Developer
#5 lore raw

PATCH v2 3/4 PCI: of: Simplify devm_of_pci_get_host_bridge_resources() interface

In reply to Bjorn Helgaas

From: Bjorn Helgaas <[email protected]>

Previously pci_parse_request_of_pci_ranges() supplied the default bus range to devm_of_pci_get_host_bridge_resources(), but that function is static and has no other callers, so there's no reason to complicate its interface by passing the default bus range.

Drop the busno and bus_max parameters and use 0x0 and 0xff directly in devm_of_pci_get_host_bridge_resources().

---
 drivers/pci/of.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
drivers/pci/of.c +8 -8
index 48b9274b846e..a2acfc52caf4 100644
@@ -302,8 +302,6 @@ EXPORT_SYMBOL_GPL(of_pci_check_probe_only);
  * devm_of_pci_get_host_bridge_resources() - Resource-managed parsing of PCI
  *                                           host bridge resources from DT
  * @dev: host bridge device
- * @busno: bus number associated with the bridge root bus
- * @bus_max: maximum number of buses for this bridge
  * @resources: list where the range of resources will be added after DT parsing
  * @ib_resources: list where the range of inbound resources (with addresses
  *                from 'dma-ranges') will be added after DT parsing
@@ -319,7 +317,6 @@ EXPORT_SYMBOL_GPL(of_pci_check_probe_only);
  * value if it failed.
  */
 static int devm_of_pci_get_host_bridge_resources(struct device *dev,
-			unsigned char busno, unsigned char bus_max,
 			struct list_head *resources,
 			struct list_head *ib_resources,
 			resource_size_t *io_base)
@@ -343,12 +340,15 @@ static int devm_of_pci_get_host_bridge_resources(struct device *dev,
 
 	err = of_pci_parse_bus_range(dev_node, bus_range);
 	if (err) {
-		bus_range->start = busno;
-		bus_range->end = bus_max;
+		bus_range->start = 0;
+		bus_range->end = 0xff;
 		bus_range->flags = IORESOURCE_BUS;
 	} else {
-		if (bus_range->end > bus_range->start + bus_max)
-			bus_range->end = bus_range->start + bus_max;
+		if (bus_range->end > 0xff) {
+			dev_info(dev, "  Invalid end bus number in %pR, defaulting to 0xff\n",
+				 bus_range);
+			bus_range->end = 0xff;
+		}
 	}
 	pci_add_resource(resources, bus_range);
 
@@ -595,7 +595,7 @@ static int pci_parse_request_of_pci_ranges(struct device *dev,
 	INIT_LIST_HEAD(&bridge->windows);
 	INIT_LIST_HEAD(&bridge->dma_ranges);
 
-	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &bridge->windows,
+	err = devm_of_pci_get_host_bridge_resources(dev, &bridge->windows,
 						    &bridge->dma_ranges, &iobase);
 	if (err)
 		return err;
Signature · 1 line
2.34.1
#6 lore raw

Re: [PATCH v2 3/4] PCI: of: Simplify devm_of_pci_get_host_bridge_resources() interface

Hi Bjorn,

Quoted 41 lines · Bjorn Helgaas

From: Bjorn Helgaas <[email protected]>

Previously pci_parse_request_of_pci_ranges() supplied the default bus range to devm_of_pci_get_host_bridge_resources(), but that function is static and has no other callers, so there's no reason to complicate its interface by passing the default bus range.

Drop the busno and bus_max parameters and use 0x0 and 0xff directly in devm_of_pci_get_host_bridge_resources().

---
  drivers/pci/of.c | 16 ++++++++--------
  1 file changed, 8 insertions(+), 8 deletions(-)
drivers/pci/of.c +0 -4
index 48b9274b846e..a2acfc52caf4 100644
@@ -302,8 +302,6 @@ EXPORT_SYMBOL_GPL(of_pci_check_probe_only);
   * devm_of_pci_get_host_bridge_resources() - Resource-managed parsing of PCI
   *                                           host bridge resources from DT
   * @dev: host bridge device
- * @busno: bus number associated with the bridge root bus
- * @bus_max: maximum number of buses for this bridge
   * @resources: list where the range of resources will be added after DT parsing
   * @ib_resources: list where the range of inbound resources (with addresses
   *                from 'dma-ranges') will be added after DT parsing
@@ -319,7 +317,6 @@ EXPORT_SYMBOL_GPL(of_pci_check_probe_only);
   * value if it failed.
   */
  static int devm_of_pci_get_host_bridge_resources(struct device *dev,
-			unsigned char busno, unsigned char bus_max,
  			struct list_head *resources,
  			struct list_head *ib_resources,
  			resource_size_t *io_base)
@@ -343,12 +340,15 @@ static int devm_of_pci_get_host_bridge_resources(struct device *dev,
 
  	err = of_pci_parse_bus_range(dev_node, bus_range);
  	if (err) {
-		bus_range->start = busno;

drivers/pci/of.c static int devm_of_pci_get_host_bridge_resources(struct device *dev, · line 349

Quoted 10 lines
drivers/pci/of.c +5 -3
-		bus_range->end = bus_max;
+		bus_range->start = 0;
+		bus_range->end = 0xff;
  		bus_range->flags = IORESOURCE_BUS;
  	} else {
-		if (bus_range->end > bus_range->start + bus_max)
-			bus_range->end = bus_range->start + bus_max;
+		if (bus_range->end > 0xff) {
+			dev_info(dev, "  Invalid end bus number in %pR, defaulting to 0xff\n",
+				 bus_range);

Use dev_warn() ? I noticed that dev_info() is used in place of warning/errors in this file. Probably it needs to be cleaned?

Quoted 14 lines
drivers/pci/of.c +3 -1
+			bus_range->end = 0xff;
+		}
  	}
  	pci_add_resource(resources, bus_range);
 
@@ -595,7 +595,7 @@ static int pci_parse_request_of_pci_ranges(struct device *dev,
  	INIT_LIST_HEAD(&bridge->windows);
  	INIT_LIST_HEAD(&bridge->dma_ranges);
 
-	err = devm_of_pci_get_host_bridge_resources(dev, 0, 0xff, &bridge->windows,
+	err = devm_of_pci_get_host_bridge_resources(dev, &bridge->windows,
  						    &bridge->dma_ranges, &iobase);
  	if (err)
  		return err;
Signature · 2 lines
Sathyanarayanan Kuppuswamy
Linux Kernel Developer
#7 lore raw

Re: [PATCH v2 3/4] PCI: of: Simplify devm_of_pci_get_host_bridge_resources() interface

Quoted 11 lines · Sathyanarayanan Kuppuswamy
Quoted 9 lines · Bjorn Helgaas

From: Bjorn Helgaas <[email protected]>

Previously pci_parse_request_of_pci_ranges() supplied the default bus range to devm_of_pci_get_host_bridge_resources(), but that function is static and has no other callers, so there's no reason to complicate its interface by passing the default bus range.

Drop the busno and bus_max parameters and use 0x0 and 0xff directly in devm_of_pci_get_host_bridge_resources().

Quoted 9 lines

drivers/pci/of.c static int devm_of_pci_get_host_bridge_resources(struct device *dev, · line 349

Quoted 6 lines
  	} else {
drivers/pci/of.c +3 -2
-		if (bus_range->end > bus_range->start + bus_max)
-			bus_range->end = bus_range->start + bus_max;
+		if (bus_range->end > 0xff) {
+			dev_info(dev, "  Invalid end bus number in %pR, defaulting to 0xff\n",
+				 bus_range);

Use dev_warn() ? I noticed that dev_info() is used in place of warning/errors in this file.

Good point, changed.

Quoted 3 lines

Probably it needs to be cleaned?

Quoted 1 line
(quoted diff) +1 -0
+			bus_range->end = 0xff;
#8 lore raw

PATCH v2 4/4 sparc/PCI: Update reference to devm_of_pci_get_host_bridge_resources()

In reply to Bjorn Helgaas

From: Bjorn Helgaas <[email protected]>

5bd51b35c7cb ("PCI: Rework of_pci_get_host_bridge_resources() to devm_of_pci_get_host_bridge_resources()") converted and renamed of_pci_get_host_bridge_resources(). Update the comment reference to match.

---
 arch/sparc/kernel/pci_common.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/sparc/kernel/pci_common.c +1 -1
index 5eeec9ad6845..2576f4f31309 100644
@@ -361,7 +361,7 @@ void pci_determine_mem_io_space(struct pci_pbm_info *pbm)
 	int i, saw_mem, saw_io;
 	int num_pbm_ranges;
 
-	/* Corresponding generic code in of_pci_get_host_bridge_resources() */
+	/* Corresponds to generic devm_of_pci_get_host_bridge_resources() */
 
 	saw_mem = saw_io = 0;
 	pbm_ranges = of_get_property(pbm->op->dev.of_node, "ranges", &i);
Signature · 1 line
2.34.1
Reviewed-by on v2 4/4
#9 lore raw

Re: [PATCH v2 4/4] sparc/PCI: Update reference to devm_of_pci_get_host_bridge_resources()

Quoted 9 lines · Bjorn Helgaas

From: Bjorn Helgaas <[email protected]>

5bd51b35c7cb ("PCI: Rework of_pci_get_host_bridge_resources() to devm_of_pci_get_host_bridge_resources()") converted and renamed of_pci_get_host_bridge_resources(). Update the comment reference to match.

---

Quoted 16 lines
  arch/sparc/kernel/pci_common.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
arch/sparc/kernel/pci_common.c +1 -1
index 5eeec9ad6845..2576f4f31309 100644
@@ -361,7 +361,7 @@ void pci_determine_mem_io_space(struct pci_pbm_info *pbm)
  	int i, saw_mem, saw_io;
  	int num_pbm_ranges;
 
-	/* Corresponding generic code in of_pci_get_host_bridge_resources() */
+	/* Corresponds to generic devm_of_pci_get_host_bridge_resources() */
 
  	saw_mem = saw_io = 0;
  	pbm_ranges = of_get_property(pbm->op->dev.of_node, "ranges", &i);
Signature · 2 lines
Sathyanarayanan Kuppuswamy
Linux Kernel Developer
author Applied
#10 lore raw
In reply to Bjorn Helgaas
Quoted 21 lines · Bjorn Helgaas

From: Bjorn Helgaas <[email protected]>

Unexport of_pci_parse_bus_range() since it's only used in drivers/pci/of.c.

Drop the "No bus range found" message since host bridges typically lead to [bus 00-ff], and we already default to that if there is no "bus-range" DT property, so there's no point in requiring it in DT or complaining if it's not there.

Drop bus range parameters from devm_of_pci_get_host_bridge_resources() since they're always the same values.

Update a sparc comment that referred to of_pci_get_host_bridge_resources(), which no longer exists.

Bjorn Helgaas (4):
PCI: Unexport of_pci_parse_bus_range()
PCI: of: Drop 'No bus range found' message
PCI: of: Simplify devm_of_pci_get_host_bridge_resources() interface sparc/PCI: Update reference to devm_of_pci_get_host_bridge_resources()

Quoted 4 lines
 arch/sparc/kernel/pci_common.c |  2 +-
 drivers/pci/of.c               | 22 ++++++++++------------
 drivers/pci/pci.h              |  7 -------
 3 files changed, 11 insertions(+), 20 deletions(-)

Applied to pci/of for v6.14.

Quoted 6 lines

Changes since v1
(https://lore.kernel.org/r/[email protected]):
- Fix compile error
- Drop 'No bus range found' message
- Add Ack from Andreas for the sparc/PCI comment update
- Add Reviewed-by from Rob for the unexport patch