19UINT64 mSmmFeatureControl = 0;
36 IN UINT8 BlSwSmiHandlerInput
64 DEBUG ((DEBUG_ERROR,
"SMM communication region not set to EFI_ALLOCATED\n"));
65 return EFI_INVALID_PARAMETER;
69 DEBUG ((DEBUG_ERROR,
"SMM communication buffer (0x%x) is too small.\n", (
UINTN)PldSmmInfo + PldSmmInfo->Header.
Header.
HobLength));
70 return EFI_BUFFER_TOO_SMALL;
73 CopyGuid (&PldSmmInfo->Header.
Name, &gS3CommunicationGuid);
74 PldSmmInfo->Header.
Header.
HobType = EFI_HOB_TYPE_GUID_EXTENSION;
75 PldSmmInfo->S3Info.SwSmiTriggerValue = BlSwSmiHandlerInput;
80 Status =
gBS->LocateProtocol (&gEfiMpServiceProtocolGuid,
NULL, (VOID **)&MpService);
81 if (EFI_ERROR (Status)) {
86 SmmBaseInfo = &PldSmmInfo->S3Info.SmmBase[0];
88 Status = MpService->GetProcessorInfo (MpService, Index, &ProcessorInfo);
89 if (EFI_ERROR (Status)) {
95 DEBUG ((DEBUG_INFO,
"CPU%d ID:%02X Base: %08X\n", Index, SmmBaseInfo->ApicId, SmmBaseInfo->SmmBase));
118 for (Index = 0; Index < mSmmRegisterHob->Count; Index++) {
119 if (mSmmRegisterHob->Registers[Index].Id == Id) {
120 return &mSmmRegisterHob->Registers[Index];
138 DEBUG ((DEBUG_ERROR,
"LockSmiGlobalEn .....\n"));
141 if (SmiLockReg ==
NULL) {
142 DEBUG ((DEBUG_ERROR,
"SMI global enable lock reg not found.\n"));
149 if ((SmiLockReg->Address.AccessSize == EFI_ACPI_3_0_DWORD) &&
150 (SmiLockReg->Address.Address != 0) &&
151 (SmiLockReg->Address.RegisterBitWidth == 1) &&
152 (SmiLockReg->Address.AddressSpaceId == EFI_ACPI_3_0_SYSTEM_MEMORY) &&
153 (SmiLockReg->Value == 1))
155 DEBUG ((DEBUG_ERROR,
"LockSmiGlobalEn ....is locked\n"));
157 MmioOr32 ((UINT32)SmiLockReg->Address.Address, 1 << SmiLockReg->Address.RegisterBitOffset);
159 DEBUG ((DEBUG_ERROR,
"Unexpected SMM SMI lock register, need enhancement here.\n"));
173 if (mSmmFeatureControl != 0) {
177 mSmmFeatureControl =
AsmReadMsr64 (MSR_SMM_FEATURE_CONTROL);
178 if ((mSmmFeatureControl & 0x5) != 0x5) {
182 AsmWriteMsr64 (MSR_SMM_FEATURE_CONTROL, mSmmFeatureControl | 0x5);
185 mSmmFeatureControl =
AsmReadMsr64 (MSR_SMM_FEATURE_CONTROL);
196 IN VOID *ProcedureArgument
199 if (ProcedureArgument !=
NULL) {
233 DEBUG ((DEBUG_ERROR,
"Two SMM regions are not continous.\n"));
240 if ((SmmBase == 0) || (SmmSize < SIZE_4KB)) {
241 DEBUG ((DEBUG_ERROR,
"Invalid SMM range.\n"));
249 if ((SmmSize !=
GetPowerOfTwo32 (SmmSize)) || ((SmmBase & ~(SmmSize - 1)) != SmmBase)) {
250 DEBUG ((DEBUG_ERROR,
" Invalid SMM range.\n"));
257 Arguments.Base = (SmmSize | MTRR_CACHE_WRITE_BACK);
258 Arguments.Mask = (~(SmmSize - 1) & EFI_MSR_SMRR_MASK);
263 Arguments.Mask |= BIT11;
272 if (EFI_ERROR (Status)) {
273 DEBUG ((DEBUG_ERROR,
"Programming SMRR on AP# %d status: %r\n", Index, Status));
297 IN OUT VOID *CommBuffer,
362 if (GuidHob !=
NULL) {
363 SmmHob = (VOID *)(GET_GUID_HOB_DATA (GuidHob));
364 CopyMem (&mPldS3Hob, SmmHob, GET_GUID_HOB_DATA_SIZE (GuidHob));
366 return EFI_NOT_FOUND;
369 if (mPldS3Hob.PldAcpiS3Enable) {
378 if (GuidHob !=
NULL) {
379 SmmHob = (VOID *)(GET_GUID_HOB_DATA (GuidHob));
380 mSmramHob =
AllocatePool (GET_GUID_HOB_DATA_SIZE (GuidHob));
381 if (mSmramHob ==
NULL) {
382 return EFI_OUT_OF_RESOURCES;
385 CopyMem (mSmramHob, SmmHob, GET_GUID_HOB_DATA_SIZE (GuidHob));
387 return EFI_NOT_FOUND;
394 if (GuidHob !=
NULL) {
395 SmmHob = (VOID *)(GET_GUID_HOB_DATA (GuidHob));
396 mSmmRegisterHob =
AllocatePool (GET_GUID_HOB_DATA_SIZE (GuidHob));
397 if (mSmmRegisterHob ==
NULL) {
398 return EFI_OUT_OF_RESOURCES;
401 CopyMem (mSmmRegisterHob, SmmHob, GET_GUID_HOB_DATA_SIZE (GuidHob));
403 return EFI_NOT_FOUND;
409 Status =
gSmst->SmmLocateProtocol (&gEfiSmmSwDispatch2ProtocolGuid,
NULL, (VOID **)&SwDispatch);
410 if (EFI_ERROR (Status)) {
414 SwContext.SwSmiInputValue = (
UINTN)-1;
415 Status = SwDispatch->Register (SwDispatch,
BlSwSmiHandler, &SwContext, &SwHandle);
416 if (EFI_ERROR (Status)) {
417 DEBUG ((DEBUG_ERROR,
"Registering S3 smi handler failed: %r\n", Status));
424 Status =
gSmst->SmmRegisterProtocolNotify (
425 &gEfiSmmReadyToLockProtocolGuid,
VOID *EFIAPI GetFirstGuidHob(IN CONST EFI_GUID *Guid)
UINT32 EFIAPI GetPowerOfTwo32(IN UINT32 Operand)
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
VOID SmmFeatureLockOnS3(VOID)
EFI_STATUS SaveSmmInfoForS3(IN UINT8 BlSwSmiHandlerInput)
EFI_STATUS EFIAPI BlSupportSmmReadyToLockCallback(IN CONST EFI_GUID *Protocol, IN VOID *Interface, IN EFI_HANDLE Handle)
EFI_STATUS EFIAPI BlSwSmiHandler(IN EFI_HANDLE DispatchHandle, IN CONST VOID *Context, IN OUT VOID *CommBuffer, IN OUT UINTN *CommBufferSize)
VOID EFIAPI SetSmrr(IN VOID *ProcedureArgument)
VOID LockSmiGlobalEn(VOID)
EFI_STATUS EFIAPI BlSupportSmm(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
PLD_GENERIC_REGISTER * GetRegisterById(UINT64 Id)
UINT64 EFIAPI AsmReadMsr64(IN UINT32 Index)
UINT64 EFIAPI AsmWriteMsr64(IN UINT32 Index, IN UINT64 Value)
UINT32 EFIAPI MmioOr32(IN UINTN Address, IN UINT32 OrData)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
#define MSR_IA32_SMRR_PHYSBASE
#define MSR_IA32_SMRR_PHYSMASK
#define SMRAM_SAVE_STATE_MAP_OFFSET
EFI_SMM_SYSTEM_TABLE2 * gSmst
VOID *EFIAPI AllocatePool(IN UINTN AllocationSize)
EFI_GUID gSmmRegisterInfoGuid
EFI_SMM_STARTUP_THIS_AP SmmStartupThisAp
UINTN CurrentlyExecutingCpu
EFI_HOB_GENERIC_HEADER Header
EFI_PHYSICAL_ADDRESS PhysicalStart
UINT32 NumberOfSmmReservedRegions
EFI_SMRAM_DESCRIPTOR Descriptor[1]