Skip to contentSkip to conversation

of/pci: Provide common support for PCI DT parsing

PATCH Superseded Andrew Murray 5 participants 26 messages Apr 16, 2013 – Apr 22, 2013

Subsystems (6)
PowerPC PCI MIPS Arm Samsung Exynos +2 more subsystems

v7 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v7 cover of/pci: Provide common support for PCI DT parsing

This patchset factors out duplicated code associated with parsing PCI DT "ranges" properties across the architectures and introduces a "ranges" parser. This parser "of_pci_range_parser" can be used directly by ARM host bridge drivers enabling them to obtain ranges from device trees.

I've included the Reviewed-by and Tested-by's received from v5/v6 in this patchset, earlier versions of this patchset (v3) have been tested-by:

Thierry Reding <[email protected]>
Jingoo Han <[email protected]>

I've tested that this patchset builds and runs on ARM and that it builds on PowerPC and x86_64.

Compared to the v6 sent by Andrew Murray, the following changes have been made in response to build errors/warnings:

* Inclusion of linux/of_address.h in of_pci.c as suggested by Michal Simek to prevent compilation failures on Microblaze (and others) and his ack.

* Use of externs, static inlines and a typo in linux/of_address.h in response to linker errors (multiple defination) on x86_64 as spotted by a kbuild test robot on (jcooper/linux.git mvebu/drivers)

* Add EXPORT_SYMBOL_GPL to of_pci_range_parser function to be consistent with of_pci_process_ranges function

Compared to the v5 sent by Andrew Murray, the following changes have been made:

* Use of CONFIG_64BIT instead of CONFIG_[a32bitarch] as suggested by Rob Herring in drivers/of/of_pci.c

* Added forward declaration of struct pci_controller in linux/of_pci.h to prevent compiler warning as suggested by Thomas Petazzoni

* Improved error checking (!range check), removal of unnecessary be32_to_cpup call, improved formatting of struct of_pci_range_parser layout and replacement of macro with a static inline. All suggested by Rob Herring.

Compared to the v4 (incorrectly labelled v3) sent by Andrew Murray, the following changes have been made:

* Split the patch as suggested by Rob Herring

Compared to the v3 sent by Andrew Murray, the following changes have been made:

* Unify and move duplicate pci_process_bridge_OF_ranges functions to drivers/of/of_pci.c as suggested by Rob Herring

* Fix potential build errors with Microblaze/MIPS

Compared to "[PATCH v5 01/17] of/pci: Provide support for parsing PCI DT ranges property", the following changes have been made:

* Correct use of IORESOURCE_* as suggested by Russell King

* Improved interface and naming as suggested by Thierry Reding

Compared to the v2 sent by Andrew Murray, Thomas Petazzoni did:

* Add a memset() on the struct of_pci_range_iter when starting the for loop in for_each_pci_range(). Otherwise, with an uninitialized of_pci_range_iter, of_pci_process_ranges() may crash.

* Add parenthesis around 'res', 'np' and 'iter' in the for_each_of_pci_range macro definitions. Otherwise, passing something like &foobar as 'res' didn't work.

* Rebased on top of 3.9-rc2, which required fixing a few conflicts in the Microblaze code.

v2:
This follows on from suggestions made by Grant Likely (marc.info/?l=linux-kernel&m=136079602806328)

Andrew Murray (3):
of/pci: Unify pci_process_bridge_OF_ranges from Microblaze and
PowerPC
of/pci: Provide support for parsing PCI DT ranges property of/pci: mips: convert to common of_pci_range_parser

 arch/microblaze/include/asm/pci-bridge.h |    5 +-
 arch/microblaze/pci/pci-common.c         |  192 ------------------------------
 arch/mips/pci/pci.c                      |   50 +++------
 arch/powerpc/include/asm/pci-bridge.h    |    5 +-
 arch/powerpc/kernel/pci-common.c         |  192 ------------------------------
 drivers/of/address.c                     |   67 +++++++++++
 drivers/of/of_pci.c                      |  169 ++++++++++++++++++++++++++
 include/linux/of_address.h               |   46 +++++++
 include/linux/of_pci.h                   |    4 +
 9 files changed, 304 insertions(+), 426 deletions(-)
#1 lore raw

PATCH v7 1/3 of/pci: Unify pci_process_bridge_OF_ranges from Microblaze and PowerPC

The pci_process_bridge_OF_ranges function, used to parse the "ranges" property of a PCI host device, is found in both Microblaze and PowerPC architectures. These implementations are nearly identical. This patch moves this common code to a common place.

---
 arch/microblaze/include/asm/pci-bridge.h |    5 +-
 arch/microblaze/pci/pci-common.c         |  192 ----------------------------
 arch/powerpc/include/asm/pci-bridge.h    |    5 +-
 arch/powerpc/kernel/pci-common.c         |  192 ----------------------------
 drivers/of/of_pci.c                      |  200 ++++++++++++++++++++++++++++++
 include/linux/of_pci.h                   |    4 +
 6 files changed, 206 insertions(+), 392 deletions(-)
arch/microblaze/include/asm/pci-bridge.h +1 -4
index cb5d397..5783cd6 100644
@@ -10,6 +10,7 @@
 #include <linux/pci.h>
 #include <linux/list.h>
 #include <linux/ioport.h>
+#include <linux/of_pci.h>
 
 struct device_node;
 
@@ -132,10 +133,6 @@ extern void setup_indirect_pci(struct pci_controller *hose,
 extern struct pci_controller *pci_find_hose_for_OF_device(
 			struct device_node *node);
 
-/* Fill up host controller resources from the OF node */
-extern void pci_process_bridge_OF_ranges(struct pci_controller *hose,
-			struct device_node *dev, int primary);
-
 /* Allocate & free a PCI host bridge structure */
 extern struct pci_controller *pcibios_alloc_controller(struct device_node *dev);
 extern void pcibios_free_controller(struct pci_controller *phb);
arch/microblaze/pci/pci-common.c +0 -192

198 lines not on this page · raw message

arch/powerpc/include/asm/pci-bridge.h +1 -4
index 025a130..205bfba 100644
@@ -10,6 +10,7 @@
 #include <linux/pci.h>
 #include <linux/list.h>
 #include <linux/ioport.h>
+#include <linux/of_pci.h>
 #include <asm-generic/pci-bridge.h>
 
 struct device_node;
@@ -231,10 +232,6 @@ extern int pcibios_map_io_space(struct pci_bus *bus);
 extern struct pci_controller *pci_find_hose_for_OF_device(
 			struct device_node* node);
 
-/* Fill up host controller resources from the OF node */
-extern void pci_process_bridge_OF_ranges(struct pci_controller *hose,
-			struct device_node *dev, int primary);
-
 /* Allocate & free a PCI host bridge structure */
 extern struct pci_controller *pcibios_alloc_controller(struct device_node *dev);
 extern void pcibios_free_controller(struct pci_controller *phb);
arch/powerpc/kernel/pci-common.c +0 -192

198 lines not on this page · raw message

drivers/of/of_pci.c +200 -0

209 lines not on this page · raw message

include/linux/of_pci.h +4 -0
index bb115de..33e8ead 100644
@@ -11,4 +11,8 @@ struct device_node;
 struct device_node *of_pci_find_child_device(struct device_node *parent,
 					     unsigned int devfn);
 
+struct pci_controller;
+void pci_process_bridge_OF_ranges(struct pci_controller *hose,
+			struct device_node *dev, int primary);
+
 #endif
Signature · 1 line
1.7.0.4
#2 lore raw

PATCH v7 1/3 of/pci: Unify pci_process_bridge_OF_ranges from Microblaze and PowerPC

Quoted 11 lines · Andrew Murray

The pci_process_bridge_OF_ranges function, used to parse the "ranges" property of a PCI host device, is found in both Microblaze and PowerPC architectures. These implementations are nearly identical. This patch moves this common code to a common place.

Quoted 5 lines
---
 arch/microblaze/include/asm/pci-bridge.h |    5 +-
 arch/microblaze/pci/pci-common.c         |  192 ----------------------------
 arch/powerpc/include/asm/pci-bridge.h    |    5 +-
 arch/powerpc/kernel/pci-common.c         |  192 ----------------------------

Is there anyone on linuxppc-dev/linux-mips that can help test this patchset?

I've tested that it builds on powerpc with a variety of configs (some which include fsl_pci.c implementation). Though I don't have hardware to verify that it works.

I haven't tested this builds or runs on MIPS.

You shouldn't see any difference in behaviour or new warnings and PCI devices should continue to operate as before.

Andrew Murray

#3 lore raw

PATCH v7 1/3 of/pci: Unify pci_process_bridge_OF_ranges from Microblaze and PowerPC

Quoted 20 lines · Andrew Murray
Quoted 11 lines · Andrew Murray

The pci_process_bridge_OF_ranges function, used to parse the "ranges" property of a PCI host device, is found in both Microblaze and PowerPC architectures. These implementations are nearly identical. This patch moves this common code to a common place.

Quoted 5 lines
---
 arch/microblaze/include/asm/pci-bridge.h |    5 +-
 arch/microblaze/pci/pci-common.c         |  192 ----------------------------
 arch/powerpc/include/asm/pci-bridge.h    |    5 +-
 arch/powerpc/kernel/pci-common.c         |  192 ----------------------------

Is there anyone on linuxppc-dev/linux-mips that can help test this patchset?

Quoted 8 lines

I've tested that it builds on powerpc with a variety of configs (some which include fsl_pci.c implementation). Though I don't have hardware to verify that it works.

I haven't tested this builds or runs on MIPS.

You shouldn't see any difference in behaviour or new warnings and PCI devices should continue to operate as before.

I've got through a line-by-line comparison between powerpc, microblaze, and then new code. The differences are purely cosmetic, so I have absolutely no concerns about this patch. I've applied it to my tree.

g.

#4 lore raw

PATCH v7 1/3 of/pci: Unify pci_process_bridge_OF_ranges from Microblaze and PowerPC

Quoted 25 lines · Grant Likely
Quoted 24 lines · Andrew Murray
Quoted 11 lines · Andrew Murray

The pci_process_bridge_OF_ranges function, used to parse the "ranges" property of a PCI host device, is found in both Microblaze and PowerPC architectures. These implementations are nearly identical. This patch moves this common code to a common place.

Quoted 5 lines
---
 arch/microblaze/include/asm/pci-bridge.h |    5 +-
 arch/microblaze/pci/pci-common.c         |  192 ----------------------------
 arch/powerpc/include/asm/pci-bridge.h    |    5 +-
 arch/powerpc/kernel/pci-common.c         |  192 ----------------------------

Is there anyone on linuxppc-dev/linux-mips that can help test this patchset?

I've tested that it builds on powerpc with a variety of configs (some which include fsl_pci.c implementation). Though I don't have hardware to verify that it works.

Quoted 8 lines
Quoted 4 lines

I haven't tested this builds or runs on MIPS.

You shouldn't see any difference in behaviour or new warnings and PCI devices should continue to operate as before.

I've got through a line-by-line comparison between powerpc, microblaze, and then new code. The differences are purely cosmetic, so I have absolutely no concerns about this patch. I've applied it to my tree.

oops. Due to the number of dependencies the mvebu-pcie series has (this being one of them, we (arm-soc/mvebu) asked if we could take this through our tree. Rob Herring agreed to this several days ago. Is this a problem for you?

It would truly (dogs and cats living together) upset the apple cart for us at this stage to pipe these through a different tree...

thx,

Jason.

#5 lore raw

PATCH v7 1/3 of/pci: Unify pci_process_bridge_OF_ranges from Microblaze and PowerPC

Quoted 35 lines · Jason Cooper
Quoted 25 lines · Grant Likely
Quoted 24 lines · Andrew Murray
Quoted 11 lines · Andrew Murray

The pci_process_bridge_OF_ranges function, used to parse the "ranges" property of a PCI host device, is found in both Microblaze and PowerPC architectures. These implementations are nearly identical. This patch moves this common code to a common place.

Quoted 5 lines
---
 arch/microblaze/include/asm/pci-bridge.h |    5 +-
 arch/microblaze/pci/pci-common.c         |  192 ----------------------------
 arch/powerpc/include/asm/pci-bridge.h    |    5 +-
 arch/powerpc/kernel/pci-common.c         |  192 ----------------------------

Is there anyone on linuxppc-dev/linux-mips that can help test this patchset?

I've tested that it builds on powerpc with a variety of configs (some which include fsl_pci.c implementation). Though I don't have hardware to verify that it works.

Quoted 8 lines
Quoted 4 lines

I haven't tested this builds or runs on MIPS.

You shouldn't see any difference in behaviour or new warnings and PCI devices should continue to operate as before.

I've got through a line-by-line comparison between powerpc, microblaze, and then new code. The differences are purely cosmetic, so I have absolutely no concerns about this patch. I've applied it to my tree.

Quoted 7 lines

oops. Due to the number of dependencies the mvebu-pcie series has (this being one of them, we (arm-soc/mvebu) asked if we could take this through our tree. Rob Herring agreed to this several days ago. Is this a problem for you?

It would truly (dogs and cats living together) upset the apple cart for us at this stage to pipe these through a different tree...

Not a problem at all. I'll drop it.

g.

#6 lore raw

PATCH v7 1/3 of/pci: Unify pci_process_bridge_OF_ranges from Microblaze and PowerPC

Quoted 41 lines · Grant Likely
Quoted 40 lines · Jason Cooper
Quoted 25 lines · Grant Likely
Quoted 24 lines · Andrew Murray
Quoted 11 lines · Andrew Murray

The pci_process_bridge_OF_ranges function, used to parse the "ranges" property of a PCI host device, is found in both Microblaze and PowerPC architectures. These implementations are nearly identical. This patch moves this common code to a common place.

Quoted 5 lines
---
 arch/microblaze/include/asm/pci-bridge.h |    5 +-
 arch/microblaze/pci/pci-common.c         |  192 ----------------------------
 arch/powerpc/include/asm/pci-bridge.h    |    5 +-
 arch/powerpc/kernel/pci-common.c         |  192 ----------------------------

Is there anyone on linuxppc-dev/linux-mips that can help test this patchset?

I've tested that it builds on powerpc with a variety of configs (some which include fsl_pci.c implementation). Though I don't have hardware to verify that it works.

Quoted 8 lines
Quoted 4 lines

I haven't tested this builds or runs on MIPS.

You shouldn't see any difference in behaviour or new warnings and PCI devices should continue to operate as before.

I've got through a line-by-line comparison between powerpc, microblaze, and then new code. The differences are purely cosmetic, so I have absolutely no concerns about this patch. I've applied it to my tree.

oops. Due to the number of dependencies the mvebu-pcie series has (this being one of them, we (arm-soc/mvebu) asked if we could take this through our tree. Rob Herring agreed to this several days ago. Is this a problem for you?

Quoted 4 lines
Quoted 2 lines

It would truly (dogs and cats living together) upset the apple cart for us at this stage to pipe these through a different tree...

Not a problem at all. I'll drop it.

Great! Thanks.

Jason.

#7 lore raw

PATCH v7 1/3 of/pci: Unify pci_process_bridge_OF_ranges from Microblaze and PowerPC

Quoted 42 lines · Jason Cooper
Quoted 41 lines · Grant Likely
Quoted 40 lines · Jason Cooper
Quoted 25 lines · Grant Likely
Quoted 24 lines · Andrew Murray
Quoted 11 lines · Andrew Murray

The pci_process_bridge_OF_ranges function, used to parse the "ranges" property of a PCI host device, is found in both Microblaze and PowerPC architectures. These implementations are nearly identical. This patch moves this common code to a common place.

Quoted 5 lines
---
 arch/microblaze/include/asm/pci-bridge.h |    5 +-
 arch/microblaze/pci/pci-common.c         |  192 ----------------------------
 arch/powerpc/include/asm/pci-bridge.h    |    5 +-
 arch/powerpc/kernel/pci-common.c         |  192 ----------------------------

Is there anyone on linuxppc-dev/linux-mips that can help test this patchset?

I've tested that it builds on powerpc with a variety of configs (some which include fsl_pci.c implementation). Though I don't have hardware to verify that it works.

Quoted 8 lines
Quoted 4 lines

I haven't tested this builds or runs on MIPS.

You shouldn't see any difference in behaviour or new warnings and PCI devices should continue to operate as before.

I've got through a line-by-line comparison between powerpc, microblaze, and then new code. The differences are purely cosmetic, so I have absolutely no concerns about this patch. I've applied it to my tree.

oops. Due to the number of dependencies the mvebu-pcie series has (this being one of them, we (arm-soc/mvebu) asked if we could take this through our tree. Rob Herring agreed to this several days ago. Is this a problem for you?

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

It would truly (dogs and cats living together) upset the apple cart for us at this stage to pipe these through a different tree...

Not a problem at all. I'll drop it.

Great! Thanks.

You can add my Acked-by: Grant Likely <[email protected]> to the first patch. I've not reviewed out the second or third patches yet.

None of this appears to be in linux-next yet. I've boot tested on PowerPC, but that isn't the same as an ack by the PowerPC maintainers. It is probably too late for the whole now since we're after -rc7. However, if you ask me to, I have absolutely no problem putting the first patch into my tree for v3.10 merging. I went over the patch line-by-line and am convinced that it is functionally identical.

Let me know if you need me to do this.

g.

#8 lore raw

PATCH v7 1/3 of/pci: Unify pci_process_bridge_OF_ranges from Microblaze and PowerPC

Quoted 53 lines · Grant Likely
Quoted 42 lines · Jason Cooper
Quoted 41 lines · Grant Likely
Quoted 40 lines · Jason Cooper
Quoted 25 lines · Grant Likely
Quoted 24 lines · Andrew Murray
Quoted 11 lines · Andrew Murray

The pci_process_bridge_OF_ranges function, used to parse the "ranges" property of a PCI host device, is found in both Microblaze and PowerPC architectures. These implementations are nearly identical. This patch moves this common code to a common place.

Quoted 5 lines
---
 arch/microblaze/include/asm/pci-bridge.h |    5 +-
 arch/microblaze/pci/pci-common.c         |  192 ----------------------------
 arch/powerpc/include/asm/pci-bridge.h    |    5 +-
 arch/powerpc/kernel/pci-common.c         |  192 ----------------------------

Is there anyone on linuxppc-dev/linux-mips that can help test this patchset?

I've tested that it builds on powerpc with a variety of configs (some which include fsl_pci.c implementation). Though I don't have hardware to verify that it works.

Quoted 8 lines
Quoted 4 lines

I haven't tested this builds or runs on MIPS.

You shouldn't see any difference in behaviour or new warnings and PCI devices should continue to operate as before.

I've got through a line-by-line comparison between powerpc, microblaze, and then new code. The differences are purely cosmetic, so I have absolutely no concerns about this patch. I've applied it to my tree.

oops. Due to the number of dependencies the mvebu-pcie series has (this being one of them, we (arm-soc/mvebu) asked if we could take this through our tree. Rob Herring agreed to this several days ago. Is this a problem for you?

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

It would truly (dogs and cats living together) upset the apple cart for us at this stage to pipe these through a different tree...

Not a problem at all. I'll drop it.

Great! Thanks.

You can add my Acked-by: Grant Likely <[email protected]> to the first patch. I've not reviewed out the second or third patches yet.

Quoted 8 lines

None of this appears to be in linux-next yet. I've boot tested on PowerPC, but that isn't the same as an ack by the PowerPC maintainers. It is probably too late for the whole now since we're after -rc7. However, if you ask me to, I have absolutely no problem putting the first patch into my tree for v3.10 merging. I went over the patch line-by-line and am convinced that it is functionally identical.

Let me know if you need me to do this.

Thanks for the offer, Olof just pulled the branch last night (my PRs were a little late trying to sort all this out), so it should be in shortly.

FYI:

65ee348 of/pci: Unify pci_process_bridge_OF_ranges from Microblaze and PowerPC

is in arm-soc/mvebu/drivers as well as arm-soc/next/drivers (and arm-soc/for-next if you want to test merging everything...)

thx,

Jason.

#9 lore raw

PATCH v7 2/3 of/pci: Provide support for parsing PCI DT ranges property

In reply to Andrew Murray

This patch factors out common implementation patterns to reduce overall kernel code and provide a means for host bridge drivers to directly obtain struct resources from the DT's ranges property without relying on architecture specific DT handling. This will make it easier to write archiecture independent host bridge drivers and mitigate against further duplication of DT parsing code.

This patch can be used in the following way:

	struct of_pci_range_parser parser;
	struct of_pci_range range;

	if (of_pci_range_parser(&parser, np))
		; //no ranges property

	for_each_of_pci_range(&parser, &range) {

		/*
			directly access properties of the address range, e.g.:
			range.pci_space, range.pci_addr, range.cpu_addr,
			range.size, range.flags

			alternatively obtain a struct resource, e.g.:
			struct resource res;
			of_pci_range_to_resource(&range, np, &res);
		*/
	}

Additionally the implementation takes care of adjacent ranges and merges them into a single range (as was the case with powerpc and microblaze).

---
 drivers/of/address.c       |   67 ++++++++++++++++++++++++++
 drivers/of/of_pci.c        |  113 ++++++++++++++++----------------------------
 include/linux/of_address.h |   46 ++++++++++++++++++
 3 files changed, 154 insertions(+), 72 deletions(-)
drivers/of/address.c +67 -0
index 04da786..6eec70c 100644
@@ -227,6 +227,73 @@ int of_pci_address_to_resource(struct device_node *dev, int bar,
 	return __of_address_to_resource(dev, addrp, size, flags, NULL, r);
 }
 EXPORT_SYMBOL_GPL(of_pci_address_to_resource);
+
+int of_pci_range_parser(struct of_pci_range_parser *parser,
+			struct device_node *node)
+{
+	const int na = 3, ns = 2;
+	int rlen;
+
+	parser->node = node;
+	parser->pna = of_n_addr_cells(node);
+	parser->np = parser->pna + na + ns;
+
+	parser->range = of_get_property(node, "ranges", &rlen);
+	if (parser->range == NULL)
+		return -ENOENT;
+
+	parser->end = parser->range + rlen / sizeof(__be32);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_pci_range_parser);
+
+struct of_pci_range *of_pci_process_ranges(struct of_pci_range_parser *parser,
+						struct of_pci_range *range)
+{
+	const int na = 3, ns = 2;
+
+	if (!range)
+		return NULL;
+
+	if (!parser->range || parser->range + parser->np > parser->end)
+		return NULL;
+
+	range->pci_space = parser->range[0];
+	range->flags = of_bus_pci_get_flags(parser->range);
+	range->pci_addr = of_read_number(parser->range + 1, ns);
+	range->cpu_addr = of_translate_address(parser->node,
+				parser->range + na);
+	range->size = of_read_number(parser->range + parser->pna + na, ns);
+
+	parser->range += parser->np;
+
+	/* Now consume following elements while they are contiguous */
+	while (parser->range + parser->np <= parser->end) {
+		u32 flags, pci_space;
+		u64 pci_addr, cpu_addr, size;
+
+		pci_space = be32_to_cpup(parser->range);
+		flags = of_bus_pci_get_flags(parser->range);
+		pci_addr = of_read_number(parser->range + 1, ns);
+		cpu_addr = of_translate_address(parser->node,
+				parser->range + na);
+		size = of_read_number(parser->range + parser->pna + na, ns);
+
+		if (flags != range->flags)
+			break;
+		if (pci_addr != range->pci_addr + range->size ||
+		    cpu_addr != range->cpu_addr + range->size)
+			break;
+
+		range->size += size;
+		parser->range += parser->np;
+	}
+
+	return range;
+}
+EXPORT_SYMBOL_GPL(of_pci_process_ranges);
+
 #endif /* CONFIG_PCI */
 
 /*
drivers/of/of_pci.c +41 -72

187 lines not on this page · raw message

include/linux/of_address.h +46 -0

64 lines not on this page · raw message

Signature · 1 line
1.7.0.4
Acked-by on v7 2/3
#10 lore raw

Re: [PATCH v7 2/3] of/pci: Provide support for parsing PCI DT ranges property

Quoted 30 lines · Andrew Murray

This patch factors out common implementation patterns to reduce overall kernel code and provide a means for host bridge drivers to directly obtain struct resources from the DT's ranges property without relying on architecture specific DT handling. This will make it easier to write archiecture independent host bridge drivers and mitigate against further duplication of DT parsing code.

This patch can be used in the following way:

	struct of_pci_range_parser parser;
	struct of_pci_range range;

	if (of_pci_range_parser(&parser, np))
		; //no ranges property

	for_each_of_pci_range(&parser, &range) {

		/*
			directly access properties of the address range, e.g.:
			range.pci_space, range.pci_addr, range.cpu_addr,
			range.size, range.flags

			alternatively obtain a struct resource, e.g.:
			struct resource res;
			of_pci_range_to_resource(&range, np, &res);
		*/
	}

Additionally the implementation takes care of adjacent ranges and merges them into a single range (as was the case with powerpc and microblaze).

Quoted 6 lines

But comments below...

Quoted 24 lines
---
 drivers/of/address.c       |   67 ++++++++++++++++++++++++++
 drivers/of/of_pci.c        |  113 ++++++++++++++++----------------------------
 include/linux/of_address.h |   46 ++++++++++++++++++
 3 files changed, 154 insertions(+), 72 deletions(-)
drivers/of/address.c +10 -0
index 04da786..6eec70c 100644
@@ -227,6 +227,73 @@ int of_pci_address_to_resource(struct device_node *dev, int bar,
 	return __of_address_to_resource(dev, addrp, size, flags, NULL, r);
 }
 EXPORT_SYMBOL_GPL(of_pci_address_to_resource);
+
+int of_pci_range_parser(struct of_pci_range_parser *parser,
+			struct device_node *node)
+{
+	const int na = 3, ns = 2;
+	int rlen;
+
+	parser->node = node;
+	parser->pna = of_n_addr_cells(node);
+	parser->np = parser->pna + na + ns;

drivers/of/address.c int of_pci_address_to_resource(struct device_node *dev, int bar, · line 249

Quoted 10 lines
drivers/of/address.c +10 -0
+
+	parser->range = of_get_property(node, "ranges", &rlen);
+	if (parser->range == NULL)
+		return -ENOENT;
+
+	parser->end = parser->range + rlen / sizeof(__be32);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_pci_range_parser);

"of_pci_range_parser_init" would be a clearer name

drivers/of/address.c int of_pci_address_to_resource(struct device_node *dev, int bar, · line 252

Quoted 2 lines
drivers/of/address.c +2 -0
+struct of_pci_range *of_pci_process_ranges(struct of_pci_range_parser *parser,
+						struct of_pci_range *range)

Similarly, "of_pci_range_parser_one" would be more consistent.

Quoted 85 lines
drivers/of/address.c +44 -0
+{
+	const int na = 3, ns = 2;
+
+	if (!range)
+		return NULL;
+
+	if (!parser->range || parser->range + parser->np > parser->end)
+		return NULL;
+
+	range->pci_space = parser->range[0];
+	range->flags = of_bus_pci_get_flags(parser->range);
+	range->pci_addr = of_read_number(parser->range + 1, ns);
+	range->cpu_addr = of_translate_address(parser->node,
+				parser->range + na);
+	range->size = of_read_number(parser->range + parser->pna + na, ns);
+
+	parser->range += parser->np;
+
+	/* Now consume following elements while they are contiguous */
+	while (parser->range + parser->np <= parser->end) {
+		u32 flags, pci_space;
+		u64 pci_addr, cpu_addr, size;
+
+		pci_space = be32_to_cpup(parser->range);
+		flags = of_bus_pci_get_flags(parser->range);
+		pci_addr = of_read_number(parser->range + 1, ns);
+		cpu_addr = of_translate_address(parser->node,
+				parser->range + na);
+		size = of_read_number(parser->range + parser->pna + na, ns);
+
+		if (flags != range->flags)
+			break;
+		if (pci_addr != range->pci_addr + range->size ||
+		    cpu_addr != range->cpu_addr + range->size)
+			break;
+
+		range->size += size;
+		parser->range += parser->np;
+	}
+
+	return range;
+}
+EXPORT_SYMBOL_GPL(of_pci_process_ranges);
+
 #endif /* CONFIG_PCI */
 
 /*
drivers/of/of_pci.c +6 -9
index 1626172..e5ab604 100644
@@ -2,6 +2,7 @@
 #include <linux/export.h>
 #include <linux/of.h>
 #include <linux/of_pci.h>
+#include <linux/of_address.h>
 #include <asm/prom.h>
 
 #if defined(CONFIG_PPC32) || defined(CONFIG_PPC64) || defined(CONFIG_MICROBLAZE)
@@ -82,67 +83,43 @@ EXPORT_SYMBOL_GPL(of_pci_find_child_device);
 void pci_process_bridge_OF_ranges(struct pci_controller *hose,
 				  struct device_node *dev, int primary)
 {
-	const u32 *ranges;
-	int rlen;
-	int pna = of_n_addr_cells(dev);
-	int np = pna + 5;
 	int memno = 0, isa_hole = -1;
-	u32 pci_space;
-	unsigned long long pci_addr, cpu_addr, pci_next, cpu_next, size;
 	unsigned long long isa_mb = 0;
 	struct resource *res;
+	struct of_pci_range range;
+	struct of_pci_range_parser parser;
+	u32 res_type;
 
 	pr_info("PCI host bridge %s %s ranges:\n",
 	       dev->full_name, primary ? "(primary)" : "");
 
-	/* Get ranges property */
-	ranges = of_get_property(dev, "ranges", &rlen);
-	if (ranges == NULL)
+	/* Check for ranges property */
+	if (of_pci_range_parser(&parser, dev))
 		return;

drivers/of/of_pci.c EXPORT_SYMBOL_GPL(of_pci_find_child_device); · line 110

Quoted 10 lines
drivers/of/of_pci.c +1 -6
 
-	/* Parse it */
 	pr_debug("Parsing ranges property...\n");
-	while ((rlen -= np * 4) >= 0) {
+	for_each_of_pci_range(&parser, &range) {
 		/* Read next ranges element */
-		pci_space = ranges[0];
-		pci_addr = of_read_number(ranges + 1, 2);
-		cpu_addr = of_translate_address(dev, ranges + 3);
-		size = of_read_number(ranges + pna + 3, 2);

Tip: the diff on this function would be a whole lot simpler if the above locals were kept, but updated from the ranges structure. Not at all a big problem, but it is something that makes changes like this easier to review. The removal of the locals could also be split into a separate patch to end up with the same result.

drivers/of/of_pci.c EXPORT_SYMBOL_GPL(of_pci_find_child_device); · line 106

Quoted 11 lines
drivers/of/of_pci.c +4 -7
-
-		pr_debug("pci_space: 0x%08x pci_addr:0x%016llx ",
-				pci_space, pci_addr);
-		pr_debug("cpu_addr:0x%016llx size:0x%016llx\n",
-					cpu_addr, size);
-
-		ranges += np;
+		pr_debug("pci_space: 0x%08x pci_addr: 0x%016llx ",
+				range.pci_space, range.pci_addr);
+		pr_debug("cpu_addr: 0x%016llx size: 0x%016llx\n",
+				range.cpu_addr, range.size);

Nit: the patch changed whitespace on the pr_debug() statements, so even though the first line of each is identical, they look different in the patch.

drivers/of/of_pci.c EXPORT_SYMBOL_GPL(of_pci_find_child_device); · line 114

Quoted 9 lines
drivers/of/of_pci.c +1 -1
 		/* If we failed translation or got a zero-sized region
 		 * (some FW try to feed us with non sensical zero sized regions
 		 * such as power3 which look like some kind of attempt
 		 * at exposing the VGA memory hole)
 		 */
-		if (cpu_addr == OF_BAD_ADDR || size == 0)
+		if (range.cpu_addr == OF_BAD_ADDR || range.size == 0)
 			continue;

Can this also be rolled into the parsing iterator?

Quoted 10 lines
drivers/of/of_pci.c +0 -9
-		/* Now consume following elements while they are contiguous */
-		for (; rlen >= np * sizeof(u32);
-		     ranges += np, rlen -= np * 4) {
-			if (ranges[0] != pci_space)
-				break;
-			pci_next = of_read_number(ranges + 1, 2);
-			cpu_next = of_translate_address(dev, ranges + 3);
-			if (pci_next != pci_addr + size ||
-			    cpu_next != cpu_addr + size)

drivers/of/of_pci.c EXPORT_SYMBOL_GPL(of_pci_find_child_device); · line 119

Quoted 10 lines
drivers/of/of_pci.c +2 -6
-				break;
-			size += of_read_number(ranges + pna + 3, 2);
-		}
-
 		/* Act based on address space type */
 		res = NULL;
-		switch ((pci_space >> 24) & 0x3) {
-		case 1:		/* PCI IO space */
+		res_type = range.flags & IORESOURCE_TYPE_BITS;
+		if (res_type == IORESOURCE_IO) {

Why the change from switch() to an if/else if sequence?

But those are mostly nitpicks. If this is deferred to v3.10 then I would suggest fixing them up and posting for another round of review.

g.

#11 lore raw

PATCH v7 2/3 of/pci: Provide support for parsing PCI DT ranges property

Quoted 203 lines · Grant Likely
Quoted 30 lines · Andrew Murray

This patch factors out common implementation patterns to reduce overall kernel code and provide a means for host bridge drivers to directly obtain struct resources from the DT's ranges property without relying on architecture specific DT handling. This will make it easier to write archiecture independent host bridge drivers and mitigate against further duplication of DT parsing code.

This patch can be used in the following way:

	struct of_pci_range_parser parser;
	struct of_pci_range range;

	if (of_pci_range_parser(&parser, np))
		; //no ranges property

	for_each_of_pci_range(&parser, &range) {

		/*
			directly access properties of the address range, e.g.:
			range.pci_space, range.pci_addr, range.cpu_addr,
			range.size, range.flags

			alternatively obtain a struct resource, e.g.:
			struct resource res;
			of_pci_range_to_resource(&range, np, &res);
		*/
	}

Additionally the implementation takes care of adjacent ranges and merges them into a single range (as was the case with powerpc and microblaze).

Quoted 6 lines

But comments below...

Quoted 24 lines
---
 drivers/of/address.c       |   67 ++++++++++++++++++++++++++
 drivers/of/of_pci.c        |  113 ++++++++++++++++----------------------------
 include/linux/of_address.h |   46 ++++++++++++++++++
 3 files changed, 154 insertions(+), 72 deletions(-)
drivers/of/address.c +10 -0
index 04da786..6eec70c 100644
@@ -227,6 +227,73 @@ int of_pci_address_to_resource(struct device_node *dev, int bar,
 	return __of_address_to_resource(dev, addrp, size, flags, NULL, r);
 }
 EXPORT_SYMBOL_GPL(of_pci_address_to_resource);
+
+int of_pci_range_parser(struct of_pci_range_parser *parser,
+			struct device_node *node)
+{
+	const int na = 3, ns = 2;
+	int rlen;
+
+	parser->node = node;
+	parser->pna = of_n_addr_cells(node);
+	parser->np = parser->pna + na + ns;

drivers/of/address.c int of_pci_address_to_resource(struct device_node *dev, int bar, · line 249

Quoted 10 lines
drivers/of/address.c +10 -0
+
+	parser->range = of_get_property(node, "ranges", &rlen);
+	if (parser->range == NULL)
+		return -ENOENT;
+
+	parser->end = parser->range + rlen / sizeof(__be32);
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_pci_range_parser);

"of_pci_range_parser_init" would be a clearer name

drivers/of/address.c int of_pci_address_to_resource(struct device_node *dev, int bar, · line 252

Quoted 2 lines
drivers/of/address.c +2 -0
+struct of_pci_range *of_pci_process_ranges(struct of_pci_range_parser *parser,
+						struct of_pci_range *range)

Similarly, "of_pci_range_parser_one" would be more consistent.

Quoted 85 lines
drivers/of/address.c +44 -0
+{
+	const int na = 3, ns = 2;
+
+	if (!range)
+		return NULL;
+
+	if (!parser->range || parser->range + parser->np > parser->end)
+		return NULL;
+
+	range->pci_space = parser->range[0];
+	range->flags = of_bus_pci_get_flags(parser->range);
+	range->pci_addr = of_read_number(parser->range + 1, ns);
+	range->cpu_addr = of_translate_address(parser->node,
+				parser->range + na);
+	range->size = of_read_number(parser->range + parser->pna + na, ns);
+
+	parser->range += parser->np;
+
+	/* Now consume following elements while they are contiguous */
+	while (parser->range + parser->np <= parser->end) {
+		u32 flags, pci_space;
+		u64 pci_addr, cpu_addr, size;
+
+		pci_space = be32_to_cpup(parser->range);
+		flags = of_bus_pci_get_flags(parser->range);
+		pci_addr = of_read_number(parser->range + 1, ns);
+		cpu_addr = of_translate_address(parser->node,
+				parser->range + na);
+		size = of_read_number(parser->range + parser->pna + na, ns);
+
+		if (flags != range->flags)
+			break;
+		if (pci_addr != range->pci_addr + range->size ||
+		    cpu_addr != range->cpu_addr + range->size)
+			break;
+
+		range->size += size;
+		parser->range += parser->np;
+	}
+
+	return range;
+}
+EXPORT_SYMBOL_GPL(of_pci_process_ranges);
+
 #endif /* CONFIG_PCI */
 
 /*
drivers/of/of_pci.c +6 -9
index 1626172..e5ab604 100644
@@ -2,6 +2,7 @@
 #include <linux/export.h>
 #include <linux/of.h>
 #include <linux/of_pci.h>
+#include <linux/of_address.h>
 #include <asm/prom.h>
 
 #if defined(CONFIG_PPC32) || defined(CONFIG_PPC64) || defined(CONFIG_MICROBLAZE)
@@ -82,67 +83,43 @@ EXPORT_SYMBOL_GPL(of_pci_find_child_device);
 void pci_process_bridge_OF_ranges(struct pci_controller *hose,
 				  struct device_node *dev, int primary)
 {
-	const u32 *ranges;
-	int rlen;
-	int pna = of_n_addr_cells(dev);
-	int np = pna + 5;
 	int memno = 0, isa_hole = -1;
-	u32 pci_space;
-	unsigned long long pci_addr, cpu_addr, pci_next, cpu_next, size;
 	unsigned long long isa_mb = 0;
 	struct resource *res;
+	struct of_pci_range range;
+	struct of_pci_range_parser parser;
+	u32 res_type;
 
 	pr_info("PCI host bridge %s %s ranges:\n",
 	       dev->full_name, primary ? "(primary)" : "");
 
-	/* Get ranges property */
-	ranges = of_get_property(dev, "ranges", &rlen);
-	if (ranges == NULL)
+	/* Check for ranges property */
+	if (of_pci_range_parser(&parser, dev))
 		return;

drivers/of/of_pci.c EXPORT_SYMBOL_GPL(of_pci_find_child_device); · line 110

Quoted 10 lines
drivers/of/of_pci.c +1 -6
 
-	/* Parse it */
 	pr_debug("Parsing ranges property...\n");
-	while ((rlen -= np * 4) >= 0) {
+	for_each_of_pci_range(&parser, &range) {
 		/* Read next ranges element */
-		pci_space = ranges[0];
-		pci_addr = of_read_number(ranges + 1, 2);
-		cpu_addr = of_translate_address(dev, ranges + 3);
-		size = of_read_number(ranges + pna + 3, 2);

Tip: the diff on this function would be a whole lot simpler if the above locals were kept, but updated from the ranges structure. Not at all a big problem, but it is something that makes changes like this easier to review. The removal of the locals could also be split into a separate patch to end up with the same result.

drivers/of/of_pci.c EXPORT_SYMBOL_GPL(of_pci_find_child_device); · line 106

Quoted 11 lines
drivers/of/of_pci.c +4 -7
-
-		pr_debug("pci_space: 0x%08x pci_addr:0x%016llx ",
-				pci_space, pci_addr);
-		pr_debug("cpu_addr:0x%016llx size:0x%016llx\n",
-					cpu_addr, size);
-
-		ranges += np;
+		pr_debug("pci_space: 0x%08x pci_addr: 0x%016llx ",
+				range.pci_space, range.pci_addr);
+		pr_debug("cpu_addr: 0x%016llx size: 0x%016llx\n",
+				range.cpu_addr, range.size);

Nit: the patch changed whitespace on the pr_debug() statements, so even though the first line of each is identical, they look different in the patch.

Quoted 1 line
Quoted 11 lines

drivers/of/of_pci.c EXPORT_SYMBOL_GPL(of_pci_find_child_device); · line 114

Quoted 8 lines
drivers/of/of_pci.c +1 -1
 		/* If we failed translation or got a zero-sized region
 		 * (some FW try to feed us with non sensical zero sized regions
 		 * such as power3 which look like some kind of attempt
 		 * at exposing the VGA memory hole)
 		 */
-		if (cpu_addr == OF_BAD_ADDR || size == 0)
+		if (range.cpu_addr == OF_BAD_ADDR || range.size == 0)
 			continue;

Can this also be rolled into the parsing iterator?

Yes I think that would make sense.

Quoted 14 lines
Quoted 14 lines
drivers/of/of_pci.c +0 -13
-		/* Now consume following elements while they are contiguous */
-		for (; rlen >= np * sizeof(u32);
-		     ranges += np, rlen -= np * 4) {
-			if (ranges[0] != pci_space)
-				break;
-			pci_next = of_read_number(ranges + 1, 2);
-			cpu_next = of_translate_address(dev, ranges + 3);
-			if (pci_next != pci_addr + size ||
-			    cpu_next != cpu_addr + size)
-				break;
-			size += of_read_number(ranges + pna + 3, 2);
-		}
-
Quoted 8 lines

drivers/of/of_pci.c EXPORT_SYMBOL_GPL(of_pci_find_child_device); · line 119

Quoted 6 lines
drivers/of/of_pci.c +2 -2
 		/* Act based on address space type */
 		res = NULL;
-		switch ((pci_space >> 24) & 0x3) {
-		case 1:		/* PCI IO space */
+		res_type = range.flags & IORESOURCE_TYPE_BITS;
+		if (res_type == IORESOURCE_IO) {

Why the change from switch() to an if/else if sequence?

Russell King suggested this change - see
https://patchwork.kernel.org/patch/2323941/

Quoted 3 lines

But those are mostly nitpicks. If this is deferred to v3.10 then I would suggest fixing them up and posting for another round of review.

Thanks for the feedback. I'll update the patch in the future.

Andrew Murray

#12 lore raw

PATCH v7 2/3 of/pci: Provide support for parsing PCI DT ranges property

Quoted 9 lines · Andrew Murray
Quoted 8 lines · Grant Likely
Quoted 6 lines · Andrew Murray
            /* Act based on address space type */
            res = NULL;
drivers/of/of_pci.c +2 -2
-           switch ((pci_space >> 24) & 0x3) {
-           case 1:         /* PCI IO space */
+           res_type = range.flags & IORESOURCE_TYPE_BITS;
+           if (res_type == IORESOURCE_IO) {
Quoted 4 lines
Quoted 1 line

Why the change from switch() to an if/else if sequence?

Russell King suggested this change - see
https://patchwork.kernel.org/patch/2323941/

Umm, that isn't what that link shows. That link shows the patch already changing to an if/else if construct, and rmk is commenting on that.

g.

#13 lore raw

PATCH v7 2/3 of/pci: Provide support for parsing PCI DT ranges property

Quoted 10 lines · Grant Likely
Quoted 9 lines · Andrew Murray
Quoted 8 lines · Grant Likely
Quoted 6 lines · Andrew Murray
            /* Act based on address space type */
            res = NULL;
drivers/of/of_pci.c +2 -2
-           switch ((pci_space >> 24) & 0x3) {
-           case 1:         /* PCI IO space */
+           res_type = range.flags & IORESOURCE_TYPE_BITS;
+           if (res_type == IORESOURCE_IO) {
Quoted 8 lines
Quoted 4 lines
Quoted 1 line

Why the change from switch() to an if/else if sequence?

Russell King suggested this change - see
https://patchwork.kernel.org/patch/2323941/

Umm, that isn't what that link shows. That link shows the patch already changing to an if/else if construct, and rmk is commenting on that.

Arh yes sorry about that. I can't find or remember any good reason why I changed it from a switch to an if/else :\

Andrew Murray

#14 lore raw

PATCH v7 2/3 of/pci: Provide support for parsing PCI DT ranges property

In reply to Grant Likely
Quoted 7 lines · Grant Likely

On Tue, 16 Apr 2013 11:18:27 +0100, Andrew Murray <[email protected]> wrote:

But comments below...

I've updated the patchset (now v8) to reflect your feedback, after a closer look...

Quoted 7 lines
Quoted 7 lines
drivers/of/of_pci.c +0 -7
-
-		pr_debug("pci_space: 0x%08x pci_addr:0x%016llx ",
-				pci_space, pci_addr);
-		pr_debug("cpu_addr:0x%016llx size:0x%016llx\n",
-					cpu_addr, size);
-
-		ranges += np;
Quoted 9 lines

drivers/of/of_pci.c EXPORT_SYMBOL_GPL(of_pci_find_child_device); · line 106

Quoted 4 lines
drivers/of/of_pci.c +4 -0
+		pr_debug("pci_space: 0x%08x pci_addr: 0x%016llx ",
+				range.pci_space, range.pci_addr);
+		pr_debug("cpu_addr: 0x%016llx size: 0x%016llx\n",
+				range.cpu_addr, range.size);

Nit: the patch changed whitespace on the pr_debug() statements, so even though the first line of each is identical, they look different in the patch.

Actually the first line isn't identical, the original file was inconsistent with its use of spaces between ':' and '0x%0' - my patch ensured that there was always a space. I guess this could have been done as a separate patch.

Quoted 12 lines

drivers/of/of_pci.c EXPORT_SYMBOL_GPL(of_pci_find_child_device); · line 114

Quoted 9 lines
drivers/of/of_pci.c +1 -1
 		/* If we failed translation or got a zero-sized region
 		 * (some FW try to feed us with non sensical zero sized regions
 		 * such as power3 which look like some kind of attempt
 		 * at exposing the VGA memory hole)
 		 */
-		if (cpu_addr == OF_BAD_ADDR || size == 0)
+		if (range.cpu_addr == OF_BAD_ADDR || range.size == 0)
 			continue;

Can this also be rolled into the parsing iterator?

I decided not to do this. Mainly because ARM drivers use the parser directly (instead of pci_process_bridge_OF_ranges function) and it seemed perfectly valid for the parser to return a range of size 0 if that is what was present in the DT.

Quoted 14 lines
Quoted 14 lines
drivers/of/of_pci.c +0 -13
-		/* Now consume following elements while they are contiguous */
-		for (; rlen >= np * sizeof(u32);
-		     ranges += np, rlen -= np * 4) {
-			if (ranges[0] != pci_space)
-				break;
-			pci_next = of_read_number(ranges + 1, 2);
-			cpu_next = of_translate_address(dev, ranges + 3);
-			if (pci_next != pci_addr + size ||
-			    cpu_next != cpu_addr + size)
-				break;
-			size += of_read_number(ranges + pna + 3, 2);
-		}
-
Quoted 8 lines

drivers/of/of_pci.c EXPORT_SYMBOL_GPL(of_pci_find_child_device); · line 119

Quoted 6 lines
drivers/of/of_pci.c +2 -2
 		/* Act based on address space type */
 		res = NULL;
-		switch ((pci_space >> 24) & 0x3) {
-		case 1:		/* PCI IO space */
+		res_type = range.flags & IORESOURCE_TYPE_BITS;
+		if (res_type == IORESOURCE_IO) {

Why the change from switch() to an if/else if sequence?

I think this was an artifact of the patches evolution, I've reverted back to the switch.

Quoted 3 lines

But those are mostly nitpicks. If this is deferred to v3.10 then I would suggest fixing them up and posting for another round of review.

Andrew Murray

#15 lore raw

PATCH v7 3/3 of/pci: mips: convert to common of_pci_range_parser

In reply to Andrew Murray

This patch converts the pci_load_of_ranges function to use the new common of_pci_range_parser.

---
 arch/mips/pci/pci.c |   50 ++++++++++++++++----------------------------------
 1 files changed, 16 insertions(+), 34 deletions(-)
arch/mips/pci/pci.c +16 -34
index 0872f12..bee49a4 100644
@@ -122,51 +122,33 @@ static void pcibios_scanbus(struct pci_controller *hose)
 #ifdef CONFIG_OF
 void pci_load_of_ranges(struct pci_controller *hose, struct device_node *node)
 {
-	const __be32 *ranges;
-	int rlen;
-	int pna = of_n_addr_cells(node);
-	int np = pna + 5;
+	struct of_pci_range_range range;
+	struct of_pci_range_parser parser;
+	u32 res_type;
 
 	pr_info("PCI host bridge %s ranges:\n", node->full_name);
-	ranges = of_get_property(node, "ranges", &rlen);
-	if (ranges == NULL)
-		return;
 	hose->of_node = node;
 
-	while ((rlen -= np * 4) >= 0) {
-		u32 pci_space;
+	if (of_pci_range_parser(&parser, node))
+		return;
+
+	for_each_of_pci_range(&parser, &range) {
 		struct resource *res = NULL;
-		u64 addr, size;
-
-		pci_space = be32_to_cpup(&ranges[0]);
-		addr = of_translate_address(node, ranges + 3);
-		size = of_read_number(ranges + pna + 3, 2);
-		ranges += np;
-		switch ((pci_space >> 24) & 0x3) {
-		case 1:		/* PCI IO space */
+
+		res_type = range.flags & IORESOURCE_TYPE_BITS;
+		if (res_type == IORESOURCE_IO) {
 			pr_info("  IO 0x%016llx..0x%016llx\n",
-					addr, addr + size - 1);
+				range.addr, range.addr + range.size - 1);
 			hose->io_map_base =
-				(unsigned long)ioremap(addr, size);
+				(unsigned long)ioremap(range.addr, range.size);
 			res = hose->io_resource;
-			res->flags = IORESOURCE_IO;
-			break;
-		case 2:		/* PCI Memory space */
-		case 3:		/* PCI 64 bits Memory space */
+		} else if (res_type == IORESOURCE_MEM) {
 			pr_info(" MEM 0x%016llx..0x%016llx\n",
-					addr, addr + size - 1);
+				range.addr, range.addr + range.size - 1);
 			res = hose->mem_resource;
-			res->flags = IORESOURCE_MEM;
-			break;
-		}
-		if (res != NULL) {
-			res->start = addr;
-			res->name = node->full_name;
-			res->end = res->start + size - 1;
-			res->parent = NULL;
-			res->sibling = NULL;
-			res->child = NULL;
 		}
+		if (res != NULL)
+			of_pci_range_to_resource(&range, node, res);
 	}
 }
 #endif
Signature · 1 line
1.7.0.4
#17 lore raw

PATCH v7 3/3 of/pci: mips: convert to common of_pci_range_parser

Quoted 10 lines · Linus Walleij
Quoted 6 lines · Andrew Murray

This patch converts the pci_load_of_ranges function to use the new common of_pci_range_parser.

Jason - you may not have seen this, but here (Linus Walleij) is another Tested-by to add to this patch in your tree (if you can).

Andrew Murray

#18 lore raw

PATCH v7 3/3 of/pci: mips: convert to common of_pci_range_parser

Quoted 6 lines · Andrew Murray
Quoted 5 lines · Linus Walleij
Quoted 3 lines · Andrew Murray

This patch converts the pci_load_of_ranges function to use the new common of_pci_range_parser.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

Jason - you may not have seen this, but here (Linus Walleij) is another Tested-by to add to this patch in your tree (if you can).

Thanks, I saw it. Unfortunately, the PR was already sent, and the branch is now pulled into arm-soc.

thx,

Jason.

#19 lore raw

PATCH v7 3/3 of/pci: mips: convert to common of_pci_range_parser

2013.04.18. 15:09 keltez?ssel, Jason Cooper ?rta:

Quoted 11 lines · Andrew Murray
Quoted 10 lines · Linus Walleij
Quoted 9 lines · Andrew Murray
Quoted 7 lines

This patch converts the pci_load_of_ranges function to use the new common of_pci_range_parser.

Quoted 7 lines
Quoted 4 lines
Quoted 1 line

Jason - you may not have seen this, but here (Linus Walleij) is another Tested-by to add to this patch in your tree (if you can).

Thanks, I saw it. Unfortunately, the PR was already sent, and the branch is now pulled into arm-soc.

Sorry I had no time earlier, but I have tested this now on MIPS. The patch causes build errors unfortunately. Given the fact that this has been merged already, I will send a fixup patch.

-Gabor

#20 lore raw

PATCH v7 3/3 of/pci: mips: convert to common of_pci_range_parser

Quoted 17 lines · Gabor Juhos

2013.04.18. 15:09 keltez?ssel, Jason Cooper ?rta:

Quoted 16 lines · Andrew Murray
Quoted 14 lines · Linus Walleij
Quoted 10 lines · Andrew Murray
Quoted 7 lines

This patch converts the pci_load_of_ranges function to use the new common of_pci_range_parser.

Jason - you may not have seen this, but here (Linus Walleij) is another Tested-by to add to this patch in your tree (if you can).

Quoted 6 lines
Quoted 2 lines

Thanks, I saw it. Unfortunately, the PR was already sent, and the branch is now pulled into arm-soc.

Sorry I had no time earlier, but I have tested this now on MIPS. The patch causes build errors unfortunately. Given the fact that this has been merged already, I will send a fixup patch.

Olof has dropped this branch from arm-soc, plase post the build error and fix here so that it can be included in this series.

thx,

Jason.

#21 lore raw

PATCH v7 3/3 of/pci: mips: convert to common of_pci_range_parser

Hi Jason,

Quoted 6 lines
Quoted 3 lines

Sorry I had no time earlier, but I have tested this now on MIPS. The patch causes build errors unfortunately. Given the fact that this has been merged already, I will send a fixup patch.

Olof has dropped this branch from arm-soc, plase post the build error and fix here so that it can be included in this series.

I have posted the patch to Olof two days ago. It has been CC'd to you as well but In case that it does not exists in your mailbox the patch can be found here:

https://patchwork.linux-mips.org/patch/5196/

However I can re-post the patch as a reply to this thread if you prefer that.

-Gabor

#22 lore raw

PATCH v7 3/3 of/pci: mips: convert to common of_pci_range_parser

Quoted 9 lines · Gabor Juhos

Hi Jason,

Quoted 6 lines
Quoted 3 lines

Sorry I had no time earlier, but I have tested this now on MIPS. The patch causes build errors unfortunately. Given the fact that this has been merged already, I will send a fixup patch.

Olof has dropped this branch from arm-soc, plase post the build error and fix here so that it can be included in this series.

Quoted 6 lines

I have posted the patch to Olof two days ago. It has been CC'd to you as well but In case that it does not exists in your mailbox the patch can be found here:

https://patchwork.linux-mips.org/patch/5196/

However I can re-post the patch as a reply to this thread if you prefer that.

As this branch was dropped I have updated my patchset to include Grant's recent feedback - I've also included Gabor's fixes to this patchset (and his sign-off).

If you include this new patchset in your branch the drivers that depend on it will need to be updated to reflect the new naming of functions as suggested by Grant.

Thanks,

Andrew Murray

Reviewed-by on v7 3/3
#23 lore raw

Re: [PATCH v7 3/3] of/pci: mips: convert to common of_pci_range_parser

In reply to Andrew Murray
Quoted 6 lines · Andrew Murray

This patch converts the pci_load_of_ranges function to use the new common of_pci_range_parser.

Looks okay to me, and thank you very much for doing the legwork to merge the common code.

#24 lore raw

PATCH v7 3/3 of/pci: mips: convert to common of_pci_range_parser

Quoted 10 lines · Grant Likely
Quoted 6 lines · Andrew Murray

This patch converts the pci_load_of_ranges function to use the new common of_pci_range_parser.

Looks okay to me, and thank you very much for doing the legwork to merge the common code.

No problem, though I think there is more than can be done in this area - there is a lot of similar PCI code floating about.

Quoted 2 lines

Thanks for the review.

Andrew Murray

#25 lore raw
In reply to Andrew Murray
Quoted 6 lines · Andrew Murray

This patchset factors out duplicated code associated with parsing PCI DT "ranges" properties across the architectures and introduces a "ranges" parser. This parser "of_pci_range_parser" can be used directly by ARM host bridge drivers enabling them to obtain ranges from device trees.

Quoted 8 lines

I've included the Reviewed-by and Tested-by's received from v5/v6 in this patchset, earlier versions of this patchset (v3) have been tested-by:

Thierry Reding <[email protected]>
Jingoo Han <[email protected]>

I've tested that this patchset builds and runs on ARM and that it builds on PowerPC and x86_64.

Series replaces v6 in mvebu/drivers

thx,

Jason.

Quoted 14 lines

Compared to the v6 sent by Andrew Murray, the following changes have been made in response to build errors/warnings:

* Inclusion of linux/of_address.h in of_pci.c as suggested by Michal Simek to prevent compilation failures on Microblaze (and others) and his ack.

* Use of externs, static inlines and a typo in linux/of_address.h in response to linker errors (multiple defination) on x86_64 as spotted by a kbuild test robot on (jcooper/linux.git mvebu/drivers)

* Add EXPORT_SYMBOL_GPL to of_pci_range_parser function to be consistent with of_pci_process_ranges function