public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH edk2-platforms 0/2] Silicon/Styx: merge and simplify ACPI platform driver
@ 2018-12-06 12:12 Ard Biesheuvel
  2018-12-06 12:12 ` [PATCH edk2-platforms 1/2] Silicon/AMD/Styx: merge ACPI table drivers Ard Biesheuvel
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Ard Biesheuvel @ 2018-12-06 12:12 UTC (permalink / raw)
  To: edk2-devel; +Cc: leif.lindholm, alan, graeme.gregory, Ard Biesheuvel

After fixing the iasl issue yesterday, I got a bit carried away and ended
up rewriting most of the ACPI table generation logic for Styx. So this
applies on top of the patches I sent out yesterday.

Patch #1 merges the DXE driver and the library, that are split in two for
no good reason.

Patch #2 simplifies the MADT generation code.

Ard Biesheuvel (2):
  Silicon/AMD/Styx: merge ACPI table drivers
  Silicon/Styx/AcpiPlatformDxe: simplify MADT generation logic

 .../AMD/OverdriveBoard/OverdriveBoard.dsc     |   1 -
 Platform/LeMaker/CelloBoard/CelloBoard.dsc    |   1 -
 .../Overdrive1000Board/Overdrive1000Board.dsc |   1 -
 .../AMD/OverdriveBoard/OverdriveBoard.fdf     |   1 +
 Platform/LeMaker/CelloBoard/CelloBoard.fdf    |   1 +
 .../Overdrive1000Board/Overdrive1000Board.fdf |   1 +
 Silicon/AMD/Styx/AcpiTables/AcpiTables.inf    |  85 -----
 .../AcpiPlatformDxe/AcpiPlatformDxe.inf       |  34 +-
 .../AcpiPlatformDxe/AcpiPlatform.h}           |  11 +-
 Silicon/AMD/Styx/AcpiTables/Madt.c            | 318 ------------------
 .../Drivers/AcpiPlatformDxe/AcpiPlatform.c    | 155 +++++----
 .../AcpiPlatformDxe/Csrt.aslc}                |  13 +-
 .../AcpiPlatformDxe/Dbg2.aslc}                |  12 +-
 .../AcpiPlatformDxe/Fadt.aslc}                |  11 +-
 .../AcpiPlatformDxe/Gtdt.aslc}                |  20 +-
 .../AcpiPlatformDxe/Iort.aslc}                |  19 +-
 .../Styx/Drivers/AcpiPlatformDxe/Madt.aslc    | 117 +++++++
 .../AcpiPlatformDxe/Mcfg.aslc}                |  13 +-
 .../AcpiPlatformDxe/Pptt.aslc}                |  10 +-
 .../AcpiPlatformDxe/Spcr.aslc}                |  12 +-
 20 files changed, 264 insertions(+), 572 deletions(-)
 delete mode 100644 Silicon/AMD/Styx/AcpiTables/AcpiTables.inf
 rename Silicon/AMD/Styx/{Common/AmdStyxAcpiLib.h => Drivers/AcpiPlatformDxe/AcpiPlatform.h} (81%)
 delete mode 100644 Silicon/AMD/Styx/AcpiTables/Madt.c
 rename Silicon/AMD/Styx/{AcpiTables/Csrt.c => Drivers/AcpiPlatformDxe/Csrt.aslc} (93%)
 rename Silicon/AMD/Styx/{AcpiTables/Dbg2.c => Drivers/AcpiPlatformDxe/Dbg2.aslc} (95%)
 rename Silicon/AMD/Styx/{AcpiTables/Fadt.c => Drivers/AcpiPlatformDxe/Fadt.aslc} (96%)
 rename Silicon/AMD/Styx/{AcpiTables/Gtdt.c => Drivers/AcpiPlatformDxe/Gtdt.aslc} (92%)
 rename Silicon/AMD/Styx/{AcpiTables/Iort.c => Drivers/AcpiPlatformDxe/Iort.aslc} (95%)
 create mode 100644 Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Madt.aslc
 rename Silicon/AMD/Styx/{AcpiTables/Mcfg.c => Drivers/AcpiPlatformDxe/Mcfg.aslc} (86%)
 rename Silicon/AMD/Styx/{AcpiTables/Pptt.c => Drivers/AcpiPlatformDxe/Pptt.aslc} (97%)
 rename Silicon/AMD/Styx/{AcpiTables/Spcr.c => Drivers/AcpiPlatformDxe/Spcr.aslc} (90%)

-- 
2.19.2



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH edk2-platforms 1/2] Silicon/AMD/Styx: merge ACPI table drivers
  2018-12-06 12:12 [PATCH edk2-platforms 0/2] Silicon/Styx: merge and simplify ACPI platform driver Ard Biesheuvel
@ 2018-12-06 12:12 ` Ard Biesheuvel
  2018-12-06 12:12 ` [PATCH edk2-platforms 2/2] Silicon/Styx/AcpiPlatformDxe: simplify MADT generation logic Ard Biesheuvel
  2018-12-10 22:20 ` [PATCH edk2-platforms 0/2] Silicon/Styx: merge and simplify ACPI platform driver Leif Lindholm
  2 siblings, 0 replies; 5+ messages in thread
From: Ard Biesheuvel @ 2018-12-06 12:12 UTC (permalink / raw)
  To: edk2-devel; +Cc: leif.lindholm, alan, graeme.gregory, Ard Biesheuvel

ACPI table support on Seattle is split into two parts for no good
reason: AcpiPlatformDxe and AmdStyxAcpiLib. Let's merge them
together, and clean up the code that iterates over the tables and
installs them.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 Platform/AMD/OverdriveBoard/OverdriveBoard.dsc                                       |   1 -
 Platform/LeMaker/CelloBoard/CelloBoard.dsc                                           |   1 -
 Platform/SoftIron/Overdrive1000Board/Overdrive1000Board.dsc                          |   1 -
 Platform/AMD/OverdriveBoard/OverdriveBoard.fdf                                       |   1 +
 Platform/LeMaker/CelloBoard/CelloBoard.fdf                                           |   1 +
 Platform/SoftIron/Overdrive1000Board/Overdrive1000Board.fdf                          |   1 +
 Silicon/AMD/Styx/AcpiTables/AcpiTables.inf                                           |  85 --------------
 Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf                         |  31 +++++-
 Silicon/AMD/Styx/{Common/AmdStyxAcpiLib.h => Drivers/AcpiPlatformDxe/AcpiPlatform.h} |   9 --
 Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatform.c                              | 117 +++++++++-----------
 Silicon/AMD/Styx/{AcpiTables => Drivers/AcpiPlatformDxe}/Madt.c                      |   3 +-
 Silicon/AMD/Styx/{AcpiTables/Csrt.c => Drivers/AcpiPlatformDxe/Csrt.aslc}            |  13 +--
 Silicon/AMD/Styx/{AcpiTables/Dbg2.c => Drivers/AcpiPlatformDxe/Dbg2.aslc}            |  12 +-
 Silicon/AMD/Styx/{AcpiTables/Fadt.c => Drivers/AcpiPlatformDxe/Fadt.aslc}            |  11 +-
 Silicon/AMD/Styx/{AcpiTables/Gtdt.c => Drivers/AcpiPlatformDxe/Gtdt.aslc}            |  20 +---
 Silicon/AMD/Styx/{AcpiTables/Iort.c => Drivers/AcpiPlatformDxe/Iort.aslc}            |  19 +---
 Silicon/AMD/Styx/{AcpiTables/Mcfg.c => Drivers/AcpiPlatformDxe/Mcfg.aslc}            |  13 +--
 Silicon/AMD/Styx/{AcpiTables/Pptt.c => Drivers/AcpiPlatformDxe/Pptt.aslc}            |  10 +-
 Silicon/AMD/Styx/{AcpiTables/Spcr.c => Drivers/AcpiPlatformDxe/Spcr.aslc}            |  12 +-
 19 files changed, 108 insertions(+), 253 deletions(-)

diff --git a/Platform/AMD/OverdriveBoard/OverdriveBoard.dsc b/Platform/AMD/OverdriveBoard/OverdriveBoard.dsc
index 2843e51f93f7..87731357e2eb 100644
--- a/Platform/AMD/OverdriveBoard/OverdriveBoard.dsc
+++ b/Platform/AMD/OverdriveBoard/OverdriveBoard.dsc
@@ -121,7 +121,6 @@ DEFINE DO_CAPSULE   = FALSE
   # Styx specific libraries
   #
   AmdSataInit|Silicon/AMD/Styx/AmdModulePkg/Library/AmdSataInitLib/AmdSataInitLib.inf
-  AmdStyxAcpiLib|Silicon/AMD/Styx/AcpiTables/AcpiTables.inf
   ResetSystemLib|ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.inf
   RealTimeClockLib|Silicon/AMD/Styx/Library/RealTimeClockLib/RealTimeClockLib.inf
 
diff --git a/Platform/LeMaker/CelloBoard/CelloBoard.dsc b/Platform/LeMaker/CelloBoard/CelloBoard.dsc
index 057bf0eb67de..29e740695366 100644
--- a/Platform/LeMaker/CelloBoard/CelloBoard.dsc
+++ b/Platform/LeMaker/CelloBoard/CelloBoard.dsc
@@ -118,7 +118,6 @@ DEFINE DO_FLASHER   = FALSE
   # Styx specific libraries
   #
   AmdSataInit|Silicon/AMD/Styx/AmdModulePkg/Library/AmdSataInitLib/AmdSataInitLib.inf
-  AmdStyxAcpiLib|Silicon/AMD/Styx/AcpiTables/AcpiTables.inf
   ResetSystemLib|ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.inf
   RealTimeClockLib|Silicon/AMD/Styx/Library/RealTimeClockLib/RealTimeClockLib.inf
 
diff --git a/Platform/SoftIron/Overdrive1000Board/Overdrive1000Board.dsc b/Platform/SoftIron/Overdrive1000Board/Overdrive1000Board.dsc
index 985ba2253a90..f342cf82d251 100644
--- a/Platform/SoftIron/Overdrive1000Board/Overdrive1000Board.dsc
+++ b/Platform/SoftIron/Overdrive1000Board/Overdrive1000Board.dsc
@@ -117,7 +117,6 @@ DEFINE DO_FLASHER   = FALSE
   # Styx specific libraries
   #
   AmdSataInit|Silicon/AMD/Styx/AmdModulePkg/Library/AmdSataInitLib/AmdSataInitLib.inf
-  AmdStyxAcpiLib|Silicon/AMD/Styx/AcpiTables/AcpiTables.inf
   ResetSystemLib|ArmPkg/Library/ArmSmcPsciResetSystemLib/ArmSmcPsciResetSystemLib.inf
   RealTimeClockLib|Silicon/AMD/Styx/Library/RealTimeClockLib/RealTimeClockLib.inf
 
diff --git a/Platform/AMD/OverdriveBoard/OverdriveBoard.fdf b/Platform/AMD/OverdriveBoard/OverdriveBoard.fdf
index 96df83e0da5a..c7e27e20ad4a 100644
--- a/Platform/AMD/OverdriveBoard/OverdriveBoard.fdf
+++ b/Platform/AMD/OverdriveBoard/OverdriveBoard.fdf
@@ -454,6 +454,7 @@ CAPSULE_HEADER_INIT_VERSION = 0x1
     PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi
     UI           STRING="$(MODULE_NAME)" Optional
     RAW          ASL                    Optional    |.aml
+    RAW          ACPI                   Optional    |.acpi
   }
 
 [Rule.Common.DXE_RUNTIME_DRIVER]
diff --git a/Platform/LeMaker/CelloBoard/CelloBoard.fdf b/Platform/LeMaker/CelloBoard/CelloBoard.fdf
index fc977f14b5a1..6362257deb8c 100644
--- a/Platform/LeMaker/CelloBoard/CelloBoard.fdf
+++ b/Platform/LeMaker/CelloBoard/CelloBoard.fdf
@@ -365,6 +365,7 @@ READ_LOCK_STATUS   = TRUE
     PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi
     UI           STRING="$(MODULE_NAME)" Optional
     RAW          ASL                    Optional    |.aml
+    RAW          ACPI                   Optional    |.acpi
   }
 
 [Rule.Common.DXE_RUNTIME_DRIVER]
diff --git a/Platform/SoftIron/Overdrive1000Board/Overdrive1000Board.fdf b/Platform/SoftIron/Overdrive1000Board/Overdrive1000Board.fdf
index 8fc9a979aebc..9ba98dd83767 100644
--- a/Platform/SoftIron/Overdrive1000Board/Overdrive1000Board.fdf
+++ b/Platform/SoftIron/Overdrive1000Board/Overdrive1000Board.fdf
@@ -367,6 +367,7 @@ READ_LOCK_STATUS   = TRUE
     PE32         PE32                   $(INF_OUTPUT)/$(MODULE_NAME).efi
     UI           STRING="$(MODULE_NAME)" Optional
     RAW          ASL                    Optional    |.aml
+    RAW          ACPI                   Optional    |.acpi
   }
 
 [Rule.Common.DXE_RUNTIME_DRIVER]
diff --git a/Silicon/AMD/Styx/AcpiTables/AcpiTables.inf b/Silicon/AMD/Styx/AcpiTables/AcpiTables.inf
deleted file mode 100644
index 0bc5b1e98964..000000000000
--- a/Silicon/AMD/Styx/AcpiTables/AcpiTables.inf
+++ /dev/null
@@ -1,85 +0,0 @@
-#/** @file
-#  Sample ACPI Platform Driver
-#
-#  Copyright (c) 2008 - 2014, Intel Corporation. All rights reserved.<BR>
-#  Copyright (c) 2014 - 2016, AMD Inc. All rights reserved.<BR>
-#
-#  This program and the accompanying materials
-#  are licensed and made available under the terms and conditions of the BSD License
-#  which accompanies this distribution.  The full text of the license may be found at
-#  http://opensource.org/licenses/bsd-license.php
-#
-#  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-#  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-#
-#**/
-#/**
-#
-#  Derived from:
-#   MdeModulePkg/Universal/Acpi/AcpiPlatformDxe/AcpiPlatformDxe.inf
-#
-#**/
-
-[Defines]
-  INF_VERSION                    = 0x00010005
-  BASE_NAME                      = AmdStyxAcpiLib
-  FILE_GUID                      = 74850e9e-371c-43af-b1fe-794d61505ad0
-  MODULE_TYPE                    = BASE
-  VERSION_STRING                 = 1.0
-  LIBRARY_CLASS                  = AmdStyxAcpiLib
-
-[Sources]
-  Gtdt.c
-  Fadt.c
-  Dbg2.c
-  Spcr.c
-  Madt.c
-  Mcfg.c
-  Csrt.c
-  Iort.c
-  Pptt.c
-
-[Packages]
-  ArmPkg/ArmPkg.dec
-  MdePkg/MdePkg.dec
-  MdeModulePkg/MdeModulePkg.dec
-  Silicon/AMD/Styx/AmdModulePkg/AmdModulePkg.dec
-  Silicon/AMD/Styx/AmdStyx.dec
-
-[LibraryClasses]
-  PcdLib
-  DebugLib
-  UefiBootServicesTableLib
-
-[Protocols]
-  gAmdMpCoreInfoProtocolGuid         ## CONSUMED
-
-[Pcd]
-  gAmdStyxTokenSpaceGuid.PcdSocCoreCount
-  gAmdStyxTokenSpaceGuid.PcdSocCpuId
-
-[FixedPcd]
-  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase
-  gArmTokenSpaceGuid.PcdGicDistributorBase
-  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase
-  gAmdStyxTokenSpaceGuid.PcdSerialDbgRegisterBase
-  gAmdStyxTokenSpaceGuid.PcdGicVersion
-  gAmdStyxTokenSpaceGuid.PcdGicHypervisorInterruptInterfaceBase
-  gAmdStyxTokenSpaceGuid.PcdGicVirtualInterruptInterfaceBase
-  gAmdStyxTokenSpaceGuid.PcdGicVirtualMaintenanceInterrupt
-  gAmdStyxTokenSpaceGuid.PcdGicVirtualRegisterInterfaceBase
-  gAmdStyxTokenSpaceGuid.PcdGicMSIFrameBase
-  gAmdStyxTokenSpaceGuid.PcdCntControlBase
-  gAmdStyxTokenSpaceGuid.PcdCntReadBase
-  gAmdStyxTokenSpaceGuid.PcdCntCTLBase
-  gAmdStyxTokenSpaceGuid.PcdCntBase0
-  gAmdStyxTokenSpaceGuid.PcdCntEL0Base0
-  gAmdStyxTokenSpaceGuid.PcdSbsaWatchDogRefreshBase
-  gAmdStyxTokenSpaceGuid.PcdSbsaWatchDogControlBase
-  gAmdStyxTokenSpaceGuid.PcdSbsaWakeUpGSIV
-  gAmdStyxTokenSpaceGuid.PcdSbsaWatchDogGSIV
-  gAmdStyxTokenSpaceGuid.PcdSocCoresPerCluster
-  gAmdStyxTokenSpaceGuid.PcdSata1PortCount
-
-[Depex]
-  gAmdMpCoreInfoProtocolGuid
diff --git a/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
index 92f185fa4bee..95745db00ff3 100644
--- a/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
+++ b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
@@ -28,7 +28,16 @@
 
 [Sources]
   AcpiPlatform.c
+  Csrt.aslc
+  Dbg2.aslc
   Dsdt.asl
+  Fadt.aslc
+  Gtdt.aslc
+  Iort.aslc
+  Madt.c
+  Mcfg.aslc
+  Pptt.aslc
+  Spcr.aslc
   SsdtB1.asl
   SsdtXgbe.asl
 
@@ -40,7 +49,6 @@
   Silicon/AMD/Styx/AmdStyx.dec
 
 [LibraryClasses]
-  AmdStyxAcpiLib
   BaseLib
   BaseMemoryLib
   DebugLib
@@ -54,12 +62,33 @@
   gAmdStyxTokenSpaceGuid.PcdEthMacA
   gAmdStyxTokenSpaceGuid.PcdEthMacB
   gAmdStyxTokenSpaceGuid.PcdEnableSmmus
+  gAmdStyxTokenSpaceGuid.PcdSocCoreCount
   gAmdStyxTokenSpaceGuid.PcdSocCpuId
 
 [FixedPcd]
+  gAmdStyxTokenSpaceGuid.PcdCntControlBase
+  gAmdStyxTokenSpaceGuid.PcdCntReadBase
+  gAmdStyxTokenSpaceGuid.PcdCntCTLBase
+  gAmdStyxTokenSpaceGuid.PcdCntBase0
+  gAmdStyxTokenSpaceGuid.PcdCntEL0Base0
+  gAmdStyxTokenSpaceGuid.PcdGicVersion
+  gAmdStyxTokenSpaceGuid.PcdGicHypervisorInterruptInterfaceBase
+  gAmdStyxTokenSpaceGuid.PcdGicVirtualInterruptInterfaceBase
+  gAmdStyxTokenSpaceGuid.PcdGicVirtualMaintenanceInterrupt
+  gAmdStyxTokenSpaceGuid.PcdGicVirtualRegisterInterfaceBase
+  gAmdStyxTokenSpaceGuid.PcdGicMSIFrameBase
   gAmdStyxTokenSpaceGuid.PcdSata1PortCount
+  gAmdStyxTokenSpaceGuid.PcdSbsaWatchDogRefreshBase
+  gAmdStyxTokenSpaceGuid.PcdSbsaWatchDogControlBase
+  gAmdStyxTokenSpaceGuid.PcdSbsaWakeUpGSIV
+  gAmdStyxTokenSpaceGuid.PcdSbsaWatchDogGSIV
+  gAmdStyxTokenSpaceGuid.PcdSerialDbgRegisterBase
+  gArmTokenSpaceGuid.PcdGicInterruptInterfaceBase
+  gArmTokenSpaceGuid.PcdGicDistributorBase
+  gEfiMdeModulePkgTokenSpaceGuid.PcdSerialRegisterBase
 
 [Protocols]
+  gAmdMpCoreInfoProtocolGuid                    ## CONSUMED
   gEfiAcpiTableProtocolGuid                     ## ALWAYS_CONSUMED
 
 [Depex]
diff --git a/Silicon/AMD/Styx/Common/AmdStyxAcpiLib.h b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatform.h
similarity index 83%
rename from Silicon/AMD/Styx/Common/AmdStyxAcpiLib.h
rename to Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatform.h
index 0dfd7635e897..b1864131795a 100644
--- a/Silicon/AMD/Styx/Common/AmdStyxAcpiLib.h
+++ b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatform.h
@@ -18,16 +18,7 @@
 
 #include <IndustryStandard/Acpi.h>
 
-EFI_ACPI_DESCRIPTION_HEADER *FadtTable (void);
-EFI_ACPI_DESCRIPTION_HEADER *FacsTable (void);
 EFI_ACPI_DESCRIPTION_HEADER *MadtHeader (void);
-EFI_ACPI_DESCRIPTION_HEADER *GtdtHeader (void);
-EFI_ACPI_DESCRIPTION_HEADER *McfgHeader (void);
-EFI_ACPI_DESCRIPTION_HEADER *Dbg2Header (void);
-EFI_ACPI_DESCRIPTION_HEADER *SpcrHeader (void);
-EFI_ACPI_DESCRIPTION_HEADER *CsrtHeader (void);
-EFI_ACPI_DESCRIPTION_HEADER *IortHeader (void);
-EFI_ACPI_DESCRIPTION_HEADER *PpttHeader (void);
 
 #define EFI_ACPI_AMD_OEM_ID_ARRAY        {'A','M','D','I','N','C'}
 #define EFI_ACPI_AMD_OEM_TABLE_ID        SIGNATURE_64('S','E','A','T','T','L','E',' ')
diff --git a/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatform.c b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatform.c
index a00bd3bd2215..ff1326982329 100644
--- a/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatform.c
+++ b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatform.c
@@ -19,7 +19,6 @@
    MdeModulePkg/Universal/Acpi/AcpiPlatformDxe/AcpiPlatform.c
 **/
 
-#include <AmdStyxAcpiLib.h>
 #include <Protocol/AcpiTable.h>
 
 #include <Library/BaseLib.h>
@@ -31,12 +30,11 @@
 #include <Library/UefiBootServicesTableLib.h>
 
 #include <IndustryStandard/Acpi61.h>
+#include <IndustryStandard/IoRemappingTable.h>
 
 #include <SocVersion.h>
 
-#define MAX_ACPI_TABLES    16
-
-EFI_ACPI_DESCRIPTION_HEADER *AcpiTableList[MAX_ACPI_TABLES];
+#include "AcpiPlatform.h"
 
 STATIC EFI_ACPI_TABLE_PROTOCOL   *mAcpiTableProtocol;
 
@@ -97,16 +95,20 @@ InstallSystemDescriptionTables (
   VOID
   )
 {
-  EFI_ACPI_DESCRIPTION_HEADER   *Table;
-  EFI_STATUS                    Status;
-  UINT32                        CpuId;
-  UINTN                         Index;
-  UINTN                         TableSize;
-  UINTN                         TableHandle;
+  EFI_ACPI_DESCRIPTION_HEADER                   *Table;
+  EFI_STATUS                                    Status;
+  UINT32                                        CpuId;
+  UINTN                                         Index;
+  UINTN                                         TableSize;
+  UINTN                                         TableHandle;
+  EFI_ACPI_5_1_GENERIC_TIMER_DESCRIPTION_TABLE  *Gtdt;
+  EFI_ACPI_6_0_IO_REMAPPING_TABLE               *Iort;
 #if DO_XGBE
   UINT8                         MacPackage[sizeof(mDefaultMacPackageA)];
 #endif
 
+  CpuId = PcdGet32 (PcdSocCpuId);
+
   Status = EFI_SUCCESS;
   for (Index = 0; !EFI_ERROR (Status); Index++) {
     Status = GetSectionFromFv (&gEfiCallerIdGuid, EFI_SECTION_RAW, Index,
@@ -117,7 +119,6 @@ InstallSystemDescriptionTables (
 
     switch (Table->OemTableId) {
     case SIGNATURE_64 ('S', 't', 'y', 'x', 'B', '1', ' ', ' '):
-      CpuId = PcdGet32 (PcdSocCpuId);
       if ((CpuId & STYX_SOC_VERSION_MASK) < STYX_SOC_VERSION_B1) {
         continue;
       }
@@ -141,11 +142,39 @@ InstallSystemDescriptionTables (
       break;
 #endif
       continue;
+
+    default:
+      switch (Table->Signature) {
+      case EFI_ACPI_6_0_IO_REMAPPING_TABLE_SIGNATURE:
+        if (!PcdGetBool (PcdEnableSmmus)) {
+          continue;
+        }
+        if ((CpuId & STYX_SOC_VERSION_MASK) < STYX_SOC_VERSION_B1) {
+          Iort = (EFI_ACPI_6_0_IO_REMAPPING_TABLE *)Table;
+          Iort->NumNodes -= 2;
+        }
+        break;
+
+      case EFI_ACPI_5_1_GENERIC_TIMER_DESCRIPTION_TABLE_SIGNATURE:
+        if ((CpuId & STYX_SOC_VERSION_MASK) < STYX_SOC_VERSION_B1) {
+          Gtdt = (EFI_ACPI_5_1_GENERIC_TIMER_DESCRIPTION_TABLE *)Table;
+          Gtdt->Header.Length = sizeof (*Gtdt);
+          Gtdt->PlatformTimerCount = 0;
+          Gtdt->PlatformTimerOffset = 0;
+        }
+        break;
+      }
     }
 
     Status = mAcpiTableProtocol->InstallAcpiTable (mAcpiTableProtocol, Table,
-                                   TableSize, &TableHandle);
-    ASSERT_EFI_ERROR (Status);
+                                   Table->Length, &TableHandle);
+
+    DEBUG ((DEBUG_WARN,
+      "Installing %c%c%c%c Table (Revision %d, Length %d) ... %r\n",
+      ((UINT8 *)&Table->Signature)[0], ((UINT8 *)&Table->Signature)[1],
+      ((UINT8 *)&Table->Signature)[2], ((UINT8 *)&Table->Signature)[3],
+      Table->Revision, Table->Length, Status));
+
     FreePool (Table);
   }
 }
@@ -168,67 +197,23 @@ AcpiPlatformEntryPoint (
   IN EFI_SYSTEM_TABLE   *SystemTable
   )
 {
-  EFI_STATUS                Status;
-  UINTN                     TableHandle;
-  UINTN                     TableIndex;
-
-  ZeroMem(AcpiTableList, sizeof(AcpiTableList));
-
-  TableIndex = 0;
-  AcpiTableList[TableIndex++] = FadtTable();
-  AcpiTableList[TableIndex++] = MadtHeader();
-  AcpiTableList[TableIndex++] = GtdtHeader();
-  AcpiTableList[TableIndex++] = Dbg2Header();
-  AcpiTableList[TableIndex++] = SpcrHeader();
-  AcpiTableList[TableIndex++] = McfgHeader();
-  AcpiTableList[TableIndex++] = CsrtHeader();
-  if (PcdGetBool (PcdEnableSmmus)) {
-    AcpiTableList[TableIndex++] = IortHeader();
-  }
-  AcpiTableList[TableIndex++] = PpttHeader();
-  AcpiTableList[TableIndex++] = NULL;
-
-  DEBUG((DEBUG_INFO, "%a(): ACPI Table installer\n", __FUNCTION__));
+  EFI_STATUS                  Status;
+  UINTN                       TableHandle;
+  EFI_ACPI_DESCRIPTION_HEADER *Header;
 
   //
   // Find the AcpiTable protocol
   //
   Status = gBS->LocateProtocol (&gEfiAcpiTableProtocolGuid, NULL,
                   (VOID**)&mAcpiTableProtocol);
-  if (EFI_ERROR (Status)) {
-    DEBUG((EFI_D_ERROR, "Failed to locate AcpiTable protocol. Status = %r\n", Status));
-    ASSERT_EFI_ERROR(Status);
-  }
+  ASSERT_EFI_ERROR (Status);
 
-  TableIndex = 0;
-  while (AcpiTableList[TableIndex] != NULL) {
-    //
-    // Install ACPI table
-    //
-    DEBUG ((EFI_D_ERROR, "Installing %c%c%c%c Table (Revision %d, Length %d) ...\n",
-                          *((UINT8*)&AcpiTableList[TableIndex]->Signature),
-                          *((UINT8*)&AcpiTableList[TableIndex]->Signature + 1),
-                          *((UINT8*)&AcpiTableList[TableIndex]->Signature + 2),
-                          *((UINT8*)&AcpiTableList[TableIndex]->Signature + 3),
-                          AcpiTableList[TableIndex]->Revision,
-                          AcpiTableList[TableIndex]->Length));
-
-    Status = mAcpiTableProtocol->InstallAcpiTable (
-                                   mAcpiTableProtocol,
-                                   AcpiTableList[TableIndex],
-                                   (AcpiTableList[TableIndex])->Length,
-                                   &TableHandle
-                                   );
-    if (EFI_ERROR (Status)) {
-      DEBUG((DEBUG_ERROR,"Error adding ACPI Table. Status = %r\n", Status));
-      ASSERT_EFI_ERROR(Status);
-    }
-    TableIndex++;
-    ASSERT( TableIndex < MAX_ACPI_TABLES );
-  }
+  Header = MadtHeader ();
+  Status = mAcpiTableProtocol->InstallAcpiTable (mAcpiTableProtocol, Header,
+                                 Header->Length, &TableHandle);
+  ASSERT_EFI_ERROR (Status);
 
   InstallSystemDescriptionTables ();
 
-  return EFI_SUCCESS;
+  return EFI_REQUEST_UNLOAD_IMAGE;
 }
-
diff --git a/Silicon/AMD/Styx/AcpiTables/Madt.c b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Madt.c
similarity index 97%
rename from Silicon/AMD/Styx/AcpiTables/Madt.c
rename to Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Madt.c
index 43d415c8bc32..b10ae7e1ab74 100644
--- a/Silicon/AMD/Styx/AcpiTables/Madt.c
+++ b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Madt.c
@@ -27,9 +27,10 @@
 #include <Library/UefiBootServicesTableLib.h>
 #include <Guid/ArmMpCoreInfo.h>
 
-#include <AmdStyxAcpiLib.h>
 #include <Protocol/AmdMpCoreInfo.h>
 
+#include "AcpiPlatform.h"
+
 AMD_MP_CORE_INFO_PROTOCOL  *mAmdMpCoreInfoProtocol = NULL;
 
 
diff --git a/Silicon/AMD/Styx/AcpiTables/Csrt.c b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Csrt.aslc
similarity index 93%
rename from Silicon/AMD/Styx/AcpiTables/Csrt.c
rename to Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Csrt.aslc
index f25f90da5314..4aca9320250b 100644
--- a/Silicon/AMD/Styx/AcpiTables/Csrt.c
+++ b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Csrt.aslc
@@ -16,7 +16,7 @@
 
 **/
 
-#include <AmdStyxAcpiLib.h>
+#include "AcpiPlatform.h"
 
 //
 // CSRT for ARM_CCN504 (L3 CACHE)
@@ -69,7 +69,7 @@ typedef struct {
 } AMD_ACPI_ARM_CCN504_CORE_SYSTEM_RESOURCE_TABLE;
 
 
-AMD_ACPI_ARM_CCN504_CORE_SYSTEM_RESOURCE_TABLE AcpiCsrt = {
+STATIC AMD_ACPI_ARM_CCN504_CORE_SYSTEM_RESOURCE_TABLE AcpiCsrt = {
    AMD_ACPI_HEADER (EFI_ACPI_5_1_CORE_SYSTEM_RESOURCE_TABLE_SIGNATURE,
                     AMD_ACPI_ARM_CCN504_CORE_SYSTEM_RESOURCE_TABLE,
                     AMD_ACPI_ARM_CCN504_CSRT_REVISION),
@@ -97,11 +97,4 @@ AMD_ACPI_ARM_CCN504_CORE_SYSTEM_RESOURCE_TABLE AcpiCsrt = {
 
 #pragma pack(pop)
 
-
-EFI_ACPI_DESCRIPTION_HEADER *
-CsrtHeader (
-  VOID
-  )
-{
-  return &AcpiCsrt.Header;
-}
+VOID* CONST ReferenceAcpiTable = &AcpiCsrt;
diff --git a/Silicon/AMD/Styx/AcpiTables/Dbg2.c b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Dbg2.aslc
similarity index 95%
rename from Silicon/AMD/Styx/AcpiTables/Dbg2.c
rename to Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Dbg2.aslc
index 5d6cf82dba5b..07635aa9dd8e 100644
--- a/Silicon/AMD/Styx/AcpiTables/Dbg2.c
+++ b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Dbg2.aslc
@@ -16,9 +16,10 @@
 
 **/
 
-#include <AmdStyxAcpiLib.h>
 #include <IndustryStandard/DebugPort2Table.h>
 
+#include "AcpiPlatform.h"
+
 #pragma pack(push, 1)
 
 #define EFI_ACPI_DBG2_REVISION                     0
@@ -104,11 +105,4 @@ STATIC DBG2_TABLE AcpiDbg2 = {
 
 #pragma pack(pop)
 
-EFI_ACPI_DESCRIPTION_HEADER *
-Dbg2Header (
-  VOID
-  )
-{
-  return &AcpiDbg2.Description.Header;
-}
-
+VOID* CONST ReferenceAcpiTable = &AcpiDbg2;
diff --git a/Silicon/AMD/Styx/AcpiTables/Fadt.c b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Fadt.aslc
similarity index 96%
rename from Silicon/AMD/Styx/AcpiTables/Fadt.c
rename to Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Fadt.aslc
index bdf88a9c8e32..35d190bdf685 100644
--- a/Silicon/AMD/Styx/AcpiTables/Fadt.c
+++ b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Fadt.aslc
@@ -21,7 +21,7 @@
 
 **/
 
-#include <AmdStyxAcpiLib.h>
+#include "AcpiPlatform.h"
 
 #define FADT_FLAGS          ( EFI_ACPI_5_1_HW_REDUCED_ACPI |           \
                               EFI_ACPI_5_1_LOW_POWER_S0_IDLE_CAPABLE | \
@@ -91,11 +91,4 @@ STATIC EFI_ACPI_5_1_FIXED_ACPI_DESCRIPTION_TABLE AcpiFadt = {
 
 #pragma pack(pop)
 
-EFI_ACPI_DESCRIPTION_HEADER *
-FadtTable (
-  VOID
-  )
-{
-  return (EFI_ACPI_DESCRIPTION_HEADER *) &AcpiFadt;
-}
-
+VOID* CONST ReferenceAcpiTable = &AcpiFadt;
diff --git a/Silicon/AMD/Styx/AcpiTables/Gtdt.c b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Gtdt.aslc
similarity index 92%
rename from Silicon/AMD/Styx/AcpiTables/Gtdt.c
rename to Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Gtdt.aslc
index 139c9ae0baad..34f92f2e4061 100644
--- a/Silicon/AMD/Styx/AcpiTables/Gtdt.c
+++ b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Gtdt.aslc
@@ -21,7 +21,7 @@
 
 **/
 
-#include <AmdStyxAcpiLib.h>
+#include "AcpiPlatform.h"
 
 #pragma pack(push, 1)
 
@@ -170,20 +170,4 @@ STATIC AMD_ACPI_5_1_ARM_GTDT_STRUCTURE AcpiGtdt = {
 
 #pragma pack(pop)
 
-
-EFI_ACPI_DESCRIPTION_HEADER *
-GtdtHeader (
-  VOID
-  )
-{
-  UINT32 CpuId = PcdGet32 (PcdSocCpuId);
-
-  // Check BaseModel and Stepping: Styx-B0 or prior?
-  if (((CpuId & 0xFF0) == 0) || ((CpuId & 0x00F) == 0)) {
-    AcpiGtdt.Gtdt.Header.Length = sizeof (EFI_ACPI_5_1_GENERIC_TIMER_DESCRIPTION_TABLE);
-    AcpiGtdt.Gtdt.PlatformTimerCount = 0;
-    AcpiGtdt.Gtdt.PlatformTimerOffset = 0;
-  }
-
-  return (EFI_ACPI_DESCRIPTION_HEADER *) &AcpiGtdt.Gtdt.Header;
-}
+VOID* CONST ReferenceAcpiTable = &AcpiGtdt;
diff --git a/Silicon/AMD/Styx/AcpiTables/Iort.c b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Iort.aslc
similarity index 95%
rename from Silicon/AMD/Styx/AcpiTables/Iort.c
rename to Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Iort.aslc
index 9c232379eff5..7723a4ddade3 100644
--- a/Silicon/AMD/Styx/AcpiTables/Iort.c
+++ b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Iort.aslc
@@ -12,9 +12,9 @@
 
 **/
 
-#include <AmdStyxAcpiLib.h>
 #include <IndustryStandard/IoRemappingTable.h>
-#include <SocVersion.h>
+
+#include "AcpiPlatform.h"
 
 #define FIELD_OFFSET(type, name)            __builtin_offsetof(type, name)
 
@@ -355,17 +355,4 @@ STATIC STYX_IO_REMAPPING_STRUCTURE AcpiIort = {
 
 #pragma pack()
 
-EFI_ACPI_DESCRIPTION_HEADER *
-IortHeader (
-  VOID
-  )
-{
-  if ((PcdGet32 (PcdSocCpuId) & STYX_SOC_VERSION_MASK) < STYX_SOC_VERSION_B1) {
-    //
-    // Silicon revisions prior to B1 have only one SATA port,
-    // so omit the nodes of the second port in this case.
-    //
-    AcpiIort.Iort.NumNodes -= 2;
-  }
-  return (EFI_ACPI_DESCRIPTION_HEADER *)&AcpiIort.Iort.Header;
-}
+VOID* CONST ReferenceAcpiTable = &AcpiIort;
diff --git a/Silicon/AMD/Styx/AcpiTables/Mcfg.c b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Mcfg.aslc
similarity index 86%
rename from Silicon/AMD/Styx/AcpiTables/Mcfg.c
rename to Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Mcfg.aslc
index 4fc18e8efcfc..67fb0429d840 100644
--- a/Silicon/AMD/Styx/AcpiTables/Mcfg.c
+++ b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Mcfg.aslc
@@ -16,9 +16,10 @@
 
 **/
 
-#include <AmdStyxAcpiLib.h>
 #include <IndustryStandard/MemoryMappedConfigurationSpaceAccessTable.h>
 
+#include "AcpiPlatform.h"
+
 #if STYX_A0
 #define END_PCI_BUS_NUMBER                15
 #else
@@ -32,7 +33,7 @@ typedef struct {
   EFI_ACPI_MEMORY_MAPPED_ENHANCED_CONFIGURATION_SPACE_BASE_ADDRESS_ALLOCATION_STRUCTURE Structure;
 } EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_DESCRIPTION_TABLE;
 
-EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_DESCRIPTION_TABLE AcpiMcfg = {
+STATIC EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_DESCRIPTION_TABLE AcpiMcfg = {
   { AMD_ACPI_HEADER (EFI_ACPI_5_0_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE,
     EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_DESCRIPTION_TABLE,
     EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_TABLE_REVISION),
@@ -42,10 +43,4 @@ EFI_ACPI_MEMORY_MAPPED_CONFIGURATION_SPACE_ACCESS_DESCRIPTION_TABLE AcpiMcfg = {
 
 #pragma pack(pop)
 
-EFI_ACPI_DESCRIPTION_HEADER *
-McfgHeader (
-  VOID
-  )
-{
-  return &AcpiMcfg.Header.Header;
-}
+VOID* CONST ReferenceAcpiTable = &AcpiMcfg;
diff --git a/Silicon/AMD/Styx/AcpiTables/Pptt.c b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Pptt.aslc
similarity index 97%
rename from Silicon/AMD/Styx/AcpiTables/Pptt.c
rename to Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Pptt.aslc
index 1746bbe8b596..64a6cda7fd87 100644
--- a/Silicon/AMD/Styx/AcpiTables/Pptt.c
+++ b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Pptt.aslc
@@ -14,7 +14,7 @@
 
 #include <IndustryStandard/Acpi.h>
 
-#include <AmdStyxAcpiLib.h>
+#include "AcpiPlatform.h"
 
 #define FIELD_OFFSET(type, name)            __builtin_offsetof(type, name)
 
@@ -216,10 +216,4 @@ STATIC STYX_PPTT_TABLE mStyxPpttTable = {
   }
 };
 
-EFI_ACPI_DESCRIPTION_HEADER *
-PpttHeader (
-  VOID
-  )
-{
-  return (EFI_ACPI_DESCRIPTION_HEADER *)&mStyxPpttTable.Pptt.Header;
-}
+VOID* CONST ReferenceAcpiTable = &mStyxPpttTable;
diff --git a/Silicon/AMD/Styx/AcpiTables/Spcr.c b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Spcr.aslc
similarity index 90%
rename from Silicon/AMD/Styx/AcpiTables/Spcr.c
rename to Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Spcr.aslc
index 719c276cfb31..bd84a19cce46 100644
--- a/Silicon/AMD/Styx/AcpiTables/Spcr.c
+++ b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Spcr.aslc
@@ -16,9 +16,10 @@
 
 **/
 
-#include <AmdStyxAcpiLib.h>
 #include <IndustryStandard/SerialPortConsoleRedirectionTable.h>
 
+#include "AcpiPlatform.h"
+
 #pragma pack(push, 1)
 
 #define EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_INTERFACE_TYPE_PL011   3
@@ -114,11 +115,4 @@ STATIC EFI_ACPI_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE AcpiSpcr = {
 
 #pragma pack(pop)
 
-EFI_ACPI_DESCRIPTION_HEADER *
-SpcrHeader (
-  VOID
-  )
-{
-  return &AcpiSpcr.Header;
-}
-
+VOID* CONST ReferenceAcpiTable = &AcpiSpcr;
-- 
2.19.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH edk2-platforms 2/2] Silicon/Styx/AcpiPlatformDxe: simplify MADT generation logic
  2018-12-06 12:12 [PATCH edk2-platforms 0/2] Silicon/Styx: merge and simplify ACPI platform driver Ard Biesheuvel
  2018-12-06 12:12 ` [PATCH edk2-platforms 1/2] Silicon/AMD/Styx: merge ACPI table drivers Ard Biesheuvel
@ 2018-12-06 12:12 ` Ard Biesheuvel
  2018-12-10 22:20 ` [PATCH edk2-platforms 0/2] Silicon/Styx: merge and simplify ACPI platform driver Leif Lindholm
  2 siblings, 0 replies; 5+ messages in thread
From: Ard Biesheuvel @ 2018-12-06 12:12 UTC (permalink / raw)
  To: edk2-devel; +Cc: leif.lindholm, alan, graeme.gregory, Ard Biesheuvel

The MADT generation code is rather unpolished and overcomplicated,
and rewrites most of the table with information that is known
statically at build time, with the exception of which CPUs are
actually online.

So remove all the runtime generation code, and replace it with a
simple loop that sets the 'enabled' flag on each CPU that is
reported as present by the secure firmware.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ard Biesheuvel <ard.biesheuvel@linaro.org>
---
 Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf |   5 +-
 Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatform.h      |   2 +-
 Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatform.c      |  64 +++-
 Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Madt.c              | 319 --------------------
 Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Madt.aslc           | 117 +++++++
 5 files changed, 172 insertions(+), 335 deletions(-)

diff --git a/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
index 95745db00ff3..2a42d76d4883 100644
--- a/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
+++ b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatformDxe.inf
@@ -34,7 +34,7 @@
   Fadt.aslc
   Gtdt.aslc
   Iort.aslc
-  Madt.c
+  Madt.aslc
   Mcfg.aslc
   Pptt.aslc
   Spcr.aslc
@@ -49,6 +49,7 @@
   Silicon/AMD/Styx/AmdStyx.dec
 
 [LibraryClasses]
+  ArmLib
   BaseLib
   BaseMemoryLib
   DebugLib
@@ -92,4 +93,4 @@
   gEfiAcpiTableProtocolGuid                     ## ALWAYS_CONSUMED
 
 [Depex]
-  gEfiAcpiTableProtocolGuid
+  gEfiAcpiTableProtocolGuid AND gAmdMpCoreInfoProtocolGuid
diff --git a/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatform.h b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatform.h
index b1864131795a..883dc9df36f9 100644
--- a/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatform.h
+++ b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatform.h
@@ -18,7 +18,7 @@
 
 #include <IndustryStandard/Acpi.h>
 
-EFI_ACPI_DESCRIPTION_HEADER *MadtHeader (void);
+#define MAX_CORES                        8
 
 #define EFI_ACPI_AMD_OEM_ID_ARRAY        {'A','M','D','I','N','C'}
 #define EFI_ACPI_AMD_OEM_TABLE_ID        SIGNATURE_64('S','E','A','T','T','L','E',' ')
diff --git a/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatform.c b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatform.c
index ff1326982329..f1223ada2444 100644
--- a/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatform.c
+++ b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/AcpiPlatform.c
@@ -19,8 +19,12 @@
    MdeModulePkg/Universal/Acpi/AcpiPlatformDxe/AcpiPlatform.c
 **/
 
+#include <Guid/ArmMpCoreInfo.h>
+
 #include <Protocol/AcpiTable.h>
+#include <Protocol/AmdMpCoreInfo.h>
 
+#include <Library/ArmLib.h>
 #include <Library/BaseLib.h>
 #include <Library/BaseMemoryLib.h>
 #include <Library/DebugLib.h>
@@ -37,6 +41,7 @@
 #include "AcpiPlatform.h"
 
 STATIC EFI_ACPI_TABLE_PROTOCOL   *mAcpiTableProtocol;
+STATIC AMD_MP_CORE_INFO_PROTOCOL *mAmdMpCoreInfoProtocol;
 
 #if DO_XGBE
 
@@ -89,20 +94,49 @@ PatchAmlPackage (
 
 #endif
 
+STATIC
+VOID
+EnableAvailableCores (
+  EFI_ACPI_5_1_GIC_STRUCTURE            *GicC
+  )
+{
+  ARM_CORE_INFO                         *ArmCoreInfoTable;
+  UINTN                                 CoreCount;
+  UINTN                                 Index;
+
+  CoreCount = 0;
+  ArmCoreInfoTable = mAmdMpCoreInfoProtocol->GetArmCoreInfoTable (&CoreCount);
+  ASSERT (ArmCoreInfoTable != NULL);
+
+  while (CoreCount--) {
+    for (Index = 0; Index < MAX_CORES; Index++) {
+      if (GicC[Index].MPIDR == GET_MPID (ArmCoreInfoTable->ClusterId,
+                                         ArmCoreInfoTable->CoreId)) {
+        GicC[Index].Flags |= EFI_ACPI_5_1_GIC_ENABLED;
+        break;
+      }
+    }
+    ArmCoreInfoTable++;
+  }
+}
+
 STATIC
 VOID
 InstallSystemDescriptionTables (
   VOID
   )
 {
-  EFI_ACPI_DESCRIPTION_HEADER                   *Table;
-  EFI_STATUS                                    Status;
-  UINT32                                        CpuId;
-  UINTN                                         Index;
-  UINTN                                         TableSize;
-  UINTN                                         TableHandle;
-  EFI_ACPI_5_1_GENERIC_TIMER_DESCRIPTION_TABLE  *Gtdt;
-  EFI_ACPI_6_0_IO_REMAPPING_TABLE               *Iort;
+  EFI_ACPI_DESCRIPTION_HEADER                         *Table;
+  EFI_STATUS                                          Status;
+  UINT32                                              CpuId;
+  UINTN                                               Index;
+  UINTN                                               TableSize;
+  UINTN                                               TableHandle;
+  EFI_ACPI_5_1_GENERIC_TIMER_DESCRIPTION_TABLE        *Gtdt;
+  EFI_ACPI_6_0_IO_REMAPPING_TABLE                     *Iort;
+  EFI_ACPI_5_1_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER *Madt;
+  EFI_ACPI_5_1_GIC_STRUCTURE                          *GicC;
+
 #if DO_XGBE
   UINT8                         MacPackage[sizeof(mDefaultMacPackageA)];
 #endif
@@ -163,6 +197,13 @@ InstallSystemDescriptionTables (
           Gtdt->PlatformTimerOffset = 0;
         }
         break;
+
+      case EFI_ACPI_5_1_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE:
+        Madt = (EFI_ACPI_5_1_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER *)Table;
+        GicC = (EFI_ACPI_5_1_GIC_STRUCTURE *)(Madt + 1);
+
+        EnableAvailableCores (GicC);
+        break;
       }
     }
 
@@ -198,8 +239,6 @@ AcpiPlatformEntryPoint (
   )
 {
   EFI_STATUS                  Status;
-  UINTN                       TableHandle;
-  EFI_ACPI_DESCRIPTION_HEADER *Header;
 
   //
   // Find the AcpiTable protocol
@@ -208,9 +247,8 @@ AcpiPlatformEntryPoint (
                   (VOID**)&mAcpiTableProtocol);
   ASSERT_EFI_ERROR (Status);
 
-  Header = MadtHeader ();
-  Status = mAcpiTableProtocol->InstallAcpiTable (mAcpiTableProtocol, Header,
-                                 Header->Length, &TableHandle);
+  Status = gBS->LocateProtocol (&gAmdMpCoreInfoProtocolGuid, NULL,
+                  (VOID**)&mAmdMpCoreInfoProtocol);
   ASSERT_EFI_ERROR (Status);
 
   InstallSystemDescriptionTables ();
diff --git a/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Madt.c b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Madt.c
deleted file mode 100644
index b10ae7e1ab74..000000000000
--- a/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Madt.c
+++ /dev/null
@@ -1,319 +0,0 @@
-/** @file
-
-  Multiple APIC Description Table (MADT)
-
-  Copyright (c) 2012 - 2014, ARM Ltd. All rights reserved.<BR>
-  Copyright (c) 2014 - 2016, AMD Inc. All rights reserved.<BR>
-
-  This program and the accompanying materials
-  are licensed and made available under the terms and conditions of the BSD License
-  which accompanies this distribution.  The full text of the license may be found at
-  http://opensource.org/licenses/bsd-license.php
-
-  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
-  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
-
-**/
-/**
-
-  Derived from:
-   ArmPlatformPkg/ArmJunoPkg/AcpiTables/Madt.aslc
-
-**/
-
-#include <Uefi.h>
-#include <Library/ArmLib.h>
-#include <Library/DebugLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Guid/ArmMpCoreInfo.h>
-
-#include <Protocol/AmdMpCoreInfo.h>
-
-#include "AcpiPlatform.h"
-
-AMD_MP_CORE_INFO_PROTOCOL  *mAmdMpCoreInfoProtocol = NULL;
-
-
-// ARM PL390 General Interrupt Controller
-#define GIC_BASE                             (FixedPcdGet64 (PcdGicInterruptInterfaceBase))
-#define GICD_BASE                            (FixedPcdGet64 (PcdGicDistributorBase))
-#define GICV_BASE                            (FixedPcdGet64 (PcdGicVirtualInterruptInterfaceBase))
-#define GICH_BASE                            (FixedPcdGet64 (PcdGicHypervisorInterruptInterfaceBase))
-#define VGIC_MAINT_INT                       (FixedPcdGet32 (PcdGicVirtualMaintenanceInterrupt))
-#define GICVR_BASE                           (FixedPcdGet64 (PcdGicVirtualRegisterInterfaceBase))
-#define GIC_MSI_FRAME                        (FixedPcdGet64 (PcdGicMSIFrameBase))
-#define GIC_VERSION                          (FixedPcdGet8  (PcdGicVersion))
-
-#define GICD_ID                              ( 0 )
-#define GICD_VECTOR                          ( 0 )
-
-#define GICM_ID                              ( 0 )
-#define GICM_SPI_COUNT                       ( 0x100 )
-#define GICM_SPI_BASE                        ( 0x40 )
-#define GSIV_SPI_OFFSET                      ( 32 )
-
-#if STYX_A0
-  #define MSI_TYPER_FLAG                     ( 1 ) // Ignore TYPER register and use Count/Base fields
-#else
-  #define MSI_TYPER_FLAG                     ( 0 ) // Use TYPER register and ignore Count/Base fields
-#endif
-
-#define CORES_PER_CLUSTER                    (FixedPcdGet32 (PcdSocCoresPerCluster))
-
-
-/* Macro to populate EFI_ACPI_5_1_GIC_STRUCTURE */
-#define AMD_GIC(CpuNum, ClusterId, CoreId, PerfInt)  {                        \
-  EFI_ACPI_5_1_GIC,                     /* UINT8 Type */                      \
-  sizeof (EFI_ACPI_5_1_GIC_STRUCTURE),  /* UINT8 Length */                    \
-  EFI_ACPI_RESERVED_WORD,               /* UINT16 Reserved */                 \
-  CpuNum,                               /* UINT32 CPUInterfaceNumber */       \
-  (ClusterId << 8) | CoreId,            /* UINT32 AcpiProcessorUid */         \
-  EFI_ACPI_5_1_GIC_ENABLED,             /* UINT32 Flags */                    \
-  0,                                    /* UINT32 ParkingProtocolVersion */   \
-  PerfInt,                              /* UINT32 PerformanceInterruptGsiv */ \
-  0,                                    /* UINT64 ParkedAddress */            \
-  GIC_BASE,                             /* UINT64 PhysicalBaseAddress */      \
-  GICV_BASE,                            /* UINT64 GICV */                     \
-  GICH_BASE,                            /* UINT64 GICH */                     \
-  VGIC_MAINT_INT,                       /* UINT32 VGICMaintenanceInterrupt */ \
-  GICVR_BASE,                           /* UINT64 GICRBaseAddress */          \
-  (ClusterId << 8) | CoreId             /* UINT64 MPIDR */                    \
-  }
-
-/* Macro to initialise EFI_ACPI_5_1_GIC_DISTRIBUTOR_STRUCTURE */
-#define AMD_GICD(Id, Vec) {                                                             \
-  EFI_ACPI_5_1_GICD,                                /* UINT8 Type */                    \
-  sizeof (EFI_ACPI_5_1_GIC_DISTRIBUTOR_STRUCTURE),  /* UINT8 Length */                  \
-  EFI_ACPI_RESERVED_WORD,                           /* UINT16 Reserved1 */              \
-  Id,                                               /* UINT32 GicId */                  \
-  GICD_BASE,                                        /* UINT64 PhysicalBaseAddress */    \
-  Vec,                                              /* UINT32 SystemVectorBase */       \
-  EFI_ACPI_RESERVED_DWORD                           /* UINT32 Reserved2 */              \
-  }
-
-/* Macro to initialise EFI_ACPI_5_1_GIC_MSI_FRAME_STRUCTURE */
-#define AMD_GICM(Id, SpiCount, SpiBase) {                                               \
-   EFI_ACPI_5_1_GIC_MSI_FRAME,                      /* UINT8 Type */                    \
-   sizeof(EFI_ACPI_5_1_GIC_MSI_FRAME_STRUCTURE),    /* UINT8 Length */                  \
-   EFI_ACPI_RESERVED_WORD,                          /* UINT16 Reserved1 */              \
-   Id,                                              /* UINT32 GicMsiFrameId */          \
-   GIC_MSI_FRAME,                                   /* UINT64 PhysicalBaseAddress */    \
-   MSI_TYPER_FLAG,                                  /* UINT32 Flags */                  \
-   SpiCount,                                        /* UINT16 SPICount */               \
-   SpiBase                                          /* UINT16 SPIBase */                \
-   }
-
-
-//
-// NOTE: NUM_CORES is a pre-processor macro passed in with -D option
-//
-#pragma pack(push, 1)
-typedef struct {
-  EFI_ACPI_5_1_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER Header;
-  EFI_ACPI_5_1_GIC_STRUCTURE                          GicC[NUM_CORES];
-  EFI_ACPI_5_1_GIC_DISTRIBUTOR_STRUCTURE              GicD;
-  EFI_ACPI_5_1_GIC_MSI_FRAME_STRUCTURE                GicM;
-} EFI_ACPI_5_1_ARM_MADT_STRUCTURE;
-#pragma pack(pop)
-
-
-STATIC EFI_ACPI_5_1_ARM_MADT_STRUCTURE AcpiMadt = {
-  {
-    AMD_ACPI_HEADER (EFI_ACPI_5_1_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE,
-                     EFI_ACPI_5_1_ARM_MADT_STRUCTURE,
-                     EFI_ACPI_5_1_MULTIPLE_APIC_DESCRIPTION_TABLE_REVISION),
-    GIC_BASE,                                 // UINT32  LocalApicAddress
-    0                                         // UINT32  Flags
-  },
-  {
-    /*
-     * GIC Interface for Cluster 0 CPU 0
-     */
-    AMD_GIC(0, 0, 0, 39),                     // EFI_ACPI_5_1_GIC_STRUCTURE
-#if (NUM_CORES > 1)
-    /*
-     * GIC Interface for Cluster 0 CPU 1
-     */
-    AMD_GIC(1, 0, 1, 40),                     // EFI_ACPI_5_1_GIC_STRUCTURE
-#endif
-#if (NUM_CORES > 2)
-    /*
-     * GIC Interface for Cluster 1 CPU 0
-     */
-    AMD_GIC(2, 1, 0, 41),                     // EFI_ACPI_5_1_GIC_STRUCTURE
-#endif
-#if (NUM_CORES > 3)
-    /*
-     * GIC Interface for Cluster 1 CPU 1
-     */
-    AMD_GIC(3, 1, 1, 42),                     // EFI_ACPI_5_1_GIC_STRUCTURE
-#endif
-#if (NUM_CORES > 4)
-    /*
-     * GIC Interface for Cluster 2 CPU 0
-     */
-    AMD_GIC(4, 2, 0, 43),                     // EFI_ACPI_5_1_GIC_STRUCTURE
-#endif
-#if (NUM_CORES > 5)
-    /*
-     * GIC Interface for Cluster 2 CPU 1
-     */
-    AMD_GIC(5, 2, 1, 44),                     // EFI_ACPI_5_1_GIC_STRUCTURE
-#endif
-#if (NUM_CORES > 6)
-    /*
-     * GIC Interface for Cluster 3 CPU 0
-     */
-    AMD_GIC(6, 3, 0, 45),                     // EFI_ACPI_5_1_GIC_STRUCTURE
-#endif
-#if (NUM_CORES > 7)
-    /*
-     * GIC Interface for Cluster 3 CPU 1
-     */
-    AMD_GIC(7, 3, 1, 46),                     // EFI_ACPI_5_1_GIC_STRUCTURE
-#endif
-  },
-  /*
-   * GIC Distributor
-   */
-    AMD_GICD(GICD_ID, GICD_VECTOR),           // EFI_ACPI_5_1_GIC_DISTRIBUTOR_STRUCTURE
-  /*
-   * GIC MSI Frame
-   */
-  AMD_GICM(GICM_ID, GICM_SPI_COUNT, GICM_SPI_BASE),
-};
-
-
-STATIC
-EFI_STATUS
-BuildGicC (
-  EFI_ACPI_5_1_GIC_STRUCTURE *GicC,
-  UINT32 CpuNum,
-  UINT32 ClusterId,
-  UINT32 CoreId
-  )
-{
-  UINT32 MpId, PmuSpi;
-  EFI_STATUS Status;
-
-  MpId = (UINT32) GET_MPID (ClusterId, CoreId);
-  Status = mAmdMpCoreInfoProtocol->GetPmuSpiFromMpId (MpId, &PmuSpi);
-  if (EFI_ERROR (Status))
-    return Status;
-
-  GicC->Type = EFI_ACPI_5_1_GIC;
-  GicC->Length = sizeof (EFI_ACPI_5_1_GIC_STRUCTURE);
-  GicC->Reserved = EFI_ACPI_RESERVED_WORD;
-  GicC->CPUInterfaceNumber = CpuNum;
-  GicC->AcpiProcessorUid = MpId;
-  GicC->Flags = EFI_ACPI_5_1_GIC_ENABLED;
-  GicC->PhysicalBaseAddress = GIC_BASE;
-  GicC->GICV = GICV_BASE;
-  GicC->GICH = GICH_BASE;
-  GicC->VGICMaintenanceInterrupt = VGIC_MAINT_INT;
-  GicC->GICRBaseAddress = GICVR_BASE;
-  GicC->PerformanceInterruptGsiv = PmuSpi + GSIV_SPI_OFFSET;
-  GicC->MPIDR = MpId;
-
-  return EFI_SUCCESS;
-}
-
-STATIC
-VOID
-BuildGicD (
-  EFI_ACPI_5_1_GIC_DISTRIBUTOR_STRUCTURE *GicD,
-  UINT32 GicId,
-  UINT32 SystemVectorBase
-  )
-{
-  GicD->Type = EFI_ACPI_5_1_GICD;
-  GicD->Length = sizeof (EFI_ACPI_5_1_GIC_DISTRIBUTOR_STRUCTURE);
-  GicD->Reserved1 = EFI_ACPI_RESERVED_WORD;
-  GicD->GicId = GicId;
-  GicD->PhysicalBaseAddress = GICD_BASE;
-  GicD->SystemVectorBase = SystemVectorBase;
-#if 0
-  GicD->Reserved2 = EFI_ACPI_RESERVED_DWORD;
-#else
-  GicD->GicVersion = EFI_ACPI_RESERVED_BYTE;
-  GicD->Reserved2[0] = EFI_ACPI_RESERVED_BYTE;
-  GicD->Reserved2[1] = EFI_ACPI_RESERVED_BYTE;
-  GicD->Reserved2[2] = EFI_ACPI_RESERVED_BYTE;
-#endif
-}
-
-
-STATIC
-VOID
-BuildGicM (
-  EFI_ACPI_5_1_GIC_MSI_FRAME_STRUCTURE *GicM,
-  UINT32 MsiFrameId,
-  UINT16 SpiCount,
-  UINT16 SpiBase
-  )
-{
-  GicM->Type = EFI_ACPI_5_1_GIC_MSI_FRAME;
-  GicM->Length = sizeof(EFI_ACPI_5_1_GIC_MSI_FRAME_STRUCTURE);
-  GicM->Reserved1 = EFI_ACPI_RESERVED_WORD;
-  GicM->GicMsiFrameId = MsiFrameId;
-  GicM->PhysicalBaseAddress = GIC_MSI_FRAME;
-  GicM->Flags = MSI_TYPER_FLAG;
-  GicM->SPICount = SpiCount;
-  GicM->SPIBase = SpiBase;
-}
-
-
-EFI_ACPI_DESCRIPTION_HEADER *
-MadtHeader (
-  VOID
-  )
-{
-  EFI_ACPI_5_1_GIC_STRUCTURE             *GicC;
-  EFI_ACPI_5_1_GIC_DISTRIBUTOR_STRUCTURE *GicD;
-  EFI_ACPI_5_1_GIC_MSI_FRAME_STRUCTURE   *GicM;
-  ARM_CORE_INFO                          *ArmCoreInfoTable;
-  UINTN                                  CoreCount, CpuNum;
-  EFI_STATUS                             Status;
-
-  Status = gBS->LocateProtocol (
-               &gAmdMpCoreInfoProtocolGuid,
-               NULL,
-               (VOID **)&mAmdMpCoreInfoProtocol
-               );
-  ASSERT_EFI_ERROR (Status);
-
-  // Get pointer to ARM core info table
-  ArmCoreInfoTable = mAmdMpCoreInfoProtocol->GetArmCoreInfoTable (&CoreCount);
-  ASSERT (ArmCoreInfoTable != NULL);
-
-  // Make sure SoC's core count does not exceed what we want to build
-  ASSERT (CoreCount <= NUM_CORES);
-  ASSERT (CoreCount <= PcdGet32(PcdSocCoreCount));
-
-  GicC = (EFI_ACPI_5_1_GIC_STRUCTURE *)&AcpiMadt.GicC[0];
-  AcpiMadt.Header.Header.Length = sizeof (EFI_ACPI_5_1_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER);
-
-  for (CpuNum = 0; CpuNum < CoreCount; ++CpuNum, ++GicC) {
-    DEBUG ((EFI_D_ERROR, "MADT: Core[%d]: ClusterId = %d   CoreId = %d\n",
-            CpuNum, ArmCoreInfoTable[CpuNum].ClusterId, ArmCoreInfoTable[CpuNum].CoreId));
-
-    Status = BuildGicC (GicC, CpuNum,
-                ArmCoreInfoTable[CpuNum].ClusterId,
-                ArmCoreInfoTable[CpuNum].CoreId
-                );
-    ASSERT_EFI_ERROR (Status);
-
-    AcpiMadt.Header.Header.Length += sizeof (EFI_ACPI_5_1_GIC_STRUCTURE);
-  }
-
-  GicD = (EFI_ACPI_5_1_GIC_DISTRIBUTOR_STRUCTURE *)(UINT8 *)((UINTN)&AcpiMadt + (UINTN)AcpiMadt.Header.Header.Length);
-  BuildGicD (GicD, GICD_ID, GICD_VECTOR);
-  AcpiMadt.Header.Header.Length += sizeof (EFI_ACPI_5_1_GIC_DISTRIBUTOR_STRUCTURE);
-
-  GicM = (EFI_ACPI_5_1_GIC_MSI_FRAME_STRUCTURE *)(UINT8 *)((UINTN)&AcpiMadt + (UINTN)AcpiMadt.Header.Header.Length);
-  BuildGicM (GicM, GICM_ID, GICM_SPI_COUNT, GICM_SPI_BASE);
-  AcpiMadt.Header.Header.Length += sizeof (EFI_ACPI_5_1_GIC_MSI_FRAME_STRUCTURE);
-
-  return &AcpiMadt.Header.Header;
-}
-
diff --git a/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Madt.aslc b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Madt.aslc
new file mode 100644
index 000000000000..d4762bbbae3d
--- /dev/null
+++ b/Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Madt.aslc
@@ -0,0 +1,117 @@
+/** @file
+
+  Multiple APIC Description Table (MADT)
+
+  Copyright (c) 2012 - 2014, ARM Ltd. All rights reserved.<BR>
+  Copyright (c) 2014 - 2016, AMD Inc. All rights reserved.<BR>
+  Copyright (c) 2018, Linaro, Ltd. All rights reserved.<BR>
+
+  This program and the accompanying materials
+  are licensed and made available under the terms and conditions of the BSD License
+  which accompanies this distribution.  The full text of the license may be found at
+  http://opensource.org/licenses/bsd-license.php
+
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+**/
+
+#include <IndustryStandard/Acpi61.h>
+
+#include "AcpiPlatform.h"
+
+#define GICM_SPI_COUNT      (0x100)
+#define GICM_SPI_BASE       (0x40)
+
+#define GIC_BASE            (FixedPcdGet64 (PcdGicInterruptInterfaceBase))
+#define GICD_BASE           (FixedPcdGet64 (PcdGicDistributorBase))
+#define GICV_BASE           (FixedPcdGet64 (PcdGicVirtualInterruptInterfaceBase))
+#define GICH_BASE           (FixedPcdGet64 (PcdGicHypervisorInterruptInterfaceBase))
+#define VGIC_MAINT_INT      (FixedPcdGet32 (PcdGicVirtualMaintenanceInterrupt))
+#define GICVR_BASE          (FixedPcdGet64 (PcdGicVirtualRegisterInterfaceBase))
+#define GIC_MSI_FRAME       (FixedPcdGet64 (PcdGicMSIFrameBase))
+#define GIC_VERSION         (FixedPcdGet8  (PcdGicVersion))
+#define CORES_PER_CLUSTER   (FixedPcdGet32 (PcdSocCoresPerCluster))
+
+
+/* Macro to populate EFI_ACPI_5_1_GIC_STRUCTURE */
+#define AMD_GIC(CpuNum, ClusterId, CoreId, PerfInt)  {                        \
+  EFI_ACPI_5_1_GIC,                     /* UINT8 Type */                      \
+  sizeof (EFI_ACPI_5_1_GIC_STRUCTURE),  /* UINT8 Length */                    \
+  EFI_ACPI_RESERVED_WORD,               /* UINT16 Reserved */                 \
+  CpuNum,                               /* UINT32 CPUInterfaceNumber */       \
+  (ClusterId << 8) | CoreId,            /* UINT32 AcpiProcessorUid */         \
+  0,                                    /* UINT32 Flags */                    \
+  0,                                    /* UINT32 ParkingProtocolVersion */   \
+  PerfInt,                              /* UINT32 PerformanceInterruptGsiv */ \
+  0,                                    /* UINT64 ParkedAddress */            \
+  GIC_BASE,                             /* UINT64 PhysicalBaseAddress */      \
+  GICV_BASE,                            /* UINT64 GICV */                     \
+  GICH_BASE,                            /* UINT64 GICH */                     \
+  VGIC_MAINT_INT,                       /* UINT32 VGICMaintenanceInterrupt */ \
+  GICVR_BASE,                           /* UINT64 GICRBaseAddress */          \
+  (ClusterId << 8) | CoreId             /* UINT64 MPIDR */                    \
+  }
+
+
+#pragma pack(push, 1)
+typedef struct {
+  EFI_ACPI_5_1_MULTIPLE_APIC_DESCRIPTION_TABLE_HEADER Header;
+  EFI_ACPI_5_1_GIC_STRUCTURE                          GicC[MAX_CORES];
+  EFI_ACPI_5_1_GIC_DISTRIBUTOR_STRUCTURE              GicD;
+  EFI_ACPI_5_1_GIC_MSI_FRAME_STRUCTURE                GicM;
+} EFI_ACPI_5_1_ARM_MADT_STRUCTURE;
+#pragma pack(pop)
+
+
+STATIC EFI_ACPI_5_1_ARM_MADT_STRUCTURE AcpiMadt = {
+  {
+    AMD_ACPI_HEADER (EFI_ACPI_5_1_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE,
+                     EFI_ACPI_5_1_ARM_MADT_STRUCTURE,
+                     EFI_ACPI_5_1_MULTIPLE_APIC_DESCRIPTION_TABLE_REVISION),
+    GIC_BASE,                                 // UINT32  LocalApicAddress
+    0                                         // UINT32  Flags
+  },
+  {
+    AMD_GIC (0, 0, 0, 39),
+    AMD_GIC (1, 0, 1, 40),
+    AMD_GIC (2, 1, 0, 41),
+    AMD_GIC (3, 1, 1, 42),
+    AMD_GIC (4, 2, 0, 43),
+    AMD_GIC (5, 2, 1, 44),
+    AMD_GIC (6, 3, 0, 45),
+    AMD_GIC (7, 3, 1, 46),
+  },
+  /*
+   * GIC Distributor
+   */
+  {
+    EFI_ACPI_5_1_GICD,                                // UINT8 Type
+    sizeof (EFI_ACPI_5_1_GIC_DISTRIBUTOR_STRUCTURE),  // UINT8 Length
+    EFI_ACPI_RESERVED_WORD,                           // UINT16 Reserved1
+    0,                                                // UINT32 GicId
+    GICD_BASE,                                        // UINT64 PhysicalBaseAddress
+    0,                                                // UINT32 SystemVectorBase
+    EFI_ACPI_RESERVED_BYTE,                           // UINT8 GicVersion
+    {                                                 // UINT8 Reserved2[3]
+      EFI_ACPI_RESERVED_BYTE,
+      EFI_ACPI_RESERVED_BYTE,
+      EFI_ACPI_RESERVED_BYTE,
+    }
+  },
+  /*
+   * GIC MSI Frame
+   */
+  {
+    EFI_ACPI_5_1_GIC_MSI_FRAME,                      // UINT8 Type
+    sizeof(EFI_ACPI_5_1_GIC_MSI_FRAME_STRUCTURE),    // UINT8 Length
+    EFI_ACPI_RESERVED_WORD,                          // UINT16 Reserved1
+    0,                                               // UINT32 GicMsiFrameId
+    GIC_MSI_FRAME,                                   // UINT64 PhysicalBaseAddress
+    0,                                               // UINT32 Flags
+    GICM_SPI_COUNT,                                  // UINT16 SPICount
+    GICM_SPI_BASE                                    // UINT16 SPIBase
+  }
+};
+
+VOID* CONST ReferenceAcpiTable = &AcpiMadt;
-- 
2.19.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH edk2-platforms 0/2] Silicon/Styx: merge and simplify ACPI platform driver
  2018-12-06 12:12 [PATCH edk2-platforms 0/2] Silicon/Styx: merge and simplify ACPI platform driver Ard Biesheuvel
  2018-12-06 12:12 ` [PATCH edk2-platforms 1/2] Silicon/AMD/Styx: merge ACPI table drivers Ard Biesheuvel
  2018-12-06 12:12 ` [PATCH edk2-platforms 2/2] Silicon/Styx/AcpiPlatformDxe: simplify MADT generation logic Ard Biesheuvel
@ 2018-12-10 22:20 ` Leif Lindholm
  2018-12-11  8:02   ` Ard Biesheuvel
  2 siblings, 1 reply; 5+ messages in thread
From: Leif Lindholm @ 2018-12-10 22:20 UTC (permalink / raw)
  To: Ard Biesheuvel; +Cc: edk2-devel, alan, graeme.gregory

On Thu, Dec 06, 2018 at 01:12:02PM +0100, Ard Biesheuvel wrote:
> After fixing the iasl issue yesterday, I got a bit carried away and ended
> up rewriting most of the ACPI table generation logic for Styx. So this
> applies on top of the patches I sent out yesterday.
> 
> Patch #1 merges the DXE driver and the library, that are split in two for
> no good reason.
> 
> Patch #2 simplifies the MADT generation code.

I would be lying if I said I'd properly reviewed this series, but
superficially it looks good, and I trust you to have tested it
properly. So:
Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>

> Ard Biesheuvel (2):
>   Silicon/AMD/Styx: merge ACPI table drivers
>   Silicon/Styx/AcpiPlatformDxe: simplify MADT generation logic
> 
>  .../AMD/OverdriveBoard/OverdriveBoard.dsc     |   1 -
>  Platform/LeMaker/CelloBoard/CelloBoard.dsc    |   1 -
>  .../Overdrive1000Board/Overdrive1000Board.dsc |   1 -
>  .../AMD/OverdriveBoard/OverdriveBoard.fdf     |   1 +
>  Platform/LeMaker/CelloBoard/CelloBoard.fdf    |   1 +
>  .../Overdrive1000Board/Overdrive1000Board.fdf |   1 +
>  Silicon/AMD/Styx/AcpiTables/AcpiTables.inf    |  85 -----
>  .../AcpiPlatformDxe/AcpiPlatformDxe.inf       |  34 +-
>  .../AcpiPlatformDxe/AcpiPlatform.h}           |  11 +-
>  Silicon/AMD/Styx/AcpiTables/Madt.c            | 318 ------------------
>  .../Drivers/AcpiPlatformDxe/AcpiPlatform.c    | 155 +++++----
>  .../AcpiPlatformDxe/Csrt.aslc}                |  13 +-
>  .../AcpiPlatformDxe/Dbg2.aslc}                |  12 +-
>  .../AcpiPlatformDxe/Fadt.aslc}                |  11 +-
>  .../AcpiPlatformDxe/Gtdt.aslc}                |  20 +-
>  .../AcpiPlatformDxe/Iort.aslc}                |  19 +-
>  .../Styx/Drivers/AcpiPlatformDxe/Madt.aslc    | 117 +++++++
>  .../AcpiPlatformDxe/Mcfg.aslc}                |  13 +-
>  .../AcpiPlatformDxe/Pptt.aslc}                |  10 +-
>  .../AcpiPlatformDxe/Spcr.aslc}                |  12 +-
>  20 files changed, 264 insertions(+), 572 deletions(-)
>  delete mode 100644 Silicon/AMD/Styx/AcpiTables/AcpiTables.inf
>  rename Silicon/AMD/Styx/{Common/AmdStyxAcpiLib.h => Drivers/AcpiPlatformDxe/AcpiPlatform.h} (81%)
>  delete mode 100644 Silicon/AMD/Styx/AcpiTables/Madt.c
>  rename Silicon/AMD/Styx/{AcpiTables/Csrt.c => Drivers/AcpiPlatformDxe/Csrt.aslc} (93%)
>  rename Silicon/AMD/Styx/{AcpiTables/Dbg2.c => Drivers/AcpiPlatformDxe/Dbg2.aslc} (95%)
>  rename Silicon/AMD/Styx/{AcpiTables/Fadt.c => Drivers/AcpiPlatformDxe/Fadt.aslc} (96%)
>  rename Silicon/AMD/Styx/{AcpiTables/Gtdt.c => Drivers/AcpiPlatformDxe/Gtdt.aslc} (92%)
>  rename Silicon/AMD/Styx/{AcpiTables/Iort.c => Drivers/AcpiPlatformDxe/Iort.aslc} (95%)
>  create mode 100644 Silicon/AMD/Styx/Drivers/AcpiPlatformDxe/Madt.aslc
>  rename Silicon/AMD/Styx/{AcpiTables/Mcfg.c => Drivers/AcpiPlatformDxe/Mcfg.aslc} (86%)
>  rename Silicon/AMD/Styx/{AcpiTables/Pptt.c => Drivers/AcpiPlatformDxe/Pptt.aslc} (97%)
>  rename Silicon/AMD/Styx/{AcpiTables/Spcr.c => Drivers/AcpiPlatformDxe/Spcr.aslc} (90%)
> 
> -- 
> 2.19.2
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH edk2-platforms 0/2] Silicon/Styx: merge and simplify ACPI platform driver
  2018-12-10 22:20 ` [PATCH edk2-platforms 0/2] Silicon/Styx: merge and simplify ACPI platform driver Leif Lindholm
@ 2018-12-11  8:02   ` Ard Biesheuvel
  0 siblings, 0 replies; 5+ messages in thread
From: Ard Biesheuvel @ 2018-12-11  8:02 UTC (permalink / raw)
  To: Leif Lindholm; +Cc: edk2-devel@lists.01.org, Alan Ott, Graeme Gregory

On Mon, 10 Dec 2018 at 23:20, Leif Lindholm <leif.lindholm@linaro.org> wrote:
>
> On Thu, Dec 06, 2018 at 01:12:02PM +0100, Ard Biesheuvel wrote:
> > After fixing the iasl issue yesterday, I got a bit carried away and ended
> > up rewriting most of the ACPI table generation logic for Styx. So this
> > applies on top of the patches I sent out yesterday.
> >
> > Patch #1 merges the DXE driver and the library, that are split in two for
> > no good reason.
> >
> > Patch #2 simplifies the MADT generation code.
>
> I would be lying if I said I'd properly reviewed this series, but
> superficially it looks good, and I trust you to have tested it
> properly. So:
> Reviewed-by: Leif Lindholm <leif.lindholm@linaro.org>
>

Thanks

Pushed as 217713e2cfc9..d645d82b5868


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2018-12-11  8:02 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-06 12:12 [PATCH edk2-platforms 0/2] Silicon/Styx: merge and simplify ACPI platform driver Ard Biesheuvel
2018-12-06 12:12 ` [PATCH edk2-platforms 1/2] Silicon/AMD/Styx: merge ACPI table drivers Ard Biesheuvel
2018-12-06 12:12 ` [PATCH edk2-platforms 2/2] Silicon/Styx/AcpiPlatformDxe: simplify MADT generation logic Ard Biesheuvel
2018-12-10 22:20 ` [PATCH edk2-platforms 0/2] Silicon/Styx: merge and simplify ACPI platform driver Leif Lindholm
2018-12-11  8:02   ` Ard Biesheuvel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox