public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
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 5/6] UefiCpuPkg: Cache core type in MpInfo2 HOB
Date: Tue,  5 Dec 2023 13:48:59 +0800	[thread overview]
Message-ID: <20231205054900.926-6-dun.tan@intel.com> (raw)
In-Reply-To: <20231205054900.926-1-dun.tan@intel.com>

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 4d80d52799..8f6863f4d9 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                                    *CoreType;
+  CPUID_NATIVE_MODEL_ID_AND_CORE_TYPE_EAX  NativeModelIdAndCoreTypeEax;
+  UINTN                                    ProcessorIndex;
+
+  Status = MpInitLibWhoAmI (&ProcessorIndex);
+  ASSERT_EFI_ERROR (Status);
+
+  CoreType = (UINT8 *)Buffer;
+  AsmCpuidEx (CPUID_HYBRID_INFORMATION, CPUID_HYBRID_INFORMATION_MAIN_LEAF, &NativeModelIdAndCoreTypeEax.Uint32, NULL, NULL, NULL);
+  CoreType[ProcessorIndex] = (UINT8)NativeModelIdAndCoreTypeEax.Bits.CoreType;
+}
+
 /**
   Create gMpInformationHobGuid2.
 **/
@@ -558,13 +582,36 @@ BuildMpInformationHob (
   MP_INFORMATION2_HOB_DATA  *MpInformation2HobData;
   MP_INFORMATION2_ENTRY     *MpInformation2Entry;
   UINTN                     Index;
+  UINT8                     *CoreType;
+  UINT32                    CpuidMaxInput;
+  UINTN                     Pages;
 
   ProcessorIndex        = 0;
   MpInformation2HobData = NULL;
   MpInformation2Entry   = NULL;
+  CoreType              = NULL;
+  Pages                 = 0;
 
   Status = MpInitLibGetNumberOfProcessors (&NumberOfProcessors, &NumberOfEnabledProcessors);
   ASSERT_EFI_ERROR (Status);
+
+  //
+  // Get Processors CoreType
+  //
+  AsmCpuid (CPUID_SIGNATURE, &CpuidMaxInput, NULL, NULL, NULL);
+  if (CpuidMaxInput >= CPUID_HYBRID_INFORMATION) {
+    Pages    = EFI_SIZE_TO_PAGES (sizeof (UINT8) * NumberOfProcessors);
+    CoreType = AllocatePages (Pages);
+    ASSERT (CoreType != NULL);
+
+    Status = MpInitLibStartupAllCPUs (
+               GetProcessorCoreType,
+               0,
+               (VOID *)CoreType
+               );
+    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 = (CoreType != NULL) ? CoreType[Index + ProcessorIndex] : 0;
+
       DEBUG ((
         DEBUG_INFO,
-        "ProcessorIndex = %x, ProcessorId = %lx, StatusFlag = %x\n",
+        "ProcessorIndex = %x, ProcessorId = %lx, StatusFlag = %x, CoreType = %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 (CoreType != NULL) {
+    FreePages (CoreType, Pages);
+  }
 }
 
 /**
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 (#112067): https://edk2.groups.io/g/devel/message/112067
Mute This Topic: https://groups.io/mt/102987141/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



  parent reply	other threads:[~2023-12-05  5:49 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-12-05  5:48 [edk2-devel] [PATCH 0/6] Create and consume a new gMpInformationHobGuid2 in UefiCpuPkg duntan
2023-12-05  5:48 ` [edk2-devel] [PATCH 1/6] UefiCpuPkg: Create " duntan
2023-12-06  9:09   ` Ni, Ray
2023-12-07  0:21     ` duntan
2023-12-05  5:48 ` [edk2-devel] [PATCH 2/6] UefiCpuPkg: Build MpInfo2HOB in CpuMpPei duntan
2023-12-06  9:24   ` Ni, Ray
2023-12-07  0:21     ` duntan
2023-12-05  5:48 ` [edk2-devel] [PATCH 3/6] UefiCpuPkg: Consume MpInfo2Hob in PiSmmCpuDxe duntan
2023-12-06  9:55   ` Ni, Ray
2023-12-07  0:22     ` duntan
2023-12-07  1:26       ` Ni, Ray
2023-12-05  5:48 ` [edk2-devel] [PATCH 4/6] UefiCpuPkg: Add a new field in MpInfo2 HOB duntan
2023-12-06  9:55   ` Ni, Ray
2023-12-05  5:48 ` duntan [this message]
2023-12-06 10:01   ` [edk2-devel] [PATCH 5/6] UefiCpuPkg: Cache core type " Ni, Ray
2023-12-07  0:23     ` duntan
2023-12-05  5:49 ` [edk2-devel] [PATCH 6/6] UefiCpuPkg: Avoid assuming only one smmbasehob duntan
2023-12-06 10:14   ` Ni, Ray
2023-12-07  0:37     ` duntan
2023-12-07  1:25       ` 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=20231205054900.926-6-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