Skip to contentSkip to conversation

PCI: of: update endpoint ranges dynamically

PATCH Superseded Alex Elder 3 participants 14 messages Sep 24 – Oct 26 PCI

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore

Alex Elder

author
#0 lore raw

v3 cover PCI: of: update endpoint ranges dynamically

A PCI endpoint bus is a devicetree construct that allows a PCI endpoint (function) to have sub-devices defined that are accessible in an SoC via the PCI endpoint's BARs. Such a bus is represented as a devicetree sub-node for a PCI function having the name "pci-ep-bus". There can be one or more pci-ep-bus nodes.

A PCI function with a pci-ep-bus devicetree node must also define "#address-cells", "#size-cells", and "ranges" properties, to specify how endpoint bus addresses are translated to the PCI parent bus.

An endpoint bus address has three cells; the first indicates which of the function's BARs the address is associated with, and the other two specify a 64-bit (2 cell) offset within the BAR's region.

BAR base addresses are determined dynamically by the PCI enumeration process, so generally it's not possible to include them in a static devicetree file. When this addressing scheme was introduced, this was not a problem because the devicetree content was generated dynamically--after booting--based on the information (including BAR addresses) available following PCI enumeration.

It is possible (and in some cases, necessary) to define the devicetree nodes that represent PCI devices ahead of time, in a statically-defined devicetree file. In order to support the PCI endpoint bus model in this case it is necessary to dynamically update the static devicetree so that the BAR base addresses assigned during enumeration are reflected in the endpoint's "ranges" property.

This series implements that dynamic update, leveraging the same code used to create the "ranges" property when PCI_DYNAMIC_OF_NODES is enabled. The first patch makes an argument to of_pci_get_addr_flags() optional. The second patch separates the code that dynamically builds the property value into a helper function, and the last arranges for a statically-defined devicetree node for a PCI endpoint to have its "ranges" property updated (if it includes a "pci-ep-bus" sub-node)..

-Alex

Note: this series is built upon these patches:
https://lore.kernel.org/lkml/[email protected]/

The entire series (based on v7.3-rc4 and including those prerequisites) is available here:
https://github.com/riscstar/linux/tree/outgoing/dynamic_ranges-v3

Between version 2 and version 3:
- The ranges property for a PCI endpoint with an existing devicetree node is only updated if its ranges property has an empty value (i.e., it is "ranges;", or is not defined)

Version 2 is available here:
https://lore.kernel.org/lkml/[email protected]/

Between version 1 and version 2:
- Included the first patch (which was previously posted in a different series)
- Modified the last patch so the ranges property is updated only for PCI endpoints having at least one "pci-ep-bus" node
- Rebased on v7.3-rc2 (and the prerequisite series)

Version 1 is available here:
https://lore.kernel.org/lkml/[email protected]/

Alex Elder (3):
PCI: of: make a flags argument optional
PCI: of: introduce of_pci_build_prop_ranges()
PCI: of: introduce of_pci_update_endpoint_node_ranges()

 drivers/pci/of.c          |  94 +++++++++++++++++++++++---
 drivers/pci/of_property.c | 137 +++++++++++++++++++++++++-------------
 drivers/pci/pci.h         |   1 +
 3 files changed, 178 insertions(+), 54 deletions(-)

base-commit: 6ba8359b84d69a07d508693551ed3f661d838e9f

Signature · 1 line
2.53.0
author
#1 lore raw

PATCH v3 1/3 PCI: of: make a flags argument optional

The address of a u32 object is passed to of_pci_get_addr_flags() so it can be filled with the computed flags value.

Allow a null pointer to be passed, so that the validity of the resource's flags can be checked without filling in the flags value.

---
 drivers/pci/of_property.c | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
drivers/pci/of_property.c +5 -3
index 1e5d7dde467b8..a6c0cca986bdc 100644
@@ -82,9 +82,11 @@ static int of_pci_get_addr_flags(const struct resource *res, u32 *flags)
 	else
 		return -EINVAL;
 
-	*flags = FIELD_PREP(OF_PCI_ADDR_FIELD_SS, ss);
-	if (res->flags & IORESOURCE_PREFETCH)
-		*flags |= OF_PCI_ADDR_FIELD_PREFETCH;
+	if (flags) {
+		*flags = FIELD_PREP(OF_PCI_ADDR_FIELD_SS, ss);
+		if (res->flags & IORESOURCE_PREFETCH)
+			*flags |= OF_PCI_ADDR_FIELD_PREFETCH;
+	}
 
 	return 0;
 }
Signature · 1 line
2.53.0
author
#2 lore raw

PATCH v3 2/3 PCI: of: introduce of_pci_build_prop_ranges()

In reply to Alex Elder

Move the bulk of what happens inside of_pci_prop_ranges() into a helper function that builds up the value to be passed to of_changeset_add_prop_u32_array().

This helper will be used in the next commit to build the ranges property for a statically-defined PCI endpoint devicetree node when it has a "pci-ep-bus" sub-node.

---
 drivers/pci/of_property.c | 129 +++++++++++++++++++++++++-------------
 1 file changed, 86 insertions(+), 43 deletions(-)
drivers/pci/of_property.c +86 -43
index a6c0cca986bdc..9f30b3c09a730 100644
@@ -102,57 +102,100 @@ static int of_pci_prop_bus_range(struct pci_dev *pdev,
 					       ARRAY_SIZE(bus_range));
 }
 
+/*
+ * Build a "ranges" property value that defines the mapping between
+ * child and parent PCI address space for each of the given PCI
+ * device's resources.
+ *
+ * Returns a dynamically allocated array of u32 devicetree cells, or
+ * a null pointer if allocation fails.  The cell array is built as a
+ * of_pci_prop_ranges structure consisting of 8 32-bit cells in host
+ * byte order.  It is suitable for use as the value of a PCI device
+ * node "ranges" property passed to of_changeset_add_prop_u32_array().
+ * The total number of cells in the array is returned in *count.
+ *
+ * Caller is responsible for ensuring the returned pointer gets freed.
+ */
+static u32 *of_pci_build_prop_ranges(struct pci_dev *pdev, u32 *count)
+{
+	bool bridge_device = pci_is_bridge(pdev);
+	struct of_pci_range_entry *entries;
+	struct of_pci_range_entry *ep;
+	u32 resource_count = 0;
+	struct resource *res;
+	u32 first;
+	u32 num;
+	u32 i;
+
+	if (bridge_device) {
+		first = PCI_BRIDGE_RESOURCES;
+		num = PCI_BRIDGE_RESOURCE_NUM;
+	} else {
+		first = PCI_STD_RESOURCES;
+		num = PCI_STD_NUM_BARS;
+	}
+
+	/* First count how many resources will get a range property */
+	res = &pdev->resource[first];
+	for (i = 0; i < num; i++, res++)
+		if (resource_size(res) && !of_pci_get_addr_flags(res, NULL))
+			resource_count++;
+
+	entries = kzalloc_objs(*entries, resource_count);
+	if (!entries)
+		return NULL;
+
+	ep = entries;
+	res = &pdev->resource[first];
+	for (i = 0; i < num; i++, res++) {
+		u64 size = resource_size(res);
+		u32 flags;
+
+		if (!size || of_pci_get_addr_flags(res, &flags))
+			continue;
+
+		/* Record the size in the range entry */
+		ep->size[0] = upper_32_bits(size);
+		ep->size[1] = lower_32_bits(size);
+
+		/* Record the parent bus address from the resource */
+		of_pci_set_address(pdev, ep->parent_addr,
+				   pci_bus_address(pdev, first + i),
+				   flags, false);
+
+		/*
+		 * For a bridge device, the child address matches the
+		 * parent address (including its flags cell).  For an
+		 * endpoint device, the (flags) cell contains the BAR
+		 * number, and the two address cells are zero.
+		 */
+		if (bridge_device)
+			memcpy(ep->child_addr, ep->parent_addr,
+			       sizeof(ep->child_addr));
+		else
+			ep->child_addr[0] = i;
+
+		ep++;
+	}
+	*count = resource_count * sizeof(*ep) / sizeof(u32);
+
+	return (u32 *)entries;
+}
+
 static int of_pci_prop_ranges(struct pci_dev *pdev, struct of_changeset *ocs,
 			      struct device_node *np)
 {
 	struct of_pci_range_entry *rp;
-	struct resource *res;
-	int i, j, ret;
-	u32 flags, num;
-	u64 val64;
+	u32 *value;
+	u32 count;
+	int ret;
 
-	if (pci_is_bridge(pdev)) {
-		num = PCI_BRIDGE_RESOURCE_NUM;
-		res = &pdev->resource[PCI_BRIDGE_RESOURCES];
-	} else {
-		num = PCI_STD_NUM_BARS;
-		res = &pdev->resource[PCI_STD_RESOURCES];
-	}
-
-	rp = kzalloc_objs(*rp, num);
-	if (!rp)
+	value = of_pci_build_prop_ranges(pdev, &count);
+	if (!value)
 		return -ENOMEM;
 
-	for (i = 0, j = 0; j < num; j++) {
-		if (!resource_size(&res[j]))
-			continue;
+	ret = of_changeset_add_prop_u32_array(ocs, np, "ranges", value, count);
 
-		if (of_pci_get_addr_flags(&res[j], &flags))
-			continue;
-
-		val64 = pci_bus_address(pdev, &res[j] - pdev->resource);
-		of_pci_set_address(pdev, rp[i].parent_addr, val64, flags,
-				   false);
-		if (pci_is_bridge(pdev)) {
-			memcpy(rp[i].child_addr, rp[i].parent_addr,
-			       sizeof(rp[i].child_addr));
-		} else {
-			/*
-			 * For endpoint device, the lower 64-bits of child
-			 * address is always zero.
-			 */
-			rp[i].child_addr[0] = j;
-		}
-
-		val64 = resource_size(&res[j]);
-		rp[i].size[0] = upper_32_bits(val64);
-		rp[i].size[1] = lower_32_bits(val64);
-
-		i++;
-	}
-
-	ret = of_changeset_add_prop_u32_array(ocs, np, "ranges", (u32 *)rp,
-					      i * sizeof(*rp) / sizeof(u32));
 	kfree(rp);
 
 	return ret;
Signature · 1 line
2.53.0
#3 lore raw

Re: [PATCH v3 2/3] PCI: of: introduce of_pci_build_prop_ranges()

Quoted 46 lines · Alex Elder

Move the bulk of what happens inside of_pci_prop_ranges() into a helper function that builds up the value to be passed to of_changeset_add_prop_u32_array().

This helper will be used in the next commit to build the ranges property for a statically-defined PCI endpoint devicetree node when it has a "pci-ep-bus" sub-node.

---
 drivers/pci/of_property.c | 129 +++++++++++++++++++++++++-------------
 1 file changed, 86 insertions(+), 43 deletions(-)
drivers/pci/of_property.c +25 -0
index a6c0cca986bdc..9f30b3c09a730 100644
@@ -102,57 +102,100 @@ static int of_pci_prop_bus_range(struct pci_dev *pdev,
 					       ARRAY_SIZE(bus_range));
 }
 
+/*
+ * Build a "ranges" property value that defines the mapping between
+ * child and parent PCI address space for each of the given PCI
+ * device's resources.
+ *
+ * Returns a dynamically allocated array of u32 devicetree cells, or
+ * a null pointer if allocation fails.  The cell array is built as a
+ * of_pci_prop_ranges structure consisting of 8 32-bit cells in host
+ * byte order.  It is suitable for use as the value of a PCI device
+ * node "ranges" property passed to of_changeset_add_prop_u32_array().
+ * The total number of cells in the array is returned in *count.
+ *
+ * Caller is responsible for ensuring the returned pointer gets freed.
+ */
+static u32 *of_pci_build_prop_ranges(struct pci_dev *pdev, u32 *count)
+{
+	bool bridge_device = pci_is_bridge(pdev);
+	struct of_pci_range_entry *entries;
+	struct of_pci_range_entry *ep;
+	u32 resource_count = 0;
+	struct resource *res;
+	u32 first;
+	u32 num;
+	u32 i;
+

drivers/pci/of_property.c static int of_pci_prop_bus_range(struct pci_dev *pdev, · line 139

Quoted 10 lines
drivers/pci/of_property.c +10 -0
+	if (bridge_device) {
+		first = PCI_BRIDGE_RESOURCES;
+		num = PCI_BRIDGE_RESOURCE_NUM;
+	} else {
+		first = PCI_STD_RESOURCES;
+		num = PCI_STD_NUM_BARS;
+	}
+
+	/* First count how many resources will get a range property */
+	res = &pdev->resource[first];

pci_resource_n()

drivers/pci/of_property.c static int of_pci_prop_bus_range(struct pci_dev *pdev, · line 141

Quoted 2 lines
drivers/pci/of_property.c +2 -0
+	for (i = 0; i < num; i++, res++)
+		if (resource_size(res) && !of_pci_get_addr_flags(res, NULL))

+ ioport.h

(I know you're mostly moving code around in this change so these missing includes are a pre-existing problem but it would be nice to finally add them.)

drivers/pci/of_property.c static int of_pci_prop_bus_range(struct pci_dev *pdev, · line 144

Quoted 3 lines
drivers/pci/of_property.c +3 -0
+			resource_count++;
+
+	entries = kzalloc_objs(*entries, resource_count);

include

drivers/pci/of_property.c static int of_pci_prop_bus_range(struct pci_dev *pdev, · line 149

Quoted 5 lines
drivers/pci/of_property.c +5 -0
+	if (!entries)
+		return NULL;
+
+	ep = entries;
+	res = &pdev->resource[first];

pci_resource_n()

drivers/pci/of_property.c static int of_pci_prop_bus_range(struct pci_dev *pdev,

Quoted 11 lines
drivers/pci/of_property.c +10 -0
+	for (i = 0; i < num; i++, res++) {
+		u64 size = resource_size(res);
+		u32 flags;
+
+		if (!size || of_pci_get_addr_flags(res, &flags))
+			continue;
+
+		/* Record the size in the range entry */
 
+		ep->size[0] = upper_32_bits(size);
+		ep->size[1] = lower_32_bits(size);

include.

Quoted 73 lines
drivers/pci/of_property.c +31 -34
+
+		/* Record the parent bus address from the resource */
+		of_pci_set_address(pdev, ep->parent_addr,
+				   pci_bus_address(pdev, first + i),
+				   flags, false);
+
+		/*
+		 * For a bridge device, the child address matches the
+		 * parent address (including its flags cell).  For an
+		 * endpoint device, the (flags) cell contains the BAR
+		 * number, and the two address cells are zero.
+		 */
+		if (bridge_device)
+			memcpy(ep->child_addr, ep->parent_addr,
+			       sizeof(ep->child_addr));
+		else
+			ep->child_addr[0] = i;
+
+		ep++;
+	}
+	*count = resource_count * sizeof(*ep) / sizeof(u32);
+
+	return (u32 *)entries;
+}
+
 static int of_pci_prop_ranges(struct pci_dev *pdev, struct of_changeset *ocs,
 			      struct device_node *np)
 {
 	struct of_pci_range_entry *rp;
-	struct resource *res;
-	int i, j, ret;
-	u32 flags, num;
-	u64 val64;
+	u32 *value;
+	u32 count;
+	int ret;
 
-	if (pci_is_bridge(pdev)) {
-		num = PCI_BRIDGE_RESOURCE_NUM;
-		res = &pdev->resource[PCI_BRIDGE_RESOURCES];
-	} else {
-		num = PCI_STD_NUM_BARS;
-		res = &pdev->resource[PCI_STD_RESOURCES];
-	}
-
-	rp = kzalloc_objs(*rp, num);
-	if (!rp)
+	value = of_pci_build_prop_ranges(pdev, &count);
+	if (!value)
 		return -ENOMEM;
 
-	for (i = 0, j = 0; j < num; j++) {
-		if (!resource_size(&res[j]))
-			continue;
+	ret = of_changeset_add_prop_u32_array(ocs, np, "ranges", value, count);
 
-		if (of_pci_get_addr_flags(&res[j], &flags))
-			continue;
-
-		val64 = pci_bus_address(pdev, &res[j] - pdev->resource);
-		of_pci_set_address(pdev, rp[i].parent_addr, val64, flags,
-				   false);
-		if (pci_is_bridge(pdev)) {
-			memcpy(rp[i].child_addr, rp[i].parent_addr,
-			       sizeof(rp[i].child_addr));
-		} else {
-			/*
-			 * For endpoint device, the lower 64-bits of child
-			 * address is always zero.
-			 */
-			rp[i].child_addr[0] = j;
-		}
-

drivers/pci/of_property.c static int of_pci_prop_bus_range(struct pci_dev *pdev, · line 199

Quoted 10 lines
drivers/pci/of_property.c +0 -9
-		val64 = resource_size(&res[j]);
-		rp[i].size[0] = upper_32_bits(val64);
-		rp[i].size[1] = lower_32_bits(val64);
-
-		i++;
-	}
-
-	ret = of_changeset_add_prop_u32_array(ocs, np, "ranges", (u32 *)rp,
-					      i * sizeof(*rp) / sizeof(u32));
 	kfree(rp);

Isn't totally rp unused now so this frees with an uninitialized value?

Quoted 3 lines
drivers/pci/of_property.c +0 -0
 	return ret;
Signature · 1 line
 i.
author
#4 lore raw

Re: [PATCH v3 2/3] PCI: of: introduce of_pci_build_prop_ranges()

Quoted 11 lines · Ilpo Järvinen
Quoted 9 lines · Alex Elder

Move the bulk of what happens inside of_pci_prop_ranges() into a helper function that builds up the value to be passed to of_changeset_add_prop_u32_array().

This helper will be used in the next commit to build the ranges property for a statically-defined PCI endpoint devicetree node when it has a "pci-ep-bus" sub-node.

Thanks for your review. As I comment below, I'll add the #includes you mention, to ensure the symbols used aren't declared by accident.

You commented on patch 3/3 too, but I'll respond here:
you suggested adding an include, and I'll fix that in version 4 of this series.

Quoted 41 lines
Quoted 41 lines
---
  drivers/pci/of_property.c | 129 +++++++++++++++++++++++++-------------
  1 file changed, 86 insertions(+), 43 deletions(-)
drivers/pci/of_property.c +29 -0
index a6c0cca986bdc..9f30b3c09a730 100644
@@ -102,57 +102,100 @@ static int of_pci_prop_bus_range(struct pci_dev *pdev,
  					       ARRAY_SIZE(bus_range));
  }
 
+/*
+ * Build a "ranges" property value that defines the mapping between
+ * child and parent PCI address space for each of the given PCI
+ * device's resources.
+ *
+ * Returns a dynamically allocated array of u32 devicetree cells, or
+ * a null pointer if allocation fails.  The cell array is built as a
+ * of_pci_prop_ranges structure consisting of 8 32-bit cells in host
+ * byte order.  It is suitable for use as the value of a PCI device
+ * node "ranges" property passed to of_changeset_add_prop_u32_array().
+ * The total number of cells in the array is returned in *count.
+ *
+ * Caller is responsible for ensuring the returned pointer gets freed.
+ */
+static u32 *of_pci_build_prop_ranges(struct pci_dev *pdev, u32 *count)
+{
+	bool bridge_device = pci_is_bridge(pdev);
+	struct of_pci_range_entry *entries;
+	struct of_pci_range_entry *ep;
+	u32 resource_count = 0;
+	struct resource *res;
+	u32 first;
+	u32 num;
+	u32 i;
+
+	if (bridge_device) {
+		first = PCI_BRIDGE_RESOURCES;
+		num = PCI_BRIDGE_RESOURCE_NUM;
+	} else {
Quoted 8 lines

drivers/pci/of_property.c static int of_pci_prop_bus_range(struct pci_dev *pdev, · line 139

Quoted 6 lines
drivers/pci/of_property.c +6 -0
+		first = PCI_STD_RESOURCES;
+		num = PCI_STD_NUM_BARS;
+	}
+
+	/* First count how many resources will get a range property */
+	res = &pdev->resource[first];

pci_resource_n()

That's better. I'll use that.

Quoted 9 lines

drivers/pci/of_property.c static int of_pci_prop_bus_range(struct pci_dev *pdev, · line 141

Quoted 3 lines
drivers/pci/of_property.c +2 -0
+	for (i = 0; i < num; i++, res++)
+		if (resource_size(res) && !of_pci_get_addr_flags(res, NULL))

+ ioport.h

(I know you're mostly moving code around in this change so these missing includes are a pre-existing problem but it would be nice to finally add them.)

I'll gladly add this and the others you mention below. I like to include whatever I need but I currently only do that by manually scanning through (and fixing it when there's a warning).

Quoted 106 lines

drivers/pci/of_property.c static int of_pci_prop_bus_range(struct pci_dev *pdev, · line 144

Quoted 4 lines
drivers/pci/of_property.c +3 -0
+			resource_count++;
+
+	entries = kzalloc_objs(*entries, resource_count);

include

drivers/pci/of_property.c static int of_pci_prop_bus_range(struct pci_dev *pdev, · line 149

Quoted 5 lines
drivers/pci/of_property.c +5 -0
+	if (!entries)
+		return NULL;
+
+	ep = entries;
+	res = &pdev->resource[first];

pci_resource_n()

drivers/pci/of_property.c static int of_pci_prop_bus_range(struct pci_dev *pdev,

Quoted 11 lines
drivers/pci/of_property.c +10 -0
+	for (i = 0; i < num; i++, res++) {
+		u64 size = resource_size(res);
+		u32 flags;
+
+		if (!size || of_pci_get_addr_flags(res, &flags))
+			continue;
+
+		/* Record the size in the range entry */
 
+		ep->size[0] = upper_32_bits(size);
+		ep->size[1] = lower_32_bits(size);

include.

Quoted 77 lines
drivers/pci/of_property.c +31 -38
+
+		/* Record the parent bus address from the resource */
+		of_pci_set_address(pdev, ep->parent_addr,
+				   pci_bus_address(pdev, first + i),
+				   flags, false);
+
+		/*
+		 * For a bridge device, the child address matches the
+		 * parent address (including its flags cell).  For an
+		 * endpoint device, the (flags) cell contains the BAR
+		 * number, and the two address cells are zero.
+		 */
+		if (bridge_device)
+			memcpy(ep->child_addr, ep->parent_addr,
+			       sizeof(ep->child_addr));
+		else
+			ep->child_addr[0] = i;
+
+		ep++;
+	}
+	*count = resource_count * sizeof(*ep) / sizeof(u32);
+
+	return (u32 *)entries;
+}
+
  static int of_pci_prop_ranges(struct pci_dev *pdev, struct of_changeset *ocs,
  			      struct device_node *np)
  {
  	struct of_pci_range_entry *rp;
-	struct resource *res;
-	int i, j, ret;
-	u32 flags, num;
-	u64 val64;
+	u32 *value;
+	u32 count;
+	int ret;
 
-	if (pci_is_bridge(pdev)) {
-		num = PCI_BRIDGE_RESOURCE_NUM;
-		res = &pdev->resource[PCI_BRIDGE_RESOURCES];
-	} else {
-		num = PCI_STD_NUM_BARS;
-		res = &pdev->resource[PCI_STD_RESOURCES];
-	}
-
-	rp = kzalloc_objs(*rp, num);
-	if (!rp)
+	value = of_pci_build_prop_ranges(pdev, &count);
+	if (!value)
  		return -ENOMEM;
 
-	for (i = 0, j = 0; j < num; j++) {
-		if (!resource_size(&res[j]))
-			continue;
+	ret = of_changeset_add_prop_u32_array(ocs, np, "ranges", value, count);
 
-		if (of_pci_get_addr_flags(&res[j], &flags))
-			continue;
-
-		val64 = pci_bus_address(pdev, &res[j] - pdev->resource);
-		of_pci_set_address(pdev, rp[i].parent_addr, val64, flags,
-				   false);
-		if (pci_is_bridge(pdev)) {
-			memcpy(rp[i].child_addr, rp[i].parent_addr,
-			       sizeof(rp[i].child_addr));
-		} else {
-			/*
-			 * For endpoint device, the lower 64-bits of child
-			 * address is always zero.
-			 */
-			rp[i].child_addr[0] = j;
-		}
-
-		val64 = resource_size(&res[j]);
-		rp[i].size[0] = upper_32_bits(val64);
-		rp[i].size[1] = lower_32_bits(val64);
-
Quoted 8 lines

drivers/pci/of_property.c static int of_pci_prop_bus_range(struct pci_dev *pdev, · line 199

Quoted 6 lines
drivers/pci/of_property.c +0 -5
-		i++;
-	}
-
-	ret = of_changeset_add_prop_u32_array(ocs, np, "ranges", (u32 *)rp,
-					      i * sizeof(*rp) / sizeof(u32));
  	kfree(rp);

Isn't totally rp unused now so this frees with an uninitialized value?

Wow, you're right. This line needs to go too.

-Alex

Quoted 4 lines
Quoted 3 lines
drivers/pci/of_property.c +0 -0
  	return ret;
author
#5 lore raw

PATCH v3 3/3 PCI: of: introduce of_pci_update_endpoint_node_ranges()

In reply to Alex Elder

Commit 407d1a51921e9 ("PCI: Create device tree node for bridge") introduced the PCI_DYNAMIC_OF_NODES Kconfig option, which creates a devicetree node for a PCI bridge as part of pci_bus_add_device(). Its successor commit ae9813db1dc5a ("PCI: Add quirks to generate device tree node for Xilinx Alveo U50") shows how to use a PCI final fixup quirk to also create a devicetree node for a non-bridge PCI device. In both cases, of_pci_make_dev_node() uses an OF changeset to dynamically create a node populated with appropriate properties and apply it to the live devicetree.

The dynamic devicetree node for a PCI device will include a "ranges" property, and a new type of 3-cell address is introduced for use within an endpoint. The endpoint's ranges property will contain a range entry for each of the endpoint's BARs. The "child address" portion of each range will use the BAR number in the "flags" (first) cell in the address. This allows addresses within the endpoint to be expressed relative to whatever address gets assigned to each BAR.

Unfortunately, if a PCI endpoint device had a devicetree node set up statically, its "ranges" property (if present) will be static, and it cannot contain the addresses assigned to the endpoint's BARs during enumeration.

This means that the "BAR number" based addressing scheme doesn't work for PCI endpoints whose devicetree nodes are created statically.

To remedy this, modify of_pci_make_dev_node() to dynamically create a "ranges" property even if the device already has a devicetree node--just as is done when the endpoint has none. A few conditions:
- A PCI bridge node's ranges property is never updated
- If a PCI endpoint node defines a ranges property with a non-empty value (i.e., it's not just "ranges;"), that ranges property is preserved

Otherwise a new ranges property is created using assigned addresses, and it replaces (or adds) that property to the PCI endpoint node.

As a result, "BAR number" addresses work correctly even when the endpoint's devicetree node is created statically.

---
v3: - Don't update an existing non-empty ranges property

 drivers/pci/of.c          | 94 +++++++++++++++++++++++++++++++++++----
 drivers/pci/of_property.c |  2 +-
 drivers/pci/pci.h         |  1 +
 3 files changed, 88 insertions(+), 9 deletions(-)
drivers/pci/of.c +86 -8
index 5a040ed836744..7fb5e0351719c 100644
@@ -742,20 +742,98 @@ void of_pci_remove_node(struct pci_dev *pdev)
 	of_node_put(np);
 }
 
+/* Returns true if the ranges property was added or updated successfully */
+static bool of_pci_update_endpoint_node_ranges(struct pci_dev *pdev)
+{
+	struct device_node *np = pci_device_to_OF_node(pdev);
+	struct property *prop;
+	u32 *value;
+	u32 size;
+
+	prop = kzalloc_obj(*prop);
+	if (!prop)
+		return false;
+
+	value = of_pci_build_prop_ranges(pdev, &size);
+	if (!value) {
+		kfree(prop);
+		return false;
+	}
+
+	prop->name = "ranges";
+	prop->length = size * sizeof(u32);
+	prop->value = value;
+
+	/* The property value needs to be in big-endian byte order */
+	while (size--)
+		cpu_to_be32s(value++);
+
+	/* of_update_property() consumes the allocated property */
+	of_update_property(np, prop);
+
+	return true;
+}
+
+/*
+ * Create a devicetree node for a PCI device.  If the device is a bridge
+ * and it already has a devicetree node, there's nothing further to do.
+ * If it is a bridge without an existing devicetree node, one is created
+ * dynamically.
+ *
+ * This function can also be called (via PCI quirk) for a PCI endpoint
+ * (function) that implements a PCI endpoint bus.  As with a PCI bridge,
+ * if the endpoint has no existing devicetree node, one is created
+ * dynamically.  The node will include a ranges property that maps
+ * BAR-relative addresses in the child to the PCI address ranges
+ * assigned to the PCI endpoint BARs.
+ *
+ * If an endpoint already has a devicetree node, and it includes a
+ * "pci-ep-bus" sub-node, its ranges property must still be dynamically
+ * populated so that it can take into account the BAR ranges assigned
+ * during PCI enumeration.
+ */
 void of_pci_make_dev_node(struct pci_dev *pdev)
 {
-	struct device_node *ppnode, *np = NULL;
+	struct device_node *np = pci_device_to_OF_node(pdev);
+	struct device *dev = &pdev->dev;
+	struct device_node *ppnode;
+	struct of_changeset *cset;
 	const char *pci_type;
-	struct of_changeset *cset;
 	const char *name;
 	int ret;
 
-	/*
-	 * If there is already a device tree node linked to this device,
-	 * return immediately.
-	 */
-	if (pci_device_to_OF_node(pdev))
+	/* See if the PCI device already has a devicetree node */
+	if (np) {
+		struct device_node *child;
+		unsigned int rlen = 0;
+
+		/* Nothing further needed for a bridge */
+		if (pci_is_bridge(pdev))
+			return;
+
+		/*
+		 * A ranges property is only needed if the endpoint's
+		 * devicetree node includes a "pci-ep-bus" sub-node.
+		 */
+		child = of_get_child_by_name(np, "pci-ep-bus");
+		if (!child)
+			return;
+		of_node_put(child);
+
+		/* If the ranges property is non-empty, just keep it.*/
+		if (of_get_property(np, "ranges", &rlen) && rlen)
+			return;
+
+		/*
+		 * Otherwise create a ranges property, defining an entry for
+		 * each BAR, and map BAR offsets to the PCI bus address based
+		 * on the BAR's assigned range.
+		 */
+		if (!of_pci_update_endpoint_node_ranges(pdev))
+			dev_err(dev, "failed to update ranges property\n");
+
 		return;
+	}
 
 	/* Check if there is device tree node for parent device */
 	if (!pdev->bus->self)
@@ -794,7 +872,7 @@ void of_pci_make_dev_node(struct pci_dev *pdev)
 
 	np->data = cset;
 
-	ret = device_add_of_node(&pdev->dev, np);
+	ret = device_add_of_node(dev, np);
 	if (ret)
 		goto out_revert_cset;
 
drivers/pci/of_property.c +1 -1
index 9f30b3c09a730..8e1548c4aac3c 100644
@@ -116,7 +116,7 @@ static int of_pci_prop_bus_range(struct pci_dev *pdev,
  *
  * Caller is responsible for ensuring the returned pointer gets freed.
  */
-static u32 *of_pci_build_prop_ranges(struct pci_dev *pdev, u32 *count)
+u32 *of_pci_build_prop_ranges(struct pci_dev *pdev, u32 *count)
 {
 	bool bridge_device = pci_is_bridge(pdev);
 	struct of_pci_range_entry *entries;
drivers/pci/pci.h +1 -0
index 2e33d3bd4b0ba..1461e52777532 100644
@@ -1318,6 +1318,7 @@ struct of_changeset;
 #ifdef CONFIG_PCI_DYNAMIC_OF_NODES
 void of_pci_make_dev_node(struct pci_dev *pdev);
 void of_pci_remove_node(struct pci_dev *pdev);
+u32 *of_pci_build_prop_ranges(struct pci_dev *pdev, u32 *count);
 int of_pci_add_properties(struct pci_dev *pdev, struct of_changeset *ocs,
 			  struct device_node *np);
 void of_pci_make_host_bridge_node(struct pci_host_bridge *bridge);
Signature · 1 line
2.53.0
#6 lore raw

Re: [PATCH v3 3/3] PCI: of: introduce of_pci_update_endpoint_node_ranges()

Quoted 72 lines · Alex Elder

Commit 407d1a51921e9 ("PCI: Create device tree node for bridge") introduced the PCI_DYNAMIC_OF_NODES Kconfig option, which creates a devicetree node for a PCI bridge as part of pci_bus_add_device(). Its successor commit ae9813db1dc5a ("PCI: Add quirks to generate device tree node for Xilinx Alveo U50") shows how to use a PCI final fixup quirk to also create a devicetree node for a non-bridge PCI device. In both cases, of_pci_make_dev_node() uses an OF changeset to dynamically create a node populated with appropriate properties and apply it to the live devicetree.

The dynamic devicetree node for a PCI device will include a "ranges" property, and a new type of 3-cell address is introduced for use within an endpoint. The endpoint's ranges property will contain a range entry for each of the endpoint's BARs. The "child address" portion of each range will use the BAR number in the "flags" (first) cell in the address. This allows addresses within the endpoint to be expressed relative to whatever address gets assigned to each BAR.

Unfortunately, if a PCI endpoint device had a devicetree node set up statically, its "ranges" property (if present) will be static, and it cannot contain the addresses assigned to the endpoint's BARs during enumeration.

This means that the "BAR number" based addressing scheme doesn't work for PCI endpoints whose devicetree nodes are created statically.

To remedy this, modify of_pci_make_dev_node() to dynamically create a "ranges" property even if the device already has a devicetree node--just as is done when the endpoint has none. A few conditions:
- A PCI bridge node's ranges property is never updated
- If a PCI endpoint node defines a ranges property with a non-empty value (i.e., it's not just "ranges;"), that ranges property is preserved

Otherwise a new ranges property is created using assigned addresses, and it replaces (or adds) that property to the PCI endpoint node.

As a result, "BAR number" addresses work correctly even when the endpoint's devicetree node is created statically.

---
v3: - Don't update an existing non-empty ranges property

 drivers/pci/of.c          | 94 +++++++++++++++++++++++++++++++++++----
 drivers/pci/of_property.c |  2 +-
 drivers/pci/pci.h         |  1 +
 3 files changed, 88 insertions(+), 9 deletions(-)
drivers/pci/of.c +15 -0
index 5a040ed836744..7fb5e0351719c 100644
@@ -742,20 +742,98 @@ void of_pci_remove_node(struct pci_dev *pdev)
 	of_node_put(np);
 }
 
+/* Returns true if the ranges property was added or updated successfully */
+static bool of_pci_update_endpoint_node_ranges(struct pci_dev *pdev)
+{
+	struct device_node *np = pci_device_to_OF_node(pdev);
+	struct property *prop;
+	u32 *value;
+	u32 size;
+
+	prop = kzalloc_obj(*prop);
+	if (!prop)
+		return false;
+
+	value = of_pci_build_prop_ranges(pdev, &size);
+	if (!value) {
+		kfree(prop);

drivers/pci/of.c void of_pci_remove_node(struct pci_dev *pdev) · line 769

Quoted 10 lines
drivers/pci/of.c +10 -0
+		return false;
+	}
+
+	prop->name = "ranges";
+	prop->length = size * sizeof(u32);
+	prop->value = value;
+
+	/* The property value needs to be in big-endian byte order */
+	while (size--)
+		cpu_to_be32s(value++);

Add include.

Signature · 1 line
 i.
Quoted 112 lines
drivers/pci/of.c +61 -8
+
+	/* of_update_property() consumes the allocated property */
+	of_update_property(np, prop);
+
+	return true;
+}
+
+/*
+ * Create a devicetree node for a PCI device.  If the device is a bridge
+ * and it already has a devicetree node, there's nothing further to do.
+ * If it is a bridge without an existing devicetree node, one is created
+ * dynamically.
+ *
+ * This function can also be called (via PCI quirk) for a PCI endpoint
+ * (function) that implements a PCI endpoint bus.  As with a PCI bridge,
+ * if the endpoint has no existing devicetree node, one is created
+ * dynamically.  The node will include a ranges property that maps
+ * BAR-relative addresses in the child to the PCI address ranges
+ * assigned to the PCI endpoint BARs.
+ *
+ * If an endpoint already has a devicetree node, and it includes a
+ * "pci-ep-bus" sub-node, its ranges property must still be dynamically
+ * populated so that it can take into account the BAR ranges assigned
+ * during PCI enumeration.
+ */
 void of_pci_make_dev_node(struct pci_dev *pdev)
 {
-	struct device_node *ppnode, *np = NULL;
+	struct device_node *np = pci_device_to_OF_node(pdev);
+	struct device *dev = &pdev->dev;
+	struct device_node *ppnode;
+	struct of_changeset *cset;
 	const char *pci_type;
-	struct of_changeset *cset;
 	const char *name;
 	int ret;
 
-	/*
-	 * If there is already a device tree node linked to this device,
-	 * return immediately.
-	 */
-	if (pci_device_to_OF_node(pdev))
+	/* See if the PCI device already has a devicetree node */
+	if (np) {
+		struct device_node *child;
+		unsigned int rlen = 0;
+
+		/* Nothing further needed for a bridge */
+		if (pci_is_bridge(pdev))
+			return;
+
+		/*
+		 * A ranges property is only needed if the endpoint's
+		 * devicetree node includes a "pci-ep-bus" sub-node.
+		 */
+		child = of_get_child_by_name(np, "pci-ep-bus");
+		if (!child)
+			return;
+		of_node_put(child);
+
+		/* If the ranges property is non-empty, just keep it.*/
+		if (of_get_property(np, "ranges", &rlen) && rlen)
+			return;
+
+		/*
+		 * Otherwise create a ranges property, defining an entry for
+		 * each BAR, and map BAR offsets to the PCI bus address based
+		 * on the BAR's assigned range.
+		 */
+		if (!of_pci_update_endpoint_node_ranges(pdev))
+			dev_err(dev, "failed to update ranges property\n");
+
 		return;
+	}
 
 	/* Check if there is device tree node for parent device */
 	if (!pdev->bus->self)
@@ -794,7 +872,7 @@ void of_pci_make_dev_node(struct pci_dev *pdev)
 
 	np->data = cset;
 
-	ret = device_add_of_node(&pdev->dev, np);
+	ret = device_add_of_node(dev, np);
 	if (ret)
 		goto out_revert_cset;
 
drivers/pci/of_property.c +1 -1
index 9f30b3c09a730..8e1548c4aac3c 100644
@@ -116,7 +116,7 @@ static int of_pci_prop_bus_range(struct pci_dev *pdev,
  *
  * Caller is responsible for ensuring the returned pointer gets freed.
  */
-static u32 *of_pci_build_prop_ranges(struct pci_dev *pdev, u32 *count)
+u32 *of_pci_build_prop_ranges(struct pci_dev *pdev, u32 *count)
 {
 	bool bridge_device = pci_is_bridge(pdev);
 	struct of_pci_range_entry *entries;
drivers/pci/pci.h +1 -0
index 2e33d3bd4b0ba..1461e52777532 100644
@@ -1318,6 +1318,7 @@ struct of_changeset;
 #ifdef CONFIG_PCI_DYNAMIC_OF_NODES
 void of_pci_make_dev_node(struct pci_dev *pdev);
 void of_pci_remove_node(struct pci_dev *pdev);
+u32 *of_pci_build_prop_ranges(struct pci_dev *pdev, u32 *count);
 int of_pci_add_properties(struct pci_dev *pdev, struct of_changeset *ocs,
 			  struct device_node *np);
 void of_pci_make_host_bridge_node(struct pci_host_bridge *bridge);
author
#7 lore raw
In reply to Alex Elder
Quoted 14 lines · Alex Elder

A PCI endpoint bus is a devicetree construct that allows a PCI endpoint (function) to have sub-devices defined that are accessible in an SoC via the PCI endpoint's BARs. Such a bus is represented as a devicetree sub-node for a PCI function having the name "pci-ep-bus". There can be one or more pci-ep-bus nodes.

A PCI function with a pci-ep-bus devicetree node must also define "#address-cells", "#size-cells", and "ranges" properties, to specify how endpoint bus addresses are translated to the PCI parent bus.

An endpoint bus address has three cells; the first indicates which of the function's BARs the address is associated with, and the other two specify a 64-bit (2 cell) offset within the BAR's region.

Quoted 6 lines

BAR base addresses are determined dynamically by the PCI enumeration process, so generally it's not possible to include them in a static devicetree file. When this addressing scheme was introduced, this was not a problem because the devicetree content was generated dynamically--after booting--based on the information (including BAR addresses) available following PCI enumeration.

The PCI endpoint bus model implements an addressing scheme that allows sub-devices to specify addresses relative to the base of an endpoint BAR. This avoids needing to know the address assigned to the BAR, which cannot be known until runtime.

For users (such as the LAN966x) that rely on dynamically-created devicetree nodes for PCI endpoints, the generated ranges property already incorporates the assigned addresses.

However if a PCI endpoint is defined in devicetree statically (as
in the case for the Toshiba TC9564), its ranges property must get updated at runtime to reflect the addresses assigned by the PCI enumeration process.

The TC9564 requires the functionality provided by this series for it to be able to use the PCI endpoint bus model.

==> Would someone please consider and comment on this change?

It reuses the code that generates the ranges property for dynamically-created devicetree nodes, to ensure that the static and dynamic cases are consistent.

Thank you.

-Alex

Quoted 55 lines

It is possible (and in some cases, necessary) to define the devicetree nodes that represent PCI devices ahead of time, in a statically-defined devicetree file. In order to support the PCI endpoint bus model in this case it is necessary to dynamically update the static devicetree so that the BAR base addresses assigned during enumeration are reflected in the endpoint's "ranges" property.

This series implements that dynamic update, leveraging the same code used to create the "ranges" property when PCI_DYNAMIC_OF_NODES is enabled. The first patch makes an argument to of_pci_get_addr_flags() optional. The second patch separates the code that dynamically builds the property value into a helper function, and the last arranges for a statically-defined devicetree node for a PCI endpoint to have its "ranges" property updated (if it includes a "pci-ep-bus" sub-node)..

-Alex

Note: this series is built upon these patches:

   https://lore.kernel.org/lkml/[email protected]/

The entire series (based on v7.3-rc4 and including those prerequisites) is available here:
https://github.com/riscstar/linux/tree/outgoing/dynamic_ranges-v3

Between version 2 and version 3:
- The ranges property for a PCI endpoint with an existing devicetree node is only updated if its ranges property has an empty value (i.e., it is "ranges;", or is not defined)

Version 2 is available here:

   https://lore.kernel.org/lkml/[email protected]/

Between version 1 and version 2:
- Included the first patch (which was previously posted in a different series)
- Modified the last patch so the ranges property is updated only for PCI endpoints having at least one "pci-ep-bus" node
- Rebased on v7.3-rc2 (and the prerequisite series)

Version 1 is available here:

   https://lore.kernel.org/lkml/[email protected]/

Alex Elder (3):
PCI: of: make a flags argument optional
PCI: of: introduce of_pci_build_prop_ranges()
PCI: of: introduce of_pci_update_endpoint_node_ranges()

  drivers/pci/of.c          |  94 +++++++++++++++++++++++---
  drivers/pci/of_property.c | 137 +++++++++++++++++++++++++-------------
  drivers/pci/pci.h         |   1 +
  3 files changed, 178 insertions(+), 54 deletions(-)

base-commit: 6ba8359b84d69a07d508693551ed3f661d838e9f

#8 lore raw
In reply to Alex Elder

Hi Alex,

Quoted 69 lines · Alex Elder

A PCI endpoint bus is a devicetree construct that allows a PCI endpoint (function) to have sub-devices defined that are accessible in an SoC via the PCI endpoint's BARs. Such a bus is represented as a devicetree sub-node for a PCI function having the name "pci-ep-bus". There can be one or more pci-ep-bus nodes.

A PCI function with a pci-ep-bus devicetree node must also define "#address-cells", "#size-cells", and "ranges" properties, to specify how endpoint bus addresses are translated to the PCI parent bus.

An endpoint bus address has three cells; the first indicates which of the function's BARs the address is associated with, and the other two specify a 64-bit (2 cell) offset within the BAR's region.

BAR base addresses are determined dynamically by the PCI enumeration process, so generally it's not possible to include them in a static devicetree file. When this addressing scheme was introduced, this was not a problem because the devicetree content was generated dynamically--after booting--based on the information (including BAR addresses) available following PCI enumeration.

It is possible (and in some cases, necessary) to define the devicetree nodes that represent PCI devices ahead of time, in a statically-defined devicetree file. In order to support the PCI endpoint bus model in this case it is necessary to dynamically update the static devicetree so that the BAR base addresses assigned during enumeration are reflected in the endpoint's "ranges" property.

This series implements that dynamic update, leveraging the same code used to create the "ranges" property when PCI_DYNAMIC_OF_NODES is enabled. The first patch makes an argument to of_pci_get_addr_flags() optional. The second patch separates the code that dynamically builds the property value into a helper function, and the last arranges for a statically-defined devicetree node for a PCI endpoint to have its "ranges" property updated (if it includes a "pci-ep-bus" sub-node)..

-Alex

Note: this series is built upon these patches:
https://lore.kernel.org/lkml/[email protected]/

The entire series (based on v7.3-rc4 and including those prerequisites) is available here:
https://github.com/riscstar/linux/tree/outgoing/dynamic_ranges-v3

Between version 2 and version 3:
- The ranges property for a PCI endpoint with an existing devicetree node is only updated if its ranges property has an empty value (i.e., it is "ranges;", or is not defined)

Version 2 is available here:
https://lore.kernel.org/lkml/[email protected]/

Between version 1 and version 2:
- Included the first patch (which was previously posted in a different series)
- Modified the last patch so the ranges property is updated only for PCI endpoints having at least one "pci-ep-bus" node
- Rebased on v7.3-rc2 (and the prerequisite series)

Version 1 is available here:
https://lore.kernel.org/lkml/[email protected]/

Alex Elder (3):
PCI: of: make a flags argument optional
PCI: of: introduce of_pci_build_prop_ranges()
PCI: of: introduce of_pci_update_endpoint_node_ranges()

Quoted 10 lines
 drivers/pci/of.c          |  94 +++++++++++++++++++++++---
 drivers/pci/of_property.c | 137 +++++++++++++++++++++++++-------------
 drivers/pci/pci.h         |   1 +
 3 files changed, 178 insertions(+), 54 deletions(-)

base-commit: 6ba8359b84d69a07d508693551ed3f661d838e9f

Signature · 1 line
2.53.0

After a quick test, it seems that it's not working out of the box on my RPi5. Let me investigate a bit to see what's wrong.

Many thanks,
Andrea

author
#9 lore raw
Quoted 2 lines · Andrea della Porta

After a quick test, it seems that it's not working out of the box on my RPi5. Let me investigate a bit to see what's wrong.

THANK YOU FOR TESTING THIS!!!

My hope was that the recent change (to avoid doing any updating of ranges property unless it was found to be "empty") would avoid any trouble with the RPi5.

I'm eager to hear what more you find. Please let me know if I can be of any other help.

-Alex

#10 lore raw

Hi Alex,

Quoted 3 lines · Alex Elder
Quoted 2 lines · Andrea della Porta

After a quick test, it seems that it's not working out of the box on my RPi5. Let me investigate a bit to see what's wrong.

I stand corrected: it works perfectly. So:

I think it should even be possible to tweak the static RPi5 DT in order to make it work dynamically with your patch. Can you please provide the relevant PCI DT nodes (from PCI controller to pci-ep-bus endpoint) from the output of:

dtc -I fs -O dts /sys/firmware/devicetree/base/

taken on your reference board?

Many thanks for your work,
Andrea

Quoted 11 lines

THANK YOU FOR TESTING THIS!!!

My hope was that the recent change (to avoid doing any updating of ranges property unless it was found to be "empty") would avoid any trouble with the RPi5.

I'm eager to hear what more you find. Please let me know if I can be of any other help.

-Alex

author
#11 lore raw
Quoted 10 lines · Andrea della Porta

Hi Alex,

Quoted 3 lines · Alex Elder
Quoted 2 lines · Andrea della Porta

After a quick test, it seems that it's not working out of the box on my RPi5. Let me investigate a bit to see what's wrong.

I stand corrected: it works perfectly. So:

Sorry for the delay. I'll add the above to v4.

Quoted 2 lines

I think it should even be possible to tweak the static RPi5 DT in order to make it work dynamically with your patch. Can

I suspected that your static definitions *happen* to work, but I never took the time to confirm that and understand why.

Quoted 6 lines

you please provide the relevant PCI DT nodes (from PCI controller to pci-ep-bus endpoint) from the output of:

dtc -I fs -O dts /sys/firmware/devicetree/base/

taken on your reference board?

I'll send you that in a private message.

Thanks again.

-Alex

Quoted 16 lines

Many thanks for your work,
Andrea

Quoted 11 lines

THANK YOU FOR TESTING THIS!!!

My hope was that the recent change (to avoid doing any updating of ranges property unless it was found to be "empty") would avoid any trouble with the RPi5.

I'm eager to hear what more you find. Please let me know if I can be of any other help.

-Alex

#12 lore raw

Hi Alex,

Quoted 12 lines · Alex Elder
Quoted 10 lines · Andrea della Porta

Hi Alex,

Quoted 3 lines · Alex Elder
Quoted 2 lines · Andrea della Porta

After a quick test, it seems that it's not working out of the box on my RPi5. Let me investigate a bit to see what's wrong.

I stand corrected: it works perfectly. So:

Quoted 8 lines

Sorry for the delay. I'll add the above to v4.

Quoted 2 lines

I think it should even be possible to tweak the static RPi5 DT in order to make it work dynamically with your patch. Can

I suspected that your static definitions *happen* to work, but I never took the time to confirm that and understand why.

As per your design and as expected, the static range is preserved since the conditionals make the function exit if the device is a bridge or it already has a ranges property,o it all works as before. Right now the RP1 is acknowledged as a PCI bridge.
what I meant is that we can maybe amend the RPi5 DT getting rid of the static ranges and tweaking the reg offset in the subperipheral nodes. I will do some experiments with this, but not now in order to not clash with current downstream DT. Definitely a thing I'd like to try in teh long run, though.

Cheers,
Andrea

Quoted 31 lines
Quoted 7 lines

you please provide the relevant PCI DT nodes (from PCI controller to pci-ep-bus endpoint) from the output of:

dtc -I fs -O dts /sys/firmware/devicetree/base/

taken on your reference board?

I'll send you that in a private message.

Thanks again.

-Alex

Quoted 16 lines

Many thanks for your work,
Andrea

Quoted 11 lines

THANK YOU FOR TESTING THIS!!!

My hope was that the recent change (to avoid doing any updating of ranges property unless it was found to be "empty") would avoid any trouble with the RPi5.

I'm eager to hear what more you find. Please let me know if I can be of any other help.

-Alex

#13 lore raw

Hi,

Quoted 24 lines · Andrea della Porta

Hi Alex,

Quoted 12 lines · Alex Elder
Quoted 10 lines · Andrea della Porta

Hi Alex,

Quoted 3 lines · Alex Elder
Quoted 2 lines · Andrea della Porta

After a quick test, it seems that it's not working out of the box on my RPi5. Let me investigate a bit to see what's wrong.

I stand corrected: it works perfectly. So:

Quoted 8 lines

Sorry for the delay. I'll add the above to v4.

Quoted 2 lines

I think it should even be possible to tweak the static RPi5 DT in order to make it work dynamically with your patch. Can

I suspected that your static definitions *happen* to work, but I never took the time to confirm that and understand why.

Quoted 9 lines

As per your design and as expected, the static range is preserved since the conditionals make the function exit if the device is a bridge or it already has a ranges property,o it all works as before. Right now the RP1 is acknowledged as a PCI bridge.
what I meant is that we can maybe amend the RPi5 DT getting rid of the static ranges and tweaking the reg offset in the subperipheral nodes. I will do some experiments with this, but not now in order to not clash with current downstream DT. Definitely a thing I'd like to try in teh long run, though.

After some experiments, invoking of_pci_make_dev_node() as quirks for RP1 PCI endpoint and getting rid of the ranges property in the endpoint node makes everything working fine, which is very nice.

Regards,
Andrea

Quoted 35 lines

Cheers,
Andrea

Quoted 31 lines
Quoted 7 lines

you please provide the relevant PCI DT nodes (from PCI controller to pci-ep-bus endpoint) from the output of:

dtc -I fs -O dts /sys/firmware/devicetree/base/

taken on your reference board?

I'll send you that in a private message.

Thanks again.

-Alex

Quoted 16 lines

Many thanks for your work,
Andrea

Quoted 11 lines

THANK YOU FOR TESTING THIS!!!

My hope was that the recent change (to avoid doing any updating of ranges property unless it was found to be "empty") would avoid any trouble with the RPi5.

I'm eager to hear what more you find. Please let me know if I can be of any other help.

-Alex