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 14/14] OvmfPkg/QemuFwCfgLib: remove mQemuFwCfgSupported + mQemuFwCfgDmaSupported
Date: Fri,  2 Dec 2022 14:10:09 +0100	[thread overview]
Message-ID: <20221202131009.3190040-15-kraxel@redhat.com> (raw)
In-Reply-To: <20221202131009.3190040-1-kraxel@redhat.com>

Remove global variables, store the state in PlatformInfoHob instead.
Probing for fw_cfg happens on first use, at library initialization
time the Hob might not be present yet.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 .../Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf  |  4 ++
 OvmfPkg/Include/Library/PlatformInitLib.h     |  4 ++
 OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPei.c   | 44 ++++++++++++++++---
 3 files changed, 45 insertions(+), 7 deletions(-)

diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf
index 1d7543a7d40f..b1f548febcf7 100644
--- a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf
+++ b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPeiLib.inf
@@ -39,8 +39,12 @@ [LibraryClasses]
   BaseLib
   BaseMemoryLib
   DebugLib
+  HobLib
   IoLib
   MemoryAllocationLib
 
+[Guids]
+  gUefiOvmfPkgPlatformInfoGuid
+
 [Pcd]
   gUefiOvmfPkgTokenSpaceGuid.PcdOvmfWorkAreaBase
diff --git a/OvmfPkg/Include/Library/PlatformInitLib.h b/OvmfPkg/Include/Library/PlatformInitLib.h
index da7ed76041d2..bf6f90a5761c 100644
--- a/OvmfPkg/Include/Library/PlatformInitLib.h
+++ b/OvmfPkg/Include/Library/PlatformInitLib.h
@@ -50,6 +50,10 @@ typedef struct {
   UINT32               S3AcpiReservedMemorySize;
 
   UINT64               FeatureControlValue;
+
+  BOOLEAN              QemuFwCfgChecked;
+  BOOLEAN              QemuFwCfgSupported;
+  BOOLEAN              QemuFwCfgDmaSupported;
 } EFI_HOB_PLATFORM_INFO;
 #pragma pack()
 
diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPei.c b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPei.c
index a936fd103955..da86a3c84c02 100644
--- a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPei.c
+++ b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgPei.c
@@ -9,17 +9,17 @@
   SPDX-License-Identifier: BSD-2-Clause-Patent
 **/
 
+#include <PiPei.h>
 #include <Library/BaseLib.h>
-#include <Library/IoLib.h>
 #include <Library/DebugLib.h>
+#include <Library/HobLib.h>
+#include <Library/IoLib.h>
+#include <Library/PlatformInitLib.h>
 #include <Library/QemuFwCfgLib.h>
 #include <WorkArea.h>
 
 #include "QemuFwCfgLibInternal.h"
 
-STATIC BOOLEAN  mQemuFwCfgSupported = FALSE;
-STATIC BOOLEAN  mQemuFwCfgDmaSupported;
-
 /**
   Check if it is Tdx guest
 
@@ -93,13 +93,39 @@ QemuFwCfgProbe (
     ));
 }
 
+STATIC
+EFI_HOB_PLATFORM_INFO *
+QemuFwCfgGetPlatformInfo (
+  VOID
+  )
+{
+  EFI_HOB_PLATFORM_INFO  *PlatformInfoHob;
+  EFI_HOB_GUID_TYPE      *GuidHob;
+
+  GuidHob = GetFirstGuidHob (&gUefiOvmfPkgPlatformInfoGuid);
+  if (GuidHob == NULL) {
+    return NULL;
+  }
+
+  PlatformInfoHob = (EFI_HOB_PLATFORM_INFO *)GET_GUID_HOB_DATA (GuidHob);
+
+  if (!PlatformInfoHob->QemuFwCfgChecked) {
+    QemuFwCfgProbe (
+      &PlatformInfoHob->QemuFwCfgSupported,
+      &PlatformInfoHob->QemuFwCfgDmaSupported
+      );
+    PlatformInfoHob->QemuFwCfgChecked = TRUE;
+  }
+
+  return PlatformInfoHob;
+}
+
 RETURN_STATUS
 EFIAPI
 QemuFwCfgInitialize (
   VOID
   )
 {
-  QemuFwCfgProbe (&mQemuFwCfgSupported, &mQemuFwCfgDmaSupported);
   return RETURN_SUCCESS;
 }
 
@@ -117,7 +143,9 @@ InternalQemuFwCfgIsAvailable (
   VOID
   )
 {
-  return mQemuFwCfgSupported;
+  EFI_HOB_PLATFORM_INFO  *PlatformInfoHob = QemuFwCfgGetPlatformInfo ();
+
+  return PlatformInfoHob->QemuFwCfgSupported;
 }
 
 /**
@@ -132,7 +160,9 @@ InternalQemuFwCfgDmaIsAvailable (
   VOID
   )
 {
-  return mQemuFwCfgDmaSupported;
+  EFI_HOB_PLATFORM_INFO  *PlatformInfoHob = QemuFwCfgGetPlatformInfo ();
+
+  return PlatformInfoHob->QemuFwCfgDmaSupported;
 }
 
 /**
-- 
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 ` [PATCH 11/14] OvmfPkg/PlatformPei: remove mFeatureControlValue Gerd Hoffmann
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 ` Gerd Hoffmann [this message]
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-15-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