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