From: "Gerd Hoffmann" <kraxel@redhat.com>
To: "Ni, Ray" <ray.ni@intel.com>
Cc: "devel@edk2.groups.io" <devel@edk2.groups.io>
Subject: Re: [edk2-devel] [PATCH 0/4] Sync BSP's APIC mode to APs in MP init flow
Date: Fri, 7 Jul 2023 13:26:08 +0200 [thread overview]
Message-ID: <ixmzx33lipdzjxyha33pkv54wb7re4hq6iw7akvdbjea225baj@z4cux2zrzzrb> (raw)
In-Reply-To: <MN6PR11MB8244FD482EEA73BF0BCF998E8C2DA@MN6PR11MB8244.namprd11.prod.outlook.com>
On Fri, Jul 07, 2023 at 09:25:39AM +0000, Ni, Ray wrote:
> Gerd,
> No. I don't plan to add PCD.
> I thought that initially but in the end I figured out:
> * PCD is a way to let platform configure the common logic behavior.
> * Why not treat "X2 APIC status in BSP" as a "hardware" PCD?
A PCD has the advantage that most configuration knobs use that,
so people are used to use PCDs to configure their platform builds.
Using hardware status as pseudo PCD technically works too, and
it isn't the first case in edk2 either, 5-level paging works the
same way for example.
ovmf test patch (enabling x2mode unconditionally) below.
Tested-by: Gerd Hoffmann <kraxel@redhat.com>
Acked-by: Gerd Hoffmann <kraxel@redhat.com>
take care,
Gerd
------------------------------ cut here -----------------------------
>From 46a2d9128c42f62547f76afbdb8eef9cf5d0a8a1 Mon Sep 17 00:00:00 2001
From: Gerd Hoffmann <kraxel@redhat.com>
Date: Fri, 7 Jul 2023 12:44:21 +0200
Subject: [PATCH 1/1] OvmfPkg/PlatformPei: enable x2apic mode if supported
Switch the BSP local apic into x2apic mode if supported by the CPU.
CpuMpPei will switch the APs into x2apic mode, see commit FIXME.
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
OvmfPkg/PlatformPei/PlatformPei.inf | 1 +
OvmfPkg/PlatformPei/Platform.c | 26 ++++++++++++++++++++++++++
2 files changed, 27 insertions(+)
diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/PlatformPei.inf
index 3934aeed9514..b670e1ba6745 100644
--- a/OvmfPkg/PlatformPei/PlatformPei.inf
+++ b/OvmfPkg/PlatformPei/PlatformPei.inf
@@ -52,6 +52,7 @@ [LibraryClasses]
DebugLib
HobLib
IoLib
+ LocalApicLib
PciLib
ResourcePublicationLib
PeiServicesLib
diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c
index f5dc41c3a8c4..fd34fceafa31 100644
--- a/OvmfPkg/PlatformPei/Platform.c
+++ b/OvmfPkg/PlatformPei/Platform.c
@@ -21,6 +21,7 @@
#include <Library/DebugLib.h>
#include <Library/HobLib.h>
#include <Library/IoLib.h>
+#include <Library/LocalApicLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/PcdLib.h>
#include <Library/PciLib.h>
@@ -271,6 +272,29 @@ MaxCpuCountInitialization (
ASSERT_RETURN_ERROR (PcdStatus);
}
+STATIC
+VOID
+PlatformApicInit (
+ IN EFI_HOB_PLATFORM_INFO *PlatformInfoHob
+ )
+{
+ UINT32 RegEax, RegEbx, RegEcx, RegEdx;
+
+ AsmCpuid (1, &RegEax, &RegEbx, &RegEcx, &RegEdx);
+ if (!(RegEcx & (1 << 21))) {
+ DEBUG ((DEBUG_INFO, "%a: x2apic mode not supported\n", __func__));
+ return;
+ }
+
+ SetApicMode(LOCAL_APIC_MODE_X2APIC);
+ if (!(GetApicMode() == LOCAL_APIC_MODE_X2APIC)) {
+ DEBUG ((DEBUG_WARN, "%a: enabling x2apic mode failed\n", __func__));
+ return;
+ }
+
+ DEBUG ((DEBUG_INFO, "%a: x2apic mode enabled\n", __func__));
+}
+
/**
* @brief Builds PlatformInfo Hob
*/
@@ -368,5 +392,7 @@ InitializePlatform (
IntelTdxInitialize ();
InstallFeatureControlCallback (PlatformInfoHob);
+ PlatformApicInit(PlatformInfoHob);
+
return EFI_SUCCESS;
}
--
2.41.0
next prev parent reply other threads:[~2023-07-07 11:26 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-07 5:28 [PATCH 0/4] Sync BSP's APIC mode to APs in MP init flow Ni, Ray
2023-07-07 5:28 ` [PATCH 1/4] UefiCpuPkg/MpInitLib: Separate X2APIC enabling to subfunction Ni, Ray
2023-07-07 5:28 ` [PATCH 2/4] UefiCpuPkg/MpInitLib: Sync BSP's APIC mode to APs in InitConfig path Ni, Ray
2023-07-07 5:29 ` [PATCH 3/4] UefiCpuPkg/MpInitLib: Skip X2APIC enabling when BSP in X2APIC already Ni, Ray
2023-07-07 5:29 ` [PATCH 4/4] UefiCpuPkg/CpuFeatures: Deprecate CPU_FEATURE_X2APIC Ni, Ray
2023-07-07 8:55 ` [edk2-devel] [PATCH 0/4] Sync BSP's APIC mode to APs in MP init flow Gerd Hoffmann
2023-07-07 9:25 ` Ni, Ray
2023-07-07 11:26 ` Gerd Hoffmann [this message]
2023-11-09 16:29 ` Aaron Young via groups.io
2023-11-09 18:08 ` Michael D Kinney
2023-11-13 12:32 ` Laszlo Ersek
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=ixmzx33lipdzjxyha33pkv54wb7re4hq6iw7akvdbjea225baj@z4cux2zrzzrb \
--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