2 ACPI Table Protocol Implementation
4 Copyright (c) 2006 - 2016, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include "AcpiTable.h"
21 // The maximum number of tables that pre-allocated.
23 UINTN mEfiAcpiMaxNumTables
= EFI_ACPI_MAX_NUM_TABLES
;
26 // Allocation strategy to use for AllocatePages ().
27 // Runtime value depends on PcdExposedAcpiTableVersions.
29 STATIC EFI_ALLOCATE_TYPE mAcpiTableAllocType
;
32 This function adds an ACPI table to the table list. It will detect FACS and
33 allocate the correct type of memory and properly align the table.
35 @param AcpiTableInstance Instance of the protocol.
36 @param Table Table to add.
37 @param Checksum Does the table require checksumming.
38 @param Version The version of the list to add the table to.
39 @param Handle Pointer for returning the handle.
41 @return EFI_SUCCESS The function completed successfully.
42 @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
43 @return EFI_ABORTED The table is a duplicate of a table that is required
49 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
52 IN EFI_ACPI_TABLE_VERSION Version
,
57 This function finds and removes the table specified by the handle.
59 @param AcpiTableInstance Instance of the protocol.
60 @param Version Bitmask of which versions to remove.
61 @param Handle Table to remove.
63 @return EFI_SUCCESS The function completed successfully.
64 @return EFI_ABORTED An error occurred.
65 @return EFI_NOT_FOUND Handle not found in table list.
70 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
71 IN EFI_ACPI_TABLE_VERSION Version
,
76 This function calculates and updates an UINT8 checksum.
78 @param Buffer Pointer to buffer to checksum
79 @param Size Number of bytes to checksum
80 @param ChecksumOffset Offset to place the checksum result in
82 @return EFI_SUCCESS The function completed successfully.
85 AcpiPlatformChecksum (
88 IN UINTN ChecksumOffset
92 Checksum all versions of the common tables, RSDP, RSDT, XSDT.
94 @param AcpiTableInstance Protocol instance private data.
96 @return EFI_SUCCESS The function completed successfully.
100 ChecksumCommonTables (
101 IN OUT EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
105 // Protocol function implementations.
109 This function publishes the specified versions of the ACPI tables by
110 installing EFI configuration table entries for them. Any combination of
111 table versions can be published.
113 @param AcpiTableInstance Instance of the protocol.
114 @param Version Version(s) to publish.
116 @return EFI_SUCCESS The function completed successfully.
117 @return EFI_ABORTED The function could not complete successfully.
123 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
124 IN EFI_ACPI_TABLE_VERSION Version
128 UINT32
*CurrentRsdtEntry
;
129 VOID
*CurrentXsdtEntry
;
133 // Reorder tables as some operating systems don't seem to find the
134 // FADT correctly if it is not in the first few entries
138 // Add FADT as the first entry
140 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
141 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) AcpiTableInstance
->Rsdt1
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
142 *CurrentRsdtEntry
= (UINT32
) (UINTN
) AcpiTableInstance
->Fadt1
;
144 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) AcpiTableInstance
->Rsdt3
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
145 *CurrentRsdtEntry
= (UINT32
) (UINTN
) AcpiTableInstance
->Fadt3
;
147 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
148 CurrentXsdtEntry
= (VOID
*) ((UINT8
*) AcpiTableInstance
->Xsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
150 // Add entry to XSDT, XSDT expects 64 bit pointers, but
151 // the table pointers in XSDT are not aligned on 8 byte boundary.
153 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Fadt3
;
162 // Do checksum again because Dsdt/Xsdt is updated.
164 ChecksumCommonTables (AcpiTableInstance
);
167 // Add the RSD_PTR to the system table and store that we have installed the
170 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
171 Status
= gBS
->InstallConfigurationTable (&gEfiAcpi10TableGuid
, AcpiTableInstance
->Rsdp1
);
172 if (EFI_ERROR (Status
)) {
177 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
178 Status
= gBS
->InstallConfigurationTable (&gEfiAcpiTableGuid
, AcpiTableInstance
->Rsdp3
);
179 if (EFI_ERROR (Status
)) {
189 Installs an ACPI table into the RSDT/XSDT.
190 Note that the ACPI table should be checksumed before installing it.
191 Otherwise it will assert.
193 @param This Protocol instance pointer.
194 @param AcpiTableBuffer A pointer to a buffer containing the ACPI table to be installed.
195 @param AcpiTableBufferSize Specifies the size, in bytes, of the AcpiTableBuffer buffer.
196 @param TableKey Reurns a key to refer to the ACPI table.
198 @return EFI_SUCCESS The table was successfully inserted.
199 @return EFI_INVALID_PARAMETER Either AcpiTableBuffer is NULL, TableKey is NULL, or AcpiTableBufferSize
200 and the size field embedded in the ACPI table pointed to by AcpiTableBuffer
202 @return EFI_OUT_OF_RESOURCES Insufficient resources exist to complete the request.
203 @retval EFI_ACCESS_DENIED The table signature matches a table already
204 present in the system and platform policy
205 does not allow duplicate tables of this type.
211 IN EFI_ACPI_TABLE_PROTOCOL
*This
,
212 IN VOID
*AcpiTableBuffer
,
213 IN UINTN AcpiTableBufferSize
,
217 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
;
219 VOID
*AcpiTableBufferConst
;
220 EFI_ACPI_TABLE_VERSION Version
;
223 // Check for invalid input parameters
225 if ((AcpiTableBuffer
== NULL
) || (TableKey
== NULL
)
226 || (((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTableBuffer
)->Length
!= AcpiTableBufferSize
)) {
227 return EFI_INVALID_PARAMETER
;
230 Version
= PcdGet32 (PcdAcpiExposedTableVersions
);
233 // Get the instance of the ACPI table protocol
235 AcpiTableInstance
= EFI_ACPI_TABLE_INSTANCE_FROM_THIS (This
);
238 // Install the ACPI table
240 AcpiTableBufferConst
= AllocateCopyPool (AcpiTableBufferSize
,AcpiTableBuffer
);
242 Status
= AddTableToList (
244 AcpiTableBufferConst
,
249 if (!EFI_ERROR (Status
)) {
250 Status
= PublishTables (
255 FreePool (AcpiTableBufferConst
);
258 // Add a new table successfully, notify registed callback
260 if (FeaturePcdGet (PcdInstallAcpiSdtProtocol
)) {
261 if (!EFI_ERROR (Status
)) {
275 Removes an ACPI table from the RSDT/XSDT.
277 @param This Protocol instance pointer.
278 @param TableKey Specifies the table to uninstall. The key was returned from InstallAcpiTable().
280 @return EFI_SUCCESS The table was successfully uninstalled.
281 @return EFI_NOT_FOUND TableKey does not refer to a valid key for a table entry.
287 IN EFI_ACPI_TABLE_PROTOCOL
*This
,
291 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
;
295 // Get the instance of the ACPI table protocol
297 AcpiTableInstance
= EFI_ACPI_TABLE_INSTANCE_FROM_THIS (This
);
300 // Uninstall the ACPI table
302 Status
= RemoveTableFromList (
304 EFI_ACPI_TABLE_VERSION_1_0B
| ACPI_TABLE_VERSION_GTE_2_0
,
307 if (!EFI_ERROR (Status
)) {
308 Status
= PublishTables (
310 EFI_ACPI_TABLE_VERSION_1_0B
| ACPI_TABLE_VERSION_GTE_2_0
314 if (EFI_ERROR (Status
)) {
315 return EFI_NOT_FOUND
;
322 If the number of APCI tables exceeds the preallocated max table number, enlarge the table buffer.
324 @param AcpiTableInstance ACPI table protocol instance data structure.
326 @return EFI_SUCCESS reallocate the table beffer successfully.
327 @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
331 ReallocateAcpiTableBuffer (
332 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
335 UINTN NewMaxTableNumber
;
338 EFI_PHYSICAL_ADDRESS PageAddress
;
339 EFI_ACPI_TABLE_INSTANCE TempPrivateData
;
343 CopyMem (&TempPrivateData
, AcpiTableInstance
, sizeof (EFI_ACPI_TABLE_INSTANCE
));
345 // Enlarge the max table number from mEfiAcpiMaxNumTables to mEfiAcpiMaxNumTables + EFI_ACPI_MAX_NUM_TABLES
347 NewMaxTableNumber
= mEfiAcpiMaxNumTables
+ EFI_ACPI_MAX_NUM_TABLES
;
349 // Create RSDT, XSDT structures and allocate buffers.
351 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
352 NewMaxTableNumber
* sizeof (UINT64
);
354 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
355 TotalSize
+= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
356 NewMaxTableNumber
* sizeof (UINT32
) +
357 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
358 NewMaxTableNumber
* sizeof (UINT32
);
362 // Allocate memory in the lower 32 bit of address range for
363 // compatibility with ACPI 1.0 OS.
365 // This is done because ACPI 1.0 pointers are 32 bit values.
366 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
367 // There is no architectural reason these should be below 4GB, it is purely
368 // for convenience of implementation that we force memory below 4GB.
370 PageAddress
= 0xFFFFFFFF;
371 Status
= gBS
->AllocatePages (
373 EfiACPIReclaimMemory
,
374 EFI_SIZE_TO_PAGES (TotalSize
),
378 if (EFI_ERROR (Status
)) {
379 return EFI_OUT_OF_RESOURCES
;
382 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
383 ZeroMem (Pointer
, TotalSize
);
385 AcpiTableInstance
->Rsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
386 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
387 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + NewMaxTableNumber
* sizeof (UINT32
));
388 AcpiTableInstance
->Rsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
389 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + NewMaxTableNumber
* sizeof (UINT32
));
391 AcpiTableInstance
->Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
394 // Update RSDP to point to the new Rsdt and Xsdt address.
396 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
397 AcpiTableInstance
->Rsdp1
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt1
;
398 AcpiTableInstance
->Rsdp3
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt3
;
400 CurrentData
= (UINT64
) (UINTN
) AcpiTableInstance
->Xsdt
;
401 CopyMem (&AcpiTableInstance
->Rsdp3
->XsdtAddress
, &CurrentData
, sizeof (UINT64
));
404 // copy the original Rsdt1, Rsdt3 and Xsdt structure to new buffer
406 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
407 CopyMem (AcpiTableInstance
->Rsdt1
, TempPrivateData
.Rsdt1
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT32
)));
408 CopyMem (AcpiTableInstance
->Rsdt3
, TempPrivateData
.Rsdt3
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT32
)));
410 CopyMem (AcpiTableInstance
->Xsdt
, TempPrivateData
.Xsdt
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT64
)));
413 // Calculate orignal ACPI table buffer size
415 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
416 mEfiAcpiMaxNumTables
* sizeof (UINT64
);
418 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
419 TotalSize
+= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
420 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
421 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
422 mEfiAcpiMaxNumTables
* sizeof (UINT32
);
425 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
)(UINTN
)TempPrivateData
.Rsdt1
, EFI_SIZE_TO_PAGES (TotalSize
));
428 // Update the Max ACPI table number
430 mEfiAcpiMaxNumTables
= NewMaxTableNumber
;
435 This function adds an ACPI table to the table list. It will detect FACS and
436 allocate the correct type of memory and properly align the table.
438 @param AcpiTableInstance Instance of the protocol.
439 @param Table Table to add.
440 @param Checksum Does the table require checksumming.
441 @param Version The version of the list to add the table to.
442 @param Handle Pointer for returning the handle.
444 @return EFI_SUCCESS The function completed successfully.
445 @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
446 @retval EFI_ACCESS_DENIED The table signature matches a table already
447 present in the system and platform policy
448 does not allow duplicate tables of this type.
453 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
456 IN EFI_ACPI_TABLE_VERSION Version
,
461 EFI_ACPI_TABLE_LIST
*CurrentTableList
;
462 UINT32 CurrentTableSignature
;
463 UINT32 CurrentTableSize
;
464 UINT32
*CurrentRsdtEntry
;
465 VOID
*CurrentXsdtEntry
;
470 // Check for invalid input parameters
472 ASSERT (AcpiTableInstance
);
482 // Create a new list entry
484 CurrentTableList
= AllocatePool (sizeof (EFI_ACPI_TABLE_LIST
));
485 ASSERT (CurrentTableList
);
488 // Determine table type and size
490 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
)->Signature
;
491 CurrentTableSize
= ((EFI_ACPI_COMMON_HEADER
*) Table
)->Length
;
494 // Allocate a buffer for the table. All tables are allocated in the lower 32 bits of address space
495 // for backwards compatibility with ACPI 1.0 OS.
497 // This is done because ACPI 1.0 pointers are 32 bit values.
498 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
499 // There is no architectural reason these should be below 4GB, it is purely
500 // for convenience of implementation that we force memory below 4GB.
502 CurrentTableList
->PageAddress
= 0xFFFFFFFF;
503 CurrentTableList
->NumberOfPages
= EFI_SIZE_TO_PAGES (CurrentTableSize
);
506 // Allocation memory type depends on the type of the table
508 if ((CurrentTableSignature
== EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) ||
509 (CurrentTableSignature
== EFI_ACPI_4_0_UEFI_ACPI_DATA_TABLE_SIGNATURE
)) {
511 // Allocate memory for the FACS. This structure must be aligned
512 // on a 64 byte boundary and must be ACPI NVS memory.
513 // Using AllocatePages should ensure that it is always aligned.
514 // Do not change signature for new ACPI version because they are same.
516 // UEFI table also need to be in ACPI NVS memory, because some data field
517 // could be updated by OS present agent. For example, BufferPtrAddress in
518 // SMM communication ACPI table.
520 ASSERT ((EFI_PAGE_SIZE
% 64) == 0);
521 Status
= gBS
->AllocatePages (
524 CurrentTableList
->NumberOfPages
,
525 &CurrentTableList
->PageAddress
529 // All other tables are ACPI reclaim memory, no alignment requirements.
531 Status
= gBS
->AllocatePages (
533 EfiACPIReclaimMemory
,
534 CurrentTableList
->NumberOfPages
,
535 &CurrentTableList
->PageAddress
539 // Check return value from memory alloc.
541 if (EFI_ERROR (Status
)) {
542 gBS
->FreePool (CurrentTableList
);
543 return EFI_OUT_OF_RESOURCES
;
546 // Update the table pointer with the allocated memory start
548 CurrentTableList
->Table
= (EFI_ACPI_COMMON_HEADER
*) (UINTN
) CurrentTableList
->PageAddress
;
551 // Initialize the table contents
553 CurrentTableList
->Signature
= EFI_ACPI_TABLE_LIST_SIGNATURE
;
554 CopyMem (CurrentTableList
->Table
, Table
, CurrentTableSize
);
555 CurrentTableList
->Handle
= AcpiTableInstance
->CurrentHandle
++;
556 *Handle
= CurrentTableList
->Handle
;
557 CurrentTableList
->Version
= Version
;
560 // Update internal pointers if this is a required table. If it is a required
561 // table and a table of that type already exists, return an error.
563 // Calculate the checksum if the table is not FACS.
565 switch (CurrentTableSignature
) {
567 case EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
569 // We don't add the FADT in the standard way because some
570 // OS expect the FADT to be early in the table list.
571 // So we always add it as the first element in the list.
576 // Check that the table has not been previously added.
578 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Fadt1
!= NULL
) ||
579 ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0 && AcpiTableInstance
->Fadt3
!= NULL
)
581 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
582 gBS
->FreePool (CurrentTableList
);
583 return EFI_ACCESS_DENIED
;
586 // Add the table to the appropriate table version
588 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
590 // Save a pointer to the table
592 AcpiTableInstance
->Fadt1
= (EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE
*) CurrentTableList
->Table
;
595 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
597 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs1
;
598 AcpiTableInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt1
;
601 // RSDP OEM information is updated to match the FADT OEM information
604 &AcpiTableInstance
->Rsdp1
->OemId
,
605 &AcpiTableInstance
->Fadt1
->Header
.OemId
,
610 // RSDT OEM information is updated to match the FADT OEM information.
613 &AcpiTableInstance
->Rsdt1
->OemId
,
614 &AcpiTableInstance
->Fadt1
->Header
.OemId
,
619 &AcpiTableInstance
->Rsdt1
->OemTableId
,
620 &AcpiTableInstance
->Fadt1
->Header
.OemTableId
,
623 AcpiTableInstance
->Rsdt1
->OemRevision
= AcpiTableInstance
->Fadt1
->Header
.OemRevision
;
626 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
628 // Save a pointer to the table
630 AcpiTableInstance
->Fadt3
= (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE
*) CurrentTableList
->Table
;
633 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
634 // Note: If the FIRMWARE_CTRL is non-zero, then X_FIRMWARE_CTRL must be zero, and
637 if ((UINT64
)(UINTN
)AcpiTableInstance
->Facs3
< BASE_4GB
) {
638 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs3
;
639 ZeroMem (&AcpiTableInstance
->Fadt3
->XFirmwareCtrl
, sizeof (UINT64
));
641 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Facs3
;
643 &AcpiTableInstance
->Fadt3
->XFirmwareCtrl
,
647 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= 0;
649 if ((UINT64
)(UINTN
)AcpiTableInstance
->Dsdt3
< BASE_4GB
) {
650 AcpiTableInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt3
;
652 // Comment block "the caller installs the tables in "DSDT, FADT" order"
653 // The below comments are also in "the caller installs the tables in "FADT, DSDT" order" comment block.
655 // The ACPI specification, up to and including revision 5.1 Errata A,
656 // allows the DSDT and X_DSDT fields to be both set in the FADT.
657 // (Obviously, this only makes sense if the DSDT address is representable in 4 bytes.)
658 // Starting with 5.1 Errata B, specifically for Mantis 1393 <https://mantis.uefi.org/mantis/view.php?id=1393>,
659 // the spec requires at most one of DSDT and X_DSDT fields to be set to a nonzero value,
660 // but strangely an exception is 6.0 that has no this requirement.
662 // Here we do not make the DSDT and X_DSDT fields mutual exclusion conditionally
663 // by checking FADT revision, but always set both DSDT and X_DSDT fields in the FADT
664 // to have better compatibility as some OS may have assumption to only consume X_DSDT
665 // field even the DSDT address is < 4G.
667 Buffer64
= AcpiTableInstance
->Fadt3
->Dsdt
;
669 AcpiTableInstance
->Fadt3
->Dsdt
= 0;
670 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Dsdt3
;
672 CopyMem (&AcpiTableInstance
->Fadt3
->XDsdt
, &Buffer64
, sizeof (UINT64
));
675 // RSDP OEM information is updated to match the FADT OEM information
678 &AcpiTableInstance
->Rsdp3
->OemId
,
679 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
683 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
685 // RSDT OEM information is updated to match FADT OEM information.
688 &AcpiTableInstance
->Rsdt3
->OemId
,
689 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
693 &AcpiTableInstance
->Rsdt3
->OemTableId
,
694 &AcpiTableInstance
->Fadt3
->Header
.OemTableId
,
697 AcpiTableInstance
->Rsdt3
->OemRevision
= AcpiTableInstance
->Fadt3
->Header
.OemRevision
;
701 // XSDT OEM information is updated to match FADT OEM information.
704 &AcpiTableInstance
->Xsdt
->OemId
,
705 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
709 &AcpiTableInstance
->Xsdt
->OemTableId
,
710 &AcpiTableInstance
->Fadt3
->Header
.OemTableId
,
713 AcpiTableInstance
->Xsdt
->OemRevision
= AcpiTableInstance
->Fadt3
->Header
.OemRevision
;
716 // Checksum the table
719 AcpiPlatformChecksum (
720 CurrentTableList
->Table
,
721 CurrentTableList
->Table
->Length
,
722 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
728 case EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
730 // Check that the table has not been previously added.
732 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Facs1
!= NULL
) ||
733 ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0 && AcpiTableInstance
->Facs3
!= NULL
)
735 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
736 gBS
->FreePool (CurrentTableList
);
737 return EFI_ACCESS_DENIED
;
740 // FACS is referenced by FADT and is not part of RSDT
745 // Add the table to the appropriate table version
747 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
749 // Save a pointer to the table
751 AcpiTableInstance
->Facs1
= (EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
754 // If FADT already exists, update table pointers.
756 if (AcpiTableInstance
->Fadt1
!= NULL
) {
757 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs1
;
760 // Checksum FADT table
762 AcpiPlatformChecksum (
763 AcpiTableInstance
->Fadt1
,
764 AcpiTableInstance
->Fadt1
->Header
.Length
,
765 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
771 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
773 // Save a pointer to the table
775 AcpiTableInstance
->Facs3
= (EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
778 // If FADT already exists, update table pointers.
780 if (AcpiTableInstance
->Fadt3
!= NULL
) {
782 // Note: If the FIRMWARE_CTRL is non-zero, then X_FIRMWARE_CTRL must be zero, and
785 if ((UINT64
)(UINTN
)AcpiTableInstance
->Facs3
< BASE_4GB
) {
786 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs3
;
787 ZeroMem (&AcpiTableInstance
->Fadt3
->XFirmwareCtrl
, sizeof (UINT64
));
789 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Facs3
;
791 &AcpiTableInstance
->Fadt3
->XFirmwareCtrl
,
795 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= 0;
799 // Checksum FADT table
801 AcpiPlatformChecksum (
802 AcpiTableInstance
->Fadt3
,
803 AcpiTableInstance
->Fadt3
->Header
.Length
,
804 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
812 case EFI_ACPI_1_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
814 // Check that the table has not been previously added.
816 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Dsdt1
!= NULL
) ||
817 ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0 && AcpiTableInstance
->Dsdt3
!= NULL
)
819 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
820 gBS
->FreePool (CurrentTableList
);
821 return EFI_ACCESS_DENIED
;
824 // DSDT is referenced by FADT and is not part of RSDT
829 // Add the table to the appropriate table version
831 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
833 // Save a pointer to the table
835 AcpiTableInstance
->Dsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
838 // If FADT already exists, update table pointers.
840 if (AcpiTableInstance
->Fadt1
!= NULL
) {
841 AcpiTableInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt1
;
844 // Checksum FADT table
846 AcpiPlatformChecksum (
847 AcpiTableInstance
->Fadt1
,
848 AcpiTableInstance
->Fadt1
->Header
.Length
,
849 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
855 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
857 // Save a pointer to the table
859 AcpiTableInstance
->Dsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
862 // If FADT already exists, update table pointers.
864 if (AcpiTableInstance
->Fadt3
!= NULL
) {
865 if ((UINT64
)(UINTN
)AcpiTableInstance
->Dsdt3
< BASE_4GB
) {
866 AcpiTableInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt3
;
868 // Comment block "the caller installs the tables in "FADT, DSDT" order"
869 // The below comments are also in "the caller installs the tables in "DSDT, FADT" order" comment block.
871 // The ACPI specification, up to and including revision 5.1 Errata A,
872 // allows the DSDT and X_DSDT fields to be both set in the FADT.
873 // (Obviously, this only makes sense if the DSDT address is representable in 4 bytes.)
874 // Starting with 5.1 Errata B, specifically for Mantis 1393 <https://mantis.uefi.org/mantis/view.php?id=1393>,
875 // the spec requires at most one of DSDT and X_DSDT fields to be set to a nonzero value,
876 // but strangely an exception is 6.0 that has no this requirement.
878 // Here we do not make the DSDT and X_DSDT fields mutual exclusion conditionally
879 // by checking FADT revision, but always set both DSDT and X_DSDT fields in the FADT
880 // to have better compatibility as some OS may have assumption to only consume X_DSDT
881 // field even the DSDT address is < 4G.
883 Buffer64
= AcpiTableInstance
->Fadt3
->Dsdt
;
885 AcpiTableInstance
->Fadt3
->Dsdt
= 0;
886 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Dsdt3
;
888 CopyMem (&AcpiTableInstance
->Fadt3
->XDsdt
, &Buffer64
, sizeof (UINT64
));
891 // Checksum FADT table
893 AcpiPlatformChecksum (
894 AcpiTableInstance
->Fadt3
,
895 AcpiTableInstance
->Fadt3
->Header
.Length
,
896 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
902 // Checksum the table
905 AcpiPlatformChecksum (
906 CurrentTableList
->Table
,
907 CurrentTableList
->Table
->Length
,
908 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
916 // Checksum the table
919 AcpiPlatformChecksum (
920 CurrentTableList
->Table
,
921 CurrentTableList
->Table
->Length
,
922 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
929 // Add the table to the current list of tables
931 InsertTailList (&AcpiTableInstance
->TableList
, &CurrentTableList
->Link
);
934 // Add the table to RSDT and/or XSDT table entry lists.
937 // Add to ACPI 1.0b table tree
939 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
942 // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
944 if (AcpiTableInstance
->NumberOfTableEntries1
>= mEfiAcpiMaxNumTables
) {
945 Status
= ReallocateAcpiTableBuffer (AcpiTableInstance
);
946 ASSERT_EFI_ERROR (Status
);
948 CurrentRsdtEntry
= (UINT32
*)
950 (UINT8
*) AcpiTableInstance
->Rsdt1
+
951 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
952 AcpiTableInstance
->NumberOfTableEntries1
*
957 // Add entry to the RSDT unless its the FACS or DSDT
959 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
962 // Update RSDT length
964 AcpiTableInstance
->Rsdt1
->Length
= AcpiTableInstance
->Rsdt1
->Length
+ sizeof (UINT32
);
966 AcpiTableInstance
->NumberOfTableEntries1
++;
970 // Add to ACPI 2.0/3.0 table tree
972 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
975 // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
977 if (AcpiTableInstance
->NumberOfTableEntries3
>= mEfiAcpiMaxNumTables
) {
978 Status
= ReallocateAcpiTableBuffer (AcpiTableInstance
);
979 ASSERT_EFI_ERROR (Status
);
982 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
984 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
985 // If it becomes necessary to maintain separate table lists, changes will be required.
987 CurrentRsdtEntry
= (UINT32
*)
989 (UINT8
*) AcpiTableInstance
->Rsdt3
+
990 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
991 AcpiTableInstance
->NumberOfTableEntries3
*
996 // Add entry to the RSDT
998 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
1001 // Update RSDT length
1003 AcpiTableInstance
->Rsdt3
->Length
= AcpiTableInstance
->Rsdt3
->Length
+ sizeof (UINT32
);
1007 // This pointer must not be directly dereferenced as the XSDT entries may not
1008 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
1010 CurrentXsdtEntry
= (VOID
*)
1012 (UINT8
*) AcpiTableInstance
->Xsdt
+
1013 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
1014 AcpiTableInstance
->NumberOfTableEntries3
*
1019 // Add entry to XSDT, XSDT expects 64 bit pointers, but
1020 // the table pointers in XSDT are not aligned on 8 byte boundary.
1022 Buffer64
= (UINT64
) (UINTN
) CurrentTableList
->Table
;
1032 AcpiTableInstance
->Xsdt
->Length
= AcpiTableInstance
->Xsdt
->Length
+ sizeof (UINT64
);
1034 AcpiTableInstance
->NumberOfTableEntries3
++;
1038 ChecksumCommonTables (AcpiTableInstance
);
1044 This function finds the table specified by the handle and returns a pointer to it.
1045 If the handle is not found, EFI_NOT_FOUND is returned and the contents of Table are
1048 @param Handle Table to find.
1049 @param TableList Table list to search
1050 @param Table Pointer to table found.
1052 @return EFI_SUCCESS The function completed successfully.
1053 @return EFI_NOT_FOUND No table found matching the handle specified.
1059 IN LIST_ENTRY
*TableList
,
1060 OUT EFI_ACPI_TABLE_LIST
**Table
1063 LIST_ENTRY
*CurrentLink
;
1064 EFI_ACPI_TABLE_LIST
*CurrentTable
;
1067 // Check for invalid input parameters
1074 CurrentLink
= TableList
->ForwardLink
;
1076 while (CurrentLink
!= TableList
) {
1077 CurrentTable
= EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink
);
1078 if (CurrentTable
->Handle
== Handle
) {
1080 // Found handle, so return this table.
1082 *Table
= CurrentTable
;
1086 CurrentLink
= CurrentLink
->ForwardLink
;
1091 return EFI_NOT_FOUND
;
1096 This function removes a basic table from the RSDT and/or XSDT.
1097 For Acpi 1.0 tables, pass in the Rsdt.
1098 For Acpi 2.0 tables, pass in both Rsdt and Xsdt.
1100 @param Table Pointer to table found.
1101 @param NumberOfTableEntries Current number of table entries in the RSDT/XSDT
1102 @param Rsdt Pointer to the RSDT to remove from
1103 @param Xsdt Pointer to the Xsdt to remove from
1105 @return EFI_SUCCESS The function completed successfully.
1106 @return EFI_INVALID_PARAMETER The table was not found in both Rsdt and Xsdt.
1110 RemoveTableFromRsdt (
1111 IN OUT EFI_ACPI_TABLE_LIST
* Table
,
1112 IN OUT UINTN
*NumberOfTableEntries
,
1113 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Rsdt OPTIONAL
,
1114 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Xsdt OPTIONAL
1117 UINT32
*CurrentRsdtEntry
;
1118 VOID
*CurrentXsdtEntry
;
1119 UINT64 CurrentTablePointer64
;
1123 // Check for invalid input parameters
1126 ASSERT (NumberOfTableEntries
);
1127 ASSERT (Rsdt
|| Xsdt
);
1130 // Find the table entry in the RSDT and XSDT
1132 for (Index
= 0; Index
< *NumberOfTableEntries
; Index
++) {
1134 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
1135 // If it becomes necessary to maintain separate table lists, changes will be required.
1138 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) Rsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + Index
* sizeof (UINT32
));
1140 CurrentRsdtEntry
= NULL
;
1144 // This pointer must not be directly dereferenced as the XSDT entries may not
1145 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
1147 CurrentXsdtEntry
= (VOID
*) ((UINT8
*) Xsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + Index
* sizeof (UINT64
));
1150 // Read the entry value out of the XSDT
1152 CopyMem (&CurrentTablePointer64
, CurrentXsdtEntry
, sizeof (UINT64
));
1155 // Initialize to NULL
1157 CurrentXsdtEntry
= 0;
1158 CurrentTablePointer64
= 0;
1161 // Check if we have found the corresponding entry in both RSDT and XSDT
1163 if (((Rsdt
== NULL
) || *CurrentRsdtEntry
== (UINT32
) (UINTN
) Table
->Table
) &&
1164 ((Xsdt
== NULL
) || CurrentTablePointer64
== (UINT64
) (UINTN
) Table
->Table
)
1167 // Found entry, so copy all following entries and shrink table
1168 // We actually copy all + 1 to copy the initialized value of memory over
1172 CopyMem (CurrentRsdtEntry
, CurrentRsdtEntry
+ 1, (*NumberOfTableEntries
- Index
) * sizeof (UINT32
));
1173 Rsdt
->Length
= Rsdt
->Length
- sizeof (UINT32
);
1176 CopyMem (CurrentXsdtEntry
, ((UINT64
*) CurrentXsdtEntry
) + 1, (*NumberOfTableEntries
- Index
) * sizeof (UINT64
));
1177 Xsdt
->Length
= Xsdt
->Length
- sizeof (UINT64
);
1180 } else if (Index
+ 1 == *NumberOfTableEntries
) {
1182 // At the last entry, and table not found
1184 return EFI_INVALID_PARAMETER
;
1188 // Checksum the tables
1191 AcpiPlatformChecksum (
1194 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1200 AcpiPlatformChecksum (
1203 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1208 // Decrement the number of tables
1210 (*NumberOfTableEntries
)--;
1217 This function removes a table and frees any associated memory.
1219 @param AcpiTableInstance Instance of the protocol.
1220 @param Version Version(s) to delete.
1221 @param Table Pointer to table found.
1223 @return EFI_SUCCESS The function completed successfully.
1228 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
1229 IN EFI_ACPI_TABLE_VERSION Version
,
1230 IN OUT EFI_ACPI_TABLE_LIST
*Table
1233 UINT32 CurrentTableSignature
;
1234 BOOLEAN RemoveFromRsdt
;
1237 // Check for invalid input parameters
1239 ASSERT (AcpiTableInstance
);
1245 RemoveFromRsdt
= TRUE
;
1247 // Check for Table->Table
1249 ASSERT (Table
->Table
!= NULL
);
1250 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
->Table
)->Signature
;
1253 // Basic tasks to accomplish delete are:
1254 // Determine removal requirements (in RSDT/XSDT or not)
1255 // Remove entry from RSDT/XSDT
1256 // Remove any table references to the table
1257 // If no one is using the table
1258 // Free the table (removing pointers from private data and tables)
1260 // Free list structure
1263 // Determine if this table is in the RSDT or XSDT
1265 if ((CurrentTableSignature
== EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) ||
1266 (CurrentTableSignature
== EFI_ACPI_2_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
) ||
1267 (CurrentTableSignature
== EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
)
1269 RemoveFromRsdt
= FALSE
;
1272 // We don't remove the FADT in the standard way because some
1273 // OS expect the FADT to be early in the table list.
1274 // So we always put it as the first element in the list.
1276 if (CurrentTableSignature
== EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
) {
1277 RemoveFromRsdt
= FALSE
;
1281 // Remove the table from RSDT and XSDT
1283 if (Table
->Table
!= NULL
) {
1285 // This is a basic table, remove it from any lists and the Rsdt and/or Xsdt
1287 if (Version
& EFI_ACPI_TABLE_VERSION_NONE
& Table
->Version
) {
1289 // Remove this version from the table
1291 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_NONE
;
1294 if (Version
& EFI_ACPI_TABLE_VERSION_1_0B
& Table
->Version
) {
1296 // Remove this version from the table
1298 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_1_0B
;
1301 // Remove from Rsdt. We don't care about the return value because it is
1302 // acceptable for the table to not exist in Rsdt.
1303 // We didn't add some tables so we don't remove them.
1305 if (RemoveFromRsdt
) {
1306 RemoveTableFromRsdt (
1308 &AcpiTableInstance
->NumberOfTableEntries1
,
1309 AcpiTableInstance
->Rsdt1
,
1315 if (Version
& ACPI_TABLE_VERSION_GTE_2_0
& Table
->Version
) {
1317 // Remove this version from the table
1319 Table
->Version
= Table
->Version
&~(Version
& ACPI_TABLE_VERSION_GTE_2_0
);
1322 // Remove from Rsdt and Xsdt. We don't care about the return value
1323 // because it is acceptable for the table to not exist in Rsdt/Xsdt.
1324 // We didn't add some tables so we don't remove them.
1326 if (RemoveFromRsdt
) {
1327 RemoveTableFromRsdt (
1329 &AcpiTableInstance
->NumberOfTableEntries3
,
1330 AcpiTableInstance
->Rsdt3
,
1331 AcpiTableInstance
->Xsdt
1336 // Free the table, clean up any dependent tables and our private data pointers.
1338 switch (Table
->Table
->Signature
) {
1340 case EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
1341 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1342 AcpiTableInstance
->Fadt1
= NULL
;
1345 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
1346 AcpiTableInstance
->Fadt3
= NULL
;
1350 case EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
1351 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1352 AcpiTableInstance
->Facs1
= NULL
;
1355 // Update FADT table pointers
1357 if (AcpiTableInstance
->Fadt1
!= NULL
) {
1358 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= 0;
1363 AcpiPlatformChecksum (
1364 AcpiTableInstance
->Fadt1
,
1365 AcpiTableInstance
->Fadt1
->Header
.Length
,
1366 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1372 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
1373 AcpiTableInstance
->Facs3
= NULL
;
1376 // Update FADT table pointers
1378 if (AcpiTableInstance
->Fadt3
!= NULL
) {
1379 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= 0;
1380 ZeroMem (&AcpiTableInstance
->Fadt3
->XFirmwareCtrl
, sizeof (UINT64
));
1385 AcpiPlatformChecksum (
1386 AcpiTableInstance
->Fadt3
,
1387 AcpiTableInstance
->Fadt3
->Header
.Length
,
1388 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1395 case EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
1396 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1397 AcpiTableInstance
->Dsdt1
= NULL
;
1400 // Update FADT table pointers
1402 if (AcpiTableInstance
->Fadt1
!= NULL
) {
1403 AcpiTableInstance
->Fadt1
->Dsdt
= 0;
1408 AcpiPlatformChecksum (
1409 AcpiTableInstance
->Fadt1
,
1410 AcpiTableInstance
->Fadt1
->Header
.Length
,
1411 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1418 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
1419 AcpiTableInstance
->Dsdt3
= NULL
;
1422 // Update FADT table pointers
1424 if (AcpiTableInstance
->Fadt3
!= NULL
) {
1425 AcpiTableInstance
->Fadt3
->Dsdt
= 0;
1426 ZeroMem (&AcpiTableInstance
->Fadt3
->XDsdt
, sizeof (UINT64
));
1431 AcpiPlatformChecksum (
1432 AcpiTableInstance
->Fadt3
,
1433 AcpiTableInstance
->Fadt3
->Header
.Length
,
1434 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1449 // If no version is using this table anymore, remove and free list entry.
1451 if (Table
->Version
== 0) {
1455 gBS
->FreePages (Table
->PageAddress
, Table
->NumberOfPages
);
1456 RemoveEntryList (&(Table
->Link
));
1457 gBS
->FreePool (Table
);
1467 This function finds and removes the table specified by the handle.
1469 @param AcpiTableInstance Instance of the protocol.
1470 @param Version Bitmask of which versions to remove.
1471 @param Handle Table to remove.
1473 @return EFI_SUCCESS The function completed successfully.
1474 @return EFI_ABORTED An error occurred.
1475 @return EFI_NOT_FOUND Handle not found in table list.
1479 RemoveTableFromList (
1480 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
1481 IN EFI_ACPI_TABLE_VERSION Version
,
1485 EFI_ACPI_TABLE_LIST
*Table
;
1488 Table
= (EFI_ACPI_TABLE_LIST
*) NULL
;
1491 // Check for invalid input parameters
1493 ASSERT (AcpiTableInstance
);
1498 Status
= FindTableByHandle (
1500 &AcpiTableInstance
->TableList
,
1503 if (EFI_ERROR (Status
)) {
1504 return EFI_NOT_FOUND
;
1509 Status
= DeleteTable (AcpiTableInstance
, Version
, Table
);
1510 if (EFI_ERROR (Status
)) {
1514 // Completed successfully
1521 This function calculates and updates an UINT8 checksum.
1523 @param Buffer Pointer to buffer to checksum
1524 @param Size Number of bytes to checksum
1525 @param ChecksumOffset Offset to place the checksum result in
1527 @return EFI_SUCCESS The function completed successfully.
1531 AcpiPlatformChecksum (
1534 IN UINTN ChecksumOffset
1542 // Initialize pointer
1547 // set checksum to 0 first
1549 Ptr
[ChecksumOffset
] = 0;
1552 // add all content of buffer
1554 while ((Size
--) != 0) {
1555 Sum
= (UINT8
) (Sum
+ (*Ptr
++));
1561 Ptr
[ChecksumOffset
] = (UINT8
) (0xff - Sum
+ 1);
1568 Checksum all versions of the common tables, RSDP, RSDT, XSDT.
1570 @param AcpiTableInstance Protocol instance private data.
1572 @return EFI_SUCCESS The function completed successfully.
1576 ChecksumCommonTables (
1577 IN OUT EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
1581 // RSDP ACPI 1.0 checksum for 1.0 table. This is only the first 20 bytes of the structure
1583 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1584 AcpiPlatformChecksum (
1585 AcpiTableInstance
->Rsdp1
,
1586 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1587 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1593 // RSDP ACPI 1.0 checksum for 2.0/3.0 table. This is only the first 20 bytes of the structure
1595 AcpiPlatformChecksum (
1596 AcpiTableInstance
->Rsdp3
,
1597 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1598 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1603 // RSDP ACPI 2.0/3.0 checksum, this is the entire table
1605 AcpiPlatformChecksum (
1606 AcpiTableInstance
->Rsdp3
,
1607 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1608 OFFSET_OF (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1612 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1616 AcpiPlatformChecksum (
1617 AcpiTableInstance
->Rsdt1
,
1618 AcpiTableInstance
->Rsdt1
->Length
,
1619 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1623 AcpiPlatformChecksum (
1624 AcpiTableInstance
->Rsdt3
,
1625 AcpiTableInstance
->Rsdt3
->Length
,
1626 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1634 AcpiPlatformChecksum (
1635 AcpiTableInstance
->Xsdt
,
1636 AcpiTableInstance
->Xsdt
->Length
,
1637 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1646 Constructor for the ACPI table protocol. Initializes instance
1649 @param AcpiTableInstance Instance to construct
1651 @return EFI_SUCCESS Instance initialized.
1652 @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
1656 AcpiTableAcpiTableConstructor (
1657 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
1663 UINTN RsdpTableSize
;
1665 EFI_PHYSICAL_ADDRESS PageAddress
;
1668 // Check for invalid input parameters
1670 ASSERT (AcpiTableInstance
);
1673 // If ACPI v1.0b is among the ACPI versions we aim to support, we have to
1674 // ensure that all memory allocations are below 4 GB.
1676 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1677 mAcpiTableAllocType
= AllocateMaxAddress
;
1679 mAcpiTableAllocType
= AllocateAnyPages
;
1682 InitializeListHead (&AcpiTableInstance
->TableList
);
1683 AcpiTableInstance
->CurrentHandle
= 1;
1685 AcpiTableInstance
->AcpiTableProtocol
.InstallAcpiTable
= InstallAcpiTable
;
1686 AcpiTableInstance
->AcpiTableProtocol
.UninstallAcpiTable
= UninstallAcpiTable
;
1688 if (FeaturePcdGet (PcdInstallAcpiSdtProtocol
)) {
1689 SdtAcpiTableAcpiSdtConstructor (AcpiTableInstance
);
1693 // Create RSDP table
1695 RsdpTableSize
= sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1696 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1697 RsdpTableSize
+= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1700 PageAddress
= 0xFFFFFFFF;
1701 Status
= gBS
->AllocatePages (
1702 mAcpiTableAllocType
,
1703 EfiACPIReclaimMemory
,
1704 EFI_SIZE_TO_PAGES (RsdpTableSize
),
1708 if (EFI_ERROR (Status
)) {
1709 return EFI_OUT_OF_RESOURCES
;
1712 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
1713 ZeroMem (Pointer
, RsdpTableSize
);
1715 AcpiTableInstance
->Rsdp1
= (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1716 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1717 Pointer
+= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1719 AcpiTableInstance
->Rsdp3
= (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1722 // Create RSDT, XSDT structures
1724 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
1725 mEfiAcpiMaxNumTables
* sizeof (UINT64
);
1727 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1728 TotalSize
+= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
1729 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
1730 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
1731 mEfiAcpiMaxNumTables
* sizeof (UINT32
);
1735 // Allocate memory in the lower 32 bit of address range for
1736 // compatibility with ACPI 1.0 OS.
1738 // This is done because ACPI 1.0 pointers are 32 bit values.
1739 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
1740 // There is no architectural reason these should be below 4GB, it is purely
1741 // for convenience of implementation that we force memory below 4GB.
1743 PageAddress
= 0xFFFFFFFF;
1744 Status
= gBS
->AllocatePages (
1745 mAcpiTableAllocType
,
1746 EfiACPIReclaimMemory
,
1747 EFI_SIZE_TO_PAGES (TotalSize
),
1751 if (EFI_ERROR (Status
)) {
1752 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
)(UINTN
)AcpiTableInstance
->Rsdp1
, EFI_SIZE_TO_PAGES (RsdpTableSize
));
1753 return EFI_OUT_OF_RESOURCES
;
1756 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
1757 ZeroMem (Pointer
, TotalSize
);
1759 AcpiTableInstance
->Rsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1760 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1761 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1762 AcpiTableInstance
->Rsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1763 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1765 AcpiTableInstance
->Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1770 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1771 CurrentData
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1772 CopyMem (&AcpiTableInstance
->Rsdp1
->Signature
, &CurrentData
, sizeof (UINT64
));
1773 CopyMem (AcpiTableInstance
->Rsdp1
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdp1
->OemId
));
1774 AcpiTableInstance
->Rsdp1
->Reserved
= EFI_ACPI_RESERVED_BYTE
;
1775 AcpiTableInstance
->Rsdp1
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt1
;
1778 CurrentData
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1779 CopyMem (&AcpiTableInstance
->Rsdp3
->Signature
, &CurrentData
, sizeof (UINT64
));
1780 CopyMem (AcpiTableInstance
->Rsdp3
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdp3
->OemId
));
1781 AcpiTableInstance
->Rsdp3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION
;
1782 AcpiTableInstance
->Rsdp3
->Length
= sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1783 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1784 AcpiTableInstance
->Rsdp3
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt3
;
1786 CurrentData
= (UINT64
) (UINTN
) AcpiTableInstance
->Xsdt
;
1787 CopyMem (&AcpiTableInstance
->Rsdp3
->XsdtAddress
, &CurrentData
, sizeof (UINT64
));
1788 SetMem (AcpiTableInstance
->Rsdp3
->Reserved
, 3, EFI_ACPI_RESERVED_BYTE
);
1790 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1794 // Note that we "reserve" one entry for the FADT so it can always be
1795 // at the beginning of the list of tables. Some OS don't seem
1796 // to find it correctly if it is too far down the list.
1798 AcpiTableInstance
->Rsdt1
->Signature
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1799 AcpiTableInstance
->Rsdt1
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1800 AcpiTableInstance
->Rsdt1
->Revision
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1801 CopyMem (AcpiTableInstance
->Rsdt1
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdt1
->OemId
));
1802 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1803 CopyMem (&AcpiTableInstance
->Rsdt1
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1804 AcpiTableInstance
->Rsdt1
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1805 AcpiTableInstance
->Rsdt1
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1806 AcpiTableInstance
->Rsdt1
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1808 // We always reserve first one for FADT
1810 AcpiTableInstance
->NumberOfTableEntries1
= 1;
1811 AcpiTableInstance
->Rsdt1
->Length
= AcpiTableInstance
->Rsdt1
->Length
+ sizeof(UINT32
);
1813 AcpiTableInstance
->Rsdt3
->Signature
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1814 AcpiTableInstance
->Rsdt3
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1815 AcpiTableInstance
->Rsdt3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1816 CopyMem (AcpiTableInstance
->Rsdt3
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdt3
->OemId
));
1817 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1818 CopyMem (&AcpiTableInstance
->Rsdt3
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1819 AcpiTableInstance
->Rsdt3
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1820 AcpiTableInstance
->Rsdt3
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1821 AcpiTableInstance
->Rsdt3
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1823 // We always reserve first one for FADT
1825 AcpiTableInstance
->Rsdt3
->Length
= AcpiTableInstance
->Rsdt3
->Length
+ sizeof(UINT32
);
1827 AcpiTableInstance
->NumberOfTableEntries3
= 1;
1832 AcpiTableInstance
->Xsdt
->Signature
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1833 AcpiTableInstance
->Xsdt
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1834 AcpiTableInstance
->Xsdt
->Revision
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1835 CopyMem (AcpiTableInstance
->Xsdt
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Xsdt
->OemId
));
1836 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1837 CopyMem (&AcpiTableInstance
->Xsdt
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1838 AcpiTableInstance
->Xsdt
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1839 AcpiTableInstance
->Xsdt
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1840 AcpiTableInstance
->Xsdt
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1842 // We always reserve first one for FADT
1844 AcpiTableInstance
->Xsdt
->Length
= AcpiTableInstance
->Xsdt
->Length
+ sizeof(UINT64
);
1846 ChecksumCommonTables (AcpiTableInstance
);
1849 // Completed successfully