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