Skip to contentSkip to conversation

add support for Xilinx PCIe root ports on RISC-V

PATCH In review Christoph Hellwig 3 participants 7 messages Jun 19, 2018

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

Hi all,

this series with patches originally from Palmer and Wesley adds support for the pcie-xilinx host driver on RISC-V boards. The interesting part about that is that the IP blocks is limited to 32-bit DMA internally, which didn't seem to be an issue with the existing users, but shows up easily with the Sifive RISC-V boards that have physical memory wired up above 4G. To support this the per-device flag I've added last merge window is set through a new hook in struct pci_ops.

#1 lore raw

PATCH 1/3 PCI: Add hooks for bus/bridge-specific fixups

From: "Wesley W. Terpstra" <[email protected]>

There is currently no way for a PCIe bridge to impose constraints on devices added to it. For example, the Xilinx PCIe host bridge only supports 32-bit physical addresses (due to a limitation on the AXI port's address width). Thus, even devices that claim to support 64-bit DMA addresses must be restricted to 32-bit addresses when attached to this host controller.

This patch adds at "add_dev" hook to pci_ops that allows the PCI infastructure to interpose when adding a device, which in the case of the Xilinx driver will be used to restrict the address ranges used for DMA.

[hch: simplified the prototype]
---
 drivers/pci/probe.c | 3 +++
 include/linux/pci.h | 1 +
 2 files changed, 4 insertions(+)
drivers/pci/probe.c +3 -0
index ac876e32de4b..978e684cba2c 100644
@@ -2331,6 +2331,9 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
 	/* Set up MSI IRQ domain */
 	pci_set_msi_domain(dev);
 
+	if (bus->ops->add_dev)
+		bus->ops->add_dev(dev, bus);
+
 	/* Notifier could use PCI capabilities */
 	dev->match_driver = false;
 	ret = device_add(&dev->dev);
include/linux/pci.h +1 -0
index 340029b2fb38..ea9609fc44fc 100644
@@ -662,6 +662,7 @@ static inline int pcibios_err_to_errno(int err)
 struct pci_ops {
 	int (*add_bus)(struct pci_bus *bus);
 	void (*remove_bus)(struct pci_bus *bus);
+	void (*add_dev)(struct pci_dev *dev, struct pci_bus *bus);
 	void __iomem *(*map_bus)(struct pci_bus *bus, unsigned int devfn, int where);
 	int (*read)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val);
 	int (*write)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val);
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH 1/3] PCI: Add hooks for bus/bridge-specific fixups

include/linux/pci.h static inline int pcibios_err_to_errno(int err) · line 668

Quoted 13 lines · Christoph Hellwig

From: "Wesley W. Terpstra" <[email protected]>

index 340029b2fb38..ea9609fc44fc 100644

include/linux/pci.h +1 -0
@@ -662,6 +662,7 @@ static inline int pcibios_err_to_errno(int err)
 struct pci_ops {
        int (*add_bus)(struct pci_bus *bus);
        void (*remove_bus)(struct pci_bus *bus);
+       void (*add_dev)(struct pci_dev *dev, struct pci_bus *bus);
        void __iomem *(*map_bus)(struct pci_bus *bus, unsigned int devfn, int where);
        int (*read)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *val);
        int (*write)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val);

We are a bit inconsistent about adding callbacks to pci_ops or pci_host_bridge. I would argue this should be part of pci_host_bridge, and the other two should probably be there as well, or possibly moved into a separate 'pci_host_bridge_ops'
structure referenced from pci_host_bridge along with the other callbacks there.

One of the things we discussed in the past (but never implemented) is that many of the current '__weak' functions in the PCI core can be turned into host_bridge specific operations.

Some config space operations by contrast are currently shared across host bridge drivers (see pci_bus_set_ops, or drivers/pci/ecam.c) and probably better left out of the host bridge.

Arnd

#3 lore raw

Re: [PATCH 1/3] PCI: Add hooks for bus/bridge-specific fixups

Quoted 5 lines · Arnd Bergmann

We are a bit inconsistent about adding callbacks to pci_ops or pci_host_bridge. I would argue this should be part of pci_host_bridge, and the other two should probably be there as well, or possibly moved into a separate 'pci_host_bridge_ops'
structure referenced from pci_host_bridge along with the other callbacks there.

How do we find the proper pci_host_bridge from an arbitrary device deep down the hierachy below it?

#4 lore raw

Re: [PATCH 1/3] PCI: Add hooks for bus/bridge-specific fixups

Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Arnd Bergmann

We are a bit inconsistent about adding callbacks to pci_ops or pci_host_bridge. I would argue this should be part of pci_host_bridge, and the other two should probably be there as well, or possibly moved into a separate 'pci_host_bridge_ops'
structure referenced from pci_host_bridge along with the other callbacks there.

How do we find the proper pci_host_bridge from an arbitrary device deep down the hierachy below it?

pci_get_host_bridge_device() should do the work.

#5 lore raw

PATCH 2/3 PCI/xilinx: Work-around for hardware DMA limit (32 bits)

In reply to Christoph Hellwig

From: "Wesley W. Terpstra" <[email protected]>

This PCIe bridge only has a 32 bit bus master interface, thus truncating the DMA capability of all PCIe devices attached beneath it. This caps the child device capability so that these devices work on systems with physical memory beyond the 4GiB threshold.

[hch: switched to setting the dma_32bit_limit flag instead of overriding
the dma_map_ops]

---
 drivers/pci/controller/pcie-xilinx.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/pci/controller/pcie-xilinx.c +10 -0
index b110a3a814e3..f6b41df59886 100644
@@ -197,11 +197,21 @@ static void __iomem *xilinx_pcie_map_bus(struct pci_bus *bus,
 	return port->reg_base + relbus + where;
 }
 
+/*
+ * This PCIe bridge only has a 32 bit bus master interface, thus truncating
+ * the DMA capability of all PCIe devices attached beneath it.
+ */
+static void xilinx_pcie_add_dev(struct pci_dev *pdev, struct pci_bus *bus)
+{
+	pdev->dev.dma_32bit_limit = true;
+}
+
 /* PCIe operations */
 static struct pci_ops xilinx_pcie_ops = {
 	.map_bus = xilinx_pcie_map_bus,
 	.read	= pci_generic_config_read,
 	.write	= pci_generic_config_write,
+	.add_dev = xilinx_pcie_add_dev,
 };
 
 /* MSI functions */
Signature · 1 line
2.17.1
#6 lore raw

PATCH 3/3 PCI/xilinx: Depend on OF instead of the ARCH

In reply to Christoph Hellwig

From: Palmer Dabbelt <[email protected]>

There isn't a hard dependency of the Xilinx AXI-PCIe host bridge on any architecture. For example: at SiFive we map RISC-V cores to Xilinx FPGAs and connect the Xilinx IP via a TileLink adapter, so the RISC-V Linux port will need to be able to enable PCIE_XILINX in order to have PCIe support.

This patch decouples the PCIE_XILINX support from ARCH. Instead it just depends on OF, which I believe is the only true dependency.

[hch: replaced the now removed OF_PCI dependency with just OF]
---
 drivers/pci/controller/Kconfig | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/pci/controller/Kconfig +1 -1
index 18fa09b3ac8f..1fc3d4eb373d 100644
@@ -103,7 +103,7 @@ config PCI_HOST_GENERIC
 
 config PCIE_XILINX
 	bool "Xilinx AXI PCIe host bridge support"
-	depends on ARCH_ZYNQ || MICROBLAZE || (MIPS && PCI_DRIVERS_GENERIC) || COMPILE_TEST
+	depends on OF || COMPILE_TEST
 	help
 	  Say 'Y' here if you want kernel to support the Xilinx AXI PCIe
 	  Host Bridge driver.
Signature · 1 line
2.17.1