diff options
author | xieyuanh <yuanhao.xie@intel.com> | 2024-07-22 14:31:41 +0800 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2024-09-02 17:26:58 +0000 |
commit | df58def118a72bcf540e049ae560c6bea0b0c488 (patch) | |
tree | 910547062866248d1227665255b65c8cda2d68b6 /MdeModulePkg | |
parent | 02f67748039ad44aed83654b9048cfdd052ba424 (diff) | |
download | edk2-df58def118a72bcf540e049ae560c6bea0b0c488.tar.gz edk2-df58def118a72bcf540e049ae560c6bea0b0c488.tar.bz2 edk2-df58def118a72bcf540e049ae560c6bea0b0c488.zip |
MdeModulePkg: Add VarCheckHiiLibStandaloneMm.
This library is designed for handling variable HII checks within the
Standalone MMm environment. It includes the functions
dedicated to registering handlers that process information received
from VarCheckHiiLibMmDependency.
Cc: Liming Gao <gaoliming@byosoft.com.cn>
Cc: Rahul Kumar <rahul1.kumar@intel.com>
Cc: Gerd Hoffmann <kraxel@redhat.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: Hongbin1 Zhang <hongbin1.zhang@intel.com>
Cc: Wei6 Xu <wei6.xu@intel.com>
Cc: Dun Tan <dun.tan@intel.com>
Cc: Dandan Bi <dandan.bi@intel.com>
Signed-off-by: Yuanhao Xie <yuanhao.xie@intel.com>
Diffstat (limited to 'MdeModulePkg')
3 files changed, 214 insertions, 0 deletions
diff --git a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibStandaloneMm.c b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibStandaloneMm.c new file mode 100644 index 0000000000..c1ee55bb2e --- /dev/null +++ b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibStandaloneMm.c @@ -0,0 +1,152 @@ +/** @file
+
+ Implementation functions and structures for var check services.
+ This file provides functions and structures to register and handle variable checks
+ in the Standalone MM environment, specifically for HII variables.
+
+Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
+SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Uefi.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/MmServicesTableLib.h>
+#include <Protocol/MmCommunication.h>
+#include <Library/VarCheckLib.h>
+
+#include "VarCheckHii.h"
+#include "VarCheckHiiLibCommon.h"
+
+//
+// In the standalone setup, mVarCheckHiiBin is used for sending, while mVarCheckHiiBinMmReceived is used for receiving,
+// while in the traditional setup, mVarCheckHiiBin is used for both sending and receiving.
+//
+VAR_CHECK_HII_VARIABLE_HEADER *mMmReceivedVarCheckHiiBin = NULL;
+UINTN mMmReceivedVarCheckHiiBinSize = 0;
+EFI_GUID gVarCheckReceivedHiiBinHandlerGuid = VAR_CHECK_RECEIVED_HII_BIN_HANDLER_GUID;
+
+/**
+ Registers a handler for HII variable checks in MM environment.
+ This function is intended to be called to register a handler for checking variables
+ in the Standalone MM environment. It allocates memory for the variable
+ check data and copies the data from the communication buffer.
+
+ @param[in] DispatchHandle The handle of the dispatch function.
+ @param[in] Context Optional context for the handler, not used in this implementation.
+ @param CommBuffer The buffer of data being passed in.
+ @param CommBufferSize The size of the data being passed in.
+ @retval EFI_SUCCESS Registration and memory allocation were successful.
+ @retval EFI_INVALID_PARAMETER The CommBuffer or CommBufferSize is NULL.
+ @retval EFI_ACCESS_DENIED The buffer size is invalid or the buffer is in an invalid location.
+ @retval EFI_OUT_OF_RESOURCES Memory allocation for the variable check data failed.
+
+**/
+EFI_STATUS
+EFIAPI
+VarCheckHiiLibReceiveHiiBinHandler (
+ IN EFI_HANDLE DispatchHandle,
+ IN CONST VOID *Context OPTIONAL,
+ IN OUT VOID *CommBuffer OPTIONAL,
+ IN OUT UINTN *CommBufferSize OPTIONAL
+ )
+{
+ EFI_STATUS Status;
+
+ //
+ // If input is invalid, stop processing this SMI
+ //
+ if ((CommBuffer == NULL) || (CommBufferSize == NULL)) {
+ return EFI_SUCCESS;
+ }
+
+ mMmReceivedVarCheckHiiBinSize = *CommBufferSize;
+
+ if (mMmReceivedVarCheckHiiBinSize < sizeof (VAR_CHECK_HII_VARIABLE_HEADER)) {
+ DEBUG ((DEBUG_ERROR, "%a: MM Communication buffer size is invalid for this handler!\n", __func__));
+ return EFI_ACCESS_DENIED;
+ }
+
+ mMmReceivedVarCheckHiiBin = AllocateZeroPool (mMmReceivedVarCheckHiiBinSize);
+ if (mMmReceivedVarCheckHiiBin == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a: Failed to allocate memory for mVarCheckHiiBinMm\n", __func__));
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ CopyMem (mMmReceivedVarCheckHiiBin, CommBuffer, mMmReceivedVarCheckHiiBinSize);
+ if (DispatchHandle != NULL) {
+ Status = gMmst->MmiHandlerUnRegister (DispatchHandle);
+ }
+
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Failed to unregister handler - %r!\n", __func__, Status));
+ } else {
+ DEBUG ((DEBUG_INFO, "%a: Handler unregistered successfully.\n", __func__));
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+
+ Sets the variable check handler for HII.
+ This function registers a handler that will be invoked for variable checks
+ in the HII environment. It allows for custom validation logic to be implemented
+ for setting HII variables.
+ @param[in] VariableName Name of Variable to set.
+ @param[in] VendorGuid Variable vendor GUID.
+ @param[in] Attributes Attribute value of the variable.
+ @param[in] DataSize Size of Data to set.
+ @param[in] Data Data pointer.
+
+**/
+EFI_STATUS
+EFIAPI
+SetVariableCheckHandlerHii (
+ IN CHAR16 *VariableName,
+ IN EFI_GUID *VendorGuid,
+ IN UINT32 Attributes,
+ IN UINTN DataSize,
+ IN VOID *Data
+ )
+{
+ return CheckHiiVariableCommon (mMmReceivedVarCheckHiiBin, mMmReceivedVarCheckHiiBinSize, VariableName, VendorGuid, Attributes, DataSize, Data);
+}
+
+/**
+ Constructor function for variable check library in Standalone MM.
+ This function registers a handler for variable checks and sets up the environment
+ for variable checking in the Standalone MM environment.
+ @param[in] ImageHandle The firmware allocated handle for the EFI image.
+ @param[in] SystemTable A pointer to the EFI system table.
+ @retval EFI_SUCCESS The constructor executed successfully.
+ @retval Others An error occurred during execution.
+
+**/
+EFI_STATUS
+EFIAPI
+VarCheckHiiLibConstructorStandaloneMm (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_MM_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ EFI_HANDLE DispatchHandle;
+
+ DEBUG ((DEBUG_INFO, "%a: starts.\n", __func__));
+ //
+ // Register a handler to recieve the HII variable checking data.
+ //
+ Status = gMmst->MmiHandlerRegister (VarCheckHiiLibReceiveHiiBinHandler, &gVarCheckReceivedHiiBinHandlerGuid, &DispatchHandle);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "%a: Failed to register handler - %r!\n", __func__, Status));
+
+ return Status;
+ }
+
+ VarCheckLibRegisterAddressPointer ((VOID **)&mMmReceivedVarCheckHiiBin);
+ VarCheckLibRegisterSetVariableCheckHandler (SetVariableCheckHandlerHii);
+ DEBUG ((DEBUG_INFO, "%a: ends.\n", __func__));
+ return EFI_SUCCESS;
+}
diff --git a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibStandaloneMm.inf b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibStandaloneMm.inf new file mode 100644 index 0000000000..dcef802940 --- /dev/null +++ b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibStandaloneMm.inf @@ -0,0 +1,47 @@ +## @file
+# Implementation functions and structures for var check services.
+#
+# Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
+#
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010017
+ BASE_NAME = VarCheckHiiLib
+ MODULE_UNI_FILE = VarCheckHiiLibStandaloneMm.uni
+ FILE_GUID = 8545E553-AF7D-4FA0-B402-9B5A67ABC812
+ MODULE_TYPE = MM_STANDALONE
+ VERSION_STRING = 1.0
+ PI_SPECIFICATION_VERSION = 0x00010032
+ LIBRARY_CLASS = VarCheckHiiLib|MM_STANDALONE
+ CONSTRUCTOR = VarCheckHiiLibConstructorStandaloneMm
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ VarCheckHiiLibStandaloneMm.c
+ VarCheckHii.h
+ InternalVarCheckStructure.h
+ VarCheckHiiLibCommon.c
+ VarCheckHiiLibCommon.h
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ StandaloneMmPkg/StandaloneMmPkg.dec
+
+[LibraryClasses]
+ BaseLib
+ BaseMemoryLib
+ DebugLib
+ MemoryAllocationLib
+ VarCheckLib
+
+[Protocols]
+ gEfiMmEndOfDxeProtocolGuid
diff --git a/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibStandaloneMm.uni b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibStandaloneMm.uni new file mode 100644 index 0000000000..a84a1ccb96 --- /dev/null +++ b/MdeModulePkg/Library/VarCheckHiiLib/VarCheckHiiLibStandaloneMm.uni @@ -0,0 +1,15 @@ +// /** @file
+// Provides variable check services and database management.
+//
+// Provides variable check services and database management.
+//
+// Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+
+#string STR_MODULE_ABSTRACT #language en-US "Provides StandaloneMm variable check services and database management"
+
+#string STR_MODULE_DESCRIPTION #language en-US "Provides StandaloneMm variable check services and database management."
|