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
;
395 // Check for invalid input parameters
397 if ((AcpiTableBuffer
== NULL
) || (TableKey
== NULL
)
398 || (((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTableBuffer
)->Length
!= AcpiTableBufferSize
)) {
399 return EFI_INVALID_PARAMETER
;
403 // Get the instance of the ACPI support protocol
405 AcpiSupportInstance
= EFI_ACPI_TABLE_INSTANCE_FROM_ACPI_SUPPORT_THIS (This
);
406 AcpiSupport
= &AcpiSupportInstance
->AcpiSupport
;
409 // Install the ACPI table by using ACPI support protocol
411 AcpiTableBufferConst
= AllocateCopyPool (AcpiTableBufferSize
, AcpiTableBuffer
);
413 Status
= AcpiSupport
->SetAcpiTable (
415 AcpiTableBufferConst
,
417 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
,
420 if (!EFI_ERROR (Status
)) {
421 Status
= AcpiSupport
->PublishTables (
423 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
426 FreePool (AcpiTableBufferConst
);
431 Removes an ACPI table from the RSDT/XSDT.
433 @param This Protocol instance pointer.
434 @param TableKey Specifies the table to uninstall. The key was returned from InstallAcpiTable().
436 @return EFI_SUCCESS The table was successfully uninstalled.
437 @return EFI_NOT_FOUND TableKey does not refer to a valid key for a table entry.
443 IN EFI_ACPI_TABLE_PROTOCOL
*This
,
447 EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
;
448 EFI_ACPI_SUPPORT_PROTOCOL
*AcpiSupport
;
452 // Get the instance of the ACPI support protocol
454 AcpiSupportInstance
= EFI_ACPI_TABLE_INSTANCE_FROM_ACPI_SUPPORT_THIS (This
);
455 AcpiSupport
= &AcpiSupportInstance
->AcpiSupport
;
458 // Uninstall the ACPI table by using ACPI support protocol
460 Status
= AcpiSupport
->SetAcpiTable (
464 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
,
467 if (!EFI_ERROR (Status
)) {
468 Status
= AcpiSupport
->PublishTables (
470 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
474 if (EFI_ERROR (Status
)) {
475 return EFI_NOT_FOUND
;
481 If the number of APCI tables exceeds the preallocated max table number, enlarge the table buffer.
483 @param AcpiSupportInstance ACPI support protocol instance data structure
485 @return EFI_SUCCESS reallocate the table beffer successfully.
486 @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
490 ReallocateAcpiTableBuffer (
491 IN EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
494 UINTN NewMaxTableNumber
;
497 EFI_PHYSICAL_ADDRESS PageAddress
;
498 EFI_ACPI_SUPPORT_INSTANCE TempPrivateData
;
502 CopyMem (&TempPrivateData
, AcpiSupportInstance
, sizeof (EFI_ACPI_SUPPORT_INSTANCE
));
504 // Enlarge the max table number from mEfiAcpiMaxNumTables to mEfiAcpiMaxNumTables + EFI_ACPI_MAX_NUM_TABLES
506 NewMaxTableNumber
= mEfiAcpiMaxNumTables
+ EFI_ACPI_MAX_NUM_TABLES
;
508 // Create RSDT, XSDT structures and allocate buffers.
510 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
511 NewMaxTableNumber
* sizeof (UINT32
) +
512 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
513 NewMaxTableNumber
* sizeof (UINT32
) +
514 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
515 NewMaxTableNumber
* sizeof (UINT64
);
518 // Allocate memory in the lower 32 bit of address range for
519 // compatibility with ACPI 1.0 OS.
521 // This is done because ACPI 1.0 pointers are 32 bit values.
522 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
523 // There is no architectural reason these should be below 4GB, it is purely
524 // for convenience of implementation that we force memory below 4GB.
526 PageAddress
= 0xFFFFFFFF;
527 Status
= gBS
->AllocatePages (
529 EfiACPIReclaimMemory
,
530 EFI_SIZE_TO_PAGES (TotalSize
),
534 if (EFI_ERROR (Status
)) {
535 return EFI_OUT_OF_RESOURCES
;
538 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
539 ZeroMem (Pointer
, TotalSize
);
541 AcpiSupportInstance
->Rsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
542 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + NewMaxTableNumber
* sizeof (UINT32
));
543 AcpiSupportInstance
->Rsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
544 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + NewMaxTableNumber
* sizeof (UINT32
));
545 AcpiSupportInstance
->Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
548 // Update RSDP to point to the new Rsdt and Xsdt address.
550 AcpiSupportInstance
->Rsdp1
->RsdtAddress
= (UINT32
) (UINTN
) AcpiSupportInstance
->Rsdt1
;
551 AcpiSupportInstance
->Rsdp3
->RsdtAddress
= (UINT32
) (UINTN
) AcpiSupportInstance
->Rsdt3
;
552 CurrentData
= (UINT64
) (UINTN
) AcpiSupportInstance
->Xsdt
;
553 CopyMem (&AcpiSupportInstance
->Rsdp3
->XsdtAddress
, &CurrentData
, sizeof (UINT64
));
556 // copy the original Rsdt1, Rsdt3 and Xsdt structure to new buffer
558 CopyMem (AcpiSupportInstance
->Rsdt1
, TempPrivateData
.Rsdt1
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT32
)));
559 CopyMem (AcpiSupportInstance
->Rsdt3
, TempPrivateData
.Rsdt3
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT32
)));
560 CopyMem (AcpiSupportInstance
->Xsdt
, TempPrivateData
.Xsdt
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT64
)));
563 // Calculate orignal ACPI table buffer size
565 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
566 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
567 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
568 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
569 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
570 mEfiAcpiMaxNumTables
* sizeof (UINT64
);
571 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
)(UINTN
)TempPrivateData
.Rsdt1
, EFI_SIZE_TO_PAGES (TotalSize
));
574 // Update the Max ACPI table number
576 mEfiAcpiMaxNumTables
= NewMaxTableNumber
;
580 This function adds an ACPI table to the table list. It will detect FACS and
581 allocate the correct type of memory and properly align the table.
583 @param AcpiSupportInstance Instance of the protocol.
584 @param Table Table to add.
585 @param Checksum Does the table require checksumming.
586 @param Version The version of the list to add the table to.
587 @param Handle Pointer for returning the handle.
589 @return EFI_SUCCESS The function completed successfully.
590 @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
591 @return EFI_ABORTED The table is a duplicate of a table that is required
596 IN EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
,
599 IN EFI_ACPI_TABLE_VERSION Version
,
604 EFI_ACPI_TABLE_LIST
*CurrentTableList
;
605 UINT32 CurrentTableSignature
;
606 UINT32 CurrentTableSize
;
607 UINT32
*CurrentRsdtEntry
;
608 VOID
*CurrentXsdtEntry
;
613 // Check for invalid input parameters
615 ASSERT (AcpiSupportInstance
);
625 // Create a new list entry
627 CurrentTableList
= AllocatePool (sizeof (EFI_ACPI_TABLE_LIST
));
628 ASSERT (CurrentTableList
);
631 // Determine table type and size
633 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
)->Signature
;
634 CurrentTableSize
= ((EFI_ACPI_COMMON_HEADER
*) Table
)->Length
;
637 // Allocate a buffer for the table. All tables are allocated in the lower 32 bits of address space
638 // for backwards compatibility with ACPI 1.0 OS.
640 // This is done because ACPI 1.0 pointers are 32 bit values.
641 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
642 // There is no architectural reason these should be below 4GB, it is purely
643 // for convenience of implementation that we force memory below 4GB.
645 CurrentTableList
->PageAddress
= 0xFFFFFFFF;
646 CurrentTableList
->NumberOfPages
= EFI_SIZE_TO_PAGES (CurrentTableSize
);
649 // Allocation memory type depends on the type of the table
651 if ((CurrentTableSignature
== EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) ||
652 (CurrentTableSignature
== EFI_ACPI_4_0_UEFI_ACPI_DATA_TABLE_SIGNATURE
)) {
654 // Allocate memory for the FACS. This structure must be aligned
655 // on a 64 byte boundary and must be ACPI NVS memory.
656 // Using AllocatePages should ensure that it is always aligned.
657 // Do not change signature for new ACPI version because they are same.
659 // UEFI table also need to be in ACPI NVS memory, because some data field
660 // could be updated by OS present agent. For example, BufferPtrAddress in
661 // SMM communication ACPI table.
663 ASSERT ((EFI_PAGE_SIZE
% 64) == 0);
664 Status
= gBS
->AllocatePages (
667 CurrentTableList
->NumberOfPages
,
668 &CurrentTableList
->PageAddress
672 // All other tables are ACPI reclaim memory, no alignment requirements.
674 Status
= gBS
->AllocatePages (
676 EfiACPIReclaimMemory
,
677 CurrentTableList
->NumberOfPages
,
678 &CurrentTableList
->PageAddress
682 // Check return value from memory alloc.
684 if (EFI_ERROR (Status
)) {
685 gBS
->FreePool (CurrentTableList
);
686 return EFI_OUT_OF_RESOURCES
;
689 // Update the table pointer with the allocated memory start
691 CurrentTableList
->Table
= (EFI_ACPI_COMMON_HEADER
*) (UINTN
) CurrentTableList
->PageAddress
;
694 // Initialize the table contents
696 CurrentTableList
->Signature
= EFI_ACPI_TABLE_LIST_SIGNATURE
;
697 CopyMem (CurrentTableList
->Table
, Table
, CurrentTableSize
);
698 CurrentTableList
->Handle
= AcpiSupportInstance
->CurrentHandle
++;
699 *Handle
= CurrentTableList
->Handle
;
700 CurrentTableList
->Version
= Version
;
703 // Update internal pointers if this is a required table. If it is a required
704 // table and a table of that type already exists, return an error.
706 // Calculate the checksum if the table is not FACS.
708 switch (CurrentTableSignature
) {
710 case EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
712 // We don't add the FADT in the standard way because some
713 // OS expect the FADT to be early in the table list.
714 // So we always add it as the first element in the list.
719 // Check that the table has not been previously added.
721 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiSupportInstance
->Fadt1
!= NULL
) ||
722 ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 && AcpiSupportInstance
->Fadt3
!= NULL
) ||
723 ((Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0 && AcpiSupportInstance
->Fadt3
!= NULL
)
725 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
726 gBS
->FreePool (CurrentTableList
);
730 // Add the table to the appropriate table version
732 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
734 // Save a pointer to the table
736 AcpiSupportInstance
->Fadt1
= (EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE
*) CurrentTableList
->Table
;
739 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
741 AcpiSupportInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiSupportInstance
->Facs1
;
742 AcpiSupportInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiSupportInstance
->Dsdt1
;
745 // RSDP OEM information is updated to match the FADT OEM information
748 &AcpiSupportInstance
->Rsdp1
->OemId
,
749 &AcpiSupportInstance
->Fadt1
->Header
.OemId
,
754 // RSDT OEM information is updated to match the FADT OEM information.
757 &AcpiSupportInstance
->Rsdt1
->OemId
,
758 &AcpiSupportInstance
->Fadt1
->Header
.OemId
,
763 &AcpiSupportInstance
->Rsdt1
->OemTableId
,
764 &AcpiSupportInstance
->Fadt1
->Header
.OemTableId
,
767 AcpiSupportInstance
->Rsdt1
->OemRevision
= AcpiSupportInstance
->Fadt1
->Header
.OemRevision
;
770 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
771 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
773 // Save a pointer to the table
775 AcpiSupportInstance
->Fadt3
= (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE
*) CurrentTableList
->Table
;
778 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
780 AcpiSupportInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiSupportInstance
->Facs3
;
781 Buffer64
= (UINT64
) (UINTN
) AcpiSupportInstance
->Facs3
;
783 &AcpiSupportInstance
->Fadt3
->XFirmwareCtrl
,
787 AcpiSupportInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiSupportInstance
->Dsdt3
;
788 Buffer64
= (UINT64
) (UINTN
) AcpiSupportInstance
->Dsdt3
;
790 &AcpiSupportInstance
->Fadt3
->XDsdt
,
796 // RSDP OEM information is updated to match the FADT OEM information
799 &AcpiSupportInstance
->Rsdp3
->OemId
,
800 &AcpiSupportInstance
->Fadt3
->Header
.OemId
,
805 // RSDT OEM information is updated to match FADT OEM information.
808 &AcpiSupportInstance
->Rsdt3
->OemId
,
809 &AcpiSupportInstance
->Fadt3
->Header
.OemId
,
813 &AcpiSupportInstance
->Rsdt3
->OemTableId
,
814 &AcpiSupportInstance
->Fadt3
->Header
.OemTableId
,
817 AcpiSupportInstance
->Rsdt3
->OemRevision
= AcpiSupportInstance
->Fadt3
->Header
.OemRevision
;
820 // XSDT OEM information is updated to match FADT OEM information.
823 &AcpiSupportInstance
->Xsdt
->OemId
,
824 &AcpiSupportInstance
->Fadt3
->Header
.OemId
,
828 &AcpiSupportInstance
->Xsdt
->OemTableId
,
829 &AcpiSupportInstance
->Fadt3
->Header
.OemTableId
,
832 AcpiSupportInstance
->Xsdt
->OemRevision
= AcpiSupportInstance
->Fadt3
->Header
.OemRevision
;
836 // Checksum the table
839 AcpiPlatformChecksum (
840 CurrentTableList
->Table
,
841 CurrentTableList
->Table
->Length
,
842 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
848 case EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
850 // Check that the table has not been previously added.
852 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiSupportInstance
->Facs1
!= NULL
) ||
853 ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 && AcpiSupportInstance
->Facs3
!= NULL
) ||
854 ((Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0 && AcpiSupportInstance
->Facs3
!= NULL
)
856 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
857 gBS
->FreePool (CurrentTableList
);
861 // FACS is referenced by FADT and is not part of RSDT
866 // Add the table to the appropriate table version
868 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
870 // Save a pointer to the table
872 AcpiSupportInstance
->Facs1
= (EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
875 // If FADT already exists, update table pointers.
877 if (AcpiSupportInstance
->Fadt1
!= NULL
) {
878 AcpiSupportInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiSupportInstance
->Facs1
;
881 // Checksum FADT table
883 AcpiPlatformChecksum (
884 AcpiSupportInstance
->Fadt1
,
885 AcpiSupportInstance
->Fadt1
->Header
.Length
,
886 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
892 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
893 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
895 // Save a pointer to the table
897 AcpiSupportInstance
->Facs3
= (EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
900 // If FADT already exists, update table pointers.
902 if (AcpiSupportInstance
->Fadt3
!= NULL
) {
903 AcpiSupportInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiSupportInstance
->Facs3
;
904 Buffer64
= (UINT64
) (UINTN
) AcpiSupportInstance
->Facs3
;
906 &AcpiSupportInstance
->Fadt3
->XFirmwareCtrl
,
912 // Checksum FADT table
914 AcpiPlatformChecksum (
915 AcpiSupportInstance
->Fadt3
,
916 AcpiSupportInstance
->Fadt3
->Header
.Length
,
917 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
925 case EFI_ACPI_1_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
927 // Check that the table has not been previously added.
929 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiSupportInstance
->Dsdt1
!= NULL
) ||
930 ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 && AcpiSupportInstance
->Dsdt3
!= NULL
) ||
931 ((Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0 && AcpiSupportInstance
->Dsdt3
!= NULL
)
933 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
934 gBS
->FreePool (CurrentTableList
);
938 // DSDT is referenced by FADT and is not part of RSDT
943 // Add the table to the appropriate table version
945 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
947 // Save a pointer to the table
949 AcpiSupportInstance
->Dsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
952 // If FADT already exists, update table pointers.
954 if (AcpiSupportInstance
->Fadt1
!= NULL
) {
955 AcpiSupportInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiSupportInstance
->Dsdt1
;
958 // Checksum FADT table
960 AcpiPlatformChecksum (
961 AcpiSupportInstance
->Fadt1
,
962 AcpiSupportInstance
->Fadt1
->Header
.Length
,
963 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
969 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
970 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
972 // Save a pointer to the table
974 AcpiSupportInstance
->Dsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
977 // If FADT already exists, update table pointers.
979 if (AcpiSupportInstance
->Fadt3
!= NULL
) {
980 AcpiSupportInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiSupportInstance
->Dsdt3
;
981 Buffer64
= (UINT64
) (UINTN
) AcpiSupportInstance
->Dsdt3
;
983 &AcpiSupportInstance
->Fadt3
->XDsdt
,
989 // Checksum FADT table
991 AcpiPlatformChecksum (
992 AcpiSupportInstance
->Fadt3
,
993 AcpiSupportInstance
->Fadt3
->Header
.Length
,
994 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1000 // Checksum the table
1003 AcpiPlatformChecksum (
1004 CurrentTableList
->Table
,
1005 CurrentTableList
->Table
->Length
,
1006 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
,
1027 // Add the table to the current list of tables
1029 InsertTailList (&AcpiSupportInstance
->TableList
, &CurrentTableList
->Link
);
1032 // Add the table to RSDT and/or XSDT table entry lists.
1035 // Add to ACPI 1.0b table tree
1037 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1040 // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
1042 if (AcpiSupportInstance
->NumberOfTableEntries1
>= mEfiAcpiMaxNumTables
) {
1043 Status
= ReallocateAcpiTableBuffer (AcpiSupportInstance
);
1044 ASSERT_EFI_ERROR (Status
);
1046 CurrentRsdtEntry
= (UINT32
*)
1048 (UINT8
*) AcpiSupportInstance
->Rsdt1
+
1049 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
1050 AcpiSupportInstance
->NumberOfTableEntries1
*
1055 // Add entry to the RSDT unless its the FACS or DSDT
1057 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
1060 // Update RSDT length
1062 AcpiSupportInstance
->Rsdt1
->Length
= AcpiSupportInstance
->Rsdt1
->Length
+ sizeof (UINT32
);
1064 AcpiSupportInstance
->NumberOfTableEntries1
++;
1068 // Add to ACPI 2.0/3.0 table tree
1070 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 || (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1073 // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
1075 if (AcpiSupportInstance
->NumberOfTableEntries3
>= mEfiAcpiMaxNumTables
) {
1076 Status
= ReallocateAcpiTableBuffer (AcpiSupportInstance
);
1077 ASSERT_EFI_ERROR (Status
);
1080 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
1081 // If it becomes necessary to maintain separate table lists, changes will be required.
1083 CurrentRsdtEntry
= (UINT32
*)
1085 (UINT8
*) AcpiSupportInstance
->Rsdt3
+
1086 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
1087 AcpiSupportInstance
->NumberOfTableEntries3
*
1092 // This pointer must not be directly dereferenced as the XSDT entries may not
1093 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
1095 CurrentXsdtEntry
= (VOID
*)
1097 (UINT8
*) AcpiSupportInstance
->Xsdt
+
1098 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
1099 AcpiSupportInstance
->NumberOfTableEntries3
*
1104 // Add entry to the RSDT
1106 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
1109 // Update RSDT length
1111 AcpiSupportInstance
->Rsdt3
->Length
= AcpiSupportInstance
->Rsdt3
->Length
+ sizeof (UINT32
);
1114 // Add entry to XSDT, XSDT expects 64 bit pointers, but
1115 // the table pointers in XSDT are not aligned on 8 byte boundary.
1117 Buffer64
= (UINT64
) (UINTN
) CurrentTableList
->Table
;
1127 AcpiSupportInstance
->Xsdt
->Length
= AcpiSupportInstance
->Xsdt
->Length
+ sizeof (UINT64
);
1129 AcpiSupportInstance
->NumberOfTableEntries3
++;
1133 ChecksumCommonTables (AcpiSupportInstance
);
1137 This function finds the table specified by the handle and returns a pointer to it.
1138 If the handle is not found, EFI_NOT_FOUND is returned and the contents of Table are
1141 @param Handle Table to find.
1142 @param TableList Table list to search
1143 @param Table Pointer to table found.
1145 @return EFI_SUCCESS The function completed successfully.
1146 @return EFI_NOT_FOUND No table found matching the handle specified.
1152 IN LIST_ENTRY
*TableList
,
1153 OUT EFI_ACPI_TABLE_LIST
**Table
1156 LIST_ENTRY
*CurrentLink
;
1157 EFI_ACPI_TABLE_LIST
*CurrentTable
;
1160 // Check for invalid input parameters
1167 CurrentLink
= TableList
->ForwardLink
;
1169 while (CurrentLink
!= TableList
) {
1170 CurrentTable
= EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink
);
1171 if (CurrentTable
->Handle
== Handle
) {
1173 // Found handle, so return this table.
1175 *Table
= CurrentTable
;
1179 CurrentLink
= CurrentLink
->ForwardLink
;
1184 return EFI_NOT_FOUND
;
1187 This function removes a basic table from the RSDT and/or XSDT.
1188 For Acpi 1.0 tables, pass in the Rsdt.
1189 For Acpi 2.0 tables, pass in both Rsdt and Xsdt.
1191 @param Table Pointer to table found.
1192 @param NumberOfTableEntries Current number of table entries in the RSDT/XSDT
1193 @param Rsdt Pointer to the RSDT to remove from
1194 @param Xsdt Pointer to the Xsdt to remove from
1196 @return EFI_SUCCESS The function completed successfully.
1197 @return EFI_INVALID_PARAMETER The table was not found in both Rsdt and Xsdt.
1201 RemoveTableFromRsdt (
1202 IN OUT EFI_ACPI_TABLE_LIST
* Table
,
1203 IN OUT UINTN
*NumberOfTableEntries
,
1204 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Rsdt
,
1205 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Xsdt OPTIONAL
1208 UINT32
*CurrentRsdtEntry
;
1209 VOID
*CurrentXsdtEntry
;
1210 UINT64 CurrentTablePointer64
;
1214 // Check for invalid input parameters
1217 ASSERT (NumberOfTableEntries
);
1221 // Find the table entry in the RSDT and XSDT
1223 for (TempIndex
= 0; TempIndex
< *NumberOfTableEntries
; TempIndex
++) {
1225 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
1226 // If it becomes necessary to maintain separate table lists, changes will be required.
1228 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) Rsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + TempIndex
* sizeof (UINT32
));
1231 // This pointer must not be directly dereferenced as the XSDT entries may not
1232 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
1234 CurrentXsdtEntry
= (VOID
*) ((UINT8
*) Xsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + TempIndex
* sizeof (UINT64
));
1237 // Read the entry value out of the XSDT
1239 CopyMem (&CurrentTablePointer64
, CurrentXsdtEntry
, sizeof (UINT64
));
1242 // Initialize to NULL
1244 CurrentXsdtEntry
= 0;
1245 CurrentTablePointer64
= 0;
1248 // Check if we have found the corresponding entry in both RSDT and XSDT
1250 if (*CurrentRsdtEntry
== (UINT32
) (UINTN
) Table
->Table
&&
1251 ((Xsdt
== NULL
) || CurrentTablePointer64
== (UINT64
) (UINTN
) Table
->Table
)
1254 // Found entry, so copy all following entries and shrink table
1255 // We actually copy all + 1 to copy the initialized value of memory over
1258 CopyMem (CurrentRsdtEntry
, CurrentRsdtEntry
+ 1, (*NumberOfTableEntries
- TempIndex
) * sizeof (UINT32
));
1259 Rsdt
->Length
= Rsdt
->Length
- sizeof (UINT32
);
1261 CopyMem (CurrentXsdtEntry
, ((UINT64
*) CurrentXsdtEntry
) + 1, (*NumberOfTableEntries
- TempIndex
) * sizeof (UINT64
));
1262 Xsdt
->Length
= Xsdt
->Length
- sizeof (UINT64
);
1265 } else if (TempIndex
+ 1 == *NumberOfTableEntries
) {
1267 // At the last entry, and table not found
1269 return EFI_INVALID_PARAMETER
;
1273 // Checksum the tables
1275 AcpiPlatformChecksum (
1278 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1283 AcpiPlatformChecksum (
1286 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1291 // Decrement the number of tables
1293 (*NumberOfTableEntries
)--;
1298 This function removes a table and frees any associated memory.
1300 @param AcpiSupportInstance Instance of the protocol.
1301 @param Version Version(s) to delete.
1302 @param Table Pointer to table found.
1304 @return EFI_SUCCESS The function completed successfully.
1309 IN EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
,
1310 IN EFI_ACPI_TABLE_VERSION Version
,
1311 IN OUT EFI_ACPI_TABLE_LIST
*Table
1314 UINT32 CurrentTableSignature
;
1315 BOOLEAN RemoveFromRsdt
;
1318 // Check for invalid input parameters
1320 ASSERT (AcpiSupportInstance
);
1326 RemoveFromRsdt
= TRUE
;
1328 if (Table
->Table
!= NULL
) {
1329 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
->Table
)->Signature
;
1332 // Basic tasks to accomplish delete are:
1333 // Determine removal requirements (in RSDT/XSDT or not)
1334 // Remove entry from RSDT/XSDT
1335 // Remove any table references to the table
1336 // If no one is using the table
1337 // Free the table (removing pointers from private data and tables)
1339 // Free list structure
1342 // Determine if this table is in the RSDT or XSDT
1344 if ((CurrentTableSignature
== EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) ||
1345 (CurrentTableSignature
== EFI_ACPI_2_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
) ||
1346 (CurrentTableSignature
== EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
)
1348 RemoveFromRsdt
= FALSE
;
1351 // We don't remove the FADT in the standard way because some
1352 // OS expect the FADT to be early in the table list.
1353 // So we always put it as the first element in the list.
1355 if (CurrentTableSignature
== EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
) {
1356 RemoveFromRsdt
= FALSE
;
1360 // Remove the table from RSDT and XSDT
1364 // This is a basic table, remove it from any lists and the Rsdt and/or Xsdt
1366 if (Version
& EFI_ACPI_TABLE_VERSION_NONE
& Table
->Version
) {
1368 // Remove this version from the table
1370 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_NONE
;
1373 if (Version
& EFI_ACPI_TABLE_VERSION_1_0B
& Table
->Version
) {
1375 // Remove this version from the table
1377 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_1_0B
;
1380 // Remove from Rsdt. We don't care about the return value because it is
1381 // acceptable for the table to not exist in Rsdt.
1382 // We didn't add some tables so we don't remove them.
1384 if (RemoveFromRsdt
) {
1385 RemoveTableFromRsdt (
1387 &AcpiSupportInstance
->NumberOfTableEntries1
,
1388 AcpiSupportInstance
->Rsdt1
,
1394 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
& Table
->Version
) ||
1395 (Version
& EFI_ACPI_TABLE_VERSION_3_0
& Table
->Version
)) {
1397 // Remove this version from the table
1399 if (Version
& EFI_ACPI_TABLE_VERSION_2_0
& Table
->Version
) {
1400 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_2_0
;
1402 if (Version
& EFI_ACPI_TABLE_VERSION_3_0
& Table
->Version
) {
1403 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_3_0
;
1407 // Remove from Rsdt and Xsdt. We don't care about the return value
1408 // because it is acceptable for the table to not exist in Rsdt/Xsdt.
1409 // We didn't add some tables so we don't remove them.
1411 if (RemoveFromRsdt
) {
1412 RemoveTableFromRsdt (
1414 &AcpiSupportInstance
->NumberOfTableEntries3
,
1415 AcpiSupportInstance
->Rsdt3
,
1416 AcpiSupportInstance
->Xsdt
1421 // Free the table, clean up any dependent tables and our private data pointers.
1423 switch (Table
->Table
->Signature
) {
1425 case EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
1426 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1427 AcpiSupportInstance
->Fadt1
= NULL
;
1430 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
1431 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1432 AcpiSupportInstance
->Fadt3
= NULL
;
1436 case EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
1437 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1438 AcpiSupportInstance
->Facs1
= NULL
;
1441 // Update FADT table pointers
1443 if (AcpiSupportInstance
->Fadt1
!= NULL
) {
1444 AcpiSupportInstance
->Fadt1
->FirmwareCtrl
= 0;
1449 AcpiPlatformChecksum (
1450 AcpiSupportInstance
->Fadt1
,
1451 AcpiSupportInstance
->Fadt1
->Header
.Length
,
1452 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1458 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
1459 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1460 AcpiSupportInstance
->Facs3
= NULL
;
1463 // Update FADT table pointers
1465 if (AcpiSupportInstance
->Fadt3
!= NULL
) {
1466 AcpiSupportInstance
->Fadt3
->FirmwareCtrl
= 0;
1467 ZeroMem (&AcpiSupportInstance
->Fadt3
->XFirmwareCtrl
, sizeof (UINT64
));
1472 AcpiPlatformChecksum (
1473 AcpiSupportInstance
->Fadt3
,
1474 AcpiSupportInstance
->Fadt3
->Header
.Length
,
1475 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1482 case EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
1483 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1484 AcpiSupportInstance
->Dsdt1
= NULL
;
1487 // Update FADT table pointers
1489 if (AcpiSupportInstance
->Fadt1
!= NULL
) {
1490 AcpiSupportInstance
->Fadt1
->Dsdt
= 0;
1495 AcpiPlatformChecksum (
1496 AcpiSupportInstance
->Fadt1
,
1497 AcpiSupportInstance
->Fadt1
->Header
.Length
,
1498 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1505 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
1506 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1507 AcpiSupportInstance
->Dsdt3
= NULL
;
1510 // Update FADT table pointers
1512 if (AcpiSupportInstance
->Fadt3
!= NULL
) {
1513 AcpiSupportInstance
->Fadt3
->Dsdt
= 0;
1514 ZeroMem (&AcpiSupportInstance
->Fadt3
->XDsdt
, sizeof (UINT64
));
1519 AcpiPlatformChecksum (
1520 AcpiSupportInstance
->Fadt3
,
1521 AcpiSupportInstance
->Fadt3
->Header
.Length
,
1522 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1537 // If no version is using this table anymore, remove and free list entry.
1539 if (Table
->Version
== 0) {
1543 gBS
->FreePages (Table
->PageAddress
, Table
->NumberOfPages
);
1544 RemoveEntryList (&(Table
->Link
));
1545 gBS
->FreePool (Table
);
1553 This function finds and removes the table specified by the handle.
1555 @param AcpiSupportInstance Instance of the protocol.
1556 @param Version Bitmask of which versions to remove.
1557 @param Handle Table to remove.
1559 @return EFI_SUCCESS The function completed successfully.
1560 @return EFI_ABORTED An error occurred.
1561 @return EFI_NOT_FOUND Handle not found in table list.
1564 RemoveTableFromList (
1565 IN EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
,
1566 IN EFI_ACPI_TABLE_VERSION Version
,
1570 EFI_ACPI_TABLE_LIST
*Table
;
1576 // Check for invalid input parameters
1578 ASSERT (AcpiSupportInstance
);
1583 Status
= FindTableByHandle (
1585 &AcpiSupportInstance
->TableList
,
1588 if (EFI_ERROR (Status
)) {
1589 return EFI_NOT_FOUND
;
1594 Status
= DeleteTable (AcpiSupportInstance
, Version
, Table
);
1595 if (EFI_ERROR (Status
)) {
1599 // Completed successfully
1604 This function calculates and updates an UINT8 checksum.
1606 @param Buffer Pointer to buffer to checksum
1607 @param Size Number of bytes to checksum
1608 @param ChecksumOffset Offset to place the checksum result in
1610 @return EFI_SUCCESS The function completed successfully.
1614 AcpiPlatformChecksum (
1617 IN UINTN ChecksumOffset
1625 // Initialize pointer
1630 // set checksum to 0 first
1632 Ptr
[ChecksumOffset
] = 0;
1635 // add all content of buffer
1637 while ((Size
--) != 0) {
1638 Sum
= (UINT8
) (Sum
+ (*Ptr
++));
1644 Ptr
[ChecksumOffset
] = (UINT8
) (0xff - Sum
+ 1);
1649 Checksum all versions of the common tables, RSDP, RSDT, XSDT.
1651 @param AcpiSupportInstance Protocol instance private data.
1653 @return EFI_SUCCESS The function completed successfully.
1657 ChecksumCommonTables (
1658 IN OUT EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
1662 // RSDP ACPI 1.0 checksum for 1.0 table. This is only the first 20 bytes of the structure
1664 AcpiPlatformChecksum (
1665 AcpiSupportInstance
->Rsdp1
,
1666 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1667 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1672 // RSDP ACPI 1.0 checksum for 2.0/3.0 table. This is only the first 20 bytes of the structure
1674 AcpiPlatformChecksum (
1675 AcpiSupportInstance
->Rsdp3
,
1676 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1677 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1682 // RSDP ACPI 2.0/3.0 checksum, this is the entire table
1684 AcpiPlatformChecksum (
1685 AcpiSupportInstance
->Rsdp3
,
1686 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1687 OFFSET_OF (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1694 AcpiPlatformChecksum (
1695 AcpiSupportInstance
->Rsdt1
,
1696 AcpiSupportInstance
->Rsdt1
->Length
,
1697 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1701 AcpiPlatformChecksum (
1702 AcpiSupportInstance
->Rsdt3
,
1703 AcpiSupportInstance
->Rsdt3
->Length
,
1704 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1711 AcpiPlatformChecksum (
1712 AcpiSupportInstance
->Xsdt
,
1713 AcpiSupportInstance
->Xsdt
->Length
,
1714 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1721 Constructor for the ACPI support protocol to initializes instance data.
1723 @param AcpiSupportInstance Instance to construct
1725 @retval EFI_SUCCESS Instance initialized.
1726 @retval EFI_OUT_OF_RESOURCES Unable to allocate required resources.
1729 AcpiSupportAcpiSupportConstructor (
1730 IN EFI_ACPI_SUPPORT_INSTANCE
*AcpiSupportInstance
1736 UINTN RsdpTableSize
;
1738 EFI_PHYSICAL_ADDRESS PageAddress
;
1741 // Check for invalid input parameters
1743 ASSERT (AcpiSupportInstance
);
1745 InitializeListHead (&AcpiSupportInstance
->TableList
);
1746 AcpiSupportInstance
->CurrentHandle
= 1;
1747 AcpiSupportInstance
->AcpiSupport
.GetAcpiTable
= GetAcpiTable
;
1748 AcpiSupportInstance
->AcpiSupport
.SetAcpiTable
= SetAcpiTable
;
1749 AcpiSupportInstance
->AcpiSupport
.PublishTables
= PublishTables
;
1751 AcpiSupportInstance
->AcpiTableProtocol
.InstallAcpiTable
= InstallAcpiTable
;
1752 AcpiSupportInstance
->AcpiTableProtocol
.UninstallAcpiTable
= UninstallAcpiTable
;
1755 // Create RSDP table
1757 RsdpTableSize
= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
) +
1758 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1760 PageAddress
= 0xFFFFFFFF;
1761 Status
= gBS
->AllocatePages (
1763 EfiACPIReclaimMemory
,
1764 EFI_SIZE_TO_PAGES (RsdpTableSize
),
1768 if (EFI_ERROR (Status
)) {
1769 return EFI_OUT_OF_RESOURCES
;
1772 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
1773 ZeroMem (Pointer
, RsdpTableSize
);
1775 AcpiSupportInstance
->Rsdp1
= (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1776 Pointer
+= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1777 AcpiSupportInstance
->Rsdp3
= (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1780 // Create RSDT, XSDT structures
1782 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
1783 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
1784 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
1785 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
1786 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
1787 mEfiAcpiMaxNumTables
* sizeof (UINT64
);
1790 // Allocate memory in the lower 32 bit of address range for
1791 // compatibility with ACPI 1.0 OS.
1793 // This is done because ACPI 1.0 pointers are 32 bit values.
1794 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
1795 // There is no architectural reason these should be below 4GB, it is purely
1796 // for convenience of implementation that we force memory below 4GB.
1798 PageAddress
= 0xFFFFFFFF;
1799 Status
= gBS
->AllocatePages (
1801 EfiACPIReclaimMemory
,
1802 EFI_SIZE_TO_PAGES (TotalSize
),
1806 if (EFI_ERROR (Status
)) {
1807 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
)(UINTN
)AcpiSupportInstance
->Rsdp1
, EFI_SIZE_TO_PAGES (RsdpTableSize
));
1808 return EFI_OUT_OF_RESOURCES
;
1811 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
1812 ZeroMem (Pointer
, TotalSize
);
1814 AcpiSupportInstance
->Rsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1815 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1816 AcpiSupportInstance
->Rsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1817 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1818 AcpiSupportInstance
->Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1823 CurrentData
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1824 CopyMem (&AcpiSupportInstance
->Rsdp1
->Signature
, &CurrentData
, sizeof (UINT64
));
1825 CopyMem (AcpiSupportInstance
->Rsdp1
->OemId
, EFI_ACPI_OEM_ID
, 6);
1826 AcpiSupportInstance
->Rsdp1
->Reserved
= EFI_ACPI_RESERVED_BYTE
;
1827 AcpiSupportInstance
->Rsdp1
->RsdtAddress
= (UINT32
) (UINTN
) AcpiSupportInstance
->Rsdt1
;
1829 CurrentData
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1830 CopyMem (&AcpiSupportInstance
->Rsdp3
->Signature
, &CurrentData
, sizeof (UINT64
));
1831 CopyMem (AcpiSupportInstance
->Rsdp3
->OemId
, EFI_ACPI_OEM_ID
, 6);
1832 AcpiSupportInstance
->Rsdp3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION
;
1833 AcpiSupportInstance
->Rsdp3
->RsdtAddress
= (UINT32
) (UINTN
) AcpiSupportInstance
->Rsdt3
;
1834 AcpiSupportInstance
->Rsdp3
->Length
= sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1835 CurrentData
= (UINT64
) (UINTN
) AcpiSupportInstance
->Xsdt
;
1836 CopyMem (&AcpiSupportInstance
->Rsdp3
->XsdtAddress
, &CurrentData
, sizeof (UINT64
));
1837 SetMem (AcpiSupportInstance
->Rsdp3
->Reserved
, 3, EFI_ACPI_RESERVED_BYTE
);
1842 // Note that we "reserve" one entry for the FADT so it can always be
1843 // at the beginning of the list of tables. Some OS don't seem
1844 // to find it correctly if it is too far down the list.
1846 AcpiSupportInstance
->Rsdt1
->Signature
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1847 AcpiSupportInstance
->Rsdt1
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1848 AcpiSupportInstance
->Rsdt1
->Revision
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1849 CopyMem (AcpiSupportInstance
->Rsdt1
->OemId
, EFI_ACPI_OEM_ID
, 6);
1850 CurrentData
= EFI_ACPI_OEM_TABLE_ID
;
1851 CopyMem (&AcpiSupportInstance
->Rsdt1
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1852 AcpiSupportInstance
->Rsdt1
->OemRevision
= EFI_ACPI_OEM_REVISION
;
1853 AcpiSupportInstance
->Rsdt1
->CreatorId
= EFI_ACPI_CREATOR_ID
;
1854 AcpiSupportInstance
->Rsdt1
->CreatorRevision
= EFI_ACPI_CREATOR_REVISION
;
1856 // We always reserve first one for FADT
1858 AcpiSupportInstance
->NumberOfTableEntries1
= 1;
1859 AcpiSupportInstance
->Rsdt1
->Length
= AcpiSupportInstance
->Rsdt1
->Length
+ sizeof(UINT32
);
1861 AcpiSupportInstance
->Rsdt3
->Signature
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1862 AcpiSupportInstance
->Rsdt3
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1863 AcpiSupportInstance
->Rsdt3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1864 CopyMem (AcpiSupportInstance
->Rsdt3
->OemId
, EFI_ACPI_OEM_ID
, 6);
1865 CurrentData
= EFI_ACPI_OEM_TABLE_ID
;
1866 CopyMem (&AcpiSupportInstance
->Rsdt3
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1867 AcpiSupportInstance
->Rsdt3
->OemRevision
= EFI_ACPI_OEM_REVISION
;
1868 AcpiSupportInstance
->Rsdt3
->CreatorId
= EFI_ACPI_CREATOR_ID
;
1869 AcpiSupportInstance
->Rsdt3
->CreatorRevision
= EFI_ACPI_CREATOR_REVISION
;
1871 // We always reserve first one for FADT
1873 AcpiSupportInstance
->NumberOfTableEntries3
= 1;
1874 AcpiSupportInstance
->Rsdt3
->Length
= AcpiSupportInstance
->Rsdt3
->Length
+ sizeof(UINT32
);
1879 AcpiSupportInstance
->Xsdt
->Signature
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1880 AcpiSupportInstance
->Xsdt
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1881 AcpiSupportInstance
->Xsdt
->Revision
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1882 CopyMem (AcpiSupportInstance
->Xsdt
->OemId
, EFI_ACPI_OEM_ID
, 6);
1883 CurrentData
= EFI_ACPI_OEM_TABLE_ID
;
1884 CopyMem (&AcpiSupportInstance
->Xsdt
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1885 AcpiSupportInstance
->Xsdt
->OemRevision
= EFI_ACPI_OEM_REVISION
;
1886 AcpiSupportInstance
->Xsdt
->CreatorId
= EFI_ACPI_CREATOR_ID
;
1887 AcpiSupportInstance
->Xsdt
->CreatorRevision
= EFI_ACPI_CREATOR_REVISION
;
1889 // We always reserve first one for FADT
1891 AcpiSupportInstance
->Xsdt
->Length
= AcpiSupportInstance
->Xsdt
->Length
+ sizeof(UINT64
);
1893 ChecksumCommonTables (AcpiSupportInstance
);
1896 // Completed successfully