pcie_layerscape.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * Copyright 2017-2020 NXP
  4. * Copyright 2014-2015 Freescale Semiconductor, Inc.
  5. * Layerscape PCIe driver
  6. */
  7. #ifndef _PCIE_LAYERSCAPE_H_
  8. #define _PCIE_LAYERSCAPE_H_
  9. #include <pci.h>
  10. #include <linux/sizes.h>
  11. #include <asm/arch-fsl-layerscape/svr.h>
  12. #include <asm/arch-ls102xa/svr.h>
  13. #ifndef CONFIG_SYS_PCI_MEMORY_BUS
  14. #define CONFIG_SYS_PCI_MEMORY_BUS CONFIG_SYS_SDRAM_BASE
  15. #endif
  16. #ifndef CONFIG_SYS_PCI_MEMORY_PHYS
  17. #define CONFIG_SYS_PCI_MEMORY_PHYS CONFIG_SYS_SDRAM_BASE
  18. #endif
  19. #ifndef CONFIG_SYS_PCI_MEMORY_SIZE
  20. #define CONFIG_SYS_PCI_MEMORY_SIZE SZ_4G
  21. #endif
  22. #ifndef CONFIG_SYS_PCI_EP_MEMORY_BASE
  23. #define CONFIG_SYS_PCI_EP_MEMORY_BASE CONFIG_SYS_LOAD_ADDR
  24. #endif
  25. #define PCIE_PHYS_SIZE 0x200000000
  26. #define LS2088A_PCIE_PHYS_SIZE 0x800000000
  27. #define LS2088A_PCIE1_PHYS_ADDR 0x2000000000
  28. /* iATU registers */
  29. #define PCIE_ATU_VIEWPORT 0x900
  30. #define PCIE_ATU_REGION_INBOUND (0x1 << 31)
  31. #define PCIE_ATU_REGION_OUTBOUND (0x0 << 31)
  32. #define PCIE_ATU_REGION_INDEX0 (0x0 << 0)
  33. #define PCIE_ATU_REGION_INDEX1 (0x1 << 0)
  34. #define PCIE_ATU_REGION_INDEX2 (0x2 << 0)
  35. #define PCIE_ATU_REGION_INDEX3 (0x3 << 0)
  36. #define PCIE_ATU_REGION_NUM 6
  37. #define PCIE_ATU_REGION_NUM_SRIOV 24
  38. #define PCIE_ATU_CR1 0x904
  39. #define PCIE_ATU_TYPE_MEM (0x0 << 0)
  40. #define PCIE_ATU_TYPE_IO (0x2 << 0)
  41. #define PCIE_ATU_TYPE_CFG0 (0x4 << 0)
  42. #define PCIE_ATU_TYPE_CFG1 (0x5 << 0)
  43. #define PCIE_ATU_FUNC_NUM(pf) ((pf) << 20)
  44. #define PCIE_ATU_CR2 0x908
  45. #define PCIE_ATU_ENABLE (0x1 << 31)
  46. #define PCIE_ATU_BAR_MODE_ENABLE (0x1 << 30)
  47. #define PCIE_ATU_FUNC_NUM_MATCH_EN BIT(19)
  48. #define PCIE_ATU_VFBAR_MATCH_MODE_EN BIT(26)
  49. #define PCIE_ATU_BAR_NUM(bar) ((bar) << 8)
  50. #define PCIE_ATU_LOWER_BASE 0x90C
  51. #define PCIE_ATU_UPPER_BASE 0x910
  52. #define PCIE_ATU_LIMIT 0x914
  53. #define PCIE_ATU_LOWER_TARGET 0x918
  54. #define PCIE_ATU_BUS(x) (((x) & 0xff) << 24)
  55. #define PCIE_ATU_DEV(x) (((x) & 0x1f) << 19)
  56. #define PCIE_ATU_FUNC(x) (((x) & 0x7) << 16)
  57. #define PCIE_ATU_UPPER_TARGET 0x91C
  58. /* DBI registers */
  59. #define PCIE_SRIOV 0x178
  60. #define PCIE_STRFMR1 0x71c /* Symbol Timer & Filter Mask Register1 */
  61. #define PCIE_DBI_RO_WR_EN BIT(0)
  62. #define PCIE_MISC_CONTROL_1_OFF 0x8BC
  63. #define PCIE_LINK_CAP 0x7c
  64. #define PCIE_LINK_SPEED_MASK 0xf
  65. #define PCIE_LINK_WIDTH_MASK 0x3f0
  66. #define PCIE_LINK_STA 0x82
  67. #define LTSSM_STATE_MASK 0x3f
  68. #define LTSSM_PCIE_L0 0x11 /* L0 state */
  69. #define PCIE_DBI_SIZE 0x100000 /* 1M */
  70. #define PCIE_LCTRL0_CFG2_ENABLE (1 << 31)
  71. #define PCIE_LCTRL0_VF(vf) ((vf) << 22)
  72. #define PCIE_LCTRL0_PF(pf) ((pf) << 16)
  73. #define PCIE_LCTRL0_VF_ACTIVE (1 << 21)
  74. #define PCIE_LCTRL0_VAL(pf, vf) (PCIE_LCTRL0_PF(pf) | \
  75. PCIE_LCTRL0_VF(vf) | \
  76. ((vf) == 0 ? 0 : PCIE_LCTRL0_VF_ACTIVE) | \
  77. PCIE_LCTRL0_CFG2_ENABLE)
  78. #define PCIE_NO_SRIOV_BAR_BASE 0x1000
  79. #define FSL_PCIE_EP_MIN_APERTURE 4096 /* 4 Kbytes */
  80. #define PCIE_PF_NUM 2
  81. #define PCIE_VF_NUM 64
  82. #define BAR_NUM 8
  83. #define PCIE_BAR0_SIZE SZ_4K
  84. #define PCIE_BAR1_SIZE SZ_8K
  85. #define PCIE_BAR2_SIZE SZ_4K
  86. #define PCIE_BAR4_SIZE SZ_1M
  87. #define PCIE_SRIOV_VFBAR0 0x19C
  88. #define PCIE_MASK_OFFSET(flag, pf, off) ((flag) ? 0 : (0x1000 + (off) * (pf)))
  89. /* LUT registers */
  90. #define PCIE_LUT_UDR(n) (0x800 + (n) * 8)
  91. #define PCIE_LUT_LDR(n) (0x804 + (n) * 8)
  92. #define PCIE_LUT_ENABLE (1 << 31)
  93. #define PCIE_LUT_ENTRY_COUNT 32
  94. /* PF Controll registers */
  95. #define PCIE_PF_CONFIG 0x14
  96. #define PCIE_PF_VF_CTRL 0x7F8
  97. #define PCIE_PF_DBG 0x7FC
  98. #define PCIE_CONFIG_READY (1 << 0)
  99. #define PCIE_SRDS_PRTCL(idx) (PCIE1 + (idx))
  100. #define PCIE_SYS_BASE_ADDR 0x3400000
  101. #define PCIE_CCSR_SIZE 0x0100000
  102. /* CS2 */
  103. #define PCIE_CS2_OFFSET 0x1000 /* For PCIe without SR-IOV */
  104. /* LS1021a PCIE space */
  105. #define LS1021_PCIE_SPACE_OFFSET 0x4000000000ULL
  106. #define LS1021_PCIE_SPACE_SIZE 0x0800000000ULL
  107. /* LS1021a PEX1/2 Misc Ports Status Register */
  108. #define LS1021_PEXMSCPORTSR(pex_idx) (0x94 + (pex_idx) * 4)
  109. #define LS1021_LTSSM_STATE_SHIFT 20
  110. /* LX2160a PF1 offset */
  111. #define LX2160_PCIE_PF1_OFFSET 0x8000
  112. /* layerscape PF1 offset */
  113. #define LS_PCIE_PF1_OFFSET 0x20000
  114. struct ls_pcie {
  115. void __iomem *dbi;
  116. void __iomem *lut;
  117. void __iomem *ctrl;
  118. int idx;
  119. bool big_endian;
  120. int mode;
  121. };
  122. struct ls_pcie_rc {
  123. struct ls_pcie *pcie;
  124. struct list_head list;
  125. struct udevice *bus;
  126. struct fdt_resource dbi_res;
  127. struct fdt_resource lut_res;
  128. struct fdt_resource ctrl_res;
  129. struct fdt_resource cfg_res;
  130. void __iomem *cfg0;
  131. void __iomem *cfg1;
  132. bool enabled;
  133. int next_lut_index;
  134. int stream_id_cur;
  135. };
  136. struct ls_pcie_ep {
  137. struct fdt_resource addr_res;
  138. struct ls_pcie *pcie;
  139. struct udevice *bus;
  140. void __iomem *addr;
  141. u32 cfg2_flag;
  142. u32 sriov_flag;
  143. u32 pf1_offset;
  144. u32 num_ib_wins;
  145. u32 num_ob_wins;
  146. u8 max_functions;
  147. };
  148. extern struct list_head ls_pcie_list;
  149. unsigned int dbi_readl(struct ls_pcie *pcie, unsigned int offset);
  150. void dbi_writel(struct ls_pcie *pcie, unsigned int value, unsigned int offset);
  151. unsigned int ctrl_readl(struct ls_pcie *pcie, unsigned int offset);
  152. void ctrl_writel(struct ls_pcie *pcie, unsigned int value, unsigned int offset);
  153. void ls_pcie_atu_outbound_set(struct ls_pcie *pcie, int idx, int type,
  154. u64 phys, u64 bus_addr, u64 size);
  155. void ls_pcie_atu_inbound_set(struct ls_pcie *pcie, u32 pf, u32 vf_flag,
  156. int type, int idx, int bar, u64 phys);
  157. void ls_pcie_dump_atu(struct ls_pcie *pcie, u32 win_num, u32 type);
  158. int ls_pcie_link_up(struct ls_pcie *pcie);
  159. void ls_pcie_dbi_ro_wr_en(struct ls_pcie *pcie);
  160. void ls_pcie_dbi_ro_wr_dis(struct ls_pcie *pcie);
  161. #endif /* _PCIE_LAYERSCAPE_H_ */