From mboxrd@z Thu Jan 1 00:00:00 1970 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 Authentication-Results: mx.groups.io; dkim=missing; spf=none, err=permanent DNS error (domain: smic.int.bsdio.com, ip: 65.103.231.193, mailfrom: bcran@smic.int.bsdio.com) 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) 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: [PATCH 07/13] OvmfPkg: add QemuFwCfgS3LibNull Date: Wed, 15 Apr 2020 17:09:33 -0600 Message-Id: <4bcc9055d068dadb3dac66d72fb463bb37472251.1586991816.git.rebecca@bsdio.com> X-Mailer: git-send-email 2.26.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=0D +# Limited functionality QemuFwCfgS3Lib instance, for PEI phase modules.=0D +#=0D +# QemuFwCfgS3Enabled() queries S3 enablement via fw_cfg. Other library API= s=0D +# will report lack of support.=0D +#=0D +# Copyright (c) 2018, Intel Corporation. All rights reserved.
=0D +# Copyright (C) 2017, Red Hat, Inc.=0D +#=0D +# SPDX-License-Identifier: BSD-2-Clause-Patent=0D +##=0D +=0D +[Defines]=0D + INF_VERSION =3D 1.25=0D + BASE_NAME =3D PeiQemuFwCfgS3LibFwCfg=0D + FILE_GUID =3D C3E69E90-20D3-4E45-935C-7189899BEAC1= =0D + MODULE_TYPE =3D PEIM=0D + VERSION_STRING =3D 1.0=0D + LIBRARY_CLASS =3D QemuFwCfgS3Lib|PEIM=0D +=0D +#=0D +# The following information is for reference only and not required by the = build=0D +# tools.=0D +#=0D +# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 EBC=0D +#=0D +=0D +[Sources]=0D + QemuFwCfgS3BasePeiNull.c=0D + QemuFwCfgS3PeiNull.c=0D + QemuFwCfgS3PeiDxeNull.c=0D +=0D +[Packages]=0D + MdePkg/MdePkg.dec=0D + OvmfPkg/OvmfPkg.dec=0D +=0D +[LibraryClasses]=0D + DebugLib=0D + QemuFwCfgLib=0D 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=0D + Shared code for the Base Null and PEI fw_cfg instances of the QemuFwCfgS= 3Lib=0D + class.=0D +=0D + Copyright (C) 2017, Red Hat, Inc.=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +**/=0D +=0D +#include =0D +#include =0D +=0D +/**=0D + Produce ACPI S3 Boot Script opcodes that (optionally) select an fw_cfg i= tem,=0D + and transfer data to it.=0D +=0D + The opcodes produced by QemuFwCfgS3ScriptWriteBytes() will first restore= =0D + NumberOfBytes bytes in ScratchBuffer in-place, in reserved memory, then = write=0D + them to fw_cfg using DMA.=0D +=0D + If the operation fails during S3 resume, the boot script will hang.=0D +=0D + This function may only be called from the client module's=0D + FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION, which was passed to=0D + QemuFwCfgS3CallWhenBootScriptReady() as Callback.=0D +=0D + @param[in] FirmwareConfigItem The UINT16 selector key of the firmware c= onfig=0D + item to write, expressed as INT32. If=0D + FirmwareConfigItem is -1, no selection is= =0D + made, the write will occur to the current= ly=0D + selected item, at its currently selected= =0D + offset. Otherwise, the specified item wil= l be=0D + selected, and the write will occur at off= set=0D + 0.=0D +=0D + @param[in] NumberOfBytes Size of the data to restore in ScratchBuf= fer,=0D + and to write from ScratchBuffer, during S= 3=0D + resume. NumberOfBytes must not exceed=0D + ScratchBufferSize, which was passed to=0D + QemuFwCfgS3CallWhenBootScriptReady().=0D +=0D + @retval RETURN_SUCCESS The opcodes were appended to the ACPI = S3=0D + Boot Script successfully. There is no = way=0D + to undo this action.=0D +=0D + @retval RETURN_INVALID_PARAMETER FirmwareConfigItem is invalid.=0D +=0D + @retval RETURN_BAD_BUFFER_SIZE NumberOfBytes is larger than=0D + ScratchBufferSize.=0D +=0D + @return Error codes from underlying functions.= =0D +**/=0D +RETURN_STATUS=0D +EFIAPI=0D +QemuFwCfgS3ScriptWriteBytes (=0D + IN INT32 FirmwareConfigItem,=0D + IN UINTN NumberOfBytes=0D + )=0D +{=0D + ASSERT (FALSE);=0D + return RETURN_UNSUPPORTED;=0D +}=0D +=0D +=0D +/**=0D + Produce ACPI S3 Boot Script opcodes that (optionally) select an fw_cfg i= tem,=0D + and transfer data from it.=0D +=0D + The opcodes produced by QemuFwCfgS3ScriptReadBytes() will read NumberOfB= ytes=0D + bytes from fw_cfg using DMA, storing the result in ScratchBuffer, in res= erved=0D + memory.=0D +=0D + If the operation fails during S3 resume, the boot script will hang.=0D +=0D + This function may only be called from the client module's=0D + FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION, which was passed to=0D + QemuFwCfgS3CallWhenBootScriptReady() as Callback.=0D +=0D + @param[in] FirmwareConfigItem The UINT16 selector key of the firmware c= onfig=0D + item to read, expressed as INT32. If=0D + FirmwareConfigItem is -1, no selection is= =0D + made, the read will occur from the curren= tly=0D + selected item, from its currently selecte= d=0D + offset. Otherwise, the specified item wil= l be=0D + selected, and the read will occur from of= fset=0D + 0.=0D +=0D + @param[in] NumberOfBytes Size of the data to read during S3 resume= .=0D + NumberOfBytes must not exceed=0D + ScratchBufferSize, which was passed to=0D + QemuFwCfgS3CallWhenBootScriptReady().=0D +=0D + @retval RETURN_SUCCESS The opcodes were appended to the ACPI = S3=0D + Boot Script successfully. There is no = way=0D + to undo this action.=0D +=0D + @retval RETURN_INVALID_PARAMETER FirmwareConfigItem is invalid.=0D +=0D + @retval RETURN_BAD_BUFFER_SIZE NumberOfBytes is larger than=0D + ScratchBufferSize.=0D +=0D + @return Error codes from underlying functions.= =0D +**/=0D +RETURN_STATUS=0D +EFIAPI=0D +QemuFwCfgS3ScriptReadBytes (=0D + IN INT32 FirmwareConfigItem,=0D + IN UINTN NumberOfBytes=0D + )=0D +{=0D + ASSERT (FALSE);=0D + return RETURN_UNSUPPORTED;=0D +}=0D +=0D +=0D +/**=0D + Produce ACPI S3 Boot Script opcodes that (optionally) select an fw_cfg i= tem,=0D + and increase its offset.=0D +=0D + If the operation fails during S3 resume, the boot script will hang.=0D +=0D + This function may only be called from the client module's=0D + FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION, which was passed to=0D + QemuFwCfgS3CallWhenBootScriptReady() as Callback.=0D +=0D + @param[in] FirmwareConfigItem The UINT16 selector key of the firmware c= onfig=0D + item to advance the offset of, expressed = as=0D + INT32. If FirmwareConfigItem is -1, no=0D + selection is made, and the offset for the= =0D + currently selected item is increased.=0D + Otherwise, the specified item will be=0D + selected, and the offset increment will o= ccur=0D + from offset 0.=0D +=0D + @param[in] NumberOfBytes The number of bytes to skip in the subjec= t=0D + fw_cfg item.=0D +=0D + @retval RETURN_SUCCESS The opcodes were appended to the ACPI = S3=0D + Boot Script successfully. There is no = way=0D + to undo this action.=0D +=0D + @retval RETURN_INVALID_PARAMETER FirmwareConfigItem is invalid.=0D +=0D + @retval RETURN_BAD_BUFFER_SIZE NumberOfBytes is too large.=0D +=0D + @return Error codes from underlying functions.= =0D +**/=0D +RETURN_STATUS=0D +EFIAPI=0D +QemuFwCfgS3ScriptSkipBytes (=0D + IN INT32 FirmwareConfigItem,=0D + IN UINTN NumberOfBytes=0D + )=0D +{=0D + ASSERT (FALSE);=0D + return RETURN_UNSUPPORTED;=0D +}=0D +=0D +=0D +/**=0D + Produce ACPI S3 Boot Script opcodes that check a value in ScratchBuffer.= =0D +=0D + If the check fails during S3 resume, the boot script will hang.=0D +=0D + This function may only be called from the client module's=0D + FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION, which was passed to=0D + QemuFwCfgS3CallWhenBootScriptReady() as Callback.=0D +=0D + @param[in] ScratchData Pointer to the UINT8, UINT16, UINT32 or UINT64 f= ield=0D + in ScratchBuffer that should be checked. The cal= ler=0D + is responsible for populating the field during S= 3=0D + resume, by calling QemuFwCfgS3ScriptReadBytes() = ahead=0D + of QemuFwCfgS3ScriptCheckValue().=0D +=0D + ScratchData must point into ScratchBuffer, which= was=0D + allocated, and passed to Callback(), by=0D + QemuFwCfgS3CallWhenBootScriptReady().=0D +=0D + ScratchData must be aligned at ValueSize bytes.= =0D +=0D + @param[in] ValueSize One of 1, 2, 4 or 8, specifying the size of the = field=0D + to check.=0D +=0D + @param[in] ValueMask The value read from ScratchData is binarily AND-= ed=0D + with ValueMask, and the result is compared again= st=0D + Value. If the masked data equals Value, the chec= k=0D + passes, and the boot script can proceed. Otherwi= se,=0D + the check fails, and the boot script hangs.=0D +=0D + @param[in] Value Refer to ValueMask.=0D +=0D + @retval RETURN_SUCCESS The opcodes were appended to the ACPI = S3=0D + Boot Script successfully. There is no = way=0D + to undo this action.=0D +=0D + @retval RETURN_INVALID_PARAMETER ValueSize is invalid.=0D +=0D + @retval RETURN_INVALID_PARAMETER ValueMask or Value cannot be represent= ed in=0D + ValueSize bytes.=0D +=0D + @retval RETURN_INVALID_PARAMETER ScratchData is not aligned at ValueSiz= e=0D + bytes.=0D +=0D + @retval RETURN_BAD_BUFFER_SIZE The ValueSize bytes at ScratchData are= n't=0D + wholly contained in the ScratchBufferS= ize=0D + bytes at ScratchBuffer.=0D +=0D + @return Error codes from underlying functions.= =0D +**/=0D +RETURN_STATUS=0D +EFIAPI=0D +QemuFwCfgS3ScriptCheckValue (=0D + IN VOID *ScratchData,=0D + IN UINT8 ValueSize,=0D + IN UINT64 ValueMask,=0D + IN UINT64 Value=0D + )=0D +{=0D + ASSERT (FALSE);=0D + return RETURN_UNSUPPORTED;=0D +}=0D 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=0D + Limited functionality QemuFwCfgS3Lib instance, for PEI phase modules.=0D +=0D + QemuFwCfgS3Enabled() queries S3 enablement via fw_cfg. Other library API= s=0D + will report lack of support.=0D +=0D + Copyright (C) 2017, Red Hat, Inc.=0D +=0D + SPDX-License-Identifier: BSD-2-Clause-Patent=0D +**/=0D +=0D +#include =0D +=0D +/**=0D + Install the client module's FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION callbac= k for=0D + when the production of ACPI S3 Boot Script opcodes becomes possible.=0D +=0D + Take ownership of the client-provided Context, and pass it to the callba= ck=0D + function, when the latter is invoked.=0D +=0D + Allocate scratch space for those ACPI S3 Boot Script opcodes to work upo= n=0D + that the client will produce in the callback function.=0D +=0D + @param[in] Callback FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION to in= voke=0D + when the production of ACPI S3 Boot Script= =0D + opcodes becomes possible. Callback() may b= e=0D + called immediately from=0D + QemuFwCfgS3CallWhenBootScriptReady().=0D +=0D + @param[in,out] Context Client-provided data structure for the=0D + Callback() callback function to consume.=0D +=0D + If Context points to dynamically allocated= =0D + memory, then Callback() must release it.=0D +=0D + If Context points to dynamically allocated= =0D + memory, and=0D + QemuFwCfgS3CallWhenBootScriptReady() retur= ns=0D + successfully, then the caller of=0D + QemuFwCfgS3CallWhenBootScriptReady() must= =0D + neither dereference nor even evaluate Cont= ext=0D + any longer, as ownership of the referenced= area=0D + has been transferred to Callback().=0D +=0D + @param[in] ScratchBufferSize The size of the scratch buffer that will h= old,=0D + in reserved memory, all client data read,= =0D + written, and checked by the ACPI S3 Boot S= cript=0D + opcodes produced by Callback().=0D +=0D + @retval RETURN_UNSUPPORTED The library instance does not support t= his=0D + function.=0D +=0D + @retval RETURN_NOT_FOUND The fw_cfg DMA interface to QEMU is=0D + unavailable.=0D +=0D + @retval RETURN_BAD_BUFFER_SIZE ScratchBufferSize is too large.=0D +=0D + @retval RETURN_OUT_OF_RESOURCES Memory allocation failed.=0D +=0D + @retval RETURN_SUCCESS Callback() has been installed, and the= =0D + ownership of Context has been transferr= ed.=0D + Reserved memory has been allocated for = the=0D + scratch buffer.=0D +=0D + A successful invocation of=0D + QemuFwCfgS3CallWhenBootScriptReady() ca= nnot=0D + be rolled back.=0D +=0D + @return Error codes from underlying functions.= =0D +**/=0D +RETURN_STATUS=0D +EFIAPI=0D +QemuFwCfgS3CallWhenBootScriptReady (=0D + IN FW_CFG_BOOT_SCRIPT_CALLBACK_FUNCTION *Callback,=0D + IN OUT VOID *Context, OPTIONAL= =0D + IN UINTN ScratchBufferSize=0D + )=0D +{=0D + return RETURN_UNSUPPORTED;=0D +}=0D --=20 2.26.1