2 ACPI Table Protocol Implementation
4 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include "AcpiTable.h"
21 // The maximum number of tables that pre-allocated.
23 UINTN mEfiAcpiMaxNumTables
= EFI_ACPI_MAX_NUM_TABLES
;
26 // Allocation strategy to use for AllocatePages ().
27 // Runtime value depends on PcdExposedAcpiTableVersions.
29 STATIC EFI_ALLOCATE_TYPE mAcpiTableAllocType
;
32 This function adds an ACPI table to the table list. It will detect FACS and
33 allocate the correct type of memory and properly align the table.
35 @param AcpiTableInstance Instance of the protocol.
36 @param Table Table to add.
37 @param Checksum Does the table require checksumming.
38 @param Version The version of the list to add the table to.
39 @param Handle Pointer for returning the handle.
41 @return EFI_SUCCESS The function completed successfully.
42 @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
43 @return EFI_ABORTED The table is a duplicate of a table that is required
49 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
52 IN EFI_ACPI_TABLE_VERSION Version
,
57 This function finds and removes the table specified by the handle.
59 @param AcpiTableInstance Instance of the protocol.
60 @param Version Bitmask of which versions to remove.
61 @param Handle Table to remove.
63 @return EFI_SUCCESS The function completed successfully.
64 @return EFI_ABORTED An error occurred.
65 @return EFI_NOT_FOUND Handle not found in table list.
70 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
71 IN EFI_ACPI_TABLE_VERSION Version
,
76 This function calculates and updates an UINT8 checksum.
78 @param Buffer Pointer to buffer to checksum
79 @param Size Number of bytes to checksum
80 @param ChecksumOffset Offset to place the checksum result in
82 @return EFI_SUCCESS The function completed successfully.
85 AcpiPlatformChecksum (
88 IN UINTN ChecksumOffset
92 Checksum all versions of the common tables, RSDP, RSDT, XSDT.
94 @param AcpiTableInstance Protocol instance private data.
96 @return EFI_SUCCESS The function completed successfully.
100 ChecksumCommonTables (
101 IN OUT EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
105 // Protocol function implementations.
109 This function publishes the specified versions of the ACPI tables by
110 installing EFI configuration table entries for them. Any combination of
111 table versions can be published.
113 @param AcpiTableInstance Instance of the protocol.
114 @param Version Version(s) to publish.
116 @return EFI_SUCCESS The function completed successfully.
117 @return EFI_ABORTED The function could not complete successfully.
123 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
124 IN EFI_ACPI_TABLE_VERSION Version
128 UINT32
*CurrentRsdtEntry
;
129 VOID
*CurrentXsdtEntry
;
133 // Reorder tables as some operating systems don't seem to find the
134 // FADT correctly if it is not in the first few entries
138 // Add FADT as the first entry
140 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
141 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) AcpiTableInstance
->Rsdt1
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
142 *CurrentRsdtEntry
= (UINT32
) (UINTN
) AcpiTableInstance
->Fadt1
;
144 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) AcpiTableInstance
->Rsdt3
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
145 *CurrentRsdtEntry
= (UINT32
) (UINTN
) AcpiTableInstance
->Fadt3
;
147 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
148 CurrentXsdtEntry
= (VOID
*) ((UINT8
*) AcpiTableInstance
->Xsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
150 // Add entry to XSDT, XSDT expects 64 bit pointers, but
151 // the table pointers in XSDT are not aligned on 8 byte boundary.
153 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Fadt3
;
162 // Do checksum again because Dsdt/Xsdt is updated.
164 ChecksumCommonTables (AcpiTableInstance
);
167 // Add the RSD_PTR to the system table and store that we have installed the
170 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
171 Status
= gBS
->InstallConfigurationTable (&gEfiAcpi10TableGuid
, AcpiTableInstance
->Rsdp1
);
172 if (EFI_ERROR (Status
)) {
177 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
178 Status
= gBS
->InstallConfigurationTable (&gEfiAcpiTableGuid
, AcpiTableInstance
->Rsdp3
);
179 if (EFI_ERROR (Status
)) {
189 Installs an ACPI table into the RSDT/XSDT.
190 Note that the ACPI table should be checksumed before installing it.
191 Otherwise it will assert.
193 @param This Protocol instance pointer.
194 @param AcpiTableBuffer A pointer to a buffer containing the ACPI table to be installed.
195 @param AcpiTableBufferSize Specifies the size, in bytes, of the AcpiTableBuffer buffer.
196 @param TableKey Reurns a key to refer to the ACPI table.
198 @return EFI_SUCCESS The table was successfully inserted.
199 @return EFI_INVALID_PARAMETER Either AcpiTableBuffer is NULL, TableKey is NULL, or AcpiTableBufferSize
200 and the size field embedded in the ACPI table pointed to by AcpiTableBuffer
202 @return EFI_OUT_OF_RESOURCES Insufficient resources exist to complete the request.
203 @retval EFI_ACCESS_DENIED The table signature matches a table already
204 present in the system and platform policy
205 does not allow duplicate tables of this type.
211 IN EFI_ACPI_TABLE_PROTOCOL
*This
,
212 IN VOID
*AcpiTableBuffer
,
213 IN UINTN AcpiTableBufferSize
,
217 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
;
219 VOID
*AcpiTableBufferConst
;
220 EFI_ACPI_TABLE_VERSION Version
;
223 // Check for invalid input parameters
225 if ((AcpiTableBuffer
== NULL
) || (TableKey
== NULL
)
226 || (((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTableBuffer
)->Length
!= AcpiTableBufferSize
)) {
227 return EFI_INVALID_PARAMETER
;
230 Version
= PcdGet32 (PcdAcpiExposedTableVersions
);
233 // Get the instance of the ACPI table protocol
235 AcpiTableInstance
= EFI_ACPI_TABLE_INSTANCE_FROM_THIS (This
);
238 // Install the ACPI table
240 AcpiTableBufferConst
= AllocateCopyPool (AcpiTableBufferSize
,AcpiTableBuffer
);
242 Status
= AddTableToList (
244 AcpiTableBufferConst
,
249 if (!EFI_ERROR (Status
)) {
250 Status
= PublishTables (
255 FreePool (AcpiTableBufferConst
);
258 // Add a new table successfully, notify registed callback
260 if (FeaturePcdGet (PcdInstallAcpiSdtProtocol
)) {
261 if (!EFI_ERROR (Status
)) {
275 Removes an ACPI table from the RSDT/XSDT.
277 @param This Protocol instance pointer.
278 @param TableKey Specifies the table to uninstall. The key was returned from InstallAcpiTable().
280 @return EFI_SUCCESS The table was successfully uninstalled.
281 @return EFI_NOT_FOUND TableKey does not refer to a valid key for a table entry.
287 IN EFI_ACPI_TABLE_PROTOCOL
*This
,
291 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
;
295 // Get the instance of the ACPI table protocol
297 AcpiTableInstance
= EFI_ACPI_TABLE_INSTANCE_FROM_THIS (This
);
300 // Uninstall the ACPI table
302 Status
= RemoveTableFromList (
304 EFI_ACPI_TABLE_VERSION_1_0B
| ACPI_TABLE_VERSION_GTE_2_0
,
307 if (!EFI_ERROR (Status
)) {
308 Status
= PublishTables (
310 EFI_ACPI_TABLE_VERSION_1_0B
| ACPI_TABLE_VERSION_GTE_2_0
314 if (EFI_ERROR (Status
)) {
315 return EFI_NOT_FOUND
;
322 If the number of APCI tables exceeds the preallocated max table number, enlarge the table buffer.
324 @param AcpiTableInstance ACPI table protocol instance data structure.
326 @return EFI_SUCCESS reallocate the table beffer successfully.
327 @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
331 ReallocateAcpiTableBuffer (
332 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
335 UINTN NewMaxTableNumber
;
338 EFI_PHYSICAL_ADDRESS PageAddress
;
339 EFI_ACPI_TABLE_INSTANCE TempPrivateData
;
343 CopyMem (&TempPrivateData
, AcpiTableInstance
, sizeof (EFI_ACPI_TABLE_INSTANCE
));
345 // Enlarge the max table number from mEfiAcpiMaxNumTables to mEfiAcpiMaxNumTables + EFI_ACPI_MAX_NUM_TABLES
347 NewMaxTableNumber
= mEfiAcpiMaxNumTables
+ EFI_ACPI_MAX_NUM_TABLES
;
349 // Create RSDT, XSDT structures and allocate buffers.
351 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
352 NewMaxTableNumber
* sizeof (UINT64
);
354 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
355 TotalSize
+= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
356 NewMaxTableNumber
* sizeof (UINT32
) +
357 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
358 NewMaxTableNumber
* sizeof (UINT32
);
362 // Allocate memory in the lower 32 bit of address range for
363 // compatibility with ACPI 1.0 OS.
365 // This is done because ACPI 1.0 pointers are 32 bit values.
366 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
367 // There is no architectural reason these should be below 4GB, it is purely
368 // for convenience of implementation that we force memory below 4GB.
370 PageAddress
= 0xFFFFFFFF;
371 Status
= gBS
->AllocatePages (
373 EfiACPIReclaimMemory
,
374 EFI_SIZE_TO_PAGES (TotalSize
),
378 if (EFI_ERROR (Status
)) {
379 return EFI_OUT_OF_RESOURCES
;
382 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
383 ZeroMem (Pointer
, TotalSize
);
385 AcpiTableInstance
->Rsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
386 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
387 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + NewMaxTableNumber
* sizeof (UINT32
));
388 AcpiTableInstance
->Rsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
389 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + NewMaxTableNumber
* sizeof (UINT32
));
391 AcpiTableInstance
->Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
394 // Update RSDP to point to the new Rsdt and Xsdt address.
396 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
397 AcpiTableInstance
->Rsdp1
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt1
;
398 AcpiTableInstance
->Rsdp3
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt3
;
400 CurrentData
= (UINT64
) (UINTN
) AcpiTableInstance
->Xsdt
;
401 CopyMem (&AcpiTableInstance
->Rsdp3
->XsdtAddress
, &CurrentData
, sizeof (UINT64
));
404 // copy the original Rsdt1, Rsdt3 and Xsdt structure to new buffer
406 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
407 CopyMem (AcpiTableInstance
->Rsdt1
, TempPrivateData
.Rsdt1
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT32
)));
408 CopyMem (AcpiTableInstance
->Rsdt3
, TempPrivateData
.Rsdt3
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT32
)));
410 CopyMem (AcpiTableInstance
->Xsdt
, TempPrivateData
.Xsdt
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT64
)));
413 // Calculate orignal ACPI table buffer size
415 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
416 mEfiAcpiMaxNumTables
* sizeof (UINT64
);
418 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
419 TotalSize
+= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
420 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
421 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
422 mEfiAcpiMaxNumTables
* sizeof (UINT32
);
425 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
)(UINTN
)TempPrivateData
.Rsdt1
, EFI_SIZE_TO_PAGES (TotalSize
));
428 // Update the Max ACPI table number
430 mEfiAcpiMaxNumTables
= NewMaxTableNumber
;
435 Determine whether the FADT table passed in as parameter requires mutual
436 exclusion between the DSDT and X_DSDT fields. (That is, whether there exists
437 an explicit requirement that at most one of those fields is permitted to be
440 @param[in] Fadt The EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE object to
443 @retval TRUE Fadt requires mutual exclusion between DSDT and X_DSDT.
444 @retval FALSE Otherwise.
447 RequireDsdtXDsdtExclusion (
448 IN EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE
*Fadt
452 // Mantis ticket #1393 was addressed in ACPI 5.1 Errata B. Unfortunately, we
453 // can't tell apart 5.1 Errata A and 5.1 Errata B just from looking at the
454 // FADT table. Therefore let's require exclusion for table versions >= 5.1.
456 // While this needlessly covers 5.1 and 5.1A too, it is safer to require
457 // DSDT<->X_DSDT exclusion for lax (5.1, 5.1A) versions of the spec than to
458 // permit DSDT<->X_DSDT duplication for strict (5.1B) versions of the spec.
460 // The same applies to 6.0 vs. 6.0A. While 6.0 does not require the
461 // exclusion, 6.0A and 6.1 do. Since we cannot distinguish 6.0 from 6.0A
462 // based on just the FADT, we lump 6.0 in with the rest of >= 5.1.
464 if ((Fadt
->Header
.Revision
< 5) ||
465 ((Fadt
->Header
.Revision
== 5) &&
466 (((EFI_ACPI_5_1_FIXED_ACPI_DESCRIPTION_TABLE
*)Fadt
)->MinorVersion
== 0))) {
479 This function adds an ACPI table to the table list. It will detect FACS and
480 allocate the correct type of memory and properly align the table.
482 @param AcpiTableInstance Instance of the protocol.
483 @param Table Table to add.
484 @param Checksum Does the table require checksumming.
485 @param Version The version of the list to add the table to.
486 @param Handle Pointer for returning the handle.
488 @return EFI_SUCCESS The function completed successfully.
489 @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
490 @retval EFI_ACCESS_DENIED The table signature matches a table already
491 present in the system and platform policy
492 does not allow duplicate tables of this type.
497 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
500 IN EFI_ACPI_TABLE_VERSION Version
,
505 EFI_ACPI_TABLE_LIST
*CurrentTableList
;
506 UINT32 CurrentTableSignature
;
507 UINT32 CurrentTableSize
;
508 UINT32
*CurrentRsdtEntry
;
509 VOID
*CurrentXsdtEntry
;
514 // Check for invalid input parameters
516 ASSERT (AcpiTableInstance
);
526 // Create a new list entry
528 CurrentTableList
= AllocatePool (sizeof (EFI_ACPI_TABLE_LIST
));
529 ASSERT (CurrentTableList
);
532 // Determine table type and size
534 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
)->Signature
;
535 CurrentTableSize
= ((EFI_ACPI_COMMON_HEADER
*) Table
)->Length
;
538 // Allocate a buffer for the table. All tables are allocated in the lower 32 bits of address space
539 // for backwards compatibility with ACPI 1.0 OS.
541 // This is done because ACPI 1.0 pointers are 32 bit values.
542 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
543 // There is no architectural reason these should be below 4GB, it is purely
544 // for convenience of implementation that we force memory below 4GB.
546 CurrentTableList
->PageAddress
= 0xFFFFFFFF;
547 CurrentTableList
->NumberOfPages
= EFI_SIZE_TO_PAGES (CurrentTableSize
);
550 // Allocation memory type depends on the type of the table
552 if ((CurrentTableSignature
== EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) ||
553 (CurrentTableSignature
== EFI_ACPI_4_0_UEFI_ACPI_DATA_TABLE_SIGNATURE
)) {
555 // Allocate memory for the FACS. This structure must be aligned
556 // on a 64 byte boundary and must be ACPI NVS memory.
557 // Using AllocatePages should ensure that it is always aligned.
558 // Do not change signature for new ACPI version because they are same.
560 // UEFI table also need to be in ACPI NVS memory, because some data field
561 // could be updated by OS present agent. For example, BufferPtrAddress in
562 // SMM communication ACPI table.
564 ASSERT ((EFI_PAGE_SIZE
% 64) == 0);
565 Status
= gBS
->AllocatePages (
568 CurrentTableList
->NumberOfPages
,
569 &CurrentTableList
->PageAddress
573 // All other tables are ACPI reclaim memory, no alignment requirements.
575 Status
= gBS
->AllocatePages (
577 EfiACPIReclaimMemory
,
578 CurrentTableList
->NumberOfPages
,
579 &CurrentTableList
->PageAddress
583 // Check return value from memory alloc.
585 if (EFI_ERROR (Status
)) {
586 gBS
->FreePool (CurrentTableList
);
587 return EFI_OUT_OF_RESOURCES
;
590 // Update the table pointer with the allocated memory start
592 CurrentTableList
->Table
= (EFI_ACPI_COMMON_HEADER
*) (UINTN
) CurrentTableList
->PageAddress
;
595 // Initialize the table contents
597 CurrentTableList
->Signature
= EFI_ACPI_TABLE_LIST_SIGNATURE
;
598 CopyMem (CurrentTableList
->Table
, Table
, CurrentTableSize
);
599 CurrentTableList
->Handle
= AcpiTableInstance
->CurrentHandle
++;
600 *Handle
= CurrentTableList
->Handle
;
601 CurrentTableList
->Version
= Version
;
604 // Update internal pointers if this is a required table. If it is a required
605 // table and a table of that type already exists, return an error.
607 // Calculate the checksum if the table is not FACS.
609 switch (CurrentTableSignature
) {
611 case EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
613 // We don't add the FADT in the standard way because some
614 // OS expect the FADT to be early in the table list.
615 // So we always add it as the first element in the list.
620 // Check that the table has not been previously added.
622 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Fadt1
!= NULL
) ||
623 ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0 && AcpiTableInstance
->Fadt3
!= NULL
)
625 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
626 gBS
->FreePool (CurrentTableList
);
627 return EFI_ACCESS_DENIED
;
630 // Add the table to the appropriate table version
632 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
634 // Save a pointer to the table
636 AcpiTableInstance
->Fadt1
= (EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE
*) CurrentTableList
->Table
;
639 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
641 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs1
;
642 AcpiTableInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt1
;
645 // RSDP OEM information is updated to match the FADT OEM information
648 &AcpiTableInstance
->Rsdp1
->OemId
,
649 &AcpiTableInstance
->Fadt1
->Header
.OemId
,
654 // RSDT OEM information is updated to match the FADT OEM information.
657 &AcpiTableInstance
->Rsdt1
->OemId
,
658 &AcpiTableInstance
->Fadt1
->Header
.OemId
,
663 &AcpiTableInstance
->Rsdt1
->OemTableId
,
664 &AcpiTableInstance
->Fadt1
->Header
.OemTableId
,
667 AcpiTableInstance
->Rsdt1
->OemRevision
= AcpiTableInstance
->Fadt1
->Header
.OemRevision
;
670 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
672 // Save a pointer to the table
674 AcpiTableInstance
->Fadt3
= (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE
*) CurrentTableList
->Table
;
677 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
678 // Note: If the FIRMWARE_CTRL is non-zero, then X_FIRMWARE_CTRL must be zero, and
681 if ((UINT64
)(UINTN
)AcpiTableInstance
->Facs3
< BASE_4GB
) {
682 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs3
;
683 ZeroMem (&AcpiTableInstance
->Fadt3
->XFirmwareCtrl
, sizeof (UINT64
));
685 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Facs3
;
687 &AcpiTableInstance
->Fadt3
->XFirmwareCtrl
,
691 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= 0;
693 if ((UINT64
)(UINTN
)AcpiTableInstance
->Dsdt3
< BASE_4GB
) {
694 AcpiTableInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt3
;
695 if (RequireDsdtXDsdtExclusion (AcpiTableInstance
->Fadt3
)) {
698 Buffer64
= AcpiTableInstance
->Fadt3
->Dsdt
;
701 AcpiTableInstance
->Fadt3
->Dsdt
= 0;
702 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Dsdt3
;
704 CopyMem (&AcpiTableInstance
->Fadt3
->XDsdt
, &Buffer64
, sizeof (UINT64
));
707 // RSDP OEM information is updated to match the FADT OEM information
710 &AcpiTableInstance
->Rsdp3
->OemId
,
711 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
715 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
717 // RSDT OEM information is updated to match FADT OEM information.
720 &AcpiTableInstance
->Rsdt3
->OemId
,
721 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
725 &AcpiTableInstance
->Rsdt3
->OemTableId
,
726 &AcpiTableInstance
->Fadt3
->Header
.OemTableId
,
729 AcpiTableInstance
->Rsdt3
->OemRevision
= AcpiTableInstance
->Fadt3
->Header
.OemRevision
;
733 // XSDT OEM information is updated to match FADT OEM information.
736 &AcpiTableInstance
->Xsdt
->OemId
,
737 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
741 &AcpiTableInstance
->Xsdt
->OemTableId
,
742 &AcpiTableInstance
->Fadt3
->Header
.OemTableId
,
745 AcpiTableInstance
->Xsdt
->OemRevision
= AcpiTableInstance
->Fadt3
->Header
.OemRevision
;
748 // Checksum the table
751 AcpiPlatformChecksum (
752 CurrentTableList
->Table
,
753 CurrentTableList
->Table
->Length
,
754 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
760 case EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
762 // Check that the table has not been previously added.
764 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Facs1
!= NULL
) ||
765 ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0 && AcpiTableInstance
->Facs3
!= NULL
)
767 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
768 gBS
->FreePool (CurrentTableList
);
769 return EFI_ACCESS_DENIED
;
772 // FACS is referenced by FADT and is not part of RSDT
777 // Add the table to the appropriate table version
779 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
781 // Save a pointer to the table
783 AcpiTableInstance
->Facs1
= (EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
786 // If FADT already exists, update table pointers.
788 if (AcpiTableInstance
->Fadt1
!= NULL
) {
789 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs1
;
792 // Checksum FADT table
794 AcpiPlatformChecksum (
795 AcpiTableInstance
->Fadt1
,
796 AcpiTableInstance
->Fadt1
->Header
.Length
,
797 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
803 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
805 // Save a pointer to the table
807 AcpiTableInstance
->Facs3
= (EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
810 // If FADT already exists, update table pointers.
812 if (AcpiTableInstance
->Fadt3
!= NULL
) {
814 // Note: If the FIRMWARE_CTRL is non-zero, then X_FIRMWARE_CTRL must be zero, and
817 if ((UINT64
)(UINTN
)AcpiTableInstance
->Facs3
< BASE_4GB
) {
818 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs3
;
819 ZeroMem (&AcpiTableInstance
->Fadt3
->XFirmwareCtrl
, sizeof (UINT64
));
821 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Facs3
;
823 &AcpiTableInstance
->Fadt3
->XFirmwareCtrl
,
827 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= 0;
831 // Checksum FADT table
833 AcpiPlatformChecksum (
834 AcpiTableInstance
->Fadt3
,
835 AcpiTableInstance
->Fadt3
->Header
.Length
,
836 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
844 case EFI_ACPI_1_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
846 // Check that the table has not been previously added.
848 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Dsdt1
!= NULL
) ||
849 ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0 && AcpiTableInstance
->Dsdt3
!= NULL
)
851 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
852 gBS
->FreePool (CurrentTableList
);
853 return EFI_ACCESS_DENIED
;
856 // DSDT is referenced by FADT and is not part of RSDT
861 // Add the table to the appropriate table version
863 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
865 // Save a pointer to the table
867 AcpiTableInstance
->Dsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
870 // If FADT already exists, update table pointers.
872 if (AcpiTableInstance
->Fadt1
!= NULL
) {
873 AcpiTableInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt1
;
876 // Checksum FADT table
878 AcpiPlatformChecksum (
879 AcpiTableInstance
->Fadt1
,
880 AcpiTableInstance
->Fadt1
->Header
.Length
,
881 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
887 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
889 // Save a pointer to the table
891 AcpiTableInstance
->Dsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
894 // If FADT already exists, update table pointers.
896 if (AcpiTableInstance
->Fadt3
!= NULL
) {
897 if ((UINT64
)(UINTN
)AcpiTableInstance
->Dsdt3
< BASE_4GB
) {
898 AcpiTableInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt3
;
899 if (RequireDsdtXDsdtExclusion (AcpiTableInstance
->Fadt3
)) {
902 Buffer64
= AcpiTableInstance
->Fadt3
->Dsdt
;
905 AcpiTableInstance
->Fadt3
->Dsdt
= 0;
906 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Dsdt3
;
908 CopyMem (&AcpiTableInstance
->Fadt3
->XDsdt
, &Buffer64
, sizeof (UINT64
));
911 // Checksum FADT table
913 AcpiPlatformChecksum (
914 AcpiTableInstance
->Fadt3
,
915 AcpiTableInstance
->Fadt3
->Header
.Length
,
916 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
922 // Checksum the table
925 AcpiPlatformChecksum (
926 CurrentTableList
->Table
,
927 CurrentTableList
->Table
->Length
,
928 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
936 // Checksum the table
939 AcpiPlatformChecksum (
940 CurrentTableList
->Table
,
941 CurrentTableList
->Table
->Length
,
942 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
949 // Add the table to the current list of tables
951 InsertTailList (&AcpiTableInstance
->TableList
, &CurrentTableList
->Link
);
954 // Add the table to RSDT and/or XSDT table entry lists.
957 // Add to ACPI 1.0b table tree
959 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
962 // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
964 if (AcpiTableInstance
->NumberOfTableEntries1
>= mEfiAcpiMaxNumTables
) {
965 Status
= ReallocateAcpiTableBuffer (AcpiTableInstance
);
966 ASSERT_EFI_ERROR (Status
);
968 CurrentRsdtEntry
= (UINT32
*)
970 (UINT8
*) AcpiTableInstance
->Rsdt1
+
971 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
972 AcpiTableInstance
->NumberOfTableEntries1
*
977 // Add entry to the RSDT unless its the FACS or DSDT
979 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
982 // Update RSDT length
984 AcpiTableInstance
->Rsdt1
->Length
= AcpiTableInstance
->Rsdt1
->Length
+ sizeof (UINT32
);
986 AcpiTableInstance
->NumberOfTableEntries1
++;
990 // Add to ACPI 2.0/3.0 table tree
992 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
995 // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
997 if (AcpiTableInstance
->NumberOfTableEntries3
>= mEfiAcpiMaxNumTables
) {
998 Status
= ReallocateAcpiTableBuffer (AcpiTableInstance
);
999 ASSERT_EFI_ERROR (Status
);
1002 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1004 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
1005 // If it becomes necessary to maintain separate table lists, changes will be required.
1007 CurrentRsdtEntry
= (UINT32
*)
1009 (UINT8
*) AcpiTableInstance
->Rsdt3
+
1010 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
1011 AcpiTableInstance
->NumberOfTableEntries3
*
1016 // Add entry to the RSDT
1018 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
1021 // Update RSDT length
1023 AcpiTableInstance
->Rsdt3
->Length
= AcpiTableInstance
->Rsdt3
->Length
+ sizeof (UINT32
);
1027 // This pointer must not be directly dereferenced as the XSDT entries may not
1028 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
1030 CurrentXsdtEntry
= (VOID
*)
1032 (UINT8
*) AcpiTableInstance
->Xsdt
+
1033 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
1034 AcpiTableInstance
->NumberOfTableEntries3
*
1039 // Add entry to XSDT, XSDT expects 64 bit pointers, but
1040 // the table pointers in XSDT are not aligned on 8 byte boundary.
1042 Buffer64
= (UINT64
) (UINTN
) CurrentTableList
->Table
;
1052 AcpiTableInstance
->Xsdt
->Length
= AcpiTableInstance
->Xsdt
->Length
+ sizeof (UINT64
);
1054 AcpiTableInstance
->NumberOfTableEntries3
++;
1058 ChecksumCommonTables (AcpiTableInstance
);
1064 This function finds the table specified by the handle and returns a pointer to it.
1065 If the handle is not found, EFI_NOT_FOUND is returned and the contents of Table are
1068 @param Handle Table to find.
1069 @param TableList Table list to search
1070 @param Table Pointer to table found.
1072 @return EFI_SUCCESS The function completed successfully.
1073 @return EFI_NOT_FOUND No table found matching the handle specified.
1079 IN LIST_ENTRY
*TableList
,
1080 OUT EFI_ACPI_TABLE_LIST
**Table
1083 LIST_ENTRY
*CurrentLink
;
1084 EFI_ACPI_TABLE_LIST
*CurrentTable
;
1087 // Check for invalid input parameters
1094 CurrentLink
= TableList
->ForwardLink
;
1096 while (CurrentLink
!= TableList
) {
1097 CurrentTable
= EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink
);
1098 if (CurrentTable
->Handle
== Handle
) {
1100 // Found handle, so return this table.
1102 *Table
= CurrentTable
;
1106 CurrentLink
= CurrentLink
->ForwardLink
;
1111 return EFI_NOT_FOUND
;
1116 This function removes a basic table from the RSDT and/or XSDT.
1117 For Acpi 1.0 tables, pass in the Rsdt.
1118 For Acpi 2.0 tables, pass in both Rsdt and Xsdt.
1120 @param Table Pointer to table found.
1121 @param NumberOfTableEntries Current number of table entries in the RSDT/XSDT
1122 @param Rsdt Pointer to the RSDT to remove from
1123 @param Xsdt Pointer to the Xsdt to remove from
1125 @return EFI_SUCCESS The function completed successfully.
1126 @return EFI_INVALID_PARAMETER The table was not found in both Rsdt and Xsdt.
1130 RemoveTableFromRsdt (
1131 IN OUT EFI_ACPI_TABLE_LIST
* Table
,
1132 IN OUT UINTN
*NumberOfTableEntries
,
1133 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Rsdt OPTIONAL
,
1134 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Xsdt OPTIONAL
1137 UINT32
*CurrentRsdtEntry
;
1138 VOID
*CurrentXsdtEntry
;
1139 UINT64 CurrentTablePointer64
;
1143 // Check for invalid input parameters
1146 ASSERT (NumberOfTableEntries
);
1147 ASSERT (Rsdt
|| Xsdt
);
1150 // Find the table entry in the RSDT and XSDT
1152 for (Index
= 0; Index
< *NumberOfTableEntries
; Index
++) {
1154 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
1155 // If it becomes necessary to maintain separate table lists, changes will be required.
1158 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) Rsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + Index
* sizeof (UINT32
));
1160 CurrentRsdtEntry
= NULL
;
1164 // This pointer must not be directly dereferenced as the XSDT entries may not
1165 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
1167 CurrentXsdtEntry
= (VOID
*) ((UINT8
*) Xsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + Index
* sizeof (UINT64
));
1170 // Read the entry value out of the XSDT
1172 CopyMem (&CurrentTablePointer64
, CurrentXsdtEntry
, sizeof (UINT64
));
1175 // Initialize to NULL
1177 CurrentXsdtEntry
= 0;
1178 CurrentTablePointer64
= 0;
1181 // Check if we have found the corresponding entry in both RSDT and XSDT
1183 if (((Rsdt
== NULL
) || *CurrentRsdtEntry
== (UINT32
) (UINTN
) Table
->Table
) &&
1184 ((Xsdt
== NULL
) || CurrentTablePointer64
== (UINT64
) (UINTN
) Table
->Table
)
1187 // Found entry, so copy all following entries and shrink table
1188 // We actually copy all + 1 to copy the initialized value of memory over
1192 CopyMem (CurrentRsdtEntry
, CurrentRsdtEntry
+ 1, (*NumberOfTableEntries
- Index
) * sizeof (UINT32
));
1193 Rsdt
->Length
= Rsdt
->Length
- sizeof (UINT32
);
1196 CopyMem (CurrentXsdtEntry
, ((UINT64
*) CurrentXsdtEntry
) + 1, (*NumberOfTableEntries
- Index
) * sizeof (UINT64
));
1197 Xsdt
->Length
= Xsdt
->Length
- sizeof (UINT64
);
1200 } else if (Index
+ 1 == *NumberOfTableEntries
) {
1202 // At the last entry, and table not found
1204 return EFI_INVALID_PARAMETER
;
1208 // Checksum the tables
1211 AcpiPlatformChecksum (
1214 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1220 AcpiPlatformChecksum (
1223 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1228 // Decrement the number of tables
1230 (*NumberOfTableEntries
)--;
1237 This function removes a table and frees any associated memory.
1239 @param AcpiTableInstance Instance of the protocol.
1240 @param Version Version(s) to delete.
1241 @param Table Pointer to table found.
1243 @return EFI_SUCCESS The function completed successfully.
1248 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
1249 IN EFI_ACPI_TABLE_VERSION Version
,
1250 IN OUT EFI_ACPI_TABLE_LIST
*Table
1253 UINT32 CurrentTableSignature
;
1254 BOOLEAN RemoveFromRsdt
;
1257 // Check for invalid input parameters
1259 ASSERT (AcpiTableInstance
);
1265 RemoveFromRsdt
= TRUE
;
1267 // Check for Table->Table
1269 ASSERT (Table
->Table
!= NULL
);
1270 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
->Table
)->Signature
;
1273 // Basic tasks to accomplish delete are:
1274 // Determine removal requirements (in RSDT/XSDT or not)
1275 // Remove entry from RSDT/XSDT
1276 // Remove any table references to the table
1277 // If no one is using the table
1278 // Free the table (removing pointers from private data and tables)
1280 // Free list structure
1283 // Determine if this table is in the RSDT or XSDT
1285 if ((CurrentTableSignature
== EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) ||
1286 (CurrentTableSignature
== EFI_ACPI_2_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
) ||
1287 (CurrentTableSignature
== EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
)
1289 RemoveFromRsdt
= FALSE
;
1292 // We don't remove the FADT in the standard way because some
1293 // OS expect the FADT to be early in the table list.
1294 // So we always put it as the first element in the list.
1296 if (CurrentTableSignature
== EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
) {
1297 RemoveFromRsdt
= FALSE
;
1301 // Remove the table from RSDT and XSDT
1303 if (Table
->Table
!= NULL
) {
1305 // This is a basic table, remove it from any lists and the Rsdt and/or Xsdt
1307 if (Version
& EFI_ACPI_TABLE_VERSION_NONE
& Table
->Version
) {
1309 // Remove this version from the table
1311 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_NONE
;
1314 if (Version
& EFI_ACPI_TABLE_VERSION_1_0B
& Table
->Version
) {
1316 // Remove this version from the table
1318 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_1_0B
;
1321 // Remove from Rsdt. We don't care about the return value because it is
1322 // acceptable for the table to not exist in Rsdt.
1323 // We didn't add some tables so we don't remove them.
1325 if (RemoveFromRsdt
) {
1326 RemoveTableFromRsdt (
1328 &AcpiTableInstance
->NumberOfTableEntries1
,
1329 AcpiTableInstance
->Rsdt1
,
1335 if (Version
& ACPI_TABLE_VERSION_GTE_2_0
& Table
->Version
) {
1337 // Remove this version from the table
1339 Table
->Version
= Table
->Version
&~(Version
& ACPI_TABLE_VERSION_GTE_2_0
);
1342 // Remove from Rsdt and Xsdt. We don't care about the return value
1343 // because it is acceptable for the table to not exist in Rsdt/Xsdt.
1344 // We didn't add some tables so we don't remove them.
1346 if (RemoveFromRsdt
) {
1347 RemoveTableFromRsdt (
1349 &AcpiTableInstance
->NumberOfTableEntries3
,
1350 AcpiTableInstance
->Rsdt3
,
1351 AcpiTableInstance
->Xsdt
1356 // Free the table, clean up any dependent tables and our private data pointers.
1358 switch (Table
->Table
->Signature
) {
1360 case EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
1361 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1362 AcpiTableInstance
->Fadt1
= NULL
;
1365 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
1366 AcpiTableInstance
->Fadt3
= NULL
;
1370 case EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
1371 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1372 AcpiTableInstance
->Facs1
= NULL
;
1375 // Update FADT table pointers
1377 if (AcpiTableInstance
->Fadt1
!= NULL
) {
1378 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= 0;
1383 AcpiPlatformChecksum (
1384 AcpiTableInstance
->Fadt1
,
1385 AcpiTableInstance
->Fadt1
->Header
.Length
,
1386 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1392 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
1393 AcpiTableInstance
->Facs3
= NULL
;
1396 // Update FADT table pointers
1398 if (AcpiTableInstance
->Fadt3
!= NULL
) {
1399 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= 0;
1400 ZeroMem (&AcpiTableInstance
->Fadt3
->XFirmwareCtrl
, sizeof (UINT64
));
1405 AcpiPlatformChecksum (
1406 AcpiTableInstance
->Fadt3
,
1407 AcpiTableInstance
->Fadt3
->Header
.Length
,
1408 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1415 case EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
1416 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1417 AcpiTableInstance
->Dsdt1
= NULL
;
1420 // Update FADT table pointers
1422 if (AcpiTableInstance
->Fadt1
!= NULL
) {
1423 AcpiTableInstance
->Fadt1
->Dsdt
= 0;
1428 AcpiPlatformChecksum (
1429 AcpiTableInstance
->Fadt1
,
1430 AcpiTableInstance
->Fadt1
->Header
.Length
,
1431 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1438 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
1439 AcpiTableInstance
->Dsdt3
= NULL
;
1442 // Update FADT table pointers
1444 if (AcpiTableInstance
->Fadt3
!= NULL
) {
1445 AcpiTableInstance
->Fadt3
->Dsdt
= 0;
1446 ZeroMem (&AcpiTableInstance
->Fadt3
->XDsdt
, sizeof (UINT64
));
1451 AcpiPlatformChecksum (
1452 AcpiTableInstance
->Fadt3
,
1453 AcpiTableInstance
->Fadt3
->Header
.Length
,
1454 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1469 // If no version is using this table anymore, remove and free list entry.
1471 if (Table
->Version
== 0) {
1475 gBS
->FreePages (Table
->PageAddress
, Table
->NumberOfPages
);
1476 RemoveEntryList (&(Table
->Link
));
1477 gBS
->FreePool (Table
);
1487 This function finds and removes the table specified by the handle.
1489 @param AcpiTableInstance Instance of the protocol.
1490 @param Version Bitmask of which versions to remove.
1491 @param Handle Table to remove.
1493 @return EFI_SUCCESS The function completed successfully.
1494 @return EFI_ABORTED An error occurred.
1495 @return EFI_NOT_FOUND Handle not found in table list.
1499 RemoveTableFromList (
1500 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
1501 IN EFI_ACPI_TABLE_VERSION Version
,
1505 EFI_ACPI_TABLE_LIST
*Table
;
1508 Table
= (EFI_ACPI_TABLE_LIST
*) NULL
;
1511 // Check for invalid input parameters
1513 ASSERT (AcpiTableInstance
);
1518 Status
= FindTableByHandle (
1520 &AcpiTableInstance
->TableList
,
1523 if (EFI_ERROR (Status
)) {
1524 return EFI_NOT_FOUND
;
1529 Status
= DeleteTable (AcpiTableInstance
, Version
, Table
);
1530 if (EFI_ERROR (Status
)) {
1534 // Completed successfully
1541 This function calculates and updates an UINT8 checksum.
1543 @param Buffer Pointer to buffer to checksum
1544 @param Size Number of bytes to checksum
1545 @param ChecksumOffset Offset to place the checksum result in
1547 @return EFI_SUCCESS The function completed successfully.
1551 AcpiPlatformChecksum (
1554 IN UINTN ChecksumOffset
1562 // Initialize pointer
1567 // set checksum to 0 first
1569 Ptr
[ChecksumOffset
] = 0;
1572 // add all content of buffer
1574 while ((Size
--) != 0) {
1575 Sum
= (UINT8
) (Sum
+ (*Ptr
++));
1581 Ptr
[ChecksumOffset
] = (UINT8
) (0xff - Sum
+ 1);
1588 Checksum all versions of the common tables, RSDP, RSDT, XSDT.
1590 @param AcpiTableInstance Protocol instance private data.
1592 @return EFI_SUCCESS The function completed successfully.
1596 ChecksumCommonTables (
1597 IN OUT EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
1601 // RSDP ACPI 1.0 checksum for 1.0 table. This is only the first 20 bytes of the structure
1603 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1604 AcpiPlatformChecksum (
1605 AcpiTableInstance
->Rsdp1
,
1606 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1607 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1613 // RSDP ACPI 1.0 checksum for 2.0/3.0 table. This is only the first 20 bytes of the structure
1615 AcpiPlatformChecksum (
1616 AcpiTableInstance
->Rsdp3
,
1617 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1618 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1623 // RSDP ACPI 2.0/3.0 checksum, this is the entire table
1625 AcpiPlatformChecksum (
1626 AcpiTableInstance
->Rsdp3
,
1627 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1628 OFFSET_OF (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1632 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1636 AcpiPlatformChecksum (
1637 AcpiTableInstance
->Rsdt1
,
1638 AcpiTableInstance
->Rsdt1
->Length
,
1639 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1643 AcpiPlatformChecksum (
1644 AcpiTableInstance
->Rsdt3
,
1645 AcpiTableInstance
->Rsdt3
->Length
,
1646 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1654 AcpiPlatformChecksum (
1655 AcpiTableInstance
->Xsdt
,
1656 AcpiTableInstance
->Xsdt
->Length
,
1657 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1666 Constructor for the ACPI table protocol. Initializes instance
1669 @param AcpiTableInstance Instance to construct
1671 @return EFI_SUCCESS Instance initialized.
1672 @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
1676 AcpiTableAcpiTableConstructor (
1677 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
1683 UINTN RsdpTableSize
;
1685 EFI_PHYSICAL_ADDRESS PageAddress
;
1688 // Check for invalid input parameters
1690 ASSERT (AcpiTableInstance
);
1693 // If ACPI v1.0b is among the ACPI versions we aim to support, we have to
1694 // ensure that all memory allocations are below 4 GB.
1696 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1697 mAcpiTableAllocType
= AllocateMaxAddress
;
1699 mAcpiTableAllocType
= AllocateAnyPages
;
1702 InitializeListHead (&AcpiTableInstance
->TableList
);
1703 AcpiTableInstance
->CurrentHandle
= 1;
1705 AcpiTableInstance
->AcpiTableProtocol
.InstallAcpiTable
= InstallAcpiTable
;
1706 AcpiTableInstance
->AcpiTableProtocol
.UninstallAcpiTable
= UninstallAcpiTable
;
1708 if (FeaturePcdGet (PcdInstallAcpiSdtProtocol
)) {
1709 SdtAcpiTableAcpiSdtConstructor (AcpiTableInstance
);
1713 // Create RSDP table
1715 RsdpTableSize
= sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1716 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1717 RsdpTableSize
+= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1720 PageAddress
= 0xFFFFFFFF;
1721 Status
= gBS
->AllocatePages (
1722 mAcpiTableAllocType
,
1723 EfiACPIReclaimMemory
,
1724 EFI_SIZE_TO_PAGES (RsdpTableSize
),
1728 if (EFI_ERROR (Status
)) {
1729 return EFI_OUT_OF_RESOURCES
;
1732 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
1733 ZeroMem (Pointer
, RsdpTableSize
);
1735 AcpiTableInstance
->Rsdp1
= (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1736 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1737 Pointer
+= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1739 AcpiTableInstance
->Rsdp3
= (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1742 // Create RSDT, XSDT structures
1744 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
1745 mEfiAcpiMaxNumTables
* sizeof (UINT64
);
1747 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1748 TotalSize
+= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
1749 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
1750 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
1751 mEfiAcpiMaxNumTables
* sizeof (UINT32
);
1755 // Allocate memory in the lower 32 bit of address range for
1756 // compatibility with ACPI 1.0 OS.
1758 // This is done because ACPI 1.0 pointers are 32 bit values.
1759 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
1760 // There is no architectural reason these should be below 4GB, it is purely
1761 // for convenience of implementation that we force memory below 4GB.
1763 PageAddress
= 0xFFFFFFFF;
1764 Status
= gBS
->AllocatePages (
1765 mAcpiTableAllocType
,
1766 EfiACPIReclaimMemory
,
1767 EFI_SIZE_TO_PAGES (TotalSize
),
1771 if (EFI_ERROR (Status
)) {
1772 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
)(UINTN
)AcpiTableInstance
->Rsdp1
, EFI_SIZE_TO_PAGES (RsdpTableSize
));
1773 return EFI_OUT_OF_RESOURCES
;
1776 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
1777 ZeroMem (Pointer
, TotalSize
);
1779 AcpiTableInstance
->Rsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1780 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1781 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1782 AcpiTableInstance
->Rsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1783 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1785 AcpiTableInstance
->Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1790 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1791 CurrentData
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1792 CopyMem (&AcpiTableInstance
->Rsdp1
->Signature
, &CurrentData
, sizeof (UINT64
));
1793 CopyMem (AcpiTableInstance
->Rsdp1
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdp1
->OemId
));
1794 AcpiTableInstance
->Rsdp1
->Reserved
= EFI_ACPI_RESERVED_BYTE
;
1795 AcpiTableInstance
->Rsdp1
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt1
;
1798 CurrentData
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1799 CopyMem (&AcpiTableInstance
->Rsdp3
->Signature
, &CurrentData
, sizeof (UINT64
));
1800 CopyMem (AcpiTableInstance
->Rsdp3
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdp3
->OemId
));
1801 AcpiTableInstance
->Rsdp3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION
;
1802 AcpiTableInstance
->Rsdp3
->Length
= sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1803 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1804 AcpiTableInstance
->Rsdp3
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt3
;
1806 CurrentData
= (UINT64
) (UINTN
) AcpiTableInstance
->Xsdt
;
1807 CopyMem (&AcpiTableInstance
->Rsdp3
->XsdtAddress
, &CurrentData
, sizeof (UINT64
));
1808 SetMem (AcpiTableInstance
->Rsdp3
->Reserved
, 3, EFI_ACPI_RESERVED_BYTE
);
1810 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1814 // Note that we "reserve" one entry for the FADT so it can always be
1815 // at the beginning of the list of tables. Some OS don't seem
1816 // to find it correctly if it is too far down the list.
1818 AcpiTableInstance
->Rsdt1
->Signature
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1819 AcpiTableInstance
->Rsdt1
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1820 AcpiTableInstance
->Rsdt1
->Revision
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1821 CopyMem (AcpiTableInstance
->Rsdt1
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdt1
->OemId
));
1822 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1823 CopyMem (&AcpiTableInstance
->Rsdt1
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1824 AcpiTableInstance
->Rsdt1
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1825 AcpiTableInstance
->Rsdt1
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1826 AcpiTableInstance
->Rsdt1
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1828 // We always reserve first one for FADT
1830 AcpiTableInstance
->NumberOfTableEntries1
= 1;
1831 AcpiTableInstance
->Rsdt1
->Length
= AcpiTableInstance
->Rsdt1
->Length
+ sizeof(UINT32
);
1833 AcpiTableInstance
->Rsdt3
->Signature
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1834 AcpiTableInstance
->Rsdt3
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1835 AcpiTableInstance
->Rsdt3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1836 CopyMem (AcpiTableInstance
->Rsdt3
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdt3
->OemId
));
1837 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1838 CopyMem (&AcpiTableInstance
->Rsdt3
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1839 AcpiTableInstance
->Rsdt3
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1840 AcpiTableInstance
->Rsdt3
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1841 AcpiTableInstance
->Rsdt3
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1843 // We always reserve first one for FADT
1845 AcpiTableInstance
->Rsdt3
->Length
= AcpiTableInstance
->Rsdt3
->Length
+ sizeof(UINT32
);
1847 AcpiTableInstance
->NumberOfTableEntries3
= 1;
1852 AcpiTableInstance
->Xsdt
->Signature
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1853 AcpiTableInstance
->Xsdt
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1854 AcpiTableInstance
->Xsdt
->Revision
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1855 CopyMem (AcpiTableInstance
->Xsdt
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Xsdt
->OemId
));
1856 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1857 CopyMem (&AcpiTableInstance
->Xsdt
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1858 AcpiTableInstance
->Xsdt
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1859 AcpiTableInstance
->Xsdt
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1860 AcpiTableInstance
->Xsdt
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1862 // We always reserve first one for FADT
1864 AcpiTableInstance
->Xsdt
->Length
= AcpiTableInstance
->Xsdt
->Length
+ sizeof(UINT64
);
1866 ChecksumCommonTables (AcpiTableInstance
);
1869 // Completed successfully