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