summaryrefslogtreecommitdiff
path: root/MdeModulePkg/Universal/Acpi/AcpiTableDxe
diff options
context:
space:
mode:
Diffstat (limited to 'MdeModulePkg/Universal/Acpi/AcpiTableDxe')
-rw-r--r--MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c2200
-rw-r--r--MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.h1158
-rw-r--r--MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.c168
-rw-r--r--MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.h542
-rw-r--r--MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf162
-rw-r--r--MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.uni28
-rw-r--r--MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxeExtra.uni28
-rw-r--r--MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c4400
-rw-r--r--MdeModulePkg/Universal/Acpi/AcpiTableDxe/Aml.c592
-rw-r--r--MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlChild.c560
-rw-r--r--MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlNamespace.c1228
-rw-r--r--MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlOption.c932
-rw-r--r--MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlString.c1104
13 files changed, 6551 insertions, 6551 deletions
diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c
index bb258c9710..f4962b761b 100644
--- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c
+++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c
@@ -1,1100 +1,1100 @@
-/** @file
- ACPI Sdt Protocol Driver
-
- Copyright (c) 2010 - 2021, Intel Corporation. All rights reserved. <BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-//
-// Includes
-//
-#include "AcpiTable.h"
-
-GLOBAL_REMOVE_IF_UNREFERENCED
-EFI_ACPI_SDT_PROTOCOL mAcpiSdtProtocolTemplate = {
- EFI_ACPI_TABLE_VERSION_NONE,
- GetAcpiTable2,
- RegisterNotify,
- Open,
- OpenSdt,
- Close,
- GetChild,
- GetOption,
- SetOption,
- FindPath
-};
-
-/**
- This function returns ACPI Table instance.
-
- @return AcpiTableInstance
-**/
-EFI_ACPI_TABLE_INSTANCE *
-SdtGetAcpiTableInstance (
- VOID
- )
-{
- return mPrivateData;
-}
-
-/**
- This function finds the table specified by the buffer.
-
- @param[in] Buffer Table buffer to find.
-
- @return ACPI table list.
-**/
-EFI_ACPI_TABLE_LIST *
-FindTableByBuffer (
- IN VOID *Buffer
- )
-{
- EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance;
- LIST_ENTRY *CurrentLink;
- EFI_ACPI_TABLE_LIST *CurrentTableList;
- LIST_ENTRY *StartLink;
-
- //
- // Get the instance of the ACPI Table
- //
- AcpiTableInstance = SdtGetAcpiTableInstance ();
-
- //
- // Find the notify
- //
- StartLink = &AcpiTableInstance->TableList;
- CurrentLink = StartLink->ForwardLink;
-
- while (CurrentLink != StartLink) {
- CurrentTableList = EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink);
- if (((UINTN)CurrentTableList->Table <= (UINTN)Buffer) &&
- ((UINTN)CurrentTableList->Table + CurrentTableList->TableSize > (UINTN)Buffer))
- {
- //
- // Good! Found Table.
- //
- return CurrentTableList;
- }
-
- CurrentLink = CurrentLink->ForwardLink;
- }
-
- return NULL;
-}
-
-/**
- This function updates AML table checksum.
- It will search the ACPI table installed by ACPI_TABLE protocol.
-
- @param[in] Buffer A piece of AML code buffer pointer.
-
- @retval EFI_SUCCESS The table holds the AML buffer is found, and checksum is updated.
- @retval EFI_NOT_FOUND The table holds the AML buffer is not found.
-**/
-EFI_STATUS
-SdtUpdateAmlChecksum (
- IN VOID *Buffer
- )
-{
- EFI_ACPI_TABLE_LIST *CurrentTableList;
-
- CurrentTableList = FindTableByBuffer (Buffer);
- if (CurrentTableList == NULL) {
- return EFI_NOT_FOUND;
- }
-
- AcpiPlatformChecksum (
- (VOID *)CurrentTableList->Table,
- CurrentTableList->Table->Length,
- OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER, Checksum)
- );
- return EFI_SUCCESS;
-}
-
-/**
- This function finds MAX AML buffer size.
- It will search the ACPI table installed by ACPI_TABLE protocol.
-
- @param[in] Buffer A piece of AML code buffer pointer.
- @param[out] MaxSize On return it holds the MAX size of buffer.
-
- @retval EFI_SUCCESS The table holds the AML buffer is found, and MAX size if returned.
- @retval EFI_NOT_FOUND The table holds the AML buffer is not found.
-**/
-EFI_STATUS
-SdtGetMaxAmlBufferSize (
- IN VOID *Buffer,
- OUT UINTN *MaxSize
- )
-{
- EFI_ACPI_TABLE_LIST *CurrentTableList;
-
- CurrentTableList = FindTableByBuffer (Buffer);
- if (CurrentTableList == NULL) {
- return EFI_NOT_FOUND;
- }
-
- *MaxSize = (UINTN)CurrentTableList->Table + CurrentTableList->Table->Length - (UINTN)Buffer;
- return EFI_SUCCESS;
-}
-
-/**
- This function invokes ACPI notification.
-
- @param[in] AcpiTableInstance Instance to AcpiTable
- @param[in] Version Version(s) to set.
- @param[in] Handle Handle of the table.
-**/
-VOID
-SdtNotifyAcpiList (
- IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
- IN EFI_ACPI_TABLE_VERSION Version,
- IN UINTN Handle
- )
-{
- EFI_ACPI_NOTIFY_LIST *CurrentNotifyList;
- LIST_ENTRY *CurrentLink;
- LIST_ENTRY *StartLink;
- EFI_ACPI_TABLE_LIST *Table;
- EFI_STATUS Status;
-
- //
- // We should not use Table buffer, because it is user input buffer.
- //
- Status = FindTableByHandle (
- Handle,
- &AcpiTableInstance->TableList,
- &Table
- );
- ASSERT_EFI_ERROR (Status);
-
- //
- // Find the notify
- //
- StartLink = &AcpiTableInstance->NotifyList;
- CurrentLink = StartLink->ForwardLink;
-
- while (CurrentLink != StartLink) {
- CurrentNotifyList = EFI_ACPI_NOTIFY_LIST_FROM_LINK (CurrentLink);
-
- //
- // Inovke notification
- //
- CurrentNotifyList->Notification ((EFI_ACPI_SDT_HEADER *)Table->Table, Version, Handle);
-
- CurrentLink = CurrentLink->ForwardLink;
- }
-
- return;
-}
-
-/**
- Returns a requested ACPI table.
-
- The following structures are not considered elements in the list of
- ACPI tables:
- - Root System Description Pointer (RSD_PTR)
- - Root System Description Table (RSDT)
- - Extended System Description Table (XSDT)
- Version is updated with a bit map containing all the versions of ACPI of which the table is a
- member. For tables installed via the EFI_ACPI_TABLE_PROTOCOL.InstallAcpiTable() interface,
- the function returns the value of EFI_ACPI_STD_PROTOCOL.AcpiVersion.
-
- @param[in] AcpiTableInstance ACPI table Instance.
- @param[in] Index The zero-based index of the table to retrieve.
- @param[out] Table Pointer for returning the table buffer.
- @param[out] Version On return, updated with the ACPI versions to which this table belongs. Type
- EFI_ACPI_TABLE_VERSION is defined in "Related Definitions" in the
- EFI_ACPI_SDT_PROTOCOL.
- @param[out] TableKey On return, points to the table key for the specified ACPI system definition table.
- This is identical to the table key used in the EFI_ACPI_TABLE_PROTOCOL.
- The TableKey can be passed to EFI_ACPI_TABLE_PROTOCOL.UninstallAcpiTable()
- to uninstall the table.
- @retval EFI_SUCCESS The function completed successfully.
- @retval EFI_NOT_FOUND The requested index is too large and a table was not found.
-**/
-EFI_STATUS
-SdtGetAcpiTable (
- IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
- IN UINTN Index,
- OUT EFI_ACPI_SDT_HEADER **Table,
- OUT EFI_ACPI_TABLE_VERSION *Version,
- OUT UINTN *TableKey
- )
-{
- UINTN TableIndex;
- LIST_ENTRY *CurrentLink;
- LIST_ENTRY *StartLink;
- EFI_ACPI_TABLE_LIST *CurrentTable;
-
- //
- // Find the table
- //
- StartLink = &AcpiTableInstance->TableList;
- CurrentLink = StartLink->ForwardLink;
- TableIndex = 0;
-
- while (CurrentLink != StartLink) {
- if (TableIndex == Index) {
- break;
- }
-
- //
- // Next one
- //
- CurrentLink = CurrentLink->ForwardLink;
- TableIndex++;
- }
-
- if ((TableIndex != Index) || (CurrentLink == StartLink)) {
- return EFI_NOT_FOUND;
- }
-
- //
- // Get handle and version
- //
- CurrentTable = EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink);
- *TableKey = CurrentTable->Handle;
- *Version = CurrentTable->Version;
- *Table = (EFI_ACPI_SDT_HEADER *)CurrentTable->Table;
-
- return EFI_SUCCESS;
-}
-
-/**
- Returns a requested ACPI table.
-
- The GetAcpiTable() function returns a pointer to a buffer containing the ACPI table associated
- with the Index that was input. The following structures are not considered elements in the list of
- ACPI tables:
- - Root System Description Pointer (RSD_PTR)
- - Root System Description Table (RSDT)
- - Extended System Description Table (XSDT)
- Version is updated with a bit map containing all the versions of ACPI of which the table is a
- member. For tables installed via the EFI_ACPI_TABLE_PROTOCOL.InstallAcpiTable() interface,
- the function returns the value of EFI_ACPI_STD_PROTOCOL.AcpiVersion.
-
- @param[in] Index The zero-based index of the table to retrieve.
- @param[out] Table Pointer for returning the table buffer.
- @param[out] Version On return, updated with the ACPI versions to which this table belongs. Type
- EFI_ACPI_TABLE_VERSION is defined in "Related Definitions" in the
- EFI_ACPI_SDT_PROTOCOL.
- @param[out] TableKey On return, points to the table key for the specified ACPI system definition table.
- This is identical to the table key used in the EFI_ACPI_TABLE_PROTOCOL.
- The TableKey can be passed to EFI_ACPI_TABLE_PROTOCOL.UninstallAcpiTable()
- to uninstall the table.
- @retval EFI_SUCCESS The function completed successfully.
- @retval EFI_NOT_FOUND The requested index is too large and a table was not found.
-**/
-EFI_STATUS
-EFIAPI
-GetAcpiTable2 (
- IN UINTN Index,
- OUT EFI_ACPI_SDT_HEADER **Table,
- OUT EFI_ACPI_TABLE_VERSION *Version,
- OUT UINTN *TableKey
- )
-{
- EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance;
-
- ASSERT (Table != NULL);
- ASSERT (Version != NULL);
- ASSERT (TableKey != NULL);
-
- //
- // Get the instance of the ACPI Table
- //
- AcpiTableInstance = SdtGetAcpiTableInstance ();
-
- return SdtGetAcpiTable (AcpiTableInstance, Index, Table, Version, TableKey);
-}
-
-/**
- Register a callback when an ACPI table is installed.
-
- This function registers a function which will be called whenever a new ACPI table is installed.
-
- @param[in] Notification Points to the callback function to be registered
-**/
-VOID
-SdtRegisterNotify (
- IN EFI_ACPI_NOTIFICATION_FN Notification
- )
-{
- EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance;
- EFI_ACPI_NOTIFY_LIST *CurrentNotifyList;
-
- //
- // Get the instance of the ACPI Table
- //
- AcpiTableInstance = SdtGetAcpiTableInstance ();
-
- //
- // Create a new list entry
- //
- CurrentNotifyList = AllocatePool (sizeof (EFI_ACPI_NOTIFY_LIST));
- ASSERT (CurrentNotifyList != NULL);
-
- //
- // Initialize the table contents
- //
- CurrentNotifyList->Signature = EFI_ACPI_NOTIFY_LIST_SIGNATURE;
- CurrentNotifyList->Notification = Notification;
-
- //
- // Add the table to the current list of tables
- //
- InsertTailList (&AcpiTableInstance->NotifyList, &CurrentNotifyList->Link);
-
- return;
-}
-
-/**
- Unregister a callback when an ACPI table is installed.
-
- This function unregisters a function which will be called whenever a new ACPI table is installed.
-
- @param[in] Notification Points to the callback function to be unregistered.
-
- @retval EFI_SUCCESS Callback successfully unregistered.
- @retval EFI_INVALID_PARAMETER Notification does not match a known registration function.
-**/
-EFI_STATUS
-SdtUnregisterNotify (
- IN EFI_ACPI_NOTIFICATION_FN Notification
- )
-{
- EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance;
- EFI_ACPI_NOTIFY_LIST *CurrentNotifyList;
- LIST_ENTRY *CurrentLink;
- LIST_ENTRY *StartLink;
-
- //
- // Get the instance of the ACPI Table
- //
- AcpiTableInstance = SdtGetAcpiTableInstance ();
-
- //
- // Find the notify
- //
- StartLink = &AcpiTableInstance->NotifyList;
- CurrentLink = StartLink->ForwardLink;
-
- while (CurrentLink != StartLink) {
- CurrentNotifyList = EFI_ACPI_NOTIFY_LIST_FROM_LINK (CurrentLink);
- if (CurrentNotifyList->Notification == Notification) {
- //
- // Good! Found notification.
- //
- // Remove it from list and free the node.
- //
- RemoveEntryList (&(CurrentNotifyList->Link));
- FreePool (CurrentNotifyList);
- return EFI_SUCCESS;
- }
-
- CurrentLink = CurrentLink->ForwardLink;
- }
-
- //
- // Not found!
- //
- return EFI_INVALID_PARAMETER;
-}
-
-/**
- Register or unregister a callback when an ACPI table is installed.
-
- This function registers or unregisters a function which will be called whenever a new ACPI table is
- installed.
-
- @param[in] Register If TRUE, then the specified function will be registered. If FALSE, then the specified
- function will be unregistered.
- @param[in] Notification Points to the callback function to be registered or unregistered.
-
- @retval EFI_SUCCESS Callback successfully registered or unregistered.
- @retval EFI_INVALID_PARAMETER Notification is NULL
- @retval EFI_INVALID_PARAMETER Register is FALSE and Notification does not match a known registration function.
-**/
-EFI_STATUS
-EFIAPI
-RegisterNotify (
- IN BOOLEAN Register,
- IN EFI_ACPI_NOTIFICATION_FN Notification
- )
-{
- //
- // Check for invalid input parameters
- //
- if (Notification == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- if (Register) {
- //
- // Register a new notify
- //
- SdtRegisterNotify (Notification);
- return EFI_SUCCESS;
- } else {
- //
- // Unregister an old notify
- //
- return SdtUnregisterNotify (Notification);
- }
-}
-
-/**
- Create a handle for the first ACPI opcode in an ACPI system description table.
-
- @param[in] TableKey The table key for the ACPI table, as returned by GetTable().
- @param[out] Handle On return, points to the newly created ACPI handle.
-
- @retval EFI_SUCCESS Handle created successfully.
- @retval EFI_NOT_FOUND TableKey does not refer to a valid ACPI table.
-**/
-EFI_STATUS
-SdtOpenSdtTable (
- IN UINTN TableKey,
- OUT EFI_ACPI_HANDLE *Handle
- )
-{
- EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance;
- EFI_STATUS Status;
- EFI_ACPI_TABLE_LIST *Table;
- EFI_AML_HANDLE *AmlHandle;
-
- //
- // Get the instance of the ACPI Table
- //
- AcpiTableInstance = SdtGetAcpiTableInstance ();
-
- //
- // Find the table
- //
- Status = FindTableByHandle (
- TableKey,
- &AcpiTableInstance->TableList,
- &Table
- );
- if (EFI_ERROR (Status)) {
- return EFI_NOT_FOUND;
- }
-
- AmlHandle = AllocatePool (sizeof (*AmlHandle));
- ASSERT (AmlHandle != NULL);
- AmlHandle->Signature = EFI_AML_ROOT_HANDLE_SIGNATURE;
- AmlHandle->Buffer = (VOID *)((UINTN)Table->Table + sizeof (EFI_ACPI_SDT_HEADER));
- AmlHandle->Size = Table->Table->Length - sizeof (EFI_ACPI_SDT_HEADER);
- AmlHandle->AmlByteEncoding = NULL;
- AmlHandle->Modified = FALSE;
-
- //
- // return the ACPI handle
- //
- *Handle = (EFI_ACPI_HANDLE)AmlHandle;
-
- return EFI_SUCCESS;
-}
-
-/**
- Create a handle for the first ACPI opcode in an ACPI system description table.
-
- @param[in] TableKey The table key for the ACPI table, as returned by GetTable().
- @param[out] Handle On return, points to the newly created ACPI handle.
-
- @retval EFI_SUCCESS Handle created successfully.
- @retval EFI_NOT_FOUND TableKey does not refer to a valid ACPI table.
-**/
-EFI_STATUS
-EFIAPI
-OpenSdt (
- IN UINTN TableKey,
- OUT EFI_ACPI_HANDLE *Handle
- )
-{
- if (Handle == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- return SdtOpenSdtTable (TableKey, Handle);
-}
-
-/**
- Create a handle from an ACPI opcode
-
- @param[in] Buffer Points to the ACPI opcode.
- @param[in] BufferSize Max buffer size.
- @param[out] Handle Upon return, holds the handle.
-
- @retval EFI_SUCCESS Success
- @retval EFI_INVALID_PARAMETER Buffer is NULL or Handle is NULL or Buffer points to an
- invalid opcode.
-
-**/
-EFI_STATUS
-SdtOpenEx (
- IN VOID *Buffer,
- IN UINTN BufferSize,
- OUT EFI_ACPI_HANDLE *Handle
- )
-{
- AML_BYTE_ENCODING *AmlByteEncoding;
- EFI_AML_HANDLE *AmlHandle;
-
- AmlByteEncoding = AmlSearchByOpByte (Buffer);
- if (AmlByteEncoding == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // Do not open NameString as handle
- //
- if ((AmlByteEncoding->Attribute & AML_IS_NAME_CHAR) != 0) {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // Good, find it
- //
- AmlHandle = AllocatePool (sizeof (*AmlHandle));
- ASSERT (AmlHandle != NULL);
-
- AmlHandle->Signature = EFI_AML_HANDLE_SIGNATURE;
- AmlHandle->Buffer = Buffer;
- AmlHandle->AmlByteEncoding = AmlByteEncoding;
- AmlHandle->Modified = FALSE;
-
- AmlHandle->Size = AmlGetObjectSize (AmlByteEncoding, Buffer, BufferSize);
- if (AmlHandle->Size == 0) {
- FreePool (AmlHandle);
- return EFI_INVALID_PARAMETER;
- }
-
- *Handle = (EFI_ACPI_HANDLE)AmlHandle;
-
- return EFI_SUCCESS;
-}
-
-/**
- Create a handle from an ACPI opcode
-
- @param[in] Buffer Points to the ACPI opcode.
- @param[out] Handle Upon return, holds the handle.
-
- @retval EFI_SUCCESS Success
- @retval EFI_INVALID_PARAMETER Buffer is NULL or Handle is NULL or Buffer points to an
- invalid opcode.
-
-**/
-EFI_STATUS
-EFIAPI
-Open (
- IN VOID *Buffer,
- OUT EFI_ACPI_HANDLE *Handle
- )
-{
- EFI_STATUS Status;
- UINTN MaxSize;
-
- MaxSize = 0;
-
- //
- // Check for invalid input parameters
- //
- if ((Buffer == NULL) || (Handle == NULL)) {
- return EFI_INVALID_PARAMETER;
- }
-
- Status = SdtGetMaxAmlBufferSize (Buffer, &MaxSize);
- if (EFI_ERROR (Status)) {
- return EFI_INVALID_PARAMETER;
- }
-
- return SdtOpenEx (Buffer, MaxSize, Handle);
-}
-
-/**
- Close an ACPI handle.
-
- @param[in] Handle Returns the handle.
-
- @retval EFI_SUCCESS Success
- @retval EFI_INVALID_PARAMETER Handle is NULL or does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-EFIAPI
-Close (
- IN EFI_ACPI_HANDLE Handle
- )
-{
- EFI_AML_HANDLE *AmlHandle;
- EFI_STATUS Status;
-
- //
- // Check for invalid input parameters
- //
- if (Handle == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- AmlHandle = (EFI_AML_HANDLE *)Handle;
- if ((AmlHandle->Signature != EFI_AML_ROOT_HANDLE_SIGNATURE) &&
- (AmlHandle->Signature != EFI_AML_HANDLE_SIGNATURE))
- {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // Update Checksum only if modified
- //
- if (AmlHandle->Modified) {
- Status = SdtUpdateAmlChecksum (AmlHandle->Buffer);
- if (EFI_ERROR (Status)) {
- return EFI_INVALID_PARAMETER;
- }
- }
-
- FreePool (AmlHandle);
-
- return EFI_SUCCESS;
-}
-
-/**
- Retrieve information about an ACPI object.
-
- @param[in] Handle ACPI object handle.
- @param[in] Index Index of the data to retrieve from the object. In general, indexes read from left-to-right
- in the ACPI encoding, with index 0 always being the ACPI opcode.
- @param[out] DataType Points to the returned data type or EFI_ACPI_DATA_TYPE_NONE if no data exists
- for the specified index.
- @param[out] Data Upon return, points to the pointer to the data.
- @param[out] DataSize Upon return, points to the size of Data.
-
- @retval EFI_SUCCESS Success.
- @retval EFI_INVALID_PARAMETER Handle is NULL or does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-EFIAPI
-GetOption (
- IN EFI_ACPI_HANDLE Handle,
- IN UINTN Index,
- OUT EFI_ACPI_DATA_TYPE *DataType,
- OUT CONST VOID **Data,
- OUT UINTN *DataSize
- )
-{
- EFI_AML_HANDLE *AmlHandle;
- AML_BYTE_ENCODING *AmlByteEncoding;
- EFI_STATUS Status;
-
- ASSERT (DataType != NULL);
- ASSERT (Data != NULL);
- ASSERT (DataSize != NULL);
-
- //
- // Check for invalid input parameters
- //
- if (Handle == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- AmlHandle = (EFI_AML_HANDLE *)Handle;
- //
- // Do not check EFI_AML_ROOT_HANDLE_SIGNATURE because there is no option for Root handle
- //
- if (AmlHandle->Signature != EFI_AML_HANDLE_SIGNATURE) {
- return EFI_INVALID_PARAMETER;
- }
-
- AmlByteEncoding = AmlHandle->AmlByteEncoding;
- if (Index > AmlByteEncoding->MaxIndex) {
- *DataType = EFI_ACPI_DATA_TYPE_NONE;
- return EFI_SUCCESS;
- }
-
- //
- // Parse option
- //
- Status = AmlParseOptionHandleCommon (AmlHandle, (AML_OP_PARSE_INDEX)Index, DataType, (VOID **)Data, DataSize);
- if (EFI_ERROR (Status)) {
- return EFI_INVALID_PARAMETER;
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Change information about an ACPI object.
-
- @param[in] Handle ACPI object handle.
- @param[in] Index Index of the data to retrieve from the object. In general, indexes read from left-to-right
- in the ACPI encoding, with index 0 always being the ACPI opcode.
- @param[in] Data Points to the data.
- @param[in] DataSize The size of the Data.
-
- @retval EFI_SUCCESS Success
- @retval EFI_INVALID_PARAMETER Handle is NULL or does not refer to a valid ACPI object.
- @retval EFI_BAD_BUFFER_SIZE Data cannot be accommodated in the space occupied by
- the option.
-
-**/
-EFI_STATUS
-EFIAPI
-SetOption (
- IN EFI_ACPI_HANDLE Handle,
- IN UINTN Index,
- IN CONST VOID *Data,
- IN UINTN DataSize
- )
-{
- EFI_AML_HANDLE *AmlHandle;
- AML_BYTE_ENCODING *AmlByteEncoding;
- EFI_STATUS Status;
- EFI_ACPI_DATA_TYPE DataType;
- VOID *OrgData;
- UINTN OrgDataSize;
-
- ASSERT (Data != NULL);
-
- //
- // Check for invalid input parameters
- //
- if (Handle == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- AmlHandle = (EFI_AML_HANDLE *)Handle;
- //
- // Do not check EFI_AML_ROOT_HANDLE_SIGNATURE because there is no option for Root handle
- //
- if (AmlHandle->Signature != EFI_AML_HANDLE_SIGNATURE) {
- return EFI_INVALID_PARAMETER;
- }
-
- AmlByteEncoding = AmlHandle->AmlByteEncoding;
-
- if (Index > AmlByteEncoding->MaxIndex) {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // Parse option
- //
- Status = AmlParseOptionHandleCommon (AmlHandle, (AML_OP_PARSE_INDEX)Index, &DataType, &OrgData, &OrgDataSize);
- if (EFI_ERROR (Status)) {
- return EFI_INVALID_PARAMETER;
- }
-
- if (DataType == EFI_ACPI_DATA_TYPE_NONE) {
- return EFI_INVALID_PARAMETER;
- }
-
- if (DataSize > OrgDataSize) {
- return EFI_BAD_BUFFER_SIZE;
- }
-
- //
- // Update
- //
- CopyMem (OrgData, Data, DataSize);
- AmlHandle->Modified = TRUE;
-
- return EFI_SUCCESS;
-}
-
-/**
- Return the child ACPI objects.
-
- @param[in] ParentHandle Parent handle.
- @param[in, out] Handle On entry, points to the previously returned handle or NULL to start with the first
- handle. On return, points to the next returned ACPI handle or NULL if there are no
- child objects.
-
- @retval EFI_SUCCESS Success
- @retval EFI_INVALID_PARAMETER ParentHandle is NULL or does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-EFIAPI
-GetChild (
- IN EFI_ACPI_HANDLE ParentHandle,
- IN OUT EFI_ACPI_HANDLE *Handle
- )
-{
- EFI_AML_HANDLE *AmlParentHandle;
- EFI_AML_HANDLE *AmlHandle;
- VOID *Buffer;
- EFI_STATUS Status;
-
- ASSERT (Handle != NULL);
-
- //
- // Check for invalid input parameters
- //
- if (ParentHandle == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- AmlHandle = *Handle;
- if ((AmlHandle != NULL) && (AmlHandle->Signature != EFI_AML_HANDLE_SIGNATURE)) {
- return EFI_INVALID_PARAMETER;
- }
-
- AmlParentHandle = (EFI_AML_HANDLE *)ParentHandle;
- if (AmlParentHandle->Signature == EFI_AML_ROOT_HANDLE_SIGNATURE) {
- //
- // Root handle
- //
- Status = AmlGetChildFromRoot (AmlParentHandle, AmlHandle, &Buffer);
- } else if (AmlParentHandle->Signature == EFI_AML_HANDLE_SIGNATURE) {
- //
- // Non-root handle
- //
- Status = AmlGetChildFromNonRoot (AmlParentHandle, AmlHandle, &Buffer);
- } else {
- //
- // Invalid
- //
- return EFI_INVALID_PARAMETER;
- }
-
- if (EFI_ERROR (Status)) {
- return EFI_INVALID_PARAMETER;
- }
-
- if (Buffer == NULL) {
- *Handle = NULL;
- return EFI_SUCCESS;
- }
-
- return SdtOpenEx (Buffer, (UINTN)AmlParentHandle->Buffer + AmlParentHandle->Size - (UINTN)Buffer, Handle);
-}
-
-/**
- Returns the handle of the ACPI object representing the specified ACPI path
-
- @param[in] HandleIn Points to the handle of the object representing the starting point for the path search.
- @param[in] AmlPath Points to the AML path.
- @param[out] HandleOut On return, points to the ACPI object which represents AcpiPath, relative to
- HandleIn.
-
- @retval EFI_SUCCESS Success
- @retval EFI_INVALID_PARAMETER HandleIn is NULL or does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-SdtFindPathFromNonRoot (
- IN EFI_ACPI_HANDLE HandleIn,
- IN UINT8 *AmlPath,
- OUT EFI_ACPI_HANDLE *HandleOut
- )
-{
- EFI_AML_HANDLE *AmlHandle;
- VOID *Buffer;
- EFI_STATUS Status;
-
- Buffer = NULL;
- AmlHandle = (EFI_AML_HANDLE *)HandleIn;
-
- //
- // For non-root handle, we need search from THIS node instead of ROOT.
- //
- Status = AmlFindPath (AmlHandle, AmlPath, &Buffer, FALSE);
- if (EFI_ERROR (Status)) {
- return EFI_INVALID_PARAMETER;
- }
-
- if (Buffer == NULL) {
- *HandleOut = NULL;
- return EFI_SUCCESS;
- }
-
- return SdtOpenEx (Buffer, (UINTN)AmlHandle->Buffer + AmlHandle->Size - (UINTN)Buffer, HandleOut);
-}
-
-/**
- Duplicate AML handle.
-
- @param[in] AmlHandle Handle to be duplicated.
-
- @return Duplicated AML handle.
-**/
-EFI_AML_HANDLE *
-SdtDuplicateHandle (
- IN EFI_AML_HANDLE *AmlHandle
- )
-{
- EFI_AML_HANDLE *DstAmlHandle;
-
- DstAmlHandle = AllocatePool (sizeof (*DstAmlHandle));
- ASSERT (DstAmlHandle != NULL);
- CopyMem (DstAmlHandle, (VOID *)AmlHandle, sizeof (*DstAmlHandle));
-
- return DstAmlHandle;
-}
-
-/**
- Returns the handle of the ACPI object representing the specified ACPI path
-
- @param[in] HandleIn Points to the handle of the object representing the starting point for the path search.
- @param[in] AmlPath Points to the AML path.
- @param[out] HandleOut On return, points to the ACPI object which represents AcpiPath, relative to
- HandleIn.
-
- @retval EFI_SUCCESS Success
- @retval EFI_INVALID_PARAMETER HandleIn is NULL or does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-SdtFindPathFromRoot (
- IN EFI_ACPI_HANDLE HandleIn,
- IN UINT8 *AmlPath,
- OUT EFI_ACPI_HANDLE *HandleOut
- )
-{
- EFI_ACPI_HANDLE ChildHandle;
- EFI_AML_HANDLE *AmlHandle;
- EFI_STATUS Status;
- VOID *Buffer;
-
- Buffer = NULL;
- AmlHandle = (EFI_AML_HANDLE *)HandleIn;
-
- //
- // Handle case that AcpiPath is Root
- //
- if (AmlIsRootPath (AmlPath)) {
- //
- // Duplicate RootHandle
- //
- *HandleOut = (EFI_ACPI_HANDLE)SdtDuplicateHandle (AmlHandle);
- return EFI_SUCCESS;
- }
-
- //
- // Let children find it.
- //
- ChildHandle = NULL;
- while (TRUE) {
- Status = GetChild (HandleIn, &ChildHandle);
- if (EFI_ERROR (Status)) {
- return EFI_INVALID_PARAMETER;
- }
-
- if (ChildHandle == NULL) {
- //
- // Not found
- //
- *HandleOut = NULL;
- return EFI_SUCCESS;
- }
-
- //
- // More child
- //
- AmlHandle = (EFI_AML_HANDLE *)ChildHandle;
- Status = AmlFindPath (AmlHandle, AmlPath, &Buffer, TRUE);
- if (EFI_ERROR (Status)) {
- return EFI_INVALID_PARAMETER;
- }
-
- if (Buffer != NULL) {
- //
- // Great! Find it, open
- //
- Status = SdtOpenEx (Buffer, (UINTN)AmlHandle->Buffer + AmlHandle->Size - (UINTN)Buffer, HandleOut);
- if (!EFI_ERROR (Status)) {
- return EFI_SUCCESS;
- }
-
- //
- // Not success, try next one
- //
- }
- }
-
- //
- // Should not run here
- //
-}
-
-/**
- Returns the handle of the ACPI object representing the specified ACPI path
-
- @param[in] HandleIn Points to the handle of the object representing the starting point for the path search.
- @param[in] AcpiPath Points to the ACPI path, which conforms to the ACPI encoded path format.
- @param[out] HandleOut On return, points to the ACPI object which represents AcpiPath, relative to
- HandleIn.
-
- @retval EFI_SUCCESS Success
- @retval EFI_INVALID_PARAMETER HandleIn is NULL or does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-EFIAPI
-FindPath (
- IN EFI_ACPI_HANDLE HandleIn,
- IN VOID *AcpiPath,
- OUT EFI_ACPI_HANDLE *HandleOut
- )
-{
- EFI_AML_HANDLE *AmlHandle;
- EFI_STATUS Status;
- UINT8 *AmlPath;
-
- //
- // Check for invalid input parameters
- //
- if (HandleIn == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- AmlHandle = (EFI_AML_HANDLE *)HandleIn;
-
- //
- // Convert ASL path to AML path
- //
- AmlPath = AmlNameFromAslName (AcpiPath);
- if (AmlPath == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- DEBUG_CODE_BEGIN ();
- DEBUG ((DEBUG_ERROR, "AcpiSdt: FindPath - "));
- AmlPrintNameString (AmlPath);
- DEBUG ((DEBUG_ERROR, "\n"));
- DEBUG_CODE_END ();
-
- if (AmlHandle->Signature == EFI_AML_ROOT_HANDLE_SIGNATURE) {
- //
- // Root Handle
- //
- Status = SdtFindPathFromRoot (HandleIn, AmlPath, HandleOut);
- } else if (AmlHandle->Signature == EFI_AML_HANDLE_SIGNATURE) {
- //
- // Non-Root handle
- //
- Status = SdtFindPathFromNonRoot (HandleIn, AmlPath, HandleOut);
- } else {
- Status = EFI_INVALID_PARAMETER;
- }
-
- FreePool (AmlPath);
-
- return Status;
-}
-
-/**
- This function initializes AcpiSdt protocol in ACPI table instance.
-
- @param[in] AcpiTableInstance Instance to construct
-**/
-VOID
-SdtAcpiTableAcpiSdtConstructor (
- IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance
- )
-{
- InitializeListHead (&AcpiTableInstance->NotifyList);
- CopyMem (&AcpiTableInstance->AcpiSdtProtocol, &mAcpiSdtProtocolTemplate, sizeof (mAcpiSdtProtocolTemplate));
- AcpiTableInstance->AcpiSdtProtocol.AcpiVersion = (EFI_ACPI_TABLE_VERSION)PcdGet32 (PcdAcpiExposedTableVersions);
-
- return;
-}
+/** @file
+ ACPI Sdt Protocol Driver
+
+ Copyright (c) 2010 - 2021, Intel Corporation. All rights reserved. <BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+//
+// Includes
+//
+#include "AcpiTable.h"
+
+GLOBAL_REMOVE_IF_UNREFERENCED
+EFI_ACPI_SDT_PROTOCOL mAcpiSdtProtocolTemplate = {
+ EFI_ACPI_TABLE_VERSION_NONE,
+ GetAcpiTable2,
+ RegisterNotify,
+ Open,
+ OpenSdt,
+ Close,
+ GetChild,
+ GetOption,
+ SetOption,
+ FindPath
+};
+
+/**
+ This function returns ACPI Table instance.
+
+ @return AcpiTableInstance
+**/
+EFI_ACPI_TABLE_INSTANCE *
+SdtGetAcpiTableInstance (
+ VOID
+ )
+{
+ return mPrivateData;
+}
+
+/**
+ This function finds the table specified by the buffer.
+
+ @param[in] Buffer Table buffer to find.
+
+ @return ACPI table list.
+**/
+EFI_ACPI_TABLE_LIST *
+FindTableByBuffer (
+ IN VOID *Buffer
+ )
+{
+ EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance;
+ LIST_ENTRY *CurrentLink;
+ EFI_ACPI_TABLE_LIST *CurrentTableList;
+ LIST_ENTRY *StartLink;
+
+ //
+ // Get the instance of the ACPI Table
+ //
+ AcpiTableInstance = SdtGetAcpiTableInstance ();
+
+ //
+ // Find the notify
+ //
+ StartLink = &AcpiTableInstance->TableList;
+ CurrentLink = StartLink->ForwardLink;
+
+ while (CurrentLink != StartLink) {
+ CurrentTableList = EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink);
+ if (((UINTN)CurrentTableList->Table <= (UINTN)Buffer) &&
+ ((UINTN)CurrentTableList->Table + CurrentTableList->TableSize > (UINTN)Buffer))
+ {
+ //
+ // Good! Found Table.
+ //
+ return CurrentTableList;
+ }
+
+ CurrentLink = CurrentLink->ForwardLink;
+ }
+
+ return NULL;
+}
+
+/**
+ This function updates AML table checksum.
+ It will search the ACPI table installed by ACPI_TABLE protocol.
+
+ @param[in] Buffer A piece of AML code buffer pointer.
+
+ @retval EFI_SUCCESS The table holds the AML buffer is found, and checksum is updated.
+ @retval EFI_NOT_FOUND The table holds the AML buffer is not found.
+**/
+EFI_STATUS
+SdtUpdateAmlChecksum (
+ IN VOID *Buffer
+ )
+{
+ EFI_ACPI_TABLE_LIST *CurrentTableList;
+
+ CurrentTableList = FindTableByBuffer (Buffer);
+ if (CurrentTableList == NULL) {
+ return EFI_NOT_FOUND;
+ }
+
+ AcpiPlatformChecksum (
+ (VOID *)CurrentTableList->Table,
+ CurrentTableList->Table->Length,
+ OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER, Checksum)
+ );
+ return EFI_SUCCESS;
+}
+
+/**
+ This function finds MAX AML buffer size.
+ It will search the ACPI table installed by ACPI_TABLE protocol.
+
+ @param[in] Buffer A piece of AML code buffer pointer.
+ @param[out] MaxSize On return it holds the MAX size of buffer.
+
+ @retval EFI_SUCCESS The table holds the AML buffer is found, and MAX size if returned.
+ @retval EFI_NOT_FOUND The table holds the AML buffer is not found.
+**/
+EFI_STATUS
+SdtGetMaxAmlBufferSize (
+ IN VOID *Buffer,
+ OUT UINTN *MaxSize
+ )
+{
+ EFI_ACPI_TABLE_LIST *CurrentTableList;
+
+ CurrentTableList = FindTableByBuffer (Buffer);
+ if (CurrentTableList == NULL) {
+ return EFI_NOT_FOUND;
+ }
+
+ *MaxSize = (UINTN)CurrentTableList->Table + CurrentTableList->Table->Length - (UINTN)Buffer;
+ return EFI_SUCCESS;
+}
+
+/**
+ This function invokes ACPI notification.
+
+ @param[in] AcpiTableInstance Instance to AcpiTable
+ @param[in] Version Version(s) to set.
+ @param[in] Handle Handle of the table.
+**/
+VOID
+SdtNotifyAcpiList (
+ IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
+ IN EFI_ACPI_TABLE_VERSION Version,
+ IN UINTN Handle
+ )
+{
+ EFI_ACPI_NOTIFY_LIST *CurrentNotifyList;
+ LIST_ENTRY *CurrentLink;
+ LIST_ENTRY *StartLink;
+ EFI_ACPI_TABLE_LIST *Table;
+ EFI_STATUS Status;
+
+ //
+ // We should not use Table buffer, because it is user input buffer.
+ //
+ Status = FindTableByHandle (
+ Handle,
+ &AcpiTableInstance->TableList,
+ &Table
+ );
+ ASSERT_EFI_ERROR (Status);
+
+ //
+ // Find the notify
+ //
+ StartLink = &AcpiTableInstance->NotifyList;
+ CurrentLink = StartLink->ForwardLink;
+
+ while (CurrentLink != StartLink) {
+ CurrentNotifyList = EFI_ACPI_NOTIFY_LIST_FROM_LINK (CurrentLink);
+
+ //
+ // Inovke notification
+ //
+ CurrentNotifyList->Notification ((EFI_ACPI_SDT_HEADER *)Table->Table, Version, Handle);
+
+ CurrentLink = CurrentLink->ForwardLink;
+ }
+
+ return;
+}
+
+/**
+ Returns a requested ACPI table.
+
+ The following structures are not considered elements in the list of
+ ACPI tables:
+ - Root System Description Pointer (RSD_PTR)
+ - Root System Description Table (RSDT)
+ - Extended System Description Table (XSDT)
+ Version is updated with a bit map containing all the versions of ACPI of which the table is a
+ member. For tables installed via the EFI_ACPI_TABLE_PROTOCOL.InstallAcpiTable() interface,
+ the function returns the value of EFI_ACPI_STD_PROTOCOL.AcpiVersion.
+
+ @param[in] AcpiTableInstance ACPI table Instance.
+ @param[in] Index The zero-based index of the table to retrieve.
+ @param[out] Table Pointer for returning the table buffer.
+ @param[out] Version On return, updated with the ACPI versions to which this table belongs. Type
+ EFI_ACPI_TABLE_VERSION is defined in "Related Definitions" in the
+ EFI_ACPI_SDT_PROTOCOL.
+ @param[out] TableKey On return, points to the table key for the specified ACPI system definition table.
+ This is identical to the table key used in the EFI_ACPI_TABLE_PROTOCOL.
+ The TableKey can be passed to EFI_ACPI_TABLE_PROTOCOL.UninstallAcpiTable()
+ to uninstall the table.
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_NOT_FOUND The requested index is too large and a table was not found.
+**/
+EFI_STATUS
+SdtGetAcpiTable (
+ IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
+ IN UINTN Index,
+ OUT EFI_ACPI_SDT_HEADER **Table,
+ OUT EFI_ACPI_TABLE_VERSION *Version,
+ OUT UINTN *TableKey
+ )
+{
+ UINTN TableIndex;
+ LIST_ENTRY *CurrentLink;
+ LIST_ENTRY *StartLink;
+ EFI_ACPI_TABLE_LIST *CurrentTable;
+
+ //
+ // Find the table
+ //
+ StartLink = &AcpiTableInstance->TableList;
+ CurrentLink = StartLink->ForwardLink;
+ TableIndex = 0;
+
+ while (CurrentLink != StartLink) {
+ if (TableIndex == Index) {
+ break;
+ }
+
+ //
+ // Next one
+ //
+ CurrentLink = CurrentLink->ForwardLink;
+ TableIndex++;
+ }
+
+ if ((TableIndex != Index) || (CurrentLink == StartLink)) {
+ return EFI_NOT_FOUND;
+ }
+
+ //
+ // Get handle and version
+ //
+ CurrentTable = EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink);
+ *TableKey = CurrentTable->Handle;
+ *Version = CurrentTable->Version;
+ *Table = (EFI_ACPI_SDT_HEADER *)CurrentTable->Table;
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Returns a requested ACPI table.
+
+ The GetAcpiTable() function returns a pointer to a buffer containing the ACPI table associated
+ with the Index that was input. The following structures are not considered elements in the list of
+ ACPI tables:
+ - Root System Description Pointer (RSD_PTR)
+ - Root System Description Table (RSDT)
+ - Extended System Description Table (XSDT)
+ Version is updated with a bit map containing all the versions of ACPI of which the table is a
+ member. For tables installed via the EFI_ACPI_TABLE_PROTOCOL.InstallAcpiTable() interface,
+ the function returns the value of EFI_ACPI_STD_PROTOCOL.AcpiVersion.
+
+ @param[in] Index The zero-based index of the table to retrieve.
+ @param[out] Table Pointer for returning the table buffer.
+ @param[out] Version On return, updated with the ACPI versions to which this table belongs. Type
+ EFI_ACPI_TABLE_VERSION is defined in "Related Definitions" in the
+ EFI_ACPI_SDT_PROTOCOL.
+ @param[out] TableKey On return, points to the table key for the specified ACPI system definition table.
+ This is identical to the table key used in the EFI_ACPI_TABLE_PROTOCOL.
+ The TableKey can be passed to EFI_ACPI_TABLE_PROTOCOL.UninstallAcpiTable()
+ to uninstall the table.
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_NOT_FOUND The requested index is too large and a table was not found.
+**/
+EFI_STATUS
+EFIAPI
+GetAcpiTable2 (
+ IN UINTN Index,
+ OUT EFI_ACPI_SDT_HEADER **Table,
+ OUT EFI_ACPI_TABLE_VERSION *Version,
+ OUT UINTN *TableKey
+ )
+{
+ EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance;
+
+ ASSERT (Table != NULL);
+ ASSERT (Version != NULL);
+ ASSERT (TableKey != NULL);
+
+ //
+ // Get the instance of the ACPI Table
+ //
+ AcpiTableInstance = SdtGetAcpiTableInstance ();
+
+ return SdtGetAcpiTable (AcpiTableInstance, Index, Table, Version, TableKey);
+}
+
+/**
+ Register a callback when an ACPI table is installed.
+
+ This function registers a function which will be called whenever a new ACPI table is installed.
+
+ @param[in] Notification Points to the callback function to be registered
+**/
+VOID
+SdtRegisterNotify (
+ IN EFI_ACPI_NOTIFICATION_FN Notification
+ )
+{
+ EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance;
+ EFI_ACPI_NOTIFY_LIST *CurrentNotifyList;
+
+ //
+ // Get the instance of the ACPI Table
+ //
+ AcpiTableInstance = SdtGetAcpiTableInstance ();
+
+ //
+ // Create a new list entry
+ //
+ CurrentNotifyList = AllocatePool (sizeof (EFI_ACPI_NOTIFY_LIST));
+ ASSERT (CurrentNotifyList != NULL);
+
+ //
+ // Initialize the table contents
+ //
+ CurrentNotifyList->Signature = EFI_ACPI_NOTIFY_LIST_SIGNATURE;
+ CurrentNotifyList->Notification = Notification;
+
+ //
+ // Add the table to the current list of tables
+ //
+ InsertTailList (&AcpiTableInstance->NotifyList, &CurrentNotifyList->Link);
+
+ return;
+}
+
+/**
+ Unregister a callback when an ACPI table is installed.
+
+ This function unregisters a function which will be called whenever a new ACPI table is installed.
+
+ @param[in] Notification Points to the callback function to be unregistered.
+
+ @retval EFI_SUCCESS Callback successfully unregistered.
+ @retval EFI_INVALID_PARAMETER Notification does not match a known registration function.
+**/
+EFI_STATUS
+SdtUnregisterNotify (
+ IN EFI_ACPI_NOTIFICATION_FN Notification
+ )
+{
+ EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance;
+ EFI_ACPI_NOTIFY_LIST *CurrentNotifyList;
+ LIST_ENTRY *CurrentLink;
+ LIST_ENTRY *StartLink;
+
+ //
+ // Get the instance of the ACPI Table
+ //
+ AcpiTableInstance = SdtGetAcpiTableInstance ();
+
+ //
+ // Find the notify
+ //
+ StartLink = &AcpiTableInstance->NotifyList;
+ CurrentLink = StartLink->ForwardLink;
+
+ while (CurrentLink != StartLink) {
+ CurrentNotifyList = EFI_ACPI_NOTIFY_LIST_FROM_LINK (CurrentLink);
+ if (CurrentNotifyList->Notification == Notification) {
+ //
+ // Good! Found notification.
+ //
+ // Remove it from list and free the node.
+ //
+ RemoveEntryList (&(CurrentNotifyList->Link));
+ FreePool (CurrentNotifyList);
+ return EFI_SUCCESS;
+ }
+
+ CurrentLink = CurrentLink->ForwardLink;
+ }
+
+ //
+ // Not found!
+ //
+ return EFI_INVALID_PARAMETER;
+}
+
+/**
+ Register or unregister a callback when an ACPI table is installed.
+
+ This function registers or unregisters a function which will be called whenever a new ACPI table is
+ installed.
+
+ @param[in] Register If TRUE, then the specified function will be registered. If FALSE, then the specified
+ function will be unregistered.
+ @param[in] Notification Points to the callback function to be registered or unregistered.
+
+ @retval EFI_SUCCESS Callback successfully registered or unregistered.
+ @retval EFI_INVALID_PARAMETER Notification is NULL
+ @retval EFI_INVALID_PARAMETER Register is FALSE and Notification does not match a known registration function.
+**/
+EFI_STATUS
+EFIAPI
+RegisterNotify (
+ IN BOOLEAN Register,
+ IN EFI_ACPI_NOTIFICATION_FN Notification
+ )
+{
+ //
+ // Check for invalid input parameters
+ //
+ if (Notification == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (Register) {
+ //
+ // Register a new notify
+ //
+ SdtRegisterNotify (Notification);
+ return EFI_SUCCESS;
+ } else {
+ //
+ // Unregister an old notify
+ //
+ return SdtUnregisterNotify (Notification);
+ }
+}
+
+/**
+ Create a handle for the first ACPI opcode in an ACPI system description table.
+
+ @param[in] TableKey The table key for the ACPI table, as returned by GetTable().
+ @param[out] Handle On return, points to the newly created ACPI handle.
+
+ @retval EFI_SUCCESS Handle created successfully.
+ @retval EFI_NOT_FOUND TableKey does not refer to a valid ACPI table.
+**/
+EFI_STATUS
+SdtOpenSdtTable (
+ IN UINTN TableKey,
+ OUT EFI_ACPI_HANDLE *Handle
+ )
+{
+ EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance;
+ EFI_STATUS Status;
+ EFI_ACPI_TABLE_LIST *Table;
+ EFI_AML_HANDLE *AmlHandle;
+
+ //
+ // Get the instance of the ACPI Table
+ //
+ AcpiTableInstance = SdtGetAcpiTableInstance ();
+
+ //
+ // Find the table
+ //
+ Status = FindTableByHandle (
+ TableKey,
+ &AcpiTableInstance->TableList,
+ &Table
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_NOT_FOUND;
+ }
+
+ AmlHandle = AllocatePool (sizeof (*AmlHandle));
+ ASSERT (AmlHandle != NULL);
+ AmlHandle->Signature = EFI_AML_ROOT_HANDLE_SIGNATURE;
+ AmlHandle->Buffer = (VOID *)((UINTN)Table->Table + sizeof (EFI_ACPI_SDT_HEADER));
+ AmlHandle->Size = Table->Table->Length - sizeof (EFI_ACPI_SDT_HEADER);
+ AmlHandle->AmlByteEncoding = NULL;
+ AmlHandle->Modified = FALSE;
+
+ //
+ // return the ACPI handle
+ //
+ *Handle = (EFI_ACPI_HANDLE)AmlHandle;
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Create a handle for the first ACPI opcode in an ACPI system description table.
+
+ @param[in] TableKey The table key for the ACPI table, as returned by GetTable().
+ @param[out] Handle On return, points to the newly created ACPI handle.
+
+ @retval EFI_SUCCESS Handle created successfully.
+ @retval EFI_NOT_FOUND TableKey does not refer to a valid ACPI table.
+**/
+EFI_STATUS
+EFIAPI
+OpenSdt (
+ IN UINTN TableKey,
+ OUT EFI_ACPI_HANDLE *Handle
+ )
+{
+ if (Handle == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ return SdtOpenSdtTable (TableKey, Handle);
+}
+
+/**
+ Create a handle from an ACPI opcode
+
+ @param[in] Buffer Points to the ACPI opcode.
+ @param[in] BufferSize Max buffer size.
+ @param[out] Handle Upon return, holds the handle.
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_INVALID_PARAMETER Buffer is NULL or Handle is NULL or Buffer points to an
+ invalid opcode.
+
+**/
+EFI_STATUS
+SdtOpenEx (
+ IN VOID *Buffer,
+ IN UINTN BufferSize,
+ OUT EFI_ACPI_HANDLE *Handle
+ )
+{
+ AML_BYTE_ENCODING *AmlByteEncoding;
+ EFI_AML_HANDLE *AmlHandle;
+
+ AmlByteEncoding = AmlSearchByOpByte (Buffer);
+ if (AmlByteEncoding == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Do not open NameString as handle
+ //
+ if ((AmlByteEncoding->Attribute & AML_IS_NAME_CHAR) != 0) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Good, find it
+ //
+ AmlHandle = AllocatePool (sizeof (*AmlHandle));
+ ASSERT (AmlHandle != NULL);
+
+ AmlHandle->Signature = EFI_AML_HANDLE_SIGNATURE;
+ AmlHandle->Buffer = Buffer;
+ AmlHandle->AmlByteEncoding = AmlByteEncoding;
+ AmlHandle->Modified = FALSE;
+
+ AmlHandle->Size = AmlGetObjectSize (AmlByteEncoding, Buffer, BufferSize);
+ if (AmlHandle->Size == 0) {
+ FreePool (AmlHandle);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ *Handle = (EFI_ACPI_HANDLE)AmlHandle;
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Create a handle from an ACPI opcode
+
+ @param[in] Buffer Points to the ACPI opcode.
+ @param[out] Handle Upon return, holds the handle.
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_INVALID_PARAMETER Buffer is NULL or Handle is NULL or Buffer points to an
+ invalid opcode.
+
+**/
+EFI_STATUS
+EFIAPI
+Open (
+ IN VOID *Buffer,
+ OUT EFI_ACPI_HANDLE *Handle
+ )
+{
+ EFI_STATUS Status;
+ UINTN MaxSize;
+
+ MaxSize = 0;
+
+ //
+ // Check for invalid input parameters
+ //
+ if ((Buffer == NULL) || (Handle == NULL)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Status = SdtGetMaxAmlBufferSize (Buffer, &MaxSize);
+ if (EFI_ERROR (Status)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ return SdtOpenEx (Buffer, MaxSize, Handle);
+}
+
+/**
+ Close an ACPI handle.
+
+ @param[in] Handle Returns the handle.
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_INVALID_PARAMETER Handle is NULL or does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+EFIAPI
+Close (
+ IN EFI_ACPI_HANDLE Handle
+ )
+{
+ EFI_AML_HANDLE *AmlHandle;
+ EFI_STATUS Status;
+
+ //
+ // Check for invalid input parameters
+ //
+ if (Handle == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ AmlHandle = (EFI_AML_HANDLE *)Handle;
+ if ((AmlHandle->Signature != EFI_AML_ROOT_HANDLE_SIGNATURE) &&
+ (AmlHandle->Signature != EFI_AML_HANDLE_SIGNATURE))
+ {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Update Checksum only if modified
+ //
+ if (AmlHandle->Modified) {
+ Status = SdtUpdateAmlChecksum (AmlHandle->Buffer);
+ if (EFI_ERROR (Status)) {
+ return EFI_INVALID_PARAMETER;
+ }
+ }
+
+ FreePool (AmlHandle);
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Retrieve information about an ACPI object.
+
+ @param[in] Handle ACPI object handle.
+ @param[in] Index Index of the data to retrieve from the object. In general, indexes read from left-to-right
+ in the ACPI encoding, with index 0 always being the ACPI opcode.
+ @param[out] DataType Points to the returned data type or EFI_ACPI_DATA_TYPE_NONE if no data exists
+ for the specified index.
+ @param[out] Data Upon return, points to the pointer to the data.
+ @param[out] DataSize Upon return, points to the size of Data.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER Handle is NULL or does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+EFIAPI
+GetOption (
+ IN EFI_ACPI_HANDLE Handle,
+ IN UINTN Index,
+ OUT EFI_ACPI_DATA_TYPE *DataType,
+ OUT CONST VOID **Data,
+ OUT UINTN *DataSize
+ )
+{
+ EFI_AML_HANDLE *AmlHandle;
+ AML_BYTE_ENCODING *AmlByteEncoding;
+ EFI_STATUS Status;
+
+ ASSERT (DataType != NULL);
+ ASSERT (Data != NULL);
+ ASSERT (DataSize != NULL);
+
+ //
+ // Check for invalid input parameters
+ //
+ if (Handle == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ AmlHandle = (EFI_AML_HANDLE *)Handle;
+ //
+ // Do not check EFI_AML_ROOT_HANDLE_SIGNATURE because there is no option for Root handle
+ //
+ if (AmlHandle->Signature != EFI_AML_HANDLE_SIGNATURE) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ AmlByteEncoding = AmlHandle->AmlByteEncoding;
+ if (Index > AmlByteEncoding->MaxIndex) {
+ *DataType = EFI_ACPI_DATA_TYPE_NONE;
+ return EFI_SUCCESS;
+ }
+
+ //
+ // Parse option
+ //
+ Status = AmlParseOptionHandleCommon (AmlHandle, (AML_OP_PARSE_INDEX)Index, DataType, (VOID **)Data, DataSize);
+ if (EFI_ERROR (Status)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Change information about an ACPI object.
+
+ @param[in] Handle ACPI object handle.
+ @param[in] Index Index of the data to retrieve from the object. In general, indexes read from left-to-right
+ in the ACPI encoding, with index 0 always being the ACPI opcode.
+ @param[in] Data Points to the data.
+ @param[in] DataSize The size of the Data.
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_INVALID_PARAMETER Handle is NULL or does not refer to a valid ACPI object.
+ @retval EFI_BAD_BUFFER_SIZE Data cannot be accommodated in the space occupied by
+ the option.
+
+**/
+EFI_STATUS
+EFIAPI
+SetOption (
+ IN EFI_ACPI_HANDLE Handle,
+ IN UINTN Index,
+ IN CONST VOID *Data,
+ IN UINTN DataSize
+ )
+{
+ EFI_AML_HANDLE *AmlHandle;
+ AML_BYTE_ENCODING *AmlByteEncoding;
+ EFI_STATUS Status;
+ EFI_ACPI_DATA_TYPE DataType;
+ VOID *OrgData;
+ UINTN OrgDataSize;
+
+ ASSERT (Data != NULL);
+
+ //
+ // Check for invalid input parameters
+ //
+ if (Handle == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ AmlHandle = (EFI_AML_HANDLE *)Handle;
+ //
+ // Do not check EFI_AML_ROOT_HANDLE_SIGNATURE because there is no option for Root handle
+ //
+ if (AmlHandle->Signature != EFI_AML_HANDLE_SIGNATURE) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ AmlByteEncoding = AmlHandle->AmlByteEncoding;
+
+ if (Index > AmlByteEncoding->MaxIndex) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Parse option
+ //
+ Status = AmlParseOptionHandleCommon (AmlHandle, (AML_OP_PARSE_INDEX)Index, &DataType, &OrgData, &OrgDataSize);
+ if (EFI_ERROR (Status)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (DataType == EFI_ACPI_DATA_TYPE_NONE) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (DataSize > OrgDataSize) {
+ return EFI_BAD_BUFFER_SIZE;
+ }
+
+ //
+ // Update
+ //
+ CopyMem (OrgData, Data, DataSize);
+ AmlHandle->Modified = TRUE;
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Return the child ACPI objects.
+
+ @param[in] ParentHandle Parent handle.
+ @param[in, out] Handle On entry, points to the previously returned handle or NULL to start with the first
+ handle. On return, points to the next returned ACPI handle or NULL if there are no
+ child objects.
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_INVALID_PARAMETER ParentHandle is NULL or does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+EFIAPI
+GetChild (
+ IN EFI_ACPI_HANDLE ParentHandle,
+ IN OUT EFI_ACPI_HANDLE *Handle
+ )
+{
+ EFI_AML_HANDLE *AmlParentHandle;
+ EFI_AML_HANDLE *AmlHandle;
+ VOID *Buffer;
+ EFI_STATUS Status;
+
+ ASSERT (Handle != NULL);
+
+ //
+ // Check for invalid input parameters
+ //
+ if (ParentHandle == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ AmlHandle = *Handle;
+ if ((AmlHandle != NULL) && (AmlHandle->Signature != EFI_AML_HANDLE_SIGNATURE)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ AmlParentHandle = (EFI_AML_HANDLE *)ParentHandle;
+ if (AmlParentHandle->Signature == EFI_AML_ROOT_HANDLE_SIGNATURE) {
+ //
+ // Root handle
+ //
+ Status = AmlGetChildFromRoot (AmlParentHandle, AmlHandle, &Buffer);
+ } else if (AmlParentHandle->Signature == EFI_AML_HANDLE_SIGNATURE) {
+ //
+ // Non-root handle
+ //
+ Status = AmlGetChildFromNonRoot (AmlParentHandle, AmlHandle, &Buffer);
+ } else {
+ //
+ // Invalid
+ //
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (EFI_ERROR (Status)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (Buffer == NULL) {
+ *Handle = NULL;
+ return EFI_SUCCESS;
+ }
+
+ return SdtOpenEx (Buffer, (UINTN)AmlParentHandle->Buffer + AmlParentHandle->Size - (UINTN)Buffer, Handle);
+}
+
+/**
+ Returns the handle of the ACPI object representing the specified ACPI path
+
+ @param[in] HandleIn Points to the handle of the object representing the starting point for the path search.
+ @param[in] AmlPath Points to the AML path.
+ @param[out] HandleOut On return, points to the ACPI object which represents AcpiPath, relative to
+ HandleIn.
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_INVALID_PARAMETER HandleIn is NULL or does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+SdtFindPathFromNonRoot (
+ IN EFI_ACPI_HANDLE HandleIn,
+ IN UINT8 *AmlPath,
+ OUT EFI_ACPI_HANDLE *HandleOut
+ )
+{
+ EFI_AML_HANDLE *AmlHandle;
+ VOID *Buffer;
+ EFI_STATUS Status;
+
+ Buffer = NULL;
+ AmlHandle = (EFI_AML_HANDLE *)HandleIn;
+
+ //
+ // For non-root handle, we need search from THIS node instead of ROOT.
+ //
+ Status = AmlFindPath (AmlHandle, AmlPath, &Buffer, FALSE);
+ if (EFI_ERROR (Status)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (Buffer == NULL) {
+ *HandleOut = NULL;
+ return EFI_SUCCESS;
+ }
+
+ return SdtOpenEx (Buffer, (UINTN)AmlHandle->Buffer + AmlHandle->Size - (UINTN)Buffer, HandleOut);
+}
+
+/**
+ Duplicate AML handle.
+
+ @param[in] AmlHandle Handle to be duplicated.
+
+ @return Duplicated AML handle.
+**/
+EFI_AML_HANDLE *
+SdtDuplicateHandle (
+ IN EFI_AML_HANDLE *AmlHandle
+ )
+{
+ EFI_AML_HANDLE *DstAmlHandle;
+
+ DstAmlHandle = AllocatePool (sizeof (*DstAmlHandle));
+ ASSERT (DstAmlHandle != NULL);
+ CopyMem (DstAmlHandle, (VOID *)AmlHandle, sizeof (*DstAmlHandle));
+
+ return DstAmlHandle;
+}
+
+/**
+ Returns the handle of the ACPI object representing the specified ACPI path
+
+ @param[in] HandleIn Points to the handle of the object representing the starting point for the path search.
+ @param[in] AmlPath Points to the AML path.
+ @param[out] HandleOut On return, points to the ACPI object which represents AcpiPath, relative to
+ HandleIn.
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_INVALID_PARAMETER HandleIn is NULL or does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+SdtFindPathFromRoot (
+ IN EFI_ACPI_HANDLE HandleIn,
+ IN UINT8 *AmlPath,
+ OUT EFI_ACPI_HANDLE *HandleOut
+ )
+{
+ EFI_ACPI_HANDLE ChildHandle;
+ EFI_AML_HANDLE *AmlHandle;
+ EFI_STATUS Status;
+ VOID *Buffer;
+
+ Buffer = NULL;
+ AmlHandle = (EFI_AML_HANDLE *)HandleIn;
+
+ //
+ // Handle case that AcpiPath is Root
+ //
+ if (AmlIsRootPath (AmlPath)) {
+ //
+ // Duplicate RootHandle
+ //
+ *HandleOut = (EFI_ACPI_HANDLE)SdtDuplicateHandle (AmlHandle);
+ return EFI_SUCCESS;
+ }
+
+ //
+ // Let children find it.
+ //
+ ChildHandle = NULL;
+ while (TRUE) {
+ Status = GetChild (HandleIn, &ChildHandle);
+ if (EFI_ERROR (Status)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (ChildHandle == NULL) {
+ //
+ // Not found
+ //
+ *HandleOut = NULL;
+ return EFI_SUCCESS;
+ }
+
+ //
+ // More child
+ //
+ AmlHandle = (EFI_AML_HANDLE *)ChildHandle;
+ Status = AmlFindPath (AmlHandle, AmlPath, &Buffer, TRUE);
+ if (EFI_ERROR (Status)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (Buffer != NULL) {
+ //
+ // Great! Find it, open
+ //
+ Status = SdtOpenEx (Buffer, (UINTN)AmlHandle->Buffer + AmlHandle->Size - (UINTN)Buffer, HandleOut);
+ if (!EFI_ERROR (Status)) {
+ return EFI_SUCCESS;
+ }
+
+ //
+ // Not success, try next one
+ //
+ }
+ }
+
+ //
+ // Should not run here
+ //
+}
+
+/**
+ Returns the handle of the ACPI object representing the specified ACPI path
+
+ @param[in] HandleIn Points to the handle of the object representing the starting point for the path search.
+ @param[in] AcpiPath Points to the ACPI path, which conforms to the ACPI encoded path format.
+ @param[out] HandleOut On return, points to the ACPI object which represents AcpiPath, relative to
+ HandleIn.
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_INVALID_PARAMETER HandleIn is NULL or does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+EFIAPI
+FindPath (
+ IN EFI_ACPI_HANDLE HandleIn,
+ IN VOID *AcpiPath,
+ OUT EFI_ACPI_HANDLE *HandleOut
+ )
+{
+ EFI_AML_HANDLE *AmlHandle;
+ EFI_STATUS Status;
+ UINT8 *AmlPath;
+
+ //
+ // Check for invalid input parameters
+ //
+ if (HandleIn == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ AmlHandle = (EFI_AML_HANDLE *)HandleIn;
+
+ //
+ // Convert ASL path to AML path
+ //
+ AmlPath = AmlNameFromAslName (AcpiPath);
+ if (AmlPath == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ DEBUG_CODE_BEGIN ();
+ DEBUG ((DEBUG_ERROR, "AcpiSdt: FindPath - "));
+ AmlPrintNameString (AmlPath);
+ DEBUG ((DEBUG_ERROR, "\n"));
+ DEBUG_CODE_END ();
+
+ if (AmlHandle->Signature == EFI_AML_ROOT_HANDLE_SIGNATURE) {
+ //
+ // Root Handle
+ //
+ Status = SdtFindPathFromRoot (HandleIn, AmlPath, HandleOut);
+ } else if (AmlHandle->Signature == EFI_AML_HANDLE_SIGNATURE) {
+ //
+ // Non-Root handle
+ //
+ Status = SdtFindPathFromNonRoot (HandleIn, AmlPath, HandleOut);
+ } else {
+ Status = EFI_INVALID_PARAMETER;
+ }
+
+ FreePool (AmlPath);
+
+ return Status;
+}
+
+/**
+ This function initializes AcpiSdt protocol in ACPI table instance.
+
+ @param[in] AcpiTableInstance Instance to construct
+**/
+VOID
+SdtAcpiTableAcpiSdtConstructor (
+ IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance
+ )
+{
+ InitializeListHead (&AcpiTableInstance->NotifyList);
+ CopyMem (&AcpiTableInstance->AcpiSdtProtocol, &mAcpiSdtProtocolTemplate, sizeof (mAcpiSdtProtocolTemplate));
+ AcpiTableInstance->AcpiSdtProtocol.AcpiVersion = (EFI_ACPI_TABLE_VERSION)PcdGet32 (PcdAcpiExposedTableVersions);
+
+ return;
+}
diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.h b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.h
index 89eb535136..f0b6079f3e 100644
--- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.h
+++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.h
@@ -1,579 +1,579 @@
-/** @file
- ACPI Sdt Protocol Driver
-
- Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved. <BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#ifndef _ACPI_SDT_H_
-#define _ACPI_SDT_H_
-
-//
-// Privacy data structure
-//
-
-//
-// ACPI Notify Linked List Signature.
-//
-#define EFI_ACPI_NOTIFY_LIST_SIGNATURE SIGNATURE_32 ('E', 'A', 'N', 'L')
-
-//
-// ACPI Notify List Entry definition.
-//
-// Signature must be set to EFI_ACPI_NOTIFY_LIST_SIGNATURE
-// Link is the linked list data.
-// Notification is the callback function.
-//
-typedef struct {
- UINT32 Signature;
- LIST_ENTRY Link;
- EFI_ACPI_NOTIFICATION_FN Notification;
-} EFI_ACPI_NOTIFY_LIST;
-
-//
-// Containment record for ACPI Notify linked list.
-//
-#define EFI_ACPI_NOTIFY_LIST_FROM_LINK(_link) CR (_link, EFI_ACPI_NOTIFY_LIST, Link, EFI_ACPI_NOTIFY_LIST_SIGNATURE)
-
-typedef struct _AML_BYTE_ENCODING AML_BYTE_ENCODING;
-typedef struct _EFI_AML_NODE_LIST EFI_AML_NODE_LIST;
-
-//
-// AML Node Linked List Signature.
-//
-#define EFI_AML_NODE_LIST_SIGNATURE SIGNATURE_32 ('E', 'A', 'M', 'L')
-
-//
-// AML Node Linked List Entry definition.
-//
-// Signature must be set to EFI_AML_NODE_LIST_SIGNATURE
-// Link is the linked list data.
-// Name is the ACPI node name.
-// This is listed for PATH finding.
-// Buffer is the ACPI node buffer pointer, the first/second bytes are opcode.
-// This buffer should not be freed.
-// Size is the total size of this ACPI node buffer.
-// Children is the children linked list of this node.
-//
-
-struct _EFI_AML_NODE_LIST {
- UINT32 Signature;
- UINT8 Name[AML_NAME_SEG_SIZE];
- UINT8 *Buffer;
- UINTN Size;
- LIST_ENTRY Link;
- LIST_ENTRY Children;
- EFI_AML_NODE_LIST *Parent;
- AML_BYTE_ENCODING *AmlByteEncoding;
-};
-
-//
-// Containment record for AML Node linked list.
-//
-#define EFI_AML_NODE_LIST_FROM_LINK(_link) CR (_link, EFI_AML_NODE_LIST, Link, EFI_AML_NODE_LIST_SIGNATURE)
-
-//
-// AML Handle Signature.
-//
-#define EFI_AML_HANDLE_SIGNATURE SIGNATURE_32 ('E', 'A', 'H', 'S')
-#define EFI_AML_ROOT_HANDLE_SIGNATURE SIGNATURE_32 ('E', 'A', 'R', 'H')
-
-//
-// AML Handle Entry definition.
-//
-// Signature must be set to EFI_AML_HANDLE_SIGNATURE or EFI_AML_ROOT_HANDLE_SIGNATURE
-// Buffer is the ACPI node buffer pointer, the first/second bytes are opcode.
-// This buffer should not be freed.
-// Size is the total size of this ACPI node buffer.
-//
-typedef struct {
- UINT32 Signature;
- UINT8 *Buffer;
- UINTN Size;
- AML_BYTE_ENCODING *AmlByteEncoding;
- BOOLEAN Modified;
-} EFI_AML_HANDLE;
-
-typedef UINT32 AML_OP_PARSE_INDEX;
-
-#define AML_OP_PARSE_INDEX_GET_OPCODE 0
-#define AML_OP_PARSE_INDEX_GET_TERM1 1
-#define AML_OP_PARSE_INDEX_GET_TERM2 2
-#define AML_OP_PARSE_INDEX_GET_TERM3 3
-#define AML_OP_PARSE_INDEX_GET_TERM4 4
-#define AML_OP_PARSE_INDEX_GET_TERM5 5
-#define AML_OP_PARSE_INDEX_GET_TERM6 6
-#define AML_OP_PARSE_INDEX_GET_SIZE (AML_OP_PARSE_INDEX)-1
-
-typedef UINT32 AML_OP_PARSE_FORMAT;
-#define AML_NONE 0
-#define AML_OPCODE 1
-#define AML_UINT8 2
-#define AML_UINT16 3
-#define AML_UINT32 4
-#define AML_UINT64 5
-#define AML_NAME 6
-#define AML_STRING 7
-#define AML_OBJECT 8
-
-typedef UINT32 AML_OP_ATTRIBUTE;
-#define AML_HAS_PKG_LENGTH 0x1 // It is ACPI attribute - if OpCode has PkgLength
-#define AML_IS_NAME_CHAR 0x2 // It is ACPI attribute - if this is NameChar
-#define AML_HAS_CHILD_OBJ 0x4 // it is ACPI attribute - if OpCode has Child Object.
-#define AML_IN_NAMESPACE 0x10000 // It is UEFI SDT attribute - if OpCode will be in NameSpace
- // NOTE; Not all OBJECT will be in NameSpace
- // For example, BankField | CreateBitField | CreateByteField | CreateDWordField |
- // CreateField | CreateQWordField | CreateWordField | Field | IndexField.
-
-struct _AML_BYTE_ENCODING {
- UINT8 OpCode;
- UINT8 SubOpCode;
- AML_OP_PARSE_INDEX MaxIndex;
- AML_OP_PARSE_FORMAT Format[6];
- AML_OP_ATTRIBUTE Attribute;
-};
-
-//
-// AcpiSdt protocol declaration
-//
-
-/**
- Returns a requested ACPI table.
-
- The GetAcpiTable() function returns a pointer to a buffer containing the ACPI table associated
- with the Index that was input. The following structures are not considered elements in the list of
- ACPI tables:
- - Root System Description Pointer (RSD_PTR)
- - Root System Description Table (RSDT)
- - Extended System Description Table (XSDT)
- Version is updated with a bit map containing all the versions of ACPI of which the table is a
- member. For tables installed via the EFI_ACPI_TABLE_PROTOCOL.InstallAcpiTable() interface,
- the function returns the value of EFI_ACPI_STD_PROTOCOL.AcpiVersion.
-
- @param[in] Index The zero-based index of the table to retrieve.
- @param[out] Table Pointer for returning the table buffer.
- @param[out] Version On return, updated with the ACPI versions to which this table belongs. Type
- EFI_ACPI_TABLE_VERSION is defined in "Related Definitions" in the
- EFI_ACPI_SDT_PROTOCOL.
- @param[out] TableKey On return, points to the table key for the specified ACPI system definition table.
- This is identical to the table key used in the EFI_ACPI_TABLE_PROTOCOL.
- The TableKey can be passed to EFI_ACPI_TABLE_PROTOCOL.UninstallAcpiTable()
- to uninstall the table.
-
- @retval EFI_SUCCESS The function completed successfully.
- @retval EFI_NOT_FOUND The requested index is too large and a table was not found.
-**/
-EFI_STATUS
-EFIAPI
-GetAcpiTable2 (
- IN UINTN Index,
- OUT EFI_ACPI_SDT_HEADER **Table,
- OUT EFI_ACPI_TABLE_VERSION *Version,
- OUT UINTN *TableKey
- );
-
-/**
- Register or unregister a callback when an ACPI table is installed.
-
- This function registers or unregisters a function which will be called whenever a new ACPI table is
- installed.
-
- @param[in] Register If TRUE, then the specified function will be registered. If FALSE, then the specified
- function will be unregistered.
- @param[in] Notification Points to the callback function to be registered or unregistered.
-
- @retval EFI_SUCCESS Callback successfully registered or unregistered.
- @retval EFI_INVALID_PARAMETER Notification is NULL
- @retval EFI_INVALID_PARAMETER Register is FALSE and Notification does not match a known registration function.
-**/
-EFI_STATUS
-EFIAPI
-RegisterNotify (
- IN BOOLEAN Register,
- IN EFI_ACPI_NOTIFICATION_FN Notification
- );
-
-/**
- Create a handle for the first ACPI opcode in an ACPI system description table.
-
- @param[in] TableKey The table key for the ACPI table, as returned by GetTable().
- @param[out] Handle On return, points to the newly created ACPI handle.
-
- @retval EFI_SUCCESS Handle created successfully.
- @retval EFI_NOT_FOUND TableKey does not refer to a valid ACPI table.
-**/
-EFI_STATUS
-EFIAPI
-OpenSdt (
- IN UINTN TableKey,
- OUT EFI_ACPI_HANDLE *Handle
- );
-
-/**
- Create a handle from an ACPI opcode
-
- @param[in] Buffer Points to the ACPI opcode.
- @param[out] Handle Upon return, holds the handle.
-
- @retval EFI_SUCCESS Success
- @retval EFI_INVALID_PARAMETER Buffer is NULL or Handle is NULL or Buffer points to an
- invalid opcode.
-
-**/
-EFI_STATUS
-EFIAPI
-Open (
- IN VOID *Buffer,
- OUT EFI_ACPI_HANDLE *Handle
- );
-
-/**
- Close an ACPI handle.
-
- @param[in] Handle Returns the handle.
-
- @retval EFI_SUCCESS Success
- @retval EFI_INVALID_PARAMETER Handle is NULL or does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-EFIAPI
-Close (
- IN EFI_ACPI_HANDLE Handle
- );
-
-/**
- Retrieve information about an ACPI object.
-
- @param[in] Handle ACPI object handle.
- @param[in] Index Index of the data to retrieve from the object. In general, indexes read from left-to-right
- in the ACPI encoding, with index 0 always being the ACPI opcode.
- @param[out] DataType Points to the returned data type or EFI_ACPI_DATA_TYPE_NONE if no data exists
- for the specified index.
- @param[out] Data Upon return, points to the pointer to the data.
- @param[out] DataSize Upon return, points to the size of Data.
-
- @retval EFI_SUCCESS Success.
- @retval EFI_INVALID_PARAMETER Handle is NULL or does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-EFIAPI
-GetOption (
- IN EFI_ACPI_HANDLE Handle,
- IN UINTN Index,
- OUT EFI_ACPI_DATA_TYPE *DataType,
- OUT CONST VOID **Data,
- OUT UINTN *DataSize
- );
-
-/**
- Change information about an ACPI object.
-
- @param[in] Handle ACPI object handle.
- @param[in] Index Index of the data to retrieve from the object. In general, indexes read from left-to-right
- in the ACPI encoding, with index 0 always being the ACPI opcode.
- @param[in] Data Points to the data.
- @param[in] DataSize The size of the Data.
-
- @retval EFI_SUCCESS Success
- @retval EFI_INVALID_PARAMETER Handle is NULL or does not refer to a valid ACPI object.
- @retval EFI_BAD_BUFFER_SIZE Data cannot be accommodated in the space occupied by
- the option.
-
-**/
-EFI_STATUS
-EFIAPI
-SetOption (
- IN EFI_ACPI_HANDLE Handle,
- IN UINTN Index,
- IN CONST VOID *Data,
- IN UINTN DataSize
- );
-
-/**
- Return the child ACPI objects.
-
- @param[in] ParentHandle Parent handle.
- @param[in, out] Handle On entry, points to the previously returned handle or NULL to start with the first
- handle. On return, points to the next returned ACPI handle or NULL if there are no
- child objects.
-
- @retval EFI_SUCCESS Success
- @retval EFI_INVALID_PARAMETER ParentHandle is NULL or does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-EFIAPI
-GetChild (
- IN EFI_ACPI_HANDLE ParentHandle,
- IN OUT EFI_ACPI_HANDLE *Handle
- );
-
-/**
- Returns the handle of the ACPI object representing the specified ACPI path
-
- @param[in] HandleIn Points to the handle of the object representing the starting point for the path search.
- @param[in] AcpiPath Points to the ACPI path, which conforms to the ACPI encoded path format.
- @param[out] HandleOut On return, points to the ACPI object which represents AcpiPath, relative to
- HandleIn.
-
- @retval EFI_SUCCESS Success
- @retval EFI_INVALID_PARAMETER HandleIn is NULL or does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-EFIAPI
-FindPath (
- IN EFI_ACPI_HANDLE HandleIn,
- IN VOID *AcpiPath,
- OUT EFI_ACPI_HANDLE *HandleOut
- );
-
-//
-// ACPI SDT function
-//
-
-/**
- Create a handle from an ACPI opcode
-
- @param[in] Buffer Points to the ACPI opcode.
- @param[in] BufferSize Max buffer size.
- @param[out] Handle Upon return, holds the handle.
-
- @retval EFI_SUCCESS Success
- @retval EFI_INVALID_PARAMETER Buffer is NULL or Handle is NULL or Buffer points to an
- invalid opcode.
-
-**/
-EFI_STATUS
-SdtOpenEx (
- IN VOID *Buffer,
- IN UINTN BufferSize,
- OUT EFI_ACPI_HANDLE *Handle
- );
-
-//
-// AML support function
-//
-
-/**
- Get AML NameString size.
-
- @param[in] Buffer AML NameString.
- @param[out] BufferSize AML NameString size
-
- @retval EFI_SUCCESS Success.
- @retval EFI_INVALID_PARAMETER Buffer does not refer to a valid AML NameString.
-**/
-EFI_STATUS
-AmlGetNameStringSize (
- IN UINT8 *Buffer,
- OUT UINTN *BufferSize
- );
-
-/**
- This function retuns package length from the buffer.
-
- @param[in] Buffer AML buffer
- @param[out] PkgLength The total length of package.
-
- @return The byte data count to present the package length.
-**/
-UINTN
-AmlGetPkgLength (
- IN UINT8 *Buffer,
- OUT UINTN *PkgLength
- );
-
-/**
- This function returns AcpiDataType according to AmlType.
-
- @param[in] AmlType AML Type.
-
- @return AcpiDataType
-**/
-EFI_ACPI_DATA_TYPE
-AmlTypeToAcpiType (
- IN AML_OP_PARSE_FORMAT AmlType
- );
-
-/**
- This function returns AmlByteEncoding according to OpCode Byte.
-
- @param[in] OpByteBuffer OpCode byte buffer.
-
- @return AmlByteEncoding
-**/
-AML_BYTE_ENCODING *
-AmlSearchByOpByte (
- IN UINT8 *OpByteBuffer
- );
-
-/**
- Return object size.
-
- @param[in] AmlByteEncoding AML Byte Encoding.
- @param[in] Buffer AML object buffer.
- @param[in] MaxBufferSize AML object buffer MAX size. The parser can not parse any data exceed this region.
-
- @return Size of the object.
-**/
-UINTN
-AmlGetObjectSize (
- IN AML_BYTE_ENCODING *AmlByteEncoding,
- IN UINT8 *Buffer,
- IN UINTN MaxBufferSize
- );
-
-/**
- Return object name.
-
- @param[in] AmlHandle AML handle.
-
- @return Name of the object.
-**/
-CHAR8 *
-AmlGetObjectName (
- IN EFI_AML_HANDLE *AmlHandle
- );
-
-/**
- Retrieve information according to AmlHandle
-
- @param[in] AmlHandle AML handle.
- @param[in] Index Index of the data to retrieve from the object. In general, indexes read from left-to-right
- in the ACPI encoding, with index 0 always being the ACPI opcode.
- @param[out] DataType Points to the returned data type or EFI_ACPI_DATA_TYPE_NONE if no data exists
- for the specified index.
- @param[out] Data Upon return, points to the pointer to the data.
- @param[out] DataSize Upon return, points to the size of Data.
-
- @retval EFI_SUCCESS Success.
- @retval EFI_INVALID_PARAMETER AmlHandle does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-AmlParseOptionHandleCommon (
- IN EFI_AML_HANDLE *AmlHandle,
- IN AML_OP_PARSE_INDEX Index,
- OUT EFI_ACPI_DATA_TYPE *DataType,
- OUT VOID **Data,
- OUT UINTN *DataSize
- );
-
-/**
- Return offset of last option.
-
- @param[in] AmlHandle AML Handle.
- @param[out] Buffer Upon return, points to the offset after last option.
-
- @retval EFI_SUCCESS Success.
- @retval EFI_INVALID_PARAMETER AmlHandle does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-AmlGetOffsetAfterLastOption (
- IN EFI_AML_HANDLE *AmlHandle,
- OUT UINT8 **Buffer
- );
-
-/**
- Return the child ACPI objects from Root Handle.
-
- @param[in] AmlParentHandle Parent handle. It is Root Handle.
- @param[in] AmlHandle The previously returned handle or NULL to start with the first handle.
- @param[out] Buffer On return, points to the next returned ACPI handle or NULL if there are no
- child objects.
-
- @retval EFI_SUCCESS Success
- @retval EFI_INVALID_PARAMETER ParentHandle is NULL or does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-AmlGetChildFromRoot (
- IN EFI_AML_HANDLE *AmlParentHandle,
- IN EFI_AML_HANDLE *AmlHandle,
- OUT VOID **Buffer
- );
-
-/**
- Return the child ACPI objects from Non-Root Handle.
-
- @param[in] AmlParentHandle Parent handle. It is Non-Root Handle.
- @param[in] AmlHandle The previously returned handle or NULL to start with the first handle.
- @param[out] Buffer On return, points to the next returned ACPI handle or NULL if there are no
- child objects.
-
- @retval EFI_SUCCESS Success
- @retval EFI_INVALID_PARAMETER ParentHandle is NULL or does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-AmlGetChildFromNonRoot (
- IN EFI_AML_HANDLE *AmlParentHandle,
- IN EFI_AML_HANDLE *AmlHandle,
- OUT VOID **Buffer
- );
-
-/**
- Return AML name according to ASL name.
- The caller need free the AmlName returned.
-
- @param[in] AslPath ASL name.
-
- @return AmlName
-**/
-UINT8 *
-AmlNameFromAslName (
- IN UINT8 *AslPath
- );
-
-/**
- Returns the handle of the ACPI object representing the specified ACPI AML path
-
- @param[in] AmlHandle Points to the handle of the object representing the starting point for the path search.
- @param[in] AmlPath Points to the ACPI AML path.
- @param[out] Buffer On return, points to the ACPI object which represents AcpiPath, relative to
- HandleIn.
- @param[in] FromRoot TRUE means to find AML path from \ (Root) Node.
- FALSE means to find AML path from this Node (The HandleIn).
-
- @retval EFI_SUCCESS Success
- @retval EFI_INVALID_PARAMETER HandleIn does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-AmlFindPath (
- IN EFI_AML_HANDLE *AmlHandle,
- IN UINT8 *AmlPath,
- OUT VOID **Buffer,
- IN BOOLEAN FromRoot
- );
-
-/**
- Print AML NameString.
-
- @param[in] Buffer AML NameString.
-**/
-VOID
-AmlPrintNameString (
- IN UINT8 *Buffer
- );
-
-/**
- Print AML NameSeg.
-
- @param[in] Buffer AML NameSeg.
-**/
-VOID
-AmlPrintNameSeg (
- IN UINT8 *Buffer
- );
-
-/**
- Check if it is AML Root name
-
- @param[in] Buffer AML path.
-
- @retval TRUE AML path is root.
- @retval FALSE AML path is not root.
-**/
-BOOLEAN
-AmlIsRootPath (
- IN UINT8 *Buffer
- );
-
-#endif
+/** @file
+ ACPI Sdt Protocol Driver
+
+ Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved. <BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _ACPI_SDT_H_
+#define _ACPI_SDT_H_
+
+//
+// Privacy data structure
+//
+
+//
+// ACPI Notify Linked List Signature.
+//
+#define EFI_ACPI_NOTIFY_LIST_SIGNATURE SIGNATURE_32 ('E', 'A', 'N', 'L')
+
+//
+// ACPI Notify List Entry definition.
+//
+// Signature must be set to EFI_ACPI_NOTIFY_LIST_SIGNATURE
+// Link is the linked list data.
+// Notification is the callback function.
+//
+typedef struct {
+ UINT32 Signature;
+ LIST_ENTRY Link;
+ EFI_ACPI_NOTIFICATION_FN Notification;
+} EFI_ACPI_NOTIFY_LIST;
+
+//
+// Containment record for ACPI Notify linked list.
+//
+#define EFI_ACPI_NOTIFY_LIST_FROM_LINK(_link) CR (_link, EFI_ACPI_NOTIFY_LIST, Link, EFI_ACPI_NOTIFY_LIST_SIGNATURE)
+
+typedef struct _AML_BYTE_ENCODING AML_BYTE_ENCODING;
+typedef struct _EFI_AML_NODE_LIST EFI_AML_NODE_LIST;
+
+//
+// AML Node Linked List Signature.
+//
+#define EFI_AML_NODE_LIST_SIGNATURE SIGNATURE_32 ('E', 'A', 'M', 'L')
+
+//
+// AML Node Linked List Entry definition.
+//
+// Signature must be set to EFI_AML_NODE_LIST_SIGNATURE
+// Link is the linked list data.
+// Name is the ACPI node name.
+// This is listed for PATH finding.
+// Buffer is the ACPI node buffer pointer, the first/second bytes are opcode.
+// This buffer should not be freed.
+// Size is the total size of this ACPI node buffer.
+// Children is the children linked list of this node.
+//
+
+struct _EFI_AML_NODE_LIST {
+ UINT32 Signature;
+ UINT8 Name[AML_NAME_SEG_SIZE];
+ UINT8 *Buffer;
+ UINTN Size;
+ LIST_ENTRY Link;
+ LIST_ENTRY Children;
+ EFI_AML_NODE_LIST *Parent;
+ AML_BYTE_ENCODING *AmlByteEncoding;
+};
+
+//
+// Containment record for AML Node linked list.
+//
+#define EFI_AML_NODE_LIST_FROM_LINK(_link) CR (_link, EFI_AML_NODE_LIST, Link, EFI_AML_NODE_LIST_SIGNATURE)
+
+//
+// AML Handle Signature.
+//
+#define EFI_AML_HANDLE_SIGNATURE SIGNATURE_32 ('E', 'A', 'H', 'S')
+#define EFI_AML_ROOT_HANDLE_SIGNATURE SIGNATURE_32 ('E', 'A', 'R', 'H')
+
+//
+// AML Handle Entry definition.
+//
+// Signature must be set to EFI_AML_HANDLE_SIGNATURE or EFI_AML_ROOT_HANDLE_SIGNATURE
+// Buffer is the ACPI node buffer pointer, the first/second bytes are opcode.
+// This buffer should not be freed.
+// Size is the total size of this ACPI node buffer.
+//
+typedef struct {
+ UINT32 Signature;
+ UINT8 *Buffer;
+ UINTN Size;
+ AML_BYTE_ENCODING *AmlByteEncoding;
+ BOOLEAN Modified;
+} EFI_AML_HANDLE;
+
+typedef UINT32 AML_OP_PARSE_INDEX;
+
+#define AML_OP_PARSE_INDEX_GET_OPCODE 0
+#define AML_OP_PARSE_INDEX_GET_TERM1 1
+#define AML_OP_PARSE_INDEX_GET_TERM2 2
+#define AML_OP_PARSE_INDEX_GET_TERM3 3
+#define AML_OP_PARSE_INDEX_GET_TERM4 4
+#define AML_OP_PARSE_INDEX_GET_TERM5 5
+#define AML_OP_PARSE_INDEX_GET_TERM6 6
+#define AML_OP_PARSE_INDEX_GET_SIZE (AML_OP_PARSE_INDEX)-1
+
+typedef UINT32 AML_OP_PARSE_FORMAT;
+#define AML_NONE 0
+#define AML_OPCODE 1
+#define AML_UINT8 2
+#define AML_UINT16 3
+#define AML_UINT32 4
+#define AML_UINT64 5
+#define AML_NAME 6
+#define AML_STRING 7
+#define AML_OBJECT 8
+
+typedef UINT32 AML_OP_ATTRIBUTE;
+#define AML_HAS_PKG_LENGTH 0x1 // It is ACPI attribute - if OpCode has PkgLength
+#define AML_IS_NAME_CHAR 0x2 // It is ACPI attribute - if this is NameChar
+#define AML_HAS_CHILD_OBJ 0x4 // it is ACPI attribute - if OpCode has Child Object.
+#define AML_IN_NAMESPACE 0x10000 // It is UEFI SDT attribute - if OpCode will be in NameSpace
+ // NOTE; Not all OBJECT will be in NameSpace
+ // For example, BankField | CreateBitField | CreateByteField | CreateDWordField |
+ // CreateField | CreateQWordField | CreateWordField | Field | IndexField.
+
+struct _AML_BYTE_ENCODING {
+ UINT8 OpCode;
+ UINT8 SubOpCode;
+ AML_OP_PARSE_INDEX MaxIndex;
+ AML_OP_PARSE_FORMAT Format[6];
+ AML_OP_ATTRIBUTE Attribute;
+};
+
+//
+// AcpiSdt protocol declaration
+//
+
+/**
+ Returns a requested ACPI table.
+
+ The GetAcpiTable() function returns a pointer to a buffer containing the ACPI table associated
+ with the Index that was input. The following structures are not considered elements in the list of
+ ACPI tables:
+ - Root System Description Pointer (RSD_PTR)
+ - Root System Description Table (RSDT)
+ - Extended System Description Table (XSDT)
+ Version is updated with a bit map containing all the versions of ACPI of which the table is a
+ member. For tables installed via the EFI_ACPI_TABLE_PROTOCOL.InstallAcpiTable() interface,
+ the function returns the value of EFI_ACPI_STD_PROTOCOL.AcpiVersion.
+
+ @param[in] Index The zero-based index of the table to retrieve.
+ @param[out] Table Pointer for returning the table buffer.
+ @param[out] Version On return, updated with the ACPI versions to which this table belongs. Type
+ EFI_ACPI_TABLE_VERSION is defined in "Related Definitions" in the
+ EFI_ACPI_SDT_PROTOCOL.
+ @param[out] TableKey On return, points to the table key for the specified ACPI system definition table.
+ This is identical to the table key used in the EFI_ACPI_TABLE_PROTOCOL.
+ The TableKey can be passed to EFI_ACPI_TABLE_PROTOCOL.UninstallAcpiTable()
+ to uninstall the table.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_NOT_FOUND The requested index is too large and a table was not found.
+**/
+EFI_STATUS
+EFIAPI
+GetAcpiTable2 (
+ IN UINTN Index,
+ OUT EFI_ACPI_SDT_HEADER **Table,
+ OUT EFI_ACPI_TABLE_VERSION *Version,
+ OUT UINTN *TableKey
+ );
+
+/**
+ Register or unregister a callback when an ACPI table is installed.
+
+ This function registers or unregisters a function which will be called whenever a new ACPI table is
+ installed.
+
+ @param[in] Register If TRUE, then the specified function will be registered. If FALSE, then the specified
+ function will be unregistered.
+ @param[in] Notification Points to the callback function to be registered or unregistered.
+
+ @retval EFI_SUCCESS Callback successfully registered or unregistered.
+ @retval EFI_INVALID_PARAMETER Notification is NULL
+ @retval EFI_INVALID_PARAMETER Register is FALSE and Notification does not match a known registration function.
+**/
+EFI_STATUS
+EFIAPI
+RegisterNotify (
+ IN BOOLEAN Register,
+ IN EFI_ACPI_NOTIFICATION_FN Notification
+ );
+
+/**
+ Create a handle for the first ACPI opcode in an ACPI system description table.
+
+ @param[in] TableKey The table key for the ACPI table, as returned by GetTable().
+ @param[out] Handle On return, points to the newly created ACPI handle.
+
+ @retval EFI_SUCCESS Handle created successfully.
+ @retval EFI_NOT_FOUND TableKey does not refer to a valid ACPI table.
+**/
+EFI_STATUS
+EFIAPI
+OpenSdt (
+ IN UINTN TableKey,
+ OUT EFI_ACPI_HANDLE *Handle
+ );
+
+/**
+ Create a handle from an ACPI opcode
+
+ @param[in] Buffer Points to the ACPI opcode.
+ @param[out] Handle Upon return, holds the handle.
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_INVALID_PARAMETER Buffer is NULL or Handle is NULL or Buffer points to an
+ invalid opcode.
+
+**/
+EFI_STATUS
+EFIAPI
+Open (
+ IN VOID *Buffer,
+ OUT EFI_ACPI_HANDLE *Handle
+ );
+
+/**
+ Close an ACPI handle.
+
+ @param[in] Handle Returns the handle.
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_INVALID_PARAMETER Handle is NULL or does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+EFIAPI
+Close (
+ IN EFI_ACPI_HANDLE Handle
+ );
+
+/**
+ Retrieve information about an ACPI object.
+
+ @param[in] Handle ACPI object handle.
+ @param[in] Index Index of the data to retrieve from the object. In general, indexes read from left-to-right
+ in the ACPI encoding, with index 0 always being the ACPI opcode.
+ @param[out] DataType Points to the returned data type or EFI_ACPI_DATA_TYPE_NONE if no data exists
+ for the specified index.
+ @param[out] Data Upon return, points to the pointer to the data.
+ @param[out] DataSize Upon return, points to the size of Data.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER Handle is NULL or does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+EFIAPI
+GetOption (
+ IN EFI_ACPI_HANDLE Handle,
+ IN UINTN Index,
+ OUT EFI_ACPI_DATA_TYPE *DataType,
+ OUT CONST VOID **Data,
+ OUT UINTN *DataSize
+ );
+
+/**
+ Change information about an ACPI object.
+
+ @param[in] Handle ACPI object handle.
+ @param[in] Index Index of the data to retrieve from the object. In general, indexes read from left-to-right
+ in the ACPI encoding, with index 0 always being the ACPI opcode.
+ @param[in] Data Points to the data.
+ @param[in] DataSize The size of the Data.
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_INVALID_PARAMETER Handle is NULL or does not refer to a valid ACPI object.
+ @retval EFI_BAD_BUFFER_SIZE Data cannot be accommodated in the space occupied by
+ the option.
+
+**/
+EFI_STATUS
+EFIAPI
+SetOption (
+ IN EFI_ACPI_HANDLE Handle,
+ IN UINTN Index,
+ IN CONST VOID *Data,
+ IN UINTN DataSize
+ );
+
+/**
+ Return the child ACPI objects.
+
+ @param[in] ParentHandle Parent handle.
+ @param[in, out] Handle On entry, points to the previously returned handle or NULL to start with the first
+ handle. On return, points to the next returned ACPI handle or NULL if there are no
+ child objects.
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_INVALID_PARAMETER ParentHandle is NULL or does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+EFIAPI
+GetChild (
+ IN EFI_ACPI_HANDLE ParentHandle,
+ IN OUT EFI_ACPI_HANDLE *Handle
+ );
+
+/**
+ Returns the handle of the ACPI object representing the specified ACPI path
+
+ @param[in] HandleIn Points to the handle of the object representing the starting point for the path search.
+ @param[in] AcpiPath Points to the ACPI path, which conforms to the ACPI encoded path format.
+ @param[out] HandleOut On return, points to the ACPI object which represents AcpiPath, relative to
+ HandleIn.
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_INVALID_PARAMETER HandleIn is NULL or does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+EFIAPI
+FindPath (
+ IN EFI_ACPI_HANDLE HandleIn,
+ IN VOID *AcpiPath,
+ OUT EFI_ACPI_HANDLE *HandleOut
+ );
+
+//
+// ACPI SDT function
+//
+
+/**
+ Create a handle from an ACPI opcode
+
+ @param[in] Buffer Points to the ACPI opcode.
+ @param[in] BufferSize Max buffer size.
+ @param[out] Handle Upon return, holds the handle.
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_INVALID_PARAMETER Buffer is NULL or Handle is NULL or Buffer points to an
+ invalid opcode.
+
+**/
+EFI_STATUS
+SdtOpenEx (
+ IN VOID *Buffer,
+ IN UINTN BufferSize,
+ OUT EFI_ACPI_HANDLE *Handle
+ );
+
+//
+// AML support function
+//
+
+/**
+ Get AML NameString size.
+
+ @param[in] Buffer AML NameString.
+ @param[out] BufferSize AML NameString size
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER Buffer does not refer to a valid AML NameString.
+**/
+EFI_STATUS
+AmlGetNameStringSize (
+ IN UINT8 *Buffer,
+ OUT UINTN *BufferSize
+ );
+
+/**
+ This function retuns package length from the buffer.
+
+ @param[in] Buffer AML buffer
+ @param[out] PkgLength The total length of package.
+
+ @return The byte data count to present the package length.
+**/
+UINTN
+AmlGetPkgLength (
+ IN UINT8 *Buffer,
+ OUT UINTN *PkgLength
+ );
+
+/**
+ This function returns AcpiDataType according to AmlType.
+
+ @param[in] AmlType AML Type.
+
+ @return AcpiDataType
+**/
+EFI_ACPI_DATA_TYPE
+AmlTypeToAcpiType (
+ IN AML_OP_PARSE_FORMAT AmlType
+ );
+
+/**
+ This function returns AmlByteEncoding according to OpCode Byte.
+
+ @param[in] OpByteBuffer OpCode byte buffer.
+
+ @return AmlByteEncoding
+**/
+AML_BYTE_ENCODING *
+AmlSearchByOpByte (
+ IN UINT8 *OpByteBuffer
+ );
+
+/**
+ Return object size.
+
+ @param[in] AmlByteEncoding AML Byte Encoding.
+ @param[in] Buffer AML object buffer.
+ @param[in] MaxBufferSize AML object buffer MAX size. The parser can not parse any data exceed this region.
+
+ @return Size of the object.
+**/
+UINTN
+AmlGetObjectSize (
+ IN AML_BYTE_ENCODING *AmlByteEncoding,
+ IN UINT8 *Buffer,
+ IN UINTN MaxBufferSize
+ );
+
+/**
+ Return object name.
+
+ @param[in] AmlHandle AML handle.
+
+ @return Name of the object.
+**/
+CHAR8 *
+AmlGetObjectName (
+ IN EFI_AML_HANDLE *AmlHandle
+ );
+
+/**
+ Retrieve information according to AmlHandle
+
+ @param[in] AmlHandle AML handle.
+ @param[in] Index Index of the data to retrieve from the object. In general, indexes read from left-to-right
+ in the ACPI encoding, with index 0 always being the ACPI opcode.
+ @param[out] DataType Points to the returned data type or EFI_ACPI_DATA_TYPE_NONE if no data exists
+ for the specified index.
+ @param[out] Data Upon return, points to the pointer to the data.
+ @param[out] DataSize Upon return, points to the size of Data.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER AmlHandle does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+AmlParseOptionHandleCommon (
+ IN EFI_AML_HANDLE *AmlHandle,
+ IN AML_OP_PARSE_INDEX Index,
+ OUT EFI_ACPI_DATA_TYPE *DataType,
+ OUT VOID **Data,
+ OUT UINTN *DataSize
+ );
+
+/**
+ Return offset of last option.
+
+ @param[in] AmlHandle AML Handle.
+ @param[out] Buffer Upon return, points to the offset after last option.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER AmlHandle does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+AmlGetOffsetAfterLastOption (
+ IN EFI_AML_HANDLE *AmlHandle,
+ OUT UINT8 **Buffer
+ );
+
+/**
+ Return the child ACPI objects from Root Handle.
+
+ @param[in] AmlParentHandle Parent handle. It is Root Handle.
+ @param[in] AmlHandle The previously returned handle or NULL to start with the first handle.
+ @param[out] Buffer On return, points to the next returned ACPI handle or NULL if there are no
+ child objects.
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_INVALID_PARAMETER ParentHandle is NULL or does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+AmlGetChildFromRoot (
+ IN EFI_AML_HANDLE *AmlParentHandle,
+ IN EFI_AML_HANDLE *AmlHandle,
+ OUT VOID **Buffer
+ );
+
+/**
+ Return the child ACPI objects from Non-Root Handle.
+
+ @param[in] AmlParentHandle Parent handle. It is Non-Root Handle.
+ @param[in] AmlHandle The previously returned handle or NULL to start with the first handle.
+ @param[out] Buffer On return, points to the next returned ACPI handle or NULL if there are no
+ child objects.
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_INVALID_PARAMETER ParentHandle is NULL or does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+AmlGetChildFromNonRoot (
+ IN EFI_AML_HANDLE *AmlParentHandle,
+ IN EFI_AML_HANDLE *AmlHandle,
+ OUT VOID **Buffer
+ );
+
+/**
+ Return AML name according to ASL name.
+ The caller need free the AmlName returned.
+
+ @param[in] AslPath ASL name.
+
+ @return AmlName
+**/
+UINT8 *
+AmlNameFromAslName (
+ IN UINT8 *AslPath
+ );
+
+/**
+ Returns the handle of the ACPI object representing the specified ACPI AML path
+
+ @param[in] AmlHandle Points to the handle of the object representing the starting point for the path search.
+ @param[in] AmlPath Points to the ACPI AML path.
+ @param[out] Buffer On return, points to the ACPI object which represents AcpiPath, relative to
+ HandleIn.
+ @param[in] FromRoot TRUE means to find AML path from \ (Root) Node.
+ FALSE means to find AML path from this Node (The HandleIn).
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_INVALID_PARAMETER HandleIn does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+AmlFindPath (
+ IN EFI_AML_HANDLE *AmlHandle,
+ IN UINT8 *AmlPath,
+ OUT VOID **Buffer,
+ IN BOOLEAN FromRoot
+ );
+
+/**
+ Print AML NameString.
+
+ @param[in] Buffer AML NameString.
+**/
+VOID
+AmlPrintNameString (
+ IN UINT8 *Buffer
+ );
+
+/**
+ Print AML NameSeg.
+
+ @param[in] Buffer AML NameSeg.
+**/
+VOID
+AmlPrintNameSeg (
+ IN UINT8 *Buffer
+ );
+
+/**
+ Check if it is AML Root name
+
+ @param[in] Buffer AML path.
+
+ @retval TRUE AML path is root.
+ @retval FALSE AML path is not root.
+**/
+BOOLEAN
+AmlIsRootPath (
+ IN UINT8 *Buffer
+ );
+
+#endif
diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.c b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.c
index f50068d0e0..8a8972c646 100644
--- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.c
+++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.c
@@ -1,84 +1,84 @@
-/** @file
- ACPI Table Protocol Driver
-
- Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-//
-// Includes
-//
-#include "AcpiTable.h"
-
-//
-// Handle to install ACPI Table Protocol
-//
-EFI_HANDLE mHandle = NULL;
-GLOBAL_REMOVE_IF_UNREFERENCED EFI_ACPI_TABLE_INSTANCE *mPrivateData = NULL;
-
-/**
- Entry point of the ACPI table driver.
- Creates and initializes an instance of the ACPI Table
- Protocol and installs it on a new handle.
-
- @param ImageHandle A handle for the image that is initializing this driver.
- @param SystemTable A pointer to the EFI system table.
-
- @return EFI_SUCCESS Driver initialized successfully.
- @return EFI_LOAD_ERROR Failed to Initialize or has been loaded.
- @return EFI_OUT_OF_RESOURCES Could not allocate needed resources.
-
-**/
-EFI_STATUS
-EFIAPI
-InitializeAcpiTableDxe (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- )
-{
- EFI_STATUS Status;
- EFI_ACPI_TABLE_INSTANCE *PrivateData;
-
- //
- // Initialize our protocol
- //
- PrivateData = AllocateZeroPool (sizeof (EFI_ACPI_TABLE_INSTANCE));
- ASSERT (PrivateData);
- PrivateData->Signature = EFI_ACPI_TABLE_SIGNATURE;
-
- //
- // Call all constructors per produced protocols
- //
- Status = AcpiTableAcpiTableConstructor (PrivateData);
- if (EFI_ERROR (Status)) {
- gBS->FreePool (PrivateData);
- return EFI_LOAD_ERROR;
- }
-
- //
- // Install ACPI Table protocol
- //
- if (FeaturePcdGet (PcdInstallAcpiSdtProtocol)) {
- mPrivateData = PrivateData;
- Status = gBS->InstallMultipleProtocolInterfaces (
- &mHandle,
- &gEfiAcpiTableProtocolGuid,
- &PrivateData->AcpiTableProtocol,
- &gEfiAcpiSdtProtocolGuid,
- &mPrivateData->AcpiSdtProtocol,
- NULL
- );
- } else {
- Status = gBS->InstallMultipleProtocolInterfaces (
- &mHandle,
- &gEfiAcpiTableProtocolGuid,
- &PrivateData->AcpiTableProtocol,
- NULL
- );
- }
-
- ASSERT_EFI_ERROR (Status);
-
- return Status;
-}
+/** @file
+ ACPI Table Protocol Driver
+
+ Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+//
+// Includes
+//
+#include "AcpiTable.h"
+
+//
+// Handle to install ACPI Table Protocol
+//
+EFI_HANDLE mHandle = NULL;
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_ACPI_TABLE_INSTANCE *mPrivateData = NULL;
+
+/**
+ Entry point of the ACPI table driver.
+ Creates and initializes an instance of the ACPI Table
+ Protocol and installs it on a new handle.
+
+ @param ImageHandle A handle for the image that is initializing this driver.
+ @param SystemTable A pointer to the EFI system table.
+
+ @return EFI_SUCCESS Driver initialized successfully.
+ @return EFI_LOAD_ERROR Failed to Initialize or has been loaded.
+ @return EFI_OUT_OF_RESOURCES Could not allocate needed resources.
+
+**/
+EFI_STATUS
+EFIAPI
+InitializeAcpiTableDxe (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ )
+{
+ EFI_STATUS Status;
+ EFI_ACPI_TABLE_INSTANCE *PrivateData;
+
+ //
+ // Initialize our protocol
+ //
+ PrivateData = AllocateZeroPool (sizeof (EFI_ACPI_TABLE_INSTANCE));
+ ASSERT (PrivateData);
+ PrivateData->Signature = EFI_ACPI_TABLE_SIGNATURE;
+
+ //
+ // Call all constructors per produced protocols
+ //
+ Status = AcpiTableAcpiTableConstructor (PrivateData);
+ if (EFI_ERROR (Status)) {
+ gBS->FreePool (PrivateData);
+ return EFI_LOAD_ERROR;
+ }
+
+ //
+ // Install ACPI Table protocol
+ //
+ if (FeaturePcdGet (PcdInstallAcpiSdtProtocol)) {
+ mPrivateData = PrivateData;
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &mHandle,
+ &gEfiAcpiTableProtocolGuid,
+ &PrivateData->AcpiTableProtocol,
+ &gEfiAcpiSdtProtocolGuid,
+ &mPrivateData->AcpiSdtProtocol,
+ NULL
+ );
+ } else {
+ Status = gBS->InstallMultipleProtocolInterfaces (
+ &mHandle,
+ &gEfiAcpiTableProtocolGuid,
+ &PrivateData->AcpiTableProtocol,
+ NULL
+ );
+ }
+
+ ASSERT_EFI_ERROR (Status);
+
+ return Status;
+}
diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.h b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.h
index 9cfef3d718..5294b738f1 100644
--- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.h
+++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.h
@@ -1,271 +1,271 @@
-/** @file
- ACPI Table Protocol Driver
-
- Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#ifndef _ACPI_TABLE_H_
-#define _ACPI_TABLE_H_
-
-#include <PiDxe.h>
-
-#include <Protocol/AcpiTable.h>
-#include <Guid/Acpi.h>
-#include <Protocol/AcpiSystemDescriptionTable.h>
-
-#include <Library/BaseLib.h>
-#include <Library/DebugLib.h>
-#include <Library/UefiLib.h>
-#include <Library/BaseMemoryLib.h>
-#include <Library/UefiDriverEntryPoint.h>
-#include <Library/MemoryAllocationLib.h>
-#include <Library/UefiBootServicesTableLib.h>
-#include <Library/PcdLib.h>
-#include <Library/HobLib.h>
-#include <UniversalPayload/AcpiTable.h>
-
-//
-// Statements that include other files
-//
-#include <IndustryStandard/Acpi.h>
-
-#include "AcpiSdt.h"
-
-//
-// Great than or equal to 2.0.
-//
-#define ACPI_TABLE_VERSION_GTE_2_0 (EFI_ACPI_TABLE_VERSION_2_0 |\
- EFI_ACPI_TABLE_VERSION_3_0 | \
- EFI_ACPI_TABLE_VERSION_4_0 | \
- EFI_ACPI_TABLE_VERSION_5_0)
-
-//
-// Private Driver Data
-//
-//
-// ACPI Table Linked List Signature.
-//
-#define EFI_ACPI_TABLE_LIST_SIGNATURE SIGNATURE_32 ('E', 'A', 'T', 'L')
-
-//
-// ACPI Table Linked List Entry definition.
-//
-// Signature must be set to EFI_ACPI_TABLE_LIST_SIGNATURE
-// Link is the linked list data.
-// Version is the versions of the ACPI tables that this table belongs in.
-// Table is a pointer to the table.
-// TableSize is the size of the table
-// Handle is used to identify a particular table.
-// PoolAllocation carries the allocation type:
-// FALSE: Table points to EFI_SIZE_TO_PAGES(TableSize) pages allocated using
-// gBS->AllocatePages ()
-// TRUE: Table points to TableSize bytes allocated using gBS->AllocatePool ()
-//
-typedef struct {
- UINT32 Signature;
- LIST_ENTRY Link;
- EFI_ACPI_TABLE_VERSION Version;
- EFI_ACPI_COMMON_HEADER *Table;
- UINTN TableSize;
- UINTN Handle;
- BOOLEAN PoolAllocation;
-} EFI_ACPI_TABLE_LIST;
-
-//
-// Containment record for ACPI Table linked list.
-//
-#define EFI_ACPI_TABLE_LIST_FROM_LINK(_link) CR (_link, EFI_ACPI_TABLE_LIST, Link, EFI_ACPI_TABLE_LIST_SIGNATURE)
-
-//
-// The maximum number of tables this driver supports
-//
-#define EFI_ACPI_MAX_NUM_TABLES 20
-
-//
-// Protocol private structure definition
-//
-//
-// ACPI support protocol instance signature definition.
-//
-#define EFI_ACPI_TABLE_SIGNATURE SIGNATURE_32 ('S', 'T', 'A', 'E')
-
-//
-// ACPI support protocol instance data structure
-//
-typedef struct {
- UINTN Signature;
- EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp1; // Pointer to RSD_PTR structure
- EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp3; // Pointer to RSD_PTR structure
- EFI_ACPI_DESCRIPTION_HEADER *Rsdt1; // Pointer to RSDT table header
- EFI_ACPI_DESCRIPTION_HEADER *Rsdt3; // Pointer to RSDT table header
- EFI_ACPI_DESCRIPTION_HEADER *Xsdt; // Pointer to XSDT table header
- EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt1; // Pointer to FADT table header
- EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt3; // Pointer to FADT table header
- EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *Facs1; // Pointer to FACS table header
- EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *Facs3; // Pointer to FACS table header
- EFI_ACPI_DESCRIPTION_HEADER *Dsdt1; // Pointer to DSDT table header
- EFI_ACPI_DESCRIPTION_HEADER *Dsdt3; // Pointer to DSDT table header
- LIST_ENTRY TableList;
- UINTN NumberOfTableEntries1; // Number of ACPI 1.0 tables
- UINTN NumberOfTableEntries3; // Number of ACPI 3.0 tables
- UINTN CurrentHandle;
- EFI_ACPI_TABLE_PROTOCOL AcpiTableProtocol;
- EFI_ACPI_SDT_PROTOCOL AcpiSdtProtocol;
- LIST_ENTRY NotifyList;
-} EFI_ACPI_TABLE_INSTANCE;
-
-//
-// ACPI table protocol instance containing record macro
-//
-#define EFI_ACPI_TABLE_INSTANCE_FROM_THIS(a) \
- CR (a, \
- EFI_ACPI_TABLE_INSTANCE, \
- AcpiTableProtocol, \
- EFI_ACPI_TABLE_SIGNATURE \
- )
-
-//
-// Protocol Constructor functions
-//
-
-/**
- Constructor for the ACPI support protocol. Initializes instance
- data.
-
- @param AcpiTableInstance Instance to construct
-
- @return EFI_SUCCESS Instance initialized.
- @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
-
-**/
-EFI_STATUS
-AcpiTableAcpiTableConstructor (
- EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance
- );
-
-/**
- Entry point of the ACPI table driver.
- Creates and initializes an instance of the ACPI Table
- Protocol and installs it on a new handle.
-
- @param ImageHandle A handle for the image that is initializing this driver
- @param SystemTable A pointer to the EFI system table
-
- @return EFI_SUCCESS Driver initialized successfully
- @return EFI_LOAD_ERROR Failed to Initialize or has been loaded
- @return EFI_OUT_OF_RESOURCES Could not allocate needed resources
-
-**/
-EFI_STATUS
-EFIAPI
-InitializeAcpiTableDxe (
- IN EFI_HANDLE ImageHandle,
- IN EFI_SYSTEM_TABLE *SystemTable
- );
-
-/**
-
- This function finds the table specified by the handle and returns a pointer to it.
- If the handle is not found, EFI_NOT_FOUND is returned and the contents of Table are
- undefined.
-
- @param[in] Handle Table to find.
- @param[in] TableList Table list to search
- @param[out] Table Pointer to table found.
-
- @retval EFI_SUCCESS The function completed successfully.
- @retval EFI_NOT_FOUND No table found matching the handle specified.
-
-**/
-EFI_STATUS
-FindTableByHandle (
- IN UINTN Handle,
- IN LIST_ENTRY *TableList,
- OUT EFI_ACPI_TABLE_LIST **Table
- );
-
-/**
-
- This function calculates and updates an UINT8 checksum.
-
- @param[in] Buffer Pointer to buffer to checksum
- @param[in] Size Number of bytes to checksum
- @param[in] ChecksumOffset Offset to place the checksum result in
-
- @retval EFI_SUCCESS The function completed successfully.
-
-**/
-EFI_STATUS
-AcpiPlatformChecksum (
- IN VOID *Buffer,
- IN UINTN Size,
- IN UINTN ChecksumOffset
- );
-
-/**
- This function invokes ACPI notification.
-
- @param[in] AcpiTableInstance Instance to AcpiTable
- @param[in] Version Version(s) to set.
- @param[in] Handle Handle of the table.
-**/
-VOID
-SdtNotifyAcpiList (
- IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
- IN EFI_ACPI_TABLE_VERSION Version,
- IN UINTN Handle
- );
-
-/**
- This function initializes AcpiSdt protocol in ACPI table instance.
-
- @param[in] AcpiTableInstance Instance to construct
-**/
-VOID
-SdtAcpiTableAcpiSdtConstructor (
- IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance
- );
-
-/**
- Returns a requested ACPI table.
-
- The following structures are not considered elements in the list of
- ACPI tables:
- - Root System Description Pointer (RSD_PTR)
- - Root System Description Table (RSDT)
- - Extended System Description Table (XSDT)
- Version is updated with a bit map containing all the versions of ACPI of which the table is a
- member. For tables installed via the EFI_ACPI_TABLE_PROTOCOL.InstallAcpiTable() interface,
- the function returns the value of EFI_ACPI_STD_PROTOCOL.AcpiVersion.
-
- @param[in] AcpiTableInstance ACPI table Instance.
- @param[in] Index The zero-based index of the table to retrieve.
- @param[out] Table Pointer for returning the table buffer.
- @param[out] Version On return, updated with the ACPI versions to which this table belongs. Type
- EFI_ACPI_TABLE_VERSION is defined in "Related Definitions" in the
- EFI_ACPI_SDT_PROTOCOL.
- @param[out] TableKey On return, points to the table key for the specified ACPI system definition table.
- This is identical to the table key used in the EFI_ACPI_TABLE_PROTOCOL.
- The TableKey can be passed to EFI_ACPI_TABLE_PROTOCOL.UninstallAcpiTable()
- to uninstall the table.
- @retval EFI_SUCCESS The function completed successfully.
- @retval EFI_NOT_FOUND The requested index is too large and a table was not found.
-**/
-EFI_STATUS
-SdtGetAcpiTable (
- IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
- IN UINTN Index,
- OUT EFI_ACPI_SDT_HEADER **Table,
- OUT EFI_ACPI_TABLE_VERSION *Version,
- OUT UINTN *TableKey
- );
-
-//
-// export PrivateData symbol, because we need that in AcpiSdtProtol implementation
-//
-extern EFI_HANDLE mHandle;
-extern EFI_ACPI_TABLE_INSTANCE *mPrivateData;
-
-#endif
+/** @file
+ ACPI Table Protocol Driver
+
+ Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#ifndef _ACPI_TABLE_H_
+#define _ACPI_TABLE_H_
+
+#include <PiDxe.h>
+
+#include <Protocol/AcpiTable.h>
+#include <Guid/Acpi.h>
+#include <Protocol/AcpiSystemDescriptionTable.h>
+
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/UefiLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/UefiDriverEntryPoint.h>
+#include <Library/MemoryAllocationLib.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/PcdLib.h>
+#include <Library/HobLib.h>
+#include <UniversalPayload/AcpiTable.h>
+
+//
+// Statements that include other files
+//
+#include <IndustryStandard/Acpi.h>
+
+#include "AcpiSdt.h"
+
+//
+// Great than or equal to 2.0.
+//
+#define ACPI_TABLE_VERSION_GTE_2_0 (EFI_ACPI_TABLE_VERSION_2_0 |\
+ EFI_ACPI_TABLE_VERSION_3_0 | \
+ EFI_ACPI_TABLE_VERSION_4_0 | \
+ EFI_ACPI_TABLE_VERSION_5_0)
+
+//
+// Private Driver Data
+//
+//
+// ACPI Table Linked List Signature.
+//
+#define EFI_ACPI_TABLE_LIST_SIGNATURE SIGNATURE_32 ('E', 'A', 'T', 'L')
+
+//
+// ACPI Table Linked List Entry definition.
+//
+// Signature must be set to EFI_ACPI_TABLE_LIST_SIGNATURE
+// Link is the linked list data.
+// Version is the versions of the ACPI tables that this table belongs in.
+// Table is a pointer to the table.
+// TableSize is the size of the table
+// Handle is used to identify a particular table.
+// PoolAllocation carries the allocation type:
+// FALSE: Table points to EFI_SIZE_TO_PAGES(TableSize) pages allocated using
+// gBS->AllocatePages ()
+// TRUE: Table points to TableSize bytes allocated using gBS->AllocatePool ()
+//
+typedef struct {
+ UINT32 Signature;
+ LIST_ENTRY Link;
+ EFI_ACPI_TABLE_VERSION Version;
+ EFI_ACPI_COMMON_HEADER *Table;
+ UINTN TableSize;
+ UINTN Handle;
+ BOOLEAN PoolAllocation;
+} EFI_ACPI_TABLE_LIST;
+
+//
+// Containment record for ACPI Table linked list.
+//
+#define EFI_ACPI_TABLE_LIST_FROM_LINK(_link) CR (_link, EFI_ACPI_TABLE_LIST, Link, EFI_ACPI_TABLE_LIST_SIGNATURE)
+
+//
+// The maximum number of tables this driver supports
+//
+#define EFI_ACPI_MAX_NUM_TABLES 20
+
+//
+// Protocol private structure definition
+//
+//
+// ACPI support protocol instance signature definition.
+//
+#define EFI_ACPI_TABLE_SIGNATURE SIGNATURE_32 ('S', 'T', 'A', 'E')
+
+//
+// ACPI support protocol instance data structure
+//
+typedef struct {
+ UINTN Signature;
+ EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp1; // Pointer to RSD_PTR structure
+ EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp3; // Pointer to RSD_PTR structure
+ EFI_ACPI_DESCRIPTION_HEADER *Rsdt1; // Pointer to RSDT table header
+ EFI_ACPI_DESCRIPTION_HEADER *Rsdt3; // Pointer to RSDT table header
+ EFI_ACPI_DESCRIPTION_HEADER *Xsdt; // Pointer to XSDT table header
+ EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt1; // Pointer to FADT table header
+ EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *Fadt3; // Pointer to FADT table header
+ EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *Facs1; // Pointer to FACS table header
+ EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *Facs3; // Pointer to FACS table header
+ EFI_ACPI_DESCRIPTION_HEADER *Dsdt1; // Pointer to DSDT table header
+ EFI_ACPI_DESCRIPTION_HEADER *Dsdt3; // Pointer to DSDT table header
+ LIST_ENTRY TableList;
+ UINTN NumberOfTableEntries1; // Number of ACPI 1.0 tables
+ UINTN NumberOfTableEntries3; // Number of ACPI 3.0 tables
+ UINTN CurrentHandle;
+ EFI_ACPI_TABLE_PROTOCOL AcpiTableProtocol;
+ EFI_ACPI_SDT_PROTOCOL AcpiSdtProtocol;
+ LIST_ENTRY NotifyList;
+} EFI_ACPI_TABLE_INSTANCE;
+
+//
+// ACPI table protocol instance containing record macro
+//
+#define EFI_ACPI_TABLE_INSTANCE_FROM_THIS(a) \
+ CR (a, \
+ EFI_ACPI_TABLE_INSTANCE, \
+ AcpiTableProtocol, \
+ EFI_ACPI_TABLE_SIGNATURE \
+ )
+
+//
+// Protocol Constructor functions
+//
+
+/**
+ Constructor for the ACPI support protocol. Initializes instance
+ data.
+
+ @param AcpiTableInstance Instance to construct
+
+ @return EFI_SUCCESS Instance initialized.
+ @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
+
+**/
+EFI_STATUS
+AcpiTableAcpiTableConstructor (
+ EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance
+ );
+
+/**
+ Entry point of the ACPI table driver.
+ Creates and initializes an instance of the ACPI Table
+ Protocol and installs it on a new handle.
+
+ @param ImageHandle A handle for the image that is initializing this driver
+ @param SystemTable A pointer to the EFI system table
+
+ @return EFI_SUCCESS Driver initialized successfully
+ @return EFI_LOAD_ERROR Failed to Initialize or has been loaded
+ @return EFI_OUT_OF_RESOURCES Could not allocate needed resources
+
+**/
+EFI_STATUS
+EFIAPI
+InitializeAcpiTableDxe (
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_SYSTEM_TABLE *SystemTable
+ );
+
+/**
+
+ This function finds the table specified by the handle and returns a pointer to it.
+ If the handle is not found, EFI_NOT_FOUND is returned and the contents of Table are
+ undefined.
+
+ @param[in] Handle Table to find.
+ @param[in] TableList Table list to search
+ @param[out] Table Pointer to table found.
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_NOT_FOUND No table found matching the handle specified.
+
+**/
+EFI_STATUS
+FindTableByHandle (
+ IN UINTN Handle,
+ IN LIST_ENTRY *TableList,
+ OUT EFI_ACPI_TABLE_LIST **Table
+ );
+
+/**
+
+ This function calculates and updates an UINT8 checksum.
+
+ @param[in] Buffer Pointer to buffer to checksum
+ @param[in] Size Number of bytes to checksum
+ @param[in] ChecksumOffset Offset to place the checksum result in
+
+ @retval EFI_SUCCESS The function completed successfully.
+
+**/
+EFI_STATUS
+AcpiPlatformChecksum (
+ IN VOID *Buffer,
+ IN UINTN Size,
+ IN UINTN ChecksumOffset
+ );
+
+/**
+ This function invokes ACPI notification.
+
+ @param[in] AcpiTableInstance Instance to AcpiTable
+ @param[in] Version Version(s) to set.
+ @param[in] Handle Handle of the table.
+**/
+VOID
+SdtNotifyAcpiList (
+ IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
+ IN EFI_ACPI_TABLE_VERSION Version,
+ IN UINTN Handle
+ );
+
+/**
+ This function initializes AcpiSdt protocol in ACPI table instance.
+
+ @param[in] AcpiTableInstance Instance to construct
+**/
+VOID
+SdtAcpiTableAcpiSdtConstructor (
+ IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance
+ );
+
+/**
+ Returns a requested ACPI table.
+
+ The following structures are not considered elements in the list of
+ ACPI tables:
+ - Root System Description Pointer (RSD_PTR)
+ - Root System Description Table (RSDT)
+ - Extended System Description Table (XSDT)
+ Version is updated with a bit map containing all the versions of ACPI of which the table is a
+ member. For tables installed via the EFI_ACPI_TABLE_PROTOCOL.InstallAcpiTable() interface,
+ the function returns the value of EFI_ACPI_STD_PROTOCOL.AcpiVersion.
+
+ @param[in] AcpiTableInstance ACPI table Instance.
+ @param[in] Index The zero-based index of the table to retrieve.
+ @param[out] Table Pointer for returning the table buffer.
+ @param[out] Version On return, updated with the ACPI versions to which this table belongs. Type
+ EFI_ACPI_TABLE_VERSION is defined in "Related Definitions" in the
+ EFI_ACPI_SDT_PROTOCOL.
+ @param[out] TableKey On return, points to the table key for the specified ACPI system definition table.
+ This is identical to the table key used in the EFI_ACPI_TABLE_PROTOCOL.
+ The TableKey can be passed to EFI_ACPI_TABLE_PROTOCOL.UninstallAcpiTable()
+ to uninstall the table.
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_NOT_FOUND The requested index is too large and a table was not found.
+**/
+EFI_STATUS
+SdtGetAcpiTable (
+ IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
+ IN UINTN Index,
+ OUT EFI_ACPI_SDT_HEADER **Table,
+ OUT EFI_ACPI_TABLE_VERSION *Version,
+ OUT UINTN *TableKey
+ );
+
+//
+// export PrivateData symbol, because we need that in AcpiSdtProtol implementation
+//
+extern EFI_HANDLE mHandle;
+extern EFI_ACPI_TABLE_INSTANCE *mPrivateData;
+
+#endif
diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
index be498a56cf..7927ba42de 100644
--- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
+++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
@@ -1,81 +1,81 @@
-## @file
-# ACPI Table Protocol Driver
-#
-# This driver initializes ACPI tables (Rsdp, Rsdt and Xsdt) and produces UEFI/PI
-# services to install/uninstall/manage ACPI tables.
-#
-# Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>
-# Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
-# SPDX-License-Identifier: BSD-2-Clause-Patent
-#
-##
-
-[Defines]
- INF_VERSION = 0x00010005
- BASE_NAME = AcpiTableDxe
- MODULE_UNI_FILE = AcpiTableDxe.uni
- FILE_GUID = 9622E42C-8E38-4a08-9E8F-54F784652F6B
- MODULE_TYPE = DXE_DRIVER
- VERSION_STRING = 1.0
-
- ENTRY_POINT = InitializeAcpiTableDxe
-
-#
-# The following information is for reference only and not required by the build tools.
-#
-# VALID_ARCHITECTURES = IA32 X64 EBC
-#
-
-[Sources]
- AcpiTableProtocol.c
- AcpiTable.h
- AcpiTable.c
- AcpiSdt.h
- AcpiSdt.c
- Aml.c
- AmlString.c
- AmlOption.c
- AmlChild.c
- AmlNamespace.c
-
-[Packages]
- MdePkg/MdePkg.dec
- MdeModulePkg/MdeModulePkg.dec
-
-[LibraryClasses]
- UefiBootServicesTableLib
- MemoryAllocationLib
- UefiDriverEntryPoint
- BaseMemoryLib
- UefiLib
- DebugLib
- BaseLib
- PcdLib
- HobLib
-
-[Guids]
- gEfiAcpi10TableGuid ## PRODUCES ## SystemTable
- gEfiAcpiTableGuid ## PRODUCES ## SystemTable
- gUniversalPayloadAcpiTableGuid ## SOMETIMES_CONSUMES ## HOB
-
-[FeaturePcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdInstallAcpiSdtProtocol ## CONSUMES
-
-[Pcd]
- gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemId ## CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemTableId ## CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemRevision ## CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorId ## CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorRevision ## CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiExposedTableVersions ## CONSUMES
- gEfiMdeModulePkgTokenSpaceGuid.PcdNoACPIReclaimMemory ## CONSUMES
-
-[Protocols]
- gEfiAcpiTableProtocolGuid ## PRODUCES
- gEfiAcpiSdtProtocolGuid ## PRODUCES
-
-[Depex]
- TRUE
-
-[UserExtensions.TianoCore."ExtraFiles"]
- AcpiTableDxeExtra.uni
+## @file
+# ACPI Table Protocol Driver
+#
+# This driver initializes ACPI tables (Rsdp, Rsdt and Xsdt) and produces UEFI/PI
+# services to install/uninstall/manage ACPI tables.
+#
+# Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>
+# Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = AcpiTableDxe
+ MODULE_UNI_FILE = AcpiTableDxe.uni
+ FILE_GUID = 9622E42C-8E38-4a08-9E8F-54F784652F6B
+ MODULE_TYPE = DXE_DRIVER
+ VERSION_STRING = 1.0
+
+ ENTRY_POINT = InitializeAcpiTableDxe
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64 EBC
+#
+
+[Sources]
+ AcpiTableProtocol.c
+ AcpiTable.h
+ AcpiTable.c
+ AcpiSdt.h
+ AcpiSdt.c
+ Aml.c
+ AmlString.c
+ AmlOption.c
+ AmlChild.c
+ AmlNamespace.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+ UefiBootServicesTableLib
+ MemoryAllocationLib
+ UefiDriverEntryPoint
+ BaseMemoryLib
+ UefiLib
+ DebugLib
+ BaseLib
+ PcdLib
+ HobLib
+
+[Guids]
+ gEfiAcpi10TableGuid ## PRODUCES ## SystemTable
+ gEfiAcpiTableGuid ## PRODUCES ## SystemTable
+ gUniversalPayloadAcpiTableGuid ## SOMETIMES_CONSUMES ## HOB
+
+[FeaturePcd]
+ gEfiMdeModulePkgTokenSpaceGuid.PcdInstallAcpiSdtProtocol ## CONSUMES
+
+[Pcd]
+ gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemId ## CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemTableId ## CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultOemRevision ## CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorId ## CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiDefaultCreatorRevision ## CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdAcpiExposedTableVersions ## CONSUMES
+ gEfiMdeModulePkgTokenSpaceGuid.PcdNoACPIReclaimMemory ## CONSUMES
+
+[Protocols]
+ gEfiAcpiTableProtocolGuid ## PRODUCES
+ gEfiAcpiSdtProtocolGuid ## PRODUCES
+
+[Depex]
+ TRUE
+
+[UserExtensions.TianoCore."ExtraFiles"]
+ AcpiTableDxeExtra.uni
diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.uni b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.uni
index 7afe9bd4df..e9e56f9b41 100644
--- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.uni
+++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.uni
@@ -1,14 +1,14 @@
-// /** @file
-// AcpiTableDxe Module Localized Abstract and Description Content
-//
-// Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>
-//
-// SPDX-License-Identifier: BSD-2-Clause-Patent
-//
-// **/
-
-
-#string STR_MODULE_ABSTRACT #language en-US "ACPI Table Protocol Driver"
-
-#string STR_MODULE_DESCRIPTION #language en-US "This driver initializes ACPI tables (Rsdp, Rsdt and Xsdt) and produces UEFI/PI services to install/uninstall/manage ACPI tables."
-
+// /** @file
+// AcpiTableDxe Module Localized Abstract and Description Content
+//
+// Copyright (c) 2012 - 2018, Intel Corporation. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+
+#string STR_MODULE_ABSTRACT #language en-US "ACPI Table Protocol Driver"
+
+#string STR_MODULE_DESCRIPTION #language en-US "This driver initializes ACPI tables (Rsdp, Rsdt and Xsdt) and produces UEFI/PI services to install/uninstall/manage ACPI tables."
+
diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxeExtra.uni b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxeExtra.uni
index b64bc2b250..2ec5508187 100644
--- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxeExtra.uni
+++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxeExtra.uni
@@ -1,14 +1,14 @@
-// /** @file
-// AcpiTableDxe Localized Strings and Content
-//
-// Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
-//
-// SPDX-License-Identifier: BSD-2-Clause-Patent
-//
-// **/
-
-#string STR_PROPERTIES_MODULE_NAME
-#language en-US
-"ACPI Table DXE Driver"
-
-
+// /** @file
+// AcpiTableDxe Localized Strings and Content
+//
+// Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved.<BR>
+//
+// SPDX-License-Identifier: BSD-2-Clause-Patent
+//
+// **/
+
+#string STR_PROPERTIES_MODULE_NAME
+#language en-US
+"ACPI Table DXE Driver"
+
+
diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c
index 5f8d20a7e9..71ec2e4ab0 100644
--- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c
+++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c
@@ -1,2200 +1,2200 @@
-/** @file
- ACPI Table Protocol Implementation
-
- Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>
- Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-//
-// Includes
-//
-#include "AcpiTable.h"
-//
-// The maximum number of tables that pre-allocated.
-//
-UINTN mEfiAcpiMaxNumTables = EFI_ACPI_MAX_NUM_TABLES;
-
-//
-// Allocation strategy to use for AllocatePages ().
-// Runtime value depends on PcdExposedAcpiTableVersions.
-//
-STATIC EFI_ALLOCATE_TYPE mAcpiTableAllocType;
-
-/**
- This function adds an ACPI table to the table list. It will detect FACS and
- allocate the correct type of memory and properly align the table.
-
- @param AcpiTableInstance Instance of the protocol.
- @param Table Table to add.
- @param Checksum Does the table require checksumming.
- @param Version The version of the list to add the table to.
- @param IsFromHob True, if add Apci Table from Hob List.
- @param Handle Pointer for returning the handle.
-
- @return EFI_SUCCESS The function completed successfully.
- @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
- @return EFI_ABORTED The table is a duplicate of a table that is required
- to be unique.
-
-**/
-EFI_STATUS
-AddTableToList (
- IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
- IN VOID *Table,
- IN BOOLEAN Checksum,
- IN EFI_ACPI_TABLE_VERSION Version,
- IN BOOLEAN IsFromHob,
- OUT UINTN *Handle
- );
-
-/**
- This function finds and removes the table specified by the handle.
-
- @param AcpiTableInstance Instance of the protocol.
- @param Version Bitmask of which versions to remove.
- @param Handle Table to remove.
-
- @return EFI_SUCCESS The function completed successfully.
- @return EFI_ABORTED An error occurred.
- @return EFI_NOT_FOUND Handle not found in table list.
-
-**/
-EFI_STATUS
-RemoveTableFromList (
- IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
- IN EFI_ACPI_TABLE_VERSION Version,
- IN UINTN Handle
- );
-
-/**
- This function calculates and updates an UINT8 checksum.
-
- @param Buffer Pointer to buffer to checksum
- @param Size Number of bytes to checksum
- @param ChecksumOffset Offset to place the checksum result in
-
- @return EFI_SUCCESS The function completed successfully.
-**/
-EFI_STATUS
-AcpiPlatformChecksum (
- IN VOID *Buffer,
- IN UINTN Size,
- IN UINTN ChecksumOffset
- );
-
-/**
- Checksum all versions of the common tables, RSDP, RSDT, XSDT.
-
- @param AcpiTableInstance Protocol instance private data.
-
- @return EFI_SUCCESS The function completed successfully.
-
-**/
-EFI_STATUS
-ChecksumCommonTables (
- IN OUT EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance
- );
-
-//
-// Protocol function implementations.
-//
-
-/**
- This function publishes the specified versions of the ACPI tables by
- installing EFI configuration table entries for them. Any combination of
- table versions can be published.
-
- @param AcpiTableInstance Instance of the protocol.
- @param Version Version(s) to publish.
-
- @return EFI_SUCCESS The function completed successfully.
- @return EFI_ABORTED The function could not complete successfully.
-
-**/
-EFI_STATUS
-EFIAPI
-PublishTables (
- IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
- IN EFI_ACPI_TABLE_VERSION Version
- )
-{
- EFI_STATUS Status;
- UINT32 *CurrentRsdtEntry;
- VOID *CurrentXsdtEntry;
- UINT64 Buffer64;
-
- //
- // Reorder tables as some operating systems don't seem to find the
- // FADT correctly if it is not in the first few entries
- //
-
- //
- // Add FADT as the first entry
- //
- if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- CurrentRsdtEntry = (UINT32 *)((UINT8 *)AcpiTableInstance->Rsdt1 + sizeof (EFI_ACPI_DESCRIPTION_HEADER));
- *CurrentRsdtEntry = (UINT32)(UINTN)AcpiTableInstance->Fadt1;
-
- CurrentRsdtEntry = (UINT32 *)((UINT8 *)AcpiTableInstance->Rsdt3 + sizeof (EFI_ACPI_DESCRIPTION_HEADER));
- *CurrentRsdtEntry = (UINT32)(UINTN)AcpiTableInstance->Fadt3;
- }
-
- if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
- CurrentXsdtEntry = (VOID *)((UINT8 *)AcpiTableInstance->Xsdt + sizeof (EFI_ACPI_DESCRIPTION_HEADER));
- //
- // Add entry to XSDT, XSDT expects 64 bit pointers, but
- // the table pointers in XSDT are not aligned on 8 byte boundary.
- //
- Buffer64 = (UINT64)(UINTN)AcpiTableInstance->Fadt3;
- CopyMem (
- CurrentXsdtEntry,
- &Buffer64,
- sizeof (UINT64)
- );
- }
-
- //
- // Do checksum again because Dsdt/Xsdt is updated.
- //
- ChecksumCommonTables (AcpiTableInstance);
-
- //
- // Add the RSD_PTR to the system table and store that we have installed the
- // tables.
- //
- if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- Status = gBS->InstallConfigurationTable (&gEfiAcpi10TableGuid, AcpiTableInstance->Rsdp1);
- if (EFI_ERROR (Status)) {
- return EFI_ABORTED;
- }
- }
-
- if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
- Status = gBS->InstallConfigurationTable (&gEfiAcpiTableGuid, AcpiTableInstance->Rsdp3);
- if (EFI_ERROR (Status)) {
- return EFI_ABORTED;
- }
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Installs an ACPI table into the RSDT/XSDT.
- Note that the ACPI table should be checksumed before installing it.
- Otherwise it will assert.
-
- @param This Protocol instance pointer.
- @param AcpiTableBuffer A pointer to a buffer containing the ACPI table to be installed.
- @param AcpiTableBufferSize Specifies the size, in bytes, of the AcpiTableBuffer buffer.
- @param TableKey Reurns a key to refer to the ACPI table.
-
- @return EFI_SUCCESS The table was successfully inserted.
- @return EFI_INVALID_PARAMETER Either AcpiTableBuffer is NULL, TableKey is NULL, or AcpiTableBufferSize
- and the size field embedded in the ACPI table pointed to by AcpiTableBuffer
- are not in sync.
- @return EFI_OUT_OF_RESOURCES Insufficient resources exist to complete the request.
- @retval EFI_ACCESS_DENIED The table signature matches a table already
- present in the system and platform policy
- does not allow duplicate tables of this type.
-
-**/
-EFI_STATUS
-EFIAPI
-InstallAcpiTable (
- IN EFI_ACPI_TABLE_PROTOCOL *This,
- IN VOID *AcpiTableBuffer,
- IN UINTN AcpiTableBufferSize,
- OUT UINTN *TableKey
- )
-{
- EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance;
- EFI_STATUS Status;
- VOID *AcpiTableBufferConst;
- EFI_ACPI_TABLE_VERSION Version;
-
- //
- // Check for invalid input parameters
- //
- if ( (AcpiTableBuffer == NULL) || (TableKey == NULL)
- || (((EFI_ACPI_DESCRIPTION_HEADER *)AcpiTableBuffer)->Length != AcpiTableBufferSize))
- {
- return EFI_INVALID_PARAMETER;
- }
-
- Version = PcdGet32 (PcdAcpiExposedTableVersions);
-
- //
- // Get the instance of the ACPI table protocol
- //
- AcpiTableInstance = EFI_ACPI_TABLE_INSTANCE_FROM_THIS (This);
-
- //
- // Install the ACPI table
- //
- AcpiTableBufferConst = AllocateCopyPool (AcpiTableBufferSize, AcpiTableBuffer);
- *TableKey = 0;
- Status = AddTableToList (
- AcpiTableInstance,
- AcpiTableBufferConst,
- TRUE,
- Version,
- FALSE,
- TableKey
- );
- if (!EFI_ERROR (Status)) {
- Status = PublishTables (
- AcpiTableInstance,
- Version
- );
- }
-
- FreePool (AcpiTableBufferConst);
-
- //
- // Add a new table successfully, notify registed callback
- //
- if (FeaturePcdGet (PcdInstallAcpiSdtProtocol)) {
- if (!EFI_ERROR (Status)) {
- SdtNotifyAcpiList (
- AcpiTableInstance,
- Version,
- *TableKey
- );
- }
- }
-
- return Status;
-}
-
-/**
- Removes an ACPI table from the RSDT/XSDT.
-
- @param This Protocol instance pointer.
- @param TableKey Specifies the table to uninstall. The key was returned from InstallAcpiTable().
-
- @return EFI_SUCCESS The table was successfully uninstalled.
- @return EFI_NOT_FOUND TableKey does not refer to a valid key for a table entry.
-
-**/
-EFI_STATUS
-EFIAPI
-UninstallAcpiTable (
- IN EFI_ACPI_TABLE_PROTOCOL *This,
- IN UINTN TableKey
- )
-{
- EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance;
- EFI_STATUS Status;
- EFI_ACPI_TABLE_VERSION Version;
-
- //
- // Get the instance of the ACPI table protocol
- //
- AcpiTableInstance = EFI_ACPI_TABLE_INSTANCE_FROM_THIS (This);
-
- Version = PcdGet32 (PcdAcpiExposedTableVersions);
-
- //
- // Uninstall the ACPI table
- //
- Status = RemoveTableFromList (
- AcpiTableInstance,
- Version,
- TableKey
- );
- if (!EFI_ERROR (Status)) {
- Status = PublishTables (
- AcpiTableInstance,
- Version
- );
- }
-
- if (EFI_ERROR (Status)) {
- return EFI_NOT_FOUND;
- } else {
- return EFI_SUCCESS;
- }
-}
-
-/**
- If the number of APCI tables exceeds the preallocated max table number, enlarge the table buffer.
-
- @param AcpiTableInstance ACPI table protocol instance data structure.
-
- @return EFI_SUCCESS reallocate the table beffer successfully.
- @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
-
-**/
-EFI_STATUS
-ReallocateAcpiTableBuffer (
- IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance
- )
-{
- UINTN NewMaxTableNumber;
- UINTN TotalSize;
- UINT8 *Pointer;
- EFI_PHYSICAL_ADDRESS PageAddress;
- EFI_ACPI_TABLE_INSTANCE TempPrivateData;
- EFI_STATUS Status;
- UINT64 CurrentData;
- EFI_MEMORY_TYPE AcpiAllocateMemoryType;
-
- CopyMem (&TempPrivateData, AcpiTableInstance, sizeof (EFI_ACPI_TABLE_INSTANCE));
- //
- // Enlarge the max table number from mEfiAcpiMaxNumTables to mEfiAcpiMaxNumTables + EFI_ACPI_MAX_NUM_TABLES
- //
- NewMaxTableNumber = mEfiAcpiMaxNumTables + EFI_ACPI_MAX_NUM_TABLES;
- //
- // Create RSDT, XSDT structures and allocate buffers.
- //
- TotalSize = sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 2.0/3.0 XSDT
- NewMaxTableNumber * sizeof (UINT64);
-
- if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- TotalSize += sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 1.0 RSDT
- NewMaxTableNumber * sizeof (UINT32) +
- sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 2.0/3.0 RSDT
- NewMaxTableNumber * sizeof (UINT32);
- }
-
- if (PcdGetBool (PcdNoACPIReclaimMemory)) {
- AcpiAllocateMemoryType = EfiACPIMemoryNVS;
- } else {
- AcpiAllocateMemoryType = EfiACPIReclaimMemory;
- }
-
- if (mAcpiTableAllocType != AllocateAnyPages) {
- //
- // Allocate memory in the lower 32 bit of address range for
- // compatibility with ACPI 1.0 OS.
- //
- // This is done because ACPI 1.0 pointers are 32 bit values.
- // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
- // There is no architectural reason these should be below 4GB, it is purely
- // for convenience of implementation that we force memory below 4GB.
- //
- PageAddress = 0xFFFFFFFF;
- Status = gBS->AllocatePages (
- mAcpiTableAllocType,
- AcpiAllocateMemoryType,
- EFI_SIZE_TO_PAGES (TotalSize),
- &PageAddress
- );
- } else {
- Status = gBS->AllocatePool (
- AcpiAllocateMemoryType,
- TotalSize,
- (VOID **)&Pointer
- );
- }
-
- if (EFI_ERROR (Status)) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- if (mAcpiTableAllocType != AllocateAnyPages) {
- Pointer = (UINT8 *)(UINTN)PageAddress;
- }
-
- ZeroMem (Pointer, TotalSize);
-
- AcpiTableInstance->Rsdt1 = (EFI_ACPI_DESCRIPTION_HEADER *)Pointer;
- if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- Pointer += (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + NewMaxTableNumber * sizeof (UINT32));
- AcpiTableInstance->Rsdt3 = (EFI_ACPI_DESCRIPTION_HEADER *)Pointer;
- Pointer += (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + NewMaxTableNumber * sizeof (UINT32));
- }
-
- AcpiTableInstance->Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *)Pointer;
-
- //
- // Update RSDP to point to the new Rsdt and Xsdt address.
- //
- if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- AcpiTableInstance->Rsdp1->RsdtAddress = (UINT32)(UINTN)AcpiTableInstance->Rsdt1;
- AcpiTableInstance->Rsdp3->RsdtAddress = (UINT32)(UINTN)AcpiTableInstance->Rsdt3;
- }
-
- CurrentData = (UINT64)(UINTN)AcpiTableInstance->Xsdt;
- CopyMem (&AcpiTableInstance->Rsdp3->XsdtAddress, &CurrentData, sizeof (UINT64));
-
- //
- // copy the original Rsdt1, Rsdt3 and Xsdt structure to new buffer
- //
- if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- CopyMem (AcpiTableInstance->Rsdt1, TempPrivateData.Rsdt1, (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + mEfiAcpiMaxNumTables * sizeof (UINT32)));
- CopyMem (AcpiTableInstance->Rsdt3, TempPrivateData.Rsdt3, (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + mEfiAcpiMaxNumTables * sizeof (UINT32)));
- }
-
- CopyMem (AcpiTableInstance->Xsdt, TempPrivateData.Xsdt, (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + mEfiAcpiMaxNumTables * sizeof (UINT64)));
-
- if (mAcpiTableAllocType != AllocateAnyPages) {
- //
- // Calculate orignal ACPI table buffer size
- //
- TotalSize = sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 2.0/3.0 XSDT
- mEfiAcpiMaxNumTables * sizeof (UINT64);
-
- if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- TotalSize += sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 1.0 RSDT
- mEfiAcpiMaxNumTables * sizeof (UINT32) +
- sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 2.0/3.0 RSDT
- mEfiAcpiMaxNumTables * sizeof (UINT32);
- }
-
- gBS->FreePages (
- (EFI_PHYSICAL_ADDRESS)(UINTN)TempPrivateData.Rsdt1,
- EFI_SIZE_TO_PAGES (TotalSize)
- );
- } else {
- gBS->FreePool (TempPrivateData.Rsdt1);
- }
-
- //
- // Update the Max ACPI table number
- //
- mEfiAcpiMaxNumTables = NewMaxTableNumber;
- return EFI_SUCCESS;
-}
-
-/**
- Free the memory associated with the provided EFI_ACPI_TABLE_LIST instance.
-
- @param TableEntry EFI_ACPI_TABLE_LIST instance pointer
-
-**/
-STATIC
-VOID
-FreeTableMemory (
- EFI_ACPI_TABLE_LIST *TableEntry
- )
-{
- if (TableEntry->PoolAllocation) {
- gBS->FreePool (TableEntry->Table);
- } else {
- gBS->FreePages (
- (EFI_PHYSICAL_ADDRESS)(UINTN)TableEntry->Table,
- EFI_SIZE_TO_PAGES (TableEntry->TableSize)
- );
- }
-}
-
-/**
- This function adds an ACPI table to the table list. It will detect FACS and
- allocate the correct type of memory and properly align the table.
-
- @param AcpiTableInstance Instance of the protocol.
- @param Table Table to add.
- @param Checksum Does the table require checksumming.
- @param Version The version of the list to add the table to.
- @param IsFromHob True, if add Apci Table from Hob List.
- @param Handle Pointer for returning the handle.
-
- @return EFI_SUCCESS The function completed successfully.
- @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
- @retval EFI_ACCESS_DENIED The table signature matches a table already
- present in the system and platform policy
- does not allow duplicate tables of this type.
-
-**/
-EFI_STATUS
-AddTableToList (
- IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
- IN VOID *Table,
- IN BOOLEAN Checksum,
- IN EFI_ACPI_TABLE_VERSION Version,
- IN BOOLEAN IsFromHob,
- OUT UINTN *Handle
- )
-{
- EFI_STATUS Status;
- EFI_ACPI_TABLE_LIST *CurrentTableList;
- UINT32 CurrentTableSignature;
- UINT32 CurrentTableSize;
- UINT32 *CurrentRsdtEntry;
- VOID *CurrentXsdtEntry;
- EFI_PHYSICAL_ADDRESS AllocPhysAddress;
- UINT64 Buffer64;
- BOOLEAN AddToRsdt;
- EFI_MEMORY_TYPE AcpiAllocateMemoryType;
-
- //
- // Check for invalid input parameters
- //
- ASSERT (AcpiTableInstance);
- ASSERT (Table);
- ASSERT (Handle);
-
- //
- // Init locals
- //
- AddToRsdt = TRUE;
-
- //
- // Create a new list entry
- //
- CurrentTableList = AllocatePool (sizeof (EFI_ACPI_TABLE_LIST));
- ASSERT (CurrentTableList);
-
- //
- // Determine table type and size
- //
- CurrentTableSignature = ((EFI_ACPI_COMMON_HEADER *)Table)->Signature;
- CurrentTableSize = ((EFI_ACPI_COMMON_HEADER *)Table)->Length;
-
- //
- // Allocate a buffer for the table. All tables are allocated in the lower 32 bits of address space
- // for backwards compatibility with ACPI 1.0 OS.
- //
- // This is done because ACPI 1.0 pointers are 32 bit values.
- // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
- // There is no architectural reason these should be below 4GB, it is purely
- // for convenience of implementation that we force memory below 4GB.
- //
- AllocPhysAddress = 0xFFFFFFFF;
- CurrentTableList->TableSize = CurrentTableSize;
- CurrentTableList->PoolAllocation = FALSE;
-
- if (PcdGetBool (PcdNoACPIReclaimMemory)) {
- AcpiAllocateMemoryType = EfiACPIMemoryNVS;
- } else {
- AcpiAllocateMemoryType = EfiACPIReclaimMemory;
- }
-
- //
- // Allocation memory type depends on the type of the table
- //
- if ((CurrentTableSignature == EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE) ||
- (CurrentTableSignature == EFI_ACPI_4_0_UEFI_ACPI_DATA_TABLE_SIGNATURE))
- {
- //
- // Allocate memory for the FACS. This structure must be aligned
- // on a 64 byte boundary and must be ACPI NVS memory.
- // Using AllocatePages should ensure that it is always aligned.
- // Do not change signature for new ACPI version because they are same.
- //
- // UEFI table also need to be in ACPI NVS memory, because some data field
- // could be updated by OS present agent. For example, BufferPtrAddress in
- // SMM communication ACPI table.
- //
- ASSERT ((EFI_PAGE_SIZE % 64) == 0);
- if (IsFromHob) {
- AllocPhysAddress = (UINTN)Table;
- Status = EFI_SUCCESS;
- } else {
- Status = gBS->AllocatePages (
- AllocateMaxAddress,
- EfiACPIMemoryNVS,
- EFI_SIZE_TO_PAGES (CurrentTableList->TableSize),
- &AllocPhysAddress
- );
- }
- } else if (mAcpiTableAllocType == AllocateAnyPages) {
- //
- // If there is no allocation limit, there is also no need to use page
- // based allocations for ACPI tables, which may be wasteful on platforms
- // such as AArch64 that allocate multiples of 64 KB
- //
- Status = gBS->AllocatePool (
- AcpiAllocateMemoryType,
- CurrentTableList->TableSize,
- (VOID **)&CurrentTableList->Table
- );
- CurrentTableList->PoolAllocation = TRUE;
- } else {
- //
- // All other tables are ACPI reclaim memory, no alignment requirements.
- //
- Status = gBS->AllocatePages (
- mAcpiTableAllocType,
- AcpiAllocateMemoryType,
- EFI_SIZE_TO_PAGES (CurrentTableList->TableSize),
- &AllocPhysAddress
- );
- CurrentTableList->Table = (EFI_ACPI_COMMON_HEADER *)(UINTN)AllocPhysAddress;
- }
-
- //
- // Check return value from memory alloc.
- //
- if (EFI_ERROR (Status)) {
- gBS->FreePool (CurrentTableList);
- return EFI_OUT_OF_RESOURCES;
- }
-
- if (!CurrentTableList->PoolAllocation) {
- CurrentTableList->Table = (EFI_ACPI_COMMON_HEADER *)(UINTN)AllocPhysAddress;
- }
-
- //
- // Initialize the table contents
- //
- CurrentTableList->Signature = EFI_ACPI_TABLE_LIST_SIGNATURE;
- CopyMem (CurrentTableList->Table, Table, CurrentTableSize);
- CurrentTableList->Handle = AcpiTableInstance->CurrentHandle++;
- *Handle = CurrentTableList->Handle;
- CurrentTableList->Version = Version;
-
- //
- // Update internal pointers if this is a required table. If it is a required
- // table and a table of that type already exists, return an error.
- //
- // Calculate the checksum if the table is not FACS.
- //
- switch (CurrentTableSignature) {
- case EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE:
- //
- // We don't add the FADT in the standard way because some
- // OS expect the FADT to be early in the table list.
- // So we always add it as the first element in the list.
- //
- AddToRsdt = FALSE;
-
- //
- // Check that the table has not been previously added.
- //
- if ((((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) && (AcpiTableInstance->Fadt1 != NULL)) ||
- (((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) && (AcpiTableInstance->Fadt3 != NULL))
- )
- {
- FreeTableMemory (CurrentTableList);
- gBS->FreePool (CurrentTableList);
- return EFI_ACCESS_DENIED;
- }
-
- //
- // Add the table to the appropriate table version
- //
- if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- //
- // Save a pointer to the table
- //
- AcpiTableInstance->Fadt1 = (EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE *)CurrentTableList->Table;
-
- //
- // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
- //
- AcpiTableInstance->Fadt1->FirmwareCtrl = (UINT32)(UINTN)AcpiTableInstance->Facs1;
- AcpiTableInstance->Fadt1->Dsdt = (UINT32)(UINTN)AcpiTableInstance->Dsdt1;
-
- //
- // RSDP OEM information is updated to match the FADT OEM information
- //
- CopyMem (
- &AcpiTableInstance->Rsdp1->OemId,
- &AcpiTableInstance->Fadt1->Header.OemId,
- 6
- );
-
- //
- // RSDT OEM information is updated to match the FADT OEM information.
- //
- CopyMem (
- &AcpiTableInstance->Rsdt1->OemId,
- &AcpiTableInstance->Fadt1->Header.OemId,
- 6
- );
-
- CopyMem (
- &AcpiTableInstance->Rsdt1->OemTableId,
- &AcpiTableInstance->Fadt1->Header.OemTableId,
- sizeof (UINT64)
- );
- AcpiTableInstance->Rsdt1->OemRevision = AcpiTableInstance->Fadt1->Header.OemRevision;
- }
-
- if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
- //
- // Save a pointer to the table
- //
- AcpiTableInstance->Fadt3 = (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)CurrentTableList->Table;
-
- //
- // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
- // Note: If the FIRMWARE_CTRL is non-zero, then X_FIRMWARE_CTRL must be zero, and
- // vice-versa.
- //
- if ((UINT64)(UINTN)AcpiTableInstance->Facs3 < BASE_4GB) {
- AcpiTableInstance->Fadt3->FirmwareCtrl = (UINT32)(UINTN)AcpiTableInstance->Facs3;
- ZeroMem (&AcpiTableInstance->Fadt3->XFirmwareCtrl, sizeof (UINT64));
- } else {
- Buffer64 = (UINT64)(UINTN)AcpiTableInstance->Facs3;
- CopyMem (
- &AcpiTableInstance->Fadt3->XFirmwareCtrl,
- &Buffer64,
- sizeof (UINT64)
- );
- AcpiTableInstance->Fadt3->FirmwareCtrl = 0;
- }
-
- if ((UINT64)(UINTN)AcpiTableInstance->Dsdt3 < BASE_4GB) {
- AcpiTableInstance->Fadt3->Dsdt = (UINT32)(UINTN)AcpiTableInstance->Dsdt3;
- //
- // Comment block "the caller installs the tables in "DSDT, FADT" order"
- // The below comments are also in "the caller installs the tables in "FADT, DSDT" order" comment block.
- //
- // The ACPI specification, up to and including revision 5.1 Errata A,
- // allows the DSDT and X_DSDT fields to be both set in the FADT.
- // (Obviously, this only makes sense if the DSDT address is representable in 4 bytes.)
- // Starting with 5.1 Errata B, specifically for Mantis 1393 <https://mantis.uefi.org/mantis/view.php?id=1393>,
- // the spec requires at most one of DSDT and X_DSDT fields to be set to a nonzero value,
- // but strangely an exception is 6.0 that has no this requirement.
- //
- // Here we do not make the DSDT and X_DSDT fields mutual exclusion conditionally
- // by checking FADT revision, but always set both DSDT and X_DSDT fields in the FADT
- // to have better compatibility as some OS may have assumption to only consume X_DSDT
- // field even the DSDT address is < 4G.
- //
- Buffer64 = AcpiTableInstance->Fadt3->Dsdt;
- } else {
- AcpiTableInstance->Fadt3->Dsdt = 0;
- Buffer64 = (UINT64)(UINTN)AcpiTableInstance->Dsdt3;
- }
-
- CopyMem (&AcpiTableInstance->Fadt3->XDsdt, &Buffer64, sizeof (UINT64));
-
- //
- // RSDP OEM information is updated to match the FADT OEM information
- //
- CopyMem (
- &AcpiTableInstance->Rsdp3->OemId,
- &AcpiTableInstance->Fadt3->Header.OemId,
- 6
- );
-
- if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- //
- // RSDT OEM information is updated to match FADT OEM information.
- //
- CopyMem (
- &AcpiTableInstance->Rsdt3->OemId,
- &AcpiTableInstance->Fadt3->Header.OemId,
- 6
- );
- CopyMem (
- &AcpiTableInstance->Rsdt3->OemTableId,
- &AcpiTableInstance->Fadt3->Header.OemTableId,
- sizeof (UINT64)
- );
- AcpiTableInstance->Rsdt3->OemRevision = AcpiTableInstance->Fadt3->Header.OemRevision;
- }
-
- //
- // XSDT OEM information is updated to match FADT OEM information.
- //
- CopyMem (
- &AcpiTableInstance->Xsdt->OemId,
- &AcpiTableInstance->Fadt3->Header.OemId,
- 6
- );
- CopyMem (
- &AcpiTableInstance->Xsdt->OemTableId,
- &AcpiTableInstance->Fadt3->Header.OemTableId,
- sizeof (UINT64)
- );
- AcpiTableInstance->Xsdt->OemRevision = AcpiTableInstance->Fadt3->Header.OemRevision;
- }
-
- //
- // Checksum the table
- //
- if (Checksum) {
- AcpiPlatformChecksum (
- CurrentTableList->Table,
- CurrentTableList->Table->Length,
- OFFSET_OF (
- EFI_ACPI_DESCRIPTION_HEADER,
- Checksum
- )
- );
- }
-
- break;
-
- case EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE:
- //
- // Check that the table has not been previously added.
- //
- if ((((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) && (AcpiTableInstance->Facs1 != NULL)) ||
- (((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) && (AcpiTableInstance->Facs3 != NULL))
- )
- {
- FreeTableMemory (CurrentTableList);
- gBS->FreePool (CurrentTableList);
- return EFI_ACCESS_DENIED;
- }
-
- //
- // FACS is referenced by FADT and is not part of RSDT
- //
- AddToRsdt = FALSE;
-
- //
- // Add the table to the appropriate table version
- //
- if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- //
- // Save a pointer to the table
- //
- AcpiTableInstance->Facs1 = (EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *)CurrentTableList->Table;
-
- //
- // If FADT already exists, update table pointers.
- //
- if (AcpiTableInstance->Fadt1 != NULL) {
- AcpiTableInstance->Fadt1->FirmwareCtrl = (UINT32)(UINTN)AcpiTableInstance->Facs1;
-
- //
- // Checksum FADT table
- //
- AcpiPlatformChecksum (
- AcpiTableInstance->Fadt1,
- AcpiTableInstance->Fadt1->Header.Length,
- OFFSET_OF (
- EFI_ACPI_DESCRIPTION_HEADER,
- Checksum
- )
- );
- }
- }
-
- if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
- //
- // Save a pointer to the table
- //
- AcpiTableInstance->Facs3 = (EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *)CurrentTableList->Table;
-
- //
- // If FADT already exists, update table pointers.
- //
- if (AcpiTableInstance->Fadt3 != NULL) {
- //
- // Note: If the FIRMWARE_CTRL is non-zero, then X_FIRMWARE_CTRL must be zero, and
- // vice-versa.
- //
- if ((UINT64)(UINTN)AcpiTableInstance->Facs3 < BASE_4GB) {
- AcpiTableInstance->Fadt3->FirmwareCtrl = (UINT32)(UINTN)AcpiTableInstance->Facs3;
- ZeroMem (&AcpiTableInstance->Fadt3->XFirmwareCtrl, sizeof (UINT64));
- } else {
- Buffer64 = (UINT64)(UINTN)AcpiTableInstance->Facs3;
- CopyMem (
- &AcpiTableInstance->Fadt3->XFirmwareCtrl,
- &Buffer64,
- sizeof (UINT64)
- );
- AcpiTableInstance->Fadt3->FirmwareCtrl = 0;
- }
-
- //
- // Checksum FADT table
- //
- AcpiPlatformChecksum (
- AcpiTableInstance->Fadt3,
- AcpiTableInstance->Fadt3->Header.Length,
- OFFSET_OF (
- EFI_ACPI_DESCRIPTION_HEADER,
- Checksum
- )
- );
- }
- }
-
- break;
-
- case EFI_ACPI_1_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE:
- //
- // Check that the table has not been previously added.
- //
- if ((((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) && (AcpiTableInstance->Dsdt1 != NULL)) ||
- (((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) && (AcpiTableInstance->Dsdt3 != NULL))
- )
- {
- FreeTableMemory (CurrentTableList);
- gBS->FreePool (CurrentTableList);
- return EFI_ACCESS_DENIED;
- }
-
- //
- // DSDT is referenced by FADT and is not part of RSDT
- //
- AddToRsdt = FALSE;
-
- //
- // Add the table to the appropriate table version
- //
- if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- //
- // Save a pointer to the table
- //
- AcpiTableInstance->Dsdt1 = (EFI_ACPI_DESCRIPTION_HEADER *)CurrentTableList->Table;
-
- //
- // If FADT already exists, update table pointers.
- //
- if (AcpiTableInstance->Fadt1 != NULL) {
- AcpiTableInstance->Fadt1->Dsdt = (UINT32)(UINTN)AcpiTableInstance->Dsdt1;
-
- //
- // Checksum FADT table
- //
- AcpiPlatformChecksum (
- AcpiTableInstance->Fadt1,
- AcpiTableInstance->Fadt1->Header.Length,
- OFFSET_OF (
- EFI_ACPI_DESCRIPTION_HEADER,
- Checksum
- )
- );
- }
- }
-
- if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
- //
- // Save a pointer to the table
- //
- AcpiTableInstance->Dsdt3 = (EFI_ACPI_DESCRIPTION_HEADER *)CurrentTableList->Table;
-
- //
- // If FADT already exists, update table pointers.
- //
- if (AcpiTableInstance->Fadt3 != NULL) {
- if ((UINT64)(UINTN)AcpiTableInstance->Dsdt3 < BASE_4GB) {
- AcpiTableInstance->Fadt3->Dsdt = (UINT32)(UINTN)AcpiTableInstance->Dsdt3;
- //
- // Comment block "the caller installs the tables in "FADT, DSDT" order"
- // The below comments are also in "the caller installs the tables in "DSDT, FADT" order" comment block.
- //
- // The ACPI specification, up to and including revision 5.1 Errata A,
- // allows the DSDT and X_DSDT fields to be both set in the FADT.
- // (Obviously, this only makes sense if the DSDT address is representable in 4 bytes.)
- // Starting with 5.1 Errata B, specifically for Mantis 1393 <https://mantis.uefi.org/mantis/view.php?id=1393>,
- // the spec requires at most one of DSDT and X_DSDT fields to be set to a nonzero value,
- // but strangely an exception is 6.0 that has no this requirement.
- //
- // Here we do not make the DSDT and X_DSDT fields mutual exclusion conditionally
- // by checking FADT revision, but always set both DSDT and X_DSDT fields in the FADT
- // to have better compatibility as some OS may have assumption to only consume X_DSDT
- // field even the DSDT address is < 4G.
- //
- Buffer64 = AcpiTableInstance->Fadt3->Dsdt;
- } else {
- AcpiTableInstance->Fadt3->Dsdt = 0;
- Buffer64 = (UINT64)(UINTN)AcpiTableInstance->Dsdt3;
- }
-
- CopyMem (&AcpiTableInstance->Fadt3->XDsdt, &Buffer64, sizeof (UINT64));
-
- //
- // Checksum FADT table
- //
- AcpiPlatformChecksum (
- AcpiTableInstance->Fadt3,
- AcpiTableInstance->Fadt3->Header.Length,
- OFFSET_OF (
- EFI_ACPI_DESCRIPTION_HEADER,
- Checksum
- )
- );
- }
- }
-
- //
- // Checksum the table
- //
- if (Checksum) {
- AcpiPlatformChecksum (
- CurrentTableList->Table,
- CurrentTableList->Table->Length,
- OFFSET_OF (
- EFI_ACPI_DESCRIPTION_HEADER,
- Checksum
- )
- );
- }
-
- break;
-
- default:
- //
- // Checksum the table
- //
- if (Checksum) {
- AcpiPlatformChecksum (
- CurrentTableList->Table,
- CurrentTableList->Table->Length,
- OFFSET_OF (
- EFI_ACPI_DESCRIPTION_HEADER,
- Checksum
- )
- );
- }
-
- break;
- }
-
- //
- // Add the table to the current list of tables
- //
- InsertTailList (&AcpiTableInstance->TableList, &CurrentTableList->Link);
-
- //
- // Add the table to RSDT and/or XSDT table entry lists.
- //
- //
- // Add to ACPI 1.0b table tree
- //
- if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- if (AddToRsdt) {
- //
- // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
- //
- if (AcpiTableInstance->NumberOfTableEntries1 >= mEfiAcpiMaxNumTables) {
- Status = ReallocateAcpiTableBuffer (AcpiTableInstance);
- ASSERT_EFI_ERROR (Status);
- }
-
- CurrentRsdtEntry = (UINT32 *)
- (
- (UINT8 *)AcpiTableInstance->Rsdt1 +
- sizeof (EFI_ACPI_DESCRIPTION_HEADER) +
- AcpiTableInstance->NumberOfTableEntries1 *
- sizeof (UINT32)
- );
-
- //
- // Add entry to the RSDT unless its the FACS or DSDT
- //
- *CurrentRsdtEntry = (UINT32)(UINTN)CurrentTableList->Table;
-
- //
- // Update RSDT length
- //
- AcpiTableInstance->Rsdt1->Length = AcpiTableInstance->Rsdt1->Length + sizeof (UINT32);
-
- AcpiTableInstance->NumberOfTableEntries1++;
- }
- }
-
- //
- // Add to ACPI 2.0/3.0 table tree
- //
- if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
- if (AddToRsdt) {
- //
- // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
- //
- if (AcpiTableInstance->NumberOfTableEntries3 >= mEfiAcpiMaxNumTables) {
- Status = ReallocateAcpiTableBuffer (AcpiTableInstance);
- ASSERT_EFI_ERROR (Status);
- }
-
- if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- //
- // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
- // If it becomes necessary to maintain separate table lists, changes will be required.
- //
- CurrentRsdtEntry = (UINT32 *)
- (
- (UINT8 *)AcpiTableInstance->Rsdt3 +
- sizeof (EFI_ACPI_DESCRIPTION_HEADER) +
- AcpiTableInstance->NumberOfTableEntries3 *
- sizeof (UINT32)
- );
-
- //
- // Add entry to the RSDT
- //
- *CurrentRsdtEntry = (UINT32)(UINTN)CurrentTableList->Table;
-
- //
- // Update RSDT length
- //
- AcpiTableInstance->Rsdt3->Length = AcpiTableInstance->Rsdt3->Length + sizeof (UINT32);
- }
-
- //
- // This pointer must not be directly dereferenced as the XSDT entries may not
- // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
- //
- CurrentXsdtEntry = (VOID *)
- (
- (UINT8 *)AcpiTableInstance->Xsdt +
- sizeof (EFI_ACPI_DESCRIPTION_HEADER) +
- AcpiTableInstance->NumberOfTableEntries3 *
- sizeof (UINT64)
- );
-
- //
- // Add entry to XSDT, XSDT expects 64 bit pointers, but
- // the table pointers in XSDT are not aligned on 8 byte boundary.
- //
- Buffer64 = (UINT64)(UINTN)CurrentTableList->Table;
- CopyMem (
- CurrentXsdtEntry,
- &Buffer64,
- sizeof (UINT64)
- );
-
- //
- // Update length
- //
- AcpiTableInstance->Xsdt->Length = AcpiTableInstance->Xsdt->Length + sizeof (UINT64);
-
- AcpiTableInstance->NumberOfTableEntries3++;
- }
- }
-
- ChecksumCommonTables (AcpiTableInstance);
- return EFI_SUCCESS;
-}
-
-/**
- This function finds the table specified by the handle and returns a pointer to it.
- If the handle is not found, EFI_NOT_FOUND is returned and the contents of Table are
- undefined.
-
- @param Handle Table to find.
- @param TableList Table list to search
- @param Table Pointer to table found.
-
- @return EFI_SUCCESS The function completed successfully.
- @return EFI_NOT_FOUND No table found matching the handle specified.
-
-**/
-EFI_STATUS
-FindTableByHandle (
- IN UINTN Handle,
- IN LIST_ENTRY *TableList,
- OUT EFI_ACPI_TABLE_LIST **Table
- )
-{
- LIST_ENTRY *CurrentLink;
- EFI_ACPI_TABLE_LIST *CurrentTable;
-
- //
- // Check for invalid input parameters
- //
- ASSERT (Table);
-
- //
- // Find the table
- //
- CurrentLink = TableList->ForwardLink;
-
- while (CurrentLink != TableList) {
- CurrentTable = EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink);
- if (CurrentTable->Handle == Handle) {
- //
- // Found handle, so return this table.
- //
- *Table = CurrentTable;
- return EFI_SUCCESS;
- }
-
- CurrentLink = CurrentLink->ForwardLink;
- }
-
- //
- // Table not found
- //
- return EFI_NOT_FOUND;
-}
-
-/**
- This function removes a basic table from the RSDT and/or XSDT.
- For Acpi 1.0 tables, pass in the Rsdt.
- For Acpi 2.0 tables, pass in both Rsdt and Xsdt.
-
- @param Table Pointer to table found.
- @param NumberOfTableEntries Current number of table entries in the RSDT/XSDT
- @param Rsdt Pointer to the RSDT to remove from
- @param Xsdt Pointer to the Xsdt to remove from
-
- @return EFI_SUCCESS The function completed successfully.
- @return EFI_INVALID_PARAMETER The table was not found in both Rsdt and Xsdt.
-
-**/
-EFI_STATUS
-RemoveTableFromRsdt (
- IN OUT EFI_ACPI_TABLE_LIST *Table,
- IN OUT UINTN *NumberOfTableEntries,
- IN OUT EFI_ACPI_DESCRIPTION_HEADER *Rsdt OPTIONAL,
- IN OUT EFI_ACPI_DESCRIPTION_HEADER *Xsdt OPTIONAL
- )
-{
- UINT32 *CurrentRsdtEntry;
- VOID *CurrentXsdtEntry;
- UINT64 CurrentTablePointer64;
- UINTN Index;
-
- //
- // Check for invalid input parameters
- //
- ASSERT (Table);
- ASSERT (NumberOfTableEntries);
- ASSERT (Rsdt || Xsdt);
-
- //
- // Find the table entry in the RSDT and XSDT
- //
- for (Index = 0; Index < *NumberOfTableEntries; Index++) {
- //
- // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
- // If it becomes necessary to maintain separate table lists, changes will be required.
- //
- if (Rsdt != NULL) {
- CurrentRsdtEntry = (UINT32 *)((UINT8 *)Rsdt + sizeof (EFI_ACPI_DESCRIPTION_HEADER) + Index * sizeof (UINT32));
- } else {
- CurrentRsdtEntry = NULL;
- }
-
- if (Xsdt != NULL) {
- //
- // This pointer must not be directly dereferenced as the XSDT entries may not
- // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
- //
- CurrentXsdtEntry = (VOID *)((UINT8 *)Xsdt + sizeof (EFI_ACPI_DESCRIPTION_HEADER) + Index * sizeof (UINT64));
-
- //
- // Read the entry value out of the XSDT
- //
- CopyMem (&CurrentTablePointer64, CurrentXsdtEntry, sizeof (UINT64));
- } else {
- //
- // Initialize to NULL
- //
- CurrentXsdtEntry = 0;
- CurrentTablePointer64 = 0;
- }
-
- //
- // Check if we have found the corresponding entry in both RSDT and XSDT
- //
- if (((Rsdt == NULL) || (*CurrentRsdtEntry == (UINT32)(UINTN)Table->Table)) &&
- ((Xsdt == NULL) || (CurrentTablePointer64 == (UINT64)(UINTN)Table->Table))
- )
- {
- //
- // Found entry, so copy all following entries and shrink table
- // We actually copy all + 1 to copy the initialized value of memory over
- // the last entry.
- //
- if (Rsdt != NULL) {
- CopyMem (CurrentRsdtEntry, CurrentRsdtEntry + 1, (*NumberOfTableEntries - Index) * sizeof (UINT32));
- Rsdt->Length = Rsdt->Length - sizeof (UINT32);
- }
-
- if (Xsdt != NULL) {
- CopyMem (CurrentXsdtEntry, ((UINT64 *)CurrentXsdtEntry) + 1, (*NumberOfTableEntries - Index) * sizeof (UINT64));
- Xsdt->Length = Xsdt->Length - sizeof (UINT64);
- }
-
- break;
- } else if (Index + 1 == *NumberOfTableEntries) {
- //
- // At the last entry, and table not found
- //
- return EFI_INVALID_PARAMETER;
- }
- }
-
- //
- // Checksum the tables
- //
- if (Rsdt != NULL) {
- AcpiPlatformChecksum (
- Rsdt,
- Rsdt->Length,
- OFFSET_OF (
- EFI_ACPI_DESCRIPTION_HEADER,
- Checksum
- )
- );
- }
-
- if (Xsdt != NULL) {
- AcpiPlatformChecksum (
- Xsdt,
- Xsdt->Length,
- OFFSET_OF (
- EFI_ACPI_DESCRIPTION_HEADER,
- Checksum
- )
- );
- }
-
- //
- // Decrement the number of tables
- //
- (*NumberOfTableEntries)--;
-
- return EFI_SUCCESS;
-}
-
-/**
- This function removes a table and frees any associated memory.
-
- @param AcpiTableInstance Instance of the protocol.
- @param Version Version(s) to delete.
- @param Table Pointer to table found.
-
- @return EFI_SUCCESS The function completed successfully.
-
-**/
-EFI_STATUS
-DeleteTable (
- IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
- IN EFI_ACPI_TABLE_VERSION Version,
- IN OUT EFI_ACPI_TABLE_LIST *Table
- )
-{
- UINT32 CurrentTableSignature;
- BOOLEAN RemoveFromRsdt;
-
- //
- // Check for invalid input parameters
- //
- ASSERT (AcpiTableInstance);
- ASSERT (Table);
-
- //
- // Init locals
- //
- RemoveFromRsdt = TRUE;
- //
- // Check for Table->Table
- //
- ASSERT (Table->Table != NULL);
- CurrentTableSignature = ((EFI_ACPI_COMMON_HEADER *)Table->Table)->Signature;
-
- //
- // Basic tasks to accomplish delete are:
- // Determine removal requirements (in RSDT/XSDT or not)
- // Remove entry from RSDT/XSDT
- // Remove any table references to the table
- // If no one is using the table
- // Free the table (removing pointers from private data and tables)
- // Remove from list
- // Free list structure
- //
- //
- // Determine if this table is in the RSDT or XSDT
- //
- if ((CurrentTableSignature == EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE) ||
- (CurrentTableSignature == EFI_ACPI_2_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE) ||
- (CurrentTableSignature == EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE)
- )
- {
- RemoveFromRsdt = FALSE;
- }
-
- //
- // We don't remove the FADT in the standard way because some
- // OS expect the FADT to be early in the table list.
- // So we always put it as the first element in the list.
- //
- if (CurrentTableSignature == EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {
- RemoveFromRsdt = FALSE;
- }
-
- //
- // Remove the table from RSDT and XSDT
- //
- if (Table->Table != NULL) {
- //
- // This is a basic table, remove it from any lists and the Rsdt and/or Xsdt
- //
- if (Version & EFI_ACPI_TABLE_VERSION_NONE & Table->Version) {
- //
- // Remove this version from the table
- //
- Table->Version = Table->Version &~EFI_ACPI_TABLE_VERSION_NONE;
- }
-
- if (Version & EFI_ACPI_TABLE_VERSION_1_0B & Table->Version) {
- //
- // Remove this version from the table
- //
- Table->Version = Table->Version &~EFI_ACPI_TABLE_VERSION_1_0B;
-
- //
- // Remove from Rsdt. We don't care about the return value because it is
- // acceptable for the table to not exist in Rsdt.
- // We didn't add some tables so we don't remove them.
- //
- if (RemoveFromRsdt) {
- RemoveTableFromRsdt (
- Table,
- &AcpiTableInstance->NumberOfTableEntries1,
- AcpiTableInstance->Rsdt1,
- NULL
- );
- }
- }
-
- if (Version & ACPI_TABLE_VERSION_GTE_2_0 & Table->Version) {
- //
- // Remove this version from the table
- //
- Table->Version = Table->Version &~(Version & ACPI_TABLE_VERSION_GTE_2_0);
-
- //
- // Remove from Rsdt and Xsdt. We don't care about the return value
- // because it is acceptable for the table to not exist in Rsdt/Xsdt.
- // We didn't add some tables so we don't remove them.
- //
- if (RemoveFromRsdt) {
- RemoveTableFromRsdt (
- Table,
- &AcpiTableInstance->NumberOfTableEntries3,
- AcpiTableInstance->Rsdt3,
- AcpiTableInstance->Xsdt
- );
- }
- }
-
- //
- // Free the table, clean up any dependent tables and our private data pointers.
- //
- switch (Table->Table->Signature) {
- case EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE:
- if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- AcpiTableInstance->Fadt1 = NULL;
- }
-
- if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
- AcpiTableInstance->Fadt3 = NULL;
- }
-
- break;
-
- case EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE:
- if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- AcpiTableInstance->Facs1 = NULL;
-
- //
- // Update FADT table pointers
- //
- if (AcpiTableInstance->Fadt1 != NULL) {
- AcpiTableInstance->Fadt1->FirmwareCtrl = 0;
-
- //
- // Checksum table
- //
- AcpiPlatformChecksum (
- AcpiTableInstance->Fadt1,
- AcpiTableInstance->Fadt1->Header.Length,
- OFFSET_OF (
- EFI_ACPI_DESCRIPTION_HEADER,
- Checksum
- )
- );
- }
- }
-
- if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
- AcpiTableInstance->Facs3 = NULL;
-
- //
- // Update FADT table pointers
- //
- if (AcpiTableInstance->Fadt3 != NULL) {
- AcpiTableInstance->Fadt3->FirmwareCtrl = 0;
- ZeroMem (&AcpiTableInstance->Fadt3->XFirmwareCtrl, sizeof (UINT64));
-
- //
- // Checksum table
- //
- AcpiPlatformChecksum (
- AcpiTableInstance->Fadt3,
- AcpiTableInstance->Fadt3->Header.Length,
- OFFSET_OF (
- EFI_ACPI_DESCRIPTION_HEADER,
- Checksum
- )
- );
- }
- }
-
- break;
-
- case EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE:
- if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- AcpiTableInstance->Dsdt1 = NULL;
-
- //
- // Update FADT table pointers
- //
- if (AcpiTableInstance->Fadt1 != NULL) {
- AcpiTableInstance->Fadt1->Dsdt = 0;
-
- //
- // Checksum table
- //
- AcpiPlatformChecksum (
- AcpiTableInstance->Fadt1,
- AcpiTableInstance->Fadt1->Header.Length,
- OFFSET_OF (
- EFI_ACPI_DESCRIPTION_HEADER,
- Checksum
- )
- );
- }
- }
-
- if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
- AcpiTableInstance->Dsdt3 = NULL;
-
- //
- // Update FADT table pointers
- //
- if (AcpiTableInstance->Fadt3 != NULL) {
- AcpiTableInstance->Fadt3->Dsdt = 0;
- ZeroMem (&AcpiTableInstance->Fadt3->XDsdt, sizeof (UINT64));
-
- //
- // Checksum table
- //
- AcpiPlatformChecksum (
- AcpiTableInstance->Fadt3,
- AcpiTableInstance->Fadt3->Header.Length,
- OFFSET_OF (
- EFI_ACPI_DESCRIPTION_HEADER,
- Checksum
- )
- );
- }
- }
-
- break;
-
- default:
- //
- // Do nothing
- //
- break;
- }
- }
-
- //
- // If no version is using this table anymore, remove and free list entry.
- //
- if (Table->Version == 0) {
- //
- // Free the Table
- //
- FreeTableMemory (Table);
- RemoveEntryList (&(Table->Link));
- gBS->FreePool (Table);
- }
-
- //
- // Done
- //
- return EFI_SUCCESS;
-}
-
-/**
- This function finds and removes the table specified by the handle.
-
- @param AcpiTableInstance Instance of the protocol.
- @param Version Bitmask of which versions to remove.
- @param Handle Table to remove.
-
- @return EFI_SUCCESS The function completed successfully.
- @return EFI_ABORTED An error occurred.
- @return EFI_NOT_FOUND Handle not found in table list.
-
-**/
-EFI_STATUS
-RemoveTableFromList (
- IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
- IN EFI_ACPI_TABLE_VERSION Version,
- IN UINTN Handle
- )
-{
- EFI_ACPI_TABLE_LIST *Table;
- EFI_STATUS Status;
-
- Table = (EFI_ACPI_TABLE_LIST *)NULL;
-
- //
- // Check for invalid input parameters
- //
- ASSERT (AcpiTableInstance);
-
- //
- // Find the table
- //
- Status = FindTableByHandle (
- Handle,
- &AcpiTableInstance->TableList,
- &Table
- );
- if (EFI_ERROR (Status)) {
- return EFI_NOT_FOUND;
- }
-
- //
- // Remove the table
- //
- Status = DeleteTable (AcpiTableInstance, Version, Table);
- if (EFI_ERROR (Status)) {
- return EFI_ABORTED;
- }
-
- //
- // Completed successfully
- //
- return EFI_SUCCESS;
-}
-
-/**
- This function calculates and updates an UINT8 checksum.
-
- @param Buffer Pointer to buffer to checksum
- @param Size Number of bytes to checksum
- @param ChecksumOffset Offset to place the checksum result in
-
- @return EFI_SUCCESS The function completed successfully.
-
-**/
-EFI_STATUS
-AcpiPlatformChecksum (
- IN VOID *Buffer,
- IN UINTN Size,
- IN UINTN ChecksumOffset
- )
-{
- UINT8 Sum;
- UINT8 *Ptr;
-
- Sum = 0;
- //
- // Initialize pointer
- //
- Ptr = Buffer;
-
- //
- // set checksum to 0 first
- //
- Ptr[ChecksumOffset] = 0;
-
- //
- // add all content of buffer
- //
- while ((Size--) != 0) {
- Sum = (UINT8)(Sum + (*Ptr++));
- }
-
- //
- // set checksum
- //
- Ptr = Buffer;
- Ptr[ChecksumOffset] = (UINT8)(0xff - Sum + 1);
-
- return EFI_SUCCESS;
-}
-
-/**
- Checksum all versions of the common tables, RSDP, RSDT, XSDT.
-
- @param AcpiTableInstance Protocol instance private data.
-
- @return EFI_SUCCESS The function completed successfully.
-
-**/
-EFI_STATUS
-ChecksumCommonTables (
- IN OUT EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance
- )
-{
- //
- // RSDP ACPI 1.0 checksum for 1.0 table. This is only the first 20 bytes of the structure
- //
- if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- AcpiPlatformChecksum (
- AcpiTableInstance->Rsdp1,
- sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER),
- OFFSET_OF (
- EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER,
- Checksum
- )
- );
- }
-
- //
- // RSDP ACPI 1.0 checksum for 2.0/3.0 table. This is only the first 20 bytes of the structure
- //
- AcpiPlatformChecksum (
- AcpiTableInstance->Rsdp3,
- sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER),
- OFFSET_OF (
- EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER,
- Checksum
- )
- );
-
- //
- // RSDP ACPI 2.0/3.0 checksum, this is the entire table
- //
- AcpiPlatformChecksum (
- AcpiTableInstance->Rsdp3,
- sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER),
- OFFSET_OF (
- EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER,
- ExtendedChecksum
- )
- );
-
- if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- //
- // RSDT checksums
- //
- AcpiPlatformChecksum (
- AcpiTableInstance->Rsdt1,
- AcpiTableInstance->Rsdt1->Length,
- OFFSET_OF (
- EFI_ACPI_DESCRIPTION_HEADER,
- Checksum
- )
- );
-
- AcpiPlatformChecksum (
- AcpiTableInstance->Rsdt3,
- AcpiTableInstance->Rsdt3->Length,
- OFFSET_OF (
- EFI_ACPI_DESCRIPTION_HEADER,
- Checksum
- )
- );
- }
-
- //
- // XSDT checksum
- //
- AcpiPlatformChecksum (
- AcpiTableInstance->Xsdt,
- AcpiTableInstance->Xsdt->Length,
- OFFSET_OF (
- EFI_ACPI_DESCRIPTION_HEADER,
- Checksum
- )
- );
-
- return EFI_SUCCESS;
-}
-
-/**
- This function will find gUniversalPayloadAcpiTableGuid Guid Hob, and install Acpi table from it.
-
- @param AcpiTableInstance Protocol instance private data.
-
- @return EFI_SUCCESS The function completed successfully.
- @return EFI_NOT_FOUND The function doesn't find the gEfiAcpiTableGuid Guid Hob.
- @return EFI_ABORTED The function could not complete successfully.
-
-**/
-EFI_STATUS
-InstallAcpiTableFromHob (
- EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance
- )
-{
- EFI_HOB_GUID_TYPE *GuidHob;
- EFI_ACPI_TABLE_VERSION Version;
- EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp;
- EFI_ACPI_DESCRIPTION_HEADER *Rsdt;
- EFI_ACPI_DESCRIPTION_HEADER *ChildTable;
- UINT64 ChildTableAddress;
- UINTN Count;
- UINTN Index;
- UINTN TableKey;
- EFI_STATUS Status;
- UINTN EntrySize;
- UNIVERSAL_PAYLOAD_ACPI_TABLE *AcpiTableAdress;
- VOID *TableToInstall;
- EFI_ACPI_SDT_HEADER *Table;
- UNIVERSAL_PAYLOAD_GENERIC_HEADER *GenericHeader;
-
- TableKey = 0;
- Version = PcdGet32 (PcdAcpiExposedTableVersions);
- Status = EFI_SUCCESS;
- //
- // HOB only contains the ACPI table in 2.0+ format.
- //
- GuidHob = GetFirstGuidHob (&gUniversalPayloadAcpiTableGuid);
- if (GuidHob == NULL) {
- return EFI_NOT_FOUND;
- }
-
- GenericHeader = (UNIVERSAL_PAYLOAD_GENERIC_HEADER *)GET_GUID_HOB_DATA (GuidHob);
- if ((sizeof (UNIVERSAL_PAYLOAD_GENERIC_HEADER) > GET_GUID_HOB_DATA_SIZE (GuidHob)) || (GenericHeader->Length > GET_GUID_HOB_DATA_SIZE (GuidHob))) {
- return EFI_NOT_FOUND;
- }
-
- if (GenericHeader->Revision == UNIVERSAL_PAYLOAD_ACPI_TABLE_REVISION) {
- //
- // UNIVERSAL_PAYLOAD_ACPI_TABLE structure is used when Revision equals to UNIVERSAL_PAYLOAD_ACPI_TABLE_REVISION
- //
- AcpiTableAdress = (UNIVERSAL_PAYLOAD_ACPI_TABLE *)GET_GUID_HOB_DATA (GuidHob);
- if (AcpiTableAdress->Header.Length < UNIVERSAL_PAYLOAD_SIZEOF_THROUGH_FIELD (UNIVERSAL_PAYLOAD_ACPI_TABLE, Rsdp)) {
- //
- // Retrun if can't find the ACPI Info Hob with enough length
- //
- return EFI_NOT_FOUND;
- }
-
- Rsdp = (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *)(UINTN)(AcpiTableAdress->Rsdp);
-
- //
- // An ACPI-compatible OS must use the XSDT if present.
- // It shouldn't happen that XsdtAddress points beyond 4G range in 32-bit environment.
- //
- ASSERT ((UINTN)Rsdp->XsdtAddress == Rsdp->XsdtAddress);
-
- EntrySize = sizeof (UINT64);
- Rsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->XsdtAddress;
- if (Rsdt == NULL) {
- //
- // XsdtAddress is zero, then we use Rsdt which has 32 bit entry
- //
- Rsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->RsdtAddress;
- EntrySize = sizeof (UINT32);
- }
-
- if (Rsdt->Length <= sizeof (EFI_ACPI_DESCRIPTION_HEADER)) {
- return EFI_ABORTED;
- }
-
- Count = (Rsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / EntrySize;
-
- for (Index = 0; Index < Count; Index++) {
- ChildTableAddress = 0;
- CopyMem (&ChildTableAddress, (UINT8 *)(Rsdt + 1) + EntrySize * Index, EntrySize);
- //
- // If the address is of UINT64 while this module runs at 32 bits,
- // make sure the upper bits are all-zeros.
- //
- ASSERT (ChildTableAddress == (UINTN)ChildTableAddress);
- if (ChildTableAddress != (UINTN)ChildTableAddress) {
- Status = EFI_ABORTED;
- break;
- }
-
- ChildTable = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)ChildTableAddress;
- Status = AddTableToList (AcpiTableInstance, ChildTable, TRUE, Version, TRUE, &TableKey);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "InstallAcpiTableFromHob: Fail to add ACPI table at 0x%p\n", ChildTable));
- ASSERT_EFI_ERROR (Status);
- break;
- }
-
- if (ChildTable->Signature == EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {
- //
- // Add the FACS and DSDT tables if it is not NULL.
- //
- if (((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)ChildTable)->FirmwareCtrl != 0) {
- TableToInstall = (VOID *)(UINTN)((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)ChildTable)->FirmwareCtrl;
- Status = AddTableToList (AcpiTableInstance, TableToInstall, TRUE, Version, TRUE, &TableKey);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "InstallAcpiTableFromHob: Fail to add ACPI table FACS\n"));
- ASSERT_EFI_ERROR (Status);
- break;
- }
- }
-
- //
- // First check if xDSDT is available, as that is preferred as per
- // ACPI Spec 6.5+ Table 5-9 X_DSDT definition
- //
- if (((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)ChildTable)->XDsdt != 0) {
- TableToInstall = (VOID *)(UINTN)((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)ChildTable)->XDsdt;
- } else if (((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)ChildTable)->Dsdt != 0) {
- TableToInstall = (VOID *)(UINTN)((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)ChildTable)->Dsdt;
- } else {
- DEBUG ((DEBUG_ERROR, "DSDT table not found\n"));
- continue;
- }
-
- Status = AddTableToList (AcpiTableInstance, TableToInstall, TRUE, Version, TRUE, &TableKey);
- if (EFI_ERROR (Status)) {
- DEBUG ((DEBUG_ERROR, "InstallAcpiTableFromHob: Fail to add ACPI table DSDT\n"));
- ASSERT_EFI_ERROR (Status);
- break;
- }
- }
- }
- } else {
- return EFI_NOT_FOUND;
- }
-
- if (EFI_ERROR (Status)) {
- //
- // Error happens when trying to add ACPI table to the list.
- // Remove all of them from list because at this time, no other tables except from HOB are in the list
- //
- while (SdtGetAcpiTable (AcpiTableInstance, 0, &Table, &Version, &TableKey) == EFI_SUCCESS) {
- RemoveTableFromList (AcpiTableInstance, Version, TableKey);
- }
- } else {
- Status = PublishTables (AcpiTableInstance, Version);
- }
-
- ASSERT_EFI_ERROR (Status);
- return Status;
-}
-
-/**
- Constructor for the ACPI table protocol. Initializes instance
- data.
-
- @param AcpiTableInstance Instance to construct
-
- @return EFI_SUCCESS Instance initialized.
- @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
-
-**/
-EFI_STATUS
-AcpiTableAcpiTableConstructor (
- EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance
- )
-{
- EFI_STATUS Status;
- UINT64 CurrentData;
- UINTN TotalSize;
- UINTN RsdpTableSize;
- UINT8 *Pointer;
- EFI_PHYSICAL_ADDRESS PageAddress;
- EFI_MEMORY_TYPE AcpiAllocateMemoryType;
-
- //
- // Check for invalid input parameters
- //
- ASSERT (AcpiTableInstance);
-
- //
- // If ACPI v1.0b is among the ACPI versions we aim to support, we have to
- // ensure that all memory allocations are below 4 GB.
- //
- if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- mAcpiTableAllocType = AllocateMaxAddress;
- } else {
- mAcpiTableAllocType = AllocateAnyPages;
- }
-
- InitializeListHead (&AcpiTableInstance->TableList);
- AcpiTableInstance->CurrentHandle = 1;
-
- AcpiTableInstance->AcpiTableProtocol.InstallAcpiTable = InstallAcpiTable;
- AcpiTableInstance->AcpiTableProtocol.UninstallAcpiTable = UninstallAcpiTable;
-
- if (FeaturePcdGet (PcdInstallAcpiSdtProtocol)) {
- SdtAcpiTableAcpiSdtConstructor (AcpiTableInstance);
- }
-
- //
- // Create RSDP table
- //
- RsdpTableSize = sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER);
- if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- RsdpTableSize += sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER);
- }
-
- if (PcdGetBool (PcdNoACPIReclaimMemory)) {
- AcpiAllocateMemoryType = EfiACPIMemoryNVS;
- } else {
- AcpiAllocateMemoryType = EfiACPIReclaimMemory;
- }
-
- if (mAcpiTableAllocType != AllocateAnyPages) {
- PageAddress = 0xFFFFFFFF;
- Status = gBS->AllocatePages (
- mAcpiTableAllocType,
- AcpiAllocateMemoryType,
- EFI_SIZE_TO_PAGES (RsdpTableSize),
- &PageAddress
- );
- } else {
- Status = gBS->AllocatePool (
- AcpiAllocateMemoryType,
- RsdpTableSize,
- (VOID **)&Pointer
- );
- }
-
- if (EFI_ERROR (Status)) {
- return EFI_OUT_OF_RESOURCES;
- }
-
- if (mAcpiTableAllocType != AllocateAnyPages) {
- Pointer = (UINT8 *)(UINTN)PageAddress;
- }
-
- ZeroMem (Pointer, RsdpTableSize);
-
- AcpiTableInstance->Rsdp1 = (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER *)Pointer;
- if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- Pointer += sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER);
- }
-
- AcpiTableInstance->Rsdp3 = (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *)Pointer;
-
- //
- // Create RSDT, XSDT structures
- //
- TotalSize = sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 2.0/3.0 XSDT
- mEfiAcpiMaxNumTables * sizeof (UINT64);
-
- if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- TotalSize += sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 1.0 RSDT
- mEfiAcpiMaxNumTables * sizeof (UINT32) +
- sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 2.0/3.0 RSDT
- mEfiAcpiMaxNumTables * sizeof (UINT32);
- }
-
- if (mAcpiTableAllocType != AllocateAnyPages) {
- //
- // Allocate memory in the lower 32 bit of address range for
- // compatibility with ACPI 1.0 OS.
- //
- // This is done because ACPI 1.0 pointers are 32 bit values.
- // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
- // There is no architectural reason these should be below 4GB, it is purely
- // for convenience of implementation that we force memory below 4GB.
- //
- PageAddress = 0xFFFFFFFF;
- Status = gBS->AllocatePages (
- mAcpiTableAllocType,
- AcpiAllocateMemoryType,
- EFI_SIZE_TO_PAGES (TotalSize),
- &PageAddress
- );
- } else {
- Status = gBS->AllocatePool (
- AcpiAllocateMemoryType,
- TotalSize,
- (VOID **)&Pointer
- );
- }
-
- if (EFI_ERROR (Status)) {
- if (mAcpiTableAllocType != AllocateAnyPages) {
- gBS->FreePages (
- (EFI_PHYSICAL_ADDRESS)(UINTN)AcpiTableInstance->Rsdp1,
- EFI_SIZE_TO_PAGES (RsdpTableSize)
- );
- } else {
- gBS->FreePool (AcpiTableInstance->Rsdp1);
- }
-
- return EFI_OUT_OF_RESOURCES;
- }
-
- if (mAcpiTableAllocType != AllocateAnyPages) {
- Pointer = (UINT8 *)(UINTN)PageAddress;
- }
-
- ZeroMem (Pointer, TotalSize);
-
- AcpiTableInstance->Rsdt1 = (EFI_ACPI_DESCRIPTION_HEADER *)Pointer;
- if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- Pointer += (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + EFI_ACPI_MAX_NUM_TABLES * sizeof (UINT32));
- AcpiTableInstance->Rsdt3 = (EFI_ACPI_DESCRIPTION_HEADER *)Pointer;
- Pointer += (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + EFI_ACPI_MAX_NUM_TABLES * sizeof (UINT32));
- }
-
- AcpiTableInstance->Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *)Pointer;
-
- //
- // Initialize RSDP
- //
- if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- CurrentData = EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE;
- CopyMem (&AcpiTableInstance->Rsdp1->Signature, &CurrentData, sizeof (UINT64));
- CopyMem (AcpiTableInstance->Rsdp1->OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (AcpiTableInstance->Rsdp1->OemId));
- AcpiTableInstance->Rsdp1->Reserved = EFI_ACPI_RESERVED_BYTE;
- AcpiTableInstance->Rsdp1->RsdtAddress = (UINT32)(UINTN)AcpiTableInstance->Rsdt1;
- }
-
- CurrentData = EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE;
- CopyMem (&AcpiTableInstance->Rsdp3->Signature, &CurrentData, sizeof (UINT64));
- CopyMem (AcpiTableInstance->Rsdp3->OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (AcpiTableInstance->Rsdp3->OemId));
- AcpiTableInstance->Rsdp3->Revision = EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION;
- AcpiTableInstance->Rsdp3->Length = sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER);
- if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- AcpiTableInstance->Rsdp3->RsdtAddress = (UINT32)(UINTN)AcpiTableInstance->Rsdt3;
- }
-
- CurrentData = (UINT64)(UINTN)AcpiTableInstance->Xsdt;
- CopyMem (&AcpiTableInstance->Rsdp3->XsdtAddress, &CurrentData, sizeof (UINT64));
- SetMem (AcpiTableInstance->Rsdp3->Reserved, 3, EFI_ACPI_RESERVED_BYTE);
-
- if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
- //
- // Initialize Rsdt
- //
- // Note that we "reserve" one entry for the FADT so it can always be
- // at the beginning of the list of tables. Some OS don't seem
- // to find it correctly if it is too far down the list.
- //
- AcpiTableInstance->Rsdt1->Signature = EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE;
- AcpiTableInstance->Rsdt1->Length = sizeof (EFI_ACPI_DESCRIPTION_HEADER);
- AcpiTableInstance->Rsdt1->Revision = EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION;
- CopyMem (AcpiTableInstance->Rsdt1->OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (AcpiTableInstance->Rsdt1->OemId));
- CurrentData = PcdGet64 (PcdAcpiDefaultOemTableId);
- CopyMem (&AcpiTableInstance->Rsdt1->OemTableId, &CurrentData, sizeof (UINT64));
- AcpiTableInstance->Rsdt1->OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision);
- AcpiTableInstance->Rsdt1->CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId);
- AcpiTableInstance->Rsdt1->CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision);
- //
- // We always reserve first one for FADT
- //
- AcpiTableInstance->NumberOfTableEntries1 = 1;
- AcpiTableInstance->Rsdt1->Length = AcpiTableInstance->Rsdt1->Length + sizeof (UINT32);
-
- AcpiTableInstance->Rsdt3->Signature = EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE;
- AcpiTableInstance->Rsdt3->Length = sizeof (EFI_ACPI_DESCRIPTION_HEADER);
- AcpiTableInstance->Rsdt3->Revision = EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION;
- CopyMem (AcpiTableInstance->Rsdt3->OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (AcpiTableInstance->Rsdt3->OemId));
- CurrentData = PcdGet64 (PcdAcpiDefaultOemTableId);
- CopyMem (&AcpiTableInstance->Rsdt3->OemTableId, &CurrentData, sizeof (UINT64));
- AcpiTableInstance->Rsdt3->OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision);
- AcpiTableInstance->Rsdt3->CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId);
- AcpiTableInstance->Rsdt3->CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision);
- //
- // We always reserve first one for FADT
- //
- AcpiTableInstance->Rsdt3->Length = AcpiTableInstance->Rsdt3->Length + sizeof (UINT32);
- }
-
- AcpiTableInstance->NumberOfTableEntries3 = 1;
-
- //
- // Initialize Xsdt
- //
- AcpiTableInstance->Xsdt->Signature = EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE;
- AcpiTableInstance->Xsdt->Length = sizeof (EFI_ACPI_DESCRIPTION_HEADER);
- AcpiTableInstance->Xsdt->Revision = EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_REVISION;
- CopyMem (AcpiTableInstance->Xsdt->OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (AcpiTableInstance->Xsdt->OemId));
- CurrentData = PcdGet64 (PcdAcpiDefaultOemTableId);
- CopyMem (&AcpiTableInstance->Xsdt->OemTableId, &CurrentData, sizeof (UINT64));
- AcpiTableInstance->Xsdt->OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision);
- AcpiTableInstance->Xsdt->CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId);
- AcpiTableInstance->Xsdt->CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision);
- //
- // We always reserve first one for FADT
- //
- AcpiTableInstance->Xsdt->Length = AcpiTableInstance->Xsdt->Length + sizeof (UINT64);
-
- ChecksumCommonTables (AcpiTableInstance);
-
- InstallAcpiTableFromHob (AcpiTableInstance);
-
- //
- // Completed successfully
- //
- return EFI_SUCCESS;
-}
+/** @file
+ ACPI Table Protocol Implementation
+
+ Copyright (c) 2006 - 2021, Intel Corporation. All rights reserved.<BR>
+ Copyright (c) 2016, Linaro Ltd. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+//
+// Includes
+//
+#include "AcpiTable.h"
+//
+// The maximum number of tables that pre-allocated.
+//
+UINTN mEfiAcpiMaxNumTables = EFI_ACPI_MAX_NUM_TABLES;
+
+//
+// Allocation strategy to use for AllocatePages ().
+// Runtime value depends on PcdExposedAcpiTableVersions.
+//
+STATIC EFI_ALLOCATE_TYPE mAcpiTableAllocType;
+
+/**
+ This function adds an ACPI table to the table list. It will detect FACS and
+ allocate the correct type of memory and properly align the table.
+
+ @param AcpiTableInstance Instance of the protocol.
+ @param Table Table to add.
+ @param Checksum Does the table require checksumming.
+ @param Version The version of the list to add the table to.
+ @param IsFromHob True, if add Apci Table from Hob List.
+ @param Handle Pointer for returning the handle.
+
+ @return EFI_SUCCESS The function completed successfully.
+ @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
+ @return EFI_ABORTED The table is a duplicate of a table that is required
+ to be unique.
+
+**/
+EFI_STATUS
+AddTableToList (
+ IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
+ IN VOID *Table,
+ IN BOOLEAN Checksum,
+ IN EFI_ACPI_TABLE_VERSION Version,
+ IN BOOLEAN IsFromHob,
+ OUT UINTN *Handle
+ );
+
+/**
+ This function finds and removes the table specified by the handle.
+
+ @param AcpiTableInstance Instance of the protocol.
+ @param Version Bitmask of which versions to remove.
+ @param Handle Table to remove.
+
+ @return EFI_SUCCESS The function completed successfully.
+ @return EFI_ABORTED An error occurred.
+ @return EFI_NOT_FOUND Handle not found in table list.
+
+**/
+EFI_STATUS
+RemoveTableFromList (
+ IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
+ IN EFI_ACPI_TABLE_VERSION Version,
+ IN UINTN Handle
+ );
+
+/**
+ This function calculates and updates an UINT8 checksum.
+
+ @param Buffer Pointer to buffer to checksum
+ @param Size Number of bytes to checksum
+ @param ChecksumOffset Offset to place the checksum result in
+
+ @return EFI_SUCCESS The function completed successfully.
+**/
+EFI_STATUS
+AcpiPlatformChecksum (
+ IN VOID *Buffer,
+ IN UINTN Size,
+ IN UINTN ChecksumOffset
+ );
+
+/**
+ Checksum all versions of the common tables, RSDP, RSDT, XSDT.
+
+ @param AcpiTableInstance Protocol instance private data.
+
+ @return EFI_SUCCESS The function completed successfully.
+
+**/
+EFI_STATUS
+ChecksumCommonTables (
+ IN OUT EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance
+ );
+
+//
+// Protocol function implementations.
+//
+
+/**
+ This function publishes the specified versions of the ACPI tables by
+ installing EFI configuration table entries for them. Any combination of
+ table versions can be published.
+
+ @param AcpiTableInstance Instance of the protocol.
+ @param Version Version(s) to publish.
+
+ @return EFI_SUCCESS The function completed successfully.
+ @return EFI_ABORTED The function could not complete successfully.
+
+**/
+EFI_STATUS
+EFIAPI
+PublishTables (
+ IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
+ IN EFI_ACPI_TABLE_VERSION Version
+ )
+{
+ EFI_STATUS Status;
+ UINT32 *CurrentRsdtEntry;
+ VOID *CurrentXsdtEntry;
+ UINT64 Buffer64;
+
+ //
+ // Reorder tables as some operating systems don't seem to find the
+ // FADT correctly if it is not in the first few entries
+ //
+
+ //
+ // Add FADT as the first entry
+ //
+ if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ CurrentRsdtEntry = (UINT32 *)((UINT8 *)AcpiTableInstance->Rsdt1 + sizeof (EFI_ACPI_DESCRIPTION_HEADER));
+ *CurrentRsdtEntry = (UINT32)(UINTN)AcpiTableInstance->Fadt1;
+
+ CurrentRsdtEntry = (UINT32 *)((UINT8 *)AcpiTableInstance->Rsdt3 + sizeof (EFI_ACPI_DESCRIPTION_HEADER));
+ *CurrentRsdtEntry = (UINT32)(UINTN)AcpiTableInstance->Fadt3;
+ }
+
+ if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
+ CurrentXsdtEntry = (VOID *)((UINT8 *)AcpiTableInstance->Xsdt + sizeof (EFI_ACPI_DESCRIPTION_HEADER));
+ //
+ // Add entry to XSDT, XSDT expects 64 bit pointers, but
+ // the table pointers in XSDT are not aligned on 8 byte boundary.
+ //
+ Buffer64 = (UINT64)(UINTN)AcpiTableInstance->Fadt3;
+ CopyMem (
+ CurrentXsdtEntry,
+ &Buffer64,
+ sizeof (UINT64)
+ );
+ }
+
+ //
+ // Do checksum again because Dsdt/Xsdt is updated.
+ //
+ ChecksumCommonTables (AcpiTableInstance);
+
+ //
+ // Add the RSD_PTR to the system table and store that we have installed the
+ // tables.
+ //
+ if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ Status = gBS->InstallConfigurationTable (&gEfiAcpi10TableGuid, AcpiTableInstance->Rsdp1);
+ if (EFI_ERROR (Status)) {
+ return EFI_ABORTED;
+ }
+ }
+
+ if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
+ Status = gBS->InstallConfigurationTable (&gEfiAcpiTableGuid, AcpiTableInstance->Rsdp3);
+ if (EFI_ERROR (Status)) {
+ return EFI_ABORTED;
+ }
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Installs an ACPI table into the RSDT/XSDT.
+ Note that the ACPI table should be checksumed before installing it.
+ Otherwise it will assert.
+
+ @param This Protocol instance pointer.
+ @param AcpiTableBuffer A pointer to a buffer containing the ACPI table to be installed.
+ @param AcpiTableBufferSize Specifies the size, in bytes, of the AcpiTableBuffer buffer.
+ @param TableKey Reurns a key to refer to the ACPI table.
+
+ @return EFI_SUCCESS The table was successfully inserted.
+ @return EFI_INVALID_PARAMETER Either AcpiTableBuffer is NULL, TableKey is NULL, or AcpiTableBufferSize
+ and the size field embedded in the ACPI table pointed to by AcpiTableBuffer
+ are not in sync.
+ @return EFI_OUT_OF_RESOURCES Insufficient resources exist to complete the request.
+ @retval EFI_ACCESS_DENIED The table signature matches a table already
+ present in the system and platform policy
+ does not allow duplicate tables of this type.
+
+**/
+EFI_STATUS
+EFIAPI
+InstallAcpiTable (
+ IN EFI_ACPI_TABLE_PROTOCOL *This,
+ IN VOID *AcpiTableBuffer,
+ IN UINTN AcpiTableBufferSize,
+ OUT UINTN *TableKey
+ )
+{
+ EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance;
+ EFI_STATUS Status;
+ VOID *AcpiTableBufferConst;
+ EFI_ACPI_TABLE_VERSION Version;
+
+ //
+ // Check for invalid input parameters
+ //
+ if ( (AcpiTableBuffer == NULL) || (TableKey == NULL)
+ || (((EFI_ACPI_DESCRIPTION_HEADER *)AcpiTableBuffer)->Length != AcpiTableBufferSize))
+ {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Version = PcdGet32 (PcdAcpiExposedTableVersions);
+
+ //
+ // Get the instance of the ACPI table protocol
+ //
+ AcpiTableInstance = EFI_ACPI_TABLE_INSTANCE_FROM_THIS (This);
+
+ //
+ // Install the ACPI table
+ //
+ AcpiTableBufferConst = AllocateCopyPool (AcpiTableBufferSize, AcpiTableBuffer);
+ *TableKey = 0;
+ Status = AddTableToList (
+ AcpiTableInstance,
+ AcpiTableBufferConst,
+ TRUE,
+ Version,
+ FALSE,
+ TableKey
+ );
+ if (!EFI_ERROR (Status)) {
+ Status = PublishTables (
+ AcpiTableInstance,
+ Version
+ );
+ }
+
+ FreePool (AcpiTableBufferConst);
+
+ //
+ // Add a new table successfully, notify registed callback
+ //
+ if (FeaturePcdGet (PcdInstallAcpiSdtProtocol)) {
+ if (!EFI_ERROR (Status)) {
+ SdtNotifyAcpiList (
+ AcpiTableInstance,
+ Version,
+ *TableKey
+ );
+ }
+ }
+
+ return Status;
+}
+
+/**
+ Removes an ACPI table from the RSDT/XSDT.
+
+ @param This Protocol instance pointer.
+ @param TableKey Specifies the table to uninstall. The key was returned from InstallAcpiTable().
+
+ @return EFI_SUCCESS The table was successfully uninstalled.
+ @return EFI_NOT_FOUND TableKey does not refer to a valid key for a table entry.
+
+**/
+EFI_STATUS
+EFIAPI
+UninstallAcpiTable (
+ IN EFI_ACPI_TABLE_PROTOCOL *This,
+ IN UINTN TableKey
+ )
+{
+ EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance;
+ EFI_STATUS Status;
+ EFI_ACPI_TABLE_VERSION Version;
+
+ //
+ // Get the instance of the ACPI table protocol
+ //
+ AcpiTableInstance = EFI_ACPI_TABLE_INSTANCE_FROM_THIS (This);
+
+ Version = PcdGet32 (PcdAcpiExposedTableVersions);
+
+ //
+ // Uninstall the ACPI table
+ //
+ Status = RemoveTableFromList (
+ AcpiTableInstance,
+ Version,
+ TableKey
+ );
+ if (!EFI_ERROR (Status)) {
+ Status = PublishTables (
+ AcpiTableInstance,
+ Version
+ );
+ }
+
+ if (EFI_ERROR (Status)) {
+ return EFI_NOT_FOUND;
+ } else {
+ return EFI_SUCCESS;
+ }
+}
+
+/**
+ If the number of APCI tables exceeds the preallocated max table number, enlarge the table buffer.
+
+ @param AcpiTableInstance ACPI table protocol instance data structure.
+
+ @return EFI_SUCCESS reallocate the table beffer successfully.
+ @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
+
+**/
+EFI_STATUS
+ReallocateAcpiTableBuffer (
+ IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance
+ )
+{
+ UINTN NewMaxTableNumber;
+ UINTN TotalSize;
+ UINT8 *Pointer;
+ EFI_PHYSICAL_ADDRESS PageAddress;
+ EFI_ACPI_TABLE_INSTANCE TempPrivateData;
+ EFI_STATUS Status;
+ UINT64 CurrentData;
+ EFI_MEMORY_TYPE AcpiAllocateMemoryType;
+
+ CopyMem (&TempPrivateData, AcpiTableInstance, sizeof (EFI_ACPI_TABLE_INSTANCE));
+ //
+ // Enlarge the max table number from mEfiAcpiMaxNumTables to mEfiAcpiMaxNumTables + EFI_ACPI_MAX_NUM_TABLES
+ //
+ NewMaxTableNumber = mEfiAcpiMaxNumTables + EFI_ACPI_MAX_NUM_TABLES;
+ //
+ // Create RSDT, XSDT structures and allocate buffers.
+ //
+ TotalSize = sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 2.0/3.0 XSDT
+ NewMaxTableNumber * sizeof (UINT64);
+
+ if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ TotalSize += sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 1.0 RSDT
+ NewMaxTableNumber * sizeof (UINT32) +
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 2.0/3.0 RSDT
+ NewMaxTableNumber * sizeof (UINT32);
+ }
+
+ if (PcdGetBool (PcdNoACPIReclaimMemory)) {
+ AcpiAllocateMemoryType = EfiACPIMemoryNVS;
+ } else {
+ AcpiAllocateMemoryType = EfiACPIReclaimMemory;
+ }
+
+ if (mAcpiTableAllocType != AllocateAnyPages) {
+ //
+ // Allocate memory in the lower 32 bit of address range for
+ // compatibility with ACPI 1.0 OS.
+ //
+ // This is done because ACPI 1.0 pointers are 32 bit values.
+ // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
+ // There is no architectural reason these should be below 4GB, it is purely
+ // for convenience of implementation that we force memory below 4GB.
+ //
+ PageAddress = 0xFFFFFFFF;
+ Status = gBS->AllocatePages (
+ mAcpiTableAllocType,
+ AcpiAllocateMemoryType,
+ EFI_SIZE_TO_PAGES (TotalSize),
+ &PageAddress
+ );
+ } else {
+ Status = gBS->AllocatePool (
+ AcpiAllocateMemoryType,
+ TotalSize,
+ (VOID **)&Pointer
+ );
+ }
+
+ if (EFI_ERROR (Status)) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ if (mAcpiTableAllocType != AllocateAnyPages) {
+ Pointer = (UINT8 *)(UINTN)PageAddress;
+ }
+
+ ZeroMem (Pointer, TotalSize);
+
+ AcpiTableInstance->Rsdt1 = (EFI_ACPI_DESCRIPTION_HEADER *)Pointer;
+ if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ Pointer += (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + NewMaxTableNumber * sizeof (UINT32));
+ AcpiTableInstance->Rsdt3 = (EFI_ACPI_DESCRIPTION_HEADER *)Pointer;
+ Pointer += (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + NewMaxTableNumber * sizeof (UINT32));
+ }
+
+ AcpiTableInstance->Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *)Pointer;
+
+ //
+ // Update RSDP to point to the new Rsdt and Xsdt address.
+ //
+ if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ AcpiTableInstance->Rsdp1->RsdtAddress = (UINT32)(UINTN)AcpiTableInstance->Rsdt1;
+ AcpiTableInstance->Rsdp3->RsdtAddress = (UINT32)(UINTN)AcpiTableInstance->Rsdt3;
+ }
+
+ CurrentData = (UINT64)(UINTN)AcpiTableInstance->Xsdt;
+ CopyMem (&AcpiTableInstance->Rsdp3->XsdtAddress, &CurrentData, sizeof (UINT64));
+
+ //
+ // copy the original Rsdt1, Rsdt3 and Xsdt structure to new buffer
+ //
+ if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ CopyMem (AcpiTableInstance->Rsdt1, TempPrivateData.Rsdt1, (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + mEfiAcpiMaxNumTables * sizeof (UINT32)));
+ CopyMem (AcpiTableInstance->Rsdt3, TempPrivateData.Rsdt3, (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + mEfiAcpiMaxNumTables * sizeof (UINT32)));
+ }
+
+ CopyMem (AcpiTableInstance->Xsdt, TempPrivateData.Xsdt, (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + mEfiAcpiMaxNumTables * sizeof (UINT64)));
+
+ if (mAcpiTableAllocType != AllocateAnyPages) {
+ //
+ // Calculate orignal ACPI table buffer size
+ //
+ TotalSize = sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 2.0/3.0 XSDT
+ mEfiAcpiMaxNumTables * sizeof (UINT64);
+
+ if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ TotalSize += sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 1.0 RSDT
+ mEfiAcpiMaxNumTables * sizeof (UINT32) +
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 2.0/3.0 RSDT
+ mEfiAcpiMaxNumTables * sizeof (UINT32);
+ }
+
+ gBS->FreePages (
+ (EFI_PHYSICAL_ADDRESS)(UINTN)TempPrivateData.Rsdt1,
+ EFI_SIZE_TO_PAGES (TotalSize)
+ );
+ } else {
+ gBS->FreePool (TempPrivateData.Rsdt1);
+ }
+
+ //
+ // Update the Max ACPI table number
+ //
+ mEfiAcpiMaxNumTables = NewMaxTableNumber;
+ return EFI_SUCCESS;
+}
+
+/**
+ Free the memory associated with the provided EFI_ACPI_TABLE_LIST instance.
+
+ @param TableEntry EFI_ACPI_TABLE_LIST instance pointer
+
+**/
+STATIC
+VOID
+FreeTableMemory (
+ EFI_ACPI_TABLE_LIST *TableEntry
+ )
+{
+ if (TableEntry->PoolAllocation) {
+ gBS->FreePool (TableEntry->Table);
+ } else {
+ gBS->FreePages (
+ (EFI_PHYSICAL_ADDRESS)(UINTN)TableEntry->Table,
+ EFI_SIZE_TO_PAGES (TableEntry->TableSize)
+ );
+ }
+}
+
+/**
+ This function adds an ACPI table to the table list. It will detect FACS and
+ allocate the correct type of memory and properly align the table.
+
+ @param AcpiTableInstance Instance of the protocol.
+ @param Table Table to add.
+ @param Checksum Does the table require checksumming.
+ @param Version The version of the list to add the table to.
+ @param IsFromHob True, if add Apci Table from Hob List.
+ @param Handle Pointer for returning the handle.
+
+ @return EFI_SUCCESS The function completed successfully.
+ @return EFI_OUT_OF_RESOURCES Could not allocate a required resource.
+ @retval EFI_ACCESS_DENIED The table signature matches a table already
+ present in the system and platform policy
+ does not allow duplicate tables of this type.
+
+**/
+EFI_STATUS
+AddTableToList (
+ IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
+ IN VOID *Table,
+ IN BOOLEAN Checksum,
+ IN EFI_ACPI_TABLE_VERSION Version,
+ IN BOOLEAN IsFromHob,
+ OUT UINTN *Handle
+ )
+{
+ EFI_STATUS Status;
+ EFI_ACPI_TABLE_LIST *CurrentTableList;
+ UINT32 CurrentTableSignature;
+ UINT32 CurrentTableSize;
+ UINT32 *CurrentRsdtEntry;
+ VOID *CurrentXsdtEntry;
+ EFI_PHYSICAL_ADDRESS AllocPhysAddress;
+ UINT64 Buffer64;
+ BOOLEAN AddToRsdt;
+ EFI_MEMORY_TYPE AcpiAllocateMemoryType;
+
+ //
+ // Check for invalid input parameters
+ //
+ ASSERT (AcpiTableInstance);
+ ASSERT (Table);
+ ASSERT (Handle);
+
+ //
+ // Init locals
+ //
+ AddToRsdt = TRUE;
+
+ //
+ // Create a new list entry
+ //
+ CurrentTableList = AllocatePool (sizeof (EFI_ACPI_TABLE_LIST));
+ ASSERT (CurrentTableList);
+
+ //
+ // Determine table type and size
+ //
+ CurrentTableSignature = ((EFI_ACPI_COMMON_HEADER *)Table)->Signature;
+ CurrentTableSize = ((EFI_ACPI_COMMON_HEADER *)Table)->Length;
+
+ //
+ // Allocate a buffer for the table. All tables are allocated in the lower 32 bits of address space
+ // for backwards compatibility with ACPI 1.0 OS.
+ //
+ // This is done because ACPI 1.0 pointers are 32 bit values.
+ // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
+ // There is no architectural reason these should be below 4GB, it is purely
+ // for convenience of implementation that we force memory below 4GB.
+ //
+ AllocPhysAddress = 0xFFFFFFFF;
+ CurrentTableList->TableSize = CurrentTableSize;
+ CurrentTableList->PoolAllocation = FALSE;
+
+ if (PcdGetBool (PcdNoACPIReclaimMemory)) {
+ AcpiAllocateMemoryType = EfiACPIMemoryNVS;
+ } else {
+ AcpiAllocateMemoryType = EfiACPIReclaimMemory;
+ }
+
+ //
+ // Allocation memory type depends on the type of the table
+ //
+ if ((CurrentTableSignature == EFI_ACPI_2_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE) ||
+ (CurrentTableSignature == EFI_ACPI_4_0_UEFI_ACPI_DATA_TABLE_SIGNATURE))
+ {
+ //
+ // Allocate memory for the FACS. This structure must be aligned
+ // on a 64 byte boundary and must be ACPI NVS memory.
+ // Using AllocatePages should ensure that it is always aligned.
+ // Do not change signature for new ACPI version because they are same.
+ //
+ // UEFI table also need to be in ACPI NVS memory, because some data field
+ // could be updated by OS present agent. For example, BufferPtrAddress in
+ // SMM communication ACPI table.
+ //
+ ASSERT ((EFI_PAGE_SIZE % 64) == 0);
+ if (IsFromHob) {
+ AllocPhysAddress = (UINTN)Table;
+ Status = EFI_SUCCESS;
+ } else {
+ Status = gBS->AllocatePages (
+ AllocateMaxAddress,
+ EfiACPIMemoryNVS,
+ EFI_SIZE_TO_PAGES (CurrentTableList->TableSize),
+ &AllocPhysAddress
+ );
+ }
+ } else if (mAcpiTableAllocType == AllocateAnyPages) {
+ //
+ // If there is no allocation limit, there is also no need to use page
+ // based allocations for ACPI tables, which may be wasteful on platforms
+ // such as AArch64 that allocate multiples of 64 KB
+ //
+ Status = gBS->AllocatePool (
+ AcpiAllocateMemoryType,
+ CurrentTableList->TableSize,
+ (VOID **)&CurrentTableList->Table
+ );
+ CurrentTableList->PoolAllocation = TRUE;
+ } else {
+ //
+ // All other tables are ACPI reclaim memory, no alignment requirements.
+ //
+ Status = gBS->AllocatePages (
+ mAcpiTableAllocType,
+ AcpiAllocateMemoryType,
+ EFI_SIZE_TO_PAGES (CurrentTableList->TableSize),
+ &AllocPhysAddress
+ );
+ CurrentTableList->Table = (EFI_ACPI_COMMON_HEADER *)(UINTN)AllocPhysAddress;
+ }
+
+ //
+ // Check return value from memory alloc.
+ //
+ if (EFI_ERROR (Status)) {
+ gBS->FreePool (CurrentTableList);
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ if (!CurrentTableList->PoolAllocation) {
+ CurrentTableList->Table = (EFI_ACPI_COMMON_HEADER *)(UINTN)AllocPhysAddress;
+ }
+
+ //
+ // Initialize the table contents
+ //
+ CurrentTableList->Signature = EFI_ACPI_TABLE_LIST_SIGNATURE;
+ CopyMem (CurrentTableList->Table, Table, CurrentTableSize);
+ CurrentTableList->Handle = AcpiTableInstance->CurrentHandle++;
+ *Handle = CurrentTableList->Handle;
+ CurrentTableList->Version = Version;
+
+ //
+ // Update internal pointers if this is a required table. If it is a required
+ // table and a table of that type already exists, return an error.
+ //
+ // Calculate the checksum if the table is not FACS.
+ //
+ switch (CurrentTableSignature) {
+ case EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE:
+ //
+ // We don't add the FADT in the standard way because some
+ // OS expect the FADT to be early in the table list.
+ // So we always add it as the first element in the list.
+ //
+ AddToRsdt = FALSE;
+
+ //
+ // Check that the table has not been previously added.
+ //
+ if ((((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) && (AcpiTableInstance->Fadt1 != NULL)) ||
+ (((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) && (AcpiTableInstance->Fadt3 != NULL))
+ )
+ {
+ FreeTableMemory (CurrentTableList);
+ gBS->FreePool (CurrentTableList);
+ return EFI_ACCESS_DENIED;
+ }
+
+ //
+ // Add the table to the appropriate table version
+ //
+ if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ //
+ // Save a pointer to the table
+ //
+ AcpiTableInstance->Fadt1 = (EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE *)CurrentTableList->Table;
+
+ //
+ // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
+ //
+ AcpiTableInstance->Fadt1->FirmwareCtrl = (UINT32)(UINTN)AcpiTableInstance->Facs1;
+ AcpiTableInstance->Fadt1->Dsdt = (UINT32)(UINTN)AcpiTableInstance->Dsdt1;
+
+ //
+ // RSDP OEM information is updated to match the FADT OEM information
+ //
+ CopyMem (
+ &AcpiTableInstance->Rsdp1->OemId,
+ &AcpiTableInstance->Fadt1->Header.OemId,
+ 6
+ );
+
+ //
+ // RSDT OEM information is updated to match the FADT OEM information.
+ //
+ CopyMem (
+ &AcpiTableInstance->Rsdt1->OemId,
+ &AcpiTableInstance->Fadt1->Header.OemId,
+ 6
+ );
+
+ CopyMem (
+ &AcpiTableInstance->Rsdt1->OemTableId,
+ &AcpiTableInstance->Fadt1->Header.OemTableId,
+ sizeof (UINT64)
+ );
+ AcpiTableInstance->Rsdt1->OemRevision = AcpiTableInstance->Fadt1->Header.OemRevision;
+ }
+
+ if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
+ //
+ // Save a pointer to the table
+ //
+ AcpiTableInstance->Fadt3 = (EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)CurrentTableList->Table;
+
+ //
+ // Update pointers in FADT. If tables don't exist this will put NULL pointers there.
+ // Note: If the FIRMWARE_CTRL is non-zero, then X_FIRMWARE_CTRL must be zero, and
+ // vice-versa.
+ //
+ if ((UINT64)(UINTN)AcpiTableInstance->Facs3 < BASE_4GB) {
+ AcpiTableInstance->Fadt3->FirmwareCtrl = (UINT32)(UINTN)AcpiTableInstance->Facs3;
+ ZeroMem (&AcpiTableInstance->Fadt3->XFirmwareCtrl, sizeof (UINT64));
+ } else {
+ Buffer64 = (UINT64)(UINTN)AcpiTableInstance->Facs3;
+ CopyMem (
+ &AcpiTableInstance->Fadt3->XFirmwareCtrl,
+ &Buffer64,
+ sizeof (UINT64)
+ );
+ AcpiTableInstance->Fadt3->FirmwareCtrl = 0;
+ }
+
+ if ((UINT64)(UINTN)AcpiTableInstance->Dsdt3 < BASE_4GB) {
+ AcpiTableInstance->Fadt3->Dsdt = (UINT32)(UINTN)AcpiTableInstance->Dsdt3;
+ //
+ // Comment block "the caller installs the tables in "DSDT, FADT" order"
+ // The below comments are also in "the caller installs the tables in "FADT, DSDT" order" comment block.
+ //
+ // The ACPI specification, up to and including revision 5.1 Errata A,
+ // allows the DSDT and X_DSDT fields to be both set in the FADT.
+ // (Obviously, this only makes sense if the DSDT address is representable in 4 bytes.)
+ // Starting with 5.1 Errata B, specifically for Mantis 1393 <https://mantis.uefi.org/mantis/view.php?id=1393>,
+ // the spec requires at most one of DSDT and X_DSDT fields to be set to a nonzero value,
+ // but strangely an exception is 6.0 that has no this requirement.
+ //
+ // Here we do not make the DSDT and X_DSDT fields mutual exclusion conditionally
+ // by checking FADT revision, but always set both DSDT and X_DSDT fields in the FADT
+ // to have better compatibility as some OS may have assumption to only consume X_DSDT
+ // field even the DSDT address is < 4G.
+ //
+ Buffer64 = AcpiTableInstance->Fadt3->Dsdt;
+ } else {
+ AcpiTableInstance->Fadt3->Dsdt = 0;
+ Buffer64 = (UINT64)(UINTN)AcpiTableInstance->Dsdt3;
+ }
+
+ CopyMem (&AcpiTableInstance->Fadt3->XDsdt, &Buffer64, sizeof (UINT64));
+
+ //
+ // RSDP OEM information is updated to match the FADT OEM information
+ //
+ CopyMem (
+ &AcpiTableInstance->Rsdp3->OemId,
+ &AcpiTableInstance->Fadt3->Header.OemId,
+ 6
+ );
+
+ if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ //
+ // RSDT OEM information is updated to match FADT OEM information.
+ //
+ CopyMem (
+ &AcpiTableInstance->Rsdt3->OemId,
+ &AcpiTableInstance->Fadt3->Header.OemId,
+ 6
+ );
+ CopyMem (
+ &AcpiTableInstance->Rsdt3->OemTableId,
+ &AcpiTableInstance->Fadt3->Header.OemTableId,
+ sizeof (UINT64)
+ );
+ AcpiTableInstance->Rsdt3->OemRevision = AcpiTableInstance->Fadt3->Header.OemRevision;
+ }
+
+ //
+ // XSDT OEM information is updated to match FADT OEM information.
+ //
+ CopyMem (
+ &AcpiTableInstance->Xsdt->OemId,
+ &AcpiTableInstance->Fadt3->Header.OemId,
+ 6
+ );
+ CopyMem (
+ &AcpiTableInstance->Xsdt->OemTableId,
+ &AcpiTableInstance->Fadt3->Header.OemTableId,
+ sizeof (UINT64)
+ );
+ AcpiTableInstance->Xsdt->OemRevision = AcpiTableInstance->Fadt3->Header.OemRevision;
+ }
+
+ //
+ // Checksum the table
+ //
+ if (Checksum) {
+ AcpiPlatformChecksum (
+ CurrentTableList->Table,
+ CurrentTableList->Table->Length,
+ OFFSET_OF (
+ EFI_ACPI_DESCRIPTION_HEADER,
+ Checksum
+ )
+ );
+ }
+
+ break;
+
+ case EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE:
+ //
+ // Check that the table has not been previously added.
+ //
+ if ((((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) && (AcpiTableInstance->Facs1 != NULL)) ||
+ (((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) && (AcpiTableInstance->Facs3 != NULL))
+ )
+ {
+ FreeTableMemory (CurrentTableList);
+ gBS->FreePool (CurrentTableList);
+ return EFI_ACCESS_DENIED;
+ }
+
+ //
+ // FACS is referenced by FADT and is not part of RSDT
+ //
+ AddToRsdt = FALSE;
+
+ //
+ // Add the table to the appropriate table version
+ //
+ if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ //
+ // Save a pointer to the table
+ //
+ AcpiTableInstance->Facs1 = (EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *)CurrentTableList->Table;
+
+ //
+ // If FADT already exists, update table pointers.
+ //
+ if (AcpiTableInstance->Fadt1 != NULL) {
+ AcpiTableInstance->Fadt1->FirmwareCtrl = (UINT32)(UINTN)AcpiTableInstance->Facs1;
+
+ //
+ // Checksum FADT table
+ //
+ AcpiPlatformChecksum (
+ AcpiTableInstance->Fadt1,
+ AcpiTableInstance->Fadt1->Header.Length,
+ OFFSET_OF (
+ EFI_ACPI_DESCRIPTION_HEADER,
+ Checksum
+ )
+ );
+ }
+ }
+
+ if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
+ //
+ // Save a pointer to the table
+ //
+ AcpiTableInstance->Facs3 = (EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE *)CurrentTableList->Table;
+
+ //
+ // If FADT already exists, update table pointers.
+ //
+ if (AcpiTableInstance->Fadt3 != NULL) {
+ //
+ // Note: If the FIRMWARE_CTRL is non-zero, then X_FIRMWARE_CTRL must be zero, and
+ // vice-versa.
+ //
+ if ((UINT64)(UINTN)AcpiTableInstance->Facs3 < BASE_4GB) {
+ AcpiTableInstance->Fadt3->FirmwareCtrl = (UINT32)(UINTN)AcpiTableInstance->Facs3;
+ ZeroMem (&AcpiTableInstance->Fadt3->XFirmwareCtrl, sizeof (UINT64));
+ } else {
+ Buffer64 = (UINT64)(UINTN)AcpiTableInstance->Facs3;
+ CopyMem (
+ &AcpiTableInstance->Fadt3->XFirmwareCtrl,
+ &Buffer64,
+ sizeof (UINT64)
+ );
+ AcpiTableInstance->Fadt3->FirmwareCtrl = 0;
+ }
+
+ //
+ // Checksum FADT table
+ //
+ AcpiPlatformChecksum (
+ AcpiTableInstance->Fadt3,
+ AcpiTableInstance->Fadt3->Header.Length,
+ OFFSET_OF (
+ EFI_ACPI_DESCRIPTION_HEADER,
+ Checksum
+ )
+ );
+ }
+ }
+
+ break;
+
+ case EFI_ACPI_1_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE:
+ //
+ // Check that the table has not been previously added.
+ //
+ if ((((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) && (AcpiTableInstance->Dsdt1 != NULL)) ||
+ (((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) && (AcpiTableInstance->Dsdt3 != NULL))
+ )
+ {
+ FreeTableMemory (CurrentTableList);
+ gBS->FreePool (CurrentTableList);
+ return EFI_ACCESS_DENIED;
+ }
+
+ //
+ // DSDT is referenced by FADT and is not part of RSDT
+ //
+ AddToRsdt = FALSE;
+
+ //
+ // Add the table to the appropriate table version
+ //
+ if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ //
+ // Save a pointer to the table
+ //
+ AcpiTableInstance->Dsdt1 = (EFI_ACPI_DESCRIPTION_HEADER *)CurrentTableList->Table;
+
+ //
+ // If FADT already exists, update table pointers.
+ //
+ if (AcpiTableInstance->Fadt1 != NULL) {
+ AcpiTableInstance->Fadt1->Dsdt = (UINT32)(UINTN)AcpiTableInstance->Dsdt1;
+
+ //
+ // Checksum FADT table
+ //
+ AcpiPlatformChecksum (
+ AcpiTableInstance->Fadt1,
+ AcpiTableInstance->Fadt1->Header.Length,
+ OFFSET_OF (
+ EFI_ACPI_DESCRIPTION_HEADER,
+ Checksum
+ )
+ );
+ }
+ }
+
+ if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
+ //
+ // Save a pointer to the table
+ //
+ AcpiTableInstance->Dsdt3 = (EFI_ACPI_DESCRIPTION_HEADER *)CurrentTableList->Table;
+
+ //
+ // If FADT already exists, update table pointers.
+ //
+ if (AcpiTableInstance->Fadt3 != NULL) {
+ if ((UINT64)(UINTN)AcpiTableInstance->Dsdt3 < BASE_4GB) {
+ AcpiTableInstance->Fadt3->Dsdt = (UINT32)(UINTN)AcpiTableInstance->Dsdt3;
+ //
+ // Comment block "the caller installs the tables in "FADT, DSDT" order"
+ // The below comments are also in "the caller installs the tables in "DSDT, FADT" order" comment block.
+ //
+ // The ACPI specification, up to and including revision 5.1 Errata A,
+ // allows the DSDT and X_DSDT fields to be both set in the FADT.
+ // (Obviously, this only makes sense if the DSDT address is representable in 4 bytes.)
+ // Starting with 5.1 Errata B, specifically for Mantis 1393 <https://mantis.uefi.org/mantis/view.php?id=1393>,
+ // the spec requires at most one of DSDT and X_DSDT fields to be set to a nonzero value,
+ // but strangely an exception is 6.0 that has no this requirement.
+ //
+ // Here we do not make the DSDT and X_DSDT fields mutual exclusion conditionally
+ // by checking FADT revision, but always set both DSDT and X_DSDT fields in the FADT
+ // to have better compatibility as some OS may have assumption to only consume X_DSDT
+ // field even the DSDT address is < 4G.
+ //
+ Buffer64 = AcpiTableInstance->Fadt3->Dsdt;
+ } else {
+ AcpiTableInstance->Fadt3->Dsdt = 0;
+ Buffer64 = (UINT64)(UINTN)AcpiTableInstance->Dsdt3;
+ }
+
+ CopyMem (&AcpiTableInstance->Fadt3->XDsdt, &Buffer64, sizeof (UINT64));
+
+ //
+ // Checksum FADT table
+ //
+ AcpiPlatformChecksum (
+ AcpiTableInstance->Fadt3,
+ AcpiTableInstance->Fadt3->Header.Length,
+ OFFSET_OF (
+ EFI_ACPI_DESCRIPTION_HEADER,
+ Checksum
+ )
+ );
+ }
+ }
+
+ //
+ // Checksum the table
+ //
+ if (Checksum) {
+ AcpiPlatformChecksum (
+ CurrentTableList->Table,
+ CurrentTableList->Table->Length,
+ OFFSET_OF (
+ EFI_ACPI_DESCRIPTION_HEADER,
+ Checksum
+ )
+ );
+ }
+
+ break;
+
+ default:
+ //
+ // Checksum the table
+ //
+ if (Checksum) {
+ AcpiPlatformChecksum (
+ CurrentTableList->Table,
+ CurrentTableList->Table->Length,
+ OFFSET_OF (
+ EFI_ACPI_DESCRIPTION_HEADER,
+ Checksum
+ )
+ );
+ }
+
+ break;
+ }
+
+ //
+ // Add the table to the current list of tables
+ //
+ InsertTailList (&AcpiTableInstance->TableList, &CurrentTableList->Link);
+
+ //
+ // Add the table to RSDT and/or XSDT table entry lists.
+ //
+ //
+ // Add to ACPI 1.0b table tree
+ //
+ if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ if (AddToRsdt) {
+ //
+ // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
+ //
+ if (AcpiTableInstance->NumberOfTableEntries1 >= mEfiAcpiMaxNumTables) {
+ Status = ReallocateAcpiTableBuffer (AcpiTableInstance);
+ ASSERT_EFI_ERROR (Status);
+ }
+
+ CurrentRsdtEntry = (UINT32 *)
+ (
+ (UINT8 *)AcpiTableInstance->Rsdt1 +
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER) +
+ AcpiTableInstance->NumberOfTableEntries1 *
+ sizeof (UINT32)
+ );
+
+ //
+ // Add entry to the RSDT unless its the FACS or DSDT
+ //
+ *CurrentRsdtEntry = (UINT32)(UINTN)CurrentTableList->Table;
+
+ //
+ // Update RSDT length
+ //
+ AcpiTableInstance->Rsdt1->Length = AcpiTableInstance->Rsdt1->Length + sizeof (UINT32);
+
+ AcpiTableInstance->NumberOfTableEntries1++;
+ }
+ }
+
+ //
+ // Add to ACPI 2.0/3.0 table tree
+ //
+ if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
+ if (AddToRsdt) {
+ //
+ // If the table number exceed the gEfiAcpiMaxNumTables, enlarge the table buffer
+ //
+ if (AcpiTableInstance->NumberOfTableEntries3 >= mEfiAcpiMaxNumTables) {
+ Status = ReallocateAcpiTableBuffer (AcpiTableInstance);
+ ASSERT_EFI_ERROR (Status);
+ }
+
+ if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ //
+ // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
+ // If it becomes necessary to maintain separate table lists, changes will be required.
+ //
+ CurrentRsdtEntry = (UINT32 *)
+ (
+ (UINT8 *)AcpiTableInstance->Rsdt3 +
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER) +
+ AcpiTableInstance->NumberOfTableEntries3 *
+ sizeof (UINT32)
+ );
+
+ //
+ // Add entry to the RSDT
+ //
+ *CurrentRsdtEntry = (UINT32)(UINTN)CurrentTableList->Table;
+
+ //
+ // Update RSDT length
+ //
+ AcpiTableInstance->Rsdt3->Length = AcpiTableInstance->Rsdt3->Length + sizeof (UINT32);
+ }
+
+ //
+ // This pointer must not be directly dereferenced as the XSDT entries may not
+ // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
+ //
+ CurrentXsdtEntry = (VOID *)
+ (
+ (UINT8 *)AcpiTableInstance->Xsdt +
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER) +
+ AcpiTableInstance->NumberOfTableEntries3 *
+ sizeof (UINT64)
+ );
+
+ //
+ // Add entry to XSDT, XSDT expects 64 bit pointers, but
+ // the table pointers in XSDT are not aligned on 8 byte boundary.
+ //
+ Buffer64 = (UINT64)(UINTN)CurrentTableList->Table;
+ CopyMem (
+ CurrentXsdtEntry,
+ &Buffer64,
+ sizeof (UINT64)
+ );
+
+ //
+ // Update length
+ //
+ AcpiTableInstance->Xsdt->Length = AcpiTableInstance->Xsdt->Length + sizeof (UINT64);
+
+ AcpiTableInstance->NumberOfTableEntries3++;
+ }
+ }
+
+ ChecksumCommonTables (AcpiTableInstance);
+ return EFI_SUCCESS;
+}
+
+/**
+ This function finds the table specified by the handle and returns a pointer to it.
+ If the handle is not found, EFI_NOT_FOUND is returned and the contents of Table are
+ undefined.
+
+ @param Handle Table to find.
+ @param TableList Table list to search
+ @param Table Pointer to table found.
+
+ @return EFI_SUCCESS The function completed successfully.
+ @return EFI_NOT_FOUND No table found matching the handle specified.
+
+**/
+EFI_STATUS
+FindTableByHandle (
+ IN UINTN Handle,
+ IN LIST_ENTRY *TableList,
+ OUT EFI_ACPI_TABLE_LIST **Table
+ )
+{
+ LIST_ENTRY *CurrentLink;
+ EFI_ACPI_TABLE_LIST *CurrentTable;
+
+ //
+ // Check for invalid input parameters
+ //
+ ASSERT (Table);
+
+ //
+ // Find the table
+ //
+ CurrentLink = TableList->ForwardLink;
+
+ while (CurrentLink != TableList) {
+ CurrentTable = EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink);
+ if (CurrentTable->Handle == Handle) {
+ //
+ // Found handle, so return this table.
+ //
+ *Table = CurrentTable;
+ return EFI_SUCCESS;
+ }
+
+ CurrentLink = CurrentLink->ForwardLink;
+ }
+
+ //
+ // Table not found
+ //
+ return EFI_NOT_FOUND;
+}
+
+/**
+ This function removes a basic table from the RSDT and/or XSDT.
+ For Acpi 1.0 tables, pass in the Rsdt.
+ For Acpi 2.0 tables, pass in both Rsdt and Xsdt.
+
+ @param Table Pointer to table found.
+ @param NumberOfTableEntries Current number of table entries in the RSDT/XSDT
+ @param Rsdt Pointer to the RSDT to remove from
+ @param Xsdt Pointer to the Xsdt to remove from
+
+ @return EFI_SUCCESS The function completed successfully.
+ @return EFI_INVALID_PARAMETER The table was not found in both Rsdt and Xsdt.
+
+**/
+EFI_STATUS
+RemoveTableFromRsdt (
+ IN OUT EFI_ACPI_TABLE_LIST *Table,
+ IN OUT UINTN *NumberOfTableEntries,
+ IN OUT EFI_ACPI_DESCRIPTION_HEADER *Rsdt OPTIONAL,
+ IN OUT EFI_ACPI_DESCRIPTION_HEADER *Xsdt OPTIONAL
+ )
+{
+ UINT32 *CurrentRsdtEntry;
+ VOID *CurrentXsdtEntry;
+ UINT64 CurrentTablePointer64;
+ UINTN Index;
+
+ //
+ // Check for invalid input parameters
+ //
+ ASSERT (Table);
+ ASSERT (NumberOfTableEntries);
+ ASSERT (Rsdt || Xsdt);
+
+ //
+ // Find the table entry in the RSDT and XSDT
+ //
+ for (Index = 0; Index < *NumberOfTableEntries; Index++) {
+ //
+ // At this time, it is assumed that RSDT and XSDT maintain parallel lists of tables.
+ // If it becomes necessary to maintain separate table lists, changes will be required.
+ //
+ if (Rsdt != NULL) {
+ CurrentRsdtEntry = (UINT32 *)((UINT8 *)Rsdt + sizeof (EFI_ACPI_DESCRIPTION_HEADER) + Index * sizeof (UINT32));
+ } else {
+ CurrentRsdtEntry = NULL;
+ }
+
+ if (Xsdt != NULL) {
+ //
+ // This pointer must not be directly dereferenced as the XSDT entries may not
+ // be 64 bit aligned resulting in a possible fault. Use CopyMem to update.
+ //
+ CurrentXsdtEntry = (VOID *)((UINT8 *)Xsdt + sizeof (EFI_ACPI_DESCRIPTION_HEADER) + Index * sizeof (UINT64));
+
+ //
+ // Read the entry value out of the XSDT
+ //
+ CopyMem (&CurrentTablePointer64, CurrentXsdtEntry, sizeof (UINT64));
+ } else {
+ //
+ // Initialize to NULL
+ //
+ CurrentXsdtEntry = 0;
+ CurrentTablePointer64 = 0;
+ }
+
+ //
+ // Check if we have found the corresponding entry in both RSDT and XSDT
+ //
+ if (((Rsdt == NULL) || (*CurrentRsdtEntry == (UINT32)(UINTN)Table->Table)) &&
+ ((Xsdt == NULL) || (CurrentTablePointer64 == (UINT64)(UINTN)Table->Table))
+ )
+ {
+ //
+ // Found entry, so copy all following entries and shrink table
+ // We actually copy all + 1 to copy the initialized value of memory over
+ // the last entry.
+ //
+ if (Rsdt != NULL) {
+ CopyMem (CurrentRsdtEntry, CurrentRsdtEntry + 1, (*NumberOfTableEntries - Index) * sizeof (UINT32));
+ Rsdt->Length = Rsdt->Length - sizeof (UINT32);
+ }
+
+ if (Xsdt != NULL) {
+ CopyMem (CurrentXsdtEntry, ((UINT64 *)CurrentXsdtEntry) + 1, (*NumberOfTableEntries - Index) * sizeof (UINT64));
+ Xsdt->Length = Xsdt->Length - sizeof (UINT64);
+ }
+
+ break;
+ } else if (Index + 1 == *NumberOfTableEntries) {
+ //
+ // At the last entry, and table not found
+ //
+ return EFI_INVALID_PARAMETER;
+ }
+ }
+
+ //
+ // Checksum the tables
+ //
+ if (Rsdt != NULL) {
+ AcpiPlatformChecksum (
+ Rsdt,
+ Rsdt->Length,
+ OFFSET_OF (
+ EFI_ACPI_DESCRIPTION_HEADER,
+ Checksum
+ )
+ );
+ }
+
+ if (Xsdt != NULL) {
+ AcpiPlatformChecksum (
+ Xsdt,
+ Xsdt->Length,
+ OFFSET_OF (
+ EFI_ACPI_DESCRIPTION_HEADER,
+ Checksum
+ )
+ );
+ }
+
+ //
+ // Decrement the number of tables
+ //
+ (*NumberOfTableEntries)--;
+
+ return EFI_SUCCESS;
+}
+
+/**
+ This function removes a table and frees any associated memory.
+
+ @param AcpiTableInstance Instance of the protocol.
+ @param Version Version(s) to delete.
+ @param Table Pointer to table found.
+
+ @return EFI_SUCCESS The function completed successfully.
+
+**/
+EFI_STATUS
+DeleteTable (
+ IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
+ IN EFI_ACPI_TABLE_VERSION Version,
+ IN OUT EFI_ACPI_TABLE_LIST *Table
+ )
+{
+ UINT32 CurrentTableSignature;
+ BOOLEAN RemoveFromRsdt;
+
+ //
+ // Check for invalid input parameters
+ //
+ ASSERT (AcpiTableInstance);
+ ASSERT (Table);
+
+ //
+ // Init locals
+ //
+ RemoveFromRsdt = TRUE;
+ //
+ // Check for Table->Table
+ //
+ ASSERT (Table->Table != NULL);
+ CurrentTableSignature = ((EFI_ACPI_COMMON_HEADER *)Table->Table)->Signature;
+
+ //
+ // Basic tasks to accomplish delete are:
+ // Determine removal requirements (in RSDT/XSDT or not)
+ // Remove entry from RSDT/XSDT
+ // Remove any table references to the table
+ // If no one is using the table
+ // Free the table (removing pointers from private data and tables)
+ // Remove from list
+ // Free list structure
+ //
+ //
+ // Determine if this table is in the RSDT or XSDT
+ //
+ if ((CurrentTableSignature == EFI_ACPI_1_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE) ||
+ (CurrentTableSignature == EFI_ACPI_2_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE) ||
+ (CurrentTableSignature == EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE)
+ )
+ {
+ RemoveFromRsdt = FALSE;
+ }
+
+ //
+ // We don't remove the FADT in the standard way because some
+ // OS expect the FADT to be early in the table list.
+ // So we always put it as the first element in the list.
+ //
+ if (CurrentTableSignature == EFI_ACPI_1_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {
+ RemoveFromRsdt = FALSE;
+ }
+
+ //
+ // Remove the table from RSDT and XSDT
+ //
+ if (Table->Table != NULL) {
+ //
+ // This is a basic table, remove it from any lists and the Rsdt and/or Xsdt
+ //
+ if (Version & EFI_ACPI_TABLE_VERSION_NONE & Table->Version) {
+ //
+ // Remove this version from the table
+ //
+ Table->Version = Table->Version &~EFI_ACPI_TABLE_VERSION_NONE;
+ }
+
+ if (Version & EFI_ACPI_TABLE_VERSION_1_0B & Table->Version) {
+ //
+ // Remove this version from the table
+ //
+ Table->Version = Table->Version &~EFI_ACPI_TABLE_VERSION_1_0B;
+
+ //
+ // Remove from Rsdt. We don't care about the return value because it is
+ // acceptable for the table to not exist in Rsdt.
+ // We didn't add some tables so we don't remove them.
+ //
+ if (RemoveFromRsdt) {
+ RemoveTableFromRsdt (
+ Table,
+ &AcpiTableInstance->NumberOfTableEntries1,
+ AcpiTableInstance->Rsdt1,
+ NULL
+ );
+ }
+ }
+
+ if (Version & ACPI_TABLE_VERSION_GTE_2_0 & Table->Version) {
+ //
+ // Remove this version from the table
+ //
+ Table->Version = Table->Version &~(Version & ACPI_TABLE_VERSION_GTE_2_0);
+
+ //
+ // Remove from Rsdt and Xsdt. We don't care about the return value
+ // because it is acceptable for the table to not exist in Rsdt/Xsdt.
+ // We didn't add some tables so we don't remove them.
+ //
+ if (RemoveFromRsdt) {
+ RemoveTableFromRsdt (
+ Table,
+ &AcpiTableInstance->NumberOfTableEntries3,
+ AcpiTableInstance->Rsdt3,
+ AcpiTableInstance->Xsdt
+ );
+ }
+ }
+
+ //
+ // Free the table, clean up any dependent tables and our private data pointers.
+ //
+ switch (Table->Table->Signature) {
+ case EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE:
+ if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ AcpiTableInstance->Fadt1 = NULL;
+ }
+
+ if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
+ AcpiTableInstance->Fadt3 = NULL;
+ }
+
+ break;
+
+ case EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE:
+ if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ AcpiTableInstance->Facs1 = NULL;
+
+ //
+ // Update FADT table pointers
+ //
+ if (AcpiTableInstance->Fadt1 != NULL) {
+ AcpiTableInstance->Fadt1->FirmwareCtrl = 0;
+
+ //
+ // Checksum table
+ //
+ AcpiPlatformChecksum (
+ AcpiTableInstance->Fadt1,
+ AcpiTableInstance->Fadt1->Header.Length,
+ OFFSET_OF (
+ EFI_ACPI_DESCRIPTION_HEADER,
+ Checksum
+ )
+ );
+ }
+ }
+
+ if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
+ AcpiTableInstance->Facs3 = NULL;
+
+ //
+ // Update FADT table pointers
+ //
+ if (AcpiTableInstance->Fadt3 != NULL) {
+ AcpiTableInstance->Fadt3->FirmwareCtrl = 0;
+ ZeroMem (&AcpiTableInstance->Fadt3->XFirmwareCtrl, sizeof (UINT64));
+
+ //
+ // Checksum table
+ //
+ AcpiPlatformChecksum (
+ AcpiTableInstance->Fadt3,
+ AcpiTableInstance->Fadt3->Header.Length,
+ OFFSET_OF (
+ EFI_ACPI_DESCRIPTION_HEADER,
+ Checksum
+ )
+ );
+ }
+ }
+
+ break;
+
+ case EFI_ACPI_3_0_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE:
+ if ((Version & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ AcpiTableInstance->Dsdt1 = NULL;
+
+ //
+ // Update FADT table pointers
+ //
+ if (AcpiTableInstance->Fadt1 != NULL) {
+ AcpiTableInstance->Fadt1->Dsdt = 0;
+
+ //
+ // Checksum table
+ //
+ AcpiPlatformChecksum (
+ AcpiTableInstance->Fadt1,
+ AcpiTableInstance->Fadt1->Header.Length,
+ OFFSET_OF (
+ EFI_ACPI_DESCRIPTION_HEADER,
+ Checksum
+ )
+ );
+ }
+ }
+
+ if ((Version & ACPI_TABLE_VERSION_GTE_2_0) != 0) {
+ AcpiTableInstance->Dsdt3 = NULL;
+
+ //
+ // Update FADT table pointers
+ //
+ if (AcpiTableInstance->Fadt3 != NULL) {
+ AcpiTableInstance->Fadt3->Dsdt = 0;
+ ZeroMem (&AcpiTableInstance->Fadt3->XDsdt, sizeof (UINT64));
+
+ //
+ // Checksum table
+ //
+ AcpiPlatformChecksum (
+ AcpiTableInstance->Fadt3,
+ AcpiTableInstance->Fadt3->Header.Length,
+ OFFSET_OF (
+ EFI_ACPI_DESCRIPTION_HEADER,
+ Checksum
+ )
+ );
+ }
+ }
+
+ break;
+
+ default:
+ //
+ // Do nothing
+ //
+ break;
+ }
+ }
+
+ //
+ // If no version is using this table anymore, remove and free list entry.
+ //
+ if (Table->Version == 0) {
+ //
+ // Free the Table
+ //
+ FreeTableMemory (Table);
+ RemoveEntryList (&(Table->Link));
+ gBS->FreePool (Table);
+ }
+
+ //
+ // Done
+ //
+ return EFI_SUCCESS;
+}
+
+/**
+ This function finds and removes the table specified by the handle.
+
+ @param AcpiTableInstance Instance of the protocol.
+ @param Version Bitmask of which versions to remove.
+ @param Handle Table to remove.
+
+ @return EFI_SUCCESS The function completed successfully.
+ @return EFI_ABORTED An error occurred.
+ @return EFI_NOT_FOUND Handle not found in table list.
+
+**/
+EFI_STATUS
+RemoveTableFromList (
+ IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance,
+ IN EFI_ACPI_TABLE_VERSION Version,
+ IN UINTN Handle
+ )
+{
+ EFI_ACPI_TABLE_LIST *Table;
+ EFI_STATUS Status;
+
+ Table = (EFI_ACPI_TABLE_LIST *)NULL;
+
+ //
+ // Check for invalid input parameters
+ //
+ ASSERT (AcpiTableInstance);
+
+ //
+ // Find the table
+ //
+ Status = FindTableByHandle (
+ Handle,
+ &AcpiTableInstance->TableList,
+ &Table
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_NOT_FOUND;
+ }
+
+ //
+ // Remove the table
+ //
+ Status = DeleteTable (AcpiTableInstance, Version, Table);
+ if (EFI_ERROR (Status)) {
+ return EFI_ABORTED;
+ }
+
+ //
+ // Completed successfully
+ //
+ return EFI_SUCCESS;
+}
+
+/**
+ This function calculates and updates an UINT8 checksum.
+
+ @param Buffer Pointer to buffer to checksum
+ @param Size Number of bytes to checksum
+ @param ChecksumOffset Offset to place the checksum result in
+
+ @return EFI_SUCCESS The function completed successfully.
+
+**/
+EFI_STATUS
+AcpiPlatformChecksum (
+ IN VOID *Buffer,
+ IN UINTN Size,
+ IN UINTN ChecksumOffset
+ )
+{
+ UINT8 Sum;
+ UINT8 *Ptr;
+
+ Sum = 0;
+ //
+ // Initialize pointer
+ //
+ Ptr = Buffer;
+
+ //
+ // set checksum to 0 first
+ //
+ Ptr[ChecksumOffset] = 0;
+
+ //
+ // add all content of buffer
+ //
+ while ((Size--) != 0) {
+ Sum = (UINT8)(Sum + (*Ptr++));
+ }
+
+ //
+ // set checksum
+ //
+ Ptr = Buffer;
+ Ptr[ChecksumOffset] = (UINT8)(0xff - Sum + 1);
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Checksum all versions of the common tables, RSDP, RSDT, XSDT.
+
+ @param AcpiTableInstance Protocol instance private data.
+
+ @return EFI_SUCCESS The function completed successfully.
+
+**/
+EFI_STATUS
+ChecksumCommonTables (
+ IN OUT EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance
+ )
+{
+ //
+ // RSDP ACPI 1.0 checksum for 1.0 table. This is only the first 20 bytes of the structure
+ //
+ if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ AcpiPlatformChecksum (
+ AcpiTableInstance->Rsdp1,
+ sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER),
+ OFFSET_OF (
+ EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER,
+ Checksum
+ )
+ );
+ }
+
+ //
+ // RSDP ACPI 1.0 checksum for 2.0/3.0 table. This is only the first 20 bytes of the structure
+ //
+ AcpiPlatformChecksum (
+ AcpiTableInstance->Rsdp3,
+ sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER),
+ OFFSET_OF (
+ EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER,
+ Checksum
+ )
+ );
+
+ //
+ // RSDP ACPI 2.0/3.0 checksum, this is the entire table
+ //
+ AcpiPlatformChecksum (
+ AcpiTableInstance->Rsdp3,
+ sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER),
+ OFFSET_OF (
+ EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER,
+ ExtendedChecksum
+ )
+ );
+
+ if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ //
+ // RSDT checksums
+ //
+ AcpiPlatformChecksum (
+ AcpiTableInstance->Rsdt1,
+ AcpiTableInstance->Rsdt1->Length,
+ OFFSET_OF (
+ EFI_ACPI_DESCRIPTION_HEADER,
+ Checksum
+ )
+ );
+
+ AcpiPlatformChecksum (
+ AcpiTableInstance->Rsdt3,
+ AcpiTableInstance->Rsdt3->Length,
+ OFFSET_OF (
+ EFI_ACPI_DESCRIPTION_HEADER,
+ Checksum
+ )
+ );
+ }
+
+ //
+ // XSDT checksum
+ //
+ AcpiPlatformChecksum (
+ AcpiTableInstance->Xsdt,
+ AcpiTableInstance->Xsdt->Length,
+ OFFSET_OF (
+ EFI_ACPI_DESCRIPTION_HEADER,
+ Checksum
+ )
+ );
+
+ return EFI_SUCCESS;
+}
+
+/**
+ This function will find gUniversalPayloadAcpiTableGuid Guid Hob, and install Acpi table from it.
+
+ @param AcpiTableInstance Protocol instance private data.
+
+ @return EFI_SUCCESS The function completed successfully.
+ @return EFI_NOT_FOUND The function doesn't find the gEfiAcpiTableGuid Guid Hob.
+ @return EFI_ABORTED The function could not complete successfully.
+
+**/
+EFI_STATUS
+InstallAcpiTableFromHob (
+ EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance
+ )
+{
+ EFI_HOB_GUID_TYPE *GuidHob;
+ EFI_ACPI_TABLE_VERSION Version;
+ EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *Rsdp;
+ EFI_ACPI_DESCRIPTION_HEADER *Rsdt;
+ EFI_ACPI_DESCRIPTION_HEADER *ChildTable;
+ UINT64 ChildTableAddress;
+ UINTN Count;
+ UINTN Index;
+ UINTN TableKey;
+ EFI_STATUS Status;
+ UINTN EntrySize;
+ UNIVERSAL_PAYLOAD_ACPI_TABLE *AcpiTableAdress;
+ VOID *TableToInstall;
+ EFI_ACPI_SDT_HEADER *Table;
+ UNIVERSAL_PAYLOAD_GENERIC_HEADER *GenericHeader;
+
+ TableKey = 0;
+ Version = PcdGet32 (PcdAcpiExposedTableVersions);
+ Status = EFI_SUCCESS;
+ //
+ // HOB only contains the ACPI table in 2.0+ format.
+ //
+ GuidHob = GetFirstGuidHob (&gUniversalPayloadAcpiTableGuid);
+ if (GuidHob == NULL) {
+ return EFI_NOT_FOUND;
+ }
+
+ GenericHeader = (UNIVERSAL_PAYLOAD_GENERIC_HEADER *)GET_GUID_HOB_DATA (GuidHob);
+ if ((sizeof (UNIVERSAL_PAYLOAD_GENERIC_HEADER) > GET_GUID_HOB_DATA_SIZE (GuidHob)) || (GenericHeader->Length > GET_GUID_HOB_DATA_SIZE (GuidHob))) {
+ return EFI_NOT_FOUND;
+ }
+
+ if (GenericHeader->Revision == UNIVERSAL_PAYLOAD_ACPI_TABLE_REVISION) {
+ //
+ // UNIVERSAL_PAYLOAD_ACPI_TABLE structure is used when Revision equals to UNIVERSAL_PAYLOAD_ACPI_TABLE_REVISION
+ //
+ AcpiTableAdress = (UNIVERSAL_PAYLOAD_ACPI_TABLE *)GET_GUID_HOB_DATA (GuidHob);
+ if (AcpiTableAdress->Header.Length < UNIVERSAL_PAYLOAD_SIZEOF_THROUGH_FIELD (UNIVERSAL_PAYLOAD_ACPI_TABLE, Rsdp)) {
+ //
+ // Retrun if can't find the ACPI Info Hob with enough length
+ //
+ return EFI_NOT_FOUND;
+ }
+
+ Rsdp = (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *)(UINTN)(AcpiTableAdress->Rsdp);
+
+ //
+ // An ACPI-compatible OS must use the XSDT if present.
+ // It shouldn't happen that XsdtAddress points beyond 4G range in 32-bit environment.
+ //
+ ASSERT ((UINTN)Rsdp->XsdtAddress == Rsdp->XsdtAddress);
+
+ EntrySize = sizeof (UINT64);
+ Rsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->XsdtAddress;
+ if (Rsdt == NULL) {
+ //
+ // XsdtAddress is zero, then we use Rsdt which has 32 bit entry
+ //
+ Rsdt = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)Rsdp->RsdtAddress;
+ EntrySize = sizeof (UINT32);
+ }
+
+ if (Rsdt->Length <= sizeof (EFI_ACPI_DESCRIPTION_HEADER)) {
+ return EFI_ABORTED;
+ }
+
+ Count = (Rsdt->Length - sizeof (EFI_ACPI_DESCRIPTION_HEADER)) / EntrySize;
+
+ for (Index = 0; Index < Count; Index++) {
+ ChildTableAddress = 0;
+ CopyMem (&ChildTableAddress, (UINT8 *)(Rsdt + 1) + EntrySize * Index, EntrySize);
+ //
+ // If the address is of UINT64 while this module runs at 32 bits,
+ // make sure the upper bits are all-zeros.
+ //
+ ASSERT (ChildTableAddress == (UINTN)ChildTableAddress);
+ if (ChildTableAddress != (UINTN)ChildTableAddress) {
+ Status = EFI_ABORTED;
+ break;
+ }
+
+ ChildTable = (EFI_ACPI_DESCRIPTION_HEADER *)(UINTN)ChildTableAddress;
+ Status = AddTableToList (AcpiTableInstance, ChildTable, TRUE, Version, TRUE, &TableKey);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "InstallAcpiTableFromHob: Fail to add ACPI table at 0x%p\n", ChildTable));
+ ASSERT_EFI_ERROR (Status);
+ break;
+ }
+
+ if (ChildTable->Signature == EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE) {
+ //
+ // Add the FACS and DSDT tables if it is not NULL.
+ //
+ if (((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)ChildTable)->FirmwareCtrl != 0) {
+ TableToInstall = (VOID *)(UINTN)((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)ChildTable)->FirmwareCtrl;
+ Status = AddTableToList (AcpiTableInstance, TableToInstall, TRUE, Version, TRUE, &TableKey);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "InstallAcpiTableFromHob: Fail to add ACPI table FACS\n"));
+ ASSERT_EFI_ERROR (Status);
+ break;
+ }
+ }
+
+ //
+ // First check if xDSDT is available, as that is preferred as per
+ // ACPI Spec 6.5+ Table 5-9 X_DSDT definition
+ //
+ if (((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)ChildTable)->XDsdt != 0) {
+ TableToInstall = (VOID *)(UINTN)((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)ChildTable)->XDsdt;
+ } else if (((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)ChildTable)->Dsdt != 0) {
+ TableToInstall = (VOID *)(UINTN)((EFI_ACPI_3_0_FIXED_ACPI_DESCRIPTION_TABLE *)ChildTable)->Dsdt;
+ } else {
+ DEBUG ((DEBUG_ERROR, "DSDT table not found\n"));
+ continue;
+ }
+
+ Status = AddTableToList (AcpiTableInstance, TableToInstall, TRUE, Version, TRUE, &TableKey);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "InstallAcpiTableFromHob: Fail to add ACPI table DSDT\n"));
+ ASSERT_EFI_ERROR (Status);
+ break;
+ }
+ }
+ }
+ } else {
+ return EFI_NOT_FOUND;
+ }
+
+ if (EFI_ERROR (Status)) {
+ //
+ // Error happens when trying to add ACPI table to the list.
+ // Remove all of them from list because at this time, no other tables except from HOB are in the list
+ //
+ while (SdtGetAcpiTable (AcpiTableInstance, 0, &Table, &Version, &TableKey) == EFI_SUCCESS) {
+ RemoveTableFromList (AcpiTableInstance, Version, TableKey);
+ }
+ } else {
+ Status = PublishTables (AcpiTableInstance, Version);
+ }
+
+ ASSERT_EFI_ERROR (Status);
+ return Status;
+}
+
+/**
+ Constructor for the ACPI table protocol. Initializes instance
+ data.
+
+ @param AcpiTableInstance Instance to construct
+
+ @return EFI_SUCCESS Instance initialized.
+ @return EFI_OUT_OF_RESOURCES Unable to allocate required resources.
+
+**/
+EFI_STATUS
+AcpiTableAcpiTableConstructor (
+ EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance
+ )
+{
+ EFI_STATUS Status;
+ UINT64 CurrentData;
+ UINTN TotalSize;
+ UINTN RsdpTableSize;
+ UINT8 *Pointer;
+ EFI_PHYSICAL_ADDRESS PageAddress;
+ EFI_MEMORY_TYPE AcpiAllocateMemoryType;
+
+ //
+ // Check for invalid input parameters
+ //
+ ASSERT (AcpiTableInstance);
+
+ //
+ // If ACPI v1.0b is among the ACPI versions we aim to support, we have to
+ // ensure that all memory allocations are below 4 GB.
+ //
+ if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ mAcpiTableAllocType = AllocateMaxAddress;
+ } else {
+ mAcpiTableAllocType = AllocateAnyPages;
+ }
+
+ InitializeListHead (&AcpiTableInstance->TableList);
+ AcpiTableInstance->CurrentHandle = 1;
+
+ AcpiTableInstance->AcpiTableProtocol.InstallAcpiTable = InstallAcpiTable;
+ AcpiTableInstance->AcpiTableProtocol.UninstallAcpiTable = UninstallAcpiTable;
+
+ if (FeaturePcdGet (PcdInstallAcpiSdtProtocol)) {
+ SdtAcpiTableAcpiSdtConstructor (AcpiTableInstance);
+ }
+
+ //
+ // Create RSDP table
+ //
+ RsdpTableSize = sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER);
+ if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ RsdpTableSize += sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER);
+ }
+
+ if (PcdGetBool (PcdNoACPIReclaimMemory)) {
+ AcpiAllocateMemoryType = EfiACPIMemoryNVS;
+ } else {
+ AcpiAllocateMemoryType = EfiACPIReclaimMemory;
+ }
+
+ if (mAcpiTableAllocType != AllocateAnyPages) {
+ PageAddress = 0xFFFFFFFF;
+ Status = gBS->AllocatePages (
+ mAcpiTableAllocType,
+ AcpiAllocateMemoryType,
+ EFI_SIZE_TO_PAGES (RsdpTableSize),
+ &PageAddress
+ );
+ } else {
+ Status = gBS->AllocatePool (
+ AcpiAllocateMemoryType,
+ RsdpTableSize,
+ (VOID **)&Pointer
+ );
+ }
+
+ if (EFI_ERROR (Status)) {
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ if (mAcpiTableAllocType != AllocateAnyPages) {
+ Pointer = (UINT8 *)(UINTN)PageAddress;
+ }
+
+ ZeroMem (Pointer, RsdpTableSize);
+
+ AcpiTableInstance->Rsdp1 = (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER *)Pointer;
+ if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ Pointer += sizeof (EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER);
+ }
+
+ AcpiTableInstance->Rsdp3 = (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER *)Pointer;
+
+ //
+ // Create RSDT, XSDT structures
+ //
+ TotalSize = sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 2.0/3.0 XSDT
+ mEfiAcpiMaxNumTables * sizeof (UINT64);
+
+ if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ TotalSize += sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 1.0 RSDT
+ mEfiAcpiMaxNumTables * sizeof (UINT32) +
+ sizeof (EFI_ACPI_DESCRIPTION_HEADER) + // for ACPI 2.0/3.0 RSDT
+ mEfiAcpiMaxNumTables * sizeof (UINT32);
+ }
+
+ if (mAcpiTableAllocType != AllocateAnyPages) {
+ //
+ // Allocate memory in the lower 32 bit of address range for
+ // compatibility with ACPI 1.0 OS.
+ //
+ // This is done because ACPI 1.0 pointers are 32 bit values.
+ // ACPI 2.0 OS and all 64 bit OS must use the 64 bit ACPI table addresses.
+ // There is no architectural reason these should be below 4GB, it is purely
+ // for convenience of implementation that we force memory below 4GB.
+ //
+ PageAddress = 0xFFFFFFFF;
+ Status = gBS->AllocatePages (
+ mAcpiTableAllocType,
+ AcpiAllocateMemoryType,
+ EFI_SIZE_TO_PAGES (TotalSize),
+ &PageAddress
+ );
+ } else {
+ Status = gBS->AllocatePool (
+ AcpiAllocateMemoryType,
+ TotalSize,
+ (VOID **)&Pointer
+ );
+ }
+
+ if (EFI_ERROR (Status)) {
+ if (mAcpiTableAllocType != AllocateAnyPages) {
+ gBS->FreePages (
+ (EFI_PHYSICAL_ADDRESS)(UINTN)AcpiTableInstance->Rsdp1,
+ EFI_SIZE_TO_PAGES (RsdpTableSize)
+ );
+ } else {
+ gBS->FreePool (AcpiTableInstance->Rsdp1);
+ }
+
+ return EFI_OUT_OF_RESOURCES;
+ }
+
+ if (mAcpiTableAllocType != AllocateAnyPages) {
+ Pointer = (UINT8 *)(UINTN)PageAddress;
+ }
+
+ ZeroMem (Pointer, TotalSize);
+
+ AcpiTableInstance->Rsdt1 = (EFI_ACPI_DESCRIPTION_HEADER *)Pointer;
+ if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ Pointer += (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + EFI_ACPI_MAX_NUM_TABLES * sizeof (UINT32));
+ AcpiTableInstance->Rsdt3 = (EFI_ACPI_DESCRIPTION_HEADER *)Pointer;
+ Pointer += (sizeof (EFI_ACPI_DESCRIPTION_HEADER) + EFI_ACPI_MAX_NUM_TABLES * sizeof (UINT32));
+ }
+
+ AcpiTableInstance->Xsdt = (EFI_ACPI_DESCRIPTION_HEADER *)Pointer;
+
+ //
+ // Initialize RSDP
+ //
+ if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ CurrentData = EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE;
+ CopyMem (&AcpiTableInstance->Rsdp1->Signature, &CurrentData, sizeof (UINT64));
+ CopyMem (AcpiTableInstance->Rsdp1->OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (AcpiTableInstance->Rsdp1->OemId));
+ AcpiTableInstance->Rsdp1->Reserved = EFI_ACPI_RESERVED_BYTE;
+ AcpiTableInstance->Rsdp1->RsdtAddress = (UINT32)(UINTN)AcpiTableInstance->Rsdt1;
+ }
+
+ CurrentData = EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_SIGNATURE;
+ CopyMem (&AcpiTableInstance->Rsdp3->Signature, &CurrentData, sizeof (UINT64));
+ CopyMem (AcpiTableInstance->Rsdp3->OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (AcpiTableInstance->Rsdp3->OemId));
+ AcpiTableInstance->Rsdp3->Revision = EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER_REVISION;
+ AcpiTableInstance->Rsdp3->Length = sizeof (EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_POINTER);
+ if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ AcpiTableInstance->Rsdp3->RsdtAddress = (UINT32)(UINTN)AcpiTableInstance->Rsdt3;
+ }
+
+ CurrentData = (UINT64)(UINTN)AcpiTableInstance->Xsdt;
+ CopyMem (&AcpiTableInstance->Rsdp3->XsdtAddress, &CurrentData, sizeof (UINT64));
+ SetMem (AcpiTableInstance->Rsdp3->Reserved, 3, EFI_ACPI_RESERVED_BYTE);
+
+ if ((PcdGet32 (PcdAcpiExposedTableVersions) & EFI_ACPI_TABLE_VERSION_1_0B) != 0) {
+ //
+ // Initialize Rsdt
+ //
+ // Note that we "reserve" one entry for the FADT so it can always be
+ // at the beginning of the list of tables. Some OS don't seem
+ // to find it correctly if it is too far down the list.
+ //
+ AcpiTableInstance->Rsdt1->Signature = EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE;
+ AcpiTableInstance->Rsdt1->Length = sizeof (EFI_ACPI_DESCRIPTION_HEADER);
+ AcpiTableInstance->Rsdt1->Revision = EFI_ACPI_1_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION;
+ CopyMem (AcpiTableInstance->Rsdt1->OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (AcpiTableInstance->Rsdt1->OemId));
+ CurrentData = PcdGet64 (PcdAcpiDefaultOemTableId);
+ CopyMem (&AcpiTableInstance->Rsdt1->OemTableId, &CurrentData, sizeof (UINT64));
+ AcpiTableInstance->Rsdt1->OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision);
+ AcpiTableInstance->Rsdt1->CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId);
+ AcpiTableInstance->Rsdt1->CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision);
+ //
+ // We always reserve first one for FADT
+ //
+ AcpiTableInstance->NumberOfTableEntries1 = 1;
+ AcpiTableInstance->Rsdt1->Length = AcpiTableInstance->Rsdt1->Length + sizeof (UINT32);
+
+ AcpiTableInstance->Rsdt3->Signature = EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_SIGNATURE;
+ AcpiTableInstance->Rsdt3->Length = sizeof (EFI_ACPI_DESCRIPTION_HEADER);
+ AcpiTableInstance->Rsdt3->Revision = EFI_ACPI_3_0_ROOT_SYSTEM_DESCRIPTION_TABLE_REVISION;
+ CopyMem (AcpiTableInstance->Rsdt3->OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (AcpiTableInstance->Rsdt3->OemId));
+ CurrentData = PcdGet64 (PcdAcpiDefaultOemTableId);
+ CopyMem (&AcpiTableInstance->Rsdt3->OemTableId, &CurrentData, sizeof (UINT64));
+ AcpiTableInstance->Rsdt3->OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision);
+ AcpiTableInstance->Rsdt3->CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId);
+ AcpiTableInstance->Rsdt3->CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision);
+ //
+ // We always reserve first one for FADT
+ //
+ AcpiTableInstance->Rsdt3->Length = AcpiTableInstance->Rsdt3->Length + sizeof (UINT32);
+ }
+
+ AcpiTableInstance->NumberOfTableEntries3 = 1;
+
+ //
+ // Initialize Xsdt
+ //
+ AcpiTableInstance->Xsdt->Signature = EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE;
+ AcpiTableInstance->Xsdt->Length = sizeof (EFI_ACPI_DESCRIPTION_HEADER);
+ AcpiTableInstance->Xsdt->Revision = EFI_ACPI_3_0_EXTENDED_SYSTEM_DESCRIPTION_TABLE_REVISION;
+ CopyMem (AcpiTableInstance->Xsdt->OemId, PcdGetPtr (PcdAcpiDefaultOemId), sizeof (AcpiTableInstance->Xsdt->OemId));
+ CurrentData = PcdGet64 (PcdAcpiDefaultOemTableId);
+ CopyMem (&AcpiTableInstance->Xsdt->OemTableId, &CurrentData, sizeof (UINT64));
+ AcpiTableInstance->Xsdt->OemRevision = PcdGet32 (PcdAcpiDefaultOemRevision);
+ AcpiTableInstance->Xsdt->CreatorId = PcdGet32 (PcdAcpiDefaultCreatorId);
+ AcpiTableInstance->Xsdt->CreatorRevision = PcdGet32 (PcdAcpiDefaultCreatorRevision);
+ //
+ // We always reserve first one for FADT
+ //
+ AcpiTableInstance->Xsdt->Length = AcpiTableInstance->Xsdt->Length + sizeof (UINT64);
+
+ ChecksumCommonTables (AcpiTableInstance);
+
+ InstallAcpiTableFromHob (AcpiTableInstance);
+
+ //
+ // Completed successfully
+ //
+ return EFI_SUCCESS;
+}
diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/Aml.c b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/Aml.c
index 2e16fef9ed..d0cd1dc0c4 100644
--- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/Aml.c
+++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/Aml.c
@@ -1,296 +1,296 @@
-/** @file
- ACPI Sdt Protocol Driver
-
- Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved. <BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include "AcpiTable.h"
-
-GLOBAL_REMOVE_IF_UNREFERENCED
-AML_BYTE_ENCODING mAmlByteEncoding[] = {
- // OpCode SubOpCode Num 1 2 3 4 5 6 Attribute
- /* ZeroOp - 0x00 */ { AML_ZERO_OP, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* OneOp - 0x01 */ { AML_ONE_OP, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* AliasOp - 0x06 */ { AML_ALIAS_OP, 0, 2, { AML_NAME, AML_NAME, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IN_NAMESPACE },
- /* NameOp - 0x08 */ { AML_NAME_OP, 0, 2, { AML_NAME, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IN_NAMESPACE },
- /* BytePrefix - 0x0A */ { AML_BYTE_PREFIX, 0, 1, { AML_UINT8, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* WordPrefix - 0x0B */ { AML_WORD_PREFIX, 0, 1, { AML_UINT16, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* DWordPrefix - 0x0C */ { AML_DWORD_PREFIX, 0, 1, { AML_UINT32, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* StringPrefix - 0x0D */ { AML_STRING_PREFIX, 0, 1, { AML_STRING, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* QWordPrefix - 0x0E */ { AML_QWORD_PREFIX, 0, 1, { AML_UINT64, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* ScopeOp - 0x10 */ { AML_SCOPE_OP, 0, 1, { AML_NAME, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ | AML_IN_NAMESPACE },
- /* BufferOp - 0x11 */ { AML_BUFFER_OP, 0, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH },
- /* PackageOp - 0x12 */ { AML_PACKAGE_OP, 0, 1, { AML_UINT8, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ },
- /* VarPackageOp - 0x13 */ { AML_VAR_PACKAGE_OP, 0, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ },
- /* MethodOp - 0x14 */ { AML_METHOD_OP, 0, 2, { AML_NAME, AML_UINT8, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ | AML_IN_NAMESPACE },
- /* DualNamePrefix - 0x2F */ { AML_DUAL_NAME_PREFIX, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* MultiNamePrefix - 0x2F */ { AML_MULTI_NAME_PREFIX, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x41 */ { 'A', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x42 */ { 'B', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x43 */ { 'C', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x44 */ { 'D', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x45 */ { 'E', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x46 */ { 'F', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x47 */ { 'G', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x48 */ { 'H', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x49 */ { 'I', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x4A */ { 'J', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x4B */ { 'K', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x4C */ { 'L', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x4D */ { 'M', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x4E */ { 'N', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x4F */ { 'O', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x50 */ { 'P', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x51 */ { 'Q', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x52 */ { 'R', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x53 */ { 'S', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x54 */ { 'T', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x55 */ { 'U', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x56 */ { 'V', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x57 */ { 'W', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x58 */ { 'X', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x59 */ { 'Y', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x5A */ { 'Z', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* MutexOp - 0x5B 0x01 */ { AML_EXT_OP, AML_EXT_MUTEX_OP, 2, { AML_NAME, AML_UINT8, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IN_NAMESPACE },
- /* EventOp - 0x5B 0x02 */ { AML_EXT_OP, AML_EXT_EVENT_OP, 1, { AML_NAME, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IN_NAMESPACE },
- /* CondRefOfOp - 0x5B 0x12 */ { AML_EXT_OP, AML_EXT_COND_REF_OF_OP, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* CreateFieldOp - 0x5B 0x13 */ { AML_EXT_OP, AML_EXT_CREATE_FIELD_OP, 4, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NAME, AML_NONE, AML_NONE }, 0 },
- /* LoadTableOp - 0x5B 0x1F */ { AML_EXT_OP, AML_EXT_LOAD_TABLE_OP, 6, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_OBJECT }, 0 },
- /* LoadOp - 0x5B 0x20 */ { AML_EXT_OP, AML_EXT_LOAD_OP, 2, { AML_NAME, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* StallOp - 0x5B 0x21 */ { AML_EXT_OP, AML_EXT_STALL_OP, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* SleepOp - 0x5B 0x22 */ { AML_EXT_OP, AML_EXT_SLEEP_OP, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* AcquireOp - 0x5B 0x23 */ { AML_EXT_OP, AML_EXT_ACQUIRE_OP, 2, { AML_OBJECT, AML_UINT16, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* SignalOp - 0x5B 0x24 */ { AML_EXT_OP, AML_EXT_SIGNAL_OP, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* WaitOp - 0x5B 0x25 */ { AML_EXT_OP, AML_EXT_WAIT_OP, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* ResetOp - 0x5B 0x26 */ { AML_EXT_OP, AML_EXT_RESET_OP, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* ReleaseOp - 0x5B 0x27 */ { AML_EXT_OP, AML_EXT_RELEASE_OP, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* FromBCDOp - 0x5B 0x28 */ { AML_EXT_OP, AML_EXT_FROM_BCD_OP, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* ToBCDOp - 0x5B 0x29 */ { AML_EXT_OP, AML_EXT_TO_BCD_OP, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* UnloadOp - 0x5B 0x2A */ { AML_EXT_OP, AML_EXT_UNLOAD_OP, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* RevisionOp - 0x5B 0x30 */ { AML_EXT_OP, AML_EXT_REVISION_OP, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* DebugOp - 0x5B 0x31 */ { AML_EXT_OP, AML_EXT_DEBUG_OP, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* FatalOp - 0x5B 0x32 */ { AML_EXT_OP, AML_EXT_FATAL_OP, 3, { AML_UINT8, AML_UINT32, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* TimerOp - 0x5B 0x33 */ { AML_EXT_OP, AML_EXT_TIMER_OP, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* OpRegionOp - 0x5B 0x80 */ { AML_EXT_OP, AML_EXT_REGION_OP, 4, { AML_NAME, AML_UINT8, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE }, AML_IN_NAMESPACE },
- /* FieldOp - 0x5B 0x81 */ { AML_EXT_OP, AML_EXT_FIELD_OP, 2, { AML_NAME, AML_UINT8, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH },
- /* DeviceOp - 0x5B 0x82 */ { AML_EXT_OP, AML_EXT_DEVICE_OP, 1, { AML_NAME, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ | AML_IN_NAMESPACE },
- /* ProcessorOp - 0x5B 0x83 */ { AML_EXT_OP, AML_EXT_PROCESSOR_OP, 4, { AML_NAME, AML_UINT8, AML_UINT32, AML_UINT8, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ | AML_IN_NAMESPACE },
- /* PowerResOp - 0x5B 0x84 */ { AML_EXT_OP, AML_EXT_POWER_RES_OP, 3, { AML_NAME, AML_UINT8, AML_UINT16, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ | AML_IN_NAMESPACE },
- /* ThermalZoneOp - 0x5B 0x85 */ { AML_EXT_OP, AML_EXT_THERMAL_ZONE_OP, 1, { AML_NAME, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ | AML_IN_NAMESPACE },
- /* IndexFieldOp - 0x5B 0x86 */ { AML_EXT_OP, AML_EXT_INDEX_FIELD_OP, 3, { AML_NAME, AML_NAME, AML_UINT8, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH },
- /* BankFieldOp - 0x5B 0x87 */ { AML_EXT_OP, AML_EXT_BANK_FIELD_OP, 4, { AML_NAME, AML_NAME, AML_OBJECT, AML_UINT8, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH },
- /* DataRegionOp - 0x5B 0x88 */ { AML_EXT_OP, AML_EXT_DATA_REGION_OP, 4, { AML_NAME, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE }, AML_IN_NAMESPACE },
- /* RootChar - 0x5C */ { AML_ROOT_CHAR, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* ParentPrefixChar - 0x5E */ { AML_PARENT_PREFIX_CHAR, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* NameChar - 0x5F */ { '_', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
- /* Local0Op - 0x60 */ { AML_LOCAL0, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* Local1Op - 0x61 */ { AML_LOCAL1, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* Local2Op - 0x62 */ { AML_LOCAL2, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* Local3Op - 0x63 */ { AML_LOCAL3, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* Local4Op - 0x64 */ { AML_LOCAL4, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* Local5Op - 0x65 */ { AML_LOCAL5, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* Local6Op - 0x66 */ { AML_LOCAL6, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* Local7Op - 0x67 */ { AML_LOCAL7, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* Arg0Op - 0x68 */ { AML_ARG0, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* Arg1Op - 0x69 */ { AML_ARG1, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* Arg2Op - 0x6A */ { AML_ARG2, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* Arg3Op - 0x6B */ { AML_ARG3, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* Arg4Op - 0x6C */ { AML_ARG4, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* Arg5Op - 0x6D */ { AML_ARG5, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* Arg6Op - 0x6E */ { AML_ARG6, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* StoreOp - 0x70 */ { AML_STORE_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* RefOfOp - 0x71 */ { AML_REF_OF_OP, 0, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* AddOp - 0x72 */ { AML_ADD_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* ConcatOp - 0x73 */ { AML_CONCAT_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* SubtractOp - 0x74 */ { AML_SUBTRACT_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* IncrementOp - 0x75 */ { AML_INCREMENT_OP, 0, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* DecrementOp - 0x76 */ { AML_DECREMENT_OP, 0, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* MultiplyOp - 0x77 */ { AML_MULTIPLY_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* DivideOp - 0x78 */ { AML_DIVIDE_OP, 0, 4, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE }, 0 },
- /* ShiftLeftOp - 0x79 */ { AML_SHIFT_LEFT_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* ShiftRightOp - 0x7A */ { AML_SHIFT_RIGHT_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* AndOp - 0x7B */ { AML_AND_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* NAndOp - 0x7C */ { AML_NAND_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* OrOp - 0x7D */ { AML_OR_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* NorOp - 0x7E */ { AML_NOR_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* XOrOp - 0x7F */ { AML_XOR_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* NotOp - 0x80 */ { AML_NOT_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* FindSetLeftBitOp - 0x81 */ { AML_FIND_SET_LEFT_BIT_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* FindSetRightBitOp - 0x82 */ { AML_FIND_SET_RIGHT_BIT_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* DerefOfOp - 0x83 */ { AML_DEREF_OF_OP, 0, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* ConcatResOp - 0x84 */ { AML_CONCAT_RES_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* ModOp - 0x85 */ { AML_MOD_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* NotifyOp - 0x86 */ { AML_NOTIFY_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* SizeOfOp - 0x87 */ { AML_SIZE_OF_OP, 0, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* IndexOp - 0x88 */ { AML_INDEX_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* MatchOp - 0x89 */ { AML_MATCH_OP, 0, 6, { AML_OBJECT, AML_UINT8, AML_OBJECT, AML_UINT8, AML_OBJECT, AML_OBJECT }, 0 },
- /* CreateDWordFieldOp - 0x8A */ { AML_CREATE_DWORD_FIELD_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_NAME, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* CreateWordFieldOp - 0x8B */ { AML_CREATE_WORD_FIELD_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_NAME, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* CreateByteFieldOp - 0x8C */ { AML_CREATE_BYTE_FIELD_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_NAME, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* CreateBitFieldOp - 0x8D */ { AML_CREATE_BIT_FIELD_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_NAME, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* ObjectTypeOp - 0x8E */ { AML_OBJECT_TYPE_OP, 0, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* CreateQWordFieldOp - 0x8F */ { AML_CREATE_QWORD_FIELD_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_NAME, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* LAndOp - 0x90 */ { AML_LAND_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* LOrOp - 0x91 */ { AML_LOR_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* LNotOp - 0x92 */ { AML_LNOT_OP, 0, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* LEqualOp - 0x93 */ { AML_LEQUAL_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* LGreaterOp - 0x94 */ { AML_LGREATER_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* LLessOp - 0x95 */ { AML_LLESS_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* ToBufferOp - 0x96 */ { AML_TO_BUFFER_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* ToDecimalStringOp - 0x97 */ { AML_TO_DEC_STRING_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* ToHexStringOp - 0x98 */ { AML_TO_HEX_STRING_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* ToIntegerOp - 0x99 */ { AML_TO_INTEGER_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* ToStringOp - 0x9C */ { AML_TO_STRING_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* CopyObjectOp - 0x9D */ { AML_COPY_OBJECT_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* MidOp - 0x9E */ { AML_MID_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* ContinueOp - 0x9F */ { AML_CONTINUE_OP, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* IfOp - 0xA0 */ { AML_IF_OP, 0, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ },
- /* ElseOp - 0xA1 */ { AML_ELSE_OP, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ },
- /* WhileOp - 0xA2 */ { AML_WHILE_OP, 0, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ },
- /* NoopOp - 0xA3 */ { AML_NOOP_OP, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* ReturnOp - 0xA4 */ { AML_RETURN_OP, 0, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* BreakOp - 0xA5 */ { AML_BREAK_OP, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* BreakPointOp - 0xCC */ { AML_BREAK_POINT_OP, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
- /* OnesOp - 0xFF */ { AML_ONES_OP, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
-};
-
-GLOBAL_REMOVE_IF_UNREFERENCED
-EFI_ACPI_DATA_TYPE mAmlTypeToAcpiType[] = {
- EFI_ACPI_DATA_TYPE_NONE, // AML_NONE
- EFI_ACPI_DATA_TYPE_OPCODE, // AML_OPCODE
- EFI_ACPI_DATA_TYPE_UINT, // AML_UINT8
- EFI_ACPI_DATA_TYPE_UINT, // AML_UINT16
- EFI_ACPI_DATA_TYPE_UINT, // AML_UINT32
- EFI_ACPI_DATA_TYPE_UINT, // AML_UINT64
- EFI_ACPI_DATA_TYPE_NAME_STRING, // AML_NAME
- EFI_ACPI_DATA_TYPE_STRING, // AML_STRING
- EFI_ACPI_DATA_TYPE_CHILD // AML_OBJECT
-};
-
-/**
- This function returns AmlByteEncoding according to OpCode Byte.
-
- @param[in] OpByteBuffer OpCode byte buffer.
-
- @return AmlByteEncoding
-**/
-AML_BYTE_ENCODING *
-AmlSearchByOpByte (
- IN UINT8 *OpByteBuffer
- )
-{
- UINT8 OpCode;
- UINT8 SubOpCode;
- UINTN Index;
-
- //
- // Get OpCode and SubOpCode
- //
- OpCode = OpByteBuffer[0];
- if (OpCode == AML_EXT_OP) {
- SubOpCode = OpByteBuffer[1];
- } else {
- SubOpCode = 0;
- }
-
- //
- // Search the table
- //
- for (Index = 0; Index < sizeof (mAmlByteEncoding)/sizeof (mAmlByteEncoding[0]); Index++) {
- if ((mAmlByteEncoding[Index].OpCode == OpCode) && (mAmlByteEncoding[Index].SubOpCode == SubOpCode)) {
- return &mAmlByteEncoding[Index];
- }
- }
-
- return NULL;
-}
-
-/**
- This function returns AcpiDataType according to AmlType.
-
- @param[in] AmlType AML Type.
-
- @return AcpiDataType
-**/
-EFI_ACPI_DATA_TYPE
-AmlTypeToAcpiType (
- IN AML_OP_PARSE_FORMAT AmlType
- )
-{
- if (AmlType >= sizeof (mAmlTypeToAcpiType)/sizeof (mAmlTypeToAcpiType[0])) {
- ASSERT (FALSE);
- return EFI_ACPI_DATA_TYPE_NONE;
- }
-
- return mAmlTypeToAcpiType[AmlType];
-}
-
-/**
- This function retuns package length from the buffer.
-
- @param[in] Buffer AML buffer
- @param[out] PkgLength The total length of package.
-
- @return The byte data count to present the package length.
-**/
-UINTN
-AmlGetPkgLength (
- IN UINT8 *Buffer,
- OUT UINTN *PkgLength
- )
-{
- UINT8 LeadByte;
- UINT8 ByteCount;
- UINTN RealLength;
- UINTN Offset;
-
- //
- // <bit 7-6: ByteData count that follows (0-3)>
- // <bit 5-4: Only used if PkgLength < 63>
- // <bit 3-0: Least significant package length nybble>
- //
- // Note: The high 2 bits of the first byte reveal how many follow bytes are in the
- // If the PkgLength has only one byte, bit 0 through 5 are used to encode the
- // package length (in other words, values 0-63). If the package length value is more than
- // 63, more than one byte must be used for the encoding in which case bit 4 and 5 of the
- // PkgLeadByte are reserved and must be zero. If the multiple bytes encoding is used,
- // bits 0-3 of the PkgLeadByte become the least significant 4 bits of the resulting
- // package length value. The next ByteData will become the next least significant 8 bits
- // of the resulting value and so on, up to 3 ByteData bytes. Thus, the maximum package
- // length is 2**28.
- //
-
- LeadByte = *Buffer;
- ByteCount = (UINT8)((LeadByte >> 6) & 0x03);
- Offset = ByteCount + 1;
- RealLength = 0;
-
- switch (ByteCount) {
- case 0:
- RealLength = (UINT32)LeadByte;
- break;
- case 1:
- RealLength = *(Buffer + 1);
- RealLength = (RealLength << 4) | (LeadByte & 0xF);
- break;
- case 2:
- RealLength = *(Buffer + 1);
- RealLength |= (UINTN)((*(Buffer + 2)) << 8);
- RealLength = (RealLength << 4) | (LeadByte & 0xF);
- break;
- case 3:
- RealLength = *(Buffer + 1);
- RealLength |= (UINTN)((*(Buffer + 2)) << 8);
- RealLength |= (UINTN)((*(Buffer + 3)) << 16);
- RealLength = (RealLength << 4) | (LeadByte & 0xF);
- break;
- default:
- ASSERT (0);
- break;
- }
-
- *PkgLength = RealLength;
- return Offset;
-}
+/** @file
+ ACPI Sdt Protocol Driver
+
+ Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved. <BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "AcpiTable.h"
+
+GLOBAL_REMOVE_IF_UNREFERENCED
+AML_BYTE_ENCODING mAmlByteEncoding[] = {
+ // OpCode SubOpCode Num 1 2 3 4 5 6 Attribute
+ /* ZeroOp - 0x00 */ { AML_ZERO_OP, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* OneOp - 0x01 */ { AML_ONE_OP, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* AliasOp - 0x06 */ { AML_ALIAS_OP, 0, 2, { AML_NAME, AML_NAME, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IN_NAMESPACE },
+ /* NameOp - 0x08 */ { AML_NAME_OP, 0, 2, { AML_NAME, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IN_NAMESPACE },
+ /* BytePrefix - 0x0A */ { AML_BYTE_PREFIX, 0, 1, { AML_UINT8, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* WordPrefix - 0x0B */ { AML_WORD_PREFIX, 0, 1, { AML_UINT16, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* DWordPrefix - 0x0C */ { AML_DWORD_PREFIX, 0, 1, { AML_UINT32, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* StringPrefix - 0x0D */ { AML_STRING_PREFIX, 0, 1, { AML_STRING, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* QWordPrefix - 0x0E */ { AML_QWORD_PREFIX, 0, 1, { AML_UINT64, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* ScopeOp - 0x10 */ { AML_SCOPE_OP, 0, 1, { AML_NAME, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ | AML_IN_NAMESPACE },
+ /* BufferOp - 0x11 */ { AML_BUFFER_OP, 0, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH },
+ /* PackageOp - 0x12 */ { AML_PACKAGE_OP, 0, 1, { AML_UINT8, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ },
+ /* VarPackageOp - 0x13 */ { AML_VAR_PACKAGE_OP, 0, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ },
+ /* MethodOp - 0x14 */ { AML_METHOD_OP, 0, 2, { AML_NAME, AML_UINT8, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ | AML_IN_NAMESPACE },
+ /* DualNamePrefix - 0x2F */ { AML_DUAL_NAME_PREFIX, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* MultiNamePrefix - 0x2F */ { AML_MULTI_NAME_PREFIX, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x41 */ { 'A', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x42 */ { 'B', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x43 */ { 'C', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x44 */ { 'D', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x45 */ { 'E', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x46 */ { 'F', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x47 */ { 'G', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x48 */ { 'H', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x49 */ { 'I', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x4A */ { 'J', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x4B */ { 'K', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x4C */ { 'L', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x4D */ { 'M', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x4E */ { 'N', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x4F */ { 'O', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x50 */ { 'P', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x51 */ { 'Q', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x52 */ { 'R', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x53 */ { 'S', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x54 */ { 'T', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x55 */ { 'U', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x56 */ { 'V', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x57 */ { 'W', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x58 */ { 'X', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x59 */ { 'Y', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x5A */ { 'Z', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* MutexOp - 0x5B 0x01 */ { AML_EXT_OP, AML_EXT_MUTEX_OP, 2, { AML_NAME, AML_UINT8, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IN_NAMESPACE },
+ /* EventOp - 0x5B 0x02 */ { AML_EXT_OP, AML_EXT_EVENT_OP, 1, { AML_NAME, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IN_NAMESPACE },
+ /* CondRefOfOp - 0x5B 0x12 */ { AML_EXT_OP, AML_EXT_COND_REF_OF_OP, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* CreateFieldOp - 0x5B 0x13 */ { AML_EXT_OP, AML_EXT_CREATE_FIELD_OP, 4, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NAME, AML_NONE, AML_NONE }, 0 },
+ /* LoadTableOp - 0x5B 0x1F */ { AML_EXT_OP, AML_EXT_LOAD_TABLE_OP, 6, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_OBJECT }, 0 },
+ /* LoadOp - 0x5B 0x20 */ { AML_EXT_OP, AML_EXT_LOAD_OP, 2, { AML_NAME, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* StallOp - 0x5B 0x21 */ { AML_EXT_OP, AML_EXT_STALL_OP, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* SleepOp - 0x5B 0x22 */ { AML_EXT_OP, AML_EXT_SLEEP_OP, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* AcquireOp - 0x5B 0x23 */ { AML_EXT_OP, AML_EXT_ACQUIRE_OP, 2, { AML_OBJECT, AML_UINT16, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* SignalOp - 0x5B 0x24 */ { AML_EXT_OP, AML_EXT_SIGNAL_OP, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* WaitOp - 0x5B 0x25 */ { AML_EXT_OP, AML_EXT_WAIT_OP, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* ResetOp - 0x5B 0x26 */ { AML_EXT_OP, AML_EXT_RESET_OP, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* ReleaseOp - 0x5B 0x27 */ { AML_EXT_OP, AML_EXT_RELEASE_OP, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* FromBCDOp - 0x5B 0x28 */ { AML_EXT_OP, AML_EXT_FROM_BCD_OP, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* ToBCDOp - 0x5B 0x29 */ { AML_EXT_OP, AML_EXT_TO_BCD_OP, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* UnloadOp - 0x5B 0x2A */ { AML_EXT_OP, AML_EXT_UNLOAD_OP, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* RevisionOp - 0x5B 0x30 */ { AML_EXT_OP, AML_EXT_REVISION_OP, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* DebugOp - 0x5B 0x31 */ { AML_EXT_OP, AML_EXT_DEBUG_OP, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* FatalOp - 0x5B 0x32 */ { AML_EXT_OP, AML_EXT_FATAL_OP, 3, { AML_UINT8, AML_UINT32, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* TimerOp - 0x5B 0x33 */ { AML_EXT_OP, AML_EXT_TIMER_OP, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* OpRegionOp - 0x5B 0x80 */ { AML_EXT_OP, AML_EXT_REGION_OP, 4, { AML_NAME, AML_UINT8, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE }, AML_IN_NAMESPACE },
+ /* FieldOp - 0x5B 0x81 */ { AML_EXT_OP, AML_EXT_FIELD_OP, 2, { AML_NAME, AML_UINT8, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH },
+ /* DeviceOp - 0x5B 0x82 */ { AML_EXT_OP, AML_EXT_DEVICE_OP, 1, { AML_NAME, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ | AML_IN_NAMESPACE },
+ /* ProcessorOp - 0x5B 0x83 */ { AML_EXT_OP, AML_EXT_PROCESSOR_OP, 4, { AML_NAME, AML_UINT8, AML_UINT32, AML_UINT8, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ | AML_IN_NAMESPACE },
+ /* PowerResOp - 0x5B 0x84 */ { AML_EXT_OP, AML_EXT_POWER_RES_OP, 3, { AML_NAME, AML_UINT8, AML_UINT16, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ | AML_IN_NAMESPACE },
+ /* ThermalZoneOp - 0x5B 0x85 */ { AML_EXT_OP, AML_EXT_THERMAL_ZONE_OP, 1, { AML_NAME, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ | AML_IN_NAMESPACE },
+ /* IndexFieldOp - 0x5B 0x86 */ { AML_EXT_OP, AML_EXT_INDEX_FIELD_OP, 3, { AML_NAME, AML_NAME, AML_UINT8, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH },
+ /* BankFieldOp - 0x5B 0x87 */ { AML_EXT_OP, AML_EXT_BANK_FIELD_OP, 4, { AML_NAME, AML_NAME, AML_OBJECT, AML_UINT8, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH },
+ /* DataRegionOp - 0x5B 0x88 */ { AML_EXT_OP, AML_EXT_DATA_REGION_OP, 4, { AML_NAME, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE }, AML_IN_NAMESPACE },
+ /* RootChar - 0x5C */ { AML_ROOT_CHAR, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* ParentPrefixChar - 0x5E */ { AML_PARENT_PREFIX_CHAR, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* NameChar - 0x5F */ { '_', 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_IS_NAME_CHAR },
+ /* Local0Op - 0x60 */ { AML_LOCAL0, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* Local1Op - 0x61 */ { AML_LOCAL1, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* Local2Op - 0x62 */ { AML_LOCAL2, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* Local3Op - 0x63 */ { AML_LOCAL3, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* Local4Op - 0x64 */ { AML_LOCAL4, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* Local5Op - 0x65 */ { AML_LOCAL5, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* Local6Op - 0x66 */ { AML_LOCAL6, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* Local7Op - 0x67 */ { AML_LOCAL7, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* Arg0Op - 0x68 */ { AML_ARG0, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* Arg1Op - 0x69 */ { AML_ARG1, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* Arg2Op - 0x6A */ { AML_ARG2, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* Arg3Op - 0x6B */ { AML_ARG3, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* Arg4Op - 0x6C */ { AML_ARG4, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* Arg5Op - 0x6D */ { AML_ARG5, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* Arg6Op - 0x6E */ { AML_ARG6, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* StoreOp - 0x70 */ { AML_STORE_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* RefOfOp - 0x71 */ { AML_REF_OF_OP, 0, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* AddOp - 0x72 */ { AML_ADD_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* ConcatOp - 0x73 */ { AML_CONCAT_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* SubtractOp - 0x74 */ { AML_SUBTRACT_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* IncrementOp - 0x75 */ { AML_INCREMENT_OP, 0, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* DecrementOp - 0x76 */ { AML_DECREMENT_OP, 0, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* MultiplyOp - 0x77 */ { AML_MULTIPLY_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* DivideOp - 0x78 */ { AML_DIVIDE_OP, 0, 4, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE }, 0 },
+ /* ShiftLeftOp - 0x79 */ { AML_SHIFT_LEFT_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* ShiftRightOp - 0x7A */ { AML_SHIFT_RIGHT_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* AndOp - 0x7B */ { AML_AND_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* NAndOp - 0x7C */ { AML_NAND_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* OrOp - 0x7D */ { AML_OR_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* NorOp - 0x7E */ { AML_NOR_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* XOrOp - 0x7F */ { AML_XOR_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* NotOp - 0x80 */ { AML_NOT_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* FindSetLeftBitOp - 0x81 */ { AML_FIND_SET_LEFT_BIT_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* FindSetRightBitOp - 0x82 */ { AML_FIND_SET_RIGHT_BIT_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* DerefOfOp - 0x83 */ { AML_DEREF_OF_OP, 0, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* ConcatResOp - 0x84 */ { AML_CONCAT_RES_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* ModOp - 0x85 */ { AML_MOD_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* NotifyOp - 0x86 */ { AML_NOTIFY_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* SizeOfOp - 0x87 */ { AML_SIZE_OF_OP, 0, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* IndexOp - 0x88 */ { AML_INDEX_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* MatchOp - 0x89 */ { AML_MATCH_OP, 0, 6, { AML_OBJECT, AML_UINT8, AML_OBJECT, AML_UINT8, AML_OBJECT, AML_OBJECT }, 0 },
+ /* CreateDWordFieldOp - 0x8A */ { AML_CREATE_DWORD_FIELD_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_NAME, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* CreateWordFieldOp - 0x8B */ { AML_CREATE_WORD_FIELD_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_NAME, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* CreateByteFieldOp - 0x8C */ { AML_CREATE_BYTE_FIELD_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_NAME, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* CreateBitFieldOp - 0x8D */ { AML_CREATE_BIT_FIELD_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_NAME, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* ObjectTypeOp - 0x8E */ { AML_OBJECT_TYPE_OP, 0, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* CreateQWordFieldOp - 0x8F */ { AML_CREATE_QWORD_FIELD_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_NAME, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* LAndOp - 0x90 */ { AML_LAND_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* LOrOp - 0x91 */ { AML_LOR_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* LNotOp - 0x92 */ { AML_LNOT_OP, 0, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* LEqualOp - 0x93 */ { AML_LEQUAL_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* LGreaterOp - 0x94 */ { AML_LGREATER_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* LLessOp - 0x95 */ { AML_LLESS_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* ToBufferOp - 0x96 */ { AML_TO_BUFFER_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* ToDecimalStringOp - 0x97 */ { AML_TO_DEC_STRING_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* ToHexStringOp - 0x98 */ { AML_TO_HEX_STRING_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* ToIntegerOp - 0x99 */ { AML_TO_INTEGER_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* ToStringOp - 0x9C */ { AML_TO_STRING_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* CopyObjectOp - 0x9D */ { AML_COPY_OBJECT_OP, 0, 2, { AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* MidOp - 0x9E */ { AML_MID_OP, 0, 3, { AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* ContinueOp - 0x9F */ { AML_CONTINUE_OP, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* IfOp - 0xA0 */ { AML_IF_OP, 0, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ },
+ /* ElseOp - 0xA1 */ { AML_ELSE_OP, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ },
+ /* WhileOp - 0xA2 */ { AML_WHILE_OP, 0, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, AML_HAS_PKG_LENGTH | AML_HAS_CHILD_OBJ },
+ /* NoopOp - 0xA3 */ { AML_NOOP_OP, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* ReturnOp - 0xA4 */ { AML_RETURN_OP, 0, 1, { AML_OBJECT, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* BreakOp - 0xA5 */ { AML_BREAK_OP, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* BreakPointOp - 0xCC */ { AML_BREAK_POINT_OP, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+ /* OnesOp - 0xFF */ { AML_ONES_OP, 0, 0, { AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE, AML_NONE }, 0 },
+};
+
+GLOBAL_REMOVE_IF_UNREFERENCED
+EFI_ACPI_DATA_TYPE mAmlTypeToAcpiType[] = {
+ EFI_ACPI_DATA_TYPE_NONE, // AML_NONE
+ EFI_ACPI_DATA_TYPE_OPCODE, // AML_OPCODE
+ EFI_ACPI_DATA_TYPE_UINT, // AML_UINT8
+ EFI_ACPI_DATA_TYPE_UINT, // AML_UINT16
+ EFI_ACPI_DATA_TYPE_UINT, // AML_UINT32
+ EFI_ACPI_DATA_TYPE_UINT, // AML_UINT64
+ EFI_ACPI_DATA_TYPE_NAME_STRING, // AML_NAME
+ EFI_ACPI_DATA_TYPE_STRING, // AML_STRING
+ EFI_ACPI_DATA_TYPE_CHILD // AML_OBJECT
+};
+
+/**
+ This function returns AmlByteEncoding according to OpCode Byte.
+
+ @param[in] OpByteBuffer OpCode byte buffer.
+
+ @return AmlByteEncoding
+**/
+AML_BYTE_ENCODING *
+AmlSearchByOpByte (
+ IN UINT8 *OpByteBuffer
+ )
+{
+ UINT8 OpCode;
+ UINT8 SubOpCode;
+ UINTN Index;
+
+ //
+ // Get OpCode and SubOpCode
+ //
+ OpCode = OpByteBuffer[0];
+ if (OpCode == AML_EXT_OP) {
+ SubOpCode = OpByteBuffer[1];
+ } else {
+ SubOpCode = 0;
+ }
+
+ //
+ // Search the table
+ //
+ for (Index = 0; Index < sizeof (mAmlByteEncoding)/sizeof (mAmlByteEncoding[0]); Index++) {
+ if ((mAmlByteEncoding[Index].OpCode == OpCode) && (mAmlByteEncoding[Index].SubOpCode == SubOpCode)) {
+ return &mAmlByteEncoding[Index];
+ }
+ }
+
+ return NULL;
+}
+
+/**
+ This function returns AcpiDataType according to AmlType.
+
+ @param[in] AmlType AML Type.
+
+ @return AcpiDataType
+**/
+EFI_ACPI_DATA_TYPE
+AmlTypeToAcpiType (
+ IN AML_OP_PARSE_FORMAT AmlType
+ )
+{
+ if (AmlType >= sizeof (mAmlTypeToAcpiType)/sizeof (mAmlTypeToAcpiType[0])) {
+ ASSERT (FALSE);
+ return EFI_ACPI_DATA_TYPE_NONE;
+ }
+
+ return mAmlTypeToAcpiType[AmlType];
+}
+
+/**
+ This function retuns package length from the buffer.
+
+ @param[in] Buffer AML buffer
+ @param[out] PkgLength The total length of package.
+
+ @return The byte data count to present the package length.
+**/
+UINTN
+AmlGetPkgLength (
+ IN UINT8 *Buffer,
+ OUT UINTN *PkgLength
+ )
+{
+ UINT8 LeadByte;
+ UINT8 ByteCount;
+ UINTN RealLength;
+ UINTN Offset;
+
+ //
+ // <bit 7-6: ByteData count that follows (0-3)>
+ // <bit 5-4: Only used if PkgLength < 63>
+ // <bit 3-0: Least significant package length nybble>
+ //
+ // Note: The high 2 bits of the first byte reveal how many follow bytes are in the
+ // If the PkgLength has only one byte, bit 0 through 5 are used to encode the
+ // package length (in other words, values 0-63). If the package length value is more than
+ // 63, more than one byte must be used for the encoding in which case bit 4 and 5 of the
+ // PkgLeadByte are reserved and must be zero. If the multiple bytes encoding is used,
+ // bits 0-3 of the PkgLeadByte become the least significant 4 bits of the resulting
+ // package length value. The next ByteData will become the next least significant 8 bits
+ // of the resulting value and so on, up to 3 ByteData bytes. Thus, the maximum package
+ // length is 2**28.
+ //
+
+ LeadByte = *Buffer;
+ ByteCount = (UINT8)((LeadByte >> 6) & 0x03);
+ Offset = ByteCount + 1;
+ RealLength = 0;
+
+ switch (ByteCount) {
+ case 0:
+ RealLength = (UINT32)LeadByte;
+ break;
+ case 1:
+ RealLength = *(Buffer + 1);
+ RealLength = (RealLength << 4) | (LeadByte & 0xF);
+ break;
+ case 2:
+ RealLength = *(Buffer + 1);
+ RealLength |= (UINTN)((*(Buffer + 2)) << 8);
+ RealLength = (RealLength << 4) | (LeadByte & 0xF);
+ break;
+ case 3:
+ RealLength = *(Buffer + 1);
+ RealLength |= (UINTN)((*(Buffer + 2)) << 8);
+ RealLength |= (UINTN)((*(Buffer + 3)) << 16);
+ RealLength = (RealLength << 4) | (LeadByte & 0xF);
+ break;
+ default:
+ ASSERT (0);
+ break;
+ }
+
+ *PkgLength = RealLength;
+ return Offset;
+}
diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlChild.c b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlChild.c
index 0c154576c1..a077bb1027 100644
--- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlChild.c
+++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlChild.c
@@ -1,280 +1,280 @@
-/** @file
- ACPI Sdt Protocol Driver
-
- Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved. <BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include "AcpiTable.h"
-
-/**
- Return the child objects buffer from AML Handle's buffer.
-
- @param[in] AmlParentHandle Parent handle.
- @param[in] CurrentBuffer The current child buffer.
- @param[out] Buffer On return, points to the next returned child buffer or NULL if there are no
- child buffer.
-
- @retval EFI_SUCCESS Success
- @retval EFI_INVALID_PARAMETER AmlParentHandle does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-AmlGetChildFromObjectBuffer (
- IN EFI_AML_HANDLE *AmlParentHandle,
- IN UINT8 *CurrentBuffer,
- OUT VOID **Buffer
- )
-{
- AML_BYTE_ENCODING *AmlByteEncoding;
- UINTN DataSize;
-
- //
- // Root is considered as SCOPE, which has TermList.
- // We need return only Object in TermList.
- //
- while ((UINTN)CurrentBuffer < (UINTN)(AmlParentHandle->Buffer + AmlParentHandle->Size)) {
- AmlByteEncoding = AmlSearchByOpByte (CurrentBuffer);
- if (AmlByteEncoding == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // NOTE: We need return everything, because user might need parse the returned object.
- //
- if ((AmlByteEncoding->Attribute & AML_IS_NAME_CHAR) == 0) {
- *Buffer = CurrentBuffer;
- return EFI_SUCCESS;
- }
-
- DataSize = AmlGetObjectSize (
- AmlByteEncoding,
- CurrentBuffer,
- (UINTN)AmlParentHandle->Buffer + AmlParentHandle->Size - (UINTN)CurrentBuffer
- );
- if (DataSize == 0) {
- return EFI_INVALID_PARAMETER;
- }
-
- CurrentBuffer += DataSize;
- }
-
- //
- // No more
- //
- *Buffer = NULL;
- return EFI_SUCCESS;
-}
-
-/**
- Return the child ACPI objects from Root Handle.
-
- @param[in] AmlParentHandle Parent handle. It is Root Handle.
- @param[in] AmlHandle The previously returned handle or NULL to start with the first handle.
- @param[out] Buffer On return, points to the next returned ACPI handle or NULL if there are no
- child objects.
-
- @retval EFI_SUCCESS Success
- @retval EFI_INVALID_PARAMETER ParentHandle is NULL or does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-AmlGetChildFromRoot (
- IN EFI_AML_HANDLE *AmlParentHandle,
- IN EFI_AML_HANDLE *AmlHandle,
- OUT VOID **Buffer
- )
-{
- UINT8 *CurrentBuffer;
-
- if (AmlHandle == NULL) {
- //
- // First One
- //
- CurrentBuffer = (VOID *)AmlParentHandle->Buffer;
- } else {
- CurrentBuffer = (VOID *)(AmlHandle->Buffer + AmlHandle->Size);
- }
-
- return AmlGetChildFromObjectBuffer (AmlParentHandle, CurrentBuffer, Buffer);
-}
-
-/**
- Return the child objects buffer from AML Handle's option list.
-
- @param[in] AmlParentHandle Parent handle.
- @param[in] AmlHandle The current child handle.
- @param[out] Buffer On return, points to the next returned child buffer or NULL if there are no
- child buffer.
-
- @retval EFI_SUCCESS Success
- @retval EFI_INVALID_PARAMETER AmlParentHandle does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-AmlGetChildFromOptionList (
- IN EFI_AML_HANDLE *AmlParentHandle,
- IN EFI_AML_HANDLE *AmlHandle,
- OUT VOID **Buffer
- )
-{
- EFI_ACPI_DATA_TYPE DataType;
- VOID *Data;
- UINTN DataSize;
- AML_OP_PARSE_INDEX Index;
- EFI_STATUS Status;
- AML_OP_PARSE_INDEX MaxTerm;
-
- Index = AML_OP_PARSE_INDEX_GET_TERM1;
- MaxTerm = AmlParentHandle->AmlByteEncoding->MaxIndex;
- while (Index <= MaxTerm) {
- Status = AmlParseOptionHandleCommon (
- AmlParentHandle,
- (AML_OP_PARSE_INDEX)Index,
- &DataType,
- (VOID **)&Data,
- &DataSize
- );
- if (EFI_ERROR (Status)) {
- return EFI_INVALID_PARAMETER;
- }
-
- if (DataType == EFI_ACPI_DATA_TYPE_NONE) {
- //
- // Not found
- //
- break;
- }
-
- //
- // Find it, and Check Data
- //
- if ((DataType == EFI_ACPI_DATA_TYPE_CHILD) &&
- ((UINTN)AmlHandle->Buffer < (UINTN)Data))
- {
- //
- // Buffer < Data means current node is next one
- //
- *Buffer = Data;
- return EFI_SUCCESS;
- }
-
- //
- // Not Child
- //
- Index++;
- }
-
- *Buffer = NULL;
- return EFI_SUCCESS;
-}
-
-/**
- Return the child objects buffer from AML Handle's object child list.
-
- @param[in] AmlParentHandle Parent handle.
- @param[in] AmlHandle The current child handle.
- @param[out] Buffer On return, points to the next returned child buffer or NULL if there are no
- child buffer.
-
- @retval EFI_SUCCESS Success
- @retval EFI_INVALID_PARAMETER AmlParentHandle does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-AmlGetChildFromObjectChildList (
- IN EFI_AML_HANDLE *AmlParentHandle,
- IN EFI_AML_HANDLE *AmlHandle,
- OUT VOID **Buffer
- )
-{
- EFI_STATUS Status;
- UINT8 *CurrentBuffer;
-
- CurrentBuffer = NULL;
-
- if ((AmlParentHandle->AmlByteEncoding->Attribute & AML_HAS_CHILD_OBJ) == 0) {
- //
- // No ObjectList
- //
- *Buffer = NULL;
- return EFI_SUCCESS;
- }
-
- //
- // Do we need add node within METHOD?
- // Yes, just add Object is OK. But we need filter NameString for METHOD invoke.
- //
-
- //
- // Now, we get the last node.
- //
- Status = AmlGetOffsetAfterLastOption (AmlParentHandle, &CurrentBuffer);
- if (EFI_ERROR (Status)) {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // Go through all the reset buffer.
- //
- if ((UINTN)AmlHandle->Buffer < (UINTN)CurrentBuffer) {
- //
- // Buffer < Data means next node is first object
- //
- } else if ((UINTN)AmlHandle->Buffer + AmlHandle->Size < (UINTN)AmlParentHandle->Buffer + AmlParentHandle->Size) {
- //
- // There is still more node
- //
- CurrentBuffer = AmlHandle->Buffer + AmlHandle->Size;
- } else {
- //
- // No more data
- //
- *Buffer = NULL;
- return EFI_SUCCESS;
- }
-
- return AmlGetChildFromObjectBuffer (AmlParentHandle, CurrentBuffer, Buffer);
-}
-
-/**
- Return the child ACPI objects from Non-Root Handle.
-
- @param[in] AmlParentHandle Parent handle. It is Non-Root Handle.
- @param[in] AmlHandle The previously returned handle or NULL to start with the first handle.
- @param[out] Buffer On return, points to the next returned ACPI handle or NULL if there are no
- child objects.
-
- @retval EFI_SUCCESS Success
- @retval EFI_INVALID_PARAMETER ParentHandle is NULL or does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-AmlGetChildFromNonRoot (
- IN EFI_AML_HANDLE *AmlParentHandle,
- IN EFI_AML_HANDLE *AmlHandle,
- OUT VOID **Buffer
- )
-{
- EFI_STATUS Status;
-
- if (AmlHandle == NULL) {
- //
- // NULL means first one
- //
- AmlHandle = AmlParentHandle;
- }
-
- //
- // 1. Get Option
- //
- Status = AmlGetChildFromOptionList (AmlParentHandle, AmlHandle, Buffer);
- if (EFI_ERROR (Status)) {
- return EFI_INVALID_PARAMETER;
- }
-
- if (*Buffer != NULL) {
- return EFI_SUCCESS;
- }
-
- //
- // 2. search ObjectList
- //
- return AmlGetChildFromObjectChildList (AmlParentHandle, AmlHandle, Buffer);
-}
+/** @file
+ ACPI Sdt Protocol Driver
+
+ Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved. <BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "AcpiTable.h"
+
+/**
+ Return the child objects buffer from AML Handle's buffer.
+
+ @param[in] AmlParentHandle Parent handle.
+ @param[in] CurrentBuffer The current child buffer.
+ @param[out] Buffer On return, points to the next returned child buffer or NULL if there are no
+ child buffer.
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_INVALID_PARAMETER AmlParentHandle does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+AmlGetChildFromObjectBuffer (
+ IN EFI_AML_HANDLE *AmlParentHandle,
+ IN UINT8 *CurrentBuffer,
+ OUT VOID **Buffer
+ )
+{
+ AML_BYTE_ENCODING *AmlByteEncoding;
+ UINTN DataSize;
+
+ //
+ // Root is considered as SCOPE, which has TermList.
+ // We need return only Object in TermList.
+ //
+ while ((UINTN)CurrentBuffer < (UINTN)(AmlParentHandle->Buffer + AmlParentHandle->Size)) {
+ AmlByteEncoding = AmlSearchByOpByte (CurrentBuffer);
+ if (AmlByteEncoding == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // NOTE: We need return everything, because user might need parse the returned object.
+ //
+ if ((AmlByteEncoding->Attribute & AML_IS_NAME_CHAR) == 0) {
+ *Buffer = CurrentBuffer;
+ return EFI_SUCCESS;
+ }
+
+ DataSize = AmlGetObjectSize (
+ AmlByteEncoding,
+ CurrentBuffer,
+ (UINTN)AmlParentHandle->Buffer + AmlParentHandle->Size - (UINTN)CurrentBuffer
+ );
+ if (DataSize == 0) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ CurrentBuffer += DataSize;
+ }
+
+ //
+ // No more
+ //
+ *Buffer = NULL;
+ return EFI_SUCCESS;
+}
+
+/**
+ Return the child ACPI objects from Root Handle.
+
+ @param[in] AmlParentHandle Parent handle. It is Root Handle.
+ @param[in] AmlHandle The previously returned handle or NULL to start with the first handle.
+ @param[out] Buffer On return, points to the next returned ACPI handle or NULL if there are no
+ child objects.
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_INVALID_PARAMETER ParentHandle is NULL or does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+AmlGetChildFromRoot (
+ IN EFI_AML_HANDLE *AmlParentHandle,
+ IN EFI_AML_HANDLE *AmlHandle,
+ OUT VOID **Buffer
+ )
+{
+ UINT8 *CurrentBuffer;
+
+ if (AmlHandle == NULL) {
+ //
+ // First One
+ //
+ CurrentBuffer = (VOID *)AmlParentHandle->Buffer;
+ } else {
+ CurrentBuffer = (VOID *)(AmlHandle->Buffer + AmlHandle->Size);
+ }
+
+ return AmlGetChildFromObjectBuffer (AmlParentHandle, CurrentBuffer, Buffer);
+}
+
+/**
+ Return the child objects buffer from AML Handle's option list.
+
+ @param[in] AmlParentHandle Parent handle.
+ @param[in] AmlHandle The current child handle.
+ @param[out] Buffer On return, points to the next returned child buffer or NULL if there are no
+ child buffer.
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_INVALID_PARAMETER AmlParentHandle does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+AmlGetChildFromOptionList (
+ IN EFI_AML_HANDLE *AmlParentHandle,
+ IN EFI_AML_HANDLE *AmlHandle,
+ OUT VOID **Buffer
+ )
+{
+ EFI_ACPI_DATA_TYPE DataType;
+ VOID *Data;
+ UINTN DataSize;
+ AML_OP_PARSE_INDEX Index;
+ EFI_STATUS Status;
+ AML_OP_PARSE_INDEX MaxTerm;
+
+ Index = AML_OP_PARSE_INDEX_GET_TERM1;
+ MaxTerm = AmlParentHandle->AmlByteEncoding->MaxIndex;
+ while (Index <= MaxTerm) {
+ Status = AmlParseOptionHandleCommon (
+ AmlParentHandle,
+ (AML_OP_PARSE_INDEX)Index,
+ &DataType,
+ (VOID **)&Data,
+ &DataSize
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (DataType == EFI_ACPI_DATA_TYPE_NONE) {
+ //
+ // Not found
+ //
+ break;
+ }
+
+ //
+ // Find it, and Check Data
+ //
+ if ((DataType == EFI_ACPI_DATA_TYPE_CHILD) &&
+ ((UINTN)AmlHandle->Buffer < (UINTN)Data))
+ {
+ //
+ // Buffer < Data means current node is next one
+ //
+ *Buffer = Data;
+ return EFI_SUCCESS;
+ }
+
+ //
+ // Not Child
+ //
+ Index++;
+ }
+
+ *Buffer = NULL;
+ return EFI_SUCCESS;
+}
+
+/**
+ Return the child objects buffer from AML Handle's object child list.
+
+ @param[in] AmlParentHandle Parent handle.
+ @param[in] AmlHandle The current child handle.
+ @param[out] Buffer On return, points to the next returned child buffer or NULL if there are no
+ child buffer.
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_INVALID_PARAMETER AmlParentHandle does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+AmlGetChildFromObjectChildList (
+ IN EFI_AML_HANDLE *AmlParentHandle,
+ IN EFI_AML_HANDLE *AmlHandle,
+ OUT VOID **Buffer
+ )
+{
+ EFI_STATUS Status;
+ UINT8 *CurrentBuffer;
+
+ CurrentBuffer = NULL;
+
+ if ((AmlParentHandle->AmlByteEncoding->Attribute & AML_HAS_CHILD_OBJ) == 0) {
+ //
+ // No ObjectList
+ //
+ *Buffer = NULL;
+ return EFI_SUCCESS;
+ }
+
+ //
+ // Do we need add node within METHOD?
+ // Yes, just add Object is OK. But we need filter NameString for METHOD invoke.
+ //
+
+ //
+ // Now, we get the last node.
+ //
+ Status = AmlGetOffsetAfterLastOption (AmlParentHandle, &CurrentBuffer);
+ if (EFI_ERROR (Status)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Go through all the reset buffer.
+ //
+ if ((UINTN)AmlHandle->Buffer < (UINTN)CurrentBuffer) {
+ //
+ // Buffer < Data means next node is first object
+ //
+ } else if ((UINTN)AmlHandle->Buffer + AmlHandle->Size < (UINTN)AmlParentHandle->Buffer + AmlParentHandle->Size) {
+ //
+ // There is still more node
+ //
+ CurrentBuffer = AmlHandle->Buffer + AmlHandle->Size;
+ } else {
+ //
+ // No more data
+ //
+ *Buffer = NULL;
+ return EFI_SUCCESS;
+ }
+
+ return AmlGetChildFromObjectBuffer (AmlParentHandle, CurrentBuffer, Buffer);
+}
+
+/**
+ Return the child ACPI objects from Non-Root Handle.
+
+ @param[in] AmlParentHandle Parent handle. It is Non-Root Handle.
+ @param[in] AmlHandle The previously returned handle or NULL to start with the first handle.
+ @param[out] Buffer On return, points to the next returned ACPI handle or NULL if there are no
+ child objects.
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_INVALID_PARAMETER ParentHandle is NULL or does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+AmlGetChildFromNonRoot (
+ IN EFI_AML_HANDLE *AmlParentHandle,
+ IN EFI_AML_HANDLE *AmlHandle,
+ OUT VOID **Buffer
+ )
+{
+ EFI_STATUS Status;
+
+ if (AmlHandle == NULL) {
+ //
+ // NULL means first one
+ //
+ AmlHandle = AmlParentHandle;
+ }
+
+ //
+ // 1. Get Option
+ //
+ Status = AmlGetChildFromOptionList (AmlParentHandle, AmlHandle, Buffer);
+ if (EFI_ERROR (Status)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (*Buffer != NULL) {
+ return EFI_SUCCESS;
+ }
+
+ //
+ // 2. search ObjectList
+ //
+ return AmlGetChildFromObjectChildList (AmlParentHandle, AmlHandle, Buffer);
+}
diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlNamespace.c b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlNamespace.c
index 61c7273048..b1531608bf 100644
--- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlNamespace.c
+++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlNamespace.c
@@ -1,614 +1,614 @@
-/** @file
- ACPI Sdt Protocol Driver
-
- Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved. <BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include "AcpiTable.h"
-
-/**
- Construct node list according to the AML handle.
-
- @param[in] AmlHandle AML handle.
- @param[in] AmlRootNodeList AML root node list.
- @param[in] AmlParentNodeList AML parent node list.
-
- @retval EFI_SUCCESS Success.
- @retval EFI_INVALID_PARAMETER AML handle does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-AmlConstructNodeList (
- IN EFI_AML_HANDLE *AmlHandle,
- IN EFI_AML_NODE_LIST *AmlRootNodeList,
- IN EFI_AML_NODE_LIST *AmlParentNodeList
- );
-
-/**
- Create AML Node.
-
- @param[in] NameSeg AML NameSeg.
- @param[in] Parent AML parent node list.
- @param[in] AmlByteEncoding AML Byte Encoding.
-
- @return AML Node.
-**/
-EFI_AML_NODE_LIST *
-AmlCreateNode (
- IN UINT8 *NameSeg,
- IN EFI_AML_NODE_LIST *Parent,
- IN AML_BYTE_ENCODING *AmlByteEncoding
- )
-{
- EFI_AML_NODE_LIST *AmlNodeList;
-
- AmlNodeList = AllocatePool (sizeof (*AmlNodeList));
- ASSERT (AmlNodeList != NULL);
-
- AmlNodeList->Signature = EFI_AML_NODE_LIST_SIGNATURE;
- CopyMem (AmlNodeList->Name, NameSeg, AML_NAME_SEG_SIZE);
- AmlNodeList->Buffer = NULL;
- AmlNodeList->Size = 0;
- InitializeListHead (&AmlNodeList->Link);
- InitializeListHead (&AmlNodeList->Children);
- AmlNodeList->Parent = Parent;
- AmlNodeList->AmlByteEncoding = AmlByteEncoding;
-
- return AmlNodeList;
-}
-
-/**
- Find the AML NameSeg in the children of AmlParentNodeList.
-
- @param[in] NameSeg AML NameSeg.
- @param[in] AmlParentNodeList AML parent node list.
- @param[in] Create TRUE means to create node if not found.
-
- @return AmlChildNode whoes name is same as NameSeg.
-**/
-EFI_AML_NODE_LIST *
-AmlFindNodeInThis (
- IN UINT8 *NameSeg,
- IN EFI_AML_NODE_LIST *AmlParentNodeList,
- IN BOOLEAN Create
- )
-{
- EFI_AML_NODE_LIST *CurrentAmlNodeList;
- LIST_ENTRY *CurrentLink;
- LIST_ENTRY *StartLink;
- EFI_AML_NODE_LIST *AmlNodeList;
-
- StartLink = &AmlParentNodeList->Children;
- CurrentLink = StartLink->ForwardLink;
-
- while (CurrentLink != StartLink) {
- CurrentAmlNodeList = EFI_AML_NODE_LIST_FROM_LINK (CurrentLink);
- //
- // AML name is same as the one stored
- //
- if (CompareMem (CurrentAmlNodeList->Name, NameSeg, AML_NAME_SEG_SIZE) == 0) {
- //
- // Good! Found it
- //
- return CurrentAmlNodeList;
- }
-
- CurrentLink = CurrentLink->ForwardLink;
- }
-
- //
- // Not found
- //
- if (!Create) {
- return NULL;
- }
-
- //
- // Create new node with NULL buffer - it means namespace not be returned.
- //
- AmlNodeList = AmlCreateNode (NameSeg, AmlParentNodeList, NULL);
- InsertTailList (&AmlParentNodeList->Children, &AmlNodeList->Link);
-
- return AmlNodeList;
-}
-
-/**
- Find the AML NameString in the children of AmlParentNodeList or AmlRootNodeList.
-
- @param[in] NameString AML NameString.
- @param[in] AmlRootNodeList AML root node list.
- @param[in] AmlParentNodeList AML parent node list.
- @param[in] Create TRUE means to create node if not found.
-
- @return AmlChildNode whoes name is same as NameSeg.
-**/
-EFI_AML_NODE_LIST *
-AmlFindNodeInTheTree (
- IN UINT8 *NameString,
- IN EFI_AML_NODE_LIST *AmlRootNodeList,
- IN EFI_AML_NODE_LIST *AmlParentNodeList,
- IN BOOLEAN Create
- )
-{
- UINT8 *Buffer;
- EFI_AML_NODE_LIST *AmlNodeList;
- EFI_AML_NODE_LIST *AmlCurrentNodeList;
- UINT8 Index;
- UINT8 SegCount;
-
- Buffer = NameString;
-
- //
- // Handle root or parent prefix
- //
- if (*Buffer == AML_ROOT_CHAR) {
- AmlCurrentNodeList = AmlRootNodeList;
- Buffer += 1;
- } else if (*Buffer == AML_PARENT_PREFIX_CHAR) {
- AmlCurrentNodeList = AmlParentNodeList;
- do {
- if (AmlCurrentNodeList->Parent != NULL) {
- AmlCurrentNodeList = AmlCurrentNodeList->Parent;
- } else {
- //
- // Only root has no parent
- //
- ASSERT (AmlCurrentNodeList == AmlRootNodeList);
- }
-
- Buffer += 1;
- } while (*Buffer == AML_PARENT_PREFIX_CHAR);
- } else {
- AmlCurrentNodeList = AmlParentNodeList;
- }
-
- //
- // Handle name segment
- //
- if (*Buffer == AML_DUAL_NAME_PREFIX) {
- Buffer += 1;
- SegCount = 2;
- } else if (*Buffer == AML_MULTI_NAME_PREFIX) {
- Buffer += 1;
- SegCount = *Buffer;
- Buffer += 1;
- } else if (*Buffer == 0) {
- //
- // NULL name, only for Root
- //
- ASSERT (AmlCurrentNodeList == AmlRootNodeList);
- return AmlCurrentNodeList;
- } else {
- SegCount = 1;
- }
-
- //
- // Handle NamePath
- //
- Index = 0;
- do {
- AmlNodeList = AmlFindNodeInThis (Buffer, AmlCurrentNodeList, Create);
- if (AmlNodeList == NULL) {
- return NULL;
- }
-
- AmlCurrentNodeList = AmlNodeList;
- Buffer += AML_NAME_SEG_SIZE;
- Index++;
- } while (Index < SegCount);
-
- return AmlNodeList;
-}
-
-/**
- Insert the NameString to the AmlNodeList.
-
- @param[in] NameString AML NameString.
- @param[in] Buffer Buffer for the Node.
- @param[in] Size Size for the Node.
- @param[in] AmlRootNodeList AML root node list.
- @param[in] AmlParentNodeList AML parent node list.
-
- @return AmlChildNode whoes name is NameString.
-**/
-EFI_AML_NODE_LIST *
-AmlInsertNodeToTree (
- IN UINT8 *NameString,
- IN VOID *Buffer,
- IN UINTN Size,
- IN EFI_AML_NODE_LIST *AmlRootNodeList,
- IN EFI_AML_NODE_LIST *AmlParentNodeList
- )
-{
- EFI_AML_NODE_LIST *AmlNodeList;
-
- AmlNodeList = AmlFindNodeInTheTree (
- NameString,
- AmlRootNodeList,
- AmlParentNodeList,
- TRUE // Find and Create
- );
- ASSERT (AmlNodeList != NULL);
- if (AmlNodeList == NULL) {
- return NULL;
- }
-
- //
- // Check buffer
- //
- if (AmlNodeList->Buffer == NULL) {
- //
- // NULL means new added one or SCOPE_OP
- //
- if (*(UINT8 *)Buffer != AML_SCOPE_OP) {
- //
- // We need check if new one is SCOPE_OP, because SCOPE_OP just means namespace, not a real device.
- // We should not return SCOPE_OP.
- //
- AmlNodeList->Buffer = Buffer;
- AmlNodeList->Size = Size;
- AmlNodeList->AmlByteEncoding = AmlSearchByOpByte (Buffer);
- }
-
- return AmlNodeList;
- }
-
- //
- // Already added
- //
- if (*(UINT8 *)Buffer == AML_SCOPE_OP) {
- //
- // The new one is SCOPE_OP, OK just return;
- //
- return AmlNodeList;
- }
-
- //
- // Oops!!!, There must be something wrong.
- //
- DEBUG ((DEBUG_ERROR, "AML: Override Happen - %a!\n", NameString));
- DEBUG ((DEBUG_ERROR, "AML: Existing Node - %x\n", AmlNodeList->Buffer));
- DEBUG ((DEBUG_ERROR, "AML: New Buffer - %x\n", Buffer));
-
- return NULL;
-}
-
-/**
- Construct child node list according to the AML handle.
-
- @param[in] AmlHandle AML handle.
- @param[in] AmlRootNodeList AML root node list.
- @param[in] AmlParentNodeList AML parent node list.
-
- @retval EFI_SUCCESS Success.
- @retval EFI_INVALID_PARAMETER AML handle does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-AmlConstructNodeListForChild (
- IN EFI_AML_HANDLE *AmlHandle,
- IN EFI_AML_NODE_LIST *AmlRootNodeList,
- IN EFI_AML_NODE_LIST *AmlParentNodeList
- )
-{
- AML_BYTE_ENCODING *AmlByteEncoding;
- UINT8 *Buffer;
- UINTN BufferSize;
- UINT8 *CurrentBuffer;
- EFI_AML_HANDLE *AmlChildHandle;
- EFI_STATUS Status;
-
- CurrentBuffer = NULL;
- AmlChildHandle = NULL;
- AmlByteEncoding = AmlHandle->AmlByteEncoding;
- Buffer = AmlHandle->Buffer;
- BufferSize = AmlHandle->Size;
-
- //
- // Check if we need recursively add node
- //
- if ((AmlByteEncoding->Attribute & AML_HAS_CHILD_OBJ) == 0) {
- //
- // No more node need to be added
- //
- return EFI_SUCCESS;
- }
-
- //
- // Do we need add node within METHOD?
- // Yes, just add Object is OK. But we need filter NameString for METHOD invoke.
- //
-
- //
- // Now, we get the last node.
- //
- Status = AmlGetOffsetAfterLastOption (AmlHandle, &CurrentBuffer);
- if (EFI_ERROR (Status)) {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // Go through all the reset buffer.
- //
- while ((UINTN)CurrentBuffer < (UINTN)Buffer + BufferSize) {
- //
- // Find the child node.
- //
- Status = SdtOpenEx (CurrentBuffer, (UINTN)Buffer + BufferSize - (UINTN)CurrentBuffer, (EFI_ACPI_HANDLE *)&AmlChildHandle);
- if (EFI_ERROR (Status)) {
- //
- // No child found, break now.
- //
- break;
- }
-
- //
- // Good, find the child. Construct node recursively
- //
- Status = AmlConstructNodeList (
- AmlChildHandle,
- AmlRootNodeList,
- AmlParentNodeList
- );
- if (EFI_ERROR (Status)) {
- break;
- }
-
- //
- // Parse next one
- //
- CurrentBuffer += AmlChildHandle->Size;
-
- Close ((EFI_ACPI_HANDLE)AmlChildHandle);
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Construct node list according to the AML handle.
-
- @param[in] AmlHandle AML handle.
- @param[in] AmlRootNodeList AML root node list.
- @param[in] AmlParentNodeList AML parent node list.
-
- @retval EFI_SUCCESS Success.
- @retval EFI_INVALID_PARAMETER AML handle does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-AmlConstructNodeList (
- IN EFI_AML_HANDLE *AmlHandle,
- IN EFI_AML_NODE_LIST *AmlRootNodeList,
- IN EFI_AML_NODE_LIST *AmlParentNodeList
- )
-{
- VOID *NameString;
- EFI_AML_NODE_LIST *AmlNodeList;
-
- //
- // 1. Check if there is need to construct node for this OpCode.
- //
- if ((AmlHandle->AmlByteEncoding->Attribute & AML_IN_NAMESPACE) == 0) {
- //
- // No need to construct node, so we just skip this OpCode.
- //
- return EFI_SUCCESS;
- }
-
- //
- // 2. Now, we need construct node for this OpCode.
- //
- NameString = AmlGetObjectName (AmlHandle);
- if (NameString == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // Now, we need to insert node to the node list.
- // NOTE: The name here could be AML NameString. So the callee need parse it.
- //
- AmlNodeList = AmlInsertNodeToTree (NameString, AmlHandle->Buffer, AmlHandle->Size, AmlRootNodeList, AmlParentNodeList);
- ASSERT (AmlNodeList != NULL);
-
- //
- // 3. Ok, we need to parse the object list to see if there are more node to be added.
- //
- return AmlConstructNodeListForChild (AmlHandle, AmlRootNodeList, AmlNodeList);
-}
-
-/**
- Destruct node list
-
- @param[in] AmlParentNodeList AML parent node list.
-**/
-VOID
-AmlDestructNodeList (
- IN EFI_AML_NODE_LIST *AmlParentNodeList
- )
-{
- EFI_AML_NODE_LIST *CurrentAmlNodeList;
- LIST_ENTRY *CurrentLink;
- LIST_ENTRY *StartLink;
-
- //
- // Get the children link
- //
- StartLink = &AmlParentNodeList->Children;
- CurrentLink = StartLink->ForwardLink;
-
- //
- // Go through all the children
- //
- while (CurrentLink != StartLink) {
- //
- // Destruct the child's list recursively
- //
- CurrentAmlNodeList = EFI_AML_NODE_LIST_FROM_LINK (CurrentLink);
- CurrentLink = CurrentLink->ForwardLink;
-
- //
- // Remove this child from list and free the node
- //
- RemoveEntryList (&(CurrentAmlNodeList->Link));
-
- AmlDestructNodeList (CurrentAmlNodeList);
- }
-
- //
- // Done.
- //
- FreePool (AmlParentNodeList);
- return;
-}
-
-/**
- Dump node list
-
- @param[in] AmlParentNodeList AML parent node list.
- @param[in] Level Output debug level.
-**/
-VOID
-AmlDumpNodeInfo (
- IN EFI_AML_NODE_LIST *AmlParentNodeList,
- IN UINTN Level
- )
-{
- EFI_AML_NODE_LIST *CurrentAmlNodeList;
- volatile LIST_ENTRY *CurrentLink;
- UINTN Index;
-
- CurrentLink = AmlParentNodeList->Children.ForwardLink;
-
- if (Level == 0) {
- DEBUG ((DEBUG_ERROR, "\\"));
- } else {
- for (Index = 0; Index < Level; Index++) {
- DEBUG ((DEBUG_ERROR, " "));
- }
-
- AmlPrintNameSeg (AmlParentNodeList->Name);
- }
-
- DEBUG ((DEBUG_ERROR, "\n"));
-
- while (CurrentLink != &AmlParentNodeList->Children) {
- CurrentAmlNodeList = EFI_AML_NODE_LIST_FROM_LINK (CurrentLink);
- AmlDumpNodeInfo (CurrentAmlNodeList, Level + 1);
- CurrentLink = CurrentLink->ForwardLink;
- }
-
- return;
-}
-
-/**
- Returns the handle of the ACPI object representing the specified ACPI AML path
-
- @param[in] AmlHandle Points to the handle of the object representing the starting point for the path search.
- @param[in] AmlPath Points to the ACPI AML path.
- @param[out] Buffer On return, points to the ACPI object which represents AcpiPath, relative to
- HandleIn.
- @param[in] FromRoot TRUE means to find AML path from \ (Root) Node.
- FALSE means to find AML path from this Node (The HandleIn).
-
- @retval EFI_SUCCESS Success
- @retval EFI_INVALID_PARAMETER HandleIn does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-AmlFindPath (
- IN EFI_AML_HANDLE *AmlHandle,
- IN UINT8 *AmlPath,
- OUT VOID **Buffer,
- IN BOOLEAN FromRoot
- )
-{
- EFI_AML_NODE_LIST *AmlRootNodeList;
- EFI_STATUS Status;
- EFI_AML_NODE_LIST *AmlNodeList;
- UINT8 RootNameSeg[AML_NAME_SEG_SIZE];
- EFI_AML_NODE_LIST *CurrentAmlNodeList;
- LIST_ENTRY *CurrentLink;
-
- //
- // 1. create tree
- //
-
- //
- // Create root handle
- //
- RootNameSeg[0] = AML_ROOT_CHAR;
- RootNameSeg[1] = 0;
- AmlRootNodeList = AmlCreateNode (RootNameSeg, NULL, AmlHandle->AmlByteEncoding);
-
- Status = AmlConstructNodeList (
- AmlHandle,
- AmlRootNodeList, // Root
- AmlRootNodeList // Parent
- );
- if (EFI_ERROR (Status)) {
- return EFI_INVALID_PARAMETER;
- }
-
- DEBUG_CODE_BEGIN ();
- DEBUG ((DEBUG_ERROR, "AcpiSdt: NameSpace:\n"));
- AmlDumpNodeInfo (AmlRootNodeList, 0);
- DEBUG_CODE_END ();
-
- //
- // 2. Search the node in the tree
- //
- if (FromRoot) {
- //
- // Search from Root
- //
- CurrentAmlNodeList = AmlRootNodeList;
- } else {
- //
- // Search from this node, NOT ROOT.
- // Since we insert node to ROOT one by one, we just get the first node and search from it.
- //
- CurrentLink = AmlRootNodeList->Children.ForwardLink;
- if (CurrentLink != &AmlRootNodeList->Children) {
- //
- // First node
- //
- CurrentAmlNodeList = EFI_AML_NODE_LIST_FROM_LINK (CurrentLink);
- } else {
- //
- // No child
- //
- CurrentAmlNodeList = NULL;
- }
- }
-
- //
- // Search
- //
- if (CurrentAmlNodeList != NULL) {
- DEBUG_CODE_BEGIN ();
- DEBUG ((DEBUG_ERROR, "AcpiSdt: Search from: \\"));
- AmlPrintNameSeg (CurrentAmlNodeList->Name);
- DEBUG ((DEBUG_ERROR, "\n"));
- DEBUG_CODE_END ();
- AmlNodeList = AmlFindNodeInTheTree (
- AmlPath,
- AmlRootNodeList, // Root
- CurrentAmlNodeList, // Parent
- FALSE
- );
- } else {
- AmlNodeList = NULL;
- }
-
- *Buffer = NULL;
- Status = EFI_SUCCESS;
- if ((AmlNodeList != NULL) && (AmlNodeList->Buffer != NULL)) {
- *Buffer = AmlNodeList->Buffer;
- }
-
- //
- // 3. free the tree
- //
- AmlDestructNodeList (AmlRootNodeList);
-
- return Status;
-}
+/** @file
+ ACPI Sdt Protocol Driver
+
+ Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved. <BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "AcpiTable.h"
+
+/**
+ Construct node list according to the AML handle.
+
+ @param[in] AmlHandle AML handle.
+ @param[in] AmlRootNodeList AML root node list.
+ @param[in] AmlParentNodeList AML parent node list.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER AML handle does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+AmlConstructNodeList (
+ IN EFI_AML_HANDLE *AmlHandle,
+ IN EFI_AML_NODE_LIST *AmlRootNodeList,
+ IN EFI_AML_NODE_LIST *AmlParentNodeList
+ );
+
+/**
+ Create AML Node.
+
+ @param[in] NameSeg AML NameSeg.
+ @param[in] Parent AML parent node list.
+ @param[in] AmlByteEncoding AML Byte Encoding.
+
+ @return AML Node.
+**/
+EFI_AML_NODE_LIST *
+AmlCreateNode (
+ IN UINT8 *NameSeg,
+ IN EFI_AML_NODE_LIST *Parent,
+ IN AML_BYTE_ENCODING *AmlByteEncoding
+ )
+{
+ EFI_AML_NODE_LIST *AmlNodeList;
+
+ AmlNodeList = AllocatePool (sizeof (*AmlNodeList));
+ ASSERT (AmlNodeList != NULL);
+
+ AmlNodeList->Signature = EFI_AML_NODE_LIST_SIGNATURE;
+ CopyMem (AmlNodeList->Name, NameSeg, AML_NAME_SEG_SIZE);
+ AmlNodeList->Buffer = NULL;
+ AmlNodeList->Size = 0;
+ InitializeListHead (&AmlNodeList->Link);
+ InitializeListHead (&AmlNodeList->Children);
+ AmlNodeList->Parent = Parent;
+ AmlNodeList->AmlByteEncoding = AmlByteEncoding;
+
+ return AmlNodeList;
+}
+
+/**
+ Find the AML NameSeg in the children of AmlParentNodeList.
+
+ @param[in] NameSeg AML NameSeg.
+ @param[in] AmlParentNodeList AML parent node list.
+ @param[in] Create TRUE means to create node if not found.
+
+ @return AmlChildNode whoes name is same as NameSeg.
+**/
+EFI_AML_NODE_LIST *
+AmlFindNodeInThis (
+ IN UINT8 *NameSeg,
+ IN EFI_AML_NODE_LIST *AmlParentNodeList,
+ IN BOOLEAN Create
+ )
+{
+ EFI_AML_NODE_LIST *CurrentAmlNodeList;
+ LIST_ENTRY *CurrentLink;
+ LIST_ENTRY *StartLink;
+ EFI_AML_NODE_LIST *AmlNodeList;
+
+ StartLink = &AmlParentNodeList->Children;
+ CurrentLink = StartLink->ForwardLink;
+
+ while (CurrentLink != StartLink) {
+ CurrentAmlNodeList = EFI_AML_NODE_LIST_FROM_LINK (CurrentLink);
+ //
+ // AML name is same as the one stored
+ //
+ if (CompareMem (CurrentAmlNodeList->Name, NameSeg, AML_NAME_SEG_SIZE) == 0) {
+ //
+ // Good! Found it
+ //
+ return CurrentAmlNodeList;
+ }
+
+ CurrentLink = CurrentLink->ForwardLink;
+ }
+
+ //
+ // Not found
+ //
+ if (!Create) {
+ return NULL;
+ }
+
+ //
+ // Create new node with NULL buffer - it means namespace not be returned.
+ //
+ AmlNodeList = AmlCreateNode (NameSeg, AmlParentNodeList, NULL);
+ InsertTailList (&AmlParentNodeList->Children, &AmlNodeList->Link);
+
+ return AmlNodeList;
+}
+
+/**
+ Find the AML NameString in the children of AmlParentNodeList or AmlRootNodeList.
+
+ @param[in] NameString AML NameString.
+ @param[in] AmlRootNodeList AML root node list.
+ @param[in] AmlParentNodeList AML parent node list.
+ @param[in] Create TRUE means to create node if not found.
+
+ @return AmlChildNode whoes name is same as NameSeg.
+**/
+EFI_AML_NODE_LIST *
+AmlFindNodeInTheTree (
+ IN UINT8 *NameString,
+ IN EFI_AML_NODE_LIST *AmlRootNodeList,
+ IN EFI_AML_NODE_LIST *AmlParentNodeList,
+ IN BOOLEAN Create
+ )
+{
+ UINT8 *Buffer;
+ EFI_AML_NODE_LIST *AmlNodeList;
+ EFI_AML_NODE_LIST *AmlCurrentNodeList;
+ UINT8 Index;
+ UINT8 SegCount;
+
+ Buffer = NameString;
+
+ //
+ // Handle root or parent prefix
+ //
+ if (*Buffer == AML_ROOT_CHAR) {
+ AmlCurrentNodeList = AmlRootNodeList;
+ Buffer += 1;
+ } else if (*Buffer == AML_PARENT_PREFIX_CHAR) {
+ AmlCurrentNodeList = AmlParentNodeList;
+ do {
+ if (AmlCurrentNodeList->Parent != NULL) {
+ AmlCurrentNodeList = AmlCurrentNodeList->Parent;
+ } else {
+ //
+ // Only root has no parent
+ //
+ ASSERT (AmlCurrentNodeList == AmlRootNodeList);
+ }
+
+ Buffer += 1;
+ } while (*Buffer == AML_PARENT_PREFIX_CHAR);
+ } else {
+ AmlCurrentNodeList = AmlParentNodeList;
+ }
+
+ //
+ // Handle name segment
+ //
+ if (*Buffer == AML_DUAL_NAME_PREFIX) {
+ Buffer += 1;
+ SegCount = 2;
+ } else if (*Buffer == AML_MULTI_NAME_PREFIX) {
+ Buffer += 1;
+ SegCount = *Buffer;
+ Buffer += 1;
+ } else if (*Buffer == 0) {
+ //
+ // NULL name, only for Root
+ //
+ ASSERT (AmlCurrentNodeList == AmlRootNodeList);
+ return AmlCurrentNodeList;
+ } else {
+ SegCount = 1;
+ }
+
+ //
+ // Handle NamePath
+ //
+ Index = 0;
+ do {
+ AmlNodeList = AmlFindNodeInThis (Buffer, AmlCurrentNodeList, Create);
+ if (AmlNodeList == NULL) {
+ return NULL;
+ }
+
+ AmlCurrentNodeList = AmlNodeList;
+ Buffer += AML_NAME_SEG_SIZE;
+ Index++;
+ } while (Index < SegCount);
+
+ return AmlNodeList;
+}
+
+/**
+ Insert the NameString to the AmlNodeList.
+
+ @param[in] NameString AML NameString.
+ @param[in] Buffer Buffer for the Node.
+ @param[in] Size Size for the Node.
+ @param[in] AmlRootNodeList AML root node list.
+ @param[in] AmlParentNodeList AML parent node list.
+
+ @return AmlChildNode whoes name is NameString.
+**/
+EFI_AML_NODE_LIST *
+AmlInsertNodeToTree (
+ IN UINT8 *NameString,
+ IN VOID *Buffer,
+ IN UINTN Size,
+ IN EFI_AML_NODE_LIST *AmlRootNodeList,
+ IN EFI_AML_NODE_LIST *AmlParentNodeList
+ )
+{
+ EFI_AML_NODE_LIST *AmlNodeList;
+
+ AmlNodeList = AmlFindNodeInTheTree (
+ NameString,
+ AmlRootNodeList,
+ AmlParentNodeList,
+ TRUE // Find and Create
+ );
+ ASSERT (AmlNodeList != NULL);
+ if (AmlNodeList == NULL) {
+ return NULL;
+ }
+
+ //
+ // Check buffer
+ //
+ if (AmlNodeList->Buffer == NULL) {
+ //
+ // NULL means new added one or SCOPE_OP
+ //
+ if (*(UINT8 *)Buffer != AML_SCOPE_OP) {
+ //
+ // We need check if new one is SCOPE_OP, because SCOPE_OP just means namespace, not a real device.
+ // We should not return SCOPE_OP.
+ //
+ AmlNodeList->Buffer = Buffer;
+ AmlNodeList->Size = Size;
+ AmlNodeList->AmlByteEncoding = AmlSearchByOpByte (Buffer);
+ }
+
+ return AmlNodeList;
+ }
+
+ //
+ // Already added
+ //
+ if (*(UINT8 *)Buffer == AML_SCOPE_OP) {
+ //
+ // The new one is SCOPE_OP, OK just return;
+ //
+ return AmlNodeList;
+ }
+
+ //
+ // Oops!!!, There must be something wrong.
+ //
+ DEBUG ((DEBUG_ERROR, "AML: Override Happen - %a!\n", NameString));
+ DEBUG ((DEBUG_ERROR, "AML: Existing Node - %x\n", AmlNodeList->Buffer));
+ DEBUG ((DEBUG_ERROR, "AML: New Buffer - %x\n", Buffer));
+
+ return NULL;
+}
+
+/**
+ Construct child node list according to the AML handle.
+
+ @param[in] AmlHandle AML handle.
+ @param[in] AmlRootNodeList AML root node list.
+ @param[in] AmlParentNodeList AML parent node list.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER AML handle does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+AmlConstructNodeListForChild (
+ IN EFI_AML_HANDLE *AmlHandle,
+ IN EFI_AML_NODE_LIST *AmlRootNodeList,
+ IN EFI_AML_NODE_LIST *AmlParentNodeList
+ )
+{
+ AML_BYTE_ENCODING *AmlByteEncoding;
+ UINT8 *Buffer;
+ UINTN BufferSize;
+ UINT8 *CurrentBuffer;
+ EFI_AML_HANDLE *AmlChildHandle;
+ EFI_STATUS Status;
+
+ CurrentBuffer = NULL;
+ AmlChildHandle = NULL;
+ AmlByteEncoding = AmlHandle->AmlByteEncoding;
+ Buffer = AmlHandle->Buffer;
+ BufferSize = AmlHandle->Size;
+
+ //
+ // Check if we need recursively add node
+ //
+ if ((AmlByteEncoding->Attribute & AML_HAS_CHILD_OBJ) == 0) {
+ //
+ // No more node need to be added
+ //
+ return EFI_SUCCESS;
+ }
+
+ //
+ // Do we need add node within METHOD?
+ // Yes, just add Object is OK. But we need filter NameString for METHOD invoke.
+ //
+
+ //
+ // Now, we get the last node.
+ //
+ Status = AmlGetOffsetAfterLastOption (AmlHandle, &CurrentBuffer);
+ if (EFI_ERROR (Status)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Go through all the reset buffer.
+ //
+ while ((UINTN)CurrentBuffer < (UINTN)Buffer + BufferSize) {
+ //
+ // Find the child node.
+ //
+ Status = SdtOpenEx (CurrentBuffer, (UINTN)Buffer + BufferSize - (UINTN)CurrentBuffer, (EFI_ACPI_HANDLE *)&AmlChildHandle);
+ if (EFI_ERROR (Status)) {
+ //
+ // No child found, break now.
+ //
+ break;
+ }
+
+ //
+ // Good, find the child. Construct node recursively
+ //
+ Status = AmlConstructNodeList (
+ AmlChildHandle,
+ AmlRootNodeList,
+ AmlParentNodeList
+ );
+ if (EFI_ERROR (Status)) {
+ break;
+ }
+
+ //
+ // Parse next one
+ //
+ CurrentBuffer += AmlChildHandle->Size;
+
+ Close ((EFI_ACPI_HANDLE)AmlChildHandle);
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Construct node list according to the AML handle.
+
+ @param[in] AmlHandle AML handle.
+ @param[in] AmlRootNodeList AML root node list.
+ @param[in] AmlParentNodeList AML parent node list.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER AML handle does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+AmlConstructNodeList (
+ IN EFI_AML_HANDLE *AmlHandle,
+ IN EFI_AML_NODE_LIST *AmlRootNodeList,
+ IN EFI_AML_NODE_LIST *AmlParentNodeList
+ )
+{
+ VOID *NameString;
+ EFI_AML_NODE_LIST *AmlNodeList;
+
+ //
+ // 1. Check if there is need to construct node for this OpCode.
+ //
+ if ((AmlHandle->AmlByteEncoding->Attribute & AML_IN_NAMESPACE) == 0) {
+ //
+ // No need to construct node, so we just skip this OpCode.
+ //
+ return EFI_SUCCESS;
+ }
+
+ //
+ // 2. Now, we need construct node for this OpCode.
+ //
+ NameString = AmlGetObjectName (AmlHandle);
+ if (NameString == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // Now, we need to insert node to the node list.
+ // NOTE: The name here could be AML NameString. So the callee need parse it.
+ //
+ AmlNodeList = AmlInsertNodeToTree (NameString, AmlHandle->Buffer, AmlHandle->Size, AmlRootNodeList, AmlParentNodeList);
+ ASSERT (AmlNodeList != NULL);
+
+ //
+ // 3. Ok, we need to parse the object list to see if there are more node to be added.
+ //
+ return AmlConstructNodeListForChild (AmlHandle, AmlRootNodeList, AmlNodeList);
+}
+
+/**
+ Destruct node list
+
+ @param[in] AmlParentNodeList AML parent node list.
+**/
+VOID
+AmlDestructNodeList (
+ IN EFI_AML_NODE_LIST *AmlParentNodeList
+ )
+{
+ EFI_AML_NODE_LIST *CurrentAmlNodeList;
+ LIST_ENTRY *CurrentLink;
+ LIST_ENTRY *StartLink;
+
+ //
+ // Get the children link
+ //
+ StartLink = &AmlParentNodeList->Children;
+ CurrentLink = StartLink->ForwardLink;
+
+ //
+ // Go through all the children
+ //
+ while (CurrentLink != StartLink) {
+ //
+ // Destruct the child's list recursively
+ //
+ CurrentAmlNodeList = EFI_AML_NODE_LIST_FROM_LINK (CurrentLink);
+ CurrentLink = CurrentLink->ForwardLink;
+
+ //
+ // Remove this child from list and free the node
+ //
+ RemoveEntryList (&(CurrentAmlNodeList->Link));
+
+ AmlDestructNodeList (CurrentAmlNodeList);
+ }
+
+ //
+ // Done.
+ //
+ FreePool (AmlParentNodeList);
+ return;
+}
+
+/**
+ Dump node list
+
+ @param[in] AmlParentNodeList AML parent node list.
+ @param[in] Level Output debug level.
+**/
+VOID
+AmlDumpNodeInfo (
+ IN EFI_AML_NODE_LIST *AmlParentNodeList,
+ IN UINTN Level
+ )
+{
+ EFI_AML_NODE_LIST *CurrentAmlNodeList;
+ volatile LIST_ENTRY *CurrentLink;
+ UINTN Index;
+
+ CurrentLink = AmlParentNodeList->Children.ForwardLink;
+
+ if (Level == 0) {
+ DEBUG ((DEBUG_ERROR, "\\"));
+ } else {
+ for (Index = 0; Index < Level; Index++) {
+ DEBUG ((DEBUG_ERROR, " "));
+ }
+
+ AmlPrintNameSeg (AmlParentNodeList->Name);
+ }
+
+ DEBUG ((DEBUG_ERROR, "\n"));
+
+ while (CurrentLink != &AmlParentNodeList->Children) {
+ CurrentAmlNodeList = EFI_AML_NODE_LIST_FROM_LINK (CurrentLink);
+ AmlDumpNodeInfo (CurrentAmlNodeList, Level + 1);
+ CurrentLink = CurrentLink->ForwardLink;
+ }
+
+ return;
+}
+
+/**
+ Returns the handle of the ACPI object representing the specified ACPI AML path
+
+ @param[in] AmlHandle Points to the handle of the object representing the starting point for the path search.
+ @param[in] AmlPath Points to the ACPI AML path.
+ @param[out] Buffer On return, points to the ACPI object which represents AcpiPath, relative to
+ HandleIn.
+ @param[in] FromRoot TRUE means to find AML path from \ (Root) Node.
+ FALSE means to find AML path from this Node (The HandleIn).
+
+ @retval EFI_SUCCESS Success
+ @retval EFI_INVALID_PARAMETER HandleIn does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+AmlFindPath (
+ IN EFI_AML_HANDLE *AmlHandle,
+ IN UINT8 *AmlPath,
+ OUT VOID **Buffer,
+ IN BOOLEAN FromRoot
+ )
+{
+ EFI_AML_NODE_LIST *AmlRootNodeList;
+ EFI_STATUS Status;
+ EFI_AML_NODE_LIST *AmlNodeList;
+ UINT8 RootNameSeg[AML_NAME_SEG_SIZE];
+ EFI_AML_NODE_LIST *CurrentAmlNodeList;
+ LIST_ENTRY *CurrentLink;
+
+ //
+ // 1. create tree
+ //
+
+ //
+ // Create root handle
+ //
+ RootNameSeg[0] = AML_ROOT_CHAR;
+ RootNameSeg[1] = 0;
+ AmlRootNodeList = AmlCreateNode (RootNameSeg, NULL, AmlHandle->AmlByteEncoding);
+
+ Status = AmlConstructNodeList (
+ AmlHandle,
+ AmlRootNodeList, // Root
+ AmlRootNodeList // Parent
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ DEBUG_CODE_BEGIN ();
+ DEBUG ((DEBUG_ERROR, "AcpiSdt: NameSpace:\n"));
+ AmlDumpNodeInfo (AmlRootNodeList, 0);
+ DEBUG_CODE_END ();
+
+ //
+ // 2. Search the node in the tree
+ //
+ if (FromRoot) {
+ //
+ // Search from Root
+ //
+ CurrentAmlNodeList = AmlRootNodeList;
+ } else {
+ //
+ // Search from this node, NOT ROOT.
+ // Since we insert node to ROOT one by one, we just get the first node and search from it.
+ //
+ CurrentLink = AmlRootNodeList->Children.ForwardLink;
+ if (CurrentLink != &AmlRootNodeList->Children) {
+ //
+ // First node
+ //
+ CurrentAmlNodeList = EFI_AML_NODE_LIST_FROM_LINK (CurrentLink);
+ } else {
+ //
+ // No child
+ //
+ CurrentAmlNodeList = NULL;
+ }
+ }
+
+ //
+ // Search
+ //
+ if (CurrentAmlNodeList != NULL) {
+ DEBUG_CODE_BEGIN ();
+ DEBUG ((DEBUG_ERROR, "AcpiSdt: Search from: \\"));
+ AmlPrintNameSeg (CurrentAmlNodeList->Name);
+ DEBUG ((DEBUG_ERROR, "\n"));
+ DEBUG_CODE_END ();
+ AmlNodeList = AmlFindNodeInTheTree (
+ AmlPath,
+ AmlRootNodeList, // Root
+ CurrentAmlNodeList, // Parent
+ FALSE
+ );
+ } else {
+ AmlNodeList = NULL;
+ }
+
+ *Buffer = NULL;
+ Status = EFI_SUCCESS;
+ if ((AmlNodeList != NULL) && (AmlNodeList->Buffer != NULL)) {
+ *Buffer = AmlNodeList->Buffer;
+ }
+
+ //
+ // 3. free the tree
+ //
+ AmlDestructNodeList (AmlRootNodeList);
+
+ return Status;
+}
diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlOption.c b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlOption.c
index fbcf340e4b..f5b8e48a94 100644
--- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlOption.c
+++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlOption.c
@@ -1,466 +1,466 @@
-/** @file
- ACPI Sdt Protocol Driver
-
- Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved. <BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include "AcpiTable.h"
-
-/**
- Retrieve option term according to AmlByteEncoding and Buffer.
-
- @param[in] AmlByteEncoding AML Byte Encoding.
- @param[in] Buffer AML buffer.
- @param[in] MaxBufferSize AML buffer MAX size. The parser can not parse any data exceed this region.
- @param[in] TermIndex Index of the data to retrieve from the object.
- @param[out] DataType Points to the returned data type or EFI_ACPI_DATA_TYPE_NONE if no data exists
- for the specified index.
- @param[out] Data Upon return, points to the pointer to the data.
- @param[out] DataSize Upon return, points to the size of Data.
-
- @retval EFI_SUCCESS Success.
- @retval EFI_INVALID_PARAMETER Buffer does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-AmlParseOptionTerm (
- IN AML_BYTE_ENCODING *AmlByteEncoding,
- IN UINT8 *Buffer,
- IN UINTN MaxBufferSize,
- IN AML_OP_PARSE_INDEX TermIndex,
- OUT EFI_ACPI_DATA_TYPE *DataType,
- OUT VOID **Data,
- OUT UINTN *DataSize
- )
-{
- AML_BYTE_ENCODING *ChildAmlByteEncoding;
- EFI_STATUS Status;
-
- if (DataType != NULL) {
- *DataType = AmlTypeToAcpiType (AmlByteEncoding->Format[TermIndex - 1]);
- }
-
- if (Data != NULL) {
- *Data = Buffer;
- }
-
- //
- // Parse term according to AML type
- //
- switch (AmlByteEncoding->Format[TermIndex - 1]) {
- case AML_UINT8:
- *DataSize = sizeof (UINT8);
- break;
- case AML_UINT16:
- *DataSize = sizeof (UINT16);
- break;
- case AML_UINT32:
- *DataSize = sizeof (UINT32);
- break;
- case AML_UINT64:
- *DataSize = sizeof (UINT64);
- break;
- case AML_STRING:
- *DataSize = AsciiStrSize ((CHAR8 *)Buffer);
- break;
- case AML_NAME:
- Status = AmlGetNameStringSize (Buffer, DataSize);
- if (EFI_ERROR (Status)) {
- return EFI_INVALID_PARAMETER;
- }
-
- break;
- case AML_OBJECT:
- ChildAmlByteEncoding = AmlSearchByOpByte (Buffer);
- if (ChildAmlByteEncoding == NULL) {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // NOTE: We need override DataType here, if there is a case the AML_OBJECT is AML_NAME.
- // We need convert type from EFI_ACPI_DATA_TYPE_CHILD to EFI_ACPI_DATA_TYPE_NAME_STRING.
- // We should not return CHILD because there is NO OpCode for NameString.
- //
- if ((ChildAmlByteEncoding->Attribute & AML_IS_NAME_CHAR) != 0) {
- if (DataType != NULL) {
- *DataType = AmlTypeToAcpiType (AML_NAME);
- }
-
- Status = AmlGetNameStringSize (Buffer, DataSize);
- if (EFI_ERROR (Status)) {
- return EFI_INVALID_PARAMETER;
- }
-
- break;
- }
-
- //
- // It is real AML_OBJECT
- //
- *DataSize = AmlGetObjectSize (
- ChildAmlByteEncoding,
- Buffer,
- MaxBufferSize
- );
- if (*DataSize == 0) {
- return EFI_INVALID_PARAMETER;
- }
-
- break;
- case AML_NONE:
- //
- // No term
- //
- case AML_OPCODE:
- default:
- ASSERT (FALSE);
- return EFI_INVALID_PARAMETER;
- }
-
- if (*DataSize > MaxBufferSize) {
- return EFI_INVALID_PARAMETER;
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Retrieve information according to AmlByteEncoding and Buffer.
-
- @param[in] AmlByteEncoding AML Byte Encoding.
- @param[in] Buffer AML buffer.
- @param[in] MaxBufferSize AML buffer MAX size. The parser can not parse any data exceed this region.
- @param[in] Index Index of the data to retrieve from the object. In general, indexes read from left-to-right
- in the ACPI encoding, with index 0 always being the ACPI opcode.
- @param[out] DataType Points to the returned data type or EFI_ACPI_DATA_TYPE_NONE if no data exists
- for the specified index.
- @param[out] Data Upon return, points to the pointer to the data.
- @param[out] DataSize Upon return, points to the size of Data.
-
- @retval EFI_SUCCESS Success.
- @retval EFI_INVALID_PARAMETER Buffer does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-AmlParseOptionCommon (
- IN AML_BYTE_ENCODING *AmlByteEncoding,
- IN UINT8 *Buffer,
- IN UINTN MaxBufferSize,
- IN AML_OP_PARSE_INDEX Index,
- OUT EFI_ACPI_DATA_TYPE *DataType,
- OUT VOID **Data,
- OUT UINTN *DataSize
- )
-{
- UINT8 *CurrentBuffer;
- UINTN PkgLength;
- UINTN OpLength;
- UINTN PkgOffset;
- AML_OP_PARSE_INDEX TermIndex;
- EFI_STATUS Status;
-
- ASSERT ((Index <= AmlByteEncoding->MaxIndex) || (Index == AML_OP_PARSE_INDEX_GET_SIZE));
-
- //
- // 0. Check if this is NAME string.
- //
- if ((AmlByteEncoding->Attribute & AML_IS_NAME_CHAR) != 0) {
- //
- // Only allow GET_SIZE
- //
- if (Index != AML_OP_PARSE_INDEX_GET_SIZE) {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // return NameString size
- //
- Status = AmlGetNameStringSize (Buffer, DataSize);
- if (EFI_ERROR (Status)) {
- return EFI_INVALID_PARAMETER;
- }
-
- if (*DataSize > MaxBufferSize) {
- return EFI_INVALID_PARAMETER;
- }
-
- return EFI_SUCCESS;
- }
-
- //
- // Not NAME string, start parsing
- //
- CurrentBuffer = Buffer;
-
- //
- // 1. Get OpCode
- //
- if (Index != AML_OP_PARSE_INDEX_GET_SIZE) {
- *DataType = EFI_ACPI_DATA_TYPE_OPCODE;
- *Data = (VOID *)CurrentBuffer;
- }
-
- if (*CurrentBuffer == AML_EXT_OP) {
- OpLength = 2;
- } else {
- OpLength = 1;
- }
-
- *DataSize = OpLength;
- if (Index == AML_OP_PARSE_INDEX_GET_OPCODE) {
- return EFI_SUCCESS;
- }
-
- if (OpLength > MaxBufferSize) {
- return EFI_INVALID_PARAMETER;
- }
-
- CurrentBuffer += OpLength;
-
- //
- // 2. Skip PkgLength field, if have
- //
- if ((AmlByteEncoding->Attribute & AML_HAS_PKG_LENGTH) != 0) {
- PkgOffset = AmlGetPkgLength (CurrentBuffer, &PkgLength);
- //
- // Override MaxBufferSize if it is valid PkgLength
- //
- if (OpLength + PkgLength > MaxBufferSize) {
- return EFI_INVALID_PARAMETER;
- } else {
- MaxBufferSize = OpLength + PkgLength;
- }
- } else {
- PkgOffset = 0;
- PkgLength = 0;
- }
-
- CurrentBuffer += PkgOffset;
-
- //
- // 3. Get Term one by one.
- //
- TermIndex = AML_OP_PARSE_INDEX_GET_TERM1;
- while ((Index >= TermIndex) && (TermIndex <= AmlByteEncoding->MaxIndex) && ((UINTN)CurrentBuffer < (UINTN)Buffer + MaxBufferSize)) {
- Status = AmlParseOptionTerm (
- AmlByteEncoding,
- CurrentBuffer,
- (UINTN)Buffer + MaxBufferSize - (UINTN)CurrentBuffer,
- TermIndex,
- DataType,
- Data,
- DataSize
- );
- if (EFI_ERROR (Status)) {
- return EFI_INVALID_PARAMETER;
- }
-
- if (Index == TermIndex) {
- //
- // Done
- //
- return EFI_SUCCESS;
- }
-
- //
- // Parse next one
- //
- CurrentBuffer += *DataSize;
- TermIndex++;
- }
-
- //
- // Finish all options, but no option found.
- //
- if ((UINTN)CurrentBuffer > (UINTN)Buffer + MaxBufferSize) {
- return EFI_INVALID_PARAMETER;
- }
-
- if ((UINTN)CurrentBuffer == (UINTN)Buffer + MaxBufferSize) {
- if (Index != AML_OP_PARSE_INDEX_GET_SIZE) {
- return EFI_INVALID_PARAMETER;
- }
- }
-
- //
- // 4. Finish parsing all node, return size
- //
- ASSERT (Index == AML_OP_PARSE_INDEX_GET_SIZE);
- if ((AmlByteEncoding->Attribute & AML_HAS_PKG_LENGTH) != 0) {
- *DataSize = OpLength + PkgLength;
- } else {
- *DataSize = (UINTN)CurrentBuffer - (UINTN)Buffer;
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Return object size.
-
- @param[in] AmlByteEncoding AML Byte Encoding.
- @param[in] Buffer AML object buffer.
- @param[in] MaxBufferSize AML object buffer MAX size. The parser can not parse any data exceed this region.
-
- @return Size of the object.
-**/
-UINTN
-AmlGetObjectSize (
- IN AML_BYTE_ENCODING *AmlByteEncoding,
- IN UINT8 *Buffer,
- IN UINTN MaxBufferSize
- )
-{
- EFI_STATUS Status;
- UINTN DataSize;
-
- Status = AmlParseOptionCommon (
- AmlByteEncoding,
- Buffer,
- MaxBufferSize,
- AML_OP_PARSE_INDEX_GET_SIZE,
- NULL,
- NULL,
- &DataSize
- );
- if (EFI_ERROR (Status)) {
- return 0;
- } else {
- return DataSize;
- }
-}
-
-/**
- Return object name.
-
- @param[in] AmlHandle AML handle.
-
- @return Name of the object.
-**/
-CHAR8 *
-AmlGetObjectName (
- IN EFI_AML_HANDLE *AmlHandle
- )
-{
- AML_BYTE_ENCODING *AmlByteEncoding;
- VOID *NameString;
- UINTN NameSize;
- AML_OP_PARSE_INDEX TermIndex;
- EFI_STATUS Status;
- EFI_ACPI_DATA_TYPE DataType;
-
- AmlByteEncoding = AmlHandle->AmlByteEncoding;
-
- ASSERT ((AmlByteEncoding->Attribute & AML_IN_NAMESPACE) != 0);
-
- //
- // Find out Last Name index, according to OpCode table.
- // The last name will be the node name by design.
- //
- TermIndex = AmlByteEncoding->MaxIndex;
- for (TermIndex = AmlByteEncoding->MaxIndex; TermIndex > 0; TermIndex--) {
- if (AmlByteEncoding->Format[TermIndex - 1] == AML_NAME) {
- break;
- }
- }
-
- ASSERT (TermIndex != 0);
-
- //
- // Get Name for this node.
- //
- Status = AmlParseOptionHandleCommon (
- AmlHandle,
- TermIndex,
- &DataType,
- &NameString,
- &NameSize
- );
- if (EFI_ERROR (Status)) {
- return NULL;
- }
-
- ASSERT (DataType == EFI_ACPI_DATA_TYPE_NAME_STRING);
-
- return NameString;
-}
-
-/**
- Return offset of last option.
-
- @param[in] AmlHandle AML Handle.
- @param[out] Buffer Upon return, points to the offset after last option.
-
- @retval EFI_SUCCESS Success.
- @retval EFI_INVALID_PARAMETER AmlHandle does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-AmlGetOffsetAfterLastOption (
- IN EFI_AML_HANDLE *AmlHandle,
- OUT UINT8 **Buffer
- )
-{
- EFI_ACPI_DATA_TYPE DataType;
- VOID *Data;
- UINTN DataSize;
- EFI_STATUS Status;
-
- Status = AmlParseOptionHandleCommon (
- AmlHandle,
- AmlHandle->AmlByteEncoding->MaxIndex,
- &DataType,
- &Data,
- &DataSize
- );
- if (EFI_ERROR (Status)) {
- return EFI_INVALID_PARAMETER;
- }
-
- //
- // We need to parse the rest buffer after last node.
- //
- *Buffer = (UINT8 *)((UINTN)Data + DataSize);
-
- //
- // We need skip PkgLength if no Option
- //
- if (DataType == EFI_ACPI_DATA_TYPE_OPCODE) {
- *Buffer += AmlGetPkgLength (*Buffer, &DataSize);
- }
-
- return EFI_SUCCESS;
-}
-
-/**
- Retrieve information according to AmlHandle
-
- @param[in] AmlHandle AML handle.
- @param[in] Index Index of the data to retrieve from the object. In general, indexes read from left-to-right
- in the ACPI encoding, with index 0 always being the ACPI opcode.
- @param[out] DataType Points to the returned data type or EFI_ACPI_DATA_TYPE_NONE if no data exists
- for the specified index.
- @param[out] Data Upon return, points to the pointer to the data.
- @param[out] DataSize Upon return, points to the size of Data.
-
- @retval EFI_SUCCESS Success.
- @retval EFI_INVALID_PARAMETER AmlHandle does not refer to a valid ACPI object.
-**/
-EFI_STATUS
-AmlParseOptionHandleCommon (
- IN EFI_AML_HANDLE *AmlHandle,
- IN AML_OP_PARSE_INDEX Index,
- OUT EFI_ACPI_DATA_TYPE *DataType,
- OUT VOID **Data,
- OUT UINTN *DataSize
- )
-{
- return AmlParseOptionCommon (
- AmlHandle->AmlByteEncoding,
- AmlHandle->Buffer,
- AmlHandle->Size,
- Index,
- DataType,
- Data,
- DataSize
- );
-}
+/** @file
+ ACPI Sdt Protocol Driver
+
+ Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved. <BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "AcpiTable.h"
+
+/**
+ Retrieve option term according to AmlByteEncoding and Buffer.
+
+ @param[in] AmlByteEncoding AML Byte Encoding.
+ @param[in] Buffer AML buffer.
+ @param[in] MaxBufferSize AML buffer MAX size. The parser can not parse any data exceed this region.
+ @param[in] TermIndex Index of the data to retrieve from the object.
+ @param[out] DataType Points to the returned data type or EFI_ACPI_DATA_TYPE_NONE if no data exists
+ for the specified index.
+ @param[out] Data Upon return, points to the pointer to the data.
+ @param[out] DataSize Upon return, points to the size of Data.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER Buffer does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+AmlParseOptionTerm (
+ IN AML_BYTE_ENCODING *AmlByteEncoding,
+ IN UINT8 *Buffer,
+ IN UINTN MaxBufferSize,
+ IN AML_OP_PARSE_INDEX TermIndex,
+ OUT EFI_ACPI_DATA_TYPE *DataType,
+ OUT VOID **Data,
+ OUT UINTN *DataSize
+ )
+{
+ AML_BYTE_ENCODING *ChildAmlByteEncoding;
+ EFI_STATUS Status;
+
+ if (DataType != NULL) {
+ *DataType = AmlTypeToAcpiType (AmlByteEncoding->Format[TermIndex - 1]);
+ }
+
+ if (Data != NULL) {
+ *Data = Buffer;
+ }
+
+ //
+ // Parse term according to AML type
+ //
+ switch (AmlByteEncoding->Format[TermIndex - 1]) {
+ case AML_UINT8:
+ *DataSize = sizeof (UINT8);
+ break;
+ case AML_UINT16:
+ *DataSize = sizeof (UINT16);
+ break;
+ case AML_UINT32:
+ *DataSize = sizeof (UINT32);
+ break;
+ case AML_UINT64:
+ *DataSize = sizeof (UINT64);
+ break;
+ case AML_STRING:
+ *DataSize = AsciiStrSize ((CHAR8 *)Buffer);
+ break;
+ case AML_NAME:
+ Status = AmlGetNameStringSize (Buffer, DataSize);
+ if (EFI_ERROR (Status)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ break;
+ case AML_OBJECT:
+ ChildAmlByteEncoding = AmlSearchByOpByte (Buffer);
+ if (ChildAmlByteEncoding == NULL) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // NOTE: We need override DataType here, if there is a case the AML_OBJECT is AML_NAME.
+ // We need convert type from EFI_ACPI_DATA_TYPE_CHILD to EFI_ACPI_DATA_TYPE_NAME_STRING.
+ // We should not return CHILD because there is NO OpCode for NameString.
+ //
+ if ((ChildAmlByteEncoding->Attribute & AML_IS_NAME_CHAR) != 0) {
+ if (DataType != NULL) {
+ *DataType = AmlTypeToAcpiType (AML_NAME);
+ }
+
+ Status = AmlGetNameStringSize (Buffer, DataSize);
+ if (EFI_ERROR (Status)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ break;
+ }
+
+ //
+ // It is real AML_OBJECT
+ //
+ *DataSize = AmlGetObjectSize (
+ ChildAmlByteEncoding,
+ Buffer,
+ MaxBufferSize
+ );
+ if (*DataSize == 0) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ break;
+ case AML_NONE:
+ //
+ // No term
+ //
+ case AML_OPCODE:
+ default:
+ ASSERT (FALSE);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (*DataSize > MaxBufferSize) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Retrieve information according to AmlByteEncoding and Buffer.
+
+ @param[in] AmlByteEncoding AML Byte Encoding.
+ @param[in] Buffer AML buffer.
+ @param[in] MaxBufferSize AML buffer MAX size. The parser can not parse any data exceed this region.
+ @param[in] Index Index of the data to retrieve from the object. In general, indexes read from left-to-right
+ in the ACPI encoding, with index 0 always being the ACPI opcode.
+ @param[out] DataType Points to the returned data type or EFI_ACPI_DATA_TYPE_NONE if no data exists
+ for the specified index.
+ @param[out] Data Upon return, points to the pointer to the data.
+ @param[out] DataSize Upon return, points to the size of Data.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER Buffer does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+AmlParseOptionCommon (
+ IN AML_BYTE_ENCODING *AmlByteEncoding,
+ IN UINT8 *Buffer,
+ IN UINTN MaxBufferSize,
+ IN AML_OP_PARSE_INDEX Index,
+ OUT EFI_ACPI_DATA_TYPE *DataType,
+ OUT VOID **Data,
+ OUT UINTN *DataSize
+ )
+{
+ UINT8 *CurrentBuffer;
+ UINTN PkgLength;
+ UINTN OpLength;
+ UINTN PkgOffset;
+ AML_OP_PARSE_INDEX TermIndex;
+ EFI_STATUS Status;
+
+ ASSERT ((Index <= AmlByteEncoding->MaxIndex) || (Index == AML_OP_PARSE_INDEX_GET_SIZE));
+
+ //
+ // 0. Check if this is NAME string.
+ //
+ if ((AmlByteEncoding->Attribute & AML_IS_NAME_CHAR) != 0) {
+ //
+ // Only allow GET_SIZE
+ //
+ if (Index != AML_OP_PARSE_INDEX_GET_SIZE) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // return NameString size
+ //
+ Status = AmlGetNameStringSize (Buffer, DataSize);
+ if (EFI_ERROR (Status)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (*DataSize > MaxBufferSize) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ return EFI_SUCCESS;
+ }
+
+ //
+ // Not NAME string, start parsing
+ //
+ CurrentBuffer = Buffer;
+
+ //
+ // 1. Get OpCode
+ //
+ if (Index != AML_OP_PARSE_INDEX_GET_SIZE) {
+ *DataType = EFI_ACPI_DATA_TYPE_OPCODE;
+ *Data = (VOID *)CurrentBuffer;
+ }
+
+ if (*CurrentBuffer == AML_EXT_OP) {
+ OpLength = 2;
+ } else {
+ OpLength = 1;
+ }
+
+ *DataSize = OpLength;
+ if (Index == AML_OP_PARSE_INDEX_GET_OPCODE) {
+ return EFI_SUCCESS;
+ }
+
+ if (OpLength > MaxBufferSize) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ CurrentBuffer += OpLength;
+
+ //
+ // 2. Skip PkgLength field, if have
+ //
+ if ((AmlByteEncoding->Attribute & AML_HAS_PKG_LENGTH) != 0) {
+ PkgOffset = AmlGetPkgLength (CurrentBuffer, &PkgLength);
+ //
+ // Override MaxBufferSize if it is valid PkgLength
+ //
+ if (OpLength + PkgLength > MaxBufferSize) {
+ return EFI_INVALID_PARAMETER;
+ } else {
+ MaxBufferSize = OpLength + PkgLength;
+ }
+ } else {
+ PkgOffset = 0;
+ PkgLength = 0;
+ }
+
+ CurrentBuffer += PkgOffset;
+
+ //
+ // 3. Get Term one by one.
+ //
+ TermIndex = AML_OP_PARSE_INDEX_GET_TERM1;
+ while ((Index >= TermIndex) && (TermIndex <= AmlByteEncoding->MaxIndex) && ((UINTN)CurrentBuffer < (UINTN)Buffer + MaxBufferSize)) {
+ Status = AmlParseOptionTerm (
+ AmlByteEncoding,
+ CurrentBuffer,
+ (UINTN)Buffer + MaxBufferSize - (UINTN)CurrentBuffer,
+ TermIndex,
+ DataType,
+ Data,
+ DataSize
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if (Index == TermIndex) {
+ //
+ // Done
+ //
+ return EFI_SUCCESS;
+ }
+
+ //
+ // Parse next one
+ //
+ CurrentBuffer += *DataSize;
+ TermIndex++;
+ }
+
+ //
+ // Finish all options, but no option found.
+ //
+ if ((UINTN)CurrentBuffer > (UINTN)Buffer + MaxBufferSize) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ if ((UINTN)CurrentBuffer == (UINTN)Buffer + MaxBufferSize) {
+ if (Index != AML_OP_PARSE_INDEX_GET_SIZE) {
+ return EFI_INVALID_PARAMETER;
+ }
+ }
+
+ //
+ // 4. Finish parsing all node, return size
+ //
+ ASSERT (Index == AML_OP_PARSE_INDEX_GET_SIZE);
+ if ((AmlByteEncoding->Attribute & AML_HAS_PKG_LENGTH) != 0) {
+ *DataSize = OpLength + PkgLength;
+ } else {
+ *DataSize = (UINTN)CurrentBuffer - (UINTN)Buffer;
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Return object size.
+
+ @param[in] AmlByteEncoding AML Byte Encoding.
+ @param[in] Buffer AML object buffer.
+ @param[in] MaxBufferSize AML object buffer MAX size. The parser can not parse any data exceed this region.
+
+ @return Size of the object.
+**/
+UINTN
+AmlGetObjectSize (
+ IN AML_BYTE_ENCODING *AmlByteEncoding,
+ IN UINT8 *Buffer,
+ IN UINTN MaxBufferSize
+ )
+{
+ EFI_STATUS Status;
+ UINTN DataSize;
+
+ Status = AmlParseOptionCommon (
+ AmlByteEncoding,
+ Buffer,
+ MaxBufferSize,
+ AML_OP_PARSE_INDEX_GET_SIZE,
+ NULL,
+ NULL,
+ &DataSize
+ );
+ if (EFI_ERROR (Status)) {
+ return 0;
+ } else {
+ return DataSize;
+ }
+}
+
+/**
+ Return object name.
+
+ @param[in] AmlHandle AML handle.
+
+ @return Name of the object.
+**/
+CHAR8 *
+AmlGetObjectName (
+ IN EFI_AML_HANDLE *AmlHandle
+ )
+{
+ AML_BYTE_ENCODING *AmlByteEncoding;
+ VOID *NameString;
+ UINTN NameSize;
+ AML_OP_PARSE_INDEX TermIndex;
+ EFI_STATUS Status;
+ EFI_ACPI_DATA_TYPE DataType;
+
+ AmlByteEncoding = AmlHandle->AmlByteEncoding;
+
+ ASSERT ((AmlByteEncoding->Attribute & AML_IN_NAMESPACE) != 0);
+
+ //
+ // Find out Last Name index, according to OpCode table.
+ // The last name will be the node name by design.
+ //
+ TermIndex = AmlByteEncoding->MaxIndex;
+ for (TermIndex = AmlByteEncoding->MaxIndex; TermIndex > 0; TermIndex--) {
+ if (AmlByteEncoding->Format[TermIndex - 1] == AML_NAME) {
+ break;
+ }
+ }
+
+ ASSERT (TermIndex != 0);
+
+ //
+ // Get Name for this node.
+ //
+ Status = AmlParseOptionHandleCommon (
+ AmlHandle,
+ TermIndex,
+ &DataType,
+ &NameString,
+ &NameSize
+ );
+ if (EFI_ERROR (Status)) {
+ return NULL;
+ }
+
+ ASSERT (DataType == EFI_ACPI_DATA_TYPE_NAME_STRING);
+
+ return NameString;
+}
+
+/**
+ Return offset of last option.
+
+ @param[in] AmlHandle AML Handle.
+ @param[out] Buffer Upon return, points to the offset after last option.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER AmlHandle does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+AmlGetOffsetAfterLastOption (
+ IN EFI_AML_HANDLE *AmlHandle,
+ OUT UINT8 **Buffer
+ )
+{
+ EFI_ACPI_DATA_TYPE DataType;
+ VOID *Data;
+ UINTN DataSize;
+ EFI_STATUS Status;
+
+ Status = AmlParseOptionHandleCommon (
+ AmlHandle,
+ AmlHandle->AmlByteEncoding->MaxIndex,
+ &DataType,
+ &Data,
+ &DataSize
+ );
+ if (EFI_ERROR (Status)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ //
+ // We need to parse the rest buffer after last node.
+ //
+ *Buffer = (UINT8 *)((UINTN)Data + DataSize);
+
+ //
+ // We need skip PkgLength if no Option
+ //
+ if (DataType == EFI_ACPI_DATA_TYPE_OPCODE) {
+ *Buffer += AmlGetPkgLength (*Buffer, &DataSize);
+ }
+
+ return EFI_SUCCESS;
+}
+
+/**
+ Retrieve information according to AmlHandle
+
+ @param[in] AmlHandle AML handle.
+ @param[in] Index Index of the data to retrieve from the object. In general, indexes read from left-to-right
+ in the ACPI encoding, with index 0 always being the ACPI opcode.
+ @param[out] DataType Points to the returned data type or EFI_ACPI_DATA_TYPE_NONE if no data exists
+ for the specified index.
+ @param[out] Data Upon return, points to the pointer to the data.
+ @param[out] DataSize Upon return, points to the size of Data.
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER AmlHandle does not refer to a valid ACPI object.
+**/
+EFI_STATUS
+AmlParseOptionHandleCommon (
+ IN EFI_AML_HANDLE *AmlHandle,
+ IN AML_OP_PARSE_INDEX Index,
+ OUT EFI_ACPI_DATA_TYPE *DataType,
+ OUT VOID **Data,
+ OUT UINTN *DataSize
+ )
+{
+ return AmlParseOptionCommon (
+ AmlHandle->AmlByteEncoding,
+ AmlHandle->Buffer,
+ AmlHandle->Size,
+ Index,
+ DataType,
+ Data,
+ DataSize
+ );
+}
diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlString.c b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlString.c
index 9f67770578..2cf8d0284b 100644
--- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlString.c
+++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlString.c
@@ -1,552 +1,552 @@
-/** @file
- ACPI Sdt Protocol Driver
-
- Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved. <BR>
- SPDX-License-Identifier: BSD-2-Clause-Patent
-
-**/
-
-#include "AcpiTable.h"
-
-/**
- Check if it is AML Root name
-
- @param[in] Buffer AML path.
-
- @retval TRUE AML path is root.
- @retval FALSE AML path is not root.
-**/
-BOOLEAN
-AmlIsRootPath (
- IN UINT8 *Buffer
- )
-{
- if ((Buffer[0] == AML_ROOT_CHAR) && (Buffer[1] == 0)) {
- return TRUE;
- } else {
- return FALSE;
- }
-}
-
-/**
- Check if it is AML LeadName.
-
- @param[in] Ch Char.
-
- @retval TRUE Char is AML LeadName.
- @retval FALSE Char is not AML LeadName.
-**/
-BOOLEAN
-AmlIsLeadName (
- IN CHAR8 Ch
- )
-{
- if ((Ch == '_') || ((Ch >= 'A') && (Ch <= 'Z'))) {
- return TRUE;
- } else {
- return FALSE;
- }
-}
-
-/**
- Check if it is AML Name.
-
- @param[in] Ch Char.
-
- @retval TRUE Char is AML Name.
- @retval FALSE Char is not AML Name.
-**/
-BOOLEAN
-AmlIsName (
- IN CHAR8 Ch
- )
-{
- if (AmlIsLeadName (Ch) || ((Ch >= '0') && (Ch <= '9'))) {
- return TRUE;
- } else {
- return FALSE;
- }
-}
-
-/**
- Return is buffer is AML NameSeg.
-
- @param[in] Buffer AML NameSement.
-
- @retval TRUE It is AML NameSegment.
- @retval FALSE It is not AML NameSegment.
-**/
-BOOLEAN
-AmlIsNameSeg (
- IN UINT8 *Buffer
- )
-{
- UINTN Index;
-
- if (!AmlIsLeadName (Buffer[0])) {
- return FALSE;
- }
-
- for (Index = 1; Index < AML_NAME_SEG_SIZE; Index++) {
- if (!AmlIsName (Buffer[Index])) {
- return FALSE;
- }
- }
-
- return TRUE;
-}
-
-/**
- Get AML NameString size.
-
- @param[in] Buffer AML NameString.
- @param[out] BufferSize AML NameString size
-
- @retval EFI_SUCCESS Success.
- @retval EFI_INVALID_PARAMETER Buffer does not refer to a valid AML NameString.
-**/
-EFI_STATUS
-AmlGetNameStringSize (
- IN UINT8 *Buffer,
- OUT UINTN *BufferSize
- )
-{
- UINTN SegCount;
- UINTN Length;
- UINTN Index;
-
- Length = 0;
-
- //
- // Parse root or parent prefix
- //
- if (*Buffer == AML_ROOT_CHAR) {
- Buffer++;
- Length++;
- } else if (*Buffer == AML_PARENT_PREFIX_CHAR) {
- do {
- Buffer++;
- Length++;
- } while (*Buffer == AML_PARENT_PREFIX_CHAR);
- }
-
- //
- // Parse name segment
- //
- if (*Buffer == AML_DUAL_NAME_PREFIX) {
- Buffer++;
- Length++;
- SegCount = 2;
- } else if (*Buffer == AML_MULTI_NAME_PREFIX) {
- Buffer++;
- Length++;
- SegCount = *Buffer;
- Buffer++;
- Length++;
- } else if (*Buffer == 0) {
- //
- // NULL Name, only for Root
- //
- SegCount = 0;
- Buffer--;
- if ((Length == 1) && (*Buffer == AML_ROOT_CHAR)) {
- *BufferSize = 2;
- return EFI_SUCCESS;
- } else {
- return EFI_INVALID_PARAMETER;
- }
- } else {
- //
- // NameSeg
- //
- SegCount = 1;
- }
-
- Index = 0;
- do {
- if (!AmlIsNameSeg (Buffer)) {
- return EFI_INVALID_PARAMETER;
- }
-
- Buffer += AML_NAME_SEG_SIZE;
- Length += AML_NAME_SEG_SIZE;
- Index++;
- } while (Index < SegCount);
-
- *BufferSize = Length;
- return EFI_SUCCESS;
-}
-
-/**
- Check if it is ASL LeadName.
-
- @param[in] Ch Char.
-
- @retval TRUE Char is ASL LeadName.
- @retval FALSE Char is not ASL LeadName.
-**/
-BOOLEAN
-AmlIsAslLeadName (
- IN CHAR8 Ch
- )
-{
- if (AmlIsLeadName (Ch) || ((Ch >= 'a') && (Ch <= 'z'))) {
- return TRUE;
- } else {
- return FALSE;
- }
-}
-
-/**
- Check if it is ASL Name.
-
- @param[in] Ch Char.
-
- @retval TRUE Char is ASL Name.
- @retval FALSE Char is not ASL Name.
-**/
-BOOLEAN
-AmlIsAslName (
- IN CHAR8 Ch
- )
-{
- if (AmlIsAslLeadName (Ch) || ((Ch >= '0') && (Ch <= '9'))) {
- return TRUE;
- } else {
- return FALSE;
- }
-}
-
-/**
- Get ASL NameString size.
-
- @param[in] Buffer ASL NameString.
-
- @return ASL NameString size.
-**/
-UINTN
-AmlGetAslNameSegLength (
- IN UINT8 *Buffer
- )
-{
- UINTN Length;
- UINTN Index;
-
- if (*Buffer == 0) {
- return 0;
- }
-
- Length = 0;
- //
- // 1st
- //
- if (AmlIsAslLeadName (*Buffer)) {
- Length++;
- Buffer++;
- }
-
- if ((*Buffer == 0) || (*Buffer == '.')) {
- return Length;
- }
-
- //
- // 2, 3, 4 name char
- //
- for (Index = 0; Index < 3; Index++) {
- if (AmlIsAslName (*Buffer)) {
- Length++;
- Buffer++;
- }
-
- if ((*Buffer == 0) || (*Buffer == '.')) {
- return Length;
- }
- }
-
- //
- // Invalid ASL name
- //
- return 0;
-}
-
-/**
- Get ASL NameString size.
-
- @param[in] Buffer ASL NameString.
- @param[out] Root On return, points to Root char number.
- @param[out] Parent On return, points to Parent char number.
- @param[out] SegCount On return, points to Segment count.
-
- @return ASL NameString size.
-**/
-UINTN
-AmlGetAslNameStringSize (
- IN UINT8 *Buffer,
- OUT UINTN *Root,
- OUT UINTN *Parent,
- OUT UINTN *SegCount
- )
-{
- UINTN NameLength;
- UINTN TotalLength;
-
- *Root = 0;
- *Parent = 0;
- *SegCount = 0;
- TotalLength = 0;
- NameLength = 0;
- if (*Buffer == AML_ROOT_CHAR) {
- *Root = 1;
- Buffer++;
- } else if (*Buffer == AML_PARENT_PREFIX_CHAR) {
- do {
- Buffer++;
- (*Parent)++;
- } while (*Buffer == AML_PARENT_PREFIX_CHAR);
- }
-
- //
- // Now parse name
- //
- while (*Buffer != 0) {
- NameLength = AmlGetAslNameSegLength (Buffer);
- if ((NameLength == 0) || (NameLength > AML_NAME_SEG_SIZE)) {
- return 0;
- }
-
- (*SegCount)++;
- Buffer += NameLength;
- if (*Buffer == 0) {
- break;
- }
-
- Buffer++;
- }
-
- //
- // Check SegCoount
- //
- if (*SegCount > 0xFF) {
- return 0;
- }
-
- //
- // Calculate total length
- //
- TotalLength = *Root + *Parent + (*SegCount) * AML_NAME_SEG_SIZE;
- if (*SegCount > 2) {
- TotalLength += 2;
- } else if (*SegCount == 2) {
- TotalLength += 1;
- }
-
- //
- // Add NULL char
- //
- TotalLength++;
-
- return TotalLength;
-}
-
-/**
- Copy mem, and cast all the char in dest to be upper case.
-
- @param[in] DstBuffer Destination buffer.
- @param[in] SrcBuffer Source buffer.
- @param[in] Length Buffer length.
-**/
-VOID
-AmlUpperCaseCopyMem (
- IN UINT8 *DstBuffer,
- IN UINT8 *SrcBuffer,
- IN UINTN Length
- )
-{
- UINTN Index;
-
- for (Index = 0; Index < Length; Index++) {
- if ((SrcBuffer[Index] >= 'a') && (SrcBuffer[Index] <= 'z')) {
- DstBuffer[Index] = (UINT8)(SrcBuffer[Index] - 'a' + 'A');
- } else {
- DstBuffer[Index] = SrcBuffer[Index];
- }
- }
-}
-
-/**
- Return AML name according to ASL name.
- The caller need free the AmlName returned.
-
- @param[in] AslPath ASL name.
-
- @return AmlName
-**/
-UINT8 *
-AmlNameFromAslName (
- IN UINT8 *AslPath
- )
-{
- UINTN Root;
- UINTN Parent;
- UINTN SegCount;
- UINTN TotalLength;
- UINTN NameLength;
- UINT8 *Buffer;
- UINT8 *AmlPath;
- UINT8 *AmlBuffer;
-
- TotalLength = AmlGetAslNameStringSize (AslPath, &Root, &Parent, &SegCount);
- if (TotalLength == 0) {
- return NULL;
- }
-
- AmlPath = AllocatePool (TotalLength);
- ASSERT (AmlPath != NULL);
-
- AmlBuffer = AmlPath;
- Buffer = AslPath;
-
- //
- // Handle Root and Parent
- //
- if (Root == 1) {
- *AmlBuffer = AML_ROOT_CHAR;
- AmlBuffer++;
- Buffer++;
- } else if (Parent > 0) {
- SetMem (AmlBuffer, Parent, AML_PARENT_PREFIX_CHAR);
- AmlBuffer += Parent;
- Buffer += Parent;
- }
-
- //
- // Handle SegCount
- //
- if (SegCount > 2) {
- *AmlBuffer = AML_MULTI_NAME_PREFIX;
- AmlBuffer++;
- *AmlBuffer = (UINT8)SegCount;
- AmlBuffer++;
- } else if (SegCount == 2) {
- *AmlBuffer = AML_DUAL_NAME_PREFIX;
- AmlBuffer++;
- }
-
- //
- // Now to name
- //
- while (*Buffer != 0) {
- NameLength = AmlGetAslNameSegLength (Buffer);
- ASSERT ((NameLength != 0) && (NameLength <= AML_NAME_SEG_SIZE));
- AmlUpperCaseCopyMem (AmlBuffer, Buffer, NameLength);
- SetMem (AmlBuffer + NameLength, AML_NAME_SEG_SIZE - NameLength, AML_NAME_CHAR__);
- Buffer += NameLength;
- AmlBuffer += AML_NAME_SEG_SIZE;
- if (*Buffer == 0) {
- break;
- }
-
- Buffer++;
- }
-
- //
- // Add NULL
- //
- AmlPath[TotalLength - 1] = 0;
-
- return AmlPath;
-}
-
-/**
- Print AML NameSeg.
-
- @param[in] Buffer AML NameSeg.
-**/
-VOID
-AmlPrintNameSeg (
- IN UINT8 *Buffer
- )
-{
- DEBUG ((DEBUG_ERROR, "%c", Buffer[0]));
- if ((Buffer[1] == '_') && (Buffer[2] == '_') && (Buffer[3] == '_')) {
- return;
- }
-
- DEBUG ((DEBUG_ERROR, "%c", Buffer[1]));
- if ((Buffer[2] == '_') && (Buffer[3] == '_')) {
- return;
- }
-
- DEBUG ((DEBUG_ERROR, "%c", Buffer[2]));
- if (Buffer[3] == '_') {
- return;
- }
-
- DEBUG ((DEBUG_ERROR, "%c", Buffer[3]));
- return;
-}
-
-/**
- Print AML NameString.
-
- @param[in] Buffer AML NameString.
-**/
-VOID
-AmlPrintNameString (
- IN UINT8 *Buffer
- )
-{
- UINT8 SegCount;
- UINT8 Index;
-
- if (*Buffer == AML_ROOT_CHAR) {
- //
- // RootChar
- //
- Buffer++;
- DEBUG ((DEBUG_ERROR, "\\"));
- } else if (*Buffer == AML_PARENT_PREFIX_CHAR) {
- //
- // ParentPrefixChar
- //
- do {
- Buffer++;
- DEBUG ((DEBUG_ERROR, "^"));
- } while (*Buffer == AML_PARENT_PREFIX_CHAR);
- }
-
- if (*Buffer == AML_DUAL_NAME_PREFIX) {
- //
- // DualName
- //
- Buffer++;
- SegCount = 2;
- } else if (*Buffer == AML_MULTI_NAME_PREFIX) {
- //
- // MultiName
- //
- Buffer++;
- SegCount = *Buffer;
- Buffer++;
- } else if (*Buffer == 0) {
- //
- // NULL Name
- //
- return;
- } else {
- //
- // NameSeg
- //
- SegCount = 1;
- }
-
- AmlPrintNameSeg (Buffer);
- Buffer += AML_NAME_SEG_SIZE;
- for (Index = 0; Index < SegCount - 1; Index++) {
- DEBUG ((DEBUG_ERROR, "."));
- AmlPrintNameSeg (Buffer);
- Buffer += AML_NAME_SEG_SIZE;
- }
-
- return;
-}
+/** @file
+ ACPI Sdt Protocol Driver
+
+ Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved. <BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "AcpiTable.h"
+
+/**
+ Check if it is AML Root name
+
+ @param[in] Buffer AML path.
+
+ @retval TRUE AML path is root.
+ @retval FALSE AML path is not root.
+**/
+BOOLEAN
+AmlIsRootPath (
+ IN UINT8 *Buffer
+ )
+{
+ if ((Buffer[0] == AML_ROOT_CHAR) && (Buffer[1] == 0)) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+/**
+ Check if it is AML LeadName.
+
+ @param[in] Ch Char.
+
+ @retval TRUE Char is AML LeadName.
+ @retval FALSE Char is not AML LeadName.
+**/
+BOOLEAN
+AmlIsLeadName (
+ IN CHAR8 Ch
+ )
+{
+ if ((Ch == '_') || ((Ch >= 'A') && (Ch <= 'Z'))) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+/**
+ Check if it is AML Name.
+
+ @param[in] Ch Char.
+
+ @retval TRUE Char is AML Name.
+ @retval FALSE Char is not AML Name.
+**/
+BOOLEAN
+AmlIsName (
+ IN CHAR8 Ch
+ )
+{
+ if (AmlIsLeadName (Ch) || ((Ch >= '0') && (Ch <= '9'))) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+/**
+ Return is buffer is AML NameSeg.
+
+ @param[in] Buffer AML NameSement.
+
+ @retval TRUE It is AML NameSegment.
+ @retval FALSE It is not AML NameSegment.
+**/
+BOOLEAN
+AmlIsNameSeg (
+ IN UINT8 *Buffer
+ )
+{
+ UINTN Index;
+
+ if (!AmlIsLeadName (Buffer[0])) {
+ return FALSE;
+ }
+
+ for (Index = 1; Index < AML_NAME_SEG_SIZE; Index++) {
+ if (!AmlIsName (Buffer[Index])) {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+}
+
+/**
+ Get AML NameString size.
+
+ @param[in] Buffer AML NameString.
+ @param[out] BufferSize AML NameString size
+
+ @retval EFI_SUCCESS Success.
+ @retval EFI_INVALID_PARAMETER Buffer does not refer to a valid AML NameString.
+**/
+EFI_STATUS
+AmlGetNameStringSize (
+ IN UINT8 *Buffer,
+ OUT UINTN *BufferSize
+ )
+{
+ UINTN SegCount;
+ UINTN Length;
+ UINTN Index;
+
+ Length = 0;
+
+ //
+ // Parse root or parent prefix
+ //
+ if (*Buffer == AML_ROOT_CHAR) {
+ Buffer++;
+ Length++;
+ } else if (*Buffer == AML_PARENT_PREFIX_CHAR) {
+ do {
+ Buffer++;
+ Length++;
+ } while (*Buffer == AML_PARENT_PREFIX_CHAR);
+ }
+
+ //
+ // Parse name segment
+ //
+ if (*Buffer == AML_DUAL_NAME_PREFIX) {
+ Buffer++;
+ Length++;
+ SegCount = 2;
+ } else if (*Buffer == AML_MULTI_NAME_PREFIX) {
+ Buffer++;
+ Length++;
+ SegCount = *Buffer;
+ Buffer++;
+ Length++;
+ } else if (*Buffer == 0) {
+ //
+ // NULL Name, only for Root
+ //
+ SegCount = 0;
+ Buffer--;
+ if ((Length == 1) && (*Buffer == AML_ROOT_CHAR)) {
+ *BufferSize = 2;
+ return EFI_SUCCESS;
+ } else {
+ return EFI_INVALID_PARAMETER;
+ }
+ } else {
+ //
+ // NameSeg
+ //
+ SegCount = 1;
+ }
+
+ Index = 0;
+ do {
+ if (!AmlIsNameSeg (Buffer)) {
+ return EFI_INVALID_PARAMETER;
+ }
+
+ Buffer += AML_NAME_SEG_SIZE;
+ Length += AML_NAME_SEG_SIZE;
+ Index++;
+ } while (Index < SegCount);
+
+ *BufferSize = Length;
+ return EFI_SUCCESS;
+}
+
+/**
+ Check if it is ASL LeadName.
+
+ @param[in] Ch Char.
+
+ @retval TRUE Char is ASL LeadName.
+ @retval FALSE Char is not ASL LeadName.
+**/
+BOOLEAN
+AmlIsAslLeadName (
+ IN CHAR8 Ch
+ )
+{
+ if (AmlIsLeadName (Ch) || ((Ch >= 'a') && (Ch <= 'z'))) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+/**
+ Check if it is ASL Name.
+
+ @param[in] Ch Char.
+
+ @retval TRUE Char is ASL Name.
+ @retval FALSE Char is not ASL Name.
+**/
+BOOLEAN
+AmlIsAslName (
+ IN CHAR8 Ch
+ )
+{
+ if (AmlIsAslLeadName (Ch) || ((Ch >= '0') && (Ch <= '9'))) {
+ return TRUE;
+ } else {
+ return FALSE;
+ }
+}
+
+/**
+ Get ASL NameString size.
+
+ @param[in] Buffer ASL NameString.
+
+ @return ASL NameString size.
+**/
+UINTN
+AmlGetAslNameSegLength (
+ IN UINT8 *Buffer
+ )
+{
+ UINTN Length;
+ UINTN Index;
+
+ if (*Buffer == 0) {
+ return 0;
+ }
+
+ Length = 0;
+ //
+ // 1st
+ //
+ if (AmlIsAslLeadName (*Buffer)) {
+ Length++;
+ Buffer++;
+ }
+
+ if ((*Buffer == 0) || (*Buffer == '.')) {
+ return Length;
+ }
+
+ //
+ // 2, 3, 4 name char
+ //
+ for (Index = 0; Index < 3; Index++) {
+ if (AmlIsAslName (*Buffer)) {
+ Length++;
+ Buffer++;
+ }
+
+ if ((*Buffer == 0) || (*Buffer == '.')) {
+ return Length;
+ }
+ }
+
+ //
+ // Invalid ASL name
+ //
+ return 0;
+}
+
+/**
+ Get ASL NameString size.
+
+ @param[in] Buffer ASL NameString.
+ @param[out] Root On return, points to Root char number.
+ @param[out] Parent On return, points to Parent char number.
+ @param[out] SegCount On return, points to Segment count.
+
+ @return ASL NameString size.
+**/
+UINTN
+AmlGetAslNameStringSize (
+ IN UINT8 *Buffer,
+ OUT UINTN *Root,
+ OUT UINTN *Parent,
+ OUT UINTN *SegCount
+ )
+{
+ UINTN NameLength;
+ UINTN TotalLength;
+
+ *Root = 0;
+ *Parent = 0;
+ *SegCount = 0;
+ TotalLength = 0;
+ NameLength = 0;
+ if (*Buffer == AML_ROOT_CHAR) {
+ *Root = 1;
+ Buffer++;
+ } else if (*Buffer == AML_PARENT_PREFIX_CHAR) {
+ do {
+ Buffer++;
+ (*Parent)++;
+ } while (*Buffer == AML_PARENT_PREFIX_CHAR);
+ }
+
+ //
+ // Now parse name
+ //
+ while (*Buffer != 0) {
+ NameLength = AmlGetAslNameSegLength (Buffer);
+ if ((NameLength == 0) || (NameLength > AML_NAME_SEG_SIZE)) {
+ return 0;
+ }
+
+ (*SegCount)++;
+ Buffer += NameLength;
+ if (*Buffer == 0) {
+ break;
+ }
+
+ Buffer++;
+ }
+
+ //
+ // Check SegCoount
+ //
+ if (*SegCount > 0xFF) {
+ return 0;
+ }
+
+ //
+ // Calculate total length
+ //
+ TotalLength = *Root + *Parent + (*SegCount) * AML_NAME_SEG_SIZE;
+ if (*SegCount > 2) {
+ TotalLength += 2;
+ } else if (*SegCount == 2) {
+ TotalLength += 1;
+ }
+
+ //
+ // Add NULL char
+ //
+ TotalLength++;
+
+ return TotalLength;
+}
+
+/**
+ Copy mem, and cast all the char in dest to be upper case.
+
+ @param[in] DstBuffer Destination buffer.
+ @param[in] SrcBuffer Source buffer.
+ @param[in] Length Buffer length.
+**/
+VOID
+AmlUpperCaseCopyMem (
+ IN UINT8 *DstBuffer,
+ IN UINT8 *SrcBuffer,
+ IN UINTN Length
+ )
+{
+ UINTN Index;
+
+ for (Index = 0; Index < Length; Index++) {
+ if ((SrcBuffer[Index] >= 'a') && (SrcBuffer[Index] <= 'z')) {
+ DstBuffer[Index] = (UINT8)(SrcBuffer[Index] - 'a' + 'A');
+ } else {
+ DstBuffer[Index] = SrcBuffer[Index];
+ }
+ }
+}
+
+/**
+ Return AML name according to ASL name.
+ The caller need free the AmlName returned.
+
+ @param[in] AslPath ASL name.
+
+ @return AmlName
+**/
+UINT8 *
+AmlNameFromAslName (
+ IN UINT8 *AslPath
+ )
+{
+ UINTN Root;
+ UINTN Parent;
+ UINTN SegCount;
+ UINTN TotalLength;
+ UINTN NameLength;
+ UINT8 *Buffer;
+ UINT8 *AmlPath;
+ UINT8 *AmlBuffer;
+
+ TotalLength = AmlGetAslNameStringSize (AslPath, &Root, &Parent, &SegCount);
+ if (TotalLength == 0) {
+ return NULL;
+ }
+
+ AmlPath = AllocatePool (TotalLength);
+ ASSERT (AmlPath != NULL);
+
+ AmlBuffer = AmlPath;
+ Buffer = AslPath;
+
+ //
+ // Handle Root and Parent
+ //
+ if (Root == 1) {
+ *AmlBuffer = AML_ROOT_CHAR;
+ AmlBuffer++;
+ Buffer++;
+ } else if (Parent > 0) {
+ SetMem (AmlBuffer, Parent, AML_PARENT_PREFIX_CHAR);
+ AmlBuffer += Parent;
+ Buffer += Parent;
+ }
+
+ //
+ // Handle SegCount
+ //
+ if (SegCount > 2) {
+ *AmlBuffer = AML_MULTI_NAME_PREFIX;
+ AmlBuffer++;
+ *AmlBuffer = (UINT8)SegCount;
+ AmlBuffer++;
+ } else if (SegCount == 2) {
+ *AmlBuffer = AML_DUAL_NAME_PREFIX;
+ AmlBuffer++;
+ }
+
+ //
+ // Now to name
+ //
+ while (*Buffer != 0) {
+ NameLength = AmlGetAslNameSegLength (Buffer);
+ ASSERT ((NameLength != 0) && (NameLength <= AML_NAME_SEG_SIZE));
+ AmlUpperCaseCopyMem (AmlBuffer, Buffer, NameLength);
+ SetMem (AmlBuffer + NameLength, AML_NAME_SEG_SIZE - NameLength, AML_NAME_CHAR__);
+ Buffer += NameLength;
+ AmlBuffer += AML_NAME_SEG_SIZE;
+ if (*Buffer == 0) {
+ break;
+ }
+
+ Buffer++;
+ }
+
+ //
+ // Add NULL
+ //
+ AmlPath[TotalLength - 1] = 0;
+
+ return AmlPath;
+}
+
+/**
+ Print AML NameSeg.
+
+ @param[in] Buffer AML NameSeg.
+**/
+VOID
+AmlPrintNameSeg (
+ IN UINT8 *Buffer
+ )
+{
+ DEBUG ((DEBUG_ERROR, "%c", Buffer[0]));
+ if ((Buffer[1] == '_') && (Buffer[2] == '_') && (Buffer[3] == '_')) {
+ return;
+ }
+
+ DEBUG ((DEBUG_ERROR, "%c", Buffer[1]));
+ if ((Buffer[2] == '_') && (Buffer[3] == '_')) {
+ return;
+ }
+
+ DEBUG ((DEBUG_ERROR, "%c", Buffer[2]));
+ if (Buffer[3] == '_') {
+ return;
+ }
+
+ DEBUG ((DEBUG_ERROR, "%c", Buffer[3]));
+ return;
+}
+
+/**
+ Print AML NameString.
+
+ @param[in] Buffer AML NameString.
+**/
+VOID
+AmlPrintNameString (
+ IN UINT8 *Buffer
+ )
+{
+ UINT8 SegCount;
+ UINT8 Index;
+
+ if (*Buffer == AML_ROOT_CHAR) {
+ //
+ // RootChar
+ //
+ Buffer++;
+ DEBUG ((DEBUG_ERROR, "\\"));
+ } else if (*Buffer == AML_PARENT_PREFIX_CHAR) {
+ //
+ // ParentPrefixChar
+ //
+ do {
+ Buffer++;
+ DEBUG ((DEBUG_ERROR, "^"));
+ } while (*Buffer == AML_PARENT_PREFIX_CHAR);
+ }
+
+ if (*Buffer == AML_DUAL_NAME_PREFIX) {
+ //
+ // DualName
+ //
+ Buffer++;
+ SegCount = 2;
+ } else if (*Buffer == AML_MULTI_NAME_PREFIX) {
+ //
+ // MultiName
+ //
+ Buffer++;
+ SegCount = *Buffer;
+ Buffer++;
+ } else if (*Buffer == 0) {
+ //
+ // NULL Name
+ //
+ return;
+ } else {
+ //
+ // NameSeg
+ //
+ SegCount = 1;
+ }
+
+ AmlPrintNameSeg (Buffer);
+ Buffer += AML_NAME_SEG_SIZE;
+ for (Index = 0; Index < SegCount - 1; Index++) {
+ DEBUG ((DEBUG_ERROR, "."));
+ AmlPrintNameSeg (Buffer);
+ Buffer += AML_NAME_SEG_SIZE;
+ }
+
+ return;
+}