2 ACPI Support Protocol implementation
4 Copyright (c) 2006 - 2011, 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.
383 IN EFI_ACPI_TABLE_PROTOCOL
*This
,
384 IN VOID
*AcpiTableBuffer
,
385 IN UINTN AcpiTableBufferSize
,
389 EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
;
390 EFI_ACPI_SUPPORT_PROTOCOL
*AcpiSupport
;
392 VOID
*AcpiTableBufferConst
;
397 // Check for invalid input parameters
399 if ((AcpiTableBuffer
== NULL
) || (TableKey
== NULL
)
400 || (((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTableBuffer
)->Length
!= AcpiTableBufferSize
)) {
401 return EFI_INVALID_PARAMETER
;
404 Length
= ((EFI_ACPI_COMMON_HEADER
*) AcpiTableBuffer
)->Length
;
405 Checksum
= CalculateCheckSum8 ((UINT8
*)AcpiTableBuffer
, Length
);
407 AcpiPlatformChecksum (
408 (VOID
*)AcpiTableBuffer
,
410 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
, Checksum
)
415 // Get the instance of the ACPI support protocol
417 AcpiSupportInstance
= EFI_ACPI_TABLE_INSTANCE_FROM_ACPI_SUPPORT_THIS (This
);
418 AcpiSupport
= &AcpiSupportInstance
->AcpiSupport
;
421 // Install the ACPI table by using ACPI support protocol
423 AcpiTableBufferConst
= AllocateCopyPool (AcpiTableBufferSize
, AcpiTableBuffer
);
425 Status
= AcpiSupport
->SetAcpiTable (
427 AcpiTableBufferConst
,
429 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
,
432 if (!EFI_ERROR (Status
)) {
433 Status
= AcpiSupport
->PublishTables (
435 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
438 FreePool (AcpiTableBufferConst
);
443 Removes an ACPI table from the RSDT/XSDT.
445 @param This Protocol instance pointer.
446 @param TableKey Specifies the table to uninstall. The key was returned from InstallAcpiTable().
448 @return EFI_SUCCESS The table was successfully uninstalled.
449 @return EFI_NOT_FOUND TableKey does not refer to a valid key for a table entry.
455 IN EFI_ACPI_TABLE_PROTOCOL
*This
,
459 EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
;
460 EFI_ACPI_SUPPORT_PROTOCOL
*AcpiSupport
;
464 // Get the instance of the ACPI support protocol
466 AcpiSupportInstance
= EFI_ACPI_TABLE_INSTANCE_FROM_ACPI_SUPPORT_THIS (This
);
467 AcpiSupport
= &AcpiSupportInstance
->AcpiSupport
;
470 // Uninstall the ACPI table by using ACPI support protocol
472 Status
= AcpiSupport
->SetAcpiTable (
476 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
,
479 if (!EFI_ERROR (Status
)) {
480 Status
= AcpiSupport
->PublishTables (
482 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
486 if (EFI_ERROR (Status
)) {
487 return EFI_NOT_FOUND
;
493 If the number of APCI tables exceeds the preallocated max table number, enlarge the table buffer.
495 @param AcpiSupportInstance ACPI support protocol instance data structure
497 @return EFI_SUCCESS reallocate the table beffer successfully.
498 @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
502 ReallocateAcpiTableBuffer (
503 IN EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
506 UINTN NewMaxTableNumber
;
509 EFI_PHYSICAL_ADDRESS PageAddress
;
510 EFI_ACPI_SUPPORT_INSTANCE TempPrivateData
;
514 CopyMem (&TempPrivateData
, AcpiSupportInstance
, sizeof (EFI_ACPI_SUPPORT_INSTANCE
));
516 // Enlarge the max table number from mEfiAcpiMaxNumTables to mEfiAcpiMaxNumTables + EFI_ACPI_MAX_NUM_TABLES
518 NewMaxTableNumber
= mEfiAcpiMaxNumTables
+ EFI_ACPI_MAX_NUM_TABLES
;
520 // Create RSDT, XSDT structures and allocate buffers.
522 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
523 NewMaxTableNumber
* sizeof (UINT32
) +
524 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
525 NewMaxTableNumber
* sizeof (UINT32
) +
526 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
527 NewMaxTableNumber
* sizeof (UINT64
);
530 // Allocate memory in the lower 32 bit of address range for
531 // compatibility with ACPI 1.0 OS.
533 // This is done because ACPI 1.0 pointers are 32 bit values.
534 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
535 // There is no architectural reason these should be below 4GB, it is purely
536 // for convenience of implementation that we force memory below 4GB.
538 PageAddress
= 0xFFFFFFFF;
539 Status
= gBS
->AllocatePages (
541 EfiACPIReclaimMemory
,
542 EFI_SIZE_TO_PAGES (TotalSize
),
546 if (EFI_ERROR (Status
)) {
547 return EFI_OUT_OF_RESOURCES
;
550 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
551 ZeroMem (Pointer
, TotalSize
);
553 AcpiSupportInstance
->Rsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
554 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + NewMaxTableNumber
* sizeof (UINT32
));
555 AcpiSupportInstance
->Rsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
556 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + NewMaxTableNumber
* sizeof (UINT32
));
557 AcpiSupportInstance
->Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
560 // Update RSDP to point to the new Rsdt and Xsdt address.
562 AcpiSupportInstance
->Rsdp1
->RsdtAddress
= (UINT32
) (UINTN
) AcpiSupportInstance
->Rsdt1
;
563 AcpiSupportInstance
->Rsdp3
->RsdtAddress
= (UINT32
) (UINTN
) AcpiSupportInstance
->Rsdt3
;
564 CurrentData
= (UINT64
) (UINTN
) AcpiSupportInstance
->Xsdt
;
565 CopyMem (&AcpiSupportInstance
->Rsdp3
->XsdtAddress
, &CurrentData
, sizeof (UINT64
));
568 // copy the original Rsdt1, Rsdt3 and Xsdt structure to new buffer
570 CopyMem (AcpiSupportInstance
->Rsdt1
, TempPrivateData
.Rsdt1
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT32
)));
571 CopyMem (AcpiSupportInstance
->Rsdt3
, TempPrivateData
.Rsdt3
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT32
)));
572 CopyMem (AcpiSupportInstance
->Xsdt
, TempPrivateData
.Xsdt
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT64
)));
575 // Calculate orignal ACPI table buffer size
577 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
578 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
579 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
580 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
581 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
582 mEfiAcpiMaxNumTables
* sizeof (UINT64
);
583 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
)(UINTN
)TempPrivateData
.Rsdt1
, EFI_SIZE_TO_PAGES (TotalSize
));
586 // Update the Max ACPI table number
588 mEfiAcpiMaxNumTables
= NewMaxTableNumber
;
592 This function adds an ACPI table to the table list. It will detect FACS and
593 allocate the correct type of memory and properly align the table.
595 @param AcpiSupportInstance Instance of the protocol.
596 @param Table Table to add.
597 @param Checksum Does the table require checksumming.
598 @param Version The version of the list to add the table to.
599 @param Handle Pointer for returning the handle.
601 @return EFI_SUCCESS The function completed successfully.
602 @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
603 @return EFI_ABORTED The table is a duplicate of a table that is required
608 IN EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
,
611 IN EFI_ACPI_TABLE_VERSION Version
,
616 EFI_ACPI_TABLE_LIST
*CurrentTableList
;
617 UINT32 CurrentTableSignature
;
618 UINT32 CurrentTableSize
;
619 UINT32
*CurrentRsdtEntry
;
620 VOID
*CurrentXsdtEntry
;
625 // Check for invalid input parameters
627 ASSERT (AcpiSupportInstance
);
637 // Create a new list entry
639 CurrentTableList
= AllocatePool (sizeof (EFI_ACPI_TABLE_LIST
));
640 ASSERT (CurrentTableList
);
643 // Determine table type and size
645 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
)->Signature
;
646 CurrentTableSize
= ((EFI_ACPI_COMMON_HEADER
*) Table
)->Length
;
649 // Allocate a buffer for the table. All tables are allocated in the lower 32 bits of address space
650 // for backwards compatibility with ACPI 1.0 OS.
652 // This is done because ACPI 1.0 pointers are 32 bit values.
653 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
654 // There is no architectural reason these should be below 4GB, it is purely
655 // for convenience of implementation that we force memory below 4GB.
657 CurrentTableList
->PageAddress
= 0xFFFFFFFF;
658 CurrentTableList
->NumberOfPages
= EFI_SIZE_TO_PAGES (CurrentTableSize
);
661 // Allocation memory type depends on the type of the table
663 if ((CurrentTableSignature
== EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) ||
664 (CurrentTableSignature
== EFI_ACPI_4_0_UEFI_ACPI_DATA_TABLE_SIGNATURE
)) {
666 // Allocate memory for the FACS. This structure must be aligned
667 // on a 64 byte boundary and must be ACPI NVS memory.
668 // Using AllocatePages should ensure that it is always aligned.
669 // Do not change signature for new ACPI version because they are same.
671 // UEFI table also need to be in ACPI NVS memory, because some data field
672 // could be updated by OS present agent. For example, BufferPtrAddress in
673 // SMM communication ACPI table.
675 ASSERT ((EFI_PAGE_SIZE
% 64) == 0);
676 Status
= gBS
->AllocatePages (
679 CurrentTableList
->NumberOfPages
,
680 &CurrentTableList
->PageAddress
684 // All other tables are ACPI reclaim memory, no alignment requirements.
686 Status
= gBS
->AllocatePages (
688 EfiACPIReclaimMemory
,
689 CurrentTableList
->NumberOfPages
,
690 &CurrentTableList
->PageAddress
694 // Check return value from memory alloc.
696 if (EFI_ERROR (Status
)) {
697 gBS
->FreePool (CurrentTableList
);
698 return EFI_OUT_OF_RESOURCES
;
701 // Update the table pointer with the allocated memory start
703 CurrentTableList
->Table
= (EFI_ACPI_COMMON_HEADER
*) (UINTN
) CurrentTableList
->PageAddress
;
706 // Initialize the table contents
708 CurrentTableList
->Signature
= EFI_ACPI_TABLE_LIST_SIGNATURE
;
709 CopyMem (CurrentTableList
->Table
, Table
, CurrentTableSize
);
710 CurrentTableList
->Handle
= AcpiSupportInstance
->CurrentHandle
++;
711 *Handle
= CurrentTableList
->Handle
;
712 CurrentTableList
->Version
= Version
;
715 // Update internal pointers if this is a required table. If it is a required
716 // table and a table of that type already exists, return an error.
718 // Calculate the checksum if the table is not FACS.
720 switch (CurrentTableSignature
) {
722 case EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
724 // We don't add the FADT in the standard way because some
725 // OS expect the FADT to be early in the table list.
726 // So we always add it as the first element in the list.
731 // Check that the table has not been previously added.
733 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiSupportInstance
->Fadt1
!= NULL
) ||
734 ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 && AcpiSupportInstance
->Fadt3
!= NULL
) ||
735 ((Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0 && AcpiSupportInstance
->Fadt3
!= NULL
)
737 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
738 gBS
->FreePool (CurrentTableList
);
742 // Add the table to the appropriate table version
744 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
746 // Save a pointer to the table
748 AcpiSupportInstance
->Fadt1
= (EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE
*) CurrentTableList
->Table
;
751 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
753 AcpiSupportInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiSupportInstance
->Facs1
;
754 AcpiSupportInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiSupportInstance
->Dsdt1
;
757 // RSDP OEM information is updated to match the FADT OEM information
760 &AcpiSupportInstance
->Rsdp1
->OemId
,
761 &AcpiSupportInstance
->Fadt1
->Header
.OemId
,
766 // RSDT OEM information is updated to match the FADT OEM information.
769 &AcpiSupportInstance
->Rsdt1
->OemId
,
770 &AcpiSupportInstance
->Fadt1
->Header
.OemId
,
775 &AcpiSupportInstance
->Rsdt1
->OemTableId
,
776 &AcpiSupportInstance
->Fadt1
->Header
.OemTableId
,
779 AcpiSupportInstance
->Rsdt1
->OemRevision
= AcpiSupportInstance
->Fadt1
->Header
.OemRevision
;
782 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
783 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
785 // Save a pointer to the table
787 AcpiSupportInstance
->Fadt3
= (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE
*) CurrentTableList
->Table
;
790 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
792 if (AcpiSupportInstance
->Fadt3
!= NULL
) {
793 AcpiSupportInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiSupportInstance
->Facs3
;
794 Buffer64
= (UINT64
) (UINTN
) AcpiSupportInstance
->Facs3
;
796 &AcpiSupportInstance
->Fadt3
->XFirmwareCtrl
,
800 AcpiSupportInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiSupportInstance
->Dsdt3
;
801 Buffer64
= (UINT64
) (UINTN
) AcpiSupportInstance
->Dsdt3
;
803 &AcpiSupportInstance
->Fadt3
->XDsdt
,
809 // RSDP OEM information is updated to match the FADT OEM information
812 &AcpiSupportInstance
->Rsdp3
->OemId
,
813 &AcpiSupportInstance
->Fadt3
->Header
.OemId
,
818 // RSDT OEM information is updated to match FADT OEM information.
821 &AcpiSupportInstance
->Rsdt3
->OemId
,
822 &AcpiSupportInstance
->Fadt3
->Header
.OemId
,
826 &AcpiSupportInstance
->Rsdt3
->OemTableId
,
827 &AcpiSupportInstance
->Fadt3
->Header
.OemTableId
,
830 AcpiSupportInstance
->Rsdt3
->OemRevision
= AcpiSupportInstance
->Fadt3
->Header
.OemRevision
;
833 // XSDT OEM information is updated to match FADT OEM information.
836 &AcpiSupportInstance
->Xsdt
->OemId
,
837 &AcpiSupportInstance
->Fadt3
->Header
.OemId
,
841 &AcpiSupportInstance
->Xsdt
->OemTableId
,
842 &AcpiSupportInstance
->Fadt3
->Header
.OemTableId
,
845 AcpiSupportInstance
->Xsdt
->OemRevision
= AcpiSupportInstance
->Fadt3
->Header
.OemRevision
;
849 // Checksum the table
852 AcpiPlatformChecksum (
853 CurrentTableList
->Table
,
854 CurrentTableList
->Table
->Length
,
855 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
862 case EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
864 // Check that the table has not been previously added.
866 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiSupportInstance
->Facs1
!= NULL
) ||
867 ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 && AcpiSupportInstance
->Facs3
!= NULL
) ||
868 ((Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0 && AcpiSupportInstance
->Facs3
!= NULL
)
870 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
871 gBS
->FreePool (CurrentTableList
);
875 // FACS is referenced by FADT and is not part of RSDT
880 // Add the table to the appropriate table version
882 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
884 // Save a pointer to the table
886 AcpiSupportInstance
->Facs1
= (EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
889 // If FADT already exists, update table pointers.
891 if (AcpiSupportInstance
->Fadt1
!= NULL
) {
892 AcpiSupportInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiSupportInstance
->Facs1
;
895 // Checksum FADT table
897 AcpiPlatformChecksum (
898 AcpiSupportInstance
->Fadt1
,
899 AcpiSupportInstance
->Fadt1
->Header
.Length
,
900 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
906 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
907 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
909 // Save a pointer to the table
911 AcpiSupportInstance
->Facs3
= (EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
914 // If FADT already exists, update table pointers.
916 if (AcpiSupportInstance
->Fadt3
!= NULL
) {
917 AcpiSupportInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiSupportInstance
->Facs3
;
918 Buffer64
= (UINT64
) (UINTN
) AcpiSupportInstance
->Facs3
;
920 &AcpiSupportInstance
->Fadt3
->XFirmwareCtrl
,
926 // Checksum FADT table
928 AcpiPlatformChecksum (
929 AcpiSupportInstance
->Fadt3
,
930 AcpiSupportInstance
->Fadt3
->Header
.Length
,
931 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
939 case EFI_ACPI_1_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
941 // Check that the table has not been previously added.
943 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiSupportInstance
->Dsdt1
!= NULL
) ||
944 ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 && AcpiSupportInstance
->Dsdt3
!= NULL
) ||
945 ((Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0 && AcpiSupportInstance
->Dsdt3
!= NULL
)
947 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
948 gBS
->FreePool (CurrentTableList
);
952 // DSDT is referenced by FADT and is not part of RSDT
957 // Add the table to the appropriate table version
959 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
961 // Save a pointer to the table
963 AcpiSupportInstance
->Dsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
966 // If FADT already exists, update table pointers.
968 if (AcpiSupportInstance
->Fadt1
!= NULL
) {
969 AcpiSupportInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiSupportInstance
->Dsdt1
;
972 // Checksum FADT table
974 AcpiPlatformChecksum (
975 AcpiSupportInstance
->Fadt1
,
976 AcpiSupportInstance
->Fadt1
->Header
.Length
,
977 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
983 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
984 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
986 // Save a pointer to the table
988 AcpiSupportInstance
->Dsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
991 // If FADT already exists, update table pointers.
993 if (AcpiSupportInstance
->Fadt3
!= NULL
) {
994 AcpiSupportInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiSupportInstance
->Dsdt3
;
995 Buffer64
= (UINT64
) (UINTN
) AcpiSupportInstance
->Dsdt3
;
997 &AcpiSupportInstance
->Fadt3
->XDsdt
,
1003 // Checksum FADT table
1005 AcpiPlatformChecksum (
1006 AcpiSupportInstance
->Fadt3
,
1007 AcpiSupportInstance
->Fadt3
->Header
.Length
,
1008 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1014 // Checksum the table
1017 AcpiPlatformChecksum (
1018 CurrentTableList
->Table
,
1019 CurrentTableList
->Table
->Length
,
1020 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1028 // Checksum the table
1031 AcpiPlatformChecksum (
1032 CurrentTableList
->Table
,
1033 CurrentTableList
->Table
->Length
,
1034 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1041 // Add the table to the current list of tables
1043 InsertTailList (&AcpiSupportInstance
->TableList
, &CurrentTableList
->Link
);
1046 // Add the table to RSDT and/or XSDT table entry lists.
1049 // Add to ACPI 1.0b table tree
1051 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1054 // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
1056 if (AcpiSupportInstance
->NumberOfTableEntries1
>= mEfiAcpiMaxNumTables
) {
1057 Status
= ReallocateAcpiTableBuffer (AcpiSupportInstance
);
1058 ASSERT_EFI_ERROR (Status
);
1060 CurrentRsdtEntry
= (UINT32
*)
1062 (UINT8
*) AcpiSupportInstance
->Rsdt1
+
1063 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
1064 AcpiSupportInstance
->NumberOfTableEntries1
*
1069 // Add entry to the RSDT unless its the FACS or DSDT
1071 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
1074 // Update RSDT length
1076 AcpiSupportInstance
->Rsdt1
->Length
= AcpiSupportInstance
->Rsdt1
->Length
+ sizeof (UINT32
);
1078 AcpiSupportInstance
->NumberOfTableEntries1
++;
1082 // Add to ACPI 2.0/3.0 table tree
1084 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 || (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1087 // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
1089 if (AcpiSupportInstance
->NumberOfTableEntries3
>= mEfiAcpiMaxNumTables
) {
1090 Status
= ReallocateAcpiTableBuffer (AcpiSupportInstance
);
1091 ASSERT_EFI_ERROR (Status
);
1094 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
1095 // If it becomes necessary to maintain separate table lists, changes will be required.
1097 CurrentRsdtEntry
= (UINT32
*)
1099 (UINT8
*) AcpiSupportInstance
->Rsdt3
+
1100 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
1101 AcpiSupportInstance
->NumberOfTableEntries3
*
1106 // This pointer must not be directly dereferenced as the XSDT entries may not
1107 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
1109 CurrentXsdtEntry
= (VOID
*)
1111 (UINT8
*) AcpiSupportInstance
->Xsdt
+
1112 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
1113 AcpiSupportInstance
->NumberOfTableEntries3
*
1118 // Add entry to the RSDT
1120 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
1123 // Update RSDT length
1125 AcpiSupportInstance
->Rsdt3
->Length
= AcpiSupportInstance
->Rsdt3
->Length
+ sizeof (UINT32
);
1128 // Add entry to XSDT, XSDT expects 64 bit pointers, but
1129 // the table pointers in XSDT are not aligned on 8 byte boundary.
1131 Buffer64
= (UINT64
) (UINTN
) CurrentTableList
->Table
;
1141 AcpiSupportInstance
->Xsdt
->Length
= AcpiSupportInstance
->Xsdt
->Length
+ sizeof (UINT64
);
1143 AcpiSupportInstance
->NumberOfTableEntries3
++;
1147 ChecksumCommonTables (AcpiSupportInstance
);
1151 This function finds the table specified by the handle and returns a pointer to it.
1152 If the handle is not found, EFI_NOT_FOUND is returned and the contents of Table are
1155 @param Handle Table to find.
1156 @param TableList Table list to search
1157 @param Table Pointer to table found.
1159 @return EFI_SUCCESS The function completed successfully.
1160 @return EFI_NOT_FOUND No table found matching the handle specified.
1166 IN LIST_ENTRY
*TableList
,
1167 OUT EFI_ACPI_TABLE_LIST
**Table
1170 LIST_ENTRY
*CurrentLink
;
1171 EFI_ACPI_TABLE_LIST
*CurrentTable
;
1174 // Check for invalid input parameters
1181 CurrentLink
= TableList
->ForwardLink
;
1183 while (CurrentLink
!= TableList
) {
1184 CurrentTable
= EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink
);
1185 if (CurrentTable
->Handle
== Handle
) {
1187 // Found handle, so return this table.
1189 *Table
= CurrentTable
;
1193 CurrentLink
= CurrentLink
->ForwardLink
;
1198 return EFI_NOT_FOUND
;
1201 This function removes a basic table from the RSDT and/or XSDT.
1202 For Acpi 1.0 tables, pass in the Rsdt.
1203 For Acpi 2.0 tables, pass in both Rsdt and Xsdt.
1205 @param Table Pointer to table found.
1206 @param NumberOfTableEntries Current number of table entries in the RSDT/XSDT
1207 @param Rsdt Pointer to the RSDT to remove from
1208 @param Xsdt Pointer to the Xsdt to remove from
1210 @return EFI_SUCCESS The function completed successfully.
1211 @return EFI_INVALID_PARAMETER The table was not found in both Rsdt and Xsdt.
1215 RemoveTableFromRsdt (
1216 IN OUT EFI_ACPI_TABLE_LIST
* Table
,
1217 IN OUT UINTN
*NumberOfTableEntries
,
1218 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Rsdt
,
1219 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Xsdt OPTIONAL
1222 UINT32
*CurrentRsdtEntry
;
1223 VOID
*CurrentXsdtEntry
;
1224 UINT64 CurrentTablePointer64
;
1228 // Check for invalid input parameters
1231 ASSERT (NumberOfTableEntries
);
1235 // Find the table entry in the RSDT and XSDT
1237 for (TempIndex
= 0; TempIndex
< *NumberOfTableEntries
; TempIndex
++) {
1239 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
1240 // If it becomes necessary to maintain separate table lists, changes will be required.
1242 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) Rsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + TempIndex
* sizeof (UINT32
));
1245 // This pointer must not be directly dereferenced as the XSDT entries may not
1246 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
1248 CurrentXsdtEntry
= (VOID
*) ((UINT8
*) Xsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + TempIndex
* sizeof (UINT64
));
1251 // Read the entry value out of the XSDT
1253 CopyMem (&CurrentTablePointer64
, CurrentXsdtEntry
, sizeof (UINT64
));
1256 // Initialize to NULL
1258 CurrentXsdtEntry
= 0;
1259 CurrentTablePointer64
= 0;
1262 // Check if we have found the corresponding entry in both RSDT and XSDT
1264 if (*CurrentRsdtEntry
== (UINT32
) (UINTN
) Table
->Table
&&
1265 ((Xsdt
== NULL
) || CurrentTablePointer64
== (UINT64
) (UINTN
) Table
->Table
)
1268 // Found entry, so copy all following entries and shrink table
1269 // We actually copy all + 1 to copy the initialized value of memory over
1272 CopyMem (CurrentRsdtEntry
, CurrentRsdtEntry
+ 1, (*NumberOfTableEntries
- TempIndex
) * sizeof (UINT32
));
1273 Rsdt
->Length
= Rsdt
->Length
- sizeof (UINT32
);
1275 CopyMem (CurrentXsdtEntry
, ((UINT64
*) CurrentXsdtEntry
) + 1, (*NumberOfTableEntries
- TempIndex
) * sizeof (UINT64
));
1276 Xsdt
->Length
= Xsdt
->Length
- sizeof (UINT64
);
1279 } else if (TempIndex
+ 1 == *NumberOfTableEntries
) {
1281 // At the last entry, and table not found
1283 return EFI_INVALID_PARAMETER
;
1287 // Checksum the tables
1289 AcpiPlatformChecksum (
1292 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1297 AcpiPlatformChecksum (
1300 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1305 // Decrement the number of tables
1307 (*NumberOfTableEntries
)--;
1312 This function removes a table and frees any associated memory.
1314 @param AcpiSupportInstance Instance of the protocol.
1315 @param Version Version(s) to delete.
1316 @param Table Pointer to table found.
1318 @return EFI_SUCCESS The function completed successfully.
1323 IN EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
,
1324 IN EFI_ACPI_TABLE_VERSION Version
,
1325 IN OUT EFI_ACPI_TABLE_LIST
*Table
1328 UINT32 CurrentTableSignature
;
1329 BOOLEAN RemoveFromRsdt
;
1332 // Check for invalid input parameters
1334 ASSERT (AcpiSupportInstance
);
1340 RemoveFromRsdt
= TRUE
;
1342 if (Table
->Table
!= NULL
) {
1343 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
->Table
)->Signature
;
1346 // Basic tasks to accomplish delete are:
1347 // Determine removal requirements (in RSDT/XSDT or not)
1348 // Remove entry from RSDT/XSDT
1349 // Remove any table references to the table
1350 // If no one is using the table
1351 // Free the table (removing pointers from private data and tables)
1353 // Free list structure
1356 // Determine if this table is in the RSDT or XSDT
1358 if ((CurrentTableSignature
== EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) ||
1359 (CurrentTableSignature
== EFI_ACPI_2_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
) ||
1360 (CurrentTableSignature
== EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
)
1362 RemoveFromRsdt
= FALSE
;
1365 // We don't remove the FADT in the standard way because some
1366 // OS expect the FADT to be early in the table list.
1367 // So we always put it as the first element in the list.
1369 if (CurrentTableSignature
== EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
) {
1370 RemoveFromRsdt
= FALSE
;
1374 // Remove the table from RSDT and XSDT
1378 // This is a basic table, remove it from any lists and the Rsdt and/or Xsdt
1380 if (Version
& EFI_ACPI_TABLE_VERSION_NONE
& Table
->Version
) {
1382 // Remove this version from the table
1384 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_NONE
;
1387 if (Version
& EFI_ACPI_TABLE_VERSION_1_0B
& Table
->Version
) {
1389 // Remove this version from the table
1391 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_1_0B
;
1394 // Remove from Rsdt. We don't care about the return value because it is
1395 // acceptable for the table to not exist in Rsdt.
1396 // We didn't add some tables so we don't remove them.
1398 if (RemoveFromRsdt
) {
1399 RemoveTableFromRsdt (
1401 &AcpiSupportInstance
->NumberOfTableEntries1
,
1402 AcpiSupportInstance
->Rsdt1
,
1408 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
& Table
->Version
) ||
1409 (Version
& EFI_ACPI_TABLE_VERSION_3_0
& Table
->Version
)) {
1411 // Remove this version from the table
1413 if (Version
& EFI_ACPI_TABLE_VERSION_2_0
& Table
->Version
) {
1414 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_2_0
;
1416 if (Version
& EFI_ACPI_TABLE_VERSION_3_0
& Table
->Version
) {
1417 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_3_0
;
1421 // Remove from Rsdt and Xsdt. We don't care about the return value
1422 // because it is acceptable for the table to not exist in Rsdt/Xsdt.
1423 // We didn't add some tables so we don't remove them.
1425 if (RemoveFromRsdt
) {
1426 RemoveTableFromRsdt (
1428 &AcpiSupportInstance
->NumberOfTableEntries3
,
1429 AcpiSupportInstance
->Rsdt3
,
1430 AcpiSupportInstance
->Xsdt
1435 // Free the table, clean up any dependent tables and our private data pointers.
1437 switch (Table
->Table
->Signature
) {
1439 case EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
1440 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1441 AcpiSupportInstance
->Fadt1
= NULL
;
1444 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
1445 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1446 AcpiSupportInstance
->Fadt3
= NULL
;
1450 case EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
1451 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1452 AcpiSupportInstance
->Facs1
= NULL
;
1455 // Update FADT table pointers
1457 if (AcpiSupportInstance
->Fadt1
!= NULL
) {
1458 AcpiSupportInstance
->Fadt1
->FirmwareCtrl
= 0;
1463 AcpiPlatformChecksum (
1464 AcpiSupportInstance
->Fadt1
,
1465 AcpiSupportInstance
->Fadt1
->Header
.Length
,
1466 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1472 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
1473 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1474 AcpiSupportInstance
->Facs3
= NULL
;
1477 // Update FADT table pointers
1479 if (AcpiSupportInstance
->Fadt3
!= NULL
) {
1480 AcpiSupportInstance
->Fadt3
->FirmwareCtrl
= 0;
1481 ZeroMem (&AcpiSupportInstance
->Fadt3
->XFirmwareCtrl
, sizeof (UINT64
));
1486 AcpiPlatformChecksum (
1487 AcpiSupportInstance
->Fadt3
,
1488 AcpiSupportInstance
->Fadt3
->Header
.Length
,
1489 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1496 case EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
1497 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1498 AcpiSupportInstance
->Dsdt1
= NULL
;
1501 // Update FADT table pointers
1503 if (AcpiSupportInstance
->Fadt1
!= NULL
) {
1504 AcpiSupportInstance
->Fadt1
->Dsdt
= 0;
1509 AcpiPlatformChecksum (
1510 AcpiSupportInstance
->Fadt1
,
1511 AcpiSupportInstance
->Fadt1
->Header
.Length
,
1512 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1519 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
1520 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1521 AcpiSupportInstance
->Dsdt3
= NULL
;
1524 // Update FADT table pointers
1526 if (AcpiSupportInstance
->Fadt3
!= NULL
) {
1527 AcpiSupportInstance
->Fadt3
->Dsdt
= 0;
1528 ZeroMem (&AcpiSupportInstance
->Fadt3
->XDsdt
, sizeof (UINT64
));
1533 AcpiPlatformChecksum (
1534 AcpiSupportInstance
->Fadt3
,
1535 AcpiSupportInstance
->Fadt3
->Header
.Length
,
1536 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1551 // If no version is using this table anymore, remove and free list entry.
1553 if (Table
->Version
== 0) {
1557 gBS
->FreePages (Table
->PageAddress
, Table
->NumberOfPages
);
1558 RemoveEntryList (&(Table
->Link
));
1559 gBS
->FreePool (Table
);
1567 This function finds and removes the table specified by the handle.
1569 @param AcpiSupportInstance Instance of the protocol.
1570 @param Version Bitmask of which versions to remove.
1571 @param Handle Table to remove.
1573 @return EFI_SUCCESS The function completed successfully.
1574 @return EFI_ABORTED An error occurred.
1575 @return EFI_NOT_FOUND Handle not found in table list.
1578 RemoveTableFromList (
1579 IN EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
,
1580 IN EFI_ACPI_TABLE_VERSION Version
,
1584 EFI_ACPI_TABLE_LIST
*Table
;
1590 // Check for invalid input parameters
1592 ASSERT (AcpiSupportInstance
);
1597 Status
= FindTableByHandle (
1599 &AcpiSupportInstance
->TableList
,
1602 if (EFI_ERROR (Status
)) {
1603 return EFI_NOT_FOUND
;
1608 Status
= DeleteTable (AcpiSupportInstance
, Version
, Table
);
1609 if (EFI_ERROR (Status
)) {
1613 // Completed successfully
1618 This function calculates and updates an UINT8 checksum.
1620 @param Buffer Pointer to buffer to checksum
1621 @param Size Number of bytes to checksum
1622 @param ChecksumOffset Offset to place the checksum result in
1624 @return EFI_SUCCESS The function completed successfully.
1628 AcpiPlatformChecksum (
1631 IN UINTN ChecksumOffset
1639 // Initialize pointer
1644 // set checksum to 0 first
1646 Ptr
[ChecksumOffset
] = 0;
1649 // add all content of buffer
1651 while ((Size
--) != 0) {
1652 Sum
= (UINT8
) (Sum
+ (*Ptr
++));
1658 Ptr
[ChecksumOffset
] = (UINT8
) (0xff - Sum
+ 1);
1663 Checksum all versions of the common tables, RSDP, RSDT, XSDT.
1665 @param AcpiSupportInstance Protocol instance private data.
1667 @return EFI_SUCCESS The function completed successfully.
1671 ChecksumCommonTables (
1672 IN OUT EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
1676 // RSDP ACPI 1.0 checksum for 1.0 table. This is only the first 20 bytes of the structure
1678 AcpiPlatformChecksum (
1679 AcpiSupportInstance
->Rsdp1
,
1680 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1681 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1686 // RSDP ACPI 1.0 checksum for 2.0/3.0 table. This is only the first 20 bytes of the structure
1688 AcpiPlatformChecksum (
1689 AcpiSupportInstance
->Rsdp3
,
1690 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1691 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1696 // RSDP ACPI 2.0/3.0 checksum, this is the entire table
1698 AcpiPlatformChecksum (
1699 AcpiSupportInstance
->Rsdp3
,
1700 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1701 OFFSET_OF (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1708 AcpiPlatformChecksum (
1709 AcpiSupportInstance
->Rsdt1
,
1710 AcpiSupportInstance
->Rsdt1
->Length
,
1711 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1715 AcpiPlatformChecksum (
1716 AcpiSupportInstance
->Rsdt3
,
1717 AcpiSupportInstance
->Rsdt3
->Length
,
1718 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1725 AcpiPlatformChecksum (
1726 AcpiSupportInstance
->Xsdt
,
1727 AcpiSupportInstance
->Xsdt
->Length
,
1728 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1735 Constructor for the ACPI support protocol to initializes instance data.
1737 @param AcpiSupportInstance Instance to construct
1739 @retval EFI_SUCCESS Instance initialized.
1740 @retval EFI_OUT_OF_RESOURCES Unable to allocate required resources.
1743 AcpiSupportAcpiSupportConstructor (
1744 IN EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
1750 UINTN RsdpTableSize
;
1752 EFI_PHYSICAL_ADDRESS PageAddress
;
1755 // Check for invalid input parameters
1757 ASSERT (AcpiSupportInstance
);
1759 InitializeListHead (&AcpiSupportInstance
->TableList
);
1760 AcpiSupportInstance
->CurrentHandle
= 1;
1761 AcpiSupportInstance
->AcpiSupport
.GetAcpiTable
= GetAcpiTable
;
1762 AcpiSupportInstance
->AcpiSupport
.SetAcpiTable
= SetAcpiTable
;
1763 AcpiSupportInstance
->AcpiSupport
.PublishTables
= PublishTables
;
1765 AcpiSupportInstance
->AcpiTableProtocol
.InstallAcpiTable
= InstallAcpiTable
;
1766 AcpiSupportInstance
->AcpiTableProtocol
.UninstallAcpiTable
= UninstallAcpiTable
;
1769 // Create RSDP table
1771 RsdpTableSize
= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
) +
1772 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1774 PageAddress
= 0xFFFFFFFF;
1775 Status
= gBS
->AllocatePages (
1777 EfiACPIReclaimMemory
,
1778 EFI_SIZE_TO_PAGES (RsdpTableSize
),
1782 if (EFI_ERROR (Status
)) {
1783 return EFI_OUT_OF_RESOURCES
;
1786 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
1787 ZeroMem (Pointer
, RsdpTableSize
);
1789 AcpiSupportInstance
->Rsdp1
= (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1790 Pointer
+= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1791 AcpiSupportInstance
->Rsdp3
= (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1794 // Create RSDT, XSDT structures
1796 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
1797 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
1798 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
1799 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
1800 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
1801 mEfiAcpiMaxNumTables
* sizeof (UINT64
);
1804 // Allocate memory in the lower 32 bit of address range for
1805 // compatibility with ACPI 1.0 OS.
1807 // This is done because ACPI 1.0 pointers are 32 bit values.
1808 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
1809 // There is no architectural reason these should be below 4GB, it is purely
1810 // for convenience of implementation that we force memory below 4GB.
1812 PageAddress
= 0xFFFFFFFF;
1813 Status
= gBS
->AllocatePages (
1815 EfiACPIReclaimMemory
,
1816 EFI_SIZE_TO_PAGES (TotalSize
),
1820 if (EFI_ERROR (Status
)) {
1821 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
)(UINTN
)AcpiSupportInstance
->Rsdp1
, EFI_SIZE_TO_PAGES (RsdpTableSize
));
1822 return EFI_OUT_OF_RESOURCES
;
1825 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
1826 ZeroMem (Pointer
, TotalSize
);
1828 AcpiSupportInstance
->Rsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1829 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1830 AcpiSupportInstance
->Rsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1831 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1832 AcpiSupportInstance
->Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1837 CurrentData
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1838 CopyMem (&AcpiSupportInstance
->Rsdp1
->Signature
, &CurrentData
, sizeof (UINT64
));
1839 CopyMem (AcpiSupportInstance
->Rsdp1
->OemId
, EFI_ACPI_OEM_ID
, 6);
1840 AcpiSupportInstance
->Rsdp1
->Reserved
= EFI_ACPI_RESERVED_BYTE
;
1841 AcpiSupportInstance
->Rsdp1
->RsdtAddress
= (UINT32
) (UINTN
) AcpiSupportInstance
->Rsdt1
;
1843 CurrentData
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1844 CopyMem (&AcpiSupportInstance
->Rsdp3
->Signature
, &CurrentData
, sizeof (UINT64
));
1845 CopyMem (AcpiSupportInstance
->Rsdp3
->OemId
, EFI_ACPI_OEM_ID
, 6);
1846 AcpiSupportInstance
->Rsdp3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION
;
1847 AcpiSupportInstance
->Rsdp3
->RsdtAddress
= (UINT32
) (UINTN
) AcpiSupportInstance
->Rsdt3
;
1848 AcpiSupportInstance
->Rsdp3
->Length
= sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1849 CurrentData
= (UINT64
) (UINTN
) AcpiSupportInstance
->Xsdt
;
1850 CopyMem (&AcpiSupportInstance
->Rsdp3
->XsdtAddress
, &CurrentData
, sizeof (UINT64
));
1851 SetMem (AcpiSupportInstance
->Rsdp3
->Reserved
, 3, EFI_ACPI_RESERVED_BYTE
);
1856 // Note that we "reserve" one entry for the FADT so it can always be
1857 // at the beginning of the list of tables. Some OS don't seem
1858 // to find it correctly if it is too far down the list.
1860 AcpiSupportInstance
->Rsdt1
->Signature
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1861 AcpiSupportInstance
->Rsdt1
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1862 AcpiSupportInstance
->Rsdt1
->Revision
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1863 CopyMem (AcpiSupportInstance
->Rsdt1
->OemId
, EFI_ACPI_OEM_ID
, 6);
1864 CurrentData
= EFI_ACPI_OEM_TABLE_ID
;
1865 CopyMem (&AcpiSupportInstance
->Rsdt1
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1866 AcpiSupportInstance
->Rsdt1
->OemRevision
= EFI_ACPI_OEM_REVISION
;
1867 AcpiSupportInstance
->Rsdt1
->CreatorId
= EFI_ACPI_CREATOR_ID
;
1868 AcpiSupportInstance
->Rsdt1
->CreatorRevision
= EFI_ACPI_CREATOR_REVISION
;
1870 // We always reserve first one for FADT
1872 AcpiSupportInstance
->NumberOfTableEntries1
= 1;
1873 AcpiSupportInstance
->Rsdt1
->Length
= AcpiSupportInstance
->Rsdt1
->Length
+ sizeof(UINT32
);
1875 AcpiSupportInstance
->Rsdt3
->Signature
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1876 AcpiSupportInstance
->Rsdt3
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1877 AcpiSupportInstance
->Rsdt3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1878 CopyMem (AcpiSupportInstance
->Rsdt3
->OemId
, EFI_ACPI_OEM_ID
, 6);
1879 CurrentData
= EFI_ACPI_OEM_TABLE_ID
;
1880 CopyMem (&AcpiSupportInstance
->Rsdt3
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1881 AcpiSupportInstance
->Rsdt3
->OemRevision
= EFI_ACPI_OEM_REVISION
;
1882 AcpiSupportInstance
->Rsdt3
->CreatorId
= EFI_ACPI_CREATOR_ID
;
1883 AcpiSupportInstance
->Rsdt3
->CreatorRevision
= EFI_ACPI_CREATOR_REVISION
;
1885 // We always reserve first one for FADT
1887 AcpiSupportInstance
->NumberOfTableEntries3
= 1;
1888 AcpiSupportInstance
->Rsdt3
->Length
= AcpiSupportInstance
->Rsdt3
->Length
+ sizeof(UINT32
);
1893 AcpiSupportInstance
->Xsdt
->Signature
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1894 AcpiSupportInstance
->Xsdt
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1895 AcpiSupportInstance
->Xsdt
->Revision
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1896 CopyMem (AcpiSupportInstance
->Xsdt
->OemId
, EFI_ACPI_OEM_ID
, 6);
1897 CurrentData
= EFI_ACPI_OEM_TABLE_ID
;
1898 CopyMem (&AcpiSupportInstance
->Xsdt
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1899 AcpiSupportInstance
->Xsdt
->OemRevision
= EFI_ACPI_OEM_REVISION
;
1900 AcpiSupportInstance
->Xsdt
->CreatorId
= EFI_ACPI_CREATOR_ID
;
1901 AcpiSupportInstance
->Xsdt
->CreatorRevision
= EFI_ACPI_CREATOR_REVISION
;
1903 // We always reserve first one for FADT
1905 AcpiSupportInstance
->Xsdt
->Length
= AcpiSupportInstance
->Xsdt
->Length
+ sizeof(UINT64
);
1907 ChecksumCommonTables (AcpiSupportInstance
);
1910 // Completed successfully