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