1 From dc17fd4b8c27ca47fb5d9113df715579bc4a04a3 Mon Sep 17 00:00:00 2001
2 From: Po Liu <po.liu@nxp.com>
3 Date: Fri, 30 Sep 2016 17:11:37 +0800
4 Subject: [PATCH] pci:add support aer/pme interrupts with none MSI/MSI-X/INTx
7 On some platforms, root port doesn't support MSI/MSI-X/INTx in RC mode.
8 When chip support the aer/pme interrupts with none MSI/MSI-X/INTx mode,
9 maybe there is interrupt line for aer pme etc. Search the interrupt
10 number in the fdt file. Then fixup the dev->irq with it.
12 Signed-off-by: Po Liu <po.liu@nxp.com>
13 Signed-off-by: Hou Zhiqiang <Zhiqiang.Hou@nxp.com>
15 .../devicetree/bindings/pci/layerscape-pci.txt | 13 +++++--
16 arch/arm/kernel/bios32.c | 44 ++++++++++++++++++++++
17 arch/arm64/kernel/pci.c | 44 ++++++++++++++++++++++
18 drivers/pci/pcie/portdrv_core.c | 29 ++++++++++++++
19 include/linux/pci.h | 1 +
20 5 files changed, 127 insertions(+), 4 deletions(-)
22 --- a/Documentation/devicetree/bindings/pci/layerscape-pci.txt
23 +++ b/Documentation/devicetree/bindings/pci/layerscape-pci.txt
24 @@ -26,8 +26,12 @@ Required properties:
25 - reg: base addresses and lengths of the PCIe controller register blocks.
26 - interrupts: A list of interrupt outputs of the controller. Must contain an
27 entry for each entry in the interrupt-names property.
28 -- interrupt-names: Must include the following entries:
29 - "intr": The interrupt that is asserted for controller interrupts
30 +- interrupt-names: It could include the following entries:
31 + "aer": Asserted for aer interrupt when chip support the aer interrupt with
32 + none MSI/MSI-X/INTx mode,but there is interrupt line for aer.
33 + "pme": Asserted for pme interrupt when chip support the pme interrupt with
34 + none MSI/MSI-X/INTx mode,but there is interrupt line for pme.
36 - fsl,pcie-scfg: Must include two entries.
37 The first entry must be a link to the SCFG device node
38 The second entry must be '0' or '1' based on physical PCIe controller index.
39 @@ -43,8 +47,9 @@ Example:
40 reg = <0x00 0x03400000 0x0 0x00010000 /* controller registers */
41 0x40 0x00000000 0x0 0x00002000>; /* configuration space */
42 reg-names = "regs", "config";
43 - interrupts = <GIC_SPI 177 IRQ_TYPE_LEVEL_HIGH>; /* controller interrupt */
44 - interrupt-names = "intr";
45 + interrupts = <GIC_SPI 176 IRQ_TYPE_LEVEL_HIGH>, /* aer interrupt */
46 + <GIC_SPI 177 IRQ_TYPE_LEVEL_HIGH>; /* pme interrupt */
47 + interrupt-names = "aer", "pme";
48 fsl,pcie-scfg = <&scfg 0>;
51 --- a/arch/arm/kernel/bios32.c
52 +++ b/arch/arm/kernel/bios32.c
54 #include <linux/slab.h>
55 #include <linux/init.h>
57 +#include <linux/of_irq.h>
59 #include <asm/mach-types.h>
60 #include <asm/mach/map.h>
61 #include <asm/mach/pci.h>
63 +#include "../../../drivers/pci/pcie/portdrv.h"
68 @@ -65,6 +68,47 @@ void pcibios_report_status(u_int status_
72 + * Check device tree if the service interrupts are there
74 +int pcibios_check_service_irqs(struct pci_dev *dev, int *irqs, int mask)
77 + struct device_node *np = NULL;
79 + if (dev->bus->dev.of_node)
80 + np = dev->bus->dev.of_node;
85 + if (!IS_ENABLED(CONFIG_OF_IRQ))
88 + /* If root port doesn't support MSI/MSI-X/INTx in RC mode,
89 + * request irq for aer
91 + if (mask & PCIE_PORT_SERVICE_AER) {
92 + ret = of_irq_get_byname(np, "aer");
94 + irqs[PCIE_PORT_SERVICE_AER_SHIFT] = ret;
99 + if (mask & PCIE_PORT_SERVICE_PME) {
100 + ret = of_irq_get_byname(np, "pme");
102 + irqs[PCIE_PORT_SERVICE_PME_SHIFT] = ret;
107 + /* TODO: add more service interrupts if there it is in the device tree*/
113 * We don't use this to fix the device, but initialisation of it.
114 * It's not the correct use for this, but it works.
115 * Note that the arbiter/ISA bridge appears to be buggy, specifically in
116 --- a/arch/arm64/kernel/pci.c
117 +++ b/arch/arm64/kernel/pci.c
119 #include <linux/mm.h>
120 #include <linux/of_pci.h>
121 #include <linux/of_platform.h>
122 +#include <linux/of_irq.h>
123 #include <linux/pci.h>
124 #include <linux/pci-acpi.h>
125 #include <linux/pci-ecam.h>
126 #include <linux/slab.h>
128 +#include "../../../drivers/pci/pcie/portdrv.h"
132 * Try to assign the IRQ number when probing a new device
133 @@ -32,6 +35,47 @@ int pcibios_alloc_irq(struct pci_dev *de
137 + * Check device tree if the service interrupts are there
139 +int pcibios_check_service_irqs(struct pci_dev *dev, int *irqs, int mask)
141 + int ret, count = 0;
142 + struct device_node *np = NULL;
144 + if (dev->bus->dev.of_node)
145 + np = dev->bus->dev.of_node;
150 + if (!IS_ENABLED(CONFIG_OF_IRQ))
153 + /* If root port doesn't support MSI/MSI-X/INTx in RC mode,
154 + * request irq for aer
156 + if (mask & PCIE_PORT_SERVICE_AER) {
157 + ret = of_irq_get_byname(np, "aer");
159 + irqs[PCIE_PORT_SERVICE_AER_SHIFT] = ret;
164 + if (mask & PCIE_PORT_SERVICE_PME) {
165 + ret = of_irq_get_byname(np, "pme");
167 + irqs[PCIE_PORT_SERVICE_PME_SHIFT] = ret;
172 + /* TODO: add more service interrupts if there it is in the device tree*/
178 * raw_pci_read/write - Platform-specific PCI config space access.
180 int raw_pci_read(unsigned int domain, unsigned int bus,
181 --- a/drivers/pci/pcie/portdrv_core.c
182 +++ b/drivers/pci/pcie/portdrv_core.c
183 @@ -37,6 +37,20 @@ static void release_pcie_device(struct d
184 kfree(to_pcie_device(dev));
188 + * pcibios_check_service_irqs - check irqs in the device tree
189 + * @dev: PCI Express port to handle
190 + * @irqs: Array of irqs to populate
191 + * @mask: Bitmask of port capabilities returned by get_port_device_capability()
193 + * Return value: 0 means no service irqs in the device tree
196 +int __weak pcibios_check_service_irqs(struct pci_dev *dev, int *irqs, int mask)
202 * Fill in *pme, *aer, *dpc with the relevant Interrupt Message Numbers if
203 * services are enabled in "mask". Return the number of MSI/MSI-X vectors
204 @@ -165,10 +179,25 @@ static int pcie_port_enable_irq_vec(stru
205 static int pcie_init_service_irqs(struct pci_dev *dev, int *irqs, int mask)
210 for (i = 0; i < PCIE_PORT_DEVICE_MAXSERVICES; i++)
213 + /* Check if some platforms owns independent irq pins for AER/PME etc.
214 + * Some platforms may own independent AER/PME interrupts and set
215 + * them in the device tree file.
217 + ret = pcibios_check_service_irqs(dev, irqs, mask);
221 + for (i = 0; i < PCIE_PORT_DEVICE_MAXSERVICES; i++)
228 * If we support PME but can't use MSI/MSI-X for it, we have to
229 * fall back to INTx or other interrupts, e.g., a system shared
230 --- a/include/linux/pci.h
231 +++ b/include/linux/pci.h
232 @@ -2020,6 +2020,7 @@ static inline void pcibios_penalize_isa_
233 int pcibios_alloc_irq(struct pci_dev *dev);
234 void pcibios_free_irq(struct pci_dev *dev);
235 resource_size_t pcibios_default_alignment(void);
236 +int pcibios_check_service_irqs(struct pci_dev *dev, int *irqs, int mask);
238 #ifdef CONFIG_HIBERNATE_CALLBACKS
239 extern struct dev_pm_ops pcibios_pm_ops;