From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.groups.io with SMTP id smtpd.web10.74431.1669986643244242625 for ; Fri, 02 Dec 2022 05:10:43 -0800 Authentication-Results: mx.groups.io; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=QAeSgeNF; spf=pass (domain: redhat.com, ip: 170.10.133.124, mailfrom: kraxel@redhat.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1669986642; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=93FNY8KdvaaOk3Ls0TDKsqjlDxLLE5JOjsNExFKTwE8=; b=QAeSgeNFHVeU/gafWgX7JKFRewha9HrhxBaLsSbIdYA+RqFeDKZ/v4p/yZrMs9idHwX+ok fBWjsSgIfmVWT3tGrpbbeBs73wpVdwakRqcBm0s8Hc0tVKAKLXEGlnB1Po1169g7kH1OJE TttZCmmqmQSUdCqHKfkmNBIOGzoY6Ac= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-146-fKzciBbiNxGa1gkGGaf1bA-1; Fri, 02 Dec 2022 08:10:38 -0500 X-MC-Unique: fKzciBbiNxGa1gkGGaf1bA-1 Received: from smtp.corp.redhat.com (int-mx09.intmail.prod.int.rdu2.redhat.com [10.11.54.9]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5EADC38012C2; Fri, 2 Dec 2022 13:10:37 +0000 (UTC) Received: from sirius.home.kraxel.org (unknown [10.39.192.79]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 264B94A9257; Fri, 2 Dec 2022 13:10:37 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 0CBD11801564; Fri, 2 Dec 2022 14:10:10 +0100 (CET) From: "Gerd Hoffmann" To: devel@edk2.groups.io Cc: Bob Feng , Yuwei Chen , Erdem Aktas , Jordan Justen , Peter Grehan , Rebecca Cran , Liming Gao , Ard Biesheuvel , Gerd Hoffmann , Jiewen Yao , Min Xu , Brijesh Singh , Oliver Steffen , Pawel Polawski , Tom Lendacky , James Bottomley Subject: [PATCH 14/14] OvmfPkg/QemuFwCfgLib: remove mQemuFwCfgSupported + mQemuFwCfgDmaSupported Date: Fri, 2 Dec 2022 14:10:09 +0100 Message-Id: <20221202131009.3190040-15-kraxel@redhat.com> In-Reply-To: <20221202131009.3190040-1-kraxel@redhat.com> References: <20221202131009.3190040-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.9 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true 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 --- .../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 #include -#include #include +#include +#include +#include #include #include #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