2 ACPI Table Protocol Implementation
4 Copyright (c) 2006 - 2009, Intel Corporation<BR>
5 All rights reserved. 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.
292 @param This Protocol instance pointer.
293 @param AcpiTableBuffer A pointer to a buffer containing the ACPI table to be installed.
294 @param AcpiTableBufferSize Specifies the size, in bytes, of the AcpiTableBuffer buffer.
295 @param TableKey Reurns a key to refer to the ACPI table.
297 @return EFI_SUCCESS The table was successfully inserted.
298 @return EFI_INVALID_PARAMETER Either AcpiTableBuffer is NULL, TableKey is NULL, or AcpiTableBufferSize
299 and the size field embedded in the ACPI table pointed to by AcpiTableBuffer
301 @return EFI_OUT_OF_RESOURCES Insufficient resources exist to complete the request.
307 IN CONST EFI_ACPI_TABLE_PROTOCOL
*This
,
308 IN CONST VOID
*AcpiTableBuffer
,
309 IN UINTN AcpiTableBufferSize
,
313 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
;
315 VOID
*AcpiTableBufferConst
;
318 // Check for invalid input parameters
320 if ((AcpiTableBuffer
== NULL
) || (TableKey
== NULL
)
321 || (((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTableBuffer
)->Length
!= AcpiTableBufferSize
)) {
322 return EFI_INVALID_PARAMETER
;
326 // Get the instance of the ACPI table protocol
328 AcpiTableInstance
= EFI_ACPI_TABLE_INSTANCE_FROM_THIS (This
);
331 // Install the ACPI table
333 AcpiTableBufferConst
= AllocateCopyPool (AcpiTableBufferSize
,AcpiTableBuffer
);
335 Status
= SetAcpiTable (
337 AcpiTableBufferConst
,
339 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
,
342 if (!EFI_ERROR (Status
)) {
343 Status
= PublishTables (
345 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
348 FreePool (AcpiTableBufferConst
);
355 Removes an ACPI table from the RSDT/XSDT.
357 @param This Protocol instance pointer.
358 @param TableKey Specifies the table to uninstall. The key was returned from InstallAcpiTable().
360 @return EFI_SUCCESS The table was successfully uninstalled.
361 @return EFI_NOT_FOUND TableKey does not refer to a valid key for a table entry.
367 IN CONST EFI_ACPI_TABLE_PROTOCOL
*This
,
371 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
;
375 // Get the instance of the ACPI table protocol
377 AcpiTableInstance
= EFI_ACPI_TABLE_INSTANCE_FROM_THIS (This
);
380 // Uninstall the ACPI table
382 Status
= SetAcpiTable (
386 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
,
389 if (!EFI_ERROR (Status
)) {
390 Status
= PublishTables (
392 EFI_ACPI_TABLE_VERSION_1_0B
| EFI_ACPI_TABLE_VERSION_2_0
| EFI_ACPI_TABLE_VERSION_3_0
396 if (EFI_ERROR (Status
)) {
397 return EFI_NOT_FOUND
;
405 This function adds an ACPI table to the table list. It will detect FACS and
406 allocate the correct type of memory and properly align the table.
408 @param AcpiTableInstance Instance of the protocol.
409 @param Table Table to add.
410 @param Checksum Does the table require checksumming.
411 @param Version The version of the list to add the table to.
412 @param Handle Pointer for returning the handle.
414 @return EFI_SUCCESS The function completed successfully.
415 @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
416 @return EFI_ABORTED The table is a duplicate of a table that is required
422 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
425 IN EFI_ACPI_TABLE_VERSION Version
,
430 EFI_ACPI_TABLE_LIST
*CurrentTableList
;
431 UINT32 CurrentTableSignature
;
432 UINT32 CurrentTableSize
;
433 UINT32
*CurrentRsdtEntry
;
434 VOID
*CurrentXsdtEntry
;
439 // Check for invalid input parameters
441 ASSERT (AcpiTableInstance
);
451 // Create a new list entry
453 CurrentTableList
= AllocatePool (sizeof (EFI_ACPI_TABLE_LIST
));
454 ASSERT (CurrentTableList
);
457 // Determine table type and size
459 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
)->Signature
;
460 CurrentTableSize
= ((EFI_ACPI_COMMON_HEADER
*) Table
)->Length
;
463 // Allocate a buffer for the table. All tables are allocated in the lower 32 bits of address space
464 // for backwards compatibility with ACPI 1.0 OS.
466 // This is done because ACPI 1.0 pointers are 32 bit values.
467 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
468 // There is no architectural reason these should be below 4GB, it is purely
469 // for convenience of implementation that we force memory below 4GB.
471 CurrentTableList
->PageAddress
= 0xFFFFFFFF;
472 CurrentTableList
->NumberOfPages
= EFI_SIZE_TO_PAGES (CurrentTableSize
);
475 // Allocation memory type depends on the type of the table
477 if (CurrentTableSignature
== EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
||
478 CurrentTableSignature
== EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) {
480 // Allocate memory for the FACS. This structure must be aligned
481 // on a 64 byte boundary and must be ACPI NVS memory.
482 // Using AllocatePages should ensure that it is always aligned.
484 ASSERT ((EFI_PAGE_SIZE
% 64) == 0);
485 Status
= gBS
->AllocatePages (
488 CurrentTableList
->NumberOfPages
,
489 &CurrentTableList
->PageAddress
493 // All other tables are ACPI reclaim memory, no alignment requirements.
495 Status
= gBS
->AllocatePages (
497 EfiACPIReclaimMemory
,
498 CurrentTableList
->NumberOfPages
,
499 &CurrentTableList
->PageAddress
503 // Check return value from memory alloc.
505 if (EFI_ERROR (Status
)) {
506 gBS
->FreePool (CurrentTableList
);
507 return EFI_OUT_OF_RESOURCES
;
510 // Update the table pointer with the allocated memory start
512 CurrentTableList
->Table
= (EFI_ACPI_COMMON_HEADER
*) (UINTN
) CurrentTableList
->PageAddress
;
515 // Initialize the table contents
517 CurrentTableList
->Signature
= EFI_ACPI_TABLE_LIST_SIGNATURE
;
518 CopyMem (CurrentTableList
->Table
, Table
, CurrentTableSize
);
519 CurrentTableList
->Handle
= AcpiTableInstance
->CurrentHandle
++;
520 *Handle
= CurrentTableList
->Handle
;
521 CurrentTableList
->Version
= Version
;
524 // Update internal pointers if this is a required table. If it is a required
525 // table and a table of that type already exists, return an error.
527 // Calculate the checksum if the table is not FACS.
529 switch (CurrentTableSignature
) {
531 case EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
533 // We don't add the FADT in the standard way because some
534 // OS expect the FADT to be early in the table list.
535 // So we always add it as the first element in the list.
540 // Check that the table has not been previously added.
542 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Fadt1
!= NULL
) ||
543 ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 && AcpiTableInstance
->Fadt3
!= NULL
) ||
544 ((Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0 && AcpiTableInstance
->Fadt3
!= NULL
)
546 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
547 gBS
->FreePool (CurrentTableList
);
551 // Add the table to the appropriate table version
553 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
555 // Save a pointer to the table
557 AcpiTableInstance
->Fadt1
= (EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE
*) CurrentTableList
->Table
;
560 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
562 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs1
;
563 AcpiTableInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt1
;
566 // RSDP OEM information is updated to match the FADT OEM information
569 &AcpiTableInstance
->Rsdp1
->OemId
,
570 &AcpiTableInstance
->Fadt1
->Header
.OemId
,
575 // RSDT OEM information is updated to match the FADT OEM information.
578 &AcpiTableInstance
->Rsdt1
->OemId
,
579 &AcpiTableInstance
->Fadt1
->Header
.OemId
,
584 &AcpiTableInstance
->Rsdt1
->OemTableId
,
585 &AcpiTableInstance
->Fadt1
->Header
.OemTableId
,
588 AcpiTableInstance
->Rsdt1
->OemRevision
= AcpiTableInstance
->Fadt1
->Header
.OemRevision
;
591 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
592 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
594 // Save a pointer to the table
596 AcpiTableInstance
->Fadt3
= (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE
*) CurrentTableList
->Table
;
599 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
601 if (AcpiTableInstance
->Fadt3
!= NULL
) {
602 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs3
;
603 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Facs3
;
605 &AcpiTableInstance
->Fadt3
->XFirmwareCtrl
,
609 AcpiTableInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt3
;
610 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Dsdt3
;
612 &AcpiTableInstance
->Fadt3
->XDsdt
,
618 // RSDP OEM information is updated to match the FADT OEM information
621 &AcpiTableInstance
->Rsdp3
->OemId
,
622 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
627 // RSDT OEM information is updated to match FADT OEM information.
630 &AcpiTableInstance
->Rsdt3
->OemId
,
631 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
635 &AcpiTableInstance
->Rsdt3
->OemTableId
,
636 &AcpiTableInstance
->Fadt3
->Header
.OemTableId
,
639 AcpiTableInstance
->Rsdt3
->OemRevision
= AcpiTableInstance
->Fadt3
->Header
.OemRevision
;
642 // XSDT OEM information is updated to match FADT OEM information.
645 &AcpiTableInstance
->Xsdt
->OemId
,
646 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
650 &AcpiTableInstance
->Xsdt
->OemTableId
,
651 &AcpiTableInstance
->Fadt3
->Header
.OemTableId
,
654 AcpiTableInstance
->Xsdt
->OemRevision
= AcpiTableInstance
->Fadt3
->Header
.OemRevision
;
658 // Checksum the table
661 AcpiPlatformChecksum (
662 CurrentTableList
->Table
,
663 CurrentTableList
->Table
->Length
,
664 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
670 case EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
672 // Check that the table has not been previously added.
674 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Facs1
!= NULL
) ||
675 ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 && AcpiTableInstance
->Facs3
!= NULL
) ||
676 ((Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0 && AcpiTableInstance
->Facs3
!= NULL
)
678 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
679 gBS
->FreePool (CurrentTableList
);
683 // FACS is referenced by FADT and is not part of RSDT
688 // Add the table to the appropriate table version
690 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
692 // Save a pointer to the table
694 AcpiTableInstance
->Facs1
= (EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
697 // If FADT already exists, update table pointers.
699 if (AcpiTableInstance
->Fadt1
!= NULL
) {
700 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs1
;
703 // Checksum FADT table
705 AcpiPlatformChecksum (
706 AcpiTableInstance
->Fadt1
,
707 AcpiTableInstance
->Fadt1
->Header
.Length
,
708 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
714 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
715 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
717 // Save a pointer to the table
719 AcpiTableInstance
->Facs3
= (EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
722 // If FADT already exists, update table pointers.
724 if (AcpiTableInstance
->Fadt3
!= NULL
) {
725 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs3
;
726 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Facs3
;
728 &AcpiTableInstance
->Fadt3
->XFirmwareCtrl
,
734 // Checksum FADT table
736 AcpiPlatformChecksum (
737 AcpiTableInstance
->Fadt3
,
738 AcpiTableInstance
->Fadt3
->Header
.Length
,
739 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
747 case EFI_ACPI_1_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
749 // Check that the table has not been previously added.
751 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Dsdt1
!= NULL
) ||
752 ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 && AcpiTableInstance
->Dsdt3
!= NULL
) ||
753 ((Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0 && AcpiTableInstance
->Dsdt3
!= NULL
)
755 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
756 gBS
->FreePool (CurrentTableList
);
760 // DSDT is referenced by FADT and is not part of RSDT
765 // Add the table to the appropriate table version
767 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
769 // Save a pointer to the table
771 AcpiTableInstance
->Dsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
774 // If FADT already exists, update table pointers.
776 if (AcpiTableInstance
->Fadt1
!= NULL
) {
777 AcpiTableInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt1
;
780 // Checksum FADT table
782 AcpiPlatformChecksum (
783 AcpiTableInstance
->Fadt1
,
784 AcpiTableInstance
->Fadt1
->Header
.Length
,
785 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
791 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
792 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
794 // Save a pointer to the table
796 AcpiTableInstance
->Dsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
799 // If FADT already exists, update table pointers.
801 if (AcpiTableInstance
->Fadt3
!= NULL
) {
802 AcpiTableInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt3
;
803 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Dsdt3
;
805 &AcpiTableInstance
->Fadt3
->XDsdt
,
811 // Checksum FADT table
813 AcpiPlatformChecksum (
814 AcpiTableInstance
->Fadt3
,
815 AcpiTableInstance
->Fadt3
->Header
.Length
,
816 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
822 // Checksum the table
825 AcpiPlatformChecksum (
826 CurrentTableList
->Table
,
827 CurrentTableList
->Table
->Length
,
828 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
836 // Checksum the table
839 AcpiPlatformChecksum (
840 CurrentTableList
->Table
,
841 CurrentTableList
->Table
->Length
,
842 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
849 // Add the table to the current list of tables
851 InsertTailList (&AcpiTableInstance
->TableList
, &CurrentTableList
->Link
);
854 // Add the table to RSDT and/or XSDT table entry lists.
857 // Add to ACPI 1.0b table tree
859 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
860 CurrentRsdtEntry
= (UINT32
*)
862 (UINT8
*) AcpiTableInstance
->Rsdt1
+
863 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
864 AcpiTableInstance
->NumberOfTableEntries1
*
869 // Add entry to the RSDT unless its the FACS or DSDT
872 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
875 // Update RSDT length
877 AcpiTableInstance
->Rsdt1
->Length
= AcpiTableInstance
->Rsdt1
->Length
+ sizeof (UINT32
);
879 AcpiTableInstance
->NumberOfTableEntries1
++;
882 ASSERT (AcpiTableInstance
->NumberOfTableEntries1
<= EFI_ACPI_MAX_NUM_TABLES
);
885 // Add to ACPI 2.0/3.0 table tree
887 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
888 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
891 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
892 // If it becomes necessary to maintain separate table lists, changes will be required.
894 CurrentRsdtEntry
= (UINT32
*)
896 (UINT8
*) AcpiTableInstance
->Rsdt3
+
897 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
898 AcpiTableInstance
->NumberOfTableEntries3
*
903 // This pointer must not be directly dereferenced as the XSDT entries may not
904 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
906 CurrentXsdtEntry
= (VOID
*)
908 (UINT8
*) AcpiTableInstance
->Xsdt
+
909 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
910 AcpiTableInstance
->NumberOfTableEntries3
*
915 // Add entry to the RSDT
917 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
920 // Update RSDT length
922 AcpiTableInstance
->Rsdt3
->Length
= AcpiTableInstance
->Rsdt3
->Length
+ sizeof (UINT32
);
925 // Add entry to XSDT, XSDT expects 64 bit pointers, but
926 // the table pointers in XSDT are not aligned on 8 byte boundary.
928 Buffer64
= (UINT64
) (UINTN
) CurrentTableList
->Table
;
938 AcpiTableInstance
->Xsdt
->Length
= AcpiTableInstance
->Xsdt
->Length
+ sizeof (UINT64
);
940 AcpiTableInstance
->NumberOfTableEntries3
++;
943 ASSERT (AcpiTableInstance
->NumberOfTableEntries3
<= EFI_ACPI_MAX_NUM_TABLES
);
946 ChecksumCommonTables (AcpiTableInstance
);
952 This function finds the table specified by the handle and returns a pointer to it.
953 If the handle is not found, EFI_NOT_FOUND is returned and the contents of Table are
956 @param Handle Table to find.
957 @param TableList Table list to search
958 @param Table Pointer to table found.
960 @return EFI_SUCCESS The function completed successfully.
961 @return EFI_NOT_FOUND No table found matching the handle specified.
967 IN LIST_ENTRY
*TableList
,
968 OUT EFI_ACPI_TABLE_LIST
**Table
971 LIST_ENTRY
*CurrentLink
;
972 EFI_ACPI_TABLE_LIST
*CurrentTable
;
975 // Check for invalid input parameters
982 CurrentLink
= TableList
->ForwardLink
;
984 while (CurrentLink
!= TableList
) {
985 CurrentTable
= EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink
);
986 if (CurrentTable
->Handle
== Handle
) {
988 // Found handle, so return this table.
990 *Table
= CurrentTable
;
994 CurrentLink
= CurrentLink
->ForwardLink
;
999 return EFI_NOT_FOUND
;
1004 This function removes a basic table from the RSDT and/or XSDT.
1005 For Acpi 1.0 tables, pass in the Rsdt.
1006 For Acpi 2.0 tables, pass in both Rsdt and Xsdt.
1008 @param Table Pointer to table found.
1009 @param NumberOfTableEntries Current number of table entries in the RSDT/XSDT
1010 @param Rsdt Pointer to the RSDT to remove from
1011 @param Xsdt Pointer to the Xsdt to remove from
1013 @return EFI_SUCCESS The function completed successfully.
1014 @return EFI_INVALID_PARAMETER The table was not found in both Rsdt and Xsdt.
1018 RemoveTableFromRsdt (
1019 IN OUT EFI_ACPI_TABLE_LIST
* Table
,
1020 IN OUT UINTN
*NumberOfTableEntries
,
1021 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Rsdt
,
1022 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Xsdt OPTIONAL
1025 UINT32
*CurrentRsdtEntry
;
1026 VOID
*CurrentXsdtEntry
;
1027 UINT64 CurrentTablePointer64
;
1031 // Check for invalid input parameters
1034 ASSERT (NumberOfTableEntries
);
1038 // Find the table entry in the RSDT and XSDT
1040 for (Index
= 0; Index
< *NumberOfTableEntries
; Index
++) {
1042 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
1043 // If it becomes necessary to maintain separate table lists, changes will be required.
1045 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) Rsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + Index
* sizeof (UINT32
));
1048 // This pointer must not be directly dereferenced as the XSDT entries may not
1049 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
1051 CurrentXsdtEntry
= (VOID
*) ((UINT8
*) Xsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + Index
* sizeof (UINT64
));
1054 // Read the entry value out of the XSDT
1056 CopyMem (&CurrentTablePointer64
, CurrentXsdtEntry
, sizeof (UINT64
));
1059 // Initialize to NULL
1061 CurrentXsdtEntry
= 0;
1062 CurrentTablePointer64
= 0;
1065 // Check if we have found the corresponding entry in both RSDT and XSDT
1067 if (*CurrentRsdtEntry
== (UINT32
) (UINTN
) Table
->Table
&&
1068 ((Xsdt
== NULL
) || CurrentTablePointer64
== (UINT64
) (UINTN
) Table
->Table
)
1071 // Found entry, so copy all following entries and shrink table
1072 // We actually copy all + 1 to copy the initialized value of memory over
1075 CopyMem (CurrentRsdtEntry
, CurrentRsdtEntry
+ 1, (*NumberOfTableEntries
- Index
) * sizeof (UINT32
));
1076 Rsdt
->Length
= Rsdt
->Length
- sizeof (UINT32
);
1078 CopyMem (CurrentXsdtEntry
, ((UINT64
*) CurrentXsdtEntry
) + 1, (*NumberOfTableEntries
- Index
) * sizeof (UINT64
));
1079 Xsdt
->Length
= Xsdt
->Length
- sizeof (UINT64
);
1082 } else if (Index
+ 1 == *NumberOfTableEntries
) {
1084 // At the last entry, and table not found
1086 return EFI_INVALID_PARAMETER
;
1090 // Checksum the tables
1092 AcpiPlatformChecksum (
1095 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1100 AcpiPlatformChecksum (
1103 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1108 // Decrement the number of tables
1110 (*NumberOfTableEntries
)--;
1117 This function removes a table and frees any associated memory.
1119 @param AcpiTableInstance Instance of the protocol.
1120 @param Version Version(s) to delete.
1121 @param Table Pointer to table found.
1123 @return EFI_SUCCESS The function completed successfully.
1128 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
1129 IN EFI_ACPI_TABLE_VERSION Version
,
1130 IN OUT EFI_ACPI_TABLE_LIST
*Table
1133 UINT32 CurrentTableSignature
;
1134 BOOLEAN RemoveFromRsdt
;
1137 // Check for invalid input parameters
1139 ASSERT (AcpiTableInstance
);
1145 RemoveFromRsdt
= TRUE
;
1147 // Check for Table->Table
1149 ASSERT (Table
->Table
!= NULL
);
1150 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
->Table
)->Signature
;
1153 // Basic tasks to accomplish delete are:
1154 // Determine removal requirements (in RSDT/XSDT or not)
1155 // Remove entry from RSDT/XSDT
1156 // Remove any table references to the table
1157 // If no one is using the table
1158 // Free the table (removing pointers from private data and tables)
1160 // Free list structure
1163 // Determine if this table is in the RSDT or XSDT
1165 if ((CurrentTableSignature
== EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) ||
1166 (CurrentTableSignature
== EFI_ACPI_2_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
) ||
1167 (CurrentTableSignature
== EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
)
1169 RemoveFromRsdt
= FALSE
;
1172 // We don't remove the FADT in the standard way because some
1173 // OS expect the FADT to be early in the table list.
1174 // So we always put it as the first element in the list.
1176 if (CurrentTableSignature
== EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
) {
1177 RemoveFromRsdt
= FALSE
;
1181 // Remove the table from RSDT and XSDT
1183 if (Table
->Table
!= NULL
) {
1185 // This is a basic table, remove it from any lists and the Rsdt and/or Xsdt
1187 if (Version
& EFI_ACPI_TABLE_VERSION_NONE
& Table
->Version
) {
1189 // Remove this version from the table
1191 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_NONE
;
1194 if (Version
& EFI_ACPI_TABLE_VERSION_1_0B
& Table
->Version
) {
1196 // Remove this version from the table
1198 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_1_0B
;
1201 // Remove from Rsdt. We don't care about the return value because it is
1202 // acceptable for the table to not exist in Rsdt.
1203 // We didn't add some tables so we don't remove them.
1205 if (RemoveFromRsdt
) {
1206 RemoveTableFromRsdt (
1208 &AcpiTableInstance
->NumberOfTableEntries1
,
1209 AcpiTableInstance
->Rsdt1
,
1215 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
& Table
->Version
) ||
1216 (Version
& EFI_ACPI_TABLE_VERSION_3_0
& Table
->Version
)) {
1218 // Remove this version from the table
1220 if (Version
& EFI_ACPI_TABLE_VERSION_2_0
& Table
->Version
) {
1221 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_2_0
;
1223 if (Version
& EFI_ACPI_TABLE_VERSION_3_0
& Table
->Version
) {
1224 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_3_0
;
1228 // Remove from Rsdt and Xsdt. We don't care about the return value
1229 // because it is acceptable for the table to not exist in Rsdt/Xsdt.
1230 // We didn't add some tables so we don't remove them.
1232 if (RemoveFromRsdt
) {
1233 RemoveTableFromRsdt (
1235 &AcpiTableInstance
->NumberOfTableEntries3
,
1236 AcpiTableInstance
->Rsdt3
,
1237 AcpiTableInstance
->Xsdt
1242 // Free the table, clean up any dependent tables and our private data pointers.
1244 switch (Table
->Table
->Signature
) {
1246 case EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
1247 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1248 AcpiTableInstance
->Fadt1
= NULL
;
1251 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
1252 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1253 AcpiTableInstance
->Fadt3
= NULL
;
1257 case EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
1258 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1259 AcpiTableInstance
->Facs1
= NULL
;
1262 // Update FADT table pointers
1264 if (AcpiTableInstance
->Fadt1
!= NULL
) {
1265 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= 0;
1270 AcpiPlatformChecksum (
1271 AcpiTableInstance
->Fadt1
,
1272 AcpiTableInstance
->Fadt1
->Header
.Length
,
1273 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1279 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
1280 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1281 AcpiTableInstance
->Facs3
= NULL
;
1284 // Update FADT table pointers
1286 if (AcpiTableInstance
->Fadt3
!= NULL
) {
1287 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= 0;
1288 ZeroMem (&AcpiTableInstance
->Fadt3
->XFirmwareCtrl
, sizeof (UINT64
));
1293 AcpiPlatformChecksum (
1294 AcpiTableInstance
->Fadt3
,
1295 AcpiTableInstance
->Fadt3
->Header
.Length
,
1296 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1303 case EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
1304 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1305 AcpiTableInstance
->Dsdt1
= NULL
;
1308 // Update FADT table pointers
1310 if (AcpiTableInstance
->Fadt1
!= NULL
) {
1311 AcpiTableInstance
->Fadt1
->Dsdt
= 0;
1316 AcpiPlatformChecksum (
1317 AcpiTableInstance
->Fadt1
,
1318 AcpiTableInstance
->Fadt1
->Header
.Length
,
1319 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1326 if ((Version
& EFI_ACPI_TABLE_VERSION_2_0
) != 0 ||
1327 (Version
& EFI_ACPI_TABLE_VERSION_3_0
) != 0) {
1328 AcpiTableInstance
->Dsdt3
= NULL
;
1331 // Update FADT table pointers
1333 if (AcpiTableInstance
->Fadt3
!= NULL
) {
1334 AcpiTableInstance
->Fadt3
->Dsdt
= 0;
1335 ZeroMem (&AcpiTableInstance
->Fadt3
->XDsdt
, sizeof (UINT64
));
1340 AcpiPlatformChecksum (
1341 AcpiTableInstance
->Fadt3
,
1342 AcpiTableInstance
->Fadt3
->Header
.Length
,
1343 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1358 // If no version is using this table anymore, remove and free list entry.
1360 if (Table
->Version
== 0) {
1364 gBS
->FreePages (Table
->PageAddress
, Table
->NumberOfPages
);
1365 RemoveEntryList (&(Table
->Link
));
1366 gBS
->FreePool (Table
);
1376 This function finds and removes the table specified by the handle.
1378 @param AcpiTableInstance Instance of the protocol.
1379 @param Version Bitmask of which versions to remove.
1380 @param Handle Table to remove.
1382 @return EFI_SUCCESS The function completed successfully.
1383 @return EFI_ABORTED An error occurred.
1384 @return EFI_NOT_FOUND Handle not found in table list.
1388 RemoveTableFromList (
1389 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
1390 IN EFI_ACPI_TABLE_VERSION Version
,
1394 EFI_ACPI_TABLE_LIST
*Table
;
1398 // Check for invalid input parameters
1400 ASSERT (AcpiTableInstance
);
1405 Status
= FindTableByHandle (
1407 &AcpiTableInstance
->TableList
,
1410 if (EFI_ERROR (Status
)) {
1411 return EFI_NOT_FOUND
;
1416 Status
= DeleteTable (AcpiTableInstance
, Version
, Table
);
1417 if (EFI_ERROR (Status
)) {
1421 // Completed successfully
1428 This function calculates and updates an UINT8 checksum.
1430 @param Buffer Pointer to buffer to checksum
1431 @param Size Number of bytes to checksum
1432 @param ChecksumOffset Offset to place the checksum result in
1434 @return EFI_SUCCESS The function completed successfully.
1438 AcpiPlatformChecksum (
1441 IN UINTN ChecksumOffset
1449 // Initialize pointer
1454 // set checksum to 0 first
1456 Ptr
[ChecksumOffset
] = 0;
1459 // add all content of buffer
1461 while ((Size
--) != 0) {
1462 Sum
= (UINT8
) (Sum
+ (*Ptr
++));
1468 Ptr
[ChecksumOffset
] = (UINT8
) (0xff - Sum
+ 1);
1475 Checksum all versions of the common tables, RSDP, RSDT, XSDT.
1477 @param AcpiTableInstance Protocol instance private data.
1479 @return EFI_SUCCESS The function completed successfully.
1483 ChecksumCommonTables (
1484 IN OUT EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
1488 // RSDP ACPI 1.0 checksum for 1.0 table. This is only the first 20 bytes of the structure
1490 AcpiPlatformChecksum (
1491 AcpiTableInstance
->Rsdp1
,
1492 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1493 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1498 // RSDP ACPI 1.0 checksum for 2.0/3.0 table. This is only the first 20 bytes of the structure
1500 AcpiPlatformChecksum (
1501 AcpiTableInstance
->Rsdp3
,
1502 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1503 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1508 // RSDP ACPI 2.0/3.0 checksum, this is the entire table
1510 AcpiPlatformChecksum (
1511 AcpiTableInstance
->Rsdp3
,
1512 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1513 OFFSET_OF (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1520 AcpiPlatformChecksum (
1521 AcpiTableInstance
->Rsdt1
,
1522 AcpiTableInstance
->Rsdt1
->Length
,
1523 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1527 AcpiPlatformChecksum (
1528 AcpiTableInstance
->Rsdt3
,
1529 AcpiTableInstance
->Rsdt3
->Length
,
1530 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1537 AcpiPlatformChecksum (
1538 AcpiTableInstance
->Xsdt
,
1539 AcpiTableInstance
->Xsdt
->Length
,
1540 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1549 Constructor for the ACPI table protocol. Initializes instance
1552 @param AcpiTableInstance Instance to construct
1554 @return EFI_SUCCESS Instance initialized.
1555 @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
1559 AcpiTableAcpiTableConstructor (
1560 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
1567 EFI_PHYSICAL_ADDRESS PageAddress
;
1570 // Check for invalid input parameters
1572 ASSERT (AcpiTableInstance
);
1574 InitializeListHead (&AcpiTableInstance
->TableList
);
1575 AcpiTableInstance
->CurrentHandle
= 1;
1577 AcpiTableInstance
->AcpiTableProtocol
.InstallAcpiTable
= InstallAcpiTable
;
1578 AcpiTableInstance
->AcpiTableProtocol
.UninstallAcpiTable
= UninstallAcpiTable
;
1580 // Create RSDP, RSDT, XSDT structures
1581 // Allocate all buffers
1583 TotalSize
= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
) +
1584 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
) +
1585 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
1586 EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
) +
1587 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
1588 EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
) +
1589 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
1590 EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT64
);
1593 // Allocate memory in the lower 32 bit of address range for
1594 // compatibility with ACPI 1.0 OS.
1596 // This is done because ACPI 1.0 pointers are 32 bit values.
1597 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
1598 // There is no architectural reason these should be below 4GB, it is purely
1599 // for convenience of implementation that we force memory below 4GB.
1601 PageAddress
= 0xFFFFFFFF;
1602 Status
= gBS
->AllocatePages (
1604 EfiACPIReclaimMemory
,
1605 EFI_SIZE_TO_PAGES (TotalSize
),
1609 if (EFI_ERROR (Status
)) {
1610 return EFI_OUT_OF_RESOURCES
;
1613 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
1614 ZeroMem (Pointer
, TotalSize
);
1616 AcpiTableInstance
->Rsdp1
= (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1617 Pointer
+= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1618 AcpiTableInstance
->Rsdp3
= (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1619 Pointer
+= sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1621 AcpiTableInstance
->Rsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1622 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1623 AcpiTableInstance
->Rsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1624 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1626 AcpiTableInstance
->Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1631 CurrentData
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1632 CopyMem (&AcpiTableInstance
->Rsdp1
->Signature
, &CurrentData
, sizeof (UINT64
));
1633 CopyMem (AcpiTableInstance
->Rsdp1
->OemId
, EFI_ACPI_OEM_ID
, 6);
1634 AcpiTableInstance
->Rsdp1
->Reserved
= EFI_ACPI_RESERVED_BYTE
;
1635 AcpiTableInstance
->Rsdp1
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt1
;
1637 CurrentData
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1638 CopyMem (&AcpiTableInstance
->Rsdp3
->Signature
, &CurrentData
, sizeof (UINT64
));
1639 CopyMem (AcpiTableInstance
->Rsdp3
->OemId
, EFI_ACPI_OEM_ID
, 6);
1640 AcpiTableInstance
->Rsdp3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION
;
1641 AcpiTableInstance
->Rsdp3
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt3
;
1642 AcpiTableInstance
->Rsdp3
->Length
= sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1643 CurrentData
= (UINT64
) (UINTN
) AcpiTableInstance
->Xsdt
;
1644 CopyMem (&AcpiTableInstance
->Rsdp3
->XsdtAddress
, &CurrentData
, sizeof (UINT64
));
1645 SetMem (AcpiTableInstance
->Rsdp3
->Reserved
, 3, EFI_ACPI_RESERVED_BYTE
);
1650 // Note that we "reserve" one entry for the FADT so it can always be
1651 // at the beginning of the list of tables. Some OS don't seem
1652 // to find it correctly if it is too far down the list.
1654 AcpiTableInstance
->Rsdt1
->Signature
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1655 AcpiTableInstance
->Rsdt1
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1656 AcpiTableInstance
->Rsdt1
->Revision
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1657 CopyMem (AcpiTableInstance
->Rsdt1
->OemId
, EFI_ACPI_OEM_ID
, 6);
1658 CurrentData
= EFI_ACPI_OEM_TABLE_ID
;
1659 CopyMem (&AcpiTableInstance
->Rsdt1
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1660 AcpiTableInstance
->Rsdt1
->OemRevision
= EFI_ACPI_OEM_REVISION
;
1661 AcpiTableInstance
->Rsdt1
->CreatorId
= EFI_ACPI_CREATOR_ID
;
1662 AcpiTableInstance
->Rsdt1
->CreatorRevision
= EFI_ACPI_CREATOR_REVISION
;
1664 // We always reserve first one for FADT
1666 AcpiTableInstance
->NumberOfTableEntries1
= 1;
1667 AcpiTableInstance
->Rsdt1
->Length
= AcpiTableInstance
->Rsdt1
->Length
+ sizeof(UINT32
);
1669 AcpiTableInstance
->Rsdt3
->Signature
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1670 AcpiTableInstance
->Rsdt3
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1671 AcpiTableInstance
->Rsdt3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1672 CopyMem (AcpiTableInstance
->Rsdt3
->OemId
, EFI_ACPI_OEM_ID
, 6);
1673 CurrentData
= EFI_ACPI_OEM_TABLE_ID
;
1674 CopyMem (&AcpiTableInstance
->Rsdt3
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1675 AcpiTableInstance
->Rsdt3
->OemRevision
= EFI_ACPI_OEM_REVISION
;
1676 AcpiTableInstance
->Rsdt3
->CreatorId
= EFI_ACPI_CREATOR_ID
;
1677 AcpiTableInstance
->Rsdt3
->CreatorRevision
= EFI_ACPI_CREATOR_REVISION
;
1679 // We always reserve first one for FADT
1681 AcpiTableInstance
->NumberOfTableEntries3
= 1;
1682 AcpiTableInstance
->Rsdt3
->Length
= AcpiTableInstance
->Rsdt3
->Length
+ sizeof(UINT32
);
1687 AcpiTableInstance
->Xsdt
->Signature
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1688 AcpiTableInstance
->Xsdt
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1689 AcpiTableInstance
->Xsdt
->Revision
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1690 CopyMem (AcpiTableInstance
->Xsdt
->OemId
, EFI_ACPI_OEM_ID
, 6);
1691 CurrentData
= EFI_ACPI_OEM_TABLE_ID
;
1692 CopyMem (&AcpiTableInstance
->Xsdt
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1693 AcpiTableInstance
->Xsdt
->OemRevision
= EFI_ACPI_OEM_REVISION
;
1694 AcpiTableInstance
->Xsdt
->CreatorId
= EFI_ACPI_CREATOR_ID
;
1695 AcpiTableInstance
->Xsdt
->CreatorRevision
= EFI_ACPI_CREATOR_REVISION
;
1697 // We always reserve first one for FADT
1699 AcpiTableInstance
->Xsdt
->Length
= AcpiTableInstance
->Xsdt
->Length
+ sizeof(UINT64
);
1701 ChecksumCommonTables (AcpiTableInstance
);
1704 // Completed successfully