26#define EXTRA_PAGE_TABLE_PAGES 8
29 0xdea652b0, 0xd587, 0x4c54, { 0xb5, 0xb4, 0xc6, 0x82, 0xe7, 0xa0, 0xaa, 0x3d }
57 Status =
gBS->AllocatePages (
65 Buffer = (VOID *)(
UINTN)Address;
95 ((Facs->Flags & EFI_ACPI_4_0_64BIT_WAKE_SUPPORTED_F) != 0))
100 if (
sizeof (
UINTN) ==
sizeof (UINT64)) {
124 IN BOOLEAN LongModeWakingVectorSupport
127 if ((
FeaturePcdGet (PcdDxeIplSwitchToLongMode)) || (
sizeof (
UINTN) ==
sizeof (UINT64))) {
128 UINTN ExtraPageTablePages;
131 UINT8 PhysicalAddressBits;
132 UINT32 NumberOfPml4EntriesNeeded;
133 UINT32 NumberOfPdpEntriesNeeded;
135 UINTN TotalPageTableSize;
137 BOOLEAN Page1GSupport;
139 Page1GSupport =
FALSE;
142 if (RegEax >= 0x80000001) {
144 if ((RegEdx & BIT26) != 0) {
145 Page1GSupport =
TRUE;
155 PhysicalAddressBits = ((
EFI_HOB_CPU *)Hob)->SizeOfMemorySpace;
158 if (RegEax >= 0x80000008) {
160 PhysicalAddressBits = (UINT8)RegEax;
162 PhysicalAddressBits = 36;
169 ASSERT (PhysicalAddressBits <= 52);
170 if (PhysicalAddressBits > 48) {
171 PhysicalAddressBits = 48;
174 ExtraPageTablePages = 0;
175 if (!LongModeWakingVectorSupport) {
180 PhysicalAddressBits = 32;
181 ExtraPageTablePages = EXTRA_PAGE_TABLE_PAGES;
187 if (PhysicalAddressBits <= 39 ) {
188 NumberOfPml4EntriesNeeded = 1;
189 NumberOfPdpEntriesNeeded = (UINT32)
LShiftU64 (1, (PhysicalAddressBits - 30));
191 NumberOfPml4EntriesNeeded = (UINT32)
LShiftU64 (1, (PhysicalAddressBits - 39));
192 NumberOfPdpEntriesNeeded = 512;
198 if (!Page1GSupport) {
199 TotalPageTableSize = 1 + NumberOfPml4EntriesNeeded + NumberOfPml4EntriesNeeded * NumberOfPdpEntriesNeeded;
201 TotalPageTableSize = 1 + NumberOfPml4EntriesNeeded;
204 TotalPageTableSize += ExtraPageTablePages;
205 DEBUG ((DEBUG_INFO,
"AcpiS3ContextSave TotalPageTableSize - 0x%x pages\n", TotalPageTableSize));
211 ASSERT (S3NvsPageTableAddress != 0);
212 return S3NvsPageTableAddress;
238 IA32_DESCRIPTOR *Idtr;
239 IA32_IDT_GATE_DESCRIPTOR *IdtGate;
243 DEBUG ((DEBUG_INFO,
"AcpiS3ContextSave!\n"));
245 Status =
gBS->LocateProtocol (&gEfiLockBoxProtocolGuid,
NULL, &Interface);
246 if (EFI_ERROR (Status)) {
247 DEBUG ((DEBUG_INFO | DEBUG_WARN,
"ACPI S3 context can't be saved without LockBox!\n"));
252 ASSERT (AcpiS3Context !=
NULL);
262 ASSERT (AcpiS3Context->AcpiFacsTable != 0);
265 Idtr = (IA32_DESCRIPTOR *)(IdtGate + 0x100);
266 Idtr->Base = (
UINTN)IdtGate;
267 Idtr->Limit = (UINT16)(
sizeof (IA32_IDT_GATE_DESCRIPTOR) * 0x100 - 1);
271 &mAcpiS3IdtrProfileGuid,
273 (
UINTN)
sizeof (IA32_DESCRIPTOR)
288 AcpiS3Context->BootScriptStackSize =
PcdGet32 (PcdS3BootScriptStackSize);
290 ASSERT (AcpiS3Context->BootScriptStackBase != 0);
296 SetMem ((VOID *)(
UINTN)AcpiS3Context->S3DebugBufferAddress, EFI_PAGE_SIZE, 0xff);
298 DEBUG ((DEBUG_INFO,
"AcpiS3Context: AcpiFacsTable is 0x%8x\n", AcpiS3Context->AcpiFacsTable));
299 DEBUG ((DEBUG_INFO,
"AcpiS3Context: IdtrProfile is 0x%8x\n", AcpiS3Context->IdtrProfile));
300 DEBUG ((DEBUG_INFO,
"AcpiS3Context: S3NvsPageTableAddress is 0x%8x\n", AcpiS3Context->S3NvsPageTableAddress));
301 DEBUG ((DEBUG_INFO,
"AcpiS3Context: S3DebugBufferAddress is 0x%8x\n", AcpiS3Context->S3DebugBufferAddress));
302 DEBUG ((DEBUG_INFO,
"AcpiS3Context: BootScriptStackBase is 0x%8x\n", AcpiS3Context->BootScriptStackBase));
303 DEBUG ((DEBUG_INFO,
"AcpiS3Context: BootScriptStackSize is 0x%8x\n", AcpiS3Context->BootScriptStackSize));
306 &gEfiAcpiVariableGuid,
307 &AcpiS3ContextBuffer,
308 sizeof (AcpiS3ContextBuffer)
313 &gEfiAcpiS3ContextGuid,
314 (VOID *)(
UINTN)AcpiS3Context,
315 (
UINTN)
sizeof (*AcpiS3Context)
326 Status =
gBS->CloseEvent (Event);
#define EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
#define EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_VERSION
EFI_PHYSICAL_ADDRESS S3AllocatePageTablesBuffer(IN BOOLEAN LongModeWakingVectorSupport)
VOID EFIAPI AcpiS3ContextSaveOnEndOfDxe(IN EFI_EVENT Event, IN VOID *Context)
BOOLEAN IsLongModeWakingVectorSupport(IN EFI_ACPI_4_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *Facs)
VOID * AllocateMemoryBelow4G(IN EFI_MEMORY_TYPE MemoryType, IN UINTN Size)
VOID *EFIAPI GetFirstHob(IN UINT16 Type)
UINT64 EFIAPI LShiftU64(IN UINT64 Operand, IN UINTN Count)
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
RETURN_STATUS EFIAPI SetLockBoxAttributes(IN GUID *Guid, IN UINT64 Attributes)
RETURN_STATUS EFIAPI SaveLockBox(IN GUID *Guid, IN VOID *Buffer, IN UINTN Length)
#define ASSERT_EFI_ERROR(StatusParameter)
#define DEBUG(Expression)
UINT32 EFIAPI AsmCpuid(IN UINT32 Index, OUT UINT32 *RegisterEax OPTIONAL, OUT UINT32 *RegisterEbx OPTIONAL, OUT UINT32 *RegisterEcx OPTIONAL, OUT UINT32 *RegisterEdx OPTIONAL)
#define PcdGet32(TokenName)
#define PcdGetBool(TokenName)
#define FeaturePcdGet(TokenName)
UINT64 EFI_PHYSICAL_ADDRESS
#define EFI_PAGES_TO_SIZE(Pages)
#define EFI_SIZE_TO_PAGES(Size)
EFI_ACPI_COMMON_HEADER *EFIAPI EfiLocateFirstAcpiTable(IN UINT32 Signature)