TianoCore EDK2 master
Loading...
Searching...
No Matches
VarCheckHiiLibStandaloneMm.c
Go to the documentation of this file.
1
12#include <Uefi.h>
13#include <Library/DebugLib.h>
17#include <Library/VarCheckLib.h>
18
19#include "VarCheckHii.h"
21
22//
23// In the standalone setup, mVarCheckHiiBin is used for sending, while mVarCheckHiiBinMmReceived is used for receiving,
24// while in the traditional setup, mVarCheckHiiBin is used for both sending and receiving.
25//
26VAR_CHECK_HII_VARIABLE_HEADER *mMmReceivedVarCheckHiiBin = NULL;
27UINTN mMmReceivedVarCheckHiiBinSize = 0;
28EFI_GUID gVarCheckReceivedHiiBinHandlerGuid = VAR_CHECK_RECEIVED_HII_BIN_HANDLER_GUID;
29
47EFIAPI
49 IN EFI_HANDLE DispatchHandle,
50 IN CONST VOID *Context OPTIONAL,
51 IN OUT VOID *CommBuffer OPTIONAL,
52 IN OUT UINTN *CommBufferSize OPTIONAL
53 )
54{
55 EFI_STATUS Status;
56
57 //
58 // If input is invalid, stop processing this SMI
59 //
60 if ((CommBuffer == NULL) || (CommBufferSize == NULL)) {
61 return EFI_SUCCESS;
62 }
63
64 mMmReceivedVarCheckHiiBinSize = *CommBufferSize;
65
66 if (mMmReceivedVarCheckHiiBinSize < sizeof (VAR_CHECK_HII_VARIABLE_HEADER)) {
67 DEBUG ((DEBUG_ERROR, "%a: MM Communication buffer size is invalid for this handler!\n", __func__));
68 return EFI_ACCESS_DENIED;
69 }
70
71 mMmReceivedVarCheckHiiBin = AllocateZeroPool (mMmReceivedVarCheckHiiBinSize);
72 if (mMmReceivedVarCheckHiiBin == NULL) {
73 DEBUG ((DEBUG_ERROR, "%a: Failed to allocate memory for mVarCheckHiiBinMm\n", __func__));
74 return EFI_OUT_OF_RESOURCES;
75 }
76
77 CopyMem (mMmReceivedVarCheckHiiBin, CommBuffer, mMmReceivedVarCheckHiiBinSize);
78 if (DispatchHandle != NULL) {
79 Status = gMmst->MmiHandlerUnRegister (DispatchHandle);
80 }
81
82 if (EFI_ERROR (Status)) {
83 DEBUG ((DEBUG_ERROR, "%a: Failed to unregister handler - %r!\n", __func__, Status));
84 } else {
85 DEBUG ((DEBUG_INFO, "%a: Handler unregistered successfully.\n", __func__));
86 }
87
88 return EFI_SUCCESS;
89}
90
105EFIAPI
107 IN CHAR16 *VariableName,
108 IN EFI_GUID *VendorGuid,
109 IN UINT32 Attributes,
110 IN UINTN DataSize,
111 IN VOID *Data
112 )
113{
114 return CheckHiiVariableCommon (mMmReceivedVarCheckHiiBin, mMmReceivedVarCheckHiiBinSize, VariableName, VendorGuid, Attributes, DataSize, Data);
115}
116
128EFIAPI
130 IN EFI_HANDLE ImageHandle,
131 IN EFI_MM_SYSTEM_TABLE *SystemTable
132 )
133{
134 EFI_STATUS Status;
135 EFI_HANDLE DispatchHandle;
136
137 DEBUG ((DEBUG_INFO, "%a: starts.\n", __func__));
138 //
139 // Register a handler to recieve the HII variable checking data.
140 //
141 Status = gMmst->MmiHandlerRegister (VarCheckHiiLibReceiveHiiBinHandler, &gVarCheckReceivedHiiBinHandlerGuid, &DispatchHandle);
142 if (EFI_ERROR (Status)) {
143 DEBUG ((DEBUG_ERROR, "%a: Failed to register handler - %r!\n", __func__, Status));
144
145 return Status;
146 }
147
148 VarCheckLibRegisterAddressPointer ((VOID **)&mMmReceivedVarCheckHiiBin);
150 DEBUG ((DEBUG_INFO, "%a: ends.\n", __func__));
151 return EFI_SUCCESS;
152}
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_STATUS EFIAPI CheckHiiVariableCommon(IN VAR_CHECK_HII_VARIABLE_HEADER *HiiVariableBin, IN UINTN HiiVariableBinSize, IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data)
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 EFIAPI SetVariableCheckHandlerHii(IN CHAR16 *VariableName, IN EFI_GUID *VendorGuid, IN UINT32 Attributes, IN UINTN DataSize, IN VOID *Data)
EFI_STATUS EFIAPI VarCheckHiiLibConstructorStandaloneMm(IN EFI_HANDLE ImageHandle, IN EFI_MM_SYSTEM_TABLE *SystemTable)
EFI_STATUS EFIAPI VarCheckLibRegisterAddressPointer(IN VOID **AddressPointer)
Definition: VarCheckLib.c:398
EFI_STATUS EFIAPI VarCheckLibRegisterSetVariableCheckHandler(IN VAR_CHECK_SET_VARIABLE_CHECK_HANDLER Handler)
Definition: VarCheckLib.c:440
Definition: Base.h:213