]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Universal/Acpi/AcpiS3SaveDxe/AcpiS3Save.c
IntelFrameworkModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / Acpi / AcpiS3SaveDxe / AcpiS3Save.c
1 /** @file
2 This is an implementation of the ACPI S3 Save protocol. This is defined in
3 S3 boot path specification 0.9.
4
5 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
6
7 SPDX-License-Identifier: BSD-2-Clause-Patent
8
9 **/
10
11 #include <PiDxe.h>
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>
17
18 #include "AcpiS3Save.h"
19
20 /**
21 Hook point for AcpiVariableThunkPlatform for InstallAcpiS3Save.
22 **/
23 VOID
24 InstallAcpiS3SaveThunk (
25 VOID
26 );
27
28 /**
29 Hook point for AcpiVariableThunkPlatform for S3Ready.
30
31 **/
32 VOID
33 S3ReadyThunkPlatform (
34 VOID
35 );
36
37 UINTN mLegacyRegionSize;
38
39 EFI_ACPI_S3_SAVE_PROTOCOL mS3Save = {
40 LegacyGetS3MemorySize,
41 S3Ready,
42 };
43
44 /**
45 Allocate memory below 4G memory address.
46
47 This function allocates memory below 4G memory address.
48
49 @param MemoryType Memory type of memory to allocate.
50 @param Size Size of memory to allocate.
51
52 @return Allocated address for output.
53
54 **/
55 VOID*
56 AllocateMemoryBelow4G (
57 IN EFI_MEMORY_TYPE MemoryType,
58 IN UINTN Size
59 )
60 {
61 UINTN Pages;
62 EFI_PHYSICAL_ADDRESS Address;
63 EFI_STATUS Status;
64 VOID* Buffer;
65
66 Pages = EFI_SIZE_TO_PAGES (Size);
67 Address = 0xffffffff;
68
69 Status = gBS->AllocatePages (
70 AllocateMaxAddress,
71 MemoryType,
72 Pages,
73 &Address
74 );
75 ASSERT_EFI_ERROR (Status);
76
77 Buffer = (VOID *) (UINTN) Address;
78 ZeroMem (Buffer, Size);
79
80 return Buffer;
81 }
82
83 /**
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.
86
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.
89
90 @retval EFI_SUCCESS Size is successfully returned.
91 @retval EFI_INVALID_PARAMETER The pointer Size is NULL.
92
93 **/
94 EFI_STATUS
95 EFIAPI
96 LegacyGetS3MemorySize (
97 IN EFI_ACPI_S3_SAVE_PROTOCOL *This,
98 OUT UINTN *Size
99 )
100 {
101 if (Size == NULL) {
102 return EFI_INVALID_PARAMETER;
103 }
104
105 *Size = mLegacyRegionSize;
106 return EFI_SUCCESS;
107 }
108
109 /**
110 Prepares all information that is needed in the S3 resume boot path.
111
112 Allocate the resources or prepare informations and save in ACPI variable set for S3 resume boot path
113
114 @param This A pointer to the EFI_ACPI_S3_SAVE_PROTOCOL instance.
115 @param LegacyMemoryAddress The base address of legacy memory.
116
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.
121
122 **/
123 EFI_STATUS
124 EFIAPI
125 S3Ready (
126 IN EFI_ACPI_S3_SAVE_PROTOCOL *This,
127 IN VOID *LegacyMemoryAddress
128 )
129 {
130 STATIC BOOLEAN AlreadyEntered;
131
132 DEBUG ((EFI_D_INFO, "S3Ready!\n"));
133
134 //
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.
137 //
138 if (AlreadyEntered) {
139 return EFI_SUCCESS;
140 }
141 AlreadyEntered = TRUE;
142
143 if (FeaturePcdGet(PcdFrameworkCompatibilitySupport)) {
144 S3ReadyThunkPlatform ();
145 }
146
147 return EFI_SUCCESS;
148 }
149
150 /**
151 The Driver Entry Point.
152
153 The function is the driver Entry point which will produce AcpiS3SaveProtocol.
154
155 @param ImageHandle A handle for the image that is initializing this driver
156 @param SystemTable A pointer to the EFI system table
157
158 @retval EFI_SUCCESS Driver initialized successfully
159 @retval EFI_UNSUPPORTED Do not support ACPI S3
160 @retval EFI_OUT_OF_RESOURCES Could not allocate needed resources
161
162 **/
163 EFI_STATUS
164 EFIAPI
165 InstallAcpiS3Save (
166 IN EFI_HANDLE ImageHandle,
167 IN EFI_SYSTEM_TABLE *SystemTable
168 )
169 {
170 EFI_STATUS Status;
171
172 if (!PcdGetBool (PcdAcpiS3Enable)) {
173 return EFI_UNSUPPORTED;
174 }
175
176 if (!FeaturePcdGet(PcdPlatformCsmSupport)) {
177 //
178 // More memory for no CSM tip, because GDT need relocation
179 //
180 mLegacyRegionSize = 0x250;
181 } else {
182 mLegacyRegionSize = 0x100;
183 }
184
185 if (FeaturePcdGet(PcdFrameworkCompatibilitySupport)) {
186 InstallAcpiS3SaveThunk ();
187 }
188
189 Status = gBS->InstallProtocolInterface (
190 &ImageHandle,
191 &gEfiAcpiS3SaveProtocolGuid,
192 EFI_NATIVE_INTERFACE,
193 &mS3Save
194 );
195 ASSERT_EFI_ERROR (Status);
196 return Status;
197 }