xref: /rk3399_rockchip-uboot/drivers/pci/pcie_layerscape.h (revision a7294aba086fb05ef2bbb50098a84d6c81e38a4b)
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 struct ls_pcie {
90 	int idx;
91 	void __iomem *dbi;
92 	void __iomem *va_cfg0;
93 	void __iomem *va_cfg1;
94 	int next_lut_index;
95 	struct pci_controller hose;
96 };
97 
98 struct ls_pcie_info {
99 	unsigned long regs;
100 	int pci_num;
101 	u64 phys_base;
102 	u64 cfg0_phys;
103 	u64 cfg0_size;
104 	u64 cfg1_phys;
105 	u64 cfg1_size;
106 	u64 mem_bus;
107 	u64 mem_phys;
108 	u64 mem_size;
109 	u64 io_bus;
110 	u64 io_phys;
111 	u64 io_size;
112 };
113 
114 #define SET_LS_PCIE_INFO(x, num)			\
115 {							\
116 	x.regs = CONFIG_SYS_PCIE##num##_ADDR;		\
117 	x.phys_base = CONFIG_SYS_PCIE##num##_PHYS_ADDR;	\
118 	x.cfg0_phys = CONFIG_SYS_PCIE_CFG0_PHYS_OFF +	\
119 		      CONFIG_SYS_PCIE##num##_PHYS_ADDR;	\
120 	x.cfg0_size = CONFIG_SYS_PCIE_CFG0_SIZE;	\
121 	x.cfg1_phys = CONFIG_SYS_PCIE_CFG1_PHYS_OFF +	\
122 		      CONFIG_SYS_PCIE##num##_PHYS_ADDR;	\
123 	x.cfg1_size = CONFIG_SYS_PCIE_CFG1_SIZE;	\
124 	x.mem_bus = CONFIG_SYS_PCIE_MEM_BUS;		\
125 	x.mem_phys = CONFIG_SYS_PCIE_MEM_PHYS_OFF +	\
126 		     CONFIG_SYS_PCIE##num##_PHYS_ADDR;	\
127 	x.mem_size = CONFIG_SYS_PCIE_MEM_SIZE;		\
128 	x.io_bus = CONFIG_SYS_PCIE_IO_BUS;		\
129 	x.io_phys = CONFIG_SYS_PCIE_IO_PHYS_OFF +	\
130 		    CONFIG_SYS_PCIE##num##_PHYS_ADDR;	\
131 	x.io_size = CONFIG_SYS_PCIE_IO_SIZE;		\
132 	x.pci_num = num;				\
133 }
134 
135 #endif /* _PCIE_LAYERSCAPE_H_ */
136