5e893d4a8bead13004693951101877a5f7c1b221
[platform/kernel/u-boot.git] / drivers / pci / pcie_layerscape.h
1 /*
2  * Copyright 2014-2015 Freescale Semiconductor, Inc.
3  * Layerscape PCIe driver
4  *
5  * SPDX-License-Identifier:     GPL-2.0+
6  */
7
8 #ifndef _PCIE_LAYERSCAPE_H_
9 #define _PCIE_LAYERSCAPE_H_
10 #include <pci.h>
11
12 #ifndef CONFIG_SYS_PCI_MEMORY_BUS
13 #define CONFIG_SYS_PCI_MEMORY_BUS CONFIG_SYS_SDRAM_BASE
14 #endif
15
16 #ifndef CONFIG_SYS_PCI_MEMORY_PHYS
17 #define CONFIG_SYS_PCI_MEMORY_PHYS CONFIG_SYS_SDRAM_BASE
18 #endif
19
20 #ifndef CONFIG_SYS_PCI_MEMORY_SIZE
21 #define CONFIG_SYS_PCI_MEMORY_SIZE (2 * 1024 * 1024 * 1024UL) /* 2G */
22 #endif
23
24 #ifndef CONFIG_SYS_PCI_EP_MEMORY_BASE
25 #define CONFIG_SYS_PCI_EP_MEMORY_BASE CONFIG_SYS_LOAD_ADDR
26 #endif
27
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_CR1                    0x904
38 #define PCIE_ATU_TYPE_MEM               (0x0 << 0)
39 #define PCIE_ATU_TYPE_IO                (0x2 << 0)
40 #define PCIE_ATU_TYPE_CFG0              (0x4 << 0)
41 #define PCIE_ATU_TYPE_CFG1              (0x5 << 0)
42 #define PCIE_ATU_CR2                    0x908
43 #define PCIE_ATU_ENABLE                 (0x1 << 31)
44 #define PCIE_ATU_BAR_MODE_ENABLE        (0x1 << 30)
45 #define PCIE_ATU_BAR_NUM(bar)           ((bar) << 8)
46 #define PCIE_ATU_LOWER_BASE             0x90C
47 #define PCIE_ATU_UPPER_BASE             0x910
48 #define PCIE_ATU_LIMIT                  0x914
49 #define PCIE_ATU_LOWER_TARGET           0x918
50 #define PCIE_ATU_BUS(x)                 (((x) & 0xff) << 24)
51 #define PCIE_ATU_DEV(x)                 (((x) & 0x1f) << 19)
52 #define PCIE_ATU_FUNC(x)                (((x) & 0x7) << 16)
53 #define PCIE_ATU_UPPER_TARGET           0x91C
54
55 /* DBI registers */
56 #define PCIE_SRIOV              0x178
57 #define PCIE_STRFMR1            0x71c /* Symbol Timer & Filter Mask Register1 */
58 #define PCIE_DBI_RO_WR_EN       0x8bc
59
60 #define PCIE_LINK_CAP           0x7c
61 #define PCIE_LINK_SPEED_MASK    0xf
62 #define PCIE_LINK_WIDTH_MASK    0x3f0
63 #define PCIE_LINK_STA           0x82
64
65 #define LTSSM_STATE_MASK        0x3f
66 #define LTSSM_PCIE_L0           0x11 /* L0 state */
67
68 #define PCIE_DBI_SIZE           0x100000 /* 1M */
69
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
79 #define PCIE_NO_SRIOV_BAR_BASE  0x1000
80
81 #define PCIE_PF_NUM             2
82 #define PCIE_VF_NUM             64
83
84 #define PCIE_BAR0_SIZE          (4 * 1024) /* 4K */
85 #define PCIE_BAR1_SIZE          (8 * 1024) /* 8K for MSIX */
86 #define PCIE_BAR2_SIZE          (4 * 1024) /* 4K */
87 #define PCIE_BAR4_SIZE          (1 * 1024 * 1024) /* 1M */
88
89 #ifndef CONFIG_DM_PCI
90 struct ls_pcie {
91         int idx;
92         void __iomem *dbi;
93         void __iomem *va_cfg0;
94         void __iomem *va_cfg1;
95         int next_lut_index;
96         struct pci_controller hose;
97 };
98
99 struct ls_pcie_info {
100         unsigned long regs;
101         int pci_num;
102         u64 phys_base;
103         u64 cfg0_phys;
104         u64 cfg0_size;
105         u64 cfg1_phys;
106         u64 cfg1_size;
107         u64 mem_bus;
108         u64 mem_phys;
109         u64 mem_size;
110         u64 io_bus;
111         u64 io_phys;
112         u64 io_size;
113 };
114
115 #define SET_LS_PCIE_INFO(x, num)                        \
116 {                                                       \
117         x.regs = CONFIG_SYS_PCIE##num##_ADDR;           \
118         x.phys_base = CONFIG_SYS_PCIE##num##_PHYS_ADDR; \
119         x.cfg0_phys = CONFIG_SYS_PCIE_CFG0_PHYS_OFF +   \
120                       CONFIG_SYS_PCIE##num##_PHYS_ADDR; \
121         x.cfg0_size = CONFIG_SYS_PCIE_CFG0_SIZE;        \
122         x.cfg1_phys = CONFIG_SYS_PCIE_CFG1_PHYS_OFF +   \
123                       CONFIG_SYS_PCIE##num##_PHYS_ADDR; \
124         x.cfg1_size = CONFIG_SYS_PCIE_CFG1_SIZE;        \
125         x.mem_bus = CONFIG_SYS_PCIE_MEM_BUS;            \
126         x.mem_phys = CONFIG_SYS_PCIE_MEM_PHYS_OFF +     \
127                      CONFIG_SYS_PCIE##num##_PHYS_ADDR;  \
128         x.mem_size = CONFIG_SYS_PCIE_MEM_SIZE;          \
129         x.io_bus = CONFIG_SYS_PCIE_IO_BUS;              \
130         x.io_phys = CONFIG_SYS_PCIE_IO_PHYS_OFF +       \
131                     CONFIG_SYS_PCIE##num##_PHYS_ADDR;   \
132         x.io_size = CONFIG_SYS_PCIE_IO_SIZE;            \
133         x.pci_num = num;                                \
134 }
135
136 #else /* CONFIG_DM_PCI */
137
138 #include <dm.h>
139
140 /* LUT registers */
141 #define PCIE_LUT_UDR(n)         (0x800 + (n) * 8)
142 #define PCIE_LUT_LDR(n)         (0x804 + (n) * 8)
143 #define PCIE_LUT_ENABLE         (1 << 31)
144 #define PCIE_LUT_ENTRY_COUNT    32
145
146 /* PF Controll registers */
147 #define PCIE_PF_VF_CTRL         0x7F8
148 #define PCIE_PF_DBG             0x7FC
149
150 #define PCIE_SRDS_PRTCL(idx)    (PCIE1 + (idx))
151 #define PCIE_SYS_BASE_ADDR      0x3400000
152 #define PCIE_CCSR_SIZE          0x0100000
153
154 /* CS2 */
155 #define PCIE_CS2_OFFSET         0x1000 /* For PCIe without SR-IOV */
156
157 #define SVR_LS102XA             0
158 #define SVR_VAR_PER_SHIFT       8
159 #define SVR_LS102XA_MASK        0x700
160
161 /* LS1021a PCIE space */
162 #define LS1021_PCIE_SPACE_OFFSET        0x4000000000ULL
163 #define LS1021_PCIE_SPACE_SIZE          0x0800000000ULL
164
165 /* LS1021a PEX1/2 Misc Ports Status Register */
166 #define LS1021_PEXMSCPORTSR(pex_idx)    (0x94 + (pex_idx) * 4)
167 #define LS1021_LTSSM_STATE_SHIFT        20
168
169 struct ls_pcie {
170         int idx;
171         struct list_head list;
172         struct udevice *bus;
173         struct fdt_resource dbi_res;
174         struct fdt_resource lut_res;
175         struct fdt_resource ctrl_res;
176         struct fdt_resource cfg_res;
177         void __iomem *dbi;
178         void __iomem *lut;
179         void __iomem *ctrl;
180         void __iomem *cfg0;
181         void __iomem *cfg1;
182         bool big_endian;
183         bool enabled;
184         int next_lut_index;
185         struct pci_controller hose;
186 };
187
188 extern struct list_head ls_pcie_list;
189
190 #endif /* CONFIG_DM_PCI */
191 #endif /* _PCIE_LAYERSCAPE_H_ */