From: "duntan" <dun.tan@intel.com>
To: devel@edk2.groups.io
Cc: Eric Dong <eric.dong@intel.com>, Ray Ni <ray.ni@intel.com>,
Rahul Kumar <rahul1.kumar@intel.com>,
Gerd Hoffmann <kraxel@redhat.com>
Subject: [edk2-devel] [Patch V2 2/6] UefiCpuPkg: Build MpInfo2HOB in CpuMpPei
Date: Thu, 7 Dec 2023 15:32:27 +0800 [thread overview]
Message-ID: <20231207073230.264-3-dun.tan@intel.com> (raw)
In-Reply-To: <20231207073230.264-1-dun.tan@intel.com>
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>
Cc: Ray Ni <ray.ni@intel.com>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
---
UefiCpuPkg/CpuMpPei/CpuMpPei.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
UefiCpuPkg/CpuMpPei/CpuMpPei.h | 4 +++-
UefiCpuPkg/CpuMpPei/CpuMpPei.inf | 3 ++-
3 files changed, 96 insertions(+), 2 deletions(-)
diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.c b/UefiCpuPkg/CpuMpPei/CpuMpPei.c
index b504bea3cf..8cacf4ddf5 100644
--- a/UefiCpuPkg/CpuMpPei/CpuMpPei.c
+++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.c
@@ -541,6 +541,92 @@ InitializeMpExceptionStackSwitchHandlers (
FreePages (SwitchStackData, EFI_SIZE_TO_PAGES (NumberOfProcessors * sizeof (EXCEPTION_STACK_SWITCH_CONTEXT)));
}
+/**
+ 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/Core/Thread) = %d/%d/%d\n",
+ MpInformation2Entry->ProcessorInfo.Location.Package,
+ MpInformation2Entry->ProcessorInfo.Location.Core,
+ MpInformation2Entry->ProcessorInfo.Location.Thread
+ ));
+ DEBUG ((
+ DEBUG_INFO,
+ " Location2 (Package/Die/Tile/Module/Core/Thread) = %d/%d/%d/%d/%d/%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.
@@ -602,6 +688,11 @@ InitializeCpuMpWorker (
Status = PeiServicesInstallPpi (mPeiCpuMpPpiList);
ASSERT_EFI_ERROR (Status);
+ //
+ // Create gMpInformationHobGuid2
+ //
+ BuildMpInformationHob ();
+
return Status;
}
diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.h b/UefiCpuPkg/CpuMpPei/CpuMpPei.h
index 1b9a94e18f..a40fd2c077 100644
--- a/UefiCpuPkg/CpuMpPei/CpuMpPei.h
+++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.h
@@ -1,7 +1,7 @@
/** @file
Definitions to install Multiple Processor PPI.
- Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2015 - 2023, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
@@ -30,6 +30,8 @@
#include <Library/MemoryAllocationLib.h>
#include <Library/CpuPageTableLib.h>
+#include <Guid/MpInformation2.h>
+
extern EFI_PEI_PPI_DESCRIPTOR mPeiCpuMpPpiDesc;
/**
diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.inf b/UefiCpuPkg/CpuMpPei/CpuMpPei.inf
index 865be5627e..812fa179bd 100644
--- a/UefiCpuPkg/CpuMpPei/CpuMpPei.inf
+++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.inf
@@ -1,7 +1,7 @@
## @file
# CPU driver installs CPU PI Multi-processor PPI.
#
-# Copyright (c) 2015 - 2021, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2015 - 2023, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##
@@ -50,6 +50,7 @@
[Guids]
gEdkiiMigratedFvInfoGuid ## SOMETIMES_CONSUMES ## HOB
+ gMpInformationHobGuid2 ## PRODUCES
[Ppis]
gEfiPeiMpServicesPpiGuid ## PRODUCES
--
2.31.1.windows.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112161): https://edk2.groups.io/g/devel/message/112161
Mute This Topic: https://groups.io/mt/103030293/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
next prev parent reply other threads:[~2023-12-07 7:32 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-07 7:32 [edk2-devel] [Patch V2 0/6] Create and consume a new gMpInformationHobGuid2 in UefiCpuPkg duntan
2023-12-07 7:32 ` [edk2-devel] [Patch V2 1/6] UefiCpuPkg: Create " duntan
2023-12-08 8:24 ` Ni, Ray
2023-12-07 7:32 ` duntan [this message]
2023-12-07 7:32 ` [edk2-devel] [Patch V2 3/6] UefiCpuPkg: Consume MpInfo2Hob in PiSmmCpuDxe duntan
2023-12-08 8:17 ` Ni, Ray
2023-12-07 7:32 ` [edk2-devel] [Patch V2 5/6] UefiCpuPkg: Cache core type in MpInfo2 HOB duntan
2023-12-08 8:10 ` Ni, Ray
2023-12-07 7:32 ` [edk2-devel] [Patch V2 6/6] UefiCpuPkg: Avoid assuming only one smmbasehob duntan
2023-12-08 8:26 ` Ni, Ray
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=20231207073230.264-3-dun.tan@intel.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