812-pcie-0004-pci-add-support-aer-pme-interrupts-with-none-MSI-MSI.patch 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. From dc17fd4b8c27ca47fb5d9113df715579bc4a04a3 Mon Sep 17 00:00:00 2001
  2. From: Po Liu <[email protected]>
  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
  5. mode
  6. On some platforms, root port doesn't support MSI/MSI-X/INTx in RC mode.
  7. When chip support the aer/pme interrupts with none MSI/MSI-X/INTx mode,
  8. maybe there is interrupt line for aer pme etc. Search the interrupt
  9. number in the fdt file. Then fixup the dev->irq with it.
  10. Signed-off-by: Po Liu <[email protected]>
  11. Signed-off-by: Hou Zhiqiang <[email protected]>
  12. ---
  13. .../devicetree/bindings/pci/layerscape-pci.txt | 13 +++++--
  14. arch/arm/kernel/bios32.c | 44 ++++++++++++++++++++++
  15. arch/arm64/kernel/pci.c | 44 ++++++++++++++++++++++
  16. drivers/pci/pcie/portdrv_core.c | 29 ++++++++++++++
  17. include/linux/pci.h | 1 +
  18. 5 files changed, 127 insertions(+), 4 deletions(-)
  19. --- a/Documentation/devicetree/bindings/pci/layerscape-pci.txt
  20. +++ b/Documentation/devicetree/bindings/pci/layerscape-pci.txt
  21. @@ -26,8 +26,12 @@ Required properties:
  22. - reg: base addresses and lengths of the PCIe controller register blocks.
  23. - interrupts: A list of interrupt outputs of the controller. Must contain an
  24. entry for each entry in the interrupt-names property.
  25. -- interrupt-names: Must include the following entries:
  26. - "intr": The interrupt that is asserted for controller interrupts
  27. +- interrupt-names: It could include the following entries:
  28. + "aer": Asserted for aer interrupt when chip support the aer interrupt with
  29. + none MSI/MSI-X/INTx mode,but there is interrupt line for aer.
  30. + "pme": Asserted for pme interrupt when chip support the pme interrupt with
  31. + none MSI/MSI-X/INTx mode,but there is interrupt line for pme.
  32. + ......
  33. - fsl,pcie-scfg: Must include two entries.
  34. The first entry must be a link to the SCFG device node
  35. The second entry must be '0' or '1' based on physical PCIe controller index.
  36. @@ -43,8 +47,9 @@ Example:
  37. reg = <0x00 0x03400000 0x0 0x00010000 /* controller registers */
  38. 0x40 0x00000000 0x0 0x00002000>; /* configuration space */
  39. reg-names = "regs", "config";
  40. - interrupts = <GIC_SPI 177 IRQ_TYPE_LEVEL_HIGH>; /* controller interrupt */
  41. - interrupt-names = "intr";
  42. + interrupts = <GIC_SPI 176 IRQ_TYPE_LEVEL_HIGH>, /* aer interrupt */
  43. + <GIC_SPI 177 IRQ_TYPE_LEVEL_HIGH>; /* pme interrupt */
  44. + interrupt-names = "aer", "pme";
  45. fsl,pcie-scfg = <&scfg 0>;
  46. #address-cells = <3>;
  47. #size-cells = <2>;
  48. --- a/arch/arm/kernel/bios32.c
  49. +++ b/arch/arm/kernel/bios32.c
  50. @@ -12,11 +12,14 @@
  51. #include <linux/slab.h>
  52. #include <linux/init.h>
  53. #include <linux/io.h>
  54. +#include <linux/of_irq.h>
  55. #include <asm/mach-types.h>
  56. #include <asm/mach/map.h>
  57. #include <asm/mach/pci.h>
  58. +#include "../../../drivers/pci/pcie/portdrv.h"
  59. +
  60. static int debug_pci;
  61. /*
  62. @@ -65,6 +68,47 @@ void pcibios_report_status(u_int status_
  63. }
  64. /*
  65. + * Check device tree if the service interrupts are there
  66. + */
  67. +int pcibios_check_service_irqs(struct pci_dev *dev, int *irqs, int mask)
  68. +{
  69. + int ret, count = 0;
  70. + struct device_node *np = NULL;
  71. +
  72. + if (dev->bus->dev.of_node)
  73. + np = dev->bus->dev.of_node;
  74. +
  75. + if (np == NULL)
  76. + return 0;
  77. +
  78. + if (!IS_ENABLED(CONFIG_OF_IRQ))
  79. + return 0;
  80. +
  81. + /* If root port doesn't support MSI/MSI-X/INTx in RC mode,
  82. + * request irq for aer
  83. + */
  84. + if (mask & PCIE_PORT_SERVICE_AER) {
  85. + ret = of_irq_get_byname(np, "aer");
  86. + if (ret > 0) {
  87. + irqs[PCIE_PORT_SERVICE_AER_SHIFT] = ret;
  88. + count++;
  89. + }
  90. + }
  91. +
  92. + if (mask & PCIE_PORT_SERVICE_PME) {
  93. + ret = of_irq_get_byname(np, "pme");
  94. + if (ret > 0) {
  95. + irqs[PCIE_PORT_SERVICE_PME_SHIFT] = ret;
  96. + count++;
  97. + }
  98. + }
  99. +
  100. + /* TODO: add more service interrupts if there it is in the device tree*/
  101. +
  102. + return count;
  103. +}
  104. +
  105. +/*
  106. * We don't use this to fix the device, but initialisation of it.
  107. * It's not the correct use for this, but it works.
  108. * Note that the arbiter/ISA bridge appears to be buggy, specifically in
  109. --- a/arch/arm64/kernel/pci.c
  110. +++ b/arch/arm64/kernel/pci.c
  111. @@ -13,11 +13,14 @@
  112. #include <linux/mm.h>
  113. #include <linux/of_pci.h>
  114. #include <linux/of_platform.h>
  115. +#include <linux/of_irq.h>
  116. #include <linux/pci.h>
  117. #include <linux/pci-acpi.h>
  118. #include <linux/pci-ecam.h>
  119. #include <linux/slab.h>
  120. +#include "../../../drivers/pci/pcie/portdrv.h"
  121. +
  122. #ifdef CONFIG_ACPI
  123. /*
  124. * Try to assign the IRQ number when probing a new device
  125. @@ -32,6 +35,47 @@ int pcibios_alloc_irq(struct pci_dev *de
  126. #endif
  127. /*
  128. + * Check device tree if the service interrupts are there
  129. + */
  130. +int pcibios_check_service_irqs(struct pci_dev *dev, int *irqs, int mask)
  131. +{
  132. + int ret, count = 0;
  133. + struct device_node *np = NULL;
  134. +
  135. + if (dev->bus->dev.of_node)
  136. + np = dev->bus->dev.of_node;
  137. +
  138. + if (np == NULL)
  139. + return 0;
  140. +
  141. + if (!IS_ENABLED(CONFIG_OF_IRQ))
  142. + return 0;
  143. +
  144. + /* If root port doesn't support MSI/MSI-X/INTx in RC mode,
  145. + * request irq for aer
  146. + */
  147. + if (mask & PCIE_PORT_SERVICE_AER) {
  148. + ret = of_irq_get_byname(np, "aer");
  149. + if (ret > 0) {
  150. + irqs[PCIE_PORT_SERVICE_AER_SHIFT] = ret;
  151. + count++;
  152. + }
  153. + }
  154. +
  155. + if (mask & PCIE_PORT_SERVICE_PME) {
  156. + ret = of_irq_get_byname(np, "pme");
  157. + if (ret > 0) {
  158. + irqs[PCIE_PORT_SERVICE_PME_SHIFT] = ret;
  159. + count++;
  160. + }
  161. + }
  162. +
  163. + /* TODO: add more service interrupts if there it is in the device tree*/
  164. +
  165. + return count;
  166. +}
  167. +
  168. +/*
  169. * raw_pci_read/write - Platform-specific PCI config space access.
  170. */
  171. int raw_pci_read(unsigned int domain, unsigned int bus,
  172. --- a/drivers/pci/pcie/portdrv_core.c
  173. +++ b/drivers/pci/pcie/portdrv_core.c
  174. @@ -37,6 +37,20 @@ static void release_pcie_device(struct d
  175. kfree(to_pcie_device(dev));
  176. }
  177. +/**
  178. + * pcibios_check_service_irqs - check irqs in the device tree
  179. + * @dev: PCI Express port to handle
  180. + * @irqs: Array of irqs to populate
  181. + * @mask: Bitmask of port capabilities returned by get_port_device_capability()
  182. + *
  183. + * Return value: 0 means no service irqs in the device tree
  184. + *
  185. + */
  186. +int __weak pcibios_check_service_irqs(struct pci_dev *dev, int *irqs, int mask)
  187. +{
  188. + return 0;
  189. +}
  190. +
  191. /*
  192. * Fill in *pme, *aer, *dpc with the relevant Interrupt Message Numbers if
  193. * services are enabled in "mask". Return the number of MSI/MSI-X vectors
  194. @@ -165,10 +179,25 @@ static int pcie_port_enable_irq_vec(stru
  195. static int pcie_init_service_irqs(struct pci_dev *dev, int *irqs, int mask)
  196. {
  197. int ret, i;
  198. + int irq = -1;
  199. for (i = 0; i < PCIE_PORT_DEVICE_MAXSERVICES; i++)
  200. irqs[i] = -1;
  201. + /* Check if some platforms owns independent irq pins for AER/PME etc.
  202. + * Some platforms may own independent AER/PME interrupts and set
  203. + * them in the device tree file.
  204. + */
  205. + ret = pcibios_check_service_irqs(dev, irqs, mask);
  206. + if (ret) {
  207. + if (dev->irq)
  208. + irq = dev->irq;
  209. + for (i = 0; i < PCIE_PORT_DEVICE_MAXSERVICES; i++)
  210. + if (irqs[i] == -1)
  211. + irqs[i] = irq;
  212. + return 0;
  213. + }
  214. +
  215. /*
  216. * If we support PME but can't use MSI/MSI-X for it, we have to
  217. * fall back to INTx or other interrupts, e.g., a system shared
  218. --- a/include/linux/pci.h
  219. +++ b/include/linux/pci.h
  220. @@ -2021,6 +2021,7 @@ static inline void pcibios_penalize_isa_
  221. int pcibios_alloc_irq(struct pci_dev *dev);
  222. void pcibios_free_irq(struct pci_dev *dev);
  223. resource_size_t pcibios_default_alignment(void);
  224. +int pcibios_check_service_irqs(struct pci_dev *dev, int *irqs, int mask);
  225. #ifdef CONFIG_HIBERNATE_CALLBACKS
  226. extern struct dev_pm_ops pcibios_pm_ops;