2 ACPI Table Protocol Implementation
4 Copyright (c) 2006 - 2015, Intel Corporation. All rights reserved.<BR>
5 Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
19 #include "AcpiTable.h"
21 // The maximum number of tables that pre-allocated.
23 UINTN mEfiAcpiMaxNumTables
= EFI_ACPI_MAX_NUM_TABLES
;
26 // Allocation strategy to use for AllocatePages ().
27 // Runtime value depends on PcdExposedAcpiTableVersions.
29 STATIC EFI_ALLOCATE_TYPE mAcpiTableAllocType
;
32 This function adds an ACPI table to the table list. It will detect FACS and
33 allocate the correct type of memory and properly align the table.
35 @param AcpiTableInstance Instance of the protocol.
36 @param Table Table to add.
37 @param Checksum Does the table require checksumming.
38 @param Version The version of the list to add the table to.
39 @param Handle Pointer for returning the handle.
41 @return EFI_SUCCESS The function completed successfully.
42 @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
43 @return EFI_ABORTED The table is a duplicate of a table that is required
49 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
52 IN EFI_ACPI_TABLE_VERSION Version
,
57 This function finds and removes the table specified by the handle.
59 @param AcpiTableInstance Instance of the protocol.
60 @param Version Bitmask of which versions to remove.
61 @param Handle Table to remove.
63 @return EFI_SUCCESS The function completed successfully.
64 @return EFI_ABORTED An error occurred.
65 @return EFI_NOT_FOUND Handle not found in table list.
70 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
71 IN EFI_ACPI_TABLE_VERSION Version
,
76 This function calculates and updates an UINT8 checksum.
78 @param Buffer Pointer to buffer to checksum
79 @param Size Number of bytes to checksum
80 @param ChecksumOffset Offset to place the checksum result in
82 @return EFI_SUCCESS The function completed successfully.
85 AcpiPlatformChecksum (
88 IN UINTN ChecksumOffset
92 Checksum all versions of the common tables, RSDP, RSDT, XSDT.
94 @param AcpiTableInstance Protocol instance private data.
96 @return EFI_SUCCESS The function completed successfully.
100 ChecksumCommonTables (
101 IN OUT EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
105 // Protocol function implementations.
109 This function publishes the specified versions of the ACPI tables by
110 installing EFI configuration table entries for them. Any combination of
111 table versions can be published.
113 @param AcpiTableInstance Instance of the protocol.
114 @param Version Version(s) to publish.
116 @return EFI_SUCCESS The function completed successfully.
117 @return EFI_ABORTED The function could not complete successfully.
123 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
124 IN EFI_ACPI_TABLE_VERSION Version
128 UINT32
*CurrentRsdtEntry
;
129 VOID
*CurrentXsdtEntry
;
133 // Reorder tables as some operating systems don't seem to find the
134 // FADT correctly if it is not in the first few entries
138 // Add FADT as the first entry
140 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
141 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) AcpiTableInstance
->Rsdt1
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
142 *CurrentRsdtEntry
= (UINT32
) (UINTN
) AcpiTableInstance
->Fadt1
;
144 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) AcpiTableInstance
->Rsdt3
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
145 *CurrentRsdtEntry
= (UINT32
) (UINTN
) AcpiTableInstance
->Fadt3
;
147 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
148 CurrentXsdtEntry
= (VOID
*) ((UINT8
*) AcpiTableInstance
->Xsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
));
150 // Add entry to XSDT, XSDT expects 64 bit pointers, but
151 // the table pointers in XSDT are not aligned on 8 byte boundary.
153 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Fadt3
;
162 // Do checksum again because Dsdt/Xsdt is updated.
164 ChecksumCommonTables (AcpiTableInstance
);
167 // Add the RSD_PTR to the system table and store that we have installed the
170 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
171 Status
= gBS
->InstallConfigurationTable (&gEfiAcpi10TableGuid
, AcpiTableInstance
->Rsdp1
);
172 if (EFI_ERROR (Status
)) {
177 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
178 Status
= gBS
->InstallConfigurationTable (&gEfiAcpiTableGuid
, AcpiTableInstance
->Rsdp3
);
179 if (EFI_ERROR (Status
)) {
189 Installs an ACPI table into the RSDT/XSDT.
190 Note that the ACPI table should be checksumed before installing it.
191 Otherwise it will assert.
193 @param This Protocol instance pointer.
194 @param AcpiTableBuffer A pointer to a buffer containing the ACPI table to be installed.
195 @param AcpiTableBufferSize Specifies the size, in bytes, of the AcpiTableBuffer buffer.
196 @param TableKey Reurns a key to refer to the ACPI table.
198 @return EFI_SUCCESS The table was successfully inserted.
199 @return EFI_INVALID_PARAMETER Either AcpiTableBuffer is NULL, TableKey is NULL, or AcpiTableBufferSize
200 and the size field embedded in the ACPI table pointed to by AcpiTableBuffer
202 @return EFI_OUT_OF_RESOURCES Insufficient resources exist to complete the request.
203 @retval EFI_ACCESS_DENIED The table signature matches a table already
204 present in the system and platform policy
205 does not allow duplicate tables of this type.
211 IN EFI_ACPI_TABLE_PROTOCOL
*This
,
212 IN VOID
*AcpiTableBuffer
,
213 IN UINTN AcpiTableBufferSize
,
217 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
;
219 VOID
*AcpiTableBufferConst
;
220 EFI_ACPI_TABLE_VERSION Version
;
223 // Check for invalid input parameters
225 if ((AcpiTableBuffer
== NULL
) || (TableKey
== NULL
)
226 || (((EFI_ACPI_DESCRIPTION_HEADER
*) AcpiTableBuffer
)->Length
!= AcpiTableBufferSize
)) {
227 return EFI_INVALID_PARAMETER
;
230 Version
= PcdGet32 (PcdAcpiExposedTableVersions
);
233 // Get the instance of the ACPI table protocol
235 AcpiTableInstance
= EFI_ACPI_TABLE_INSTANCE_FROM_THIS (This
);
238 // Install the ACPI table
240 AcpiTableBufferConst
= AllocateCopyPool (AcpiTableBufferSize
,AcpiTableBuffer
);
242 Status
= AddTableToList (
244 AcpiTableBufferConst
,
249 if (!EFI_ERROR (Status
)) {
250 Status
= PublishTables (
255 FreePool (AcpiTableBufferConst
);
258 // Add a new table successfully, notify registed callback
260 if (FeaturePcdGet (PcdInstallAcpiSdtProtocol
)) {
261 if (!EFI_ERROR (Status
)) {
275 Removes an ACPI table from the RSDT/XSDT.
277 @param This Protocol instance pointer.
278 @param TableKey Specifies the table to uninstall. The key was returned from InstallAcpiTable().
280 @return EFI_SUCCESS The table was successfully uninstalled.
281 @return EFI_NOT_FOUND TableKey does not refer to a valid key for a table entry.
287 IN EFI_ACPI_TABLE_PROTOCOL
*This
,
291 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
;
295 // Get the instance of the ACPI table protocol
297 AcpiTableInstance
= EFI_ACPI_TABLE_INSTANCE_FROM_THIS (This
);
300 // Uninstall the ACPI table
302 Status
= RemoveTableFromList (
304 EFI_ACPI_TABLE_VERSION_1_0B
| ACPI_TABLE_VERSION_GTE_2_0
,
307 if (!EFI_ERROR (Status
)) {
308 Status
= PublishTables (
310 EFI_ACPI_TABLE_VERSION_1_0B
| ACPI_TABLE_VERSION_GTE_2_0
314 if (EFI_ERROR (Status
)) {
315 return EFI_NOT_FOUND
;
322 If the number of APCI tables exceeds the preallocated max table number, enlarge the table buffer.
324 @param AcpiTableInstance ACPI table protocol instance data structure.
326 @return EFI_SUCCESS reallocate the table beffer successfully.
327 @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
331 ReallocateAcpiTableBuffer (
332 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
335 UINTN NewMaxTableNumber
;
338 EFI_PHYSICAL_ADDRESS PageAddress
;
339 EFI_ACPI_TABLE_INSTANCE TempPrivateData
;
343 CopyMem (&TempPrivateData
, AcpiTableInstance
, sizeof (EFI_ACPI_TABLE_INSTANCE
));
345 // Enlarge the max table number from mEfiAcpiMaxNumTables to mEfiAcpiMaxNumTables + EFI_ACPI_MAX_NUM_TABLES
347 NewMaxTableNumber
= mEfiAcpiMaxNumTables
+ EFI_ACPI_MAX_NUM_TABLES
;
349 // Create RSDT, XSDT structures and allocate buffers.
351 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
352 NewMaxTableNumber
* sizeof (UINT64
);
354 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
355 TotalSize
+= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
356 NewMaxTableNumber
* sizeof (UINT32
) +
357 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
358 NewMaxTableNumber
* sizeof (UINT32
);
362 // Allocate memory in the lower 32 bit of address range for
363 // compatibility with ACPI 1.0 OS.
365 // This is done because ACPI 1.0 pointers are 32 bit values.
366 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
367 // There is no architectural reason these should be below 4GB, it is purely
368 // for convenience of implementation that we force memory below 4GB.
370 PageAddress
= 0xFFFFFFFF;
371 Status
= gBS
->AllocatePages (
373 EfiACPIReclaimMemory
,
374 EFI_SIZE_TO_PAGES (TotalSize
),
378 if (EFI_ERROR (Status
)) {
379 return EFI_OUT_OF_RESOURCES
;
382 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
383 ZeroMem (Pointer
, TotalSize
);
385 AcpiTableInstance
->Rsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
386 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
387 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + NewMaxTableNumber
* sizeof (UINT32
));
388 AcpiTableInstance
->Rsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
389 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + NewMaxTableNumber
* sizeof (UINT32
));
391 AcpiTableInstance
->Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
394 // Update RSDP to point to the new Rsdt and Xsdt address.
396 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
397 AcpiTableInstance
->Rsdp1
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt1
;
398 AcpiTableInstance
->Rsdp3
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt3
;
400 CurrentData
= (UINT64
) (UINTN
) AcpiTableInstance
->Xsdt
;
401 CopyMem (&AcpiTableInstance
->Rsdp3
->XsdtAddress
, &CurrentData
, sizeof (UINT64
));
404 // copy the original Rsdt1, Rsdt3 and Xsdt structure to new buffer
406 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
407 CopyMem (AcpiTableInstance
->Rsdt1
, TempPrivateData
.Rsdt1
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT32
)));
408 CopyMem (AcpiTableInstance
->Rsdt3
, TempPrivateData
.Rsdt3
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT32
)));
410 CopyMem (AcpiTableInstance
->Xsdt
, TempPrivateData
.Xsdt
, (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + mEfiAcpiMaxNumTables
* sizeof (UINT64
)));
413 // Calculate orignal ACPI table buffer size
415 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
416 mEfiAcpiMaxNumTables
* sizeof (UINT64
);
418 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
419 TotalSize
+= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
420 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
421 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
422 mEfiAcpiMaxNumTables
* sizeof (UINT32
);
425 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
)(UINTN
)TempPrivateData
.Rsdt1
, EFI_SIZE_TO_PAGES (TotalSize
));
428 // Update the Max ACPI table number
430 mEfiAcpiMaxNumTables
= NewMaxTableNumber
;
434 This function adds an ACPI table to the table list. It will detect FACS and
435 allocate the correct type of memory and properly align the table.
437 @param AcpiTableInstance Instance of the protocol.
438 @param Table Table to add.
439 @param Checksum Does the table require checksumming.
440 @param Version The version of the list to add the table to.
441 @param Handle Pointer for returning the handle.
443 @return EFI_SUCCESS The function completed successfully.
444 @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
445 @retval EFI_ACCESS_DENIED The table signature matches a table already
446 present in the system and platform policy
447 does not allow duplicate tables of this type.
452 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
455 IN EFI_ACPI_TABLE_VERSION Version
,
460 EFI_ACPI_TABLE_LIST
*CurrentTableList
;
461 UINT32 CurrentTableSignature
;
462 UINT32 CurrentTableSize
;
463 UINT32
*CurrentRsdtEntry
;
464 VOID
*CurrentXsdtEntry
;
469 // Check for invalid input parameters
471 ASSERT (AcpiTableInstance
);
481 // Create a new list entry
483 CurrentTableList
= AllocatePool (sizeof (EFI_ACPI_TABLE_LIST
));
484 ASSERT (CurrentTableList
);
487 // Determine table type and size
489 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
)->Signature
;
490 CurrentTableSize
= ((EFI_ACPI_COMMON_HEADER
*) Table
)->Length
;
493 // Allocate a buffer for the table. All tables are allocated in the lower 32 bits of address space
494 // for backwards compatibility with ACPI 1.0 OS.
496 // This is done because ACPI 1.0 pointers are 32 bit values.
497 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
498 // There is no architectural reason these should be below 4GB, it is purely
499 // for convenience of implementation that we force memory below 4GB.
501 CurrentTableList
->PageAddress
= 0xFFFFFFFF;
502 CurrentTableList
->NumberOfPages
= EFI_SIZE_TO_PAGES (CurrentTableSize
);
505 // Allocation memory type depends on the type of the table
507 if ((CurrentTableSignature
== EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) ||
508 (CurrentTableSignature
== EFI_ACPI_4_0_UEFI_ACPI_DATA_TABLE_SIGNATURE
)) {
510 // Allocate memory for the FACS. This structure must be aligned
511 // on a 64 byte boundary and must be ACPI NVS memory.
512 // Using AllocatePages should ensure that it is always aligned.
513 // Do not change signature for new ACPI version because they are same.
515 // UEFI table also need to be in ACPI NVS memory, because some data field
516 // could be updated by OS present agent. For example, BufferPtrAddress in
517 // SMM communication ACPI table.
519 ASSERT ((EFI_PAGE_SIZE
% 64) == 0);
520 Status
= gBS
->AllocatePages (
523 CurrentTableList
->NumberOfPages
,
524 &CurrentTableList
->PageAddress
528 // All other tables are ACPI reclaim memory, no alignment requirements.
530 Status
= gBS
->AllocatePages (
532 EfiACPIReclaimMemory
,
533 CurrentTableList
->NumberOfPages
,
534 &CurrentTableList
->PageAddress
538 // Check return value from memory alloc.
540 if (EFI_ERROR (Status
)) {
541 gBS
->FreePool (CurrentTableList
);
542 return EFI_OUT_OF_RESOURCES
;
545 // Update the table pointer with the allocated memory start
547 CurrentTableList
->Table
= (EFI_ACPI_COMMON_HEADER
*) (UINTN
) CurrentTableList
->PageAddress
;
550 // Initialize the table contents
552 CurrentTableList
->Signature
= EFI_ACPI_TABLE_LIST_SIGNATURE
;
553 CopyMem (CurrentTableList
->Table
, Table
, CurrentTableSize
);
554 CurrentTableList
->Handle
= AcpiTableInstance
->CurrentHandle
++;
555 *Handle
= CurrentTableList
->Handle
;
556 CurrentTableList
->Version
= Version
;
559 // Update internal pointers if this is a required table. If it is a required
560 // table and a table of that type already exists, return an error.
562 // Calculate the checksum if the table is not FACS.
564 switch (CurrentTableSignature
) {
566 case EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
568 // We don't add the FADT in the standard way because some
569 // OS expect the FADT to be early in the table list.
570 // So we always add it as the first element in the list.
575 // Check that the table has not been previously added.
577 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Fadt1
!= NULL
) ||
578 ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0 && AcpiTableInstance
->Fadt3
!= NULL
)
580 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
581 gBS
->FreePool (CurrentTableList
);
582 return EFI_ACCESS_DENIED
;
585 // Add the table to the appropriate table version
587 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
589 // Save a pointer to the table
591 AcpiTableInstance
->Fadt1
= (EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE
*) CurrentTableList
->Table
;
594 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
596 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs1
;
597 AcpiTableInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt1
;
600 // RSDP OEM information is updated to match the FADT OEM information
603 &AcpiTableInstance
->Rsdp1
->OemId
,
604 &AcpiTableInstance
->Fadt1
->Header
.OemId
,
609 // RSDT OEM information is updated to match the FADT OEM information.
612 &AcpiTableInstance
->Rsdt1
->OemId
,
613 &AcpiTableInstance
->Fadt1
->Header
.OemId
,
618 &AcpiTableInstance
->Rsdt1
->OemTableId
,
619 &AcpiTableInstance
->Fadt1
->Header
.OemTableId
,
622 AcpiTableInstance
->Rsdt1
->OemRevision
= AcpiTableInstance
->Fadt1
->Header
.OemRevision
;
625 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
627 // Save a pointer to the table
629 AcpiTableInstance
->Fadt3
= (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE
*) CurrentTableList
->Table
;
632 // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
633 // Note: If the FIRMWARE_CTRL is non-zero, then X_FIRMWARE_CTRL must be zero, and
636 if ((UINT64
)(UINTN
)AcpiTableInstance
->Facs3
< BASE_4GB
) {
637 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs3
;
638 ZeroMem (&AcpiTableInstance
->Fadt3
->XFirmwareCtrl
, sizeof (UINT64
));
640 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Facs3
;
642 &AcpiTableInstance
->Fadt3
->XFirmwareCtrl
,
646 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= 0;
648 if ((UINT64
)(UINTN
)AcpiTableInstance
->Dsdt3
< BASE_4GB
) {
649 AcpiTableInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt3
;
650 ZeroMem (&AcpiTableInstance
->Fadt3
->XDsdt
, sizeof (UINT64
));
652 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Dsdt3
;
654 &AcpiTableInstance
->Fadt3
->XDsdt
,
658 AcpiTableInstance
->Fadt3
->Dsdt
= 0;
662 // RSDP OEM information is updated to match the FADT OEM information
665 &AcpiTableInstance
->Rsdp3
->OemId
,
666 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
670 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
672 // RSDT OEM information is updated to match FADT OEM information.
675 &AcpiTableInstance
->Rsdt3
->OemId
,
676 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
680 &AcpiTableInstance
->Rsdt3
->OemTableId
,
681 &AcpiTableInstance
->Fadt3
->Header
.OemTableId
,
684 AcpiTableInstance
->Rsdt3
->OemRevision
= AcpiTableInstance
->Fadt3
->Header
.OemRevision
;
688 // XSDT OEM information is updated to match FADT OEM information.
691 &AcpiTableInstance
->Xsdt
->OemId
,
692 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
696 &AcpiTableInstance
->Xsdt
->OemTableId
,
697 &AcpiTableInstance
->Fadt3
->Header
.OemTableId
,
700 AcpiTableInstance
->Xsdt
->OemRevision
= AcpiTableInstance
->Fadt3
->Header
.OemRevision
;
703 // Checksum the table
706 AcpiPlatformChecksum (
707 CurrentTableList
->Table
,
708 CurrentTableList
->Table
->Length
,
709 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
715 case EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
717 // Check that the table has not been previously added.
719 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Facs1
!= NULL
) ||
720 ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0 && AcpiTableInstance
->Facs3
!= NULL
)
722 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
723 gBS
->FreePool (CurrentTableList
);
724 return EFI_ACCESS_DENIED
;
727 // FACS is referenced by FADT and is not part of RSDT
732 // Add the table to the appropriate table version
734 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
736 // Save a pointer to the table
738 AcpiTableInstance
->Facs1
= (EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
741 // If FADT already exists, update table pointers.
743 if (AcpiTableInstance
->Fadt1
!= NULL
) {
744 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs1
;
747 // Checksum FADT table
749 AcpiPlatformChecksum (
750 AcpiTableInstance
->Fadt1
,
751 AcpiTableInstance
->Fadt1
->Header
.Length
,
752 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
758 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
760 // Save a pointer to the table
762 AcpiTableInstance
->Facs3
= (EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
765 // If FADT already exists, update table pointers.
767 if (AcpiTableInstance
->Fadt3
!= NULL
) {
769 // Note: If the FIRMWARE_CTRL is non-zero, then X_FIRMWARE_CTRL must be zero, and
772 if ((UINT64
)(UINTN
)AcpiTableInstance
->Facs3
< BASE_4GB
) {
773 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs3
;
774 ZeroMem (&AcpiTableInstance
->Fadt3
->XFirmwareCtrl
, sizeof (UINT64
));
776 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Facs3
;
778 &AcpiTableInstance
->Fadt3
->XFirmwareCtrl
,
782 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= 0;
786 // Checksum FADT table
788 AcpiPlatformChecksum (
789 AcpiTableInstance
->Fadt3
,
790 AcpiTableInstance
->Fadt3
->Header
.Length
,
791 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
799 case EFI_ACPI_1_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
801 // Check that the table has not been previously added.
803 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Dsdt1
!= NULL
) ||
804 ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0 && AcpiTableInstance
->Dsdt3
!= NULL
)
806 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
807 gBS
->FreePool (CurrentTableList
);
808 return EFI_ACCESS_DENIED
;
811 // DSDT is referenced by FADT and is not part of RSDT
816 // Add the table to the appropriate table version
818 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
820 // Save a pointer to the table
822 AcpiTableInstance
->Dsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
825 // If FADT already exists, update table pointers.
827 if (AcpiTableInstance
->Fadt1
!= NULL
) {
828 AcpiTableInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt1
;
831 // Checksum FADT table
833 AcpiPlatformChecksum (
834 AcpiTableInstance
->Fadt1
,
835 AcpiTableInstance
->Fadt1
->Header
.Length
,
836 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
842 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
844 // Save a pointer to the table
846 AcpiTableInstance
->Dsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
849 // If FADT already exists, update table pointers.
851 if (AcpiTableInstance
->Fadt3
!= NULL
) {
852 if ((UINT64
)(UINTN
)AcpiTableInstance
->Dsdt3
< BASE_4GB
) {
853 AcpiTableInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt3
;
855 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Dsdt3
;
857 &AcpiTableInstance
->Fadt3
->XDsdt
,
863 // Checksum FADT table
865 AcpiPlatformChecksum (
866 AcpiTableInstance
->Fadt3
,
867 AcpiTableInstance
->Fadt3
->Header
.Length
,
868 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
874 // Checksum the table
877 AcpiPlatformChecksum (
878 CurrentTableList
->Table
,
879 CurrentTableList
->Table
->Length
,
880 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
888 // Checksum the table
891 AcpiPlatformChecksum (
892 CurrentTableList
->Table
,
893 CurrentTableList
->Table
->Length
,
894 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
901 // Add the table to the current list of tables
903 InsertTailList (&AcpiTableInstance
->TableList
, &CurrentTableList
->Link
);
906 // Add the table to RSDT and/or XSDT table entry lists.
909 // Add to ACPI 1.0b table tree
911 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
914 // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
916 if (AcpiTableInstance
->NumberOfTableEntries1
>= mEfiAcpiMaxNumTables
) {
917 Status
= ReallocateAcpiTableBuffer (AcpiTableInstance
);
918 ASSERT_EFI_ERROR (Status
);
920 CurrentRsdtEntry
= (UINT32
*)
922 (UINT8
*) AcpiTableInstance
->Rsdt1
+
923 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
924 AcpiTableInstance
->NumberOfTableEntries1
*
929 // Add entry to the RSDT unless its the FACS or DSDT
931 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
934 // Update RSDT length
936 AcpiTableInstance
->Rsdt1
->Length
= AcpiTableInstance
->Rsdt1
->Length
+ sizeof (UINT32
);
938 AcpiTableInstance
->NumberOfTableEntries1
++;
942 // Add to ACPI 2.0/3.0 table tree
944 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
947 // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
949 if (AcpiTableInstance
->NumberOfTableEntries3
>= mEfiAcpiMaxNumTables
) {
950 Status
= ReallocateAcpiTableBuffer (AcpiTableInstance
);
951 ASSERT_EFI_ERROR (Status
);
954 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
956 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
957 // If it becomes necessary to maintain separate table lists, changes will be required.
959 CurrentRsdtEntry
= (UINT32
*)
961 (UINT8
*) AcpiTableInstance
->Rsdt3
+
962 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
963 AcpiTableInstance
->NumberOfTableEntries3
*
969 // This pointer must not be directly dereferenced as the XSDT entries may not
970 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
972 CurrentXsdtEntry
= (VOID
*)
974 (UINT8
*) AcpiTableInstance
->Xsdt
+
975 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
976 AcpiTableInstance
->NumberOfTableEntries3
*
980 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
982 // Add entry to the RSDT
984 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
987 // Update RSDT length
989 AcpiTableInstance
->Rsdt3
->Length
= AcpiTableInstance
->Rsdt3
->Length
+ sizeof (UINT32
);
993 // Add entry to XSDT, XSDT expects 64 bit pointers, but
994 // the table pointers in XSDT are not aligned on 8 byte boundary.
996 Buffer64
= (UINT64
) (UINTN
) CurrentTableList
->Table
;
1006 AcpiTableInstance
->Xsdt
->Length
= AcpiTableInstance
->Xsdt
->Length
+ sizeof (UINT64
);
1008 AcpiTableInstance
->NumberOfTableEntries3
++;
1012 ChecksumCommonTables (AcpiTableInstance
);
1018 This function finds the table specified by the handle and returns a pointer to it.
1019 If the handle is not found, EFI_NOT_FOUND is returned and the contents of Table are
1022 @param Handle Table to find.
1023 @param TableList Table list to search
1024 @param Table Pointer to table found.
1026 @return EFI_SUCCESS The function completed successfully.
1027 @return EFI_NOT_FOUND No table found matching the handle specified.
1033 IN LIST_ENTRY
*TableList
,
1034 OUT EFI_ACPI_TABLE_LIST
**Table
1037 LIST_ENTRY
*CurrentLink
;
1038 EFI_ACPI_TABLE_LIST
*CurrentTable
;
1041 // Check for invalid input parameters
1048 CurrentLink
= TableList
->ForwardLink
;
1050 while (CurrentLink
!= TableList
) {
1051 CurrentTable
= EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink
);
1052 if (CurrentTable
->Handle
== Handle
) {
1054 // Found handle, so return this table.
1056 *Table
= CurrentTable
;
1060 CurrentLink
= CurrentLink
->ForwardLink
;
1065 return EFI_NOT_FOUND
;
1070 This function removes a basic table from the RSDT and/or XSDT.
1071 For Acpi 1.0 tables, pass in the Rsdt.
1072 For Acpi 2.0 tables, pass in both Rsdt and Xsdt.
1074 @param Table Pointer to table found.
1075 @param NumberOfTableEntries Current number of table entries in the RSDT/XSDT
1076 @param Rsdt Pointer to the RSDT to remove from
1077 @param Xsdt Pointer to the Xsdt to remove from
1079 @return EFI_SUCCESS The function completed successfully.
1080 @return EFI_INVALID_PARAMETER The table was not found in both Rsdt and Xsdt.
1084 RemoveTableFromRsdt (
1085 IN OUT EFI_ACPI_TABLE_LIST
* Table
,
1086 IN OUT UINTN
*NumberOfTableEntries
,
1087 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Rsdt OPTIONAL
,
1088 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Xsdt OPTIONAL
1091 UINT32
*CurrentRsdtEntry
;
1092 VOID
*CurrentXsdtEntry
;
1093 UINT64 CurrentTablePointer64
;
1097 // Check for invalid input parameters
1100 ASSERT (NumberOfTableEntries
);
1101 ASSERT (Rsdt
|| Xsdt
);
1104 // Find the table entry in the RSDT and XSDT
1106 for (Index
= 0; Index
< *NumberOfTableEntries
; Index
++) {
1108 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
1109 // If it becomes necessary to maintain separate table lists, changes will be required.
1112 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) Rsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + Index
* sizeof (UINT32
));
1114 CurrentRsdtEntry
= NULL
;
1118 // This pointer must not be directly dereferenced as the XSDT entries may not
1119 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
1121 CurrentXsdtEntry
= (VOID
*) ((UINT8
*) Xsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + Index
* sizeof (UINT64
));
1124 // Read the entry value out of the XSDT
1126 CopyMem (&CurrentTablePointer64
, CurrentXsdtEntry
, sizeof (UINT64
));
1129 // Initialize to NULL
1131 CurrentXsdtEntry
= 0;
1132 CurrentTablePointer64
= 0;
1135 // Check if we have found the corresponding entry in both RSDT and XSDT
1137 if ((CurrentRsdtEntry
== NULL
|| *CurrentRsdtEntry
== (UINT32
) (UINTN
) Table
->Table
) &&
1138 ((Xsdt
== NULL
) || CurrentTablePointer64
== (UINT64
) (UINTN
) Table
->Table
)
1141 // Found entry, so copy all following entries and shrink table
1142 // We actually copy all + 1 to copy the initialized value of memory over
1146 CopyMem (CurrentRsdtEntry
, CurrentRsdtEntry
+ 1, (*NumberOfTableEntries
- Index
) * sizeof (UINT32
));
1147 Rsdt
->Length
= Rsdt
->Length
- sizeof (UINT32
);
1150 CopyMem (CurrentXsdtEntry
, ((UINT64
*) CurrentXsdtEntry
) + 1, (*NumberOfTableEntries
- Index
) * sizeof (UINT64
));
1151 Xsdt
->Length
= Xsdt
->Length
- sizeof (UINT64
);
1154 } else if (Index
+ 1 == *NumberOfTableEntries
) {
1156 // At the last entry, and table not found
1158 return EFI_INVALID_PARAMETER
;
1162 // Checksum the tables
1165 AcpiPlatformChecksum (
1168 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1174 AcpiPlatformChecksum (
1177 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1182 // Decrement the number of tables
1184 (*NumberOfTableEntries
)--;
1191 This function removes a table and frees any associated memory.
1193 @param AcpiTableInstance Instance of the protocol.
1194 @param Version Version(s) to delete.
1195 @param Table Pointer to table found.
1197 @return EFI_SUCCESS The function completed successfully.
1202 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
1203 IN EFI_ACPI_TABLE_VERSION Version
,
1204 IN OUT EFI_ACPI_TABLE_LIST
*Table
1207 UINT32 CurrentTableSignature
;
1208 BOOLEAN RemoveFromRsdt
;
1211 // Check for invalid input parameters
1213 ASSERT (AcpiTableInstance
);
1219 RemoveFromRsdt
= TRUE
;
1221 // Check for Table->Table
1223 ASSERT (Table
->Table
!= NULL
);
1224 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
->Table
)->Signature
;
1227 // Basic tasks to accomplish delete are:
1228 // Determine removal requirements (in RSDT/XSDT or not)
1229 // Remove entry from RSDT/XSDT
1230 // Remove any table references to the table
1231 // If no one is using the table
1232 // Free the table (removing pointers from private data and tables)
1234 // Free list structure
1237 // Determine if this table is in the RSDT or XSDT
1239 if ((CurrentTableSignature
== EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) ||
1240 (CurrentTableSignature
== EFI_ACPI_2_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
) ||
1241 (CurrentTableSignature
== EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
)
1243 RemoveFromRsdt
= FALSE
;
1246 // We don't remove the FADT in the standard way because some
1247 // OS expect the FADT to be early in the table list.
1248 // So we always put it as the first element in the list.
1250 if (CurrentTableSignature
== EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
) {
1251 RemoveFromRsdt
= FALSE
;
1255 // Remove the table from RSDT and XSDT
1257 if (Table
->Table
!= NULL
) {
1259 // This is a basic table, remove it from any lists and the Rsdt and/or Xsdt
1261 if (Version
& EFI_ACPI_TABLE_VERSION_NONE
& Table
->Version
) {
1263 // Remove this version from the table
1265 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_NONE
;
1268 if (Version
& EFI_ACPI_TABLE_VERSION_1_0B
& Table
->Version
) {
1270 // Remove this version from the table
1272 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_1_0B
;
1275 // Remove from Rsdt. We don't care about the return value because it is
1276 // acceptable for the table to not exist in Rsdt.
1277 // We didn't add some tables so we don't remove them.
1279 if (RemoveFromRsdt
) {
1280 RemoveTableFromRsdt (
1282 &AcpiTableInstance
->NumberOfTableEntries1
,
1283 AcpiTableInstance
->Rsdt1
,
1289 if (Version
& ACPI_TABLE_VERSION_GTE_2_0
& Table
->Version
) {
1291 // Remove this version from the table
1293 Table
->Version
= Table
->Version
&~(Version
& ACPI_TABLE_VERSION_GTE_2_0
);
1296 // Remove from Rsdt and Xsdt. We don't care about the return value
1297 // because it is acceptable for the table to not exist in Rsdt/Xsdt.
1298 // We didn't add some tables so we don't remove them.
1300 if (RemoveFromRsdt
) {
1301 RemoveTableFromRsdt (
1303 &AcpiTableInstance
->NumberOfTableEntries3
,
1304 AcpiTableInstance
->Rsdt3
,
1305 AcpiTableInstance
->Xsdt
1310 // Free the table, clean up any dependent tables and our private data pointers.
1312 switch (Table
->Table
->Signature
) {
1314 case EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
1315 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1316 AcpiTableInstance
->Fadt1
= NULL
;
1319 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
1320 AcpiTableInstance
->Fadt3
= NULL
;
1324 case EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
1325 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1326 AcpiTableInstance
->Facs1
= NULL
;
1329 // Update FADT table pointers
1331 if (AcpiTableInstance
->Fadt1
!= NULL
) {
1332 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= 0;
1337 AcpiPlatformChecksum (
1338 AcpiTableInstance
->Fadt1
,
1339 AcpiTableInstance
->Fadt1
->Header
.Length
,
1340 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1346 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
1347 AcpiTableInstance
->Facs3
= NULL
;
1350 // Update FADT table pointers
1352 if (AcpiTableInstance
->Fadt3
!= NULL
) {
1353 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= 0;
1354 ZeroMem (&AcpiTableInstance
->Fadt3
->XFirmwareCtrl
, sizeof (UINT64
));
1359 AcpiPlatformChecksum (
1360 AcpiTableInstance
->Fadt3
,
1361 AcpiTableInstance
->Fadt3
->Header
.Length
,
1362 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1369 case EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
1370 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1371 AcpiTableInstance
->Dsdt1
= NULL
;
1374 // Update FADT table pointers
1376 if (AcpiTableInstance
->Fadt1
!= NULL
) {
1377 AcpiTableInstance
->Fadt1
->Dsdt
= 0;
1382 AcpiPlatformChecksum (
1383 AcpiTableInstance
->Fadt1
,
1384 AcpiTableInstance
->Fadt1
->Header
.Length
,
1385 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1392 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
1393 AcpiTableInstance
->Dsdt3
= NULL
;
1396 // Update FADT table pointers
1398 if (AcpiTableInstance
->Fadt3
!= NULL
) {
1399 AcpiTableInstance
->Fadt3
->Dsdt
= 0;
1400 ZeroMem (&AcpiTableInstance
->Fadt3
->XDsdt
, sizeof (UINT64
));
1405 AcpiPlatformChecksum (
1406 AcpiTableInstance
->Fadt3
,
1407 AcpiTableInstance
->Fadt3
->Header
.Length
,
1408 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1423 // If no version is using this table anymore, remove and free list entry.
1425 if (Table
->Version
== 0) {
1429 gBS
->FreePages (Table
->PageAddress
, Table
->NumberOfPages
);
1430 RemoveEntryList (&(Table
->Link
));
1431 gBS
->FreePool (Table
);
1441 This function finds and removes the table specified by the handle.
1443 @param AcpiTableInstance Instance of the protocol.
1444 @param Version Bitmask of which versions to remove.
1445 @param Handle Table to remove.
1447 @return EFI_SUCCESS The function completed successfully.
1448 @return EFI_ABORTED An error occurred.
1449 @return EFI_NOT_FOUND Handle not found in table list.
1453 RemoveTableFromList (
1454 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
1455 IN EFI_ACPI_TABLE_VERSION Version
,
1459 EFI_ACPI_TABLE_LIST
*Table
;
1462 Table
= (EFI_ACPI_TABLE_LIST
*) NULL
;
1465 // Check for invalid input parameters
1467 ASSERT (AcpiTableInstance
);
1472 Status
= FindTableByHandle (
1474 &AcpiTableInstance
->TableList
,
1477 if (EFI_ERROR (Status
)) {
1478 return EFI_NOT_FOUND
;
1483 Status
= DeleteTable (AcpiTableInstance
, Version
, Table
);
1484 if (EFI_ERROR (Status
)) {
1488 // Completed successfully
1495 This function calculates and updates an UINT8 checksum.
1497 @param Buffer Pointer to buffer to checksum
1498 @param Size Number of bytes to checksum
1499 @param ChecksumOffset Offset to place the checksum result in
1501 @return EFI_SUCCESS The function completed successfully.
1505 AcpiPlatformChecksum (
1508 IN UINTN ChecksumOffset
1516 // Initialize pointer
1521 // set checksum to 0 first
1523 Ptr
[ChecksumOffset
] = 0;
1526 // add all content of buffer
1528 while ((Size
--) != 0) {
1529 Sum
= (UINT8
) (Sum
+ (*Ptr
++));
1535 Ptr
[ChecksumOffset
] = (UINT8
) (0xff - Sum
+ 1);
1542 Checksum all versions of the common tables, RSDP, RSDT, XSDT.
1544 @param AcpiTableInstance Protocol instance private data.
1546 @return EFI_SUCCESS The function completed successfully.
1550 ChecksumCommonTables (
1551 IN OUT EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
1555 // RSDP ACPI 1.0 checksum for 1.0 table. This is only the first 20 bytes of the structure
1557 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1558 AcpiPlatformChecksum (
1559 AcpiTableInstance
->Rsdp1
,
1560 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1561 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1567 // RSDP ACPI 1.0 checksum for 2.0/3.0 table. This is only the first 20 bytes of the structure
1569 AcpiPlatformChecksum (
1570 AcpiTableInstance
->Rsdp3
,
1571 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1572 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1577 // RSDP ACPI 2.0/3.0 checksum, this is the entire table
1579 AcpiPlatformChecksum (
1580 AcpiTableInstance
->Rsdp3
,
1581 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1582 OFFSET_OF (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1586 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1590 AcpiPlatformChecksum (
1591 AcpiTableInstance
->Rsdt1
,
1592 AcpiTableInstance
->Rsdt1
->Length
,
1593 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1597 AcpiPlatformChecksum (
1598 AcpiTableInstance
->Rsdt3
,
1599 AcpiTableInstance
->Rsdt3
->Length
,
1600 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1608 AcpiPlatformChecksum (
1609 AcpiTableInstance
->Xsdt
,
1610 AcpiTableInstance
->Xsdt
->Length
,
1611 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1620 Constructor for the ACPI table protocol. Initializes instance
1623 @param AcpiTableInstance Instance to construct
1625 @return EFI_SUCCESS Instance initialized.
1626 @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
1630 AcpiTableAcpiTableConstructor (
1631 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
1637 UINTN RsdpTableSize
;
1639 EFI_PHYSICAL_ADDRESS PageAddress
;
1642 // Check for invalid input parameters
1644 ASSERT (AcpiTableInstance
);
1647 // If ACPI v1.0b is among the ACPI versions we aim to support, we have to
1648 // ensure that all memory allocations are below 4 GB.
1650 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1651 mAcpiTableAllocType
= AllocateMaxAddress
;
1653 mAcpiTableAllocType
= AllocateAnyPages
;
1656 InitializeListHead (&AcpiTableInstance
->TableList
);
1657 AcpiTableInstance
->CurrentHandle
= 1;
1659 AcpiTableInstance
->AcpiTableProtocol
.InstallAcpiTable
= InstallAcpiTable
;
1660 AcpiTableInstance
->AcpiTableProtocol
.UninstallAcpiTable
= UninstallAcpiTable
;
1662 if (FeaturePcdGet (PcdInstallAcpiSdtProtocol
)) {
1663 SdtAcpiTableAcpiSdtConstructor (AcpiTableInstance
);
1667 // Create RSDP table
1669 RsdpTableSize
= sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1670 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1671 RsdpTableSize
+= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1674 PageAddress
= 0xFFFFFFFF;
1675 Status
= gBS
->AllocatePages (
1676 mAcpiTableAllocType
,
1677 EfiACPIReclaimMemory
,
1678 EFI_SIZE_TO_PAGES (RsdpTableSize
),
1682 if (EFI_ERROR (Status
)) {
1683 return EFI_OUT_OF_RESOURCES
;
1686 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
1687 ZeroMem (Pointer
, RsdpTableSize
);
1689 AcpiTableInstance
->Rsdp1
= (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1690 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1691 Pointer
+= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1693 AcpiTableInstance
->Rsdp3
= (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1696 // Create RSDT, XSDT structures
1698 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
1699 mEfiAcpiMaxNumTables
* sizeof (UINT64
);
1701 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1702 TotalSize
+= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
1703 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
1704 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
1705 mEfiAcpiMaxNumTables
* sizeof (UINT32
);
1709 // Allocate memory in the lower 32 bit of address range for
1710 // compatibility with ACPI 1.0 OS.
1712 // This is done because ACPI 1.0 pointers are 32 bit values.
1713 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
1714 // There is no architectural reason these should be below 4GB, it is purely
1715 // for convenience of implementation that we force memory below 4GB.
1717 PageAddress
= 0xFFFFFFFF;
1718 Status
= gBS
->AllocatePages (
1719 mAcpiTableAllocType
,
1720 EfiACPIReclaimMemory
,
1721 EFI_SIZE_TO_PAGES (TotalSize
),
1725 if (EFI_ERROR (Status
)) {
1726 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
)(UINTN
)AcpiTableInstance
->Rsdp1
, EFI_SIZE_TO_PAGES (RsdpTableSize
));
1727 return EFI_OUT_OF_RESOURCES
;
1730 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
1731 ZeroMem (Pointer
, TotalSize
);
1733 AcpiTableInstance
->Rsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1734 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1735 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1736 AcpiTableInstance
->Rsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1737 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1739 AcpiTableInstance
->Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1744 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1745 CurrentData
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1746 CopyMem (&AcpiTableInstance
->Rsdp1
->Signature
, &CurrentData
, sizeof (UINT64
));
1747 CopyMem (AcpiTableInstance
->Rsdp1
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdp1
->OemId
));
1748 AcpiTableInstance
->Rsdp1
->Reserved
= EFI_ACPI_RESERVED_BYTE
;
1749 AcpiTableInstance
->Rsdp1
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt1
;
1752 CurrentData
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1753 CopyMem (&AcpiTableInstance
->Rsdp3
->Signature
, &CurrentData
, sizeof (UINT64
));
1754 CopyMem (AcpiTableInstance
->Rsdp3
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdp3
->OemId
));
1755 AcpiTableInstance
->Rsdp3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION
;
1756 AcpiTableInstance
->Rsdp3
->Length
= sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1757 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1758 AcpiTableInstance
->Rsdp3
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt3
;
1760 CurrentData
= (UINT64
) (UINTN
) AcpiTableInstance
->Xsdt
;
1761 CopyMem (&AcpiTableInstance
->Rsdp3
->XsdtAddress
, &CurrentData
, sizeof (UINT64
));
1762 SetMem (AcpiTableInstance
->Rsdp3
->Reserved
, 3, EFI_ACPI_RESERVED_BYTE
);
1764 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1768 // Note that we "reserve" one entry for the FADT so it can always be
1769 // at the beginning of the list of tables. Some OS don't seem
1770 // to find it correctly if it is too far down the list.
1772 AcpiTableInstance
->Rsdt1
->Signature
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1773 AcpiTableInstance
->Rsdt1
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1774 AcpiTableInstance
->Rsdt1
->Revision
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1775 CopyMem (AcpiTableInstance
->Rsdt1
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdt1
->OemId
));
1776 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1777 CopyMem (&AcpiTableInstance
->Rsdt1
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1778 AcpiTableInstance
->Rsdt1
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1779 AcpiTableInstance
->Rsdt1
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1780 AcpiTableInstance
->Rsdt1
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1782 // We always reserve first one for FADT
1784 AcpiTableInstance
->NumberOfTableEntries1
= 1;
1785 AcpiTableInstance
->Rsdt1
->Length
= AcpiTableInstance
->Rsdt1
->Length
+ sizeof(UINT32
);
1787 AcpiTableInstance
->Rsdt3
->Signature
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1788 AcpiTableInstance
->Rsdt3
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1789 AcpiTableInstance
->Rsdt3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1790 CopyMem (AcpiTableInstance
->Rsdt3
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdt3
->OemId
));
1791 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1792 CopyMem (&AcpiTableInstance
->Rsdt3
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1793 AcpiTableInstance
->Rsdt3
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1794 AcpiTableInstance
->Rsdt3
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1795 AcpiTableInstance
->Rsdt3
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1797 // We always reserve first one for FADT
1799 AcpiTableInstance
->Rsdt3
->Length
= AcpiTableInstance
->Rsdt3
->Length
+ sizeof(UINT32
);
1801 AcpiTableInstance
->NumberOfTableEntries3
= 1;
1806 AcpiTableInstance
->Xsdt
->Signature
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1807 AcpiTableInstance
->Xsdt
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1808 AcpiTableInstance
->Xsdt
->Revision
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1809 CopyMem (AcpiTableInstance
->Xsdt
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Xsdt
->OemId
));
1810 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1811 CopyMem (&AcpiTableInstance
->Xsdt
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1812 AcpiTableInstance
->Xsdt
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1813 AcpiTableInstance
->Xsdt
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1814 AcpiTableInstance
->Xsdt
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1816 // We always reserve first one for FADT
1818 AcpiTableInstance
->Xsdt
->Length
= AcpiTableInstance
->Xsdt
->Length
+ sizeof(UINT64
);
1820 ChecksumCommonTables (AcpiTableInstance
);
1823 // Completed successfully