blob: 5f8c97f1a3c7cc972d5e01af07d8b1ab9c8f9286 [file] [log] [blame]
AlexeiFedorov9f0dc012024-09-10 10:22:06 +01001/*
2 * Copyright (c) 2024, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <assert.h>
AlexeiFedorov9f2de632024-09-10 11:48:22 +01008#include <stddef.h>
9
AlexeiFedorov9f0dc012024-09-10 10:22:06 +010010#include <debug.h>
11#include <mmio.h>
AlexeiFedorov9f0dc012024-09-10 10:22:06 +010012#include <pcie.h>
13#include <pcie_spec.h>
Soby Mathew2c2810f2024-11-15 17:11:24 +000014#include <platform.h>
AlexeiFedorov9f0dc012024-09-10 10:22:06 +010015#include <tftf_lib.h>
16
AlexeiFedorov9f0dc012024-09-10 10:22:06 +010017#define PCIE_DEBUG VERBOSE
18
Soby Mathew2c2810f2024-11-15 17:11:24 +000019const struct pcie_info_table *g_pcie_info_table;
AlexeiFedorov9f0dc012024-09-10 10:22:06 +010020pcie_device_bdf_table_t *g_pcie_bdf_table;
21
22pcie_device_bdf_table_t pcie_bdf_table[PCIE_DEVICE_BDF_TABLE_SZ];
23
24uintptr_t pcie_cfg_addr(uint32_t bdf)
25{
26 uint32_t bus = PCIE_EXTRACT_BDF_BUS(bdf);
27 uint32_t dev = PCIE_EXTRACT_BDF_DEV(bdf);
28 uint32_t func = PCIE_EXTRACT_BDF_FUNC(bdf);
29 uint32_t segment = PCIE_EXTRACT_BDF_SEG(bdf);
30 uint32_t cfg_addr;
31 uintptr_t ecam_base = 0;
32 unsigned int i = 0;
33
34 assert((bus < PCIE_MAX_BUS) && (dev < PCIE_MAX_DEV) && (func < PCIE_MAX_FUNC));
35 assert(g_pcie_info_table != NULL);
36
37 while (i < g_pcie_info_table->num_entries) {
38 /* Derive ECAM specific information */
39 const pcie_info_block_t *block = &g_pcie_info_table->block[i];
40
41 if ((bus >= block->start_bus_num) &&
42 (bus <= block->end_bus_num) &&
43 (segment == block->segment_num)) {
44 ecam_base = block->ecam_base;
45 break;
46 }
47 i++;
48 }
49
50 assert(ecam_base != 0);
51
52 /*
53 * There are 8 functions / device
54 * 32 devices / Bus and each has a 4KB config space
55 */
56 cfg_addr = (bus * PCIE_MAX_DEV * PCIE_MAX_FUNC * PCIE_CFG_SIZE) +
57 (dev * PCIE_MAX_FUNC * PCIE_CFG_SIZE) + (func * PCIE_CFG_SIZE);
58
59 return ecam_base + cfg_addr;
60}
61
62/*
63 * @brief This API reads 32-bit data from PCIe config space pointed by Bus,
64 * Device, Function and register offset.
65 * 1. Caller - Test Suite
66 * 2. Prerequisite - pcie_create_info_table
67 * @param bdf - concatenated Bus(8-bits), device(8-bits) & function(8-bits)
68 * @param offset - Register offset within a device PCIe config space
69 *
70 * @return 32-bit data read from the config space
71 */
72uint32_t pcie_read_cfg(uint32_t bdf, uint32_t offset)
73{
74 uintptr_t addr = pcie_cfg_addr(bdf);
75
76 return mmio_read_32(addr + offset);
77}
78
79/*
80 * @brief This API writes 32-bit data to PCIe config space pointed by Bus,
81 * Device, Function and register offset.
82 * 1. Caller - Test Suite
83 * 2. Prerequisite - val_pcie_create_info_table
84 * @param bdf - concatenated Bus(8-bits), device(8-bits) & function(8-bits)
85 * @param offset - Register offset within a device PCIe config space
86 * @param data - data to be written to the config space
87 *
88 * @return None
89 */
90void pcie_write_cfg(uint32_t bdf, uint32_t offset, uint32_t data)
91{
92 uintptr_t addr = pcie_cfg_addr(bdf);
93
94 mmio_write_32(addr + offset, data);
95}
96
97/*
98 * @brief Check if BDF is PCIe Host Bridge.
99 *
100 * @param bdf - Function's Segment/Bus/Dev/Func in PCIE_CREATE_BDF format
101 * @return false If not a Host Bridge, true If it's a Host Bridge.
102 */
103bool pcie_is_host_bridge(uint32_t bdf)
104{
105 uint32_t reg_value = pcie_read_cfg(bdf, TYPE01_RIDR);
106
107 if ((HB_BASE_CLASS == ((reg_value >> CC_BASE_SHIFT) & CC_BASE_MASK)) &&
108 (HB_SUB_CLASS == ((reg_value >> CC_SUB_SHIFT) & CC_SUB_MASK))) {
109 return true;
110 }
111
112 return false;
113}
114
115/*
116 * @brief Find a Function's config capability offset matching it's input parameter
117 * cid. cid_offset set to the matching cpability offset w.r.t. zero.
118 *
119 * @param bdf - Segment/Bus/Dev/Func in the format of PCIE_CREATE_BDF
120 * @param cid - Capability ID
121 * @param cid_offset - On return, points to cid offset in Function config space
122 * @return PCIE_CAP_NOT_FOUND, if there was a failure in finding required capability.
123 * PCIE_SUCCESS, if the search was successful.
124 */
125uint32_t pcie_find_capability(uint32_t bdf, uint32_t cid_type, uint32_t cid,
126 uint32_t *cid_offset)
127{
128 uint32_t reg_value, next_cap_offset;
129
130 if (cid_type == PCIE_CAP) {
131 /* Search in PCIe configuration space */
132 reg_value = pcie_read_cfg(bdf, TYPE01_CPR);
133
134 next_cap_offset = (reg_value & TYPE01_CPR_MASK);
135 while (next_cap_offset != 0) {
136 reg_value = pcie_read_cfg(bdf, next_cap_offset);
137 if ((reg_value & PCIE_CIDR_MASK) == cid) {
138 *cid_offset = next_cap_offset;
139 return PCIE_SUCCESS;
140 }
141 next_cap_offset = ((reg_value >> PCIE_NCPR_SHIFT) &
142 PCIE_NCPR_MASK);
143 }
144 } else if (cid_type == PCIE_ECAP) {
145 /* Search in PCIe extended configuration space */
146 next_cap_offset = PCIE_ECAP_START;
147 while (next_cap_offset != 0) {
148 reg_value = pcie_read_cfg(bdf, next_cap_offset);
149 if ((reg_value & PCIE_ECAP_CIDR_MASK) == cid) {
150 *cid_offset = next_cap_offset;
151 return PCIE_SUCCESS;
152 }
153 next_cap_offset = ((reg_value >> PCIE_ECAP_NCPR_SHIFT) &
154 PCIE_ECAP_NCPR_MASK);
155 }
156 }
157
158 /* The capability was not found */
159 return PCIE_CAP_NOT_FOUND;
160}
161
162/*
163 * @brief This API is used as placeholder to check if the bdf
164 * obtained is valid or not
165 *
166 * @param bdf
167 * @return true if bdf is valid else false
168 */
169bool pcie_check_device_valid(uint32_t bdf)
170{
171 (void) bdf;
172 /*
173 * Add BDFs to this function if PCIe tests
174 * need to be ignored for a BDF for any reason
175 */
176 return true;
177}
178
179/*
180 * @brief Returns whether a PCIe Function is an on-chip peripheral or not
181 *
182 * @param bdf - Segment/Bus/Dev/Func in the format of PCIE_CREATE_BDF
183 * @return Returns TRUE if the Function is on-chip peripheral, FALSE if it is
184 * not an on-chip peripheral
185 */
186bool pcie_is_onchip_peripheral(uint32_t bdf)
187{
188 (void)bdf;
189 return false;
190}
191
192/*
193 * @brief Returns the type of pcie device or port for the given bdf
194 *
195 * @param bdf - Segment/Bus/Dev/Func in the format of PCIE_CREATE_BDF
196 * @return Returns (1 << 0b1001) for RCiEP, (1 << 0b1010) for RCEC,
197 * (1 << 0b0000) for EP, (1 << 0b0100) for RP,
198 * (1 << 0b1100) for iEP_EP, (1 << 0b1011) for iEP_RP,
199 * (1 << PCIECR[7:4]) for any other device type.
200 */
201uint32_t pcie_device_port_type(uint32_t bdf)
202{
203 uint32_t pciecs_base, reg_value, dp_type;
204
205 /*
206 * Get the PCI Express Capability structure offset and
207 * use that offset to read pci express capabilities register
208 */
209 pcie_find_capability(bdf, PCIE_CAP, CID_PCIECS, &pciecs_base);
210 reg_value = pcie_read_cfg(bdf, pciecs_base + CIDR_OFFSET);
211
212 /* Read Device/Port bits [7:4] in Function's PCIe Capabilities register */
213 dp_type = (reg_value >> ((PCIECR_OFFSET - CIDR_OFFSET)*8 +
214 PCIECR_DPT_SHIFT)) & PCIECR_DPT_MASK;
215 dp_type = (1 << dp_type);
216
217 /* Check if the device/port is an on-chip peripheral */
218 if (pcie_is_onchip_peripheral(bdf)) {
219 if (dp_type == EP) {
220 dp_type = iEP_EP;
221 } else if (dp_type == RP) {
222 dp_type = iEP_RP;
223 }
224 }
225
226 /* Return device/port type */
227 return dp_type;
228}
229
230/*
231 * @brief Returns BDF of the upstream Root Port of a pcie device function.
232 *
233 * @param bdf - Function's Segment/Bus/Dev/Func in PCIE_CREATE_BDF format
234 * @param usrp_bdf - Upstream Rootport bdf in PCIE_CREATE_BDF format
235 * @return 0 for success, 1 for failure.
236 */
237uint32_t pcie_get_rootport(uint32_t bdf, uint32_t *rp_bdf)
238{
239 uint32_t seg_num, sec_bus, sub_bus;
240 uint32_t reg_value, dp_type, index = 0;
241
242 dp_type = pcie_device_port_type(bdf);
243
244 PCIE_DEBUG("DP type 0x%x\n", dp_type);
245
246 /* If the device is RP or iEP_RP, set its rootport value to same */
247 if ((dp_type == RP) || (dp_type == iEP_RP)) {
248 *rp_bdf = bdf;
249 return 0;
250 }
251
252 /* If the device is RCiEP and RCEC, set RP as 0xff */
253 if ((dp_type == RCiEP) || (dp_type == RCEC)) {
254 *rp_bdf = 0xffffffff;
255 return 1;
256 }
257
Soby Mathew2c2810f2024-11-15 17:11:24 +0000258 assert(g_pcie_bdf_table != NULL);
259
AlexeiFedorov9f0dc012024-09-10 10:22:06 +0100260 while (index < g_pcie_bdf_table->num_entries) {
261 *rp_bdf = g_pcie_bdf_table->device[index++].bdf;
262
263 /*
264 * Extract Secondary and Subordinate Bus numbers of the
265 * upstream Root port and check if the input function's
266 * bus number falls within that range.
267 */
268 reg_value = pcie_read_cfg(*rp_bdf, TYPE1_PBN);
269 seg_num = PCIE_EXTRACT_BDF_SEG(*rp_bdf);
270 sec_bus = ((reg_value >> SECBN_SHIFT) & SECBN_MASK);
271 sub_bus = ((reg_value >> SUBBN_SHIFT) & SUBBN_MASK);
272 dp_type = pcie_device_port_type(*rp_bdf);
273
274 if (((dp_type == RP) || (dp_type == iEP_RP)) &&
275 (sec_bus <= PCIE_EXTRACT_BDF_BUS(bdf)) &&
276 (sub_bus >= PCIE_EXTRACT_BDF_BUS(bdf)) &&
277 (seg_num == PCIE_EXTRACT_BDF_SEG(bdf)))
278 return 0;
279 }
280
281 /* Return failure */
282 ERROR("PCIe Hierarchy fail: RP of bdf 0x%x not found\n", bdf);
283 *rp_bdf = 0;
284 return 1;
285}
286
287/*
288 * @brief Sanity checks that all Endpoints must have a Rootport
289 *
290 * @param None
291 * @return 0 if sanity check passes, 1 if sanity check fails
292 */
293static uint32_t pcie_populate_device_rootport(void)
294{
295 uint32_t bdf, rp_bdf;
296 pcie_device_bdf_table_t *bdf_tbl_ptr = g_pcie_bdf_table;
297
Soby Mathew2c2810f2024-11-15 17:11:24 +0000298 assert(bdf_tbl_ptr != NULL);
299
AlexeiFedorov9f0dc012024-09-10 10:22:06 +0100300 for (unsigned int tbl_index = 0; tbl_index < bdf_tbl_ptr->num_entries;
301 tbl_index++) {
302 bdf = bdf_tbl_ptr->device[tbl_index].bdf;
303
304 /* Checks if the BDF has RootPort */
305 pcie_get_rootport(bdf, &rp_bdf);
306
307 bdf_tbl_ptr->device[tbl_index].rp_bdf = rp_bdf;
308 PCIE_DEBUG("Dev bdf: 0x%x RP bdf: 0x%x\n", bdf, rp_bdf);
309 }
310
311 return 0;
312}
313
314/*
315 * @brief Returns the BDF Table pointer
316 *
317 * @param None
318 *
319 * @return BDF Table pointer
320 */
321pcie_device_bdf_table_t *pcie_get_bdf_table(void)
322{
Soby Mathew2c2810f2024-11-15 17:11:24 +0000323 assert(g_pcie_bdf_table != NULL);
324
AlexeiFedorov9f0dc012024-09-10 10:22:06 +0100325 return g_pcie_bdf_table;
326}
327
328/*
329 * @brief This API creates the device bdf table from enumeration
330 *
331 * @param None
332 *
333 * @return None
334 */
335void pcie_create_device_bdf_table(void)
336{
337 uint32_t seg_num, start_bus, end_bus;
338 uint32_t bus_index, dev_index, func_index, ecam_index;
339 uint32_t bdf, reg_value, cid_offset, status;
340
341 assert(g_pcie_bdf_table != NULL);
342
343 g_pcie_bdf_table->num_entries = 0;
Soby Mathew2c2810f2024-11-15 17:11:24 +0000344
345 assert(g_pcie_info_table != NULL);
AlexeiFedorov9f0dc012024-09-10 10:22:06 +0100346 assert(g_pcie_info_table->num_entries != 0);
347
348 for (ecam_index = 0; ecam_index < g_pcie_info_table->num_entries; ecam_index++) {
349 /* Derive ECAM specific information */
350 const pcie_info_block_t *block = &g_pcie_info_table->block[ecam_index];
351
352 seg_num = block->segment_num;
353 start_bus = block->start_bus_num;
354 end_bus = block->end_bus_num;
355
356 /* Iterate over all buses, devices and functions in this ecam */
357 for (bus_index = start_bus; bus_index <= end_bus; bus_index++) {
358 for (dev_index = 0; dev_index < PCIE_MAX_DEV; dev_index++) {
359 for (func_index = 0; func_index < PCIE_MAX_FUNC; func_index++) {
360 /* Form BDF using seg, bus, device, function numbers */
361 bdf = PCIE_CREATE_BDF(seg_num, bus_index, dev_index,
362 func_index);
363
364 /* Probe PCIe device Function with this BDF */
365 reg_value = pcie_read_cfg(bdf, TYPE01_VIDR);
366
367 /* Store the Function's BDF if there was a valid response */
368 if (reg_value != PCIE_UNKNOWN_RESPONSE) {
369 /* Skip if the device is a host bridge */
370 if (pcie_is_host_bridge(bdf)) {
371 continue;
372 }
373
374 /* Skip if the device is a PCI legacy device */
375 if (pcie_find_capability(bdf, PCIE_CAP,
376 CID_PCIECS, &cid_offset) != PCIE_SUCCESS) {
377 continue;
378 }
379
380 status = pcie_check_device_valid(bdf);
381 if (!status) {
382 continue;
383 }
384
385 g_pcie_bdf_table->device[
386 g_pcie_bdf_table->num_entries++].bdf = bdf;
387 }
388 }
389 }
390 }
391 }
392
393 /* Sanity Check : Confirm all EP (normal, integrated) have a rootport */
394 pcie_populate_device_rootport();
395 INFO("Number of BDFs found : %u\n", g_pcie_bdf_table->num_entries);
396}
397
398/*
399 * @brief Returns the header type of the input pcie device function
400 *
401 * @param bdf - Segment/Bus/Dev/Func in the format of PCIE_CREATE_BDF
402 * @return TYPE0_HEADER for functions with Type 0 config space header,
403 * TYPE1_HEADER for functions with Type 1 config space header,
404 */
405uint32_t pcie_function_header_type(uint32_t bdf)
406{
407 /* Read four bytes of config space starting from cache line size register */
408 uint32_t reg_value = pcie_read_cfg(bdf, TYPE01_CLSR);
409
410 /* Extract header type register value */
411 reg_value = ((reg_value >> TYPE01_HTR_SHIFT) & TYPE01_HTR_MASK);
412
413 /* Header layout bits within header type register indicate the header type */
414 return ((reg_value >> HTR_HL_SHIFT) & HTR_HL_MASK);
415}
416
417/*
418 * @brief Returns the ECAM address of the input PCIe function
419 *
420 * @param bdf - Segment/Bus/Dev/Func in PCIE_CREATE_BDF format
421 * @return ECAM address if success, else NULL address
422 */
423uintptr_t pcie_get_ecam_base(uint32_t bdf)
424{
425 uint8_t ecam_index = 0, sec_bus = 0, sub_bus;
426 uint16_t seg_num = (uint16_t)PCIE_EXTRACT_BDF_SEG(bdf);
427 uint32_t reg_value;
428 uintptr_t ecam_base = 0;
429
Soby Mathew2c2810f2024-11-15 17:11:24 +0000430 assert(g_pcie_info_table != NULL);
431
AlexeiFedorov9f0dc012024-09-10 10:22:06 +0100432 while (ecam_index < g_pcie_info_table->num_entries) {
433 /* Derive ECAM specific information */
434 const pcie_info_block_t *block = &g_pcie_info_table->block[ecam_index];
435
436 if (seg_num == block->segment_num) {
437 if (pcie_function_header_type(bdf) == TYPE0_HEADER) {
438 /* Return ecam_base if Type0 Header */
439 ecam_base = block->ecam_base;
440 break;
441 }
442
443 /* Check for Secondary/Subordinate bus if Type1 Header */
444 reg_value = pcie_read_cfg(bdf, TYPE1_PBN);
445 sec_bus = ((reg_value >> SECBN_SHIFT) & SECBN_MASK);
446 sub_bus = ((reg_value >> SUBBN_SHIFT) & SUBBN_MASK);
447
448 if ((sec_bus >= block->start_bus_num) &&
449 (sub_bus <= block->end_bus_num)) {
450 ecam_base = block->ecam_base;
451 break;
452 }
453 }
454 ecam_index++;
455 }
456
457 return ecam_base;
458}
459
460/*
461 * @brief This API prints all the PCIe Devices info
462 * 1. Caller - Validation layer.
463 * 2. Prerequisite - val_pcie_create_info_table()
464 * @param None
465 * @return None
466 */
467void pcie_print_device_info(void)
468{
469 uint32_t bdf, dp_type;
470 uint32_t tbl_index = 0;
471 uint32_t ecam_index = 0;
472 uint32_t ecam_base, ecam_start_bus, ecam_end_bus;
473 pcie_device_bdf_table_t *bdf_tbl_ptr = g_pcie_bdf_table;
Soby Mathew2c2810f2024-11-15 17:11:24 +0000474 uint32_t num_rciep __unused = 0, num_rcec __unused = 0;
475 uint32_t num_iep __unused = 0, num_irp __unused = 0;
476 uint32_t num_ep __unused = 0, num_rp __unused = 0;
477 uint32_t num_dp __unused = 0, num_up __unused = 0;
478 uint32_t num_pcie_pci __unused = 0, num_pci_pcie __unused = 0;
AlexeiFedorov9f0dc012024-09-10 10:22:06 +0100479 uint32_t bdf_counter;
480
Soby Mathew2c2810f2024-11-15 17:11:24 +0000481 assert(bdf_tbl_ptr != NULL);
482
AlexeiFedorov9f0dc012024-09-10 10:22:06 +0100483 if (bdf_tbl_ptr->num_entries == 0) {
484 INFO("BDF Table: No RCiEP or iEP found\n");
485 return;
486 }
487
488 for (tbl_index = 0; tbl_index < bdf_tbl_ptr->num_entries; tbl_index++) {
489 bdf = bdf_tbl_ptr->device[tbl_index].bdf;
490 dp_type = pcie_device_port_type(bdf);
491
492 switch (dp_type) {
493 case RCiEP:
494 num_rciep++;
495 break;
496 case RCEC:
497 num_rcec++;
498 break;
499 case EP:
500 num_ep++;
501 break;
502 case RP:
503 num_rp++;
504 break;
505 case iEP_EP:
506 num_iep++;
507 break;
508 case iEP_RP:
509 num_irp++;
510 break;
511 case UP:
512 num_up++;
513 break;
514 case DP:
515 num_dp++;
516 break;
517 case PCI_PCIE:
518 num_pci_pcie++;
519 break;
520 case PCIE_PCI:
521 num_pcie_pci++;
522 break;
523 default:
524 ERROR("Unknown dp_type 0x%x\n", dp_type);
525 }
526 }
527
528 INFO("Number of RCiEP : %u\n", num_rciep);
529 INFO("Number of RCEC : %u\n", num_rcec);
530 INFO("Number of EP : %u\n", num_ep);
531 INFO("Number of RP : %u\n", num_rp);
532 INFO("Number of iEP_EP : %u\n", num_iep);
533 INFO("Number of iEP_RP : %u\n", num_irp);
534 INFO("Number of UP of switch : %u\n", num_up);
535 INFO("Number of DP of switch : %u\n", num_dp);
536 INFO("Number of PCI/PCIe Bridge: %u\n", num_pci_pcie);
537 INFO("Number of PCIe/PCI Bridge: %u\n", num_pcie_pci);
538
Soby Mathew2c2810f2024-11-15 17:11:24 +0000539 assert(g_pcie_info_table != NULL);
540
AlexeiFedorov9f0dc012024-09-10 10:22:06 +0100541 while (ecam_index < g_pcie_info_table->num_entries) {
542
543 /* Derive ECAM specific information */
544 const pcie_info_block_t *block = &g_pcie_info_table->block[ecam_index];
545
546 ecam_base = block->ecam_base;
547 ecam_start_bus = block->start_bus_num;
548 ecam_end_bus = block->end_bus_num;
549 tbl_index = 0;
550 bdf_counter = 0;
551
552 INFO("ECAM %u: base 0x%x\n", ecam_index, ecam_base);
553
554 while (tbl_index < bdf_tbl_ptr->num_entries) {
555 uint32_t seg_num, bus_num, dev_num, func_num;
Soby Mathew2c2810f2024-11-15 17:11:24 +0000556 uint32_t device_id __unused, vendor_id __unused, reg_value;
AlexeiFedorov9f0dc012024-09-10 10:22:06 +0100557 uint32_t bdf, dev_ecam_base;
558
559 bdf = bdf_tbl_ptr->device[tbl_index++].bdf;
560 seg_num = PCIE_EXTRACT_BDF_SEG(bdf);
561 bus_num = PCIE_EXTRACT_BDF_BUS(bdf);
562 dev_num = PCIE_EXTRACT_BDF_DEV(bdf);
563 func_num = PCIE_EXTRACT_BDF_FUNC(bdf);
564
565 reg_value = pcie_read_cfg(bdf, TYPE01_VIDR);
566 device_id = (reg_value >> TYPE01_DIDR_SHIFT) & TYPE01_DIDR_MASK;
567 vendor_id = (reg_value >> TYPE01_VIDR_SHIFT) & TYPE01_VIDR_MASK;
568
569 dev_ecam_base = pcie_get_ecam_base(bdf);
570
571 if ((ecam_base == dev_ecam_base) &&
572 (bus_num >= ecam_start_bus) &&
573 (bus_num <= ecam_end_bus)) {
574 bdf_counter = 1;
575 bdf = PCIE_CREATE_BDF(seg_num, bus_num, dev_num, func_num);
576 INFO(" BDF: 0x%x\n", bdf);
577 INFO(" Seg: 0x%x Bus: 0x%x Dev: 0x%x "
578 "Func: 0x%x Dev ID: 0x%x Vendor ID: 0x%x\n",
579 seg_num, bus_num, dev_num, func_num,
580 device_id, vendor_id);
581 }
582 }
583
584 if (bdf_counter == 0) {
585 INFO(" No BDF devices in ECAM region index %d\n", ecam_index);
586 }
587
588 ecam_index++;
589 }
590}
591
592/*
593 * @brief Create PCIe table and PCI enumeration
594 * @param void
595 * @return void
596 */
597void pcie_create_info_table(void)
598{
599 unsigned int num_ecam;
600
601 INFO("Creating PCIe info table\n");
602
603 g_pcie_info_table = plat_pcie_get_info_table();
Soby Mathew2c2810f2024-11-15 17:11:24 +0000604 if (g_pcie_info_table == NULL) {
605 ERROR("PCIe info not returned by platform\n");
606 panic();
607 }
608
AlexeiFedorov9f0dc012024-09-10 10:22:06 +0100609 g_pcie_bdf_table = pcie_bdf_table;
610
611 num_ecam = g_pcie_info_table->num_entries;
612 INFO("Number of ECAM regions : %u\n", num_ecam);
Soby Mathew2c2810f2024-11-15 17:11:24 +0000613 if ((num_ecam == 0) || (num_ecam > MAX_PCIE_INFO_ENTRIES)) {
614 ERROR("PCIe info entries invalid\n");
615 panic();
AlexeiFedorov9f0dc012024-09-10 10:22:06 +0100616 }
617 pcie_create_device_bdf_table();
618 pcie_print_device_info();
619}