2 ACPI Support Protocol implementation
4 Copyright (c) 2006 - 2014, Intel Corporation. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions
8 of the BSD License which accompanies this distribution. The
9 full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
20 #include "AcpiSupport.h"
22 // The maximum number of tables that pre-allocated.
24 UINTN mEfiAcpiMaxNumTables
= EFI_ACPI_MAX_NUM_TABLES
;
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 AcpiSupportInstance 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
42 IN EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
,
45 IN EFI_ACPI_TABLE_VERSION Version
,
49 This function finds and removes the table specified by the handle.
51 @param AcpiSupportInstance Instance of the protocol.
52 @param Version Bitmask of which versions to remove.
53 @param Handle Table to remove.
55 @return EFI_SUCCESS The function completed successfully.
56 @return EFI_ABORTED An error occurred.
57 @return EFI_NOT_FOUND Handle not found in table list.
61 IN EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
,
62 IN EFI_ACPI_TABLE_VERSION Version
,
66 This function calculates and updates an UINT8 checksum.
68 @param Buffer Pointer to buffer to checksum
69 @param Size Number of bytes to checksum
70 @param ChecksumOffset Offset to place the checksum result in
72 @return EFI_SUCCESS The function completed successfully.
75 AcpiPlatformChecksum (
78 IN UINTN ChecksumOffset
81 Checksum all versions of the common tables, RSDP, RSDT, XSDT.
83 @param AcpiSupportInstance Protocol instance private data.
85 @return EFI_SUCCESS The function completed successfully.
89 ChecksumCommonTables (
90 IN OUT EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
94 This function returns a table specified by an index if it exists.
96 The function returns a buffer containing the table that the caller must free.
97 The function also returns a handle used to identify the table for update or
98 deletion using the SetAcpiTable function.
100 @param This Instance of the protocol.
101 @param Index Zero-based index of the table to retrieve.
102 @param Table Returned pointer to the table.
103 @param Version Versions that the table is currently used in.
104 @param Handle Handle of the table, used in updating tables.
106 @retval EFI_SUCCESS The function completed successfully.
107 @retval EFI_NOT_FOUND The requested table does not exist.
113 IN EFI_ACPI_SUPPORT_PROTOCOL
*This
,
116 OUT EFI_ACPI_TABLE_VERSION
*Version
,
121 EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
;
123 LIST_ENTRY
*CurrentLink
;
124 LIST_ENTRY
*StartLink
;
125 EFI_ACPI_TABLE_LIST
*CurrentTable
;
128 // Check for invalid input parameters
135 // Get the instance of the protocol
137 AcpiSupportInstance
= EFI_ACPI_SUPPORT_INSTANCE_FROM_ACPI_SUPPORT_THIS (This
);
142 CurrentLink
= AcpiSupportInstance
->TableList
.ForwardLink
;
143 StartLink
= &AcpiSupportInstance
->TableList
;
144 for (TempIndex
= 0; (TempIndex
< Index
) && (CurrentLink
!= StartLink
) && (CurrentLink
!= NULL
); TempIndex
++) {
145 CurrentLink
= CurrentLink
->ForwardLink
;
148 if (TempIndex
!= Index
|| CurrentLink
== StartLink
) {
149 return EFI_NOT_FOUND
;
152 // Get handle and version
154 CurrentTable
= EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink
);
155 *Handle
= CurrentTable
->Handle
;
156 *Version
= CurrentTable
->Version
;
161 *Table
= AllocateCopyPool (CurrentTable
->Table
->Length
, CurrentTable
->Table
);
167 This function adds, removes, or updates ACPI tables. If the address is not
168 null and the handle value is null, the table is added. If both the address and
169 handle are not null, the table at handle is updated with the table at address.
170 If the address is null and the handle is not, the table at handle is deleted.
172 @param This Pointer of the protocol.
173 @param Table Pointer to a table.
174 @param Checksum Boolean indicating if the checksum should be calculated.
175 @param Version Version(s) to set.
176 @param Handle Handle of the table.
178 @return EFI_SUCCESS The function completed successfully.
179 @return EFI_INVALID_PARAMETER Both the Table and *Handle were NULL.
180 @return EFI_ABORTED Could not complete the desired request.
186 IN EFI_ACPI_SUPPORT_PROTOCOL
*This
,
187 IN VOID
*Table OPTIONAL
,
189 IN EFI_ACPI_TABLE_VERSION Version
,
193 EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
;
198 // Check for invalid input parameters
201 ASSERT (Handle
!= NULL
);
204 // Get the instance of the protocol
206 AcpiSupportInstance
= EFI_ACPI_SUPPORT_INSTANCE_FROM_ACPI_SUPPORT_THIS (This
);
212 // Determine desired action
217 // Invalid parameter combination
219 return EFI_INVALID_PARAMETER
;
224 Status
= AddTableToList (AcpiSupportInstance
, Table
, Checksum
, Version
, Handle
);
232 // Delete the table list entry
234 Status
= RemoveTableFromList (AcpiSupportInstance
, Version
, *Handle
);
235 if (EFI_ERROR (Status
)) {
237 // Should not get an error here ever, but abort if we do.
242 // Set the handle to replace the table at the same handle
244 SavedHandle
= AcpiSupportInstance
->CurrentHandle
;
245 AcpiSupportInstance
->CurrentHandle
= *Handle
;
250 Status
= AddTableToList (AcpiSupportInstance
, Table
, Checksum
, Version
, Handle
);
253 // Restore the saved current handle
255 AcpiSupportInstance
->CurrentHandle
= SavedHandle
;
260 Status
= RemoveTableFromList (AcpiSupportInstance
, Version
, *Handle
);
264 if (EFI_ERROR (Status
)) {
266 // Should not get an error here ever, but abort if we do.
276 This function publishes the specified versions of the ACPI tables by
277 installing EFI configuration table entries for them. Any combination of
278 table versions can be published.
280 @param This Pointer of the protocol.
281 @param Version Version(s) to publish.
283 @return EFI_SUCCESS The function completed successfully.
284 @return EFI_ABORTED The function could not complete successfully.
290 IN EFI_ACPI_SUPPORT_PROTOCOL
*This
,
291 IN EFI_ACPI_TABLE_VERSION Version
294 EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
;
296 UINT32
*CurrentRsdtEntry
;
297 VOID
*CurrentXsdtEntry
;
301 // Get the instance of the protocol
303 AcpiSupportInstance
= EFI_ACPI_SUPPORT_INSTANCE_FROM_ACPI_SUPPORT_THIS (This
);
306 // Reorder tables as some operating systems don't seem to find the
307 // FADT correctly if it is not in the first few entries
311 // Add FADT as the first entry
313 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
314 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) AcpiSupportInstance
->Rsdt1
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
315 *CurrentRsdtEntry
= (UINT32
) (UINTN
) AcpiSupportInstance
->Fadt1
;
317 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 || (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
318 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) AcpiSupportInstance
->Rsdt3
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
319 *CurrentRsdtEntry
= (UINT32
) (UINTN
) AcpiSupportInstance
->Fadt3
;
320 CurrentXsdtEntry
= (VOID
*) ((UINT8
*) AcpiSupportInstance
->Xsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
322 // Add entry to XSDT, XSDT expects 64 bit pointers, but
323 // the table pointers in XSDT are not aligned on 8 byte boundary.
325 Buffer64
= (UINT64
) (UINTN
) AcpiSupportInstance
->Fadt3
;
334 // Do checksum again because Dsdt/Xsdt is updated.
336 ChecksumCommonTables (AcpiSupportInstance
);
339 // Add the RSD_PTR to the system table and store that we have installed the
342 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && !AcpiSupportInstance
->TablesInstalled1
) {
343 Status
= gBS
->InstallConfigurationTable (&gEfiAcpi10TableGuid
, AcpiSupportInstance
->Rsdp1
);
344 if (EFI_ERROR (Status
)) {
348 AcpiSupportInstance
->TablesInstalled1
= TRUE
;
351 if (((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 || (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) &&
352 !AcpiSupportInstance
->TablesInstalled3
) {
353 Status
= gBS
->InstallConfigurationTable (&gEfiAcpiTableGuid
, AcpiSupportInstance
->Rsdp3
);
354 if (EFI_ERROR (Status
)) {
358 AcpiSupportInstance
->TablesInstalled3
= TRUE
;
364 Installs an ACPI table into the RSDT/XSDT.
365 Note that the ACPI table should be checksumed before installing it.
366 Otherwise it will assert.
368 @param This Protocol instance pointer.
369 @param AcpiTableBuffer A pointer to a buffer containing the ACPI table to be installed.
370 @param AcpiTableBufferSize Specifies the size, in bytes, of the AcpiTableBuffer buffer.
371 @param TableKey Reurns a key to refer to the ACPI table.
373 @return EFI_SUCCESS The table was successfully inserted.
374 @return EFI_INVALID_PARAMETER Either AcpiTableBuffer is NULL, TableKey is NULL, or AcpiTableBufferSize
375 and the size field embedded in the ACPI table pointed to by AcpiTableBuffer
377 @return EFI_OUT_OF_RESOURCES Insufficient resources exist to complete the request.
378 @retval EFI_ACCESS_DENIED The table signature matches a table already
379 present in the system and platform policy
380 does not allow duplicate tables of this type.
386 IN EFI_ACPI_TABLE_PROTOCOL
*This
,
387 IN VOID
*AcpiTableBuffer
,
388 IN UINTN AcpiTableBufferSize
,
392 EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
;
393 EFI_ACPI_SUPPORT_PROTOCOL
*AcpiSupport
;
395 VOID
*AcpiTableBufferConst
;
398 // Check for invalid input parameters
400 if ((AcpiTableBuffer
== NULL
) || (TableKey
== NULL
)
401 || (((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTableBuffer
)->Length
!= AcpiTableBufferSize
)) {
402 return EFI_INVALID_PARAMETER
;
406 // Get the instance of the ACPI support protocol
408 AcpiSupportInstance
= EFI_ACPI_TABLE_INSTANCE_FROM_ACPI_SUPPORT_THIS (This
);
409 AcpiSupport
= &AcpiSupportInstance
->AcpiSupport
;
412 // Install the ACPI table by using ACPI support protocol
414 AcpiTableBufferConst
= AllocateCopyPool (AcpiTableBufferSize
, AcpiTableBuffer
);
416 Status
= AddTableToList (
418 AcpiTableBufferConst
,
420 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
,
423 if (!EFI_ERROR (Status
)) {
424 Status
= AcpiSupport
->PublishTables (
426 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
429 FreePool (AcpiTableBufferConst
);
434 Removes an ACPI table from the RSDT/XSDT.
436 @param This Protocol instance pointer.
437 @param TableKey Specifies the table to uninstall. The key was returned from InstallAcpiTable().
439 @return EFI_SUCCESS The table was successfully uninstalled.
440 @return EFI_NOT_FOUND TableKey does not refer to a valid key for a table entry.
446 IN EFI_ACPI_TABLE_PROTOCOL
*This
,
450 EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
;
451 EFI_ACPI_SUPPORT_PROTOCOL
*AcpiSupport
;
455 // Get the instance of the ACPI support protocol
457 AcpiSupportInstance
= EFI_ACPI_TABLE_INSTANCE_FROM_ACPI_SUPPORT_THIS (This
);
458 AcpiSupport
= &AcpiSupportInstance
->AcpiSupport
;
461 // Uninstall the ACPI table by using ACPI support protocol
463 Status
= RemoveTableFromList (
465 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
,
468 if (!EFI_ERROR (Status
)) {
469 Status
= AcpiSupport
->PublishTables (
471 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
475 if (EFI_ERROR (Status
)) {
476 return EFI_NOT_FOUND
;
482 If the number of APCI tables exceeds the preallocated max table number, enlarge the table buffer.
484 @param AcpiSupportInstance ACPI support protocol instance data structure
486 @return EFI_SUCCESS reallocate the table beffer successfully.
487 @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
491 ReallocateAcpiTableBuffer (
492 IN EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
495 UINTN NewMaxTableNumber
;
498 EFI_PHYSICAL_ADDRESS PageAddress
;
499 EFI_ACPI_SUPPORT_INSTANCE TempPrivateData
;
503 CopyMem (&TempPrivateData
, AcpiSupportInstance
, sizeof (EFI_ACPI_SUPPORT_INSTANCE
));
505 // Enlarge the max table number from mEfiAcpiMaxNumTables to mEfiAcpiMaxNumTables + EFI_ACPI_MAX_NUM_TABLES
507 NewMaxTableNumber
= mEfiAcpiMaxNumTables
+ EFI_ACPI_MAX_NUM_TABLES
;
509 // Create RSDT, XSDT structures and allocate buffers.
511 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
512 NewMaxTableNumber
* sizeof (UINT32
) +
513 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
514 NewMaxTableNumber
* sizeof (UINT32
) +
515 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
516 NewMaxTableNumber
* sizeof (UINT64
);
519 // Allocate memory in the lower 32 bit of address range for
520 // compatibility with ACPI 1.0 OS.
522 // This is done because ACPI 1.0 pointers are 32 bit values.
523 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
524 // There is no architectural reason these should be below 4GB, it is purely
525 // for convenience of implementation that we force memory below 4GB.
527 PageAddress
= 0xFFFFFFFF;
528 Status
= gBS
->AllocatePages (
530 EfiACPIReclaimMemory
,
531 EFI_SIZE_TO_PAGES (TotalSize
),
535 if (EFI_ERROR (Status
)) {
536 return EFI_OUT_OF_RESOURCES
;
539 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
540 ZeroMem (Pointer
, TotalSize
);
542 AcpiSupportInstance
->Rsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
543 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + NewMaxTableNumber
* sizeof (UINT32
));
544 AcpiSupportInstance
->Rsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
545 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + NewMaxTableNumber
* sizeof (UINT32
));
546 AcpiSupportInstance
->Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
549 // Update RSDP to point to the new Rsdt and Xsdt address.
551 AcpiSupportInstance
->Rsdp1
->RsdtAddress
= (UINT32
) (UINTN
) AcpiSupportInstance
->Rsdt1
;
552 AcpiSupportInstance
->Rsdp3
->RsdtAddress
= (UINT32
) (UINTN
) AcpiSupportInstance
->Rsdt3
;
553 CurrentData
= (UINT64
) (UINTN
) AcpiSupportInstance
->Xsdt
;
554 CopyMem (&AcpiSupportInstance
->Rsdp3
->XsdtAddress
, &CurrentData
, sizeof (UINT64
));
557 // copy the original Rsdt1, Rsdt3 and Xsdt structure to new buffer
559 CopyMem (AcpiSupportInstance
->Rsdt1
, TempPrivateData
.Rsdt1
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT32
)));
560 CopyMem (AcpiSupportInstance
->Rsdt3
, TempPrivateData
.Rsdt3
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT32
)));
561 CopyMem (AcpiSupportInstance
->Xsdt
, TempPrivateData
.Xsdt
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT64
)));
564 // Calculate orignal ACPI table buffer size
566 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
567 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
568 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
569 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
570 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
571 mEfiAcpiMaxNumTables
* sizeof (UINT64
);
572 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
)(UINTN
)TempPrivateData
.Rsdt1
, EFI_SIZE_TO_PAGES (TotalSize
));
575 // Update the Max ACPI table number
577 mEfiAcpiMaxNumTables
= NewMaxTableNumber
;
581 This function adds an ACPI table to the table list. It will detect FACS and
582 allocate the correct type of memory and properly align the table.
584 @param AcpiSupportInstance Instance of the protocol.
585 @param Table Table to add.
586 @param Checksum Does the table require checksumming.
587 @param Version The version of the list to add the table to.
588 @param Handle Pointer for returning the handle.
590 @return EFI_SUCCESS The function completed successfully.
591 @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
592 @retval EFI_ACCESS_DENIED The table signature matches a table already
593 present in the system and platform policy
594 does not allow duplicate tables of this type.
598 IN EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
,
601 IN EFI_ACPI_TABLE_VERSION Version
,
606 EFI_ACPI_TABLE_LIST
*CurrentTableList
;
607 UINT32 CurrentTableSignature
;
608 UINT32 CurrentTableSize
;
609 UINT32
*CurrentRsdtEntry
;
610 VOID
*CurrentXsdtEntry
;
615 // Check for invalid input parameters
617 ASSERT (AcpiSupportInstance
);
627 // Create a new list entry
629 CurrentTableList
= AllocatePool (sizeof (EFI_ACPI_TABLE_LIST
));
630 ASSERT (CurrentTableList
);
633 // Determine table type and size
635 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
)->Signature
;
636 CurrentTableSize
= ((EFI_ACPI_COMMON_HEADER
*) Table
)->Length
;
639 // Allocate a buffer for the table. All tables are allocated in the lower 32 bits of address space
640 // for backwards compatibility with ACPI 1.0 OS.
642 // This is done because ACPI 1.0 pointers are 32 bit values.
643 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
644 // There is no architectural reason these should be below 4GB, it is purely
645 // for convenience of implementation that we force memory below 4GB.
647 CurrentTableList
->PageAddress
= 0xFFFFFFFF;
648 CurrentTableList
->NumberOfPages
= EFI_SIZE_TO_PAGES (CurrentTableSize
);
651 // Allocation memory type depends on the type of the table
653 if ((CurrentTableSignature
== EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) ||
654 (CurrentTableSignature
== EFI_ACPI_4_0_UEFI_ACPI_DATA_TABLE_SIGNATURE
)) {
656 // Allocate memory for the FACS. This structure must be aligned
657 // on a 64 byte boundary and must be ACPI NVS memory.
658 // Using AllocatePages should ensure that it is always aligned.
659 // Do not change signature for new ACPI version because they are same.
661 // UEFI table also need to be in ACPI NVS memory, because some data field
662 // could be updated by OS present agent. For example, BufferPtrAddress in
663 // SMM communication ACPI table.
665 ASSERT ((EFI_PAGE_SIZE
% 64) == 0);
666 Status
= gBS
->AllocatePages (
669 CurrentTableList
->NumberOfPages
,
670 &CurrentTableList
->PageAddress
674 // All other tables are ACPI reclaim memory, no alignment requirements.
676 Status
= gBS
->AllocatePages (
678 EfiACPIReclaimMemory
,
679 CurrentTableList
->NumberOfPages
,
680 &CurrentTableList
->PageAddress
684 // Check return value from memory alloc.
686 if (EFI_ERROR (Status
)) {
687 gBS
->FreePool (CurrentTableList
);
688 return EFI_OUT_OF_RESOURCES
;
691 // Update the table pointer with the allocated memory start
693 CurrentTableList
->Table
= (EFI_ACPI_COMMON_HEADER
*) (UINTN
) CurrentTableList
->PageAddress
;
696 // Initialize the table contents
698 CurrentTableList
->Signature
= EFI_ACPI_TABLE_LIST_SIGNATURE
;
699 CopyMem (CurrentTableList
->Table
, Table
, CurrentTableSize
);
700 CurrentTableList
->Handle
= AcpiSupportInstance
->CurrentHandle
++;
701 *Handle
= CurrentTableList
->Handle
;
702 CurrentTableList
->Version
= Version
;
705 // Update internal pointers if this is a required table. If it is a required
706 // table and a table of that type already exists, return an error.
708 // Calculate the checksum if the table is not FACS.
710 switch (CurrentTableSignature
) {
712 case EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
714 // We don't add the FADT in the standard way because some
715 // OS expect the FADT to be early in the table list.
716 // So we always add it as the first element in the list.
721 // Check that the table has not been previously added.
723 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiSupportInstance
->Fadt1
!= NULL
) ||
724 ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 && AcpiSupportInstance
->Fadt3
!= NULL
) ||
725 ((Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0 && AcpiSupportInstance
->Fadt3
!= NULL
)
727 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
728 gBS
->FreePool (CurrentTableList
);
729 return EFI_ACCESS_DENIED
;
732 // Add the table to the appropriate table version
734 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
736 // Save a pointer to the table
738 AcpiSupportInstance
->Fadt1
= (EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE
*) CurrentTableList
->Table
;
741 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
743 AcpiSupportInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiSupportInstance
->Facs1
;
744 AcpiSupportInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiSupportInstance
->Dsdt1
;
747 // RSDP OEM information is updated to match the FADT OEM information
750 &AcpiSupportInstance
->Rsdp1
->OemId
,
751 &AcpiSupportInstance
->Fadt1
->Header
.OemId
,
756 // RSDT OEM information is updated to match the FADT OEM information.
759 &AcpiSupportInstance
->Rsdt1
->OemId
,
760 &AcpiSupportInstance
->Fadt1
->Header
.OemId
,
765 &AcpiSupportInstance
->Rsdt1
->OemTableId
,
766 &AcpiSupportInstance
->Fadt1
->Header
.OemTableId
,
769 AcpiSupportInstance
->Rsdt1
->OemRevision
= AcpiSupportInstance
->Fadt1
->Header
.OemRevision
;
772 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
773 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
775 // Save a pointer to the table
777 AcpiSupportInstance
->Fadt3
= (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE
*) CurrentTableList
->Table
;
780 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
781 // Note: If the FIRMWARE_CTRL is non-zero, then X_FIRMWARE_CTRL must be zero, and
784 if ((UINT64
)(UINTN
)AcpiSupportInstance
->Facs3
< BASE_4GB
) {
785 AcpiSupportInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiSupportInstance
->Facs3
;
787 &AcpiSupportInstance
->Fadt3
->XFirmwareCtrl
,
791 AcpiSupportInstance
->Fadt3
->FirmwareCtrl
= 0;
792 Buffer64
= (UINT64
) (UINTN
) AcpiSupportInstance
->Facs3
;
794 &AcpiSupportInstance
->Fadt3
->XFirmwareCtrl
,
799 AcpiSupportInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiSupportInstance
->Dsdt3
;
800 Buffer64
= (UINT64
) (UINTN
) AcpiSupportInstance
->Dsdt3
;
802 &AcpiSupportInstance
->Fadt3
->XDsdt
,
808 // RSDP OEM information is updated to match the FADT OEM information
811 &AcpiSupportInstance
->Rsdp3
->OemId
,
812 &AcpiSupportInstance
->Fadt3
->Header
.OemId
,
817 // RSDT OEM information is updated to match FADT OEM information.
820 &AcpiSupportInstance
->Rsdt3
->OemId
,
821 &AcpiSupportInstance
->Fadt3
->Header
.OemId
,
825 &AcpiSupportInstance
->Rsdt3
->OemTableId
,
826 &AcpiSupportInstance
->Fadt3
->Header
.OemTableId
,
829 AcpiSupportInstance
->Rsdt3
->OemRevision
= AcpiSupportInstance
->Fadt3
->Header
.OemRevision
;
832 // XSDT OEM information is updated to match FADT OEM information.
835 &AcpiSupportInstance
->Xsdt
->OemId
,
836 &AcpiSupportInstance
->Fadt3
->Header
.OemId
,
840 &AcpiSupportInstance
->Xsdt
->OemTableId
,
841 &AcpiSupportInstance
->Fadt3
->Header
.OemTableId
,
844 AcpiSupportInstance
->Xsdt
->OemRevision
= AcpiSupportInstance
->Fadt3
->Header
.OemRevision
;
848 // Checksum the table
851 AcpiPlatformChecksum (
852 CurrentTableList
->Table
,
853 CurrentTableList
->Table
->Length
,
854 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
860 case EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
862 // Check that the table has not been previously added.
864 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiSupportInstance
->Facs1
!= NULL
) ||
865 ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 && AcpiSupportInstance
->Facs3
!= NULL
) ||
866 ((Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0 && AcpiSupportInstance
->Facs3
!= NULL
)
868 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
869 gBS
->FreePool (CurrentTableList
);
870 return EFI_ACCESS_DENIED
;
873 // FACS is referenced by FADT and is not part of RSDT
878 // Add the table to the appropriate table version
880 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
882 // Save a pointer to the table
884 AcpiSupportInstance
->Facs1
= (EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
887 // If FADT already exists, update table pointers.
889 if (AcpiSupportInstance
->Fadt1
!= NULL
) {
890 AcpiSupportInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiSupportInstance
->Facs1
;
893 // Checksum FADT table
895 AcpiPlatformChecksum (
896 AcpiSupportInstance
->Fadt1
,
897 AcpiSupportInstance
->Fadt1
->Header
.Length
,
898 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
904 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
905 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
907 // Save a pointer to the table
909 AcpiSupportInstance
->Facs3
= (EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
912 // If FADT already exists, update table pointers.
914 if (AcpiSupportInstance
->Fadt3
!= NULL
) {
916 // Note: If the FIRMWARE_CTRL is non-zero, then X_FIRMWARE_CTRL must be zero, and
919 if ((UINT64
)(UINTN
)AcpiSupportInstance
->Facs3
< BASE_4GB
) {
920 AcpiSupportInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiSupportInstance
->Facs3
;
922 Buffer64
= (UINT64
) (UINTN
) AcpiSupportInstance
->Facs3
;
924 &AcpiSupportInstance
->Fadt3
->XFirmwareCtrl
,
931 // Checksum FADT table
933 AcpiPlatformChecksum (
934 AcpiSupportInstance
->Fadt3
,
935 AcpiSupportInstance
->Fadt3
->Header
.Length
,
936 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
944 case EFI_ACPI_1_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
946 // Check that the table has not been previously added.
948 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiSupportInstance
->Dsdt1
!= NULL
) ||
949 ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 && AcpiSupportInstance
->Dsdt3
!= NULL
) ||
950 ((Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0 && AcpiSupportInstance
->Dsdt3
!= NULL
)
952 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
953 gBS
->FreePool (CurrentTableList
);
954 return EFI_ACCESS_DENIED
;
957 // DSDT is referenced by FADT and is not part of RSDT
962 // Add the table to the appropriate table version
964 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
966 // Save a pointer to the table
968 AcpiSupportInstance
->Dsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
971 // If FADT already exists, update table pointers.
973 if (AcpiSupportInstance
->Fadt1
!= NULL
) {
974 AcpiSupportInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiSupportInstance
->Dsdt1
;
977 // Checksum FADT table
979 AcpiPlatformChecksum (
980 AcpiSupportInstance
->Fadt1
,
981 AcpiSupportInstance
->Fadt1
->Header
.Length
,
982 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
988 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
989 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
991 // Save a pointer to the table
993 AcpiSupportInstance
->Dsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
996 // If FADT already exists, update table pointers.
998 if (AcpiSupportInstance
->Fadt3
!= NULL
) {
999 AcpiSupportInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiSupportInstance
->Dsdt3
;
1000 Buffer64
= (UINT64
) (UINTN
) AcpiSupportInstance
->Dsdt3
;
1002 &AcpiSupportInstance
->Fadt3
->XDsdt
,
1008 // Checksum FADT table
1010 AcpiPlatformChecksum (
1011 AcpiSupportInstance
->Fadt3
,
1012 AcpiSupportInstance
->Fadt3
->Header
.Length
,
1013 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1019 // Checksum the table
1022 AcpiPlatformChecksum (
1023 CurrentTableList
->Table
,
1024 CurrentTableList
->Table
->Length
,
1025 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1033 // Checksum the table
1036 AcpiPlatformChecksum (
1037 CurrentTableList
->Table
,
1038 CurrentTableList
->Table
->Length
,
1039 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1046 // Add the table to the current list of tables
1048 InsertTailList (&AcpiSupportInstance
->TableList
, &CurrentTableList
->Link
);
1051 // Add the table to RSDT and/or XSDT table entry lists.
1054 // Add to ACPI 1.0b table tree
1056 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1059 // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
1061 if (AcpiSupportInstance
->NumberOfTableEntries1
>= mEfiAcpiMaxNumTables
) {
1062 Status
= ReallocateAcpiTableBuffer (AcpiSupportInstance
);
1063 ASSERT_EFI_ERROR (Status
);
1065 CurrentRsdtEntry
= (UINT32
*)
1067 (UINT8
*) AcpiSupportInstance
->Rsdt1
+
1068 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
1069 AcpiSupportInstance
->NumberOfTableEntries1
*
1074 // Add entry to the RSDT unless its the FACS or DSDT
1076 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
1079 // Update RSDT length
1081 AcpiSupportInstance
->Rsdt1
->Length
= AcpiSupportInstance
->Rsdt1
->Length
+ sizeof (UINT32
);
1083 AcpiSupportInstance
->NumberOfTableEntries1
++;
1087 // Add to ACPI 2.0/3.0 table tree
1089 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 || (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1092 // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
1094 if (AcpiSupportInstance
->NumberOfTableEntries3
>= mEfiAcpiMaxNumTables
) {
1095 Status
= ReallocateAcpiTableBuffer (AcpiSupportInstance
);
1096 ASSERT_EFI_ERROR (Status
);
1099 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
1100 // If it becomes necessary to maintain separate table lists, changes will be required.
1102 CurrentRsdtEntry
= (UINT32
*)
1104 (UINT8
*) AcpiSupportInstance
->Rsdt3
+
1105 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
1106 AcpiSupportInstance
->NumberOfTableEntries3
*
1111 // This pointer must not be directly dereferenced as the XSDT entries may not
1112 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
1114 CurrentXsdtEntry
= (VOID
*)
1116 (UINT8
*) AcpiSupportInstance
->Xsdt
+
1117 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
1118 AcpiSupportInstance
->NumberOfTableEntries3
*
1123 // Add entry to the RSDT
1125 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
1128 // Update RSDT length
1130 AcpiSupportInstance
->Rsdt3
->Length
= AcpiSupportInstance
->Rsdt3
->Length
+ sizeof (UINT32
);
1133 // Add entry to XSDT, XSDT expects 64 bit pointers, but
1134 // the table pointers in XSDT are not aligned on 8 byte boundary.
1136 Buffer64
= (UINT64
) (UINTN
) CurrentTableList
->Table
;
1146 AcpiSupportInstance
->Xsdt
->Length
= AcpiSupportInstance
->Xsdt
->Length
+ sizeof (UINT64
);
1148 AcpiSupportInstance
->NumberOfTableEntries3
++;
1152 ChecksumCommonTables (AcpiSupportInstance
);
1156 This function finds the table specified by the handle and returns a pointer to it.
1157 If the handle is not found, EFI_NOT_FOUND is returned and the contents of Table are
1160 @param Handle Table to find.
1161 @param TableList Table list to search
1162 @param Table Pointer to table found.
1164 @return EFI_SUCCESS The function completed successfully.
1165 @return EFI_NOT_FOUND No table found matching the handle specified.
1171 IN LIST_ENTRY
*TableList
,
1172 OUT EFI_ACPI_TABLE_LIST
**Table
1175 LIST_ENTRY
*CurrentLink
;
1176 EFI_ACPI_TABLE_LIST
*CurrentTable
;
1179 // Check for invalid input parameters
1186 CurrentLink
= TableList
->ForwardLink
;
1188 while (CurrentLink
!= TableList
) {
1189 CurrentTable
= EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink
);
1190 if (CurrentTable
->Handle
== Handle
) {
1192 // Found handle, so return this table.
1194 *Table
= CurrentTable
;
1198 CurrentLink
= CurrentLink
->ForwardLink
;
1203 return EFI_NOT_FOUND
;
1206 This function removes a basic table from the RSDT and/or XSDT.
1207 For Acpi 1.0 tables, pass in the Rsdt.
1208 For Acpi 2.0 tables, pass in both Rsdt and Xsdt.
1210 @param Table Pointer to table found.
1211 @param NumberOfTableEntries Current number of table entries in the RSDT/XSDT
1212 @param Rsdt Pointer to the RSDT to remove from
1213 @param Xsdt Pointer to the Xsdt to remove from
1215 @return EFI_SUCCESS The function completed successfully.
1216 @return EFI_INVALID_PARAMETER The table was not found in both Rsdt and Xsdt.
1220 RemoveTableFromRsdt (
1221 IN OUT EFI_ACPI_TABLE_LIST
* Table
,
1222 IN OUT UINTN
*NumberOfTableEntries
,
1223 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Rsdt
,
1224 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Xsdt OPTIONAL
1227 UINT32
*CurrentRsdtEntry
;
1228 VOID
*CurrentXsdtEntry
;
1229 UINT64 CurrentTablePointer64
;
1233 // Check for invalid input parameters
1236 ASSERT (NumberOfTableEntries
);
1240 // Find the table entry in the RSDT and XSDT
1242 for (TempIndex
= 0; TempIndex
< *NumberOfTableEntries
; TempIndex
++) {
1244 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
1245 // If it becomes necessary to maintain separate table lists, changes will be required.
1247 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) Rsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + TempIndex
* sizeof (UINT32
));
1250 // This pointer must not be directly dereferenced as the XSDT entries may not
1251 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
1253 CurrentXsdtEntry
= (VOID
*) ((UINT8
*) Xsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + TempIndex
* sizeof (UINT64
));
1256 // Read the entry value out of the XSDT
1258 CopyMem (&CurrentTablePointer64
, CurrentXsdtEntry
, sizeof (UINT64
));
1261 // Initialize to NULL
1263 CurrentXsdtEntry
= 0;
1264 CurrentTablePointer64
= 0;
1267 // Check if we have found the corresponding entry in both RSDT and XSDT
1269 if (*CurrentRsdtEntry
== (UINT32
) (UINTN
) Table
->Table
&&
1270 ((Xsdt
== NULL
) || CurrentTablePointer64
== (UINT64
) (UINTN
) Table
->Table
)
1273 // Found entry, so copy all following entries and shrink table
1274 // We actually copy all + 1 to copy the initialized value of memory over
1277 CopyMem (CurrentRsdtEntry
, CurrentRsdtEntry
+ 1, (*NumberOfTableEntries
- TempIndex
) * sizeof (UINT32
));
1278 Rsdt
->Length
= Rsdt
->Length
- sizeof (UINT32
);
1280 CopyMem (CurrentXsdtEntry
, ((UINT64
*) CurrentXsdtEntry
) + 1, (*NumberOfTableEntries
- TempIndex
) * sizeof (UINT64
));
1281 Xsdt
->Length
= Xsdt
->Length
- sizeof (UINT64
);
1284 } else if (TempIndex
+ 1 == *NumberOfTableEntries
) {
1286 // At the last entry, and table not found
1288 return EFI_INVALID_PARAMETER
;
1292 // Checksum the tables
1294 AcpiPlatformChecksum (
1297 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1302 AcpiPlatformChecksum (
1305 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1310 // Decrement the number of tables
1312 (*NumberOfTableEntries
)--;
1317 This function removes a table and frees any associated memory.
1319 @param AcpiSupportInstance Instance of the protocol.
1320 @param Version Version(s) to delete.
1321 @param Table Pointer to table found.
1323 @return EFI_SUCCESS The function completed successfully.
1328 IN EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
,
1329 IN EFI_ACPI_TABLE_VERSION Version
,
1330 IN OUT EFI_ACPI_TABLE_LIST
*Table
1333 UINT32 CurrentTableSignature
;
1334 BOOLEAN RemoveFromRsdt
;
1337 // Check for invalid input parameters
1339 ASSERT (AcpiSupportInstance
);
1345 RemoveFromRsdt
= TRUE
;
1347 if (Table
->Table
!= NULL
) {
1348 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
->Table
)->Signature
;
1351 // Basic tasks to accomplish delete are:
1352 // Determine removal requirements (in RSDT/XSDT or not)
1353 // Remove entry from RSDT/XSDT
1354 // Remove any table references to the table
1355 // If no one is using the table
1356 // Free the table (removing pointers from private data and tables)
1358 // Free list structure
1361 // Determine if this table is in the RSDT or XSDT
1363 if ((CurrentTableSignature
== EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) ||
1364 (CurrentTableSignature
== EFI_ACPI_2_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
) ||
1365 (CurrentTableSignature
== EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
)
1367 RemoveFromRsdt
= FALSE
;
1370 // We don't remove the FADT in the standard way because some
1371 // OS expect the FADT to be early in the table list.
1372 // So we always put it as the first element in the list.
1374 if (CurrentTableSignature
== EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
) {
1375 RemoveFromRsdt
= FALSE
;
1379 // Remove the table from RSDT and XSDT
1383 // This is a basic table, remove it from any lists and the Rsdt and/or Xsdt
1385 if (Version
& EFI_ACPI_TABLE_VERSION_NONE
& Table
->Version
) {
1387 // Remove this version from the table
1389 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_NONE
;
1392 if (Version
& EFI_ACPI_TABLE_VERSION_1_0B
& Table
->Version
) {
1394 // Remove this version from the table
1396 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_1_0B
;
1399 // Remove from Rsdt. We don't care about the return value because it is
1400 // acceptable for the table to not exist in Rsdt.
1401 // We didn't add some tables so we don't remove them.
1403 if (RemoveFromRsdt
) {
1404 RemoveTableFromRsdt (
1406 &AcpiSupportInstance
->NumberOfTableEntries1
,
1407 AcpiSupportInstance
->Rsdt1
,
1413 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
& Table
->Version
) ||
1414 (Version
& EFI_ACPI_TABLE_VERSION_3_0
& Table
->Version
)) {
1416 // Remove this version from the table
1418 if (Version
& EFI_ACPI_TABLE_VERSION_2_0
& Table
->Version
) {
1419 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_2_0
;
1421 if (Version
& EFI_ACPI_TABLE_VERSION_3_0
& Table
->Version
) {
1422 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_3_0
;
1426 // Remove from Rsdt and Xsdt. We don't care about the return value
1427 // because it is acceptable for the table to not exist in Rsdt/Xsdt.
1428 // We didn't add some tables so we don't remove them.
1430 if (RemoveFromRsdt
) {
1431 RemoveTableFromRsdt (
1433 &AcpiSupportInstance
->NumberOfTableEntries3
,
1434 AcpiSupportInstance
->Rsdt3
,
1435 AcpiSupportInstance
->Xsdt
1440 // Free the table, clean up any dependent tables and our private data pointers.
1442 switch (Table
->Table
->Signature
) {
1444 case EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
1445 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1446 AcpiSupportInstance
->Fadt1
= NULL
;
1449 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
1450 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1451 AcpiSupportInstance
->Fadt3
= NULL
;
1455 case EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
1456 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1457 AcpiSupportInstance
->Facs1
= NULL
;
1460 // Update FADT table pointers
1462 if (AcpiSupportInstance
->Fadt1
!= NULL
) {
1463 AcpiSupportInstance
->Fadt1
->FirmwareCtrl
= 0;
1468 AcpiPlatformChecksum (
1469 AcpiSupportInstance
->Fadt1
,
1470 AcpiSupportInstance
->Fadt1
->Header
.Length
,
1471 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1477 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
1478 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1479 AcpiSupportInstance
->Facs3
= NULL
;
1482 // Update FADT table pointers
1484 if (AcpiSupportInstance
->Fadt3
!= NULL
) {
1485 AcpiSupportInstance
->Fadt3
->FirmwareCtrl
= 0;
1486 ZeroMem (&AcpiSupportInstance
->Fadt3
->XFirmwareCtrl
, sizeof (UINT64
));
1491 AcpiPlatformChecksum (
1492 AcpiSupportInstance
->Fadt3
,
1493 AcpiSupportInstance
->Fadt3
->Header
.Length
,
1494 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1501 case EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
1502 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1503 AcpiSupportInstance
->Dsdt1
= NULL
;
1506 // Update FADT table pointers
1508 if (AcpiSupportInstance
->Fadt1
!= NULL
) {
1509 AcpiSupportInstance
->Fadt1
->Dsdt
= 0;
1514 AcpiPlatformChecksum (
1515 AcpiSupportInstance
->Fadt1
,
1516 AcpiSupportInstance
->Fadt1
->Header
.Length
,
1517 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1524 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
1525 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1526 AcpiSupportInstance
->Dsdt3
= NULL
;
1529 // Update FADT table pointers
1531 if (AcpiSupportInstance
->Fadt3
!= NULL
) {
1532 AcpiSupportInstance
->Fadt3
->Dsdt
= 0;
1533 ZeroMem (&AcpiSupportInstance
->Fadt3
->XDsdt
, sizeof (UINT64
));
1538 AcpiPlatformChecksum (
1539 AcpiSupportInstance
->Fadt3
,
1540 AcpiSupportInstance
->Fadt3
->Header
.Length
,
1541 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1556 // If no version is using this table anymore, remove and free list entry.
1558 if (Table
->Version
== 0) {
1562 gBS
->FreePages (Table
->PageAddress
, Table
->NumberOfPages
);
1563 RemoveEntryList (&(Table
->Link
));
1564 gBS
->FreePool (Table
);
1572 This function finds and removes the table specified by the handle.
1574 @param AcpiSupportInstance Instance of the protocol.
1575 @param Version Bitmask of which versions to remove.
1576 @param Handle Table to remove.
1578 @return EFI_SUCCESS The function completed successfully.
1579 @return EFI_ABORTED An error occurred.
1580 @return EFI_NOT_FOUND Handle not found in table list.
1583 RemoveTableFromList (
1584 IN EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
,
1585 IN EFI_ACPI_TABLE_VERSION Version
,
1589 EFI_ACPI_TABLE_LIST
*Table
;
1595 // Check for invalid input parameters
1597 ASSERT (AcpiSupportInstance
);
1602 Status
= FindTableByHandle (
1604 &AcpiSupportInstance
->TableList
,
1607 if (EFI_ERROR (Status
)) {
1608 return EFI_NOT_FOUND
;
1613 Status
= DeleteTable (AcpiSupportInstance
, Version
, Table
);
1614 if (EFI_ERROR (Status
)) {
1618 // Completed successfully
1623 This function calculates and updates an UINT8 checksum.
1625 @param Buffer Pointer to buffer to checksum
1626 @param Size Number of bytes to checksum
1627 @param ChecksumOffset Offset to place the checksum result in
1629 @return EFI_SUCCESS The function completed successfully.
1633 AcpiPlatformChecksum (
1636 IN UINTN ChecksumOffset
1644 // Initialize pointer
1649 // set checksum to 0 first
1651 Ptr
[ChecksumOffset
] = 0;
1654 // add all content of buffer
1656 while ((Size
--) != 0) {
1657 Sum
= (UINT8
) (Sum
+ (*Ptr
++));
1663 Ptr
[ChecksumOffset
] = (UINT8
) (0xff - Sum
+ 1);
1668 Checksum all versions of the common tables, RSDP, RSDT, XSDT.
1670 @param AcpiSupportInstance Protocol instance private data.
1672 @return EFI_SUCCESS The function completed successfully.
1676 ChecksumCommonTables (
1677 IN OUT EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
1681 // RSDP ACPI 1.0 checksum for 1.0 table. This is only the first 20 bytes of the structure
1683 AcpiPlatformChecksum (
1684 AcpiSupportInstance
->Rsdp1
,
1685 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1686 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1691 // RSDP ACPI 1.0 checksum for 2.0/3.0 table. This is only the first 20 bytes of the structure
1693 AcpiPlatformChecksum (
1694 AcpiSupportInstance
->Rsdp3
,
1695 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1696 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1701 // RSDP ACPI 2.0/3.0 checksum, this is the entire table
1703 AcpiPlatformChecksum (
1704 AcpiSupportInstance
->Rsdp3
,
1705 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1706 OFFSET_OF (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1713 AcpiPlatformChecksum (
1714 AcpiSupportInstance
->Rsdt1
,
1715 AcpiSupportInstance
->Rsdt1
->Length
,
1716 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1720 AcpiPlatformChecksum (
1721 AcpiSupportInstance
->Rsdt3
,
1722 AcpiSupportInstance
->Rsdt3
->Length
,
1723 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1730 AcpiPlatformChecksum (
1731 AcpiSupportInstance
->Xsdt
,
1732 AcpiSupportInstance
->Xsdt
->Length
,
1733 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1740 Constructor for the ACPI support protocol to initializes instance data.
1742 @param AcpiSupportInstance Instance to construct
1744 @retval EFI_SUCCESS Instance initialized.
1745 @retval EFI_OUT_OF_RESOURCES Unable to allocate required resources.
1748 AcpiSupportAcpiSupportConstructor (
1749 IN EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
1755 UINTN RsdpTableSize
;
1757 EFI_PHYSICAL_ADDRESS PageAddress
;
1760 // Check for invalid input parameters
1762 ASSERT (AcpiSupportInstance
);
1764 InitializeListHead (&AcpiSupportInstance
->TableList
);
1765 AcpiSupportInstance
->CurrentHandle
= 1;
1766 AcpiSupportInstance
->AcpiSupport
.GetAcpiTable
= GetAcpiTable
;
1767 AcpiSupportInstance
->AcpiSupport
.SetAcpiTable
= SetAcpiTable
;
1768 AcpiSupportInstance
->AcpiSupport
.PublishTables
= PublishTables
;
1770 AcpiSupportInstance
->AcpiTableProtocol
.InstallAcpiTable
= InstallAcpiTable
;
1771 AcpiSupportInstance
->AcpiTableProtocol
.UninstallAcpiTable
= UninstallAcpiTable
;
1774 // Create RSDP table
1776 RsdpTableSize
= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
) +
1777 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1779 PageAddress
= 0xFFFFFFFF;
1780 Status
= gBS
->AllocatePages (
1782 EfiACPIReclaimMemory
,
1783 EFI_SIZE_TO_PAGES (RsdpTableSize
),
1787 if (EFI_ERROR (Status
)) {
1788 return EFI_OUT_OF_RESOURCES
;
1791 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
1792 ZeroMem (Pointer
, RsdpTableSize
);
1794 AcpiSupportInstance
->Rsdp1
= (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1795 Pointer
+= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1796 AcpiSupportInstance
->Rsdp3
= (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1799 // Create RSDT, XSDT structures
1801 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
1802 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
1803 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
1804 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
1805 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
1806 mEfiAcpiMaxNumTables
* sizeof (UINT64
);
1809 // Allocate memory in the lower 32 bit of address range for
1810 // compatibility with ACPI 1.0 OS.
1812 // This is done because ACPI 1.0 pointers are 32 bit values.
1813 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
1814 // There is no architectural reason these should be below 4GB, it is purely
1815 // for convenience of implementation that we force memory below 4GB.
1817 PageAddress
= 0xFFFFFFFF;
1818 Status
= gBS
->AllocatePages (
1820 EfiACPIReclaimMemory
,
1821 EFI_SIZE_TO_PAGES (TotalSize
),
1825 if (EFI_ERROR (Status
)) {
1826 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
)(UINTN
)AcpiSupportInstance
->Rsdp1
, EFI_SIZE_TO_PAGES (RsdpTableSize
));
1827 return EFI_OUT_OF_RESOURCES
;
1830 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
1831 ZeroMem (Pointer
, TotalSize
);
1833 AcpiSupportInstance
->Rsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1834 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1835 AcpiSupportInstance
->Rsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1836 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1837 AcpiSupportInstance
->Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1842 CurrentData
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1843 CopyMem (&AcpiSupportInstance
->Rsdp1
->Signature
, &CurrentData
, sizeof (UINT64
));
1844 CopyMem (AcpiSupportInstance
->Rsdp1
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiSupportInstance
->Rsdp1
->OemId
));
1845 AcpiSupportInstance
->Rsdp1
->Reserved
= EFI_ACPI_RESERVED_BYTE
;
1846 AcpiSupportInstance
->Rsdp1
->RsdtAddress
= (UINT32
) (UINTN
) AcpiSupportInstance
->Rsdt1
;
1848 CurrentData
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1849 CopyMem (&AcpiSupportInstance
->Rsdp3
->Signature
, &CurrentData
, sizeof (UINT64
));
1850 CopyMem (AcpiSupportInstance
->Rsdp3
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiSupportInstance
->Rsdp3
->OemId
));
1851 AcpiSupportInstance
->Rsdp3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION
;
1852 AcpiSupportInstance
->Rsdp3
->RsdtAddress
= (UINT32
) (UINTN
) AcpiSupportInstance
->Rsdt3
;
1853 AcpiSupportInstance
->Rsdp3
->Length
= sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1854 CurrentData
= (UINT64
) (UINTN
) AcpiSupportInstance
->Xsdt
;
1855 CopyMem (&AcpiSupportInstance
->Rsdp3
->XsdtAddress
, &CurrentData
, sizeof (UINT64
));
1856 SetMem (AcpiSupportInstance
->Rsdp3
->Reserved
, 3, EFI_ACPI_RESERVED_BYTE
);
1861 // Note that we "reserve" one entry for the FADT so it can always be
1862 // at the beginning of the list of tables. Some OS don't seem
1863 // to find it correctly if it is too far down the list.
1865 AcpiSupportInstance
->Rsdt1
->Signature
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1866 AcpiSupportInstance
->Rsdt1
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1867 AcpiSupportInstance
->Rsdt1
->Revision
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1868 CopyMem (AcpiSupportInstance
->Rsdt1
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiSupportInstance
->Rsdt1
->OemId
));
1869 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1870 CopyMem (&AcpiSupportInstance
->Rsdt1
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1871 AcpiSupportInstance
->Rsdt1
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1872 AcpiSupportInstance
->Rsdt1
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1873 AcpiSupportInstance
->Rsdt1
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1875 // We always reserve first one for FADT
1877 AcpiSupportInstance
->NumberOfTableEntries1
= 1;
1878 AcpiSupportInstance
->Rsdt1
->Length
= AcpiSupportInstance
->Rsdt1
->Length
+ sizeof(UINT32
);
1880 AcpiSupportInstance
->Rsdt3
->Signature
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1881 AcpiSupportInstance
->Rsdt3
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1882 AcpiSupportInstance
->Rsdt3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1883 CopyMem (AcpiSupportInstance
->Rsdt3
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiSupportInstance
->Rsdt3
->OemId
));
1884 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1885 CopyMem (&AcpiSupportInstance
->Rsdt3
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1886 AcpiSupportInstance
->Rsdt3
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1887 AcpiSupportInstance
->Rsdt3
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1888 AcpiSupportInstance
->Rsdt3
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1890 // We always reserve first one for FADT
1892 AcpiSupportInstance
->NumberOfTableEntries3
= 1;
1893 AcpiSupportInstance
->Rsdt3
->Length
= AcpiSupportInstance
->Rsdt3
->Length
+ sizeof(UINT32
);
1898 AcpiSupportInstance
->Xsdt
->Signature
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1899 AcpiSupportInstance
->Xsdt
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1900 AcpiSupportInstance
->Xsdt
->Revision
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1901 CopyMem (AcpiSupportInstance
->Xsdt
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiSupportInstance
->Xsdt
->OemId
));
1902 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1903 CopyMem (&AcpiSupportInstance
->Xsdt
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1904 AcpiSupportInstance
->Xsdt
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1905 AcpiSupportInstance
->Xsdt
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1906 AcpiSupportInstance
->Xsdt
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1908 // We always reserve first one for FADT
1910 AcpiSupportInstance
->Xsdt
->Length
= AcpiSupportInstance
->Xsdt
->Length
+ sizeof(UINT64
);
1912 ChecksumCommonTables (AcpiSupportInstance
);
1915 // Completed successfully