]> Git Repo - J-u-boot.git/blame - drivers/pci/pcie_layerscape.h
Merge tag 'u-boot-imx-master-20250127' of https://gitlab.denx.de/u-boot/custodians...
[J-u-boot.git] / drivers / pci / pcie_layerscape.h
CommitLineData
83d290c5 1/* SPDX-License-Identifier: GPL-2.0+ */
a7294aba 2/*
118e58e2 3 * Copyright 2017-2020 NXP
a7294aba
HZ
4 * Copyright 2014-2015 Freescale Semiconductor, Inc.
5 * Layerscape PCIe driver
a7294aba
HZ
6 */
7
8#ifndef _PCIE_LAYERSCAPE_H_
9#define _PCIE_LAYERSCAPE_H_
10#include <pci.h>
51a4a857 11
c5174a52 12#include <linux/sizes.h>
58410733
HZ
13#include <asm/arch-fsl-layerscape/svr.h>
14#include <asm/arch-ls102xa/svr.h>
a7294aba 15
ecc8d425 16#ifndef CFG_SYS_PCI_MEMORY_BUS
aa6e94de 17#define CFG_SYS_PCI_MEMORY_BUS CFG_SYS_SDRAM_BASE
a7294aba
HZ
18#endif
19
ecc8d425 20#ifndef CFG_SYS_PCI_MEMORY_PHYS
aa6e94de 21#define CFG_SYS_PCI_MEMORY_PHYS CFG_SYS_SDRAM_BASE
a7294aba
HZ
22#endif
23
ecc8d425
TR
24#ifndef CFG_SYS_PCI_MEMORY_SIZE
25#define CFG_SYS_PCI_MEMORY_SIZE SZ_4G
a7294aba
HZ
26#endif
27
ecc8d425
TR
28#ifndef CFG_SYS_PCI_EP_MEMORY_BASE
29#define CFG_SYS_PCI_EP_MEMORY_BASE CONFIG_SYS_LOAD_ADDR
a7294aba
HZ
30#endif
31
3d8553f0
HZ
32#define PCIE_PHYS_SIZE 0x200000000
33#define LS2088A_PCIE_PHYS_SIZE 0x800000000
34#define LS2088A_PCIE1_PHYS_ADDR 0x2000000000
35
a7294aba
HZ
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
83bf32e6 45#define PCIE_ATU_REGION_NUM_SRIOV 24
a7294aba
HZ
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)
c5174a52 51#define PCIE_ATU_FUNC_NUM(pf) ((pf) << 20)
a7294aba
HZ
52#define PCIE_ATU_CR2 0x908
53#define PCIE_ATU_ENABLE (0x1 << 31)
54#define PCIE_ATU_BAR_MODE_ENABLE (0x1 << 30)
83bf32e6
XB
55#define PCIE_ATU_FUNC_NUM_MATCH_EN BIT(19)
56#define PCIE_ATU_VFBAR_MATCH_MODE_EN BIT(26)
a7294aba
HZ
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 */
118e58e2
XB
70#define PCIE_DBI_RO_WR_EN BIT(0)
71#define PCIE_MISC_CONTROL_1_OFF 0x8BC
a7294aba
HZ
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
118e58e2 93#define FSL_PCIE_EP_MIN_APERTURE 4096 /* 4 Kbytes */
a7294aba
HZ
94#define PCIE_PF_NUM 2
95#define PCIE_VF_NUM 64
83bf32e6 96#define BAR_NUM 8
a7294aba 97
c5174a52
XB
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
4085e3a4 105#define PCIE_MASK_OFFSET(flag, pf, off) ((flag) ? 0 : (0x1000 + (off) * (pf)))
a7294aba 106
80afc63f
ML
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 */
d170aca1 114#define PCIE_PF_CONFIG 0x14
80afc63f
ML
115#define PCIE_PF_VF_CTRL 0x7F8
116#define PCIE_PF_DBG 0x7FC
d170aca1 117#define PCIE_CONFIG_READY (1 << 0)
80afc63f
ML
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
80afc63f
ML
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
4085e3a4
XB
134/* LX2160a PF1 offset */
135#define LX2160_PCIE_PF1_OFFSET 0x8000
136
137/* layerscape PF1 offset */
138#define LS_PCIE_PF1_OFFSET 0x20000
139
80afc63f 140struct ls_pcie {
118e58e2
XB
141 void __iomem *dbi;
142 void __iomem *lut;
143 void __iomem *ctrl;
80afc63f 144 int idx;
118e58e2
XB
145 bool big_endian;
146 int mode;
147};
148
149struct ls_pcie_rc {
150 struct ls_pcie *pcie;
80afc63f
ML
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;
80afc63f
ML
157 void __iomem *cfg0;
158 void __iomem *cfg1;
80afc63f
ML
159 bool enabled;
160 int next_lut_index;
c81b1ea7 161 int stream_id_cur;
118e58e2
XB
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;
c5174a52
XB
169 u32 cfg2_flag;
170 u32 sriov_flag;
4085e3a4 171 u32 pf1_offset;
118e58e2
XB
172 u32 num_ib_wins;
173 u32 num_ob_wins;
174 u8 max_functions;
80afc63f
ML
175};
176
177extern struct list_head ls_pcie_list;
178
118e58e2
XB
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,
83bf32e6
XB
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);
80b5a662 187void ls_pcie_dump_atu(struct ls_pcie *pcie, u32 win_num, u32 type);
118e58e2
XB
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
a7294aba 192#endif /* _PCIE_LAYERSCAPE_H_ */
This page took 0.288675 seconds and 4 git commands to generate.