24UINT8 *mLockBoxSmmCommBuffer =
NULL;
42 if (mLockBoxSmmCommProtocol !=
NULL) {
43 return mLockBoxSmmCommProtocol;
46 Status =
gBS->LocateProtocol (
47 &gEfiSmmCommunicationProtocolGuid,
49 (VOID **)&mLockBoxSmmCommProtocol
51 if (EFI_ERROR (Status)) {
52 mLockBoxSmmCommProtocol =
NULL;
55 return mLockBoxSmmCommProtocol;
70 UINTN MinimalSizeNeeded;
79 if (mLockBoxSmmCommBuffer !=
NULL) {
80 return mLockBoxSmmCommBuffer;
83 MinimalSizeNeeded =
sizeof (
EFI_GUID) +
100 &gEdkiiPiSmmCommunicationRegionTableGuid,
101 (VOID **)&PiSmmCommunicationRegionTable
103 if (EFI_ERROR (Status)) {
104 mLockBoxSmmCommBuffer =
NULL;
105 return mLockBoxSmmCommBuffer;
108 ASSERT (PiSmmCommunicationRegionTable !=
NULL);
111 for (Index = 0; Index < PiSmmCommunicationRegionTable->NumberOfEntries; Index++) {
114 if (Size >= MinimalSizeNeeded) {
122 if (Index >= PiSmmCommunicationRegionTable->NumberOfEntries) {
123 mLockBoxSmmCommBuffer =
NULL;
125 mLockBoxSmmCommBuffer = (UINT8 *)(
UINTN)Entry->PhysicalStart;
128 return mLockBoxSmmCommBuffer;
162 DEBUG ((DEBUG_INFO,
"SmmLockBoxDxeLib SaveLockBox - Enter\n"));
167 if ((Guid ==
NULL) || (Buffer ==
NULL) || (Length == 0)) {
168 return EFI_INVALID_PARAMETER;
172 if (SmmCommunication ==
NULL) {
173 return EFI_NOT_STARTED;
180 if (CommBuffer ==
NULL) {
181 CommBuffer = &TempCommBuffer[0];
185 CopyMem (&CommHeader->
HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof (gEfiSmmLockBoxCommunicationGuid));
189 LockBoxParameterSave->Header.Command = EFI_SMM_LOCK_BOX_COMMAND_SAVE;
190 LockBoxParameterSave->Header.DataLength =
sizeof (*LockBoxParameterSave);
191 LockBoxParameterSave->Header.ReturnStatus = (UINT64)-1;
192 CopyMem (&LockBoxParameterSave->Guid, Guid, sizeof (*Guid));
194 LockBoxParameterSave->Length = (UINT64)Length;
200 Status = SmmCommunication->Communicate (
207 Status = (
EFI_STATUS)LockBoxParameterSave->Header.ReturnStatus;
209 DEBUG ((DEBUG_INFO,
"SmmLockBoxDxeLib SaveLockBox - Exit (%r)\n", Status));
245 DEBUG ((DEBUG_INFO,
"SmmLockBoxDxeLib SetLockBoxAttributes - Enter\n"));
250 if ((Guid ==
NULL) ||
251 ((Attributes & ~(LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE | LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY)) != 0))
253 return EFI_INVALID_PARAMETER;
257 if (SmmCommunication ==
NULL) {
258 return EFI_NOT_STARTED;
265 if (CommBuffer ==
NULL) {
266 CommBuffer = &TempCommBuffer[0];
270 CopyMem (&CommHeader->
HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof (gEfiSmmLockBoxCommunicationGuid));
271 CommHeader->
MessageLength =
sizeof (*LockBoxParameterSetAttributes);
274 LockBoxParameterSetAttributes->Header.Command = EFI_SMM_LOCK_BOX_COMMAND_SET_ATTRIBUTES;
275 LockBoxParameterSetAttributes->Header.DataLength =
sizeof (*LockBoxParameterSetAttributes);
276 LockBoxParameterSetAttributes->Header.ReturnStatus = (UINT64)-1;
277 CopyMem (&LockBoxParameterSetAttributes->Guid, Guid, sizeof (*Guid));
278 LockBoxParameterSetAttributes->Attributes = (UINT64)Attributes;
284 Status = SmmCommunication->Communicate (
291 Status = (
EFI_STATUS)LockBoxParameterSetAttributes->Header.ReturnStatus;
293 DEBUG ((DEBUG_INFO,
"SmmLockBoxDxeLib SetLockBoxAttributes - Exit (%r)\n", Status));
337 DEBUG ((DEBUG_INFO,
"SmmLockBoxDxeLib UpdateLockBox - Enter\n"));
342 if ((Guid ==
NULL) || (Buffer ==
NULL) || (Length == 0)) {
343 return EFI_INVALID_PARAMETER;
347 if (SmmCommunication ==
NULL) {
348 return EFI_NOT_STARTED;
355 if (CommBuffer ==
NULL) {
356 CommBuffer = &TempCommBuffer[0];
360 CopyMem (&CommHeader->
HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof (gEfiSmmLockBoxCommunicationGuid));
361 CommHeader->
MessageLength =
sizeof (*LockBoxParameterUpdate);
364 LockBoxParameterUpdate->Header.Command = EFI_SMM_LOCK_BOX_COMMAND_UPDATE;
365 LockBoxParameterUpdate->Header.DataLength =
sizeof (*LockBoxParameterUpdate);
366 LockBoxParameterUpdate->Header.ReturnStatus = (UINT64)-1;
367 CopyMem (&LockBoxParameterUpdate->Guid, Guid, sizeof (*Guid));
368 LockBoxParameterUpdate->Offset = (UINT64)Offset;
370 LockBoxParameterUpdate->Length = (UINT64)Length;
376 Status = SmmCommunication->Communicate (
383 Status = (
EFI_STATUS)LockBoxParameterUpdate->Header.ReturnStatus;
385 DEBUG ((DEBUG_INFO,
"SmmLockBoxDxeLib UpdateLockBox - Exit (%r)\n", Status));
415 IN VOID *Buffer OPTIONAL,
427 DEBUG ((DEBUG_INFO,
"SmmLockBoxDxeLib RestoreLockBox - Enter\n"));
432 if ((Guid ==
NULL) ||
433 ((Buffer ==
NULL) && (Length !=
NULL)) ||
434 ((Buffer !=
NULL) && (Length ==
NULL)))
436 return EFI_INVALID_PARAMETER;
440 if (SmmCommunication ==
NULL) {
441 return EFI_NOT_STARTED;
448 if (CommBuffer ==
NULL) {
449 CommBuffer = &TempCommBuffer[0];
453 CopyMem (&CommHeader->
HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof (gEfiSmmLockBoxCommunicationGuid));
454 CommHeader->
MessageLength =
sizeof (*LockBoxParameterRestore);
457 LockBoxParameterRestore->Header.Command = EFI_SMM_LOCK_BOX_COMMAND_RESTORE;
458 LockBoxParameterRestore->Header.DataLength =
sizeof (*LockBoxParameterRestore);
459 LockBoxParameterRestore->Header.ReturnStatus = (UINT64)-1;
460 CopyMem (&LockBoxParameterRestore->Guid, Guid, sizeof (*Guid));
462 if (Length !=
NULL) {
465 LockBoxParameterRestore->Length = 0;
472 Status = SmmCommunication->Communicate (
479 if (Length !=
NULL) {
480 *Length = (
UINTN)LockBoxParameterRestore->Length;
483 Status = (
EFI_STATUS)LockBoxParameterRestore->Header.ReturnStatus;
485 DEBUG ((DEBUG_INFO,
"SmmLockBoxDxeLib RestoreLockBox - Exit (%r)\n", Status));
514 DEBUG ((DEBUG_INFO,
"SmmLockBoxDxeLib RestoreAllLockBoxInPlace - Enter\n"));
517 if (SmmCommunication ==
NULL) {
518 return EFI_NOT_STARTED;
525 if (CommBuffer ==
NULL) {
526 CommBuffer = &TempCommBuffer[0];
530 CopyMem (&CommHeader->
HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof (gEfiSmmLockBoxCommunicationGuid));
531 CommHeader->
MessageLength =
sizeof (*LockBoxParameterRestoreAllInPlace);
534 LockBoxParameterRestoreAllInPlace->Header.Command = EFI_SMM_LOCK_BOX_COMMAND_RESTORE_ALL_IN_PLACE;
535 LockBoxParameterRestoreAllInPlace->Header.DataLength =
sizeof (*LockBoxParameterRestoreAllInPlace);
536 LockBoxParameterRestoreAllInPlace->Header.ReturnStatus = (UINT64)-1;
542 Status = SmmCommunication->Communicate (
549 Status = (
EFI_STATUS)LockBoxParameterRestoreAllInPlace->Header.ReturnStatus;
551 DEBUG ((DEBUG_INFO,
"SmmLockBoxDxeLib RestoreAllLockBoxInPlace - Exit (%r)\n", Status));
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define OFFSET_OF(TYPE, Field)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
UINT8 * LockBoxGetSmmCommBuffer(VOID)
RETURN_STATUS EFIAPI SetLockBoxAttributes(IN GUID *Guid, IN UINT64 Attributes)
EFI_SMM_COMMUNICATION_PROTOCOL * LockBoxGetSmmCommProtocol(VOID)
RETURN_STATUS EFIAPI RestoreLockBox(IN GUID *Guid, IN VOID *Buffer OPTIONAL, IN OUT UINTN *Length OPTIONAL)
RETURN_STATUS EFIAPI RestoreAllLockBoxInPlace(VOID)
RETURN_STATUS EFIAPI UpdateLockBox(IN GUID *Guid, IN UINTN Offset, IN VOID *Buffer, IN UINTN Length)
RETURN_STATUS EFIAPI SaveLockBox(IN GUID *Guid, IN VOID *Buffer, IN UINTN Length)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_PAGES_TO_SIZE(Pages)
EFI_STATUS EFIAPI EfiGetSystemConfigurationTable(IN EFI_GUID *TableGuid, OUT VOID **Table)