/** @file
This is an implementation of the ACPI S3 Save protocol. This is defined in
S3 boot path specification 0.9.
Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions
of the BSD License which accompanies this distribution. The
full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
**/
#include <PiDxe.h>
#include <Library/BaseMemoryLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
#include <Library/LockBoxLib.h>
#include <Library/DebugLib.h>
#include <Guid/AcpiVariableCompatibility.h>
#include <Guid/AcpiS3Context.h>
#include <Protocol/AcpiS3Save.h>
#include <IndustryStandard/Acpi.h>
#include "AcpiS3Save.h"
/**
Hook point for AcpiVariableThunkPlatform for InstallAcpiS3Save.
**/
);
/**
Hook point for AcpiVariableThunkPlatform for S3Ready.
@param AcpiS3Context ACPI s3 context
**/
);
};
0xdea652b0, 0xd587, 0x4c54, 0xb5, 0xb4, 0xc6, 0x82, 0xe7, 0xa0, 0xaa, 0x3d
};
/**
Allocate EfiACPIMemoryNVS below 4G memory address.
This function allocates EfiACPIMemoryNVS below 4G memory address.
@param Size Size of memory to allocate.
@return Allocated address for output.
**/
VOID*
)
{
Address = 0xffffffff;
);
return Buffer;
}
/**
To find Facs in Acpi tables.
To find Firmware ACPI control strutcure in Acpi Tables since the S3 waking vector is stored
in the table.
@param AcpiTableGuid The guid used to find ACPI table in UEFI ConfigurationTable.
@return Facs table pointer.
**/
)
{
//
// found ACPI table RSD_PTR from system table
//
//
// A match was found.
//
break;
}
}
return NULL;
}
return NULL;
}
for (Index = sizeof (EFI_ACPI_DESCRIPTION_HEADER); Index < Rsdt->Length; Index = Index + sizeof (UINT32)) {
break;
}
}
if (Fadt == NULL || Fadt->Header.Signature != EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {
return NULL;
}
return Facs;
}
/**
To find Facs in Acpi tables.
To find Firmware ACPI control strutcure in Acpi Tables since the S3 waking vector is stored
in the table.
@return Facs table pointer.
**/
)
{
return Facs;
}
return FindAcpiFacsTableByAcpiGuid (&gEfiAcpi10TableGuid);
}
/**
Allocates and fills in the Page Directory and Page Table Entries to
establish a 1:1 Virtual to Physical mapping.
If BootScriptExector driver will run in 64-bit mode, this function will establish the 1:1
virtual to physical mapping page table.
If BootScriptExector driver will not run in 64-bit mode, this function will do nothing.
@return the 1:1 Virtual to Physical identity mapping page table base address.
**/
)
{
if (FeaturePcdGet (PcdDxeIplSwitchToLongMode)) {
if (PcdGetBool(PcdUse1GPageTable)) {
if (RegEax >= 0x80000001) {
}
}
}
//
// Get physical address bits supported.
//
} else {
if (RegEax >= 0x80000008) {
} else {
PhysicalAddressBits = 36;
}
}
//
// IA-32e paging translates 48-bit linear addresses to 52-bit physical addresses.
//
if (PhysicalAddressBits > 48) {
PhysicalAddressBits = 48;
}
//
// Calculate the table entries needed.
//
if (PhysicalAddressBits <= 39 ) {
} else {
NumberOfPdpEntriesNeeded = 512;
}
//
// We need calculate whole page size then allocate once, because S3 restore page table does not know each page in Nvs.
//
if (!Page1GSupport) {
TotalPageTableSize = (UINTN)(1 + NumberOfPml4EntriesNeeded + NumberOfPml4EntriesNeeded * NumberOfPdpEntriesNeeded);
} else {
}
//
// By architecture only one PageMapLevel4 exists - so lets allocate storgage for it.
//
S3NvsPageTableAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateAcpiNvsMemoryBelow4G (EFI_PAGES_TO_SIZE(TotalPageTableSize));
ASSERT (S3NvsPageTableAddress != 0);
PageAddress = 0;
for (IndexOfPml4Entries = 0; IndexOfPml4Entries < NumberOfPml4EntriesNeeded; IndexOfPml4Entries++, PageMapLevel4Entry++) {
//
// Each PML4 entry points to a page of Page Directory Pointer entires.
// So lets allocate space for them and fill them in in the IndexOfPdpEntries loop.
//
//
// Make a PML4 Entry
//
if (Page1GSupport) {
for (IndexOfPageDirectoryEntries = 0; IndexOfPageDirectoryEntries < 512; IndexOfPageDirectoryEntries++, PageDirectory1GEntry++, PageAddress += SIZE_1GB) {
//
// Fill in the Page Directory entries
//
}
} else {
for (IndexOfPdpEntries = 0; IndexOfPdpEntries < NumberOfPdpEntriesNeeded; IndexOfPdpEntries++, PageDirectoryPointerEntry++) {
//
// Each Directory Pointer entries points to a page of Page Directory entires.
// So allocate space for them and fill them in in the IndexOfPageDirectoryEntries loop.
//
//
// Fill in a Page Directory Pointer Entries
//
for (IndexOfPageDirectoryEntries = 0; IndexOfPageDirectoryEntries < 512; IndexOfPageDirectoryEntries++, PageDirectoryEntry++, PageAddress += SIZE_2MB) {
//
// Fill in the Page Directory entries
//
}
}
}
}
} else {
//
// If DXE is running 32-bit mode, no need to establish page table.
//
return (EFI_PHYSICAL_ADDRESS) 0;
}
}
/**
Gets the buffer of legacy memory below 1 MB
This function is to get the buffer in legacy memory below 1MB that is required during S3 resume.
@param This A pointer to the EFI_ACPI_S3_SAVE_PROTOCOL instance.
@param Size The returned size of legacy memory below 1 MB.
@retval EFI_SUCCESS Size is successfully returned.
@retval EFI_INVALID_PARAMETER The pointer Size is NULL.
**/
)
{
return EFI_INVALID_PARAMETER;
}
return EFI_SUCCESS;
}
/**
Prepares all information that is needed in the S3 resume boot path.
Allocate the resources or prepare informations and save in ACPI variable set for S3 resume boot path
@param This A pointer to the EFI_ACPI_S3_SAVE_PROTOCOL instance.
@param LegacyMemoryAddress The base address of legacy memory.
@retval EFI_NOT_FOUND Some necessary information cannot be found.
@retval EFI_SUCCESS All information was saved successfully.
@retval EFI_OUT_OF_RESOURCES Resources were insufficient to save all the information.
@retval EFI_INVALID_PARAMETER The memory range is not located below 1 MB.
**/
S3Ready (
)
{
//
// Platform may invoke AcpiS3Save->S3Save() before ExitPmAuth, because we need save S3 information there, while BDS ReadyToBoot may invoke it again.
// So if 2nd S3Save() is triggered later, we need ignore it.
//
if (AlreadyEntered) {
return EFI_SUCCESS;
}
//
// Get ACPI Table because we will save its position to variable
//
IdtGate = AllocateAcpiNvsMemoryBelow4G (sizeof(IA32_IDT_GATE_DESCRIPTOR) * 0x100 + sizeof(IA32_DESCRIPTOR));
Status = SaveLockBox (
(UINTN)sizeof(IA32_DESCRIPTOR)
);
//
// Allocate page table
//
//
// Allocate stack
//
AcpiS3Context->BootScriptStackBase = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateAcpiNvsMemoryBelow4G (PcdGet32 (PcdS3BootScriptStackSize));
//
// Allocate a code buffer < 4G for S3 debug to load external code
//
AcpiS3Context->S3DebugBufferAddress = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateAcpiNvsMemoryBelow4G (EFI_PAGE_SIZE);
DEBUG((EFI_D_INFO, "AcpiS3Context: S3NvsPageTableAddress is 0x%8x\n", AcpiS3Context->S3NvsPageTableAddress));
DEBUG((EFI_D_INFO, "AcpiS3Context: S3DebugBufferAddress is 0x%8x\n", AcpiS3Context->S3DebugBufferAddress));
Status = SaveLockBox (
sizeof(AcpiS3ContextBuffer)
);
Status = SaveLockBox (
(UINTN)sizeof(*AcpiS3Context)
);
}
return EFI_SUCCESS;
}
/**
The Driver Entry Point.
The function is the driver Entry point which will produce AcpiS3SaveProtocol.
@param ImageHandle A handle for the image that is initializing this driver
@param SystemTable A pointer to the EFI system table
@retval EFI_SUCCESS: Driver initialized successfully
@retval EFI_LOAD_ERROR: Failed to Initialize or has been loaded
@retval EFI_OUT_OF_RESOURCES Could not allocate needed resources
**/
)
{
if (!FeaturePcdGet(PcdPlatformCsmSupport)) {
//
// More memory for no CSM tip, because GDT need relocation
//
mLegacyRegionSize = 0x250;
} else {
mLegacyRegionSize = 0x100;
}
}
);
return Status;
}