Skip to content

Commit

Permalink
UefiCpuPkg/BaseXApicLib: Fix CPUID_V2_EXTENDED_TOPOLOGY detection
Browse files Browse the repository at this point in the history
This patch is to complete 170d4ce, sync the change to BaseXApicLib.

Checking the max cpuid leaf is not enough to figure whenever
CPUID_V2_EXTENDED_TOPOLOGY is supported.  Intel SDM says:

Software must detect the presence of CPUID leaf 1FH by verifying
(a) the highest leaf index supported by CPUID is >= 1FH, and
(b) CPUID.1FH:EBX[15:0] reports a non-zero value.

The same is true for CPUID leaf 0BH.

This patch adds the EBX check to GetProcessorLocation2ByApicId().  The
patch also fixes the existing check in GetProcessorLocationByApicId() to
be in line with the spec by looking at bits 15:0.  The comments are
updated with a quote from the Intel SDM.

Cc: Laszlo Ersek <[email protected]>
Cc: Eric Dong <[email protected]>
Cc: Ray Ni <[email protected]>
Cc: Rahul Kumar <[email protected]>
Cc: Gerd Hoffmann <[email protected]>
Cc: Star Zeng <[email protected]>
Signed-off-by: Gerd Hoffmann <[email protected]>
Signed-off-by: Jiaxin Wu <[email protected]>
Message-Id: <[email protected]>
Reviewed-by: Laszlo Ersek <[email protected]>
Reviewed-by: Ray Ni <[email protected]>
  • Loading branch information
jiaxinwu authored and mergify[bot] committed Dec 8, 2023
1 parent fe2abc9 commit ad0b1cc
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions UefiCpuPkg/Library/BaseXApicLib/BaseXApicLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1055,11 +1055,12 @@ GetProcessorLocationByApicId (
NULL
);
//
// If CPUID.(EAX=0BH, ECX=0H):EBX returns zero and maximum input value for
// basic CPUID information is greater than 0BH, then CPUID.0BH leaf is not
// supported on that processor.
// Quoting Intel SDM:
// Software must detect the presence of CPUID leaf 0BH by
// verifying (a) the highest leaf index supported by CPUID is >=
// 0BH, and (b) CPUID.0BH:EBX[15:0] reports a non-zero value.
//
if (ExtendedTopologyEbx.Uint32 != 0) {
if (ExtendedTopologyEbx.Bits.LogicalProcessors != 0) {
TopologyLeafSupported = TRUE;

//
Expand Down Expand Up @@ -1185,6 +1186,7 @@ GetProcessorLocation2ByApicId (
)
{
CPUID_EXTENDED_TOPOLOGY_EAX ExtendedTopologyEax;
CPUID_EXTENDED_TOPOLOGY_EBX ExtendedTopologyEbx;
CPUID_EXTENDED_TOPOLOGY_ECX ExtendedTopologyEcx;
UINT32 MaxStandardCpuIdIndex;
UINT32 Index;
Expand All @@ -1197,10 +1199,19 @@ GetProcessorLocation2ByApicId (
}

//
// Get max index of CPUID
// Quoting Intel SDM:
// Software must detect the presence of CPUID leaf 1FH by verifying
// (a) the highest leaf index supported by CPUID is >= 1FH, and (b)
// CPUID.1FH:EBX[15:0] reports a non-zero value.
//
AsmCpuid (CPUID_SIGNATURE, &MaxStandardCpuIdIndex, NULL, NULL, NULL);
if (MaxStandardCpuIdIndex < CPUID_V2_EXTENDED_TOPOLOGY) {
ExtendedTopologyEbx.Bits.LogicalProcessors = 0;
} else {
AsmCpuidEx (CPUID_V2_EXTENDED_TOPOLOGY, 0, NULL, &ExtendedTopologyEbx.Uint32, NULL, NULL);
}

if (ExtendedTopologyEbx.Bits.LogicalProcessors == 0) {
if (Die != NULL) {
*Die = 0;
}
Expand Down

0 comments on commit ad0b1cc

Please sign in to comment.