Cache core type in MpInfo2 HOB by CpuMpPei module.
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 | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
UefiCpuPkg/CpuMpPei/CpuMpPei.h | 2 ++
2 files changed, 59 insertions(+), 2 deletions(-)
diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.c b/UefiCpuPkg/CpuMpPei/CpuMpPei.c
index 8cacf4ddf5..7e2d7efb6b 100644
--- a/UefiCpuPkg/CpuMpPei/CpuMpPei.c
+++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.c
@@ -541,6 +541,30 @@ InitializeMpExceptionStackSwitchHandlers (
FreePages (SwitchStackData, EFI_SIZE_TO_PAGES (NumberOfProcessors * sizeof (EXCEPTION_STACK_SWITCH_CONTEXT)));
}
+/**
+ 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;
+
+ Status = MpInitLibWhoAmI (&ProcessorIndex);
+ ASSERT_EFI_ERROR (Status);
+
+ CoreTypes = (UINT8 *)Buffer;
+ AsmCpuidEx (CPUID_HYBRID_INFORMATION, CPUID_HYBRID_INFORMATION_MAIN_LEAF, &NativeModelIdAndCoreTypeEax.Uint32, NULL, NULL, NULL);
+ CoreTypes[ProcessorIndex] = (UINT8)NativeModelIdAndCoreTypeEax.Bits.CoreType;
+}
+
/**
Create gMpInformationHobGuid2.
**/
@@ -558,13 +582,36 @@ BuildMpInformationHob (
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 = MpInitLibGetNumberOfProcessors (&NumberOfProcessors, &NumberOfEnabledProcessors);
ASSERT_EFI_ERROR (Status);
+
+ //
+ // 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);
+
+ Status = MpInitLibStartupAllCPUs (
+ GetProcessorCoreType,
+ 0,
+ (VOID *)CoreTypes
+ );
+ ASSERT_EFI_ERROR (Status);
+ }
+
MaxProcessorsPerHob = ((MAX_UINT16 & ~7) - sizeof (EFI_HOB_GUID_TYPE) - sizeof (MP_INFORMATION2_HOB_DATA)) / sizeof (MP_INFORMATION2_ENTRY);
NumberOfProcessorsInHob = MaxProcessorsPerHob;
@@ -597,12 +644,16 @@ BuildMpInformationHob (
NULL
);
ASSERT_EFI_ERROR (Status);
+
+ MpInformation2Entry->CoreType = (CoreTypes != NULL) ? CoreTypes[Index + ProcessorIndex] : 0;
+
DEBUG ((
DEBUG_INFO,
- " Processor[%04d]: ProcessorId = 0x%lx, StatusFlag = 0x%x\n",
+ " Processor[%04d]: ProcessorId = 0x%lx, StatusFlag = 0x%x, CoreType = 0x%x\n",
Index + ProcessorIndex,
MpInformation2Entry->ProcessorInfo.ProcessorId,
- MpInformation2Entry->ProcessorInfo.StatusFlag
+ MpInformation2Entry->ProcessorInfo.StatusFlag,
+ MpInformation2Entry->CoreType
));
DEBUG ((
DEBUG_INFO,
@@ -625,6 +676,10 @@ BuildMpInformationHob (
ProcessorIndex += NumberOfProcessorsInHob;
}
+
+ if (CoreTypes != NULL) {
+ FreePages (CoreTypes, CoreTypePages);
+ }
}
/**
diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.h b/UefiCpuPkg/CpuMpPei/CpuMpPei.h
index a40fd2c077..e7d07ffd64 100644
--- a/UefiCpuPkg/CpuMpPei/CpuMpPei.h
+++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.h
@@ -32,6 +32,8 @@
#include <Guid/MpInformation2.h>
+#include <Register/Cpuid.h>
+
extern EFI_PEI_PPI_DESCRIPTOR mPeiCpuMpPpiDesc;
/**
--
2.31.1.windows.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112163): https://edk2.groups.io/g/devel/message/112163
Mute This Topic: https://groups.io/mt/103030295/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
Reviewed-by: Ray Ni <ray.ni@intel.com>
Thanks,
Ray
> -----Original Message-----
> From: Tan, Dun <dun.tan@intel.com>
> Sent: Thursday, December 7, 2023 3:32 PM
> To: devel@edk2.groups.io
> Cc: Dong, Eric <eric.dong@intel.com>; Ni, Ray <ray.ni@intel.com>; Kumar,
> Rahul R <rahul.r.kumar@intel.com>; Gerd Hoffmann <kraxel@redhat.com>
> Subject: [Patch V2 5/6] UefiCpuPkg: Cache core type in MpInfo2 HOB
>
> Cache core type in MpInfo2 HOB by CpuMpPei module.
>
> 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 | 59
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
> UefiCpuPkg/CpuMpPei/CpuMpPei.h | 2 ++
> 2 files changed, 59 insertions(+), 2 deletions(-)
>
> diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.c
> b/UefiCpuPkg/CpuMpPei/CpuMpPei.c
> index 8cacf4ddf5..7e2d7efb6b 100644
> --- a/UefiCpuPkg/CpuMpPei/CpuMpPei.c
> +++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.c
> @@ -541,6 +541,30 @@ InitializeMpExceptionStackSwitchHandlers (
> FreePages (SwitchStackData, EFI_SIZE_TO_PAGES (NumberOfProcessors *
> sizeof (EXCEPTION_STACK_SWITCH_CONTEXT)));
> }
>
> +/**
> + 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;
> +
> + Status = MpInitLibWhoAmI (&ProcessorIndex);
> + ASSERT_EFI_ERROR (Status);
> +
> + CoreTypes = (UINT8 *)Buffer;
> + AsmCpuidEx (CPUID_HYBRID_INFORMATION,
> CPUID_HYBRID_INFORMATION_MAIN_LEAF,
> &NativeModelIdAndCoreTypeEax.Uint32, NULL, NULL, NULL);
> + CoreTypes[ProcessorIndex] =
> (UINT8)NativeModelIdAndCoreTypeEax.Bits.CoreType;
> +}
> +
> /**
> Create gMpInformationHobGuid2.
> **/
> @@ -558,13 +582,36 @@ BuildMpInformationHob (
> 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 = MpInitLibGetNumberOfProcessors (&NumberOfProcessors,
> &NumberOfEnabledProcessors);
> ASSERT_EFI_ERROR (Status);
> +
> + //
> + // 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);
> +
> + Status = MpInitLibStartupAllCPUs (
> + GetProcessorCoreType,
> + 0,
> + (VOID *)CoreTypes
> + );
> + ASSERT_EFI_ERROR (Status);
> + }
> +
> MaxProcessorsPerHob = ((MAX_UINT16 & ~7) - sizeof
> (EFI_HOB_GUID_TYPE) - sizeof (MP_INFORMATION2_HOB_DATA)) / sizeof
> (MP_INFORMATION2_ENTRY);
> NumberOfProcessorsInHob = MaxProcessorsPerHob;
>
> @@ -597,12 +644,16 @@ BuildMpInformationHob (
> NULL
> );
> ASSERT_EFI_ERROR (Status);
> +
> + MpInformation2Entry->CoreType = (CoreTypes != NULL) ?
> CoreTypes[Index + ProcessorIndex] : 0;
> +
> DEBUG ((
> DEBUG_INFO,
> - " Processor[%04d]: ProcessorId = 0x%lx, StatusFlag = 0x%x\n",
> + " Processor[%04d]: ProcessorId = 0x%lx, StatusFlag = 0x%x,
> CoreType = 0x%x\n",
> Index + ProcessorIndex,
> MpInformation2Entry->ProcessorInfo.ProcessorId,
> - MpInformation2Entry->ProcessorInfo.StatusFlag
> + MpInformation2Entry->ProcessorInfo.StatusFlag,
> + MpInformation2Entry->CoreType
> ));
> DEBUG ((
> DEBUG_INFO,
> @@ -625,6 +676,10 @@ BuildMpInformationHob (
>
> ProcessorIndex += NumberOfProcessorsInHob;
> }
> +
> + if (CoreTypes != NULL) {
> + FreePages (CoreTypes, CoreTypePages);
> + }
> }
>
> /**
> diff --git a/UefiCpuPkg/CpuMpPei/CpuMpPei.h
> b/UefiCpuPkg/CpuMpPei/CpuMpPei.h
> index a40fd2c077..e7d07ffd64 100644
> --- a/UefiCpuPkg/CpuMpPei/CpuMpPei.h
> +++ b/UefiCpuPkg/CpuMpPei/CpuMpPei.h
> @@ -32,6 +32,8 @@
>
> #include <Guid/MpInformation2.h>
>
> +#include <Register/Cpuid.h>
> +
> extern EFI_PEI_PPI_DESCRIPTOR mPeiCpuMpPpiDesc;
>
> /**
> --
> 2.31.1.windows.1
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#112217): https://edk2.groups.io/g/devel/message/112217
Mute This Topic: https://groups.io/mt/103030295/1787277
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076/xyzzy [importer@patchew.org]
-=-=-=-=-=-=-=-=-=-=-=-
© 2016 - 2026 Red Hat, Inc.