From nobody Sat Nov 2 12:29:48 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 1489213623195329.96103738135; Fri, 10 Mar 2017 22:27:03 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 03104803BD; Fri, 10 Mar 2017 22:27:01 -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 731BE803A1 for ; Fri, 10 Mar 2017 22:27:00 -0800 (PST) Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 10C7080B22; Sat, 11 Mar 2017 06:27:01 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-21.phx2.redhat.com [10.3.116.21]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2B6QvsF001140; Sat, 11 Mar 2017 01:26:59 -0500 X-Original-To: edk2-devel@ml01.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Sat, 11 Mar 2017 07:26:40 +0100 Message-Id: <20170311062651.28351-2-lersek@redhat.com> In-Reply-To: <20170311062651.28351-1-lersek@redhat.com> References: <20170311062651.28351-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 11 Mar 2017 06:27:01 +0000 (UTC) Subject: [edk2] [PATCH v2 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 Reviewed-by: Jordan Justen --- Notes: v2: - no changes - pick up R-b from Jordan 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 Sat Nov 2 12:29:48 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 1489213627384715.2359465171589; Fri, 10 Mar 2017 22:27:07 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 38497803BC; Fri, 10 Mar 2017 22:27:06 -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 D4250803A1 for ; Fri, 10 Mar 2017 22:27:04 -0800 (PST) Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 615DCC0094C5; Sat, 11 Mar 2017 06:27:05 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-21.phx2.redhat.com [10.3.116.21]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2B6QvsG001140; Sat, 11 Mar 2017 01:27:04 -0500 X-Original-To: edk2-devel@ml01.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Sat, 11 Mar 2017 07:26:41 +0100 Message-Id: <20170311062651.28351-3-lersek@redhat.com> In-Reply-To: <20170311062651.28351-1-lersek@redhat.com> References: <20170311062651.28351-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 11 Mar 2017 06:27:05 +0000 (UTC) Subject: [edk2] [PATCH v2 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 Reviewed-by: Jordan Justen --- Notes: v2: - no changes - pick up R-b from Jordan 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 Sat Nov 2 12:29:48 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 1489213630592405.05108193182707; Fri, 10 Mar 2017 22:27:10 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 6FA7F803CD; Fri, 10 Mar 2017 22:27:09 -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 69123803CD for ; Fri, 10 Mar 2017 22:27:06 -0800 (PST) Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 0429C3D963; Sat, 11 Mar 2017 06:27:07 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-21.phx2.redhat.com [10.3.116.21]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2B6QvsH001140; Sat, 11 Mar 2017 01:27:05 -0500 X-Original-To: edk2-devel@ml01.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Sat, 11 Mar 2017 07:26:42 +0100 Message-Id: <20170311062651.28351-4-lersek@redhat.com> In-Reply-To: <20170311062651.28351-1-lersek@redhat.com> References: <20170311062651.28351-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Sat, 11 Mar 2017 06:27:07 +0000 (UTC) Subject: [edk2] [PATCH v2 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 Reviewed-by: Jordan Justen --- Notes: v2: - no changes - pick up R-b from Jordan 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 Sat Nov 2 12:29:48 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 1489213632213111.04532401410313; Fri, 10 Mar 2017 22:27:12 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id B0FEF803D1; Fri, 10 Mar 2017 22:27:10 -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 90720803A1 for ; Fri, 10 Mar 2017 22:27:08 -0800 (PST) Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 2C25981138; Sat, 11 Mar 2017 06:27:09 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-21.phx2.redhat.com [10.3.116.21]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2B6QvsI001140; Sat, 11 Mar 2017 01:27:07 -0500 X-Original-To: edk2-devel@ml01.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Sat, 11 Mar 2017 07:26:43 +0100 Message-Id: <20170311062651.28351-5-lersek@redhat.com> In-Reply-To: <20170311062651.28351-1-lersek@redhat.com> References: <20170311062651.28351-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.27]); Sat, 11 Mar 2017 06:27:09 +0000 (UTC) Subject: [edk2] [PATCH v2 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: Jordan Justen Reviewed-by: Ard Biesheuvel --- Notes: v2: - no changes - pick up R-b from Jordan and Ard ArmVirtPkg/ArmVirtQemu.dsc | 1 + ArmVirtPkg/ArmVirtQemuKernel.dsc | 1 + 2 files changed, 2 insertions(+) diff --git a/ArmVirtPkg/ArmVirtQemu.dsc b/ArmVirtPkg/ArmVirtQemu.dsc index 7b266b98b949..0bbbe4a7aa4a 100644 --- a/ArmVirtPkg/ArmVirtQemu.dsc +++ b/ArmVirtPkg/ArmVirtQemu.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/ArmVirtPlatformLib/ArmVirtPlatformLib.= inf ArmPlatformSysConfigLib|ArmPlatformPkg/Library/ArmPlatformSysConfigLibNu= ll/ArmPlatformSysConfigLibNull.inf diff --git a/ArmVirtPkg/ArmVirtQemuKernel.dsc b/ArmVirtPkg/ArmVirtQemuKerne= l.dsc index fd39c2802a85..71f16ed192de 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 Sat Nov 2 12:29:48 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 1489213634779579.0722677400387; Fri, 10 Mar 2017 22:27:14 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E317B803D4; Fri, 10 Mar 2017 22:27:11 -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 92497803CF for ; Fri, 10 Mar 2017 22:27:09 -0800 (PST) Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 2F41F81255; Sat, 11 Mar 2017 06:27:10 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-21.phx2.redhat.com [10.3.116.21]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2B6QvsJ001140; Sat, 11 Mar 2017 01:27:09 -0500 X-Original-To: edk2-devel@ml01.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Sat, 11 Mar 2017 07:26:44 +0100 Message-Id: <20170311062651.28351-6-lersek@redhat.com> In-Reply-To: <20170311062651.28351-1-lersek@redhat.com> References: <20170311062651.28351-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.25]); Sat, 11 Mar 2017 06:27:10 +0000 (UTC) Subject: [edk2] [PATCH v2 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 Reviewed-by: Jordan Justen --- Notes: v2: - no changes - pick up R-b from Jordan 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 0bce56bc8323..0796b0db816b 100644 --- a/OvmfPkg/OvmfPkgIa32.dsc +++ b/OvmfPkg/OvmfPkgIa32.dsc @@ -236,6 +236,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 @@ -269,6 +270,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 @@ -314,6 +316,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 56f7ff9ad004..71ac62f023b5 100644 --- a/OvmfPkg/OvmfPkgIa32X64.dsc +++ b/OvmfPkg/OvmfPkgIa32X64.dsc @@ -241,6 +241,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 @@ -274,6 +275,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 @@ -319,6 +321,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 d0b0b0e1beb1..2ceb31d7ffd5 100644 --- a/OvmfPkg/OvmfPkgX64.dsc +++ b/OvmfPkg/OvmfPkgX64.dsc @@ -241,6 +241,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 @@ -274,6 +275,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 @@ -319,6 +321,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 Sat Nov 2 12:29:48 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 148921363718658.47215269654669; Fri, 10 Mar 2017 22:27:17 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 223EA803D7; Fri, 10 Mar 2017 22:27:13 -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 AD647803A1 for ; Fri, 10 Mar 2017 22:27:11 -0800 (PST) Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 44E47C0624A1; Sat, 11 Mar 2017 06:27:12 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-21.phx2.redhat.com [10.3.116.21]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2B6QvsK001140; Sat, 11 Mar 2017 01:27:10 -0500 X-Original-To: edk2-devel@ml01.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Sat, 11 Mar 2017 07:26:45 +0100 Message-Id: <20170311062651.28351-7-lersek@redhat.com> In-Reply-To: <20170311062651.28351-1-lersek@redhat.com> References: <20170311062651.28351-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.32]); Sat, 11 Mar 2017 06:27:12 +0000 (UTC) Subject: [edk2] [PATCH v2 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: Jordan Justen Reviewed-by: Ard Biesheuvel --- Notes: v2: - no changes - pick up R-b from Jordan and Ard 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 Sat Nov 2 12:29:48 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 1489213639500907.811374417671; Fri, 10 Mar 2017 22:27:19 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 55A70803CF; Fri, 10 Mar 2017 22:27:15 -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 AAEE6803DA for ; Fri, 10 Mar 2017 22:27:13 -0800 (PST) Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 47D8D80B22; Sat, 11 Mar 2017 06:27:14 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-21.phx2.redhat.com [10.3.116.21]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2B6QvsL001140; Sat, 11 Mar 2017 01:27:12 -0500 X-Original-To: edk2-devel@ml01.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Sat, 11 Mar 2017 07:26:46 +0100 Message-Id: <20170311062651.28351-8-lersek@redhat.com> In-Reply-To: <20170311062651.28351-1-lersek@redhat.com> References: <20170311062651.28351-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.28]); Sat, 11 Mar 2017 06:27:14 +0000 (UTC) Subject: [edk2] [PATCH v2 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: - QemuFwCfgS3CallWhenBootScriptReady(): 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. - QemuFwCfgS3ScriptWriteBytes(), QemuFwCfgS3ScriptReadBytes(), QemuFwCfgS3ScriptSkipBytes(), QemuFwCfgS3ScriptCheckValue(): helper functions, available only to the above callback function, for composing the boot script fragment. QemuFwCfgS3ScriptSkipBytes() 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 --- Notes: v2: - rename QemuFwCfgS3TransferOwnership to QemuFwCfgS3CallWhenBootScriptReady [Jordan] - rename FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION to FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION [Jordan] - rename "Append" to "Callback" [Laszlo] - rename QemuFwCfgS3WriteBytes, QemuFwCfgS3ReadBytes, QemuFwCfgS3SkipBytes, and QemuFwCfgS3CheckValue to QemuFwCfgS3ScriptWriteBytes, QemuFwCfgS3ScriptReadBytes, QemuFwCfgS3ScriptSkipBytes, and QemuFwCfgS3ScriptCheckValue, respectively [Jordan] OvmfPkg/Include/Library/QemuFwCfgS3Lib.h | 322 ++++++++++++++++++++ 1 file changed, 322 insertions(+) diff --git a/OvmfPkg/Include/Library/QemuFwCfgS3Lib.h b/OvmfPkg/Include/Lib= rary/QemuFwCfgS3Lib.h index 1c473610d11c..76c8554cb706 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,324 @@ QemuFwCfgS3Enabled ( VOID ); =20 + +/** + Prototype for the callback function that the client module provides. + + In the callback function, the client module calls the + QemuFwCfgS3ScriptWriteBytes(), QemuFwCfgS3ScriptReadBytes(), + QemuFwCfgS3ScriptSkipBytes(), and QemuFwCfgS3ScriptCheckValue() function= s. + Those functions produce ACPI S3 Boot Script opcodes that will perform fw= _cfg + DMA operations, and will check any 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 + QemuFwCfgS3CallWhenBootScriptReady() (see below), or after + QemuFwCfgS3CallWhenBootScriptReady() 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 + QemuFwCfgS3CallWhenBootScriptReady()) to t= he + callback 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 + QemuFwCfgS3CallWhenBootScriptReady() + internally. + + ScratchBuffer is typed and sized by the cl= ient + module when it calls + QemuFwCfgS3CallWhenBootScriptReady(). 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 read 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 + QemuFwCfgS3ScriptReadBytes() and + QemuFwCfgS3ScriptWriteBytes(). It passes f= ield + addresses and sizes in structures in the u= nion + as ScratchData and ValueSize to + QemuFwCfgS3ScriptCheckValue(). + + ScratchBuffer is aligned at 8 bytes. +**/ +typedef +VOID (EFIAPI FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION) ( + IN OUT VOID *Context, OPTIONAL + IN OUT VOID *ScratchBuffer + ); + + +/** + Install the client module's FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION callbac= k 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] Callback FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION to in= voke + when the production of ACPI S3 Boot Script + opcodes becomes possible. Callback() may be + called immediately from + QemuFwCfgS3CallWhenBootScriptReady(). + + @param[in,out] Context Client-provided data structure for the + Callback() callback function to consume. + + If Context points to dynamically allocated + memory, then Callback() must release it. + + If Context points to dynamically allocated + memory, and + QemuFwCfgS3CallWhenBootScriptReady() retur= ns + successfully, then the caller of + QemuFwCfgS3CallWhenBootScriptReady() must + neither dereference nor even evaluate Cont= ext + any longer, as ownership of the referenced= area + has been transferred to Callback(). + + @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 Callback(). + + @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 Callback() 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 + QemuFwCfgS3CallWhenBootScriptReady() ca= nnot + be rolled back. + + @return Error codes from underlying functions. +**/ +EFIAPI +RETURN_STATUS +QemuFwCfgS3CallWhenBootScriptReady ( + IN FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION *Callback, + 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 QemuFwCfgS3ScriptWriteBytes() 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_CALLBACK_FUNCTION, which was passed to + QemuFwCfgS3CallWhenBootScriptReady() as Callback. + + @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 + QemuFwCfgS3CallWhenBootScriptReady(). + + @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 +QemuFwCfgS3ScriptWriteBytes ( + 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 QemuFwCfgS3ScriptReadBytes() will read NumberOfB= ytes + bytes from fw_cfg using DMA, storing the result in ScratchBuffer, in res= erved + 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_CALLBACK_FUNCTION, which was passed to + QemuFwCfgS3CallWhenBootScriptReady() as Callback. + + @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 + QemuFwCfgS3CallWhenBootScriptReady(). + + @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 +QemuFwCfgS3ScriptReadBytes ( + 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_CALLBACK_FUNCTION, which was passed to + QemuFwCfgS3CallWhenBootScriptReady() as Callback. + + @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 +QemuFwCfgS3ScriptSkipBytes ( + 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_CALLBACK_FUNCTION, which was passed to + QemuFwCfgS3CallWhenBootScriptReady() as Callback. + + @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 QemuFwCfgS3ScriptReadBytes() = ahead + of QemuFwCfgS3ScriptCheckValue(). + + ScratchData must point into ScratchBuffer, which= was + allocated, and passed to Callback(), by + QemuFwCfgS3CallWhenBootScriptReady(). + + 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 +QemuFwCfgS3ScriptCheckValue ( + 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 Sat Nov 2 12:29:48 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 1489213642099244.57040850788098; Fri, 10 Mar 2017 22:27:22 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 8664F803DD; Fri, 10 Mar 2017 22:27:16 -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 64272803DB for ; Fri, 10 Mar 2017 22:27:15 -0800 (PST) Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 F314D61B8A; Sat, 11 Mar 2017 06:27:15 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-21.phx2.redhat.com [10.3.116.21]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2B6QvsM001140; Sat, 11 Mar 2017 01:27:14 -0500 X-Original-To: edk2-devel@ml01.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Sat, 11 Mar 2017 07:26:47 +0100 Message-Id: <20170311062651.28351-9-lersek@redhat.com> In-Reply-To: <20170311062651.28351-1-lersek@redhat.com> References: <20170311062651.28351-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sat, 11 Mar 2017 06:27:16 +0000 (UTC) Subject: [edk2] [PATCH v2 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 QemuFwCfgS3CallWhenBootScriptReady() 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 QemuFwCfgS3ScriptWriteBytes(), QemuFwCfgS3ScriptReadBytes(), QemuFwCfgS3ScriptSkipBytes(), and QemuFwCfgS3ScriptCheckValue() 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 --- Notes: v2: - rename QemuFwCfgS3TransferOwnership to QemuFwCfgS3CallWhenBootScriptReady [Jordan] - rename FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION to FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION [Jordan] - rename "Append" to "Callback" [Laszlo] - rename QemuFwCfgS3WriteBytes, QemuFwCfgS3ReadBytes, QemuFwCfgS3SkipBytes, and QemuFwCfgS3CheckValue to QemuFwCfgS3ScriptWriteBytes, QemuFwCfgS3ScriptReadBytes, QemuFwCfgS3ScriptSkipBytes, and QemuFwCfgS3ScriptCheckValue, respectively [Jordan] OvmfPkg/Library/QemuFwCfgS3Lib/BaseQemuFwCfgS3LibNull.inf | 4 + OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3Base.c | 71 ++++++ OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3BasePei.c | 227 ++++++++++= ++++++++++ 3 files changed, 302 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..7b71305d1267 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,73 @@ QemuFwCfgS3Enabled ( { return FALSE; } + + +/** + Install the client module's FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION callbac= k 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] Callback FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION to in= voke + when the production of ACPI S3 Boot Script + opcodes becomes possible. Callback() may be + called immediately from + QemuFwCfgS3CallWhenBootScriptReady(). + + @param[in,out] Context Client-provided data structure for the + Callback() callback function to consume. + + If Context points to dynamically allocated + memory, then Callback() must release it. + + If Context points to dynamically allocated + memory, and + QemuFwCfgS3CallWhenBootScriptReady() retur= ns + successfully, then the caller of + QemuFwCfgS3CallWhenBootScriptReady() must + neither dereference nor even evaluate Cont= ext + any longer, as ownership of the referenced= area + has been transferred to Callback(). + + @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 Callback(). + + @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 Callback() 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 + QemuFwCfgS3CallWhenBootScriptReady() ca= nnot + be rolled back. + + @return Error codes from underlying functions. +**/ +EFIAPI +RETURN_STATUS +QemuFwCfgS3CallWhenBootScriptReady ( + IN FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION *Callback, + 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..674929e9d500 --- /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 QemuFwCfgS3ScriptWriteBytes() 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_CALLBACK_FUNCTION, which was passed to + QemuFwCfgS3CallWhenBootScriptReady() as Callback. + + @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 + QemuFwCfgS3CallWhenBootScriptReady(). + + @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 +QemuFwCfgS3ScriptWriteBytes ( + 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 QemuFwCfgS3ScriptReadBytes() will read NumberOfB= ytes + bytes from fw_cfg using DMA, storing the result in ScratchBuffer, in res= erved + 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_CALLBACK_FUNCTION, which was passed to + QemuFwCfgS3CallWhenBootScriptReady() as Callback. + + @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 + QemuFwCfgS3CallWhenBootScriptReady(). + + @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 +QemuFwCfgS3ScriptReadBytes ( + 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_CALLBACK_FUNCTION, which was passed to + QemuFwCfgS3CallWhenBootScriptReady() as Callback. + + @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 +QemuFwCfgS3ScriptSkipBytes ( + 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_CALLBACK_FUNCTION, which was passed to + QemuFwCfgS3CallWhenBootScriptReady() as Callback. + + @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 QemuFwCfgS3ScriptReadBytes() = ahead + of QemuFwCfgS3ScriptCheckValue(). + + ScratchData must point into ScratchBuffer, which= was + allocated, and passed to Callback(), by + QemuFwCfgS3CallWhenBootScriptReady(). + + 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 +QemuFwCfgS3ScriptCheckValue ( + 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 Sat Nov 2 12:29:48 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 1489213644395105.55052757241117; Fri, 10 Mar 2017 22:27:24 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id B437F803DB; Fri, 10 Mar 2017 22:27:18 -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 41BE6803A1 for ; Fri, 10 Mar 2017 22:27:17 -0800 (PST) Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 D32B04E4C6; Sat, 11 Mar 2017 06:27:17 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-21.phx2.redhat.com [10.3.116.21]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2B6QvsN001140; Sat, 11 Mar 2017 01:27:16 -0500 X-Original-To: edk2-devel@ml01.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Sat, 11 Mar 2017 07:26:48 +0100 Message-Id: <20170311062651.28351-10-lersek@redhat.com> In-Reply-To: <20170311062651.28351-1-lersek@redhat.com> References: <20170311062651.28351-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Sat, 11 Mar 2017 06:27:17 +0000 (UTC) Subject: [edk2] [PATCH v2 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 QemuFwCfgS3CallWhenBootScriptReady(). 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 QemuFwCfgS3ScriptWriteBytes(), QemuFwCfgS3ScriptReadBytes(), QemuFwCfgS3ScriptSkipBytes(), and QemuFwCfgS3ScriptCheckValue() functions must never be called. (They could only be called from the client module's callback, but QemuFwCfgS3CallWhenBootScriptReady() 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 --- Notes: v2: - rename QemuFwCfgS3TransferOwnership to QemuFwCfgS3CallWhenBootScriptReady [Jordan] - rename FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION to FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION [Jordan] - rename "Append" to "Callback" [Laszlo] - rename QemuFwCfgS3WriteBytes, QemuFwCfgS3ReadBytes, QemuFwCfgS3SkipBytes, and QemuFwCfgS3CheckValue to QemuFwCfgS3ScriptWriteBytes, QemuFwCfgS3ScriptReadBytes, QemuFwCfgS3ScriptSkipBytes, and QemuFwCfgS3ScriptCheckValue, respectively [Jordan] OvmfPkg/Library/QemuFwCfgS3Lib/PeiQemuFwCfgS3LibFwCfg.inf | 3 + OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3Pei.c | 86 +++++++++++= +++++++++ 2 files changed, 89 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..d447e36fc01c --- /dev/null +++ b/OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3Pei.c @@ -0,0 +1,86 @@ +/** @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_CALLBACK_FUNCTION callbac= k 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] Callback FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION to in= voke + when the production of ACPI S3 Boot Script + opcodes becomes possible. Callback() may be + called immediately from + QemuFwCfgS3CallWhenBootScriptReady(). + + @param[in,out] Context Client-provided data structure for the + Callback() callback function to consume. + + If Context points to dynamically allocated + memory, then Callback() must release it. + + If Context points to dynamically allocated + memory, and + QemuFwCfgS3CallWhenBootScriptReady() retur= ns + successfully, then the caller of + QemuFwCfgS3CallWhenBootScriptReady() must + neither dereference nor even evaluate Cont= ext + any longer, as ownership of the referenced= area + has been transferred to Callback(). + + @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 Callback(). + + @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 Callback() 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 + QemuFwCfgS3CallWhenBootScriptReady() ca= nnot + be rolled back. + + @return Error codes from underlying functions. +**/ +EFIAPI +RETURN_STATUS +QemuFwCfgS3CallWhenBootScriptReady ( + IN FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION *Callback, + 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 Sat Nov 2 12:29:48 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 1489213646970630.9504327237632; Fri, 10 Mar 2017 22:27:26 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id E4483803E4; Fri, 10 Mar 2017 22:27:19 -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 7E85E803E2 for ; Fri, 10 Mar 2017 22:27:19 -0800 (PST) Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 1B2BBC04B92D; Sat, 11 Mar 2017 06:27:20 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-21.phx2.redhat.com [10.3.116.21]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2B6QvsO001140; Sat, 11 Mar 2017 01:27:18 -0500 X-Original-To: edk2-devel@ml01.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Sat, 11 Mar 2017 07:26:49 +0100 Message-Id: <20170311062651.28351-11-lersek@redhat.com> In-Reply-To: <20170311062651.28351-1-lersek@redhat.com> References: <20170311062651.28351-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Sat, 11 Mar 2017 06:27:20 +0000 (UTC) Subject: [edk2] [PATCH v2 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 QemuFwCfgS3CallWhenBootScriptReady(). We provide a fully functional implementation for QemuFwCfgS3CallWhenBootScriptReady(). A protocol notify is installed at TPL_CALLBACK for EFI_S3_SAVE_STATE_PROTOCOL. If / once the protocol is available, the client module's Callback() function is called, which is expected to produce ACPI S3 Boot Script opcodes using the helper functions listed below. In QemuFwCfgS3CallWhenBootScriptReady(), 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 QemuFwCfgS3ScriptWriteBytes(), QemuFwCfgS3ScriptReadBytes(), QemuFwCfgS3ScriptSkipBytes(), and QemuFwCfgS3ScriptCheckValue() functions are also implemented usefully, since the client module's Callback() 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 QemuFwCfgS3ScriptCheckValue() function produces a MEM_POLL opcode to validate an unsigned integer field in data that was read via QemuFwCfgS3ScriptReadBytes(). 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 --- Notes: v2: - rename QemuFwCfgS3TransferOwnership to QemuFwCfgS3CallWhenBootScriptReady [Jordan] - rename FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION to FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION [Jordan] - rename "Append" to "Callback" and "mAppend" to "mCallback" [Laszlo] - rename QemuFwCfgS3WriteBytes, QemuFwCfgS3ReadBytes, QemuFwCfgS3SkipBytes, and QemuFwCfgS3CheckValue to QemuFwCfgS3ScriptWriteBytes, QemuFwCfgS3ScriptReadBytes, QemuFwCfgS3ScriptSkipBytes, and QemuFwCfgS3ScriptCheckValue, respectively [Jordan] OvmfPkg/Library/QemuFwCfgS3Lib/DxeQemuFwCfgS3LibFwCfg.inf | 8 + OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3Dxe.c | 792 ++++++++++= ++++++++++ 2 files changed, 800 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..0bd6cf939904 --- /dev/null +++ b/OvmfPkg/Library/QemuFwCfgS3Lib/QemuFwCfgS3Dxe.c @@ -0,0 +1,792 @@ +/** @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_CALLBACK_FUNCTION *mCallback; + + +/** + 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 (mCallback !=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)); + mCallback (Context, mScratchBuffer); + + gBS->CloseEvent (mS3SaveStateInstalledEvent); + mS3SaveStateInstalledEvent =3D NULL; +} + + +/** + Install the client module's FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION callbac= k 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] Callback FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION to in= voke + when the production of ACPI S3 Boot Script + opcodes becomes possible. Callback() may be + called immediately from + QemuFwCfgS3CallWhenBootScriptReady(). + + @param[in,out] Context Client-provided data structure for the + Callback() callback function to consume. + + If Context points to dynamically allocated + memory, then Callback() must release it. + + If Context points to dynamically allocated + memory, and + QemuFwCfgS3CallWhenBootScriptReady() retur= ns + successfully, then the caller of + QemuFwCfgS3CallWhenBootScriptReady() must + neither dereference nor even evaluate Cont= ext + any longer, as ownership of the referenced= area + has been transferred to Callback(). + + @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 Callback(). + + @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 Callback() 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 + QemuFwCfgS3CallWhenBootScriptReady() ca= nnot + be rolled back. + + @return Error codes from underlying functions. +**/ +EFIAPI +RETURN_STATUS +QemuFwCfgS3CallWhenBootScriptReady ( + IN FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION *Callback, + 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; + mCallback =3D Callback; + + // + // 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; + mCallback =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 QemuFwCfgS3ScriptWriteBytes() 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_CALLBACK_FUNCTION, which was passed to + QemuFwCfgS3CallWhenBootScriptReady() as Callback. + + @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 + QemuFwCfgS3CallWhenBootScriptReady(). + + @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 +QemuFwCfgS3ScriptWriteBytes ( + 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 + // QemuFwCfgS3CallWhenBootScriptReady(). + // + 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 QemuFwCfgS3ScriptReadBytes() will read NumberOfB= ytes + bytes from fw_cfg using DMA, storing the result in ScratchBuffer, in res= erved + 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_CALLBACK_FUNCTION, which was passed to + QemuFwCfgS3CallWhenBootScriptReady() as Callback. + + @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 + QemuFwCfgS3CallWhenBootScriptReady(). + + @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 +QemuFwCfgS3ScriptReadBytes ( + 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 + // QemuFwCfgS3CallWhenBootScriptReady(). + // + 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_CALLBACK_FUNCTION, which was passed to + QemuFwCfgS3CallWhenBootScriptReady() as Callback. + + @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 +QemuFwCfgS3ScriptSkipBytes ( + 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_CALLBACK_FUNCTION, which was passed to + QemuFwCfgS3CallWhenBootScriptReady() as Callback. + + @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 QemuFwCfgS3ScriptReadBytes() = ahead + of QemuFwCfgS3ScriptCheckValue(). + + ScratchData must point into ScratchBuffer, which= was + allocated, and passed to Callback(), by + QemuFwCfgS3CallWhenBootScriptReady(). + + 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 +QemuFwCfgS3ScriptCheckValue ( + 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 Sat Nov 2 12:29:48 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 1489213649492253.09417971531957; Fri, 10 Mar 2017 22:27:29 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 23136803E2; Fri, 10 Mar 2017 22:27:22 -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 1F9F1803A1 for ; Fri, 10 Mar 2017 22:27:21 -0800 (PST) Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 B00871555A; Sat, 11 Mar 2017 06:27:21 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-21.phx2.redhat.com [10.3.116.21]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2B6QvsP001140; Sat, 11 Mar 2017 01:27:20 -0500 X-Original-To: edk2-devel@ml01.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Sat, 11 Mar 2017 07:26:50 +0100 Message-Id: <20170311062651.28351-12-lersek@redhat.com> In-Reply-To: <20170311062651.28351-1-lersek@redhat.com> References: <20170311062651.28351-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Sat, 11 Mar 2017 06:27:21 +0000 (UTC) Subject: [edk2] [PATCH v2 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 QemuFwCfgS3CallWhenBootScriptReady(). 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 --- Notes: v2: - rename QemuFwCfgS3TransferOwnership to QemuFwCfgS3CallWhenBootScriptReady [Jordan] - rename FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION to FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION [Jordan] - rename QemuFwCfgS3WriteBytes, QemuFwCfgS3ReadBytes, QemuFwCfgS3SkipBytes, and QemuFwCfgS3CheckValue to QemuFwCfgS3ScriptWriteBytes, QemuFwCfgS3ScriptReadBytes, QemuFwCfgS3ScriptSkipBytes, and QemuFwCfgS3ScriptCheckValue, respectively [Jordan] 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..7c2cbd86ee62 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_CALLBACK_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 QemuFwCfgS3ScriptWriteBytes (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 QemuFwCfgS3ScriptReadBytes (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 QemuFwCfgS3ScriptCheckValue (&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 QemuFwCfgS3CallWhenBootScriptReady (AppendFwCfgBootScript, NU= LL, + 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 Sat Nov 2 12:29:48 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 1489213652344964.7567174454755; Fri, 10 Mar 2017 22:27:32 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 4FF4B803E8; Fri, 10 Mar 2017 22:27:24 -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 A8484803E8 for ; Fri, 10 Mar 2017 22:27:22 -0800 (PST) Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (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 45D6661BAD; Sat, 11 Mar 2017 06:27:23 +0000 (UTC) Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-21.phx2.redhat.com [10.3.116.21]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id v2B6QvsQ001140; Sat, 11 Mar 2017 01:27:22 -0500 X-Original-To: edk2-devel@ml01.01.org From: Laszlo Ersek To: edk2-devel-01 Date: Sat, 11 Mar 2017 07:26:51 +0100 Message-Id: <20170311062651.28351-13-lersek@redhat.com> In-Reply-To: <20170311062651.28351-1-lersek@redhat.com> References: <20170311062651.28351-1-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Sat, 11 Mar 2017 06:27:23 +0000 (UTC) Subject: [edk2] [PATCH v2 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_CALLBACK_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 --- Notes: v2: - rename QemuFwCfgS3TransferOwnership to QemuFwCfgS3CallWhenBootScriptReady [Jordan] - rename FW_CFG_BOOT_SCRIPT_APPEND_FUNCTION to FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION [Jordan] - rename QemuFwCfgS3WriteBytes, QemuFwCfgS3ReadBytes, QemuFwCfgS3SkipBytes, and QemuFwCfgS3CheckValue to QemuFwCfgS3ScriptWriteBytes, QemuFwCfgS3ScriptReadBytes, QemuFwCfgS3ScriptSkipBytes, and QemuFwCfgS3ScriptCheckValue, respectively [Jordan] 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..a7d2f9e38f57 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_CALLBACK_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 QemuFwCfgS3ScriptSkipBytes (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 QemuFwCfgS3ScriptWriteBytes (-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 QemuFwCfgS3CallWhenBootScriptReady (AppendFwCfgBootScript, + S3Context, 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