summaryrefslogtreecommitdiffstats
path: root/UefiCpuPkg/CpuMpPei/CpuMpPei.c
diff options
context:
space:
mode:
authorDun Tan <dun.tan@intel.com>2023-11-24 15:53:33 +0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2023-12-12 01:37:41 +0000
commite10f1f5a043a402fb2daf2091b8f725fd2951743 (patch)
treeba8c9dff39b0d48e523fb476cf15132b0b04aa02 /UefiCpuPkg/CpuMpPei/CpuMpPei.c
parentc02eed8e5a5497f26f2163d44c2239f5549f9fb0 (diff)
downloadedk2-e10f1f5a043a402fb2daf2091b8f725fd2951743.tar.gz
edk2-e10f1f5a043a402fb2daf2091b8f725fd2951743.tar.bz2
edk2-e10f1f5a043a402fb2daf2091b8f725fd2951743.zip
UefiCpuPkg: Build MpInfo2HOB in CpuMpPei
Build MpInfo2HOB in CpuMpPei module so that later PiSmmCpuDxe or other StandaloneMm module can consume the HOB. Since there might be more one gMpInformationHobGuid2 in HOB list, CpuMpPei create a gMpInformationHobGuid2 with 0 value NumberOfProcessors field in the end of the process to indicate it's the last MP_INFORMATION2_HOB. Signed-off-by: Dun Tan <dun.tan@intel.com> Cc: Eric Dong <eric.dong@intel.com> Reviewed-by: Ray Ni <ray.ni@intel.com> Cc: Rahul Kumar <rahul1.kumar@intel.com> Cc: Gerd Hoffmann <kraxel@redhat.com>
Diffstat (limited to 'UefiCpuPkg/CpuMpPei/CpuMpPei.c')
-rw-r--r--UefiCpuPkg/CpuMpPei/CpuMpPei.c91
1 files changed, 91 insertions, 0 deletions
diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.c b/UefiCpuPkg/CpuMpPei/CpuMpPei.c
index b504bea3cf..e96a76c9a5 100644
--- a/UefiCpuPkg/CpuMpPei/CpuMpPei.c
+++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.c
@@ -542,6 +542,92 @@ InitializeMpExceptionStackSwitchHandlers (
}
/**
+ Create gMpInformationHobGuid2.
+**/
+VOID
+BuildMpInformationHob (
+ VOID
+ )
+{
+ EFI_STATUS Status;
+ UINTN ProcessorIndex;
+ UINTN NumberOfProcessors;
+ UINTN NumberOfEnabledProcessors;
+ UINTN NumberOfProcessorsInHob;
+ UINTN MaxProcessorsPerHob;
+ MP_INFORMATION2_HOB_DATA *MpInformation2HobData;
+ MP_INFORMATION2_ENTRY *MpInformation2Entry;
+ UINTN Index;
+
+ ProcessorIndex = 0;
+ MpInformation2HobData = NULL;
+ MpInformation2Entry = NULL;
+
+ Status = MpInitLibGetNumberOfProcessors (&NumberOfProcessors, &NumberOfEnabledProcessors);
+ 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 gMpInformationHobGuid2 with 0 value NumberOfProcessors
+ // fields to indicate it's the last MP_INFORMATION2_HOB.
+ //
+ while (NumberOfProcessorsInHob != 0) {
+ NumberOfProcessorsInHob = MIN (NumberOfProcessors - ProcessorIndex, MaxProcessorsPerHob);
+ MpInformation2HobData = BuildGuidHob (
+ &gMpInformationHobGuid2,
+ sizeof (MP_INFORMATION2_HOB_DATA) + sizeof (MP_INFORMATION2_ENTRY) * NumberOfProcessorsInHob
+ );
+ ASSERT (MpInformation2HobData != NULL);
+
+ 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 = MpInitLibGetProcessorInfo (
+ (Index + ProcessorIndex) | CPU_V2_EXTENDED_TOPOLOGY,
+ &MpInformation2Entry->ProcessorInfo,
+ NULL
+ );
+ ASSERT_EFI_ERROR (Status);
+ DEBUG ((
+ DEBUG_INFO,
+ " Processor[%04d]: ProcessorId = 0x%lx, StatusFlag = 0x%x\n",
+ Index + ProcessorIndex,
+ MpInformation2Entry->ProcessorInfo.ProcessorId,
+ MpInformation2Entry->ProcessorInfo.StatusFlag
+ ));
+ 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;
+ }
+}
+
+/**
Initializes MP and exceptions handlers.
@param PeiServices The pointer to the PEI Services Table.
@@ -602,6 +688,11 @@ InitializeCpuMpWorker (
Status = PeiServicesInstallPpi (mPeiCpuMpPpiList);
ASSERT_EFI_ERROR (Status);
+ //
+ // Create gMpInformationHobGuid2
+ //
+ BuildMpInformationHob ();
+
return Status;
}