2 This is an implementation of the ACPI S3 Save protocol. This is defined in
3 S3 boot path specification 0.9.
5 Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
12 #include <Library/BaseMemoryLib.h>
13 #include <Library/UefiBootServicesTableLib.h>
14 #include <Library/PcdLib.h>
15 #include <Library/DebugLib.h>
16 #include <Protocol/AcpiS3Save.h>
18 #include "AcpiS3Save.h"
21 Hook point for AcpiVariableThunkPlatform for InstallAcpiS3Save.
24 InstallAcpiS3SaveThunk (
29 Hook point for AcpiVariableThunkPlatform for S3Ready.
33 S3ReadyThunkPlatform (
37 UINTN mLegacyRegionSize
;
39 EFI_ACPI_S3_SAVE_PROTOCOL mS3Save
= {
40 LegacyGetS3MemorySize
,
45 Allocate memory below 4G memory address.
47 This function allocates memory below 4G memory address.
49 @param MemoryType Memory type of memory to allocate.
50 @param Size Size of memory to allocate.
52 @return Allocated address for output.
56 AllocateMemoryBelow4G (
57 IN EFI_MEMORY_TYPE MemoryType
,
62 EFI_PHYSICAL_ADDRESS Address
;
66 Pages
= EFI_SIZE_TO_PAGES (Size
);
69 Status
= gBS
->AllocatePages (
75 ASSERT_EFI_ERROR (Status
);
77 Buffer
= (VOID
*) (UINTN
) Address
;
78 ZeroMem (Buffer
, Size
);
84 Gets the buffer of legacy memory below 1 MB
85 This function is to get the buffer in legacy memory below 1MB that is required during S3 resume.
87 @param This A pointer to the EFI_ACPI_S3_SAVE_PROTOCOL instance.
88 @param Size The returned size of legacy memory below 1 MB.
90 @retval EFI_SUCCESS Size is successfully returned.
91 @retval EFI_INVALID_PARAMETER The pointer Size is NULL.
96 LegacyGetS3MemorySize (
97 IN EFI_ACPI_S3_SAVE_PROTOCOL
*This
,
102 return EFI_INVALID_PARAMETER
;
105 *Size
= mLegacyRegionSize
;
110 Prepares all information that is needed in the S3 resume boot path.
112 Allocate the resources or prepare informations and save in ACPI variable set for S3 resume boot path
114 @param This A pointer to the EFI_ACPI_S3_SAVE_PROTOCOL instance.
115 @param LegacyMemoryAddress The base address of legacy memory.
117 @retval EFI_NOT_FOUND Some necessary information cannot be found.
118 @retval EFI_SUCCESS All information was saved successfully.
119 @retval EFI_OUT_OF_RESOURCES Resources were insufficient to save all the information.
120 @retval EFI_INVALID_PARAMETER The memory range is not located below 1 MB.
126 IN EFI_ACPI_S3_SAVE_PROTOCOL
*This
,
127 IN VOID
*LegacyMemoryAddress
130 STATIC BOOLEAN AlreadyEntered
;
132 DEBUG ((EFI_D_INFO
, "S3Ready!\n"));
135 // Platform may invoke AcpiS3Save->S3Save() before ExitPmAuth, because we need save S3 information there, while BDS ReadyToBoot may invoke it again.
136 // So if 2nd S3Save() is triggered later, we need ignore it.
138 if (AlreadyEntered
) {
141 AlreadyEntered
= TRUE
;
147 The Driver Entry Point.
149 The function is the driver Entry point which will produce AcpiS3SaveProtocol.
151 @param ImageHandle A handle for the image that is initializing this driver
152 @param SystemTable A pointer to the EFI system table
154 @retval EFI_SUCCESS Driver initialized successfully
155 @retval EFI_UNSUPPORTED Do not support ACPI S3
156 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources
162 IN EFI_HANDLE ImageHandle
,
163 IN EFI_SYSTEM_TABLE
*SystemTable
168 if (!PcdGetBool (PcdAcpiS3Enable
)) {
169 return EFI_UNSUPPORTED
;
172 if (!FeaturePcdGet(PcdPlatformCsmSupport
)) {
174 // More memory for no CSM tip, because GDT need relocation
176 mLegacyRegionSize
= 0x250;
178 mLegacyRegionSize
= 0x100;
181 Status
= gBS
->InstallProtocolInterface (
183 &gEfiAcpiS3SaveProtocolGuid
,
184 EFI_NATIVE_INTERFACE
,
187 ASSERT_EFI_ERROR (Status
);