Debian Codegraph @

src/soc/intel/xeon_sp/chip_common.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 #include <acpi/acpigen_pci.h>
4 #include <console/console.h>
5 #include <device/pci.h>
6 #include <intelblocks/acpi.h>
7 #include <soc/acpi.h>
8 #include <soc/chip_common.h>
9 #include <soc/soc_util.h>
10 #include <soc/util.h>
11
12 /**
13 * Find all device of a given vendor and type for the specified socket.
14 * The function iterates over all PCI domains of the specified socket
15 * and matches the PCI vendor and device ID.
16 *
17 * @param socket The socket where to search for the device.
18 * @param vendor A PCI vendor ID (e.g. 0x8086 for Intel).
19 * @param device A PCI device ID.
20 * @param from The device pointer to start search from.
21 *
22 * @return Pointer to the device struct. When there are multiple device
23 * instances, the caller should continue search upon a non-NULL match.
24 */
25 struct device *dev_find_all_devices_on_socket(uint8_t socket, u16 vendor, u16 device,
26 struct device *from)
27 {
28 return dev_find_all_devices_on_stack(socket, XEONSP_STACK_MAX, vendor, device, from);
29 }
30
31 /*
32 * Find device of a given vendor and type for the specified socket.
33 * The function will return at the 1st match.
34 */
35 struct device *dev_find_device_on_socket(uint8_t socket, u16 vendor, u16 device)
36 {
37 return dev_find_all_devices_on_socket(socket, vendor, device, NULL);
38 }
39
40 static int filter_device_on_stack(struct device *dev, uint8_t socket, uint8_t stack,
41 u16 vendor, u16 device)
42 {
43 if (dev->path.type != DEVICE_PATH_PCI)
44 return 0;
45
46 const struct device *domain = dev_get_domain(dev);
47 if (!domain)
48 return 0;
49
50 union xeon_domain_path dn;
51 dn.domain_path = dev_get_domain_id(domain);
52
53 if (socket != XEONSP_SOCKET_MAX && dn.socket != socket)
54 return 0;
55 if (stack != XEONSP_STACK_MAX && dn.stack != stack)
56 return 0;
57 if (vendor != XEONSP_VENDOR_MAX && dev->vendor != vendor)
58 return 0;
59 if (device != XEONSP_DEVICE_MAX && dev->device != device)
60 return 0;
61
62 return 1;
63 };
64
65 /**
66 * Find all device of a given vendor and type for the specified socket and stack.
67 *
68 * @param socket The socket where to search for the device.
69 * XEONSP_SOCKET_MAX indicates any socket.
70 * @param stack The stack where to search for the device.
71 * XEONSP_STACK_MAX indicates any stack.
72 * @param vendor A PCI vendor ID (e.g. 0x8086 for Intel).
73 * XEONSP_VENDOR_MAX indicates any vendor.
74 * @param device A PCI device ID.
75 * XEONSP_DEVICE_MAX indicates any device.
76 * @param from The device pointer to start search from.
77 *
78 * @return Pointer to the device struct. When there are multiple device
79 * instances, the caller should continue search upon a non-NULL match.
80 */
81 struct device *dev_find_all_devices_on_stack(uint8_t socket, uint8_t stack,
82 u16 vendor, u16 device, struct device *from)
83 {
84 if (!from)
85 from = all_devices;
86 else
87 from = from->next;
88
89 while (from && (!filter_device_on_stack(from, socket, stack,
90 vendor, device)))
91 from = from->next;
92
93 return from;
94 }
95
96 /**
97 * Find all device of a given vendor and type for the specific domain
98 * Only the direct child of the input domain is iterated
99 *
100 * @param domain Pointer to the input domain
101 * @param vendor A PCI vendor ID
102 * XEONSP_VENDOR_MAX indicates any vendor
103 * @param vendor A PCI device ID
104 * XEONSP_DEVICE_MAX indicates any vendor
105 * @param from The device pointer to start search from.
106 *
107 * @return Pointer to the device struct. When there are multiple device
108 * instances, the caller should continue search upon a non-NULL match.
109 */
110 struct device *dev_find_all_devices_on_domain(struct device *domain, u16 vendor,
111 u16 device, struct device *from)
112 {
113 struct device *dev = from;
114 while ((dev = dev_bus_each_child(domain->downstream, dev))) {
115 if (vendor != XEONSP_VENDOR_MAX && dev->vendor != vendor)
116 continue;
117 if (device != XEONSP_DEVICE_MAX && dev->device != device)
118 continue;
119 break;
120 }
121
122 return dev;
123 }
124
125 /**
126 * Returns the socket ID where the specified device is connected to.
127 * This is an integer in the range [0, CONFIG_MAX_SOCKET).
128 *
129 * @param dev The device to look up
130 *
131 * @return Socket ID the device is attached to, negative number on error.
132 */
133 int iio_pci_domain_socket_from_dev(const struct device *dev)
134 {
135 const struct device *domain;
136 union xeon_domain_path dn;
137
138 domain = dev_get_domain(dev);
139 if (!domain)
140 return -1;
141
142 dn.domain_path = dev_get_domain_id(domain);
143
144 return dn.socket;
145 }
146
147 /**
148 * Returns the stack ID where the specified device is connected to.
149 * This is an integer in the range [0, MAX_IIO_STACK).
150 *
151 * @param dev The device to look up
152 *
153 * @return Stack ID the device is attached to, negative number on error.
154 */
155 int iio_pci_domain_stack_from_dev(const struct device *dev)
156 {
157 const struct device *domain;
158 union xeon_domain_path dn;
159
160 domain = dev_get_domain(dev);
161 if (!domain)
162 return -1;
163
164 dn.domain_path = dev_get_domain_id(domain);
165
166 return dn.stack;
167 }
168
169 void create_domain(const union xeon_domain_path dp, struct bus *upstream,
170 int bus_base, int bus_limit, const char *type,
171 struct device_operations *ops,
172 const size_t pci_segment_group)
173 {
174 struct device_path path;
175 init_xeon_domain_path(&path, dp.socket, dp.stack, bus_base);
176
177 struct device *const domain = alloc_find_dev(upstream, &path);
178 if (!domain)
179 die("%s: out of memory.\n", __func__);
180
181 domain->ops = ops;
182 iio_domain_set_acpi_name(domain, type);
183
184 struct bus *const bus = alloc_bus(domain);
185 bus->secondary = bus_base;
186 bus->subordinate = bus_base;
187 bus->max_subordinate = bus_limit;
188 bus->segment_group = pci_segment_group;
189 }
190
191 /* Attach stack as domains */
192 void attach_iio_stacks(void)
193 {
194 const IIO_UDS *hob = get_iio_uds();
195 union xeon_domain_path dn = { .domain_path = 0 };
196 if (!hob)
197 return;
198
199 struct bus *root_bus = dev_root.downstream;
200 for (int s = 0; s < CONFIG_MAX_SOCKET; ++s) {
201 if (!soc_cpu_is_enabled(s))
202 continue;
203 for (int x = 0; x < MAX_LOGIC_IIO_STACK; ++x) {
204 const xSTACK_RES *ri = &hob->PlatformData.IIO_resource[s].StackRes[x];
205 const size_t seg = hob->PlatformData.CpuQpiInfo[s].PcieSegment;
206
207 if (ri->BusBase > ri->BusLimit)
208 continue;
209
210 /* Prepare domain path */
211 dn.socket = s;
212 dn.stack = x;
213
214 create_xeonsp_domains(dn, root_bus, ri, seg);
215 }
216 }
217 }
218
219 bool is_pcie_domain(const struct device *dev)
220 {
221 if ((!dev) || (dev->path.type != DEVICE_PATH_DOMAIN))
222 return false;
223
224 return strstr(dev->name, DOMAIN_TYPE_PCIE);
225 }
226
227 bool is_ioat_domain(const struct device *dev)
228 {
229 if ((!dev) || (dev->path.type != DEVICE_PATH_DOMAIN))
230 return false;
231
232 return (strstr(dev->name, DOMAIN_TYPE_CPM0) ||
233 strstr(dev->name, DOMAIN_TYPE_CPM1) ||
234 strstr(dev->name, DOMAIN_TYPE_DINO) ||
235 strstr(dev->name, DOMAIN_TYPE_HQM0) ||
236 strstr(dev->name, DOMAIN_TYPE_HQM1));
237 }
238
239 bool is_ubox_domain(const struct device *dev)
240 {
241 if ((!dev) || (dev->path.type != DEVICE_PATH_DOMAIN))
242 return false;
243
244 return (strstr(dev->name, DOMAIN_TYPE_UBX0) ||
245 strstr(dev->name, DOMAIN_TYPE_UBX1));
246 }
247
248 bool is_cxl_domain(const struct device *dev)
249 {
250 if ((!dev) || (dev->path.type != DEVICE_PATH_DOMAIN))
251 return false;
252
253 return strstr(dev->name, DOMAIN_TYPE_CXL);
254 }