2 ACPI Table Protocol Implementation
4 Copyright (c) 2006 - 2016, 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 AcpiTableInstance
->Fadt3
->Dsdt
= 0;
653 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Dsdt3
;
654 CopyMem (&AcpiTableInstance
->Fadt3
->XDsdt
, &Buffer64
, sizeof (UINT64
));
658 // RSDP OEM information is updated to match the FADT OEM information
661 &AcpiTableInstance
->Rsdp3
->OemId
,
662 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
666 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
668 // RSDT OEM information is updated to match FADT OEM information.
671 &AcpiTableInstance
->Rsdt3
->OemId
,
672 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
676 &AcpiTableInstance
->Rsdt3
->OemTableId
,
677 &AcpiTableInstance
->Fadt3
->Header
.OemTableId
,
680 AcpiTableInstance
->Rsdt3
->OemRevision
= AcpiTableInstance
->Fadt3
->Header
.OemRevision
;
684 // XSDT OEM information is updated to match FADT OEM information.
687 &AcpiTableInstance
->Xsdt
->OemId
,
688 &AcpiTableInstance
->Fadt3
->Header
.OemId
,
692 &AcpiTableInstance
->Xsdt
->OemTableId
,
693 &AcpiTableInstance
->Fadt3
->Header
.OemTableId
,
696 AcpiTableInstance
->Xsdt
->OemRevision
= AcpiTableInstance
->Fadt3
->Header
.OemRevision
;
699 // Checksum the table
702 AcpiPlatformChecksum (
703 CurrentTableList
->Table
,
704 CurrentTableList
->Table
->Length
,
705 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
711 case EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
713 // Check that the table has not been previously added.
715 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Facs1
!= NULL
) ||
716 ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0 && AcpiTableInstance
->Facs3
!= NULL
)
718 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
719 gBS
->FreePool (CurrentTableList
);
720 return EFI_ACCESS_DENIED
;
723 // FACS is referenced by FADT and is not part of RSDT
728 // Add the table to the appropriate table version
730 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
732 // Save a pointer to the table
734 AcpiTableInstance
->Facs1
= (EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
737 // If FADT already exists, update table pointers.
739 if (AcpiTableInstance
->Fadt1
!= NULL
) {
740 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs1
;
743 // Checksum FADT table
745 AcpiPlatformChecksum (
746 AcpiTableInstance
->Fadt1
,
747 AcpiTableInstance
->Fadt1
->Header
.Length
,
748 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
754 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
756 // Save a pointer to the table
758 AcpiTableInstance
->Facs3
= (EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE
*) CurrentTableList
->Table
;
761 // If FADT already exists, update table pointers.
763 if (AcpiTableInstance
->Fadt3
!= NULL
) {
765 // Note: If the FIRMWARE_CTRL is non-zero, then X_FIRMWARE_CTRL must be zero, and
768 if ((UINT64
)(UINTN
)AcpiTableInstance
->Facs3
< BASE_4GB
) {
769 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= (UINT32
) (UINTN
) AcpiTableInstance
->Facs3
;
770 ZeroMem (&AcpiTableInstance
->Fadt3
->XFirmwareCtrl
, sizeof (UINT64
));
772 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Facs3
;
774 &AcpiTableInstance
->Fadt3
->XFirmwareCtrl
,
778 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= 0;
782 // Checksum FADT table
784 AcpiPlatformChecksum (
785 AcpiTableInstance
->Fadt3
,
786 AcpiTableInstance
->Fadt3
->Header
.Length
,
787 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
795 case EFI_ACPI_1_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
797 // Check that the table has not been previously added.
799 if (((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0 && AcpiTableInstance
->Dsdt1
!= NULL
) ||
800 ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0 && AcpiTableInstance
->Dsdt3
!= NULL
)
802 gBS
->FreePages (CurrentTableList
->PageAddress
, CurrentTableList
->NumberOfPages
);
803 gBS
->FreePool (CurrentTableList
);
804 return EFI_ACCESS_DENIED
;
807 // DSDT is referenced by FADT and is not part of RSDT
812 // Add the table to the appropriate table version
814 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
816 // Save a pointer to the table
818 AcpiTableInstance
->Dsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
821 // If FADT already exists, update table pointers.
823 if (AcpiTableInstance
->Fadt1
!= NULL
) {
824 AcpiTableInstance
->Fadt1
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt1
;
827 // Checksum FADT table
829 AcpiPlatformChecksum (
830 AcpiTableInstance
->Fadt1
,
831 AcpiTableInstance
->Fadt1
->Header
.Length
,
832 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
838 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
840 // Save a pointer to the table
842 AcpiTableInstance
->Dsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) CurrentTableList
->Table
;
845 // If FADT already exists, update table pointers.
847 if (AcpiTableInstance
->Fadt3
!= NULL
) {
848 if ((UINT64
)(UINTN
)AcpiTableInstance
->Dsdt3
< BASE_4GB
) {
849 AcpiTableInstance
->Fadt3
->Dsdt
= (UINT32
) (UINTN
) AcpiTableInstance
->Dsdt3
;
851 Buffer64
= (UINT64
) (UINTN
) AcpiTableInstance
->Dsdt3
;
852 CopyMem (&AcpiTableInstance
->Fadt3
->XDsdt
, &Buffer64
, sizeof (UINT64
));
855 // Checksum FADT table
857 AcpiPlatformChecksum (
858 AcpiTableInstance
->Fadt3
,
859 AcpiTableInstance
->Fadt3
->Header
.Length
,
860 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
866 // Checksum the table
869 AcpiPlatformChecksum (
870 CurrentTableList
->Table
,
871 CurrentTableList
->Table
->Length
,
872 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
880 // Checksum the table
883 AcpiPlatformChecksum (
884 CurrentTableList
->Table
,
885 CurrentTableList
->Table
->Length
,
886 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
893 // Add the table to the current list of tables
895 InsertTailList (&AcpiTableInstance
->TableList
, &CurrentTableList
->Link
);
898 // Add the table to RSDT and/or XSDT table entry lists.
901 // Add to ACPI 1.0b table tree
903 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
906 // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
908 if (AcpiTableInstance
->NumberOfTableEntries1
>= mEfiAcpiMaxNumTables
) {
909 Status
= ReallocateAcpiTableBuffer (AcpiTableInstance
);
910 ASSERT_EFI_ERROR (Status
);
912 CurrentRsdtEntry
= (UINT32
*)
914 (UINT8
*) AcpiTableInstance
->Rsdt1
+
915 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
916 AcpiTableInstance
->NumberOfTableEntries1
*
921 // Add entry to the RSDT unless its the FACS or DSDT
923 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
926 // Update RSDT length
928 AcpiTableInstance
->Rsdt1
->Length
= AcpiTableInstance
->Rsdt1
->Length
+ sizeof (UINT32
);
930 AcpiTableInstance
->NumberOfTableEntries1
++;
934 // Add to ACPI 2.0/3.0 table tree
936 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
939 // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
941 if (AcpiTableInstance
->NumberOfTableEntries3
>= mEfiAcpiMaxNumTables
) {
942 Status
= ReallocateAcpiTableBuffer (AcpiTableInstance
);
943 ASSERT_EFI_ERROR (Status
);
946 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
948 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
949 // If it becomes necessary to maintain separate table lists, changes will be required.
951 CurrentRsdtEntry
= (UINT32
*)
953 (UINT8
*) AcpiTableInstance
->Rsdt3
+
954 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
955 AcpiTableInstance
->NumberOfTableEntries3
*
960 // Add entry to the RSDT
962 *CurrentRsdtEntry
= (UINT32
) (UINTN
) CurrentTableList
->Table
;
965 // Update RSDT length
967 AcpiTableInstance
->Rsdt3
->Length
= AcpiTableInstance
->Rsdt3
->Length
+ sizeof (UINT32
);
971 // This pointer must not be directly dereferenced as the XSDT entries may not
972 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
974 CurrentXsdtEntry
= (VOID
*)
976 (UINT8
*) AcpiTableInstance
->Xsdt
+
977 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) +
978 AcpiTableInstance
->NumberOfTableEntries3
*
983 // Add entry to XSDT, XSDT expects 64 bit pointers, but
984 // the table pointers in XSDT are not aligned on 8 byte boundary.
986 Buffer64
= (UINT64
) (UINTN
) CurrentTableList
->Table
;
996 AcpiTableInstance
->Xsdt
->Length
= AcpiTableInstance
->Xsdt
->Length
+ sizeof (UINT64
);
998 AcpiTableInstance
->NumberOfTableEntries3
++;
1002 ChecksumCommonTables (AcpiTableInstance
);
1008 This function finds the table specified by the handle and returns a pointer to it.
1009 If the handle is not found, EFI_NOT_FOUND is returned and the contents of Table are
1012 @param Handle Table to find.
1013 @param TableList Table list to search
1014 @param Table Pointer to table found.
1016 @return EFI_SUCCESS The function completed successfully.
1017 @return EFI_NOT_FOUND No table found matching the handle specified.
1023 IN LIST_ENTRY
*TableList
,
1024 OUT EFI_ACPI_TABLE_LIST
**Table
1027 LIST_ENTRY
*CurrentLink
;
1028 EFI_ACPI_TABLE_LIST
*CurrentTable
;
1031 // Check for invalid input parameters
1038 CurrentLink
= TableList
->ForwardLink
;
1040 while (CurrentLink
!= TableList
) {
1041 CurrentTable
= EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink
);
1042 if (CurrentTable
->Handle
== Handle
) {
1044 // Found handle, so return this table.
1046 *Table
= CurrentTable
;
1050 CurrentLink
= CurrentLink
->ForwardLink
;
1055 return EFI_NOT_FOUND
;
1060 This function removes a basic table from the RSDT and/or XSDT.
1061 For Acpi 1.0 tables, pass in the Rsdt.
1062 For Acpi 2.0 tables, pass in both Rsdt and Xsdt.
1064 @param Table Pointer to table found.
1065 @param NumberOfTableEntries Current number of table entries in the RSDT/XSDT
1066 @param Rsdt Pointer to the RSDT to remove from
1067 @param Xsdt Pointer to the Xsdt to remove from
1069 @return EFI_SUCCESS The function completed successfully.
1070 @return EFI_INVALID_PARAMETER The table was not found in both Rsdt and Xsdt.
1074 RemoveTableFromRsdt (
1075 IN OUT EFI_ACPI_TABLE_LIST
* Table
,
1076 IN OUT UINTN
*NumberOfTableEntries
,
1077 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Rsdt OPTIONAL
,
1078 IN OUT EFI_ACPI_DESCRIPTION_HEADER
* Xsdt OPTIONAL
1081 UINT32
*CurrentRsdtEntry
;
1082 VOID
*CurrentXsdtEntry
;
1083 UINT64 CurrentTablePointer64
;
1087 // Check for invalid input parameters
1090 ASSERT (NumberOfTableEntries
);
1091 ASSERT (Rsdt
|| Xsdt
);
1094 // Find the table entry in the RSDT and XSDT
1096 for (Index
= 0; Index
< *NumberOfTableEntries
; Index
++) {
1098 // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
1099 // If it becomes necessary to maintain separate table lists, changes will be required.
1102 CurrentRsdtEntry
= (UINT32
*) ((UINT8
*) Rsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + Index
* sizeof (UINT32
));
1104 CurrentRsdtEntry
= NULL
;
1108 // This pointer must not be directly dereferenced as the XSDT entries may not
1109 // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
1111 CurrentXsdtEntry
= (VOID
*) ((UINT8
*) Xsdt
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + Index
* sizeof (UINT64
));
1114 // Read the entry value out of the XSDT
1116 CopyMem (&CurrentTablePointer64
, CurrentXsdtEntry
, sizeof (UINT64
));
1119 // Initialize to NULL
1121 CurrentXsdtEntry
= 0;
1122 CurrentTablePointer64
= 0;
1125 // Check if we have found the corresponding entry in both RSDT and XSDT
1127 if (((Rsdt
== NULL
) || *CurrentRsdtEntry
== (UINT32
) (UINTN
) Table
->Table
) &&
1128 ((Xsdt
== NULL
) || CurrentTablePointer64
== (UINT64
) (UINTN
) Table
->Table
)
1131 // Found entry, so copy all following entries and shrink table
1132 // We actually copy all + 1 to copy the initialized value of memory over
1136 CopyMem (CurrentRsdtEntry
, CurrentRsdtEntry
+ 1, (*NumberOfTableEntries
- Index
) * sizeof (UINT32
));
1137 Rsdt
->Length
= Rsdt
->Length
- sizeof (UINT32
);
1140 CopyMem (CurrentXsdtEntry
, ((UINT64
*) CurrentXsdtEntry
) + 1, (*NumberOfTableEntries
- Index
) * sizeof (UINT64
));
1141 Xsdt
->Length
= Xsdt
->Length
- sizeof (UINT64
);
1144 } else if (Index
+ 1 == *NumberOfTableEntries
) {
1146 // At the last entry, and table not found
1148 return EFI_INVALID_PARAMETER
;
1152 // Checksum the tables
1155 AcpiPlatformChecksum (
1158 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1164 AcpiPlatformChecksum (
1167 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1172 // Decrement the number of tables
1174 (*NumberOfTableEntries
)--;
1181 This function removes a table and frees any associated memory.
1183 @param AcpiTableInstance Instance of the protocol.
1184 @param Version Version(s) to delete.
1185 @param Table Pointer to table found.
1187 @return EFI_SUCCESS The function completed successfully.
1192 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
1193 IN EFI_ACPI_TABLE_VERSION Version
,
1194 IN OUT EFI_ACPI_TABLE_LIST
*Table
1197 UINT32 CurrentTableSignature
;
1198 BOOLEAN RemoveFromRsdt
;
1201 // Check for invalid input parameters
1203 ASSERT (AcpiTableInstance
);
1209 RemoveFromRsdt
= TRUE
;
1211 // Check for Table->Table
1213 ASSERT (Table
->Table
!= NULL
);
1214 CurrentTableSignature
= ((EFI_ACPI_COMMON_HEADER
*) Table
->Table
)->Signature
;
1217 // Basic tasks to accomplish delete are:
1218 // Determine removal requirements (in RSDT/XSDT or not)
1219 // Remove entry from RSDT/XSDT
1220 // Remove any table references to the table
1221 // If no one is using the table
1222 // Free the table (removing pointers from private data and tables)
1224 // Free list structure
1227 // Determine if this table is in the RSDT or XSDT
1229 if ((CurrentTableSignature
== EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
) ||
1230 (CurrentTableSignature
== EFI_ACPI_2_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
) ||
1231 (CurrentTableSignature
== EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
)
1233 RemoveFromRsdt
= FALSE
;
1236 // We don't remove the FADT in the standard way because some
1237 // OS expect the FADT to be early in the table list.
1238 // So we always put it as the first element in the list.
1240 if (CurrentTableSignature
== EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
) {
1241 RemoveFromRsdt
= FALSE
;
1245 // Remove the table from RSDT and XSDT
1247 if (Table
->Table
!= NULL
) {
1249 // This is a basic table, remove it from any lists and the Rsdt and/or Xsdt
1251 if (Version
& EFI_ACPI_TABLE_VERSION_NONE
& Table
->Version
) {
1253 // Remove this version from the table
1255 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_NONE
;
1258 if (Version
& EFI_ACPI_TABLE_VERSION_1_0B
& Table
->Version
) {
1260 // Remove this version from the table
1262 Table
->Version
= Table
->Version
&~EFI_ACPI_TABLE_VERSION_1_0B
;
1265 // Remove from Rsdt. We don't care about the return value because it is
1266 // acceptable for the table to not exist in Rsdt.
1267 // We didn't add some tables so we don't remove them.
1269 if (RemoveFromRsdt
) {
1270 RemoveTableFromRsdt (
1272 &AcpiTableInstance
->NumberOfTableEntries1
,
1273 AcpiTableInstance
->Rsdt1
,
1279 if (Version
& ACPI_TABLE_VERSION_GTE_2_0
& Table
->Version
) {
1281 // Remove this version from the table
1283 Table
->Version
= Table
->Version
&~(Version
& ACPI_TABLE_VERSION_GTE_2_0
);
1286 // Remove from Rsdt and Xsdt. We don't care about the return value
1287 // because it is acceptable for the table to not exist in Rsdt/Xsdt.
1288 // We didn't add some tables so we don't remove them.
1290 if (RemoveFromRsdt
) {
1291 RemoveTableFromRsdt (
1293 &AcpiTableInstance
->NumberOfTableEntries3
,
1294 AcpiTableInstance
->Rsdt3
,
1295 AcpiTableInstance
->Xsdt
1300 // Free the table, clean up any dependent tables and our private data pointers.
1302 switch (Table
->Table
->Signature
) {
1304 case EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
:
1305 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1306 AcpiTableInstance
->Fadt1
= NULL
;
1309 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
1310 AcpiTableInstance
->Fadt3
= NULL
;
1314 case EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
:
1315 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1316 AcpiTableInstance
->Facs1
= NULL
;
1319 // Update FADT table pointers
1321 if (AcpiTableInstance
->Fadt1
!= NULL
) {
1322 AcpiTableInstance
->Fadt1
->FirmwareCtrl
= 0;
1327 AcpiPlatformChecksum (
1328 AcpiTableInstance
->Fadt1
,
1329 AcpiTableInstance
->Fadt1
->Header
.Length
,
1330 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1336 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
1337 AcpiTableInstance
->Facs3
= NULL
;
1340 // Update FADT table pointers
1342 if (AcpiTableInstance
->Fadt3
!= NULL
) {
1343 AcpiTableInstance
->Fadt3
->FirmwareCtrl
= 0;
1344 ZeroMem (&AcpiTableInstance
->Fadt3
->XFirmwareCtrl
, sizeof (UINT64
));
1349 AcpiPlatformChecksum (
1350 AcpiTableInstance
->Fadt3
,
1351 AcpiTableInstance
->Fadt3
->Header
.Length
,
1352 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1359 case EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
:
1360 if ((Version
& EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1361 AcpiTableInstance
->Dsdt1
= NULL
;
1364 // Update FADT table pointers
1366 if (AcpiTableInstance
->Fadt1
!= NULL
) {
1367 AcpiTableInstance
->Fadt1
->Dsdt
= 0;
1372 AcpiPlatformChecksum (
1373 AcpiTableInstance
->Fadt1
,
1374 AcpiTableInstance
->Fadt1
->Header
.Length
,
1375 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1382 if ((Version
& ACPI_TABLE_VERSION_GTE_2_0
) != 0) {
1383 AcpiTableInstance
->Dsdt3
= NULL
;
1386 // Update FADT table pointers
1388 if (AcpiTableInstance
->Fadt3
!= NULL
) {
1389 AcpiTableInstance
->Fadt3
->Dsdt
= 0;
1390 ZeroMem (&AcpiTableInstance
->Fadt3
->XDsdt
, sizeof (UINT64
));
1395 AcpiPlatformChecksum (
1396 AcpiTableInstance
->Fadt3
,
1397 AcpiTableInstance
->Fadt3
->Header
.Length
,
1398 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1413 // If no version is using this table anymore, remove and free list entry.
1415 if (Table
->Version
== 0) {
1419 gBS
->FreePages (Table
->PageAddress
, Table
->NumberOfPages
);
1420 RemoveEntryList (&(Table
->Link
));
1421 gBS
->FreePool (Table
);
1431 This function finds and removes the table specified by the handle.
1433 @param AcpiTableInstance Instance of the protocol.
1434 @param Version Bitmask of which versions to remove.
1435 @param Handle Table to remove.
1437 @return EFI_SUCCESS The function completed successfully.
1438 @return EFI_ABORTED An error occurred.
1439 @return EFI_NOT_FOUND Handle not found in table list.
1443 RemoveTableFromList (
1444 IN EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
,
1445 IN EFI_ACPI_TABLE_VERSION Version
,
1449 EFI_ACPI_TABLE_LIST
*Table
;
1452 Table
= (EFI_ACPI_TABLE_LIST
*) NULL
;
1455 // Check for invalid input parameters
1457 ASSERT (AcpiTableInstance
);
1462 Status
= FindTableByHandle (
1464 &AcpiTableInstance
->TableList
,
1467 if (EFI_ERROR (Status
)) {
1468 return EFI_NOT_FOUND
;
1473 Status
= DeleteTable (AcpiTableInstance
, Version
, Table
);
1474 if (EFI_ERROR (Status
)) {
1478 // Completed successfully
1485 This function calculates and updates an UINT8 checksum.
1487 @param Buffer Pointer to buffer to checksum
1488 @param Size Number of bytes to checksum
1489 @param ChecksumOffset Offset to place the checksum result in
1491 @return EFI_SUCCESS The function completed successfully.
1495 AcpiPlatformChecksum (
1498 IN UINTN ChecksumOffset
1506 // Initialize pointer
1511 // set checksum to 0 first
1513 Ptr
[ChecksumOffset
] = 0;
1516 // add all content of buffer
1518 while ((Size
--) != 0) {
1519 Sum
= (UINT8
) (Sum
+ (*Ptr
++));
1525 Ptr
[ChecksumOffset
] = (UINT8
) (0xff - Sum
+ 1);
1532 Checksum all versions of the common tables, RSDP, RSDT, XSDT.
1534 @param AcpiTableInstance Protocol instance private data.
1536 @return EFI_SUCCESS The function completed successfully.
1540 ChecksumCommonTables (
1541 IN OUT EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
1545 // RSDP ACPI 1.0 checksum for 1.0 table. This is only the first 20 bytes of the structure
1547 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1548 AcpiPlatformChecksum (
1549 AcpiTableInstance
->Rsdp1
,
1550 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1551 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1557 // RSDP ACPI 1.0 checksum for 2.0/3.0 table. This is only the first 20 bytes of the structure
1559 AcpiPlatformChecksum (
1560 AcpiTableInstance
->Rsdp3
,
1561 sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1562 OFFSET_OF (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1567 // RSDP ACPI 2.0/3.0 checksum, this is the entire table
1569 AcpiPlatformChecksum (
1570 AcpiTableInstance
->Rsdp3
,
1571 sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
),
1572 OFFSET_OF (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
,
1576 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1580 AcpiPlatformChecksum (
1581 AcpiTableInstance
->Rsdt1
,
1582 AcpiTableInstance
->Rsdt1
->Length
,
1583 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1587 AcpiPlatformChecksum (
1588 AcpiTableInstance
->Rsdt3
,
1589 AcpiTableInstance
->Rsdt3
->Length
,
1590 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1598 AcpiPlatformChecksum (
1599 AcpiTableInstance
->Xsdt
,
1600 AcpiTableInstance
->Xsdt
->Length
,
1601 OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER
,
1610 Constructor for the ACPI table protocol. Initializes instance
1613 @param AcpiTableInstance Instance to construct
1615 @return EFI_SUCCESS Instance initialized.
1616 @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
1620 AcpiTableAcpiTableConstructor (
1621 EFI_ACPI_TABLE_INSTANCE
*AcpiTableInstance
1627 UINTN RsdpTableSize
;
1629 EFI_PHYSICAL_ADDRESS PageAddress
;
1632 // Check for invalid input parameters
1634 ASSERT (AcpiTableInstance
);
1637 // If ACPI v1.0b is among the ACPI versions we aim to support, we have to
1638 // ensure that all memory allocations are below 4 GB.
1640 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1641 mAcpiTableAllocType
= AllocateMaxAddress
;
1643 mAcpiTableAllocType
= AllocateAnyPages
;
1646 InitializeListHead (&AcpiTableInstance
->TableList
);
1647 AcpiTableInstance
->CurrentHandle
= 1;
1649 AcpiTableInstance
->AcpiTableProtocol
.InstallAcpiTable
= InstallAcpiTable
;
1650 AcpiTableInstance
->AcpiTableProtocol
.UninstallAcpiTable
= UninstallAcpiTable
;
1652 if (FeaturePcdGet (PcdInstallAcpiSdtProtocol
)) {
1653 SdtAcpiTableAcpiSdtConstructor (AcpiTableInstance
);
1657 // Create RSDP table
1659 RsdpTableSize
= sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1660 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1661 RsdpTableSize
+= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1664 PageAddress
= 0xFFFFFFFF;
1665 Status
= gBS
->AllocatePages (
1666 mAcpiTableAllocType
,
1667 EfiACPIReclaimMemory
,
1668 EFI_SIZE_TO_PAGES (RsdpTableSize
),
1672 if (EFI_ERROR (Status
)) {
1673 return EFI_OUT_OF_RESOURCES
;
1676 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
1677 ZeroMem (Pointer
, RsdpTableSize
);
1679 AcpiTableInstance
->Rsdp1
= (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1680 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1681 Pointer
+= sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1683 AcpiTableInstance
->Rsdp3
= (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
*) Pointer
;
1686 // Create RSDT, XSDT structures
1688 TotalSize
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 XSDT
1689 mEfiAcpiMaxNumTables
* sizeof (UINT64
);
1691 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1692 TotalSize
+= sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 1.0 RSDT
1693 mEfiAcpiMaxNumTables
* sizeof (UINT32
) +
1694 sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + // for ACPI 2.0/3.0 RSDT
1695 mEfiAcpiMaxNumTables
* sizeof (UINT32
);
1699 // Allocate memory in the lower 32 bit of address range for
1700 // compatibility with ACPI 1.0 OS.
1702 // This is done because ACPI 1.0 pointers are 32 bit values.
1703 // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
1704 // There is no architectural reason these should be below 4GB, it is purely
1705 // for convenience of implementation that we force memory below 4GB.
1707 PageAddress
= 0xFFFFFFFF;
1708 Status
= gBS
->AllocatePages (
1709 mAcpiTableAllocType
,
1710 EfiACPIReclaimMemory
,
1711 EFI_SIZE_TO_PAGES (TotalSize
),
1715 if (EFI_ERROR (Status
)) {
1716 gBS
->FreePages ((EFI_PHYSICAL_ADDRESS
)(UINTN
)AcpiTableInstance
->Rsdp1
, EFI_SIZE_TO_PAGES (RsdpTableSize
));
1717 return EFI_OUT_OF_RESOURCES
;
1720 Pointer
= (UINT8
*) (UINTN
) PageAddress
;
1721 ZeroMem (Pointer
, TotalSize
);
1723 AcpiTableInstance
->Rsdt1
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1724 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1725 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1726 AcpiTableInstance
->Rsdt3
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1727 Pointer
+= (sizeof (EFI_ACPI_DESCRIPTION_HEADER
) + EFI_ACPI_MAX_NUM_TABLES
* sizeof (UINT32
));
1729 AcpiTableInstance
->Xsdt
= (EFI_ACPI_DESCRIPTION_HEADER
*) Pointer
;
1734 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1735 CurrentData
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1736 CopyMem (&AcpiTableInstance
->Rsdp1
->Signature
, &CurrentData
, sizeof (UINT64
));
1737 CopyMem (AcpiTableInstance
->Rsdp1
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdp1
->OemId
));
1738 AcpiTableInstance
->Rsdp1
->Reserved
= EFI_ACPI_RESERVED_BYTE
;
1739 AcpiTableInstance
->Rsdp1
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt1
;
1742 CurrentData
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE
;
1743 CopyMem (&AcpiTableInstance
->Rsdp3
->Signature
, &CurrentData
, sizeof (UINT64
));
1744 CopyMem (AcpiTableInstance
->Rsdp3
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdp3
->OemId
));
1745 AcpiTableInstance
->Rsdp3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION
;
1746 AcpiTableInstance
->Rsdp3
->Length
= sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER
);
1747 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1748 AcpiTableInstance
->Rsdp3
->RsdtAddress
= (UINT32
) (UINTN
) AcpiTableInstance
->Rsdt3
;
1750 CurrentData
= (UINT64
) (UINTN
) AcpiTableInstance
->Xsdt
;
1751 CopyMem (&AcpiTableInstance
->Rsdp3
->XsdtAddress
, &CurrentData
, sizeof (UINT64
));
1752 SetMem (AcpiTableInstance
->Rsdp3
->Reserved
, 3, EFI_ACPI_RESERVED_BYTE
);
1754 if ((PcdGet32 (PcdAcpiExposedTableVersions
) & EFI_ACPI_TABLE_VERSION_1_0B
) != 0) {
1758 // Note that we "reserve" one entry for the FADT so it can always be
1759 // at the beginning of the list of tables. Some OS don't seem
1760 // to find it correctly if it is too far down the list.
1762 AcpiTableInstance
->Rsdt1
->Signature
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1763 AcpiTableInstance
->Rsdt1
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1764 AcpiTableInstance
->Rsdt1
->Revision
= EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1765 CopyMem (AcpiTableInstance
->Rsdt1
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdt1
->OemId
));
1766 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1767 CopyMem (&AcpiTableInstance
->Rsdt1
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1768 AcpiTableInstance
->Rsdt1
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1769 AcpiTableInstance
->Rsdt1
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1770 AcpiTableInstance
->Rsdt1
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1772 // We always reserve first one for FADT
1774 AcpiTableInstance
->NumberOfTableEntries1
= 1;
1775 AcpiTableInstance
->Rsdt1
->Length
= AcpiTableInstance
->Rsdt1
->Length
+ sizeof(UINT32
);
1777 AcpiTableInstance
->Rsdt3
->Signature
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1778 AcpiTableInstance
->Rsdt3
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1779 AcpiTableInstance
->Rsdt3
->Revision
= EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1780 CopyMem (AcpiTableInstance
->Rsdt3
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Rsdt3
->OemId
));
1781 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1782 CopyMem (&AcpiTableInstance
->Rsdt3
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1783 AcpiTableInstance
->Rsdt3
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1784 AcpiTableInstance
->Rsdt3
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1785 AcpiTableInstance
->Rsdt3
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1787 // We always reserve first one for FADT
1789 AcpiTableInstance
->Rsdt3
->Length
= AcpiTableInstance
->Rsdt3
->Length
+ sizeof(UINT32
);
1791 AcpiTableInstance
->NumberOfTableEntries3
= 1;
1796 AcpiTableInstance
->Xsdt
->Signature
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
;
1797 AcpiTableInstance
->Xsdt
->Length
= sizeof (EFI_ACPI_DESCRIPTION_HEADER
);
1798 AcpiTableInstance
->Xsdt
->Revision
= EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_REVISION
;
1799 CopyMem (AcpiTableInstance
->Xsdt
->OemId
, PcdGetPtr (PcdAcpiDefaultOemId
), sizeof (AcpiTableInstance
->Xsdt
->OemId
));
1800 CurrentData
= PcdGet64 (PcdAcpiDefaultOemTableId
);
1801 CopyMem (&AcpiTableInstance
->Xsdt
->OemTableId
, &CurrentData
, sizeof (UINT64
));
1802 AcpiTableInstance
->Xsdt
->OemRevision
= PcdGet32 (PcdAcpiDefaultOemRevision
);
1803 AcpiTableInstance
->Xsdt
->CreatorId
= PcdGet32 (PcdAcpiDefaultCreatorId
);
1804 AcpiTableInstance
->Xsdt
->CreatorRevision
= PcdGet32 (PcdAcpiDefaultCreatorRevision
);
1806 // We always reserve first one for FADT
1808 AcpiTableInstance
->Xsdt
->Length
= AcpiTableInstance
->Xsdt
->Length
+ sizeof(UINT64
);
1810 ChecksumCommonTables (AcpiTableInstance
);
1813 // Completed successfully