From nobody Mon Feb 9 08:34:04 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+57443+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+57443+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1586992304; cv=none; d=zohomail.com; s=zohoarc; b=lR/DaFJ3HWwnrPvb930e/7mBRehRHKjOYpUjPPnFLHuBt1q2Ri7H1ilKV/cMRRcx1EyR2Z6c6pyCW+XzTOrmW5bIDxSmux06q5+aIp2rhdOskr44C+M1J4Wpb7dvA20m8Oend9GiUHsFj0Pm0kkg06Kh7ZaT/6V+KBtABkrfkPA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1586992304; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=QVXu3bbxbpD8ljq744cfWsLBzVO762bVTn6R1xWMajg=; b=MrBVbCN/qHhS16bfkuHEd/U5QTfBmLcvGKDlk+24gfd6gmUOV+SC/r4YCafZyAHZnAb7INkY8ep4YoldVQiHWbFWmxNODUQab6XdEiZ6nzRxzrSM/5C1gf2TkAYlVq/NDARdlUizqPhvbVp/UnowdT4kC5FW0QzS+GXVvxkz5TQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+57443+1787277+3901457@groups.io Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 1586992304310605.8513456891536; Wed, 15 Apr 2020 16:11:44 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id HeiAYY1788612xlgNUUMgSL7; Wed, 15 Apr 2020 16:11:43 -0700 X-Received: from smic.int.bsdio.com (smic.int.bsdio.com [65.103.231.193]) by mx.groups.io with SMTP id smtpd.web11.801.1586992303401868417 for ; Wed, 15 Apr 2020 16:11:43 -0700 X-Received: from smic.int.bsdio.com (localhost [127.0.0.1]) by smic.int.bsdio.com (8.15.2/8.15.2) with ESMTPS id 03FNA7up063087 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Wed, 15 Apr 2020 17:10:08 -0600 (MDT) (envelope-from bcran@smic.int.bsdio.com) X-Received: (from bcran@localhost) by smic.int.bsdio.com (8.15.2/8.15.2/Submit) id 03FNA7Zf062804; Wed, 15 Apr 2020 17:10:07 -0600 (MDT) (envelope-from bcran) From: "Rebecca Cran" To: devel@edk2.groups.io Cc: Jordan Justen , Laszlo Ersek , Ard Biesheuvel , Rebecca Cran Subject: [edk2-devel] [PATCH 07/13] OvmfPkg: add QemuFwCfgS3LibNull Date: Wed, 15 Apr 2020 17:09:33 -0600 Message-Id: <4bcc9055d068dadb3dac66d72fb463bb37472251.1586991816.git.rebecca@bsdio.com> In-Reply-To: References: MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,rebecca@bsdio.com X-Gm-Message-State: 8ahrCRqdpJqHPZiZzU5XAooBx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1586992303; bh=j4OjZjfDC0pS4Sg0aeAGwWHlFTymdzc4XePBBajdtFw=; h=Cc:Date:From:Reply-To:Subject:To; b=GR/a8Pefya/obZaiYC98i7JCn5hFeD4XFgA51QERGKVfVKEP9w6Ffmc/XPR0RKLQDWO GwSdVB0H3/Vs2mS7ydThtFxQtq2tQuIAct2h/lxw5oKxDqU5VZHp04slO1x/JM73KjrHX 6ELEptPQnlB7dqzCZmSCAIdfXWp7JGRL/kM= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" Add a null implementation of QemuFwCfgS3Lib, for bhyve. Signed-off-by: Rebecca Cran --- .../PeiQemuFwCfgS3LibFwCfgNull.inf | 39 ++++ .../QemuFwCfgS3BasePeiNull.c | 221 ++++++++++++++++++ .../QemuFwCfgS3LibNull/QemuFwCfgS3PeiNull.c | 80 +++++++ 3 files changed, 340 insertions(+) create mode 100644 OvmfPkg/Library/QemuFwCfgS3LibNull/PeiQemuFwCfgS3LibFwC= fgNull.inf create mode 100644 OvmfPkg/Library/QemuFwCfgS3LibNull/QemuFwCfgS3BasePeiNu= ll.c create mode 100644 OvmfPkg/Library/QemuFwCfgS3LibNull/QemuFwCfgS3PeiNull.c diff --git a/OvmfPkg/Library/QemuFwCfgS3LibNull/PeiQemuFwCfgS3LibFwCfgNull.= inf b/OvmfPkg/Library/QemuFwCfgS3LibNull/PeiQemuFwCfgS3LibFwCfgNull.inf new file mode 100644 index 0000000000..709715a4b8 --- /dev/null +++ b/OvmfPkg/Library/QemuFwCfgS3LibNull/PeiQemuFwCfgS3LibFwCfgNull.inf @@ -0,0 +1,39 @@ +## @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) 2018, Intel Corporation. All rights reserved.
+# Copyright (C) 2017, Red Hat, Inc. +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 1.25 + BASE_NAME =3D PeiQemuFwCfgS3LibFwCfg + FILE_GUID =3D C3E69E90-20D3-4E45-935C-7189899BEAC1 + 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 EBC +# + +[Sources] + QemuFwCfgS3BasePeiNull.c + QemuFwCfgS3PeiNull.c + QemuFwCfgS3PeiDxeNull.c + +[Packages] + MdePkg/MdePkg.dec + OvmfPkg/OvmfPkg.dec + +[LibraryClasses] + DebugLib + QemuFwCfgLib diff --git a/OvmfPkg/Library/QemuFwCfgS3LibNull/QemuFwCfgS3BasePeiNull.c b/= OvmfPkg/Library/QemuFwCfgS3LibNull/QemuFwCfgS3BasePeiNull.c new file mode 100644 index 0000000000..3ec6209ba4 --- /dev/null +++ b/OvmfPkg/Library/QemuFwCfgS3LibNull/QemuFwCfgS3BasePeiNull.c @@ -0,0 +1,221 @@ +/** @file + Shared code for the Base Null and PEI fw_cfg instances of the QemuFwCfgS= 3Lib + class. + + Copyright (C) 2017, Red Hat, Inc. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#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. +**/ +RETURN_STATUS +EFIAPI +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. +**/ +RETURN_STATUS +EFIAPI +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. +**/ +RETURN_STATUS +EFIAPI +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. +**/ +RETURN_STATUS +EFIAPI +QemuFwCfgS3ScriptCheckValue ( + IN VOID *ScratchData, + IN UINT8 ValueSize, + IN UINT64 ValueMask, + IN UINT64 Value + ) +{ + ASSERT (FALSE); + return RETURN_UNSUPPORTED; +} diff --git a/OvmfPkg/Library/QemuFwCfgS3LibNull/QemuFwCfgS3PeiNull.c b/Ovmf= Pkg/Library/QemuFwCfgS3LibNull/QemuFwCfgS3PeiNull.c new file mode 100644 index 0000000000..0d055cacbd --- /dev/null +++ b/OvmfPkg/Library/QemuFwCfgS3LibNull/QemuFwCfgS3PeiNull.c @@ -0,0 +1,80 @@ +/** @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. + + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ + +#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. +**/ +RETURN_STATUS +EFIAPI +QemuFwCfgS3CallWhenBootScriptReady ( + IN FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION *Callback, + IN OUT VOID *Context, OPTIONAL + IN UINTN ScratchBufferSize + ) +{ + return RETURN_UNSUPPORTED; +} --=20 2.26.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#57443): https://edk2.groups.io/g/devel/message/57443 Mute This Topic: https://groups.io/mt/73045144/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-