--- /dev/null
+/** @file\r
+ This is an implementation of the AcpiVariable platform field for ECP platform.\r
+\r
+Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
+\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions\r
+of the BSD License which accompanies this distribution. The\r
+full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+==\r
+\r
+typedef struct {\r
+ EFI_PHYSICAL_ADDRESS AcpiReservedMemoryBase; <<===\r
+ UINT32 AcpiReservedMemorySize; <<===\r
+ EFI_PHYSICAL_ADDRESS S3ReservedLowMemoryBase;\r
+ EFI_PHYSICAL_ADDRESS AcpiBootScriptTable;\r
+ EFI_PHYSICAL_ADDRESS RuntimeScriptTableBase;\r
+ EFI_PHYSICAL_ADDRESS AcpiFacsTable;\r
+ UINT64 SystemMemoryLength; <<===\r
+ ACPI_CPU_DATA_COMPATIBILITY AcpiCpuData;\r
+ EFI_PHYSICAL_ADDRESS VideoOpromAddress;\r
+ UINT32 VideoOpromSize;\r
+ EFI_PHYSICAL_ADDRESS S3DebugBufferAddress; \r
+ EFI_PHYSICAL_ADDRESS S3ResumeNvsEntryPoint; \r
+} ACPI_VARIABLE_SET_COMPATIBILITY;\r
+\r
+**/\r
+\r
+#include <FrameworkDxe.h>\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/UefiRuntimeServicesTableLib.h>\r
+#include <Library/HobLib.h>\r
+#include <Library/PcdLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Protocol/FrameworkMpService.h>\r
+#include <Guid/AcpiVariableCompatibility.h>\r
+#include <Guid/AcpiS3Context.h>\r
+\r
+GLOBAL_REMOVE_IF_UNREFERENCED\r
+ACPI_VARIABLE_SET_COMPATIBILITY *mAcpiVariableSetCompatibility = NULL;\r
+\r
+/**\r
+ Allocate EfiACPIMemoryNVS below 4G memory address.\r
+\r
+ This function allocates EfiACPIMemoryNVS below 4G memory address.\r
+\r
+ @param Size Size of memory to allocate.\r
+ \r
+ @return Allocated address for output.\r
+\r
+**/\r
+VOID*\r
+AllocateAcpiNvsMemoryBelow4G (\r
+ IN UINTN Size\r
+ );\r
+\r
+/**\r
+ Hook point for AcpiVariableThunkPlatform for S3Ready.\r
+\r
+ @param AcpiS3Context ACPI s3 context\r
+**/\r
+VOID\r
+S3ReadyThunkPlatform (\r
+ IN ACPI_S3_CONTEXT *AcpiS3Context\r
+ )\r
+{\r
+ EFI_PHYSICAL_ADDRESS AcpiMemoryBase;\r
+ UINT32 AcpiMemorySize;\r
+ EFI_PEI_HOB_POINTERS Hob;\r
+ UINT64 MemoryLength;\r
+\r
+ DEBUG ((EFI_D_INFO, "S3ReadyThunkPlatform\n"));\r
+\r
+ //\r
+ // Allocate ACPI reserved memory under 4G\r
+ //\r
+ AcpiMemoryBase = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateAcpiNvsMemoryBelow4G (PcdGet32 (PcdS3AcpiReservedMemorySize));\r
+ ASSERT (AcpiMemoryBase != 0);\r
+ AcpiMemorySize = PcdGet32 (PcdS3AcpiReservedMemorySize);\r
+\r
+ //\r
+ // Calculate the system memory length by memory hobs\r
+ //\r
+ MemoryLength = 0x100000;\r
+ Hob.Raw = GetFirstHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR);\r
+ ASSERT (Hob.Raw != NULL);\r
+ while ((Hob.Raw != NULL) && (!END_OF_HOB_LIST (Hob))) {\r
+ if (Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) {\r
+ //\r
+ // Skip the memory region below 1MB\r
+ //\r
+ if (Hob.ResourceDescriptor->PhysicalStart >= 0x100000) {\r
+ MemoryLength += Hob.ResourceDescriptor->ResourceLength;\r
+ }\r
+ }\r
+ Hob.Raw = GET_NEXT_HOB (Hob);\r
+ Hob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, Hob.Raw);\r
+ }\r
+\r
+ mAcpiVariableSetCompatibility->AcpiReservedMemoryBase = AcpiMemoryBase;\r
+ mAcpiVariableSetCompatibility->AcpiReservedMemorySize = AcpiMemorySize;\r
+ mAcpiVariableSetCompatibility->SystemMemoryLength = MemoryLength;\r
+\r
+ DEBUG((EFI_D_INFO, "AcpiVariableThunkPlatform: AcpiMemoryBase is 0x%8x\n", mAcpiVariableSetCompatibility->AcpiReservedMemoryBase));\r
+ DEBUG((EFI_D_INFO, "AcpiVariableThunkPlatform: AcpiMemorySize is 0x%8x\n", mAcpiVariableSetCompatibility->AcpiReservedMemorySize));\r
+ DEBUG((EFI_D_INFO, "AcpiVariableThunkPlatform: SystemMemoryLength is 0x%8x\n", mAcpiVariableSetCompatibility->SystemMemoryLength));\r
+\r
+ return ;\r
+}\r
+\r
+/**\r
+ Hook point for AcpiVariableThunkPlatform for InstallAcpiS3Save.\r
+**/\r
+VOID\r
+InstallAcpiS3SaveThunk (\r
+ VOID\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ FRAMEWORK_EFI_MP_SERVICES_PROTOCOL *FrameworkMpService;\r
+ UINTN VarSize;\r
+\r
+ Status = gBS->LocateProtocol (\r
+ &gFrameworkEfiMpServiceProtocolGuid,\r
+ NULL,\r
+ (VOID**) &FrameworkMpService\r
+ );\r
+ if (!EFI_ERROR (Status)) {\r
+ //\r
+ // On ECP platform, if framework CPU drivers are in use, The compatible version of ACPI variable set \r
+ // should be produced by CPU driver. \r
+ //\r
+ VarSize = sizeof (mAcpiVariableSetCompatibility);\r
+ Status = gRT->GetVariable (\r
+ ACPI_GLOBAL_VARIABLE,\r
+ &gEfiAcpiVariableCompatiblityGuid,\r
+ NULL,\r
+ &VarSize,\r
+ &mAcpiVariableSetCompatibility\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+ } else {\r
+ //\r
+ // Allocate/initialize the compatible version of Acpi Variable Set since Framework chipset/platform \r
+ // driver need this variable\r
+ //\r
+ mAcpiVariableSetCompatibility = AllocateAcpiNvsMemoryBelow4G (sizeof(ACPI_VARIABLE_SET_COMPATIBILITY));\r
+ Status = gRT->SetVariable (\r
+ ACPI_GLOBAL_VARIABLE,\r
+ &gEfiAcpiVariableCompatiblityGuid,\r
+ EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
+ sizeof(mAcpiVariableSetCompatibility),\r
+ &mAcpiVariableSetCompatibility\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+ }\r
+\r
+ DEBUG((EFI_D_INFO, "AcpiVariableSetCompatibility is 0x%8x\n", mAcpiVariableSetCompatibility));\r
+}\r