2 This is an implementation of the AcpiVariable platform field for ECP platform.
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
11 EFI_PHYSICAL_ADDRESS AcpiReservedMemoryBase; <<===
12 UINT32 AcpiReservedMemorySize; <<===
13 EFI_PHYSICAL_ADDRESS S3ReservedLowMemoryBase;
14 EFI_PHYSICAL_ADDRESS AcpiBootScriptTable;
15 EFI_PHYSICAL_ADDRESS RuntimeScriptTableBase;
16 EFI_PHYSICAL_ADDRESS AcpiFacsTable;
17 UINT64 SystemMemoryLength; <<===
18 ACPI_CPU_DATA_COMPATIBILITY AcpiCpuData;
19 EFI_PHYSICAL_ADDRESS VideoOpromAddress;
20 UINT32 VideoOpromSize;
21 EFI_PHYSICAL_ADDRESS S3DebugBufferAddress;
22 EFI_PHYSICAL_ADDRESS S3ResumeNvsEntryPoint;
23 } ACPI_VARIABLE_SET_COMPATIBILITY;
27 #include <FrameworkDxe.h>
28 #include <Library/BaseLib.h>
29 #include <Library/BaseMemoryLib.h>
30 #include <Library/UefiBootServicesTableLib.h>
31 #include <Library/UefiRuntimeServicesTableLib.h>
32 #include <Library/HobLib.h>
33 #include <Library/PcdLib.h>
34 #include <Library/DebugLib.h>
35 #include <Library/UefiLib.h>
36 #include <Protocol/FrameworkMpService.h>
37 #include <Protocol/VariableLock.h>
38 #include <Guid/AcpiVariableCompatibility.h>
40 GLOBAL_REMOVE_IF_UNREFERENCED
41 ACPI_VARIABLE_SET_COMPATIBILITY
*mAcpiVariableSetCompatibility
= NULL
;
44 Allocate memory below 4G memory address.
46 This function allocates memory below 4G memory address.
48 @param MemoryType Memory type of memory to allocate.
49 @param Size Size of memory to allocate.
51 @return Allocated address for output.
55 AllocateMemoryBelow4G (
56 IN EFI_MEMORY_TYPE MemoryType
,
61 Hook point for AcpiVariableThunkPlatform for S3Ready.
65 S3ReadyThunkPlatform (
69 EFI_PHYSICAL_ADDRESS AcpiMemoryBase
;
70 UINT32 AcpiMemorySize
;
71 EFI_PEI_HOB_POINTERS Hob
;
74 DEBUG ((EFI_D_INFO
, "S3ReadyThunkPlatform\n"));
76 if (mAcpiVariableSetCompatibility
== NULL
) {
81 // Allocate ACPI reserved memory under 4G
83 AcpiMemoryBase
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)AllocateMemoryBelow4G (EfiReservedMemoryType
, PcdGet32 (PcdS3AcpiReservedMemorySize
));
84 ASSERT (AcpiMemoryBase
!= 0);
85 AcpiMemorySize
= PcdGet32 (PcdS3AcpiReservedMemorySize
);
88 // Calculate the system memory length by memory hobs
90 MemoryLength
= 0x100000;
91 Hob
.Raw
= GetFirstHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
);
92 ASSERT (Hob
.Raw
!= NULL
);
93 while ((Hob
.Raw
!= NULL
) && (!END_OF_HOB_LIST (Hob
))) {
94 if (Hob
.ResourceDescriptor
->ResourceType
== EFI_RESOURCE_SYSTEM_MEMORY
) {
96 // Skip the memory region below 1MB
98 if (Hob
.ResourceDescriptor
->PhysicalStart
>= 0x100000) {
99 MemoryLength
+= Hob
.ResourceDescriptor
->ResourceLength
;
102 Hob
.Raw
= GET_NEXT_HOB (Hob
);
103 Hob
.Raw
= GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR
, Hob
.Raw
);
106 mAcpiVariableSetCompatibility
->AcpiReservedMemoryBase
= AcpiMemoryBase
;
107 mAcpiVariableSetCompatibility
->AcpiReservedMemorySize
= AcpiMemorySize
;
108 mAcpiVariableSetCompatibility
->SystemMemoryLength
= MemoryLength
;
110 DEBUG((EFI_D_INFO
, "AcpiVariableThunkPlatform: AcpiMemoryBase is 0x%8x\n", mAcpiVariableSetCompatibility
->AcpiReservedMemoryBase
));
111 DEBUG((EFI_D_INFO
, "AcpiVariableThunkPlatform: AcpiMemorySize is 0x%8x\n", mAcpiVariableSetCompatibility
->AcpiReservedMemorySize
));
112 DEBUG((EFI_D_INFO
, "AcpiVariableThunkPlatform: SystemMemoryLength is 0x%8x\n", mAcpiVariableSetCompatibility
->SystemMemoryLength
));
118 Register callback function upon VariableLockProtocol
119 to lock ACPI_GLOBAL_VARIABLE variable to avoid malicious code to update it.
121 @param[in] Event Event whose notification function is being invoked.
122 @param[in] Context Pointer to the notification function's context.
126 VariableLockAcpiGlobalVariable (
132 EDKII_VARIABLE_LOCK_PROTOCOL
*VariableLock
;
134 // Mark ACPI_GLOBAL_VARIABLE variable to read-only if the Variable Lock protocol exists
136 Status
= gBS
->LocateProtocol (&gEdkiiVariableLockProtocolGuid
, NULL
, (VOID
**) &VariableLock
);
137 if (!EFI_ERROR (Status
)) {
138 Status
= VariableLock
->RequestToLock (VariableLock
, ACPI_GLOBAL_VARIABLE
, &gEfiAcpiVariableCompatiblityGuid
);
139 ASSERT_EFI_ERROR (Status
);
144 Hook point for AcpiVariableThunkPlatform for InstallAcpiS3Save.
147 InstallAcpiS3SaveThunk (
152 FRAMEWORK_EFI_MP_SERVICES_PROTOCOL
*FrameworkMpService
;
156 Status
= gBS
->LocateProtocol (
157 &gFrameworkEfiMpServiceProtocolGuid
,
159 (VOID
**) &FrameworkMpService
161 if (!EFI_ERROR (Status
)) {
163 // On ECP platform, if framework CPU drivers are in use, The compatible version of ACPI variable set
164 // should be produced by CPU driver.
166 VarSize
= sizeof (mAcpiVariableSetCompatibility
);
167 Status
= gRT
->GetVariable (
168 ACPI_GLOBAL_VARIABLE
,
169 &gEfiAcpiVariableCompatiblityGuid
,
172 &mAcpiVariableSetCompatibility
174 if (EFI_ERROR (Status
) || (VarSize
!= sizeof (mAcpiVariableSetCompatibility
))) {
175 DEBUG ((EFI_D_ERROR
, "FATAL ERROR: AcpiVariableSetCompatibility was not saved by CPU driver correctly. OS S3 may fail!\n"));
176 mAcpiVariableSetCompatibility
= NULL
;
180 // Allocate/initialize the compatible version of Acpi Variable Set since Framework chipset/platform
181 // driver need this variable. ACPI_GLOBAL_VARIABLE variable is not used in runtime phase,
182 // so RT attribute is not needed for it.
184 mAcpiVariableSetCompatibility
= AllocateMemoryBelow4G (EfiACPIMemoryNVS
, sizeof(ACPI_VARIABLE_SET_COMPATIBILITY
));
185 Status
= gRT
->SetVariable (
186 ACPI_GLOBAL_VARIABLE
,
187 &gEfiAcpiVariableCompatiblityGuid
,
188 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_NON_VOLATILE
,
189 sizeof(mAcpiVariableSetCompatibility
),
190 &mAcpiVariableSetCompatibility
192 if (!EFI_ERROR (Status
)) {
194 // Register callback function upon VariableLockProtocol
195 // to lock ACPI_GLOBAL_VARIABLE variable to avoid malicious code to update it.
197 EfiCreateProtocolNotifyEvent (
198 &gEdkiiVariableLockProtocolGuid
,
200 VariableLockAcpiGlobalVariable
,
205 DEBUG ((EFI_D_ERROR
, "FATAL ERROR: AcpiVariableSetCompatibility cannot be saved: %r. OS S3 may fail!\n", Status
));
207 (EFI_PHYSICAL_ADDRESS
) (UINTN
) mAcpiVariableSetCompatibility
,
208 EFI_SIZE_TO_PAGES (sizeof (ACPI_VARIABLE_SET_COMPATIBILITY
))
210 mAcpiVariableSetCompatibility
= NULL
;
214 DEBUG((EFI_D_INFO
, "AcpiVariableSetCompatibility is 0x%8x\n", mAcpiVariableSetCompatibility
));