2 ACPI Table Protocol Implementation
4 Copyright (c) 2006 - 2015, 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 publishes the specified versions of the ACPI tables by
103 installing EFI configuration table entries for them. Any combination of
104 table versions can be published.
106 @param AcpiTableInstance Instance of the protocol.
107 @param Version Version(s) to publish.
109 @return EFI_SUCCESS The function completed successfully.
110 @return EFI_ABORTED The function could not complete successfully.
116 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
117 IN EFI_ACPI_TABLE_VERSION Version
121 UINT32
*CurrentRsdtEntry
;
122 VOID
*CurrentXsdtEntry
;
126 // Reorder tables as some operating systems don't seem to find the
127 // FADT correctly if it is not in the first few entries
131 // Add FADT as the first entry
133 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
134 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) AcpiTableInstance
->Rsdt1
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
135 *CurrentRsdtEntry
= (UINT32
) (UINTN
) AcpiTableInstance
->Fadt1
;
137 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
138 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) AcpiTableInstance
->Rsdt3
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
139 *CurrentRsdtEntry
= (UINT32
) (UINTN
) AcpiTableInstance
->Fadt3
;
140 CurrentXsdtEntry
= (VOID
*) ((UINT8
*) AcpiTableInstance
->Xsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
142 // Add entry to XSDT, XSDT expects 64 bit pointers, but
143 // the table pointers in XSDT are not aligned on 8 byte boundary.
145 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Fadt3
;
154 // Do checksum again because Dsdt/Xsdt is updated.
156 ChecksumCommonTables (AcpiTableInstance
);
159 // Add the RSD_PTR to the system table and store that we have installed the
162 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) &&
163 !AcpiTableInstance
->TablesInstalled1
) {
164 Status
= gBS
->InstallConfigurationTable (&gEfiAcpi10TableGuid
, AcpiTableInstance
->Rsdp1
);
165 if (EFI_ERROR (Status
)) {
169 AcpiTableInstance
->TablesInstalled1
= TRUE
;
172 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) &&
173 !AcpiTableInstance
->TablesInstalled3
) {
174 Status
= gBS
->InstallConfigurationTable (&gEfiAcpiTableGuid
, AcpiTableInstance
->Rsdp3
);
175 if (EFI_ERROR (Status
)) {
179 AcpiTableInstance
->TablesInstalled3
= TRUE
;
187 Installs an ACPI table into the RSDT/XSDT.
188 Note that the ACPI table should be checksumed before installing it.
189 Otherwise it will assert.
191 @param This Protocol instance pointer.
192 @param AcpiTableBuffer A pointer to a buffer containing the ACPI table to be installed.
193 @param AcpiTableBufferSize Specifies the size, in bytes, of the AcpiTableBuffer buffer.
194 @param TableKey Reurns a key to refer to the ACPI table.
196 @return EFI_SUCCESS The table was successfully inserted.
197 @return EFI_INVALID_PARAMETER Either AcpiTableBuffer is NULL, TableKey is NULL, or AcpiTableBufferSize
198 and the size field embedded in the ACPI table pointed to by AcpiTableBuffer
200 @return EFI_OUT_OF_RESOURCES Insufficient resources exist to complete the request.
201 @retval EFI_ACCESS_DENIED The table signature matches a table already
202 present in the system and platform policy
203 does not allow duplicate tables of this type.
209 IN EFI_ACPI_TABLE_PROTOCOL
*This
,
210 IN VOID
*AcpiTableBuffer
,
211 IN UINTN AcpiTableBufferSize
,
215 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
;
217 VOID
*AcpiTableBufferConst
;
220 // Check for invalid input parameters
222 if ((AcpiTableBuffer
== NULL
) || (TableKey
== NULL
)
223 || (((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTableBuffer
)->Length
!= AcpiTableBufferSize
)) {
224 return EFI_INVALID_PARAMETER
;
228 // Get the instance of the ACPI table protocol
230 AcpiTableInstance
= EFI_ACPI_TABLE_INSTANCE_FROM_THIS (This
);
233 // Install the ACPI table
235 AcpiTableBufferConst
= AllocateCopyPool (AcpiTableBufferSize
,AcpiTableBuffer
);
237 Status
= AddTableToList (
239 AcpiTableBufferConst
,
241 EFI_ACPI_TABLE_VERSION_1_0B
| ACPI_TABLE_VERSION_GTE_2_0
,
244 if (!EFI_ERROR (Status
)) {
245 Status
= PublishTables (
247 EFI_ACPI_TABLE_VERSION_1_0B
| ACPI_TABLE_VERSION_GTE_2_0
250 FreePool (AcpiTableBufferConst
);
253 // Add a new table successfully, notify registed callback
255 if (FeaturePcdGet (PcdInstallAcpiSdtProtocol
)) {
256 if (!EFI_ERROR (Status
)) {
259 EFI_ACPI_TABLE_VERSION_1_0B
| ACPI_TABLE_VERSION_GTE_2_0
,
270 Removes an ACPI table from the RSDT/XSDT.
272 @param This Protocol instance pointer.
273 @param TableKey Specifies the table to uninstall. The key was returned from InstallAcpiTable().
275 @return EFI_SUCCESS The table was successfully uninstalled.
276 @return EFI_NOT_FOUND TableKey does not refer to a valid key for a table entry.
282 IN EFI_ACPI_TABLE_PROTOCOL
*This
,
286 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
;
290 // Get the instance of the ACPI table protocol
292 AcpiTableInstance
= EFI_ACPI_TABLE_INSTANCE_FROM_THIS (This
);
295 // Uninstall the ACPI table
297 Status
= RemoveTableFromList (
299 EFI_ACPI_TABLE_VERSION_1_0B
| ACPI_TABLE_VERSION_GTE_2_0
,
302 if (!EFI_ERROR (Status
)) {
303 Status
= PublishTables (
305 EFI_ACPI_TABLE_VERSION_1_0B
| ACPI_TABLE_VERSION_GTE_2_0
309 if (EFI_ERROR (Status
)) {
310 return EFI_NOT_FOUND
;
317 If the number of APCI tables exceeds the preallocated max table number, enlarge the table buffer.
319 @param AcpiTableInstance ACPI table protocol instance data structure.
321 @return EFI_SUCCESS reallocate the table beffer successfully.
322 @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
326 ReallocateAcpiTableBuffer (
327 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
330 UINTN NewMaxTableNumber
;
333 EFI_PHYSICAL_ADDRESS PageAddress
;
334 EFI_ACPI_TABLE_INSTANCE TempPrivateData
;
338 CopyMem (&TempPrivateData
, AcpiTableInstance
, sizeof (EFI_ACPI_TABLE_INSTANCE
));
340 // Enlarge the max table number from mEfiAcpiMaxNumTables to mEfiAcpiMaxNumTables + EFI_ACPI_MAX_NUM_TABLES
342 NewMaxTableNumber
= mEfiAcpiMaxNumTables
+ EFI_ACPI_MAX_NUM_TABLES
;
344 // Create RSDT, XSDT structures and allocate buffers.
346 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
347 NewMaxTableNumber
* sizeof (UINT32
) +
348 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
349 NewMaxTableNumber
* sizeof (UINT32
) +
350 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
351 NewMaxTableNumber
* sizeof (UINT64
);
354 // Allocate memory in the lower 32 bit of address range for
355 // compatibility with ACPI 1.0 OS.
357 // This is done because ACPI 1.0 pointers are 32 bit values.
358 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
359 // There is no architectural reason these should be below 4GB, it is purely
360 // for convenience of implementation that we force memory below 4GB.
362 PageAddress
= 0xFFFFFFFF;
363 Status
= gBS
->AllocatePages (
365 EfiACPIReclaimMemory
,
366 EFI_SIZE_TO_PAGES (TotalSize
),
370 if (EFI_ERROR (Status
)) {
371 return EFI_OUT_OF_RESOURCES
;
374 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
375 ZeroMem (Pointer
, TotalSize
);
377 AcpiTableInstance
->Rsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
378 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + NewMaxTableNumber
* sizeof (UINT32
));
379 AcpiTableInstance
->Rsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
380 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + NewMaxTableNumber
* sizeof (UINT32
));
381 AcpiTableInstance
->Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
384 // Update RSDP to point to the new Rsdt and Xsdt address.
386 AcpiTableInstance
->Rsdp1
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt1
;
387 AcpiTableInstance
->Rsdp3
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt3
;
388 CurrentData
= (UINT64
) (UINTN
) AcpiTableInstance
->Xsdt
;
389 CopyMem (&AcpiTableInstance
->Rsdp3
->XsdtAddress
, &CurrentData
, sizeof (UINT64
));
392 // copy the original Rsdt1, Rsdt3 and Xsdt structure to new buffer
394 CopyMem (AcpiTableInstance
->Rsdt1
, TempPrivateData
.Rsdt1
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT32
)));
395 CopyMem (AcpiTableInstance
->Rsdt3
, TempPrivateData
.Rsdt3
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT32
)));
396 CopyMem (AcpiTableInstance
->Xsdt
, TempPrivateData
.Xsdt
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT64
)));
399 // Calculate orignal ACPI table buffer size
401 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
402 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
403 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
404 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
405 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
406 mEfiAcpiMaxNumTables
* sizeof (UINT64
);
407 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
)(UINTN
)TempPrivateData
.Rsdt1
, EFI_SIZE_TO_PAGES (TotalSize
));
410 // Update the Max ACPI table number
412 mEfiAcpiMaxNumTables
= NewMaxTableNumber
;
416 This function adds an ACPI table to the table list. It will detect FACS and
417 allocate the correct type of memory and properly align the table.
419 @param AcpiTableInstance Instance of the protocol.
420 @param Table Table to add.
421 @param Checksum Does the table require checksumming.
422 @param Version The version of the list to add the table to.
423 @param Handle Pointer for returning the handle.
425 @return EFI_SUCCESS The function completed successfully.
426 @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
427 @retval EFI_ACCESS_DENIED The table signature matches a table already
428 present in the system and platform policy
429 does not allow duplicate tables of this type.
434 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
437 IN EFI_ACPI_TABLE_VERSION Version
,
442 EFI_ACPI_TABLE_LIST
*CurrentTableList
;
443 UINT32 CurrentTableSignature
;
444 UINT32 CurrentTableSize
;
445 UINT32
*CurrentRsdtEntry
;
446 VOID
*CurrentXsdtEntry
;
451 // Check for invalid input parameters
453 ASSERT (AcpiTableInstance
);
463 // Create a new list entry
465 CurrentTableList
= AllocatePool (sizeof (EFI_ACPI_TABLE_LIST
));
466 ASSERT (CurrentTableList
);
469 // Determine table type and size
471 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
)->Signature
;
472 CurrentTableSize
= ((EFI_ACPI_COMMON_HEADER
*) Table
)->Length
;
475 // Allocate a buffer for the table. All tables are allocated in the lower 32 bits of address space
476 // for backwards compatibility with ACPI 1.0 OS.
478 // This is done because ACPI 1.0 pointers are 32 bit values.
479 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
480 // There is no architectural reason these should be below 4GB, it is purely
481 // for convenience of implementation that we force memory below 4GB.
483 CurrentTableList
->PageAddress
= 0xFFFFFFFF;
484 CurrentTableList
->NumberOfPages
= EFI_SIZE_TO_PAGES (CurrentTableSize
);
487 // Allocation memory type depends on the type of the table
489 if ((CurrentTableSignature
== EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) ||
490 (CurrentTableSignature
== EFI_ACPI_4_0_UEFI_ACPI_DATA_TABLE_SIGNATURE
)) {
492 // Allocate memory for the FACS. This structure must be aligned
493 // on a 64 byte boundary and must be ACPI NVS memory.
494 // Using AllocatePages should ensure that it is always aligned.
495 // Do not change signature for new ACPI version because they are same.
497 // UEFI table also need to be in ACPI NVS memory, because some data field
498 // could be updated by OS present agent. For example, BufferPtrAddress in
499 // SMM communication ACPI table.
501 ASSERT ((EFI_PAGE_SIZE
% 64) == 0);
502 Status
= gBS
->AllocatePages (
505 CurrentTableList
->NumberOfPages
,
506 &CurrentTableList
->PageAddress
510 // All other tables are ACPI reclaim memory, no alignment requirements.
512 Status
= gBS
->AllocatePages (
514 EfiACPIReclaimMemory
,
515 CurrentTableList
->NumberOfPages
,
516 &CurrentTableList
->PageAddress
520 // Check return value from memory alloc.
522 if (EFI_ERROR (Status
)) {
523 gBS
->FreePool (CurrentTableList
);
524 return EFI_OUT_OF_RESOURCES
;
527 // Update the table pointer with the allocated memory start
529 CurrentTableList
->Table
= (EFI_ACPI_COMMON_HEADER
*) (UINTN
) CurrentTableList
->PageAddress
;
532 // Initialize the table contents
534 CurrentTableList
->Signature
= EFI_ACPI_TABLE_LIST_SIGNATURE
;
535 CopyMem (CurrentTableList
->Table
, Table
, CurrentTableSize
);
536 CurrentTableList
->Handle
= AcpiTableInstance
->CurrentHandle
++;
537 *Handle
= CurrentTableList
->Handle
;
538 CurrentTableList
->Version
= Version
;
541 // Update internal pointers if this is a required table. If it is a required
542 // table and a table of that type already exists, return an error.
544 // Calculate the checksum if the table is not FACS.
546 switch (CurrentTableSignature
) {
548 case EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
550 // We don't add the FADT in the standard way because some
551 // OS expect the FADT to be early in the table list.
552 // So we always add it as the first element in the list.
557 // Check that the table has not been previously added.
559 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Fadt1
!= NULL
) ||
560 ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0 && AcpiTableInstance
->Fadt3
!= NULL
)
562 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
563 gBS
->FreePool (CurrentTableList
);
564 return EFI_ACCESS_DENIED
;
567 // Add the table to the appropriate table version
569 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
571 // Save a pointer to the table
573 AcpiTableInstance
->Fadt1
= (EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE
*) CurrentTableList
->Table
;
576 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
578 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs1
;
579 AcpiTableInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt1
;
582 // RSDP OEM information is updated to match the FADT OEM information
585 &AcpiTableInstance
->Rsdp1
->OemId
,
586 &AcpiTableInstance
->Fadt1
->Header
.OemId
,
591 // RSDT OEM information is updated to match the FADT OEM information.
594 &AcpiTableInstance
->Rsdt1
->OemId
,
595 &AcpiTableInstance
->Fadt1
->Header
.OemId
,
600 &AcpiTableInstance
->Rsdt1
->OemTableId
,
601 &AcpiTableInstance
->Fadt1
->Header
.OemTableId
,
604 AcpiTableInstance
->Rsdt1
->OemRevision
= AcpiTableInstance
->Fadt1
->Header
.OemRevision
;
607 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
609 // Save a pointer to the table
611 AcpiTableInstance
->Fadt3
= (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE
*) CurrentTableList
->Table
;
614 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
615 // Note: If the FIRMWARE_CTRL is non-zero, then X_FIRMWARE_CTRL must be zero, and
618 if ((UINT64
)(UINTN
)AcpiTableInstance
->Facs3
< BASE_4GB
) {
619 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs3
;
620 ZeroMem (&AcpiTableInstance
->Fadt3
->XFirmwareCtrl
, sizeof (UINT64
));
622 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Facs3
;
624 &AcpiTableInstance
->Fadt3
->XFirmwareCtrl
,
628 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= 0;
630 AcpiTableInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt3
;
631 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Dsdt3
;
633 &AcpiTableInstance
->Fadt3
->XDsdt
,
639 // RSDP OEM information is updated to match the FADT OEM information
642 &AcpiTableInstance
->Rsdp3
->OemId
,
643 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
648 // RSDT OEM information is updated to match FADT OEM information.
651 &AcpiTableInstance
->Rsdt3
->OemId
,
652 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
656 &AcpiTableInstance
->Rsdt3
->OemTableId
,
657 &AcpiTableInstance
->Fadt3
->Header
.OemTableId
,
660 AcpiTableInstance
->Rsdt3
->OemRevision
= AcpiTableInstance
->Fadt3
->Header
.OemRevision
;
663 // XSDT OEM information is updated to match FADT OEM information.
666 &AcpiTableInstance
->Xsdt
->OemId
,
667 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
671 &AcpiTableInstance
->Xsdt
->OemTableId
,
672 &AcpiTableInstance
->Fadt3
->Header
.OemTableId
,
675 AcpiTableInstance
->Xsdt
->OemRevision
= AcpiTableInstance
->Fadt3
->Header
.OemRevision
;
678 // Checksum the table
681 AcpiPlatformChecksum (
682 CurrentTableList
->Table
,
683 CurrentTableList
->Table
->Length
,
684 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
690 case EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
692 // Check that the table has not been previously added.
694 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Facs1
!= NULL
) ||
695 ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0 && AcpiTableInstance
->Facs3
!= NULL
)
697 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
698 gBS
->FreePool (CurrentTableList
);
699 return EFI_ACCESS_DENIED
;
702 // FACS is referenced by FADT and is not part of RSDT
707 // Add the table to the appropriate table version
709 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
711 // Save a pointer to the table
713 AcpiTableInstance
->Facs1
= (EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
716 // If FADT already exists, update table pointers.
718 if (AcpiTableInstance
->Fadt1
!= NULL
) {
719 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs1
;
722 // Checksum FADT table
724 AcpiPlatformChecksum (
725 AcpiTableInstance
->Fadt1
,
726 AcpiTableInstance
->Fadt1
->Header
.Length
,
727 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
733 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
735 // Save a pointer to the table
737 AcpiTableInstance
->Facs3
= (EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
740 // If FADT already exists, update table pointers.
742 if (AcpiTableInstance
->Fadt3
!= NULL
) {
744 // Note: If the FIRMWARE_CTRL is non-zero, then X_FIRMWARE_CTRL must be zero, and
747 if ((UINT64
)(UINTN
)AcpiTableInstance
->Facs3
< BASE_4GB
) {
748 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs3
;
749 ZeroMem (&AcpiTableInstance
->Fadt3
->XFirmwareCtrl
, sizeof (UINT64
));
751 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Facs3
;
753 &AcpiTableInstance
->Fadt3
->XFirmwareCtrl
,
757 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= 0;
761 // Checksum FADT table
763 AcpiPlatformChecksum (
764 AcpiTableInstance
->Fadt3
,
765 AcpiTableInstance
->Fadt3
->Header
.Length
,
766 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
774 case EFI_ACPI_1_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
776 // Check that the table has not been previously added.
778 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Dsdt1
!= NULL
) ||
779 ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0 && AcpiTableInstance
->Dsdt3
!= NULL
)
781 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
782 gBS
->FreePool (CurrentTableList
);
783 return EFI_ACCESS_DENIED
;
786 // DSDT is referenced by FADT and is not part of RSDT
791 // Add the table to the appropriate table version
793 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
795 // Save a pointer to the table
797 AcpiTableInstance
->Dsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
800 // If FADT already exists, update table pointers.
802 if (AcpiTableInstance
->Fadt1
!= NULL
) {
803 AcpiTableInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt1
;
806 // Checksum FADT table
808 AcpiPlatformChecksum (
809 AcpiTableInstance
->Fadt1
,
810 AcpiTableInstance
->Fadt1
->Header
.Length
,
811 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
817 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
819 // Save a pointer to the table
821 AcpiTableInstance
->Dsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
824 // If FADT already exists, update table pointers.
826 if (AcpiTableInstance
->Fadt3
!= NULL
) {
827 AcpiTableInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt3
;
828 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Dsdt3
;
830 &AcpiTableInstance
->Fadt3
->XDsdt
,
836 // Checksum FADT table
838 AcpiPlatformChecksum (
839 AcpiTableInstance
->Fadt3
,
840 AcpiTableInstance
->Fadt3
->Header
.Length
,
841 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
847 // Checksum the table
850 AcpiPlatformChecksum (
851 CurrentTableList
->Table
,
852 CurrentTableList
->Table
->Length
,
853 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
861 // Checksum the table
864 AcpiPlatformChecksum (
865 CurrentTableList
->Table
,
866 CurrentTableList
->Table
->Length
,
867 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
874 // Add the table to the current list of tables
876 InsertTailList (&AcpiTableInstance
->TableList
, &CurrentTableList
->Link
);
879 // Add the table to RSDT and/or XSDT table entry lists.
882 // Add to ACPI 1.0b table tree
884 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
887 // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
889 if (AcpiTableInstance
->NumberOfTableEntries1
>= mEfiAcpiMaxNumTables
) {
890 Status
= ReallocateAcpiTableBuffer (AcpiTableInstance
);
891 ASSERT_EFI_ERROR (Status
);
893 CurrentRsdtEntry
= (UINT32
*)
895 (UINT8
*) AcpiTableInstance
->Rsdt1
+
896 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
897 AcpiTableInstance
->NumberOfTableEntries1
*
902 // Add entry to the RSDT unless its the FACS or DSDT
904 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
907 // Update RSDT length
909 AcpiTableInstance
->Rsdt1
->Length
= AcpiTableInstance
->Rsdt1
->Length
+ sizeof (UINT32
);
911 AcpiTableInstance
->NumberOfTableEntries1
++;
915 // Add to ACPI 2.0/3.0 table tree
917 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
920 // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
922 if (AcpiTableInstance
->NumberOfTableEntries3
>= mEfiAcpiMaxNumTables
) {
923 Status
= ReallocateAcpiTableBuffer (AcpiTableInstance
);
924 ASSERT_EFI_ERROR (Status
);
927 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
928 // If it becomes necessary to maintain separate table lists, changes will be required.
930 CurrentRsdtEntry
= (UINT32
*)
932 (UINT8
*) AcpiTableInstance
->Rsdt3
+
933 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
934 AcpiTableInstance
->NumberOfTableEntries3
*
939 // This pointer must not be directly dereferenced as the XSDT entries may not
940 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
942 CurrentXsdtEntry
= (VOID
*)
944 (UINT8
*) AcpiTableInstance
->Xsdt
+
945 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
946 AcpiTableInstance
->NumberOfTableEntries3
*
951 // Add entry to the RSDT
953 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
956 // Update RSDT length
958 AcpiTableInstance
->Rsdt3
->Length
= AcpiTableInstance
->Rsdt3
->Length
+ sizeof (UINT32
);
961 // Add entry to XSDT, XSDT expects 64 bit pointers, but
962 // the table pointers in XSDT are not aligned on 8 byte boundary.
964 Buffer64
= (UINT64
) (UINTN
) CurrentTableList
->Table
;
974 AcpiTableInstance
->Xsdt
->Length
= AcpiTableInstance
->Xsdt
->Length
+ sizeof (UINT64
);
976 AcpiTableInstance
->NumberOfTableEntries3
++;
980 ChecksumCommonTables (AcpiTableInstance
);
986 This function finds the table specified by the handle and returns a pointer to it.
987 If the handle is not found, EFI_NOT_FOUND is returned and the contents of Table are
990 @param Handle Table to find.
991 @param TableList Table list to search
992 @param Table Pointer to table found.
994 @return EFI_SUCCESS The function completed successfully.
995 @return EFI_NOT_FOUND No table found matching the handle specified.
1001 IN LIST_ENTRY
*TableList
,
1002 OUT EFI_ACPI_TABLE_LIST
**Table
1005 LIST_ENTRY
*CurrentLink
;
1006 EFI_ACPI_TABLE_LIST
*CurrentTable
;
1009 // Check for invalid input parameters
1016 CurrentLink
= TableList
->ForwardLink
;
1018 while (CurrentLink
!= TableList
) {
1019 CurrentTable
= EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink
);
1020 if (CurrentTable
->Handle
== Handle
) {
1022 // Found handle, so return this table.
1024 *Table
= CurrentTable
;
1028 CurrentLink
= CurrentLink
->ForwardLink
;
1033 return EFI_NOT_FOUND
;
1038 This function removes a basic table from the RSDT and/or XSDT.
1039 For Acpi 1.0 tables, pass in the Rsdt.
1040 For Acpi 2.0 tables, pass in both Rsdt and Xsdt.
1042 @param Table Pointer to table found.
1043 @param NumberOfTableEntries Current number of table entries in the RSDT/XSDT
1044 @param Rsdt Pointer to the RSDT to remove from
1045 @param Xsdt Pointer to the Xsdt to remove from
1047 @return EFI_SUCCESS The function completed successfully.
1048 @return EFI_INVALID_PARAMETER The table was not found in both Rsdt and Xsdt.
1052 RemoveTableFromRsdt (
1053 IN OUT EFI_ACPI_TABLE_LIST
* Table
,
1054 IN OUT UINTN
*NumberOfTableEntries
,
1055 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Rsdt
,
1056 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Xsdt OPTIONAL
1059 UINT32
*CurrentRsdtEntry
;
1060 VOID
*CurrentXsdtEntry
;
1061 UINT64 CurrentTablePointer64
;
1065 // Check for invalid input parameters
1068 ASSERT (NumberOfTableEntries
);
1072 // Find the table entry in the RSDT and XSDT
1074 for (Index
= 0; Index
< *NumberOfTableEntries
; Index
++) {
1076 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
1077 // If it becomes necessary to maintain separate table lists, changes will be required.
1079 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) Rsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + Index
* sizeof (UINT32
));
1082 // This pointer must not be directly dereferenced as the XSDT entries may not
1083 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
1085 CurrentXsdtEntry
= (VOID
*) ((UINT8
*) Xsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + Index
* sizeof (UINT64
));
1088 // Read the entry value out of the XSDT
1090 CopyMem (&CurrentTablePointer64
, CurrentXsdtEntry
, sizeof (UINT64
));
1093 // Initialize to NULL
1095 CurrentXsdtEntry
= 0;
1096 CurrentTablePointer64
= 0;
1099 // Check if we have found the corresponding entry in both RSDT and XSDT
1101 if (*CurrentRsdtEntry
== (UINT32
) (UINTN
) Table
->Table
&&
1102 ((Xsdt
== NULL
) || CurrentTablePointer64
== (UINT64
) (UINTN
) Table
->Table
)
1105 // Found entry, so copy all following entries and shrink table
1106 // We actually copy all + 1 to copy the initialized value of memory over
1109 CopyMem (CurrentRsdtEntry
, CurrentRsdtEntry
+ 1, (*NumberOfTableEntries
- Index
) * sizeof (UINT32
));
1110 Rsdt
->Length
= Rsdt
->Length
- sizeof (UINT32
);
1112 CopyMem (CurrentXsdtEntry
, ((UINT64
*) CurrentXsdtEntry
) + 1, (*NumberOfTableEntries
- Index
) * sizeof (UINT64
));
1113 Xsdt
->Length
= Xsdt
->Length
- sizeof (UINT64
);
1116 } else if (Index
+ 1 == *NumberOfTableEntries
) {
1118 // At the last entry, and table not found
1120 return EFI_INVALID_PARAMETER
;
1124 // Checksum the tables
1126 AcpiPlatformChecksum (
1129 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1134 AcpiPlatformChecksum (
1137 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1142 // Decrement the number of tables
1144 (*NumberOfTableEntries
)--;
1151 This function removes a table and frees any associated memory.
1153 @param AcpiTableInstance Instance of the protocol.
1154 @param Version Version(s) to delete.
1155 @param Table Pointer to table found.
1157 @return EFI_SUCCESS The function completed successfully.
1162 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
1163 IN EFI_ACPI_TABLE_VERSION Version
,
1164 IN OUT EFI_ACPI_TABLE_LIST
*Table
1167 UINT32 CurrentTableSignature
;
1168 BOOLEAN RemoveFromRsdt
;
1171 // Check for invalid input parameters
1173 ASSERT (AcpiTableInstance
);
1179 RemoveFromRsdt
= TRUE
;
1181 // Check for Table->Table
1183 ASSERT (Table
->Table
!= NULL
);
1184 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
->Table
)->Signature
;
1187 // Basic tasks to accomplish delete are:
1188 // Determine removal requirements (in RSDT/XSDT or not)
1189 // Remove entry from RSDT/XSDT
1190 // Remove any table references to the table
1191 // If no one is using the table
1192 // Free the table (removing pointers from private data and tables)
1194 // Free list structure
1197 // Determine if this table is in the RSDT or XSDT
1199 if ((CurrentTableSignature
== EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) ||
1200 (CurrentTableSignature
== EFI_ACPI_2_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
) ||
1201 (CurrentTableSignature
== EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
)
1203 RemoveFromRsdt
= FALSE
;
1206 // We don't remove the FADT in the standard way because some
1207 // OS expect the FADT to be early in the table list.
1208 // So we always put it as the first element in the list.
1210 if (CurrentTableSignature
== EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
) {
1211 RemoveFromRsdt
= FALSE
;
1215 // Remove the table from RSDT and XSDT
1217 if (Table
->Table
!= NULL
) {
1219 // This is a basic table, remove it from any lists and the Rsdt and/or Xsdt
1221 if (Version
& EFI_ACPI_TABLE_VERSION_NONE
& Table
->Version
) {
1223 // Remove this version from the table
1225 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_NONE
;
1228 if (Version
& EFI_ACPI_TABLE_VERSION_1_0B
& Table
->Version
) {
1230 // Remove this version from the table
1232 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_1_0B
;
1235 // Remove from Rsdt. We don't care about the return value because it is
1236 // acceptable for the table to not exist in Rsdt.
1237 // We didn't add some tables so we don't remove them.
1239 if (RemoveFromRsdt
) {
1240 RemoveTableFromRsdt (
1242 &AcpiTableInstance
->NumberOfTableEntries1
,
1243 AcpiTableInstance
->Rsdt1
,
1249 if (Version
& ACPI_TABLE_VERSION_GTE_2_0
& Table
->Version
) {
1251 // Remove this version from the table
1253 Table
->Version
= Table
->Version
&~(Version
& ACPI_TABLE_VERSION_GTE_2_0
);
1256 // Remove from Rsdt and Xsdt. We don't care about the return value
1257 // because it is acceptable for the table to not exist in Rsdt/Xsdt.
1258 // We didn't add some tables so we don't remove them.
1260 if (RemoveFromRsdt
) {
1261 RemoveTableFromRsdt (
1263 &AcpiTableInstance
->NumberOfTableEntries3
,
1264 AcpiTableInstance
->Rsdt3
,
1265 AcpiTableInstance
->Xsdt
1270 // Free the table, clean up any dependent tables and our private data pointers.
1272 switch (Table
->Table
->Signature
) {
1274 case EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
1275 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1276 AcpiTableInstance
->Fadt1
= NULL
;
1279 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
1280 AcpiTableInstance
->Fadt3
= NULL
;
1284 case EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
1285 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1286 AcpiTableInstance
->Facs1
= NULL
;
1289 // Update FADT table pointers
1291 if (AcpiTableInstance
->Fadt1
!= NULL
) {
1292 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= 0;
1297 AcpiPlatformChecksum (
1298 AcpiTableInstance
->Fadt1
,
1299 AcpiTableInstance
->Fadt1
->Header
.Length
,
1300 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1306 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
1307 AcpiTableInstance
->Facs3
= NULL
;
1310 // Update FADT table pointers
1312 if (AcpiTableInstance
->Fadt3
!= NULL
) {
1313 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= 0;
1314 ZeroMem (&AcpiTableInstance
->Fadt3
->XFirmwareCtrl
, sizeof (UINT64
));
1319 AcpiPlatformChecksum (
1320 AcpiTableInstance
->Fadt3
,
1321 AcpiTableInstance
->Fadt3
->Header
.Length
,
1322 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1329 case EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
1330 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1331 AcpiTableInstance
->Dsdt1
= NULL
;
1334 // Update FADT table pointers
1336 if (AcpiTableInstance
->Fadt1
!= NULL
) {
1337 AcpiTableInstance
->Fadt1
->Dsdt
= 0;
1342 AcpiPlatformChecksum (
1343 AcpiTableInstance
->Fadt1
,
1344 AcpiTableInstance
->Fadt1
->Header
.Length
,
1345 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1352 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
1353 AcpiTableInstance
->Dsdt3
= NULL
;
1356 // Update FADT table pointers
1358 if (AcpiTableInstance
->Fadt3
!= NULL
) {
1359 AcpiTableInstance
->Fadt3
->Dsdt
= 0;
1360 ZeroMem (&AcpiTableInstance
->Fadt3
->XDsdt
, sizeof (UINT64
));
1365 AcpiPlatformChecksum (
1366 AcpiTableInstance
->Fadt3
,
1367 AcpiTableInstance
->Fadt3
->Header
.Length
,
1368 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1383 // If no version is using this table anymore, remove and free list entry.
1385 if (Table
->Version
== 0) {
1389 gBS
->FreePages (Table
->PageAddress
, Table
->NumberOfPages
);
1390 RemoveEntryList (&(Table
->Link
));
1391 gBS
->FreePool (Table
);
1401 This function finds and removes the table specified by the handle.
1403 @param AcpiTableInstance Instance of the protocol.
1404 @param Version Bitmask of which versions to remove.
1405 @param Handle Table to remove.
1407 @return EFI_SUCCESS The function completed successfully.
1408 @return EFI_ABORTED An error occurred.
1409 @return EFI_NOT_FOUND Handle not found in table list.
1413 RemoveTableFromList (
1414 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
1415 IN EFI_ACPI_TABLE_VERSION Version
,
1419 EFI_ACPI_TABLE_LIST
*Table
;
1422 Table
= (EFI_ACPI_TABLE_LIST
*) NULL
;
1425 // Check for invalid input parameters
1427 ASSERT (AcpiTableInstance
);
1432 Status
= FindTableByHandle (
1434 &AcpiTableInstance
->TableList
,
1437 if (EFI_ERROR (Status
)) {
1438 return EFI_NOT_FOUND
;
1443 Status
= DeleteTable (AcpiTableInstance
, Version
, Table
);
1444 if (EFI_ERROR (Status
)) {
1448 // Completed successfully
1455 This function calculates and updates an UINT8 checksum.
1457 @param Buffer Pointer to buffer to checksum
1458 @param Size Number of bytes to checksum
1459 @param ChecksumOffset Offset to place the checksum result in
1461 @return EFI_SUCCESS The function completed successfully.
1465 AcpiPlatformChecksum (
1468 IN UINTN ChecksumOffset
1476 // Initialize pointer
1481 // set checksum to 0 first
1483 Ptr
[ChecksumOffset
] = 0;
1486 // add all content of buffer
1488 while ((Size
--) != 0) {
1489 Sum
= (UINT8
) (Sum
+ (*Ptr
++));
1495 Ptr
[ChecksumOffset
] = (UINT8
) (0xff - Sum
+ 1);
1502 Checksum all versions of the common tables, RSDP, RSDT, XSDT.
1504 @param AcpiTableInstance Protocol instance private data.
1506 @return EFI_SUCCESS The function completed successfully.
1510 ChecksumCommonTables (
1511 IN OUT EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
1515 // RSDP ACPI 1.0 checksum for 1.0 table. This is only the first 20 bytes of the structure
1517 AcpiPlatformChecksum (
1518 AcpiTableInstance
->Rsdp1
,
1519 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1520 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1525 // RSDP ACPI 1.0 checksum for 2.0/3.0 table. This is only the first 20 bytes of the structure
1527 AcpiPlatformChecksum (
1528 AcpiTableInstance
->Rsdp3
,
1529 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1530 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1535 // RSDP ACPI 2.0/3.0 checksum, this is the entire table
1537 AcpiPlatformChecksum (
1538 AcpiTableInstance
->Rsdp3
,
1539 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1540 OFFSET_OF (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1547 AcpiPlatformChecksum (
1548 AcpiTableInstance
->Rsdt1
,
1549 AcpiTableInstance
->Rsdt1
->Length
,
1550 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1554 AcpiPlatformChecksum (
1555 AcpiTableInstance
->Rsdt3
,
1556 AcpiTableInstance
->Rsdt3
->Length
,
1557 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1564 AcpiPlatformChecksum (
1565 AcpiTableInstance
->Xsdt
,
1566 AcpiTableInstance
->Xsdt
->Length
,
1567 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1576 Constructor for the ACPI table protocol. Initializes instance
1579 @param AcpiTableInstance Instance to construct
1581 @return EFI_SUCCESS Instance initialized.
1582 @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
1586 AcpiTableAcpiTableConstructor (
1587 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
1593 UINTN RsdpTableSize
;
1595 EFI_PHYSICAL_ADDRESS PageAddress
;
1598 // Check for invalid input parameters
1600 ASSERT (AcpiTableInstance
);
1602 InitializeListHead (&AcpiTableInstance
->TableList
);
1603 AcpiTableInstance
->CurrentHandle
= 1;
1605 AcpiTableInstance
->AcpiTableProtocol
.InstallAcpiTable
= InstallAcpiTable
;
1606 AcpiTableInstance
->AcpiTableProtocol
.UninstallAcpiTable
= UninstallAcpiTable
;
1608 if (FeaturePcdGet (PcdInstallAcpiSdtProtocol
)) {
1609 SdtAcpiTableAcpiSdtConstructor (AcpiTableInstance
);
1613 // Create RSDP table
1615 RsdpTableSize
= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
) +
1616 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1618 PageAddress
= 0xFFFFFFFF;
1619 Status
= gBS
->AllocatePages (
1621 EfiACPIReclaimMemory
,
1622 EFI_SIZE_TO_PAGES (RsdpTableSize
),
1626 if (EFI_ERROR (Status
)) {
1627 return EFI_OUT_OF_RESOURCES
;
1630 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
1631 ZeroMem (Pointer
, RsdpTableSize
);
1633 AcpiTableInstance
->Rsdp1
= (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1634 Pointer
+= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1635 AcpiTableInstance
->Rsdp3
= (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1638 // Create RSDT, XSDT structures
1640 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
1641 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
1642 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
1643 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
1644 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
1645 mEfiAcpiMaxNumTables
* sizeof (UINT64
);
1648 // Allocate memory in the lower 32 bit of address range for
1649 // compatibility with ACPI 1.0 OS.
1651 // This is done because ACPI 1.0 pointers are 32 bit values.
1652 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
1653 // There is no architectural reason these should be below 4GB, it is purely
1654 // for convenience of implementation that we force memory below 4GB.
1656 PageAddress
= 0xFFFFFFFF;
1657 Status
= gBS
->AllocatePages (
1659 EfiACPIReclaimMemory
,
1660 EFI_SIZE_TO_PAGES (TotalSize
),
1664 if (EFI_ERROR (Status
)) {
1665 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
)(UINTN
)AcpiTableInstance
->Rsdp1
, EFI_SIZE_TO_PAGES (RsdpTableSize
));
1666 return EFI_OUT_OF_RESOURCES
;
1669 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
1670 ZeroMem (Pointer
, TotalSize
);
1672 AcpiTableInstance
->Rsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1673 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1674 AcpiTableInstance
->Rsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1675 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1676 AcpiTableInstance
->Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1681 CurrentData
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1682 CopyMem (&AcpiTableInstance
->Rsdp1
->Signature
, &CurrentData
, sizeof (UINT64
));
1683 CopyMem (AcpiTableInstance
->Rsdp1
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdp1
->OemId
));
1684 AcpiTableInstance
->Rsdp1
->Reserved
= EFI_ACPI_RESERVED_BYTE
;
1685 AcpiTableInstance
->Rsdp1
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt1
;
1687 CurrentData
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1688 CopyMem (&AcpiTableInstance
->Rsdp3
->Signature
, &CurrentData
, sizeof (UINT64
));
1689 CopyMem (AcpiTableInstance
->Rsdp3
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdp3
->OemId
));
1690 AcpiTableInstance
->Rsdp3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION
;
1691 AcpiTableInstance
->Rsdp3
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt3
;
1692 AcpiTableInstance
->Rsdp3
->Length
= sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1693 CurrentData
= (UINT64
) (UINTN
) AcpiTableInstance
->Xsdt
;
1694 CopyMem (&AcpiTableInstance
->Rsdp3
->XsdtAddress
, &CurrentData
, sizeof (UINT64
));
1695 SetMem (AcpiTableInstance
->Rsdp3
->Reserved
, 3, EFI_ACPI_RESERVED_BYTE
);
1700 // Note that we "reserve" one entry for the FADT so it can always be
1701 // at the beginning of the list of tables. Some OS don't seem
1702 // to find it correctly if it is too far down the list.
1704 AcpiTableInstance
->Rsdt1
->Signature
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1705 AcpiTableInstance
->Rsdt1
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1706 AcpiTableInstance
->Rsdt1
->Revision
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1707 CopyMem (AcpiTableInstance
->Rsdt1
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdt1
->OemId
));
1708 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1709 CopyMem (&AcpiTableInstance
->Rsdt1
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1710 AcpiTableInstance
->Rsdt1
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1711 AcpiTableInstance
->Rsdt1
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1712 AcpiTableInstance
->Rsdt1
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1714 // We always reserve first one for FADT
1716 AcpiTableInstance
->NumberOfTableEntries1
= 1;
1717 AcpiTableInstance
->Rsdt1
->Length
= AcpiTableInstance
->Rsdt1
->Length
+ sizeof(UINT32
);
1719 AcpiTableInstance
->Rsdt3
->Signature
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1720 AcpiTableInstance
->Rsdt3
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1721 AcpiTableInstance
->Rsdt3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1722 CopyMem (AcpiTableInstance
->Rsdt3
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdt3
->OemId
));
1723 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1724 CopyMem (&AcpiTableInstance
->Rsdt3
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1725 AcpiTableInstance
->Rsdt3
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1726 AcpiTableInstance
->Rsdt3
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1727 AcpiTableInstance
->Rsdt3
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1729 // We always reserve first one for FADT
1731 AcpiTableInstance
->NumberOfTableEntries3
= 1;
1732 AcpiTableInstance
->Rsdt3
->Length
= AcpiTableInstance
->Rsdt3
->Length
+ sizeof(UINT32
);
1737 AcpiTableInstance
->Xsdt
->Signature
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1738 AcpiTableInstance
->Xsdt
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1739 AcpiTableInstance
->Xsdt
->Revision
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1740 CopyMem (AcpiTableInstance
->Xsdt
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Xsdt
->OemId
));
1741 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1742 CopyMem (&AcpiTableInstance
->Xsdt
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1743 AcpiTableInstance
->Xsdt
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1744 AcpiTableInstance
->Xsdt
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1745 AcpiTableInstance
->Xsdt
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1747 // We always reserve first one for FADT
1749 AcpiTableInstance
->Xsdt
->Length
= AcpiTableInstance
->Xsdt
->Length
+ sizeof(UINT64
);
1751 ChecksumCommonTables (AcpiTableInstance
);
1754 // Completed successfully