public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Vijayenthiran Subramaniam" <vijayenthiran.subramaniam@arm.com>
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 v2 2/5] Platform/ARM/SgiPkg: Use lookup table to install ACPI table
Date: Wed, 12 Feb 2020 18:59:24 +0530	[thread overview]
Message-ID: <1581514167-1340-3-git-send-email-vijayenthiran.subramaniam@arm.com> (raw)
In-Reply-To: <1581514167-1340-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 <vijayenthiran.subramaniam@arm.com>
---
 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..4ab0dd768cd1 100644
--- a/Platform/ARM/SgiPkg/Drivers/PlatformDxe/PlatformDxe.c
+++ b/Platform/ARM/SgiPkg/Drivers/PlatformDxe/PlatformDxe.c
@@ -11,6 +11,35 @@
 #include <Library/HobLib.h>
 #include <SgiPlatform.h>
 
+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;
+  UINT8                   i;
   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 (i = 0; i < ARRAY_SIZE (AcpiTableGuidLookup); i++) {
+    if ((PartNum == AcpiTableGuidLookup[i].SgiPlafromDescriptor.PlatformId) &&
+        (ConfigId == AcpiTableGuidLookup[i].SgiPlafromDescriptor.ConfigId)) {
+      Status = LocateAndInstallAcpiFromFv (AcpiTableGuidLookup[i].AcpiTableGuid);
+      break;
+    }
   }
 
   if (EFI_ERROR (Status)) {
-- 
2.7.4


  parent reply	other threads:[~2020-02-12 13:29 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-12 13:29 [edk2-platforms] [PATCH v2 0/5] Platform/ARM/SgiPkg: Add support for RD-N1-Edge-Dual platform Vijayenthiran Subramaniam
2020-02-12 13:29 ` [edk2-platforms] [PATCH v2 1/5] Platform/ARM/SgiPkg: Disable use of deprecated APIs Vijayenthiran Subramaniam
2020-02-13 16:56   ` Leif Lindholm
2020-02-12 13:29 ` Vijayenthiran Subramaniam [this message]
2020-02-13 17:14   ` [edk2-platforms] [PATCH v2 2/5] Platform/ARM/SgiPkg: Use lookup table to install ACPI table Leif Lindholm
2020-02-12 13:29 ` [edk2-platforms] [PATCH v2 3/5] Platform/ARM/SgiPkg: Add MultiChipMode to Platform Descriptor Vijayenthiran Subramaniam
2020-02-13 17:16   ` Leif Lindholm
2020-02-12 13:29 ` [edk2-platforms] [PATCH v2 4/5] Platform/ARM/Sgi: Add ACPI tables for dual-chip RD-N1-Edge platform Vijayenthiran Subramaniam
2020-02-13 17:22   ` Leif Lindholm
2020-02-12 13:29 ` [edk2-platforms] [PATCH v2 5/5] Platform/ARM/Sgi: Add initial support for RD-N1-Edge-Dual platform Vijayenthiran Subramaniam
2020-02-13 17:23   ` Leif Lindholm
2020-02-13 17:31 ` [edk2-platforms] [PATCH v2 0/5] Platform/ARM/SgiPkg: Add " Leif Lindholm
2020-02-14 13:52   ` [edk2-devel] " Vijayenthiran Subramaniam

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1581514167-1340-3-git-send-email-vijayenthiran.subramaniam@arm.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox