28#if defined (MDE_CPU_IA32)
29typedef struct _LIST_ENTRY64 LIST_ENTRY64;
31 LIST_ENTRY64 *ForwardLink;
33 LIST_ENTRY64 *BackLink;
39 UINT64 SmmFirmwareVendor;
40 UINT64 SmmFirmwareRevision;
51 UINT64 CurrentlyExecutingCpu;
53 UINT64 CpuSaveStateSize;
55 UINT64 NumberOfTableEntries;
56 UINT64 SmmConfigurationTable;
57} EFI_SMM_SYSTEM_TABLE2_64;
62} EFI_CONFIGURATION_TABLE64;
65#if defined (MDE_CPU_X64)
83 if ((
sizeof (
UINTN) ==
sizeof (UINT32)) && (
FeaturePcdGet (PcdDxeIplSwitchToLongMode))) {
87 return (
LIST_ENTRY *)(((LIST_ENTRY64 *)LinkList)->ForwardLink);
89 return LinkList->ForwardLink;
105 if ((
sizeof (
UINTN) ==
sizeof (UINT32)) && (
FeaturePcdGet (PcdDxeIplSwitchToLongMode))) {
109 return (
LIST_ENTRY *)(((LIST_ENTRY64 *)Link)->ForwardLink);
111 return Link->ForwardLink;
133 Link != LockBoxQueue;
166 UINTN NumberOfTableEntries;
168 EFI_SMM_SYSTEM_TABLE2_64 *Smst64;
169 EFI_CONFIGURATION_TABLE64 *SmmConfigurationTable64;
171 if ((
sizeof (
UINTN) ==
sizeof (UINT32)) && (
FeaturePcdGet (PcdDxeIplSwitchToLongMode))) {
175 Smst64 = (EFI_SMM_SYSTEM_TABLE2_64 *)Smst;
176 SmmConfigurationTable64 = (EFI_CONFIGURATION_TABLE64 *)(
UINTN)Smst64->SmmConfigurationTable;
177 NumberOfTableEntries = (
UINTN)Smst64->NumberOfTableEntries;
178 for (Index = 0; Index < NumberOfTableEntries; Index++) {
179 if (
CompareGuid (&SmmConfigurationTable64[Index].VendorGuid, VendorGuid)) {
180 return (VOID *)(
UINTN)SmmConfigurationTable64[Index].VendorTable;
186 SmmConfigurationTable = Smst->SmmConfigurationTable;
187 NumberOfTableEntries = Smst->NumberOfTableEntries;
188 for (Index = 0; Index < NumberOfTableEntries; Index++) {
189 if (
CompareGuid (&SmmConfigurationTable[Index].VendorGuid, VendorGuid)) {
190 return (VOID *)SmmConfigurationTable[Index].
VendorTable;
214 ASSERT (GuidHob !=
NULL);
219 SmmS3ResumeState->Signature,
221 &gEfiSmmLockBoxCommunicationGuid
223 ASSERT (SmmLockBoxContext !=
NULL);
225 return SmmLockBoxContext;
245 IN VOID *Buffer OPTIONAL,
261 &gPeiSmmAccessPpiGuid,
266 if (!EFI_ERROR (Status)) {
267 for (Index = 0; !EFI_ERROR (Status); Index++) {
276 LockBoxQueue = (
LIST_ENTRY *)(
UINTN)SmmLockBoxContext->LockBoxDataAddress;
290 if (LockBox ==
NULL) {
294 return EFI_NOT_FOUND;
300 if (Buffer !=
NULL) {
304 RestoreBuffer = Buffer;
309 if ((LockBox->Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE) == 0) {
310 return EFI_WRITE_PROTECTED;
313 RestoreBuffer = (VOID *)(
UINTN)LockBox->Buffer;
319 if (Length !=
NULL) {
320 if (*Length < (
UINTN)LockBox->Length) {
324 *Length = (
UINTN)LockBox->Length;
325 return EFI_BUFFER_TOO_SMALL;
328 *Length = (
UINTN)LockBox->Length;
334 CopyMem (RestoreBuffer, (VOID *)(
UINTN)LockBox->SmramBuffer, (
UINTN)LockBox->Length);
364 &gPeiSmmAccessPpiGuid,
369 if (!EFI_ERROR (Status)) {
370 for (Index = 0; !EFI_ERROR (Status); Index++) {
379 LockBoxQueue = (
LIST_ENTRY *)(
UINTN)SmmLockBoxContext->LockBoxDataAddress;
389 Link != LockBoxQueue;
397 if ((LockBox->Attributes & LOCK_BOX_ATTRIBUTE_RESTORE_IN_PLACE) != 0) {
528 IN VOID *Buffer OPTIONAL,
538 UINT64 MessageLength;
549 DEBUG ((DEBUG_INFO,
"SmmLockBoxPeiLib RestoreLockBox - Enter\n"));
554 if ((Guid ==
NULL) ||
555 ((Buffer ==
NULL) && (Length !=
NULL)) ||
556 ((Buffer !=
NULL) && (Length ==
NULL)))
558 return EFI_INVALID_PARAMETER;
565 &gEfiPeiSmmCommunicationPpiGuid,
568 (VOID **)&SmmCommunicationPpi
570 if (EFI_ERROR (Status)) {
571 DEBUG ((DEBUG_INFO,
"SmmLockBoxPeiLib LocatePpi - (%r)\n", Status));
573 DEBUG ((DEBUG_INFO,
"SmmLockBoxPeiLib RestoreLockBox - Exit (%r)\n", Status));
581 CopyMem (&CommHeader->
HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof (gEfiSmmLockBoxCommunicationGuid));
582 if ((
sizeof (
UINTN) ==
sizeof (UINT32)) && (
FeaturePcdGet (PcdDxeIplSwitchToLongMode))) {
583 MessageLength =
sizeof (*LockBoxParameterRestore);
586 CommHeader->
MessageLength =
sizeof (*LockBoxParameterRestore);
589 DEBUG ((DEBUG_INFO,
"SmmLockBoxPeiLib CommBuffer - %x\n", &CommBuffer[0]));
590 if ((
sizeof (
UINTN) ==
sizeof (UINT32)) && (
FeaturePcdGet (PcdDxeIplSwitchToLongMode))) {
596 DEBUG ((DEBUG_INFO,
"SmmLockBoxPeiLib LockBoxParameterRestore - %x\n", LockBoxParameterRestore));
597 LockBoxParameterRestore->Header.Command = EFI_SMM_LOCK_BOX_COMMAND_RESTORE;
598 LockBoxParameterRestore->Header.DataLength =
sizeof (*LockBoxParameterRestore);
599 LockBoxParameterRestore->Header.ReturnStatus = (UINT64)-1;
601 CopyMem (&LockBoxParameterRestore->Guid, Guid, sizeof (*Guid));
603 ZeroMem (&LockBoxParameterRestore->Guid, sizeof (*Guid));
607 if (Length !=
NULL) {
610 LockBoxParameterRestore->Length = 0;
616 CommSize =
sizeof (CommBuffer);
617 Status = SmmCommunicationPpi->Communicate (
622 if (Status == EFI_NOT_STARTED) {
626 DEBUG ((DEBUG_INFO,
"SmmLockBoxPeiLib Communicate - (%r)\n", Status));
628 LockBoxParameterRestore->Header.ReturnStatus = (UINT64)Status;
629 if (Length !=
NULL) {
630 LockBoxParameterRestore->Length = (UINT64)*Length;
634 if (Length !=
NULL) {
635 *Length = (
UINTN)LockBoxParameterRestore->Length;
638 Status = (
EFI_STATUS)LockBoxParameterRestore->Header.ReturnStatus;
644 DEBUG ((DEBUG_INFO,
"SmmLockBoxPeiLib RestoreLockBox - Exit (%r)\n", Status));
671 UINT64 MessageLength;
682 DEBUG ((DEBUG_INFO,
"SmmLockBoxPeiLib RestoreAllLockBoxInPlace - Enter\n"));
688 &gEfiPeiSmmCommunicationPpiGuid,
691 (VOID **)&SmmCommunicationPpi
693 if (EFI_ERROR (Status)) {
694 DEBUG ((DEBUG_INFO,
"SmmLockBoxPeiLib LocatePpi - (%r)\n", Status));
696 DEBUG ((DEBUG_INFO,
"SmmLockBoxPeiLib RestoreAllLockBoxInPlace - Exit (%r)\n", Status));
704 CopyMem (&CommHeader->
HeaderGuid, &gEfiSmmLockBoxCommunicationGuid, sizeof (gEfiSmmLockBoxCommunicationGuid));
705 if ((
sizeof (
UINTN) ==
sizeof (UINT32)) && (
FeaturePcdGet (PcdDxeIplSwitchToLongMode))) {
706 MessageLength =
sizeof (*LockBoxParameterRestoreAllInPlace);
709 CommHeader->
MessageLength =
sizeof (*LockBoxParameterRestoreAllInPlace);
712 if ((
sizeof (
UINTN) ==
sizeof (UINT32)) && (
FeaturePcdGet (PcdDxeIplSwitchToLongMode))) {
718 LockBoxParameterRestoreAllInPlace->Header.Command = EFI_SMM_LOCK_BOX_COMMAND_RESTORE_ALL_IN_PLACE;
719 LockBoxParameterRestoreAllInPlace->Header.DataLength =
sizeof (*LockBoxParameterRestoreAllInPlace);
720 LockBoxParameterRestoreAllInPlace->Header.ReturnStatus = (UINT64)-1;
725 CommSize =
sizeof (CommBuffer);
726 Status = SmmCommunicationPpi->Communicate (
731 if (Status == EFI_NOT_STARTED) {
735 DEBUG ((DEBUG_INFO,
"SmmLockBoxPeiLib Communicate - (%r)\n", Status));
737 LockBoxParameterRestoreAllInPlace->Header.ReturnStatus = (UINT64)Status;
742 Status = (
EFI_STATUS)LockBoxParameterRestoreAllInPlace->Header.ReturnStatus;
748 DEBUG ((DEBUG_INFO,
"SmmLockBoxPeiLib RestoreAllLockBoxInPlace - Exit (%r)\n", Status));
CONST EFI_PEI_SERVICES **EFIAPI GetPeiServicesTablePointer(VOID)
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
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 SmmInstallConfigurationTable(IN CONST EFI_SMM_SYSTEM_TABLE2 *SystemTable, IN CONST EFI_GUID *Guid, IN VOID *Table, IN UINTN TableSize)
EFI_STATUS EFIAPI SmmFreePages(IN EFI_PHYSICAL_ADDRESS Memory, IN UINTN NumberOfPages)
EFI_STATUS EFIAPI SmmAllocatePages(IN EFI_ALLOCATE_TYPE Type, IN EFI_MEMORY_TYPE MemoryType, IN UINTN NumberOfPages, OUT EFI_PHYSICAL_ADDRESS *Memory)
#define RETURN_UNSUPPORTED
#define OFFSET_OF(TYPE, Field)
#define BASE_CR(Record, TYPE, Field)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
#define FeaturePcdGet(TokenName)
EFI_STATUS EFIAPI SmmFreePool(IN VOID *Buffer)
EFI_STATUS EFIAPI SmmAllocatePool(IN EFI_MEMORY_TYPE PoolType, IN UINTN Size, OUT VOID **Buffer)
RETURN_STATUS EFIAPI SetLockBoxAttributes(IN GUID *Guid, IN UINT64 Attributes)
RETURN_STATUS EFIAPI RestoreLockBox(IN GUID *Guid, IN VOID *Buffer OPTIONAL, IN OUT UINTN *Length OPTIONAL)
VOID * InternalSmstGetVendorTableByGuid(IN UINT64 Signature, IN EFI_SMM_SYSTEM_TABLE2 *Smst, IN EFI_GUID *VendorGuid)
LIST_ENTRY * InternalInitLinkDxe(IN LIST_ENTRY *LinkList)
RETURN_STATUS EFIAPI RestoreAllLockBoxInPlace(VOID)
SMM_LOCK_BOX_DATA * InternalFindLockBoxByGuidFromSmram(IN LIST_ENTRY *LockBoxQueue, IN EFI_GUID *Guid)
RETURN_STATUS EFIAPI UpdateLockBox(IN GUID *Guid, IN UINTN Offset, IN VOID *Buffer, IN UINTN Length)
EFI_STATUS InternalRestoreAllLockBoxInPlaceFromSmram(VOID)
LIST_ENTRY * InternalNextLinkDxe(IN LIST_ENTRY *Link)
RETURN_STATUS EFIAPI SaveLockBox(IN GUID *Guid, IN VOID *Buffer, IN UINTN Length)
EFI_STATUS InternalRestoreLockBoxFromSmram(IN GUID *Guid, IN VOID *Buffer OPTIONAL, IN OUT UINTN *Length OPTIONAL)
SMM_LOCK_BOX_CONTEXT * InternalGetSmmLockBoxContext(VOID)
UINT64 EFI_PHYSICAL_ADDRESS
EFI_STATUS EFIAPI SmmStartupThisAp(IN EFI_AP_PROCEDURE Procedure, IN UINTN CpuIndex, IN OUT VOID *ProcArguments OPTIONAL)
EFI_PHYSICAL_ADDRESS CpuStart