mb/google/brya/var/orisa: Update Type C DisplayPort HPD Configuration
[coreboot2.git] / src / soc / intel / xeon_sp / chip_common.c
blobd819a064b2040565583a78acbbad83826d782d92
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
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>
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.
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.
22 * @return Pointer to the device struct. When there are multiple device
23 * instances, the caller should continue search upon a non-NULL match.
25 struct device *dev_find_all_devices_on_socket(uint8_t socket, u16 vendor, u16 device,
26 struct device *from)
28 return dev_find_all_devices_on_stack(socket, XEONSP_STACK_MAX, vendor, device, from);
32 * Find device of a given vendor and type for the specified socket.
33 * The function will return at the 1st match.
35 struct device *dev_find_device_on_socket(uint8_t socket, u16 vendor, u16 device)
37 return dev_find_all_devices_on_socket(socket, vendor, device, NULL);
40 static int filter_device_on_stack(struct device *dev, uint8_t socket, uint8_t stack,
41 u16 vendor, u16 device)
43 if (dev->path.type != DEVICE_PATH_PCI)
44 return 0;
46 const struct device *domain = dev_get_domain(dev);
47 if (!domain)
48 return 0;
50 union xeon_domain_path dn;
51 dn.domain_path = dev_get_domain_id(domain);
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;
62 return 1;
65 /**
66 * Find all device of a given vendor and type for the specified socket and stack.
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.
78 * @return Pointer to the device struct. When there are multiple device
79 * instances, the caller should continue search upon a non-NULL match.
81 struct device *dev_find_all_devices_on_stack(uint8_t socket, uint8_t stack,
82 u16 vendor, u16 device, struct device *from)
84 if (!from)
85 from = all_devices;
86 else
87 from = from->next;
89 while (from && (!filter_device_on_stack(from, socket, stack,
90 vendor, device)))
91 from = from->next;
93 return from;
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
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.
107 * @return Pointer to the device struct. When there are multiple device
108 * instances, the caller should continue search upon a non-NULL match.
110 struct device *dev_find_all_devices_on_domain(struct device *domain, u16 vendor,
111 u16 device, struct device *from)
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;
122 return dev;
126 * Returns the socket ID where the specified device is connected to.
127 * This is an integer in the range [0, CONFIG_MAX_SOCKET).
129 * @param dev The device to look up
131 * @return Socket ID the device is attached to, negative number on error.
133 int iio_pci_domain_socket_from_dev(const struct device *dev)
135 const struct device *domain;
136 union xeon_domain_path dn;
138 domain = dev_get_domain(dev);
139 if (!domain)
140 return -1;
142 dn.domain_path = dev_get_domain_id(domain);
144 return dn.socket;
148 * Returns the stack ID where the specified device is connected to.
149 * This is an integer in the range [0, MAX_IIO_STACK).
151 * @param dev The device to look up
153 * @return Stack ID the device is attached to, negative number on error.
155 int iio_pci_domain_stack_from_dev(const struct device *dev)
157 const struct device *domain;
158 union xeon_domain_path dn;
160 domain = dev_get_domain(dev);
161 if (!domain)
162 return -1;
164 dn.domain_path = dev_get_domain_id(domain);
166 return dn.stack;
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)
174 struct device_path path;
175 init_xeon_domain_path(&path, dp.socket, dp.stack, bus_base);
177 struct device *const domain = alloc_find_dev(upstream, &path);
178 if (!domain)
179 die("%s: out of memory.\n", __func__);
181 domain->ops = ops;
182 iio_domain_set_acpi_name(domain, type);
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;
191 /* Attach stack as domains */
192 void attach_iio_stacks(void)
194 const IIO_UDS *hob = get_iio_uds();
195 union xeon_domain_path dn = { .domain_path = 0 };
196 if (!hob)
197 return;
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;
207 if (ri->BusBase > ri->BusLimit)
208 continue;
210 /* Prepare domain path */
211 dn.socket = s;
212 dn.stack = x;
214 create_xeonsp_domains(dn, root_bus, ri, seg);
219 bool is_pcie_domain(const struct device *dev)
221 if ((!dev) || (dev->path.type != DEVICE_PATH_DOMAIN))
222 return false;
224 return strstr(dev->name, DOMAIN_TYPE_PCIE);
227 bool is_ioat_domain(const struct device *dev)
229 if ((!dev) || (dev->path.type != DEVICE_PATH_DOMAIN))
230 return false;
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));
239 bool is_ubox_domain(const struct device *dev)
241 if ((!dev) || (dev->path.type != DEVICE_PATH_DOMAIN))
242 return false;
244 return (strstr(dev->name, DOMAIN_TYPE_UBX0) ||
245 strstr(dev->name, DOMAIN_TYPE_UBX1));
248 bool is_cxl_domain(const struct device *dev)
250 if ((!dev) || (dev->path.type != DEVICE_PATH_DOMAIN))
251 return false;
253 return strstr(dev->name, DOMAIN_TYPE_CXL);