2 ACPI Table Protocol Implementation
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include "AcpiTable.h"
20 // The maximum number of tables that pre-allocated.
22 UINTN mEfiAcpiMaxNumTables
= EFI_ACPI_MAX_NUM_TABLES
;
25 This function adds an ACPI table to the table list. It will detect FACS and
26 allocate the correct type of memory and properly align the table.
28 @param AcpiTableInstance Instance of the protocol.
29 @param Table Table to add.
30 @param Checksum Does the table require checksumming.
31 @param Version The version of the list to add the table to.
32 @param Handle Pointer for returning the handle.
34 @return EFI_SUCCESS The function completed successfully.
35 @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
36 @return EFI_ABORTED The table is a duplicate of a table that is required
42 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
45 IN EFI_ACPI_TABLE_VERSION Version
,
50 This function finds and removes the table specified by the handle.
52 @param AcpiTableInstance Instance of the protocol.
53 @param Version Bitmask of which versions to remove.
54 @param Handle Table to remove.
56 @return EFI_SUCCESS The function completed successfully.
57 @return EFI_ABORTED An error occurred.
58 @return EFI_NOT_FOUND Handle not found in table list.
63 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
64 IN EFI_ACPI_TABLE_VERSION Version
,
69 This function calculates and updates an UINT8 checksum.
71 @param Buffer Pointer to buffer to checksum
72 @param Size Number of bytes to checksum
73 @param ChecksumOffset Offset to place the checksum result in
75 @return EFI_SUCCESS The function completed successfully.
78 AcpiPlatformChecksum (
81 IN UINTN ChecksumOffset
85 Checksum all versions of the common tables, RSDP, RSDT, XSDT.
87 @param AcpiTableInstance Protocol instance private data.
89 @return EFI_SUCCESS The function completed successfully.
93 ChecksumCommonTables (
94 IN OUT EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
98 // Protocol function implementations.
102 This function adds, removes, or updates ACPI tables. If the address is not
103 null and the handle value is null, the table is added. If both the address and
104 handle are not null, the table at handle is updated with the table at address.
105 If the address is null and the handle is not, the table at handle is deleted.
107 @param AcpiTableInstance Instance of the protocol.
108 @param Table Pointer to a table.
109 @param Checksum Boolean indicating if the checksum should be calculated.
110 @param Version Version(s) to set.
111 @param Handle Handle of the table.
113 @return EFI_SUCCESS The function completed successfully.
114 @return EFI_INVALID_PARAMETER Both the Table and *Handle were NULL.
115 @return EFI_ABORTED Could not complete the desired request.
121 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
122 IN VOID
*Table OPTIONAL
,
124 IN EFI_ACPI_TABLE_VERSION Version
,
132 // Check for invalid input parameters
140 // Determine desired action
145 // Invalid parameter combination
147 return EFI_INVALID_PARAMETER
;
152 Status
= AddTableToList (AcpiTableInstance
, Table
, Checksum
, Version
, Handle
);
160 // Delete the table list entry
162 Status
= RemoveTableFromList (AcpiTableInstance
, Version
, *Handle
);
163 if (EFI_ERROR (Status
)) {
165 // Should not get an error here ever, but abort if we do.
170 // Set the handle to replace the table at the same handle
172 SavedHandle
= AcpiTableInstance
->CurrentHandle
;
173 AcpiTableInstance
->CurrentHandle
= *Handle
;
178 Status
= AddTableToList (AcpiTableInstance
, Table
, Checksum
, Version
, Handle
);
181 // Restore the saved current handle
183 AcpiTableInstance
->CurrentHandle
= SavedHandle
;
188 Status
= RemoveTableFromList (AcpiTableInstance
, Version
, *Handle
);
192 if (EFI_ERROR (Status
)) {
194 // Should not get an error here ever, but abort if we do.
205 This function publishes the specified versions of the ACPI tables by
206 installing EFI configuration table entries for them. Any combination of
207 table versions can be published.
209 @param AcpiTableInstance Instance of the protocol.
210 @param Version Version(s) to publish.
212 @return EFI_SUCCESS The function completed successfully.
213 @return EFI_ABORTED The function could not complete successfully.
219 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
220 IN EFI_ACPI_TABLE_VERSION Version
224 UINT32
*CurrentRsdtEntry
;
225 VOID
*CurrentXsdtEntry
;
229 // Reorder tables as some operating systems don't seem to find the
230 // FADT correctly if it is not in the first few entries
234 // Add FADT as the first entry
236 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
237 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) AcpiTableInstance
->Rsdt1
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
238 *CurrentRsdtEntry
= (UINT32
) (UINTN
) AcpiTableInstance
->Fadt1
;
240 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
241 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
242 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) AcpiTableInstance
->Rsdt3
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
243 *CurrentRsdtEntry
= (UINT32
) (UINTN
) AcpiTableInstance
->Fadt3
;
244 CurrentXsdtEntry
= (VOID
*) ((UINT8
*) AcpiTableInstance
->Xsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
246 // Add entry to XSDT, XSDT expects 64 bit pointers, but
247 // the table pointers in XSDT are not aligned on 8 byte boundary.
249 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Fadt3
;
258 // Do checksum again because Dsdt/Xsdt is updated.
260 ChecksumCommonTables (AcpiTableInstance
);
263 // Add the RSD_PTR to the system table and store that we have installed the
266 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) &&
267 !AcpiTableInstance
->TablesInstalled1
) {
268 Status
= gBS
->InstallConfigurationTable (&gEfiAcpi10TableGuid
, AcpiTableInstance
->Rsdp1
);
269 if (EFI_ERROR (Status
)) {
273 AcpiTableInstance
->TablesInstalled1
= TRUE
;
276 if (((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
277 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) &&
278 !AcpiTableInstance
->TablesInstalled3
) {
279 Status
= gBS
->InstallConfigurationTable (&gEfiAcpiTableGuid
, AcpiTableInstance
->Rsdp3
);
280 if (EFI_ERROR (Status
)) {
284 AcpiTableInstance
->TablesInstalled3
= TRUE
;
292 Installs an ACPI table into the RSDT/XSDT.
293 Note that the ACPI table should be checksumed before installing it.
294 Otherwise it will assert.
296 @param This Protocol instance pointer.
297 @param AcpiTableBuffer A pointer to a buffer containing the ACPI table to be installed.
298 @param AcpiTableBufferSize Specifies the size, in bytes, of the AcpiTableBuffer buffer.
299 @param TableKey Reurns a key to refer to the ACPI table.
301 @return EFI_SUCCESS The table was successfully inserted.
302 @return EFI_INVALID_PARAMETER Either AcpiTableBuffer is NULL, TableKey is NULL, or AcpiTableBufferSize
303 and the size field embedded in the ACPI table pointed to by AcpiTableBuffer
305 @return EFI_OUT_OF_RESOURCES Insufficient resources exist to complete the request.
311 IN CONST EFI_ACPI_TABLE_PROTOCOL
*This
,
312 IN CONST VOID
*AcpiTableBuffer
,
313 IN UINTN AcpiTableBufferSize
,
317 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
;
319 VOID
*AcpiTableBufferConst
;
324 // Check for invalid input parameters
326 if ((AcpiTableBuffer
== NULL
) || (TableKey
== NULL
)
327 || (((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTableBuffer
)->Length
!= AcpiTableBufferSize
)) {
328 return EFI_INVALID_PARAMETER
;
331 Length
= ((EFI_ACPI_COMMON_HEADER
*) AcpiTableBuffer
)->Length
;
332 Checksum
= CalculateCheckSum8 ((UINT8
*)AcpiTableBuffer
, Length
);
333 ASSERT (Checksum
== 0);
336 // Get the instance of the ACPI table protocol
338 AcpiTableInstance
= EFI_ACPI_TABLE_INSTANCE_FROM_THIS (This
);
341 // Install the ACPI table
343 AcpiTableBufferConst
= AllocateCopyPool (AcpiTableBufferSize
,AcpiTableBuffer
);
345 Status
= SetAcpiTable (
347 AcpiTableBufferConst
,
349 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
,
352 if (!EFI_ERROR (Status
)) {
353 Status
= PublishTables (
355 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
358 FreePool (AcpiTableBufferConst
);
365 Removes an ACPI table from the RSDT/XSDT.
367 @param This Protocol instance pointer.
368 @param TableKey Specifies the table to uninstall. The key was returned from InstallAcpiTable().
370 @return EFI_SUCCESS The table was successfully uninstalled.
371 @return EFI_NOT_FOUND TableKey does not refer to a valid key for a table entry.
377 IN CONST EFI_ACPI_TABLE_PROTOCOL
*This
,
381 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
;
385 // Get the instance of the ACPI table protocol
387 AcpiTableInstance
= EFI_ACPI_TABLE_INSTANCE_FROM_THIS (This
);
390 // Uninstall the ACPI table
392 Status
= SetAcpiTable (
396 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
,
399 if (!EFI_ERROR (Status
)) {
400 Status
= PublishTables (
402 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
406 if (EFI_ERROR (Status
)) {
407 return EFI_NOT_FOUND
;
414 If the number of APCI tables exceeds the preallocated max table number, enlarge the table buffer.
416 @param AcpiTableInstance ACPI table protocol instance data structure.
418 @return EFI_SUCCESS reallocate the table beffer successfully.
419 @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
423 ReallocateAcpiTableBuffer (
424 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
427 UINTN NewMaxTableNumber
;
430 EFI_PHYSICAL_ADDRESS PageAddress
;
431 EFI_ACPI_TABLE_INSTANCE TempPrivateData
;
435 CopyMem (&TempPrivateData
, AcpiTableInstance
, sizeof (EFI_ACPI_TABLE_INSTANCE
));
437 // Enlarge the max table number from mEfiAcpiMaxNumTables to mEfiAcpiMaxNumTables + EFI_ACPI_MAX_NUM_TABLES
439 NewMaxTableNumber
= mEfiAcpiMaxNumTables
+ EFI_ACPI_MAX_NUM_TABLES
;
441 // Create RSDP, RSDT, XSDT structures and allocate all buffers
443 TotalSize
= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
) +
444 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
) +
445 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
446 NewMaxTableNumber
* sizeof (UINT32
) +
447 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
448 NewMaxTableNumber
* sizeof (UINT32
) +
449 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
450 NewMaxTableNumber
* sizeof (UINT64
);
453 // Allocate memory in the lower 32 bit of address range for
454 // compatibility with ACPI 1.0 OS.
456 // This is done because ACPI 1.0 pointers are 32 bit values.
457 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
458 // There is no architectural reason these should be below 4GB, it is purely
459 // for convenience of implementation that we force memory below 4GB.
461 PageAddress
= 0xFFFFFFFF;
462 Status
= gBS
->AllocatePages (
464 EfiACPIReclaimMemory
,
465 EFI_SIZE_TO_PAGES (TotalSize
),
469 if (EFI_ERROR (Status
)) {
470 return EFI_OUT_OF_RESOURCES
;
473 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
474 ZeroMem (Pointer
, TotalSize
);
476 AcpiTableInstance
->Rsdp1
= (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
477 Pointer
+= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
478 AcpiTableInstance
->Rsdp3
= (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
479 Pointer
+= sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
481 AcpiTableInstance
->Rsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
482 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + NewMaxTableNumber
* sizeof (UINT32
));
483 AcpiTableInstance
->Rsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
484 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + NewMaxTableNumber
* sizeof (UINT32
));
486 AcpiTableInstance
->Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
491 CopyMem (AcpiTableInstance
->Rsdp1
, TempPrivateData
.Rsdp1
, sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
));
492 AcpiTableInstance
->Rsdp1
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt1
;
494 CopyMem (AcpiTableInstance
->Rsdp3
, TempPrivateData
.Rsdp3
, sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
));
495 AcpiTableInstance
->Rsdp3
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt3
;
496 CurrentData
= (UINT64
) (UINTN
) AcpiTableInstance
->Xsdt
;
497 CopyMem (&AcpiTableInstance
->Rsdp3
->XsdtAddress
, &CurrentData
, sizeof (UINT64
));
500 // copy the original Rsdt1, Rsdt3 and Xsdt structure to new buffer
502 CopyMem (AcpiTableInstance
->Rsdt1
, TempPrivateData
.Rsdt1
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT32
)));
503 CopyMem (AcpiTableInstance
->Rsdt3
, TempPrivateData
.Rsdt3
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT32
)));
504 CopyMem (AcpiTableInstance
->Xsdt
, TempPrivateData
.Xsdt
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT64
)));
507 // Calculate orignal ACPI table buffer size
509 TotalSize
= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
) +
510 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
) +
511 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
512 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
513 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
514 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
515 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
516 mEfiAcpiMaxNumTables
* sizeof (UINT64
);
517 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
)(UINTN
)TempPrivateData
.Rsdp1
, EFI_SIZE_TO_PAGES (TotalSize
));
520 // Update the Max ACPI table number
522 mEfiAcpiMaxNumTables
= NewMaxTableNumber
;
526 This function adds an ACPI table to the table list. It will detect FACS and
527 allocate the correct type of memory and properly align the table.
529 @param AcpiTableInstance Instance of the protocol.
530 @param Table Table to add.
531 @param Checksum Does the table require checksumming.
532 @param Version The version of the list to add the table to.
533 @param Handle Pointer for returning the handle.
535 @return EFI_SUCCESS The function completed successfully.
536 @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
537 @return EFI_ABORTED The table is a duplicate of a table that is required
543 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
546 IN EFI_ACPI_TABLE_VERSION Version
,
551 EFI_ACPI_TABLE_LIST
*CurrentTableList
;
552 UINT32 CurrentTableSignature
;
553 UINT32 CurrentTableSize
;
554 UINT32
*CurrentRsdtEntry
;
555 VOID
*CurrentXsdtEntry
;
560 // Check for invalid input parameters
562 ASSERT (AcpiTableInstance
);
572 // Create a new list entry
574 CurrentTableList
= AllocatePool (sizeof (EFI_ACPI_TABLE_LIST
));
575 ASSERT (CurrentTableList
);
578 // Determine table type and size
580 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
)->Signature
;
581 CurrentTableSize
= ((EFI_ACPI_COMMON_HEADER
*) Table
)->Length
;
584 // Allocate a buffer for the table. All tables are allocated in the lower 32 bits of address space
585 // for backwards compatibility with ACPI 1.0 OS.
587 // This is done because ACPI 1.0 pointers are 32 bit values.
588 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
589 // There is no architectural reason these should be below 4GB, it is purely
590 // for convenience of implementation that we force memory below 4GB.
592 CurrentTableList
->PageAddress
= 0xFFFFFFFF;
593 CurrentTableList
->NumberOfPages
= EFI_SIZE_TO_PAGES (CurrentTableSize
);
596 // Allocation memory type depends on the type of the table
598 if (CurrentTableSignature
== EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
||
599 CurrentTableSignature
== EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) {
601 // Allocate memory for the FACS. This structure must be aligned
602 // on a 64 byte boundary and must be ACPI NVS memory.
603 // Using AllocatePages should ensure that it is always aligned.
605 ASSERT ((EFI_PAGE_SIZE
% 64) == 0);
606 Status
= gBS
->AllocatePages (
609 CurrentTableList
->NumberOfPages
,
610 &CurrentTableList
->PageAddress
614 // All other tables are ACPI reclaim memory, no alignment requirements.
616 Status
= gBS
->AllocatePages (
618 EfiACPIReclaimMemory
,
619 CurrentTableList
->NumberOfPages
,
620 &CurrentTableList
->PageAddress
624 // Check return value from memory alloc.
626 if (EFI_ERROR (Status
)) {
627 gBS
->FreePool (CurrentTableList
);
628 return EFI_OUT_OF_RESOURCES
;
631 // Update the table pointer with the allocated memory start
633 CurrentTableList
->Table
= (EFI_ACPI_COMMON_HEADER
*) (UINTN
) CurrentTableList
->PageAddress
;
636 // Initialize the table contents
638 CurrentTableList
->Signature
= EFI_ACPI_TABLE_LIST_SIGNATURE
;
639 CopyMem (CurrentTableList
->Table
, Table
, CurrentTableSize
);
640 CurrentTableList
->Handle
= AcpiTableInstance
->CurrentHandle
++;
641 *Handle
= CurrentTableList
->Handle
;
642 CurrentTableList
->Version
= Version
;
645 // Update internal pointers if this is a required table. If it is a required
646 // table and a table of that type already exists, return an error.
648 // Calculate the checksum if the table is not FACS.
650 switch (CurrentTableSignature
) {
652 case EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
654 // We don't add the FADT in the standard way because some
655 // OS expect the FADT to be early in the table list.
656 // So we always add it as the first element in the list.
661 // Check that the table has not been previously added.
663 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Fadt1
!= NULL
) ||
664 ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 && AcpiTableInstance
->Fadt3
!= NULL
) ||
665 ((Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0 && AcpiTableInstance
->Fadt3
!= NULL
)
667 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
668 gBS
->FreePool (CurrentTableList
);
672 // Add the table to the appropriate table version
674 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
676 // Save a pointer to the table
678 AcpiTableInstance
->Fadt1
= (EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE
*) CurrentTableList
->Table
;
681 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
683 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs1
;
684 AcpiTableInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt1
;
687 // RSDP OEM information is updated to match the FADT OEM information
690 &AcpiTableInstance
->Rsdp1
->OemId
,
691 &AcpiTableInstance
->Fadt1
->Header
.OemId
,
696 // RSDT OEM information is updated to match the FADT OEM information.
699 &AcpiTableInstance
->Rsdt1
->OemId
,
700 &AcpiTableInstance
->Fadt1
->Header
.OemId
,
705 &AcpiTableInstance
->Rsdt1
->OemTableId
,
706 &AcpiTableInstance
->Fadt1
->Header
.OemTableId
,
709 AcpiTableInstance
->Rsdt1
->OemRevision
= AcpiTableInstance
->Fadt1
->Header
.OemRevision
;
712 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
713 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
715 // Save a pointer to the table
717 AcpiTableInstance
->Fadt3
= (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE
*) CurrentTableList
->Table
;
720 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
722 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs3
;
723 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Facs3
;
725 &AcpiTableInstance
->Fadt3
->XFirmwareCtrl
,
729 AcpiTableInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt3
;
730 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Dsdt3
;
732 &AcpiTableInstance
->Fadt3
->XDsdt
,
738 // RSDP OEM information is updated to match the FADT OEM information
741 &AcpiTableInstance
->Rsdp3
->OemId
,
742 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
747 // RSDT OEM information is updated to match FADT OEM information.
750 &AcpiTableInstance
->Rsdt3
->OemId
,
751 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
755 &AcpiTableInstance
->Rsdt3
->OemTableId
,
756 &AcpiTableInstance
->Fadt3
->Header
.OemTableId
,
759 AcpiTableInstance
->Rsdt3
->OemRevision
= AcpiTableInstance
->Fadt3
->Header
.OemRevision
;
762 // XSDT OEM information is updated to match FADT OEM information.
765 &AcpiTableInstance
->Xsdt
->OemId
,
766 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
770 &AcpiTableInstance
->Xsdt
->OemTableId
,
771 &AcpiTableInstance
->Fadt3
->Header
.OemTableId
,
774 AcpiTableInstance
->Xsdt
->OemRevision
= AcpiTableInstance
->Fadt3
->Header
.OemRevision
;
777 // Checksum the table
780 AcpiPlatformChecksum (
781 CurrentTableList
->Table
,
782 CurrentTableList
->Table
->Length
,
783 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
789 case EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
791 // Check that the table has not been previously added.
793 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Facs1
!= NULL
) ||
794 ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 && AcpiTableInstance
->Facs3
!= NULL
) ||
795 ((Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0 && AcpiTableInstance
->Facs3
!= NULL
)
797 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
798 gBS
->FreePool (CurrentTableList
);
802 // FACS is referenced by FADT and is not part of RSDT
807 // Add the table to the appropriate table version
809 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
811 // Save a pointer to the table
813 AcpiTableInstance
->Facs1
= (EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
816 // If FADT already exists, update table pointers.
818 if (AcpiTableInstance
->Fadt1
!= NULL
) {
819 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs1
;
822 // Checksum FADT table
824 AcpiPlatformChecksum (
825 AcpiTableInstance
->Fadt1
,
826 AcpiTableInstance
->Fadt1
->Header
.Length
,
827 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
833 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
834 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
836 // Save a pointer to the table
838 AcpiTableInstance
->Facs3
= (EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
841 // If FADT already exists, update table pointers.
843 if (AcpiTableInstance
->Fadt3
!= NULL
) {
844 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs3
;
845 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Facs3
;
847 &AcpiTableInstance
->Fadt3
->XFirmwareCtrl
,
853 // Checksum FADT table
855 AcpiPlatformChecksum (
856 AcpiTableInstance
->Fadt3
,
857 AcpiTableInstance
->Fadt3
->Header
.Length
,
858 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
866 case EFI_ACPI_1_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
868 // Check that the table has not been previously added.
870 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Dsdt1
!= NULL
) ||
871 ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 && AcpiTableInstance
->Dsdt3
!= NULL
) ||
872 ((Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0 && AcpiTableInstance
->Dsdt3
!= NULL
)
874 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
875 gBS
->FreePool (CurrentTableList
);
879 // DSDT is referenced by FADT and is not part of RSDT
884 // Add the table to the appropriate table version
886 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
888 // Save a pointer to the table
890 AcpiTableInstance
->Dsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
893 // If FADT already exists, update table pointers.
895 if (AcpiTableInstance
->Fadt1
!= NULL
) {
896 AcpiTableInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt1
;
899 // Checksum FADT table
901 AcpiPlatformChecksum (
902 AcpiTableInstance
->Fadt1
,
903 AcpiTableInstance
->Fadt1
->Header
.Length
,
904 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
910 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
911 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
913 // Save a pointer to the table
915 AcpiTableInstance
->Dsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
918 // If FADT already exists, update table pointers.
920 if (AcpiTableInstance
->Fadt3
!= NULL
) {
921 AcpiTableInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt3
;
922 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Dsdt3
;
924 &AcpiTableInstance
->Fadt3
->XDsdt
,
930 // Checksum FADT table
932 AcpiPlatformChecksum (
933 AcpiTableInstance
->Fadt3
,
934 AcpiTableInstance
->Fadt3
->Header
.Length
,
935 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
941 // Checksum the table
944 AcpiPlatformChecksum (
945 CurrentTableList
->Table
,
946 CurrentTableList
->Table
->Length
,
947 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
955 // Checksum the table
958 AcpiPlatformChecksum (
959 CurrentTableList
->Table
,
960 CurrentTableList
->Table
->Length
,
961 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
968 // Add the table to the current list of tables
970 InsertTailList (&AcpiTableInstance
->TableList
, &CurrentTableList
->Link
);
973 // Add the table to RSDT and/or XSDT table entry lists.
976 // Add to ACPI 1.0b table tree
978 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
981 // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
983 if (AcpiTableInstance
->NumberOfTableEntries1
>= mEfiAcpiMaxNumTables
) {
984 Status
= ReallocateAcpiTableBuffer (AcpiTableInstance
);
985 ASSERT_EFI_ERROR (Status
);
987 CurrentRsdtEntry
= (UINT32
*)
989 (UINT8
*) AcpiTableInstance
->Rsdt1
+
990 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
991 AcpiTableInstance
->NumberOfTableEntries1
*
996 // Add entry to the RSDT unless its the FACS or DSDT
998 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
1001 // Update RSDT length
1003 AcpiTableInstance
->Rsdt1
->Length
= AcpiTableInstance
->Rsdt1
->Length
+ sizeof (UINT32
);
1005 AcpiTableInstance
->NumberOfTableEntries1
++;
1009 // Add to ACPI 2.0/3.0 table tree
1011 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
1012 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1015 // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
1017 if (AcpiTableInstance
->NumberOfTableEntries3
>= mEfiAcpiMaxNumTables
) {
1018 Status
= ReallocateAcpiTableBuffer (AcpiTableInstance
);
1019 ASSERT_EFI_ERROR (Status
);
1022 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
1023 // If it becomes necessary to maintain separate table lists, changes will be required.
1025 CurrentRsdtEntry
= (UINT32
*)
1027 (UINT8
*) AcpiTableInstance
->Rsdt3
+
1028 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
1029 AcpiTableInstance
->NumberOfTableEntries3
*
1034 // This pointer must not be directly dereferenced as the XSDT entries may not
1035 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
1037 CurrentXsdtEntry
= (VOID
*)
1039 (UINT8
*) AcpiTableInstance
->Xsdt
+
1040 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
1041 AcpiTableInstance
->NumberOfTableEntries3
*
1046 // Add entry to the RSDT
1048 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
1051 // Update RSDT length
1053 AcpiTableInstance
->Rsdt3
->Length
= AcpiTableInstance
->Rsdt3
->Length
+ sizeof (UINT32
);
1056 // Add entry to XSDT, XSDT expects 64 bit pointers, but
1057 // the table pointers in XSDT are not aligned on 8 byte boundary.
1059 Buffer64
= (UINT64
) (UINTN
) CurrentTableList
->Table
;
1069 AcpiTableInstance
->Xsdt
->Length
= AcpiTableInstance
->Xsdt
->Length
+ sizeof (UINT64
);
1071 AcpiTableInstance
->NumberOfTableEntries3
++;
1075 ChecksumCommonTables (AcpiTableInstance
);
1081 This function finds the table specified by the handle and returns a pointer to it.
1082 If the handle is not found, EFI_NOT_FOUND is returned and the contents of Table are
1085 @param Handle Table to find.
1086 @param TableList Table list to search
1087 @param Table Pointer to table found.
1089 @return EFI_SUCCESS The function completed successfully.
1090 @return EFI_NOT_FOUND No table found matching the handle specified.
1096 IN LIST_ENTRY
*TableList
,
1097 OUT EFI_ACPI_TABLE_LIST
**Table
1100 LIST_ENTRY
*CurrentLink
;
1101 EFI_ACPI_TABLE_LIST
*CurrentTable
;
1104 // Check for invalid input parameters
1111 CurrentLink
= TableList
->ForwardLink
;
1113 while (CurrentLink
!= TableList
) {
1114 CurrentTable
= EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink
);
1115 if (CurrentTable
->Handle
== Handle
) {
1117 // Found handle, so return this table.
1119 *Table
= CurrentTable
;
1123 CurrentLink
= CurrentLink
->ForwardLink
;
1128 return EFI_NOT_FOUND
;
1133 This function removes a basic table from the RSDT and/or XSDT.
1134 For Acpi 1.0 tables, pass in the Rsdt.
1135 For Acpi 2.0 tables, pass in both Rsdt and Xsdt.
1137 @param Table Pointer to table found.
1138 @param NumberOfTableEntries Current number of table entries in the RSDT/XSDT
1139 @param Rsdt Pointer to the RSDT to remove from
1140 @param Xsdt Pointer to the Xsdt to remove from
1142 @return EFI_SUCCESS The function completed successfully.
1143 @return EFI_INVALID_PARAMETER The table was not found in both Rsdt and Xsdt.
1147 RemoveTableFromRsdt (
1148 IN OUT EFI_ACPI_TABLE_LIST
* Table
,
1149 IN OUT UINTN
*NumberOfTableEntries
,
1150 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Rsdt
,
1151 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Xsdt OPTIONAL
1154 UINT32
*CurrentRsdtEntry
;
1155 VOID
*CurrentXsdtEntry
;
1156 UINT64 CurrentTablePointer64
;
1160 // Check for invalid input parameters
1163 ASSERT (NumberOfTableEntries
);
1167 // Find the table entry in the RSDT and XSDT
1169 for (Index
= 0; Index
< *NumberOfTableEntries
; Index
++) {
1171 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
1172 // If it becomes necessary to maintain separate table lists, changes will be required.
1174 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) Rsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + Index
* sizeof (UINT32
));
1177 // This pointer must not be directly dereferenced as the XSDT entries may not
1178 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
1180 CurrentXsdtEntry
= (VOID
*) ((UINT8
*) Xsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + Index
* sizeof (UINT64
));
1183 // Read the entry value out of the XSDT
1185 CopyMem (&CurrentTablePointer64
, CurrentXsdtEntry
, sizeof (UINT64
));
1188 // Initialize to NULL
1190 CurrentXsdtEntry
= 0;
1191 CurrentTablePointer64
= 0;
1194 // Check if we have found the corresponding entry in both RSDT and XSDT
1196 if (*CurrentRsdtEntry
== (UINT32
) (UINTN
) Table
->Table
&&
1197 ((Xsdt
== NULL
) || CurrentTablePointer64
== (UINT64
) (UINTN
) Table
->Table
)
1200 // Found entry, so copy all following entries and shrink table
1201 // We actually copy all + 1 to copy the initialized value of memory over
1204 CopyMem (CurrentRsdtEntry
, CurrentRsdtEntry
+ 1, (*NumberOfTableEntries
- Index
) * sizeof (UINT32
));
1205 Rsdt
->Length
= Rsdt
->Length
- sizeof (UINT32
);
1207 CopyMem (CurrentXsdtEntry
, ((UINT64
*) CurrentXsdtEntry
) + 1, (*NumberOfTableEntries
- Index
) * sizeof (UINT64
));
1208 Xsdt
->Length
= Xsdt
->Length
- sizeof (UINT64
);
1211 } else if (Index
+ 1 == *NumberOfTableEntries
) {
1213 // At the last entry, and table not found
1215 return EFI_INVALID_PARAMETER
;
1219 // Checksum the tables
1221 AcpiPlatformChecksum (
1224 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1229 AcpiPlatformChecksum (
1232 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1237 // Decrement the number of tables
1239 (*NumberOfTableEntries
)--;
1246 This function removes a table and frees any associated memory.
1248 @param AcpiTableInstance Instance of the protocol.
1249 @param Version Version(s) to delete.
1250 @param Table Pointer to table found.
1252 @return EFI_SUCCESS The function completed successfully.
1257 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
1258 IN EFI_ACPI_TABLE_VERSION Version
,
1259 IN OUT EFI_ACPI_TABLE_LIST
*Table
1262 UINT32 CurrentTableSignature
;
1263 BOOLEAN RemoveFromRsdt
;
1266 // Check for invalid input parameters
1268 ASSERT (AcpiTableInstance
);
1274 RemoveFromRsdt
= TRUE
;
1276 // Check for Table->Table
1278 ASSERT (Table
->Table
!= NULL
);
1279 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
->Table
)->Signature
;
1282 // Basic tasks to accomplish delete are:
1283 // Determine removal requirements (in RSDT/XSDT or not)
1284 // Remove entry from RSDT/XSDT
1285 // Remove any table references to the table
1286 // If no one is using the table
1287 // Free the table (removing pointers from private data and tables)
1289 // Free list structure
1292 // Determine if this table is in the RSDT or XSDT
1294 if ((CurrentTableSignature
== EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) ||
1295 (CurrentTableSignature
== EFI_ACPI_2_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
) ||
1296 (CurrentTableSignature
== EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
)
1298 RemoveFromRsdt
= FALSE
;
1301 // We don't remove the FADT in the standard way because some
1302 // OS expect the FADT to be early in the table list.
1303 // So we always put it as the first element in the list.
1305 if (CurrentTableSignature
== EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
) {
1306 RemoveFromRsdt
= FALSE
;
1310 // Remove the table from RSDT and XSDT
1312 if (Table
->Table
!= NULL
) {
1314 // This is a basic table, remove it from any lists and the Rsdt and/or Xsdt
1316 if (Version
& EFI_ACPI_TABLE_VERSION_NONE
& Table
->Version
) {
1318 // Remove this version from the table
1320 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_NONE
;
1323 if (Version
& EFI_ACPI_TABLE_VERSION_1_0B
& Table
->Version
) {
1325 // Remove this version from the table
1327 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_1_0B
;
1330 // Remove from Rsdt. We don't care about the return value because it is
1331 // acceptable for the table to not exist in Rsdt.
1332 // We didn't add some tables so we don't remove them.
1334 if (RemoveFromRsdt
) {
1335 RemoveTableFromRsdt (
1337 &AcpiTableInstance
->NumberOfTableEntries1
,
1338 AcpiTableInstance
->Rsdt1
,
1344 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
& Table
->Version
) ||
1345 (Version
& EFI_ACPI_TABLE_VERSION_3_0
& Table
->Version
)) {
1347 // Remove this version from the table
1349 if (Version
& EFI_ACPI_TABLE_VERSION_2_0
& Table
->Version
) {
1350 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_2_0
;
1352 if (Version
& EFI_ACPI_TABLE_VERSION_3_0
& Table
->Version
) {
1353 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_3_0
;
1357 // Remove from Rsdt and Xsdt. We don't care about the return value
1358 // because it is acceptable for the table to not exist in Rsdt/Xsdt.
1359 // We didn't add some tables so we don't remove them.
1361 if (RemoveFromRsdt
) {
1362 RemoveTableFromRsdt (
1364 &AcpiTableInstance
->NumberOfTableEntries3
,
1365 AcpiTableInstance
->Rsdt3
,
1366 AcpiTableInstance
->Xsdt
1371 // Free the table, clean up any dependent tables and our private data pointers.
1373 switch (Table
->Table
->Signature
) {
1375 case EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
1376 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1377 AcpiTableInstance
->Fadt1
= NULL
;
1380 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
1381 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1382 AcpiTableInstance
->Fadt3
= NULL
;
1386 case EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
1387 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1388 AcpiTableInstance
->Facs1
= NULL
;
1391 // Update FADT table pointers
1393 if (AcpiTableInstance
->Fadt1
!= NULL
) {
1394 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= 0;
1399 AcpiPlatformChecksum (
1400 AcpiTableInstance
->Fadt1
,
1401 AcpiTableInstance
->Fadt1
->Header
.Length
,
1402 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1408 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
1409 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1410 AcpiTableInstance
->Facs3
= NULL
;
1413 // Update FADT table pointers
1415 if (AcpiTableInstance
->Fadt3
!= NULL
) {
1416 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= 0;
1417 ZeroMem (&AcpiTableInstance
->Fadt3
->XFirmwareCtrl
, sizeof (UINT64
));
1422 AcpiPlatformChecksum (
1423 AcpiTableInstance
->Fadt3
,
1424 AcpiTableInstance
->Fadt3
->Header
.Length
,
1425 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1432 case EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
1433 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1434 AcpiTableInstance
->Dsdt1
= NULL
;
1437 // Update FADT table pointers
1439 if (AcpiTableInstance
->Fadt1
!= NULL
) {
1440 AcpiTableInstance
->Fadt1
->Dsdt
= 0;
1445 AcpiPlatformChecksum (
1446 AcpiTableInstance
->Fadt1
,
1447 AcpiTableInstance
->Fadt1
->Header
.Length
,
1448 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1455 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
1456 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1457 AcpiTableInstance
->Dsdt3
= NULL
;
1460 // Update FADT table pointers
1462 if (AcpiTableInstance
->Fadt3
!= NULL
) {
1463 AcpiTableInstance
->Fadt3
->Dsdt
= 0;
1464 ZeroMem (&AcpiTableInstance
->Fadt3
->XDsdt
, sizeof (UINT64
));
1469 AcpiPlatformChecksum (
1470 AcpiTableInstance
->Fadt3
,
1471 AcpiTableInstance
->Fadt3
->Header
.Length
,
1472 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1487 // If no version is using this table anymore, remove and free list entry.
1489 if (Table
->Version
== 0) {
1493 gBS
->FreePages (Table
->PageAddress
, Table
->NumberOfPages
);
1494 RemoveEntryList (&(Table
->Link
));
1495 gBS
->FreePool (Table
);
1505 This function finds and removes the table specified by the handle.
1507 @param AcpiTableInstance Instance of the protocol.
1508 @param Version Bitmask of which versions to remove.
1509 @param Handle Table to remove.
1511 @return EFI_SUCCESS The function completed successfully.
1512 @return EFI_ABORTED An error occurred.
1513 @return EFI_NOT_FOUND Handle not found in table list.
1517 RemoveTableFromList (
1518 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
1519 IN EFI_ACPI_TABLE_VERSION Version
,
1523 EFI_ACPI_TABLE_LIST
*Table
;
1526 Table
= (EFI_ACPI_TABLE_LIST
*) NULL
;
1529 // Check for invalid input parameters
1531 ASSERT (AcpiTableInstance
);
1536 Status
= FindTableByHandle (
1538 &AcpiTableInstance
->TableList
,
1541 if (EFI_ERROR (Status
)) {
1542 return EFI_NOT_FOUND
;
1547 Status
= DeleteTable (AcpiTableInstance
, Version
, Table
);
1548 if (EFI_ERROR (Status
)) {
1552 // Completed successfully
1559 This function calculates and updates an UINT8 checksum.
1561 @param Buffer Pointer to buffer to checksum
1562 @param Size Number of bytes to checksum
1563 @param ChecksumOffset Offset to place the checksum result in
1565 @return EFI_SUCCESS The function completed successfully.
1569 AcpiPlatformChecksum (
1572 IN UINTN ChecksumOffset
1580 // Initialize pointer
1585 // set checksum to 0 first
1587 Ptr
[ChecksumOffset
] = 0;
1590 // add all content of buffer
1592 while ((Size
--) != 0) {
1593 Sum
= (UINT8
) (Sum
+ (*Ptr
++));
1599 Ptr
[ChecksumOffset
] = (UINT8
) (0xff - Sum
+ 1);
1606 Checksum all versions of the common tables, RSDP, RSDT, XSDT.
1608 @param AcpiTableInstance Protocol instance private data.
1610 @return EFI_SUCCESS The function completed successfully.
1614 ChecksumCommonTables (
1615 IN OUT EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
1619 // RSDP ACPI 1.0 checksum for 1.0 table. This is only the first 20 bytes of the structure
1621 AcpiPlatformChecksum (
1622 AcpiTableInstance
->Rsdp1
,
1623 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1624 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1629 // RSDP ACPI 1.0 checksum for 2.0/3.0 table. This is only the first 20 bytes of the structure
1631 AcpiPlatformChecksum (
1632 AcpiTableInstance
->Rsdp3
,
1633 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1634 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1639 // RSDP ACPI 2.0/3.0 checksum, this is the entire table
1641 AcpiPlatformChecksum (
1642 AcpiTableInstance
->Rsdp3
,
1643 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1644 OFFSET_OF (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1651 AcpiPlatformChecksum (
1652 AcpiTableInstance
->Rsdt1
,
1653 AcpiTableInstance
->Rsdt1
->Length
,
1654 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1658 AcpiPlatformChecksum (
1659 AcpiTableInstance
->Rsdt3
,
1660 AcpiTableInstance
->Rsdt3
->Length
,
1661 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1668 AcpiPlatformChecksum (
1669 AcpiTableInstance
->Xsdt
,
1670 AcpiTableInstance
->Xsdt
->Length
,
1671 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1680 Constructor for the ACPI table protocol. Initializes instance
1683 @param AcpiTableInstance Instance to construct
1685 @return EFI_SUCCESS Instance initialized.
1686 @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
1690 AcpiTableAcpiTableConstructor (
1691 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
1698 EFI_PHYSICAL_ADDRESS PageAddress
;
1701 // Check for invalid input parameters
1703 ASSERT (AcpiTableInstance
);
1705 InitializeListHead (&AcpiTableInstance
->TableList
);
1706 AcpiTableInstance
->CurrentHandle
= 1;
1708 AcpiTableInstance
->AcpiTableProtocol
.InstallAcpiTable
= InstallAcpiTable
;
1709 AcpiTableInstance
->AcpiTableProtocol
.UninstallAcpiTable
= UninstallAcpiTable
;
1711 // Create RSDP, RSDT, XSDT structures
1712 // Allocate all buffers
1714 TotalSize
= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
) +
1715 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
) +
1716 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
1717 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
1718 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
1719 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
1720 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
1721 mEfiAcpiMaxNumTables
* sizeof (UINT64
);
1724 // Allocate memory in the lower 32 bit of address range for
1725 // compatibility with ACPI 1.0 OS.
1727 // This is done because ACPI 1.0 pointers are 32 bit values.
1728 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
1729 // There is no architectural reason these should be below 4GB, it is purely
1730 // for convenience of implementation that we force memory below 4GB.
1732 PageAddress
= 0xFFFFFFFF;
1733 Status
= gBS
->AllocatePages (
1735 EfiACPIReclaimMemory
,
1736 EFI_SIZE_TO_PAGES (TotalSize
),
1740 if (EFI_ERROR (Status
)) {
1741 return EFI_OUT_OF_RESOURCES
;
1744 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
1745 ZeroMem (Pointer
, TotalSize
);
1747 AcpiTableInstance
->Rsdp1
= (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1748 Pointer
+= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1749 AcpiTableInstance
->Rsdp3
= (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1750 Pointer
+= sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1752 AcpiTableInstance
->Rsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1753 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1754 AcpiTableInstance
->Rsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1755 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1757 AcpiTableInstance
->Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1762 CurrentData
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1763 CopyMem (&AcpiTableInstance
->Rsdp1
->Signature
, &CurrentData
, sizeof (UINT64
));
1764 CopyMem (AcpiTableInstance
->Rsdp1
->OemId
, EFI_ACPI_OEM_ID
, 6);
1765 AcpiTableInstance
->Rsdp1
->Reserved
= EFI_ACPI_RESERVED_BYTE
;
1766 AcpiTableInstance
->Rsdp1
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt1
;
1768 CurrentData
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1769 CopyMem (&AcpiTableInstance
->Rsdp3
->Signature
, &CurrentData
, sizeof (UINT64
));
1770 CopyMem (AcpiTableInstance
->Rsdp3
->OemId
, EFI_ACPI_OEM_ID
, 6);
1771 AcpiTableInstance
->Rsdp3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION
;
1772 AcpiTableInstance
->Rsdp3
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt3
;
1773 AcpiTableInstance
->Rsdp3
->Length
= sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1774 CurrentData
= (UINT64
) (UINTN
) AcpiTableInstance
->Xsdt
;
1775 CopyMem (&AcpiTableInstance
->Rsdp3
->XsdtAddress
, &CurrentData
, sizeof (UINT64
));
1776 SetMem (AcpiTableInstance
->Rsdp3
->Reserved
, 3, EFI_ACPI_RESERVED_BYTE
);
1781 // Note that we "reserve" one entry for the FADT so it can always be
1782 // at the beginning of the list of tables. Some OS don't seem
1783 // to find it correctly if it is too far down the list.
1785 AcpiTableInstance
->Rsdt1
->Signature
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1786 AcpiTableInstance
->Rsdt1
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1787 AcpiTableInstance
->Rsdt1
->Revision
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1788 CopyMem (AcpiTableInstance
->Rsdt1
->OemId
, EFI_ACPI_OEM_ID
, 6);
1789 CurrentData
= EFI_ACPI_OEM_TABLE_ID
;
1790 CopyMem (&AcpiTableInstance
->Rsdt1
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1791 AcpiTableInstance
->Rsdt1
->OemRevision
= EFI_ACPI_OEM_REVISION
;
1792 AcpiTableInstance
->Rsdt1
->CreatorId
= EFI_ACPI_CREATOR_ID
;
1793 AcpiTableInstance
->Rsdt1
->CreatorRevision
= EFI_ACPI_CREATOR_REVISION
;
1795 // We always reserve first one for FADT
1797 AcpiTableInstance
->NumberOfTableEntries1
= 1;
1798 AcpiTableInstance
->Rsdt1
->Length
= AcpiTableInstance
->Rsdt1
->Length
+ sizeof(UINT32
);
1800 AcpiTableInstance
->Rsdt3
->Signature
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1801 AcpiTableInstance
->Rsdt3
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1802 AcpiTableInstance
->Rsdt3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1803 CopyMem (AcpiTableInstance
->Rsdt3
->OemId
, EFI_ACPI_OEM_ID
, 6);
1804 CurrentData
= EFI_ACPI_OEM_TABLE_ID
;
1805 CopyMem (&AcpiTableInstance
->Rsdt3
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1806 AcpiTableInstance
->Rsdt3
->OemRevision
= EFI_ACPI_OEM_REVISION
;
1807 AcpiTableInstance
->Rsdt3
->CreatorId
= EFI_ACPI_CREATOR_ID
;
1808 AcpiTableInstance
->Rsdt3
->CreatorRevision
= EFI_ACPI_CREATOR_REVISION
;
1810 // We always reserve first one for FADT
1812 AcpiTableInstance
->NumberOfTableEntries3
= 1;
1813 AcpiTableInstance
->Rsdt3
->Length
= AcpiTableInstance
->Rsdt3
->Length
+ sizeof(UINT32
);
1818 AcpiTableInstance
->Xsdt
->Signature
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1819 AcpiTableInstance
->Xsdt
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1820 AcpiTableInstance
->Xsdt
->Revision
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1821 CopyMem (AcpiTableInstance
->Xsdt
->OemId
, EFI_ACPI_OEM_ID
, 6);
1822 CurrentData
= EFI_ACPI_OEM_TABLE_ID
;
1823 CopyMem (&AcpiTableInstance
->Xsdt
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1824 AcpiTableInstance
->Xsdt
->OemRevision
= EFI_ACPI_OEM_REVISION
;
1825 AcpiTableInstance
->Xsdt
->CreatorId
= EFI_ACPI_CREATOR_ID
;
1826 AcpiTableInstance
->Xsdt
->CreatorRevision
= EFI_ACPI_CREATOR_REVISION
;
1828 // We always reserve first one for FADT
1830 AcpiTableInstance
->Xsdt
->Length
= AcpiTableInstance
->Xsdt
->Length
+ sizeof(UINT64
);
1832 ChecksumCommonTables (AcpiTableInstance
);
1835 // Completed successfully