From nobody Thu May 2 03:57:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1487814506193151.667012139721; Wed, 22 Feb 2017 17:48:26 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id CC4F08225A; Wed, 22 Feb 2017 17:48:23 -0800 (PST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 54D6B82250 for ; Wed, 22 Feb 2017 17:48:22 -0800 (PST) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E77D483F3A; Thu, 23 Feb 2017 01:48:22 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-134.phx2.redhat.com [10.3.116.134]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1N1mJFF012836; Wed, 22 Feb 2017 20:48:22 -0500 X-Original-To: edk2-devel@ml01.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Thu, 23 Feb 2017 02:48:03 +0100 Message-Id: <20170223014814.10937-2-lersek@redhat.com> In-Reply-To: <20170223014814.10937-1-lersek@redhat.com> References: <20170223014814.10937-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Thu, 23 Feb 2017 01:48:22 +0000 (UTC) Subject: [edk2] [PATCH 01/12] OvmfPkg: introduce QemuFwCfgS3Lib class X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jordan Justen MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This library class will enable driver modules (a) to query whether S3 support was enabled on the QEMU command line, (b) to produce fw_cfg DMA operations that are to be replayed at S3 resume time. Declare the library class in OvmfPkg/OvmfPkg.dec, and add the library class header under OvmfPkg/Include/Library/. At the moment, the only API we expose is QemuFwCfgS3Enabled(), which we'll first migrate from QemuFwCfgLib. Further interfaces will be added in later patches. Cc: Jordan Justen Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D394 Suggested-by: Jordan Justen Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- OvmfPkg/OvmfPkg.dec | 4 ++ OvmfPkg/Include/Library/QemuFwCfgS3Lib.h | 39 ++++++++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/OvmfPkg/OvmfPkg.dec b/OvmfPkg/OvmfPkg.dec index a0c76a5bb448..3490f7ca7c07 100644 --- a/OvmfPkg/OvmfPkg.dec +++ b/OvmfPkg/OvmfPkg.dec @@ -35,6 +35,10 @@ [LibraryClasses] # QemuFwCfgLib|Include/Library/QemuFwCfgLib.h =20 + ## @libraryclass S3 support for QEMU fw_cfg + # + QemuFwCfgS3Lib|Include/Library/QemuFwCfgS3Lib.h + ## @libraryclass Rewrite the BootOrder NvVar based on QEMU's "bootorde= r" # fw_cfg file. # diff --git a/OvmfPkg/Include/Library/QemuFwCfgS3Lib.h b/OvmfPkg/Include/Lib= rary/QemuFwCfgS3Lib.h new file mode 100644 index 000000000000..1c473610d11c --- /dev/null +++ b/OvmfPkg/Include/Library/QemuFwCfgS3Lib.h @@ -0,0 +1,39 @@ +/** @file + S3 support for QEMU fw_cfg + + This library class enables driver modules (a) to query whether S3 suppor= t was + enabled on the QEMU command line, (b) to produce fw_cfg DMA operations t= hat + are to be replayed at S3 resume time. + + Copyright (C) 2017, Red Hat, Inc. + + This program and the accompanying materials are licensed and made availa= ble + under the terms and conditions of the BSD License which accompanies this + distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WI= THOUT + WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +**/ + +#ifndef __FW_CFG_S3_LIB__ +#define __FW_CFG_S3_LIB__ + +/** + Determine if S3 support is explicitly enabled. + + @retval TRUE If S3 support is explicitly enabled. Other functions in = this + library may be called (subject to their individual + restrictions). + + FALSE Otherwise. This includes unavailability of the firmware + configuration interface. No other function in this libra= ry + must be called. +**/ +BOOLEAN +EFIAPI +QemuFwCfgS3Enabled ( + VOID + ); + +#endif --=20 2.9.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 03:57:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1487814507398755.9129286018701; Wed, 22 Feb 2017 17:48:27 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 1BC4882259; Wed, 22 Feb 2017 17:48:26 -0800 (PST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A024A8225E for ; Wed, 22 Feb 2017 17:48:24 -0800 (PST) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3B5CD3A7690; Thu, 23 Feb 2017 01:48:25 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-134.phx2.redhat.com [10.3.116.134]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1N1mJFG012836; Wed, 22 Feb 2017 20:48:24 -0500 X-Original-To: edk2-devel@ml01.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Thu, 23 Feb 2017 02:48:04 +0100 Message-Id: <20170223014814.10937-3-lersek@redhat.com> In-Reply-To: <20170223014814.10937-1-lersek@redhat.com> References: <20170223014814.10937-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 23 Feb 2017 01:48:25 +0000 (UTC) Subject: [edk2] [PATCH 02/12] OvmfPkg/QemuFwCfgS3Lib: add initial Base Null library instance X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jordan Justen MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This library instance returns constant FALSE from QemuFwCfgS3Enabled(), and all other library functions trigger assertion failures. It is suitable for QEMU targets and machine types that never enable S3. The QemuFwCfgS3Enabled() implementation is copied from "ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c". Stubs for further QemuFwCfgS3Lib APIs (with assertion failures, see above) will be added later. Cc: Jordan Justen Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D394 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf | 39 +++++++++++= +++++++++ OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3Base.c | 39 +++++++++++= +++++++++ 2 files changed, 78 insertions(+) diff --git a/OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf b/Ov= mfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf new file mode 100644 index 000000000000..ba24a0b9d434 --- /dev/null +++ b/OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf @@ -0,0 +1,39 @@ +## @file +# Base Null library instance of the QemuFwCfgS3Lib class. +# +# This library instance returns constant FALSE from QemuFwCfgS3Enabled(), = and +# all other library functions trigger assertion failures. It is suitable f= or +# QEMU targets and machine types that never enable S3. +# +# Copyright (C) 2017, Red Hat, Inc. +# +# This program and the accompanying materials are licensed and made availa= ble +# under the terms and conditions of the BSD License which accompanies this +# distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WI= THOUT +# WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +## + +[Defines] + INF_VERSION =3D 1.25 + BASE_NAME =3D BaseQemuFwCfgS3LibNull + FILE_GUID =3D EA7D2B69-D221-4950-9C2C-C38A65BCC96E + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D QemuFwCfgS3Lib + +# +# The following information is for reference only and not required by the = build +# tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 IPF EBC +# + +[Sources] + QemuFwCfgS3Base.c + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec diff --git a/OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3Base.c b/OvmfPkg/Lib= rary/QemuFwCfgS3Lib/QemuFwCfgS3Base.c new file mode 100644 index 000000000000..bed9bf3dfb57 --- /dev/null +++ b/OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3Base.c @@ -0,0 +1,39 @@ +/** @file + Base Null library instance of the QemuFwCfgS3Lib class. + + This library instance returns constant FALSE from QemuFwCfgS3Enabled(), = and + all other library functions trigger assertion failures. It is suitable f= or + QEMU targets and machine types that never enable S3. + + Copyright (C) 2017, Red Hat, Inc. + + This program and the accompanying materials are licensed and made availa= ble + under the terms and conditions of the BSD License which accompanies this + distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WI= THOUT + WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +**/ + +#include + +/** + Determine if S3 support is explicitly enabled. + + @retval TRUE If S3 support is explicitly enabled. Other functions in = this + library may be called (subject to their individual + restrictions). + + FALSE Otherwise. This includes unavailability of the firmware + configuration interface. No other function in this libra= ry + must be called. +**/ +BOOLEAN +EFIAPI +QemuFwCfgS3Enabled ( + VOID + ) +{ + return FALSE; +} --=20 2.9.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 03:57:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1487814509743723.342583881554; Wed, 22 Feb 2017 17:48:29 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 52DBC82262; Wed, 22 Feb 2017 17:48:27 -0800 (PST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id D91F882250 for ; Wed, 22 Feb 2017 17:48:25 -0800 (PST) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 75EA581239; Thu, 23 Feb 2017 01:48:26 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-134.phx2.redhat.com [10.3.116.134]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1N1mJFH012836; Wed, 22 Feb 2017 20:48:25 -0500 X-Original-To: edk2-devel@ml01.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Thu, 23 Feb 2017 02:48:05 +0100 Message-Id: <20170223014814.10937-4-lersek@redhat.com> In-Reply-To: <20170223014814.10937-1-lersek@redhat.com> References: <20170223014814.10937-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 23 Feb 2017 01:48:26 +0000 (UTC) Subject: [edk2] [PATCH 03/12] OvmfPkg/QemuFwCfgS3Lib: add initial PEI and DXE fw_cfg library instances X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jordan Justen MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" This patch introduces PeiQemuFwCfgS3LibFwCfg, a limited functionality QemuFwCfgS3Lib instance, for PEI phase modules. The patch also introduces DxeQemuFwCfgS3LibFwCfg, a full functionality QemuFwCfgS3Lib instance, for DXE_DRIVER and DXE_RUNTIME_DRIVER modules. These library instances share the QemuFwCfgS3Enabled() function. The function actually uses fw_cfg; the implementation is copied from "OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c". The library instances will diverge in the following patches. Cc: Jordan Justen Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D394 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf | 38 +++++++++++= +++++ OvmfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf | 41 +++++++++++= ++++++ OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3PeiDxe.c | 48 +++++++++++= +++++++++ 3 files changed, 127 insertions(+) diff --git a/OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf b/Ov= mfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf new file mode 100644 index 000000000000..7016575f3dab --- /dev/null +++ b/OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf @@ -0,0 +1,38 @@ +## @file +# Full functionality QemuFwCfgS3Lib instance, for DXE phase modules. +# +# Copyright (C) 2017, Red Hat, Inc. +# +# This program and the accompanying materials are licensed and made availa= ble +# under the terms and conditions of the BSD License which accompanies this +# distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WI= THOUT +# WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +## + +[Defines] + INF_VERSION =3D 1.25 + BASE_NAME =3D DxeQemuFwCfgS3LibFwCfg + FILE_GUID =3D C5DE76EB-E8DE-4057-A487-C5A09AB039AB + MODULE_TYPE =3D DXE_DRIVER + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D QemuFwCfgS3Lib|DXE_DRIVER DXE_RUNTIME= _DRIVER + +# +# The following information is for reference only and not required by the = build +# tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 IPF EBC +# + +[Sources] + QemuFwCfgS3PeiDxe.c + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + QemuFwCfgLib diff --git a/OvmfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf b/Ov= mfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf new file mode 100644 index 000000000000..2593af8e5b4c --- /dev/null +++ b/OvmfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf @@ -0,0 +1,41 @@ +## @file +# Limited functionality QemuFwCfgS3Lib instance, for PEI phase modules. +# +# QemuFwCfgS3Enabled() queries S3 enablement via fw_cfg. Other library APIs +# will report lack of support. +# +# Copyright (C) 2017, Red Hat, Inc. +# +# This program and the accompanying materials are licensed and made availa= ble +# under the terms and conditions of the BSD License which accompanies this +# distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WI= THOUT +# WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +## + +[Defines] + INF_VERSION =3D 1.25 + BASE_NAME =3D PeiQemuFwCfgS3LibFwCfg + FILE_GUID =3D DD8D28B4-C1DC-4CAF-BB93-074BE80DAE6D + MODULE_TYPE =3D PEIM + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D QemuFwCfgS3Lib|PEIM + +# +# The following information is for reference only and not required by the = build +# tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 IPF EBC +# + +[Sources] + QemuFwCfgS3PeiDxe.c + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + QemuFwCfgLib diff --git a/OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3PeiDxe.c b/OvmfPkg/L= ibrary/QemuFwCfgS3Lib/QemuFwCfgS3PeiDxe.c new file mode 100644 index 000000000000..f87d6b8227cf --- /dev/null +++ b/OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3PeiDxe.c @@ -0,0 +1,48 @@ +/** @file + Shared code for the PEI fw_cfg and DXE fw_cfg instances of the QemuFwCfg= S3Lib + class. + + Copyright (C) 2017, Red Hat, Inc. + + This program and the accompanying materials are licensed and made availa= ble + under the terms and conditions of the BSD License which accompanies this + distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WI= THOUT + WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +**/ + +#include +#include + +/** + Determine if S3 support is explicitly enabled. + + @retval TRUE If S3 support is explicitly enabled. Other functions in = this + library may be called (subject to their individual + restrictions). + + FALSE Otherwise. This includes unavailability of the firmware + configuration interface. No other function in this libra= ry + must be called. +**/ +BOOLEAN +EFIAPI +QemuFwCfgS3Enabled ( + VOID + ) +{ + RETURN_STATUS Status; + FIRMWARE_CONFIG_ITEM FwCfgItem; + UINTN FwCfgSize; + UINT8 SystemStates[6]; + + Status =3D QemuFwCfgFindFile ("etc/system-states", &FwCfgItem, &FwCfgSiz= e); + if (Status !=3D RETURN_SUCCESS || FwCfgSize !=3D sizeof SystemStates) { + return FALSE; + } + QemuFwCfgSelectItem (FwCfgItem); + QemuFwCfgReadBytes (sizeof SystemStates, SystemStates); + return (BOOLEAN) (SystemStates[3] & BIT7); +} --=20 2.9.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 03:57:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1487814512227796.2367312932864; Wed, 22 Feb 2017 17:48:32 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8D58582265; Wed, 22 Feb 2017 17:48:29 -0800 (PST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 21AB782260 for ; Wed, 22 Feb 2017 17:48:27 -0800 (PST) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id AF10C8046A; Thu, 23 Feb 2017 01:48:27 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-134.phx2.redhat.com [10.3.116.134]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1N1mJFI012836; Wed, 22 Feb 2017 20:48:26 -0500 X-Original-To: edk2-devel@ml01.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Thu, 23 Feb 2017 02:48:06 +0100 Message-Id: <20170223014814.10937-5-lersek@redhat.com> In-Reply-To: <20170223014814.10937-1-lersek@redhat.com> References: <20170223014814.10937-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Thu, 23 Feb 2017 01:48:27 +0000 (UTC) Subject: [edk2] [PATCH 04/12] ArmVirtPkg: resolve QemuFwCfgS3Lib X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" QemuFwCfgS3Enabled() in "ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c" returns constant FALSE. The same implementation is now available factored-out in "OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3Base.c". Resolve QemuFwCfgS3Lib to BaseQemuFwCfgS3LibNull. Cc: Ard Biesheuvel Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D394 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek Reviewed-by: Ard Biesheuvel --- ArmVirtPkg/ArmVirtQemu.dsc | 1 + ArmVirtPkg/ArmVirtQemuKernel.dsc | 1 + 2 files changed, 2 insertions(+) diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index 8fe3c3816961..9c8a2d977a8a 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.dsc @@ -52,6 +52,7 @@ [LibraryClasses.common] VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice= Lib.inf QemuFwCfgLib|ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf + QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf =20 ArmPlatformLib|ArmVirtPkg/Library/ArmVirtPlatformLib/ArmVirtPlatformLib.= inf ArmPlatformSysConfigLib|ArmPlatformPkg/Library/ArmPlatformSysConfigLibNu= ll/ArmPlatformSysConfigLibNull.inf diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKerne= l.dsc index aa40374745af..6afc10e69ef5 100644 --- a/ArmVirtPkg/ArmVirtQemuKernel.dsc +++ b/ArmVirtPkg/ArmVirtQemuKernel.dsc @@ -51,6 +51,7 @@ [LibraryClasses.common] VirtioLib|OvmfPkg/Library/VirtioLib/VirtioLib.inf VirtioMmioDeviceLib|OvmfPkg/Library/VirtioMmioDeviceLib/VirtioMmioDevice= Lib.inf QemuFwCfgLib|ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.inf + QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf =20 ArmPlatformLib|ArmVirtPkg/Library/ArmQemuRelocatablePlatformLib/ArmQemuR= elocatablePlatformLib.inf ArmPlatformSysConfigLib|ArmPlatformPkg/Library/ArmPlatformSysConfigLibNu= ll/ArmPlatformSysConfigLibNull.inf --=20 2.9.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 03:57:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1487814514605145.9063826306085; Wed, 22 Feb 2017 17:48:34 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id D67A482269; Wed, 22 Feb 2017 17:48:29 -0800 (PST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 575A182250 for ; Wed, 22 Feb 2017 17:48:28 -0800 (PST) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E9AECC05681B; Thu, 23 Feb 2017 01:48:28 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-134.phx2.redhat.com [10.3.116.134]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1N1mJFJ012836; Wed, 22 Feb 2017 20:48:28 -0500 X-Original-To: edk2-devel@ml01.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Thu, 23 Feb 2017 02:48:07 +0100 Message-Id: <20170223014814.10937-6-lersek@redhat.com> In-Reply-To: <20170223014814.10937-1-lersek@redhat.com> References: <20170223014814.10937-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 23 Feb 2017 01:48:28 +0000 (UTC) Subject: [edk2] [PATCH 05/12] OvmfPkg: resolve QemuFwCfgS3Lib X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jordan Justen MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" QemuFwCfgS3Enabled() in "OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c" queries the "etc/system-states" fw_cfg file. The same implementation is now available factored-out in "OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3PeiDxe.c". It is available to PEIMs through the PeiQemuFwCfgS3LibFwCfg instance, and to DXE_DRIVER and DXE_RUNTIME_DRIVER modules through the DxeQemuFwCfgS3LibFwCfg instance. Resolve QemuFwCfgS3Lib accordingly. Cc: Jordan Justen Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D394 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- OvmfPkg/OvmfPkgIa32.dsc | 3 +++ OvmfPkg/OvmfPkgIa32X64.dsc | 3 +++ OvmfPkg/OvmfPkgX64.dsc | 3 +++ 3 files changed, 9 insertions(+) diff --git a/OvmfPkg/OvmfPkgIa32.dsc b/OvmfPkg/OvmfPkgIa32.dsc index 993547d4859e..68ac1ba22cae 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -232,6 +232,7 @@ [LibraryClasses.common.PEIM] !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuE= xceptionHandlerLib.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf + QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf =20 [LibraryClasses.common.DXE_CORE] HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf @@ -265,6 +266,7 @@ [LibraryClasses.common.DXE_RUNTIME_DRIVER] UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf + QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf =20 [LibraryClasses.common.UEFI_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf @@ -310,6 +312,7 @@ [LibraryClasses.common.DXE_DRIVER] !endif PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf + QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf =20 [LibraryClasses.common.UEFI_APPLICATION] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf diff --git a/OvmfPkg/OvmfPkgIa32X64.dsc b/OvmfPkg/OvmfPkgIa32X64.dsc index f36604ecb4d8..ee3ca38ba243 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -237,6 +237,7 @@ [LibraryClasses.common.PEIM] !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuE= xceptionHandlerLib.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf + QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf =20 [LibraryClasses.common.DXE_CORE] HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf @@ -270,6 +271,7 @@ [LibraryClasses.common.DXE_RUNTIME_DRIVER] UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf + QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf =20 [LibraryClasses.common.UEFI_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf @@ -315,6 +317,7 @@ [LibraryClasses.common.DXE_DRIVER] !endif PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf + QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf =20 [LibraryClasses.common.UEFI_APPLICATION] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf diff --git a/OvmfPkg/OvmfPkgX64.dsc b/OvmfPkg/OvmfPkgX64.dsc index c5bf1a672b1e..2ae6b5ad4488 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -237,6 +237,7 @@ [LibraryClasses.common.PEIM] !endif CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/PeiCpuE= xceptionHandlerLib.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/PeiMpInitLib.inf + QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf =20 [LibraryClasses.common.DXE_CORE] HobLib|MdePkg/Library/DxeCoreHobLib/DxeCoreHobLib.inf @@ -270,6 +271,7 @@ [LibraryClasses.common.DXE_RUNTIME_DRIVER] UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf BaseCryptLib|CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf + QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf =20 [LibraryClasses.common.UEFI_DRIVER] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf @@ -315,6 +317,7 @@ [LibraryClasses.common.DXE_DRIVER] !endif PciLib|OvmfPkg/Library/DxePciLibI440FxQ35/DxePciLibI440FxQ35.inf MpInitLib|UefiCpuPkg/Library/MpInitLib/DxeMpInitLib.inf + QemuFwCfgS3Lib|OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf =20 [LibraryClasses.common.UEFI_APPLICATION] PcdLib|MdePkg/Library/DxePcdLib/DxePcdLib.inf --=20 2.9.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 03:57:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1487814516816853.704261914962; Wed, 22 Feb 2017 17:48:36 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 21F6A82268; Wed, 22 Feb 2017 17:48:32 -0800 (PST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id C48AC82250 for ; Wed, 22 Feb 2017 17:48:29 -0800 (PST) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 610A33D95F; Thu, 23 Feb 2017 01:48:30 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-134.phx2.redhat.com [10.3.116.134]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1N1mJFK012836; Wed, 22 Feb 2017 20:48:29 -0500 X-Original-To: edk2-devel@ml01.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Thu, 23 Feb 2017 02:48:08 +0100 Message-Id: <20170223014814.10937-7-lersek@redhat.com> In-Reply-To: <20170223014814.10937-1-lersek@redhat.com> References: <20170223014814.10937-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Thu, 23 Feb 2017 01:48:30 +0000 (UTC) Subject: [edk2] [PATCH 06/12] ArmVirtPkg, OvmfPkg: retire QemuFwCfgS3Enabled() from QemuFwCfgLib X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jordan Justen , Ard Biesheuvel MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" At this point we're ready to retire QemuFwCfgS3Enabled() from the QemuFwCfgLib class, together with its implementations in: - ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c - OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c Extend all modules that call the function with a new QemuFwCfgS3Lib class dependency. Thanks to the previously added library class, instances, and class resolutions, we can do this switch now as tightly as possible. Cc: Ard Biesheuvel Cc: Jordan Justen Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D394 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek Reviewed-by: Ard Biesheuvel --- OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf | 1 + OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf | 1 + OvmfPkg/Library/LockBoxLib/LockBoxDxeLib.inf | 1 + OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf | 1 + OvmfPkg/PlatformPei/PlatformPei.inf | 1 + OvmfPkg/SmmControl2Dxe/SmmControl2Dxe.inf | 1 + OvmfPkg/Include/Library/QemuFwCfgLib.h | 14 ---= ------- OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.h | 1 + ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c | 17 ---= --------- OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c | 1 + OvmfPkg/Library/LockBoxLib/LockBoxDxe.c | 1 + OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c | 28 ---= ----------------- OvmfPkg/PlatformPei/Platform.c | 1 + OvmfPkg/SmmControl2Dxe/SmmControl2Dxe.c | 1 + 14 files changed, 11 insertions(+), 59 deletions(-) diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf b/OvmfPkg/AcpiPlat= formDxe/AcpiPlatformDxe.inf index bb5f14e0fc7a..42edc97b3da2 100644 --- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf +++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf @@ -52,6 +52,7 @@ [LibraryClasses] UefiDriverEntryPoint HobLib QemuFwCfgLib + QemuFwCfgS3Lib MemoryAllocationLib BaseLib DxeServicesTableLib diff --git a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf b/OvmfPkg= /AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf index e550ff5a4714..a9350540215d 100644 --- a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf +++ b/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf @@ -44,6 +44,7 @@ [LibraryClasses] MemoryAllocationLib OrderedCollectionLib QemuFwCfgLib + QemuFwCfgS3Lib UefiBootServicesTableLib UefiDriverEntryPoint =20 diff --git a/OvmfPkg/Library/LockBoxLib/LockBoxDxeLib.inf b/OvmfPkg/Library= /LockBoxLib/LockBoxDxeLib.inf index bedf1811e0b2..eb03f4f546bc 100644 --- a/OvmfPkg/Library/LockBoxLib/LockBoxDxeLib.inf +++ b/OvmfPkg/Library/LockBoxLib/LockBoxDxeLib.inf @@ -40,6 +40,7 @@ [LibraryClasses] DebugLib UefiBootServicesTableLib QemuFwCfgLib + QemuFwCfgS3Lib =20 [Protocols] gEfiLockBoxProtocolGuid ## SOMETIMES_PRODUCES diff --git a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.= inf b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf index f9e35c955d4d..27789b7377bc 100644 --- a/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf +++ b/OvmfPkg/Library/PlatformBootManagerLib/PlatformBootManagerLib.inf @@ -52,6 +52,7 @@ [LibraryClasses] PciLib NvVarsFileLib QemuFwCfgLib + QemuFwCfgS3Lib LoadLinuxLib QemuBootOrderLib UefiLib diff --git a/OvmfPkg/PlatformPei/PlatformPei.inf b/OvmfPkg/PlatformPei/Plat= formPei.inf index fbaed3182dcf..53c6dd445a0e 100644 --- a/OvmfPkg/PlatformPei/PlatformPei.inf +++ b/OvmfPkg/PlatformPei/PlatformPei.inf @@ -58,6 +58,7 @@ [LibraryClasses] PeiServicesTablePointerLib PeimEntryPoint QemuFwCfgLib + QemuFwCfgS3Lib MtrrLib PcdLib =20 diff --git a/OvmfPkg/SmmControl2Dxe/SmmControl2Dxe.inf b/OvmfPkg/SmmControl= 2Dxe/SmmControl2Dxe.inf index 31c80bd4448c..04b1ed0e4eb3 100644 --- a/OvmfPkg/SmmControl2Dxe/SmmControl2Dxe.inf +++ b/OvmfPkg/SmmControl2Dxe/SmmControl2Dxe.inf @@ -56,6 +56,7 @@ [LibraryClasses] PcdLib PciLib QemuFwCfgLib + QemuFwCfgS3Lib UefiBootServicesTableLib UefiDriverEntryPoint =20 diff --git a/OvmfPkg/Include/Library/QemuFwCfgLib.h b/OvmfPkg/Include/Libra= ry/QemuFwCfgLib.h index 2a1261327b01..596e3f25d5fe 100644 --- a/OvmfPkg/Include/Library/QemuFwCfgLib.h +++ b/OvmfPkg/Include/Library/QemuFwCfgLib.h @@ -179,19 +179,5 @@ QemuFwCfgFindFile ( OUT UINTN *Size ); =20 - -/** - Determine if S3 support is explicitly enabled. - - @retval TRUE if S3 support is explicitly enabled. - FALSE otherwise. This includes unavailability of the firmware - configuration interface. -**/ -BOOLEAN -EFIAPI -QemuFwCfgS3Enabled ( - VOID - ); - #endif =20 diff --git a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.h b/OvmfPkg= /Library/PlatformBootManagerLib/BdsPlatform.h index ec58efa5ef4a..97ffbb514825 100644 --- a/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.h +++ b/OvmfPkg/Library/PlatformBootManagerLib/BdsPlatform.h @@ -48,6 +48,7 @@ Abstract: #include #include #include +#include #include =20 #include diff --git a/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c b/ArmVirtPkg/Li= brary/QemuFwCfgLib/QemuFwCfgLib.c index 9dd5c911fc5c..fba1684af2b2 100644 --- a/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c +++ b/ArmVirtPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c @@ -637,20 +637,3 @@ QemuFwCfgFindFile ( =20 return RETURN_NOT_FOUND; } - - -/** - Determine if S3 support is explicitly enabled. - - @retval TRUE if S3 support is explicitly enabled. - FALSE otherwise. This includes unavailability of the firmware - configuration interface. -**/ -BOOLEAN -EFIAPI -QemuFwCfgS3Enabled ( - VOID - ) -{ - return FALSE; -} diff --git a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c b/OvmfPkg/AcpiPlatform= Dxe/QemuFwCfgAcpi.c index 6a0ecd1ad962..76512534f5e0 100644 --- a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c +++ b/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include diff --git a/OvmfPkg/Library/LockBoxLib/LockBoxDxe.c b/OvmfPkg/Library/Lock= BoxLib/LockBoxDxe.c index 818646a275a9..3da9cd21e5c9 100644 --- a/OvmfPkg/Library/LockBoxLib/LockBoxDxe.c +++ b/OvmfPkg/Library/LockBoxLib/LockBoxDxe.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include =20 diff --git a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c b/OvmfPkg/Library/= QemuFwCfgLib/QemuFwCfgLib.c index 3dd55ba5042e..1bf725d8b7ae 100644 --- a/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c +++ b/OvmfPkg/Library/QemuFwCfgLib/QemuFwCfgLib.c @@ -368,31 +368,3 @@ QemuFwCfgFindFile ( =20 return RETURN_NOT_FOUND; } - - -/** - Determine if S3 support is explicitly enabled. - - @retval TRUE if S3 support is explicitly enabled. - FALSE otherwise. This includes unavailability of the firmware - configuration interface. -**/ -BOOLEAN -EFIAPI -QemuFwCfgS3Enabled ( - VOID - ) -{ - RETURN_STATUS Status; - FIRMWARE_CONFIG_ITEM FwCfgItem; - UINTN FwCfgSize; - UINT8 SystemStates[6]; - - Status =3D QemuFwCfgFindFile ("etc/system-states", &FwCfgItem, &FwCfgSiz= e); - if (Status !=3D RETURN_SUCCESS || FwCfgSize !=3D sizeof SystemStates) { - return FALSE; - } - QemuFwCfgSelectItem (FwCfgItem); - QemuFwCfgReadBytes (sizeof SystemStates, SystemStates); - return (BOOLEAN) (SystemStates[3] & BIT7); -} diff --git a/OvmfPkg/PlatformPei/Platform.c b/OvmfPkg/PlatformPei/Platform.c index 0be86722e548..77a8a16c15b8 100644 --- a/OvmfPkg/PlatformPei/Platform.c +++ b/OvmfPkg/PlatformPei/Platform.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include diff --git a/OvmfPkg/SmmControl2Dxe/SmmControl2Dxe.c b/OvmfPkg/SmmControl2D= xe/SmmControl2Dxe.c index f31646d73461..bb79fce0855b 100644 --- a/OvmfPkg/SmmControl2Dxe/SmmControl2Dxe.c +++ b/OvmfPkg/SmmControl2Dxe/SmmControl2Dxe.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include --=20 2.9.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 03:57:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 148781451934352.31597847569253; Wed, 22 Feb 2017 17:48:39 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 6EC0F8226E; Wed, 22 Feb 2017 17:48:33 -0800 (PST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 40C958226B for ; Wed, 22 Feb 2017 17:48:31 -0800 (PST) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id CC04BC05678E; Thu, 23 Feb 2017 01:48:31 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-134.phx2.redhat.com [10.3.116.134]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1N1mJFL012836; Wed, 22 Feb 2017 20:48:30 -0500 X-Original-To: edk2-devel@ml01.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Thu, 23 Feb 2017 02:48:09 +0100 Message-Id: <20170223014814.10937-8-lersek@redhat.com> In-Reply-To: <20170223014814.10937-1-lersek@redhat.com> References: <20170223014814.10937-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Thu, 23 Feb 2017 01:48:31 +0000 (UTC) Subject: [edk2] [PATCH 07/12] OvmfPkg/QemuFwCfgS3Lib: add boot script opcode generation APIs to libclass X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jordan Justen MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Introduce the following APIs: - QemuFwCfgS3TransferOwnership(): central function that registers a callback function, with a context parameter, for when ACPI S3 Boot Script opcodes can be produced. This function also allocates reserved memory for the opcodes to operate upon. The client module is supposed to produce the boot script fragment in the callback function. - QemuFwCfgS3WriteBytes(), QemuFwCfgS3ReadBytes(), QemuFwCfgS3SkipBytes(), QemuFwCfgS3CheckValue(): helper functions, available only to the above callback function, for composing the boot script fragment. QemuFwCfgS3SkipBytes() can double as a plain "select" whenever necessary. Cc: Jordan Justen Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D394 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- OvmfPkg/Include/Library/QemuFwCfgS3Lib.h | 318 ++++++++++++++++++++ 1 file changed, 318 insertions(+) diff --git a/OvmfPkg/Include/Library/QemuFwCfgS3Lib.h b/OvmfPkg/Include/Lib= rary/QemuFwCfgS3Lib.h index 1c473610d11c..3499de3c74cc 100644 --- a/OvmfPkg/Include/Library/QemuFwCfgS3Lib.h +++ b/OvmfPkg/Include/Library/QemuFwCfgS3Lib.h @@ -19,6 +19,8 @@ #ifndef __FW_CFG_S3_LIB__ #define __FW_CFG_S3_LIB__ =20 +#include + /** Determine if S3 support is explicitly enabled. =20 @@ -36,4 +38,320 @@ QemuFwCfgS3Enabled ( VOID ); =20 + +/** + Prototype for the callback function that the client module provides. + + In the callback function, the client module calls the + QemuFwCfgS3WriteBytes(), QemuFwCfgS3ReadBytes(), QemuFwCfgS3SkipBytes(),= and + QemuFwCfgS3CheckValue() functions. Those functions produce ACPI S3 Boot + Script opcodes that will perform fw_cfg DMA operations, and will check a= ny + desired values that were read, during S3 resume. + + The callback function is invoked when the production of ACPI S3 Boot Scr= ipt + opcodes becomes possible. This may occur directly on the call stack of + QemuFwCfgS3TransferOwnership() (see below), or after + QemuFwCfgS3TransferOwnership() has successfully returned. + + The callback function must not return if it fails -- in the general case, + there is noone to propagate any errors to. Therefore, on error, an error + message should be logged, and CpuDeadLoop() must be called. + + @param[in,out] Context Carries information from the client module + itself (i.e., from the invocation of + QemuFwCfgS3TransferOwnership()) to the cal= lback + function. + + If Context points to dynamically allocated + storage, then the callback function must + release it. + + @param[in,out] ScratchBuffer Points to reserved memory, allocated by + QemuFwCfgS3TransferOwnership() internally. + + ScratchBuffer is typed and sized by the cl= ient + module when it calls + QemuFwCfgS3TransferOwnership(). The client + module defines a union type of structures = for + ScratchBuffer such that the union can hold + client data for any desired fw_cfg DMA rea= d and + write operations, and value checking. + + The callback function casts ScratchBuffer = to + the union type described above. It passes = union + member sizes as NumberOfBytes to + QemuFwCfgS3ReadBytes() and + QemuFwCfgS3WriteBytes(). It passes field + addresses and sizes in structures in the u= nion + as ScratchData and ValueSize to + QemuFwCfgS3CheckValue(). + + ScratchBuffer is aligned at 8 bytes. +**/ +typedef +VOID (EFIAPI FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION) ( + IN OUT VOID *Context, OPTIONAL + IN OUT VOID *ScratchBuffer + ); + + +/** + Install the client module's FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION callback = for + when the production of ACPI S3 Boot Script opcodes becomes possible. + + Take ownership of the client-provided Context, and pass it to the callba= ck + function, when the latter is invoked. + + Allocate scratch space for those ACPI S3 Boot Script opcodes to work upon + that the client will produce in the callback function. + + @param[in] Append FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION to invo= ke + when the production of ACPI S3 Boot Script + opcodes becomes possible. Append() may be + called immediately from + QemuFwCfgS3TransferOwnership(). + + @param[in,out] Context Client-provided data structure for the App= end() + callback function to consume. + + If Context points to dynamically allocated + memory, then Append() must release it. + + If Context points to dynamically allocated + memory, and QemuFwCfgS3TransferOwnership() + returns successfully, then the caller of + QemuFwCfgS3TransferOwnership() must neither + dereference nor even evaluate Context any + longer, as ownership of the referenced are= a has + been transferred to Append(). + + @param[in] ScratchBufferSize The size of the scratch buffer that will h= old, + in reserved memory, all client data read, + written, and checked by the ACPI S3 Boot S= cript + opcodes produced by Append(). + + @retval RETURN_UNSUPPORTED The library instance does not support t= his + function. + + @retval RETURN_NOT_FOUND The fw_cfg DMA interface to QEMU is + unavailable. + + @retval RETURN_BAD_BUFFER_SIZE ScratchBufferSize is too large. + + @retval RETURN_OUT_OF_RESOURCES Memory allocation failed. + + @retval RETURN_SUCCESS Append() has been installed, and the + ownership of Context has been transferr= ed. + Reserved memory has been allocated for = the + scratch buffer. + + A successful invocation of + QemuFwCfgS3TransferOwnership() cannot be + rolled back. + + @return Error codes from underlying functions. +**/ +EFIAPI +RETURN_STATUS +QemuFwCfgS3TransferOwnership ( + IN FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION *Append, + IN OUT VOID *Context, OPTIONAL + IN UINTN ScratchBufferSize + ); + + +/** + Produce ACPI S3 Boot Script opcodes that (optionally) select an fw_cfg i= tem, + and transfer data to it. + + The opcodes produced by QemuFwCfgS3WriteBytes() will first restore + NumberOfBytes bytes in ScratchBuffer in-place, in reserved memory, then = write + them to fw_cfg using DMA. + + If the operation fails during S3 resume, the boot script will hang. + + This function may only be called from the client module's + FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION, which was passed to + QemuFwCfgS3TransferOwnership() as Append. + + @param[in] FirmwareConfigItem The UINT16 selector key of the firmware c= onfig + item to write, expressed as INT32. If + FirmwareConfigItem is -1, no selection is + made, the write will occur to the current= ly + selected item, at its currently selected + offset. Otherwise, the specified item wil= l be + selected, and the write will occur at off= set + 0. + + @param[in] NumberOfBytes Size of the data to restore in ScratchBuf= fer, + and to write from ScratchBuffer, during S3 + resume. NumberOfBytes must not exceed + ScratchBufferSize, which was passed to + QemuFwCfgS3TransferOwnership(). + + @retval RETURN_SUCCESS The opcodes were appended to the ACPI = S3 + Boot Script successfully. There is no = way + to undo this action. + + @retval RETURN_INVALID_PARAMETER FirmwareConfigItem is invalid. + + @retval RETURN_BAD_BUFFER_SIZE NumberOfBytes is larger than + ScratchBufferSize. + + @return Error codes from underlying functions. +**/ +EFIAPI +RETURN_STATUS +QemuFwCfgS3WriteBytes ( + IN INT32 FirmwareConfigItem, + IN UINTN NumberOfBytes + ); + + +/** + Produce ACPI S3 Boot Script opcodes that (optionally) select an fw_cfg i= tem, + and transfer data from it. + + The opcodes produced by QemuFwCfgS3ReadBytes() will read NumberOfBytes b= ytes + from fw_cfg using DMA, storing the result in ScratchBuffer, in reserved + memory. + + If the operation fails during S3 resume, the boot script will hang. + + This function may only be called from the client module's + FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION, which was passed to + QemuFwCfgS3TransferOwnership() as Append. + + @param[in] FirmwareConfigItem The UINT16 selector key of the firmware c= onfig + item to read, expressed as INT32. If + FirmwareConfigItem is -1, no selection is + made, the read will occur from the curren= tly + selected item, from its currently selected + offset. Otherwise, the specified item wil= l be + selected, and the read will occur from of= fset + 0. + + @param[in] NumberOfBytes Size of the data to read during S3 resume. + NumberOfBytes must not exceed + ScratchBufferSize, which was passed to + QemuFwCfgS3TransferOwnership(). + + @retval RETURN_SUCCESS The opcodes were appended to the ACPI = S3 + Boot Script successfully. There is no = way + to undo this action. + + @retval RETURN_INVALID_PARAMETER FirmwareConfigItem is invalid. + + @retval RETURN_BAD_BUFFER_SIZE NumberOfBytes is larger than + ScratchBufferSize. + + @return Error codes from underlying functions. +**/ +EFIAPI +RETURN_STATUS +QemuFwCfgS3ReadBytes ( + IN INT32 FirmwareConfigItem, + IN UINTN NumberOfBytes + ); + + +/** + Produce ACPI S3 Boot Script opcodes that (optionally) select an fw_cfg i= tem, + and increase its offset. + + If the operation fails during S3 resume, the boot script will hang. + + This function may only be called from the client module's + FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION, which was passed to + QemuFwCfgS3TransferOwnership() as Append. + + @param[in] FirmwareConfigItem The UINT16 selector key of the firmware c= onfig + item to advance the offset of, expressed = as + INT32. If FirmwareConfigItem is -1, no + selection is made, and the offset for the + currently selected item is increased. + Otherwise, the specified item will be + selected, and the offset increment will o= ccur + from offset 0. + + @param[in] NumberOfBytes The number of bytes to skip in the subject + fw_cfg item. + + @retval RETURN_SUCCESS The opcodes were appended to the ACPI = S3 + Boot Script successfully. There is no = way + to undo this action. + + @retval RETURN_INVALID_PARAMETER FirmwareConfigItem is invalid. + + @retval RETURN_BAD_BUFFER_SIZE NumberOfBytes is too large. + + @return Error codes from underlying functions. +**/ +EFIAPI +RETURN_STATUS +QemuFwCfgS3SkipBytes ( + IN INT32 FirmwareConfigItem, + IN UINTN NumberOfBytes + ); + + +/** + Produce ACPI S3 Boot Script opcodes that check a value in ScratchBuffer. + + If the check fails during S3 resume, the boot script will hang. + + This function may only be called from the client module's + FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION, which was passed to + QemuFwCfgS3TransferOwnership() as Append. + + @param[in] ScratchData Pointer to the UINT8, UINT16, UINT32 or UINT64 f= ield + in ScratchBuffer that should be checked. The cal= ler + is responsible for populating the field during S3 + resume, by calling QemuFwCfgS3ReadBytes() ahead = of + QemuFwCfgS3CheckValue(). + + ScratchData must point into ScratchBuffer, which= was + allocated, and passed to Append(), by + QemuFwCfgS3TransferOwnership(). + + ScratchData must be aligned at ValueSize bytes. + + @param[in] ValueSize One of 1, 2, 4 or 8, specifying the size of the = field + to check. + + @param[in] ValueMask The value read from ScratchData is binarily AND-= ed + with ValueMask, and the result is compared again= st + Value. If the masked data equals Value, the check + passes, and the boot script can proceed. Otherwi= se, + the check fails, and the boot script hangs. + + @param[in] Value Refer to ValueMask. + + @retval RETURN_SUCCESS The opcodes were appended to the ACPI = S3 + Boot Script successfully. There is no = way + to undo this action. + + @retval RETURN_INVALID_PARAMETER ValueSize is invalid. + + @retval RETURN_INVALID_PARAMETER ValueMask or Value cannot be represent= ed in + ValueSize bytes. + + @retval RETURN_INVALID_PARAMETER ScratchData is not aligned at ValueSize + bytes. + + @retval RETURN_BAD_BUFFER_SIZE The ValueSize bytes at ScratchData are= n't + wholly contained in the ScratchBufferS= ize + bytes at ScratchBuffer. + + @return Error codes from underlying functions. +**/ +EFIAPI +RETURN_STATUS +QemuFwCfgS3CheckValue ( + IN VOID *ScratchData, + IN UINT8 ValueSize, + IN UINT64 ValueMask, + IN UINT64 Value + ); + #endif --=20 2.9.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 03:57:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1487814521864674.7960185614443; Wed, 22 Feb 2017 17:48:41 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id A780882272; Wed, 22 Feb 2017 17:48:33 -0800 (PST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 801BF8226D for ; Wed, 22 Feb 2017 17:48:32 -0800 (PST) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1004F3A7690; Thu, 23 Feb 2017 01:48:33 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-134.phx2.redhat.com [10.3.116.134]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1N1mJFM012836; Wed, 22 Feb 2017 20:48:32 -0500 X-Original-To: edk2-devel@ml01.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Thu, 23 Feb 2017 02:48:10 +0100 Message-Id: <20170223014814.10937-9-lersek@redhat.com> In-Reply-To: <20170223014814.10937-1-lersek@redhat.com> References: <20170223014814.10937-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Thu, 23 Feb 2017 01:48:33 +0000 (UTC) Subject: [edk2] [PATCH 08/12] OvmfPkg/QemuFwCfgS3Lib: implement opcode APIs for Base Null instance X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jordan Justen MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In the Base Null instance: - QemuFwCfgS3Enabled() returns constant FALSE. This is unique to the Base Null instance, and the function is already present in "QemuFwCfgS3Base.c". - The QemuFwCfgS3TransferOwnership() function must never be called (according to the documentation, given the above). This is also unique to the Base Null instance, so implement the function in "QemuFwCfgS3Base.c". - Consequently, the QemuFwCfgS3WriteBytes(), QemuFwCfgS3ReadBytes(), QemuFwCfgS3SkipBytes(), and QemuFwCfgS3CheckValue() functions must never be called either. This behavior is not unique to the Base Null instance (it will be shared with the PEI fw_cfg instance), so add these functions to "QemuFwCfgS3BasePei.c". Cc: Jordan Justen Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D394 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf | 4 + OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3Base.c | 70 ++++++ OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3BasePei.c | 227 ++++++++++= ++++++++++ 3 files changed, 301 insertions(+) diff --git a/OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf b/Ov= mfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf index ba24a0b9d434..837fd70db6e5 100644 --- a/OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf +++ b/OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf @@ -33,7 +33,11 @@ [Defines] =20 [Sources] QemuFwCfgS3Base.c + QemuFwCfgS3BasePei.c =20 [Packages] MdePkg/MdePkg.dec OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + DebugLib diff --git a/OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3Base.c b/OvmfPkg/Lib= rary/QemuFwCfgS3Lib/QemuFwCfgS3Base.c index bed9bf3dfb57..834ac8e523c7 100644 --- a/OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3Base.c +++ b/OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3Base.c @@ -16,6 +16,7 @@ WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. **/ =20 +#include #include =20 /** @@ -37,3 +38,72 @@ QemuFwCfgS3Enabled ( { return FALSE; } + + +/** + Install the client module's FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION callback = for + when the production of ACPI S3 Boot Script opcodes becomes possible. + + Take ownership of the client-provided Context, and pass it to the callba= ck + function, when the latter is invoked. + + Allocate scratch space for those ACPI S3 Boot Script opcodes to work upon + that the client will produce in the callback function. + + @param[in] Append FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION to invo= ke + when the production of ACPI S3 Boot Script + opcodes becomes possible. Append() may be + called immediately from + QemuFwCfgS3TransferOwnership(). + + @param[in,out] Context Client-provided data structure for the App= end() + callback function to consume. + + If Context points to dynamically allocated + memory, then Append() must release it. + + If Context points to dynamically allocated + memory, and QemuFwCfgS3TransferOwnership() + returns successfully, then the caller of + QemuFwCfgS3TransferOwnership() must neither + dereference nor even evaluate Context any + longer, as ownership of the referenced are= a has + been transferred to Append(). + + @param[in] ScratchBufferSize The size of the scratch buffer that will h= old, + in reserved memory, all client data read, + written, and checked by the ACPI S3 Boot S= cript + opcodes produced by Append(). + + @retval RETURN_UNSUPPORTED The library instance does not support t= his + function. + + @retval RETURN_NOT_FOUND The fw_cfg DMA interface to QEMU is + unavailable. + + @retval RETURN_BAD_BUFFER_SIZE ScratchBufferSize is too large. + + @retval RETURN_OUT_OF_RESOURCES Memory allocation failed. + + @retval RETURN_SUCCESS Append() has been installed, and the + ownership of Context has been transferr= ed. + Reserved memory has been allocated for = the + scratch buffer. + + A successful invocation of + QemuFwCfgS3TransferOwnership() cannot be + rolled back. + + @return Error codes from underlying functions. +**/ +EFIAPI +RETURN_STATUS +QemuFwCfgS3TransferOwnership ( + IN FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION *Append, + IN OUT VOID *Context, OPTIONAL + IN UINTN ScratchBufferSize + ) +{ + ASSERT (FALSE); + return RETURN_UNSUPPORTED; +} diff --git a/OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3BasePei.c b/OvmfPkg/= Library/QemuFwCfgS3Lib/QemuFwCfgS3BasePei.c new file mode 100644 index 000000000000..537678999c5f --- /dev/null +++ b/OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3BasePei.c @@ -0,0 +1,227 @@ +/** @file + Shared code for the Base Null and PEI fw_cfg instances of the QemuFwCfgS= 3Lib + class. + + Copyright (C) 2017, Red Hat, Inc. + + This program and the accompanying materials are licensed and made availa= ble + under the terms and conditions of the BSD License which accompanies this + distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WI= THOUT + WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +**/ + +#include +#include + +/** + Produce ACPI S3 Boot Script opcodes that (optionally) select an fw_cfg i= tem, + and transfer data to it. + + The opcodes produced by QemuFwCfgS3WriteBytes() will first restore + NumberOfBytes bytes in ScratchBuffer in-place, in reserved memory, then = write + them to fw_cfg using DMA. + + If the operation fails during S3 resume, the boot script will hang. + + This function may only be called from the client module's + FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION, which was passed to + QemuFwCfgS3TransferOwnership() as Append. + + @param[in] FirmwareConfigItem The UINT16 selector key of the firmware c= onfig + item to write, expressed as INT32. If + FirmwareConfigItem is -1, no selection is + made, the write will occur to the current= ly + selected item, at its currently selected + offset. Otherwise, the specified item wil= l be + selected, and the write will occur at off= set + 0. + + @param[in] NumberOfBytes Size of the data to restore in ScratchBuf= fer, + and to write from ScratchBuffer, during S3 + resume. NumberOfBytes must not exceed + ScratchBufferSize, which was passed to + QemuFwCfgS3TransferOwnership(). + + @retval RETURN_SUCCESS The opcodes were appended to the ACPI = S3 + Boot Script successfully. There is no = way + to undo this action. + + @retval RETURN_INVALID_PARAMETER FirmwareConfigItem is invalid. + + @retval RETURN_BAD_BUFFER_SIZE NumberOfBytes is larger than + ScratchBufferSize. + + @return Error codes from underlying functions. +**/ +EFIAPI +RETURN_STATUS +QemuFwCfgS3WriteBytes ( + IN INT32 FirmwareConfigItem, + IN UINTN NumberOfBytes + ) +{ + ASSERT (FALSE); + return RETURN_UNSUPPORTED; +} + + +/** + Produce ACPI S3 Boot Script opcodes that (optionally) select an fw_cfg i= tem, + and transfer data from it. + + The opcodes produced by QemuFwCfgS3ReadBytes() will read NumberOfBytes b= ytes + from fw_cfg using DMA, storing the result in ScratchBuffer, in reserved + memory. + + If the operation fails during S3 resume, the boot script will hang. + + This function may only be called from the client module's + FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION, which was passed to + QemuFwCfgS3TransferOwnership() as Append. + + @param[in] FirmwareConfigItem The UINT16 selector key of the firmware c= onfig + item to read, expressed as INT32. If + FirmwareConfigItem is -1, no selection is + made, the read will occur from the curren= tly + selected item, from its currently selected + offset. Otherwise, the specified item wil= l be + selected, and the read will occur from of= fset + 0. + + @param[in] NumberOfBytes Size of the data to read during S3 resume. + NumberOfBytes must not exceed + ScratchBufferSize, which was passed to + QemuFwCfgS3TransferOwnership(). + + @retval RETURN_SUCCESS The opcodes were appended to the ACPI = S3 + Boot Script successfully. There is no = way + to undo this action. + + @retval RETURN_INVALID_PARAMETER FirmwareConfigItem is invalid. + + @retval RETURN_BAD_BUFFER_SIZE NumberOfBytes is larger than + ScratchBufferSize. + + @return Error codes from underlying functions. +**/ +EFIAPI +RETURN_STATUS +QemuFwCfgS3ReadBytes ( + IN INT32 FirmwareConfigItem, + IN UINTN NumberOfBytes + ) +{ + ASSERT (FALSE); + return RETURN_UNSUPPORTED; +} + + +/** + Produce ACPI S3 Boot Script opcodes that (optionally) select an fw_cfg i= tem, + and increase its offset. + + If the operation fails during S3 resume, the boot script will hang. + + This function may only be called from the client module's + FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION, which was passed to + QemuFwCfgS3TransferOwnership() as Append. + + @param[in] FirmwareConfigItem The UINT16 selector key of the firmware c= onfig + item to advance the offset of, expressed = as + INT32. If FirmwareConfigItem is -1, no + selection is made, and the offset for the + currently selected item is increased. + Otherwise, the specified item will be + selected, and the offset increment will o= ccur + from offset 0. + + @param[in] NumberOfBytes The number of bytes to skip in the subject + fw_cfg item. + + @retval RETURN_SUCCESS The opcodes were appended to the ACPI = S3 + Boot Script successfully. There is no = way + to undo this action. + + @retval RETURN_INVALID_PARAMETER FirmwareConfigItem is invalid. + + @retval RETURN_BAD_BUFFER_SIZE NumberOfBytes is too large. + + @return Error codes from underlying functions. +**/ +EFIAPI +RETURN_STATUS +QemuFwCfgS3SkipBytes ( + IN INT32 FirmwareConfigItem, + IN UINTN NumberOfBytes + ) +{ + ASSERT (FALSE); + return RETURN_UNSUPPORTED; +} + + +/** + Produce ACPI S3 Boot Script opcodes that check a value in ScratchBuffer. + + If the check fails during S3 resume, the boot script will hang. + + This function may only be called from the client module's + FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION, which was passed to + QemuFwCfgS3TransferOwnership() as Append. + + @param[in] ScratchData Pointer to the UINT8, UINT16, UINT32 or UINT64 f= ield + in ScratchBuffer that should be checked. The cal= ler + is responsible for populating the field during S3 + resume, by calling QemuFwCfgS3ReadBytes() ahead = of + QemuFwCfgS3CheckValue(). + + ScratchData must point into ScratchBuffer, which= was + allocated, and passed to Append(), by + QemuFwCfgS3TransferOwnership(). + + ScratchData must be aligned at ValueSize bytes. + + @param[in] ValueSize One of 1, 2, 4 or 8, specifying the size of the = field + to check. + + @param[in] ValueMask The value read from ScratchData is binarily AND-= ed + with ValueMask, and the result is compared again= st + Value. If the masked data equals Value, the check + passes, and the boot script can proceed. Otherwi= se, + the check fails, and the boot script hangs. + + @param[in] Value Refer to ValueMask. + + @retval RETURN_SUCCESS The opcodes were appended to the ACPI = S3 + Boot Script successfully. There is no = way + to undo this action. + + @retval RETURN_INVALID_PARAMETER ValueSize is invalid. + + @retval RETURN_INVALID_PARAMETER ValueMask or Value cannot be represent= ed in + ValueSize bytes. + + @retval RETURN_INVALID_PARAMETER ScratchData is not aligned at ValueSize + bytes. + + @retval RETURN_BAD_BUFFER_SIZE The ValueSize bytes at ScratchData are= n't + wholly contained in the ScratchBufferS= ize + bytes at ScratchBuffer. + + @return Error codes from underlying functions. +**/ +EFIAPI +RETURN_STATUS +QemuFwCfgS3CheckValue ( + IN VOID *ScratchData, + IN UINT8 ValueSize, + IN UINT64 ValueMask, + IN UINT64 Value + ) +{ + ASSERT (FALSE); + return RETURN_UNSUPPORTED; +} --=20 2.9.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 03:57:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1487814524330653.4116755591574; Wed, 22 Feb 2017 17:48:44 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E03B382273; Wed, 22 Feb 2017 17:48:34 -0800 (PST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id A8CED82273 for ; Wed, 22 Feb 2017 17:48:33 -0800 (PST) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 479897F36F; Thu, 23 Feb 2017 01:48:34 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-134.phx2.redhat.com [10.3.116.134]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1N1mJFN012836; Wed, 22 Feb 2017 20:48:33 -0500 X-Original-To: edk2-devel@ml01.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Thu, 23 Feb 2017 02:48:11 +0100 Message-Id: <20170223014814.10937-10-lersek@redhat.com> In-Reply-To: <20170223014814.10937-1-lersek@redhat.com> References: <20170223014814.10937-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Thu, 23 Feb 2017 01:48:34 +0000 (UTC) Subject: [edk2] [PATCH 09/12] OvmfPkg/QemuFwCfgS3Lib: implement opcode APIs for PEI fw_cfg instance X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jordan Justen MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In the PEI fw_cfg instance: - QemuFwCfgS3Enabled() queries S3 enablement via fw_cfg. This behavior is shared with the DXE fw_cfg instance, and the PEI fw_cfg instance already pulls in the function from "QemuFwCfgS3PeiDxe.c". - If QemuFwCfgS3Enabled() returns TRUE, the client module is permitted to call QemuFwCfgS3TransferOwnership(). However, in the PEI phase we have no support for capturing ACPI S3 Boot Script opcodes, hence we return RETURN_UNSUPPORTED unconditionally. This behavior is unique to the PEI fw_cfg instance, so add the function to "QemuFwCfgS3Pei.c". - Consequently, the QemuFwCfgS3WriteBytes(), QemuFwCfgS3ReadBytes(), QemuFwCfgS3SkipBytes(), and QemuFwCfgS3CheckValue() functions must never be called. (They could only be called from the client module's callback, but QemuFwCfgS3TransferOwnership() will never install such callback in the PEI fw_cfg instance -- see above.) This behavior is not unique to the PEI fw_cfg instance (it is shared with the Base Null instance), so pull in these functions from "QemuFwCfgS3BasePei.c". Cc: Jordan Justen Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D394 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- OvmfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf | 3 + OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3Pei.c | 85 +++++++++++= +++++++++ 2 files changed, 88 insertions(+) diff --git a/OvmfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf b/Ov= mfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf index 2593af8e5b4c..890862076e81 100644 --- a/OvmfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf +++ b/OvmfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf @@ -31,6 +31,8 @@ [Defines] # =20 [Sources] + QemuFwCfgS3BasePei.c + QemuFwCfgS3Pei.c QemuFwCfgS3PeiDxe.c =20 [Packages] @@ -38,4 +40,5 @@ [Packages] OvmfPkg/OvmfPkg.dec =20 [LibraryClasses] + DebugLib QemuFwCfgLib diff --git a/OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3Pei.c b/OvmfPkg/Libr= ary/QemuFwCfgS3Lib/QemuFwCfgS3Pei.c new file mode 100644 index 000000000000..77ed058884e1 --- /dev/null +++ b/OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3Pei.c @@ -0,0 +1,85 @@ +/** @file + Limited functionality QemuFwCfgS3Lib instance, for PEI phase modules. + + QemuFwCfgS3Enabled() queries S3 enablement via fw_cfg. Other library APIs + will report lack of support. + + Copyright (C) 2017, Red Hat, Inc. + + This program and the accompanying materials are licensed and made availa= ble + under the terms and conditions of the BSD License which accompanies this + distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WI= THOUT + WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +**/ + +#include + +/** + Install the client module's FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION callback = for + when the production of ACPI S3 Boot Script opcodes becomes possible. + + Take ownership of the client-provided Context, and pass it to the callba= ck + function, when the latter is invoked. + + Allocate scratch space for those ACPI S3 Boot Script opcodes to work upon + that the client will produce in the callback function. + + @param[in] Append FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION to invo= ke + when the production of ACPI S3 Boot Script + opcodes becomes possible. Append() may be + called immediately from + QemuFwCfgS3TransferOwnership(). + + @param[in,out] Context Client-provided data structure for the App= end() + callback function to consume. + + If Context points to dynamically allocated + memory, then Append() must release it. + + If Context points to dynamically allocated + memory, and QemuFwCfgS3TransferOwnership() + returns successfully, then the caller of + QemuFwCfgS3TransferOwnership() must neither + dereference nor even evaluate Context any + longer, as ownership of the referenced are= a has + been transferred to Append(). + + @param[in] ScratchBufferSize The size of the scratch buffer that will h= old, + in reserved memory, all client data read, + written, and checked by the ACPI S3 Boot S= cript + opcodes produced by Append(). + + @retval RETURN_UNSUPPORTED The library instance does not support t= his + function. + + @retval RETURN_NOT_FOUND The fw_cfg DMA interface to QEMU is + unavailable. + + @retval RETURN_BAD_BUFFER_SIZE ScratchBufferSize is too large. + + @retval RETURN_OUT_OF_RESOURCES Memory allocation failed. + + @retval RETURN_SUCCESS Append() has been installed, and the + ownership of Context has been transferr= ed. + Reserved memory has been allocated for = the + scratch buffer. + + A successful invocation of + QemuFwCfgS3TransferOwnership() cannot be + rolled back. + + @return Error codes from underlying functions. +**/ +EFIAPI +RETURN_STATUS +QemuFwCfgS3TransferOwnership ( + IN FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION *Append, + IN OUT VOID *Context, OPTIONAL + IN UINTN ScratchBufferSize + ) +{ + return RETURN_UNSUPPORTED; +} --=20 2.9.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 03:57:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1487814526769156.11210717801532; Wed, 22 Feb 2017 17:48:46 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 255C58226D; Wed, 22 Feb 2017 17:48:38 -0800 (PST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 20F6C82278 for ; Wed, 22 Feb 2017 17:48:35 -0800 (PST) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B0361C049D5D; Thu, 23 Feb 2017 01:48:35 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-134.phx2.redhat.com [10.3.116.134]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1N1mJFO012836; Wed, 22 Feb 2017 20:48:34 -0500 X-Original-To: edk2-devel@ml01.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Thu, 23 Feb 2017 02:48:12 +0100 Message-Id: <20170223014814.10937-11-lersek@redhat.com> In-Reply-To: <20170223014814.10937-1-lersek@redhat.com> References: <20170223014814.10937-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 23 Feb 2017 01:48:35 +0000 (UTC) Subject: [edk2] [PATCH 10/12] OvmfPkg/QemuFwCfgS3Lib: implement opcode APIs for DXE fw_cfg instance X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jordan Justen MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" In the DXE fw_cfg instance: - QemuFwCfgS3Enabled() queries S3 enablement via fw_cfg. This behavior is shared with the PEI fw_cfg instance, and the DXE fw_cfg instance already pulls in the function from "QemuFwCfgS3PeiDxe.c". - If QemuFwCfgS3Enabled() returns TRUE, the client module is permitted to call QemuFwCfgS3TransferOwnership(). We provide a fully functional implementation for QemuFwCfgS3TransferOwnership(). A protocol notify is installed at TPL_CALLBACK for EFI_S3_SAVE_STATE_PROTOCOL. If / once the protocol is available, the client module's Append() function is called, which is expected to produce ACPI S3 Boot Script opcodes using the helper functions listed below. In QemuFwCfgS3TransferOwnership(), we also allocate a reserved memory buffer, sized & typed by the client module, for the opcodes and (internally) the fw_cfg DMA operations to work upon, during S3 resume. This behavior is unique to the DXE fw_cfg instance. Thus, add the function to "QemuFwCfgS3Dxe.c". - The QemuFwCfgS3WriteBytes(), QemuFwCfgS3ReadBytes(), QemuFwCfgS3SkipBytes(), and QemuFwCfgS3CheckValue() functions are also implemented usefully, since the client module's Append() function is expected to invoke them. Each of the first three functions produces MEM_WRITE, IO_WRITE, and MEM_POLL opcodes, to set up the DMA command in reserved memory, to start the DMA transfer, and to check the DMA result, respectively. The QemuFwCfgS3CheckValue() function produces a MEM_POLL opcode to validate an unsigned integer field in data that was read via QemuFwCfgS3ReadBytes(). This behavior is again unique to the DXE fw_cfg instance, so add the functions to "QemuFwCfgS3Dxe.c". Cc: Jordan Justen Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D394 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf | 8 + OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3Dxe.c | 791 ++++++++++= ++++++++++ 2 files changed, 799 insertions(+) diff --git a/OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf b/Ov= mfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf index 7016575f3dab..a0e4275cb8a5 100644 --- a/OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf +++ b/OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf @@ -28,6 +28,7 @@ [Defines] # =20 [Sources] + QemuFwCfgS3Dxe.c QemuFwCfgS3PeiDxe.c =20 [Packages] @@ -35,4 +36,11 @@ [Packages] OvmfPkg/OvmfPkg.dec =20 [LibraryClasses] + BaseLib + DebugLib + MemoryAllocationLib QemuFwCfgLib + UefiBootServicesTableLib + +[Protocols] + gEfiS3SaveStateProtocolGuid ## SOMETIMES_CONSUMES diff --git a/OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3Dxe.c b/OvmfPkg/Libr= ary/QemuFwCfgS3Lib/QemuFwCfgS3Dxe.c new file mode 100644 index 000000000000..51d99d66a98b --- /dev/null +++ b/OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3Dxe.c @@ -0,0 +1,791 @@ +/** @file + Full functionality QemuFwCfgS3Lib instance, for DXE phase modules. + + Copyright (C) 2017, Red Hat, Inc. + + This program and the accompanying materials are licensed and made availa= ble + under the terms and conditions of the BSD License which accompanies this + distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WI= THOUT + WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +**/ + +#include +#include +#include +#include +#include +#include +#include + + +// +// Event to signal when the S3SaveState protocol interface is installed. +// +STATIC EFI_EVENT mS3SaveStateInstalledEvent; + +// +// Reference to the S3SaveState protocol interface, after it is installed. +// +STATIC EFI_S3_SAVE_STATE_PROTOCOL *mS3SaveState; + +// +// The control structure is allocated in reserved memory, aligned at 8 byt= es. +// The client-requested ScratchBuffer will be allocated adjacently, also +// aligned at 8 bytes. +// +#define RESERVED_MEM_ALIGNMENT 8 + +STATIC FW_CFG_DMA_ACCESS *mDmaAccess; +STATIC VOID *mScratchBuffer; +STATIC UINTN mScratchBufferSize; + +// +// Callback provided by the client, for appending ACPI S3 Boot Script opco= des. +// To be called from S3SaveStateInstalledNotify(). +// +STATIC FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION *mAppend; + + +/** + Event notification function for mS3SaveStateInstalledEvent. +**/ +STATIC +VOID +EFIAPI +S3SaveStateInstalledNotify ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + + ASSERT (Event =3D=3D mS3SaveStateInstalledEvent); + + Status =3D gBS->LocateProtocol (&gEfiS3SaveStateProtocolGuid, + NULL /* Registration */, (VOID **)&mS3SaveState); + if (EFI_ERROR (Status)) { + return; + } + + ASSERT (mAppend !=3D NULL); + + DEBUG ((DEBUG_INFO, "%a: %a: DmaAccess@0x%Lx ScratchBuffer@[0x%Lx+0x%Lx]= \n", + gEfiCallerBaseName, __FUNCTION__, (UINT64)(UINTN)mDmaAccess, + (UINT64)(UINTN)mScratchBuffer, (UINT64)mScratchBufferSize)); + mAppend (Context, mScratchBuffer); + + gBS->CloseEvent (mS3SaveStateInstalledEvent); + mS3SaveStateInstalledEvent =3D NULL; +} + + +/** + Install the client module's FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION callback = for + when the production of ACPI S3 Boot Script opcodes becomes possible. + + Take ownership of the client-provided Context, and pass it to the callba= ck + function, when the latter is invoked. + + Allocate scratch space for those ACPI S3 Boot Script opcodes to work upon + that the client will produce in the callback function. + + @param[in] Append FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION to invo= ke + when the production of ACPI S3 Boot Script + opcodes becomes possible. Append() may be + called immediately from + QemuFwCfgS3TransferOwnership(). + + @param[in,out] Context Client-provided data structure for the App= end() + callback function to consume. + + If Context points to dynamically allocated + memory, then Append() must release it. + + If Context points to dynamically allocated + memory, and QemuFwCfgS3TransferOwnership() + returns successfully, then the caller of + QemuFwCfgS3TransferOwnership() must neither + dereference nor even evaluate Context any + longer, as ownership of the referenced are= a has + been transferred to Append(). + + @param[in] ScratchBufferSize The size of the scratch buffer that will h= old, + in reserved memory, all client data read, + written, and checked by the ACPI S3 Boot S= cript + opcodes produced by Append(). + + @retval RETURN_UNSUPPORTED The library instance does not support t= his + function. + + @retval RETURN_NOT_FOUND The fw_cfg DMA interface to QEMU is + unavailable. + + @retval RETURN_BAD_BUFFER_SIZE ScratchBufferSize is too large. + + @retval RETURN_OUT_OF_RESOURCES Memory allocation failed. + + @retval RETURN_SUCCESS Append() has been installed, and the + ownership of Context has been transferr= ed. + Reserved memory has been allocated for = the + scratch buffer. + + A successful invocation of + QemuFwCfgS3TransferOwnership() cannot be + rolled back. + + @return Error codes from underlying functions. +**/ +EFIAPI +RETURN_STATUS +QemuFwCfgS3TransferOwnership ( + IN FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION *Append, + IN OUT VOID *Context, OPTIONAL + IN UINTN ScratchBufferSize + ) +{ + EFI_STATUS Status; + VOID *Registration; + + // + // Basic fw_cfg is certainly available, as we can only be here after a + // successful call to QemuFwCfgS3Enabled(). Check fw_cfg DMA availabilit= y. + // + ASSERT (QemuFwCfgIsAvailable ()); + QemuFwCfgSelectItem (QemuFwCfgItemInterfaceVersion); + if ((QemuFwCfgRead32 () & FW_CFG_F_DMA) =3D=3D 0) { + DEBUG ((DEBUG_ERROR, "%a: %a: fw_cfg DMA unavailable\n", + gEfiCallerBaseName, __FUNCTION__)); + return RETURN_NOT_FOUND; + } + + // + // Allocate a reserved buffer for the DMA access control structure and t= he + // client data together. + // + if (ScratchBufferSize > + MAX_UINT32 - (RESERVED_MEM_ALIGNMENT - 1) - sizeof *mDmaAccess) { + DEBUG ((DEBUG_ERROR, "%a: %a: ScratchBufferSize too big: %Lu\n", + gEfiCallerBaseName, __FUNCTION__, (UINT64)ScratchBufferSize)); + return RETURN_BAD_BUFFER_SIZE; + } + mDmaAccess =3D AllocateReservedPool ((RESERVED_MEM_ALIGNMENT - 1) + + sizeof *mDmaAccess + ScratchBufferSize); + if (mDmaAccess =3D=3D NULL) { + DEBUG ((DEBUG_ERROR, "%a: %a: AllocateReservedPool(): out of resources= \n", + gEfiCallerBaseName, __FUNCTION__)); + return RETURN_OUT_OF_RESOURCES; + } + mDmaAccess =3D ALIGN_POINTER (mDmaAccess, RESERVED_MEM_ALIGNMENT); + + // + // Set up a protocol notify for EFI_S3_SAVE_STATE_PROTOCOL. Forward the + // client's Context to the callback. + // + Status =3D gBS->CreateEvent (EVT_NOTIFY_SIGNAL, TPL_CALLBACK, + S3SaveStateInstalledNotify, Context, + &mS3SaveStateInstalledEvent); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: %a: CreateEvent(): %r\n", gEfiCallerBaseName, + __FUNCTION__, Status)); + goto FreeDmaAccess; + } + Status =3D gBS->RegisterProtocolNotify (&gEfiS3SaveStateProtocolGuid, + mS3SaveStateInstalledEvent, &Registration); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: %a: RegisterProtocolNotify(): %r\n", + gEfiCallerBaseName, __FUNCTION__, Status)); + goto CloseEvent; + } + + // + // Set the remaining global variables. For the alignment guarantee on + // mScratchBuffer, we rely on the fact that *mDmaAccess has a size that = is an + // integral multiple of RESERVED_MEM_ALIGNMENT. + // + ASSERT (sizeof *mDmaAccess % RESERVED_MEM_ALIGNMENT =3D=3D 0); + mScratchBuffer =3D mDmaAccess + 1; + mScratchBufferSize =3D ScratchBufferSize; + mAppend =3D Append; + + // + // Kick the event; EFI_S3_SAVE_STATE_PROTOCOL could be available already. + // + Status =3D gBS->SignalEvent (mS3SaveStateInstalledEvent); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: %a: SignalEvent(): %r\n", gEfiCallerBaseName, + __FUNCTION__, Status)); + goto NullGlobals; + } + + return RETURN_SUCCESS; + +NullGlobals: + mScratchBuffer =3D NULL; + mScratchBufferSize =3D 0; + mAppend =3D NULL; + +CloseEvent: + gBS->CloseEvent (mS3SaveStateInstalledEvent); + mS3SaveStateInstalledEvent =3D NULL; + +FreeDmaAccess: + FreePool (mDmaAccess); + mDmaAccess =3D NULL; + + return (RETURN_STATUS)Status; +} + + +/** + Produce ACPI S3 Boot Script opcodes that (optionally) select an fw_cfg i= tem, + and transfer data to it. + + The opcodes produced by QemuFwCfgS3WriteBytes() will first restore + NumberOfBytes bytes in ScratchBuffer in-place, in reserved memory, then = write + them to fw_cfg using DMA. + + If the operation fails during S3 resume, the boot script will hang. + + This function may only be called from the client module's + FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION, which was passed to + QemuFwCfgS3TransferOwnership() as Append. + + @param[in] FirmwareConfigItem The UINT16 selector key of the firmware c= onfig + item to write, expressed as INT32. If + FirmwareConfigItem is -1, no selection is + made, the write will occur to the current= ly + selected item, at its currently selected + offset. Otherwise, the specified item wil= l be + selected, and the write will occur at off= set + 0. + + @param[in] NumberOfBytes Size of the data to restore in ScratchBuf= fer, + and to write from ScratchBuffer, during S3 + resume. NumberOfBytes must not exceed + ScratchBufferSize, which was passed to + QemuFwCfgS3TransferOwnership(). + + @retval RETURN_SUCCESS The opcodes were appended to the ACPI = S3 + Boot Script successfully. There is no = way + to undo this action. + + @retval RETURN_INVALID_PARAMETER FirmwareConfigItem is invalid. + + @retval RETURN_BAD_BUFFER_SIZE NumberOfBytes is larger than + ScratchBufferSize. + + @return Error codes from underlying functions. +**/ +EFIAPI +RETURN_STATUS +QemuFwCfgS3WriteBytes ( + IN INT32 FirmwareConfigItem, + IN UINTN NumberOfBytes + ) +{ + UINTN Count; + EFI_STATUS Status; + UINT64 AccessAddress; + UINT32 ControlPollData; + UINT32 ControlPollMask; + + ASSERT (mDmaAccess !=3D NULL); + ASSERT (mS3SaveState !=3D NULL); + + if (FirmwareConfigItem < -1 || FirmwareConfigItem > MAX_UINT16) { + return RETURN_INVALID_PARAMETER; + } + if (NumberOfBytes > mScratchBufferSize) { + return RETURN_BAD_BUFFER_SIZE; + } + + // + // Set up a write[+select] fw_cfg DMA command. + // + mDmaAccess->Control =3D FW_CFG_DMA_CTL_WRITE; + if (FirmwareConfigItem !=3D -1) { + mDmaAccess->Control |=3D FW_CFG_DMA_CTL_SELECT; + mDmaAccess->Control |=3D (UINT32)FirmwareConfigItem << 16; + } + mDmaAccess->Control =3D SwapBytes32 (mDmaAccess->Control); + + // + // We ensured the following constraint via mScratchBufferSize in + // QemuFwCfgS3TransferOwnership(). + // + ASSERT (NumberOfBytes <=3D MAX_UINT32); + mDmaAccess->Length =3D SwapBytes32 ((UINT32)NumberOfBytes); + + mDmaAccess->Address =3D SwapBytes64 ((UINTN)mScratchBuffer); + + // + // Copy mDmaAccess and NumberOfBytes bytes from mScratchBuffer into the = boot + // script. When executed at S3 resume, this opcode will restore all of t= hem + // in-place. + // + Count =3D (UINTN)mScratchBuffer + NumberOfBytes - (UINTN)mDmaAccess; + Status =3D mS3SaveState->Write ( + mS3SaveState, // This + EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE, // OpCode + EfiBootScriptWidthUint8, // Width + (UINT64)(UINTN)mDmaAccess, // Address + Count, // Count + (VOID *)mDmaAccess // Buffer + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: %a: EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE: %r\n", + gEfiCallerBaseName, __FUNCTION__, Status)); + return (RETURN_STATUS)Status; + } + + // + // Append an opcode that will write the address of the fw_cfg DMA comman= d to + // the fw_cfg DMA address register, which consists of two 32-bit IO port= s. + // The second (highest address, least significant) write will start the + // transfer. + // + AccessAddress =3D SwapBytes64 ((UINTN)mDmaAccess); + Status =3D mS3SaveState->Write ( + mS3SaveState, // This + EFI_BOOT_SCRIPT_IO_WRITE_OPCODE, // OpCode + EfiBootScriptWidthUint32, // Width + (UINT64)FW_CFG_IO_DMA_ADDRESS, // Address + (UINTN)2, // Count + (VOID *)&AccessAddress // Buffer + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: %a: EFI_BOOT_SCRIPT_IO_WRITE_OPCODE: %r\n", + gEfiCallerBaseName, __FUNCTION__, Status)); + return (RETURN_STATUS)Status; + } + + // + // The following opcode will wait until the Control word reads as zero + // (transfer complete). As timeout we use MAX_UINT64 * 100ns, which is + // approximately 58494 years. + // + ControlPollData =3D 0; + ControlPollMask =3D MAX_UINT32; + Status =3D mS3SaveState->Write ( + mS3SaveState, // This + EFI_BOOT_SCRIPT_MEM_POLL_OPCODE, // OpCode + EfiBootScriptWidthUint32, // Width + (UINT64)(UINTN)&mDmaAccess->Control, // Address + (VOID *)&ControlPollData, // Data + (VOID *)&ControlPollMask, // DataMask + MAX_UINT64 // Delay + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: %a: EFI_BOOT_SCRIPT_MEM_POLL_OPCODE: %r\n", + gEfiCallerBaseName, __FUNCTION__, Status)); + return (RETURN_STATUS)Status; + } + + return RETURN_SUCCESS; +} + + +/** + Produce ACPI S3 Boot Script opcodes that (optionally) select an fw_cfg i= tem, + and transfer data from it. + + The opcodes produced by QemuFwCfgS3ReadBytes() will read NumberOfBytes b= ytes + from fw_cfg using DMA, storing the result in ScratchBuffer, in reserved + memory. + + If the operation fails during S3 resume, the boot script will hang. + + This function may only be called from the client module's + FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION, which was passed to + QemuFwCfgS3TransferOwnership() as Append. + + @param[in] FirmwareConfigItem The UINT16 selector key of the firmware c= onfig + item to read, expressed as INT32. If + FirmwareConfigItem is -1, no selection is + made, the read will occur from the curren= tly + selected item, from its currently selected + offset. Otherwise, the specified item wil= l be + selected, and the read will occur from of= fset + 0. + + @param[in] NumberOfBytes Size of the data to read during S3 resume. + NumberOfBytes must not exceed + ScratchBufferSize, which was passed to + QemuFwCfgS3TransferOwnership(). + + @retval RETURN_SUCCESS The opcodes were appended to the ACPI = S3 + Boot Script successfully. There is no = way + to undo this action. + + @retval RETURN_INVALID_PARAMETER FirmwareConfigItem is invalid. + + @retval RETURN_BAD_BUFFER_SIZE NumberOfBytes is larger than + ScratchBufferSize. + + @return Error codes from underlying functions. +**/ +EFIAPI +RETURN_STATUS +QemuFwCfgS3ReadBytes ( + IN INT32 FirmwareConfigItem, + IN UINTN NumberOfBytes + ) +{ + EFI_STATUS Status; + UINT64 AccessAddress; + UINT32 ControlPollData; + UINT32 ControlPollMask; + + ASSERT (mDmaAccess !=3D NULL); + ASSERT (mS3SaveState !=3D NULL); + + if (FirmwareConfigItem < -1 || FirmwareConfigItem > MAX_UINT16) { + return RETURN_INVALID_PARAMETER; + } + if (NumberOfBytes > mScratchBufferSize) { + return RETURN_BAD_BUFFER_SIZE; + } + + // + // Set up a read[+select] fw_cfg DMA command. + // + mDmaAccess->Control =3D FW_CFG_DMA_CTL_READ; + if (FirmwareConfigItem !=3D -1) { + mDmaAccess->Control |=3D FW_CFG_DMA_CTL_SELECT; + mDmaAccess->Control |=3D (UINT32)FirmwareConfigItem << 16; + } + mDmaAccess->Control =3D SwapBytes32 (mDmaAccess->Control); + + // + // We ensured the following constraint via mScratchBufferSize in + // QemuFwCfgS3TransferOwnership(). + // + ASSERT (NumberOfBytes <=3D MAX_UINT32); + mDmaAccess->Length =3D SwapBytes32 ((UINT32)NumberOfBytes); + + mDmaAccess->Address =3D SwapBytes64 ((UINTN)mScratchBuffer); + + // + // Copy mDmaAccess into the boot script. When executed at S3 resume, this + // opcode will restore it in-place. + // + Status =3D mS3SaveState->Write ( + mS3SaveState, // This + EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE, // OpCode + EfiBootScriptWidthUint8, // Width + (UINT64)(UINTN)mDmaAccess, // Address + sizeof *mDmaAccess, // Count + (VOID *)mDmaAccess // Buffer + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: %a: EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE: %r\n", + gEfiCallerBaseName, __FUNCTION__, Status)); + return (RETURN_STATUS)Status; + } + + // + // Append an opcode that will write the address of the fw_cfg DMA comman= d to + // the fw_cfg DMA address register, which consists of two 32-bit IO port= s. + // The second (highest address, least significant) write will start the + // transfer. + // + AccessAddress =3D SwapBytes64 ((UINTN)mDmaAccess); + Status =3D mS3SaveState->Write ( + mS3SaveState, // This + EFI_BOOT_SCRIPT_IO_WRITE_OPCODE, // OpCode + EfiBootScriptWidthUint32, // Width + (UINT64)FW_CFG_IO_DMA_ADDRESS, // Address + (UINTN)2, // Count + (VOID *)&AccessAddress // Buffer + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: %a: EFI_BOOT_SCRIPT_IO_WRITE_OPCODE: %r\n", + gEfiCallerBaseName, __FUNCTION__, Status)); + return (RETURN_STATUS)Status; + } + + // + // The following opcode will wait until the Control word reads as zero + // (transfer complete). As timeout we use MAX_UINT64 * 100ns, which is + // approximately 58494 years. + // + ControlPollData =3D 0; + ControlPollMask =3D MAX_UINT32; + Status =3D mS3SaveState->Write ( + mS3SaveState, // This + EFI_BOOT_SCRIPT_MEM_POLL_OPCODE, // OpCode + EfiBootScriptWidthUint32, // Width + (UINT64)(UINTN)&mDmaAccess->Control, // Address + (VOID *)&ControlPollData, // Data + (VOID *)&ControlPollMask, // DataMask + MAX_UINT64 // Delay + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: %a: EFI_BOOT_SCRIPT_MEM_POLL_OPCODE: %r\n", + gEfiCallerBaseName, __FUNCTION__, Status)); + return (RETURN_STATUS)Status; + } + + return RETURN_SUCCESS; +} + + +/** + Produce ACPI S3 Boot Script opcodes that (optionally) select an fw_cfg i= tem, + and increase its offset. + + If the operation fails during S3 resume, the boot script will hang. + + This function may only be called from the client module's + FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION, which was passed to + QemuFwCfgS3TransferOwnership() as Append. + + @param[in] FirmwareConfigItem The UINT16 selector key of the firmware c= onfig + item to advance the offset of, expressed = as + INT32. If FirmwareConfigItem is -1, no + selection is made, and the offset for the + currently selected item is increased. + Otherwise, the specified item will be + selected, and the offset increment will o= ccur + from offset 0. + + @param[in] NumberOfBytes The number of bytes to skip in the subject + fw_cfg item. + + @retval RETURN_SUCCESS The opcodes were appended to the ACPI = S3 + Boot Script successfully. There is no = way + to undo this action. + + @retval RETURN_INVALID_PARAMETER FirmwareConfigItem is invalid. + + @retval RETURN_BAD_BUFFER_SIZE NumberOfBytes is too large. + + @return Error codes from underlying functions. +**/ +EFIAPI +RETURN_STATUS +QemuFwCfgS3SkipBytes ( + IN INT32 FirmwareConfigItem, + IN UINTN NumberOfBytes + ) +{ + EFI_STATUS Status; + UINT64 AccessAddress; + UINT32 ControlPollData; + UINT32 ControlPollMask; + + ASSERT (mDmaAccess !=3D NULL); + ASSERT (mS3SaveState !=3D NULL); + + if (FirmwareConfigItem < -1 || FirmwareConfigItem > MAX_UINT16) { + return RETURN_INVALID_PARAMETER; + } + if (NumberOfBytes > MAX_UINT32) { + return RETURN_BAD_BUFFER_SIZE; + } + + // + // Set up a skip[+select] fw_cfg DMA command. + // + mDmaAccess->Control =3D FW_CFG_DMA_CTL_SKIP; + if (FirmwareConfigItem !=3D -1) { + mDmaAccess->Control |=3D FW_CFG_DMA_CTL_SELECT; + mDmaAccess->Control |=3D (UINT32)FirmwareConfigItem << 16; + } + mDmaAccess->Control =3D SwapBytes32 (mDmaAccess->Control); + + mDmaAccess->Length =3D SwapBytes32 ((UINT32)NumberOfBytes); + mDmaAccess->Address =3D 0; + + // + // Copy mDmaAccess into the boot script. When executed at S3 resume, this + // opcode will restore it in-place. + // + Status =3D mS3SaveState->Write ( + mS3SaveState, // This + EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE, // OpCode + EfiBootScriptWidthUint8, // Width + (UINT64)(UINTN)mDmaAccess, // Address + sizeof *mDmaAccess, // Count + (VOID *)mDmaAccess // Buffer + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: %a: EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE: %r\n", + gEfiCallerBaseName, __FUNCTION__, Status)); + return (RETURN_STATUS)Status; + } + + // + // Append an opcode that will write the address of the fw_cfg DMA comman= d to + // the fw_cfg DMA address register, which consists of two 32-bit IO port= s. + // The second (highest address, least significant) write will start the + // transfer. + // + AccessAddress =3D SwapBytes64 ((UINTN)mDmaAccess); + Status =3D mS3SaveState->Write ( + mS3SaveState, // This + EFI_BOOT_SCRIPT_IO_WRITE_OPCODE, // OpCode + EfiBootScriptWidthUint32, // Width + (UINT64)FW_CFG_IO_DMA_ADDRESS, // Address + (UINTN)2, // Count + (VOID *)&AccessAddress // Buffer + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: %a: EFI_BOOT_SCRIPT_IO_WRITE_OPCODE: %r\n", + gEfiCallerBaseName, __FUNCTION__, Status)); + return (RETURN_STATUS)Status; + } + + // + // The following opcode will wait until the Control word reads as zero + // (transfer complete). As timeout we use MAX_UINT64 * 100ns, which is + // approximately 58494 years. + // + ControlPollData =3D 0; + ControlPollMask =3D MAX_UINT32; + Status =3D mS3SaveState->Write ( + mS3SaveState, // This + EFI_BOOT_SCRIPT_MEM_POLL_OPCODE, // OpCode + EfiBootScriptWidthUint32, // Width + (UINT64)(UINTN)&mDmaAccess->Control, // Address + (VOID *)&ControlPollData, // Data + (VOID *)&ControlPollMask, // DataMask + MAX_UINT64 // Delay + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: %a: EFI_BOOT_SCRIPT_MEM_POLL_OPCODE: %r\n", + gEfiCallerBaseName, __FUNCTION__, Status)); + return (RETURN_STATUS)Status; + } + + return RETURN_SUCCESS; +} + + +/** + Produce ACPI S3 Boot Script opcodes that check a value in ScratchBuffer. + + If the check fails during S3 resume, the boot script will hang. + + This function may only be called from the client module's + FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION, which was passed to + QemuFwCfgS3TransferOwnership() as Append. + + @param[in] ScratchData Pointer to the UINT8, UINT16, UINT32 or UINT64 f= ield + in ScratchBuffer that should be checked. The cal= ler + is responsible for populating the field during S3 + resume, by calling QemuFwCfgS3ReadBytes() ahead = of + QemuFwCfgS3CheckValue(). + + ScratchData must point into ScratchBuffer, which= was + allocated, and passed to Append(), by + QemuFwCfgS3TransferOwnership(). + + ScratchData must be aligned at ValueSize bytes. + + @param[in] ValueSize One of 1, 2, 4 or 8, specifying the size of the = field + to check. + + @param[in] ValueMask The value read from ScratchData is binarily AND-= ed + with ValueMask, and the result is compared again= st + Value. If the masked data equals Value, the check + passes, and the boot script can proceed. Otherwi= se, + the check fails, and the boot script hangs. + + @param[in] Value Refer to ValueMask. + + @retval RETURN_SUCCESS The opcodes were appended to the ACPI = S3 + Boot Script successfully. There is no = way + to undo this action. + + @retval RETURN_INVALID_PARAMETER ValueSize is invalid. + + @retval RETURN_INVALID_PARAMETER ValueMask or Value cannot be represent= ed in + ValueSize bytes. + + @retval RETURN_INVALID_PARAMETER ScratchData is not aligned at ValueSize + bytes. + + @retval RETURN_BAD_BUFFER_SIZE The ValueSize bytes at ScratchData are= n't + wholly contained in the ScratchBufferS= ize + bytes at ScratchBuffer. + + @return Error codes from underlying functions. +**/ +EFIAPI +RETURN_STATUS +QemuFwCfgS3CheckValue ( + IN VOID *ScratchData, + IN UINT8 ValueSize, + IN UINT64 ValueMask, + IN UINT64 Value + ) +{ + EFI_BOOT_SCRIPT_WIDTH Width; + EFI_STATUS Status; + + ASSERT (mS3SaveState !=3D NULL); + + switch (ValueSize) { + case 1: + Width =3D EfiBootScriptWidthUint8; + break; + + case 2: + Width =3D EfiBootScriptWidthUint16; + break; + + case 4: + Width =3D EfiBootScriptWidthUint32; + break; + + case 8: + Width =3D EfiBootScriptWidthUint64; + break; + + default: + return RETURN_INVALID_PARAMETER; + } + + if (ValueSize < 8 && + (RShiftU64 (ValueMask, ValueSize * 8) > 0 || + RShiftU64 (Value, ValueSize * 8) > 0)) { + return RETURN_INVALID_PARAMETER; + } + + if ((UINTN)ScratchData % ValueSize > 0) { + return RETURN_INVALID_PARAMETER; + } + + if (((UINTN)ScratchData < (UINTN)mScratchBuffer) || + ((UINTN)ScratchData > MAX_UINTN - ValueSize) || + ((UINTN)ScratchData + ValueSize > + (UINTN)mScratchBuffer + mScratchBufferSize)) { + return RETURN_BAD_BUFFER_SIZE; + } + + // + // The following opcode will wait "until" (*ScratchData & ValueMask) rea= ds as + // Value, considering the least significant ValueSize bytes. As timeout = we + // use MAX_UINT64 * 100ns, which is approximately 58494 years. + // + Status =3D mS3SaveState->Write ( + mS3SaveState, // This + EFI_BOOT_SCRIPT_MEM_POLL_OPCODE, // OpCode + Width, // Width + (UINT64)(UINTN)ScratchData, // Address + (VOID *)&Value, // Data + (VOID *)&ValueMask, // DataMask + MAX_UINT64 // Delay + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "%a: %a: EFI_BOOT_SCRIPT_MEM_POLL_OPCODE: %r\n", + gEfiCallerBaseName, __FUNCTION__, Status)); + return (RETURN_STATUS)Status; + } + + return RETURN_SUCCESS; +} --=20 2.9.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 03:57:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1487814530097164.69650344315085; Wed, 22 Feb 2017 17:48:50 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 596DD8227B; Wed, 22 Feb 2017 17:48:38 -0800 (PST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 575028226D for ; Wed, 22 Feb 2017 17:48:36 -0800 (PST) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id E76D04E4D9; Thu, 23 Feb 2017 01:48:36 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-134.phx2.redhat.com [10.3.116.134]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1N1mJFP012836; Wed, 22 Feb 2017 20:48:36 -0500 X-Original-To: edk2-devel@ml01.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Thu, 23 Feb 2017 02:48:13 +0100 Message-Id: <20170223014814.10937-12-lersek@redhat.com> In-Reply-To: <20170223014814.10937-1-lersek@redhat.com> References: <20170223014814.10937-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Thu, 23 Feb 2017 01:48:36 +0000 (UTC) Subject: [edk2] [PATCH 11/12] OvmfPkg/SmmControl2Dxe: save fw_cfg boot script with QemuFwCfgS3Lib X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jordan Justen MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" We cannot entirely eliminate the manual boot script building in this driver, as it also programs lower-level chipset registers (SMI_EN, GEN_PMCON_1) at S3 resume, not just registers exposed via fw_cfg. We can nonetheless replace the manually built opcodes for the latter class of registers with QemuFwCfgS3Lib function calls. We preserve the ordering between the two sets of registers (low-level chipset first, fw_cfg second). This patch demonstrates that manual handling of S3SaveState protocol installation can be combined with QemuFwCfgS3Lib, even without upsetting the original order between boot script fragments. An S3SaveState notify function running at TPL_CALLBACK can safely queue another S3SaveState notify function at TPL_CALLBACK with QemuFwCfgS3TransferOwnership(). Cc: Jordan Justen Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D394 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- OvmfPkg/SmmControl2Dxe/SmiFeatures.h | 5 +- OvmfPkg/SmmControl2Dxe/SmiFeatures.c | 224 +++++++------------- OvmfPkg/SmmControl2Dxe/SmmControl2Dxe.c | 5 +- 3 files changed, 77 insertions(+), 157 deletions(-) diff --git a/OvmfPkg/SmmControl2Dxe/SmiFeatures.h b/OvmfPkg/SmmControl2Dxe/= SmiFeatures.h index 9d5f1dbcb57e..3f3a5d3ea9b1 100644 --- a/OvmfPkg/SmmControl2Dxe/SmiFeatures.h +++ b/OvmfPkg/SmmControl2Dxe/SmiFeatures.h @@ -37,13 +37,10 @@ NegotiateSmiFeatures ( /** Append a boot script fragment that will re-select the previously negotia= ted SMI features during S3 resume. - - @param[in] S3SaveState The EFI_S3_SAVE_STATE_PROTOCOL instance to appen= d to - the S3 boot script with. **/ VOID SaveSmiFeatures ( - IN EFI_S3_SAVE_STATE_PROTOCOL *S3SaveState + VOID ); =20 #endif diff --git a/OvmfPkg/SmmControl2Dxe/SmiFeatures.c b/OvmfPkg/SmmControl2Dxe/= SmiFeatures.c index bd257f15d955..ecdab2fd9a86 100644 --- a/OvmfPkg/SmmControl2Dxe/SmiFeatures.c +++ b/OvmfPkg/SmmControl2Dxe/SmiFeatures.c @@ -18,6 +18,7 @@ #include #include #include +#include =20 #include "SmiFeatures.h" =20 @@ -29,29 +30,26 @@ =20 // // Provides a scratch buffer (allocated in EfiReservedMemoryType type memo= ry) -// for the S3 boot script fragment to write to and read from. The buffer -// captures a combined fw_cfg item selection + write command using the DMA -// access method. Note that we don't trust the runtime OS to preserve the -// contents of the buffer, the boot script will first rewrite it. +// for the S3 boot script fragment to write to and read from. // #pragma pack (1) -typedef struct { - FW_CFG_DMA_ACCESS Access; - UINT64 Features; +typedef union { + UINT64 Features; + UINT8 FeaturesOk; } SCRATCH_BUFFER; #pragma pack () =20 // // These carry the selector keys of the "etc/smi/requested-features" and // "etc/smi/features-ok" fw_cfg files from NegotiateSmiFeatures() to -// SaveSmiFeatures(). +// AppendFwCfgBootScript(). // STATIC FIRMWARE_CONFIG_ITEM mRequestedFeaturesItem; STATIC FIRMWARE_CONFIG_ITEM mFeaturesOkItem; =20 // // Carries the negotiated SMI features from NegotiateSmiFeatures() to -// SaveSmiFeatures(). +// AppendFwCfgBootScript(). // STATIC UINT64 mSmiFeatures; =20 @@ -168,157 +166,81 @@ FatalError: } =20 /** + FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION provided to QemuFwCfgS3Lib. +**/ +STATIC +VOID +EFIAPI +AppendFwCfgBootScript ( + IN OUT VOID *Context, OPTIONAL + IN OUT VOID *ExternalScratchBuffer + ) +{ + SCRATCH_BUFFER *ScratchBuffer; + RETURN_STATUS Status; + + ScratchBuffer =3D ExternalScratchBuffer; + + // + // Write the negotiated feature bitmap into "etc/smi/requested-features". + // + ScratchBuffer->Features =3D mSmiFeatures; + Status =3D QemuFwCfgS3WriteBytes (mRequestedFeaturesItem, + sizeof ScratchBuffer->Features); + if (RETURN_ERROR (Status)) { + goto FatalError; + } + + // + // Read back "etc/smi/features-ok". This invokes the feature validation & + // lockdown. (The validation succeeded at first boot.) + // + Status =3D QemuFwCfgS3ReadBytes (mFeaturesOkItem, + sizeof ScratchBuffer->FeaturesOk); + if (RETURN_ERROR (Status)) { + goto FatalError; + } + + // + // If "etc/smi/features-ok" read as 1, we're good. Otherwise, hang the S3 + // resume process. + // + Status =3D QemuFwCfgS3CheckValue (&ScratchBuffer->FeaturesOk, + sizeof ScratchBuffer->FeaturesOk, MAX_UINT8, 1); + if (RETURN_ERROR (Status)) { + goto FatalError; + } + + DEBUG ((DEBUG_VERBOSE, "%a: SMI feature negotiation boot script saved\n", + __FUNCTION__)); + return; + +FatalError: + ASSERT (FALSE); + CpuDeadLoop (); +} + + +/** Append a boot script fragment that will re-select the previously negotia= ted SMI features during S3 resume. - - @param[in] S3SaveState The EFI_S3_SAVE_STATE_PROTOCOL instance to appen= d to - the S3 boot script with. **/ VOID SaveSmiFeatures ( - IN EFI_S3_SAVE_STATE_PROTOCOL *S3SaveState + VOID ) { - SCRATCH_BUFFER *ScratchBuffer; - EFI_STATUS Status; - UINT64 AccessAddress; - UINT32 ControlPollData; - UINT32 ControlPollMask; - UINT16 FeaturesOkItemAsUint16; - UINT8 FeaturesOkData; - UINT8 FeaturesOkMask; + RETURN_STATUS Status; =20 - ScratchBuffer =3D AllocateReservedPool (sizeof *ScratchBuffer); - if (ScratchBuffer =3D=3D NULL) { - DEBUG ((DEBUG_ERROR, "%a: scratch buffer allocation failed\n", - __FUNCTION__)); - goto FatalError; - } - - // - // Populate the scratch buffer with a select + write fw_cfg DMA command = that - // will write the negotiated feature bitmap into - // "etc/smi/requested-features". - // - ScratchBuffer->Access.Control =3D SwapBytes32 ( - (UINT32)mRequestedFeaturesItem << 16 | - FW_CFG_DMA_CTL_SELECT | - FW_CFG_DMA_CTL_WRITE - ); - ScratchBuffer->Access.Length =3D SwapBytes32 ( - (UINT32)sizeof ScratchBuffer->Features); - ScratchBuffer->Access.Address =3D SwapBytes64 ( - (UINTN)&ScratchBuffer->Features); - ScratchBuffer->Features =3D mSmiFeatures; - - // - // Copy the scratch buffer into the boot script. When replayed, this - // EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE will restore the current contents of= the - // scratch buffer, in-place. // - Status =3D S3SaveState->Write ( - S3SaveState, // This - EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE, // OpCode - EfiBootScriptWidthUint8, // Width - (UINT64)(UINTN)ScratchBuffer, // Address - sizeof *ScratchBuffer, // Count - (VOID*)ScratchBuffer // Buffer - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a:%d: EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE: %r\n", - __FUNCTION__, __LINE__, Status)); - goto FatalError; - } - - // - // Append an opcode that will write the address of the scratch buffer to= the - // fw_cfg DMA address register, which consists of two 32-bit IO ports. T= he - // second (highest address, least significant) write will start the tran= sfer. + // We are already running at TPL_CALLBACK, on the stack of + // OnS3SaveStateInstalled(). But that's okay, we can easily queue more + // notification functions while executing a notification function. // - AccessAddress =3D SwapBytes64 ((UINTN)&ScratchBuffer->Access); - Status =3D S3SaveState->Write ( - S3SaveState, // This - EFI_BOOT_SCRIPT_IO_WRITE_OPCODE, // OpCode - EfiBootScriptWidthUint32, // Width - (UINT64)FW_CFG_IO_DMA_ADDRESS, // Address - (UINTN)2, // Count - &AccessAddress // Buffer - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a:%d: EFI_BOOT_SCRIPT_IO_WRITE_OPCODE: %r\n", - __FUNCTION__, __LINE__, Status)); - goto FatalError; + Status =3D QemuFwCfgS3TransferOwnership (AppendFwCfgBootScript, NULL, + sizeof (SCRATCH_BUFFER)); + if (RETURN_ERROR (Status)) { + ASSERT (FALSE); + CpuDeadLoop (); } - - // - // The EFI_BOOT_SCRIPT_MEM_POLL_OPCODE will wait until the Control word = reads - // as zero (transfer complete). As timeout we use MAX_UINT64 * 100ns, wh= ich - // is approximately 58494 years. - // - ControlPollData =3D 0; - ControlPollMask =3D MAX_UINT32; - Status =3D S3SaveState->Write ( - S3SaveState, // This - EFI_BOOT_SCRIPT_MEM_POLL_OPCODE, // OpC= ode - EfiBootScriptWidthUint32, // Wid= th - (UINT64)(UINTN)&ScratchBuffer->Access.Control, // Add= ress - &ControlPollData, // Data - &ControlPollMask, // Dat= aMask - MAX_UINT64 // Del= ay - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a:%d: EFI_BOOT_SCRIPT_MEM_POLL_OPCODE: %r\n", - __FUNCTION__, __LINE__, Status)); - goto FatalError; - } - - // - // Select the "etc/smi/features-ok" fw_cfg file, which invokes the featu= re - // validation & lockdown. (The validation succeeded at first boot.) - // - FeaturesOkItemAsUint16 =3D (UINT16)mFeaturesOkItem; - Status =3D S3SaveState->Write ( - S3SaveState, // This - EFI_BOOT_SCRIPT_IO_WRITE_OPCODE, // OpCode - EfiBootScriptWidthUint16, // Width - (UINT64)FW_CFG_IO_SELECTOR, // Address - (UINTN)1, // Count - &FeaturesOkItemAsUint16 // Buffer - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a:%d: EFI_BOOT_SCRIPT_IO_WRITE_OPCODE: %r\n", - __FUNCTION__, __LINE__, Status)); - goto FatalError; - } - - // - // Read the contents (one byte) of "etc/smi/features-ok". If the value is - // one, we're good. Otherwise, continue reading the data port: QEMU retu= rns 0 - // past the end of the fw_cfg item, so this will hang the resume process, - // which matches our intent. - // - FeaturesOkData =3D 1; - FeaturesOkMask =3D MAX_UINT8; - Status =3D S3SaveState->Write ( - S3SaveState, // This - EFI_BOOT_SCRIPT_IO_POLL_OPCODE, // OpCode - EfiBootScriptWidthUint8, // Width - (UINT64)(UINTN)FW_CFG_IO_DATA, // Address - &FeaturesOkData, // Data - &FeaturesOkMask, // DataMask - MAX_UINT64 // Delay - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a:%d: EFI_BOOT_SCRIPT_IO_POLL_OPCODE: %r\n", - __FUNCTION__, __LINE__, Status)); - goto FatalError; - } - - DEBUG ((DEBUG_VERBOSE, "%a: ScratchBuffer@%p\n", __FUNCTION__, - (VOID *)ScratchBuffer)); - return; - -FatalError: - ASSERT (FALSE); - CpuDeadLoop (); } diff --git a/OvmfPkg/SmmControl2Dxe/SmmControl2Dxe.c b/OvmfPkg/SmmControl2D= xe/SmmControl2Dxe.c index bb79fce0855b..e1cd3d02ac36 100644 --- a/OvmfPkg/SmmControl2Dxe/SmmControl2Dxe.c +++ b/OvmfPkg/SmmControl2Dxe/SmmControl2Dxe.c @@ -378,14 +378,15 @@ OnS3SaveStateInstalled ( CpuDeadLoop (); } =20 + DEBUG ((DEBUG_VERBOSE, "%a: chipset boot script saved\n", __FUNCTION__)); + // // Append a boot script fragment that re-selects the negotiated SMI feat= ures. // if (mSmiFeatureNegotiation) { - SaveSmiFeatures (S3SaveState); + SaveSmiFeatures (); } =20 - DEBUG ((EFI_D_VERBOSE, "%a: boot script fragment saved\n", __FUNCTION__)= ); gBS->CloseEvent (Event); mS3SaveStateInstalled =3D NULL; } --=20 2.9.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel From nobody Thu May 2 03:57:32 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Authentication-Results: mx.zoho.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org; Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1487814531695293.40447655519927; Wed, 22 Feb 2017 17:48:51 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 917158227F; Wed, 22 Feb 2017 17:48:38 -0800 (PST) Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 8D81482260 for ; Wed, 22 Feb 2017 17:48:37 -0800 (PST) Received: from int-mx11.intmail.prod.int.phx2.redhat.com (int-mx11.intmail.prod.int.phx2.redhat.com [10.5.11.24]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2BF1885363; Thu, 23 Feb 2017 01:48:38 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-134.phx2.redhat.com [10.3.116.134]) by int-mx11.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v1N1mJFQ012836; Wed, 22 Feb 2017 20:48:37 -0500 X-Original-To: edk2-devel@ml01.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Thu, 23 Feb 2017 02:48:14 +0100 Message-Id: <20170223014814.10937-13-lersek@redhat.com> In-Reply-To: <20170223014814.10937-1-lersek@redhat.com> References: <20170223014814.10937-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.24 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Thu, 23 Feb 2017 01:48:38 +0000 (UTC) Subject: [edk2] [PATCH 12/12] OvmfPkg/AcpiPlatformDxe: save fw_cfg boot script with QemuFwCfgS3Lib X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Jordan Justen MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Drop the explicit S3SaveState protocol and opcode management; instead, create ACPI S3 Boot Script opcodes for the WRITE_POINTER commands with QemuFwCfgS3Lib functions. In this case, we have a dynamically allocated Context structure, hence the patch demonstrates how the FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION takes ownership of Context. Cc: Jordan Justen Ref: https://bugzilla.tianocore.org/show_bug.cgi?id=3D394 Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Laszlo Ersek --- OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf | 1 - OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf | 1 - OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h | 2 +- OvmfPkg/AcpiPlatformDxe/BootScript.c | 262 +++++----------= ----- OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c | 7 + 5 files changed, 64 insertions(+), 209 deletions(-) diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf b/OvmfPkg/AcpiPlat= formDxe/AcpiPlatformDxe.inf index 42edc97b3da2..9a9b2e6bb2e5 100644 --- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf +++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatformDxe.inf @@ -61,7 +61,6 @@ [LibraryClasses] [Protocols] gEfiAcpiTableProtocolGuid # PROTOCOL ALWAYS_CONSUMED gEfiPciIoProtocolGuid # PROTOCOL SOMETIMES_CONSU= MED - gEfiS3SaveStateProtocolGuid # PROTOCOL SOMETIMES_CONSU= MED =20 [Guids] gEfiXenInfoGuid diff --git a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf b/OvmfPkg= /AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf index a9350540215d..adc50cfd9f76 100644 --- a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf +++ b/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpiPlatformDxe.inf @@ -51,7 +51,6 @@ [LibraryClasses] [Protocols] gEfiAcpiTableProtocolGuid # PROTOCOL ALWAYS_CONSUMED gEfiPciIoProtocolGuid # PROTOCOL SOMETIMES_CONSU= MED - gEfiS3SaveStateProtocolGuid # PROTOCOL SOMETIMES_CONSU= MED =20 [Guids] gRootBridgesConnectedEventGroupGuid diff --git a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h b/OvmfPkg/AcpiPlatformD= xe/AcpiPlatform.h index 0f035a0d5751..83b981ee005d 100644 --- a/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h +++ b/OvmfPkg/AcpiPlatformDxe/AcpiPlatform.h @@ -115,7 +115,7 @@ SaveCondensedWritePointerToS3Context ( =20 EFI_STATUS TransferS3ContextToBootScript ( - IN CONST S3_CONTEXT *S3Context + IN S3_CONTEXT *S3Context ); =20 #endif diff --git a/OvmfPkg/AcpiPlatformDxe/BootScript.c b/OvmfPkg/AcpiPlatformDxe= /BootScript.c index bff42ad8b9b0..424b4b3ee2bd 100644 --- a/OvmfPkg/AcpiPlatformDxe/BootScript.c +++ b/OvmfPkg/AcpiPlatformDxe/BootScript.c @@ -15,7 +15,7 @@ =20 #include #include -#include +#include =20 #include "AcpiPlatform.h" =20 @@ -53,19 +53,11 @@ struct S3_CONTEXT { =20 // // Scratch buffer, allocated in EfiReservedMemoryType type memory, for the= ACPI -// S3 Boot Script opcodes to work on. We use the buffer to compose and to -// replay several fw_cfg select+skip and write operations, using the DMA a= ccess -// method. The fw_cfg operations will implement the actions dictated by -// CONDENSED_WRITE_POINTER objects. +// S3 Boot Script opcodes to work on. // #pragma pack (1) -typedef struct { - FW_CFG_DMA_ACCESS Access; // filled in from - // CONDENSED_WRITE_POINTER.PointerItem, - // CONDENSED_WRITE_POINTER.PointerSize, - // CONDENSED_WRITE_POINTER.PointerOffs= et - UINT64 PointerValue; // filled in from - // CONDENSED_WRITE_POINTER.PointerValue +typedef union { + UINT64 PointerValue; // filled in from CONDENSED_WRITE_POINTER.PointerVa= lue } SCRATCH_BUFFER; #pragma pack () =20 @@ -197,220 +189,78 @@ SaveCondensedWritePointerToS3Context ( =20 =20 /** - Translate and append the information from an S3_CONTEXT object to the AC= PI S3 - Boot Script. - - The effects of a successful call to this function cannot be undone. - - @param[in] S3Context The S3_CONTEXT object to translate to ACPI S3 Boot - Script opcodes. - - @retval EFI_OUT_OF_RESOURCES Out of memory. - - @retval EFI_SUCCESS The translation of S3Context to ACPI S3 Bo= ot - Script opcodes has been successful. - - @return Error codes from underlying functions. + FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION provided to QemuFwCfgS3Lib. **/ -EFI_STATUS -TransferS3ContextToBootScript ( - IN CONST S3_CONTEXT *S3Context +STATIC +VOID +EFIAPI +AppendFwCfgBootScript ( + IN OUT VOID *Context, OPTIONAL + IN OUT VOID *ExternalScratchBuffer ) { - EFI_STATUS Status; - EFI_S3_SAVE_STATE_PROTOCOL *S3SaveState; - SCRATCH_BUFFER *ScratchBuffer; - FW_CFG_DMA_ACCESS *Access; - UINT64 BigEndianAddressOfAccess; - UINT32 ControlPollData; - UINT32 ControlPollMask; - UINTN Index; + S3_CONTEXT *S3Context; + SCRATCH_BUFFER *ScratchBuffer; + UINTN Index; =20 - // - // If the following protocol lookup fails, it shall not happen due to an - // unexpected DXE driver dispatch order. - // - // Namely, this function is only invoked on QEMU. Therefore it is only - // reached after Platform BDS signals gRootBridgesConnectedEventGroupGuid - // (see OnRootBridgesConnected() in "EntryPoint.c"). Hence, because - // TransferS3ContextToBootScript() is invoked in BDS, all DXE drivers, - // including S3SaveStateDxe (producing EFI_S3_SAVE_STATE_PROTOCOL), have= been - // dispatched by the time we get here. (S3SaveStateDxe is not expected to - // have any stricter-than-TRUE DEPEX -- not a DEPEX that gets unblocked = only - // within BDS anyway.) - // - // Reaching this function also depends on QemuFwCfgS3Enabled(). That imp= lies - // S3SaveStateDxe has not exited immediately due to S3 being disabled. T= hus - // EFI_S3_SAVE_STATE_PROTOCOL can only be missing for genuinely unforese= eable - // reasons. - // - Status =3D gBS->LocateProtocol (&gEfiS3SaveStateProtocolGuid, - NULL /* Registration */, (VOID **)&S3SaveState); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: LocateProtocol(): %r\n", __FUNCTION__, Statu= s)); - return Status; - } + S3Context =3D Context; + ScratchBuffer =3D ExternalScratchBuffer; =20 - ScratchBuffer =3D AllocateReservedPool (sizeof *ScratchBuffer); - if (ScratchBuffer =3D=3D NULL) { - return EFI_OUT_OF_RESOURCES; - } - - // - // Set up helper variables that we'll use identically for all - // CONDENSED_WRITE_POINTER elements. - // - Access =3D &ScratchBuffer->Access; - BigEndianAddressOfAccess =3D SwapBytes64 ((UINTN)Access); - ControlPollData =3D 0; - ControlPollMask =3D MAX_UINT32; - - // - // For each CONDENSED_WRITE_POINTER, we need six ACPI S3 Boot Script opc= odes: - // (1) restore an FW_CFG_DMA_ACCESS object in reserved memory that selec= ts - // the writeable fw_cfg file PointerFile (through PointerItem), and = skips - // to PointerOffset in it, - // (2) call QEMU with the FW_CFG_DMA_ACCESS object, - // (3) wait for the select+skip to finish, - // (4) restore a SCRATCH_BUFFER object in reserved memory that writes - // PointerValue (base address of the allocated / downloaded PointeeF= ile, - // plus PointeeOffset), of size PointerSize, into the fw_cfg file - // selected in (1), at the offset sought to in (1), - // (5) call QEMU with the FW_CFG_DMA_ACCESS object, - // (6) wait for the write to finish. - // - // EFI_S3_SAVE_STATE_PROTOCOL does not allow rolling back opcode additio= ns, - // therefore we treat any failure here as fatal. - // for (Index =3D 0; Index < S3Context->Used; ++Index) { CONST CONDENSED_WRITE_POINTER *Condensed; + RETURN_STATUS Status; =20 Condensed =3D &S3Context->WritePointers[Index]; =20 - // - // (1) restore an FW_CFG_DMA_ACCESS object in reserved memory that sel= ects - // the writeable fw_cfg file PointerFile (through PointerItem), and - // skips to PointerOffset in it, - // - Access->Control =3D SwapBytes32 ((UINT32)Condensed->PointerItem << 16 | - FW_CFG_DMA_CTL_SELECT | FW_CFG_DMA_CTL_SKIP); - Access->Length =3D SwapBytes32 (Condensed->PointerOffset); - Access->Address =3D 0; - Status =3D S3SaveState->Write ( - S3SaveState, // This - EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE, // OpCode - EfiBootScriptWidthUint8, // Width - (UINT64)(UINTN)Access, // Address - sizeof *Access, // Count - Access // Buffer - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: Index %Lu opcode 1: %r\n", __FUNCTION__, - (UINT64)Index, Status)); + Status =3D QemuFwCfgS3SkipBytes (Condensed->PointerItem, + Condensed->PointerOffset); + if (RETURN_ERROR (Status)) { goto FatalError; } =20 - // - // (2) call QEMU with the FW_CFG_DMA_ACCESS object, - // - Status =3D S3SaveState->Write ( - S3SaveState, // This - EFI_BOOT_SCRIPT_IO_WRITE_OPCODE, // OpCode - EfiBootScriptWidthUint32, // Width - (UINT64)FW_CFG_IO_DMA_ADDRESS, // Address - (UINTN)2, // Count - &BigEndianAddressOfAccess // Buffer - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: Index %Lu opcode 2: %r\n", __FUNCTION__, - (UINT64)Index, Status)); - goto FatalError; - } - - // - // (3) wait for the select+skip to finish, - // - Status =3D S3SaveState->Write ( - S3SaveState, // This - EFI_BOOT_SCRIPT_MEM_POLL_OPCODE, // OpCode - EfiBootScriptWidthUint32, // Width - (UINT64)(UINTN)&Access->Control, // Address - &ControlPollData, // Data - &ControlPollMask, // DataMask - MAX_UINT64 // Delay - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: Index %Lu opcode 3: %r\n", __FUNCTION__, - (UINT64)Index, Status)); - goto FatalError; - } - - // - // (4) restore a SCRATCH_BUFFER object in reserved memory that writes - // PointerValue (base address of the allocated / downloaded - // PointeeFile, plus PointeeOffset), of size PointerSize, into the - // fw_cfg file selected in (1), at the offset sought to in (1), - // - Access->Control =3D SwapBytes32 (FW_CFG_DMA_CTL_WRITE); - Access->Length =3D SwapBytes32 (Condensed->PointerSize); - Access->Address =3D SwapBytes64 ((UINTN)&ScratchBuffer->PointerValue); ScratchBuffer->PointerValue =3D Condensed->PointerValue; - Status =3D S3SaveState->Write ( - S3SaveState, // This - EFI_BOOT_SCRIPT_MEM_WRITE_OPCODE, // OpCode - EfiBootScriptWidthUint8, // Width - (UINT64)(UINTN)ScratchBuffer, // Address - sizeof *ScratchBuffer, // Count - ScratchBuffer // Buffer - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: Index %Lu opcode 4: %r\n", __FUNCTION__, - (UINT64)Index, Status)); - goto FatalError; - } - - // - // (5) call QEMU with the FW_CFG_DMA_ACCESS object, - // - Status =3D S3SaveState->Write ( - S3SaveState, // This - EFI_BOOT_SCRIPT_IO_WRITE_OPCODE, // OpCode - EfiBootScriptWidthUint32, // Width - (UINT64)FW_CFG_IO_DMA_ADDRESS, // Address - (UINTN)2, // Count - &BigEndianAddressOfAccess // Buffer - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: Index %Lu opcode 5: %r\n", __FUNCTION__, - (UINT64)Index, Status)); - goto FatalError; - } - - // - // (6) wait for the write to finish. - // - Status =3D S3SaveState->Write ( - S3SaveState, // This - EFI_BOOT_SCRIPT_MEM_POLL_OPCODE, // OpCode - EfiBootScriptWidthUint32, // Width - (UINT64)(UINTN)&Access->Control, // Address - &ControlPollData, // Data - &ControlPollMask, // DataMask - MAX_UINT64 // Delay - ); - if (EFI_ERROR (Status)) { - DEBUG ((DEBUG_ERROR, "%a: Index %Lu opcode 6: %r\n", __FUNCTION__, - (UINT64)Index, Status)); + Status =3D QemuFwCfgS3WriteBytes (-1, Condensed->PointerSize); + if (RETURN_ERROR (Status)) { goto FatalError; } } =20 - DEBUG ((DEBUG_VERBOSE, "%a: boot script fragment saved, ScratchBuffer=3D= %p\n", - __FUNCTION__, (VOID *)ScratchBuffer)); - return EFI_SUCCESS; + DEBUG ((DEBUG_VERBOSE, "%a: boot script fragment saved\n", __FUNCTION__)= ); + + ReleaseS3Context (S3Context); + return; =20 FatalError: ASSERT (FALSE); CpuDeadLoop (); - return Status; +} + + +/** + Translate and append the information from an S3_CONTEXT object to the AC= PI S3 + Boot Script. + + The effects of a successful call to this function cannot be undone. + + @param[in] S3Context The S3_CONTEXT object to translate to ACPI S3 Boot + Script opcodes. If the function returns successful= ly, + the caller must set the S3Context pointer -- origi= nally + returned by AllocateS3Context() -- immediately to = NULL, + because the ownership of S3Context has been transf= ered. + + @retval EFI_SUCCESS The translation of S3Context to ACPI S3 Boot Script + opcodes has been successfully executed or queued. + + @return Error codes from underlying functions. +**/ +EFI_STATUS +TransferS3ContextToBootScript ( + IN S3_CONTEXT *S3Context + ) +{ + RETURN_STATUS Status; + + Status =3D QemuFwCfgS3TransferOwnership (AppendFwCfgBootScript, S3Contex= t, + sizeof (SCRATCH_BUFFER)); + return (EFI_STATUS)Status; } diff --git a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c b/OvmfPkg/AcpiPlatform= Dxe/QemuFwCfgAcpi.c index 76512534f5e0..7bb2e3f21821 100644 --- a/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c +++ b/OvmfPkg/AcpiPlatformDxe/QemuFwCfgAcpi.c @@ -848,6 +848,13 @@ InstallQemuFwCfgTables ( // if (S3Context !=3D NULL) { Status =3D TransferS3ContextToBootScript (S3Context); + if (EFI_ERROR (Status)) { + goto UninstallAcpiTables; + } + // + // Ownership of S3Context has been transfered. + // + S3Context =3D NULL; } =20 UninstallAcpiTables: --=20 2.9.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel