]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Universal/Acpi/AcpiS3SaveDxe/AcpiS3Save.c
IntelFrameworkModulePkg: Remove PcdFrameworkCompatibilitySupport usage
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / Acpi / AcpiS3SaveDxe / AcpiS3Save.c
CommitLineData
13d4af68 1/** @file\r
2 This is an implementation of the ACPI S3 Save protocol. This is defined in\r
3 S3 boot path specification 0.9.\r
4\r
9feffce9 5Copyright (c) 2006 - 2019, Intel Corporation. All rights reserved.<BR>\r
13d4af68 6\r
c0a00b14 7SPDX-License-Identifier: BSD-2-Clause-Patent\r
13d4af68 8\r
9**/\r
10\r
11#include <PiDxe.h>\r
13d4af68 12#include <Library/BaseMemoryLib.h>\r
13#include <Library/UefiBootServicesTableLib.h>\r
13d4af68 14#include <Library/PcdLib.h>\r
15#include <Library/DebugLib.h>\r
13d4af68 16#include <Protocol/AcpiS3Save.h>\r
13d4af68 17\r
18#include "AcpiS3Save.h"\r
19\r
20/**\r
21 Hook point for AcpiVariableThunkPlatform for InstallAcpiS3Save.\r
22**/\r
23VOID\r
24InstallAcpiS3SaveThunk (\r
25 VOID\r
26 );\r
27\r
28/**\r
29 Hook point for AcpiVariableThunkPlatform for S3Ready.\r
30\r
13d4af68 31**/\r
32VOID\r
33S3ReadyThunkPlatform (\r
8ccd1d5b 34 VOID\r
13d4af68 35 );\r
36\r
37UINTN mLegacyRegionSize;\r
38\r
39EFI_ACPI_S3_SAVE_PROTOCOL mS3Save = {\r
40 LegacyGetS3MemorySize,\r
41 S3Ready,\r
42};\r
43\r
13d4af68 44/**\r
091249f4 45 Allocate memory below 4G memory address.\r
13d4af68 46\r
091249f4 47 This function allocates memory below 4G memory address.\r
13d4af68 48\r
091249f4 49 @param MemoryType Memory type of memory to allocate.\r
13d4af68 50 @param Size Size of memory to allocate.\r
0a6f4824 51\r
13d4af68 52 @return Allocated address for output.\r
53\r
54**/\r
55VOID*\r
091249f4 56AllocateMemoryBelow4G (\r
73f0127f
SZ
57 IN EFI_MEMORY_TYPE MemoryType,\r
58 IN UINTN Size\r
13d4af68 59 )\r
60{\r
61 UINTN Pages;\r
62 EFI_PHYSICAL_ADDRESS Address;\r
63 EFI_STATUS Status;\r
64 VOID* Buffer;\r
65\r
66 Pages = EFI_SIZE_TO_PAGES (Size);\r
67 Address = 0xffffffff;\r
68\r
69 Status = gBS->AllocatePages (\r
70 AllocateMaxAddress,\r
091249f4 71 MemoryType,\r
13d4af68 72 Pages,\r
73 &Address\r
74 );\r
75 ASSERT_EFI_ERROR (Status);\r
76\r
77 Buffer = (VOID *) (UINTN) Address;\r
78 ZeroMem (Buffer, Size);\r
79\r
80 return Buffer;\r
81}\r
82\r
13d4af68 83/**\r
0a6f4824 84 Gets the buffer of legacy memory below 1 MB\r
13d4af68 85 This function is to get the buffer in legacy memory below 1MB that is required during S3 resume.\r
86\r
87 @param This A pointer to the EFI_ACPI_S3_SAVE_PROTOCOL instance.\r
88 @param Size The returned size of legacy memory below 1 MB.\r
89\r
90 @retval EFI_SUCCESS Size is successfully returned.\r
91 @retval EFI_INVALID_PARAMETER The pointer Size is NULL.\r
92\r
93**/\r
94EFI_STATUS\r
95EFIAPI\r
96LegacyGetS3MemorySize (\r
97 IN EFI_ACPI_S3_SAVE_PROTOCOL *This,\r
98 OUT UINTN *Size\r
99 )\r
100{\r
101 if (Size == NULL) {\r
102 return EFI_INVALID_PARAMETER;\r
103 }\r
104\r
105 *Size = mLegacyRegionSize;\r
106 return EFI_SUCCESS;\r
107}\r
108\r
109/**\r
110 Prepares all information that is needed in the S3 resume boot path.\r
0a6f4824
LG
111\r
112 Allocate the resources or prepare informations and save in ACPI variable set for S3 resume boot path\r
113\r
13d4af68 114 @param This A pointer to the EFI_ACPI_S3_SAVE_PROTOCOL instance.\r
115 @param LegacyMemoryAddress The base address of legacy memory.\r
116\r
117 @retval EFI_NOT_FOUND Some necessary information cannot be found.\r
118 @retval EFI_SUCCESS All information was saved successfully.\r
119 @retval EFI_OUT_OF_RESOURCES Resources were insufficient to save all the information.\r
120 @retval EFI_INVALID_PARAMETER The memory range is not located below 1 MB.\r
121\r
122**/\r
123EFI_STATUS\r
124EFIAPI\r
125S3Ready (\r
126 IN EFI_ACPI_S3_SAVE_PROTOCOL *This,\r
127 IN VOID *LegacyMemoryAddress\r
128 )\r
129{\r
8ccd1d5b 130 STATIC BOOLEAN AlreadyEntered;\r
13d4af68 131\r
132 DEBUG ((EFI_D_INFO, "S3Ready!\n"));\r
133\r
134 //\r
135 // Platform may invoke AcpiS3Save->S3Save() before ExitPmAuth, because we need save S3 information there, while BDS ReadyToBoot may invoke it again.\r
136 // So if 2nd S3Save() is triggered later, we need ignore it.\r
137 //\r
138 if (AlreadyEntered) {\r
139 return EFI_SUCCESS;\r
140 }\r
141 AlreadyEntered = TRUE;\r
142\r
13d4af68 143 return EFI_SUCCESS;\r
144}\r
145\r
146/**\r
147 The Driver Entry Point.\r
0a6f4824 148\r
13d4af68 149 The function is the driver Entry point which will produce AcpiS3SaveProtocol.\r
0a6f4824 150\r
13d4af68 151 @param ImageHandle A handle for the image that is initializing this driver\r
152 @param SystemTable A pointer to the EFI system table\r
153\r
e96708de
SZ
154 @retval EFI_SUCCESS Driver initialized successfully\r
155 @retval EFI_UNSUPPORTED Do not support ACPI S3\r
13d4af68 156 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources\r
157\r
158**/\r
159EFI_STATUS\r
160EFIAPI\r
161InstallAcpiS3Save (\r
162 IN EFI_HANDLE ImageHandle,\r
163 IN EFI_SYSTEM_TABLE *SystemTable\r
164 )\r
165{\r
166 EFI_STATUS Status;\r
167\r
e96708de
SZ
168 if (!PcdGetBool (PcdAcpiS3Enable)) {\r
169 return EFI_UNSUPPORTED;\r
170 }\r
171\r
13d4af68 172 if (!FeaturePcdGet(PcdPlatformCsmSupport)) {\r
173 //\r
174 // More memory for no CSM tip, because GDT need relocation\r
175 //\r
176 mLegacyRegionSize = 0x250;\r
177 } else {\r
178 mLegacyRegionSize = 0x100;\r
179 }\r
180\r
13d4af68 181 Status = gBS->InstallProtocolInterface (\r
182 &ImageHandle,\r
183 &gEfiAcpiS3SaveProtocolGuid,\r
184 EFI_NATIVE_INTERFACE,\r
185 &mS3Save\r
186 );\r
187 ASSERT_EFI_ERROR (Status);\r
188 return Status;\r
189}\r