From 3dc8585e0a9fd4b2cb383f3ceb4961c7a88a8e71 Mon Sep 17 00:00:00 2001 From: jyao1 Date: Tue, 18 May 2010 02:26:49 +0000 Subject: [PATCH] MdeModulePkg: Add ACPI SDT support. Introduce PcdInstallAcpiSdtProtocol, default FALSE. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10501 6f19259b-4bc3-4df7-8a09-765794883524 --- MdeModulePkg/MdeModulePkg.dec | 3 + MdeModulePkg/MdeModulePkg.dsc | 1 + .../Universal/Acpi/AcpiTableDxe/AcpiSdt.c | 1112 +++++++++++++++++ .../Universal/Acpi/AcpiTableDxe/AcpiSdt.h | 740 +++++++++++ .../Universal/Acpi/AcpiTableDxe/AcpiTable.c | 27 +- .../Universal/Acpi/AcpiTableDxe/AcpiTable.h | 81 +- .../Acpi/AcpiTableDxe/AcpiTableDxe.inf | 12 + .../Acpi/AcpiTableDxe/AcpiTableProtocol.c | 18 + .../Universal/Acpi/AcpiTableDxe/Aml.c | 302 +++++ .../Universal/Acpi/AcpiTableDxe/AmlChild.c | 278 +++++ .../Acpi/AcpiTableDxe/AmlNamespace.c | 612 +++++++++ .../Universal/Acpi/AcpiTableDxe/AmlOption.c | 452 +++++++ .../Universal/Acpi/AcpiTableDxe/AmlString.c | 549 ++++++++ 13 files changed, 4177 insertions(+), 10 deletions(-) create mode 100644 MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c create mode 100644 MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.h create mode 100644 MdeModulePkg/Universal/Acpi/AcpiTableDxe/Aml.c create mode 100644 MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlChild.c create mode 100644 MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlNamespace.c create mode 100644 MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlOption.c create mode 100644 MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlString.c diff --git a/MdeModulePkg/MdeModulePkg.dec b/MdeModulePkg/MdeModulePkg.dec index b692c6a63c..9d0262e20c 100644 --- a/MdeModulePkg/MdeModulePkg.dec +++ b/MdeModulePkg/MdeModulePkg.dec @@ -275,6 +275,9 @@ ## This PCD specifies whether Peiphase StatusCode is replayed in DxePhase. gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeReplayIn|FALSE|BOOLEAN|0x0001002d + ## This PCD specified whether ACPI SDT protocol is installed. + gEfiMdeModulePkgTokenSpaceGuid.PcdInstallAcpiSdtProtocol|FALSE|BOOLEAN|0x0001004d + [PcdsFeatureFlag.IA32, PcdsFeatureFlag.X64] ## # This feature flag specifies whether DxeIpl switches to long mode to enter DXE phase. diff --git a/MdeModulePkg/MdeModulePkg.dsc b/MdeModulePkg/MdeModulePkg.dsc index ce2cd40223..6aba072de3 100644 --- a/MdeModulePkg/MdeModulePkg.dsc +++ b/MdeModulePkg/MdeModulePkg.dsc @@ -153,6 +153,7 @@ gEfiMdeModulePkgTokenSpaceGuid.PcdUnicodeCollation2Support|TRUE gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE gEfiMdeModulePkgTokenSpaceGuid.PcdConOutUgaSupport|TRUE + gEfiMdeModulePkgTokenSpaceGuid.PcdInstallAcpiSdtProtocol|TRUE [PcdsFeatureFlag.IA32] gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode|TRUE diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c new file mode 100644 index 0000000000..5aad7cca81 --- /dev/null +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c @@ -0,0 +1,1112 @@ +/** @file + ACPI Sdt Protocol Driver + + Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +// +// Includes +// +#include "AcpiTable.h" + +GLOBAL_REMOVE_IF_UNREFERENCED +EFI_ACPI_SDT_PROTOCOL mAcpiSdtProtocolTemplate = { + EFI_ACPI_TABLE_VERSION_NONE | EFI_ACPI_TABLE_VERSION_1_0B | EFI_ACPI_TABLE_VERSION_2_0 | EFI_ACPI_TABLE_VERSION_3_0 | EFI_ACPI_TABLE_VERSION_4_0, + 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->PageAddress <= (UINTN)Buffer) && + ((UINTN)CurrentTableList->PageAddress + EFI_PAGES_TO_SIZE(CurrentTableList->NumberOfPages) > (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 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. + + @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. + + @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; + UINTN TableIndex; + LIST_ENTRY *CurrentLink; + LIST_ENTRY *StartLink; + EFI_ACPI_TABLE_LIST *CurrentTable; + + ASSERT (Table != NULL); + ASSERT (Version != NULL); + ASSERT (TableKey != NULL); + + // + // Get the instance of the ACPI Table + // + AcpiTableInstance = SdtGetAcpiTableInstance (); + + // + // 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; +} + +/** + 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; + + // + // 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; + + 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; + + 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 ((EFI_D_ERROR, "AcpiSdt: FindPath - ")); + AmlPrintNameString (AmlPath); + DEBUG ((EFI_D_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; +} + +/** + ExitPmAuth Protocol notification event handler. + + @param[in] Event Event whose notification function is being invoked. + @param[in] Context Pointer to the notification function's context. +**/ +VOID +EFIAPI +ExitPmAuthNotification ( + IN EFI_EVENT Event, + IN VOID *Context + ) +{ + EFI_STATUS Status; + VOID *DxeSmmReadyToLock; + + // + // Add more check to locate protocol after got event, because + // the library will signal this event immediately once it is register + // just in case it is already installed. + // + Status = gBS->LocateProtocol ( + &gEfiDxeSmmReadyToLockProtocolGuid, + NULL, + &DxeSmmReadyToLock + ); + if (EFI_ERROR (Status)) { + return ; + } + + // + // Uninstall ACPI SDT protocol, so that we can make sure no one update ACPI table from API level. + // + Status = gBS->UninstallProtocolInterface ( + mHandle, + &gEfiAcpiSdtProtocolGuid, + &mPrivateData->AcpiSdtProtocol + ); + ASSERT_EFI_ERROR (Status); + + // + // Close event, so it will not be invoked again. + // + gBS->CloseEvent (Event); + + return ; +} + +/** + This function initializes AcpiSdt protocol in ACPI table instance. + + @param[in] AcpiTableInstance Instance to construct +**/ +VOID +SdtAcpiTableAcpiSdtConstructor ( + IN EFI_ACPI_TABLE_INSTANCE *AcpiTableInstance + ) +{ + VOID *Registration; + + InitializeListHead (&AcpiTableInstance->NotifyList); + CopyMem (&AcpiTableInstance->AcpiSdtProtocol, &mAcpiSdtProtocolTemplate, sizeof(mAcpiSdtProtocolTemplate)); + + // + // Register event for ExitPmAuth, so that we can uninstall ACPI SDT protocol after ExitPmAuth. + // + EfiCreateProtocolNotifyEvent ( + &gEfiDxeSmmReadyToLockProtocolGuid, + TPL_CALLBACK, + ExitPmAuthNotification, + NULL, + &Registration + ); + + return ; +} diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.h b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.h new file mode 100644 index 0000000000..56187ae54c --- /dev/null +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.h @@ -0,0 +1,740 @@ +/** @file + ACPI Sdt Protocol Driver + + Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#ifndef _ACPI_SDT_H_ +#define _ACPI_SDT_H_ + +// +// ACPI AML definition +// + +// +// Primary OpCode +// +#define AML_ZERO_OP 0x00 +#define AML_ONE_OP 0x01 +#define AML_ALIAS_OP 0x06 +#define AML_NAME_OP 0x08 +#define AML_BYTE_PREFIX 0x0a +#define AML_WORD_PREFIX 0x0b +#define AML_DWORD_PREFIX 0x0c +#define AML_STRING_PREFIX 0x0d +#define AML_QWORD_PREFIX 0x0e +#define AML_SCOPE_OP 0x10 +#define AML_BUFFER_OP 0x11 +#define AML_PACKAGE_OP 0x12 +#define AML_VAR_PACKAGE_OP 0x13 +#define AML_METHOD_OP 0x14 +#define AML_DUAL_NAME_PREFIX 0x2e +#define AML_MULTI_NAME_PREFIX 0x2f +#define AML_NAME_CHAR_A 0x41 +#define AML_NAME_CHAR_B 0x42 +#define AML_NAME_CHAR_C 0x43 +#define AML_NAME_CHAR_D 0x44 +#define AML_NAME_CHAR_E 0x45 +#define AML_NAME_CHAR_F 0x46 +#define AML_NAME_CHAR_G 0x47 +#define AML_NAME_CHAR_H 0x48 +#define AML_NAME_CHAR_I 0x49 +#define AML_NAME_CHAR_J 0x4a +#define AML_NAME_CHAR_K 0x4b +#define AML_NAME_CHAR_L 0x4c +#define AML_NAME_CHAR_M 0x4d +#define AML_NAME_CHAR_N 0x4e +#define AML_NAME_CHAR_O 0x4f +#define AML_NAME_CHAR_P 0x50 +#define AML_NAME_CHAR_Q 0x51 +#define AML_NAME_CHAR_R 0x52 +#define AML_NAME_CHAR_S 0x53 +#define AML_NAME_CHAR_T 0x54 +#define AML_NAME_CHAR_U 0x55 +#define AML_NAME_CHAR_V 0x56 +#define AML_NAME_CHAR_W 0x57 +#define AML_NAME_CHAR_X 0x58 +#define AML_NAME_CHAR_Y 0x59 +#define AML_NAME_CHAR_Z 0x5a +#define AML_ROOT_CHAR 0x5c +#define AML_PARENT_PREFIX_CHAR 0x5e +#define AML_NAME_CHAR__ 0x5f +#define AML_LOCAL0 0x60 +#define AML_LOCAL1 0x61 +#define AML_LOCAL2 0x62 +#define AML_LOCAL3 0x63 +#define AML_LOCAL4 0x64 +#define AML_LOCAL5 0x65 +#define AML_LOCAL6 0x66 +#define AML_LOCAL7 0x67 +#define AML_ARG0 0x68 +#define AML_ARG1 0x69 +#define AML_ARG2 0x6a +#define AML_ARG3 0x6b +#define AML_ARG4 0x6c +#define AML_ARG5 0x6d +#define AML_ARG6 0x6e +#define AML_STORE_OP 0x70 +#define AML_REF_OF_OP 0x71 +#define AML_ADD_OP 0x72 +#define AML_CONCAT_OP 0x73 +#define AML_SUBTRACT_OP 0x74 +#define AML_INCREMENT_OP 0x75 +#define AML_DECREMENT_OP 0x76 +#define AML_MULTIPLY_OP 0x77 +#define AML_DIVIDE_OP 0x78 +#define AML_SHIFT_LEFT_OP 0x79 +#define AML_SHIFT_RIGHT_OP 0x7a +#define AML_AND_OP 0x7b +#define AML_NAND_OP 0x7c +#define AML_OR_OP 0x7d +#define AML_NOR_OP 0x7e +#define AML_XOR_OP 0x7f +#define AML_NOT_OP 0x80 +#define AML_FIND_SET_LEFT_BIT_OP 0x81 +#define AML_FIND_SET_RIGHT_BIT_OP 0x82 +#define AML_DEREF_OF_OP 0x83 +#define AML_CONCAT_RES_OP 0x84 +#define AML_MOD_OP 0x85 +#define AML_NOTIFY_OP 0x86 +#define AML_SIZE_OF_OP 0x87 +#define AML_INDEX_OP 0x88 +#define AML_MATCH_OP 0x89 +#define AML_CREATE_DWORD_FIELD_OP 0x8a +#define AML_CREATE_WORD_FIELD_OP 0x8b +#define AML_CREATE_BYTE_FIELD_OP 0x8c +#define AML_CREATE_BIT_FIELD_OP 0x8d +#define AML_OBJECT_TYPE_OP 0x8e +#define AML_CREATE_QWORD_FIELD_OP 0x8f +#define AML_LAND_OP 0x90 +#define AML_LOR_OP 0x91 +#define AML_LNOT_OP 0x92 +#define AML_LEQUAL_OP 0x93 +#define AML_LGREATER_OP 0x94 +#define AML_LLESS_OP 0x95 +#define AML_TO_BUFFER_OP 0x96 +#define AML_TO_DEC_STRING_OP 0x97 +#define AML_TO_HEX_STRING_OP 0x98 +#define AML_TO_INTEGER_OP 0x99 +#define AML_TO_STRING_OP 0x9c +#define AML_COPY_OBJECT_OP 0x9d +#define AML_MID_OP 0x9e +#define AML_CONTINUE_OP 0x9f +#define AML_IF_OP 0xa0 +#define AML_ELSE_OP 0xa1 +#define AML_WHILE_OP 0xa2 +#define AML_NOOP_OP 0xa3 +#define AML_RETURN_OP 0xa4 +#define AML_BREAK_OP 0xa5 +#define AML_BREAK_POINT_OP 0xcc +#define AML_ONES_OP 0xff + +// +// Extended OpCode +// +#define AML_EXT_OP 0x5b + +#define AML_EXT_MUTEX_OP 0x01 +#define AML_EXT_EVENT_OP 0x02 +#define AML_EXT_COND_REF_OF_OP 0x12 +#define AML_EXT_CREATE_FIELD_OP 0x13 +#define AML_EXT_LOAD_TABLE_OP 0x1f +#define AML_EXT_LOAD_OP 0x20 +#define AML_EXT_STALL_OP 0x21 +#define AML_EXT_SLEEP_OP 0x22 +#define AML_EXT_ACQUIRE_OP 0x23 +#define AML_EXT_SIGNAL_OP 0x24 +#define AML_EXT_WAIT_OP 0x25 +#define AML_EXT_RESET_OP 0x26 +#define AML_EXT_RELEASE_OP 0x27 +#define AML_EXT_FROM_BCD_OP 0x28 +#define AML_EXT_TO_BCD_OP 0x29 +#define AML_EXT_UNLOAD_OP 0x2a +#define AML_EXT_REVISION_OP 0x30 +#define AML_EXT_DEBUG_OP 0x31 +#define AML_EXT_FATAL_OP 0x32 +#define AML_EXT_TIMER_OP 0x33 +#define AML_EXT_REGION_OP 0x80 +#define AML_EXT_FIELD_OP 0x81 +#define AML_EXT_DEVICE_OP 0x82 +#define AML_EXT_PROCESSOR_OP 0x83 +#define AML_EXT_POWER_RES_OP 0x84 +#define AML_EXT_THERMAL_ZONE_OP 0x85 +#define AML_EXT_INDEX_FIELD_OP 0x86 +#define AML_EXT_BANK_FIELD_OP 0x87 +#define AML_EXT_DATA_REGION_OP 0x88 + +// +// 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. +// +#define AML_NAME_SEG_SIZE 4 + +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. + + @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. + + @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 42abacb836..696974e325 100644 --- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.c +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.c @@ -1,7 +1,7 @@ /** @file ACPI Table Protocol Driver - Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -21,6 +21,7 @@ // Handle to install ACPI Table Protocol // EFI_HANDLE mHandle = NULL; +GLOBAL_REMOVE_IF_UNREFERENCED EFI_ACPI_TABLE_INSTANCE *mPrivateData; /** Entry point of the ACPI table driver. @@ -64,12 +65,24 @@ InitializeAcpiTableDxe ( // // Install ACPI Table protocol // - Status = gBS->InstallMultipleProtocolInterfaces ( - &mHandle, - &gEfiAcpiTableProtocolGuid, - &PrivateData->AcpiTableProtocol, - NULL - ); + 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 cb5119e4f5..d9e6428cba 100644 --- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.h +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.h @@ -1,7 +1,7 @@ /** @file ACPI Table Protocol Driver - Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.
+ Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -20,6 +20,8 @@ #include #include +#include +#include #include #include @@ -35,6 +37,8 @@ // #include +#include "AcpiSdt.h" + // // From Protocol/AcpiSupport.h // @@ -93,7 +97,7 @@ typedef struct { } EFI_ACPI_TABLE_LIST; // -// Containment record for linked 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) @@ -135,13 +139,15 @@ typedef struct { 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; + LIST_ENTRY TableList; UINTN NumberOfTableEntries1; // Number of ACPI 1.0 tables UINTN NumberOfTableEntries3; // Number of ACPI 3.0 tables UINTN CurrentHandle; BOOLEAN TablesInstalled1; // ACPI 1.0 tables published BOOLEAN TablesInstalled3; // ACPI 3.0 tables published EFI_ACPI_TABLE_PROTOCOL AcpiTableProtocol; + EFI_ACPI_SDT_PROTOCOL AcpiSdtProtocol; + LIST_ENTRY NotifyList; } EFI_ACPI_TABLE_INSTANCE; // @@ -194,4 +200,73 @@ InitializeAcpiTableDxe ( 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 + ); + +// +// 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 ffc6c6ee10..122a1ff76e 100644 --- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf @@ -31,6 +31,13 @@ AcpiTableProtocol.c AcpiTable.h AcpiTable.c + AcpiSdt.h + AcpiSdt.c + Aml.c + AmlString.c + AmlOption.c + AmlChild.c + AmlNamespace.c [Packages] MdePkg/MdePkg.dec @@ -50,8 +57,13 @@ gEfiAcpi10TableGuid # ALWAYS_CONSUMED gEfiAcpiTableGuid +[FeaturePcd] + gEfiMdeModulePkgTokenSpaceGuid.PcdInstallAcpiSdtProtocol + [Protocols] gEfiAcpiTableProtocolGuid # PROTOCOL ALWAYS_PRODUCED + gEfiAcpiSdtProtocolGuid # PROTOCOL ALWAYS_PRODUCED + gEfiDxeSmmReadyToLockProtocolGuid # PROTOCOL ALWAYS_CONSUMED [Depex] TRUE diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c index 23117b1ded..c551d0bd5d 100644 --- a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c @@ -357,6 +357,19 @@ InstallAcpiTable ( } FreePool (AcpiTableBufferConst); + // + // Add a new table successfully, notify registed callback + // + if (FeaturePcdGet (PcdInstallAcpiSdtProtocol)) { + if (!EFI_ERROR (Status)) { + SdtNotifyAcpiList ( + AcpiTableInstance, + EFI_ACPI_TABLE_VERSION_1_0B | EFI_ACPI_TABLE_VERSION_2_0 | EFI_ACPI_TABLE_VERSION_3_0, + *TableKey + ); + } + } + return Status; } @@ -1707,6 +1720,11 @@ AcpiTableAcpiTableConstructor ( AcpiTableInstance->AcpiTableProtocol.InstallAcpiTable = InstallAcpiTable; AcpiTableInstance->AcpiTableProtocol.UninstallAcpiTable = UninstallAcpiTable; + + if (FeaturePcdGet (PcdInstallAcpiSdtProtocol)) { + SdtAcpiTableAcpiSdtConstructor (AcpiTableInstance); + } + // // Create RSDP, RSDT, XSDT structures // Allocate all buffers diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/Aml.c b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/Aml.c new file mode 100644 index 0000000000..bff81a803a --- /dev/null +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/Aml.c @@ -0,0 +1,302 @@ +/** @file + ACPI Sdt Protocol Driver + + Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#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; + + // + // + // + // + // + // 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 |= (*(Buffer + 2)) << 8; + RealLength = (RealLength << 4) | (LeadByte & 0xF); + break; + case 3: + RealLength = *(Buffer + 1); + RealLength |= (*(Buffer + 2)) << 8; + RealLength |= (*(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 new file mode 100644 index 0000000000..d663feaecb --- /dev/null +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlChild.c @@ -0,0 +1,278 @@ +/** @file + ACPI Sdt Protocol Driver + + Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#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; + + 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 new file mode 100644 index 0000000000..b62256e388 --- /dev/null +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlNamespace.c @@ -0,0 +1,612 @@ +/** @file + ACPI Sdt Protocol Driver + + Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#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 ((EFI_D_ERROR, "AML: Override Happen - %a!\n", NameString)); + DEBUG ((EFI_D_ERROR, "AML: Existing Node - %x\n", AmlNodeList->Buffer)); + DEBUG ((EFI_D_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; + + 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 ((EFI_D_ERROR, "\\")); + } else { + for (Index = 0; Index < Level; Index++) { + DEBUG ((EFI_D_ERROR, " ")); + } + AmlPrintNameSeg (AmlParentNodeList->Name); + } + DEBUG ((EFI_D_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 ((EFI_D_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 ((EFI_D_ERROR, "AcpiSdt: Search from: \\")); + AmlPrintNameSeg (CurrentAmlNodeList->Name); + DEBUG ((EFI_D_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 new file mode 100644 index 0000000000..93bbe480e8 --- /dev/null +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlOption.c @@ -0,0 +1,452 @@ +/** @file + ACPI Sdt Protocol Driver + + Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#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, accroding 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 new file mode 100644 index 0000000000..fe2c7613e5 --- /dev/null +++ b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlString.c @@ -0,0 +1,549 @@ +/** @file + ACPI Sdt Protocol Driver + + Copyright (c) 2010, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +**/ + +#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; + UINT8 *Name; + + Name = Buffer; + 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 ((EFI_D_ERROR, "%c", Buffer[0])); + if ((Buffer[1] == '_') && (Buffer[2] == '_') && (Buffer[3] == '_')) { + return ; + } + DEBUG ((EFI_D_ERROR, "%c", Buffer[1])); + if ((Buffer[2] == '_') && (Buffer[3] == '_')) { + return ; + } + DEBUG ((EFI_D_ERROR, "%c", Buffer[2])); + if (Buffer[3] == '_') { + return ; + } + DEBUG ((EFI_D_ERROR, "%c", Buffer[3])); + return ; +} + +/** + Print AML NameString. + + @param[in] Buffer AML NameString. +**/ +VOID +AmlPrintNameString ( + IN UINT8 *Buffer + ) +{ + UINT8 SegCount; + UINT8 Index; + UINT8 *Name; + + Name = Buffer; + if (*Buffer == AML_ROOT_CHAR) { + // + // RootChar + // + Buffer ++; + DEBUG ((EFI_D_ERROR, "\\")); + } else if (*Buffer == AML_PARENT_PREFIX_CHAR) { + // + // ParentPrefixChar + // + do { + Buffer ++; + DEBUG ((EFI_D_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 ((EFI_D_ERROR, ".")); + AmlPrintNameSeg (Buffer); + Buffer += AML_NAME_SEG_SIZE; + } + + return ; +} -- 2.39.2