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