Skip to contentSkip to conversation

pci: Add host controller driver for Cavium ThunderX PCIe

PATCH Superseded David Daney 5 participants 10 messages Dec 22, 2015 – Dec 23, 2015

Subsystems (3)

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

cover pci: Add host controller driver for Cavium ThunderX PCIe

From: David Daney <[email protected]>

Some Cavium ThunderX processors require quirky access methods for the config space of the PCIe bridge.

There are two patches:

1) Refactor code in pci-host-generic so that it can more easily be used by other drivers.

2) Add the ThunderX PCIe driver, which leverages the code in pci-host-generic

David Daney (2):
PCI: generic: Refactor code to enable reuse by other drivers. pci, pcie-thunder-pem: Add PCIe host driver for ThunderX processors.

 .../devicetree/bindings/pci/pcie-thunder-pem.txt   |  43 ++++
 drivers/pci/host/Kconfig                           |   6 +
 drivers/pci/host/Makefile                          |   1 +
 drivers/pci/host/pci-host-generic.c                |  53 ++--
 drivers/pci/host/pci-host-generic.h                |  56 ++++
 drivers/pci/host/pcie-thunder-pem.c                | 283 +++++++++++++++++++++
 6 files changed, 407 insertions(+), 35 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/pci/pcie-thunder-pem.txt
 create mode 100644 drivers/pci/host/pci-host-generic.h
 create mode 100644 drivers/pci/host/pcie-thunder-pem.c
Signature · 1 line
1.8.3.1
#1 lore raw

PATCH 1/2 PCI: generic: Refactor code to enable reuse by other drivers.

From: David Daney <[email protected]>

No change in functionality.

Move structure definitions into a separate header file. Split probe function in to two parts:

- a small driver specific probe function (gen_pci_probe)

- a common probe that can be used by other drivers (gen_pci_common_probe)

---
 drivers/pci/host/pci-host-generic.c | 53 ++++++++++++-----------------------
 drivers/pci/host/pci-host-generic.h | 56 +++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+), 35 deletions(-)
 create mode 100644 drivers/pci/host/pci-host-generic.h
drivers/pci/host/pci-host-generic.c +18 -35
index 5434c90..e83cec7 100644
@@ -25,33 +25,7 @@
 #include <linux/of_pci.h>
 #include <linux/platform_device.h>
 
-struct gen_pci_cfg_bus_ops {
-	u32 bus_shift;
-	struct pci_ops ops;
-};
-
-struct gen_pci_cfg_windows {
-	struct resource				res;
-	struct resource				*bus_range;
-	void __iomem				**win;
-
-	struct gen_pci_cfg_bus_ops		*ops;
-};
-
-/*
- * ARM pcibios functions expect the ARM struct pci_sys_data as the PCI
- * sysdata.  Add pci_sys_data as the first element in struct gen_pci so
- * that when we use a gen_pci pointer as sysdata, it is also a pointer to
- * a struct pci_sys_data.
- */
-struct gen_pci {
-#ifdef CONFIG_ARM
-	struct pci_sys_data			sys;
-#endif
-	struct pci_host_bridge			host;
-	struct gen_pci_cfg_windows		cfg;
-	struct list_head			resources;
-};
+#include "pci-host-generic.h"
 
 static void __iomem *gen_pci_map_cfg_bus_cam(struct pci_bus *bus,
 					     unsigned int devfn,
@@ -208,19 +182,15 @@ static int gen_pci_parse_map_cfg_windows(struct gen_pci *pci)
 	return 0;
 }
 
-static int gen_pci_probe(struct platform_device *pdev)
+int gen_pci_common_probe(struct platform_device *pdev,
+			 struct gen_pci *pci)
 {
 	int err;
 	const char *type;
-	const struct of_device_id *of_id;
 	struct device *dev = &pdev->dev;
 	struct device_node *np = dev->of_node;
-	struct gen_pci *pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL);
 	struct pci_bus *bus, *child;
 
-	if (!pci)
-		return -ENOMEM;
-
 	type = of_get_property(np, "device_type", NULL);
 	if (!type || strcmp(type, "pci")) {
 		dev_err(dev, "invalid \"device_type\" %s\n", type);
@@ -229,8 +199,6 @@ static int gen_pci_probe(struct platform_device *pdev)
 
 	of_pci_check_probe_only();
 
-	of_id = of_match_node(gen_pci_of_match, np);
-	pci->cfg.ops = (struct gen_pci_cfg_bus_ops *)of_id->data;
 	pci->host.dev.parent = dev;
 	INIT_LIST_HEAD(&pci->host.windows);
 	INIT_LIST_HEAD(&pci->resources);
@@ -273,6 +241,21 @@ static int gen_pci_probe(struct platform_device *pdev)
 	return 0;
 }
 
+static int gen_pci_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	const struct of_device_id *of_id;
+	struct gen_pci *pci = devm_kzalloc(dev, sizeof(*pci), GFP_KERNEL);
+
+	if (!pci)
+		return -ENOMEM;
+
+	of_id = of_match_node(gen_pci_of_match, dev->of_node);
+	pci->cfg.ops = (struct gen_pci_cfg_bus_ops *)of_id->data;
+
+	return gen_pci_common_probe(pdev, pci);
+}
+
 static struct platform_driver gen_pci_driver = {
 	.driver = {
 		.name = "pci-host-generic",
drivers/pci/host/pci-host-generic.h new file +56 -0

56 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#5 lore raw

PATCH 2/2 pci, pcie-thunder-pem: Add PCIe host driver for ThunderX processors.

In reply to David Daney

From: David Daney <[email protected]>

Some Cavium ThunderX processors require quirky access methods for the config space of the PCIe bridge. Add a driver to provide these config space accessor functions. The pci-host-generic driver code is used to configure the PCI machinery.

---
 .../devicetree/bindings/pci/pcie-thunder-pem.txt   |  43 ++++
 drivers/pci/host/Kconfig                           |   6 +
 drivers/pci/host/Makefile                          |   1 +
 drivers/pci/host/pcie-thunder-pem.c                | 283 +++++++++++++++++++++
 4 files changed, 333 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/pcie-thunder-pem.txt
 create mode 100644 drivers/pci/host/pcie-thunder-pem.c
Documentation/devicetree/bindings/pci/pcie-thunder-pem.txt new file +43 -0
new file mode 100644
index 0000000..66824d5
@@ -0,0 +1,43 @@
+* ThunderX PEM PCIe host controller
+
+Firmware-initialized PCIe host controller found on some Cavium
+ThunderX processors.
+
+The properties and their meanings are identical to those described in
+host-heneric-pci.txt except as listed below.
+
+Properties of the host controller node that differ from
+host-heneric-pci.txt:
+
+- compatible     : Must be "cavium,pci-host-thunder-pem"
+
+- reg            : Two entries: First the configuration space for down
+                   stream devices base address and size, as accessed
+                   from the parent bus. Second, the register bank of
+                   the PEM device PCIe bridge.
+
+Example:
+
+    pem2 {
+	compatible = "cavium,pci-host-thunder-pem";
+	device_type = "pci";
+	msi-parent = <&its>;
+	msi-map = <0 &its 0x10000 0x10000>;
+	bus-range = <0x8f 0xc7>;
+	#size-cells = <2>;
+	#address-cells = <3>;
+
+	reg = <0x8880 0x8f000000 0x0 0x39000000>,  /* Configuration space */
+	      <0x87e0 0xc2000000 0x0 0x00010000>; /* PEM space */
+	ranges = <0x01000000 0x00 0x00020000 0x88b0 0x00020000 0x00 0x00010000>, /* I/O */
+		 <0x03000000 0x00 0x10000000 0x8890 0x10000000 0x0f 0xf0000000>, /* mem64 */
+		 <0x43000000 0x10 0x00000000 0x88a0 0x00000000 0x10 0x00000000>, /* mem64-pref */
+		 <0x03000000 0x87e0 0xc2f00000 0x87e0 0xc2000000 0x00 0x00100000>; /* mem64 PEM BAR4 */
+
+	#interrupt-cells = <1>;
+	interrupt-map-mask = <0 0 0 7>;
+	interrupt-map = <0 0 0 1 &gic0 0 0 0 24 4>, /* INTA */
+			<0 0 0 2 &gic0 0 0 0 25 4>, /* INTB */
+			<0 0 0 3 &gic0 0 0 0 26 4>, /* INTC */
+			<0 0 0 4 &gic0 0 0 0 27 4>; /* INTD */
+    };
drivers/pci/host/Kconfig +6 -0
index f131ba9..16ed9c3 100644
@@ -172,4 +172,10 @@ config PCI_HISI
 	help
 	  Say Y here if you want PCIe controller support on HiSilicon HIP05 SoC
 
+config PCIE_HOST_THUNDER_PEM
+	bool "Cavium Thunder PCIe controller to off-chip devices"
+	depends on PCI_HOST_GENERIC && ARM64
+	help
+	  Say Y here if you want PCIe support for CN88XX Cavium Thunder SoCs.
+
 endmenu
drivers/pci/host/Makefile +1 -0
index 9d4d3c6..70bfc37 100644
@@ -20,3 +20,4 @@ obj-$(CONFIG_PCIE_IPROC_BCMA) += pcie-iproc-bcma.o
 obj-$(CONFIG_PCIE_ALTERA) += pcie-altera.o
 obj-$(CONFIG_PCIE_ALTERA_MSI) += pcie-altera-msi.o
 obj-$(CONFIG_PCI_HISI) += pcie-hisi.o
+obj-$(CONFIG_PCIE_HOST_THUNDER_PEM) += pcie-thunder-pem.o
drivers/pci/host/pcie-thunder-pem.c new file +283 -0

283 lines not on this page · raw message

Signature · 1 line
1.8.3.1
#6 lore raw

Re: [PATCH 2/2] pci, pcie-thunder-pem: Add PCIe host driver for ThunderX processors.

Quoted 23 lines · David Daney

From: David Daney <[email protected]>

Some Cavium ThunderX processors require quirky access methods for the config space of the PCIe bridge. Add a driver to provide these config space accessor functions. The pci-host-generic driver code is used to configure the PCI machinery.

---
 .../devicetree/bindings/pci/pcie-thunder-pem.txt   |  43 ++++
 drivers/pci/host/Kconfig                           |   6 +
 drivers/pci/host/Makefile                          |   1 +
 drivers/pci/host/pcie-thunder-pem.c                | 283 +++++++++++++++++++++
 4 files changed, 333 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/pcie-thunder-pem.txt
 create mode 100644 drivers/pci/host/pcie-thunder-pem.c
Documentation/devicetree/bindings/pci/pcie-thunder-pem.txt new file +0 -0
new file mode 100644
index 0000000..66824d5

Documentation/devicetree/bindings/pci/pcie-thunder-pem.txt line 10

Quoted 10 lines
Documentation/devicetree/bindings/pci/pcie-thunder-pem.txt new file +10 -0
@@ -0,0 +1,43 @@
+* ThunderX PEM PCIe host controller
+
+Firmware-initialized PCIe host controller found on some Cavium
+ThunderX processors.
+
+The properties and their meanings are identical to those described in
+host-heneric-pci.txt except as listed below.
+
+Properties of the host controller node that differ from
+host-heneric-pci.txt:

Consistently odd typo (s/heneric/generic/)!

Quoted 38 lines
Documentation/devicetree/bindings/pci/pcie-thunder-pem.txt new file +33 -0
+
+- compatible     : Must be "cavium,pci-host-thunder-pem"
+
+- reg            : Two entries: First the configuration space for down
+                   stream devices base address and size, as accessed
+                   from the parent bus. Second, the register bank of
+                   the PEM device PCIe bridge.
+
+Example:
+
+    pem2 {
+	compatible = "cavium,pci-host-thunder-pem";
+	device_type = "pci";
+	msi-parent = <&its>;
+	msi-map = <0 &its 0x10000 0x10000>;
+	bus-range = <0x8f 0xc7>;
+	#size-cells = <2>;
+	#address-cells = <3>;
+
+	reg = <0x8880 0x8f000000 0x0 0x39000000>,  /* Configuration space */
+	      <0x87e0 0xc2000000 0x0 0x00010000>; /* PEM space */
+	ranges = <0x01000000 0x00 0x00020000 0x88b0 0x00020000 0x00 0x00010000>, /* I/O */
+		 <0x03000000 0x00 0x10000000 0x8890 0x10000000 0x0f 0xf0000000>, /* mem64 */
+		 <0x43000000 0x10 0x00000000 0x88a0 0x00000000 0x10 0x00000000>, /* mem64-pref */
+		 <0x03000000 0x87e0 0xc2f00000 0x87e0 0xc2000000 0x00 0x00100000>; /* mem64 PEM BAR4 */
+
+	#interrupt-cells = <1>;
+	interrupt-map-mask = <0 0 0 7>;
+	interrupt-map = <0 0 0 1 &gic0 0 0 0 24 4>, /* INTA */
+			<0 0 0 2 &gic0 0 0 0 25 4>, /* INTB */
+			<0 0 0 3 &gic0 0 0 0 26 4>, /* INTC */
+			<0 0 0 4 &gic0 0 0 0 27 4>; /* INTD */
+    };
drivers/pci/host/Kconfig +0 -0
index f131ba9..16ed9c3 100644

drivers/pci/host/Kconfig config PCI_HISI · line 177

Quoted 6 lines
drivers/pci/host/Kconfig +3 -0
@@ -172,4 +172,10 @@ config PCI_HISI
 	help
 	  Say Y here if you want PCIe controller support on HiSilicon HIP05 SoC
 
+config PCIE_HOST_THUNDER_PEM
+	bool "Cavium Thunder PCIe controller to off-chip devices"
+	depends on PCI_HOST_GENERIC && ARM64

|| COMPILE_TEST ?

(or does the use of writeq get you? If so, maybe COMPILE_TEST && 64BIT)

Will

#2 lore raw

Re: [PATCH 1/2] PCI: generic: Refactor code to enable reuse by other drivers.

In reply to David Daney
Quoted 59 lines · David Daney

From: David Daney <[email protected]>

No change in functionality.

Move structure definitions into a separate header file. Split probe function in to two parts:

- a small driver specific probe function (gen_pci_probe)

- a common probe that can be used by other drivers (gen_pci_common_probe)

---
 drivers/pci/host/pci-host-generic.c | 53 ++++++++++++-----------------------
 drivers/pci/host/pci-host-generic.h | 56 +++++++++++++++++++++++++++++++++++++
 2 files changed, 74 insertions(+), 35 deletions(-)
 create mode 100644 drivers/pci/host/pci-host-generic.h
drivers/pci/host/pci-host-generic.c +1 -27
index 5434c90..e83cec7 100644
@@ -25,33 +25,7 @@
 #include <linux/of_pci.h>
 #include <linux/platform_device.h>
 
-struct gen_pci_cfg_bus_ops {
-	u32 bus_shift;
-	struct pci_ops ops;
-};
-
-struct gen_pci_cfg_windows {
-	struct resource				res;
-	struct resource				*bus_range;
-	void __iomem				**win;
-
-	struct gen_pci_cfg_bus_ops		*ops;
-};
-
-/*
- * ARM pcibios functions expect the ARM struct pci_sys_data as the PCI
- * sysdata.  Add pci_sys_data as the first element in struct gen_pci so
- * that when we use a gen_pci pointer as sysdata, it is also a pointer to
- * a struct pci_sys_data.
- */
-struct gen_pci {
-#ifdef CONFIG_ARM
-	struct pci_sys_data			sys;
-#endif
-	struct pci_host_bridge			host;
-	struct gen_pci_cfg_windows		cfg;
-	struct list_head			resources;
-};
+#include "pci-host-generic.h"
 
 static void __iomem *gen_pci_map_cfg_bus_cam(struct pci_bus *bus,
 					     unsigned int devfn,

drivers/pci/host/pci-host-generic.c static int gen_pci_parse_map_cfg_windows(struct gen_pci *pci) · line 186

Quoted 6 lines
drivers/pci/host/pci-host-generic.c +2 -1
@@ -208,19 +182,15 @@ static int gen_pci_parse_map_cfg_windows(struct gen_pci *pci)
 	return 0;
 }
 
-static int gen_pci_probe(struct platform_device *pdev)
+int gen_pci_common_probe(struct platform_device *pdev,
+			 struct gen_pci *pci)

Whilst I'm fine with this patch, I don't know how Bjorn will feel about exposing this function outside of the generic host driver. We could avoid it by turning things upside-down and having the generic driver probe the other drivers by matching a compatible string with a probe function pointer, but I'd be interested to see what others think.

Will

#3 lore raw

Re: [PATCH 1/2] PCI: generic: Refactor code to enable reuse by other drivers.

Quoted 24 lines · Will Deacon
Quoted 23 lines · David Daney

From: David Daney <[email protected]>

No change in functionality.

Move structure definitions into a separate header file. Split probe function in to two parts:

- a small driver specific probe function (gen_pci_probe)

- a common probe that can be used by other drivers (gen_pci_common_probe)

---
  drivers/pci/host/pci-host-generic.c | 53 ++++++++++++-----------------------
  drivers/pci/host/pci-host-generic.h | 56 +++++++++++++++++++++++++++++++++++++
  2 files changed, 74 insertions(+), 35 deletions(-)

create mode 100644 drivers/pci/host/pci-host-generic.h

drivers/pci/host/pci-host-generic.c +0 -0
index 5434c90..e83cec7 100644

[...]

Quoted 10 lines

drivers/pci/host/pci-host-generic.c static int gen_pci_parse_map_cfg_windows(struct gen_pci *pci) · line 186

Quoted 3 lines
drivers/pci/host/pci-host-generic.c +2 -1
-static int gen_pci_probe(struct platform_device *pdev)
+int gen_pci_common_probe(struct platform_device *pdev,
+			 struct gen_pci *pci)

Whilst I'm fine with this patch, I don't know how Bjorn will feel about exposing this function outside of the generic host driver. We could avoid it by turning things upside-down and having the generic driver probe the other drivers by matching a compatible string with a probe function pointer, but I'd be interested to see what others think.

Note: I know that pci-host-generic is not built as a loadable module, but...

struct of_device_id, MODULE_DEVICE_TABLE, struct platform_driver and the registering of platform drivers is fairly well standardized in the kernel, and module loading userpace tools.

The struct of_device_id, MODULE_DEVICE_TABLE must really reside in the
same module as the driver for the device. We are creating a separate
driver precisely because we don't want to mix all this ThunderX specific code into the pci-host-generic driver when it is used by arm-32bit and others. This means that, at a minimum, we would have to export the pci-host-generic probe function so that it could be referenced by struct platform_driver in other modules.

This brings up the next problem. How to attach driver specific data to the generic driver structures? At first I tried augmenting struct gen_pci_cfg_bus_ops with a callback .init() function to be called by the generic driver, but this would also require adding an an element to struct gen_pci to point to a driver specific data object. It felt a little convoluted and complex.

This led me to the current design where struct gen_pci is embedded in the driver specific structure, and the allocation of this is done in the driver specific probe function. No more callbacks, no additions to the pci-host-generic structures. I think it is a little cleaner this way.

If there are suggestions as to how it can be made cleaner yet, I would be happy to implement and test them.

David Daney

Quoted 2 lines

Will

#7 lore raw

Re: [PATCH 2/2] pci, pcie-thunder-pem: Add PCIe host driver for ThunderX processors.

In reply to Will Deacon
Quoted 28 lines · Will Deacon
Quoted 27 lines · David Daney

From: David Daney <[email protected]>

Some Cavium ThunderX processors require quirky access methods for the config space of the PCIe bridge. Add a driver to provide these config space accessor functions. The pci-host-generic driver code is used to configure the PCI machinery.

---
  .../devicetree/bindings/pci/pcie-thunder-pem.txt   |  43 ++++
  drivers/pci/host/Kconfig                           |   6 +
  drivers/pci/host/Makefile                          |   1 +
  drivers/pci/host/pcie-thunder-pem.c                | 283 +++++++++++++++++++++
  4 files changed, 333 insertions(+)

create mode 100644 Documentation/devicetree/bindings/pci/pcie-thunder-pem.txt create mode 100644 drivers/pci/host/pcie-thunder-pem.c

Documentation/devicetree/bindings/pci/pcie-thunder-pem.txt new file +4 -0
new file mode 100644
index 0000000..66824d5
@@ -0,0 +1,43 @@
+* ThunderX PEM PCIe host controller
+
+Firmware-initialized PCIe host controller found on some Cavium
+ThunderX processors.
Quoted 9 lines

Documentation/devicetree/bindings/pci/pcie-thunder-pem.txt line 10

Quoted 6 lines
Documentation/devicetree/bindings/pci/pcie-thunder-pem.txt new file +6 -0
+
+The properties and their meanings are identical to those described in
+host-heneric-pci.txt except as listed below.
+
+Properties of the host controller node that differ from
+host-heneric-pci.txt:

Consistently odd typo (s/heneric/generic/)!

I'm not sure how I managed to do that. I will fix these and resend.

Quoted 41 lines
Quoted 41 lines
Documentation/devicetree/bindings/pci/pcie-thunder-pem.txt new file +33 -0
+
+- compatible     : Must be "cavium,pci-host-thunder-pem"
+
+- reg            : Two entries: First the configuration space for down
+                   stream devices base address and size, as accessed
+                   from the parent bus. Second, the register bank of
+                   the PEM device PCIe bridge.
+
+Example:
+
+    pem2 {
+	compatible = "cavium,pci-host-thunder-pem";
+	device_type = "pci";
+	msi-parent = <&its>;
+	msi-map = <0 &its 0x10000 0x10000>;
+	bus-range = <0x8f 0xc7>;
+	#size-cells = <2>;
+	#address-cells = <3>;
+
+	reg = <0x8880 0x8f000000 0x0 0x39000000>,  /* Configuration space */
+	      <0x87e0 0xc2000000 0x0 0x00010000>; /* PEM space */
+	ranges = <0x01000000 0x00 0x00020000 0x88b0 0x00020000 0x00 0x00010000>, /* I/O */
+		 <0x03000000 0x00 0x10000000 0x8890 0x10000000 0x0f 0xf0000000>, /* mem64 */
+		 <0x43000000 0x10 0x00000000 0x88a0 0x00000000 0x10 0x00000000>, /* mem64-pref */
+		 <0x03000000 0x87e0 0xc2f00000 0x87e0 0xc2000000 0x00 0x00100000>; /* mem64 PEM BAR4 */
+
+	#interrupt-cells = <1>;
+	interrupt-map-mask = <0 0 0 7>;
+	interrupt-map = <0 0 0 1 &gic0 0 0 0 24 4>, /* INTA */
+			<0 0 0 2 &gic0 0 0 0 25 4>, /* INTB */
+			<0 0 0 3 &gic0 0 0 0 26 4>, /* INTC */
+			<0 0 0 4 &gic0 0 0 0 27 4>; /* INTD */
+    };
drivers/pci/host/Kconfig +0 -0
index f131ba9..16ed9c3 100644
@@ -172,4 +172,10 @@ config PCI_HISI
  	help
  	  Say Y here if you want PCIe controller support on HiSilicon HIP05 SoC
 
Quoted 7 lines

drivers/pci/host/Kconfig config PCI_HISI · line 177

Quoted 3 lines
drivers/pci/host/Kconfig +3 -0
+config PCIE_HOST_THUNDER_PEM
+	bool "Cavium Thunder PCIe controller to off-chip devices"
+	depends on PCI_HOST_GENERIC && ARM64

|| COMPILE_TEST ?

(or does the use of writeq get you? If so, maybe COMPILE_TEST && 64BIT)

Yes, we must use writeq in the driver, I will change it to ||(COMPILE_TEST && 64BIT)

Thanks,
David Daney

Quoted 3 lines

Will

#4 lore raw

Re: [PATCH 1/2] PCI: generic: Refactor code to enable reuse by other drivers.

In reply to David Daney
Quoted 19 lines · David Daney
Quoted 6 lines · Will Deacon
Quoted 5 lines · David Daney

From: David Daney <[email protected]>

drivers/pci/host/pci-host-generic.c +0 -0
index 5434c90..e83cec7 100644

[...]

Quoted 10 lines

drivers/pci/host/pci-host-generic.c static int gen_pci_parse_map_cfg_windows(struct gen_pci *pci) · line 186

Quoted 3 lines
drivers/pci/host/pci-host-generic.c +2 -1
-static int gen_pci_probe(struct platform_device *pdev)
+int gen_pci_common_probe(struct platform_device *pdev,
+			 struct gen_pci *pci)

Whilst I'm fine with this patch, I don't know how Bjorn will feel about exposing this function outside of the generic host driver. We could avoid it by turning things upside-down and having the generic driver probe the other drivers by matching a compatible string with a probe function pointer, but I'd be interested to see what others think.

Quoted 5 lines

Note: I know that pci-host-generic is not built as a loadable module, but...

struct of_device_id, MODULE_DEVICE_TABLE, struct platform_driver and the registering of platform drivers is fairly well standardized in the kernel, and module loading userpace tools.

Agreed, this is the correct way to do the abstraction if we want one, the way that Will describes is generally not a good idea, and we've converted a number of drivers that did it like that to the way you do it here.

Quoted 7 lines

The struct of_device_id, MODULE_DEVICE_TABLE must really reside in the
same module as the driver for the device. We are creating a separate
driver precisely because we don't want to mix all this ThunderX specific code into the pci-host-generic driver when it is used by arm-32bit and others. This means that, at a minimum, we would have to export the pci-host-generic probe function so that it could be referenced by struct platform_driver in other modules.

Right.

Quoted 7 lines

This brings up the next problem. How to attach driver specific data to the generic driver structures? At first I tried augmenting struct gen_pci_cfg_bus_ops with a callback .init() function to be called by the generic driver, but this would also require adding an an element to struct gen_pci to point to a driver specific data object. It felt a little convoluted and complex.

Quoted 7 lines

This led me to the current design where struct gen_pci is embedded in the driver specific structure, and the allocation of this is done in the driver specific probe function. No more callbacks, no additions to the pci-host-generic structures. I think it is a little cleaner this way.

If there are suggestions as to how it can be made cleaner yet, I would be happy to implement and test them.

My idea of the long-term direction for the pci-host-generic driver would be to move more parts into the PCI core code as library functions that can be used by other drivers as well. This would also address my other concern that I'd like to see the generic host driver remain the simplest example that we have, and only require any additional code in other drivers to add functionality or workarounds.

Adding an abstraction layer within the driver to some degree goes in the opposite direction of that.

One approach that might work would be to split the existing driver into three files: one for CAM, one for ECAM and one for the common parts, with an interface similar to what you have here. Then you can add your driver as a third front-end, and we can keep working on integrating the common parts further into the PCI core.

Arnd

#8 lore raw

Re: [PATCH 2/2] pci, pcie-thunder-pem: Add PCIe host driver for ThunderX processors.

In reply to David Daney
Quoted 3 lines · David Daney
Quoted 2 lines · Will Deacon
Quoted 1 line · David Daney

From: David Daney <[email protected]>

[...]

Quoted 15 lines
Quoted 15 lines

drivers/pci/host/Kconfig config PCI_HISI · line 177

Quoted 12 lines
drivers/pci/host/Kconfig +0 -0
index f131ba9..16ed9c3 100644
@@ -172,4 +172,10 @@ config PCI_HISI
      help
        Say Y here if you want PCIe controller support on HiSilicon

HIP05 SoC

drivers/pci/host/Kconfig +3 -0
+config PCIE_HOST_THUNDER_PEM
+    bool "Cavium Thunder PCIe controller to off-chip devices"
+    depends on PCI_HOST_GENERIC && ARM64

|| COMPILE_TEST ?

Quoted 5 lines
Quoted 1 line

(or does the use of writeq get you? If so, maybe COMPILE_TEST && 64BIT)

Yes, we must use writeq in the driver, I will change it to ||(COMPILE_TEST && 64BIT)

Actually, it turns out that this is not easily done.

For x86, it appears difficult to include asm-generic/pci-bridge.h which includes the needed definition of PCI_PROBE_ONLY. So I think it is not worth supporting COMPILE_TEST

David Daney

maintainer
#9 lore raw

Re: [PATCH 2/2] pci, pcie-thunder-pem: Add PCIe host driver for ThunderX processors.

In reply to David Daney
Quoted 23 lines · David Daney

From: David Daney <[email protected]>

Some Cavium ThunderX processors require quirky access methods for the config space of the PCIe bridge. Add a driver to provide these config space accessor functions. The pci-host-generic driver code is used to configure the PCI machinery.

---
 .../devicetree/bindings/pci/pcie-thunder-pem.txt   |  43 ++++
 drivers/pci/host/Kconfig                           |   6 +
 drivers/pci/host/Makefile                          |   1 +
 drivers/pci/host/pcie-thunder-pem.c                | 283 +++++++++++++++++++++
 4 files changed, 333 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/pcie-thunder-pem.txt
 create mode 100644 drivers/pci/host/pcie-thunder-pem.c
Documentation/devicetree/bindings/pci/pcie-thunder-pem.txt new file +0 -0
new file mode 100644
index 0000000..66824d5

Documentation/devicetree/bindings/pci/pcie-thunder-pem.txt line 7

Quoted 7 lines
Documentation/devicetree/bindings/pci/pcie-thunder-pem.txt new file +7 -0
@@ -0,0 +1,43 @@
+* ThunderX PEM PCIe host controller
+
+Firmware-initialized PCIe host controller found on some Cavium
+ThunderX processors.
+
+The properties and their meanings are identical to those described in
+host-heneric-pci.txt except as listed below.

s/heneric/generic/

Documentation/devicetree/bindings/pci/pcie-thunder-pem.txt line 10

Quoted 3 lines
Documentation/devicetree/bindings/pci/pcie-thunder-pem.txt new file +3 -0
+
+Properties of the host controller node that differ from
+host-heneric-pci.txt:

ditto

Documentation/devicetree/bindings/pci/pcie-thunder-pem.txt line 12

Quoted 2 lines
Documentation/devicetree/bindings/pci/pcie-thunder-pem.txt new file +2 -0
+
+- compatible     : Must be "cavium,pci-host-thunder-pem"

pcie rather than pci?

Documentation/devicetree/bindings/pci/pcie-thunder-pem.txt line 21

Quoted 9 lines
Documentation/devicetree/bindings/pci/pcie-thunder-pem.txt new file +9 -0
+
+- reg            : Two entries: First the configuration space for down
+                   stream devices base address and size, as accessed
+                   from the parent bus. Second, the register bank of
+                   the PEM device PCIe bridge.
+
+Example:
+
+    pem2 {

pcie-controller at ...

Quoted 22 lines
Documentation/devicetree/bindings/pci/pcie-thunder-pem.txt new file +22 -0
+	compatible = "cavium,pci-host-thunder-pem";
+	device_type = "pci";
+	msi-parent = <&its>;
+	msi-map = <0 &its 0x10000 0x10000>;
+	bus-range = <0x8f 0xc7>;
+	#size-cells = <2>;
+	#address-cells = <3>;
+
+	reg = <0x8880 0x8f000000 0x0 0x39000000>,  /* Configuration space */
+	      <0x87e0 0xc2000000 0x0 0x00010000>; /* PEM space */
+	ranges = <0x01000000 0x00 0x00020000 0x88b0 0x00020000 0x00 0x00010000>, /* I/O */
+		 <0x03000000 0x00 0x10000000 0x8890 0x10000000 0x0f 0xf0000000>, /* mem64 */
+		 <0x43000000 0x10 0x00000000 0x88a0 0x00000000 0x10 0x00000000>, /* mem64-pref */
+		 <0x03000000 0x87e0 0xc2f00000 0x87e0 0xc2000000 0x00 0x00100000>; /* mem64 PEM BAR4 */
+
+	#interrupt-cells = <1>;
+	interrupt-map-mask = <0 0 0 7>;
+	interrupt-map = <0 0 0 1 &gic0 0 0 0 24 4>, /* INTA */
+			<0 0 0 2 &gic0 0 0 0 25 4>, /* INTB */
+			<0 0 0 3 &gic0 0 0 0 26 4>, /* INTC */
+			<0 0 0 4 &gic0 0 0 0 27 4>; /* INTD */
+    };