pcie-plda.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * PLDA PCIe host controller driver
  4. */
  5. #ifndef _PCIE_PLDA_H
  6. #define _PCIE_PLDA_H
  7. /* Number of MSI IRQs */
  8. #define PLDA_MAX_NUM_MSI_IRQS 32
  9. /* PCIe Bridge Phy Regs */
  10. #define GEN_SETTINGS 0x80
  11. #define RP_ENABLE 1
  12. #define PCIE_PCI_IDS_DW1 0x9c
  13. #define IDS_CLASS_CODE_SHIFT 16
  14. #define REVISION_ID_MASK GENMASK(7, 0)
  15. #define CLASS_CODE_ID_MASK GENMASK(31, 8)
  16. #define PCIE_PCI_IRQ_DW0 0xa8
  17. #define MSIX_CAP_MASK BIT(31)
  18. #define NUM_MSI_MSGS_MASK GENMASK(6, 4)
  19. #define NUM_MSI_MSGS_SHIFT 4
  20. #define PCI_MISC 0xb4
  21. #define PHY_FUNCTION_DIS BIT(15)
  22. #define PCIE_WINROM 0xfc
  23. #define PREF_MEM_WIN_64_SUPPORT BIT(3)
  24. #define IMASK_LOCAL 0x180
  25. #define DMA_END_ENGINE_0_MASK 0x00000000u
  26. #define DMA_END_ENGINE_0_SHIFT 0
  27. #define DMA_END_ENGINE_1_MASK 0x00000000u
  28. #define DMA_END_ENGINE_1_SHIFT 1
  29. #define DMA_ERROR_ENGINE_0_MASK 0x00000100u
  30. #define DMA_ERROR_ENGINE_0_SHIFT 8
  31. #define DMA_ERROR_ENGINE_1_MASK 0x00000200u
  32. #define DMA_ERROR_ENGINE_1_SHIFT 9
  33. #define A_ATR_EVT_POST_ERR_MASK 0x00010000u
  34. #define A_ATR_EVT_POST_ERR_SHIFT 16
  35. #define A_ATR_EVT_FETCH_ERR_MASK 0x00020000u
  36. #define A_ATR_EVT_FETCH_ERR_SHIFT 17
  37. #define A_ATR_EVT_DISCARD_ERR_MASK 0x00040000u
  38. #define A_ATR_EVT_DISCARD_ERR_SHIFT 18
  39. #define A_ATR_EVT_DOORBELL_MASK 0x00000000u
  40. #define A_ATR_EVT_DOORBELL_SHIFT 19
  41. #define P_ATR_EVT_POST_ERR_MASK 0x00100000u
  42. #define P_ATR_EVT_POST_ERR_SHIFT 20
  43. #define P_ATR_EVT_FETCH_ERR_MASK 0x00200000u
  44. #define P_ATR_EVT_FETCH_ERR_SHIFT 21
  45. #define P_ATR_EVT_DISCARD_ERR_MASK 0x00400000u
  46. #define P_ATR_EVT_DISCARD_ERR_SHIFT 22
  47. #define P_ATR_EVT_DOORBELL_MASK 0x00000000u
  48. #define P_ATR_EVT_DOORBELL_SHIFT 23
  49. #define PM_MSI_INT_INTA_MASK 0x01000000u
  50. #define PM_MSI_INT_INTA_SHIFT 24
  51. #define PM_MSI_INT_INTB_MASK 0x02000000u
  52. #define PM_MSI_INT_INTB_SHIFT 25
  53. #define PM_MSI_INT_INTC_MASK 0x04000000u
  54. #define PM_MSI_INT_INTC_SHIFT 26
  55. #define PM_MSI_INT_INTD_MASK 0x08000000u
  56. #define PM_MSI_INT_INTD_SHIFT 27
  57. #define PM_MSI_INT_INTX_MASK 0x0f000000u
  58. #define PM_MSI_INT_INTX_SHIFT 24
  59. #define PM_MSI_INT_MSI_MASK 0x10000000u
  60. #define PM_MSI_INT_MSI_SHIFT 28
  61. #define PM_MSI_INT_AER_EVT_MASK 0x20000000u
  62. #define PM_MSI_INT_AER_EVT_SHIFT 29
  63. #define PM_MSI_INT_EVENTS_MASK 0x40000000u
  64. #define PM_MSI_INT_EVENTS_SHIFT 30
  65. #define PM_MSI_INT_SYS_ERR_MASK 0x80000000u
  66. #define PM_MSI_INT_SYS_ERR_SHIFT 31
  67. #define SYS_AND_MSI_MASK GENMASK(31, 28)
  68. #define NUM_LOCAL_EVENTS 15
  69. #define ISTATUS_LOCAL 0x184
  70. #define IMASK_HOST 0x188
  71. #define ISTATUS_HOST 0x18c
  72. #define IMSI_ADDR 0x190
  73. #define ISTATUS_MSI 0x194
  74. #define PMSG_SUPPORT_RX 0x3f0
  75. #define PMSG_LTR_SUPPORT BIT(2)
  76. /* PCIe Master table init defines */
  77. #define ATR0_PCIE_WIN0_SRCADDR_PARAM 0x600u
  78. #define ATR0_PCIE_ATR_SIZE 0x25
  79. #define ATR0_PCIE_ATR_SIZE_SHIFT 1
  80. #define ATR0_PCIE_WIN0_SRC_ADDR 0x604u
  81. #define ATR0_PCIE_WIN0_TRSL_ADDR_LSB 0x608u
  82. #define ATR0_PCIE_WIN0_TRSL_ADDR_UDW 0x60cu
  83. #define ATR0_PCIE_WIN0_TRSL_PARAM 0x610u
  84. /* PCIe AXI slave table init defines */
  85. #define ATR0_AXI4_SLV0_SRCADDR_PARAM 0x800u
  86. #define ATR_SIZE_MASK GENMASK(6, 1)
  87. #define ATR_IMPL_ENABLE BIT(0)
  88. #define ATR0_AXI4_SLV0_SRC_ADDR 0x804u
  89. #define ATR0_AXI4_SLV0_TRSL_ADDR_LSB 0x808u
  90. #define ATR0_AXI4_SLV0_TRSL_ADDR_UDW 0x80cu
  91. #define ATR0_AXI4_SLV0_TRSL_PARAM 0x810u
  92. #define PCIE_TX_RX_INTERFACE 0x00000000u
  93. #define PCIE_CONFIG_INTERFACE 0x00000001u
  94. #define TRSL_ID_AXI4_MASTER_0 0x00000004u
  95. #define CONFIG_SPACE_ADDR_OFFSET 0x1000u
  96. #define ATR_ENTRY_SIZE 32
  97. enum plda_int_event {
  98. PLDA_AXI_POST_ERR,
  99. PLDA_AXI_FETCH_ERR,
  100. PLDA_AXI_DISCARD_ERR,
  101. PLDA_AXI_DOORBELL,
  102. PLDA_PCIE_POST_ERR,
  103. PLDA_PCIE_FETCH_ERR,
  104. PLDA_PCIE_DISCARD_ERR,
  105. PLDA_PCIE_DOORBELL,
  106. PLDA_INTX,
  107. PLDA_MSI,
  108. PLDA_AER_EVENT,
  109. PLDA_MISC_EVENTS,
  110. PLDA_SYS_ERR,
  111. PLDA_INT_EVENT_NUM
  112. };
  113. #define PLDA_NUM_DMA_EVENTS 16
  114. #define EVENT_PM_MSI_INT_INTX (PLDA_NUM_DMA_EVENTS + PLDA_INTX)
  115. #define EVENT_PM_MSI_INT_MSI (PLDA_NUM_DMA_EVENTS + PLDA_MSI)
  116. #define PLDA_MAX_EVENT_NUM (PLDA_NUM_DMA_EVENTS + PLDA_INT_EVENT_NUM)
  117. /*
  118. * PLDA interrupt register
  119. *
  120. * 31 27 23 15 7 0
  121. * +--+--+--+-+------+-+-+-+-+-+-+-+-+-----------+-----------+
  122. * |12|11|10|9| intx |7|6|5|4|3|2|1|0| DMA error | DMA end |
  123. * +--+--+--+-+------+-+-+-+-+-+-+-+-+-----------+-----------+
  124. * event bit
  125. * 0-7 (0-7) DMA interrupt end : reserved for vendor implement
  126. * 8-15 (8-15) DMA error : reserved for vendor implement
  127. * 16 (16) AXI post error (PLDA_AXI_POST_ERR)
  128. * 17 (17) AXI fetch error (PLDA_AXI_FETCH_ERR)
  129. * 18 (18) AXI discard error (PLDA_AXI_DISCARD_ERR)
  130. * 19 (19) AXI doorbell (PLDA_PCIE_DOORBELL)
  131. * 20 (20) PCIe post error (PLDA_PCIE_POST_ERR)
  132. * 21 (21) PCIe fetch error (PLDA_PCIE_FETCH_ERR)
  133. * 22 (22) PCIe discard error (PLDA_PCIE_DISCARD_ERR)
  134. * 23 (23) PCIe doorbell (PLDA_PCIE_DOORBELL)
  135. * 24 (27-24) INTx interruts (PLDA_INTX)
  136. * 25 (28): MSI interrupt (PLDA_MSI)
  137. * 26 (29): AER event (PLDA_AER_EVENT)
  138. * 27 (30): PM/LTR/Hotplug (PLDA_MISC_EVENTS)
  139. * 28 (31): System error (PLDA_SYS_ERR)
  140. */
  141. struct plda_pcie_rp;
  142. struct plda_event_ops {
  143. u32 (*get_events)(struct plda_pcie_rp *pcie);
  144. };
  145. struct plda_pcie_host_ops {
  146. int (*host_init)(struct plda_pcie_rp *pcie);
  147. void (*host_deinit)(struct plda_pcie_rp *pcie);
  148. };
  149. struct plda_msi {
  150. struct mutex lock; /* Protect used bitmap */
  151. struct irq_domain *dev_domain;
  152. u32 num_vectors;
  153. u64 vector_phy;
  154. DECLARE_BITMAP(used, PLDA_MAX_NUM_MSI_IRQS);
  155. };
  156. struct plda_pcie_rp {
  157. struct device *dev;
  158. struct pci_host_bridge *bridge;
  159. struct irq_domain *intx_domain;
  160. struct irq_domain *event_domain;
  161. raw_spinlock_t lock;
  162. struct plda_msi msi;
  163. const struct plda_event_ops *event_ops;
  164. const struct irq_chip *event_irq_chip;
  165. const struct plda_pcie_host_ops *host_ops;
  166. void __iomem *bridge_addr;
  167. void __iomem *config_base;
  168. unsigned long events_bitmap;
  169. int irq;
  170. int msi_irq;
  171. int intx_irq;
  172. int num_events;
  173. };
  174. struct plda_event {
  175. int (*request_event_irq)(struct plda_pcie_rp *pcie,
  176. int event_irq, int event);
  177. int intx_event;
  178. int msi_event;
  179. };
  180. void __iomem *plda_pcie_map_bus(struct pci_bus *bus, unsigned int devfn,
  181. int where);
  182. int plda_init_interrupts(struct platform_device *pdev,
  183. struct plda_pcie_rp *port,
  184. const struct plda_event *event);
  185. void plda_pcie_setup_window(void __iomem *bridge_base_addr, u32 index,
  186. phys_addr_t axi_addr, phys_addr_t pci_addr,
  187. size_t size);
  188. void plda_pcie_setup_inbound_address_translation(struct plda_pcie_rp *port);
  189. int plda_pcie_setup_iomems(struct pci_host_bridge *bridge,
  190. struct plda_pcie_rp *port);
  191. int plda_pcie_host_init(struct plda_pcie_rp *port, struct pci_ops *ops,
  192. const struct plda_event *plda_event);
  193. void plda_pcie_host_deinit(struct plda_pcie_rp *pcie);
  194. static inline void plda_set_default_msi(struct plda_msi *msi)
  195. {
  196. msi->vector_phy = IMSI_ADDR;
  197. msi->num_vectors = PLDA_MAX_NUM_MSI_IRQS;
  198. }
  199. static inline void plda_pcie_enable_root_port(struct plda_pcie_rp *plda)
  200. {
  201. u32 value;
  202. value = readl_relaxed(plda->bridge_addr + GEN_SETTINGS);
  203. value |= RP_ENABLE;
  204. writel_relaxed(value, plda->bridge_addr + GEN_SETTINGS);
  205. }
  206. static inline void plda_pcie_set_standard_class(struct plda_pcie_rp *plda)
  207. {
  208. u32 value;
  209. /* set class code and reserve revision id */
  210. value = readl_relaxed(plda->bridge_addr + PCIE_PCI_IDS_DW1);
  211. value &= REVISION_ID_MASK;
  212. value |= (PCI_CLASS_BRIDGE_PCI << IDS_CLASS_CODE_SHIFT);
  213. writel_relaxed(value, plda->bridge_addr + PCIE_PCI_IDS_DW1);
  214. }
  215. static inline void plda_pcie_set_pref_win_64bit(struct plda_pcie_rp *plda)
  216. {
  217. u32 value;
  218. value = readl_relaxed(plda->bridge_addr + PCIE_WINROM);
  219. value |= PREF_MEM_WIN_64_SUPPORT;
  220. writel_relaxed(value, plda->bridge_addr + PCIE_WINROM);
  221. }
  222. static inline void plda_pcie_disable_ltr(struct plda_pcie_rp *plda)
  223. {
  224. u32 value;
  225. value = readl_relaxed(plda->bridge_addr + PMSG_SUPPORT_RX);
  226. value &= ~PMSG_LTR_SUPPORT;
  227. writel_relaxed(value, plda->bridge_addr + PMSG_SUPPORT_RX);
  228. }
  229. static inline void plda_pcie_disable_func(struct plda_pcie_rp *plda)
  230. {
  231. u32 value;
  232. value = readl_relaxed(plda->bridge_addr + PCI_MISC);
  233. value |= PHY_FUNCTION_DIS;
  234. writel_relaxed(value, plda->bridge_addr + PCI_MISC);
  235. }
  236. static inline void plda_pcie_write_rc_bar(struct plda_pcie_rp *plda, u64 val)
  237. {
  238. void __iomem *addr = plda->bridge_addr + CONFIG_SPACE_ADDR_OFFSET;
  239. writel_relaxed(lower_32_bits(val), addr + PCI_BASE_ADDRESS_0);
  240. writel_relaxed(upper_32_bits(val), addr + PCI_BASE_ADDRESS_1);
  241. }
  242. #endif /* _PCIE_PLDA_H */