public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Gerd Hoffmann" <kraxel@redhat.com>
To: devel@edk2.groups.io
Cc: Bob Feng <bob.c.feng@intel.com>,
	Yuwei Chen <yuwei.chen@intel.com>,
	Erdem Aktas <erdemaktas@google.com>,
	Jordan Justen <jordan.l.justen@intel.com>,
	Peter Grehan <grehan@freebsd.org>,
	Rebecca Cran <rebecca@bsdio.com>,
	Liming Gao <gaoliming@byosoft.com.cn>,
	Ard Biesheuvel <ardb+tianocore@kernel.org>,
	Gerd Hoffmann <kraxel@redhat.com>,
	Jiewen Yao <jiewen.yao@intel.com>, Min Xu <min.m.xu@intel.com>,
	Brijesh Singh <brijesh.singh@amd.com>,
	Oliver Steffen <osteffen@redhat.com>,
	Pawel Polawski <ppolawsk@redhat.com>,
	Tom Lendacky <thomas.lendacky@amd.com>,
	James Bottomley <jejb@linux.ibm.com>
Subject: [PATCH 11/14] OvmfPkg/PlatformPei: remove mFeatureControlValue
Date: Fri,  2 Dec 2022 14:10:06 +0100	[thread overview]
Message-ID: <20221202131009.3190040-12-kraxel@redhat.com> (raw)
In-Reply-To: <20221202131009.3190040-1-kraxel@redhat.com>

Use PlatformInfoHob->FeatureControlValue instead.
OnMpServicesAvailable() will find PlatformInfoHob using
GetFirstGuidHob() and pass a pointer to the WriteFeatureControl
callback.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 OvmfPkg/Include/Library/PlatformInitLib.h |  2 ++
 OvmfPkg/PlatformPei/Platform.h            |  2 +-
 OvmfPkg/PlatformPei/FeatureControl.c      | 44 ++++++++++++++++-------
 OvmfPkg/PlatformPei/Platform.c            |  2 +-
 4 files changed, 36 insertions(+), 14 deletions(-)

diff --git a/OvmfPkg/Include/Library/PlatformInitLib.h b/OvmfPkg/Include/Library/PlatformInitLib.h
index c5234bf26d45..da7ed76041d2 100644
--- a/OvmfPkg/Include/Library/PlatformInitLib.h
+++ b/OvmfPkg/Include/Library/PlatformInitLib.h
@@ -48,6 +48,8 @@ typedef struct {
 
   UINT32               S3AcpiReservedMemoryBase;
   UINT32               S3AcpiReservedMemorySize;
+
+  UINT64               FeatureControlValue;
 } EFI_HOB_PLATFORM_INFO;
 #pragma pack()
 
diff --git a/OvmfPkg/PlatformPei/Platform.h b/OvmfPkg/PlatformPei/Platform.h
index 86f603ff649c..1cf44844a781 100644
--- a/OvmfPkg/PlatformPei/Platform.h
+++ b/OvmfPkg/PlatformPei/Platform.h
@@ -70,7 +70,7 @@ MemTypeInfoInitialization (
 
 VOID
 InstallFeatureControlCallback (
-  VOID
+  IN OUT EFI_HOB_PLATFORM_INFO  *PlatformInfoHob
   );
 
 VOID
diff --git a/OvmfPkg/PlatformPei/FeatureControl.c b/OvmfPkg/PlatformPei/FeatureControl.c
index 5864ee0c214d..d8a398cd5565 100644
--- a/OvmfPkg/PlatformPei/FeatureControl.c
+++ b/OvmfPkg/PlatformPei/FeatureControl.c
@@ -8,6 +8,7 @@
 **/
 
 #include <Library/DebugLib.h>
+#include <Library/HobLib.h>
 #include <Library/PeiServicesLib.h>
 #include <Library/QemuFwCfgLib.h>
 #include <Ppi/MpServices.h>
@@ -16,11 +17,6 @@
 
 #include "Platform.h"
 
-//
-// The value to be written to the Feature Control MSR, retrieved from fw_cfg.
-//
-STATIC UINT64  mFeatureControlValue;
-
 /**
   Write the Feature Control MSR on an Application Processor or the Boot
   Processor.
@@ -38,10 +34,22 @@ WriteFeatureControl (
   IN OUT VOID  *WorkSpace
   )
 {
+  EFI_HOB_PLATFORM_INFO  *PlatformInfoHob = WorkSpace;
+
   if (TdIsEnabled ()) {
-    TdVmCall (TDVMCALL_WRMSR, (UINT64)MSR_IA32_FEATURE_CONTROL, mFeatureControlValue, 0, 0, 0);
+    TdVmCall (
+      TDVMCALL_WRMSR,
+      (UINT64)MSR_IA32_FEATURE_CONTROL,
+      PlatformInfoHob->FeatureControlValue,
+      0,
+      0,
+      0
+      );
   } else {
-    AsmWriteMsr64 (MSR_IA32_FEATURE_CONTROL, mFeatureControlValue);
+    AsmWriteMsr64 (
+      MSR_IA32_FEATURE_CONTROL,
+      PlatformInfoHob->FeatureControlValue
+      );
   }
 }
 
@@ -67,6 +75,15 @@ OnMpServicesAvailable (
 {
   EFI_PEI_MP_SERVICES_PPI  *MpServices;
   EFI_STATUS               Status;
+  EFI_HOB_PLATFORM_INFO    *PlatformInfoHob;
+  EFI_HOB_GUID_TYPE        *GuidHob;
+
+  GuidHob = GetFirstGuidHob (&gUefiOvmfPkgPlatformInfoGuid);
+  if (GuidHob == NULL) {
+    return EFI_UNSUPPORTED;
+  }
+
+  PlatformInfoHob = (EFI_HOB_PLATFORM_INFO *)GET_GUID_HOB_DATA (GuidHob);
 
   DEBUG ((DEBUG_VERBOSE, "%a: %a\n", gEfiCallerBaseName, __FUNCTION__));
 
@@ -80,7 +97,7 @@ OnMpServicesAvailable (
                              WriteFeatureControl, // Procedure
                              FALSE,               // SingleThread
                              0,                   // TimeoutInMicroSeconds: inf.
-                             NULL                 // ProcedureArgument
+                             PlatformInfoHob      // ProcedureArgument
                              );
   if (EFI_ERROR (Status) && (Status != EFI_NOT_STARTED)) {
     DEBUG ((DEBUG_ERROR, "%a: StartupAllAps(): %r\n", __FUNCTION__, Status));
@@ -90,7 +107,7 @@ OnMpServicesAvailable (
   //
   // Now write the MSR on the BSP too.
   //
-  WriteFeatureControl (NULL);
+  WriteFeatureControl (PlatformInfoHob);
   return EFI_SUCCESS;
 }
 
@@ -107,7 +124,7 @@ STATIC CONST EFI_PEI_NOTIFY_DESCRIPTOR  mMpServicesNotify = {
 
 VOID
 InstallFeatureControlCallback (
-  VOID
+  IN OUT EFI_HOB_PLATFORM_INFO  *PlatformInfoHob
   )
 {
   EFI_STATUS            Status;
@@ -119,7 +136,7 @@ InstallFeatureControlCallback (
              &FwCfgItem,
              &FwCfgSize
              );
-  if (EFI_ERROR (Status) || (FwCfgSize != sizeof mFeatureControlValue)) {
+  if (EFI_ERROR (Status) || (FwCfgSize != sizeof (PlatformInfoHob->FeatureControlValue))) {
     //
     // Nothing to do.
     //
@@ -127,7 +144,10 @@ InstallFeatureControlCallback (
   }
 
   QemuFwCfgSelectItem (FwCfgItem);
-  QemuFwCfgReadBytes (sizeof mFeatureControlValue, &mFeatureControlValue);
+  QemuFwCfgReadBytes (
+    sizeof (PlatformInfoHob->FeatureControlValue),
+    &(PlatformInfoHob->FeatureControlValue)
+    );
 
   Status = PeiServicesNotifyPpi (&mMpServicesNotify);
   if (EFI_ERROR (Status)) {
diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c
index ebce2ba1290e..148240342b4b 100644
--- a/OvmfPkg/PlatformPei/Platform.c
+++ b/OvmfPkg/PlatformPei/Platform.c
@@ -396,7 +396,7 @@ InitializePlatform (
   }
 
   IntelTdxInitialize ();
-  InstallFeatureControlCallback ();
+  InstallFeatureControlCallback (PlatformInfoHob);
 
   return EFI_SUCCESS;
 }
-- 
2.38.1


  parent reply	other threads:[~2022-12-02 13:10 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-02 13:09 [PATCH 00/14] OvmfPkg: avoid global variables in PEI Gerd Hoffmann
2022-12-02 13:09 ` [PATCH 01/14] tools_def: remove GCC_IA32_CC_FLAGS/GCC_X64_CC_FLAGS Gerd Hoffmann
2022-12-02 13:09 ` [PATCH 02/14] tools_def: add -fno-omit-frame-pointer to GCC48_{IA32,X64}_CC_FLAGS Gerd Hoffmann
2022-12-02 13:09 ` [PATCH 03/14] OvmfPkg/PlatformPei: AmdSev: stop using mPlatformInfoHob Gerd Hoffmann
2022-12-02 13:09 ` [PATCH 04/14] OvmfPkg/PlatformPei: PeiFv: " Gerd Hoffmann
2022-12-02 13:10 ` [PATCH 05/14] OvmfPkg/PlatformPei Q35 SMM helpers: " Gerd Hoffmann
2022-12-02 13:10 ` [PATCH 06/14] OvmfPkg/PlatformPei: PeiMemory: " Gerd Hoffmann
2022-12-02 13:10 ` [PATCH 07/14] OvmfPkg/PlatformPei: MemTypeInfo: " Gerd Hoffmann
2022-12-02 13:10 ` [PATCH 08/14] OvmfPkg/PlatformPei: NoExec: " Gerd Hoffmann
2022-12-02 13:10 ` [PATCH 09/14] OvmfPkg/PlatformPei: Verification: " Gerd Hoffmann
2022-12-02 13:10 ` [PATCH 10/14] OvmfPkg/PlatformPei: remove mPlatformInfoHob Gerd Hoffmann
2022-12-02 13:10 ` Gerd Hoffmann [this message]
2022-12-02 13:10 ` [PATCH 12/14] OvmfPkg/DebugLibIoPort: use Rom version for PEI Gerd Hoffmann
2022-12-02 13:10 ` [PATCH 13/14] OvmfPkg/QemuFwCfgLib: rewrite fw_cfg probe Gerd Hoffmann
2022-12-02 13:10 ` [PATCH 14/14] OvmfPkg/QemuFwCfgLib: remove mQemuFwCfgSupported + mQemuFwCfgDmaSupported Gerd Hoffmann
2022-12-12 16:58 ` [PATCH 00/14] OvmfPkg: avoid global variables in PEI Lendacky, Thomas
2022-12-14 17:26   ` Ard Biesheuvel

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=20221202131009.3190040-12-kraxel@redhat.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