1
2
3
4
5
6
7
8#ifndef _PCIE_LAYERSCAPE_H_
9#define _PCIE_LAYERSCAPE_H_
10#include <pci.h>
11
12#include <linux/sizes.h>
13#include <asm/arch-fsl-layerscape/svr.h>
14#include <asm/arch-ls102xa/svr.h>
15
16#ifndef CONFIG_SYS_PCI_MEMORY_BUS
17#define CONFIG_SYS_PCI_MEMORY_BUS CONFIG_SYS_SDRAM_BASE
18#endif
19
20#ifndef CONFIG_SYS_PCI_MEMORY_PHYS
21#define CONFIG_SYS_PCI_MEMORY_PHYS CONFIG_SYS_SDRAM_BASE
22#endif
23
24#ifndef CONFIG_SYS_PCI_MEMORY_SIZE
25#define CONFIG_SYS_PCI_MEMORY_SIZE SZ_4G
26#endif
27
28#ifndef CONFIG_SYS_PCI_EP_MEMORY_BASE
29#define CONFIG_SYS_PCI_EP_MEMORY_BASE CONFIG_SYS_LOAD_ADDR
30#endif
31
32#define PCIE_PHYS_SIZE 0x200000000
33#define LS2088A_PCIE_PHYS_SIZE 0x800000000
34#define LS2088A_PCIE1_PHYS_ADDR 0x2000000000
35
36
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
45#define PCIE_ATU_REGION_NUM_SRIOV 24
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)
51#define PCIE_ATU_FUNC_NUM(pf) ((pf) << 20)
52#define PCIE_ATU_CR2 0x908
53#define PCIE_ATU_ENABLE (0x1 << 31)
54#define PCIE_ATU_BAR_MODE_ENABLE (0x1 << 30)
55#define PCIE_ATU_FUNC_NUM_MATCH_EN BIT(19)
56#define PCIE_ATU_VFBAR_MATCH_MODE_EN BIT(26)
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
68#define PCIE_SRIOV 0x178
69#define PCIE_STRFMR1 0x71c
70#define PCIE_DBI_RO_WR_EN BIT(0)
71#define PCIE_MISC_CONTROL_1_OFF 0x8BC
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
80
81#define PCIE_DBI_SIZE 0x100000
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
93#define FSL_PCIE_EP_MIN_APERTURE 4096
94#define PCIE_PF_NUM 2
95#define PCIE_VF_NUM 64
96#define BAR_NUM 8
97
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
105#define PCIE_MASK_OFFSET(flag, pf, off) ((flag) ? 0 : (0x1000 + (off) * (pf)))
106
107
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
114#define PCIE_PF_CONFIG 0x14
115#define PCIE_PF_VF_CTRL 0x7F8
116#define PCIE_PF_DBG 0x7FC
117#define PCIE_CONFIG_READY (1 << 0)
118
119#define PCIE_SRDS_PRTCL(idx) (PCIE1 + (idx))
120#define PCIE_SYS_BASE_ADDR 0x3400000
121#define PCIE_CCSR_SIZE 0x0100000
122
123
124#define PCIE_CS2_OFFSET 0x1000
125
126
127#define LS1021_PCIE_SPACE_OFFSET 0x4000000000ULL
128#define LS1021_PCIE_SPACE_SIZE 0x0800000000ULL
129
130
131#define LS1021_PEXMSCPORTSR(pex_idx) (0x94 + (pex_idx) * 4)
132#define LS1021_LTSSM_STATE_SHIFT 20
133
134
135#define LX2160_PCIE_PF1_OFFSET 0x8000
136
137
138#define LS_PCIE_PF1_OFFSET 0x20000
139
140struct ls_pcie {
141 void __iomem *dbi;
142 void __iomem *lut;
143 void __iomem *ctrl;
144 int idx;
145 bool big_endian;
146 int mode;
147};
148
149struct ls_pcie_rc {
150 struct ls_pcie *pcie;
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;
157 void __iomem *cfg0;
158 void __iomem *cfg1;
159 bool enabled;
160 int next_lut_index;
161 int stream_id_cur;
162};
163
164struct ls_pcie_ep {
165 struct fdt_resource addr_res;
166 struct ls_pcie *pcie;
167 struct udevice *bus;
168 void __iomem *addr;
169 u32 cfg2_flag;
170 u32 sriov_flag;
171 u32 pf1_offset;
172 u32 num_ib_wins;
173 u32 num_ob_wins;
174 u8 max_functions;
175};
176
177extern struct list_head ls_pcie_list;
178
179unsigned int dbi_readl(struct ls_pcie *pcie, unsigned int offset);
180void dbi_writel(struct ls_pcie *pcie, unsigned int value, unsigned int offset);
181unsigned int ctrl_readl(struct ls_pcie *pcie, unsigned int offset);
182void ctrl_writel(struct ls_pcie *pcie, unsigned int value, unsigned int offset);
183void ls_pcie_atu_outbound_set(struct ls_pcie *pcie, int idx, int type,
184 u64 phys, u64 bus_addr, u64 size);
185void ls_pcie_atu_inbound_set(struct ls_pcie *pcie, u32 pf, u32 vf_flag,
186 int type, int idx, int bar, u64 phys);
187void ls_pcie_dump_atu(struct ls_pcie *pcie, u32 win_num, u32 type);
188int ls_pcie_link_up(struct ls_pcie *pcie);
189void ls_pcie_dbi_ro_wr_en(struct ls_pcie *pcie);
190void ls_pcie_dbi_ro_wr_dis(struct ls_pcie *pcie);
191
192#endif
193