9#include "MmVariablePei.h"
11#define MM_VARIABLE_COMM_BUFFER_OFFSET (SMM_COMMUNICATE_HEADER_SIZE + SMM_VARIABLE_COMMUNICATE_HEADER_SIZE)
18 PeiMmGetNextVariableName
22 (EFI_PEI_PPI_DESCRIPTOR_PPI | EFI_PEI_PPI_DESCRIPTOR_TERMINATE_LIST),
23 &gEfiPeiReadOnlyVariable2PpiGuid,
24 &mPeiSecureVariableRead
39PeiMmVariableInitialize (
61PopulateHeaderAndCommunicate (
62 IN OUT UINT8 *CommunicateBuffer,
73 if ((CommunicateBuffer ==
NULL) ||
74 (CommunicateBufferSize < MM_VARIABLE_COMM_BUFFER_OFFSET))
76 Status = EFI_INVALID_PARAMETER;
77 DEBUG ((DEBUG_ERROR,
"%a: Invalid incoming parameters: %p and 0x%x\n", __func__, CommunicateBuffer, CommunicateBufferSize));
81 if ((Function != SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME) &&
82 (Function != SMM_VARIABLE_FUNCTION_GET_VARIABLE))
84 Status = EFI_INVALID_PARAMETER;
85 DEBUG ((DEBUG_ERROR,
"%a: Invalid function value: 0x%x\n", __func__, Function));
90 if (EFI_ERROR (Status)) {
91 DEBUG ((DEBUG_ERROR,
"%a: Failed to locate PEI MM Communication PPI: %r\n", __func__, Status));
109 MmVarCommsHeader->Function = Function;
112 Status = MmCommunicationPpi->Communicate (MmCommunicationPpi, CommunicateBuffer, &CommunicateBufferSize);
113 if (EFI_ERROR (Status)) {
115 DEBUG ((DEBUG_ERROR,
"%a - MM Interface Error: %r\n", __func__, Status));
121 Status = MmVarCommsHeader->ReturnStatus;
122 if (EFI_ERROR (Status)) {
125 if (Status != EFI_BUFFER_TOO_SMALL) {
126 DEBUG ((DEBUG_ERROR,
"%a - Variable Service Error: %r\n", __func__, Status));
169 OUT UINT32 *Attributes, OPTIONAL
171 OUT VOID *Data OPTIONAL
177 UINT8 *MmCommunicateBuffer;
181 if ((VariableName ==
NULL) || (VariableGuid ==
NULL) || (DataSize ==
NULL)) {
182 return EFI_INVALID_PARAMETER;
185 if (VariableName[0] == 0) {
186 return EFI_NOT_FOUND;
189 if ((*DataSize > 0) && (Data ==
NULL)) {
190 return EFI_INVALID_PARAMETER;
194 MessageSize = MM_VARIABLE_COMM_BUFFER_OFFSET +
196 StrSize (VariableName) + *DataSize;
199 MmCommunicateBuffer = (UINT8 *)
AllocatePages (RequiredPages);
201 if (MmCommunicateBuffer ==
NULL) {
202 Status = EFI_OUT_OF_RESOURCES;
203 DEBUG ((DEBUG_ERROR,
"%a: Failed to allocate memory: %r\n", __func__, Status));
208 ZeroMem (MmCommunicateBuffer, (RequiredPages * EFI_PAGE_SIZE));
216 CopyMem ((VOID *)&MmVarAccessHeader->Guid, VariableGuid, sizeof (
GUID));
219 MmVarAccessHeader->DataSize = *DataSize;
222 MmVarAccessHeader->NameSize =
StrSize (VariableName);
225 CopyMem ((VOID *)&MmVarAccessHeader->Name, VariableName, MmVarAccessHeader->NameSize);
227 Status = PopulateHeaderAndCommunicate (MmCommunicateBuffer, MessageSize, SMM_VARIABLE_FUNCTION_GET_VARIABLE);
228 if (EFI_ERROR (Status)) {
230 if (Status != EFI_BUFFER_TOO_SMALL) {
231 DEBUG ((DEBUG_ERROR,
"%a - Communite to MM for variable service errored: %r\n", __func__, Status));
240 if (*DataSize < MmVarAccessHeader->DataSize) {
241 Status = EFI_BUFFER_TOO_SMALL;
246 if (Attributes !=
NULL) {
247 *Attributes = MmVarAccessHeader->Attributes;
250 *DataSize = MmVarAccessHeader->DataSize;
253 CopyMem ((VOID *)Data, (UINT8 *)MmVarAccessHeader->Name + MmVarAccessHeader->NameSize, *DataSize);
257 if (MmCommunicateBuffer !=
NULL) {
258 FreePages (MmCommunicateBuffer, RequiredPages);
295PeiMmGetNextVariableName (
298 IN OUT CHAR16 *VariableName,
304 UINT8 *MmCommunicateBuffer;
309 if ((VariableName ==
NULL) ||
310 (VariableGuid ==
NULL) ||
311 (VariableNameSize ==
NULL) ||
312 (*VariableNameSize == 0))
314 return EFI_INVALID_PARAMETER;
318 MessageSize = MM_VARIABLE_COMM_BUFFER_OFFSET +
320 StrSize (VariableName) + *VariableNameSize;
323 MmCommunicateBuffer = (UINT8 *)
AllocatePages (RequiredPages);
325 if (MmCommunicateBuffer ==
NULL) {
326 Status = EFI_OUT_OF_RESOURCES;
327 DEBUG ((DEBUG_ERROR,
"%a: Failed to allocate memory: %r\n", __func__, Status));
332 ZeroMem (MmCommunicateBuffer, (RequiredPages * EFI_PAGE_SIZE));
340 CopyMem ((VOID *)&MmVarGetNextVarHeader->Guid, VariableGuid, sizeof (
GUID));
343 MmVarGetNextVarHeader->NameSize = *VariableNameSize;
346 CopyMem ((VOID *)&MmVarGetNextVarHeader->Name, VariableName, MmVarGetNextVarHeader->NameSize);
349 Status = PopulateHeaderAndCommunicate (MmCommunicateBuffer, MessageSize, SMM_VARIABLE_FUNCTION_GET_NEXT_VARIABLE_NAME);
350 if (EFI_ERROR (Status)) {
352 if (Status != EFI_BUFFER_TOO_SMALL) {
353 DEBUG ((DEBUG_ERROR,
"%a - Communite to MM for variable service errored: %r\n", __func__, Status));
362 if (*VariableNameSize < MmVarGetNextVarHeader->NameSize) {
363 Status = EFI_BUFFER_TOO_SMALL;
368 *VariableNameSize = MmVarGetNextVarHeader->NameSize;
371 CopyMem ((VOID *)VariableName, (UINT8 *)MmVarGetNextVarHeader->Name, *VariableNameSize);
372 CopyMem ((VOID *)VariableGuid, (UINT8 *)&(MmVarGetNextVarHeader->Guid), sizeof (
EFI_GUID));
376 if (MmCommunicateBuffer !=
NULL) {
377 FreePages (MmCommunicateBuffer, RequiredPages);
UINTN EFIAPI StrSize(IN CONST CHAR16 *String)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID EFIAPI FreePages(IN VOID *Buffer, IN UINTN Pages)
EFI_STATUS EFIAPI PeiServicesLocatePpi(IN CONST EFI_GUID *Guid, IN UINTN Instance, IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor, IN OUT VOID **Ppi)
EFI_STATUS EFIAPI PeiServicesInstallPpi(IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList)
#define OFFSET_OF(TYPE, Field)
#define DEBUG(Expression)
VOID * EFI_PEI_FILE_HANDLE
VOID *EFIAPI AllocatePages(IN UINTN Pages)
#define SMM_COMMUNICATE_HEADER_SIZE
VOID EFIAPI Exit(IN EFI_STATUS Status)
#define EFI_SIZE_TO_PAGES(Size)