1 /* SPDX-License-Identifier: GPL-2.0+ */
3 * Copyright 2018-2019 NXP
5 * PCIe Gen4 driver for NXP Layerscape SoCs
6 * Author: Hou Zhiqiang <Minder.Hou@gmail.com>
9 #ifndef _PCIE_LAYERSCAPE_GEN4_H_
10 #define _PCIE_LAYERSCAPE_GEN4_H_
14 #ifndef CONFIG_SYS_PCI_MEMORY_SIZE
15 #define CONFIG_SYS_PCI_MEMORY_SIZE (4 * 1024 * 1024 * 1024ULL)
18 #ifndef CONFIG_SYS_PCI_EP_MEMORY_BASE
19 #define CONFIG_SYS_PCI_EP_MEMORY_BASE CONFIG_SYS_LOAD_ADDR
23 #define PCIE_VF_NUM 32
29 #define PCIE_BAR_SIZE (8 * 1024) /* 8K */
30 #define PCIE_BAR0_SIZE PCIE_BAR_SIZE
31 #define PCIE_BAR1_SIZE PCIE_BAR_SIZE
32 #define PCIE_BAR2_SIZE PCIE_BAR_SIZE
33 #define PCIE_BAR4_SIZE PCIE_BAR_SIZE
34 #define SIZE_1T (1024 * 1024 * 1024 * 1024ULL)
37 #define GPEX_CLASSCODE 0x474
38 #define GPEX_CLASSCODE_SHIFT 16
39 #define GPEX_CLASSCODE_MASK 0xffff
41 #define GPEX_CFG_READY 0x4b0
42 #define PCIE_CONFIG_READY BIT(0)
44 #define GPEX_BAR_ENABLE 0x4d4
45 #define GPEX_BAR_SIZE_LDW 0x4d8
46 #define GPEX_BAR_SIZE_UDW 0x4dC
47 #define GPEX_BAR_SELECT 0x4e0
49 #define BAR_POS(bar, pf, vf_bar) \
50 ((bar) + (pf) * PF_BAR_NUM + (vf_bar) * PCIE_PF_NUM * PF_BAR_NUM)
52 #define GPEX_SRIOV_INIT_VFS_TOTAL_VF(pf) (0x644 + (pf) * 4)
53 #define TTL_VF_MASK 0xffff
54 #define TTL_VF_SHIFT 16
55 #define INI_VF_MASK 0xffff
56 #define INI_VF_SHIFT 0
57 #define GPEX_SRIOV_VF_OFFSET_STRIDE(pf) (0x704 + (pf) * 4)
60 #define PAB_CTRL 0x808
61 #define PAB_CTRL_APIO_EN BIT(0)
62 #define PAB_CTRL_PPIO_EN BIT(1)
63 #define PAB_CTRL_MAX_BRST_LEN_SHIFT 4
64 #define PAB_CTRL_MAX_BRST_LEN_MASK 0x3
65 #define PAB_CTRL_PAGE_SEL_SHIFT 13
66 #define PAB_CTRL_PAGE_SEL_MASK 0x3f
67 #define PAB_CTRL_FUNC_SEL_SHIFT 19
68 #define PAB_CTRL_FUNC_SEL_MASK 0x1ff
70 #define PAB_RST_CTRL 0x820
71 #define PAB_BR_STAT 0x80c
74 #define PAB_AXI_PIO_CTRL(idx) (0x840 + 0x10 * (idx))
75 #define APIO_EN BIT(0)
76 #define MEM_WIN_EN BIT(1)
77 #define IO_WIN_EN BIT(2)
78 #define CFG_WIN_EN BIT(3)
79 #define PAB_AXI_PIO_STAT(idx) (0x844 + 0x10 * (idx))
80 #define PAB_AXI_PIO_SL_CMD_STAT(idx) (0x848 + 0x10 * (idx))
81 #define PAB_AXI_PIO_SL_ADDR_STAT(idx) (0x84c + 0x10 * (idx))
82 #define PAB_AXI_PIO_SL_EXT_ADDR_STAT(idx) (0xb8a0 + 0x4 * (idx))
85 #define PAB_PEX_PIO_CTRL(idx) (0x8c0 + 0x10 * (idx))
86 #define PPIO_EN BIT(0)
87 #define PAB_PEX_PIO_STAT(idx) (0x8c4 + 0x10 * (idx))
88 #define PAB_PEX_PIO_MT_STAT(idx) (0x8c8 + 0x10 * (idx))
90 #define INDIRECT_ADDR_BNDRY 0xc00
91 #define PAGE_IDX_SHIFT 10
92 #define PAGE_ADDR_MASK 0x3ff
94 #define OFFSET_TO_PAGE_IDX(off) \
95 (((off) >> PAGE_IDX_SHIFT) & PAB_CTRL_PAGE_SEL_MASK)
97 #define OFFSET_TO_PAGE_ADDR(off) \
98 (((off) & PAGE_ADDR_MASK) | INDIRECT_ADDR_BNDRY)
101 #define PAB_AXI_AMAP_CTRL(idx) (0xba0 + 0x10 * (idx))
102 #define PAB_EXT_AXI_AMAP_SIZE(idx) (0xbaf0 + 0x4 * (idx))
103 #define PAB_AXI_AMAP_AXI_WIN(idx) (0xba4 + 0x10 * (idx))
104 #define PAB_EXT_AXI_AMAP_AXI_WIN(idx) (0x80a0 + 0x4 * (idx))
105 #define PAB_AXI_AMAP_PEX_WIN_L(idx) (0xba8 + 0x10 * (idx))
106 #define PAB_AXI_AMAP_PEX_WIN_H(idx) (0xbac + 0x10 * (idx))
107 #define PAB_AXI_AMAP_PCI_HDR_PARAM(idx) (0x5ba0 + 0x4 * (idx))
108 #define FUNC_NUM_PCIE_MASK GENMASK(7, 0)
110 #define AXI_AMAP_CTRL_EN BIT(0)
111 #define AXI_AMAP_CTRL_TYPE_SHIFT 1
112 #define AXI_AMAP_CTRL_TYPE_MASK 0x3
113 #define AXI_AMAP_CTRL_SIZE_SHIFT 10
114 #define AXI_AMAP_CTRL_SIZE_MASK 0x3fffff
116 #define PAB_TARGET_BUS(x) (((x) & 0xff) << 24)
117 #define PAB_TARGET_DEV(x) (((x) & 0x1f) << 19)
118 #define PAB_TARGET_FUNC(x) (((x) & 0x7) << 16)
120 #define PAB_AXI_TYPE_CFG 0x00
121 #define PAB_AXI_TYPE_IO 0x01
122 #define PAB_AXI_TYPE_MEM 0x02
123 #define PAB_AXI_TYPE_ATOM 0x03
125 #define PAB_WINS_NUM 256
127 /* PPIO WINs RC mode */
128 #define PAB_PEX_AMAP_CTRL(idx) (0x4ba0 + 0x10 * (idx))
129 #define PAB_EXT_PEX_AMAP_SIZE(idx) (0xbef0 + 0x04 * (idx))
130 #define PAB_PEX_AMAP_AXI_WIN(idx) (0x4ba4 + 0x10 * (idx))
131 #define PAB_EXT_PEX_AMAP_AXI_WIN(idx) (0xb4a0 + 0x04 * (idx))
132 #define PAB_PEX_AMAP_PEX_WIN_L(idx) (0x4ba8 + 0x10 * (idx))
133 #define PAB_PEX_AMAP_PEX_WIN_H(idx) (0x4bac + 0x10 * (idx))
135 #define IB_TYPE_MEM_F 0x2
136 #define IB_TYPE_MEM_NF 0x3
138 #define PEX_AMAP_CTRL_TYPE_SHIFT 0x1
139 #define PEX_AMAP_CTRL_EN_SHIFT 0x0
140 #define PEX_AMAP_CTRL_TYPE_MASK 0x3
141 #define PEX_AMAP_CTRL_EN_MASK 0x1
143 /* PPIO WINs EP mode */
144 #define PAB_PEX_BAR_AMAP(pf, bar) \
145 (0x1ba0 + 0x20 * (pf) + 4 * (bar))
146 #define BAR_AMAP_EN BIT(0)
147 #define PAB_EXT_PEX_BAR_AMAP(pf, bar) \
148 (0x84a0 + 0x20 * (pf) + 4 * (bar))
151 #define PCIE_LINK_CTRL_STA 0x5c
152 #define PCIE_LINK_SPEED_SHIFT 16
153 #define PCIE_LINK_SPEED_MASK 0x0f
154 #define PCIE_LINK_WIDTH_SHIFT 20
155 #define PCIE_LINK_WIDTH_MASK 0x3f
156 #define PCIE_SRIOV_CAPABILITY 0x2a0
157 #define PCIE_SRIOV_VF_OFFSET_STRIDE 0x2b4
160 #define PCIE_LUT_UDR(n) (0x800 + (n) * 8)
161 #define PCIE_LUT_LDR(n) (0x804 + (n) * 8)
162 #define PCIE_LUT_ENABLE BIT(31)
163 #define PCIE_LUT_ENTRY_COUNT 32
165 /* PF control registers */
166 #define PCIE_LTSSM_STA 0x7fc
167 #define LTSSM_STATE_MASK 0x7f
168 #define LTSSM_PCIE_L0 0x2d /* L0 state */
170 #define PCIE_SRDS_PRTCL(idx) (PCIE1 + (idx))
171 #define PCIE_SYS_BASE_ADDR 0x3400000
172 #define PCIE_CCSR_SIZE 0x0100000
176 struct list_head list;
178 struct fdt_resource ccsr_res;
179 struct fdt_resource cfg_res;
180 struct fdt_resource lut_res;
181 struct fdt_resource pf_ctrl_res;
185 void __iomem *pf_ctrl;
189 struct pci_controller hose;
195 extern struct list_head ls_pcie_g4_list;
197 static inline void lut_writel(struct ls_pcie_g4 *pcie, unsigned int value,
200 if (pcie->big_endian)
201 out_be32(pcie->lut + offset, value);
203 out_le32(pcie->lut + offset, value);
206 static inline u32 lut_readl(struct ls_pcie_g4 *pcie, unsigned int offset)
208 if (pcie->big_endian)
209 return in_be32(pcie->lut + offset);
211 return in_le32(pcie->lut + offset);
214 static inline void ccsr_set_page(struct ls_pcie_g4 *pcie, u8 pg_idx)
218 val = in_le32(pcie->ccsr + PAB_CTRL);
219 val &= ~(PAB_CTRL_PAGE_SEL_MASK << PAB_CTRL_PAGE_SEL_SHIFT);
220 val |= (pg_idx & PAB_CTRL_PAGE_SEL_MASK) << PAB_CTRL_PAGE_SEL_SHIFT;
222 out_le32(pcie->ccsr + PAB_CTRL, val);
225 static inline unsigned int ccsr_readl(struct ls_pcie_g4 *pcie, u32 offset)
227 if (offset < INDIRECT_ADDR_BNDRY) {
228 ccsr_set_page(pcie, 0);
229 return in_le32(pcie->ccsr + offset);
232 ccsr_set_page(pcie, OFFSET_TO_PAGE_IDX(offset));
233 return in_le32(pcie->ccsr + OFFSET_TO_PAGE_ADDR(offset));
236 static inline void ccsr_writel(struct ls_pcie_g4 *pcie, u32 offset, u32 value)
238 if (offset < INDIRECT_ADDR_BNDRY) {
239 ccsr_set_page(pcie, 0);
240 out_le32(pcie->ccsr + offset, value);
242 ccsr_set_page(pcie, OFFSET_TO_PAGE_IDX(offset));
243 out_le32(pcie->ccsr + OFFSET_TO_PAGE_ADDR(offset), value);
247 static inline unsigned int pf_ctrl_readl(struct ls_pcie_g4 *pcie, u32 offset)
249 if (pcie->big_endian)
250 return in_be32(pcie->pf_ctrl + offset);
252 return in_le32(pcie->pf_ctrl + offset);
255 static inline void pf_ctrl_writel(struct ls_pcie_g4 *pcie, u32 offset,
258 if (pcie->big_endian)
259 out_be32(pcie->pf_ctrl + offset, value);
261 out_le32(pcie->pf_ctrl + offset, value);
264 #endif /* _PCIE_LAYERSCAPE_GEN4_H_ */