2 ACPI Table Protocol Implementation
4 Copyright (c) 2006 - 2013, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include "AcpiTable.h"
20 // The maximum number of tables that pre-allocated.
22 UINTN mEfiAcpiMaxNumTables
= EFI_ACPI_MAX_NUM_TABLES
;
25 This function adds an ACPI table to the table list. It will detect FACS and
26 allocate the correct type of memory and properly align the table.
28 @param AcpiTableInstance Instance of the protocol.
29 @param Table Table to add.
30 @param Checksum Does the table require checksumming.
31 @param Version The version of the list to add the table to.
32 @param Handle Pointer for returning the handle.
34 @return EFI_SUCCESS The function completed successfully.
35 @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
36 @return EFI_ABORTED The table is a duplicate of a table that is required
42 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
45 IN EFI_ACPI_TABLE_VERSION Version
,
50 This function finds and removes the table specified by the handle.
52 @param AcpiTableInstance Instance of the protocol.
53 @param Version Bitmask of which versions to remove.
54 @param Handle Table to remove.
56 @return EFI_SUCCESS The function completed successfully.
57 @return EFI_ABORTED An error occurred.
58 @return EFI_NOT_FOUND Handle not found in table list.
63 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
64 IN EFI_ACPI_TABLE_VERSION Version
,
69 This function calculates and updates an UINT8 checksum.
71 @param Buffer Pointer to buffer to checksum
72 @param Size Number of bytes to checksum
73 @param ChecksumOffset Offset to place the checksum result in
75 @return EFI_SUCCESS The function completed successfully.
78 AcpiPlatformChecksum (
81 IN UINTN ChecksumOffset
85 Checksum all versions of the common tables, RSDP, RSDT, XSDT.
87 @param AcpiTableInstance Protocol instance private data.
89 @return EFI_SUCCESS The function completed successfully.
93 ChecksumCommonTables (
94 IN OUT EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
98 // Protocol function implementations.
102 This function adds, removes, or updates ACPI tables. If the address is not
103 null and the handle value is null, the table is added. If both the address and
104 handle are not null, the table at handle is updated with the table at address.
105 If the address is null and the handle is not, the table at handle is deleted.
107 @param AcpiTableInstance Instance of the protocol.
108 @param Table Pointer to a table.
109 @param Checksum Boolean indicating if the checksum should be calculated.
110 @param Version Version(s) to set.
111 @param Handle Handle of the table.
113 @return EFI_SUCCESS The function completed successfully.
114 @return EFI_INVALID_PARAMETER Both the Table and *Handle were NULL.
115 @return EFI_ABORTED Could not complete the desired request.
121 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
122 IN VOID
*Table OPTIONAL
,
124 IN EFI_ACPI_TABLE_VERSION Version
,
132 // Check for invalid input parameters
140 // Determine desired action
145 // Invalid parameter combination
147 return EFI_INVALID_PARAMETER
;
152 Status
= AddTableToList (AcpiTableInstance
, Table
, Checksum
, Version
, Handle
);
160 // Delete the table list entry
162 Status
= RemoveTableFromList (AcpiTableInstance
, Version
, *Handle
);
163 if (EFI_ERROR (Status
)) {
165 // Should not get an error here ever, but abort if we do.
170 // Set the handle to replace the table at the same handle
172 SavedHandle
= AcpiTableInstance
->CurrentHandle
;
173 AcpiTableInstance
->CurrentHandle
= *Handle
;
178 Status
= AddTableToList (AcpiTableInstance
, Table
, Checksum
, Version
, Handle
);
181 // Restore the saved current handle
183 AcpiTableInstance
->CurrentHandle
= SavedHandle
;
188 Status
= RemoveTableFromList (AcpiTableInstance
, Version
, *Handle
);
192 if (EFI_ERROR (Status
)) {
194 // Should not get an error here ever, but abort if we do.
205 This function publishes the specified versions of the ACPI tables by
206 installing EFI configuration table entries for them. Any combination of
207 table versions can be published.
209 @param AcpiTableInstance Instance of the protocol.
210 @param Version Version(s) to publish.
212 @return EFI_SUCCESS The function completed successfully.
213 @return EFI_ABORTED The function could not complete successfully.
219 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
220 IN EFI_ACPI_TABLE_VERSION Version
224 UINT32
*CurrentRsdtEntry
;
225 VOID
*CurrentXsdtEntry
;
229 // Reorder tables as some operating systems don't seem to find the
230 // FADT correctly if it is not in the first few entries
234 // Add FADT as the first entry
236 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
237 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) AcpiTableInstance
->Rsdt1
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
238 *CurrentRsdtEntry
= (UINT32
) (UINTN
) AcpiTableInstance
->Fadt1
;
240 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
241 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
242 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) AcpiTableInstance
->Rsdt3
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
243 *CurrentRsdtEntry
= (UINT32
) (UINTN
) AcpiTableInstance
->Fadt3
;
244 CurrentXsdtEntry
= (VOID
*) ((UINT8
*) AcpiTableInstance
->Xsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
246 // Add entry to XSDT, XSDT expects 64 bit pointers, but
247 // the table pointers in XSDT are not aligned on 8 byte boundary.
249 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Fadt3
;
258 // Do checksum again because Dsdt/Xsdt is updated.
260 ChecksumCommonTables (AcpiTableInstance
);
263 // Add the RSD_PTR to the system table and store that we have installed the
266 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) &&
267 !AcpiTableInstance
->TablesInstalled1
) {
268 Status
= gBS
->InstallConfigurationTable (&gEfiAcpi10TableGuid
, AcpiTableInstance
->Rsdp1
);
269 if (EFI_ERROR (Status
)) {
273 AcpiTableInstance
->TablesInstalled1
= TRUE
;
276 if (((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
277 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) &&
278 !AcpiTableInstance
->TablesInstalled3
) {
279 Status
= gBS
->InstallConfigurationTable (&gEfiAcpiTableGuid
, AcpiTableInstance
->Rsdp3
);
280 if (EFI_ERROR (Status
)) {
284 AcpiTableInstance
->TablesInstalled3
= TRUE
;
292 Installs an ACPI table into the RSDT/XSDT.
293 Note that the ACPI table should be checksumed before installing it.
294 Otherwise it will assert.
296 @param This Protocol instance pointer.
297 @param AcpiTableBuffer A pointer to a buffer containing the ACPI table to be installed.
298 @param AcpiTableBufferSize Specifies the size, in bytes, of the AcpiTableBuffer buffer.
299 @param TableKey Reurns a key to refer to the ACPI table.
301 @return EFI_SUCCESS The table was successfully inserted.
302 @return EFI_INVALID_PARAMETER Either AcpiTableBuffer is NULL, TableKey is NULL, or AcpiTableBufferSize
303 and the size field embedded in the ACPI table pointed to by AcpiTableBuffer
305 @return EFI_OUT_OF_RESOURCES Insufficient resources exist to complete the request.
311 IN EFI_ACPI_TABLE_PROTOCOL
*This
,
312 IN VOID
*AcpiTableBuffer
,
313 IN UINTN AcpiTableBufferSize
,
317 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
;
319 VOID
*AcpiTableBufferConst
;
322 // Check for invalid input parameters
324 if ((AcpiTableBuffer
== NULL
) || (TableKey
== NULL
)
325 || (((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTableBuffer
)->Length
!= AcpiTableBufferSize
)) {
326 return EFI_INVALID_PARAMETER
;
330 // Get the instance of the ACPI table protocol
332 AcpiTableInstance
= EFI_ACPI_TABLE_INSTANCE_FROM_THIS (This
);
335 // Install the ACPI table
337 AcpiTableBufferConst
= AllocateCopyPool (AcpiTableBufferSize
,AcpiTableBuffer
);
339 Status
= SetAcpiTable (
341 AcpiTableBufferConst
,
343 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
,
346 if (!EFI_ERROR (Status
)) {
347 Status
= PublishTables (
349 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
352 FreePool (AcpiTableBufferConst
);
355 // Add a new table successfully, notify registed callback
357 if (FeaturePcdGet (PcdInstallAcpiSdtProtocol
)) {
358 if (!EFI_ERROR (Status
)) {
361 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
,
372 Removes an ACPI table from the RSDT/XSDT.
374 @param This Protocol instance pointer.
375 @param TableKey Specifies the table to uninstall. The key was returned from InstallAcpiTable().
377 @return EFI_SUCCESS The table was successfully uninstalled.
378 @return EFI_NOT_FOUND TableKey does not refer to a valid key for a table entry.
384 IN EFI_ACPI_TABLE_PROTOCOL
*This
,
388 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
;
392 // Get the instance of the ACPI table protocol
394 AcpiTableInstance
= EFI_ACPI_TABLE_INSTANCE_FROM_THIS (This
);
397 // Uninstall the ACPI table
399 Status
= SetAcpiTable (
403 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
,
406 if (!EFI_ERROR (Status
)) {
407 Status
= PublishTables (
409 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
413 if (EFI_ERROR (Status
)) {
414 return EFI_NOT_FOUND
;
421 If the number of APCI tables exceeds the preallocated max table number, enlarge the table buffer.
423 @param AcpiTableInstance ACPI table protocol instance data structure.
425 @return EFI_SUCCESS reallocate the table beffer successfully.
426 @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
430 ReallocateAcpiTableBuffer (
431 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
434 UINTN NewMaxTableNumber
;
437 EFI_PHYSICAL_ADDRESS PageAddress
;
438 EFI_ACPI_TABLE_INSTANCE TempPrivateData
;
442 CopyMem (&TempPrivateData
, AcpiTableInstance
, sizeof (EFI_ACPI_TABLE_INSTANCE
));
444 // Enlarge the max table number from mEfiAcpiMaxNumTables to mEfiAcpiMaxNumTables + EFI_ACPI_MAX_NUM_TABLES
446 NewMaxTableNumber
= mEfiAcpiMaxNumTables
+ EFI_ACPI_MAX_NUM_TABLES
;
448 // Create RSDT, XSDT structures and allocate buffers.
450 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
451 NewMaxTableNumber
* sizeof (UINT32
) +
452 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
453 NewMaxTableNumber
* sizeof (UINT32
) +
454 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
455 NewMaxTableNumber
* sizeof (UINT64
);
458 // Allocate memory in the lower 32 bit of address range for
459 // compatibility with ACPI 1.0 OS.
461 // This is done because ACPI 1.0 pointers are 32 bit values.
462 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
463 // There is no architectural reason these should be below 4GB, it is purely
464 // for convenience of implementation that we force memory below 4GB.
466 PageAddress
= 0xFFFFFFFF;
467 Status
= gBS
->AllocatePages (
469 EfiACPIReclaimMemory
,
470 EFI_SIZE_TO_PAGES (TotalSize
),
474 if (EFI_ERROR (Status
)) {
475 return EFI_OUT_OF_RESOURCES
;
478 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
479 ZeroMem (Pointer
, TotalSize
);
481 AcpiTableInstance
->Rsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
482 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + NewMaxTableNumber
* sizeof (UINT32
));
483 AcpiTableInstance
->Rsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
484 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + NewMaxTableNumber
* sizeof (UINT32
));
485 AcpiTableInstance
->Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
488 // Update RSDP to point to the new Rsdt and Xsdt address.
490 AcpiTableInstance
->Rsdp1
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt1
;
491 AcpiTableInstance
->Rsdp3
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt3
;
492 CurrentData
= (UINT64
) (UINTN
) AcpiTableInstance
->Xsdt
;
493 CopyMem (&AcpiTableInstance
->Rsdp3
->XsdtAddress
, &CurrentData
, sizeof (UINT64
));
496 // copy the original Rsdt1, Rsdt3 and Xsdt structure to new buffer
498 CopyMem (AcpiTableInstance
->Rsdt1
, TempPrivateData
.Rsdt1
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT32
)));
499 CopyMem (AcpiTableInstance
->Rsdt3
, TempPrivateData
.Rsdt3
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT32
)));
500 CopyMem (AcpiTableInstance
->Xsdt
, TempPrivateData
.Xsdt
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT64
)));
503 // Calculate orignal ACPI table buffer size
505 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
506 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
507 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
508 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
509 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
510 mEfiAcpiMaxNumTables
* sizeof (UINT64
);
511 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
)(UINTN
)TempPrivateData
.Rsdt1
, EFI_SIZE_TO_PAGES (TotalSize
));
514 // Update the Max ACPI table number
516 mEfiAcpiMaxNumTables
= NewMaxTableNumber
;
520 This function adds an ACPI table to the table list. It will detect FACS and
521 allocate the correct type of memory and properly align the table.
523 @param AcpiTableInstance Instance of the protocol.
524 @param Table Table to add.
525 @param Checksum Does the table require checksumming.
526 @param Version The version of the list to add the table to.
527 @param Handle Pointer for returning the handle.
529 @return EFI_SUCCESS The function completed successfully.
530 @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
531 @return EFI_ABORTED The table is a duplicate of a table that is required
537 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
540 IN EFI_ACPI_TABLE_VERSION Version
,
545 EFI_ACPI_TABLE_LIST
*CurrentTableList
;
546 UINT32 CurrentTableSignature
;
547 UINT32 CurrentTableSize
;
548 UINT32
*CurrentRsdtEntry
;
549 VOID
*CurrentXsdtEntry
;
554 // Check for invalid input parameters
556 ASSERT (AcpiTableInstance
);
566 // Create a new list entry
568 CurrentTableList
= AllocatePool (sizeof (EFI_ACPI_TABLE_LIST
));
569 ASSERT (CurrentTableList
);
572 // Determine table type and size
574 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
)->Signature
;
575 CurrentTableSize
= ((EFI_ACPI_COMMON_HEADER
*) Table
)->Length
;
578 // Allocate a buffer for the table. All tables are allocated in the lower 32 bits of address space
579 // for backwards compatibility with ACPI 1.0 OS.
581 // This is done because ACPI 1.0 pointers are 32 bit values.
582 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
583 // There is no architectural reason these should be below 4GB, it is purely
584 // for convenience of implementation that we force memory below 4GB.
586 CurrentTableList
->PageAddress
= 0xFFFFFFFF;
587 CurrentTableList
->NumberOfPages
= EFI_SIZE_TO_PAGES (CurrentTableSize
);
590 // Allocation memory type depends on the type of the table
592 if ((CurrentTableSignature
== EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) ||
593 (CurrentTableSignature
== EFI_ACPI_4_0_UEFI_ACPI_DATA_TABLE_SIGNATURE
)) {
595 // Allocate memory for the FACS. This structure must be aligned
596 // on a 64 byte boundary and must be ACPI NVS memory.
597 // Using AllocatePages should ensure that it is always aligned.
598 // Do not change signature for new ACPI version because they are same.
600 // UEFI table also need to be in ACPI NVS memory, because some data field
601 // could be updated by OS present agent. For example, BufferPtrAddress in
602 // SMM communication ACPI table.
604 ASSERT ((EFI_PAGE_SIZE
% 64) == 0);
605 Status
= gBS
->AllocatePages (
608 CurrentTableList
->NumberOfPages
,
609 &CurrentTableList
->PageAddress
613 // All other tables are ACPI reclaim memory, no alignment requirements.
615 Status
= gBS
->AllocatePages (
617 EfiACPIReclaimMemory
,
618 CurrentTableList
->NumberOfPages
,
619 &CurrentTableList
->PageAddress
623 // Check return value from memory alloc.
625 if (EFI_ERROR (Status
)) {
626 gBS
->FreePool (CurrentTableList
);
627 return EFI_OUT_OF_RESOURCES
;
630 // Update the table pointer with the allocated memory start
632 CurrentTableList
->Table
= (EFI_ACPI_COMMON_HEADER
*) (UINTN
) CurrentTableList
->PageAddress
;
635 // Initialize the table contents
637 CurrentTableList
->Signature
= EFI_ACPI_TABLE_LIST_SIGNATURE
;
638 CopyMem (CurrentTableList
->Table
, Table
, CurrentTableSize
);
639 CurrentTableList
->Handle
= AcpiTableInstance
->CurrentHandle
++;
640 *Handle
= CurrentTableList
->Handle
;
641 CurrentTableList
->Version
= Version
;
644 // Update internal pointers if this is a required table. If it is a required
645 // table and a table of that type already exists, return an error.
647 // Calculate the checksum if the table is not FACS.
649 switch (CurrentTableSignature
) {
651 case EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
653 // We don't add the FADT in the standard way because some
654 // OS expect the FADT to be early in the table list.
655 // So we always add it as the first element in the list.
660 // Check that the table has not been previously added.
662 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Fadt1
!= NULL
) ||
663 ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 && AcpiTableInstance
->Fadt3
!= NULL
) ||
664 ((Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0 && AcpiTableInstance
->Fadt3
!= NULL
)
666 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
667 gBS
->FreePool (CurrentTableList
);
671 // Add the table to the appropriate table version
673 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
675 // Save a pointer to the table
677 AcpiTableInstance
->Fadt1
= (EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE
*) CurrentTableList
->Table
;
680 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
682 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs1
;
683 AcpiTableInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt1
;
686 // RSDP OEM information is updated to match the FADT OEM information
689 &AcpiTableInstance
->Rsdp1
->OemId
,
690 &AcpiTableInstance
->Fadt1
->Header
.OemId
,
695 // RSDT OEM information is updated to match the FADT OEM information.
698 &AcpiTableInstance
->Rsdt1
->OemId
,
699 &AcpiTableInstance
->Fadt1
->Header
.OemId
,
704 &AcpiTableInstance
->Rsdt1
->OemTableId
,
705 &AcpiTableInstance
->Fadt1
->Header
.OemTableId
,
708 AcpiTableInstance
->Rsdt1
->OemRevision
= AcpiTableInstance
->Fadt1
->Header
.OemRevision
;
711 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
712 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
714 // Save a pointer to the table
716 AcpiTableInstance
->Fadt3
= (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE
*) CurrentTableList
->Table
;
719 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
720 // Note: If the FIRMWARE_CTRL is non-zero, then X_FIRMWARE_CTRL must be zero, and
723 if ((UINT64
)(UINTN
)AcpiTableInstance
->Facs3
< BASE_4GB
) {
724 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs3
;
726 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Facs3
;
728 &AcpiTableInstance
->Fadt3
->XFirmwareCtrl
,
733 AcpiTableInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt3
;
734 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Dsdt3
;
736 &AcpiTableInstance
->Fadt3
->XDsdt
,
742 // RSDP OEM information is updated to match the FADT OEM information
745 &AcpiTableInstance
->Rsdp3
->OemId
,
746 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
751 // RSDT OEM information is updated to match FADT OEM information.
754 &AcpiTableInstance
->Rsdt3
->OemId
,
755 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
759 &AcpiTableInstance
->Rsdt3
->OemTableId
,
760 &AcpiTableInstance
->Fadt3
->Header
.OemTableId
,
763 AcpiTableInstance
->Rsdt3
->OemRevision
= AcpiTableInstance
->Fadt3
->Header
.OemRevision
;
766 // XSDT OEM information is updated to match FADT OEM information.
769 &AcpiTableInstance
->Xsdt
->OemId
,
770 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
774 &AcpiTableInstance
->Xsdt
->OemTableId
,
775 &AcpiTableInstance
->Fadt3
->Header
.OemTableId
,
778 AcpiTableInstance
->Xsdt
->OemRevision
= AcpiTableInstance
->Fadt3
->Header
.OemRevision
;
781 // Checksum the table
784 AcpiPlatformChecksum (
785 CurrentTableList
->Table
,
786 CurrentTableList
->Table
->Length
,
787 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
793 case EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
795 // Check that the table has not been previously added.
797 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Facs1
!= NULL
) ||
798 ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 && AcpiTableInstance
->Facs3
!= NULL
) ||
799 ((Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0 && AcpiTableInstance
->Facs3
!= NULL
)
801 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
802 gBS
->FreePool (CurrentTableList
);
806 // FACS is referenced by FADT and is not part of RSDT
811 // Add the table to the appropriate table version
813 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
815 // Save a pointer to the table
817 AcpiTableInstance
->Facs1
= (EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
820 // If FADT already exists, update table pointers.
822 if (AcpiTableInstance
->Fadt1
!= NULL
) {
823 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs1
;
826 // Checksum FADT table
828 AcpiPlatformChecksum (
829 AcpiTableInstance
->Fadt1
,
830 AcpiTableInstance
->Fadt1
->Header
.Length
,
831 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
837 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
838 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
840 // Save a pointer to the table
842 AcpiTableInstance
->Facs3
= (EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
845 // If FADT already exists, update table pointers.
847 if (AcpiTableInstance
->Fadt3
!= NULL
) {
849 // Note: If the FIRMWARE_CTRL is non-zero, then X_FIRMWARE_CTRL must be zero, and
852 if ((UINT64
)(UINTN
)AcpiTableInstance
->Facs3
< BASE_4GB
) {
853 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs3
;
855 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Facs3
;
857 &AcpiTableInstance
->Fadt3
->XFirmwareCtrl
,
864 // Checksum FADT table
866 AcpiPlatformChecksum (
867 AcpiTableInstance
->Fadt3
,
868 AcpiTableInstance
->Fadt3
->Header
.Length
,
869 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
877 case EFI_ACPI_1_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
879 // Check that the table has not been previously added.
881 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Dsdt1
!= NULL
) ||
882 ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 && AcpiTableInstance
->Dsdt3
!= NULL
) ||
883 ((Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0 && AcpiTableInstance
->Dsdt3
!= NULL
)
885 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
886 gBS
->FreePool (CurrentTableList
);
890 // DSDT is referenced by FADT and is not part of RSDT
895 // Add the table to the appropriate table version
897 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
899 // Save a pointer to the table
901 AcpiTableInstance
->Dsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
904 // If FADT already exists, update table pointers.
906 if (AcpiTableInstance
->Fadt1
!= NULL
) {
907 AcpiTableInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt1
;
910 // Checksum FADT table
912 AcpiPlatformChecksum (
913 AcpiTableInstance
->Fadt1
,
914 AcpiTableInstance
->Fadt1
->Header
.Length
,
915 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
921 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
922 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
924 // Save a pointer to the table
926 AcpiTableInstance
->Dsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
929 // If FADT already exists, update table pointers.
931 if (AcpiTableInstance
->Fadt3
!= NULL
) {
932 AcpiTableInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt3
;
933 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Dsdt3
;
935 &AcpiTableInstance
->Fadt3
->XDsdt
,
941 // Checksum FADT table
943 AcpiPlatformChecksum (
944 AcpiTableInstance
->Fadt3
,
945 AcpiTableInstance
->Fadt3
->Header
.Length
,
946 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
952 // Checksum the table
955 AcpiPlatformChecksum (
956 CurrentTableList
->Table
,
957 CurrentTableList
->Table
->Length
,
958 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
966 // Checksum the table
969 AcpiPlatformChecksum (
970 CurrentTableList
->Table
,
971 CurrentTableList
->Table
->Length
,
972 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
979 // Add the table to the current list of tables
981 InsertTailList (&AcpiTableInstance
->TableList
, &CurrentTableList
->Link
);
984 // Add the table to RSDT and/or XSDT table entry lists.
987 // Add to ACPI 1.0b table tree
989 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
992 // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
994 if (AcpiTableInstance
->NumberOfTableEntries1
>= mEfiAcpiMaxNumTables
) {
995 Status
= ReallocateAcpiTableBuffer (AcpiTableInstance
);
996 ASSERT_EFI_ERROR (Status
);
998 CurrentRsdtEntry
= (UINT32
*)
1000 (UINT8
*) AcpiTableInstance
->Rsdt1
+
1001 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
1002 AcpiTableInstance
->NumberOfTableEntries1
*
1007 // Add entry to the RSDT unless its the FACS or DSDT
1009 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
1012 // Update RSDT length
1014 AcpiTableInstance
->Rsdt1
->Length
= AcpiTableInstance
->Rsdt1
->Length
+ sizeof (UINT32
);
1016 AcpiTableInstance
->NumberOfTableEntries1
++;
1020 // Add to ACPI 2.0/3.0 table tree
1022 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
1023 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1026 // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
1028 if (AcpiTableInstance
->NumberOfTableEntries3
>= mEfiAcpiMaxNumTables
) {
1029 Status
= ReallocateAcpiTableBuffer (AcpiTableInstance
);
1030 ASSERT_EFI_ERROR (Status
);
1033 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
1034 // If it becomes necessary to maintain separate table lists, changes will be required.
1036 CurrentRsdtEntry
= (UINT32
*)
1038 (UINT8
*) AcpiTableInstance
->Rsdt3
+
1039 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
1040 AcpiTableInstance
->NumberOfTableEntries3
*
1045 // This pointer must not be directly dereferenced as the XSDT entries may not
1046 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
1048 CurrentXsdtEntry
= (VOID
*)
1050 (UINT8
*) AcpiTableInstance
->Xsdt
+
1051 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
1052 AcpiTableInstance
->NumberOfTableEntries3
*
1057 // Add entry to the RSDT
1059 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
1062 // Update RSDT length
1064 AcpiTableInstance
->Rsdt3
->Length
= AcpiTableInstance
->Rsdt3
->Length
+ sizeof (UINT32
);
1067 // Add entry to XSDT, XSDT expects 64 bit pointers, but
1068 // the table pointers in XSDT are not aligned on 8 byte boundary.
1070 Buffer64
= (UINT64
) (UINTN
) CurrentTableList
->Table
;
1080 AcpiTableInstance
->Xsdt
->Length
= AcpiTableInstance
->Xsdt
->Length
+ sizeof (UINT64
);
1082 AcpiTableInstance
->NumberOfTableEntries3
++;
1086 ChecksumCommonTables (AcpiTableInstance
);
1092 This function finds the table specified by the handle and returns a pointer to it.
1093 If the handle is not found, EFI_NOT_FOUND is returned and the contents of Table are
1096 @param Handle Table to find.
1097 @param TableList Table list to search
1098 @param Table Pointer to table found.
1100 @return EFI_SUCCESS The function completed successfully.
1101 @return EFI_NOT_FOUND No table found matching the handle specified.
1107 IN LIST_ENTRY
*TableList
,
1108 OUT EFI_ACPI_TABLE_LIST
**Table
1111 LIST_ENTRY
*CurrentLink
;
1112 EFI_ACPI_TABLE_LIST
*CurrentTable
;
1115 // Check for invalid input parameters
1122 CurrentLink
= TableList
->ForwardLink
;
1124 while (CurrentLink
!= TableList
) {
1125 CurrentTable
= EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink
);
1126 if (CurrentTable
->Handle
== Handle
) {
1128 // Found handle, so return this table.
1130 *Table
= CurrentTable
;
1134 CurrentLink
= CurrentLink
->ForwardLink
;
1139 return EFI_NOT_FOUND
;
1144 This function removes a basic table from the RSDT and/or XSDT.
1145 For Acpi 1.0 tables, pass in the Rsdt.
1146 For Acpi 2.0 tables, pass in both Rsdt and Xsdt.
1148 @param Table Pointer to table found.
1149 @param NumberOfTableEntries Current number of table entries in the RSDT/XSDT
1150 @param Rsdt Pointer to the RSDT to remove from
1151 @param Xsdt Pointer to the Xsdt to remove from
1153 @return EFI_SUCCESS The function completed successfully.
1154 @return EFI_INVALID_PARAMETER The table was not found in both Rsdt and Xsdt.
1158 RemoveTableFromRsdt (
1159 IN OUT EFI_ACPI_TABLE_LIST
* Table
,
1160 IN OUT UINTN
*NumberOfTableEntries
,
1161 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Rsdt
,
1162 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Xsdt OPTIONAL
1165 UINT32
*CurrentRsdtEntry
;
1166 VOID
*CurrentXsdtEntry
;
1167 UINT64 CurrentTablePointer64
;
1171 // Check for invalid input parameters
1174 ASSERT (NumberOfTableEntries
);
1178 // Find the table entry in the RSDT and XSDT
1180 for (Index
= 0; Index
< *NumberOfTableEntries
; Index
++) {
1182 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
1183 // If it becomes necessary to maintain separate table lists, changes will be required.
1185 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) Rsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + Index
* sizeof (UINT32
));
1188 // This pointer must not be directly dereferenced as the XSDT entries may not
1189 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
1191 CurrentXsdtEntry
= (VOID
*) ((UINT8
*) Xsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + Index
* sizeof (UINT64
));
1194 // Read the entry value out of the XSDT
1196 CopyMem (&CurrentTablePointer64
, CurrentXsdtEntry
, sizeof (UINT64
));
1199 // Initialize to NULL
1201 CurrentXsdtEntry
= 0;
1202 CurrentTablePointer64
= 0;
1205 // Check if we have found the corresponding entry in both RSDT and XSDT
1207 if (*CurrentRsdtEntry
== (UINT32
) (UINTN
) Table
->Table
&&
1208 ((Xsdt
== NULL
) || CurrentTablePointer64
== (UINT64
) (UINTN
) Table
->Table
)
1211 // Found entry, so copy all following entries and shrink table
1212 // We actually copy all + 1 to copy the initialized value of memory over
1215 CopyMem (CurrentRsdtEntry
, CurrentRsdtEntry
+ 1, (*NumberOfTableEntries
- Index
) * sizeof (UINT32
));
1216 Rsdt
->Length
= Rsdt
->Length
- sizeof (UINT32
);
1218 CopyMem (CurrentXsdtEntry
, ((UINT64
*) CurrentXsdtEntry
) + 1, (*NumberOfTableEntries
- Index
) * sizeof (UINT64
));
1219 Xsdt
->Length
= Xsdt
->Length
- sizeof (UINT64
);
1222 } else if (Index
+ 1 == *NumberOfTableEntries
) {
1224 // At the last entry, and table not found
1226 return EFI_INVALID_PARAMETER
;
1230 // Checksum the tables
1232 AcpiPlatformChecksum (
1235 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1240 AcpiPlatformChecksum (
1243 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1248 // Decrement the number of tables
1250 (*NumberOfTableEntries
)--;
1257 This function removes a table and frees any associated memory.
1259 @param AcpiTableInstance Instance of the protocol.
1260 @param Version Version(s) to delete.
1261 @param Table Pointer to table found.
1263 @return EFI_SUCCESS The function completed successfully.
1268 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
1269 IN EFI_ACPI_TABLE_VERSION Version
,
1270 IN OUT EFI_ACPI_TABLE_LIST
*Table
1273 UINT32 CurrentTableSignature
;
1274 BOOLEAN RemoveFromRsdt
;
1277 // Check for invalid input parameters
1279 ASSERT (AcpiTableInstance
);
1285 RemoveFromRsdt
= TRUE
;
1287 // Check for Table->Table
1289 ASSERT (Table
->Table
!= NULL
);
1290 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
->Table
)->Signature
;
1293 // Basic tasks to accomplish delete are:
1294 // Determine removal requirements (in RSDT/XSDT or not)
1295 // Remove entry from RSDT/XSDT
1296 // Remove any table references to the table
1297 // If no one is using the table
1298 // Free the table (removing pointers from private data and tables)
1300 // Free list structure
1303 // Determine if this table is in the RSDT or XSDT
1305 if ((CurrentTableSignature
== EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) ||
1306 (CurrentTableSignature
== EFI_ACPI_2_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
) ||
1307 (CurrentTableSignature
== EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
)
1309 RemoveFromRsdt
= FALSE
;
1312 // We don't remove the FADT in the standard way because some
1313 // OS expect the FADT to be early in the table list.
1314 // So we always put it as the first element in the list.
1316 if (CurrentTableSignature
== EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
) {
1317 RemoveFromRsdt
= FALSE
;
1321 // Remove the table from RSDT and XSDT
1323 if (Table
->Table
!= NULL
) {
1325 // This is a basic table, remove it from any lists and the Rsdt and/or Xsdt
1327 if (Version
& EFI_ACPI_TABLE_VERSION_NONE
& Table
->Version
) {
1329 // Remove this version from the table
1331 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_NONE
;
1334 if (Version
& EFI_ACPI_TABLE_VERSION_1_0B
& Table
->Version
) {
1336 // Remove this version from the table
1338 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_1_0B
;
1341 // Remove from Rsdt. We don't care about the return value because it is
1342 // acceptable for the table to not exist in Rsdt.
1343 // We didn't add some tables so we don't remove them.
1345 if (RemoveFromRsdt
) {
1346 RemoveTableFromRsdt (
1348 &AcpiTableInstance
->NumberOfTableEntries1
,
1349 AcpiTableInstance
->Rsdt1
,
1355 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
& Table
->Version
) ||
1356 (Version
& EFI_ACPI_TABLE_VERSION_3_0
& Table
->Version
)) {
1358 // Remove this version from the table
1360 if (Version
& EFI_ACPI_TABLE_VERSION_2_0
& Table
->Version
) {
1361 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_2_0
;
1363 if (Version
& EFI_ACPI_TABLE_VERSION_3_0
& Table
->Version
) {
1364 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_3_0
;
1368 // Remove from Rsdt and Xsdt. We don't care about the return value
1369 // because it is acceptable for the table to not exist in Rsdt/Xsdt.
1370 // We didn't add some tables so we don't remove them.
1372 if (RemoveFromRsdt
) {
1373 RemoveTableFromRsdt (
1375 &AcpiTableInstance
->NumberOfTableEntries3
,
1376 AcpiTableInstance
->Rsdt3
,
1377 AcpiTableInstance
->Xsdt
1382 // Free the table, clean up any dependent tables and our private data pointers.
1384 switch (Table
->Table
->Signature
) {
1386 case EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
1387 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1388 AcpiTableInstance
->Fadt1
= NULL
;
1391 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
1392 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1393 AcpiTableInstance
->Fadt3
= NULL
;
1397 case EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
1398 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1399 AcpiTableInstance
->Facs1
= NULL
;
1402 // Update FADT table pointers
1404 if (AcpiTableInstance
->Fadt1
!= NULL
) {
1405 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= 0;
1410 AcpiPlatformChecksum (
1411 AcpiTableInstance
->Fadt1
,
1412 AcpiTableInstance
->Fadt1
->Header
.Length
,
1413 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1419 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
1420 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1421 AcpiTableInstance
->Facs3
= NULL
;
1424 // Update FADT table pointers
1426 if (AcpiTableInstance
->Fadt3
!= NULL
) {
1427 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= 0;
1428 ZeroMem (&AcpiTableInstance
->Fadt3
->XFirmwareCtrl
, sizeof (UINT64
));
1433 AcpiPlatformChecksum (
1434 AcpiTableInstance
->Fadt3
,
1435 AcpiTableInstance
->Fadt3
->Header
.Length
,
1436 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1443 case EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
1444 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1445 AcpiTableInstance
->Dsdt1
= NULL
;
1448 // Update FADT table pointers
1450 if (AcpiTableInstance
->Fadt1
!= NULL
) {
1451 AcpiTableInstance
->Fadt1
->Dsdt
= 0;
1456 AcpiPlatformChecksum (
1457 AcpiTableInstance
->Fadt1
,
1458 AcpiTableInstance
->Fadt1
->Header
.Length
,
1459 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1466 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
1467 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1468 AcpiTableInstance
->Dsdt3
= NULL
;
1471 // Update FADT table pointers
1473 if (AcpiTableInstance
->Fadt3
!= NULL
) {
1474 AcpiTableInstance
->Fadt3
->Dsdt
= 0;
1475 ZeroMem (&AcpiTableInstance
->Fadt3
->XDsdt
, sizeof (UINT64
));
1480 AcpiPlatformChecksum (
1481 AcpiTableInstance
->Fadt3
,
1482 AcpiTableInstance
->Fadt3
->Header
.Length
,
1483 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1498 // If no version is using this table anymore, remove and free list entry.
1500 if (Table
->Version
== 0) {
1504 gBS
->FreePages (Table
->PageAddress
, Table
->NumberOfPages
);
1505 RemoveEntryList (&(Table
->Link
));
1506 gBS
->FreePool (Table
);
1516 This function finds and removes the table specified by the handle.
1518 @param AcpiTableInstance Instance of the protocol.
1519 @param Version Bitmask of which versions to remove.
1520 @param Handle Table to remove.
1522 @return EFI_SUCCESS The function completed successfully.
1523 @return EFI_ABORTED An error occurred.
1524 @return EFI_NOT_FOUND Handle not found in table list.
1528 RemoveTableFromList (
1529 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
1530 IN EFI_ACPI_TABLE_VERSION Version
,
1534 EFI_ACPI_TABLE_LIST
*Table
;
1537 Table
= (EFI_ACPI_TABLE_LIST
*) NULL
;
1540 // Check for invalid input parameters
1542 ASSERT (AcpiTableInstance
);
1547 Status
= FindTableByHandle (
1549 &AcpiTableInstance
->TableList
,
1552 if (EFI_ERROR (Status
)) {
1553 return EFI_NOT_FOUND
;
1558 Status
= DeleteTable (AcpiTableInstance
, Version
, Table
);
1559 if (EFI_ERROR (Status
)) {
1563 // Completed successfully
1570 This function calculates and updates an UINT8 checksum.
1572 @param Buffer Pointer to buffer to checksum
1573 @param Size Number of bytes to checksum
1574 @param ChecksumOffset Offset to place the checksum result in
1576 @return EFI_SUCCESS The function completed successfully.
1580 AcpiPlatformChecksum (
1583 IN UINTN ChecksumOffset
1591 // Initialize pointer
1596 // set checksum to 0 first
1598 Ptr
[ChecksumOffset
] = 0;
1601 // add all content of buffer
1603 while ((Size
--) != 0) {
1604 Sum
= (UINT8
) (Sum
+ (*Ptr
++));
1610 Ptr
[ChecksumOffset
] = (UINT8
) (0xff - Sum
+ 1);
1617 Checksum all versions of the common tables, RSDP, RSDT, XSDT.
1619 @param AcpiTableInstance Protocol instance private data.
1621 @return EFI_SUCCESS The function completed successfully.
1625 ChecksumCommonTables (
1626 IN OUT EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
1630 // RSDP ACPI 1.0 checksum for 1.0 table. This is only the first 20 bytes of the structure
1632 AcpiPlatformChecksum (
1633 AcpiTableInstance
->Rsdp1
,
1634 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1635 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1640 // RSDP ACPI 1.0 checksum for 2.0/3.0 table. This is only the first 20 bytes of the structure
1642 AcpiPlatformChecksum (
1643 AcpiTableInstance
->Rsdp3
,
1644 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1645 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1650 // RSDP ACPI 2.0/3.0 checksum, this is the entire table
1652 AcpiPlatformChecksum (
1653 AcpiTableInstance
->Rsdp3
,
1654 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1655 OFFSET_OF (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1662 AcpiPlatformChecksum (
1663 AcpiTableInstance
->Rsdt1
,
1664 AcpiTableInstance
->Rsdt1
->Length
,
1665 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1669 AcpiPlatformChecksum (
1670 AcpiTableInstance
->Rsdt3
,
1671 AcpiTableInstance
->Rsdt3
->Length
,
1672 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1679 AcpiPlatformChecksum (
1680 AcpiTableInstance
->Xsdt
,
1681 AcpiTableInstance
->Xsdt
->Length
,
1682 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1691 Constructor for the ACPI table protocol. Initializes instance
1694 @param AcpiTableInstance Instance to construct
1696 @return EFI_SUCCESS Instance initialized.
1697 @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
1701 AcpiTableAcpiTableConstructor (
1702 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
1708 UINTN RsdpTableSize
;
1710 EFI_PHYSICAL_ADDRESS PageAddress
;
1713 // Check for invalid input parameters
1715 ASSERT (AcpiTableInstance
);
1717 InitializeListHead (&AcpiTableInstance
->TableList
);
1718 AcpiTableInstance
->CurrentHandle
= 1;
1720 AcpiTableInstance
->AcpiTableProtocol
.InstallAcpiTable
= InstallAcpiTable
;
1721 AcpiTableInstance
->AcpiTableProtocol
.UninstallAcpiTable
= UninstallAcpiTable
;
1723 if (FeaturePcdGet (PcdInstallAcpiSdtProtocol
)) {
1724 SdtAcpiTableAcpiSdtConstructor (AcpiTableInstance
);
1728 // Create RSDP table
1730 RsdpTableSize
= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
) +
1731 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1733 PageAddress
= 0xFFFFFFFF;
1734 Status
= gBS
->AllocatePages (
1736 EfiACPIReclaimMemory
,
1737 EFI_SIZE_TO_PAGES (RsdpTableSize
),
1741 if (EFI_ERROR (Status
)) {
1742 return EFI_OUT_OF_RESOURCES
;
1745 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
1746 ZeroMem (Pointer
, RsdpTableSize
);
1748 AcpiTableInstance
->Rsdp1
= (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1749 Pointer
+= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1750 AcpiTableInstance
->Rsdp3
= (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1753 // Create RSDT, XSDT structures
1755 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
1756 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
1757 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
1758 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
1759 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
1760 mEfiAcpiMaxNumTables
* sizeof (UINT64
);
1763 // Allocate memory in the lower 32 bit of address range for
1764 // compatibility with ACPI 1.0 OS.
1766 // This is done because ACPI 1.0 pointers are 32 bit values.
1767 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
1768 // There is no architectural reason these should be below 4GB, it is purely
1769 // for convenience of implementation that we force memory below 4GB.
1771 PageAddress
= 0xFFFFFFFF;
1772 Status
= gBS
->AllocatePages (
1774 EfiACPIReclaimMemory
,
1775 EFI_SIZE_TO_PAGES (TotalSize
),
1779 if (EFI_ERROR (Status
)) {
1780 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
)(UINTN
)AcpiTableInstance
->Rsdp1
, EFI_SIZE_TO_PAGES (RsdpTableSize
));
1781 return EFI_OUT_OF_RESOURCES
;
1784 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
1785 ZeroMem (Pointer
, TotalSize
);
1787 AcpiTableInstance
->Rsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1788 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1789 AcpiTableInstance
->Rsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1790 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1791 AcpiTableInstance
->Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1796 CurrentData
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1797 CopyMem (&AcpiTableInstance
->Rsdp1
->Signature
, &CurrentData
, sizeof (UINT64
));
1798 CopyMem (AcpiTableInstance
->Rsdp1
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdp1
->OemId
));
1799 AcpiTableInstance
->Rsdp1
->Reserved
= EFI_ACPI_RESERVED_BYTE
;
1800 AcpiTableInstance
->Rsdp1
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt1
;
1802 CurrentData
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1803 CopyMem (&AcpiTableInstance
->Rsdp3
->Signature
, &CurrentData
, sizeof (UINT64
));
1804 CopyMem (AcpiTableInstance
->Rsdp3
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdp3
->OemId
));
1805 AcpiTableInstance
->Rsdp3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION
;
1806 AcpiTableInstance
->Rsdp3
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt3
;
1807 AcpiTableInstance
->Rsdp3
->Length
= sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1808 CurrentData
= (UINT64
) (UINTN
) AcpiTableInstance
->Xsdt
;
1809 CopyMem (&AcpiTableInstance
->Rsdp3
->XsdtAddress
, &CurrentData
, sizeof (UINT64
));
1810 SetMem (AcpiTableInstance
->Rsdp3
->Reserved
, 3, EFI_ACPI_RESERVED_BYTE
);
1815 // Note that we "reserve" one entry for the FADT so it can always be
1816 // at the beginning of the list of tables. Some OS don't seem
1817 // to find it correctly if it is too far down the list.
1819 AcpiTableInstance
->Rsdt1
->Signature
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1820 AcpiTableInstance
->Rsdt1
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1821 AcpiTableInstance
->Rsdt1
->Revision
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1822 CopyMem (AcpiTableInstance
->Rsdt1
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdt1
->OemId
));
1823 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1824 CopyMem (&AcpiTableInstance
->Rsdt1
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1825 AcpiTableInstance
->Rsdt1
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1826 AcpiTableInstance
->Rsdt1
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1827 AcpiTableInstance
->Rsdt1
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1829 // We always reserve first one for FADT
1831 AcpiTableInstance
->NumberOfTableEntries1
= 1;
1832 AcpiTableInstance
->Rsdt1
->Length
= AcpiTableInstance
->Rsdt1
->Length
+ sizeof(UINT32
);
1834 AcpiTableInstance
->Rsdt3
->Signature
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1835 AcpiTableInstance
->Rsdt3
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1836 AcpiTableInstance
->Rsdt3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1837 CopyMem (AcpiTableInstance
->Rsdt3
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdt3
->OemId
));
1838 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1839 CopyMem (&AcpiTableInstance
->Rsdt3
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1840 AcpiTableInstance
->Rsdt3
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1841 AcpiTableInstance
->Rsdt3
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1842 AcpiTableInstance
->Rsdt3
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1844 // We always reserve first one for FADT
1846 AcpiTableInstance
->NumberOfTableEntries3
= 1;
1847 AcpiTableInstance
->Rsdt3
->Length
= AcpiTableInstance
->Rsdt3
->Length
+ sizeof(UINT32
);
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