TianoCore EDK2 master
Loading...
Searching...
No Matches
Acpi.c
Go to the documentation of this file.
1
9#include "UefiLibInternal.h"
11#include <Guid/Acpi.h>
12
34 IN UINTN TablePointerSize,
35 IN UINT32 Signature,
36 IN EFI_ACPI_COMMON_HEADER *PreviousTable OPTIONAL,
37 OUT BOOLEAN *PreviousTableLocated OPTIONAL
38 )
39{
40 UINTN Index;
41 UINTN EntryCount;
42 UINT64 EntryPtr;
43 UINTN BasePtr;
45
46 if (PreviousTableLocated != NULL) {
47 ASSERT (PreviousTable != NULL);
48 *PreviousTableLocated = FALSE;
49 } else {
50 ASSERT (PreviousTable == NULL);
51 }
52
53 if (Sdt == NULL) {
54 return NULL;
55 }
56
57 EntryCount = (Sdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / TablePointerSize;
58
59 BasePtr = (UINTN)(Sdt + 1);
60 for (Index = 0; Index < EntryCount; Index++) {
61 EntryPtr = 0;
62 CopyMem (&EntryPtr, (VOID *)(BasePtr + Index * TablePointerSize), TablePointerSize);
63 Table = (EFI_ACPI_COMMON_HEADER *)((UINTN)(EntryPtr));
64 if ((Table != NULL) && (Table->Signature == Signature)) {
65 if (PreviousTable != NULL) {
66 if (Table == PreviousTable) {
67 *PreviousTableLocated = TRUE;
68 } else if (*PreviousTableLocated) {
69 //
70 // Return next table.
71 //
72 return Table;
73 }
74 } else {
75 //
76 // Return first table.
77 //
78 return Table;
79 }
80 }
81 }
82
83 return NULL;
84}
85
97 )
98{
100 UINT64 Data64;
101
102 if (Fadt == NULL) {
103 return NULL;
104 }
105
106 if (Fadt->Header.Revision < EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_REVISION) {
107 Facs = (EFI_ACPI_COMMON_HEADER *)(UINTN)Fadt->FirmwareCtrl;
108 } else {
109 CopyMem (&Data64, &Fadt->XFirmwareCtrl, sizeof (UINT64));
110 if (Data64 != 0) {
111 Facs = (EFI_ACPI_COMMON_HEADER *)(UINTN)Data64;
112 } else {
113 Facs = (EFI_ACPI_COMMON_HEADER *)(UINTN)Fadt->FirmwareCtrl;
114 }
115 }
116
117 return Facs;
118}
119
131 )
132{
134 UINT64 Data64;
135
136 if (Fadt == NULL) {
137 return NULL;
138 }
139
140 if (Fadt->Header.Revision < EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_REVISION) {
141 Dsdt = (EFI_ACPI_COMMON_HEADER *)(UINTN)Fadt->Dsdt;
142 } else {
143 CopyMem (&Data64, &Fadt->XDsdt, sizeof (UINT64));
144 if (Data64 != 0) {
145 Dsdt = (EFI_ACPI_COMMON_HEADER *)(UINTN)Data64;
146 } else {
147 Dsdt = (EFI_ACPI_COMMON_HEADER *)(UINTN)Fadt->Dsdt;
148 }
149 }
150
151 return Dsdt;
152}
153
174 IN EFI_GUID *AcpiGuid,
175 IN UINT32 Signature,
176 IN EFI_ACPI_COMMON_HEADER *PreviousTable OPTIONAL,
177 OUT BOOLEAN *PreviousTableLocated OPTIONAL
178 )
179{
180 EFI_STATUS Status;
186
187 if (PreviousTableLocated != NULL) {
188 ASSERT (PreviousTable != NULL);
189 *PreviousTableLocated = FALSE;
190 } else {
191 ASSERT (PreviousTable == NULL);
192 }
193
194 Rsdp = NULL;
195 //
196 // Get ACPI ConfigurationTable (RSD_PTR)
197 //
198 Status = EfiGetSystemConfigurationTable (AcpiGuid, (VOID **)&Rsdp);
199 if (EFI_ERROR (Status) || (Rsdp == NULL)) {
200 return NULL;
201 }
202
203 Table = NULL;
204
205 //
206 // Search XSDT
207 //
209 Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->XsdtAddress;
211 ASSERT (PreviousTable == NULL);
212 //
213 // It is to locate DSDT,
214 // need to locate FADT first.
215 //
217 Xsdt,
218 sizeof (UINT64),
220 NULL,
221 NULL
222 );
223
224 if (Fadt != NULL) {
225 Table = LocateAcpiDsdtFromFadt (Fadt);
226 } else {
227 Table = NULL;
228 }
230 ASSERT (PreviousTable == NULL);
231 //
232 // It is to locate FACS,
233 // need to locate FADT first.
234 //
236 Xsdt,
237 sizeof (UINT64),
239 NULL,
240 NULL
241 );
242
243 if (Fadt != NULL) {
244 Table = LocateAcpiFacsFromFadt (Fadt);
245 } else {
246 Table = NULL;
247 }
248 } else {
249 Table = ScanTableInSDT (
250 Xsdt,
251 sizeof (UINT64),
252 Signature,
253 PreviousTable,
254 PreviousTableLocated
255 );
256 }
257 }
258
259 if (Table != NULL) {
260 return Table;
261 } else if ((PreviousTableLocated != NULL) &&
262 *PreviousTableLocated)
263 {
264 //
265 // PreviousTable could be located in XSDT,
266 // but next table could not be located in XSDT.
267 //
268 return NULL;
269 }
270
271 //
272 // Search RSDT
273 //
274 Rsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->RsdtAddress;
276 ASSERT (PreviousTable == NULL);
277 //
278 // It is to locate DSDT,
279 // need to locate FADT first.
280 //
282 Rsdt,
283 sizeof (UINT32),
285 NULL,
286 NULL
287 );
288
289 if (Fadt != NULL) {
290 Table = LocateAcpiDsdtFromFadt (Fadt);
291 } else {
292 Table = NULL;
293 }
295 ASSERT (PreviousTable == NULL);
296 //
297 // It is to locate FACS,
298 // need to locate FADT first.
299 //
301 Rsdt,
302 sizeof (UINT32),
304 NULL,
305 NULL
306 );
307
308 if (Fadt != NULL) {
309 Table = LocateAcpiFacsFromFadt (Fadt);
310 } else {
311 Table = NULL;
312 }
313 } else {
314 Table = ScanTableInSDT (
315 Rsdt,
316 sizeof (UINT32),
317 Signature,
318 PreviousTable,
319 PreviousTableLocated
320 );
321 }
322
323 return Table;
324}
325
362EFIAPI
364 IN UINT32 Signature,
365 IN EFI_ACPI_COMMON_HEADER *PreviousTable OPTIONAL
366 )
367{
369 BOOLEAN TempPreviousTableLocated;
370 BOOLEAN *PreviousTableLocated;
371
372 if (PreviousTable != NULL) {
373 if (PreviousTable->Signature != Signature) {
374 //
375 // PreviousTable->Signature is not same with Signature.
376 //
377 return NULL;
378 } else if ((Signature == EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) ||
381 {
382 //
383 // There is only one FADT/DSDT/FACS table,
384 // so don't try to locate next one.
385 //
386 return NULL;
387 }
388
389 PreviousTableLocated = &TempPreviousTableLocated;
390 *PreviousTableLocated = FALSE;
391 } else {
392 PreviousTableLocated = NULL;
393 }
394
396 &gEfiAcpi20TableGuid,
397 Signature,
398 PreviousTable,
399 PreviousTableLocated
400 );
401 if (Table != NULL) {
402 return Table;
403 } else if ((PreviousTableLocated != NULL) &&
404 *PreviousTableLocated)
405 {
406 //
407 // PreviousTable could be located in gEfiAcpi20TableGuid system
408 // configuration table, but next table could not be located in
409 // gEfiAcpi20TableGuid system configuration table.
410 //
411 return NULL;
412 }
413
415 &gEfiAcpi10TableGuid,
416 Signature,
417 PreviousTable,
418 PreviousTableLocated
419 );
420}
421
440EFIAPI
442 IN UINT32 Signature
443 )
444{
445 return EfiLocateNextAcpiTable (Signature, NULL);
446}
UINT64 UINTN
#define EFI_ACPI_2_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
Definition: Acpi20.h:460
#define EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
Definition: Acpi20.h:475
#define EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
Definition: Acpi20.h:480
#define EFI_ACPI_2_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION
Definition: Acpi20.h:87
#define EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE_REVISION
Definition: Acpi20.h:181
EFI_ACPI_COMMON_HEADER * LocateAcpiDsdtFromFadt(IN EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt)
Definition: Acpi.c:129
EFI_ACPI_COMMON_HEADER * LocateAcpiTableInAcpiConfigurationTable(IN EFI_GUID *AcpiGuid, IN UINT32 Signature, IN EFI_ACPI_COMMON_HEADER *PreviousTable OPTIONAL, OUT BOOLEAN *PreviousTableLocated OPTIONAL)
Definition: Acpi.c:173
EFI_ACPI_COMMON_HEADER * ScanTableInSDT(IN EFI_ACPI_DESCRIPTION_HEADER *Sdt, IN UINTN TablePointerSize, IN UINT32 Signature, IN EFI_ACPI_COMMON_HEADER *PreviousTable OPTIONAL, OUT BOOLEAN *PreviousTableLocated OPTIONAL)
Definition: Acpi.c:32
EFI_ACPI_COMMON_HEADER * LocateAcpiFacsFromFadt(IN EFI_ACPI_2_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt)
Definition: Acpi.c:95
EFI_ACPI_COMMON_HEADER *EFIAPI EfiLocateNextAcpiTable(IN UINT32 Signature, IN EFI_ACPI_COMMON_HEADER *PreviousTable OPTIONAL)
Definition: Acpi.c:363
EFI_ACPI_COMMON_HEADER *EFIAPI EfiLocateFirstAcpiTable(IN UINT32 Signature)
Definition: Acpi.c:441
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
EFI_STATUS EFIAPI EfiGetSystemConfigurationTable(IN EFI_GUID *TableGuid, OUT VOID **Table)
Definition: UefiLib.c:82
Definition: Base.h:213