1
2
3
4
5
6
7
8#include <common.h>
9#include <dm.h>
10#include <pci.h>
11
12#include <asm/io.h>
13
14
15
16
17
18struct xilinx_pcie {
19 void *cfg_base;
20};
21
22
23#define XILINX_PCIE_REG_PSCR 0x144
24#define XILINX_PCIE_REG_PSCR_LNKUP BIT(11)
25
26
27
28
29
30
31
32
33
34static bool pcie_xilinx_link_up(struct xilinx_pcie *pcie)
35{
36 uint32_t pscr = __raw_readl(pcie->cfg_base + XILINX_PCIE_REG_PSCR);
37
38 return pscr & XILINX_PCIE_REG_PSCR_LNKUP;
39}
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57static int pcie_xilinx_config_address(struct udevice *udev, pci_dev_t bdf,
58 uint offset, void **paddress)
59{
60 struct xilinx_pcie *pcie = dev_get_priv(udev);
61 unsigned int bus = PCI_BUS(bdf);
62 unsigned int dev = PCI_DEV(bdf);
63 unsigned int func = PCI_FUNC(bdf);
64 void *addr;
65
66 if ((bus > 0) && !pcie_xilinx_link_up(pcie))
67 return -ENODEV;
68
69
70
71
72
73 if ((bus < 2) && (dev > 0))
74 return -ENODEV;
75
76 addr = pcie->cfg_base;
77 addr += bus << 20;
78 addr += dev << 15;
79 addr += func << 12;
80 addr += offset;
81 *paddress = addr;
82
83 return 0;
84}
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100static int pcie_xilinx_read_config(struct udevice *bus, pci_dev_t bdf,
101 uint offset, ulong *valuep,
102 enum pci_size_t size)
103{
104 return pci_generic_mmap_read_config(bus, pcie_xilinx_config_address,
105 bdf, offset, valuep, size);
106}
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122static int pcie_xilinx_write_config(struct udevice *bus, pci_dev_t bdf,
123 uint offset, ulong value,
124 enum pci_size_t size)
125{
126 return pci_generic_mmap_write_config(bus, pcie_xilinx_config_address,
127 bdf, offset, value, size);
128}
129
130
131
132
133
134
135
136
137
138
139
140static int pcie_xilinx_ofdata_to_platdata(struct udevice *dev)
141{
142 struct xilinx_pcie *pcie = dev_get_priv(dev);
143 struct fdt_resource reg_res;
144 DECLARE_GLOBAL_DATA_PTR;
145 int err;
146
147 err = fdt_get_resource(gd->fdt_blob, dev_of_offset(dev), "reg",
148 0, ®_res);
149 if (err < 0) {
150 pr_err("\"reg\" resource not found\n");
151 return err;
152 }
153
154 pcie->cfg_base = map_physmem(reg_res.start,
155 fdt_resource_size(®_res),
156 MAP_NOCACHE);
157
158 return 0;
159}
160
161static const struct dm_pci_ops pcie_xilinx_ops = {
162 .read_config = pcie_xilinx_read_config,
163 .write_config = pcie_xilinx_write_config,
164};
165
166static const struct udevice_id pcie_xilinx_ids[] = {
167 { .compatible = "xlnx,axi-pcie-host-1.00.a" },
168 { }
169};
170
171U_BOOT_DRIVER(pcie_xilinx) = {
172 .name = "pcie_xilinx",
173 .id = UCLASS_PCI,
174 .of_match = pcie_xilinx_ids,
175 .ops = &pcie_xilinx_ops,
176 .ofdata_to_platdata = pcie_xilinx_ofdata_to_platdata,
177 .priv_auto_alloc_size = sizeof(struct xilinx_pcie),
178};
179