2 ACPI Table Protocol Implementation
4 Copyright (c) 2006 - 2018, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
13 #include "AcpiTable.h"
15 // The maximum number of tables that pre-allocated.
17 UINTN mEfiAcpiMaxNumTables
= EFI_ACPI_MAX_NUM_TABLES
;
20 // Allocation strategy to use for AllocatePages ().
21 // Runtime value depends on PcdExposedAcpiTableVersions.
23 STATIC EFI_ALLOCATE_TYPE mAcpiTableAllocType
;
26 This function adds an ACPI table to the table list. It will detect FACS and
27 allocate the correct type of memory and properly align the table.
29 @param AcpiTableInstance Instance of the protocol.
30 @param Table Table to add.
31 @param Checksum Does the table require checksumming.
32 @param Version The version of the list to add the table to.
33 @param Handle Pointer for returning the handle.
35 @return EFI_SUCCESS The function completed successfully.
36 @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
37 @return EFI_ABORTED The table is a duplicate of a table that is required
43 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
46 IN EFI_ACPI_TABLE_VERSION Version
,
51 This function finds and removes the table specified by the handle.
53 @param AcpiTableInstance Instance of the protocol.
54 @param Version Bitmask of which versions to remove.
55 @param Handle Table to remove.
57 @return EFI_SUCCESS The function completed successfully.
58 @return EFI_ABORTED An error occurred.
59 @return EFI_NOT_FOUND Handle not found in table list.
64 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
65 IN EFI_ACPI_TABLE_VERSION Version
,
70 This function calculates and updates an UINT8 checksum.
72 @param Buffer Pointer to buffer to checksum
73 @param Size Number of bytes to checksum
74 @param ChecksumOffset Offset to place the checksum result in
76 @return EFI_SUCCESS The function completed successfully.
79 AcpiPlatformChecksum (
82 IN UINTN ChecksumOffset
86 Checksum all versions of the common tables, RSDP, RSDT, XSDT.
88 @param AcpiTableInstance Protocol instance private data.
90 @return EFI_SUCCESS The function completed successfully.
94 ChecksumCommonTables (
95 IN OUT EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
99 // Protocol function implementations.
103 This function publishes the specified versions of the ACPI tables by
104 installing EFI configuration table entries for them. Any combination of
105 table versions can be published.
107 @param AcpiTableInstance Instance of the protocol.
108 @param Version Version(s) to publish.
110 @return EFI_SUCCESS The function completed successfully.
111 @return EFI_ABORTED The function could not complete successfully.
117 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
118 IN EFI_ACPI_TABLE_VERSION Version
122 UINT32
*CurrentRsdtEntry
;
123 VOID
*CurrentXsdtEntry
;
127 // Reorder tables as some operating systems don't seem to find the
128 // FADT correctly if it is not in the first few entries
132 // Add FADT as the first entry
134 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
135 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) AcpiTableInstance
->Rsdt1
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
136 *CurrentRsdtEntry
= (UINT32
) (UINTN
) AcpiTableInstance
->Fadt1
;
138 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) AcpiTableInstance
->Rsdt3
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
139 *CurrentRsdtEntry
= (UINT32
) (UINTN
) AcpiTableInstance
->Fadt3
;
141 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
142 CurrentXsdtEntry
= (VOID
*) ((UINT8
*) AcpiTableInstance
->Xsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
144 // Add entry to XSDT, XSDT expects 64 bit pointers, but
145 // the table pointers in XSDT are not aligned on 8 byte boundary.
147 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Fadt3
;
156 // Do checksum again because Dsdt/Xsdt is updated.
158 ChecksumCommonTables (AcpiTableInstance
);
161 // Add the RSD_PTR to the system table and store that we have installed the
164 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
165 Status
= gBS
->InstallConfigurationTable (&gEfiAcpi10TableGuid
, AcpiTableInstance
->Rsdp1
);
166 if (EFI_ERROR (Status
)) {
171 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
172 Status
= gBS
->InstallConfigurationTable (&gEfiAcpiTableGuid
, AcpiTableInstance
->Rsdp3
);
173 if (EFI_ERROR (Status
)) {
183 Installs an ACPI table into the RSDT/XSDT.
184 Note that the ACPI table should be checksumed before installing it.
185 Otherwise it will assert.
187 @param This Protocol instance pointer.
188 @param AcpiTableBuffer A pointer to a buffer containing the ACPI table to be installed.
189 @param AcpiTableBufferSize Specifies the size, in bytes, of the AcpiTableBuffer buffer.
190 @param TableKey Reurns a key to refer to the ACPI table.
192 @return EFI_SUCCESS The table was successfully inserted.
193 @return EFI_INVALID_PARAMETER Either AcpiTableBuffer is NULL, TableKey is NULL, or AcpiTableBufferSize
194 and the size field embedded in the ACPI table pointed to by AcpiTableBuffer
196 @return EFI_OUT_OF_RESOURCES Insufficient resources exist to complete the request.
197 @retval EFI_ACCESS_DENIED The table signature matches a table already
198 present in the system and platform policy
199 does not allow duplicate tables of this type.
205 IN EFI_ACPI_TABLE_PROTOCOL
*This
,
206 IN VOID
*AcpiTableBuffer
,
207 IN UINTN AcpiTableBufferSize
,
211 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
;
213 VOID
*AcpiTableBufferConst
;
214 EFI_ACPI_TABLE_VERSION Version
;
217 // Check for invalid input parameters
219 if ((AcpiTableBuffer
== NULL
) || (TableKey
== NULL
)
220 || (((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTableBuffer
)->Length
!= AcpiTableBufferSize
)) {
221 return EFI_INVALID_PARAMETER
;
224 Version
= PcdGet32 (PcdAcpiExposedTableVersions
);
227 // Get the instance of the ACPI table protocol
229 AcpiTableInstance
= EFI_ACPI_TABLE_INSTANCE_FROM_THIS (This
);
232 // Install the ACPI table
234 AcpiTableBufferConst
= AllocateCopyPool (AcpiTableBufferSize
,AcpiTableBuffer
);
236 Status
= AddTableToList (
238 AcpiTableBufferConst
,
243 if (!EFI_ERROR (Status
)) {
244 Status
= PublishTables (
249 FreePool (AcpiTableBufferConst
);
252 // Add a new table successfully, notify registed callback
254 if (FeaturePcdGet (PcdInstallAcpiSdtProtocol
)) {
255 if (!EFI_ERROR (Status
)) {
269 Removes an ACPI table from the RSDT/XSDT.
271 @param This Protocol instance pointer.
272 @param TableKey Specifies the table to uninstall. The key was returned from InstallAcpiTable().
274 @return EFI_SUCCESS The table was successfully uninstalled.
275 @return EFI_NOT_FOUND TableKey does not refer to a valid key for a table entry.
281 IN EFI_ACPI_TABLE_PROTOCOL
*This
,
285 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
;
287 EFI_ACPI_TABLE_VERSION Version
;
290 // Get the instance of the ACPI table protocol
292 AcpiTableInstance
= EFI_ACPI_TABLE_INSTANCE_FROM_THIS (This
);
294 Version
= PcdGet32 (PcdAcpiExposedTableVersions
);
297 // Uninstall the ACPI table
299 Status
= RemoveTableFromList (
304 if (!EFI_ERROR (Status
)) {
305 Status
= PublishTables (
311 if (EFI_ERROR (Status
)) {
312 return EFI_NOT_FOUND
;
319 If the number of APCI tables exceeds the preallocated max table number, enlarge the table buffer.
321 @param AcpiTableInstance ACPI table protocol instance data structure.
323 @return EFI_SUCCESS reallocate the table beffer successfully.
324 @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
328 ReallocateAcpiTableBuffer (
329 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
332 UINTN NewMaxTableNumber
;
335 EFI_PHYSICAL_ADDRESS PageAddress
;
336 EFI_ACPI_TABLE_INSTANCE TempPrivateData
;
340 CopyMem (&TempPrivateData
, AcpiTableInstance
, sizeof (EFI_ACPI_TABLE_INSTANCE
));
342 // Enlarge the max table number from mEfiAcpiMaxNumTables to mEfiAcpiMaxNumTables + EFI_ACPI_MAX_NUM_TABLES
344 NewMaxTableNumber
= mEfiAcpiMaxNumTables
+ EFI_ACPI_MAX_NUM_TABLES
;
346 // Create RSDT, XSDT structures and allocate buffers.
348 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
349 NewMaxTableNumber
* sizeof (UINT64
);
351 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
352 TotalSize
+= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
353 NewMaxTableNumber
* sizeof (UINT32
) +
354 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
355 NewMaxTableNumber
* sizeof (UINT32
);
358 if (mAcpiTableAllocType
!= AllocateAnyPages
) {
360 // Allocate memory in the lower 32 bit of address range for
361 // compatibility with ACPI 1.0 OS.
363 // This is done because ACPI 1.0 pointers are 32 bit values.
364 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
365 // There is no architectural reason these should be below 4GB, it is purely
366 // for convenience of implementation that we force memory below 4GB.
368 PageAddress
= 0xFFFFFFFF;
369 Status
= gBS
->AllocatePages (
371 EfiACPIReclaimMemory
,
372 EFI_SIZE_TO_PAGES (TotalSize
),
376 Status
= gBS
->AllocatePool (
377 EfiACPIReclaimMemory
,
383 if (EFI_ERROR (Status
)) {
384 return EFI_OUT_OF_RESOURCES
;
387 if (mAcpiTableAllocType
!= AllocateAnyPages
) {
388 Pointer
= (UINT8
*)(UINTN
)PageAddress
;
391 ZeroMem (Pointer
, TotalSize
);
393 AcpiTableInstance
->Rsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
394 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
395 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + NewMaxTableNumber
* sizeof (UINT32
));
396 AcpiTableInstance
->Rsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
397 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + NewMaxTableNumber
* sizeof (UINT32
));
399 AcpiTableInstance
->Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
402 // Update RSDP to point to the new Rsdt and Xsdt address.
404 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
405 AcpiTableInstance
->Rsdp1
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt1
;
406 AcpiTableInstance
->Rsdp3
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt3
;
408 CurrentData
= (UINT64
) (UINTN
) AcpiTableInstance
->Xsdt
;
409 CopyMem (&AcpiTableInstance
->Rsdp3
->XsdtAddress
, &CurrentData
, sizeof (UINT64
));
412 // copy the original Rsdt1, Rsdt3 and Xsdt structure to new buffer
414 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
415 CopyMem (AcpiTableInstance
->Rsdt1
, TempPrivateData
.Rsdt1
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT32
)));
416 CopyMem (AcpiTableInstance
->Rsdt3
, TempPrivateData
.Rsdt3
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT32
)));
418 CopyMem (AcpiTableInstance
->Xsdt
, TempPrivateData
.Xsdt
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT64
)));
420 if (mAcpiTableAllocType
!= AllocateAnyPages
) {
422 // Calculate orignal ACPI table buffer size
424 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
425 mEfiAcpiMaxNumTables
* sizeof (UINT64
);
427 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
428 TotalSize
+= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
429 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
430 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
431 mEfiAcpiMaxNumTables
* sizeof (UINT32
);
434 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
)(UINTN
)TempPrivateData
.Rsdt1
,
435 EFI_SIZE_TO_PAGES (TotalSize
));
437 gBS
->FreePool (TempPrivateData
.Rsdt1
);
441 // Update the Max ACPI table number
443 mEfiAcpiMaxNumTables
= NewMaxTableNumber
;
448 Free the memory associated with the provided EFI_ACPI_TABLE_LIST instance.
450 @param TableEntry EFI_ACPI_TABLE_LIST instance pointer
456 EFI_ACPI_TABLE_LIST
*TableEntry
459 if (TableEntry
->PoolAllocation
) {
460 gBS
->FreePool (TableEntry
->Table
);
462 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
)(UINTN
)TableEntry
->Table
,
463 EFI_SIZE_TO_PAGES (TableEntry
->TableSize
));
468 This function adds an ACPI table to the table list. It will detect FACS and
469 allocate the correct type of memory and properly align the table.
471 @param AcpiTableInstance Instance of the protocol.
472 @param Table Table to add.
473 @param Checksum Does the table require checksumming.
474 @param Version The version of the list to add the table to.
475 @param Handle Pointer for returning the handle.
477 @return EFI_SUCCESS The function completed successfully.
478 @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
479 @retval EFI_ACCESS_DENIED The table signature matches a table already
480 present in the system and platform policy
481 does not allow duplicate tables of this type.
486 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
489 IN EFI_ACPI_TABLE_VERSION Version
,
494 EFI_ACPI_TABLE_LIST
*CurrentTableList
;
495 UINT32 CurrentTableSignature
;
496 UINT32 CurrentTableSize
;
497 UINT32
*CurrentRsdtEntry
;
498 VOID
*CurrentXsdtEntry
;
499 EFI_PHYSICAL_ADDRESS AllocPhysAddress
;
504 // Check for invalid input parameters
506 ASSERT (AcpiTableInstance
);
516 // Create a new list entry
518 CurrentTableList
= AllocatePool (sizeof (EFI_ACPI_TABLE_LIST
));
519 ASSERT (CurrentTableList
);
522 // Determine table type and size
524 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
)->Signature
;
525 CurrentTableSize
= ((EFI_ACPI_COMMON_HEADER
*) Table
)->Length
;
528 // Allocate a buffer for the table. All tables are allocated in the lower 32 bits of address space
529 // for backwards compatibility with ACPI 1.0 OS.
531 // This is done because ACPI 1.0 pointers are 32 bit values.
532 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
533 // There is no architectural reason these should be below 4GB, it is purely
534 // for convenience of implementation that we force memory below 4GB.
536 AllocPhysAddress
= 0xFFFFFFFF;
537 CurrentTableList
->TableSize
= CurrentTableSize
;
538 CurrentTableList
->PoolAllocation
= FALSE
;
541 // Allocation memory type depends on the type of the table
543 if ((CurrentTableSignature
== EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) ||
544 (CurrentTableSignature
== EFI_ACPI_4_0_UEFI_ACPI_DATA_TABLE_SIGNATURE
)) {
546 // Allocate memory for the FACS. This structure must be aligned
547 // on a 64 byte boundary and must be ACPI NVS memory.
548 // Using AllocatePages should ensure that it is always aligned.
549 // Do not change signature for new ACPI version because they are same.
551 // UEFI table also need to be in ACPI NVS memory, because some data field
552 // could be updated by OS present agent. For example, BufferPtrAddress in
553 // SMM communication ACPI table.
555 ASSERT ((EFI_PAGE_SIZE
% 64) == 0);
556 Status
= gBS
->AllocatePages (
559 EFI_SIZE_TO_PAGES (CurrentTableList
->TableSize
),
562 } else if (mAcpiTableAllocType
== AllocateAnyPages
) {
564 // If there is no allocation limit, there is also no need to use page
565 // based allocations for ACPI tables, which may be wasteful on platforms
566 // such as AArch64 that allocate multiples of 64 KB
568 Status
= gBS
->AllocatePool (
569 EfiACPIReclaimMemory
,
570 CurrentTableList
->TableSize
,
571 (VOID
**)&CurrentTableList
->Table
573 CurrentTableList
->PoolAllocation
= TRUE
;
576 // All other tables are ACPI reclaim memory, no alignment requirements.
578 Status
= gBS
->AllocatePages (
580 EfiACPIReclaimMemory
,
581 EFI_SIZE_TO_PAGES (CurrentTableList
->TableSize
),
584 CurrentTableList
->Table
= (EFI_ACPI_COMMON_HEADER
*)(UINTN
)AllocPhysAddress
;
587 // Check return value from memory alloc.
589 if (EFI_ERROR (Status
)) {
590 gBS
->FreePool (CurrentTableList
);
591 return EFI_OUT_OF_RESOURCES
;
594 if (!CurrentTableList
->PoolAllocation
) {
595 CurrentTableList
->Table
= (EFI_ACPI_COMMON_HEADER
*)(UINTN
)AllocPhysAddress
;
599 // Initialize the table contents
601 CurrentTableList
->Signature
= EFI_ACPI_TABLE_LIST_SIGNATURE
;
602 CopyMem (CurrentTableList
->Table
, Table
, CurrentTableSize
);
603 CurrentTableList
->Handle
= AcpiTableInstance
->CurrentHandle
++;
604 *Handle
= CurrentTableList
->Handle
;
605 CurrentTableList
->Version
= Version
;
608 // Update internal pointers if this is a required table. If it is a required
609 // table and a table of that type already exists, return an error.
611 // Calculate the checksum if the table is not FACS.
613 switch (CurrentTableSignature
) {
615 case EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
617 // We don't add the FADT in the standard way because some
618 // OS expect the FADT to be early in the table list.
619 // So we always add it as the first element in the list.
624 // Check that the table has not been previously added.
626 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Fadt1
!= NULL
) ||
627 ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0 && AcpiTableInstance
->Fadt3
!= NULL
)
629 FreeTableMemory (CurrentTableList
);
630 gBS
->FreePool (CurrentTableList
);
631 return EFI_ACCESS_DENIED
;
634 // Add the table to the appropriate table version
636 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
638 // Save a pointer to the table
640 AcpiTableInstance
->Fadt1
= (EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE
*) CurrentTableList
->Table
;
643 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
645 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs1
;
646 AcpiTableInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt1
;
649 // RSDP OEM information is updated to match the FADT OEM information
652 &AcpiTableInstance
->Rsdp1
->OemId
,
653 &AcpiTableInstance
->Fadt1
->Header
.OemId
,
658 // RSDT OEM information is updated to match the FADT OEM information.
661 &AcpiTableInstance
->Rsdt1
->OemId
,
662 &AcpiTableInstance
->Fadt1
->Header
.OemId
,
667 &AcpiTableInstance
->Rsdt1
->OemTableId
,
668 &AcpiTableInstance
->Fadt1
->Header
.OemTableId
,
671 AcpiTableInstance
->Rsdt1
->OemRevision
= AcpiTableInstance
->Fadt1
->Header
.OemRevision
;
674 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
676 // Save a pointer to the table
678 AcpiTableInstance
->Fadt3
= (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE
*) CurrentTableList
->Table
;
681 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
682 // Note: If the FIRMWARE_CTRL is non-zero, then X_FIRMWARE_CTRL must be zero, and
685 if ((UINT64
)(UINTN
)AcpiTableInstance
->Facs3
< BASE_4GB
) {
686 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs3
;
687 ZeroMem (&AcpiTableInstance
->Fadt3
->XFirmwareCtrl
, sizeof (UINT64
));
689 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Facs3
;
691 &AcpiTableInstance
->Fadt3
->XFirmwareCtrl
,
695 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= 0;
697 if ((UINT64
)(UINTN
)AcpiTableInstance
->Dsdt3
< BASE_4GB
) {
698 AcpiTableInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt3
;
700 // Comment block "the caller installs the tables in "DSDT, FADT" order"
701 // The below comments are also in "the caller installs the tables in "FADT, DSDT" order" comment block.
703 // The ACPI specification, up to and including revision 5.1 Errata A,
704 // allows the DSDT and X_DSDT fields to be both set in the FADT.
705 // (Obviously, this only makes sense if the DSDT address is representable in 4 bytes.)
706 // Starting with 5.1 Errata B, specifically for Mantis 1393 <https://mantis.uefi.org/mantis/view.php?id=1393>,
707 // the spec requires at most one of DSDT and X_DSDT fields to be set to a nonzero value,
708 // but strangely an exception is 6.0 that has no this requirement.
710 // Here we do not make the DSDT and X_DSDT fields mutual exclusion conditionally
711 // by checking FADT revision, but always set both DSDT and X_DSDT fields in the FADT
712 // to have better compatibility as some OS may have assumption to only consume X_DSDT
713 // field even the DSDT address is < 4G.
715 Buffer64
= AcpiTableInstance
->Fadt3
->Dsdt
;
717 AcpiTableInstance
->Fadt3
->Dsdt
= 0;
718 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Dsdt3
;
720 CopyMem (&AcpiTableInstance
->Fadt3
->XDsdt
, &Buffer64
, sizeof (UINT64
));
723 // RSDP OEM information is updated to match the FADT OEM information
726 &AcpiTableInstance
->Rsdp3
->OemId
,
727 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
731 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
733 // RSDT OEM information is updated to match FADT OEM information.
736 &AcpiTableInstance
->Rsdt3
->OemId
,
737 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
741 &AcpiTableInstance
->Rsdt3
->OemTableId
,
742 &AcpiTableInstance
->Fadt3
->Header
.OemTableId
,
745 AcpiTableInstance
->Rsdt3
->OemRevision
= AcpiTableInstance
->Fadt3
->Header
.OemRevision
;
749 // XSDT OEM information is updated to match FADT OEM information.
752 &AcpiTableInstance
->Xsdt
->OemId
,
753 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
757 &AcpiTableInstance
->Xsdt
->OemTableId
,
758 &AcpiTableInstance
->Fadt3
->Header
.OemTableId
,
761 AcpiTableInstance
->Xsdt
->OemRevision
= AcpiTableInstance
->Fadt3
->Header
.OemRevision
;
764 // Checksum the table
767 AcpiPlatformChecksum (
768 CurrentTableList
->Table
,
769 CurrentTableList
->Table
->Length
,
770 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
776 case EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
778 // Check that the table has not been previously added.
780 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Facs1
!= NULL
) ||
781 ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0 && AcpiTableInstance
->Facs3
!= NULL
)
783 FreeTableMemory (CurrentTableList
);
784 gBS
->FreePool (CurrentTableList
);
785 return EFI_ACCESS_DENIED
;
788 // FACS is referenced by FADT and is not part of RSDT
793 // Add the table to the appropriate table version
795 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
797 // Save a pointer to the table
799 AcpiTableInstance
->Facs1
= (EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
802 // If FADT already exists, update table pointers.
804 if (AcpiTableInstance
->Fadt1
!= NULL
) {
805 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs1
;
808 // Checksum FADT table
810 AcpiPlatformChecksum (
811 AcpiTableInstance
->Fadt1
,
812 AcpiTableInstance
->Fadt1
->Header
.Length
,
813 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
819 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
821 // Save a pointer to the table
823 AcpiTableInstance
->Facs3
= (EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
826 // If FADT already exists, update table pointers.
828 if (AcpiTableInstance
->Fadt3
!= NULL
) {
830 // Note: If the FIRMWARE_CTRL is non-zero, then X_FIRMWARE_CTRL must be zero, and
833 if ((UINT64
)(UINTN
)AcpiTableInstance
->Facs3
< BASE_4GB
) {
834 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs3
;
835 ZeroMem (&AcpiTableInstance
->Fadt3
->XFirmwareCtrl
, sizeof (UINT64
));
837 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Facs3
;
839 &AcpiTableInstance
->Fadt3
->XFirmwareCtrl
,
843 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= 0;
847 // Checksum FADT table
849 AcpiPlatformChecksum (
850 AcpiTableInstance
->Fadt3
,
851 AcpiTableInstance
->Fadt3
->Header
.Length
,
852 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
860 case EFI_ACPI_1_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
862 // Check that the table has not been previously added.
864 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Dsdt1
!= NULL
) ||
865 ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0 && AcpiTableInstance
->Dsdt3
!= NULL
)
867 FreeTableMemory (CurrentTableList
);
868 gBS
->FreePool (CurrentTableList
);
869 return EFI_ACCESS_DENIED
;
872 // DSDT is referenced by FADT and is not part of RSDT
877 // Add the table to the appropriate table version
879 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
881 // Save a pointer to the table
883 AcpiTableInstance
->Dsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
886 // If FADT already exists, update table pointers.
888 if (AcpiTableInstance
->Fadt1
!= NULL
) {
889 AcpiTableInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt1
;
892 // Checksum FADT table
894 AcpiPlatformChecksum (
895 AcpiTableInstance
->Fadt1
,
896 AcpiTableInstance
->Fadt1
->Header
.Length
,
897 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
903 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
905 // Save a pointer to the table
907 AcpiTableInstance
->Dsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
910 // If FADT already exists, update table pointers.
912 if (AcpiTableInstance
->Fadt3
!= NULL
) {
913 if ((UINT64
)(UINTN
)AcpiTableInstance
->Dsdt3
< BASE_4GB
) {
914 AcpiTableInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt3
;
916 // Comment block "the caller installs the tables in "FADT, DSDT" order"
917 // The below comments are also in "the caller installs the tables in "DSDT, FADT" order" comment block.
919 // The ACPI specification, up to and including revision 5.1 Errata A,
920 // allows the DSDT and X_DSDT fields to be both set in the FADT.
921 // (Obviously, this only makes sense if the DSDT address is representable in 4 bytes.)
922 // Starting with 5.1 Errata B, specifically for Mantis 1393 <https://mantis.uefi.org/mantis/view.php?id=1393>,
923 // the spec requires at most one of DSDT and X_DSDT fields to be set to a nonzero value,
924 // but strangely an exception is 6.0 that has no this requirement.
926 // Here we do not make the DSDT and X_DSDT fields mutual exclusion conditionally
927 // by checking FADT revision, but always set both DSDT and X_DSDT fields in the FADT
928 // to have better compatibility as some OS may have assumption to only consume X_DSDT
929 // field even the DSDT address is < 4G.
931 Buffer64
= AcpiTableInstance
->Fadt3
->Dsdt
;
933 AcpiTableInstance
->Fadt3
->Dsdt
= 0;
934 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Dsdt3
;
936 CopyMem (&AcpiTableInstance
->Fadt3
->XDsdt
, &Buffer64
, sizeof (UINT64
));
939 // Checksum FADT table
941 AcpiPlatformChecksum (
942 AcpiTableInstance
->Fadt3
,
943 AcpiTableInstance
->Fadt3
->Header
.Length
,
944 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
950 // Checksum the table
953 AcpiPlatformChecksum (
954 CurrentTableList
->Table
,
955 CurrentTableList
->Table
->Length
,
956 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
964 // Checksum the table
967 AcpiPlatformChecksum (
968 CurrentTableList
->Table
,
969 CurrentTableList
->Table
->Length
,
970 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
977 // Add the table to the current list of tables
979 InsertTailList (&AcpiTableInstance
->TableList
, &CurrentTableList
->Link
);
982 // Add the table to RSDT and/or XSDT table entry lists.
985 // Add to ACPI 1.0b table tree
987 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
990 // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
992 if (AcpiTableInstance
->NumberOfTableEntries1
>= mEfiAcpiMaxNumTables
) {
993 Status
= ReallocateAcpiTableBuffer (AcpiTableInstance
);
994 ASSERT_EFI_ERROR (Status
);
996 CurrentRsdtEntry
= (UINT32
*)
998 (UINT8
*) AcpiTableInstance
->Rsdt1
+
999 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
1000 AcpiTableInstance
->NumberOfTableEntries1
*
1005 // Add entry to the RSDT unless its the FACS or DSDT
1007 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
1010 // Update RSDT length
1012 AcpiTableInstance
->Rsdt1
->Length
= AcpiTableInstance
->Rsdt1
->Length
+ sizeof (UINT32
);
1014 AcpiTableInstance
->NumberOfTableEntries1
++;
1018 // Add to ACPI 2.0/3.0 table tree
1020 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
1023 // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
1025 if (AcpiTableInstance
->NumberOfTableEntries3
>= mEfiAcpiMaxNumTables
) {
1026 Status
= ReallocateAcpiTableBuffer (AcpiTableInstance
);
1027 ASSERT_EFI_ERROR (Status
);
1030 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1032 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
1033 // If it becomes necessary to maintain separate table lists, changes will be required.
1035 CurrentRsdtEntry
= (UINT32
*)
1037 (UINT8
*) AcpiTableInstance
->Rsdt3
+
1038 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
1039 AcpiTableInstance
->NumberOfTableEntries3
*
1044 // Add entry to the RSDT
1046 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
1049 // Update RSDT length
1051 AcpiTableInstance
->Rsdt3
->Length
= AcpiTableInstance
->Rsdt3
->Length
+ sizeof (UINT32
);
1055 // This pointer must not be directly dereferenced as the XSDT entries may not
1056 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
1058 CurrentXsdtEntry
= (VOID
*)
1060 (UINT8
*) AcpiTableInstance
->Xsdt
+
1061 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
1062 AcpiTableInstance
->NumberOfTableEntries3
*
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 OPTIONAL
,
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
);
1175 ASSERT (Rsdt
|| Xsdt
);
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.
1186 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) Rsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + Index
* sizeof (UINT32
));
1188 CurrentRsdtEntry
= NULL
;
1192 // This pointer must not be directly dereferenced as the XSDT entries may not
1193 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
1195 CurrentXsdtEntry
= (VOID
*) ((UINT8
*) Xsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + Index
* sizeof (UINT64
));
1198 // Read the entry value out of the XSDT
1200 CopyMem (&CurrentTablePointer64
, CurrentXsdtEntry
, sizeof (UINT64
));
1203 // Initialize to NULL
1205 CurrentXsdtEntry
= 0;
1206 CurrentTablePointer64
= 0;
1209 // Check if we have found the corresponding entry in both RSDT and XSDT
1211 if (((Rsdt
== NULL
) || *CurrentRsdtEntry
== (UINT32
) (UINTN
) Table
->Table
) &&
1212 ((Xsdt
== NULL
) || CurrentTablePointer64
== (UINT64
) (UINTN
) Table
->Table
)
1215 // Found entry, so copy all following entries and shrink table
1216 // We actually copy all + 1 to copy the initialized value of memory over
1220 CopyMem (CurrentRsdtEntry
, CurrentRsdtEntry
+ 1, (*NumberOfTableEntries
- Index
) * sizeof (UINT32
));
1221 Rsdt
->Length
= Rsdt
->Length
- sizeof (UINT32
);
1224 CopyMem (CurrentXsdtEntry
, ((UINT64
*) CurrentXsdtEntry
) + 1, (*NumberOfTableEntries
- Index
) * sizeof (UINT64
));
1225 Xsdt
->Length
= Xsdt
->Length
- sizeof (UINT64
);
1228 } else if (Index
+ 1 == *NumberOfTableEntries
) {
1230 // At the last entry, and table not found
1232 return EFI_INVALID_PARAMETER
;
1236 // Checksum the tables
1239 AcpiPlatformChecksum (
1242 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1248 AcpiPlatformChecksum (
1251 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1256 // Decrement the number of tables
1258 (*NumberOfTableEntries
)--;
1265 This function removes a table and frees any associated memory.
1267 @param AcpiTableInstance Instance of the protocol.
1268 @param Version Version(s) to delete.
1269 @param Table Pointer to table found.
1271 @return EFI_SUCCESS The function completed successfully.
1276 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
1277 IN EFI_ACPI_TABLE_VERSION Version
,
1278 IN OUT EFI_ACPI_TABLE_LIST
*Table
1281 UINT32 CurrentTableSignature
;
1282 BOOLEAN RemoveFromRsdt
;
1285 // Check for invalid input parameters
1287 ASSERT (AcpiTableInstance
);
1293 RemoveFromRsdt
= TRUE
;
1295 // Check for Table->Table
1297 ASSERT (Table
->Table
!= NULL
);
1298 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
->Table
)->Signature
;
1301 // Basic tasks to accomplish delete are:
1302 // Determine removal requirements (in RSDT/XSDT or not)
1303 // Remove entry from RSDT/XSDT
1304 // Remove any table references to the table
1305 // If no one is using the table
1306 // Free the table (removing pointers from private data and tables)
1308 // Free list structure
1311 // Determine if this table is in the RSDT or XSDT
1313 if ((CurrentTableSignature
== EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) ||
1314 (CurrentTableSignature
== EFI_ACPI_2_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
) ||
1315 (CurrentTableSignature
== EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
)
1317 RemoveFromRsdt
= FALSE
;
1320 // We don't remove the FADT in the standard way because some
1321 // OS expect the FADT to be early in the table list.
1322 // So we always put it as the first element in the list.
1324 if (CurrentTableSignature
== EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
) {
1325 RemoveFromRsdt
= FALSE
;
1329 // Remove the table from RSDT and XSDT
1331 if (Table
->Table
!= NULL
) {
1333 // This is a basic table, remove it from any lists and the Rsdt and/or Xsdt
1335 if (Version
& EFI_ACPI_TABLE_VERSION_NONE
& Table
->Version
) {
1337 // Remove this version from the table
1339 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_NONE
;
1342 if (Version
& EFI_ACPI_TABLE_VERSION_1_0B
& Table
->Version
) {
1344 // Remove this version from the table
1346 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_1_0B
;
1349 // Remove from Rsdt. We don't care about the return value because it is
1350 // acceptable for the table to not exist in Rsdt.
1351 // We didn't add some tables so we don't remove them.
1353 if (RemoveFromRsdt
) {
1354 RemoveTableFromRsdt (
1356 &AcpiTableInstance
->NumberOfTableEntries1
,
1357 AcpiTableInstance
->Rsdt1
,
1363 if (Version
& ACPI_TABLE_VERSION_GTE_2_0
& Table
->Version
) {
1365 // Remove this version from the table
1367 Table
->Version
= Table
->Version
&~(Version
& ACPI_TABLE_VERSION_GTE_2_0
);
1370 // Remove from Rsdt and Xsdt. We don't care about the return value
1371 // because it is acceptable for the table to not exist in Rsdt/Xsdt.
1372 // We didn't add some tables so we don't remove them.
1374 if (RemoveFromRsdt
) {
1375 RemoveTableFromRsdt (
1377 &AcpiTableInstance
->NumberOfTableEntries3
,
1378 AcpiTableInstance
->Rsdt3
,
1379 AcpiTableInstance
->Xsdt
1384 // Free the table, clean up any dependent tables and our private data pointers.
1386 switch (Table
->Table
->Signature
) {
1388 case EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
1389 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1390 AcpiTableInstance
->Fadt1
= NULL
;
1393 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
1394 AcpiTableInstance
->Fadt3
= NULL
;
1398 case EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
1399 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1400 AcpiTableInstance
->Facs1
= NULL
;
1403 // Update FADT table pointers
1405 if (AcpiTableInstance
->Fadt1
!= NULL
) {
1406 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= 0;
1411 AcpiPlatformChecksum (
1412 AcpiTableInstance
->Fadt1
,
1413 AcpiTableInstance
->Fadt1
->Header
.Length
,
1414 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1420 if ((Version
& ACPI_TABLE_VERSION_GTE_2_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
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
1467 AcpiTableInstance
->Dsdt3
= NULL
;
1470 // Update FADT table pointers
1472 if (AcpiTableInstance
->Fadt3
!= NULL
) {
1473 AcpiTableInstance
->Fadt3
->Dsdt
= 0;
1474 ZeroMem (&AcpiTableInstance
->Fadt3
->XDsdt
, sizeof (UINT64
));
1479 AcpiPlatformChecksum (
1480 AcpiTableInstance
->Fadt3
,
1481 AcpiTableInstance
->Fadt3
->Header
.Length
,
1482 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1497 // If no version is using this table anymore, remove and free list entry.
1499 if (Table
->Version
== 0) {
1503 FreeTableMemory (Table
);
1504 RemoveEntryList (&(Table
->Link
));
1505 gBS
->FreePool (Table
);
1515 This function finds and removes the table specified by the handle.
1517 @param AcpiTableInstance Instance of the protocol.
1518 @param Version Bitmask of which versions to remove.
1519 @param Handle Table to remove.
1521 @return EFI_SUCCESS The function completed successfully.
1522 @return EFI_ABORTED An error occurred.
1523 @return EFI_NOT_FOUND Handle not found in table list.
1527 RemoveTableFromList (
1528 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
1529 IN EFI_ACPI_TABLE_VERSION Version
,
1533 EFI_ACPI_TABLE_LIST
*Table
;
1536 Table
= (EFI_ACPI_TABLE_LIST
*) NULL
;
1539 // Check for invalid input parameters
1541 ASSERT (AcpiTableInstance
);
1546 Status
= FindTableByHandle (
1548 &AcpiTableInstance
->TableList
,
1551 if (EFI_ERROR (Status
)) {
1552 return EFI_NOT_FOUND
;
1557 Status
= DeleteTable (AcpiTableInstance
, Version
, Table
);
1558 if (EFI_ERROR (Status
)) {
1562 // Completed successfully
1569 This function calculates and updates an UINT8 checksum.
1571 @param Buffer Pointer to buffer to checksum
1572 @param Size Number of bytes to checksum
1573 @param ChecksumOffset Offset to place the checksum result in
1575 @return EFI_SUCCESS The function completed successfully.
1579 AcpiPlatformChecksum (
1582 IN UINTN ChecksumOffset
1590 // Initialize pointer
1595 // set checksum to 0 first
1597 Ptr
[ChecksumOffset
] = 0;
1600 // add all content of buffer
1602 while ((Size
--) != 0) {
1603 Sum
= (UINT8
) (Sum
+ (*Ptr
++));
1609 Ptr
[ChecksumOffset
] = (UINT8
) (0xff - Sum
+ 1);
1616 Checksum all versions of the common tables, RSDP, RSDT, XSDT.
1618 @param AcpiTableInstance Protocol instance private data.
1620 @return EFI_SUCCESS The function completed successfully.
1624 ChecksumCommonTables (
1625 IN OUT EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
1629 // RSDP ACPI 1.0 checksum for 1.0 table. This is only the first 20 bytes of the structure
1631 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
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
,
1641 // RSDP ACPI 1.0 checksum for 2.0/3.0 table. This is only the first 20 bytes of the structure
1643 AcpiPlatformChecksum (
1644 AcpiTableInstance
->Rsdp3
,
1645 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1646 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1651 // RSDP ACPI 2.0/3.0 checksum, this is the entire table
1653 AcpiPlatformChecksum (
1654 AcpiTableInstance
->Rsdp3
,
1655 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1656 OFFSET_OF (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1660 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1664 AcpiPlatformChecksum (
1665 AcpiTableInstance
->Rsdt1
,
1666 AcpiTableInstance
->Rsdt1
->Length
,
1667 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1671 AcpiPlatformChecksum (
1672 AcpiTableInstance
->Rsdt3
,
1673 AcpiTableInstance
->Rsdt3
->Length
,
1674 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1682 AcpiPlatformChecksum (
1683 AcpiTableInstance
->Xsdt
,
1684 AcpiTableInstance
->Xsdt
->Length
,
1685 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1694 Constructor for the ACPI table protocol. Initializes instance
1697 @param AcpiTableInstance Instance to construct
1699 @return EFI_SUCCESS Instance initialized.
1700 @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
1704 AcpiTableAcpiTableConstructor (
1705 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
1711 UINTN RsdpTableSize
;
1713 EFI_PHYSICAL_ADDRESS PageAddress
;
1716 // Check for invalid input parameters
1718 ASSERT (AcpiTableInstance
);
1721 // If ACPI v1.0b is among the ACPI versions we aim to support, we have to
1722 // ensure that all memory allocations are below 4 GB.
1724 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1725 mAcpiTableAllocType
= AllocateMaxAddress
;
1727 mAcpiTableAllocType
= AllocateAnyPages
;
1730 InitializeListHead (&AcpiTableInstance
->TableList
);
1731 AcpiTableInstance
->CurrentHandle
= 1;
1733 AcpiTableInstance
->AcpiTableProtocol
.InstallAcpiTable
= InstallAcpiTable
;
1734 AcpiTableInstance
->AcpiTableProtocol
.UninstallAcpiTable
= UninstallAcpiTable
;
1736 if (FeaturePcdGet (PcdInstallAcpiSdtProtocol
)) {
1737 SdtAcpiTableAcpiSdtConstructor (AcpiTableInstance
);
1741 // Create RSDP table
1743 RsdpTableSize
= sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1744 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1745 RsdpTableSize
+= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1748 if (mAcpiTableAllocType
!= AllocateAnyPages
) {
1749 PageAddress
= 0xFFFFFFFF;
1750 Status
= gBS
->AllocatePages (
1751 mAcpiTableAllocType
,
1752 EfiACPIReclaimMemory
,
1753 EFI_SIZE_TO_PAGES (RsdpTableSize
),
1757 Status
= gBS
->AllocatePool (
1758 EfiACPIReclaimMemory
,
1764 if (EFI_ERROR (Status
)) {
1765 return EFI_OUT_OF_RESOURCES
;
1768 if (mAcpiTableAllocType
!= AllocateAnyPages
) {
1769 Pointer
= (UINT8
*)(UINTN
)PageAddress
;
1771 ZeroMem (Pointer
, RsdpTableSize
);
1773 AcpiTableInstance
->Rsdp1
= (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1774 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1775 Pointer
+= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1777 AcpiTableInstance
->Rsdp3
= (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1780 // Create RSDT, XSDT structures
1782 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
1783 mEfiAcpiMaxNumTables
* sizeof (UINT64
);
1785 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1786 TotalSize
+= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
1787 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
1788 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
1789 mEfiAcpiMaxNumTables
* sizeof (UINT32
);
1792 if (mAcpiTableAllocType
!= AllocateAnyPages
) {
1794 // Allocate memory in the lower 32 bit of address range for
1795 // compatibility with ACPI 1.0 OS.
1797 // This is done because ACPI 1.0 pointers are 32 bit values.
1798 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
1799 // There is no architectural reason these should be below 4GB, it is purely
1800 // for convenience of implementation that we force memory below 4GB.
1802 PageAddress
= 0xFFFFFFFF;
1803 Status
= gBS
->AllocatePages (
1804 mAcpiTableAllocType
,
1805 EfiACPIReclaimMemory
,
1806 EFI_SIZE_TO_PAGES (TotalSize
),
1810 Status
= gBS
->AllocatePool (
1811 EfiACPIReclaimMemory
,
1817 if (EFI_ERROR (Status
)) {
1818 if (mAcpiTableAllocType
!= AllocateAnyPages
) {
1819 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
)(UINTN
)AcpiTableInstance
->Rsdp1
,
1820 EFI_SIZE_TO_PAGES (RsdpTableSize
));
1822 gBS
->FreePool (AcpiTableInstance
->Rsdp1
);
1824 return EFI_OUT_OF_RESOURCES
;
1827 if (mAcpiTableAllocType
!= AllocateAnyPages
) {
1828 Pointer
= (UINT8
*)(UINTN
)PageAddress
;
1830 ZeroMem (Pointer
, TotalSize
);
1832 AcpiTableInstance
->Rsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1833 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1834 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1835 AcpiTableInstance
->Rsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1836 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1838 AcpiTableInstance
->Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1843 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1844 CurrentData
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1845 CopyMem (&AcpiTableInstance
->Rsdp1
->Signature
, &CurrentData
, sizeof (UINT64
));
1846 CopyMem (AcpiTableInstance
->Rsdp1
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdp1
->OemId
));
1847 AcpiTableInstance
->Rsdp1
->Reserved
= EFI_ACPI_RESERVED_BYTE
;
1848 AcpiTableInstance
->Rsdp1
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt1
;
1851 CurrentData
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1852 CopyMem (&AcpiTableInstance
->Rsdp3
->Signature
, &CurrentData
, sizeof (UINT64
));
1853 CopyMem (AcpiTableInstance
->Rsdp3
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdp3
->OemId
));
1854 AcpiTableInstance
->Rsdp3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION
;
1855 AcpiTableInstance
->Rsdp3
->Length
= sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1856 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1857 AcpiTableInstance
->Rsdp3
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt3
;
1859 CurrentData
= (UINT64
) (UINTN
) AcpiTableInstance
->Xsdt
;
1860 CopyMem (&AcpiTableInstance
->Rsdp3
->XsdtAddress
, &CurrentData
, sizeof (UINT64
));
1861 SetMem (AcpiTableInstance
->Rsdp3
->Reserved
, 3, EFI_ACPI_RESERVED_BYTE
);
1863 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1867 // Note that we "reserve" one entry for the FADT so it can always be
1868 // at the beginning of the list of tables. Some OS don't seem
1869 // to find it correctly if it is too far down the list.
1871 AcpiTableInstance
->Rsdt1
->Signature
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1872 AcpiTableInstance
->Rsdt1
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1873 AcpiTableInstance
->Rsdt1
->Revision
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1874 CopyMem (AcpiTableInstance
->Rsdt1
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdt1
->OemId
));
1875 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1876 CopyMem (&AcpiTableInstance
->Rsdt1
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1877 AcpiTableInstance
->Rsdt1
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1878 AcpiTableInstance
->Rsdt1
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1879 AcpiTableInstance
->Rsdt1
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1881 // We always reserve first one for FADT
1883 AcpiTableInstance
->NumberOfTableEntries1
= 1;
1884 AcpiTableInstance
->Rsdt1
->Length
= AcpiTableInstance
->Rsdt1
->Length
+ sizeof(UINT32
);
1886 AcpiTableInstance
->Rsdt3
->Signature
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1887 AcpiTableInstance
->Rsdt3
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1888 AcpiTableInstance
->Rsdt3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1889 CopyMem (AcpiTableInstance
->Rsdt3
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdt3
->OemId
));
1890 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1891 CopyMem (&AcpiTableInstance
->Rsdt3
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1892 AcpiTableInstance
->Rsdt3
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1893 AcpiTableInstance
->Rsdt3
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1894 AcpiTableInstance
->Rsdt3
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1896 // We always reserve first one for FADT
1898 AcpiTableInstance
->Rsdt3
->Length
= AcpiTableInstance
->Rsdt3
->Length
+ sizeof(UINT32
);
1900 AcpiTableInstance
->NumberOfTableEntries3
= 1;
1905 AcpiTableInstance
->Xsdt
->Signature
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1906 AcpiTableInstance
->Xsdt
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1907 AcpiTableInstance
->Xsdt
->Revision
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1908 CopyMem (AcpiTableInstance
->Xsdt
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Xsdt
->OemId
));
1909 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1910 CopyMem (&AcpiTableInstance
->Xsdt
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1911 AcpiTableInstance
->Xsdt
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1912 AcpiTableInstance
->Xsdt
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1913 AcpiTableInstance
->Xsdt
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1915 // We always reserve first one for FADT
1917 AcpiTableInstance
->Xsdt
->Length
= AcpiTableInstance
->Xsdt
->Length
+ sizeof(UINT64
);
1919 ChecksumCommonTables (AcpiTableInstance
);
1922 // Completed successfully