]> git.proxmox.com Git - mirror_edk2.git/blame - IntelFrameworkModulePkg/Universal/Acpi/AcpiS3SaveDxe/AcpiVariableThunkPlatform.c
Fix ICC11(VS2005) build failure.
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / Acpi / AcpiS3SaveDxe / AcpiVariableThunkPlatform.c
CommitLineData
13d4af68 1/** @file\r
2 This is an implementation of the AcpiVariable platform field for ECP platform.\r
3\r
73f0127f 4Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>\r
13d4af68 5\r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions\r
8of the BSD License which accompanies this distribution. The\r
9full text of the license may be found at\r
10http://opensource.org/licenses/bsd-license.php\r
11\r
12THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
13WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
14\r
15==\r
16\r
17typedef struct {\r
18 EFI_PHYSICAL_ADDRESS AcpiReservedMemoryBase; <<===\r
19 UINT32 AcpiReservedMemorySize; <<===\r
20 EFI_PHYSICAL_ADDRESS S3ReservedLowMemoryBase;\r
21 EFI_PHYSICAL_ADDRESS AcpiBootScriptTable;\r
22 EFI_PHYSICAL_ADDRESS RuntimeScriptTableBase;\r
23 EFI_PHYSICAL_ADDRESS AcpiFacsTable;\r
24 UINT64 SystemMemoryLength; <<===\r
25 ACPI_CPU_DATA_COMPATIBILITY AcpiCpuData;\r
26 EFI_PHYSICAL_ADDRESS VideoOpromAddress;\r
27 UINT32 VideoOpromSize;\r
28 EFI_PHYSICAL_ADDRESS S3DebugBufferAddress; \r
29 EFI_PHYSICAL_ADDRESS S3ResumeNvsEntryPoint; \r
30} ACPI_VARIABLE_SET_COMPATIBILITY;\r
31\r
32**/\r
33\r
34#include <FrameworkDxe.h>\r
35#include <Library/BaseLib.h>\r
36#include <Library/BaseMemoryLib.h>\r
37#include <Library/UefiBootServicesTableLib.h>\r
38#include <Library/UefiRuntimeServicesTableLib.h>\r
39#include <Library/HobLib.h>\r
40#include <Library/PcdLib.h>\r
41#include <Library/DebugLib.h>\r
42#include <Protocol/FrameworkMpService.h>\r
43#include <Guid/AcpiVariableCompatibility.h>\r
44#include <Guid/AcpiS3Context.h>\r
45\r
46GLOBAL_REMOVE_IF_UNREFERENCED\r
47ACPI_VARIABLE_SET_COMPATIBILITY *mAcpiVariableSetCompatibility = NULL;\r
48\r
49/**\r
091249f4 50 Allocate memory below 4G memory address.\r
13d4af68 51\r
091249f4 52 This function allocates memory below 4G memory address.\r
13d4af68 53\r
091249f4 54 @param MemoryType Memory type of memory to allocate.\r
13d4af68 55 @param Size Size of memory to allocate.\r
56 \r
57 @return Allocated address for output.\r
58\r
59**/\r
60VOID*\r
091249f4 61AllocateMemoryBelow4G (\r
73f0127f
SZ
62 IN EFI_MEMORY_TYPE MemoryType,\r
63 IN UINTN Size\r
13d4af68 64 );\r
65\r
66/**\r
67 Hook point for AcpiVariableThunkPlatform for S3Ready.\r
68\r
69 @param AcpiS3Context ACPI s3 context\r
70**/\r
71VOID\r
72S3ReadyThunkPlatform (\r
73 IN ACPI_S3_CONTEXT *AcpiS3Context\r
74 )\r
75{\r
76 EFI_PHYSICAL_ADDRESS AcpiMemoryBase;\r
77 UINT32 AcpiMemorySize;\r
78 EFI_PEI_HOB_POINTERS Hob;\r
79 UINT64 MemoryLength;\r
80\r
81 DEBUG ((EFI_D_INFO, "S3ReadyThunkPlatform\n"));\r
82\r
83 //\r
84 // Allocate ACPI reserved memory under 4G\r
85 //\r
091249f4 86 AcpiMemoryBase = (EFI_PHYSICAL_ADDRESS)(UINTN)AllocateMemoryBelow4G (EfiReservedMemoryType, PcdGet32 (PcdS3AcpiReservedMemorySize));\r
13d4af68 87 ASSERT (AcpiMemoryBase != 0);\r
88 AcpiMemorySize = PcdGet32 (PcdS3AcpiReservedMemorySize);\r
89\r
90 //\r
91 // Calculate the system memory length by memory hobs\r
92 //\r
93 MemoryLength = 0x100000;\r
94 Hob.Raw = GetFirstHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR);\r
95 ASSERT (Hob.Raw != NULL);\r
96 while ((Hob.Raw != NULL) && (!END_OF_HOB_LIST (Hob))) {\r
97 if (Hob.ResourceDescriptor->ResourceType == EFI_RESOURCE_SYSTEM_MEMORY) {\r
98 //\r
99 // Skip the memory region below 1MB\r
100 //\r
101 if (Hob.ResourceDescriptor->PhysicalStart >= 0x100000) {\r
102 MemoryLength += Hob.ResourceDescriptor->ResourceLength;\r
103 }\r
104 }\r
105 Hob.Raw = GET_NEXT_HOB (Hob);\r
106 Hob.Raw = GetNextHob (EFI_HOB_TYPE_RESOURCE_DESCRIPTOR, Hob.Raw);\r
107 }\r
108\r
109 mAcpiVariableSetCompatibility->AcpiReservedMemoryBase = AcpiMemoryBase;\r
110 mAcpiVariableSetCompatibility->AcpiReservedMemorySize = AcpiMemorySize;\r
111 mAcpiVariableSetCompatibility->SystemMemoryLength = MemoryLength;\r
112\r
113 DEBUG((EFI_D_INFO, "AcpiVariableThunkPlatform: AcpiMemoryBase is 0x%8x\n", mAcpiVariableSetCompatibility->AcpiReservedMemoryBase));\r
114 DEBUG((EFI_D_INFO, "AcpiVariableThunkPlatform: AcpiMemorySize is 0x%8x\n", mAcpiVariableSetCompatibility->AcpiReservedMemorySize));\r
115 DEBUG((EFI_D_INFO, "AcpiVariableThunkPlatform: SystemMemoryLength is 0x%8x\n", mAcpiVariableSetCompatibility->SystemMemoryLength));\r
116\r
117 return ;\r
118}\r
119\r
120/**\r
121 Hook point for AcpiVariableThunkPlatform for InstallAcpiS3Save.\r
122**/\r
123VOID\r
124InstallAcpiS3SaveThunk (\r
125 VOID\r
126 )\r
127{\r
128 EFI_STATUS Status;\r
129 FRAMEWORK_EFI_MP_SERVICES_PROTOCOL *FrameworkMpService;\r
130 UINTN VarSize;\r
131\r
132 Status = gBS->LocateProtocol (\r
133 &gFrameworkEfiMpServiceProtocolGuid,\r
134 NULL,\r
135 (VOID**) &FrameworkMpService\r
136 );\r
137 if (!EFI_ERROR (Status)) {\r
138 //\r
139 // On ECP platform, if framework CPU drivers are in use, The compatible version of ACPI variable set \r
140 // should be produced by CPU driver. \r
141 //\r
142 VarSize = sizeof (mAcpiVariableSetCompatibility);\r
143 Status = gRT->GetVariable (\r
144 ACPI_GLOBAL_VARIABLE,\r
145 &gEfiAcpiVariableCompatiblityGuid,\r
146 NULL,\r
147 &VarSize,\r
148 &mAcpiVariableSetCompatibility\r
149 );\r
150 ASSERT_EFI_ERROR (Status);\r
151 } else {\r
152 //\r
153 // Allocate/initialize the compatible version of Acpi Variable Set since Framework chipset/platform \r
154 // driver need this variable\r
155 //\r
091249f4 156 mAcpiVariableSetCompatibility = AllocateMemoryBelow4G (EfiACPIMemoryNVS, sizeof(ACPI_VARIABLE_SET_COMPATIBILITY));\r
13d4af68 157 Status = gRT->SetVariable (\r
158 ACPI_GLOBAL_VARIABLE,\r
159 &gEfiAcpiVariableCompatiblityGuid,\r
160 EFI_VARIABLE_BOOTSERVICE_ACCESS | EFI_VARIABLE_RUNTIME_ACCESS | EFI_VARIABLE_NON_VOLATILE,\r
161 sizeof(mAcpiVariableSetCompatibility),\r
162 &mAcpiVariableSetCompatibility\r
163 );\r
164 ASSERT_EFI_ERROR (Status);\r
165 }\r
166\r
167 DEBUG((EFI_D_INFO, "AcpiVariableSetCompatibility is 0x%8x\n", mAcpiVariableSetCompatibility));\r
168}\r