Skip to contentSkip to conversation

PCIe support for the Armada 370 and Armada XP SoCs

PATCH New Thomas Petazzoni 3 participants 17 messages May 16, 2013 – May 20, 2013

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

v10 cover PCIe support for the Armada 370 and Armada XP SoCs

Hello,

This series of patches introduces PCIe support for the Marvell Armada 370 and Armada XP.

I'd like this code to be merged for 3.11.

For easier testing, the code has been pushed to:

git://github.com/MISL-EBU-System-SW/mainline-public.git marvell-pcie-v10

This PATCHv10 follows:
* PATCHv9, sent on May, 16th 2013
* PATCHv8, sent on April, 9th 2013
* PATCHv7, sent on March, 27th 2013
* PATCHv6, sent on March, 26st 2013
* PATCHv5, sent on March, 21st 2013
* PATCHv4, sent on March, 8th 2013
* PATCHv3, sent on February, 12th 2013
* PATCHv2, sent on January, 28th 2013
* RFCv1, sent on December, 7th 2012

Changes between v9 and v10:

* Mark mvebu_pcie_init() as __init, as reported by Ezequiel Garcia. platform_driver_probe() is __init_or_module, so when !CONFIG_MODULES is used, platform_driver_probe() belongs to the __init section.

* Mark two other small functions as __init, just because they are only used during the initialization (mvebu_pcie_enable and mvebu_pcie_map_registers). Suggested by Ezequiel Garcia.

Changes between v8 and v9:

* Rebased on top of 3.10-rc1. Since the PCIe Device Tree informations were merged in 3.10-rc1, it allowed to reduce quite significantly the size of this patch set.

* A fix for the PCIe Device Tree information is added as the first patch, it adds a missing range entry to let the global PCIe memory/IO window addresses be correctly translated. It should be merged into the 3.10-rc cycle, to fix the hardware definition of the platform.

* The patch set now integrates the latest version of Andrew Murray of/pci patch, that adds the PCI range parsing functions. The one I've integrated is:

[PATCH v9 1/3] of/pci: Provide support for parsing PCI DT ranges property

* I've fixed the PowerPC64 build problem, which was the reason why this driver was not taken for 3.10. In fact, the patch 'pci:
infrastructure to add drivers in drivers/pci/host' was introducing a drivers/pci/host directory, with just an empty Makefile. Unfortunately, an empty Makefile doesn't trigger the generation of drivers/pci/host/built-in.o. So if you try to build the kernel with just this patch applied, and not the PCIe driver itself, the Makefile is empty, and the build breaks.

To solve this, I've simply merged this patch with the PCIe driver patch itself. The PCIe driver patch adds the drivers/pci/host/ directory and the related Kconfig/Makefile bits.

* Fixed a regression in the driver introduced between the v7 and the v8. A #define <something> 1 was changed to #define <something> BIT(1), which obviously doesn't work. Changed to BIT(0), which is correct.

Changes between v7 and v8:

* In the patch introducing the drivers/pci/host directory, add an empty drivers/pci/host/Makefile to ensure that the kernel still build. This Makefile will actually gets its first useful line when the Marvell PCIe driver gets added. Noted by Neil Greatorex.

* Remove bogus (and useless) CFLAGS in drivers/pci/host/Makefile for the compilation of the Marvell PCIe driver. Noticed by Bjorn Helgaas.

* Added missing parenthesis in the definition of the PCIE_BAR_CTRL_OFF macro. Noticed by Bjorn Helgaas.

* Make mvebu_pcie_link_up() return 'bool' instead of 'int'. Suggested by Bjorn Helgaas.

* Change mvebu_pcie_link_up(), mvebu_pcie_set_local_bus_nr(), mvebu_pcie_setup_wins(), mvebu_pcie_setup_hw(), mvebu_pcie_hw_rd_conf(), mvebu_pcie_hw_wr_conf() so that they take a 'struct mvebu_pcie_port *' instead of a 'void __iomem *' as first argument. The base address of the PCIe interface register are available using the 'base' field of 'struct mvebu_pcie_port'. Suggested by Bjorn Helgaas.

* Fixed multi-line comments that should have been one line comments. Noticed by Bjorn Helgaas.

* Fixed a for() loop in mvebu_pcie_setup_wins() to use the more conventional 'ii < 3' ending condition instead of 'i <= 2'. Suggested by Bjorn Helgaas.

* Add a #define instead of an hardcoded magic value when enabling interrupts A-D in mvebu_pcie_setup_hw(). Suggested by Bjorn Helgaas.

* Add a PCIE_CONF_ADDR() to simplify the code in mvebu_pcie_hw_rd_conf() and mvebu_pcie_hw_wr_conf(). Suggested by Bjorn Helgaas.

* Clarify the comments in mvebu_pcie_handle_iobase_change() and mvebu_pcie_handle_membase_change() so that it is clear we look at the new iobase/iolimit (respectively membase/memlimit) values. Suggested by Bjorn Helgaas.

* Replace mvebu_pcie_find_port_by_bus() and mvebu_pcie_find_port_by_devfn() by a single mvebu_pcie_find_port() function, and simplify the mvebu_pcie_rd_conf() and mvebu_pcie_wr_conf() functions. Suggested by Bjorn Helgaas.

* Fix the computation of the real I/O resource start and end addresses, according to the suggestions of Arnd Bergmann and Jason Gunthorpe.

* Remove the MASK/OFFS definition, and use definitions more in the style of pci_regs.h. Suggested by Bjorn Helgaas.

* Integrate the latest version of 'of/pci: Provide support for parsing PCI DT ranges property' from Andrew Murray, fixed according to the review of Rob Herring.

* Added the Acked-by tags from Bjorn Helgaas on the PCI patches.

Changes between v6 and v7:

* Use assigned-addresses in the DT subnodes for the MMIO PCIe registers, in order to align with what Thierry is doing on the Tegra PCIe driver.

* Added empty 'ranges;' properties in the subnodes, as requested by Arnd. Note that due to this, it is not possible to remove the #address-cells and #size-cells properties from the subnodes, as Jason Gunthorpe requested, otherwise the DT compiler complains with:

Warning (ranges_format): /soc/pcie-controller/pcie at 1,0 has empty "ranges" property but its #address-cells (2) differs from /soc/pcie-controller (3)

Warning (ranges_format): /soc/pcie-controller/pcie at 1,0 has empty "ranges" property but its #size-cells (1) differs from /soc/pcie-controller (2)

* Use the new RFCv3 patch from Andrew Murray for 'of/pci: Provide support for parsing PCI DT ranges property'.

* Updated the DT binding documentation accordingly.

Changes between v5 and v6:

* Use pci_create_root_bus() + pci_scan_child_bus() instead of pci_scan_root_bus(). This is needed to be able to add MSI support later on. Moreover Thierry Reding suggested that pci_scan_root_bus() "does a pci_bus_add_devices(), which is called again in pci_common_init() in the ARM code". Thanks Thierry for pointing out this issue.

Changes between v4 and v5:

* Rebased on top of 3.9-rc2 + the new mvebu-mbus driver (v3).

* Changed the names of the PCI DT sub-nodes to match the OF
specifications: they should be named pcie at DD,FF where DD is the device number and FF the function number. Requested by Mitch Bradley.

* Add the device_type = "pci" property@the pcie-controller level. Requested by Mitch Bradley.

* Drop patch 'of/pci: Add of_pci_get_bus() function' because it wasn't actually used in the rest of the patch series.

* Updated the patch 'of/pci: Provide support for parsing PCI DT ranges property' to use the latest version proposed by Andrew Murray on the devicetree-discuss@ mailing list.

Changes between v3 and v4:

* Rebased on top of 3.9-rc1.

* Drop patch "ARM: pci: Allow passing per-controller private data" because it was merged in 3.9.

* Drop patch "lib: devres: don't enclose pcim_*() functions in CONFIG_HAS_IOPORT", because it was merged in 3.9.

* Added CONFIG_PCI_MVEBU=y in mvebu_defconfig, so that the right PCI host controller driver is automatically enabled.

* Instead of using the DT 'ranges' property to encode the PCIe register ranges, use a 'reg' property on the main PCIe controller DT node together with a 'reg-names' property. Suggested by Jason Gunthorpe.

* Don't select PCI_SW_HOST_BRIDGE and PCI_SW_PCI_PCI_BRIDGE, they don't exist anymore. Reported by Bjorn Helgaas.

* Added support for the Armada XP GP board.

* Fix the 'ranges' property so that the memory range is an identity map between CPU addresses and bus addresses. Suggested by Arnd Bergmann.

* Changed the 'ranges' property to have the I/O region after the memory region.

* Use the new mvebu-mbus driver API to create/remove address decoding windows when needed. This remove the need to include <mach/addr-map.h>. Requested by Arnd Bergmann.

* Include directly into the driver the few common PCIe functions we were using from arch/arm/plat-orion/pcie.c. This allows to remove the inclusion of <plat/pcie.h>. Requested by Arnd Bergmann.

* Directly set up the address decoding windows when the memory base/limit and I/O base/limit are configured in the PCI-to-PCI bridge instead of relying on the memory and I/O accesses being enabled in the PCI_COMMAND register. Suggested by Bjorn Helgaas.

* Added some comments on top of the calculations of the I/O base/limit and memory base/limit. Suggested by Arnd Bergmann.

* Changed a bit the way the "realio" resource is created, from suggestions given by Arnd Bergmann.

* Updated the Device Tree binding documentation. Reported by Jason Gunthorpe.

* Instead of using "marvell,armada-370-xp-pcie" as the DT compatible string, use two separate compatible strings:
"marvell,armada-370-pcie" and "marvell,armada-xp-pcie". For now, the driver does the same thing for both.

Changes between v2 and v3:

* Use of_irq_map_pci() instead of of_irq_map_raw(), as suggested by Andrew Murray. In order to do this, we moved the interrupt-map and interrupt-map-mask DT properties from the main PCIe controller node to the DT subnodes representing each PCIe interface.

* Remove the usage of the emulated host bridge.

* Move the emulated PCI-to-PCI bridge code into the Marvell PCI driver itself, in order to allow a tighter integration. Suggested by Bjorn Helgaas and Jason Gunthorpe.

* Make the allocation of address decoding windows dynamic: it's when memory accesses or I/O accesses are enabled at the PCI-to-PCI bridge level that we allocate and setup the corresponding address decoding window. Requested by Bjorn Helgaas.

* Fixed the implementation of I/O accesses to use I/O addresses that fall within the normal IO_SPACE_LIMIT. This required using the "remap" functionality of address decoding windows, and therefore some changes in the address decoding window allocator. Follows a long discussion about I/O accesses.

* Set up a correct bus number in the configuration of the PCIe interfaces so that we don't have to fake bus numbers anymore. Requested by Jason Gunthorpe.

* Fix the of_pci_get_devfn() implementation according to Stephen Warren's comment.

* Use CFLAGS_ instead of ccflags to add the mach-mvebu and plat-orion include paths when building the pci-mvebu driver. This ensures that the include paths are only added when building this specific driver. Requested by Stephen Warren.

* Fix the ->resource_align() to only apply on bus 0 (the one on which the emulated PCI-to-PCI bridges sit), and to request an alignment on the size of the window (and not only 64 KB for I/O windows and 1 MB for memory windows).

* Clarified the commit log of "clk: mvebu: create parent-child relation for PCIe clocks on Armada 370"

Thanks,

Thomas

Andrew Murray (1):
of/pci: Provide support for parsing PCI DT ranges property

Thierry Reding (2):
of/pci: Add of_pci_get_devfn() function
of/pci: Add of_pci_parse_bus_range() function

Thomas Petazzoni (6):
arm: mvebu: fix the 'ranges' property to handle PCIe
clk: mvebu: create parent-child relation for PCIe clocks on Armada

    370

clk: mvebu: add more PCIe clocks for Armada XP
pci: PCIe driver for Marvell Armada 370/XP systems
arm: mvebu: PCIe support is now available on mvebu
arm: mvebu: update defconfig with PCI and USB support

 .../devicetree/bindings/pci/mvebu-pci.txt          |  220 +++++
 arch/arm/boot/dts/armada-370-xp.dtsi               |    3 +-
 arch/arm/boot/dts/armada-370.dtsi                  |    3 +-
 arch/arm/configs/mvebu_defconfig                   |    3 +
 arch/arm/mach-mvebu/Kconfig                        |    2 +
 drivers/clk/mvebu/clk-gating-ctrl.c                |   18 +-
 drivers/of/address.c                               |   67 ++
 drivers/of/of_pci.c                                |   59 +-
 drivers/pci/Kconfig                                |    2 +
 drivers/pci/Makefile                               |    3 +
 drivers/pci/host/Kconfig                           |    8 +
 drivers/pci/host/Makefile                          |    1 +
 drivers/pci/host/pci-mvebu.c                       |  880 ++++++++++++++++++++
 include/linux/of_address.h                         |   48 ++
 include/linux/of_pci.h                             |    2 +
 15 files changed, 1306 insertions(+), 13 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/pci/mvebu-pci.txt
 create mode 100644 drivers/pci/host/Kconfig
 create mode 100644 drivers/pci/host/Makefile
 create mode 100644 drivers/pci/host/pci-mvebu.c
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH v10 1/9 arm: mvebu: fix the 'ranges' property to handle PCIe

Since 82a682676 ('ARM: dts: mvebu: Convert all the mvebu files to use the range property') all the device nodes of Armada 370/XP are under a common 'ranges' property that translates the device register addresses into their absolute address, thanks to the base address of the internal register space.

However, beyond just the register areas, there are also PCIe I/O and memory regions, whose addresses should be properly translated. This patch fixes the Armada 370 and XP ranges property to take PCIe into account properly.

---
Since the PCIe Device Tree description has been merged in 3.10-rc1, this commit should go in 3.10-rc as well.

---
 arch/arm/boot/dts/armada-370-xp.dtsi |    3 ++-
 arch/arm/boot/dts/armada-370.dtsi    |    3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
arch/arm/boot/dts/armada-370-xp.dtsi +2 -1
index 272bbc6..550eb77 100644
@@ -33,7 +33,8 @@
 		#size-cells = <1>;
 		compatible = "simple-bus";
 		interrupt-parent = <&mpic>;
-		ranges = <0 0 0xd0000000 0x100000>;
+		ranges = <0          0 0xd0000000 0x0100000 /* internal registers */
+			  0xe0000000 0 0xe0000000 0x8100000 /* PCIe */>;
 
 		internal-regs {
 			compatible = "simple-bus";
arch/arm/boot/dts/armada-370.dtsi +2 -1
index b2c1b5a..834c9be 100644
@@ -29,7 +29,8 @@
 	};
 
 	soc {
-		ranges = <0 0xd0000000 0x100000>;
+		ranges = <0          0xd0000000 0x0100000 /* internal registers */
+			  0xe0000000 0xe0000000 0x8100000 /* PCIe */>;
 		internal-regs {
 			system-controller at 18200 {
 				compatible = "marvell,armada-370-xp-system-controller";
Signature · 1 line
1.7.9.5
Applied
#2 lore raw

PATCH v10 1/9 arm: mvebu: fix the 'ranges' property to handle PCIe

Quoted 11 lines · Thomas Petazzoni

Since 82a682676 ('ARM: dts: mvebu: Convert all the mvebu files to use the range property') all the device nodes of Armada 370/XP are under a common 'ranges' property that translates the device register addresses into their absolute address, thanks to the base address of the internal register space.

However, beyond just the register areas, there are also PCIe I/O and memory regions, whose addresses should be properly translated. This patch fixes the Armada 370 and XP ranges property to take PCIe into account properly.

Quoted 8 lines

---
Since the PCIe Device Tree description has been merged in 3.10-rc1, this commit should go in 3.10-rc as well.

---
 arch/arm/boot/dts/armada-370-xp.dtsi |    3 ++-
 arch/arm/boot/dts/armada-370.dtsi    |    3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

Applied to mvebu/fixes

thx,

Jason.

#3 lore raw

PATCH v10 2/9 of/pci: Provide support for parsing PCI DT ranges property

In reply to Thomas Petazzoni

From: Andrew Murray <[email protected]>

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_init(&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 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of_address.h |   48 +++++++++++++++++++++++++++++++
 2 files changed, 115 insertions(+)
drivers/of/address.c +67 -0
index 04da786..fdd0636 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_init(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_init);
+
+struct of_pci_range *of_pci_range_parser_one(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_range_parser_one);
+
 #endif /* CONFIG_PCI */
 
 /*
include/linux/of_address.h +48 -0

66 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#4 lore raw

PATCH v10 2/9 of/pci: Provide support for parsing PCI DT ranges property

Quoted 40 lines · Thomas Petazzoni

From: Andrew Murray <[email protected]>

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_init(&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 4 lines
---
 drivers/of/address.c       |   67 ++++++++++++++++++++++++++++++++++++++++++++
 include/linux/of_address.h |   48 +++++++++++++++++++++++++++++++
 2 files changed, 115 insertions(+)

patches 2, 3, and 4 applied to mvebu/of_pci to facilitate others (LinusW) basing their work off of it.

thx,

Jason.

#5 lore raw

PATCH v10 2/9 of/pci: Provide support for parsing PCI DT ranges property

Quoted 2 lines · Jason Cooper

patches 2, 3, and 4 applied to mvebu/of_pci to facilitate others (LinusW) basing their work off of it.

Thanks, is this going to be pulled into ARM SoC soon-ish?

I think Arnd may need this for some PCI work too.

Yours,
Linus Walleij

#6 lore raw

PATCH v10 2/9 of/pci: Provide support for parsing PCI DT ranges property

Quoted 8 lines · Linus Walleij
Quoted 2 lines · Jason Cooper

patches 2, 3, and 4 applied to mvebu/of_pci to facilitate others (LinusW) basing their work off of it.

Thanks, is this going to be pulled into ARM SoC soon-ish?

I think Arnd may need this for some PCI work too.

I was half expecting -rc2 to drop yesterday. Since it didn't, I'll go ahead and send another round of PRs, including this one. Probably today or tomorrow.

thx,

Jason.

#7 lore raw

PATCH v10 3/9 of/pci: Add of_pci_get_devfn() function

In reply to Thomas Petazzoni

From: Thierry Reding <[email protected]>

This function can be used to parse the device and function number from a standard 5-cell PCI resource. PCI_SLOT() and PCI_FUNC() can be used on the returned value obtain the device and function numbers respectively.

---
 drivers/of/of_pci.c    |   34 +++++++++++++++++++++++++++++-----
 include/linux/of_pci.h |    1 +
 2 files changed, 30 insertions(+), 5 deletions(-)
drivers/of/of_pci.c +29 -5
index 13e37e2..4dd7b9b 100644
@@ -5,14 +5,15 @@
 #include <asm/prom.h>
 
 static inline int __of_pci_pci_compare(struct device_node *node,
-				       unsigned int devfn)
+				       unsigned int data)
 {
-	unsigned int size;
-	const __be32 *reg = of_get_property(node, "reg", &size);
+	int devfn;
 
-	if (!reg || size < 5 * sizeof(__be32))
+	devfn = of_pci_get_devfn(node);
+	if (devfn < 0)
 		return 0;
-	return ((be32_to_cpup(&reg[0]) >> 8) & 0xff) == devfn;
+
+	return devfn == data;
 }
 
 struct device_node *of_pci_find_child_device(struct device_node *parent,
@@ -40,3 +41,26 @@ struct device_node *of_pci_find_child_device(struct device_node *parent,
 	return NULL;
 }
 EXPORT_SYMBOL_GPL(of_pci_find_child_device);
+
+/**
+ * of_pci_get_devfn() - Get device and function numbers for a device node
+ * @np: device node
+ *
+ * Parses a standard 5-cell PCI resource and returns an 8-bit value that can
+ * be passed to the PCI_SLOT() and PCI_FUNC() macros to extract the device
+ * and function numbers respectively. On error a negative error code is
+ * returned.
+ */
+int of_pci_get_devfn(struct device_node *np)
+{
+	unsigned int size;
+	const __be32 *reg;
+
+	reg = of_get_property(np, "reg", &size);
+
+	if (!reg || size < 5 * sizeof(__be32))
+		return -EINVAL;
+
+	return (be32_to_cpup(reg) >> 8) & 0xff;
+}
+EXPORT_SYMBOL_GPL(of_pci_get_devfn);
include/linux/of_pci.h +1 -0
index bb115de..91ec484 100644
@@ -10,5 +10,6 @@ int of_irq_map_pci(const struct pci_dev *pdev, struct of_irq *out_irq);
 struct device_node;
 struct device_node *of_pci_find_child_device(struct device_node *parent,
 					     unsigned int devfn);
+int of_pci_get_devfn(struct device_node *np);
 
 #endif
Signature · 1 line
1.7.9.5
#8 lore raw

PATCH v10 4/9 of/pci: Add of_pci_parse_bus_range() function

In reply to Thomas Petazzoni

From: Thierry Reding <[email protected]>

This function can be used to parse a bus-range property as specified by device nodes representing PCI bridges.

---
 drivers/of/of_pci.c    |   25 +++++++++++++++++++++++++
 include/linux/of_pci.h |    1 +
 2 files changed, 26 insertions(+)
drivers/of/of_pci.c +25 -0
index 4dd7b9b..42c687a 100644
@@ -64,3 +64,28 @@ int of_pci_get_devfn(struct device_node *np)
 	return (be32_to_cpup(reg) >> 8) & 0xff;
 }
 EXPORT_SYMBOL_GPL(of_pci_get_devfn);
+
+/**
+ * of_pci_parse_bus_range() - parse the bus-range property of a PCI device
+ * @node: device node
+ * @res: address to a struct resource to return the bus-range
+ *
+ * Returns 0 on success or a negative error-code on failure.
+ */
+int of_pci_parse_bus_range(struct device_node *node, struct resource *res)
+{
+	const __be32 *values;
+	int len;
+
+	values = of_get_property(node, "bus-range", &len);
+	if (!values || len < sizeof(*values) * 2)
+		return -EINVAL;
+
+	res->name = node->name;
+	res->start = be32_to_cpup(values++);
+	res->end = be32_to_cpup(values);
+	res->flags = IORESOURCE_BUS;
+
+	return 0;
+}
+EXPORT_SYMBOL_GPL(of_pci_parse_bus_range);
include/linux/of_pci.h +1 -0
index 91ec484..7a04826 100644
@@ -11,5 +11,6 @@ struct device_node;
 struct device_node *of_pci_find_child_device(struct device_node *parent,
 					     unsigned int devfn);
 int of_pci_get_devfn(struct device_node *np);
+int of_pci_parse_bus_range(struct device_node *node, struct resource *res);
 
 #endif
Signature · 1 line
1.7.9.5
#9 lore raw

PATCH v10 5/9 clk: mvebu: create parent-child relation for PCIe clocks on Armada 370

In reply to Thomas Petazzoni

The Armada 370 has two gatable clocks for each PCIe interface, and we want both of them to be enabled. We therefore make one of the two clocks a child of the other, as we did for the sataX and sataXlnk clocks on Armada XP.

---
 drivers/clk/mvebu/clk-gating-ctrl.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/clk/mvebu/clk-gating-ctrl.c +2 -2
index ebf141d..b35785a 100644
@@ -119,8 +119,8 @@ static const struct mvebu_soc_descr __initconst armada_370_gating_descr[] = {
 	{ "pex1_en", NULL,  2 },
 	{ "ge1", NULL, 3 },
 	{ "ge0", NULL, 4 },
-	{ "pex0", NULL, 5 },
-	{ "pex1", NULL, 9 },
+	{ "pex0", "pex0_en", 5 },
+	{ "pex1", "pex1_en", 9 },
 	{ "sata0", NULL, 15 },
 	{ "sdio", NULL, 17 },
 	{ "tdm", NULL, 25 },
Signature · 1 line
1.7.9.5
#10 lore raw

PATCH v10 5/9 clk: mvebu: create parent-child relation for PCIe clocks on Armada 370

Quoted 10 lines · Thomas Petazzoni

The Armada 370 has two gatable clocks for each PCIe interface, and we want both of them to be enabled. We therefore make one of the two clocks a child of the other, as we did for the sataX and sataXlnk clocks on Armada XP.

---
 drivers/clk/mvebu/clk-gating-ctrl.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Patches 5 - 8 applied to mvebu/pcie, with a dep on Sebastian's clock rework and mvebu/of_pci. Thanks for the head's up on the clk conflict. My resolution should match yours. Please let me know if it doesn't.

thx,

Jason.

#11 lore raw

PATCH v10 5/9 clk: mvebu: create parent-child relation for PCIe clocks on Armada 370

Quoted 12 lines · Jason Cooper
Quoted 10 lines · Thomas Petazzoni

The Armada 370 has two gatable clocks for each PCIe interface, and we want both of them to be enabled. We therefore make one of the two clocks a child of the other, as we did for the sataX and sataXlnk clocks on Armada XP.

---
 drivers/clk/mvebu/clk-gating-ctrl.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 3 lines

Patches 5 - 8 applied to mvebu/pcie, with a dep on Sebastian's clock rework and mvebu/of_pci. Thanks for the head's up on the clk conflict. My resolution should match yours. Please let me know if it doesn't.

As stated in the clk thread, I'm going to re-order this so pcie doesn't depend on the clk series.

thx,

Jason.

#12 lore raw

PATCH v10 6/9 clk: mvebu: add more PCIe clocks for Armada XP

In reply to Thomas Petazzoni

The current revision of the datasheet only mentions the gatable clocks for the PCIe 0.0, 0.1, 0.2 and 0.3 interfaces, and forgot to mention the ones for the PCIe 1.0, 1.1, 1.2, 1.3, 2.0 and 3.0 interfaces. After confirmation with Marvell engineers, this patch adds the missing gatable clocks for those PCIe interfaces.

It also changes the name of the previously existing PCIe gatable clocks, in order to match the naming using the datasheets.

---
 drivers/clk/mvebu/clk-gating-ctrl.c |   14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
drivers/clk/mvebu/clk-gating-ctrl.c +10 -4
index b35785a..2f03723 100644
@@ -137,10 +137,14 @@ static const struct mvebu_soc_descr __initconst armada_xp_gating_descr[] = {
 	{ "ge2", NULL,  2 },
 	{ "ge1", NULL, 3 },
 	{ "ge0", NULL, 4 },
-	{ "pex0", NULL, 5 },
-	{ "pex1", NULL, 6 },
-	{ "pex2", NULL, 7 },
-	{ "pex3", NULL, 8 },
+	{ "pex00", NULL, 5 },
+	{ "pex01", NULL, 6 },
+	{ "pex02", NULL, 7 },
+	{ "pex03", NULL, 8 },
+	{ "pex10", NULL, 9 },
+	{ "pex11", NULL, 10 },
+	{ "pex12", NULL, 11 },
+	{ "pex13", NULL, 12 },
 	{ "bp", NULL, 13 },
 	{ "sata0lnk", NULL, 14 },
 	{ "sata0", "sata0lnk", 15 },
@@ -152,6 +156,8 @@ static const struct mvebu_soc_descr __initconst armada_xp_gating_descr[] = {
 	{ "xor0", NULL, 22 },
 	{ "crypto", NULL, 23 },
 	{ "tdm", NULL, 25 },
+	{ "pex20", NULL, 26 },
+	{ "pex30", NULL, 27 },
 	{ "xor1", NULL, 28 },
 	{ "sata1lnk", NULL, 29 },
 	{ "sata1", "sata1lnk", 30 },
Signature · 1 line
1.7.9.5
#13 lore raw

PATCH v10 7/9 pci: PCIe driver for Marvell Armada 370/XP systems

In reply to Thomas Petazzoni

This driver implements the support for the PCIe interfaces on the Marvell Armada 370/XP ARM SoCs. In the future, it might be extended to cover earlier families of Marvell SoCs, such as Dove, Orion and Kirkwood.

The driver implements the hw_pci operations needed by the core ARM PCI code to setup PCI devices and get their corresponding IRQs, and the pci_ops operations that are used by the PCI core to read/write the configuration space of PCI devices.

Since the PCIe interfaces of Marvell SoCs are completely separate and not linked together in a bus, this driver sets up an emulated PCI host bridge, with one PCI-to-PCI bridge as child for each hardware PCIe interface.

In addition, this driver enumerates the different PCIe slots, and for those having a device plugged in, it sets up the necessary address decoding windows, using the mvebu-mbus driver.

---
 .../devicetree/bindings/pci/mvebu-pci.txt          |  220 +++++
 drivers/pci/Kconfig                                |    2 +
 drivers/pci/Makefile                               |    3 +
 drivers/pci/host/Kconfig                           |    8 +
 drivers/pci/host/Makefile                          |    1 +
 drivers/pci/host/pci-mvebu.c                       |  880 ++++++++++++++++++++
 6 files changed, 1114 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/mvebu-pci.txt
 create mode 100644 drivers/pci/host/Kconfig
 create mode 100644 drivers/pci/host/Makefile
 create mode 100644 drivers/pci/host/pci-mvebu.c
Documentation/devicetree/bindings/pci/mvebu-pci.txt new file +220 -0
new file mode 100644
index 0000000..eb69d92
@@ -0,0 +1,220 @@
+* Marvell EBU PCIe interfaces
+
+Mandatory properties:
+- compatible: one of the following values:
+    marvell,armada-370-pcie
+    marvell,armada-xp-pcie
+- #address-cells, set to <3>
+- #size-cells, set to <2>
+- #interrupt-cells, set to <1>
+- bus-range: PCI bus numbers covered
+- device_type, set to "pci"
+- ranges: ranges for the PCI memory and I/O regions, as well as the
+  MMIO registers to control the PCIe interfaces.
+
+In addition, the Device Tree node must have sub-nodes describing each
+PCIe interface, having the following mandatory properties:
+- reg: used only for interrupt mapping, so only the first four bytes
+  are used to refer to the correct bus number and device number.
+- assigned-addresses: reference to the MMIO registers used to control
+  this PCIe interface.
+- clocks: the clock associated to this PCIe interface
+- marvell,pcie-port: the physical PCIe port number
+- status: either "disabled" or "okay"
+- device_type, set to "pci"
+- #address-cells, set to <3>
+- #size-cells, set to <2>
+- #interrupt-cells, set to <1>
+- ranges, empty property.
+- interrupt-map-mask and interrupt-map, standard PCI properties to
+  define the mapping of the PCIe interface to interrupt numbers.
+
+and the following optional properties:
+- marvell,pcie-lane: the physical PCIe lane number, for ports having
+  multiple lanes. If this property is not found, we assume that the
+  value is 0.
+
+Example:
+
+pcie-controller {
+	compatible = "marvell,armada-xp-pcie";
+	status = "disabled";
+	device_type = "pci";
+
+	#address-cells = <3>;
+	#size-cells = <2>;
+
+	bus-range = <0x00 0xff>;
+
+	ranges = <0x82000000 0 0xd0040000 0xd0040000 0 0x00002000   /* Port 0.0 registers */
+		  0x82000000 0 0xd0042000 0xd0042000 0 0x00002000   /* Port 2.0 registers */
+		  0x82000000 0 0xd0044000 0xd0044000 0 0x00002000   /* Port 0.1 registers */
+		  0x82000000 0 0xd0048000 0xd0048000 0 0x00002000   /* Port 0.2 registers */
+		  0x82000000 0 0xd004c000 0xd004c000 0 0x00002000   /* Port 0.3 registers */
+		  0x82000000 0 0xd0080000 0xd0080000 0 0x00002000   /* Port 1.0 registers */
+		  0x82000000 0 0xd0082000 0xd0082000 0 0x00002000   /* Port 3.0 registers */
+		  0x82000000 0 0xd0084000 0xd0084000 0 0x00002000   /* Port 1.1 registers */
+		  0x82000000 0 0xd0088000 0xd0088000 0 0x00002000   /* Port 1.2 registers */
+		  0x82000000 0 0xd008c000 0xd008c000 0 0x00002000   /* Port 1.3 registers */
+		  0x82000000 0 0xe0000000 0xe0000000 0 0x08000000   /* non-prefetchable memory */
+		  0x81000000 0 0	  0xe8000000 0 0x00100000>; /* downstream I/O */
+
+	pcie at 1,0 {
+		device_type = "pci";
+		assigned-addresses = <0x82000800 0 0xd0040000 0 0x2000>;
+		reg = <0x0800 0 0 0 0>;
+		#address-cells = <3>;
+		#size-cells = <2>;
+		#interrupt-cells = <1>;
+		ranges;
+		interrupt-map-mask = <0 0 0 0>;
+		interrupt-map = <0 0 0 0 &mpic 58>;
+		marvell,pcie-port = <0>;
+		marvell,pcie-lane = <0>;
+		clocks = <&gateclk 5>;
+		status = "disabled";
+	};
+
+	pcie at 2,0 {
+		device_type = "pci";
+		assigned-addresses = <0x82001000 0 0xd0044000 0 0x2000>;
+		reg = <0x1000 0 0 0 0>;
+		#address-cells = <3>;
+		#size-cells = <2>;
+		#interrupt-cells = <1>;
+		ranges;
+		interrupt-map-mask = <0 0 0 0>;
+		interrupt-map = <0 0 0 0 &mpic 59>;
+		marvell,pcie-port = <0>;
+		marvell,pcie-lane = <1>;
+		clocks = <&gateclk 6>;
+		status = "disabled";
+	};
+
+	pcie at 3,0 {
+		device_type = "pci";
+		assigned-addresses = <0x82001800 0 0xd0048000 0 0x2000>;
+		reg = <0x1800 0 0 0 0>;
+		#address-cells = <3>;
+		#size-cells = <2>;
+		#interrupt-cells = <1>;
+		ranges;
+		interrupt-map-mask = <0 0 0 0>;
+		interrupt-map = <0 0 0 0 &mpic 60>;
+		marvell,pcie-port = <0>;
+		marvell,pcie-lane = <2>;
+		clocks = <&gateclk 7>;
+		status = "disabled";
+	};
+
+	pcie at 4,0 {
+		device_type = "pci";
+		assigned-addresses = <0x82002000 0 0xd004c000 0 0x2000>;
+		reg = <0x2000 0 0 0 0>;
+		#address-cells = <3>;
+		#size-cells = <2>;
+		#interrupt-cells = <1>;
+		ranges;
+		interrupt-map-mask = <0 0 0 0>;
+		interrupt-map = <0 0 0 0 &mpic 61>;
+		marvell,pcie-port = <0>;
+		marvell,pcie-lane = <3>;
+		clocks = <&gateclk 8>;
+		status = "disabled";
+	};
+
+	pcie at 5,0 {
+		device_type = "pci";
+		assigned-addresses = <0x82002800 0 0xd0080000 0 0x2000>;
+		reg = <0x2800 0 0 0 0>;
+		#address-cells = <3>;
+		#size-cells = <2>;
+		#interrupt-cells = <1>;
+		ranges;
+		interrupt-map-mask = <0 0 0 0>;
+		interrupt-map = <0 0 0 0 &mpic 62>;
+		marvell,pcie-port = <1>;
+		marvell,pcie-lane = <0>;
+		clocks = <&gateclk 9>;
+		status = "disabled";
+	};
+
+	pcie at 6,0 {
+		device_type = "pci";
+		assigned-addresses = <0x82003000 0 0xd0084000 0 0x2000>;
+		reg = <0x3000 0 0 0 0>;
+		#address-cells = <3>;
+		#size-cells = <2>;
+		#interrupt-cells = <1>;
+		ranges;
+		interrupt-map-mask = <0 0 0 0>;
+		interrupt-map = <0 0 0 0 &mpic 63>;
+		marvell,pcie-port = <1>;
+		marvell,pcie-lane = <1>;
+		clocks = <&gateclk 10>;
+		status = "disabled";
+	};
+
+	pcie at 7,0 {
+		device_type = "pci";
+		assigned-addresses = <0x82003800 0 0xd0088000 0 0x2000>;
+		reg = <0x3800 0 0 0 0>;
+		#address-cells = <3>;
+		#size-cells = <2>;
+		#interrupt-cells = <1>;
+		ranges;
+		interrupt-map-mask = <0 0 0 0>;
+		interrupt-map = <0 0 0 0 &mpic 64>;
+		marvell,pcie-port = <1>;
+		marvell,pcie-lane = <2>;
+		clocks = <&gateclk 11>;
+		status = "disabled";
+	};
+
+	pcie at 8,0 {
+		device_type = "pci";
+		assigned-addresses = <0x82004000 0 0xd008c000 0 0x2000>;
+		reg = <0x4000 0 0 0 0>;
+		#address-cells = <3>;
+		#size-cells = <2>;
+		#interrupt-cells = <1>;
+		ranges;
+		interrupt-map-mask = <0 0 0 0>;
+		interrupt-map = <0 0 0 0 &mpic 65>;
+		marvell,pcie-port = <1>;
+		marvell,pcie-lane = <3>;
+		clocks = <&gateclk 12>;
+		status = "disabled";
+	};
+	pcie at 9,0 {
+		device_type = "pci";
+		assigned-addresses = <0x82004800 0 0xd0042000 0 0x2000>;
+		reg = <0x4800 0 0 0 0>;
+		#address-cells = <3>;
+		#size-cells = <2>;
+		#interrupt-cells = <1>;
+		ranges;
+		interrupt-map-mask = <0 0 0 0>;
+		interrupt-map = <0 0 0 0 &mpic 99>;
+		marvell,pcie-port = <2>;
+		marvell,pcie-lane = <0>;
+		clocks = <&gateclk 26>;
+		status = "disabled";
+	};
+
+	pcie at 10,0 {
+		device_type = "pci";
+		assigned-addresses = <0x82005000 0 0xd0082000 0 0x2000>;
+		reg = <0x5000 0 0 0 0>;
+		#address-cells = <3>;
+		#size-cells = <2>;
+		#interrupt-cells = <1>;
+		ranges;
+		interrupt-map-mask = <0 0 0 0>;
+		interrupt-map = <0 0 0 0 &mpic 103>;
+		marvell,pcie-port = <3>;
+		marvell,pcie-lane = <0>;
+		clocks = <&gateclk 27>;
+		status = "disabled";
+	};
+};
drivers/pci/Kconfig +2 -0
index 6d51aa6..ac45398 100644
@@ -119,3 +119,5 @@ config PCI_IOAPIC
 config PCI_LABEL
 	def_bool y if (DMI || ACPI)
 	select NLS
+
+source "drivers/pci/host/Kconfig"
drivers/pci/Makefile +3 -0
index 0c3efcf..6ebf5bf 100644
@@ -67,3 +67,6 @@ obj-$(CONFIG_XEN_PCIDEV_FRONTEND) += xen-pcifront.o
 obj-$(CONFIG_OF) += of.o
 
 ccflags-$(CONFIG_PCI_DEBUG) := -DDEBUG
+
+# PCI host controller drivers
+obj-y += host/
drivers/pci/host/Kconfig new file +8 -0
new file mode 100644
index 0000000..6918fbc
@@ -0,0 +1,8 @@
+menu "PCI host controller drivers"
+	depends on PCI
+
+config PCI_MVEBU
+	bool "Marvell EBU PCIe controller"
+	depends on ARCH_MVEBU
+
+endmenu
drivers/pci/host/Makefile new file +1 -0
new file mode 100644
index 0000000..5ea2d8b
@@ -0,0 +1 @@
+obj-$(CONFIG_PCI_MVEBU) += pci-mvebu.o
drivers/pci/host/pci-mvebu.c new file +880 -0

880 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#14 lore raw

PATCH v10 8/9 arm: mvebu: PCIe support is now available on mvebu

In reply to Thomas Petazzoni

Now that the PCIe driver for mvebu has been integrated and all its relevant dependencies, we can mark the ARCH_MVEBU platform has MIGHT_HAVE_PCI, which allows to select the PCI bus support if needed.

---
 arch/arm/mach-mvebu/Kconfig |    2 ++
 1 file changed, 2 insertions(+)
arch/arm/mach-mvebu/Kconfig +2 -0
index e11acbb..381062d 100644
@@ -15,6 +15,8 @@ config ARCH_MVEBU
 	select MVEBU_CLK_GATING
 	select MVEBU_MBUS
 	select ZONE_DMA if ARM_LPAE
+	select MIGHT_HAVE_PCI
+	select PCI_QUIRKS if PCI
 
 if ARCH_MVEBU
 
Signature · 1 line
1.7.9.5
#15 lore raw

PATCH v10 9/9 arm: mvebu: update defconfig with PCI and USB support

In reply to Thomas Petazzoni

Now that we have the necessary drivers and Device Tree informations to support PCIe on Armada 370 and Armada XP, enable the CONFIG_PCI option.

Also, since the Armada 370 Mirabox has a built-in USB XHCI controller connected on the PCIe bus, enable the corresponding options as well.

---
 arch/arm/configs/mvebu_defconfig |    3 +++
 1 file changed, 3 insertions(+)
arch/arm/configs/mvebu_defconfig +3 -0
index f3e8ae0..966281e 100644
@@ -13,6 +13,8 @@ CONFIG_MACH_ARMADA_370=y
 CONFIG_MACH_ARMADA_XP=y
 # CONFIG_CACHE_L2X0 is not set
 # CONFIG_SWP_EMULATE is not set
+CONFIG_PCI=y
+CONFIG_PCI_MVEBU=y
 CONFIG_SMP=y
 CONFIG_AEABI=y
 CONFIG_HIGHMEM=y
@@ -60,6 +62,7 @@ CONFIG_USB_SUPPORT=y
 CONFIG_USB=y
 CONFIG_USB_EHCI_HCD=y
 CONFIG_USB_EHCI_ROOT_HUB_TT=y
+CONFIG_USB_XHCI_HCD=y
 CONFIG_MMC=y
 CONFIG_MMC_MVSDIO=y
 CONFIG_NEW_LEDS=y
Signature · 1 line
1.7.9.5
Applied
#16 lore raw

PATCH v10 9/9 arm: mvebu: update defconfig with PCI and USB support

Quoted 11 lines · Thomas Petazzoni

Now that we have the necessary drivers and Device Tree informations to support PCIe on Armada 370 and Armada XP, enable the CONFIG_PCI option.

Also, since the Armada 370 Mirabox has a built-in USB XHCI controller connected on the PCIe bus, enable the corresponding options as well.

---
 arch/arm/configs/mvebu_defconfig |    3 +++
 1 file changed, 3 insertions(+)

Applied to mvebu/defconfig

thx,

Jason.