TianoCore EDK2 master
Loading...
Searching...
No Matches
AcpiLib.c
Go to the documentation of this file.
1
10#include <Uefi.h>
11
12#include <Library/AcpiLib.h>
13#include <Library/BaseLib.h>
15#include <Library/DebugLib.h>
17
19#include <Protocol/AcpiTable.h>
21
23
38 IN CONST EFI_GUID *AcpiFile,
39 IN EFI_LOCATE_ACPI_CHECK CheckAcpiTableFunction
40 )
41{
42 EFI_STATUS Status;
43 EFI_ACPI_TABLE_PROTOCOL *AcpiProtocol;
44 EFI_HANDLE *HandleBuffer;
45 UINTN NumberOfHandles;
46 UINT32 FvStatus;
47 UINTN Index;
49 INTN SectionInstance;
50 UINTN SectionSize;
51 EFI_ACPI_COMMON_HEADER *AcpiTable;
52 UINTN AcpiTableSize;
53 UINTN AcpiTableKey;
54 BOOLEAN Valid;
55 BOOLEAN FoundAcpiFile;
56
57 FoundAcpiFile = FALSE;
58
59 // Ensure the ACPI Table is present
60 Status = gBS->LocateProtocol (
61 &gEfiAcpiTableProtocolGuid,
62 NULL,
63 (VOID **)&AcpiProtocol
64 );
65 if (EFI_ERROR (Status)) {
66 return Status;
67 }
68
69 FvStatus = 0;
70 SectionInstance = 0;
71
72 // Locate all the Firmware Volume protocols.
73 Status = gBS->LocateHandleBuffer (
75 &gEfiFirmwareVolume2ProtocolGuid,
76 NULL,
77 &NumberOfHandles,
78 &HandleBuffer
79 );
80 if (EFI_ERROR (Status)) {
81 return Status;
82 }
83
84 // Looking for FV with ACPI storage file
85 for (Index = 0; Index < NumberOfHandles; Index++) {
86 //
87 // Get the protocol on this handle
88 // This should not fail because of LocateHandleBuffer
89 //
90 Status = gBS->HandleProtocol (
91 HandleBuffer[Index],
92 &gEfiFirmwareVolume2ProtocolGuid,
93 (VOID **)&FvInstance
94 );
95 if (EFI_ERROR (Status)) {
96 goto FREE_HANDLE_BUFFER;
97 }
98
99 while (Status == EFI_SUCCESS) {
100 // AcpiTable must be allocated by ReadSection (ie: AcpiTable == NULL)
101 AcpiTable = NULL;
102
103 // See if it has the ACPI storage file
104 Status = FvInstance->ReadSection (
105 FvInstance,
106 AcpiFile,
107 EFI_SECTION_RAW,
108 SectionInstance,
109 (VOID **)&AcpiTable,
110 &SectionSize,
111 &FvStatus
112 );
113
114 if (EFI_ERROR (Status)) {
115 break;
116 }
117
118 FoundAcpiFile = TRUE;
119
120 AcpiTableKey = 0;
121 AcpiTableSize = ((EFI_ACPI_DESCRIPTION_HEADER *)AcpiTable)->Length;
122 ASSERT (SectionSize >= AcpiTableSize);
123
124 DEBUG ((
125 DEBUG_ERROR,
126 "- Found '%c%c%c%c' ACPI Table\n",
127 (((EFI_ACPI_DESCRIPTION_HEADER *)AcpiTable)->Signature & 0xFF),
128 ((((EFI_ACPI_DESCRIPTION_HEADER *)AcpiTable)->Signature >> 8) & 0xFF),
129 ((((EFI_ACPI_DESCRIPTION_HEADER *)AcpiTable)->Signature >> 16) & 0xFF),
130 ((((EFI_ACPI_DESCRIPTION_HEADER *)AcpiTable)->Signature >> 24) & 0xFF)
131 ));
132
133 // Is the ACPI table valid?
134 if (CheckAcpiTableFunction != NULL) {
135 Valid = CheckAcpiTableFunction ((EFI_ACPI_DESCRIPTION_HEADER *)AcpiTable);
136 } else {
137 Valid = TRUE;
138 }
139
140 // Install the ACPI Table
141 if (Valid) {
142 Status = AcpiProtocol->InstallAcpiTable (
143 AcpiProtocol,
144 AcpiTable,
145 AcpiTableSize,
146 &AcpiTableKey
147 );
148 }
149
150 // Free memory allocated by ReadSection
151 gBS->FreePool (AcpiTable);
152
153 // Increment the section instance
154 SectionInstance++;
155 }
156 }
157
158FREE_HANDLE_BUFFER:
159 //
160 // Free any allocated buffers
161 //
162 gBS->FreePool (HandleBuffer);
163
164 return (FoundAcpiFile ? EFI_SUCCESS : EFI_NOT_FOUND);
165}
166
179 IN CONST EFI_GUID *AcpiFile
180 )
181{
183}
184
197EFIAPI
199 IN OUT UINT8 *Buffer,
200 IN UINTN Size
201 )
202{
203 UINTN ChecksumOffset;
204
205 if ((Buffer == NULL) || (Size == 0)) {
206 return EFI_INVALID_PARAMETER;
207 }
208
209 ChecksumOffset = OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER, Checksum);
210
211 //
212 // Set checksum to 0 first
213 //
214 Buffer[ChecksumOffset] = 0;
215
216 //
217 // Update checksum value
218 //
219 Buffer[ChecksumOffset] = CalculateCheckSum8 (Buffer, Size);
220
221 return EFI_SUCCESS;
222}
223
242EFIAPI
244 IN EFI_ACPI_SDT_PROTOCOL *AcpiSdtProtocol,
245 IN UINT32 TableSignature,
246 IN OUT UINTN *Index,
248 OUT UINTN *TableKey
249 )
250{
251 EFI_STATUS Status;
252 EFI_ACPI_SDT_HEADER *TempTable;
253 EFI_ACPI_TABLE_VERSION TableVersion;
254 UINTN TableIndex;
255
256 if ( (AcpiSdtProtocol == NULL)
257 || (Table == NULL)
258 || (TableKey == NULL))
259 {
260 return EFI_INVALID_PARAMETER;
261 }
262
263 Status = EFI_SUCCESS;
264
265 //
266 // Search for ACPI Table with matching signature
267 //
268 TableVersion = 0;
269 TableIndex = *Index;
270 while (!EFI_ERROR (Status)) {
271 Status = AcpiSdtProtocol->GetAcpiTable (
272 TableIndex,
273 &TempTable,
274 &TableVersion,
275 TableKey
276 );
277 if (!EFI_ERROR (Status)) {
278 TableIndex++;
279
280 if (((EFI_ACPI_DESCRIPTION_HEADER *)TempTable)->Signature == TableSignature) {
281 *Table = (EFI_ACPI_DESCRIPTION_HEADER *)TempTable;
282 *Index = TableIndex;
283 break;
284 }
285 }
286 }
287
288 return Status;
289}
290
307EFIAPI
309 IN EFI_ACPI_SDT_PROTOCOL *AcpiSdtProtocol,
310 IN EFI_ACPI_HANDLE TableHandle,
311 IN CHAR8 *AsciiObjectPath,
312 IN UINTN Value
313 )
314{
315 EFI_STATUS Status;
316 EFI_ACPI_HANDLE ObjectHandle;
317 EFI_ACPI_HANDLE DataHandle;
318 EFI_ACPI_DATA_TYPE DataType;
319 UINT8 *Buffer;
320 UINTN BufferSize;
321 UINTN DataSize;
322
323 if ((AcpiSdtProtocol == NULL) || (AsciiObjectPath == NULL)) {
324 return EFI_INVALID_PARAMETER;
325 }
326
327 ObjectHandle = NULL;
328 DataHandle = NULL;
329
330 Status = AcpiSdtProtocol->FindPath (TableHandle, AsciiObjectPath, &ObjectHandle);
331 if (EFI_ERROR (Status)) {
332 return Status;
333 }
334
335 Status = AcpiSdtProtocol->GetOption (ObjectHandle, 0, &DataType, (VOID *)&Buffer, &BufferSize);
336 if (EFI_ERROR (Status)) {
337 Status = EFI_NOT_FOUND;
338 goto Exit;
339 }
340
341 ASSERT (DataType == EFI_ACPI_DATA_TYPE_OPCODE);
342 ASSERT (Buffer != NULL);
343
344 if (Buffer[0] != AML_NAME_OP) {
345 Status = EFI_NOT_FOUND;
346 goto Exit;
347 }
348
349 //
350 // Get handle of data object
351 //
352 Status = AcpiSdtProtocol->GetChild (ObjectHandle, &DataHandle);
353 ASSERT_EFI_ERROR (Status);
354
355 Status = AcpiSdtProtocol->GetOption (DataHandle, 0, &DataType, (VOID *)&Buffer, &BufferSize);
356 ASSERT (DataType == EFI_ACPI_DATA_TYPE_OPCODE);
357 ASSERT (Buffer != NULL);
358
359 if ((Buffer[0] == AML_ZERO_OP) || (Buffer[0] == AML_ONE_OP)) {
360 Status = AcpiSdtProtocol->SetOption (DataHandle, 0, (VOID *)&Value, sizeof (UINT8));
361 ASSERT_EFI_ERROR (Status);
362 } else {
363 //
364 // Check the size of data object
365 //
366 switch (Buffer[0]) {
367 case AML_BYTE_PREFIX:
368 DataSize = sizeof (UINT8);
369 break;
370
371 case AML_WORD_PREFIX:
372 DataSize = sizeof (UINT16);
373 break;
374
375 case AML_DWORD_PREFIX:
376 DataSize = sizeof (UINT32);
377 break;
378
379 case AML_QWORD_PREFIX:
380 DataSize = sizeof (UINT64);
381 break;
382
383 default:
384 // The data type of the ACPI object is not an integer
385 Status = EFI_INVALID_PARAMETER;
386 goto Exit;
387 }
388
389 Status = AcpiSdtProtocol->SetOption (DataHandle, 1, (VOID *)&Value, DataSize);
390 ASSERT_EFI_ERROR (Status);
391 }
392
393Exit:
394 AcpiSdtProtocol->Close (DataHandle);
395 AcpiSdtProtocol->Close (ObjectHandle);
396
397 return Status;
398}
UINT64 UINTN
INT64 INTN
EFI_STATUS EFIAPI AcpiUpdateChecksum(IN OUT UINT8 *Buffer, IN UINTN Size)
Definition: AcpiLib.c:198
EFI_STATUS EFIAPI AcpiAmlObjectUpdateInteger(IN EFI_ACPI_SDT_PROTOCOL *AcpiSdtProtocol, IN EFI_ACPI_HANDLE TableHandle, IN CHAR8 *AsciiObjectPath, IN UINTN Value)
Definition: AcpiLib.c:308
EFI_STATUS EFIAPI AcpiLocateTableBySignature(IN EFI_ACPI_SDT_PROTOCOL *AcpiSdtProtocol, IN UINT32 TableSignature, IN OUT UINTN *Index, OUT EFI_ACPI_DESCRIPTION_HEADER **Table, OUT UINTN *TableKey)
Definition: AcpiLib.c:243
EFI_STATUS LocateAndInstallAcpiFromFvConditional(IN CONST EFI_GUID *AcpiFile, IN EFI_LOCATE_ACPI_CHECK CheckAcpiTableFunction)
Definition: AcpiLib.c:37
EFI_STATUS LocateAndInstallAcpiFromFv(IN CONST EFI_GUID *AcpiFile)
Definition: AcpiLib.c:178
UINT8 EFIAPI CalculateCheckSum8(IN CONST UINT8 *Buffer, IN UINTN Length)
Definition: CheckSum.c:71
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OFFSET_OF(TYPE, Field)
Definition: Base.h:758
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
VOID EFIAPI Exit(IN EFI_STATUS Status)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
@ ByProtocol
Definition: UefiSpec.h:1518
Definition: Base.h:213