amd-iommu: get_highest_supported_ivhd_type question

From: Bui Quang Minh
Date: Mon May 15 2023 - 10:36:21 EST


Hello everyone,

Since this commit 8c7142f56fedfc6824b5bca56fee1f443e01746b (iommu/amd: Use the most comprehensive IVHD type that the driver can support), amd_iommu driver can support IVHD type 0x11 and 0x40 beside old type 0x10. This commit introduces a new function to determine the appropriate IVHD type

/**
* get_highest_supported_ivhd_type - Look up the appropriate IVHD type
* @ivrs Pointer to the IVRS header
*
* This function search through all IVDB of the maximum supported IVHD
*/
static u8 get_highest_supported_ivhd_type(struct acpi_table_header *ivrs)
{
u8 *base = (u8 *)ivrs;
struct ivhd_header *ivhd = (struct ivhd_header *)
(base + IVRS_HEADER_LENGTH);
u8 last_type = ivhd->type;
u16 devid = ivhd->devid;

while (((u8 *)ivhd - base < ivrs->length) &&
(ivhd->type <= ACPI_IVHD_TYPE_MAX_SUPPORTED)) {
u8 *p = (u8 *) ivhd;

if (ivhd->devid == devid)
last_type = ivhd->type;
ivhd = (struct ivhd_header *)(p + ivhd->length);
}

return last_type;
}

As the name and comment suggest, the driver is intended to use the highest IVHD type provided in ACPI table. However, looking at the implementation, I see that it chooses to use the last IVHD type of the first devid appears in the ACPI table. Are there any reasons behind this implementation?

Thank you,
Quang Minh.