TianoCore EDK2 master
Loading...
Searching...
No Matches
DxeResetSystemAcpiGed.c
Go to the documentation of this file.
1
10#include <Base.h>
11#include <Library/DebugLib.h>
14#include <Library/UefiLib.h>
15#include <Library/UefiRuntimeLib.h> // EfiConvertPointer()
16#include "ResetSystemAcpiGed.h"
17
39 UINTN Address
40 )
41{
42 EFI_STATUS Status;
44
45 Address &= ~EFI_PAGE_MASK;
46
47 Status = gDS->GetMemorySpaceDescriptor (Address, &Descriptor);
48 if (EFI_ERROR (Status)) {
49 DEBUG ((DEBUG_INFO, "%a: GetMemorySpaceDescriptor failed\n", __func__));
50 return Status;
51 }
52
54 Status = gDS->AddMemorySpace (
56 Address,
57 EFI_PAGE_SIZE,
58 EFI_MEMORY_UC | EFI_MEMORY_RUNTIME
59 );
60 if (EFI_ERROR (Status)) {
61 DEBUG ((DEBUG_INFO, "%a: AddMemorySpace failed\n", __func__));
62 return Status;
63 }
64
65 Status = gDS->SetMemorySpaceAttributes (
66 Address,
67 EFI_PAGE_SIZE,
68 EFI_MEMORY_RUNTIME
69 );
70 if (EFI_ERROR (Status)) {
71 DEBUG ((DEBUG_INFO, "%a:%d SetMemorySpaceAttributes failed\n", __func__, __LINE__));
72 return Status;
73 }
74 } else if (!(Descriptor.Attributes & EFI_MEMORY_RUNTIME)) {
75 Status = gDS->SetMemorySpaceAttributes (
76 Address,
77 EFI_PAGE_SIZE,
78 Descriptor.Attributes | EFI_MEMORY_RUNTIME
79 );
80
81 if (EFI_ERROR (Status)) {
82 DEBUG ((DEBUG_INFO, "%a:%d SetMemorySpaceAttributes failed\n", __func__, __LINE__));
83 return Status;
84 }
85 }
86
87 return EFI_SUCCESS;
88}
89
99 VOID
100 )
101{
106 UINT32 *Entry32 = NULL;
107 UINTN Entry32Num;
108 UINT32 *Signature = NULL;
109 UINTN Idx;
110 EFI_STATUS Status;
111
112 Status = EfiGetSystemConfigurationTable (&gEfiAcpiTableGuid, (VOID **)&Rsdp);
113 if (EFI_ERROR (Status)) {
114 Status = EfiGetSystemConfigurationTable (&gEfiAcpi10TableGuid, (VOID **)&Rsdp);
115 }
116
117 if (EFI_ERROR (Status) || (Rsdp == NULL)) {
118 DEBUG ((DEBUG_ERROR, "EFI_ERROR or Rsdp == NULL\n"));
119 return RETURN_NOT_FOUND;
120 }
121
122 Rsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->RsdtAddress;
123 Entry32 = (UINT32 *)(UINTN)(Rsdt + 1);
124 Entry32Num = (Rsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) >> 2;
125 for (Idx = 0; Idx < Entry32Num; Idx++) {
126 Signature = (UINT32 *)(UINTN)Entry32[Idx];
129 DEBUG ((DEBUG_INFO, "Found Fadt in Rsdt\n"));
130 goto Done;
131 }
132 }
133
134 Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *)Rsdp->XsdtAddress;
135 Entry32 = (UINT32 *)(Xsdt + 1);
136 Entry32Num = (Xsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) >> 2;
137 for (Idx = 0; Idx < Entry32Num; Idx++) {
138 Signature = (UINT32 *)(UINTN)Entry32[Idx];
141 DEBUG ((DEBUG_INFO, "Found Fadt in Xsdt\n"));
142 goto Done;
143 }
144 }
145
146 DEBUG ((DEBUG_ERROR, " Fadt Not Found\n"));
147 return RETURN_NOT_FOUND;
148
149Done:
150 mPowerManager.ResetRegAddr = Fadt->ResetReg.Address;
151 mPowerManager.ResetValue = Fadt->ResetValue;
152 mPowerManager.SleepControlRegAddr = Fadt->SleepControlReg.Address;
153 mPowerManager.SleepStatusRegAddr = Fadt->SleepStatusReg.Address;
154 return RETURN_SUCCESS;
155}
156
164STATIC
165VOID
167 IN EFI_EVENT Event,
168 IN VOID *Context
169 )
170{
171 EfiConvertPointer (0, (VOID **)&mPowerManager.SleepControlRegAddr);
172 EfiConvertPointer (0, (VOID **)&mPowerManager.SleepStatusRegAddr);
173 EfiConvertPointer (0, (VOID **)&mPowerManager.ResetRegAddr);
174}
175
185STATIC
186VOID
188 IN EFI_EVENT Event,
189 IN VOID *Context
190 )
191{
192 EFI_STATUS Status;
193
195 if (EFI_ERROR (Status)) {
196 return;
197 }
198
199 DEBUG ((DEBUG_INFO, "%a: sleepControl %llx\n", __func__, mPowerManager.SleepControlRegAddr));
200 ASSERT (mPowerManager.SleepControlRegAddr);
201 Status = SetMemoryAttributesRunTime (mPowerManager.SleepControlRegAddr);
202 if (EFI_ERROR (Status)) {
203 DEBUG ((DEBUG_INFO, "%a:%d\n", __func__, __LINE__));
204 return;
205 }
206
207 DEBUG ((DEBUG_INFO, "%a: sleepStatus %llx\n", __func__, mPowerManager.SleepStatusRegAddr));
208 ASSERT (mPowerManager.SleepStatusRegAddr);
209 Status = SetMemoryAttributesRunTime (mPowerManager.SleepStatusRegAddr);
210 if (EFI_ERROR (Status)) {
211 DEBUG ((DEBUG_INFO, "%a:%d\n", __func__, __LINE__));
212 return;
213 }
214
215 DEBUG ((DEBUG_INFO, "%a: ResetReg %llx\n", __func__, mPowerManager.ResetRegAddr));
216 ASSERT (mPowerManager.ResetRegAddr);
217 Status = SetMemoryAttributesRunTime (mPowerManager.ResetRegAddr);
218 if (EFI_ERROR (Status)) {
219 DEBUG ((DEBUG_INFO, "%a:%d\n", __func__, __LINE__));
220 }
221
222 return;
223}
224
231EFIAPI
233 IN EFI_HANDLE ImageHandle,
234 IN EFI_SYSTEM_TABLE *SystemTable
235 )
236{
237 EFI_STATUS Status;
238 EFI_EVENT Event;
239 EFI_EVENT ResetSystemVirtualNotifyEvent;
240
241 Status = gBS->CreateEventEx (
242 EVT_NOTIFY_SIGNAL,
243 TPL_CALLBACK,
245 NULL,
246 &gEfiAcpiTableGuid,
247 &Event
248 );
249
250 //
251 // Register SetVirtualAddressMap () notify function
252 //
253 Status = gBS->CreateEvent (
254 EVT_SIGNAL_VIRTUAL_ADDRESS_CHANGE,
255 TPL_NOTIFY,
257 NULL,
258 &ResetSystemVirtualNotifyEvent
259 );
260 ASSERT_EFI_ERROR (Status);
261 return Status;
262}
UINT64 UINTN
#define EFI_ACPI_5_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
Definition: Acpi50.h:1930
STATIC EFI_STATUS GetPowerManagerByParseAcpiInfo(VOID)
STATIC VOID ResetSystemLibAddressChangeEvent(IN EFI_EVENT Event, IN VOID *Context)
STATIC EFI_STATUS SetMemoryAttributesRunTime(UINTN Address)
EFI_STATUS EFIAPI ResetSystemLibConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
STATIC VOID AcpiNotificationEvent(IN EFI_EVENT Event, IN VOID *Context)
EFI_DXE_SERVICES * gDS
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#define RETURN_NOT_FOUND
Definition: Base.h:1142
#define RETURN_SUCCESS
Definition: Base.h:1066
#define IN
Definition: Base.h:279
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
@ EfiGcdMemoryTypeNonExistent
Definition: PiDxeCis.h:26
@ EfiGcdMemoryTypeMemoryMappedIo
Definition: PiDxeCis.h:44
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
EFI_STATUS EFIAPI EfiGetSystemConfigurationTable(IN EFI_GUID *TableGuid, OUT VOID **Table)
Definition: UefiLib.c:82
EFI_STATUS EFIAPI EfiConvertPointer(IN UINTN DebugDisposition, IN OUT VOID **Address)
Definition: RuntimeLib.c:561
EFI_GCD_MEMORY_TYPE GcdMemoryType
Definition: PiDxeCis.h:152