From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by mx.groups.io with SMTP id smtpd.web12.6376.1581687704774824058 for ; Fri, 14 Feb 2020 05:41:44 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: arm.com, ip: 217.140.110.172, mailfrom: vijayenthiran.subramaniam@arm.com) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 0B0BD1FB; Fri, 14 Feb 2020 05:41:44 -0800 (PST) Received: from usa.arm.com (a074939-lin.blr.arm.com [10.162.16.42]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPA id 2F1653F68F; Fri, 14 Feb 2020 05:41:41 -0800 (PST) From: "Vijayenthiran Subramaniam" To: devel@edk2.groups.io, leif@nuviainc.com, michael.d.kinney@intel.com, Ard.Biesheuvel@arm.com Cc: thomas.abraham@arm.com Subject: [edk2-platforms] [PATCH v3 2/5] Platform/ARM/SgiPkg: Use lookup table to install ACPI table Date: Fri, 14 Feb 2020 19:11:31 +0530 Message-Id: <1581687694-12752-3-git-send-email-vijayenthiran.subramaniam@arm.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1581687694-12752-1-git-send-email-vijayenthiran.subramaniam@arm.com> References: <1581687694-12752-1-git-send-email-vijayenthiran.subramaniam@arm.com> Use lookup table to identify the platform and install corresponding ACPI tables. As the number of supported platforms grow, the existing platform identification using if..else does not scale well. Signed-off-by: Vijayenthiran Subramaniam --- Platform/ARM/SgiPkg/Drivers/PlatformDxe/PlatformDxe.c | 49 ++++++++++++++++---- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/Platform/ARM/SgiPkg/Drivers/PlatformDxe/PlatformDxe.c b/Platform/ARM/SgiPkg/Drivers/PlatformDxe/PlatformDxe.c index 09e00e5d538b..db66fd1fb1cc 100644 --- a/Platform/ARM/SgiPkg/Drivers/PlatformDxe/PlatformDxe.c +++ b/Platform/ARM/SgiPkg/Drivers/PlatformDxe/PlatformDxe.c @@ -11,6 +11,35 @@ #include #include +typedef struct { + SGI_PLATFORM_DESCRIPTOR SgiPlafromDescriptor; + CONST EFI_GUID* AcpiTableGuid; +} SGI_PLATFORM_ACPI_TABLE_GUID_LOOKUP; + +// Macro to construct the SGI_PLATFORM_ACPI_TABLE_GUID_LOOKUP structure +#define ACPI_GUID_LOOKUP(PART_NUM, CONFIG_NUM, GUID) \ +{ \ + { \ + PART_NUM, CONFIG_NUM \ + }, \ + GUID \ +} \ + +STATIC SGI_PLATFORM_ACPI_TABLE_GUID_LOOKUP AcpiTableGuidLookup[] = { + ACPI_GUID_LOOKUP ( + SGI575_PART_NUM, + SGI575_CONF_NUM, + &gSgi575AcpiTablesFileGuid), + ACPI_GUID_LOOKUP ( + RD_N1E1_EDGE_PART_NUM, + RD_N1_EDGE_CONF_ID, + &gRdN1EdgeAcpiTablesFileGuid), + ACPI_GUID_LOOKUP ( + RD_N1E1_EDGE_PART_NUM, + RD_E1_EDGE_CONF_ID, + &gRdE1EdgeAcpiTablesFileGuid), +}; + VOID InitVirtioDevices ( VOID @@ -26,6 +55,7 @@ ArmSgiPkgEntryPoint ( EFI_STATUS Status; VOID *SystemIdHob; SGI_PLATFORM_DESCRIPTOR *HobData; + UINTN Idx; UINT32 ConfigId; UINT32 PartNum; @@ -40,16 +70,15 @@ ArmSgiPkgEntryPoint ( PartNum = HobData->PlatformId; ConfigId = HobData->ConfigId; - if ((PartNum == SGI575_PART_NUM) && (ConfigId == SGI575_CONF_NUM)) { - Status = LocateAndInstallAcpiFromFv (&gSgi575AcpiTablesFileGuid); - } else if ((PartNum == RD_N1E1_EDGE_PART_NUM) && - (ConfigId == RD_N1_EDGE_CONF_ID)) { - Status = LocateAndInstallAcpiFromFv (&gRdN1EdgeAcpiTablesFileGuid); - } else if ((PartNum == RD_N1E1_EDGE_PART_NUM) && - (ConfigId == RD_E1_EDGE_CONF_ID)) { - Status = LocateAndInstallAcpiFromFv (&gRdE1EdgeAcpiTablesFileGuid); - } else { - Status = EFI_UNSUPPORTED; + Status = EFI_UNSUPPORTED; + + // Walk through the AcpiTableGuidLookup lookup array + for (Idx = 0; Idx < ARRAY_SIZE (AcpiTableGuidLookup); Idx++) { + if ((PartNum == AcpiTableGuidLookup[Idx].SgiPlafromDescriptor.PlatformId) && + (ConfigId == AcpiTableGuidLookup[Idx].SgiPlafromDescriptor.ConfigId)) { + Status = LocateAndInstallAcpiFromFv (AcpiTableGuidLookup[Idx].AcpiTableGuid); + break; + } } if (EFI_ERROR (Status)) { -- 2.7.4