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 - 2016, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions
9 of the BSD License which accompanies this distribution. The
10 full text of the license may be found at
11 http://opensource.org/licenses/bsd-license.php
13 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
14 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include <Library/BaseMemoryLib.h>
20 #include <Library/UefiBootServicesTableLib.h>
21 #include <Library/PcdLib.h>
22 #include <Library/DebugLib.h>
23 #include <Protocol/AcpiS3Save.h>
25 #include "AcpiS3Save.h"
28 Hook point for AcpiVariableThunkPlatform for InstallAcpiS3Save.
31 InstallAcpiS3SaveThunk (
36 Hook point for AcpiVariableThunkPlatform for S3Ready.
40 S3ReadyThunkPlatform (
44 UINTN mLegacyRegionSize
;
46 EFI_ACPI_S3_SAVE_PROTOCOL mS3Save
= {
47 LegacyGetS3MemorySize
,
52 Allocate memory below 4G memory address.
54 This function allocates memory below 4G memory address.
56 @param MemoryType Memory type of memory to allocate.
57 @param Size Size of memory to allocate.
59 @return Allocated address for output.
63 AllocateMemoryBelow4G (
64 IN EFI_MEMORY_TYPE MemoryType
,
69 EFI_PHYSICAL_ADDRESS Address
;
73 Pages
= EFI_SIZE_TO_PAGES (Size
);
76 Status
= gBS
->AllocatePages (
82 ASSERT_EFI_ERROR (Status
);
84 Buffer
= (VOID
*) (UINTN
) Address
;
85 ZeroMem (Buffer
, Size
);
91 Gets the buffer of legacy memory below 1 MB
92 This function is to get the buffer in legacy memory below 1MB that is required during S3 resume.
94 @param This A pointer to the EFI_ACPI_S3_SAVE_PROTOCOL instance.
95 @param Size The returned size of legacy memory below 1 MB.
97 @retval EFI_SUCCESS Size is successfully returned.
98 @retval EFI_INVALID_PARAMETER The pointer Size is NULL.
103 LegacyGetS3MemorySize (
104 IN EFI_ACPI_S3_SAVE_PROTOCOL
*This
,
109 return EFI_INVALID_PARAMETER
;
112 *Size
= mLegacyRegionSize
;
117 Prepares all information that is needed in the S3 resume boot path.
119 Allocate the resources or prepare informations and save in ACPI variable set for S3 resume boot path
121 @param This A pointer to the EFI_ACPI_S3_SAVE_PROTOCOL instance.
122 @param LegacyMemoryAddress The base address of legacy memory.
124 @retval EFI_NOT_FOUND Some necessary information cannot be found.
125 @retval EFI_SUCCESS All information was saved successfully.
126 @retval EFI_OUT_OF_RESOURCES Resources were insufficient to save all the information.
127 @retval EFI_INVALID_PARAMETER The memory range is not located below 1 MB.
133 IN EFI_ACPI_S3_SAVE_PROTOCOL
*This
,
134 IN VOID
*LegacyMemoryAddress
137 STATIC BOOLEAN AlreadyEntered
;
139 DEBUG ((EFI_D_INFO
, "S3Ready!\n"));
142 // Platform may invoke AcpiS3Save->S3Save() before ExitPmAuth, because we need save S3 information there, while BDS ReadyToBoot may invoke it again.
143 // So if 2nd S3Save() is triggered later, we need ignore it.
145 if (AlreadyEntered
) {
148 AlreadyEntered
= TRUE
;
150 if (FeaturePcdGet(PcdFrameworkCompatibilitySupport
)) {
151 S3ReadyThunkPlatform ();
158 The Driver Entry Point.
160 The function is the driver Entry point which will produce AcpiS3SaveProtocol.
162 @param ImageHandle A handle for the image that is initializing this driver
163 @param SystemTable A pointer to the EFI system table
165 @retval EFI_SUCCESS Driver initialized successfully
166 @retval EFI_UNSUPPORTED Do not support ACPI S3
167 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources
173 IN EFI_HANDLE ImageHandle
,
174 IN EFI_SYSTEM_TABLE
*SystemTable
179 if (!PcdGetBool (PcdAcpiS3Enable
)) {
180 return EFI_UNSUPPORTED
;
183 if (!FeaturePcdGet(PcdPlatformCsmSupport
)) {
185 // More memory for no CSM tip, because GDT need relocation
187 mLegacyRegionSize
= 0x250;
189 mLegacyRegionSize
= 0x100;
192 if (FeaturePcdGet(PcdFrameworkCompatibilitySupport
)) {
193 InstallAcpiS3SaveThunk ();
196 Status
= gBS
->InstallProtocolInterface (
198 &gEfiAcpiS3SaveProtocolGuid
,
199 EFI_NATIVE_INTERFACE
,
202 ASSERT_EFI_ERROR (Status
);