Skip to contentSkip to conversation

pci: iproc: Add Broadcom iProc PCIe support

PATCH Superseded Ray Jui 4 participants 10 messages Mar 6, 2015 – Mar 9, 2015

Subsystems (4)

v3 of 9 Superseded Latest is v9 →

lore
Share & tools
lore

Ray Jui

author maintainer
#0 lore raw

v3 cover pci: iproc: Add Broadcom iProc PCIe support

This patch series adds the support for Broadcom iProc PCIe controller

pcie-iproc.c servers as the common core driver, and front-end bus interface needs to be added to support different bus interfaces

pcie-iproc-pltfm.c contains the support for the platform bus interface

Changes from v2:
- Major rework of the PCIe driver to factor out common generic code from front-end bus interface. Support for generic platform bus interface is also added
- Adapt to several new PCI APIs that have been introduced lately

Changes from v1:
- Add standard PCI interrupt DT properties "#interrupt-cells", "interrupt-map-mask" and "interrupt-map" so legacy INTx interrupts can be supported by using standard PCI OF IRQ parsing function
- Get rid of custom IRQ mapping function in the driver. Use of_irq_parse_and_map_pci instead

Ray Jui (3):
pci: iProc: define iProc PCIe platform bus binding
pci: iproc: Add Broadcom iProc PCIe support
ARM: dts: enable PCIe support for Cygnus

 .../devicetree/bindings/pci/brcm,iproc-pcie.txt    |   63 ++++
 arch/arm/boot/dts/bcm-cygnus.dtsi                  |   42 +++
 arch/arm/boot/dts/bcm958300k.dts                   |    8 +
 drivers/pci/host/Kconfig                           |   17 +
 drivers/pci/host/Makefile                          |    2 +
 drivers/pci/host/pcie-iproc-pltfm.c                |  101 ++++++
 drivers/pci/host/pcie-iproc.c                      |  337 ++++++++++++++++++++
 drivers/pci/host/pcie-iproc.h                      |   39 +++
 8 files changed, 609 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/brcm,iproc-pcie.txt
 create mode 100644 drivers/pci/host/pcie-iproc-pltfm.c
 create mode 100644 drivers/pci/host/pcie-iproc.c
 create mode 100644 drivers/pci/host/pcie-iproc.h
Signature · 1 line
1.7.9.5
author maintainer
#1 lore raw

PATCH v3 1/3 pci: iProc: define iProc PCIe platform bus binding

Document the Broadcom iProc PCIe platform interface device tree binding

---
 .../devicetree/bindings/pci/brcm,iproc-pcie.txt    |   63 ++++++++++++++++++++
 1 file changed, 63 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/pci/brcm,iproc-pcie.txt
Documentation/devicetree/bindings/pci/brcm,iproc-pcie.txt new file +63 -0
new file mode 100644
index 0000000..f7ce50e
@@ -0,0 +1,63 @@
+* Broadcom iProc PCIe controller with the platform bus interface
+
+Required properties:
+- compatible: Must be "brcm,iproc-pcie"
+- reg: base address and length of the PCIe controller I/O register space
+- #interrupt-cells: set to <1>
+- interrupt-map-mask and interrupt-map, standard PCI properties to define the
+  mapping of the PCIe interface to interrupt numbers
+- linux,pci-domain: PCI domain ID. Should be unique for each host controller
+- bus-range: PCI bus numbers covered
+- #address-cells: set to <3>
+- #size-cells: set to <2>
+- device_type: set to "pci"
+- ranges: ranges for the PCI memory and I/O regions
+
+Optional properties:
+- phys: phandle of the PCIe PHY device
+- phy-names: must be "pcie-phy"
+
+Example:
+	pcie0: pcie@18012000 {
+		compatible = "brcm,iproc-pcie";
+		reg = <0x18012000 0x1000>;
+
+		#interrupt-cells = <1>;
+		interrupt-map-mask = <0 0 0 0>;
+		interrupt-map = <0 0 0 0 &gic GIC_SPI 100 IRQ_TYPE_NONE>;
+
+		linux,pci-domain = <0>;
+
+		bus-range = <0x00 0xff>;
+
+		#address-cells = <3>;
+		#size-cells = <2>;
+		device_type = "pci";
+		ranges = <0x81000000 0 0	  0x28000000 0 0x00010000
+			  0x82000000 0 0x20000000 0x20000000 0 0x04000000>;
+
+		phys = <&phy 0 5>;
+		phy-names = "pcie-phy";
+	};
+
+	pcie1: pcie@18013000 {
+		compatible = "brcm,iproc-pcie";
+		reg = <0x18013000 0x1000>;
+
+		#interrupt-cells = <1>;
+		interrupt-map-mask = <0 0 0 0>;
+		interrupt-map = <0 0 0 0 &gic GIC_SPI 106 IRQ_TYPE_NONE>;
+
+		linux,pci-domain = <1>;
+
+		bus-range = <0x00 0xff>;
+
+		#address-cells = <3>;
+		#size-cells = <2>;
+		device_type = "pci";
+		ranges = <0x81000000 0 0	  0x48000000 0 0x00010000
+			  0x82000000 0 0x40000000 0x40000000 0 0x04000000>;
+
+		phys = <&phy 1 6>;
+		phy-names = "pcie-phy";
+	};
Signature · 1 line
1.7.9.5
author maintainer
#9 lore raw

PATCH v3 3/3 ARM: dts: enable PCIe support for Cygnus

In reply to Ray Jui

Add PCIe device nodes in bcm-cygnus.dtsi but keep them disabled there. Only enable them for bcm958300k where PCIe interfaces are populated

---
 arch/arm/boot/dts/bcm-cygnus.dtsi |   42 +++++++++++++++++++++++++++++++++++++
 arch/arm/boot/dts/bcm958300k.dts  |    8 +++++++
 2 files changed, 50 insertions(+)
arch/arm/boot/dts/bcm-cygnus.dtsi +42 -0
index ff5fb6a..ee0c6e4 100644
@@ -90,6 +90,48 @@
 		status = "disabled";
 	};
 
+	pcie0: pcie@18012000 {
+		compatible = "brcm,iproc-pcie";
+		reg = <0x18012000 0x1000>;
+
+		#interrupt-cells = <1>;
+		interrupt-map-mask = <0 0 0 0>;
+		interrupt-map = <0 0 0 0 &gic GIC_SPI 100 IRQ_TYPE_NONE>;
+
+		linux,pci-domain = <0>;
+
+		bus-range = <0x00 0xff>;
+
+		#address-cells = <3>;
+		#size-cells = <2>;
+		device_type = "pci";
+		ranges = <0x81000000 0 0	  0x28000000 0 0x00010000
+			  0x82000000 0 0x20000000 0x20000000 0 0x04000000>;
+
+		status = "disabled";
+	};
+
+	pcie1: pcie@18013000 {
+		compatible = "brcm,iproc-pcie";
+		reg = <0x18013000 0x1000>;
+
+		#interrupt-cells = <1>;
+		interrupt-map-mask = <0 0 0 0>;
+		interrupt-map = <0 0 0 0 &gic GIC_SPI 106 IRQ_TYPE_NONE>;
+
+		linux,pci-domain = <1>;
+
+		bus-range = <0x00 0xff>;
+
+		#address-cells = <3>;
+		#size-cells = <2>;
+		device_type = "pci";
+		ranges = <0x81000000 0 0	  0x48000000 0 0x00010000
+			  0x82000000 0 0x40000000 0x40000000 0 0x04000000>;
+
+		status = "disabled";
+	};
+
 	uart0: serial@18020000 {
 		compatible = "snps,dw-apb-uart";
 		reg = <0x18020000 0x100>;
arch/arm/boot/dts/bcm958300k.dts +8 -0
index f1bb36f..c9eb856 100644
@@ -47,6 +47,14 @@
 		bootargs = "console=ttyS0,115200";
 	};
 
+	pcie0: pcie@18012000 {
+		status = "okay";
+	};
+
+	pcie1: pcie@18013000 {
+		status = "okay";
+	};
+
 	uart3: serial@18023000 {
 		status = "okay";
 	};
Signature · 1 line
1.7.9.5
author maintainer
#2 lore raw

PATCH v3 2/3 pci: iproc: Add Broadcom iProc PCIe support

In reply to Ray Jui

This adds the support for Broadcom iProc PCIe controller

pcie-iproc.c servers as the common core driver, and front-end bus interface needs to be added to support different bus interfaces

pcie-iproc-pltfm.c contains the support for the platform bus interface

---
 drivers/pci/host/Kconfig            |   17 ++
 drivers/pci/host/Makefile           |    2 +
 drivers/pci/host/pcie-iproc-pltfm.c |  101 +++++++++++
 drivers/pci/host/pcie-iproc.c       |  337 +++++++++++++++++++++++++++++++++++
 drivers/pci/host/pcie-iproc.h       |   39 ++++
 5 files changed, 496 insertions(+)
 create mode 100644 drivers/pci/host/pcie-iproc-pltfm.c
 create mode 100644 drivers/pci/host/pcie-iproc.c
 create mode 100644 drivers/pci/host/pcie-iproc.h
drivers/pci/host/Kconfig +17 -0
index 7b892a9..e10c3e3 100644
@@ -106,4 +106,21 @@ config PCI_VERSATILE
 	bool "ARM Versatile PB PCI controller"
 	depends on ARCH_VERSATILE
 
+config PCIE_IPROC
+	bool "Broadcom iProc PCIe controller"
+	help
+	  This enables the iProc PCIe core controller support for Broadcom's
+	  iProc family of SoCs. An appropriate bus interface driver also needs
+	  to be enabled
+
+config PCIE_IPROC_PLTFM
+	bool "Broadcom iProc PCIe platform bus driver"
+	depends on ARCH_BCM_IPROC || COMPILE_TEST
+	depends on OF
+	select PCIE_IPROC
+	default ARCH_BCM_IPROC
+	help
+	  Say Y here if you want to use the Broadcom iProc PCIe controller
+	  through the generic platform bus interface
+
 endmenu
drivers/pci/host/Makefile +2 -0
index e61d91c..2e02d20 100644
@@ -13,3 +13,5 @@ obj-$(CONFIG_PCIE_XILINX) += pcie-xilinx.o
 obj-$(CONFIG_PCI_XGENE) += pci-xgene.o
 obj-$(CONFIG_PCI_LAYERSCAPE) += pci-layerscape.o
 obj-$(CONFIG_PCI_VERSATILE) += pci-versatile.o
+obj-$(CONFIG_PCIE_IPROC) += pcie-iproc.o
+obj-$(CONFIG_PCIE_IPROC_PLTFM) += pcie-iproc-pltfm.o
drivers/pci/host/pcie-iproc-pltfm.c new file +101 -0

101 lines not on this page · raw message

drivers/pci/host/pcie-iproc.c new file +337 -0

337 lines not on this page · raw message

drivers/pci/host/pcie-iproc.h new file +39 -0
new file mode 100644
index 0000000..4e2437e
@@ -0,0 +1,39 @@
+/*
+ * Copyright (C) 2014-2015 Broadcom Corporation
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation version 2.
+ *
+ * This program is distributed "as is" WITHOUT ANY WARRANTY of any
+ * kind, whether express or implied; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef _PCIE_IPROC_H
+#define _PCIE_IPROC_H
+
+#define IPROC_PCIE_MAX_NUM_IRQS 6
+
+/**
+ * iProc PCIe device
+ * @dev: pointer to device data structure
+ * @base: PCIe host controller I/O register base
+ * @resources: linked list of all PCI resources
+ * @sysdata: Per PCI controller data
+ * @phy: optional PHY device that controls the Serdes
+ * @irqs: interrupt IDs
+ */
+struct iproc_pcie {
+	struct device *dev;
+	void __iomem *base;
+	struct list_head *resources;
+	struct pci_sys_data sysdata;
+	struct phy *phy;
+	int irqs[IPROC_PCIE_MAX_NUM_IRQS];
+};
+
+extern int iproc_pcie_setup(struct iproc_pcie *pcie);
+
+#endif /* _PCIE_IPROC_H */
Signature · 1 line
1.7.9.5
#3 lore raw

drivers/pci/host/Kconfig config PCI_VERSATILE · line 110

Quoted 8 lines · Ray Jui
drivers/pci/host/Kconfig +2 -0
@@ -106,4 +106,21 @@ config PCI_VERSATILE
 	bool "ARM Versatile PB PCI controller"
 	depends on ARCH_VERSATILE
 
+config PCIE_IPROC
+	bool "Broadcom iProc PCIe controller"

bool symbol.

drivers/pci/host/Kconfig config PCI_VERSATILE · line 117

Quoted 7 lines
drivers/pci/host/Kconfig +7 -0
+	help
+	  This enables the iProc PCIe core controller support for Broadcom's
+	  iProc family of SoCs. An appropriate bus interface driver also needs
+	  to be enabled
+
+config PCIE_IPROC_PLTFM
+	bool "Broadcom iProc PCIe platform bus driver"

Another bool symbol.

Quoted 12 lines
drivers/pci/host/Kconfig +8 -0
+	depends on ARCH_BCM_IPROC || COMPILE_TEST
+	depends on OF
+	select PCIE_IPROC
+	default ARCH_BCM_IPROC
+	help
+	  Say Y here if you want to use the Broadcom iProc PCIe controller
+	  through the generic platform bus interface
+
 endmenu

drivers/pci/host/Makefile obj-$(CONFIG_PCIE_XILINX) += pcie-xilinx.o · line 17

Quoted 3 lines
drivers/pci/host/Makefile +2 -0
 
+obj-$(CONFIG_PCIE_IPROC) += pcie-iproc.o
+obj-$(CONFIG_PCIE_IPROC_PLTFM) += pcie-iproc-pltfm.o

Both objectfiles will never be part of a module.

drivers/pci/host/pcie-iproc-pltfm.c

Quoted 4 lines
drivers/pci/host/pcie-iproc-pltfm.c new file +1 -0
 
+#include <linux/module.h>

Is this needed?

Quoted 1 line

+MODULE_DEVICE_TABLE(of, iproc_pcie_of_match_table);

This macro will be preprocessed away, won't it?

drivers/pci/host/pcie-iproc-pltfm.c line 97

Quoted 9 lines
drivers/pci/host/pcie-iproc-pltfm.c new file +9 -0
+static struct platform_driver iproc_pcie_pltfm_driver = {
+	.driver = {
+		.name = "iproc-pcie",
+		.of_match_table = of_match_ptr(iproc_pcie_of_match_table),
+		.suppress_bind_attrs = true,
+	},
+	.probe = iproc_pcie_pltfm_probe,
+};
+module_platform_driver(iproc_pcie_pltfm_driver);

Perhaps it's clearer to have make this a call to platform_driver_register(), put that in a wrapper function, and invoke that wrapper function through device_initcall() or similar. I haven't actually tested that, so the details could be off.

drivers/pci/host/pcie-iproc-pltfm.c line 101

Quoted 3 lines
drivers/pci/host/pcie-iproc-pltfm.c new file +3 -0
+MODULE_AUTHOR("Ray Jui <[email protected]>");
+MODULE_DESCRIPTION("Broadcom iPROC PCIe platform driver");
+MODULE_LICENSE("GPL v2");

And these three macros will, effectively, be preprocessed away.

drivers/pci/host/pcie-iproc.c

Quoted 4 lines
drivers/pci/host/pcie-iproc.c new file +1 -0
 
+#include <linux/module.h>

See above.

drivers/pci/host/pcie-iproc.c line 337

Quoted 3 lines
drivers/pci/host/pcie-iproc.c new file +3 -0
+MODULE_AUTHOR("Ray Jui <[email protected]>");
+MODULE_DESCRIPTION("Broadcom iPROC PCIe common driver");
+MODULE_LICENSE("GPL v2");

Ditto.

Paul Bolle

author maintainer
#4 lore raw

Hi Paul,

Quoted 79 lines · Paul Bolle

drivers/pci/host/Kconfig config PCI_VERSATILE · line 110

Quoted 8 lines · Ray Jui
drivers/pci/host/Kconfig +2 -0
@@ -106,4 +106,21 @@ config PCI_VERSATILE
 	bool "ARM Versatile PB PCI controller"
 	depends on ARCH_VERSATILE
 
+config PCIE_IPROC
+	bool "Broadcom iProc PCIe controller"

bool symbol.

drivers/pci/host/Kconfig config PCI_VERSATILE · line 117

Quoted 7 lines
drivers/pci/host/Kconfig +7 -0
+	help
+	  This enables the iProc PCIe core controller support for Broadcom's
+	  iProc family of SoCs. An appropriate bus interface driver also needs
+	  to be enabled
+
+config PCIE_IPROC_PLTFM
+	bool "Broadcom iProc PCIe platform bus driver"

Another bool symbol.

Quoted 12 lines
drivers/pci/host/Kconfig +8 -0
+	depends on ARCH_BCM_IPROC || COMPILE_TEST
+	depends on OF
+	select PCIE_IPROC
+	default ARCH_BCM_IPROC
+	help
+	  Say Y here if you want to use the Broadcom iProc PCIe controller
+	  through the generic platform bus interface
+
 endmenu

drivers/pci/host/Makefile obj-$(CONFIG_PCIE_XILINX) += pcie-xilinx.o · line 17

Quoted 3 lines
drivers/pci/host/Makefile +2 -0
 
+obj-$(CONFIG_PCIE_IPROC) += pcie-iproc.o
+obj-$(CONFIG_PCIE_IPROC_PLTFM) += pcie-iproc-pltfm.o

Both objectfiles will never be part of a module.

drivers/pci/host/pcie-iproc-pltfm.c

Quoted 4 lines
drivers/pci/host/pcie-iproc-pltfm.c new file +1 -0
 
+#include <linux/module.h>

Is this needed?

Quoted 1 line

+MODULE_DEVICE_TABLE(of, iproc_pcie_of_match_table);

This macro will be preprocessed away, won't it?

drivers/pci/host/pcie-iproc-pltfm.c line 97

Quoted 9 lines
drivers/pci/host/pcie-iproc-pltfm.c new file +9 -0
+static struct platform_driver iproc_pcie_pltfm_driver = {
+	.driver = {
+		.name = "iproc-pcie",
+		.of_match_table = of_match_ptr(iproc_pcie_of_match_table),
+		.suppress_bind_attrs = true,
+	},
+	.probe = iproc_pcie_pltfm_probe,
+};
+module_platform_driver(iproc_pcie_pltfm_driver);

Perhaps it's clearer to have make this a call to platform_driver_register(), put that in a wrapper function, and invoke that wrapper function through device_initcall() or similar. I haven't actually tested that, so the details could be off.

drivers/pci/host/pcie-iproc-pltfm.c line 101

Quoted 3 lines
drivers/pci/host/pcie-iproc-pltfm.c new file +3 -0
+MODULE_AUTHOR("Ray Jui <[email protected]>");
+MODULE_DESCRIPTION("Broadcom iPROC PCIe platform driver");
+MODULE_LICENSE("GPL v2");

And these three macros will, effectively, be preprocessed away.

drivers/pci/host/pcie-iproc.c

Quoted 4 lines
drivers/pci/host/pcie-iproc.c new file +1 -0
 
+#include <linux/module.h>

See above.

Quoted 9 lines

drivers/pci/host/pcie-iproc.c line 337

Quoted 3 lines
drivers/pci/host/pcie-iproc.c new file +3 -0
+MODULE_AUTHOR("Ray Jui <[email protected]>");
+MODULE_DESCRIPTION("Broadcom iPROC PCIe common driver");
+MODULE_LICENSE("GPL v2");

Ditto.

Paul Bolle

So every single PCIe host driver under drivers/pci/host/* has their config flag of "bool" type, and all of them except pci-keystone-dw.c have these MODULE based macros in their driver. While I agree with you that these macros will preprocessed away while compiled as statically linked in, I thought it's a convention to have these macros in the driver. At least it provides information on the author, driver description, and license (although one can also argue you can find all of those info from the maintainer list, Kconfig, and license header).

Would you be able to sort this out with a developer or subsystem maintainer who is familiar with this matter and let us know what is the convention for MODULE macros usage in a driver when its config flag is set to "bool" instead of "tristate"?

Thanks,

Ray

#5 lore raw
Quoted 101 lines · Ray Jui

Hi Paul,

Quoted 79 lines · Paul Bolle

drivers/pci/host/Kconfig config PCI_VERSATILE · line 110

Quoted 8 lines · Ray Jui
drivers/pci/host/Kconfig +2 -0
@@ -106,4 +106,21 @@ config PCI_VERSATILE
     bool "ARM Versatile PB PCI controller"
     depends on ARCH_VERSATILE
 
+config PCIE_IPROC
+    bool "Broadcom iProc PCIe controller"

bool symbol.

drivers/pci/host/Kconfig config PCI_VERSATILE · line 117

Quoted 7 lines
drivers/pci/host/Kconfig +7 -0
+    help
+      This enables the iProc PCIe core controller support for Broadcom's
+      iProc family of SoCs. An appropriate bus interface driver also needs
+      to be enabled
+
+config PCIE_IPROC_PLTFM
+    bool "Broadcom iProc PCIe platform bus driver"

Another bool symbol.

Quoted 12 lines
drivers/pci/host/Kconfig +8 -0
+    depends on ARCH_BCM_IPROC || COMPILE_TEST
+    depends on OF
+    select PCIE_IPROC
+    default ARCH_BCM_IPROC
+    help
+      Say Y here if you want to use the Broadcom iProc PCIe controller
+      through the generic platform bus interface
+
 endmenu

drivers/pci/host/Makefile obj-$(CONFIG_PCIE_XILINX) += pcie-xilinx.o · line 17

Quoted 3 lines
drivers/pci/host/Makefile +2 -0
 
+obj-$(CONFIG_PCIE_IPROC) += pcie-iproc.o
+obj-$(CONFIG_PCIE_IPROC_PLTFM) += pcie-iproc-pltfm.o

Both objectfiles will never be part of a module.

drivers/pci/host/pcie-iproc-pltfm.c

Quoted 4 lines
drivers/pci/host/pcie-iproc-pltfm.c new file +1 -0
 
+#include <linux/module.h>

Is this needed?

Quoted 1 line

+MODULE_DEVICE_TABLE(of, iproc_pcie_of_match_table);

This macro will be preprocessed away, won't it?

drivers/pci/host/pcie-iproc-pltfm.c line 97

Quoted 9 lines
drivers/pci/host/pcie-iproc-pltfm.c new file +9 -0
+static struct platform_driver iproc_pcie_pltfm_driver = {
+    .driver = {
+            .name = "iproc-pcie",
+            .of_match_table = of_match_ptr(iproc_pcie_of_match_table),
+            .suppress_bind_attrs = true,
+    },
+    .probe = iproc_pcie_pltfm_probe,
+};
+module_platform_driver(iproc_pcie_pltfm_driver);

Perhaps it's clearer to have make this a call to platform_driver_register(), put that in a wrapper function, and invoke that wrapper function through device_initcall() or similar. I haven't actually tested that, so the details could be off.

drivers/pci/host/pcie-iproc-pltfm.c line 101

Quoted 3 lines
drivers/pci/host/pcie-iproc-pltfm.c new file +3 -0
+MODULE_AUTHOR("Ray Jui <[email protected]>");
+MODULE_DESCRIPTION("Broadcom iPROC PCIe platform driver");
+MODULE_LICENSE("GPL v2");

And these three macros will, effectively, be preprocessed away.

drivers/pci/host/pcie-iproc.c

Quoted 4 lines
drivers/pci/host/pcie-iproc.c new file +1 -0
 
+#include <linux/module.h>

See above.

Quoted 9 lines

drivers/pci/host/pcie-iproc.c line 337

Quoted 3 lines
drivers/pci/host/pcie-iproc.c new file +3 -0
+MODULE_AUTHOR("Ray Jui <[email protected]>");
+MODULE_DESCRIPTION("Broadcom iPROC PCIe common driver");
+MODULE_LICENSE("GPL v2");

Ditto.

Paul Bolle

So every single PCIe host driver under drivers/pci/host/* has their config flag of "bool" type, and all of them except pci-keystone-dw.c have these MODULE based macros in their driver. While I agree with you that these macros will preprocessed away while compiled as statically linked in, I thought it's a convention to have these macros in the driver. At least it provides information on the author, driver description, and license (although one can also argue you can find all of those info from the maintainer list, Kconfig, and license header).

Quoted 4 lines

Would you be able to sort this out with a developer or subsystem maintainer who is familiar with this matter and let us know what is the convention for MODULE macros usage in a driver when its config flag is set to "bool" instead of "tristate"?

Is there a technical reason why the driver can't be a module? We can suppress module unloading if unloading properly is hard (i see you already suppress unbinding via sysfs), but we should be able to load it after kernel booted, no?

Thanks,
Dmitry

author maintainer
#6 lore raw

Hi Dmitry,

Quoted 107 lines · Dmitry Torokhov
Quoted 101 lines · Ray Jui

Hi Paul,

Quoted 79 lines · Paul Bolle

drivers/pci/host/Kconfig config PCI_VERSATILE · line 110

Quoted 8 lines · Ray Jui
drivers/pci/host/Kconfig +2 -0
@@ -106,4 +106,21 @@ config PCI_VERSATILE
     bool "ARM Versatile PB PCI controller"
     depends on ARCH_VERSATILE
 
+config PCIE_IPROC
+    bool "Broadcom iProc PCIe controller"

bool symbol.

drivers/pci/host/Kconfig config PCI_VERSATILE · line 117

Quoted 7 lines
drivers/pci/host/Kconfig +7 -0
+    help
+      This enables the iProc PCIe core controller support for Broadcom's
+      iProc family of SoCs. An appropriate bus interface driver also needs
+      to be enabled
+
+config PCIE_IPROC_PLTFM
+    bool "Broadcom iProc PCIe platform bus driver"

Another bool symbol.

Quoted 12 lines
drivers/pci/host/Kconfig +8 -0
+    depends on ARCH_BCM_IPROC || COMPILE_TEST
+    depends on OF
+    select PCIE_IPROC
+    default ARCH_BCM_IPROC
+    help
+      Say Y here if you want to use the Broadcom iProc PCIe controller
+      through the generic platform bus interface
+
 endmenu

drivers/pci/host/Makefile obj-$(CONFIG_PCIE_XILINX) += pcie-xilinx.o · line 17

Quoted 3 lines
drivers/pci/host/Makefile +2 -0
 
+obj-$(CONFIG_PCIE_IPROC) += pcie-iproc.o
+obj-$(CONFIG_PCIE_IPROC_PLTFM) += pcie-iproc-pltfm.o

Both objectfiles will never be part of a module.

drivers/pci/host/pcie-iproc-pltfm.c

Quoted 4 lines
drivers/pci/host/pcie-iproc-pltfm.c new file +1 -0
 
+#include <linux/module.h>

Is this needed?

Quoted 1 line

+MODULE_DEVICE_TABLE(of, iproc_pcie_of_match_table);

This macro will be preprocessed away, won't it?

drivers/pci/host/pcie-iproc-pltfm.c line 97

Quoted 9 lines
drivers/pci/host/pcie-iproc-pltfm.c new file +9 -0
+static struct platform_driver iproc_pcie_pltfm_driver = {
+    .driver = {
+            .name = "iproc-pcie",
+            .of_match_table = of_match_ptr(iproc_pcie_of_match_table),
+            .suppress_bind_attrs = true,
+    },
+    .probe = iproc_pcie_pltfm_probe,
+};
+module_platform_driver(iproc_pcie_pltfm_driver);

Perhaps it's clearer to have make this a call to platform_driver_register(), put that in a wrapper function, and invoke that wrapper function through device_initcall() or similar. I haven't actually tested that, so the details could be off.

drivers/pci/host/pcie-iproc-pltfm.c line 101

Quoted 3 lines
drivers/pci/host/pcie-iproc-pltfm.c new file +3 -0
+MODULE_AUTHOR("Ray Jui <[email protected]>");
+MODULE_DESCRIPTION("Broadcom iPROC PCIe platform driver");
+MODULE_LICENSE("GPL v2");

And these three macros will, effectively, be preprocessed away.

drivers/pci/host/pcie-iproc.c

Quoted 4 lines
drivers/pci/host/pcie-iproc.c new file +1 -0
 
+#include <linux/module.h>

See above.

Quoted 9 lines

drivers/pci/host/pcie-iproc.c line 337

Quoted 3 lines
drivers/pci/host/pcie-iproc.c new file +3 -0
+MODULE_AUTHOR("Ray Jui <[email protected]>");
+MODULE_DESCRIPTION("Broadcom iPROC PCIe common driver");
+MODULE_LICENSE("GPL v2");

Ditto.

Paul Bolle

So every single PCIe host driver under drivers/pci/host/* has their config flag of "bool" type, and all of them except pci-keystone-dw.c have these MODULE based macros in their driver. While I agree with you that these macros will preprocessed away while compiled as statically linked in, I thought it's a convention to have these macros in the driver. At least it provides information on the author, driver description, and license (although one can also argue you can find all of those info from the maintainer list, Kconfig, and license header).

Quoted 4 lines

Would you be able to sort this out with a developer or subsystem maintainer who is familiar with this matter and let us know what is the convention for MODULE macros usage in a driver when its config flag is set to "bool" instead of "tristate"?

Quoted 8 lines

Is there a technical reason why the driver can't be a module? We can suppress module unloading if unloading properly is hard (i see you already suppress unbinding via sysfs), but we should be able to load it after kernel booted, no?

Thanks,
Dmitry

Although I have not tested it, but to my best knowledge there shouldn't be any technical issue by making the PCIe iProc driver a loadable module and installing the module later after the kernel finishes booting.

But I wonder why I haven't seen any PCIe host driver being allowed to be compiled as module? Maybe there's no obvious benefit of doing that. People typically opt to load slave devices as module but tend to keep the bus or host devices compiled in.

And to allow a PCI host driver to be compiled as module, some PCI functions need to have their symbols exported:

ERROR: "pci_common_swizzle" [drivers/pci/host/pcie-iproc.ko] undefined!
ERROR: "pci_fixup_irqs" [drivers/pci/host/pcie-iproc.ko] undefined!
ERROR: "pci_assign_unassigned_bus_resources" [drivers/pci/host/pcie-iproc.ko] undefined!
ERROR: "pci_remove_root_bus" [drivers/pci/host/pcie-iproc.ko] undefined!
ERROR: "pci_stop_root_bus" [drivers/pci/host/pcie-iproc.ko] undefined!
ERROR: "pci_create_root_bus" [drivers/pci/host/pcie-iproc.ko] undefined!

Maybe Bjorn can help to shed some light here? Should I go ahead and export_symbol these PCI functions and make the iProc PCI driver "tristate"?

Thanks,

Ray

#7 lore raw
Quoted 22 lines · On Friday 06 March 2015 10:00:34 Ray Jui wrote:
Quoted 1 line

Although I have not tested it, but to my best knowledge there shouldn't be any technical issue by making the PCIe iProc driver a loadable module and installing the module later after the kernel finishes booting.

But I wonder why I haven't seen any PCIe host driver being allowed to be compiled as module? Maybe there's no obvious benefit of doing that. People typically opt to load slave devices as module but tend to keep the bus or host devices compiled in.

And to allow a PCI host driver to be compiled as module, some PCI functions need to have their symbols exported:

ERROR: "pci_common_swizzle" [drivers/pci/host/pcie-iproc.ko] undefined!
ERROR: "pci_fixup_irqs" [drivers/pci/host/pcie-iproc.ko] undefined!
ERROR: "pci_assign_unassigned_bus_resources" [drivers/pci/host/pcie-iproc.ko] undefined!
ERROR: "pci_remove_root_bus" [drivers/pci/host/pcie-iproc.ko] undefined!
ERROR: "pci_stop_root_bus" [drivers/pci/host/pcie-iproc.ko] undefined!
ERROR: "pci_create_root_bus" [drivers/pci/host/pcie-iproc.ko] undefined!

Quoted 2 lines

Maybe Bjorn can help to shed some light here? Should I go ahead and export_symbol these PCI functions and make the iProc PCI driver "tristate"?

My best guess is that no loadable driver ever tried to use these and we should indeed just export them.

The call to pci_assign_unassigned_bus_resources could be avoided by using pci_rescan_bus(), which would simplify the driver a little, but for some reason, nothing else uses that, so I'm not sure about it.

The pci_remove_root_bus/pci_stop_root_bus calls are rarely used anywhere else. Are they functional to the point where you could unload a pci host driver that is a loadable module? If so, that would be wonderful.

Arnd

author maintainer
#8 lore raw

Hi Arnd,

Quoted 23 lines · Arnd Bergmann
Quoted 22 lines · On Friday 06 March 2015 10:00:34 Ray Jui wrote:
Quoted 1 line

Although I have not tested it, but to my best knowledge there shouldn't be any technical issue by making the PCIe iProc driver a loadable module and installing the module later after the kernel finishes booting.

But I wonder why I haven't seen any PCIe host driver being allowed to be compiled as module? Maybe there's no obvious benefit of doing that. People typically opt to load slave devices as module but tend to keep the bus or host devices compiled in.

And to allow a PCI host driver to be compiled as module, some PCI functions need to have their symbols exported:

ERROR: "pci_common_swizzle" [drivers/pci/host/pcie-iproc.ko] undefined!
ERROR: "pci_fixup_irqs" [drivers/pci/host/pcie-iproc.ko] undefined!
ERROR: "pci_assign_unassigned_bus_resources" [drivers/pci/host/pcie-iproc.ko] undefined!
ERROR: "pci_remove_root_bus" [drivers/pci/host/pcie-iproc.ko] undefined!
ERROR: "pci_stop_root_bus" [drivers/pci/host/pcie-iproc.ko] undefined!
ERROR: "pci_create_root_bus" [drivers/pci/host/pcie-iproc.ko] undefined!

Quoted 5 lines
Quoted 2 lines

Maybe Bjorn can help to shed some light here? Should I go ahead and export_symbol these PCI functions and make the iProc PCI driver "tristate"?

My best guess is that no loadable driver ever tried to use these and we should indeed just export them.

True. I can export those symbols.

Quoted 9 lines

The call to pci_assign_unassigned_bus_resources could be avoided by using pci_rescan_bus(), which would simplify the driver a little, but for some reason, nothing else uses that, so I'm not sure about it.

The pci_remove_root_bus/pci_stop_root_bus calls are rarely used anywhere else. Are they functional to the point where you could unload a pci host driver that is a loadable module? If so, that would be wonderful.

It is quite wonderful, :)

I added driver remove function support and tested it out. I'm able to install/remove/install the iProc PCIe platform driver as a kernel loadable module. pci_remove_root_bus/pci_stop_root_bus works fine. See logs below.

-bash-3.2# insmod pcie-iproc-pltfm.ko

[   54.058546] PCI host bridge /pcie at 18012000 ranges:
[   54.064584]    IO 0x28000000..0x2800ffff -> 0x00000000
[   54.071003]   MEM 0x20000000..0x23ffffff -> 0x20000000
[   54.330194] iproc-pcie 18012000.pcie: PCI host bridge to bus 0000:00
[   54.338138] pci_bus 0000:00: root bus resource [bus 00-ff]
[   54.344983] pci_bus 0000:00: root bus resource [io  0x0000-0xffff]
[   54.352683] pci_bus 0000:00: root bus resource [mem
0x20000000-0x23ffffff]
[   54.361254] iproc-pcie 18012000.pcie: link: UP
[   54.367086] PCI: bus0: Fast back to back transfers disabled
[   54.374046] pci 0000:00:00.0: bridge configuration invalid ([bus
00-00]), reconfiguring
[   54.400237] PCI: bus1: Fast back to back transfers disabled
[   54.407274] pci 0000:00:00.0: BAR 8: assigned [mem 0x20000000-0x200fffff]
[   54.415766] pci 0000:01:00.0: BAR 1: assigned [mem 0x20000000-0x2007ffff]
[   54.424241] pci 0000:01:00.0: BAR 6: assigned [mem
0x20080000-0x200bffff pref]
[   54.433245] pci 0000:01:00.0: BAR 0: assigned [mem 0x200c0000-0x200dffff]
[   54.441710] pci 0000:01:00.0: BAR 3: assigned [mem 0x200e0000-0x200e3fff]
[   54.450173] pci 0000:01:00.0: BAR 2: no space for [io  size 0x0020]
[   54.457979] pci 0000:01:00.0: BAR 2: failed to assign [io  size 0x0020]
[   54.466217] pci 0000:00:00.0: PCI bridge to [bus 01]
[   54.472404] pci 0000:00:00.0:   bridge window [mem 0x20000000-0x200fffff]
[   54.480945] pcieport 0000:00:00.0: enabling device (0140 -> 0142)
[   54.488767] e1000e 0000:01:00.0: enabling device (0140 -> 0142)
[   54.496315] e1000e 0000:01:00.0: Interrupt Throttling Rate (ints/sec)
set to dynamic conservative mode
[   54.507958] e1000e 0000:01:00.0 0000:01:00.0 (uninitialized): Failed
to initialize MSI-X interrupts.  Falling back to MSI interru.
[   54.522913] e1000e 0000:01:00.0 0000:01:00.0 (uninitialized): Failed
to initialize MSI interrupts.  Falling back to legacy interr.
[   54.643486] e1000e 0000:01:00.0 eth0: registered PHC clock
[   54.650379] e1000e 0000:01:00.0 eth0: (PCI Express:2.5GT/s:Width x1)
68:05:ca:28:19:e8
[   54.660254] e1000e 0000:01:00.0 eth0: Intel(R) PRO/1000 Network
Connection
[   54.668834] e1000e 0000:01:00.0 eth0: MAC: 3, PHY: 8, PBA No: E46981-008

-bash-3.2# rmmod pcie-iproc-pltfm

[   66.465834] e1000e 0000:01:00.0 eth0: removed PHC

-bash-3.2# insmod pcie-iproc-pltfm.ko

[   71.043195] PCI host bridge /pcie at 18012000 ranges:
[   71.049235]    IO 0x28000000..0x2800ffff -> 0x00000000
[   71.055652]   MEM 0x20000000..0x23ffffff -> 0x20000000
[   71.315192] iproc-pcie 18012000.pcie: PCI host bridge to bus 0000:00
[   71.323135] pci_bus 0000:00: root bus resource [bus 00-ff]
[   71.329979] pci_bus 0000:00: root bus resource [io  0x0000-0xffff]
[   71.337679] pci_bus 0000:00: root bus resource [mem
0x20000000-0x23ffffff]
[   71.346249] iproc-pcie 18012000.pcie: link: UP
[   71.352072] PCI: bus0: Fast back to back transfers disabled
[   71.375261] PCI: bus1: Fast back to back transfers disabled
[   71.382291] pci 0000:00:00.0: BAR 8: assigned [mem 0x20000000-0x200fffff]
[   71.390782] pci 0000:01:00.0: BAR 1: assigned [mem 0x20000000-0x2007ffff]
[   71.399258] pci 0000:01:00.0: BAR 6: assigned [mem
0x20080000-0x200bffff pref]
[   71.408263] pci 0000:01:00.0: BAR 0: assigned [mem 0x200c0000-0x200dffff]
[   71.416728] pci 0000:01:00.0: BAR 3: assigned [mem 0x200e0000-0x200e3fff]
[   71.425190] pci 0000:01:00.0: BAR 2: no space for [io  size 0x0020]
[   71.432996] pci 0000:01:00.0: BAR 2: failed to assign [io  size 0x0020]
[   71.441235] pci 0000:00:00.0: PCI bridge to [bus 01]
[   71.447422] pci 0000:00:00.0:   bridge window [mem 0x20000000-0x200fffff]
[   71.456125] pcieport 0000:00:00.0: Signaling PME through PCIe PME
interrupt
[   71.464812] pci 0000:01:00.0: Signaling PME through PCIe PME interrupt
[   71.473411] e1000e 0000:01:00.0: Interrupt Throttling Rate (ints/sec)
set to dynamic conservative mode
[   71.485069] e1000e 0000:01:00.0 0000:01:00.0 (uninitialized): Failed
to initialize MSI-X interrupts.  Falling back to MSI interru.
[   71.500025] e1000e 0000:01:00.0 0000:01:00.0 (uninitialized): Failed
to initialize MSI interrupts.  Falling back to legacy interr.
[   71.624549] e1000e 0000:01:00.0 eth0: registered PHC clock
[   71.631444] e1000e 0000:01:00.0 eth0: (PCI Express:2.5GT/s:Width x1)
68:05:ca:28:19:e8
[   71.641314] e1000e 0000:01:00.0 eth0: Intel(R) PRO/1000 Network
Connection
[   71.649894] e1000e 0000:01:00.0 eth0: MAC: 3, PHY: 8, PBA No: E46981-008
Quoted 3 lines

Arnd

I'll submit patch series v4 with loadable module support.

Thanks,

Ray