Skip to content

Commit 655a69c

Browse files
committed
fix(PCIe): iterate and validate all EA capability entries
Enhanced Allocation capability structures may contain multiple entries per function. Previously, only a single entry was checked, which could miss other enabled entries. - Resolves: ARM-software/sbsa-acs#563 - Reads the number of EA entries from the capability header - Iterates over all entries using their encoded sizes - Checks the enable bit in each EA entry individually - Adds supporting macros for EA entry size, count, and DWORD access Signed-off-by: Srikar Josyula <srikar.josyula@arm.com>
1 parent 8baac16 commit 655a69c

2 files changed

Lines changed: 42 additions & 11 deletions

File tree

test_pool/pcie/p087.c

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ payload(void)
3939
uint32_t test_skip = 1;
4040
uint32_t cap_base;
4141
uint32_t status;
42+
uint32_t entry, num_entries;
43+
uint32_t entry_size;
44+
uint32_t entry_type_offset;
4245
pcie_device_bdf_table *bdf_tbl_ptr;
4346

4447
pe_index = val_pe_get_index_mpid(val_pe_get_mpid());
@@ -64,21 +67,44 @@ payload(void)
6467
test_skip = 0;
6568

6669
/* Retrieve the addr of Enhanced Allocation capability (14h) and check if the
67-
* capability structure is not supported.
68-
*/
70+
* capability structure is not supported. */
6971
status = val_pcie_find_capability(bdf, PCIE_CAP, CID_EA, &cap_base);
7072
if (status == PCIE_CAP_NOT_FOUND)
7173
continue;
7274

73-
/* Read Entry type register(08h) present in Enhanced Allocation capability struct(10h) */
74-
val_pcie_read_cfg(bdf, cap_base + EA_ENTRY_TYPE_OFFSET, &reg_value);
75+
/* Read number of entries in the EA Cap structure */
76+
val_pcie_read_cfg(bdf, cap_base, &reg_value);
77+
num_entries = (reg_value >> EA_NUM_ENTRY_SHIFT) & EA_NUM_ENTRY_MASK;
7578

76-
/* Extract enable value */
77-
enable_value = (reg_value >> EA_ENTRY_TYPE_ENABLE_SHIFT) & EA_ENTRY_TYPE_ENABLE_MASK;
78-
if (enable_value)
79-
{
80-
val_print(ACS_PRINT_ERR, "\n Failed. BDF 0x%x Supports Enhanced Allocation", bdf);
81-
test_fails++;
79+
/* Move to next bdf if the EA Cap structure has no entries */
80+
if (!num_entries)
81+
continue;
82+
83+
/* First DW of the structure is common across all entires */
84+
entry_type_offset = PCIE_DWORD_SIZE;
85+
86+
/* Type 1 functions implement additional DW after the fist DW - Bus Numbers register */
87+
if (val_pcie_function_header_type(bdf) == TYPE1_HEADER)
88+
entry_type_offset += PCIE_DWORD_SIZE;
89+
90+
for (entry = 0; entry < num_entries; entry++) {
91+
val_print(ACS_PRINT_DEBUG, "\n Reading entry at offset %llx", entry_type_offset);
92+
93+
/* Read Entry type register present in Enhanced Allocation capability struct(14h) */
94+
val_pcie_read_cfg(bdf, cap_base + entry_type_offset, &reg_value);
95+
96+
/* Extract enable value */
97+
enable_value = (reg_value >> EA_ENTRY_TYPE_ENABLE_SHIFT) & EA_ENTRY_TYPE_ENABLE_MASK;
98+
if (enable_value)
99+
{
100+
val_print(ACS_PRINT_ERR, "\n Enhanced Allocation enabled for BDF 0x%x", bdf);
101+
test_fails++;
102+
}
103+
104+
entry_size = (reg_value & EA_ENTRY_TYPE_SIZE_MASK);
105+
106+
/* Skip Base and Max registers and move to next entry */
107+
entry_type_offset += ((entry_size + 1) * PCIE_DWORD_SIZE);
82108
}
83109
}
84110

val/include/acs_pcie_spec.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,9 @@
260260
#define AER_ERROR_MASK 0xFFFFFFFF
261261

262262
/* EA Capability struct offsets */
263-
#define EA_ENTRY_TYPE_OFFSET 8
263+
#define EA_NUM_ENTRY_SHIFT 16
264+
#define EA_NUM_ENTRY_MASK 0x3F
265+
#define EA_ENTRY_TYPE_SIZE_MASK 0x7
264266
#define EA_ENTRY_TYPE_ENABLE_SHIFT 31
265267
#define EA_ENTRY_TYPE_ENABLE_MASK 1
266268

@@ -373,6 +375,9 @@
373375
#define PCIE_PCI (1 << 0b0111)
374376
#define PCIe_ALL (iEP_RP | iEP_EP | RP | EP | RCEC | RCiEP)
375377

378+
/* PCIe DWord definition */
379+
#define PCIE_DWORD_SIZE 0x04
380+
376381
/* MSI-X Capabilities */
377382
#define MSI_X_ENABLE_SHIFT 31
378383

0 commit comments

Comments
 (0)