public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [edk2-devel] [edk2-platforms] [PATCH v1 0/2] Intel/MinPlatform: Add MpInfo2HobPei
@ 2024-05-09  0:09 Nate DeSimone
  2024-05-09  0:09 ` [edk2-devel] [edk2-platforms] [PATCH v1 1/2] MinPlatform: " Nate DeSimone
  2024-05-09  0:09 ` [edk2-devel] [edk2-platforms] [PATCH v1 2/2] AlderlakeOpenBoardPkg: Include MpInfo2HobPei Nate DeSimone
  0 siblings, 2 replies; 8+ messages in thread
From: Nate DeSimone @ 2024-05-09  0:09 UTC (permalink / raw)
  To: devel
  Cc: Sai Chaganty, Rosen Chuang, Saloni Kasbekar, Chasel Chiu,
	Liming Gao, Eric Dong

Newer versions of CpuMpPei produce the gMpInformation2HobGuid. This HOB is
required by newer implementations of the CPU DXE driver, however older
versions of CpuMpPei do not produce it. This can cause backwards
compatibiliity issues if the FSP binary was built with an older version of
EDK II and the OpenBoard code is built with the latest version of EDK II.

To solve this problem, this patch series introduces a new PEIM called
MpInfo2HobPei. This PEIM will check if CpuMpPei creates gMpInformation2HobGuid
and if it does not then MpInfo2HobPei will create it.

Cc: Sai Chaganty <rangasai.v.chaganty@intel.com>
Cc: Rosen Chuang <rosen.chuang@intel.com>
Cc: Saloni Kasbekar <saloni.kasbekar@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Eric Dong <eric.dong@intel.com>
Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>

Nate DeSimone (2):
  MinPlatform: Add MpInfo2HobPei
  AlderlakeOpenBoardPkg: Include MpInfo2HobPei

 .../AlderlakePRvp/OpenBoardPkg.dsc            |  10 +-
 .../AlderlakePRvp/OpenBoardPkg.fdf            |  10 +-
 .../FspWrapper/MpInfo2HobPei/MpInfo2HobPei.c  | 236 ++++++++++++++++++
 .../MpInfo2HobPei/MpInfo2HobPei.inf           |  47 ++++
 .../Intel/MinPlatformPkg/MinPlatformPkg.dsc   |   3 +-
 5 files changed, 303 insertions(+), 3 deletions(-)
 create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.c
 create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.inf

-- 
2.44.0.windows.1



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



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

* [edk2-devel] [edk2-platforms] [PATCH v1 1/2] MinPlatform: Add MpInfo2HobPei
  2024-05-09  0:09 [edk2-devel] [edk2-platforms] [PATCH v1 0/2] Intel/MinPlatform: Add MpInfo2HobPei Nate DeSimone
@ 2024-05-09  0:09 ` Nate DeSimone
  2024-05-09 23:02   ` Chiu, Chasel
  2024-05-10  1:14   ` Chaganty, Rangasai V
  2024-05-09  0:09 ` [edk2-devel] [edk2-platforms] [PATCH v1 2/2] AlderlakeOpenBoardPkg: Include MpInfo2HobPei Nate DeSimone
  1 sibling, 2 replies; 8+ messages in thread
From: Nate DeSimone @ 2024-05-09  0:09 UTC (permalink / raw)
  To: devel
  Cc: Chasel Chiu, Liming Gao, Eric Dong, Sai Chaganty, Rosen Chuang,
	Saloni Kasbekar

MpInfo2HobPei provides backwards compatibility between FSP binaries built with
older versions of EDK II and the latest EDK II.

Newer versions of CpuMpPei produce the gMpInformation2HobGuid. This HOB is
required by newer implementations of the CPU DXE driver, however older
versions of CpuMpPei do not produce it. This PEIM will check if CpuMpPei
creates gMpInformation2HobGuid and if it does not it creates it.

Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Sai Chaganty <rangasai.v.chaganty@intel.com>
Cc: Rosen Chuang <rosen.chuang@intel.com>
Cc: Saloni Kasbekar <saloni.kasbekar@intel.com>
Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
---
 .../FspWrapper/MpInfo2HobPei/MpInfo2HobPei.c  | 236 ++++++++++++++++++
 .../MpInfo2HobPei/MpInfo2HobPei.inf           |  47 ++++
 .../Intel/MinPlatformPkg/MinPlatformPkg.dsc   |   3 +-
 3 files changed, 285 insertions(+), 1 deletion(-)
 create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.c
 create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.inf

diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.c b/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.c
new file mode 100644
index 0000000000..4cbc4cf7e6
--- /dev/null
+++ b/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.c
@@ -0,0 +1,236 @@
+/** @file
+  Multi-processor Info 2 HOB PEIM.
+
+  The purpose of this PEIM is to provide backwards compatibility between FSP
+  binaries built with older versions of EDK II and the latest EDK II.
+
+  Newer versions of CpuMpPei produce the gMpInformation2HobGuid. This HOB is
+  required by newer implementations of the CPU DXE driver, however older
+  versions of CpuMpPei do not produce it. This PEIM will check if CpuMpPei
+  creates gMpInformation2HobGuid and if it does not it creates it.
+
+Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.h>
+#include <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/HobLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/PeiServicesLib.h>
+
+#include <Ppi/MpServices2.h>
+#include <Guid/MpInformation2.h>
+#include <Register/Cpuid.h>
+
+typedef struct {
+  EDKII_PEI_MP_SERVICES2_PPI    *CpuMpPpi2;
+  UINT8                         *CoreTypes;
+} GET_PROCESSOR_CORE_TYPE_BUFFER;
+
+/**
+  Get CPU core type.
+
+  @param[in, out] Buffer  Argument of the procedure.
+**/
+VOID
+EFIAPI
+GetProcessorCoreType (
+  IN OUT VOID  *Buffer
+  )
+{
+  EFI_STATUS                               Status;
+  UINT8                                    *CoreTypes;
+  CPUID_NATIVE_MODEL_ID_AND_CORE_TYPE_EAX  NativeModelIdAndCoreTypeEax;
+  UINTN                                    ProcessorIndex;
+  GET_PROCESSOR_CORE_TYPE_BUFFER           *Params;
+
+  Params = (GET_PROCESSOR_CORE_TYPE_BUFFER *)Buffer;
+  Status = Params->CpuMpPpi2->WhoAmI (Params->CpuMpPpi2, &ProcessorIndex);
+  ASSERT_EFI_ERROR (Status);
+
+  CoreTypes = Params->CoreTypes;
+  AsmCpuidEx (CPUID_HYBRID_INFORMATION, CPUID_HYBRID_INFORMATION_MAIN_LEAF, &NativeModelIdAndCoreTypeEax.Uint32, NULL, NULL, NULL);
+  CoreTypes[ProcessorIndex] = (UINT8)NativeModelIdAndCoreTypeEax.Bits.CoreType;
+}
+
+/**
+  Create gMpInformation2HobGuid.
+**/
+VOID
+BuildMpInformationHob (
+  IN  EDKII_PEI_MP_SERVICES2_PPI  *CpuMpPpi2
+  )
+{
+  GET_PROCESSOR_CORE_TYPE_BUFFER  Buffer;
+  EFI_STATUS                      Status;
+  UINTN                           ProcessorIndex;
+  UINTN                           NumberOfProcessors;
+  UINTN                           NumberOfEnabledProcessors;
+  UINTN                           NumberOfProcessorsInHob;
+  UINTN                           MaxProcessorsPerHob;
+  MP_INFORMATION2_HOB_DATA        *MpInformation2HobData;
+  MP_INFORMATION2_ENTRY           *MpInformation2Entry;
+  UINTN                           Index;
+  UINT8                           *CoreTypes;
+  UINT32                          CpuidMaxInput;
+  UINTN                           CoreTypePages;
+
+  ProcessorIndex        = 0;
+  MpInformation2HobData = NULL;
+  MpInformation2Entry   = NULL;
+  CoreTypes             = NULL;
+  CoreTypePages         = 0;
+
+  Status = CpuMpPpi2->GetNumberOfProcessors (
+                        CpuMpPpi2,
+                        &NumberOfProcessors,
+                        &NumberOfEnabledProcessors
+                        );
+  ASSERT_EFI_ERROR (Status);
+  if (EFI_ERROR (Status)) {
+    goto Done;
+  }
+
+  //
+  // Get Processors CoreType
+  //
+  AsmCpuid (CPUID_SIGNATURE, &CpuidMaxInput, NULL, NULL, NULL);
+  if (CpuidMaxInput >= CPUID_HYBRID_INFORMATION) {
+    CoreTypePages = EFI_SIZE_TO_PAGES (sizeof (UINT8) * NumberOfProcessors);
+    CoreTypes     = AllocatePages (CoreTypePages);
+    ASSERT (CoreTypes != NULL);
+    if (CoreTypes == NULL) {
+      goto Done;
+    }
+
+    Buffer.CoreTypes = CoreTypes;
+    Buffer.CpuMpPpi2 = CpuMpPpi2;
+    Status           = CpuMpPpi2->StartupAllCPUs (
+                                    CpuMpPpi2,
+                                    GetProcessorCoreType,
+                                    0,
+                                    (VOID *)&Buffer
+                                    );
+    ASSERT_EFI_ERROR (Status);
+  }
+
+  MaxProcessorsPerHob     = ((MAX_UINT16 & ~7) - sizeof (EFI_HOB_GUID_TYPE) - sizeof (MP_INFORMATION2_HOB_DATA)) / sizeof (MP_INFORMATION2_ENTRY);
+  NumberOfProcessorsInHob = MaxProcessorsPerHob;
+
+  //
+  // Create MP_INFORMATION2_HOB. when the max HobLength 0xFFF8 is not enough, there
+  // will be a MP_INFORMATION2_HOB series in the HOB list.
+  // In the HOB list, there is a gMpInformation2HobGuid with 0 value NumberOfProcessors
+  // fields to indicate it's the last MP_INFORMATION2_HOB.
+  //
+  while (NumberOfProcessorsInHob != 0) {
+    NumberOfProcessorsInHob = MIN (NumberOfProcessors - ProcessorIndex, MaxProcessorsPerHob);
+    MpInformation2HobData   = BuildGuidHob (
+                                &gMpInformation2HobGuid,
+                                sizeof (MP_INFORMATION2_HOB_DATA) + sizeof (MP_INFORMATION2_ENTRY) * NumberOfProcessorsInHob
+                                );
+    ASSERT (MpInformation2HobData != NULL);
+    if (MpInformation2HobData == NULL) {
+      goto Done;
+    }
+
+    MpInformation2HobData->Version            = MP_INFORMATION2_HOB_REVISION;
+    MpInformation2HobData->ProcessorIndex     = ProcessorIndex;
+    MpInformation2HobData->NumberOfProcessors = (UINT16)NumberOfProcessorsInHob;
+    MpInformation2HobData->EntrySize          = sizeof (MP_INFORMATION2_ENTRY);
+
+    DEBUG ((DEBUG_INFO, "Creating MpInformation2 HOB...\n"));
+
+    for (Index = 0; Index < NumberOfProcessorsInHob; Index++) {
+      MpInformation2Entry = &MpInformation2HobData->Entry[Index];
+      Status              = CpuMpPpi2->GetProcessorInfo (
+                                         CpuMpPpi2,
+                                         (Index + ProcessorIndex) | CPU_V2_EXTENDED_TOPOLOGY,
+                                         &MpInformation2Entry->ProcessorInfo
+                                         );
+      ASSERT_EFI_ERROR (Status);
+
+      MpInformation2Entry->CoreType = (CoreTypes != NULL) ? CoreTypes[Index + ProcessorIndex] : 0;
+
+      DEBUG ((
+        DEBUG_INFO,
+        "  Processor[%04d]: ProcessorId = 0x%lx, StatusFlag = 0x%x, CoreType = 0x%x\n",
+        Index + ProcessorIndex,
+        MpInformation2Entry->ProcessorInfo.ProcessorId,
+        MpInformation2Entry->ProcessorInfo.StatusFlag,
+        MpInformation2Entry->CoreType
+        ));
+      DEBUG ((
+        DEBUG_INFO,
+        "    Location = Package:%d Core:%d Thread:%d\n",
+        MpInformation2Entry->ProcessorInfo.Location.Package,
+        MpInformation2Entry->ProcessorInfo.Location.Core,
+        MpInformation2Entry->ProcessorInfo.Location.Thread
+        ));
+      DEBUG ((
+        DEBUG_INFO,
+        "    Location2 = Package:%d Die:%d Tile:%d Module:%d Core:%d Thread:%d\n",
+        MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.Package,
+        MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.Die,
+        MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.Tile,
+        MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.Module,
+        MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.Core,
+        MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.Thread
+        ));
+    }
+
+    ProcessorIndex += NumberOfProcessorsInHob;
+  }
+
+Done:
+  if (CoreTypes != NULL) {
+    FreePages (CoreTypes, CoreTypePages);
+  }
+}
+
+/**
+  Check if CpuMpPei creates gMpInformation2HobGuid and if it does not it
+  creates it.
+
+  @param[in] ImageHandle    Handle for the image of this driver
+  @param[in] SystemTable    Pointer to the EFI System Table
+
+  @retval    EFI_UNSUPPORTED
+**/
+EFI_STATUS
+EFIAPI
+MpInfo2HobPeiEntryPoint (
+  IN       EFI_PEI_FILE_HANDLE  FileHandle,
+  IN CONST EFI_PEI_SERVICES     **PeiServices
+  )
+{
+  EFI_STATUS                  Status;
+  EFI_PEI_PPI_DESCRIPTOR      *TempPpiDescriptor;
+  EDKII_PEI_MP_SERVICES2_PPI  *CpuMpPpi2;
+  EFI_HOB_GUID_TYPE           *GuidHob;
+
+  Status = PeiServicesLocatePpi (
+             &gEdkiiPeiMpServices2PpiGuid,
+             0,
+             &TempPpiDescriptor,
+             (VOID **)&CpuMpPpi2
+             );
+  ASSERT_EFI_ERROR (Status);
+  if (EFI_ERROR (Status)) {
+    goto Done;
+  }
+
+  GuidHob = GetFirstGuidHob (&gMpInformation2HobGuid);
+  if (GuidHob == NULL) {
+    DEBUG ((DEBUG_INFO, "gMpInformation2HobGuid was not created by CpuMpPei, creating now\n"));
+    BuildMpInformationHob (CpuMpPpi2);
+  }
+
+Done:
+  return Status;
+}
diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.inf b/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.inf
new file mode 100644
index 0000000000..eecfdbf422
--- /dev/null
+++ b/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.inf
@@ -0,0 +1,47 @@
+### @file
+# Component information file for the Multi-processor Info 2 HOB PEIM.
+#
+# The purpose of this PEIM is to provide backwards compatibility between FSP
+# binaries built with older versions of EDK II and the latest EDK II.
+#
+# Newer versions of CpuMpPei produce the gMpInformation2HobGuid. This HOB is
+# required by newer implementations of the CPU DXE driver, however older
+# versions of CpuMpPei do not produce it. This PEIM will check if CpuMpPei
+# creates gMpInformation2HobGuid and if it does not it creates it.
+#
+# Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+###
+
+[Defines]
+  INF_VERSION                    = 0x00010017
+  BASE_NAME                      = MpInfo2HobPei
+  FILE_GUID                      = 010B5607-D5B3-4302-BCBC-C1A68087E9BE
+  VERSION_STRING                 = 1.0
+  MODULE_TYPE                    = PEIM
+  ENTRY_POINT                    = MpInfo2HobPeiEntryPoint
+
+[LibraryClasses]
+  PeimEntryPoint
+  DebugLib
+  MemoryAllocationLib
+  HobLib
+
+[Packages]
+  MdePkg/MdePkg.dec
+  UefiCpuPkg/UefiCpuPkg.dec
+  MinPlatformPkg/MinPlatformPkg.dec
+
+[Sources]
+  MpInfo2HobPei.c
+
+[Guids]
+  gMpInformation2HobGuid                        ## SOMETIMES_PRODUCES   ## HOB
+
+[Ppis]
+  gEdkiiPeiMpServices2PpiGuid                   ## CONSUMES
+
+[Depex]
+  gEdkiiPeiMpServices2PpiGuid
diff --git a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc
index ecb4d8f65e..30cdf1fb82 100644
--- a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc
+++ b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc
@@ -1,7 +1,7 @@
 ## @file
 #  Platform description.
 #
-# Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2017 - 2024, Intel Corporation. All rights reserved.<BR>
 # Copyright (c) Microsoft Corporation.<BR>
 #
 # SPDX-License-Identifier: BSD-2-Clause-Patent
@@ -150,6 +150,7 @@
   MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/DxePlatformBootManagerLib.inf
 
   MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig.inf
+  MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.inf
   MinPlatformPkg/FspWrapper/Library/PeiFspWrapperHobProcessLib/PeiFspWrapperHobProcessLib.inf
   MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecFspWrapperPlatformSecLib.inf
   MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformLib/PeiFspWrapperPlatformLib.inf
-- 
2.44.0.windows.1



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



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

* [edk2-devel] [edk2-platforms] [PATCH v1 2/2] AlderlakeOpenBoardPkg: Include MpInfo2HobPei
  2024-05-09  0:09 [edk2-devel] [edk2-platforms] [PATCH v1 0/2] Intel/MinPlatform: Add MpInfo2HobPei Nate DeSimone
  2024-05-09  0:09 ` [edk2-devel] [edk2-platforms] [PATCH v1 1/2] MinPlatform: " Nate DeSimone
@ 2024-05-09  0:09 ` Nate DeSimone
  2024-05-10 20:17   ` Chaganty, Rangasai V
  1 sibling, 1 reply; 8+ messages in thread
From: Nate DeSimone @ 2024-05-09  0:09 UTC (permalink / raw)
  To: devel
  Cc: Sai Chaganty, Rosen Chuang, Saloni Kasbekar, Chasel Chiu,
	Liming Gao, Eric Dong

Because Alder Lake FSP includes an older version of CpuMpPei MpInfo2HobPei
is needed to boot with newer versions of EDK II.

Accordingly, this change adds MpInfo2HobPei to FvPostMemory.

Cc: Sai Chaganty <rangasai.v.chaganty@intel.com>
Cc: Rosen Chuang <rosen.chuang@intel.com>
Cc: Saloni Kasbekar <saloni.kasbekar@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Eric Dong <eric.dong@intel.com>
Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
---
 .../AlderlakePRvp/OpenBoardPkg.dsc                     | 10 +++++++++-
 .../AlderlakePRvp/OpenBoardPkg.fdf                     | 10 +++++++++-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/Platform/Intel/AlderlakeOpenBoardPkg/AlderlakePRvp/OpenBoardPkg.dsc b/Platform/Intel/AlderlakeOpenBoardPkg/AlderlakePRvp/OpenBoardPkg.dsc
index edd03cba68..092cb34831 100644
--- a/Platform/Intel/AlderlakeOpenBoardPkg/AlderlakePRvp/OpenBoardPkg.dsc
+++ b/Platform/Intel/AlderlakeOpenBoardPkg/AlderlakePRvp/OpenBoardPkg.dsc
@@ -1,7 +1,7 @@
 ## @file
 #  The main build description file for the AlderlakePRvp board.
 #
-#   Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+#   Copyright (c) 2022 - 2024, Intel Corporation. All rights reserved.<BR>
 #   SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
@@ -342,6 +342,14 @@ ResetSystemLib|$(PLATFORM_SI_PACKAGE)/Pch/Library/BaseResetSystemLib/BaseResetSy
     <LibraryClasses>
   }
 
+  #
+  # ADL FSP includes an older version of CpuMpPei, so the compatibility PEIM
+  # is needed when using FSP Dispatch mode.
+  #
+!if gIntelFsp2WrapperTokenSpaceGuid.PcdFspModeSelection == 0
+  $(PLATFORM_PACKAGE)/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.inf
+!endif
+
 #
 # Security
 #
diff --git a/Platform/Intel/AlderlakeOpenBoardPkg/AlderlakePRvp/OpenBoardPkg.fdf b/Platform/Intel/AlderlakeOpenBoardPkg/AlderlakePRvp/OpenBoardPkg.fdf
index ae7896e5e0..c8ceb8684c 100644
--- a/Platform/Intel/AlderlakeOpenBoardPkg/AlderlakePRvp/OpenBoardPkg.fdf
+++ b/Platform/Intel/AlderlakeOpenBoardPkg/AlderlakePRvp/OpenBoardPkg.fdf
@@ -1,7 +1,7 @@
 ## @file
 #  FDF file of Platform.
 #
-#   Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+#   Copyright (c) 2022 - 2024, Intel Corporation. All rights reserved.<BR>
 #   SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
@@ -344,6 +344,14 @@ INF $(PLATFORM_BOARD_PACKAGE)/OpenBoardPlatformInit/OpenBoardPlatformInitPei/Ope
 INF $(PLATFORM_PACKAGE)/PlatformInit/SiliconPolicyPei/SiliconPolicyPeiPostMem.inf
 INF IntelFsp2WrapperPkg/FspsWrapperPeim/FspsWrapperPeim.inf
 
+#
+# ADL FSP includes an older version of CpuMpPei, so the compatibility PEIM
+# is needed when using FSP Dispatch mode.
+#
+!if gIntelFsp2WrapperTokenSpaceGuid.PcdFspModeSelection == 0
+  INF $(PLATFORM_PACKAGE)/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.inf
+!endif
+
 
 [FV.FvPostMemory]
 BlockSize          = $(FLASH_BLOCK_SIZE)
-- 
2.44.0.windows.1



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



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

* Re: [edk2-devel] [edk2-platforms] [PATCH v1 1/2] MinPlatform: Add MpInfo2HobPei
  2024-05-09  0:09 ` [edk2-devel] [edk2-platforms] [PATCH v1 1/2] MinPlatform: " Nate DeSimone
@ 2024-05-09 23:02   ` Chiu, Chasel
  2024-05-10  1:14   ` Chaganty, Rangasai V
  1 sibling, 0 replies; 8+ messages in thread
From: Chiu, Chasel @ 2024-05-09 23:02 UTC (permalink / raw)
  To: Desimone, Nathaniel L, devel@edk2.groups.io
  Cc: Liming Gao, Dong, Eric, Chaganty, Rangasai V, Chuang, Rosen,
	Kasbekar, Saloni


Hi Nate,

Change looks good.
Reviewed-by: Chasel Chiu <chasel.chiu@intel.com>

Just one minor optimization you might consider in below inline when merging this patch series.

Thanks,
Chasel


> -----Original Message-----
> From: Desimone, Nathaniel L <nathaniel.l.desimone@intel.com>
> Sent: Wednesday, May 8, 2024 5:09 PM
> To: devel@edk2.groups.io
> Cc: Chiu, Chasel <chasel.chiu@intel.com>; Liming Gao
> <gaoliming@byosoft.com.cn>; Dong, Eric <eric.dong@intel.com>; Chaganty,
> Rangasai V <rangasai.v.chaganty@intel.com>; Chuang, Rosen
> <rosen.chuang@intel.com>; Kasbekar, Saloni <saloni.kasbekar@intel.com>
> Subject: [edk2-platforms] [PATCH v1 1/2] MinPlatform: Add MpInfo2HobPei
> 
> MpInfo2HobPei provides backwards compatibility between FSP binaries built with
> older versions of EDK II and the latest EDK II.
> 
> Newer versions of CpuMpPei produce the gMpInformation2HobGuid. This HOB is
> required by newer implementations of the CPU DXE driver, however older
> versions of CpuMpPei do not produce it. This PEIM will check if CpuMpPei creates
> gMpInformation2HobGuid and if it does not it creates it.
> 
> Cc: Chasel Chiu <chasel.chiu@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Sai Chaganty <rangasai.v.chaganty@intel.com>
> Cc: Rosen Chuang <rosen.chuang@intel.com>
> Cc: Saloni Kasbekar <saloni.kasbekar@intel.com>
> Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
> ---
>  .../FspWrapper/MpInfo2HobPei/MpInfo2HobPei.c  | 236 ++++++++++++++++++
>  .../MpInfo2HobPei/MpInfo2HobPei.inf           |  47 ++++
>  .../Intel/MinPlatformPkg/MinPlatformPkg.dsc   |   3 +-
>  3 files changed, 285 insertions(+), 1 deletion(-)  create mode 100644
> Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.c
>  create mode 100644
> Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.inf
> 
> diff --git
> a/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.c
> b/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.c
> new file mode 100644
> index 0000000000..4cbc4cf7e6
> --- /dev/null
> +++
> b/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobP
> +++ ei.c
> @@ -0,0 +1,236 @@
> +/** @file
> +  Multi-processor Info 2 HOB PEIM.
> +
> +  The purpose of this PEIM is to provide backwards compatibility
> + between FSP  binaries built with older versions of EDK II and the latest EDK II.
> +
> +  Newer versions of CpuMpPei produce the gMpInformation2HobGuid. This
> + HOB is  required by newer implementations of the CPU DXE driver,
> + however older  versions of CpuMpPei do not produce it. This PEIM will
> + check if CpuMpPei  creates gMpInformation2HobGuid and if it does not it
> creates it.
> +
> +Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
> +
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <Base.h>
> +#include <Uefi.h>
> +#include <Library/BaseLib.h>
> +#include <Library/HobLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/MemoryAllocationLib.h> #include
> +<Library/PeiServicesLib.h>
> +
> +#include <Ppi/MpServices2.h>
> +#include <Guid/MpInformation2.h>
> +#include <Register/Cpuid.h>
> +
> +typedef struct {
> +  EDKII_PEI_MP_SERVICES2_PPI    *CpuMpPpi2;
> +  UINT8                         *CoreTypes;
> +} GET_PROCESSOR_CORE_TYPE_BUFFER;
> +
> +/**
> +  Get CPU core type.
> +
> +  @param[in, out] Buffer  Argument of the procedure.
> +**/
> +VOID
> +EFIAPI
> +GetProcessorCoreType (
> +  IN OUT VOID  *Buffer
> +  )
> +{
> +  EFI_STATUS                               Status;
> +  UINT8                                    *CoreTypes;
> +  CPUID_NATIVE_MODEL_ID_AND_CORE_TYPE_EAX
> NativeModelIdAndCoreTypeEax;
> +  UINTN                                    ProcessorIndex;
> +  GET_PROCESSOR_CORE_TYPE_BUFFER           *Params;
> +
> +  Params = (GET_PROCESSOR_CORE_TYPE_BUFFER *)Buffer;  Status =
> + Params->CpuMpPpi2->WhoAmI (Params->CpuMpPpi2, &ProcessorIndex);
> + ASSERT_EFI_ERROR (Status);
> +
> +  CoreTypes = Params->CoreTypes;
> +  AsmCpuidEx (CPUID_HYBRID_INFORMATION,
> +CPUID_HYBRID_INFORMATION_MAIN_LEAF,
> +&NativeModelIdAndCoreTypeEax.Uint32, NULL, NULL, NULL);
> +  CoreTypes[ProcessorIndex] =
> +(UINT8)NativeModelIdAndCoreTypeEax.Bits.CoreType;
> +}
> +
> +/**
> +  Create gMpInformation2HobGuid.
> +**/
> +VOID
> +BuildMpInformationHob (
> +  IN  EDKII_PEI_MP_SERVICES2_PPI  *CpuMpPpi2
> +  )
> +{
> +  GET_PROCESSOR_CORE_TYPE_BUFFER  Buffer;
> +  EFI_STATUS                      Status;
> +  UINTN                           ProcessorIndex;
> +  UINTN                           NumberOfProcessors;
> +  UINTN                           NumberOfEnabledProcessors;
> +  UINTN                           NumberOfProcessorsInHob;
> +  UINTN                           MaxProcessorsPerHob;
> +  MP_INFORMATION2_HOB_DATA        *MpInformation2HobData;
> +  MP_INFORMATION2_ENTRY           *MpInformation2Entry;
> +  UINTN                           Index;
> +  UINT8                           *CoreTypes;
> +  UINT32                          CpuidMaxInput;
> +  UINTN                           CoreTypePages;
> +
> +  ProcessorIndex        = 0;
> +  MpInformation2HobData = NULL;
> +  MpInformation2Entry   = NULL;
> +  CoreTypes             = NULL;
> +  CoreTypePages         = 0;
> +
> +  Status = CpuMpPpi2->GetNumberOfProcessors (
> +                        CpuMpPpi2,
> +                        &NumberOfProcessors,
> +                        &NumberOfEnabledProcessors
> +                        );
> +  ASSERT_EFI_ERROR (Status);
> +  if (EFI_ERROR (Status)) {
> +    goto Done;
> +  }
> +
> +  //
> +  // Get Processors CoreType
> +  //
> +  AsmCpuid (CPUID_SIGNATURE, &CpuidMaxInput, NULL, NULL, NULL);  if
> + (CpuidMaxInput >= CPUID_HYBRID_INFORMATION) {
> +    CoreTypePages = EFI_SIZE_TO_PAGES (sizeof (UINT8) * NumberOfProcessors);
> +    CoreTypes     = AllocatePages (CoreTypePages);
> +    ASSERT (CoreTypes != NULL);
> +    if (CoreTypes == NULL) {
> +      goto Done;
> +    }
> +
> +    Buffer.CoreTypes = CoreTypes;
> +    Buffer.CpuMpPpi2 = CpuMpPpi2;
> +    Status           = CpuMpPpi2->StartupAllCPUs (
> +                                    CpuMpPpi2,
> +                                    GetProcessorCoreType,
> +                                    0,
> +                                    (VOID *)&Buffer
> +                                    );
> +    ASSERT_EFI_ERROR (Status);
> +  }
> +
> +  MaxProcessorsPerHob     = ((MAX_UINT16 & ~7) - sizeof
> (EFI_HOB_GUID_TYPE) - sizeof (MP_INFORMATION2_HOB_DATA)) / sizeof
> (MP_INFORMATION2_ENTRY);
> +  NumberOfProcessorsInHob = MaxProcessorsPerHob;
> +
> +  //
> +  // Create MP_INFORMATION2_HOB. when the max HobLength 0xFFF8 is not
> + enough, there  // will be a MP_INFORMATION2_HOB series in the HOB list.
> +  // In the HOB list, there is a gMpInformation2HobGuid with 0 value
> + NumberOfProcessors  // fields to indicate it's the last
> MP_INFORMATION2_HOB.
> +  //
> +  while (NumberOfProcessorsInHob != 0) {
> +    NumberOfProcessorsInHob = MIN (NumberOfProcessors - ProcessorIndex,
> MaxProcessorsPerHob);
> +    MpInformation2HobData   = BuildGuidHob (
> +                                &gMpInformation2HobGuid,
> +                                sizeof (MP_INFORMATION2_HOB_DATA) + sizeof
> (MP_INFORMATION2_ENTRY) * NumberOfProcessorsInHob
> +                                );
> +    ASSERT (MpInformation2HobData != NULL);
> +    if (MpInformation2HobData == NULL) {
> +      goto Done;
> +    }
> +
> +    MpInformation2HobData->Version            =
> MP_INFORMATION2_HOB_REVISION;
> +    MpInformation2HobData->ProcessorIndex     = ProcessorIndex;
> +    MpInformation2HobData->NumberOfProcessors =
> (UINT16)NumberOfProcessorsInHob;
> +    MpInformation2HobData->EntrySize          = sizeof
> (MP_INFORMATION2_ENTRY);
> +
> +    DEBUG ((DEBUG_INFO, "Creating MpInformation2 HOB...\n"));
> +
> +    for (Index = 0; Index < NumberOfProcessorsInHob; Index++) {
> +      MpInformation2Entry = &MpInformation2HobData->Entry[Index];
> +      Status              = CpuMpPpi2->GetProcessorInfo (
> +                                         CpuMpPpi2,
> +                                         (Index + ProcessorIndex) |
> CPU_V2_EXTENDED_TOPOLOGY,
> +                                         &MpInformation2Entry->ProcessorInfo
> +                                         );
> +      ASSERT_EFI_ERROR (Status);
> +
> +      MpInformation2Entry->CoreType = (CoreTypes != NULL) ?
> + CoreTypes[Index + ProcessorIndex] : 0;
> +
> +      DEBUG ((
> +        DEBUG_INFO,
> +        "  Processor[%04d]: ProcessorId = 0x%lx, StatusFlag = 0x%x, CoreType =
> 0x%x\n",
> +        Index + ProcessorIndex,
> +        MpInformation2Entry->ProcessorInfo.ProcessorId,
> +        MpInformation2Entry->ProcessorInfo.StatusFlag,
> +        MpInformation2Entry->CoreType
> +        ));
> +      DEBUG ((
> +        DEBUG_INFO,
> +        "    Location = Package:%d Core:%d Thread:%d\n",
> +        MpInformation2Entry->ProcessorInfo.Location.Package,
> +        MpInformation2Entry->ProcessorInfo.Location.Core,
> +        MpInformation2Entry->ProcessorInfo.Location.Thread
> +        ));
> +      DEBUG ((
> +        DEBUG_INFO,
> +        "    Location2 = Package:%d Die:%d Tile:%d Module:%d Core:%d
> Thread:%d\n",
> +        MpInformation2Entry-
> >ProcessorInfo.ExtendedInformation.Location2.Package,
> +        MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.Die,
> +        MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.Tile,
> +        MpInformation2Entry-
> >ProcessorInfo.ExtendedInformation.Location2.Module,
> +        MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.Core,
> +        MpInformation2Entry-
> >ProcessorInfo.ExtendedInformation.Location2.Thread
> +        ));
> +    }
> +
> +    ProcessorIndex += NumberOfProcessorsInHob;  }
> +
> +Done:
> +  if (CoreTypes != NULL) {
> +    FreePages (CoreTypes, CoreTypePages);
> +  }
> +}
> +
> +/**
> +  Check if CpuMpPei creates gMpInformation2HobGuid and if it does not
> +it
> +  creates it.
> +
> +  @param[in] ImageHandle    Handle for the image of this driver
> +  @param[in] SystemTable    Pointer to the EFI System Table
> +
> +  @retval    EFI_UNSUPPORTED
> +**/
> +EFI_STATUS
> +EFIAPI
> +MpInfo2HobPeiEntryPoint (
> +  IN       EFI_PEI_FILE_HANDLE  FileHandle,
> +  IN CONST EFI_PEI_SERVICES     **PeiServices
> +  )
> +{
> +  EFI_STATUS                  Status;
> +  EFI_PEI_PPI_DESCRIPTOR      *TempPpiDescriptor;
> +  EDKII_PEI_MP_SERVICES2_PPI  *CpuMpPpi2;
> +  EFI_HOB_GUID_TYPE           *GuidHob;
> +
> +  Status = PeiServicesLocatePpi (
> +             &gEdkiiPeiMpServices2PpiGuid,
> +             0,
> +             &TempPpiDescriptor,
> +             (VOID **)&CpuMpPpi2
> +             );
> +  ASSERT_EFI_ERROR (Status);
> +  if (EFI_ERROR (Status)) {
> +    goto Done;
> +  }
> +
> +  GuidHob = GetFirstGuidHob (&gMpInformation2HobGuid);  if (GuidHob ==
> + NULL) {


You might want to move PPI allocation code here as we only consume it when GuidHob == NULL.


> +    DEBUG ((DEBUG_INFO, "gMpInformation2HobGuid was not created by
> CpuMpPei, creating now\n"));
> +    BuildMpInformationHob (CpuMpPpi2);
> +  }
> +
> +Done:
> +  return Status;
> +}
> diff --git
> a/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.i
> nf
> b/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.i
> nf
> new file mode 100644
> index 0000000000..eecfdbf422
> --- /dev/null
> +++
> b/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobP
> +++ ei.inf
> @@ -0,0 +1,47 @@
> +### @file
> +# Component information file for the Multi-processor Info 2 HOB PEIM.
> +#
> +# The purpose of this PEIM is to provide backwards compatibility
> +between FSP # binaries built with older versions of EDK II and the latest EDK II.
> +#
> +# Newer versions of CpuMpPei produce the gMpInformation2HobGuid. This
> +HOB is # required by newer implementations of the CPU DXE driver,
> +however older # versions of CpuMpPei do not produce it. This PEIM will
> +check if CpuMpPei # creates gMpInformation2HobGuid and if it does not it
> creates it.
> +#
> +# Copyright (c) 2024, Intel Corporation. All rights reserved.<BR> # #
> +SPDX-License-Identifier: BSD-2-Clause-Patent # ###
> +
> +[Defines]
> +  INF_VERSION                    = 0x00010017
> +  BASE_NAME                      = MpInfo2HobPei
> +  FILE_GUID                      = 010B5607-D5B3-4302-BCBC-C1A68087E9BE
> +  VERSION_STRING                 = 1.0
> +  MODULE_TYPE                    = PEIM
> +  ENTRY_POINT                    = MpInfo2HobPeiEntryPoint
> +
> +[LibraryClasses]
> +  PeimEntryPoint
> +  DebugLib
> +  MemoryAllocationLib
> +  HobLib
> +
> +[Packages]
> +  MdePkg/MdePkg.dec
> +  UefiCpuPkg/UefiCpuPkg.dec
> +  MinPlatformPkg/MinPlatformPkg.dec
> +
> +[Sources]
> +  MpInfo2HobPei.c
> +
> +[Guids]
> +  gMpInformation2HobGuid                        ## SOMETIMES_PRODUCES   ## HOB
> +
> +[Ppis]
> +  gEdkiiPeiMpServices2PpiGuid                   ## CONSUMES
> +
> +[Depex]
> +  gEdkiiPeiMpServices2PpiGuid
> diff --git a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc
> b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc
> index ecb4d8f65e..30cdf1fb82 100644
> --- a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc
> +++ b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc
> @@ -1,7 +1,7 @@
>  ## @file
>  #  Platform description.
>  #
> -# Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.<BR>
> +# Copyright (c) 2017 - 2024, Intel Corporation. All rights
> +reserved.<BR>
>  # Copyright (c) Microsoft Corporation.<BR>  #  # SPDX-License-Identifier: BSD-2-
> Clause-Patent @@ -150,6 +150,7 @@
> 
> MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/DxePlatformBootMan
> agerLib.inf
> 
>    MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig.inf
> +  MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.inf
> 
> MinPlatformPkg/FspWrapper/Library/PeiFspWrapperHobProcessLib/PeiFspWrapp
> erHobProcessLib.inf
> 
> MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecFspWrap
> perPlatformSecLib.inf
> 
> MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformLib/PeiFspWrapper
> PlatformLib.inf
> --
> 2.44.0.windows.1



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



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

* Re: [edk2-devel] [edk2-platforms] [PATCH v1 1/2] MinPlatform: Add MpInfo2HobPei
  2024-05-09  0:09 ` [edk2-devel] [edk2-platforms] [PATCH v1 1/2] MinPlatform: " Nate DeSimone
  2024-05-09 23:02   ` Chiu, Chasel
@ 2024-05-10  1:14   ` Chaganty, Rangasai V
  2024-05-13 20:48     ` Nate DeSimone
  1 sibling, 1 reply; 8+ messages in thread
From: Chaganty, Rangasai V @ 2024-05-10  1:14 UTC (permalink / raw)
  To: Desimone, Nathaniel L, devel@edk2.groups.io
  Cc: Chiu, Chasel, Liming Gao, Dong, Eric, Chuang, Rosen,
	Kasbekar, Saloni

Hi Nate, 
Looks good. 
In addition to optimization suggested by Chasel to save unnecessary call to locate PPI, you might also want to consider checking for checking "no error" status for locate PPI and perhaps avoid a "goto" label.
With that, Reviewed-by: Sai Chaganty <rangasai.v.chaganty@intel.com> for the whole patch series. 

Thanks,
Sai


-----Original Message-----
From: Desimone, Nathaniel L <nathaniel.l.desimone@intel.com> 
Sent: Wednesday, May 8, 2024 5:09 PM
To: devel@edk2.groups.io
Cc: Chiu, Chasel <chasel.chiu@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>; Dong, Eric <eric.dong@intel.com>; Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>; Chuang, Rosen <rosen.chuang@intel.com>; Kasbekar, Saloni <saloni.kasbekar@intel.com>
Subject: [edk2-platforms] [PATCH v1 1/2] MinPlatform: Add MpInfo2HobPei

MpInfo2HobPei provides backwards compatibility between FSP binaries built with older versions of EDK II and the latest EDK II.

Newer versions of CpuMpPei produce the gMpInformation2HobGuid. This HOB is required by newer implementations of the CPU DXE driver, however older versions of CpuMpPei do not produce it. This PEIM will check if CpuMpPei creates gMpInformation2HobGuid and if it does not it creates it.

Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Eric Dong <eric.dong@intel.com>
Cc: Sai Chaganty <rangasai.v.chaganty@intel.com>
Cc: Rosen Chuang <rosen.chuang@intel.com>
Cc: Saloni Kasbekar <saloni.kasbekar@intel.com>
Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
---
 .../FspWrapper/MpInfo2HobPei/MpInfo2HobPei.c  | 236 ++++++++++++++++++
 .../MpInfo2HobPei/MpInfo2HobPei.inf           |  47 ++++
 .../Intel/MinPlatformPkg/MinPlatformPkg.dsc   |   3 +-
 3 files changed, 285 insertions(+), 1 deletion(-)  create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.c
 create mode 100644 Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.inf

diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.c b/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.c
new file mode 100644
index 0000000000..4cbc4cf7e6
--- /dev/null
+++ b/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobP
+++ ei.c
@@ -0,0 +1,236 @@
+/** @file
+  Multi-processor Info 2 HOB PEIM.
+
+  The purpose of this PEIM is to provide backwards compatibility 
+ between FSP  binaries built with older versions of EDK II and the latest EDK II.
+
+  Newer versions of CpuMpPei produce the gMpInformation2HobGuid. This 
+ HOB is  required by newer implementations of the CPU DXE driver, 
+ however older  versions of CpuMpPei do not produce it. This PEIM will 
+ check if CpuMpPei  creates gMpInformation2HobGuid and if it does not it creates it.
+
+Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
+
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.h>
+#include <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/HobLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h> #include 
+<Library/PeiServicesLib.h>
+
+#include <Ppi/MpServices2.h>
+#include <Guid/MpInformation2.h>
+#include <Register/Cpuid.h>
+
+typedef struct {
+  EDKII_PEI_MP_SERVICES2_PPI    *CpuMpPpi2;
+  UINT8                         *CoreTypes;
+} GET_PROCESSOR_CORE_TYPE_BUFFER;
+
+/**
+  Get CPU core type.
+
+  @param[in, out] Buffer  Argument of the procedure.
+**/
+VOID
+EFIAPI
+GetProcessorCoreType (
+  IN OUT VOID  *Buffer
+  )
+{
+  EFI_STATUS                               Status;
+  UINT8                                    *CoreTypes;
+  CPUID_NATIVE_MODEL_ID_AND_CORE_TYPE_EAX  NativeModelIdAndCoreTypeEax;
+  UINTN                                    ProcessorIndex;
+  GET_PROCESSOR_CORE_TYPE_BUFFER           *Params;
+
+  Params = (GET_PROCESSOR_CORE_TYPE_BUFFER *)Buffer;  Status = 
+ Params->CpuMpPpi2->WhoAmI (Params->CpuMpPpi2, &ProcessorIndex);  
+ ASSERT_EFI_ERROR (Status);
+
+  CoreTypes = Params->CoreTypes;
+  AsmCpuidEx (CPUID_HYBRID_INFORMATION, 
+CPUID_HYBRID_INFORMATION_MAIN_LEAF, 
+&NativeModelIdAndCoreTypeEax.Uint32, NULL, NULL, NULL);
+  CoreTypes[ProcessorIndex] = 
+(UINT8)NativeModelIdAndCoreTypeEax.Bits.CoreType;
+}
+
+/**
+  Create gMpInformation2HobGuid.
+**/
+VOID
+BuildMpInformationHob (
+  IN  EDKII_PEI_MP_SERVICES2_PPI  *CpuMpPpi2
+  )
+{
+  GET_PROCESSOR_CORE_TYPE_BUFFER  Buffer;
+  EFI_STATUS                      Status;
+  UINTN                           ProcessorIndex;
+  UINTN                           NumberOfProcessors;
+  UINTN                           NumberOfEnabledProcessors;
+  UINTN                           NumberOfProcessorsInHob;
+  UINTN                           MaxProcessorsPerHob;
+  MP_INFORMATION2_HOB_DATA        *MpInformation2HobData;
+  MP_INFORMATION2_ENTRY           *MpInformation2Entry;
+  UINTN                           Index;
+  UINT8                           *CoreTypes;
+  UINT32                          CpuidMaxInput;
+  UINTN                           CoreTypePages;
+
+  ProcessorIndex        = 0;
+  MpInformation2HobData = NULL;
+  MpInformation2Entry   = NULL;
+  CoreTypes             = NULL;
+  CoreTypePages         = 0;
+
+  Status = CpuMpPpi2->GetNumberOfProcessors (
+                        CpuMpPpi2,
+                        &NumberOfProcessors,
+                        &NumberOfEnabledProcessors
+                        );
+  ASSERT_EFI_ERROR (Status);
+  if (EFI_ERROR (Status)) {
+    goto Done;
+  }
+
+  //
+  // Get Processors CoreType
+  //
+  AsmCpuid (CPUID_SIGNATURE, &CpuidMaxInput, NULL, NULL, NULL);  if 
+ (CpuidMaxInput >= CPUID_HYBRID_INFORMATION) {
+    CoreTypePages = EFI_SIZE_TO_PAGES (sizeof (UINT8) * NumberOfProcessors);
+    CoreTypes     = AllocatePages (CoreTypePages);
+    ASSERT (CoreTypes != NULL);
+    if (CoreTypes == NULL) {
+      goto Done;
+    }
+
+    Buffer.CoreTypes = CoreTypes;
+    Buffer.CpuMpPpi2 = CpuMpPpi2;
+    Status           = CpuMpPpi2->StartupAllCPUs (
+                                    CpuMpPpi2,
+                                    GetProcessorCoreType,
+                                    0,
+                                    (VOID *)&Buffer
+                                    );
+    ASSERT_EFI_ERROR (Status);
+  }
+
+  MaxProcessorsPerHob     = ((MAX_UINT16 & ~7) - sizeof (EFI_HOB_GUID_TYPE) - sizeof (MP_INFORMATION2_HOB_DATA)) / sizeof (MP_INFORMATION2_ENTRY);
+  NumberOfProcessorsInHob = MaxProcessorsPerHob;
+
+  //
+  // Create MP_INFORMATION2_HOB. when the max HobLength 0xFFF8 is not 
+ enough, there  // will be a MP_INFORMATION2_HOB series in the HOB list.
+  // In the HOB list, there is a gMpInformation2HobGuid with 0 value 
+ NumberOfProcessors  // fields to indicate it's the last MP_INFORMATION2_HOB.
+  //
+  while (NumberOfProcessorsInHob != 0) {
+    NumberOfProcessorsInHob = MIN (NumberOfProcessors - ProcessorIndex, MaxProcessorsPerHob);
+    MpInformation2HobData   = BuildGuidHob (
+                                &gMpInformation2HobGuid,
+                                sizeof (MP_INFORMATION2_HOB_DATA) + sizeof (MP_INFORMATION2_ENTRY) * NumberOfProcessorsInHob
+                                );
+    ASSERT (MpInformation2HobData != NULL);
+    if (MpInformation2HobData == NULL) {
+      goto Done;
+    }
+
+    MpInformation2HobData->Version            = MP_INFORMATION2_HOB_REVISION;
+    MpInformation2HobData->ProcessorIndex     = ProcessorIndex;
+    MpInformation2HobData->NumberOfProcessors = (UINT16)NumberOfProcessorsInHob;
+    MpInformation2HobData->EntrySize          = sizeof (MP_INFORMATION2_ENTRY);
+
+    DEBUG ((DEBUG_INFO, "Creating MpInformation2 HOB...\n"));
+
+    for (Index = 0; Index < NumberOfProcessorsInHob; Index++) {
+      MpInformation2Entry = &MpInformation2HobData->Entry[Index];
+      Status              = CpuMpPpi2->GetProcessorInfo (
+                                         CpuMpPpi2,
+                                         (Index + ProcessorIndex) | CPU_V2_EXTENDED_TOPOLOGY,
+                                         &MpInformation2Entry->ProcessorInfo
+                                         );
+      ASSERT_EFI_ERROR (Status);
+
+      MpInformation2Entry->CoreType = (CoreTypes != NULL) ? 
+ CoreTypes[Index + ProcessorIndex] : 0;
+
+      DEBUG ((
+        DEBUG_INFO,
+        "  Processor[%04d]: ProcessorId = 0x%lx, StatusFlag = 0x%x, CoreType = 0x%x\n",
+        Index + ProcessorIndex,
+        MpInformation2Entry->ProcessorInfo.ProcessorId,
+        MpInformation2Entry->ProcessorInfo.StatusFlag,
+        MpInformation2Entry->CoreType
+        ));
+      DEBUG ((
+        DEBUG_INFO,
+        "    Location = Package:%d Core:%d Thread:%d\n",
+        MpInformation2Entry->ProcessorInfo.Location.Package,
+        MpInformation2Entry->ProcessorInfo.Location.Core,
+        MpInformation2Entry->ProcessorInfo.Location.Thread
+        ));
+      DEBUG ((
+        DEBUG_INFO,
+        "    Location2 = Package:%d Die:%d Tile:%d Module:%d Core:%d Thread:%d\n",
+        MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.Package,
+        MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.Die,
+        MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.Tile,
+        MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.Module,
+        MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.Core,
+        MpInformation2Entry->ProcessorInfo.ExtendedInformation.Location2.Thread
+        ));
+    }
+
+    ProcessorIndex += NumberOfProcessorsInHob;  }
+
+Done:
+  if (CoreTypes != NULL) {
+    FreePages (CoreTypes, CoreTypePages);
+  }
+}
+
+/**
+  Check if CpuMpPei creates gMpInformation2HobGuid and if it does not 
+it
+  creates it.
+
+  @param[in] ImageHandle    Handle for the image of this driver
+  @param[in] SystemTable    Pointer to the EFI System Table
+
+  @retval    EFI_UNSUPPORTED
+**/
+EFI_STATUS
+EFIAPI
+MpInfo2HobPeiEntryPoint (
+  IN       EFI_PEI_FILE_HANDLE  FileHandle,
+  IN CONST EFI_PEI_SERVICES     **PeiServices
+  )
+{
+  EFI_STATUS                  Status;
+  EFI_PEI_PPI_DESCRIPTOR      *TempPpiDescriptor;
+  EDKII_PEI_MP_SERVICES2_PPI  *CpuMpPpi2;
+  EFI_HOB_GUID_TYPE           *GuidHob;
+
+  Status = PeiServicesLocatePpi (
+             &gEdkiiPeiMpServices2PpiGuid,
+             0,
+             &TempPpiDescriptor,
+             (VOID **)&CpuMpPpi2
+             );
+  ASSERT_EFI_ERROR (Status);
+  if (EFI_ERROR (Status)) {
+    goto Done;
+  }
+
+  GuidHob = GetFirstGuidHob (&gMpInformation2HobGuid);  if (GuidHob == 
+ NULL) {
+    DEBUG ((DEBUG_INFO, "gMpInformation2HobGuid was not created by CpuMpPei, creating now\n"));
+    BuildMpInformationHob (CpuMpPpi2);
+  }
+
+Done:
+  return Status;
+}
diff --git a/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.inf b/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.inf
new file mode 100644
index 0000000000..eecfdbf422
--- /dev/null
+++ b/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobP
+++ ei.inf
@@ -0,0 +1,47 @@
+### @file
+# Component information file for the Multi-processor Info 2 HOB PEIM.
+#
+# The purpose of this PEIM is to provide backwards compatibility 
+between FSP # binaries built with older versions of EDK II and the latest EDK II.
+#
+# Newer versions of CpuMpPei produce the gMpInformation2HobGuid. This 
+HOB is # required by newer implementations of the CPU DXE driver, 
+however older # versions of CpuMpPei do not produce it. This PEIM will 
+check if CpuMpPei # creates gMpInformation2HobGuid and if it does not it creates it.
+#
+# Copyright (c) 2024, Intel Corporation. All rights reserved.<BR> # # 
+SPDX-License-Identifier: BSD-2-Clause-Patent # ###
+
+[Defines]
+  INF_VERSION                    = 0x00010017
+  BASE_NAME                      = MpInfo2HobPei
+  FILE_GUID                      = 010B5607-D5B3-4302-BCBC-C1A68087E9BE
+  VERSION_STRING                 = 1.0
+  MODULE_TYPE                    = PEIM
+  ENTRY_POINT                    = MpInfo2HobPeiEntryPoint
+
+[LibraryClasses]
+  PeimEntryPoint
+  DebugLib
+  MemoryAllocationLib
+  HobLib
+
+[Packages]
+  MdePkg/MdePkg.dec
+  UefiCpuPkg/UefiCpuPkg.dec
+  MinPlatformPkg/MinPlatformPkg.dec
+
+[Sources]
+  MpInfo2HobPei.c
+
+[Guids]
+  gMpInformation2HobGuid                        ## SOMETIMES_PRODUCES   ## HOB
+
+[Ppis]
+  gEdkiiPeiMpServices2PpiGuid                   ## CONSUMES
+
+[Depex]
+  gEdkiiPeiMpServices2PpiGuid
diff --git a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc
index ecb4d8f65e..30cdf1fb82 100644
--- a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc
+++ b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc
@@ -1,7 +1,7 @@
 ## @file
 #  Platform description.
 #
-# Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2017 - 2024, Intel Corporation. All rights 
+reserved.<BR>
 # Copyright (c) Microsoft Corporation.<BR>  #  # SPDX-License-Identifier: BSD-2-Clause-Patent @@ -150,6 +150,7 @@
   MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/DxePlatformBootManagerLib.inf
 
   MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig.inf
+  MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.inf
   MinPlatformPkg/FspWrapper/Library/PeiFspWrapperHobProcessLib/PeiFspWrapperHobProcessLib.inf
   MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecFspWrapperPlatformSecLib.inf
   MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformLib/PeiFspWrapperPlatformLib.inf
--
2.44.0.windows.1



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



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

* Re: [edk2-devel] [edk2-platforms] [PATCH v1 2/2] AlderlakeOpenBoardPkg: Include MpInfo2HobPei
  2024-05-09  0:09 ` [edk2-devel] [edk2-platforms] [PATCH v1 2/2] AlderlakeOpenBoardPkg: Include MpInfo2HobPei Nate DeSimone
@ 2024-05-10 20:17   ` Chaganty, Rangasai V
  0 siblings, 0 replies; 8+ messages in thread
From: Chaganty, Rangasai V @ 2024-05-10 20:17 UTC (permalink / raw)
  To: Desimone, Nathaniel L, devel@edk2.groups.io
  Cc: Chuang, Rosen, Kasbekar, Saloni, Chiu, Chasel, Liming Gao,
	Dong, Eric

Reviewed-by: Sai Chaganty <rangasai.v.chaganty@intel.com>

-----Original Message-----
From: Desimone, Nathaniel L <nathaniel.l.desimone@intel.com> 
Sent: Wednesday, May 08, 2024 5:09 PM
To: devel@edk2.groups.io
Cc: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>; Chuang, Rosen <rosen.chuang@intel.com>; Kasbekar, Saloni <saloni.kasbekar@intel.com>; Chiu, Chasel <chasel.chiu@intel.com>; Liming Gao <gaoliming@byosoft.com.cn>; Dong, Eric <eric.dong@intel.com>
Subject: [edk2-platforms] [PATCH v1 2/2] AlderlakeOpenBoardPkg: Include MpInfo2HobPei

Because Alder Lake FSP includes an older version of CpuMpPei MpInfo2HobPei is needed to boot with newer versions of EDK II.

Accordingly, this change adds MpInfo2HobPei to FvPostMemory.

Cc: Sai Chaganty <rangasai.v.chaganty@intel.com>
Cc: Rosen Chuang <rosen.chuang@intel.com>
Cc: Saloni Kasbekar <saloni.kasbekar@intel.com>
Cc: Chasel Chiu <chasel.chiu@intel.com>
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Eric Dong <eric.dong@intel.com>
Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
---
 .../AlderlakePRvp/OpenBoardPkg.dsc                     | 10 +++++++++-
 .../AlderlakePRvp/OpenBoardPkg.fdf                     | 10 +++++++++-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/Platform/Intel/AlderlakeOpenBoardPkg/AlderlakePRvp/OpenBoardPkg.dsc b/Platform/Intel/AlderlakeOpenBoardPkg/AlderlakePRvp/OpenBoardPkg.dsc
index edd03cba68..092cb34831 100644
--- a/Platform/Intel/AlderlakeOpenBoardPkg/AlderlakePRvp/OpenBoardPkg.dsc
+++ b/Platform/Intel/AlderlakeOpenBoardPkg/AlderlakePRvp/OpenBoardPkg.ds
+++ c
@@ -1,7 +1,7 @@
 ## @file
 #  The main build description file for the AlderlakePRvp board.
 #
-#   Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+#   Copyright (c) 2022 - 2024, Intel Corporation. All rights reserved.<BR>
 #   SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
@@ -342,6 +342,14 @@ ResetSystemLib|$(PLATFORM_SI_PACKAGE)/Pch/Library/BaseResetSystemLib/BaseResetSy
     <LibraryClasses>
   }
 
+  #
+  # ADL FSP includes an older version of CpuMpPei, so the compatibility 
+PEIM
+  # is needed when using FSP Dispatch mode.
+  #
+!if gIntelFsp2WrapperTokenSpaceGuid.PcdFspModeSelection == 0
+  $(PLATFORM_PACKAGE)/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.inf
+!endif
+
 #
 # Security
 #
diff --git a/Platform/Intel/AlderlakeOpenBoardPkg/AlderlakePRvp/OpenBoardPkg.fdf b/Platform/Intel/AlderlakeOpenBoardPkg/AlderlakePRvp/OpenBoardPkg.fdf
index ae7896e5e0..c8ceb8684c 100644
--- a/Platform/Intel/AlderlakeOpenBoardPkg/AlderlakePRvp/OpenBoardPkg.fdf
+++ b/Platform/Intel/AlderlakeOpenBoardPkg/AlderlakePRvp/OpenBoardPkg.fd
+++ f
@@ -1,7 +1,7 @@
 ## @file
 #  FDF file of Platform.
 #
-#   Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
+#   Copyright (c) 2022 - 2024, Intel Corporation. All rights reserved.<BR>
 #   SPDX-License-Identifier: BSD-2-Clause-Patent
 #
 ##
@@ -344,6 +344,14 @@ INF $(PLATFORM_BOARD_PACKAGE)/OpenBoardPlatformInit/OpenBoardPlatformInitPei/Ope
 INF $(PLATFORM_PACKAGE)/PlatformInit/SiliconPolicyPei/SiliconPolicyPeiPostMem.inf
 INF IntelFsp2WrapperPkg/FspsWrapperPeim/FspsWrapperPeim.inf
 
+#
+# ADL FSP includes an older version of CpuMpPei, so the compatibility 
+PEIM # is needed when using FSP Dispatch mode.
+#
+!if gIntelFsp2WrapperTokenSpaceGuid.PcdFspModeSelection == 0
+  INF $(PLATFORM_PACKAGE)/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.inf
+!endif
+
 
 [FV.FvPostMemory]
 BlockSize          = $(FLASH_BLOCK_SIZE)
--
2.44.0.windows.1



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



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

* Re: [edk2-devel] [edk2-platforms] [PATCH v1 0/2] Intel/MinPlatform: Add MpInfo2HobPei
       [not found] <17CDA9784D6773F8.18011@groups.io>
@ 2024-05-13 20:48 ` Nate DeSimone
  0 siblings, 0 replies; 8+ messages in thread
From: Nate DeSimone @ 2024-05-13 20:48 UTC (permalink / raw)
  To: devel@edk2.groups.io, Desimone, Nathaniel L
  Cc: Chaganty, Rangasai V, Chuang, Rosen, Kasbekar, Saloni,
	Chiu, Chasel, Liming Gao, Dong, Eric

The series has been pushed as c31962b~..0ba43d4

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Nate
> DeSimone
> Sent: Wednesday, May 8, 2024 5:09 PM
> To: devel@edk2.groups.io
> Cc: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>; Chuang, Rosen
> <rosen.chuang@intel.com>; Kasbekar, Saloni <saloni.kasbekar@intel.com>;
> Chiu, Chasel <chasel.chiu@intel.com>; Liming Gao
> <gaoliming@byosoft.com.cn>; Dong, Eric <eric.dong@intel.com>
> Subject: [edk2-devel] [edk2-platforms] [PATCH v1 0/2] Intel/MinPlatform:
> Add MpInfo2HobPei
> 
> Newer versions of CpuMpPei produce the gMpInformation2HobGuid. This
> HOB is required by newer implementations of the CPU DXE driver, however
> older versions of CpuMpPei do not produce it. This can cause backwards
> compatibiliity issues if the FSP binary was built with an older version of EDK II
> and the OpenBoard code is built with the latest version of EDK II.
> 
> To solve this problem, this patch series introduces a new PEIM called
> MpInfo2HobPei. This PEIM will check if CpuMpPei creates
> gMpInformation2HobGuid and if it does not then MpInfo2HobPei will create
> it.
> 
> Cc: Sai Chaganty <rangasai.v.chaganty@intel.com>
> Cc: Rosen Chuang <rosen.chuang@intel.com>
> Cc: Saloni Kasbekar <saloni.kasbekar@intel.com>
> Cc: Chasel Chiu <chasel.chiu@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Eric Dong <eric.dong@intel.com>
> Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
> 
> Nate DeSimone (2):
>   MinPlatform: Add MpInfo2HobPei
>   AlderlakeOpenBoardPkg: Include MpInfo2HobPei
> 
>  .../AlderlakePRvp/OpenBoardPkg.dsc            |  10 +-
>  .../AlderlakePRvp/OpenBoardPkg.fdf            |  10 +-
>  .../FspWrapper/MpInfo2HobPei/MpInfo2HobPei.c  | 236
> ++++++++++++++++++
>  .../MpInfo2HobPei/MpInfo2HobPei.inf           |  47 ++++
>  .../Intel/MinPlatformPkg/MinPlatformPkg.dsc   |   3 +-
>  5 files changed, 303 insertions(+), 3 deletions(-)  create mode 100644
> Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPe
> i.c
>  create mode 100644
> Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPe
> i.inf
> 
> --
> 2.44.0.windows.1
> 
> 
> 
> 
> 



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



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

* Re: [edk2-devel] [edk2-platforms] [PATCH v1 1/2] MinPlatform: Add MpInfo2HobPei
  2024-05-10  1:14   ` Chaganty, Rangasai V
@ 2024-05-13 20:48     ` Nate DeSimone
  0 siblings, 0 replies; 8+ messages in thread
From: Nate DeSimone @ 2024-05-13 20:48 UTC (permalink / raw)
  To: Chaganty, Rangasai V, devel@edk2.groups.io
  Cc: Chiu, Chasel, Liming Gao, Dong, Eric, Chuang, Rosen,
	Kasbekar, Saloni

Thanks for the feedback Chasel and Sai! I have incorporated all your suggestions.

> -----Original Message-----
> From: Chaganty, Rangasai V <rangasai.v.chaganty@intel.com>
> Sent: Thursday, May 9, 2024 6:15 PM
> To: Desimone, Nathaniel L <nathaniel.l.desimone@intel.com>;
> devel@edk2.groups.io
> Cc: Chiu, Chasel <chasel.chiu@intel.com>; Liming Gao
> <gaoliming@byosoft.com.cn>; Dong, Eric <eric.dong@intel.com>; Chuang,
> Rosen <rosen.chuang@intel.com>; Kasbekar, Saloni
> <saloni.kasbekar@intel.com>
> Subject: RE: [edk2-platforms] [PATCH v1 1/2] MinPlatform: Add
> MpInfo2HobPei
> 
> Hi Nate,
> Looks good.
> In addition to optimization suggested by Chasel to save unnecessary call to
> locate PPI, you might also want to consider checking for checking "no error"
> status for locate PPI and perhaps avoid a "goto" label.
> With that, Reviewed-by: Sai Chaganty <rangasai.v.chaganty@intel.com> for
> the whole patch series.
> 
> Thanks,
> Sai
> 
> 
> -----Original Message-----
> From: Desimone, Nathaniel L <nathaniel.l.desimone@intel.com>
> Sent: Wednesday, May 8, 2024 5:09 PM
> To: devel@edk2.groups.io
> Cc: Chiu, Chasel <chasel.chiu@intel.com>; Liming Gao
> <gaoliming@byosoft.com.cn>; Dong, Eric <eric.dong@intel.com>; Chaganty,
> Rangasai V <rangasai.v.chaganty@intel.com>; Chuang, Rosen
> <rosen.chuang@intel.com>; Kasbekar, Saloni <saloni.kasbekar@intel.com>
> Subject: [edk2-platforms] [PATCH v1 1/2] MinPlatform: Add MpInfo2HobPei
> 
> MpInfo2HobPei provides backwards compatibility between FSP binaries built
> with older versions of EDK II and the latest EDK II.
> 
> Newer versions of CpuMpPei produce the gMpInformation2HobGuid. This
> HOB is required by newer implementations of the CPU DXE driver, however
> older versions of CpuMpPei do not produce it. This PEIM will check if
> CpuMpPei creates gMpInformation2HobGuid and if it does not it creates it.
> 
> Cc: Chasel Chiu <chasel.chiu@intel.com>
> Cc: Liming Gao <gaoliming@byosoft.com.cn>
> Cc: Eric Dong <eric.dong@intel.com>
> Cc: Sai Chaganty <rangasai.v.chaganty@intel.com>
> Cc: Rosen Chuang <rosen.chuang@intel.com>
> Cc: Saloni Kasbekar <saloni.kasbekar@intel.com>
> Signed-off-by: Nate DeSimone <nathaniel.l.desimone@intel.com>
> ---
>  .../FspWrapper/MpInfo2HobPei/MpInfo2HobPei.c  | 236
> ++++++++++++++++++
>  .../MpInfo2HobPei/MpInfo2HobPei.inf           |  47 ++++
>  .../Intel/MinPlatformPkg/MinPlatformPkg.dsc   |   3 +-
>  3 files changed, 285 insertions(+), 1 deletion(-)  create mode 100644
> Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPe
> i.c
>  create mode 100644
> Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPe
> i.inf
> 
> diff --git
> a/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2Hob
> Pei.c
> b/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2Hob
> Pei.c
> new file mode 100644
> index 0000000000..4cbc4cf7e6
> --- /dev/null
> +++
> b/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2Hob
> P
> +++ ei.c
> @@ -0,0 +1,236 @@
> +/** @file
> +  Multi-processor Info 2 HOB PEIM.
> +
> +  The purpose of this PEIM is to provide backwards compatibility
> + between FSP  binaries built with older versions of EDK II and the latest EDK II.
> +
> +  Newer versions of CpuMpPei produce the gMpInformation2HobGuid. This
> + HOB is  required by newer implementations of the CPU DXE driver,
> + however older  versions of CpuMpPei do not produce it. This PEIM will
> + check if CpuMpPei  creates gMpInformation2HobGuid and if it does not it
> creates it.
> +
> +Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
> +
> +SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <Base.h>
> +#include <Uefi.h>
> +#include <Library/BaseLib.h>
> +#include <Library/HobLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/MemoryAllocationLib.h> #include
> +<Library/PeiServicesLib.h>
> +
> +#include <Ppi/MpServices2.h>
> +#include <Guid/MpInformation2.h>
> +#include <Register/Cpuid.h>
> +
> +typedef struct {
> +  EDKII_PEI_MP_SERVICES2_PPI    *CpuMpPpi2;
> +  UINT8                         *CoreTypes;
> +} GET_PROCESSOR_CORE_TYPE_BUFFER;
> +
> +/**
> +  Get CPU core type.
> +
> +  @param[in, out] Buffer  Argument of the procedure.
> +**/
> +VOID
> +EFIAPI
> +GetProcessorCoreType (
> +  IN OUT VOID  *Buffer
> +  )
> +{
> +  EFI_STATUS                               Status;
> +  UINT8                                    *CoreTypes;
> +  CPUID_NATIVE_MODEL_ID_AND_CORE_TYPE_EAX
> NativeModelIdAndCoreTypeEax;
> +  UINTN                                    ProcessorIndex;
> +  GET_PROCESSOR_CORE_TYPE_BUFFER           *Params;
> +
> +  Params = (GET_PROCESSOR_CORE_TYPE_BUFFER *)Buffer;  Status =
> + Params->CpuMpPpi2->WhoAmI (Params->CpuMpPpi2, &ProcessorIndex);
> + ASSERT_EFI_ERROR (Status);
> +
> +  CoreTypes = Params->CoreTypes;
> +  AsmCpuidEx (CPUID_HYBRID_INFORMATION,
> +CPUID_HYBRID_INFORMATION_MAIN_LEAF,
> +&NativeModelIdAndCoreTypeEax.Uint32, NULL, NULL, NULL);
> +  CoreTypes[ProcessorIndex] =
> +(UINT8)NativeModelIdAndCoreTypeEax.Bits.CoreType;
> +}
> +
> +/**
> +  Create gMpInformation2HobGuid.
> +**/
> +VOID
> +BuildMpInformationHob (
> +  IN  EDKII_PEI_MP_SERVICES2_PPI  *CpuMpPpi2
> +  )
> +{
> +  GET_PROCESSOR_CORE_TYPE_BUFFER  Buffer;
> +  EFI_STATUS                      Status;
> +  UINTN                           ProcessorIndex;
> +  UINTN                           NumberOfProcessors;
> +  UINTN                           NumberOfEnabledProcessors;
> +  UINTN                           NumberOfProcessorsInHob;
> +  UINTN                           MaxProcessorsPerHob;
> +  MP_INFORMATION2_HOB_DATA        *MpInformation2HobData;
> +  MP_INFORMATION2_ENTRY           *MpInformation2Entry;
> +  UINTN                           Index;
> +  UINT8                           *CoreTypes;
> +  UINT32                          CpuidMaxInput;
> +  UINTN                           CoreTypePages;
> +
> +  ProcessorIndex        = 0;
> +  MpInformation2HobData = NULL;
> +  MpInformation2Entry   = NULL;
> +  CoreTypes             = NULL;
> +  CoreTypePages         = 0;
> +
> +  Status = CpuMpPpi2->GetNumberOfProcessors (
> +                        CpuMpPpi2,
> +                        &NumberOfProcessors,
> +                        &NumberOfEnabledProcessors
> +                        );
> +  ASSERT_EFI_ERROR (Status);
> +  if (EFI_ERROR (Status)) {
> +    goto Done;
> +  }
> +
> +  //
> +  // Get Processors CoreType
> +  //
> +  AsmCpuid (CPUID_SIGNATURE, &CpuidMaxInput, NULL, NULL, NULL);  if
> + (CpuidMaxInput >= CPUID_HYBRID_INFORMATION) {
> +    CoreTypePages = EFI_SIZE_TO_PAGES (sizeof (UINT8) *
> NumberOfProcessors);
> +    CoreTypes     = AllocatePages (CoreTypePages);
> +    ASSERT (CoreTypes != NULL);
> +    if (CoreTypes == NULL) {
> +      goto Done;
> +    }
> +
> +    Buffer.CoreTypes = CoreTypes;
> +    Buffer.CpuMpPpi2 = CpuMpPpi2;
> +    Status           = CpuMpPpi2->StartupAllCPUs (
> +                                    CpuMpPpi2,
> +                                    GetProcessorCoreType,
> +                                    0,
> +                                    (VOID *)&Buffer
> +                                    );
> +    ASSERT_EFI_ERROR (Status);
> +  }
> +
> +  MaxProcessorsPerHob     = ((MAX_UINT16 & ~7) - sizeof
> (EFI_HOB_GUID_TYPE) - sizeof (MP_INFORMATION2_HOB_DATA)) / sizeof
> (MP_INFORMATION2_ENTRY);
> +  NumberOfProcessorsInHob = MaxProcessorsPerHob;
> +
> +  //
> +  // Create MP_INFORMATION2_HOB. when the max HobLength 0xFFF8 is
> not
> + enough, there  // will be a MP_INFORMATION2_HOB series in the HOB list.
> +  // In the HOB list, there is a gMpInformation2HobGuid with 0 value
> + NumberOfProcessors  // fields to indicate it's the last
> MP_INFORMATION2_HOB.
> +  //
> +  while (NumberOfProcessorsInHob != 0) {
> +    NumberOfProcessorsInHob = MIN (NumberOfProcessors -
> ProcessorIndex, MaxProcessorsPerHob);
> +    MpInformation2HobData   = BuildGuidHob (
> +                                &gMpInformation2HobGuid,
> +                                sizeof (MP_INFORMATION2_HOB_DATA) + sizeof
> (MP_INFORMATION2_ENTRY) * NumberOfProcessorsInHob
> +                                );
> +    ASSERT (MpInformation2HobData != NULL);
> +    if (MpInformation2HobData == NULL) {
> +      goto Done;
> +    }
> +
> +    MpInformation2HobData->Version            =
> MP_INFORMATION2_HOB_REVISION;
> +    MpInformation2HobData->ProcessorIndex     = ProcessorIndex;
> +    MpInformation2HobData->NumberOfProcessors =
> (UINT16)NumberOfProcessorsInHob;
> +    MpInformation2HobData->EntrySize          = sizeof
> (MP_INFORMATION2_ENTRY);
> +
> +    DEBUG ((DEBUG_INFO, "Creating MpInformation2 HOB...\n"));
> +
> +    for (Index = 0; Index < NumberOfProcessorsInHob; Index++) {
> +      MpInformation2Entry = &MpInformation2HobData->Entry[Index];
> +      Status              = CpuMpPpi2->GetProcessorInfo (
> +                                         CpuMpPpi2,
> +                                         (Index + ProcessorIndex) |
> CPU_V2_EXTENDED_TOPOLOGY,
> +                                         &MpInformation2Entry->ProcessorInfo
> +                                         );
> +      ASSERT_EFI_ERROR (Status);
> +
> +      MpInformation2Entry->CoreType = (CoreTypes != NULL) ?
> + CoreTypes[Index + ProcessorIndex] : 0;
> +
> +      DEBUG ((
> +        DEBUG_INFO,
> +        "  Processor[%04d]: ProcessorId = 0x%lx, StatusFlag = 0x%x, CoreType =
> 0x%x\n",
> +        Index + ProcessorIndex,
> +        MpInformation2Entry->ProcessorInfo.ProcessorId,
> +        MpInformation2Entry->ProcessorInfo.StatusFlag,
> +        MpInformation2Entry->CoreType
> +        ));
> +      DEBUG ((
> +        DEBUG_INFO,
> +        "    Location = Package:%d Core:%d Thread:%d\n",
> +        MpInformation2Entry->ProcessorInfo.Location.Package,
> +        MpInformation2Entry->ProcessorInfo.Location.Core,
> +        MpInformation2Entry->ProcessorInfo.Location.Thread
> +        ));
> +      DEBUG ((
> +        DEBUG_INFO,
> +        "    Location2 = Package:%d Die:%d Tile:%d Module:%d Core:%d
> Thread:%d\n",
> +        MpInformation2Entry-
> >ProcessorInfo.ExtendedInformation.Location2.Package,
> +        MpInformation2Entry-
> >ProcessorInfo.ExtendedInformation.Location2.Die,
> +        MpInformation2Entry-
> >ProcessorInfo.ExtendedInformation.Location2.Tile,
> +        MpInformation2Entry-
> >ProcessorInfo.ExtendedInformation.Location2.Module,
> +        MpInformation2Entry-
> >ProcessorInfo.ExtendedInformation.Location2.Core,
> +        MpInformation2Entry-
> >ProcessorInfo.ExtendedInformation.Location2.Thread
> +        ));
> +    }
> +
> +    ProcessorIndex += NumberOfProcessorsInHob;  }
> +
> +Done:
> +  if (CoreTypes != NULL) {
> +    FreePages (CoreTypes, CoreTypePages);
> +  }
> +}
> +
> +/**
> +  Check if CpuMpPei creates gMpInformation2HobGuid and if it does not
> +it
> +  creates it.
> +
> +  @param[in] ImageHandle    Handle for the image of this driver
> +  @param[in] SystemTable    Pointer to the EFI System Table
> +
> +  @retval    EFI_UNSUPPORTED
> +**/
> +EFI_STATUS
> +EFIAPI
> +MpInfo2HobPeiEntryPoint (
> +  IN       EFI_PEI_FILE_HANDLE  FileHandle,
> +  IN CONST EFI_PEI_SERVICES     **PeiServices
> +  )
> +{
> +  EFI_STATUS                  Status;
> +  EFI_PEI_PPI_DESCRIPTOR      *TempPpiDescriptor;
> +  EDKII_PEI_MP_SERVICES2_PPI  *CpuMpPpi2;
> +  EFI_HOB_GUID_TYPE           *GuidHob;
> +
> +  Status = PeiServicesLocatePpi (
> +             &gEdkiiPeiMpServices2PpiGuid,
> +             0,
> +             &TempPpiDescriptor,
> +             (VOID **)&CpuMpPpi2
> +             );
> +  ASSERT_EFI_ERROR (Status);
> +  if (EFI_ERROR (Status)) {
> +    goto Done;
> +  }
> +
> +  GuidHob = GetFirstGuidHob (&gMpInformation2HobGuid);  if (GuidHob ==
> + NULL) {
> +    DEBUG ((DEBUG_INFO, "gMpInformation2HobGuid was not created by
> CpuMpPei, creating now\n"));
> +    BuildMpInformationHob (CpuMpPpi2);
> +  }
> +
> +Done:
> +  return Status;
> +}
> diff --git
> a/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2Hob
> Pei.inf
> b/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2Hob
> Pei.inf
> new file mode 100644
> index 0000000000..eecfdbf422
> --- /dev/null
> +++
> b/Platform/Intel/MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2Hob
> P
> +++ ei.inf
> @@ -0,0 +1,47 @@
> +### @file
> +# Component information file for the Multi-processor Info 2 HOB PEIM.
> +#
> +# The purpose of this PEIM is to provide backwards compatibility
> +between FSP # binaries built with older versions of EDK II and the latest EDK
> II.
> +#
> +# Newer versions of CpuMpPei produce the gMpInformation2HobGuid. This
> +HOB is # required by newer implementations of the CPU DXE driver,
> +however older # versions of CpuMpPei do not produce it. This PEIM will
> +check if CpuMpPei # creates gMpInformation2HobGuid and if it does not it
> creates it.
> +#
> +# Copyright (c) 2024, Intel Corporation. All rights reserved.<BR> # #
> +SPDX-License-Identifier: BSD-2-Clause-Patent # ###
> +
> +[Defines]
> +  INF_VERSION                    = 0x00010017
> +  BASE_NAME                      = MpInfo2HobPei
> +  FILE_GUID                      = 010B5607-D5B3-4302-BCBC-C1A68087E9BE
> +  VERSION_STRING                 = 1.0
> +  MODULE_TYPE                    = PEIM
> +  ENTRY_POINT                    = MpInfo2HobPeiEntryPoint
> +
> +[LibraryClasses]
> +  PeimEntryPoint
> +  DebugLib
> +  MemoryAllocationLib
> +  HobLib
> +
> +[Packages]
> +  MdePkg/MdePkg.dec
> +  UefiCpuPkg/UefiCpuPkg.dec
> +  MinPlatformPkg/MinPlatformPkg.dec
> +
> +[Sources]
> +  MpInfo2HobPei.c
> +
> +[Guids]
> +  gMpInformation2HobGuid                        ## SOMETIMES_PRODUCES   ## HOB
> +
> +[Ppis]
> +  gEdkiiPeiMpServices2PpiGuid                   ## CONSUMES
> +
> +[Depex]
> +  gEdkiiPeiMpServices2PpiGuid
> diff --git a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc
> b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc
> index ecb4d8f65e..30cdf1fb82 100644
> --- a/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc
> +++ b/Platform/Intel/MinPlatformPkg/MinPlatformPkg.dsc
> @@ -1,7 +1,7 @@
>  ## @file
>  #  Platform description.
>  #
> -# Copyright (c) 2017 - 2021, Intel Corporation. All rights reserved.<BR>
> +# Copyright (c) 2017 - 2024, Intel Corporation. All rights
> +reserved.<BR>
>  # Copyright (c) Microsoft Corporation.<BR>  #  # SPDX-License-Identifier: BSD-
> 2-Clause-Patent @@ -150,6 +150,7 @@
> 
> MinPlatformPkg/Bds/Library/DxePlatformBootManagerLib/DxePlatformBoot
> ManagerLib.inf
> 
>    MinPlatformPkg/FspWrapper/SaveMemoryConfig/SaveMemoryConfig.inf
> +  MinPlatformPkg/FspWrapper/MpInfo2HobPei/MpInfo2HobPei.inf
> 
> MinPlatformPkg/FspWrapper/Library/PeiFspWrapperHobProcessLib/PeiFspW
> rapperHobProcessLib.inf
> 
> MinPlatformPkg/FspWrapper/Library/SecFspWrapperPlatformSecLib/SecFsp
> WrapperPlatformSecLib.inf
> 
> MinPlatformPkg/FspWrapper/Library/PeiFspWrapperPlatformLib/PeiFspWrap
> perPlatformLib.inf
> --
> 2.44.0.windows.1



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



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

end of thread, other threads:[~2024-05-13 20:48 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-05-09  0:09 [edk2-devel] [edk2-platforms] [PATCH v1 0/2] Intel/MinPlatform: Add MpInfo2HobPei Nate DeSimone
2024-05-09  0:09 ` [edk2-devel] [edk2-platforms] [PATCH v1 1/2] MinPlatform: " Nate DeSimone
2024-05-09 23:02   ` Chiu, Chasel
2024-05-10  1:14   ` Chaganty, Rangasai V
2024-05-13 20:48     ` Nate DeSimone
2024-05-09  0:09 ` [edk2-devel] [edk2-platforms] [PATCH v1 2/2] AlderlakeOpenBoardPkg: Include MpInfo2HobPei Nate DeSimone
2024-05-10 20:17   ` Chaganty, Rangasai V
     [not found] <17CDA9784D6773F8.18011@groups.io>
2024-05-13 20:48 ` [edk2-devel] [edk2-platforms] [PATCH v1 0/2] Intel/MinPlatform: Add MpInfo2HobPei Nate DeSimone

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