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
*
968 // Add entry to the RSDT
970 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
973 // Update RSDT length
975 AcpiTableInstance
->Rsdt3
->Length
= AcpiTableInstance
->Rsdt3
->Length
+ sizeof (UINT32
);
979 // This pointer must not be directly dereferenced as the XSDT entries may not
980 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
982 CurrentXsdtEntry
= (VOID
*)
984 (UINT8
*) AcpiTableInstance
->Xsdt
+
985 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
986 AcpiTableInstance
->NumberOfTableEntries3
*
991 // Add entry to XSDT, XSDT expects 64 bit pointers, but
992 // the table pointers in XSDT are not aligned on 8 byte boundary.
994 Buffer64
= (UINT64
) (UINTN
) CurrentTableList
->Table
;
1004 AcpiTableInstance
->Xsdt
->Length
= AcpiTableInstance
->Xsdt
->Length
+ sizeof (UINT64
);
1006 AcpiTableInstance
->NumberOfTableEntries3
++;
1010 ChecksumCommonTables (AcpiTableInstance
);
1016 This function finds the table specified by the handle and returns a pointer to it.
1017 If the handle is not found, EFI_NOT_FOUND is returned and the contents of Table are
1020 @param Handle Table to find.
1021 @param TableList Table list to search
1022 @param Table Pointer to table found.
1024 @return EFI_SUCCESS The function completed successfully.
1025 @return EFI_NOT_FOUND No table found matching the handle specified.
1031 IN LIST_ENTRY
*TableList
,
1032 OUT EFI_ACPI_TABLE_LIST
**Table
1035 LIST_ENTRY
*CurrentLink
;
1036 EFI_ACPI_TABLE_LIST
*CurrentTable
;
1039 // Check for invalid input parameters
1046 CurrentLink
= TableList
->ForwardLink
;
1048 while (CurrentLink
!= TableList
) {
1049 CurrentTable
= EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink
);
1050 if (CurrentTable
->Handle
== Handle
) {
1052 // Found handle, so return this table.
1054 *Table
= CurrentTable
;
1058 CurrentLink
= CurrentLink
->ForwardLink
;
1063 return EFI_NOT_FOUND
;
1068 This function removes a basic table from the RSDT and/or XSDT.
1069 For Acpi 1.0 tables, pass in the Rsdt.
1070 For Acpi 2.0 tables, pass in both Rsdt and Xsdt.
1072 @param Table Pointer to table found.
1073 @param NumberOfTableEntries Current number of table entries in the RSDT/XSDT
1074 @param Rsdt Pointer to the RSDT to remove from
1075 @param Xsdt Pointer to the Xsdt to remove from
1077 @return EFI_SUCCESS The function completed successfully.
1078 @return EFI_INVALID_PARAMETER The table was not found in both Rsdt and Xsdt.
1082 RemoveTableFromRsdt (
1083 IN OUT EFI_ACPI_TABLE_LIST
* Table
,
1084 IN OUT UINTN
*NumberOfTableEntries
,
1085 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Rsdt OPTIONAL
,
1086 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Xsdt OPTIONAL
1089 UINT32
*CurrentRsdtEntry
;
1090 VOID
*CurrentXsdtEntry
;
1091 UINT64 CurrentTablePointer64
;
1095 // Check for invalid input parameters
1098 ASSERT (NumberOfTableEntries
);
1099 ASSERT (Rsdt
|| Xsdt
);
1102 // Find the table entry in the RSDT and XSDT
1104 for (Index
= 0; Index
< *NumberOfTableEntries
; Index
++) {
1106 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
1107 // If it becomes necessary to maintain separate table lists, changes will be required.
1110 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) Rsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + Index
* sizeof (UINT32
));
1112 CurrentRsdtEntry
= NULL
;
1116 // This pointer must not be directly dereferenced as the XSDT entries may not
1117 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
1119 CurrentXsdtEntry
= (VOID
*) ((UINT8
*) Xsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + Index
* sizeof (UINT64
));
1122 // Read the entry value out of the XSDT
1124 CopyMem (&CurrentTablePointer64
, CurrentXsdtEntry
, sizeof (UINT64
));
1127 // Initialize to NULL
1129 CurrentXsdtEntry
= 0;
1130 CurrentTablePointer64
= 0;
1133 // Check if we have found the corresponding entry in both RSDT and XSDT
1135 if ((CurrentRsdtEntry
== NULL
|| *CurrentRsdtEntry
== (UINT32
) (UINTN
) Table
->Table
) &&
1136 ((Xsdt
== NULL
) || CurrentTablePointer64
== (UINT64
) (UINTN
) Table
->Table
)
1139 // Found entry, so copy all following entries and shrink table
1140 // We actually copy all + 1 to copy the initialized value of memory over
1144 CopyMem (CurrentRsdtEntry
, CurrentRsdtEntry
+ 1, (*NumberOfTableEntries
- Index
) * sizeof (UINT32
));
1145 Rsdt
->Length
= Rsdt
->Length
- sizeof (UINT32
);
1148 CopyMem (CurrentXsdtEntry
, ((UINT64
*) CurrentXsdtEntry
) + 1, (*NumberOfTableEntries
- Index
) * sizeof (UINT64
));
1149 Xsdt
->Length
= Xsdt
->Length
- sizeof (UINT64
);
1152 } else if (Index
+ 1 == *NumberOfTableEntries
) {
1154 // At the last entry, and table not found
1156 return EFI_INVALID_PARAMETER
;
1160 // Checksum the tables
1163 AcpiPlatformChecksum (
1166 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1172 AcpiPlatformChecksum (
1175 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1180 // Decrement the number of tables
1182 (*NumberOfTableEntries
)--;
1189 This function removes a table and frees any associated memory.
1191 @param AcpiTableInstance Instance of the protocol.
1192 @param Version Version(s) to delete.
1193 @param Table Pointer to table found.
1195 @return EFI_SUCCESS The function completed successfully.
1200 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
1201 IN EFI_ACPI_TABLE_VERSION Version
,
1202 IN OUT EFI_ACPI_TABLE_LIST
*Table
1205 UINT32 CurrentTableSignature
;
1206 BOOLEAN RemoveFromRsdt
;
1209 // Check for invalid input parameters
1211 ASSERT (AcpiTableInstance
);
1217 RemoveFromRsdt
= TRUE
;
1219 // Check for Table->Table
1221 ASSERT (Table
->Table
!= NULL
);
1222 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
->Table
)->Signature
;
1225 // Basic tasks to accomplish delete are:
1226 // Determine removal requirements (in RSDT/XSDT or not)
1227 // Remove entry from RSDT/XSDT
1228 // Remove any table references to the table
1229 // If no one is using the table
1230 // Free the table (removing pointers from private data and tables)
1232 // Free list structure
1235 // Determine if this table is in the RSDT or XSDT
1237 if ((CurrentTableSignature
== EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) ||
1238 (CurrentTableSignature
== EFI_ACPI_2_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
) ||
1239 (CurrentTableSignature
== EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
)
1241 RemoveFromRsdt
= FALSE
;
1244 // We don't remove the FADT in the standard way because some
1245 // OS expect the FADT to be early in the table list.
1246 // So we always put it as the first element in the list.
1248 if (CurrentTableSignature
== EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
) {
1249 RemoveFromRsdt
= FALSE
;
1253 // Remove the table from RSDT and XSDT
1255 if (Table
->Table
!= NULL
) {
1257 // This is a basic table, remove it from any lists and the Rsdt and/or Xsdt
1259 if (Version
& EFI_ACPI_TABLE_VERSION_NONE
& Table
->Version
) {
1261 // Remove this version from the table
1263 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_NONE
;
1266 if (Version
& EFI_ACPI_TABLE_VERSION_1_0B
& Table
->Version
) {
1268 // Remove this version from the table
1270 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_1_0B
;
1273 // Remove from Rsdt. We don't care about the return value because it is
1274 // acceptable for the table to not exist in Rsdt.
1275 // We didn't add some tables so we don't remove them.
1277 if (RemoveFromRsdt
) {
1278 RemoveTableFromRsdt (
1280 &AcpiTableInstance
->NumberOfTableEntries1
,
1281 AcpiTableInstance
->Rsdt1
,
1287 if (Version
& ACPI_TABLE_VERSION_GTE_2_0
& Table
->Version
) {
1289 // Remove this version from the table
1291 Table
->Version
= Table
->Version
&~(Version
& ACPI_TABLE_VERSION_GTE_2_0
);
1294 // Remove from Rsdt and Xsdt. We don't care about the return value
1295 // because it is acceptable for the table to not exist in Rsdt/Xsdt.
1296 // We didn't add some tables so we don't remove them.
1298 if (RemoveFromRsdt
) {
1299 RemoveTableFromRsdt (
1301 &AcpiTableInstance
->NumberOfTableEntries3
,
1302 AcpiTableInstance
->Rsdt3
,
1303 AcpiTableInstance
->Xsdt
1308 // Free the table, clean up any dependent tables and our private data pointers.
1310 switch (Table
->Table
->Signature
) {
1312 case EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
1313 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1314 AcpiTableInstance
->Fadt1
= NULL
;
1317 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
1318 AcpiTableInstance
->Fadt3
= NULL
;
1322 case EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
1323 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1324 AcpiTableInstance
->Facs1
= NULL
;
1327 // Update FADT table pointers
1329 if (AcpiTableInstance
->Fadt1
!= NULL
) {
1330 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= 0;
1335 AcpiPlatformChecksum (
1336 AcpiTableInstance
->Fadt1
,
1337 AcpiTableInstance
->Fadt1
->Header
.Length
,
1338 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1344 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
1345 AcpiTableInstance
->Facs3
= NULL
;
1348 // Update FADT table pointers
1350 if (AcpiTableInstance
->Fadt3
!= NULL
) {
1351 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= 0;
1352 ZeroMem (&AcpiTableInstance
->Fadt3
->XFirmwareCtrl
, sizeof (UINT64
));
1357 AcpiPlatformChecksum (
1358 AcpiTableInstance
->Fadt3
,
1359 AcpiTableInstance
->Fadt3
->Header
.Length
,
1360 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1367 case EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
1368 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1369 AcpiTableInstance
->Dsdt1
= NULL
;
1372 // Update FADT table pointers
1374 if (AcpiTableInstance
->Fadt1
!= NULL
) {
1375 AcpiTableInstance
->Fadt1
->Dsdt
= 0;
1380 AcpiPlatformChecksum (
1381 AcpiTableInstance
->Fadt1
,
1382 AcpiTableInstance
->Fadt1
->Header
.Length
,
1383 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1390 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
1391 AcpiTableInstance
->Dsdt3
= NULL
;
1394 // Update FADT table pointers
1396 if (AcpiTableInstance
->Fadt3
!= NULL
) {
1397 AcpiTableInstance
->Fadt3
->Dsdt
= 0;
1398 ZeroMem (&AcpiTableInstance
->Fadt3
->XDsdt
, sizeof (UINT64
));
1403 AcpiPlatformChecksum (
1404 AcpiTableInstance
->Fadt3
,
1405 AcpiTableInstance
->Fadt3
->Header
.Length
,
1406 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1421 // If no version is using this table anymore, remove and free list entry.
1423 if (Table
->Version
== 0) {
1427 gBS
->FreePages (Table
->PageAddress
, Table
->NumberOfPages
);
1428 RemoveEntryList (&(Table
->Link
));
1429 gBS
->FreePool (Table
);
1439 This function finds and removes the table specified by the handle.
1441 @param AcpiTableInstance Instance of the protocol.
1442 @param Version Bitmask of which versions to remove.
1443 @param Handle Table to remove.
1445 @return EFI_SUCCESS The function completed successfully.
1446 @return EFI_ABORTED An error occurred.
1447 @return EFI_NOT_FOUND Handle not found in table list.
1451 RemoveTableFromList (
1452 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
1453 IN EFI_ACPI_TABLE_VERSION Version
,
1457 EFI_ACPI_TABLE_LIST
*Table
;
1460 Table
= (EFI_ACPI_TABLE_LIST
*) NULL
;
1463 // Check for invalid input parameters
1465 ASSERT (AcpiTableInstance
);
1470 Status
= FindTableByHandle (
1472 &AcpiTableInstance
->TableList
,
1475 if (EFI_ERROR (Status
)) {
1476 return EFI_NOT_FOUND
;
1481 Status
= DeleteTable (AcpiTableInstance
, Version
, Table
);
1482 if (EFI_ERROR (Status
)) {
1486 // Completed successfully
1493 This function calculates and updates an UINT8 checksum.
1495 @param Buffer Pointer to buffer to checksum
1496 @param Size Number of bytes to checksum
1497 @param ChecksumOffset Offset to place the checksum result in
1499 @return EFI_SUCCESS The function completed successfully.
1503 AcpiPlatformChecksum (
1506 IN UINTN ChecksumOffset
1514 // Initialize pointer
1519 // set checksum to 0 first
1521 Ptr
[ChecksumOffset
] = 0;
1524 // add all content of buffer
1526 while ((Size
--) != 0) {
1527 Sum
= (UINT8
) (Sum
+ (*Ptr
++));
1533 Ptr
[ChecksumOffset
] = (UINT8
) (0xff - Sum
+ 1);
1540 Checksum all versions of the common tables, RSDP, RSDT, XSDT.
1542 @param AcpiTableInstance Protocol instance private data.
1544 @return EFI_SUCCESS The function completed successfully.
1548 ChecksumCommonTables (
1549 IN OUT EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
1553 // RSDP ACPI 1.0 checksum for 1.0 table. This is only the first 20 bytes of the structure
1555 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1556 AcpiPlatformChecksum (
1557 AcpiTableInstance
->Rsdp1
,
1558 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1559 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1565 // RSDP ACPI 1.0 checksum for 2.0/3.0 table. This is only the first 20 bytes of the structure
1567 AcpiPlatformChecksum (
1568 AcpiTableInstance
->Rsdp3
,
1569 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1570 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1575 // RSDP ACPI 2.0/3.0 checksum, this is the entire table
1577 AcpiPlatformChecksum (
1578 AcpiTableInstance
->Rsdp3
,
1579 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1580 OFFSET_OF (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1584 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1588 AcpiPlatformChecksum (
1589 AcpiTableInstance
->Rsdt1
,
1590 AcpiTableInstance
->Rsdt1
->Length
,
1591 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1595 AcpiPlatformChecksum (
1596 AcpiTableInstance
->Rsdt3
,
1597 AcpiTableInstance
->Rsdt3
->Length
,
1598 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1606 AcpiPlatformChecksum (
1607 AcpiTableInstance
->Xsdt
,
1608 AcpiTableInstance
->Xsdt
->Length
,
1609 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1618 Constructor for the ACPI table protocol. Initializes instance
1621 @param AcpiTableInstance Instance to construct
1623 @return EFI_SUCCESS Instance initialized.
1624 @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
1628 AcpiTableAcpiTableConstructor (
1629 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
1635 UINTN RsdpTableSize
;
1637 EFI_PHYSICAL_ADDRESS PageAddress
;
1640 // Check for invalid input parameters
1642 ASSERT (AcpiTableInstance
);
1645 // If ACPI v1.0b is among the ACPI versions we aim to support, we have to
1646 // ensure that all memory allocations are below 4 GB.
1648 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1649 mAcpiTableAllocType
= AllocateMaxAddress
;
1651 mAcpiTableAllocType
= AllocateAnyPages
;
1654 InitializeListHead (&AcpiTableInstance
->TableList
);
1655 AcpiTableInstance
->CurrentHandle
= 1;
1657 AcpiTableInstance
->AcpiTableProtocol
.InstallAcpiTable
= InstallAcpiTable
;
1658 AcpiTableInstance
->AcpiTableProtocol
.UninstallAcpiTable
= UninstallAcpiTable
;
1660 if (FeaturePcdGet (PcdInstallAcpiSdtProtocol
)) {
1661 SdtAcpiTableAcpiSdtConstructor (AcpiTableInstance
);
1665 // Create RSDP table
1667 RsdpTableSize
= sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1668 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1669 RsdpTableSize
+= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1672 PageAddress
= 0xFFFFFFFF;
1673 Status
= gBS
->AllocatePages (
1674 mAcpiTableAllocType
,
1675 EfiACPIReclaimMemory
,
1676 EFI_SIZE_TO_PAGES (RsdpTableSize
),
1680 if (EFI_ERROR (Status
)) {
1681 return EFI_OUT_OF_RESOURCES
;
1684 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
1685 ZeroMem (Pointer
, RsdpTableSize
);
1687 AcpiTableInstance
->Rsdp1
= (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1688 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1689 Pointer
+= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1691 AcpiTableInstance
->Rsdp3
= (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1694 // Create RSDT, XSDT structures
1696 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
1697 mEfiAcpiMaxNumTables
* sizeof (UINT64
);
1699 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1700 TotalSize
+= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
1701 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
1702 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
1703 mEfiAcpiMaxNumTables
* sizeof (UINT32
);
1707 // Allocate memory in the lower 32 bit of address range for
1708 // compatibility with ACPI 1.0 OS.
1710 // This is done because ACPI 1.0 pointers are 32 bit values.
1711 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
1712 // There is no architectural reason these should be below 4GB, it is purely
1713 // for convenience of implementation that we force memory below 4GB.
1715 PageAddress
= 0xFFFFFFFF;
1716 Status
= gBS
->AllocatePages (
1717 mAcpiTableAllocType
,
1718 EfiACPIReclaimMemory
,
1719 EFI_SIZE_TO_PAGES (TotalSize
),
1723 if (EFI_ERROR (Status
)) {
1724 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
)(UINTN
)AcpiTableInstance
->Rsdp1
, EFI_SIZE_TO_PAGES (RsdpTableSize
));
1725 return EFI_OUT_OF_RESOURCES
;
1728 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
1729 ZeroMem (Pointer
, TotalSize
);
1731 AcpiTableInstance
->Rsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1732 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1733 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1734 AcpiTableInstance
->Rsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1735 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1737 AcpiTableInstance
->Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1742 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1743 CurrentData
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1744 CopyMem (&AcpiTableInstance
->Rsdp1
->Signature
, &CurrentData
, sizeof (UINT64
));
1745 CopyMem (AcpiTableInstance
->Rsdp1
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdp1
->OemId
));
1746 AcpiTableInstance
->Rsdp1
->Reserved
= EFI_ACPI_RESERVED_BYTE
;
1747 AcpiTableInstance
->Rsdp1
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt1
;
1750 CurrentData
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1751 CopyMem (&AcpiTableInstance
->Rsdp3
->Signature
, &CurrentData
, sizeof (UINT64
));
1752 CopyMem (AcpiTableInstance
->Rsdp3
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdp3
->OemId
));
1753 AcpiTableInstance
->Rsdp3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION
;
1754 AcpiTableInstance
->Rsdp3
->Length
= sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1755 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1756 AcpiTableInstance
->Rsdp3
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt3
;
1758 CurrentData
= (UINT64
) (UINTN
) AcpiTableInstance
->Xsdt
;
1759 CopyMem (&AcpiTableInstance
->Rsdp3
->XsdtAddress
, &CurrentData
, sizeof (UINT64
));
1760 SetMem (AcpiTableInstance
->Rsdp3
->Reserved
, 3, EFI_ACPI_RESERVED_BYTE
);
1762 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1766 // Note that we "reserve" one entry for the FADT so it can always be
1767 // at the beginning of the list of tables. Some OS don't seem
1768 // to find it correctly if it is too far down the list.
1770 AcpiTableInstance
->Rsdt1
->Signature
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1771 AcpiTableInstance
->Rsdt1
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1772 AcpiTableInstance
->Rsdt1
->Revision
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1773 CopyMem (AcpiTableInstance
->Rsdt1
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdt1
->OemId
));
1774 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1775 CopyMem (&AcpiTableInstance
->Rsdt1
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1776 AcpiTableInstance
->Rsdt1
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1777 AcpiTableInstance
->Rsdt1
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1778 AcpiTableInstance
->Rsdt1
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1780 // We always reserve first one for FADT
1782 AcpiTableInstance
->NumberOfTableEntries1
= 1;
1783 AcpiTableInstance
->Rsdt1
->Length
= AcpiTableInstance
->Rsdt1
->Length
+ sizeof(UINT32
);
1785 AcpiTableInstance
->Rsdt3
->Signature
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1786 AcpiTableInstance
->Rsdt3
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1787 AcpiTableInstance
->Rsdt3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1788 CopyMem (AcpiTableInstance
->Rsdt3
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdt3
->OemId
));
1789 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1790 CopyMem (&AcpiTableInstance
->Rsdt3
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1791 AcpiTableInstance
->Rsdt3
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1792 AcpiTableInstance
->Rsdt3
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1793 AcpiTableInstance
->Rsdt3
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1795 // We always reserve first one for FADT
1797 AcpiTableInstance
->Rsdt3
->Length
= AcpiTableInstance
->Rsdt3
->Length
+ sizeof(UINT32
);
1799 AcpiTableInstance
->NumberOfTableEntries3
= 1;
1804 AcpiTableInstance
->Xsdt
->Signature
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1805 AcpiTableInstance
->Xsdt
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1806 AcpiTableInstance
->Xsdt
->Revision
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1807 CopyMem (AcpiTableInstance
->Xsdt
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Xsdt
->OemId
));
1808 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1809 CopyMem (&AcpiTableInstance
->Xsdt
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1810 AcpiTableInstance
->Xsdt
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1811 AcpiTableInstance
->Xsdt
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1812 AcpiTableInstance
->Xsdt
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1814 // We always reserve first one for FADT
1816 AcpiTableInstance
->Xsdt
->Length
= AcpiTableInstance
->Xsdt
->Length
+ sizeof(UINT64
);
1818 ChecksumCommonTables (AcpiTableInstance
);
1821 // Completed successfully