2 ACPI Table Protocol Implementation
4 Copyright (c) 2006 - 2009, 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"
22 This function adds an ACPI table to the table list. It will detect FACS and
23 allocate the correct type of memory and properly align the table.
25 @param AcpiTableInstance Instance of the protocol.
26 @param Table Table to add.
27 @param Checksum Does the table require checksumming.
28 @param Version The version of the list to add the table to.
29 @param Handle Pointer for returning the handle.
31 @return EFI_SUCCESS The function completed successfully.
32 @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
33 @return EFI_ABORTED The table is a duplicate of a table that is required
39 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
42 IN EFI_ACPI_TABLE_VERSION Version
,
47 This function finds and removes the table specified by the handle.
49 @param AcpiTableInstance Instance of the protocol.
50 @param Version Bitmask of which versions to remove.
51 @param Handle Table to remove.
53 @return EFI_SUCCESS The function completed successfully.
54 @return EFI_ABORTED An error occurred.
55 @return EFI_NOT_FOUND Handle not found in table list.
60 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
61 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.
76 AcpiPlatformChecksum (
79 IN UINTN ChecksumOffset
83 Checksum all versions of the common tables, RSDP, RSDT, XSDT.
85 @param AcpiTableInstance Protocol instance private data.
87 @return EFI_SUCCESS The function completed successfully.
91 ChecksumCommonTables (
92 IN OUT EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
96 // Protocol function implementations.
100 This function adds, removes, or updates ACPI tables. If the address is not
101 null and the handle value is null, the table is added. If both the address and
102 handle are not null, the table at handle is updated with the table at address.
103 If the address is null and the handle is not, the table at handle is deleted.
105 @param AcpiTableInstance Instance of the protocol.
106 @param Table Pointer to a table.
107 @param Checksum Boolean indicating if the checksum should be calculated.
108 @param Version Version(s) to set.
109 @param Handle Handle of the table.
111 @return EFI_SUCCESS The function completed successfully.
112 @return EFI_INVALID_PARAMETER Both the Table and *Handle were NULL.
113 @return EFI_ABORTED Could not complete the desired request.
119 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
120 IN VOID
*Table OPTIONAL
,
122 IN EFI_ACPI_TABLE_VERSION Version
,
130 // Check for invalid input parameters
138 // Determine desired action
143 // Invalid parameter combination
145 return EFI_INVALID_PARAMETER
;
150 Status
= AddTableToList (AcpiTableInstance
, Table
, Checksum
, Version
, Handle
);
158 // Delete the table list entry
160 Status
= RemoveTableFromList (AcpiTableInstance
, Version
, *Handle
);
161 if (EFI_ERROR (Status
)) {
163 // Should not get an error here ever, but abort if we do.
168 // Set the handle to replace the table at the same handle
170 SavedHandle
= AcpiTableInstance
->CurrentHandle
;
171 AcpiTableInstance
->CurrentHandle
= *Handle
;
176 Status
= AddTableToList (AcpiTableInstance
, Table
, Checksum
, Version
, Handle
);
179 // Restore the saved current handle
181 AcpiTableInstance
->CurrentHandle
= SavedHandle
;
186 Status
= RemoveTableFromList (AcpiTableInstance
, Version
, *Handle
);
190 if (EFI_ERROR (Status
)) {
192 // Should not get an error here ever, but abort if we do.
203 This function publishes the specified versions of the ACPI tables by
204 installing EFI configuration table entries for them. Any combination of
205 table versions can be published.
207 @param AcpiTableInstance Instance of the protocol.
208 @param Version Version(s) to publish.
210 @return EFI_SUCCESS The function completed successfully.
211 @return EFI_ABORTED The function could not complete successfully.
217 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
218 IN EFI_ACPI_TABLE_VERSION Version
222 UINT32
*CurrentRsdtEntry
;
223 VOID
*CurrentXsdtEntry
;
227 // Reorder tables as some operating systems don't seem to find the
228 // FADT correctly if it is not in the first few entries
232 // Add FADT as the first entry
234 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
235 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) AcpiTableInstance
->Rsdt1
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
236 *CurrentRsdtEntry
= (UINT32
) (UINTN
) AcpiTableInstance
->Fadt1
;
238 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
239 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
240 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) AcpiTableInstance
->Rsdt3
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
241 *CurrentRsdtEntry
= (UINT32
) (UINTN
) AcpiTableInstance
->Fadt3
;
242 CurrentXsdtEntry
= (VOID
*) ((UINT8
*) AcpiTableInstance
->Xsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
244 // Add entry to XSDT, XSDT expects 64 bit pointers, but
245 // the table pointers in XSDT are not aligned on 8 byte boundary.
247 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Fadt3
;
256 // Do checksum again because Dsdt/Xsdt is updated.
258 ChecksumCommonTables (AcpiTableInstance
);
261 // Add the RSD_PTR to the system table and store that we have installed the
264 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) &&
265 !AcpiTableInstance
->TablesInstalled1
) {
266 Status
= gBS
->InstallConfigurationTable (&gEfiAcpi10TableGuid
, AcpiTableInstance
->Rsdp1
);
267 if (EFI_ERROR (Status
)) {
271 AcpiTableInstance
->TablesInstalled1
= TRUE
;
274 if (((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
275 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) &&
276 !AcpiTableInstance
->TablesInstalled3
) {
277 Status
= gBS
->InstallConfigurationTable (&gEfiAcpiTableGuid
, AcpiTableInstance
->Rsdp3
);
278 if (EFI_ERROR (Status
)) {
282 AcpiTableInstance
->TablesInstalled3
= TRUE
;
290 Installs an ACPI table into the RSDT/XSDT.
291 Note that the ACPI table should be checksumed before installing it.
292 Otherwise it will assert.
294 @param This Protocol instance pointer.
295 @param AcpiTableBuffer A pointer to a buffer containing the ACPI table to be installed.
296 @param AcpiTableBufferSize Specifies the size, in bytes, of the AcpiTableBuffer buffer.
297 @param TableKey Reurns a key to refer to the ACPI table.
299 @return EFI_SUCCESS The table was successfully inserted.
300 @return EFI_INVALID_PARAMETER Either AcpiTableBuffer is NULL, TableKey is NULL, or AcpiTableBufferSize
301 and the size field embedded in the ACPI table pointed to by AcpiTableBuffer
303 @return EFI_OUT_OF_RESOURCES Insufficient resources exist to complete the request.
309 IN CONST EFI_ACPI_TABLE_PROTOCOL
*This
,
310 IN CONST VOID
*AcpiTableBuffer
,
311 IN UINTN AcpiTableBufferSize
,
315 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
;
317 VOID
*AcpiTableBufferConst
;
322 // Check for invalid input parameters
324 if ((AcpiTableBuffer
== NULL
) || (TableKey
== NULL
)
325 || (((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTableBuffer
)->Length
!= AcpiTableBufferSize
)) {
326 return EFI_INVALID_PARAMETER
;
329 Length
= ((EFI_ACPI_COMMON_HEADER
*) AcpiTableBuffer
)->Length
;
330 Checksum
= CalculateCheckSum8 ((UINT8
*)AcpiTableBuffer
, Length
);
331 ASSERT (Checksum
== 0);
334 // Get the instance of the ACPI table protocol
336 AcpiTableInstance
= EFI_ACPI_TABLE_INSTANCE_FROM_THIS (This
);
339 // Install the ACPI table
341 AcpiTableBufferConst
= AllocateCopyPool (AcpiTableBufferSize
,AcpiTableBuffer
);
343 Status
= SetAcpiTable (
345 AcpiTableBufferConst
,
347 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
,
350 if (!EFI_ERROR (Status
)) {
351 Status
= PublishTables (
353 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
356 FreePool (AcpiTableBufferConst
);
363 Removes an ACPI table from the RSDT/XSDT.
365 @param This Protocol instance pointer.
366 @param TableKey Specifies the table to uninstall. The key was returned from InstallAcpiTable().
368 @return EFI_SUCCESS The table was successfully uninstalled.
369 @return EFI_NOT_FOUND TableKey does not refer to a valid key for a table entry.
375 IN CONST EFI_ACPI_TABLE_PROTOCOL
*This
,
379 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
;
383 // Get the instance of the ACPI table protocol
385 AcpiTableInstance
= EFI_ACPI_TABLE_INSTANCE_FROM_THIS (This
);
388 // Uninstall the ACPI table
390 Status
= SetAcpiTable (
394 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
,
397 if (!EFI_ERROR (Status
)) {
398 Status
= PublishTables (
400 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
404 if (EFI_ERROR (Status
)) {
405 return EFI_NOT_FOUND
;
413 This function adds an ACPI table to the table list. It will detect FACS and
414 allocate the correct type of memory and properly align the table.
416 @param AcpiTableInstance Instance of the protocol.
417 @param Table Table to add.
418 @param Checksum Does the table require checksumming.
419 @param Version The version of the list to add the table to.
420 @param Handle Pointer for returning the handle.
422 @return EFI_SUCCESS The function completed successfully.
423 @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
424 @return EFI_ABORTED The table is a duplicate of a table that is required
430 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
433 IN EFI_ACPI_TABLE_VERSION Version
,
438 EFI_ACPI_TABLE_LIST
*CurrentTableList
;
439 UINT32 CurrentTableSignature
;
440 UINT32 CurrentTableSize
;
441 UINT32
*CurrentRsdtEntry
;
442 VOID
*CurrentXsdtEntry
;
447 // Check for invalid input parameters
449 ASSERT (AcpiTableInstance
);
459 // Create a new list entry
461 CurrentTableList
= AllocatePool (sizeof (EFI_ACPI_TABLE_LIST
));
462 ASSERT (CurrentTableList
);
465 // Determine table type and size
467 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
)->Signature
;
468 CurrentTableSize
= ((EFI_ACPI_COMMON_HEADER
*) Table
)->Length
;
471 // Allocate a buffer for the table. All tables are allocated in the lower 32 bits of address space
472 // for backwards compatibility with ACPI 1.0 OS.
474 // This is done because ACPI 1.0 pointers are 32 bit values.
475 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
476 // There is no architectural reason these should be below 4GB, it is purely
477 // for convenience of implementation that we force memory below 4GB.
479 CurrentTableList
->PageAddress
= 0xFFFFFFFF;
480 CurrentTableList
->NumberOfPages
= EFI_SIZE_TO_PAGES (CurrentTableSize
);
483 // Allocation memory type depends on the type of the table
485 if (CurrentTableSignature
== EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
||
486 CurrentTableSignature
== EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) {
488 // Allocate memory for the FACS. This structure must be aligned
489 // on a 64 byte boundary and must be ACPI NVS memory.
490 // Using AllocatePages should ensure that it is always aligned.
492 ASSERT ((EFI_PAGE_SIZE
% 64) == 0);
493 Status
= gBS
->AllocatePages (
496 CurrentTableList
->NumberOfPages
,
497 &CurrentTableList
->PageAddress
501 // All other tables are ACPI reclaim memory, no alignment requirements.
503 Status
= gBS
->AllocatePages (
505 EfiACPIReclaimMemory
,
506 CurrentTableList
->NumberOfPages
,
507 &CurrentTableList
->PageAddress
511 // Check return value from memory alloc.
513 if (EFI_ERROR (Status
)) {
514 gBS
->FreePool (CurrentTableList
);
515 return EFI_OUT_OF_RESOURCES
;
518 // Update the table pointer with the allocated memory start
520 CurrentTableList
->Table
= (EFI_ACPI_COMMON_HEADER
*) (UINTN
) CurrentTableList
->PageAddress
;
523 // Initialize the table contents
525 CurrentTableList
->Signature
= EFI_ACPI_TABLE_LIST_SIGNATURE
;
526 CopyMem (CurrentTableList
->Table
, Table
, CurrentTableSize
);
527 CurrentTableList
->Handle
= AcpiTableInstance
->CurrentHandle
++;
528 *Handle
= CurrentTableList
->Handle
;
529 CurrentTableList
->Version
= Version
;
532 // Update internal pointers if this is a required table. If it is a required
533 // table and a table of that type already exists, return an error.
535 // Calculate the checksum if the table is not FACS.
537 switch (CurrentTableSignature
) {
539 case EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
541 // We don't add the FADT in the standard way because some
542 // OS expect the FADT to be early in the table list.
543 // So we always add it as the first element in the list.
548 // Check that the table has not been previously added.
550 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Fadt1
!= NULL
) ||
551 ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 && AcpiTableInstance
->Fadt3
!= NULL
) ||
552 ((Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0 && AcpiTableInstance
->Fadt3
!= NULL
)
554 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
555 gBS
->FreePool (CurrentTableList
);
559 // Add the table to the appropriate table version
561 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
563 // Save a pointer to the table
565 AcpiTableInstance
->Fadt1
= (EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE
*) CurrentTableList
->Table
;
568 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
570 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs1
;
571 AcpiTableInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt1
;
574 // RSDP OEM information is updated to match the FADT OEM information
577 &AcpiTableInstance
->Rsdp1
->OemId
,
578 &AcpiTableInstance
->Fadt1
->Header
.OemId
,
583 // RSDT OEM information is updated to match the FADT OEM information.
586 &AcpiTableInstance
->Rsdt1
->OemId
,
587 &AcpiTableInstance
->Fadt1
->Header
.OemId
,
592 &AcpiTableInstance
->Rsdt1
->OemTableId
,
593 &AcpiTableInstance
->Fadt1
->Header
.OemTableId
,
596 AcpiTableInstance
->Rsdt1
->OemRevision
= AcpiTableInstance
->Fadt1
->Header
.OemRevision
;
599 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
600 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
602 // Save a pointer to the table
604 AcpiTableInstance
->Fadt3
= (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE
*) CurrentTableList
->Table
;
607 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
609 if (AcpiTableInstance
->Fadt3
!= NULL
) {
610 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs3
;
611 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Facs3
;
613 &AcpiTableInstance
->Fadt3
->XFirmwareCtrl
,
617 AcpiTableInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt3
;
618 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Dsdt3
;
620 &AcpiTableInstance
->Fadt3
->XDsdt
,
626 // RSDP OEM information is updated to match the FADT OEM information
629 &AcpiTableInstance
->Rsdp3
->OemId
,
630 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
635 // RSDT OEM information is updated to match FADT OEM information.
638 &AcpiTableInstance
->Rsdt3
->OemId
,
639 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
643 &AcpiTableInstance
->Rsdt3
->OemTableId
,
644 &AcpiTableInstance
->Fadt3
->Header
.OemTableId
,
647 AcpiTableInstance
->Rsdt3
->OemRevision
= AcpiTableInstance
->Fadt3
->Header
.OemRevision
;
650 // XSDT OEM information is updated to match FADT OEM information.
653 &AcpiTableInstance
->Xsdt
->OemId
,
654 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
658 &AcpiTableInstance
->Xsdt
->OemTableId
,
659 &AcpiTableInstance
->Fadt3
->Header
.OemTableId
,
662 AcpiTableInstance
->Xsdt
->OemRevision
= AcpiTableInstance
->Fadt3
->Header
.OemRevision
;
666 // Checksum the table
669 AcpiPlatformChecksum (
670 CurrentTableList
->Table
,
671 CurrentTableList
->Table
->Length
,
672 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
678 case EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
680 // Check that the table has not been previously added.
682 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Facs1
!= NULL
) ||
683 ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 && AcpiTableInstance
->Facs3
!= NULL
) ||
684 ((Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0 && AcpiTableInstance
->Facs3
!= NULL
)
686 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
687 gBS
->FreePool (CurrentTableList
);
691 // FACS is referenced by FADT and is not part of RSDT
696 // Add the table to the appropriate table version
698 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
700 // Save a pointer to the table
702 AcpiTableInstance
->Facs1
= (EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
705 // If FADT already exists, update table pointers.
707 if (AcpiTableInstance
->Fadt1
!= NULL
) {
708 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs1
;
711 // Checksum FADT table
713 AcpiPlatformChecksum (
714 AcpiTableInstance
->Fadt1
,
715 AcpiTableInstance
->Fadt1
->Header
.Length
,
716 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
722 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
723 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
725 // Save a pointer to the table
727 AcpiTableInstance
->Facs3
= (EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
730 // If FADT already exists, update table pointers.
732 if (AcpiTableInstance
->Fadt3
!= NULL
) {
733 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs3
;
734 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Facs3
;
736 &AcpiTableInstance
->Fadt3
->XFirmwareCtrl
,
742 // Checksum FADT table
744 AcpiPlatformChecksum (
745 AcpiTableInstance
->Fadt3
,
746 AcpiTableInstance
->Fadt3
->Header
.Length
,
747 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
755 case EFI_ACPI_1_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
757 // Check that the table has not been previously added.
759 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Dsdt1
!= NULL
) ||
760 ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 && AcpiTableInstance
->Dsdt3
!= NULL
) ||
761 ((Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0 && AcpiTableInstance
->Dsdt3
!= NULL
)
763 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
764 gBS
->FreePool (CurrentTableList
);
768 // DSDT is referenced by FADT and is not part of RSDT
773 // Add the table to the appropriate table version
775 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
777 // Save a pointer to the table
779 AcpiTableInstance
->Dsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
782 // If FADT already exists, update table pointers.
784 if (AcpiTableInstance
->Fadt1
!= NULL
) {
785 AcpiTableInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt1
;
788 // Checksum FADT table
790 AcpiPlatformChecksum (
791 AcpiTableInstance
->Fadt1
,
792 AcpiTableInstance
->Fadt1
->Header
.Length
,
793 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
799 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
800 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
802 // Save a pointer to the table
804 AcpiTableInstance
->Dsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
807 // If FADT already exists, update table pointers.
809 if (AcpiTableInstance
->Fadt3
!= NULL
) {
810 AcpiTableInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt3
;
811 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Dsdt3
;
813 &AcpiTableInstance
->Fadt3
->XDsdt
,
819 // Checksum FADT table
821 AcpiPlatformChecksum (
822 AcpiTableInstance
->Fadt3
,
823 AcpiTableInstance
->Fadt3
->Header
.Length
,
824 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
830 // Checksum the table
833 AcpiPlatformChecksum (
834 CurrentTableList
->Table
,
835 CurrentTableList
->Table
->Length
,
836 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
844 // Checksum the table
847 AcpiPlatformChecksum (
848 CurrentTableList
->Table
,
849 CurrentTableList
->Table
->Length
,
850 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
857 // Add the table to the current list of tables
859 InsertTailList (&AcpiTableInstance
->TableList
, &CurrentTableList
->Link
);
862 // Add the table to RSDT and/or XSDT table entry lists.
865 // Add to ACPI 1.0b table tree
867 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
868 CurrentRsdtEntry
= (UINT32
*)
870 (UINT8
*) AcpiTableInstance
->Rsdt1
+
871 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
872 AcpiTableInstance
->NumberOfTableEntries1
*
877 // Add entry to the RSDT unless its the FACS or DSDT
880 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
883 // Update RSDT length
885 AcpiTableInstance
->Rsdt1
->Length
= AcpiTableInstance
->Rsdt1
->Length
+ sizeof (UINT32
);
887 AcpiTableInstance
->NumberOfTableEntries1
++;
890 ASSERT (AcpiTableInstance
->NumberOfTableEntries1
<= EFI_ACPI_MAX_NUM_TABLES
);
893 // Add to ACPI 2.0/3.0 table tree
895 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
896 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
899 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
900 // If it becomes necessary to maintain separate table lists, changes will be required.
902 CurrentRsdtEntry
= (UINT32
*)
904 (UINT8
*) AcpiTableInstance
->Rsdt3
+
905 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
906 AcpiTableInstance
->NumberOfTableEntries3
*
911 // This pointer must not be directly dereferenced as the XSDT entries may not
912 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
914 CurrentXsdtEntry
= (VOID
*)
916 (UINT8
*) AcpiTableInstance
->Xsdt
+
917 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
918 AcpiTableInstance
->NumberOfTableEntries3
*
923 // Add entry to the RSDT
925 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
928 // Update RSDT length
930 AcpiTableInstance
->Rsdt3
->Length
= AcpiTableInstance
->Rsdt3
->Length
+ sizeof (UINT32
);
933 // Add entry to XSDT, XSDT expects 64 bit pointers, but
934 // the table pointers in XSDT are not aligned on 8 byte boundary.
936 Buffer64
= (UINT64
) (UINTN
) CurrentTableList
->Table
;
946 AcpiTableInstance
->Xsdt
->Length
= AcpiTableInstance
->Xsdt
->Length
+ sizeof (UINT64
);
948 AcpiTableInstance
->NumberOfTableEntries3
++;
951 ASSERT (AcpiTableInstance
->NumberOfTableEntries3
<= EFI_ACPI_MAX_NUM_TABLES
);
954 ChecksumCommonTables (AcpiTableInstance
);
960 This function finds the table specified by the handle and returns a pointer to it.
961 If the handle is not found, EFI_NOT_FOUND is returned and the contents of Table are
964 @param Handle Table to find.
965 @param TableList Table list to search
966 @param Table Pointer to table found.
968 @return EFI_SUCCESS The function completed successfully.
969 @return EFI_NOT_FOUND No table found matching the handle specified.
975 IN LIST_ENTRY
*TableList
,
976 OUT EFI_ACPI_TABLE_LIST
**Table
979 LIST_ENTRY
*CurrentLink
;
980 EFI_ACPI_TABLE_LIST
*CurrentTable
;
983 // Check for invalid input parameters
990 CurrentLink
= TableList
->ForwardLink
;
992 while (CurrentLink
!= TableList
) {
993 CurrentTable
= EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink
);
994 if (CurrentTable
->Handle
== Handle
) {
996 // Found handle, so return this table.
998 *Table
= CurrentTable
;
1002 CurrentLink
= CurrentLink
->ForwardLink
;
1007 return EFI_NOT_FOUND
;
1012 This function removes a basic table from the RSDT and/or XSDT.
1013 For Acpi 1.0 tables, pass in the Rsdt.
1014 For Acpi 2.0 tables, pass in both Rsdt and Xsdt.
1016 @param Table Pointer to table found.
1017 @param NumberOfTableEntries Current number of table entries in the RSDT/XSDT
1018 @param Rsdt Pointer to the RSDT to remove from
1019 @param Xsdt Pointer to the Xsdt to remove from
1021 @return EFI_SUCCESS The function completed successfully.
1022 @return EFI_INVALID_PARAMETER The table was not found in both Rsdt and Xsdt.
1026 RemoveTableFromRsdt (
1027 IN OUT EFI_ACPI_TABLE_LIST
* Table
,
1028 IN OUT UINTN
*NumberOfTableEntries
,
1029 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Rsdt
,
1030 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Xsdt OPTIONAL
1033 UINT32
*CurrentRsdtEntry
;
1034 VOID
*CurrentXsdtEntry
;
1035 UINT64 CurrentTablePointer64
;
1039 // Check for invalid input parameters
1042 ASSERT (NumberOfTableEntries
);
1046 // Find the table entry in the RSDT and XSDT
1048 for (Index
= 0; Index
< *NumberOfTableEntries
; Index
++) {
1050 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
1051 // If it becomes necessary to maintain separate table lists, changes will be required.
1053 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) Rsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + Index
* sizeof (UINT32
));
1056 // This pointer must not be directly dereferenced as the XSDT entries may not
1057 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
1059 CurrentXsdtEntry
= (VOID
*) ((UINT8
*) Xsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + Index
* sizeof (UINT64
));
1062 // Read the entry value out of the XSDT
1064 CopyMem (&CurrentTablePointer64
, CurrentXsdtEntry
, sizeof (UINT64
));
1067 // Initialize to NULL
1069 CurrentXsdtEntry
= 0;
1070 CurrentTablePointer64
= 0;
1073 // Check if we have found the corresponding entry in both RSDT and XSDT
1075 if (*CurrentRsdtEntry
== (UINT32
) (UINTN
) Table
->Table
&&
1076 ((Xsdt
== NULL
) || CurrentTablePointer64
== (UINT64
) (UINTN
) Table
->Table
)
1079 // Found entry, so copy all following entries and shrink table
1080 // We actually copy all + 1 to copy the initialized value of memory over
1083 CopyMem (CurrentRsdtEntry
, CurrentRsdtEntry
+ 1, (*NumberOfTableEntries
- Index
) * sizeof (UINT32
));
1084 Rsdt
->Length
= Rsdt
->Length
- sizeof (UINT32
);
1086 CopyMem (CurrentXsdtEntry
, ((UINT64
*) CurrentXsdtEntry
) + 1, (*NumberOfTableEntries
- Index
) * sizeof (UINT64
));
1087 Xsdt
->Length
= Xsdt
->Length
- sizeof (UINT64
);
1090 } else if (Index
+ 1 == *NumberOfTableEntries
) {
1092 // At the last entry, and table not found
1094 return EFI_INVALID_PARAMETER
;
1098 // Checksum the tables
1100 AcpiPlatformChecksum (
1103 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1108 AcpiPlatformChecksum (
1111 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1116 // Decrement the number of tables
1118 (*NumberOfTableEntries
)--;
1125 This function removes a table and frees any associated memory.
1127 @param AcpiTableInstance Instance of the protocol.
1128 @param Version Version(s) to delete.
1129 @param Table Pointer to table found.
1131 @return EFI_SUCCESS The function completed successfully.
1136 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
1137 IN EFI_ACPI_TABLE_VERSION Version
,
1138 IN OUT EFI_ACPI_TABLE_LIST
*Table
1141 UINT32 CurrentTableSignature
;
1142 BOOLEAN RemoveFromRsdt
;
1145 // Check for invalid input parameters
1147 ASSERT (AcpiTableInstance
);
1153 RemoveFromRsdt
= TRUE
;
1155 // Check for Table->Table
1157 ASSERT (Table
->Table
!= NULL
);
1158 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
->Table
)->Signature
;
1161 // Basic tasks to accomplish delete are:
1162 // Determine removal requirements (in RSDT/XSDT or not)
1163 // Remove entry from RSDT/XSDT
1164 // Remove any table references to the table
1165 // If no one is using the table
1166 // Free the table (removing pointers from private data and tables)
1168 // Free list structure
1171 // Determine if this table is in the RSDT or XSDT
1173 if ((CurrentTableSignature
== EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) ||
1174 (CurrentTableSignature
== EFI_ACPI_2_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
) ||
1175 (CurrentTableSignature
== EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
)
1177 RemoveFromRsdt
= FALSE
;
1180 // We don't remove the FADT in the standard way because some
1181 // OS expect the FADT to be early in the table list.
1182 // So we always put it as the first element in the list.
1184 if (CurrentTableSignature
== EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
) {
1185 RemoveFromRsdt
= FALSE
;
1189 // Remove the table from RSDT and XSDT
1191 if (Table
->Table
!= NULL
) {
1193 // This is a basic table, remove it from any lists and the Rsdt and/or Xsdt
1195 if (Version
& EFI_ACPI_TABLE_VERSION_NONE
& Table
->Version
) {
1197 // Remove this version from the table
1199 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_NONE
;
1202 if (Version
& EFI_ACPI_TABLE_VERSION_1_0B
& Table
->Version
) {
1204 // Remove this version from the table
1206 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_1_0B
;
1209 // Remove from Rsdt. We don't care about the return value because it is
1210 // acceptable for the table to not exist in Rsdt.
1211 // We didn't add some tables so we don't remove them.
1213 if (RemoveFromRsdt
) {
1214 RemoveTableFromRsdt (
1216 &AcpiTableInstance
->NumberOfTableEntries1
,
1217 AcpiTableInstance
->Rsdt1
,
1223 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
& Table
->Version
) ||
1224 (Version
& EFI_ACPI_TABLE_VERSION_3_0
& Table
->Version
)) {
1226 // Remove this version from the table
1228 if (Version
& EFI_ACPI_TABLE_VERSION_2_0
& Table
->Version
) {
1229 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_2_0
;
1231 if (Version
& EFI_ACPI_TABLE_VERSION_3_0
& Table
->Version
) {
1232 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_3_0
;
1236 // Remove from Rsdt and Xsdt. We don't care about the return value
1237 // because it is acceptable for the table to not exist in Rsdt/Xsdt.
1238 // We didn't add some tables so we don't remove them.
1240 if (RemoveFromRsdt
) {
1241 RemoveTableFromRsdt (
1243 &AcpiTableInstance
->NumberOfTableEntries3
,
1244 AcpiTableInstance
->Rsdt3
,
1245 AcpiTableInstance
->Xsdt
1250 // Free the table, clean up any dependent tables and our private data pointers.
1252 switch (Table
->Table
->Signature
) {
1254 case EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
1255 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1256 AcpiTableInstance
->Fadt1
= NULL
;
1259 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
1260 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1261 AcpiTableInstance
->Fadt3
= NULL
;
1265 case EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
1266 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1267 AcpiTableInstance
->Facs1
= NULL
;
1270 // Update FADT table pointers
1272 if (AcpiTableInstance
->Fadt1
!= NULL
) {
1273 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= 0;
1278 AcpiPlatformChecksum (
1279 AcpiTableInstance
->Fadt1
,
1280 AcpiTableInstance
->Fadt1
->Header
.Length
,
1281 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1287 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
1288 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1289 AcpiTableInstance
->Facs3
= NULL
;
1292 // Update FADT table pointers
1294 if (AcpiTableInstance
->Fadt3
!= NULL
) {
1295 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= 0;
1296 ZeroMem (&AcpiTableInstance
->Fadt3
->XFirmwareCtrl
, sizeof (UINT64
));
1301 AcpiPlatformChecksum (
1302 AcpiTableInstance
->Fadt3
,
1303 AcpiTableInstance
->Fadt3
->Header
.Length
,
1304 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1311 case EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
1312 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1313 AcpiTableInstance
->Dsdt1
= NULL
;
1316 // Update FADT table pointers
1318 if (AcpiTableInstance
->Fadt1
!= NULL
) {
1319 AcpiTableInstance
->Fadt1
->Dsdt
= 0;
1324 AcpiPlatformChecksum (
1325 AcpiTableInstance
->Fadt1
,
1326 AcpiTableInstance
->Fadt1
->Header
.Length
,
1327 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1334 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
1335 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1336 AcpiTableInstance
->Dsdt3
= NULL
;
1339 // Update FADT table pointers
1341 if (AcpiTableInstance
->Fadt3
!= NULL
) {
1342 AcpiTableInstance
->Fadt3
->Dsdt
= 0;
1343 ZeroMem (&AcpiTableInstance
->Fadt3
->XDsdt
, sizeof (UINT64
));
1348 AcpiPlatformChecksum (
1349 AcpiTableInstance
->Fadt3
,
1350 AcpiTableInstance
->Fadt3
->Header
.Length
,
1351 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1366 // If no version is using this table anymore, remove and free list entry.
1368 if (Table
->Version
== 0) {
1372 gBS
->FreePages (Table
->PageAddress
, Table
->NumberOfPages
);
1373 RemoveEntryList (&(Table
->Link
));
1374 gBS
->FreePool (Table
);
1384 This function finds and removes the table specified by the handle.
1386 @param AcpiTableInstance Instance of the protocol.
1387 @param Version Bitmask of which versions to remove.
1388 @param Handle Table to remove.
1390 @return EFI_SUCCESS The function completed successfully.
1391 @return EFI_ABORTED An error occurred.
1392 @return EFI_NOT_FOUND Handle not found in table list.
1396 RemoveTableFromList (
1397 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
1398 IN EFI_ACPI_TABLE_VERSION Version
,
1402 EFI_ACPI_TABLE_LIST
*Table
;
1405 Table
= (EFI_ACPI_TABLE_LIST
*) NULL
;
1408 // Check for invalid input parameters
1410 ASSERT (AcpiTableInstance
);
1415 Status
= FindTableByHandle (
1417 &AcpiTableInstance
->TableList
,
1420 if (EFI_ERROR (Status
)) {
1421 return EFI_NOT_FOUND
;
1426 Status
= DeleteTable (AcpiTableInstance
, Version
, Table
);
1427 if (EFI_ERROR (Status
)) {
1431 // Completed successfully
1438 This function calculates and updates an UINT8 checksum.
1440 @param Buffer Pointer to buffer to checksum
1441 @param Size Number of bytes to checksum
1442 @param ChecksumOffset Offset to place the checksum result in
1444 @return EFI_SUCCESS The function completed successfully.
1448 AcpiPlatformChecksum (
1451 IN UINTN ChecksumOffset
1459 // Initialize pointer
1464 // set checksum to 0 first
1466 Ptr
[ChecksumOffset
] = 0;
1469 // add all content of buffer
1471 while ((Size
--) != 0) {
1472 Sum
= (UINT8
) (Sum
+ (*Ptr
++));
1478 Ptr
[ChecksumOffset
] = (UINT8
) (0xff - Sum
+ 1);
1485 Checksum all versions of the common tables, RSDP, RSDT, XSDT.
1487 @param AcpiTableInstance Protocol instance private data.
1489 @return EFI_SUCCESS The function completed successfully.
1493 ChecksumCommonTables (
1494 IN OUT EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
1498 // RSDP ACPI 1.0 checksum for 1.0 table. This is only the first 20 bytes of the structure
1500 AcpiPlatformChecksum (
1501 AcpiTableInstance
->Rsdp1
,
1502 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1503 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1508 // RSDP ACPI 1.0 checksum for 2.0/3.0 table. This is only the first 20 bytes of the structure
1510 AcpiPlatformChecksum (
1511 AcpiTableInstance
->Rsdp3
,
1512 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1513 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1518 // RSDP ACPI 2.0/3.0 checksum, this is the entire table
1520 AcpiPlatformChecksum (
1521 AcpiTableInstance
->Rsdp3
,
1522 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1523 OFFSET_OF (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1530 AcpiPlatformChecksum (
1531 AcpiTableInstance
->Rsdt1
,
1532 AcpiTableInstance
->Rsdt1
->Length
,
1533 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1537 AcpiPlatformChecksum (
1538 AcpiTableInstance
->Rsdt3
,
1539 AcpiTableInstance
->Rsdt3
->Length
,
1540 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1547 AcpiPlatformChecksum (
1548 AcpiTableInstance
->Xsdt
,
1549 AcpiTableInstance
->Xsdt
->Length
,
1550 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1559 Constructor for the ACPI table protocol. Initializes instance
1562 @param AcpiTableInstance Instance to construct
1564 @return EFI_SUCCESS Instance initialized.
1565 @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
1569 AcpiTableAcpiTableConstructor (
1570 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
1577 EFI_PHYSICAL_ADDRESS PageAddress
;
1580 // Check for invalid input parameters
1582 ASSERT (AcpiTableInstance
);
1584 InitializeListHead (&AcpiTableInstance
->TableList
);
1585 AcpiTableInstance
->CurrentHandle
= 1;
1587 AcpiTableInstance
->AcpiTableProtocol
.InstallAcpiTable
= InstallAcpiTable
;
1588 AcpiTableInstance
->AcpiTableProtocol
.UninstallAcpiTable
= UninstallAcpiTable
;
1590 // Create RSDP, RSDT, XSDT structures
1591 // Allocate all buffers
1593 TotalSize
= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
) +
1594 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
) +
1595 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
1596 EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
) +
1597 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
1598 EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
) +
1599 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
1600 EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT64
);
1603 // Allocate memory in the lower 32 bit of address range for
1604 // compatibility with ACPI 1.0 OS.
1606 // This is done because ACPI 1.0 pointers are 32 bit values.
1607 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
1608 // There is no architectural reason these should be below 4GB, it is purely
1609 // for convenience of implementation that we force memory below 4GB.
1611 PageAddress
= 0xFFFFFFFF;
1612 Status
= gBS
->AllocatePages (
1614 EfiACPIReclaimMemory
,
1615 EFI_SIZE_TO_PAGES (TotalSize
),
1619 if (EFI_ERROR (Status
)) {
1620 return EFI_OUT_OF_RESOURCES
;
1623 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
1624 ZeroMem (Pointer
, TotalSize
);
1626 AcpiTableInstance
->Rsdp1
= (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1627 Pointer
+= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1628 AcpiTableInstance
->Rsdp3
= (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1629 Pointer
+= sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1631 AcpiTableInstance
->Rsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1632 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1633 AcpiTableInstance
->Rsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1634 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1636 AcpiTableInstance
->Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1641 CurrentData
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1642 CopyMem (&AcpiTableInstance
->Rsdp1
->Signature
, &CurrentData
, sizeof (UINT64
));
1643 CopyMem (AcpiTableInstance
->Rsdp1
->OemId
, EFI_ACPI_OEM_ID
, 6);
1644 AcpiTableInstance
->Rsdp1
->Reserved
= EFI_ACPI_RESERVED_BYTE
;
1645 AcpiTableInstance
->Rsdp1
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt1
;
1647 CurrentData
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1648 CopyMem (&AcpiTableInstance
->Rsdp3
->Signature
, &CurrentData
, sizeof (UINT64
));
1649 CopyMem (AcpiTableInstance
->Rsdp3
->OemId
, EFI_ACPI_OEM_ID
, 6);
1650 AcpiTableInstance
->Rsdp3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION
;
1651 AcpiTableInstance
->Rsdp3
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt3
;
1652 AcpiTableInstance
->Rsdp3
->Length
= sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1653 CurrentData
= (UINT64
) (UINTN
) AcpiTableInstance
->Xsdt
;
1654 CopyMem (&AcpiTableInstance
->Rsdp3
->XsdtAddress
, &CurrentData
, sizeof (UINT64
));
1655 SetMem (AcpiTableInstance
->Rsdp3
->Reserved
, 3, EFI_ACPI_RESERVED_BYTE
);
1660 // Note that we "reserve" one entry for the FADT so it can always be
1661 // at the beginning of the list of tables. Some OS don't seem
1662 // to find it correctly if it is too far down the list.
1664 AcpiTableInstance
->Rsdt1
->Signature
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1665 AcpiTableInstance
->Rsdt1
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1666 AcpiTableInstance
->Rsdt1
->Revision
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1667 CopyMem (AcpiTableInstance
->Rsdt1
->OemId
, EFI_ACPI_OEM_ID
, 6);
1668 CurrentData
= EFI_ACPI_OEM_TABLE_ID
;
1669 CopyMem (&AcpiTableInstance
->Rsdt1
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1670 AcpiTableInstance
->Rsdt1
->OemRevision
= EFI_ACPI_OEM_REVISION
;
1671 AcpiTableInstance
->Rsdt1
->CreatorId
= EFI_ACPI_CREATOR_ID
;
1672 AcpiTableInstance
->Rsdt1
->CreatorRevision
= EFI_ACPI_CREATOR_REVISION
;
1674 // We always reserve first one for FADT
1676 AcpiTableInstance
->NumberOfTableEntries1
= 1;
1677 AcpiTableInstance
->Rsdt1
->Length
= AcpiTableInstance
->Rsdt1
->Length
+ sizeof(UINT32
);
1679 AcpiTableInstance
->Rsdt3
->Signature
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1680 AcpiTableInstance
->Rsdt3
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1681 AcpiTableInstance
->Rsdt3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1682 CopyMem (AcpiTableInstance
->Rsdt3
->OemId
, EFI_ACPI_OEM_ID
, 6);
1683 CurrentData
= EFI_ACPI_OEM_TABLE_ID
;
1684 CopyMem (&AcpiTableInstance
->Rsdt3
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1685 AcpiTableInstance
->Rsdt3
->OemRevision
= EFI_ACPI_OEM_REVISION
;
1686 AcpiTableInstance
->Rsdt3
->CreatorId
= EFI_ACPI_CREATOR_ID
;
1687 AcpiTableInstance
->Rsdt3
->CreatorRevision
= EFI_ACPI_CREATOR_REVISION
;
1689 // We always reserve first one for FADT
1691 AcpiTableInstance
->NumberOfTableEntries3
= 1;
1692 AcpiTableInstance
->Rsdt3
->Length
= AcpiTableInstance
->Rsdt3
->Length
+ sizeof(UINT32
);
1697 AcpiTableInstance
->Xsdt
->Signature
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1698 AcpiTableInstance
->Xsdt
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1699 AcpiTableInstance
->Xsdt
->Revision
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1700 CopyMem (AcpiTableInstance
->Xsdt
->OemId
, EFI_ACPI_OEM_ID
, 6);
1701 CurrentData
= EFI_ACPI_OEM_TABLE_ID
;
1702 CopyMem (&AcpiTableInstance
->Xsdt
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1703 AcpiTableInstance
->Xsdt
->OemRevision
= EFI_ACPI_OEM_REVISION
;
1704 AcpiTableInstance
->Xsdt
->CreatorId
= EFI_ACPI_CREATOR_ID
;
1705 AcpiTableInstance
->Xsdt
->CreatorRevision
= EFI_ACPI_CREATOR_REVISION
;
1707 // We always reserve first one for FADT
1709 AcpiTableInstance
->Xsdt
->Length
= AcpiTableInstance
->Xsdt
->Length
+ sizeof(UINT64
);
1711 ChecksumCommonTables (AcpiTableInstance
);
1714 // Completed successfully