public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "PierreGondois" <pierre.gondois@arm.com>
To: devel@edk2.groups.io
Cc: Pierre Gondois <pierre.gondois@arm.com>,
	AbdulLateef Attar <AbdulLateef.Attar@amd.com>,
	Girish Mahadevan <gmahadevan@nvidia.com>,
	Jeff Brasen <jbrasen@nvidia.com>,
	Jeshua Smith <jeshuas@nvidia.com>,
	Leif Lindholm <quic_llindhol@quicinc.com>,
	Meenakshi Aggarwal <meenakshi.aggarwal@nxp.com>,
	Sami Mujawar <sami.mujawar@arm.com>,
	Sunil V L <sunilvl@ventanamicro.com>,
	Yeo Reum Yun <YeoReum.Yun@arm.com>,
	Pierre Gondois <Pierre.Gondois@arm.com>
Subject: [edk2-devel] [staging/dynamictables-reorg PATCH 06/15] DynamicTablesPkg: AcpiSratLib: Prepare to support other archs
Date: Thu, 20 Jun 2024 00:06:20 +0200	[thread overview]
Message-ID: <20240619220629.1994362-7-pierre.gondois@arm.com> (raw)
In-Reply-To: <20240619220629.1994362-1-pierre.gondois@arm.com>

Allow other architectures to reuse the AcpiSratLib by extracting
the Arm specific part of the table generation.

Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
---
 .../Acpi/Common/AcpiSratLib/AcpiSratLib.inf   |   7 +
 .../Common/AcpiSratLib/Arm/ArmSratGenerator.c | 262 ++++++++++++++++++
 .../AcpiSratLib/Common/CommonSratGenerator.c  |  77 +++++
 .../Acpi/Common/AcpiSratLib/SratGenerator.c   | 214 ++------------
 .../Acpi/Common/AcpiSratLib/SratGenerator.h   |  59 ++++
 5 files changed, 422 insertions(+), 197 deletions(-)
 create mode 100644 DynamicTablesPkg/Library/Acpi/Common/AcpiSratLib/Arm/ArmSratGenerator.c
 create mode 100644 DynamicTablesPkg/Library/Acpi/Common/AcpiSratLib/Common/CommonSratGenerator.c
 create mode 100644 DynamicTablesPkg/Library/Acpi/Common/AcpiSratLib/SratGenerator.h

diff --git a/DynamicTablesPkg/Library/Acpi/Common/AcpiSratLib/AcpiSratLib.inf b/DynamicTablesPkg/Library/Acpi/Common/AcpiSratLib/AcpiSratLib.inf
index 2f23f4e668e5..c2f24a23ccd8 100644
--- a/DynamicTablesPkg/Library/Acpi/Common/AcpiSratLib/AcpiSratLib.inf
+++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiSratLib/AcpiSratLib.inf
@@ -18,6 +18,13 @@ [Defines]
 
 [Sources]
   SratGenerator.c
+  SratGenerator.h
+
+[Sources.ARM, Sources.AARCH64]
+  Arm/ArmSratGenerator.c
+
+[Sources.IA32, Sources.X64]
+  Common/CommonSratGenerator.c
 
 [Packages]
   EmbeddedPkg/EmbeddedPkg.dec
diff --git a/DynamicTablesPkg/Library/Acpi/Common/AcpiSratLib/Arm/ArmSratGenerator.c b/DynamicTablesPkg/Library/Acpi/Common/AcpiSratLib/Arm/ArmSratGenerator.c
new file mode 100644
index 000000000000..3d36b25e1840
--- /dev/null
+++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiSratLib/Arm/ArmSratGenerator.c
@@ -0,0 +1,262 @@
+/** @file
+  Arm SRAT Table Generator
+
+  Copyright (c) 2019 - 2020, Arm Limited. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Reference(s):
+  - ACPI 6.3 Specification, January 2019
+
+  @par Glossary:
+  - Cm or CM   - Configuration Manager
+  - Obj or OBJ - Object
+**/
+
+#include <Library/AcpiLib.h>
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Protocol/AcpiTable.h>
+
+// Module specific include files.
+#include <AcpiTableGenerator.h>
+#include <ConfigurationManagerObject.h>
+#include <ConfigurationManagerHelper.h>
+#include <Library/TableHelperLib.h>
+#include <Protocol/ConfigurationManagerProtocol.h>
+
+#include "SratGenerator.h"
+
+/**
+  ARM standard SRAT Generator
+
+  Requirements:
+    The following Configuration Manager Object(s) are used by this Generator:
+    - EArmObjGicCInfo (REQUIRED)
+    - EArmObjGicItsInfo (OPTIONAL)
+*/
+
+/** This macro expands to a function that retrieves the GIC
+    CPU interface Information from the Configuration Manager.
+*/
+GET_OBJECT_LIST (
+  EObjNameSpaceArm,
+  EArmObjGicCInfo,
+  CM_ARM_GICC_INFO
+  );
+
+/** This macro expands to a function that retrieves the GIC
+    Interrupt Translation Service Information from the
+    Configuration Manager.
+*/
+GET_OBJECT_LIST (
+  EObjNameSpaceArm,
+  EArmObjGicItsInfo,
+  CM_ARM_GIC_ITS_INFO
+  );
+
+/** Enum of the Arm specific CM objects required to
+    build the arch specific information of the SRAT table.
+*/
+typedef enum ArmSratSubTableType {
+  EArmGicCSubTableType,
+  EArmGicItsSubTableType,
+  EArmSubTableTypeMax,
+} EARM_SRAT_SUB_TABLE_TYPE;
+
+typedef struct SratSubTable {
+  /// Start offset of the arch specific sub-table.
+  UINT32    Offset;
+
+  /// Count
+  UINT32    Count;
+
+  /// Array of CmInfo objects of the relevant type.
+  VOID      *CmInfo;
+} SRAT_SUB_TABLE;
+
+STATIC SRAT_SUB_TABLE  mSratSubTable[EArmSubTableTypeMax];
+
+/** Reserve arch sub-tables space.
+
+  @param [in] CfgMgrProtocol   Pointer to the Configuration Manager
+  @param [in, out] ArchOffset  On input, contains the offset where arch specific
+                               sub-tables can be written. It is expected that
+                               there enough space to write all the arch specific
+                               sub-tables from this offset onward.
+                               On ouput, contains the ending offset of the arch
+                               specific sub-tables.
+
+  @retval EFI_SUCCESS           Table generated successfully.
+  @retval EFI_INVALID_PARAMETER A parameter is invalid.
+  @retval EFI_NOT_FOUND         The required object information is not found.
+  @retval EFI_BAD_BUFFER_SIZE   The size returned by the Configuration
+                                Manager is less than the Object size for the
+                                requested object.
+**/
+EFI_STATUS
+EFIAPI
+ArchReserveOffsets (
+  IN  CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol,
+  IN OUT UINT32                                           *ArchOffset
+  )
+{
+  EFI_STATUS  Status;
+
+  ASSERT (CfgMgrProtocol != NULL);
+  ASSERT (ArchOffset != NULL);
+
+  Status = GetEArmObjGicCInfo (
+             CfgMgrProtocol,
+             CM_NULL_TOKEN,
+             (CM_ARM_GICC_INFO **)&mSratSubTable[EArmGicCSubTableType].CmInfo,
+             &mSratSubTable[EArmGicCSubTableType].Count
+             );
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: SRAT: Failed to get GICC Info. Status = %r\n",
+      Status
+      ));
+    return Status;
+  }
+
+  if (mSratSubTable[EArmGicCSubTableType].Count == 0) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: SRAT: GIC CPU Interface information not provided.\n"
+      ));
+    ASSERT (0);
+    return EFI_INVALID_PARAMETER;
+  }
+
+  Status = GetEArmObjGicItsInfo (
+             CfgMgrProtocol,
+             CM_NULL_TOKEN,
+             (CM_ARM_GIC_ITS_INFO **)&mSratSubTable[EArmGicItsSubTableType].CmInfo,
+             &mSratSubTable[EArmGicItsSubTableType].Count
+             );
+  if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: SRAT: Failed to get GIC ITS Info. Status = %r\n",
+      Status
+      ));
+    return Status;
+  }
+
+  mSratSubTable[EArmGicCSubTableType].Offset = *ArchOffset;
+  *ArchOffset                               += (sizeof (EFI_ACPI_6_3_GICC_AFFINITY_STRUCTURE) *
+                                                mSratSubTable[EArmGicCSubTableType].Count);
+
+  if (mSratSubTable[EArmGicItsSubTableType].Count != 0) {
+    mSratSubTable[EArmGicItsSubTableType].Offset = *ArchOffset;
+    *ArchOffset                                 += (sizeof (EFI_ACPI_6_3_GIC_ITS_AFFINITY_STRUCTURE) *
+                                                    mSratSubTable[EArmGicItsSubTableType].Count);
+  }
+
+  return EFI_SUCCESS;
+}
+
+/** Add the GICC Affinity Structures in the SRAT Table.
+
+  @param [in]  CfgMgrProtocol   Pointer to the Configuration Manager
+                                Protocol Interface.
+  @param [in]  Srat             Pointer to the SRAT Table.
+**/
+STATIC
+VOID
+EFIAPI
+AddGICCAffinity (
+  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL         *CONST  CfgMgrProtocol,
+  IN EFI_ACPI_6_3_SYSTEM_RESOURCE_AFFINITY_TABLE_HEADER *CONST  Srat
+  )
+{
+  EFI_ACPI_6_3_GICC_AFFINITY_STRUCTURE  *GicCAff;
+  CM_ARM_GICC_INFO                      *GicCInfo;
+
+  GicCInfo = mSratSubTable[EArmGicCSubTableType].CmInfo;
+  GicCAff  = (EFI_ACPI_6_3_GICC_AFFINITY_STRUCTURE *)((UINT8 *)Srat +
+                                                      mSratSubTable[EArmGicCSubTableType].Offset);
+
+  while (mSratSubTable[EArmGicCSubTableType].Count-- != 0) {
+    DEBUG ((DEBUG_INFO, "SRAT: GicCAff = 0x%p\n", GicCAff));
+
+    GicCAff->Type             = EFI_ACPI_6_3_GICC_AFFINITY;
+    GicCAff->Length           = sizeof (EFI_ACPI_6_3_GICC_AFFINITY_STRUCTURE);
+    GicCAff->ProximityDomain  = GicCInfo->ProximityDomain;
+    GicCAff->AcpiProcessorUid = GicCInfo->AcpiProcessorUid;
+    GicCAff->Flags            = GicCInfo->AffinityFlags;
+    GicCAff->ClockDomain      = GicCInfo->ClockDomain;
+
+    // Next
+    GicCAff++;
+    GicCInfo++;
+  }// while
+}
+
+/** Add the GIC ITS Affinity Structures in the SRAT Table.
+
+  @param [in]  CfgMgrProtocol   Pointer to the Configuration Manager
+                                Protocol Interface.
+  @param [in]  Srat             Pointer to the SRAT Table.
+**/
+STATIC
+VOID
+EFIAPI
+AddGICItsAffinity (
+  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL         *CONST  CfgMgrProtocol,
+  IN EFI_ACPI_6_3_SYSTEM_RESOURCE_AFFINITY_TABLE_HEADER *CONST  Srat
+  )
+{
+  EFI_ACPI_6_3_GIC_ITS_AFFINITY_STRUCTURE  *GicItsAff;
+  CM_ARM_GIC_ITS_INFO                      *GicItsInfo;
+
+  GicItsInfo = mSratSubTable[EArmGicItsSubTableType].CmInfo;
+  GicItsAff  = (EFI_ACPI_6_3_GIC_ITS_AFFINITY_STRUCTURE *)((UINT8 *)Srat +
+                                                           mSratSubTable[EArmGicItsSubTableType].Offset);
+
+  while (mSratSubTable[EArmGicItsSubTableType].Count-- != 0) {
+    DEBUG ((DEBUG_INFO, "SRAT: GicItsAff = 0x%p\n", GicItsAff));
+
+    GicItsAff->Type            = EFI_ACPI_6_3_GIC_ITS_AFFINITY;
+    GicItsAff->Length          = sizeof (EFI_ACPI_6_3_GIC_ITS_AFFINITY_STRUCTURE);
+    GicItsAff->ProximityDomain = GicItsInfo->ProximityDomain;
+    GicItsAff->Reserved[0]     = EFI_ACPI_RESERVED_BYTE;
+    GicItsAff->Reserved[1]     = EFI_ACPI_RESERVED_BYTE;
+    GicItsAff->ItsId           = GicItsInfo->GicItsId;
+
+    // Next
+    GicItsAff++;
+    GicItsInfo++;
+  }// while
+}
+
+/** Add the arch specific sub-tables to the SRAT table.
+
+  These sub-tables are written in the space reserved beforehand.
+
+  @param [in]  CfgMgrProtocol   Pointer to the Configuration Manager
+                                Protocol Interface.
+  @param [in]  Srat             Pointer to the SRAT Table.
+
+  @retval EFI_SUCCESS           Table generated successfully.
+**/
+EFI_STATUS
+EFIAPI
+AddArchObjects (
+  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL         *CONST  CfgMgrProtocol,
+  IN EFI_ACPI_6_3_SYSTEM_RESOURCE_AFFINITY_TABLE_HEADER *CONST  Srat
+  )
+{
+  ASSERT (CfgMgrProtocol != NULL);
+  ASSERT (Srat != NULL);
+
+  AddGICCAffinity (CfgMgrProtocol, Srat);
+
+  if (mSratSubTable[EArmGicCSubTableType].Count != 0) {
+    AddGICItsAffinity (CfgMgrProtocol, Srat);
+  }
+
+  return EFI_SUCCESS;
+}
diff --git a/DynamicTablesPkg/Library/Acpi/Common/AcpiSratLib/Common/CommonSratGenerator.c b/DynamicTablesPkg/Library/Acpi/Common/AcpiSratLib/Common/CommonSratGenerator.c
new file mode 100644
index 000000000000..bc69fbf7f3bb
--- /dev/null
+++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiSratLib/Common/CommonSratGenerator.c
@@ -0,0 +1,77 @@
+/** @file
+  Common SRAT Table Generator
+
+  Copyright (c) 2019 - 2020, Arm Limited. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Reference(s):
+  - ACPI 6.3 Specification, January 2019
+
+  @par Glossary:
+  - Cm or CM   - Configuration Manager
+  - Obj or OBJ - Object
+**/
+
+#include <Library/AcpiLib.h>
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Protocol/AcpiTable.h>
+
+// Module specific include files.
+#include <AcpiTableGenerator.h>
+#include <ConfigurationManagerObject.h>
+#include <ConfigurationManagerHelper.h>
+#include <Library/TableHelperLib.h>
+#include <Protocol/ConfigurationManagerProtocol.h>
+
+#include "SratGenerator.h"
+
+/** Reserve arch sub-tables space.
+
+  @param [in] CfgMgrProtocol   Pointer to the Configuration Manager
+  @param [in, out] ArchOffset  On input, contains the offset where arch specific
+                               sub-tables can be written. It is expected that
+                               there enough space to write all the arch specific
+                               sub-tables from this offset onward.
+                               On ouput, contains the ending offset of the arch
+                               specific sub-tables.
+
+  @retval EFI_SUCCESS           Table generated successfully.
+  @retval EFI_INVALID_PARAMETER A parameter is invalid.
+  @retval EFI_NOT_FOUND         The required object information is not found.
+  @retval EFI_BAD_BUFFER_SIZE   The size returned by the Configuration
+                                Manager is less than the Object size for the
+                                requested object.
+**/
+EFI_STATUS
+EFIAPI
+ArchReserveOffsets (
+  IN  CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol,
+  IN OUT UINT32                                           *ArchOffset
+  )
+{
+  // Nothing to do.
+  return EFI_SUCCESS;
+}
+
+/** Add the arch specific sub-tables to the SRAT table.
+
+  These sub-tables are written in the space reserved beforehand.
+
+  @param [in]  CfgMgrProtocol   Pointer to the Configuration Manager
+                                Protocol Interface.
+  @param [in]  Srat             Pointer to the SRAT Table.
+
+  @retval EFI_SUCCESS           Table generated successfully.
+**/
+EFI_STATUS
+EFIAPI
+AddArchObjects (
+  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL         *CONST  CfgMgrProtocol,
+  IN EFI_ACPI_6_3_SYSTEM_RESOURCE_AFFINITY_TABLE_HEADER *CONST  Srat
+  )
+{
+  // Nothing to do.
+  return EFI_SUCCESS;
+}
diff --git a/DynamicTablesPkg/Library/Acpi/Common/AcpiSratLib/SratGenerator.c b/DynamicTablesPkg/Library/Acpi/Common/AcpiSratLib/SratGenerator.c
index 48c9970a7151..dcdacc4e966e 100644
--- a/DynamicTablesPkg/Library/Acpi/Common/AcpiSratLib/SratGenerator.c
+++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiSratLib/SratGenerator.c
@@ -25,38 +25,19 @@
 #include <Library/TableHelperLib.h>
 #include <Protocol/ConfigurationManagerProtocol.h>
 
+#include "SratGenerator.h"
+
 /**
-  ARM standard SRAT Generator
+  Standard SRAT Generator
 
   Requirements:
     The following Configuration Manager Object(s) are used by this Generator:
-    - EArmObjGicCInfo (REQUIRED)
-    - EArmObjGicItsInfo (OPTIONAL)
     - EArchCommonObjMemoryAffinityInfo (OPTIONAL)
     - EArchCommonObjGenericInitiatorAffinityInfo (OPTIONAL)
     - EArchCommonObjDeviceHandleAcpi (OPTIONAL)
     - EArchCommonObjDeviceHandlePci (OPTIONAL)
 */
 
-/** This macro expands to a function that retrieves the GIC
-    CPU interface Information from the Configuration Manager.
-*/
-GET_OBJECT_LIST (
-  EObjNameSpaceArm,
-  EArmObjGicCInfo,
-  CM_ARM_GICC_INFO
-  );
-
-/** This macro expands to a function that retrieves the GIC
-    Interrupt Translation Service Information from the
-    Configuration Manager.
-*/
-GET_OBJECT_LIST (
-  EObjNameSpaceArm,
-  EArmObjGicItsInfo,
-  CM_ARM_GIC_ITS_INFO
-  );
-
 /**
   This macro expands to a function that retrieves the Memory Affinity
   information from the Configuration Manager.
@@ -121,102 +102,6 @@ GetBdf (
   return Bdf;
 }
 
-/** Add the GICC Affinity Structures in the SRAT Table.
-
-  @param [in]  CfgMgrProtocol   Pointer to the Configuration Manager
-                                Protocol Interface.
-  @param [in]  Srat             Pointer to the SRAT Table.
-  @param [in]  GicCAffOffset    Offset of the GICC Affinity
-                                information in the SRAT Table.
-  @param [in]  GicCInfo         Pointer to the GIC CPU Information list.
-  @param [in]  GicCCount        Count of GIC CPU Interfaces.
-
-  @retval EFI_SUCCESS           Table generated successfully.
-**/
-STATIC
-EFI_STATUS
-AddGICCAffinity (
-  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL         *CONST  CfgMgrProtocol,
-  IN EFI_ACPI_6_3_SYSTEM_RESOURCE_AFFINITY_TABLE_HEADER *CONST  Srat,
-  IN CONST UINT32                                               GicCAffOffset,
-  IN CONST CM_ARM_GICC_INFO                                     *GicCInfo,
-  IN       UINT32                                               GicCCount
-  )
-{
-  EFI_ACPI_6_3_GICC_AFFINITY_STRUCTURE  *GicCAff;
-
-  ASSERT (Srat != NULL);
-  ASSERT (GicCInfo != NULL);
-
-  GicCAff = (EFI_ACPI_6_3_GICC_AFFINITY_STRUCTURE *)((UINT8 *)Srat +
-                                                     GicCAffOffset);
-
-  while (GicCCount-- != 0) {
-    DEBUG ((DEBUG_INFO, "SRAT: GicCAff = 0x%p\n", GicCAff));
-
-    GicCAff->Type             = EFI_ACPI_6_3_GICC_AFFINITY;
-    GicCAff->Length           = sizeof (EFI_ACPI_6_3_GICC_AFFINITY_STRUCTURE);
-    GicCAff->ProximityDomain  = GicCInfo->ProximityDomain;
-    GicCAff->AcpiProcessorUid = GicCInfo->AcpiProcessorUid;
-    GicCAff->Flags            = GicCInfo->AffinityFlags;
-    GicCAff->ClockDomain      = GicCInfo->ClockDomain;
-
-    // Next
-    GicCAff++;
-    GicCInfo++;
-  }// while
-
-  return EFI_SUCCESS;
-}
-
-/** Add the GIC ITS Affinity Structures in the SRAT Table.
-
-  @param [in]  CfgMgrProtocol   Pointer to the Configuration Manager
-                                Protocol Interface.
-  @param [in]  Srat             Pointer to the SRAT Table.
-  @param [in]  GicItsAffOffset  Offset of the GIC ITS Affinity
-                                information in the SRAT Table.
-  @param [in]  GicItsInfo       Pointer to the GIC ITS Information list.
-  @param [in]  GicItsCount      Count of GIC ITS.
-
-  @retval EFI_SUCCESS           Table generated successfully.
-**/
-STATIC
-EFI_STATUS
-AddGICItsAffinity (
-  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL         *CONST  CfgMgrProtocol,
-  IN EFI_ACPI_6_3_SYSTEM_RESOURCE_AFFINITY_TABLE_HEADER *CONST  Srat,
-  IN CONST UINT32                                               GicItsAffOffset,
-  IN CONST CM_ARM_GIC_ITS_INFO                                  *GicItsInfo,
-  IN       UINT32                                               GicItsCount
-  )
-{
-  EFI_ACPI_6_3_GIC_ITS_AFFINITY_STRUCTURE  *GicItsAff;
-
-  ASSERT (Srat != NULL);
-  ASSERT (GicItsInfo != NULL);
-
-  GicItsAff = (EFI_ACPI_6_3_GIC_ITS_AFFINITY_STRUCTURE *)((UINT8 *)Srat +
-                                                          GicItsAffOffset);
-
-  while (GicItsCount-- != 0) {
-    DEBUG ((DEBUG_INFO, "SRAT: GicItsAff = 0x%p\n", GicItsAff));
-
-    GicItsAff->Type            = EFI_ACPI_6_3_GIC_ITS_AFFINITY;
-    GicItsAff->Length          = sizeof (EFI_ACPI_6_3_GIC_ITS_AFFINITY_STRUCTURE);
-    GicItsAff->ProximityDomain = GicItsInfo->ProximityDomain;
-    GicItsAff->Reserved[0]     = EFI_ACPI_RESERVED_BYTE;
-    GicItsAff->Reserved[1]     = EFI_ACPI_RESERVED_BYTE;
-    GicItsAff->ItsId           = GicItsInfo->GicItsId;
-
-    // Next
-    GicItsAff++;
-    GicItsInfo++;
-  }// while
-
-  return EFI_SUCCESS;
-}
-
 /** Add the Memory Affinity Structures in the SRAT Table.
 
   @param [in]  CfgMgrProtocol   Pointer to the Configuration Manager
@@ -455,18 +340,12 @@ BuildSratTable (
 {
   EFI_STATUS  Status;
   UINT32      TableSize;
-  UINT32      GicCCount;
-  UINT32      GicItsCount;
   UINT32      MemAffCount;
   UINT32      GenInitiatorAffCount;
 
-  UINT32  GicCAffOffset;
-  UINT32  GicItsAffOffset;
   UINT32  MemAffOffset;
   UINT32  GenInitiatorAffOffset;
 
-  CM_ARM_GICC_INFO                                *GicCInfo;
-  CM_ARM_GIC_ITS_INFO                             *GicItsInfo;
   CM_ARCH_COMMON_MEMORY_AFFINITY_INFO             *MemAffInfo;
   CM_ARCH_COMMON_GENERIC_INITIATOR_AFFINITY_INFO  *GenInitiatorAffInfo;
 
@@ -497,46 +376,6 @@ BuildSratTable (
 
   *Table = NULL;
 
-  Status = GetEArmObjGicCInfo (
-             CfgMgrProtocol,
-             CM_NULL_TOKEN,
-             &GicCInfo,
-             &GicCCount
-             );
-  if (EFI_ERROR (Status)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: SRAT: Failed to get GICC Info. Status = %r\n",
-      Status
-      ));
-    goto error_handler;
-  }
-
-  if (GicCCount == 0) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: SRAT: GIC CPU Interface information not provided.\n"
-      ));
-    ASSERT (0);
-    Status = EFI_INVALID_PARAMETER;
-    goto error_handler;
-  }
-
-  Status = GetEArmObjGicItsInfo (
-             CfgMgrProtocol,
-             CM_NULL_TOKEN,
-             &GicItsInfo,
-             &GicItsCount
-             );
-  if (EFI_ERROR (Status) && (Status != EFI_NOT_FOUND)) {
-    DEBUG ((
-      DEBUG_ERROR,
-      "ERROR: SRAT: Failed to get GIC ITS Info. Status = %r\n",
-      Status
-      ));
-    goto error_handler;
-  }
-
   Status = GetEArchCommonObjMemoryAffinityInfo (
              CfgMgrProtocol,
              CM_NULL_TOKEN,
@@ -571,13 +410,18 @@ BuildSratTable (
   // Calculate the size of the SRAT table
   TableSize = sizeof (EFI_ACPI_6_3_SYSTEM_RESOURCE_AFFINITY_TABLE_HEADER);
 
-  GicCAffOffset = TableSize;
-  TableSize    += (sizeof (EFI_ACPI_6_3_GICC_AFFINITY_STRUCTURE) * GicCCount);
-
-  if (GicItsCount != 0) {
-    GicItsAffOffset = TableSize;
-    TableSize      += (sizeof (EFI_ACPI_6_3_GIC_ITS_AFFINITY_STRUCTURE) *
-                       GicItsCount);
+  // Place the Arch specific subtables/structures first and
+  // reserve the offsets. The common subtables/structures
+  // are placed next.
+  Status = ArchReserveOffsets (CfgMgrProtocol, &TableSize);
+  if (EFI_ERROR (Status)) {
+    DEBUG ((
+      DEBUG_ERROR,
+      "ERROR: SRAT: Failed to reserve arch offsets."
+      " Status = %r\n",
+      Status
+      ));
+    goto error_handler;
   }
 
   if (MemAffCount != 0) {
@@ -636,40 +480,16 @@ BuildSratTable (
   Srat->Reserved1 = 1;
   Srat->Reserved2 = EFI_ACPI_RESERVED_QWORD;
 
-  Status = AddGICCAffinity (
-             CfgMgrProtocol,
-             Srat,
-             GicCAffOffset,
-             GicCInfo,
-             GicCCount
-             );
+  Status = AddArchObjects (CfgMgrProtocol, Srat);
   if (EFI_ERROR (Status)) {
     DEBUG ((
       DEBUG_ERROR,
-      "ERROR: SRAT: Failed to add GICC Affinity structures. Status = %r\n",
+      "ERROR: SRAT: Failed to add arch objects header. Status = %r\n",
       Status
       ));
     goto error_handler;
   }
 
-  if (GicItsCount != 0) {
-    Status = AddGICItsAffinity (
-               CfgMgrProtocol,
-               Srat,
-               GicItsAffOffset,
-               GicItsInfo,
-               GicItsCount
-               );
-    if (EFI_ERROR (Status)) {
-      DEBUG ((
-        DEBUG_ERROR,
-        "ERROR: SRAT: Failed to add GIC ITS Affinity structures. Status = %r\n",
-        Status
-        ));
-      goto error_handler;
-    }
-  }
-
   if (MemAffCount != 0) {
     Status = AddMemoryAffinity (
                CfgMgrProtocol,
diff --git a/DynamicTablesPkg/Library/Acpi/Common/AcpiSratLib/SratGenerator.h b/DynamicTablesPkg/Library/Acpi/Common/AcpiSratLib/SratGenerator.h
new file mode 100644
index 000000000000..106d0084947e
--- /dev/null
+++ b/DynamicTablesPkg/Library/Acpi/Common/AcpiSratLib/SratGenerator.h
@@ -0,0 +1,59 @@
+/** @file
+  SRAT Table Generator
+
+  Copyright (c) 2019 - 2020, Arm Limited. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Reference(s):
+  - ACPI 6.3 Specification, January 2019
+
+  @par Glossary:
+  - Cm or CM   - Configuration Manager
+  - Obj or OBJ - Object
+**/
+
+#ifndef SRAT_GENERATOR_H_
+#define SRAT_GENERATOR_H_
+
+/** Reserve arch sub-tables space.
+
+  @param [in] CfgMgrProtocol   Pointer to the Configuration Manager
+  @param [in, out] ArchOffset  On input, contains the offset where arch specific
+                               sub-tables can be written. It is expected that
+                               there enough space to write all the arch specific
+                               sub-tables from this offset onward.
+                               On ouput, contains the ending offset of the arch
+                               specific sub-tables.
+
+  @retval EFI_SUCCESS           Table generated successfully.
+  @retval EFI_INVALID_PARAMETER A parameter is invalid.
+  @retval EFI_NOT_FOUND         The required object information is not found.
+  @retval EFI_BAD_BUFFER_SIZE   The size returned by the Configuration
+                                Manager is less than the Object size for the
+                                requested object.
+**/
+EFI_STATUS
+EFIAPI
+ArchReserveOffsets (
+  IN  CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL  *CONST  CfgMgrProtocol,
+  IN OUT UINT32                                           *ArchOffset
+  );
+
+/** Add the arch specific sub-tables to the SRAT table.
+
+  These sub-tables are written in the space reserved beforehand.
+
+  @param [in]  CfgMgrProtocol   Pointer to the Configuration Manager
+                                Protocol Interface.
+  @param [in]  Srat             Pointer to the SRAT Table.
+
+  @retval EFI_SUCCESS           Table generated successfully.
+**/
+EFI_STATUS
+EFIAPI
+AddArchObjects (
+  IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL         *CONST  CfgMgrProtocol,
+  IN EFI_ACPI_6_3_SYSTEM_RESOURCE_AFFINITY_TABLE_HEADER *CONST  Srat
+  );
+
+#endif // SRAT_GENERATOR_H_
-- 
2.25.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#119638): https://edk2.groups.io/g/devel/message/119638
Mute This Topic: https://groups.io/mt/106770159/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



  parent reply	other threads:[~2024-06-19 22:07 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-19 22:06 [edk2-devel] [staging/dynamictables-reorg PATCH 00/15] Prepare libraries to support other archs PierreGondois
2024-06-19 22:06 ` [edk2-devel] [staging/dynamictables-reorg PATCH 01/15] DynamicTablesPkg: Acpi: Move generic libraries to common folder PierreGondois
2024-06-19 22:06 ` [edk2-devel] [staging/dynamictables-reorg PATCH 02/15] DynamicTablesPkg: Acpi: Prepare common libraries to support other archs PierreGondois
2024-06-19 22:06 ` [edk2-devel] [staging/dynamictables-reorg PATCH 03/15] DynamicTablesPkg: AcpiFadtLib: Prepare " PierreGondois
2024-06-19 22:06 ` [edk2-devel] [staging/dynamictables-reorg PATCH 04/15] DynamicTablesPkg: AcpiDbg2Lib: " PierreGondois
2024-06-19 22:06 ` [edk2-devel] [staging/dynamictables-reorg PATCH 05/15] DynamicTablesPkg: AcpiSpcrLib: " PierreGondois
2024-06-19 22:06 ` PierreGondois [this message]
2024-06-19 22:06 ` [edk2-devel] [staging/dynamictables-reorg PATCH 07/15] DynamicTablesPkg: AcpiSsdtCpuTopologyLib: Avoid dependency on GICC PierreGondois
2024-06-19 22:06 ` [edk2-devel] [staging/dynamictables-reorg PATCH 08/15] DynamicTablesPkg: DynamicTableManagerDxe: Refactor PresenceArray PierreGondois
2024-06-19 22:06 ` [edk2-devel] [staging/dynamictables-reorg PATCH 09/15] DynamicTablesPkg: FdtHwInfoParserLib: Move ARM parsers to Arm directory PierreGondois
2024-06-19 22:06 ` [edk2-devel] [staging/dynamictables-reorg PATCH 10/15] DynamicTablesPkg: FdtHwInfoParserLib: Refactor to prepare for other archs PierreGondois
2024-06-19 22:06 ` [edk2-devel] [staging/dynamictables-reorg PATCH 11/15] DynamicTablesPkg: FdtHwInfoParserLib: Make Pci parser arch neutral PierreGondois
2024-06-19 22:06 ` [edk2-devel] [staging/dynamictables-reorg PATCH 12/15] DynamicTablesPkg: FdtHwInfoParserLib: Make Serial Port " PierreGondois
2024-06-19 22:06 ` [edk2-devel] [staging/dynamictables-reorg PATCH 13/15] DynamicTablesPkg: FdtHwInfoParserLib: Move ArmLib.h to ArmGicCParser.c PierreGondois
2024-06-19 22:06 ` [edk2-devel] [staging/dynamictables-reorg PATCH 14/15] DynamicTablesPkg: FdtHwInfoParserLib: Move IRQ map to arch folder PierreGondois
2024-07-03  6:20   ` Sunil V L
2024-06-19 22:06 ` [edk2-devel] [staging/dynamictables-reorg PATCH 15/15] DynamicTablesPkg: FdtHwInfoParserLib: Create wrapper to get INTC addr cells PierreGondois
2024-07-03  6:50   ` Sunil V L
2024-07-03  7:36     ` Sami Mujawar
2024-07-03  9:08 ` [edk2-devel] [staging/dynamictables-reorg PATCH 00/15] Prepare libraries to support other archs Sami Mujawar
2024-07-03  9:36   ` Sunil V L
2024-07-03  9:39     ` Sami Mujawar
2024-07-03  9:43       ` Sunil V L
2024-07-03  9:55   ` PierreGondois

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=20240619220629.1994362-7-pierre.gondois@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