]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdeModulePkg:
authorjyao1 <jyao1@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 18 May 2010 02:26:49 +0000 (02:26 +0000)
committerjyao1 <jyao1@6f19259b-4bc3-4df7-8a09-765794883524>
Tue, 18 May 2010 02:26:49 +0000 (02:26 +0000)
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

13 files changed:
MdeModulePkg/MdeModulePkg.dec
MdeModulePkg/MdeModulePkg.dsc
MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c [new file with mode: 0644]
MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.h [new file with mode: 0644]
MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.c
MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTable.h
MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableDxe.inf
MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiTableProtocol.c
MdeModulePkg/Universal/Acpi/AcpiTableDxe/Aml.c [new file with mode: 0644]
MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlChild.c [new file with mode: 0644]
MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlNamespace.c [new file with mode: 0644]
MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlOption.c [new file with mode: 0644]
MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlString.c [new file with mode: 0644]

index b692c6a63c36e23a94d3b76429b9373d96807cb4..9d0262e20cbc23b00370a6bea96af5b2b483e816 100644 (file)
   ## This PCD specifies whether Peiphase StatusCode is replayed in DxePhase.\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdStatusCodeReplayIn|FALSE|BOOLEAN|0x0001002d\r
 \r
+  ## This PCD specified whether ACPI SDT protocol is installed.\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdInstallAcpiSdtProtocol|FALSE|BOOLEAN|0x0001004d\r
+\r
 [PcdsFeatureFlag.IA32, PcdsFeatureFlag.X64]\r
   ##\r
   # This feature flag specifies whether DxeIpl switches to long mode to enter DXE phase.\r
index ce2cd40223714820119c3c6e818772a06ca0cda6..6aba072de343a786129e7c991c77298a18e920b3 100644 (file)
   gEfiMdeModulePkgTokenSpaceGuid.PcdUnicodeCollation2Support|TRUE\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdConOutGopSupport|TRUE\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdConOutUgaSupport|TRUE\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdInstallAcpiSdtProtocol|TRUE\r
 \r
 [PcdsFeatureFlag.IA32]\r
   gEfiMdeModulePkgTokenSpaceGuid.PcdDxeIplSwitchToLongMode|TRUE\r
diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.c
new file mode 100644 (file)
index 0000000..5aad7cc
--- /dev/null
@@ -0,0 +1,1112 @@
+/** @file\r
+  ACPI Sdt Protocol Driver\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved. <BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+//\r
+// Includes\r
+//\r
+#include "AcpiTable.h"\r
+\r
+GLOBAL_REMOVE_IF_UNREFERENCED\r
+EFI_ACPI_SDT_PROTOCOL  mAcpiSdtProtocolTemplate = {\r
+  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,\r
+  GetAcpiTable2,\r
+  RegisterNotify,\r
+  Open,\r
+  OpenSdt,\r
+  Close,\r
+  GetChild,\r
+  GetOption,\r
+  SetOption,\r
+  FindPath\r
+};\r
+\r
+/**\r
+  This function returns ACPI Table instance.\r
+\r
+  @return AcpiTableInstance\r
+**/\r
+EFI_ACPI_TABLE_INSTANCE *\r
+SdtGetAcpiTableInstance (\r
+  VOID\r
+  )\r
+{\r
+  return mPrivateData;\r
+}\r
+\r
+/**\r
+  This function finds the table specified by the buffer.\r
+\r
+  @param[in]  Buffer      Table buffer to find.\r
+\r
+  @return ACPI table list.\r
+**/\r
+EFI_ACPI_TABLE_LIST *\r
+FindTableByBuffer (\r
+  IN VOID  *Buffer\r
+  )\r
+{\r
+  EFI_ACPI_TABLE_INSTANCE   *AcpiTableInstance;\r
+  LIST_ENTRY                *CurrentLink;\r
+  EFI_ACPI_TABLE_LIST       *CurrentTableList;\r
+  LIST_ENTRY                *StartLink;\r
+\r
+  //\r
+  // Get the instance of the ACPI Table\r
+  //\r
+  AcpiTableInstance = SdtGetAcpiTableInstance ();\r
+\r
+  //\r
+  // Find the notify\r
+  //\r
+  StartLink   = &AcpiTableInstance->TableList;\r
+  CurrentLink = StartLink->ForwardLink;\r
+\r
+  while (CurrentLink != StartLink) {\r
+    CurrentTableList = EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink);\r
+    if (((UINTN)CurrentTableList->PageAddress <= (UINTN)Buffer) &&\r
+        ((UINTN)CurrentTableList->PageAddress + EFI_PAGES_TO_SIZE(CurrentTableList->NumberOfPages) > (UINTN)Buffer)) {\r
+      //\r
+      // Good! Found Table.\r
+      //\r
+      return CurrentTableList;\r
+    }\r
+\r
+    CurrentLink = CurrentLink->ForwardLink;\r
+  }\r
+\r
+  return NULL;\r
+}\r
+\r
+/**\r
+  This function updates AML table checksum.\r
+  It will search the ACPI table installed by ACPI_TABLE protocol.\r
+\r
+  @param[in]  Buffer        A piece of AML code buffer pointer.\r
+\r
+  @retval EFI_SUCCESS       The table holds the AML buffer is found, and checksum is updated.\r
+  @retval EFI_NOT_FOUND     The table holds the AML buffer is not found.\r
+**/\r
+EFI_STATUS\r
+SdtUpdateAmlChecksum (\r
+  IN VOID  *Buffer\r
+  )\r
+{\r
+  EFI_ACPI_TABLE_LIST       *CurrentTableList;\r
+\r
+  CurrentTableList = FindTableByBuffer (Buffer);\r
+  if (CurrentTableList == NULL) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  AcpiPlatformChecksum (\r
+    (VOID *)CurrentTableList->Table,\r
+    CurrentTableList->Table->Length,\r
+    OFFSET_OF (EFI_ACPI_DESCRIPTION_HEADER, Checksum)\r
+    );\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  This function finds MAX AML buffer size.\r
+  It will search the ACPI table installed by ACPI_TABLE protocol.\r
+\r
+  @param[in]  Buffer        A piece of AML code buffer pointer.\r
+  @param[out] MaxSize       On return it holds the MAX size of buffer.\r
+\r
+  @retval EFI_SUCCESS       The table holds the AML buffer is found, and MAX size if returned.\r
+  @retval EFI_NOT_FOUND     The table holds the AML buffer is not found.\r
+**/\r
+EFI_STATUS\r
+SdtGetMaxAmlBufferSize (\r
+  IN  VOID  *Buffer,\r
+  OUT UINTN *MaxSize\r
+  )\r
+{\r
+  EFI_ACPI_TABLE_LIST       *CurrentTableList;\r
+\r
+  CurrentTableList = FindTableByBuffer (Buffer);\r
+  if (CurrentTableList == NULL) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  *MaxSize = (UINTN)CurrentTableList->Table + CurrentTableList->Table->Length - (UINTN)Buffer;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  This function invokes ACPI notification.\r
+\r
+  @param[in]  AcpiTableInstance          Instance to AcpiTable\r
+  @param[in]  Version                    Version(s) to set.\r
+  @param[in]  Handle                     Handle of the table.\r
+**/\r
+VOID\r
+SdtNotifyAcpiList (\r
+  IN EFI_ACPI_TABLE_INSTANCE   *AcpiTableInstance,\r
+  IN EFI_ACPI_TABLE_VERSION    Version,\r
+  IN UINTN                     Handle\r
+  )\r
+{\r
+  EFI_ACPI_NOTIFY_LIST      *CurrentNotifyList;\r
+  LIST_ENTRY                *CurrentLink;\r
+  LIST_ENTRY                *StartLink;\r
+  EFI_ACPI_TABLE_LIST       *Table;\r
+  EFI_STATUS                Status;\r
+\r
+  //\r
+  // We should not use Table buffer, because it is user input buffer.\r
+  //\r
+  Status = FindTableByHandle (\r
+             Handle,\r
+             &AcpiTableInstance->TableList,\r
+             &Table\r
+             );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Find the notify\r
+  //\r
+  StartLink   = &AcpiTableInstance->NotifyList;\r
+  CurrentLink = StartLink->ForwardLink;\r
+\r
+  while (CurrentLink != StartLink) {\r
+    CurrentNotifyList = EFI_ACPI_NOTIFY_LIST_FROM_LINK (CurrentLink);\r
+\r
+    //\r
+    // Inovke notification\r
+    //\r
+    CurrentNotifyList->Notification ((EFI_ACPI_SDT_HEADER *)Table->Table, Version, Handle);\r
+\r
+    CurrentLink = CurrentLink->ForwardLink;\r
+  }\r
+\r
+  return ;\r
+}\r
+\r
+/**\r
+  Returns a requested ACPI table.\r
+  \r
+  The GetAcpiTable() function returns a pointer to a buffer containing the ACPI table associated\r
+  with the Index that was input. The following structures are not considered elements in the list of\r
+  ACPI tables:\r
+  - Root System Description Pointer (RSD_PTR)\r
+  - Root System Description Table (RSDT)\r
+  - Extended System Description Table (XSDT)\r
+  Version is updated with a bit map containing all the versions of ACPI of which the table is a\r
+  member.\r
+  \r
+  @param[in]    Index       The zero-based index of the table to retrieve.\r
+  @param[out]   Table       Pointer for returning the table buffer.\r
+  @param[out]   Version     On return, updated with the ACPI versions to which this table belongs. Type\r
+                            EFI_ACPI_TABLE_VERSION is defined in "Related Definitions" in the\r
+                            EFI_ACPI_SDT_PROTOCOL.    \r
+  @param[out]   TableKey    On return, points to the table key for the specified ACPI system definition table. This\r
+                            is identical to the table key used in the EFI_ACPI_TABLE_PROTOCOL.  \r
+                            \r
+  @retval EFI_SUCCESS       The function completed successfully.\r
+  @retval EFI_NOT_FOUND     The requested index is too large and a table was not found.                                  \r
+**/  \r
+EFI_STATUS\r
+EFIAPI\r
+GetAcpiTable2 (\r
+  IN  UINTN                               Index,\r
+  OUT EFI_ACPI_SDT_HEADER                 **Table,\r
+  OUT EFI_ACPI_TABLE_VERSION              *Version,\r
+  OUT UINTN                               *TableKey\r
+  )\r
+{\r
+  EFI_ACPI_TABLE_INSTANCE   *AcpiTableInstance;\r
+  UINTN                     TableIndex;\r
+  LIST_ENTRY                *CurrentLink;\r
+  LIST_ENTRY                *StartLink;\r
+  EFI_ACPI_TABLE_LIST       *CurrentTable;\r
+\r
+  ASSERT (Table != NULL);\r
+  ASSERT (Version != NULL);\r
+  ASSERT (TableKey != NULL);\r
+\r
+  //\r
+  // Get the instance of the ACPI Table\r
+  //\r
+  AcpiTableInstance = SdtGetAcpiTableInstance ();\r
+\r
+  //\r
+  // Find the table\r
+  //\r
+  StartLink   = &AcpiTableInstance->TableList;\r
+  CurrentLink = StartLink->ForwardLink;\r
+  TableIndex = 0;\r
+\r
+  while (CurrentLink != StartLink) {\r
+    if (TableIndex == Index) {\r
+      break;\r
+    }\r
+    //\r
+    // Next one\r
+    //\r
+    CurrentLink = CurrentLink->ForwardLink;\r
+    TableIndex ++;\r
+  }\r
+\r
+  if ((TableIndex != Index) || (CurrentLink == StartLink)) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  //\r
+  // Get handle and version\r
+  //\r
+  CurrentTable  = EFI_ACPI_TABLE_LIST_FROM_LINK (CurrentLink);\r
+  *TableKey     = CurrentTable->Handle;\r
+  *Version      = CurrentTable->Version;\r
+  *Table        = (EFI_ACPI_SDT_HEADER *)CurrentTable->Table;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Register a callback when an ACPI table is installed.\r
+  \r
+  This function registers a function which will be called whenever a new ACPI table is installed.\r
+  \r
+  @param[in]  Notification               Points to the callback function to be registered\r
+**/\r
+VOID\r
+SdtRegisterNotify (\r
+  IN EFI_ACPI_NOTIFICATION_FN   Notification\r
+  )\r
+{\r
+  EFI_ACPI_TABLE_INSTANCE   *AcpiTableInstance;\r
+  EFI_ACPI_NOTIFY_LIST      *CurrentNotifyList;\r
+\r
+  //\r
+  // Get the instance of the ACPI Table\r
+  //\r
+  AcpiTableInstance = SdtGetAcpiTableInstance ();\r
+\r
+  //\r
+  // Create a new list entry\r
+  //\r
+  CurrentNotifyList = AllocatePool (sizeof (EFI_ACPI_NOTIFY_LIST));\r
+  ASSERT (CurrentNotifyList != NULL);\r
+\r
+  //\r
+  // Initialize the table contents\r
+  //\r
+  CurrentNotifyList->Signature    = EFI_ACPI_NOTIFY_LIST_SIGNATURE;\r
+  CurrentNotifyList->Notification = Notification;\r
+\r
+  //\r
+  // Add the table to the current list of tables\r
+  //\r
+  InsertTailList (&AcpiTableInstance->NotifyList, &CurrentNotifyList->Link);\r
+\r
+  return ;\r
+}\r
+\r
+/**\r
+  Unregister a callback when an ACPI table is installed.\r
+  \r
+  This function unregisters a function which will be called whenever a new ACPI table is installed.\r
+  \r
+  @param[in]  Notification               Points to the callback function to be unregistered.\r
+  \r
+  @retval EFI_SUCCESS           Callback successfully unregistered.\r
+  @retval EFI_INVALID_PARAMETER Notification does not match a known registration function.                        \r
+**/\r
+EFI_STATUS\r
+SdtUnregisterNotify (\r
+  IN EFI_ACPI_NOTIFICATION_FN   Notification\r
+  )\r
+{\r
+  EFI_ACPI_TABLE_INSTANCE   *AcpiTableInstance;\r
+  EFI_ACPI_NOTIFY_LIST      *CurrentNotifyList;\r
+  LIST_ENTRY                *CurrentLink;\r
+  LIST_ENTRY                *StartLink;\r
+\r
+  //\r
+  // Get the instance of the ACPI Table\r
+  //\r
+  AcpiTableInstance = SdtGetAcpiTableInstance ();\r
+\r
+  //\r
+  // Find the notify\r
+  //\r
+  StartLink   = &AcpiTableInstance->NotifyList;\r
+  CurrentLink = StartLink->ForwardLink;\r
+\r
+  while (CurrentLink != StartLink) {\r
+    CurrentNotifyList = EFI_ACPI_NOTIFY_LIST_FROM_LINK (CurrentLink);\r
+    if (CurrentNotifyList->Notification == Notification) {\r
+      //\r
+      // Good! Found notification.\r
+      //\r
+      // Remove it from list and free the node.\r
+      //\r
+      RemoveEntryList (&(CurrentNotifyList->Link));\r
+      FreePool (CurrentNotifyList);\r
+      return EFI_SUCCESS;\r
+    }\r
+\r
+    CurrentLink = CurrentLink->ForwardLink;\r
+  }\r
+\r
+  //\r
+  // Not found!\r
+  //\r
+  return EFI_INVALID_PARAMETER;\r
+}\r
+\r
+/**\r
+  Register or unregister a callback when an ACPI table is installed.\r
+  \r
+  This function registers or unregisters a function which will be called whenever a new ACPI table is\r
+  installed.\r
+  \r
+  @param[in]    Register        If TRUE, then the specified function will be registered. If FALSE, then the specified\r
+                                function will be unregistered.\r
+  @param[in]    Notification    Points to the callback function to be registered or unregistered.\r
+  \r
+  @retval EFI_SUCCESS           Callback successfully registered or unregistered.\r
+  @retval EFI_INVALID_PARAMETER Notification is NULL\r
+  @retval EFI_INVALID_PARAMETER Register is FALSE and Notification does not match a known registration function.                        \r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RegisterNotify (\r
+  IN BOOLEAN                    Register,\r
+  IN EFI_ACPI_NOTIFICATION_FN   Notification\r
+  )\r
+{\r
+  //\r
+  // Check for invalid input parameters\r
+  //\r
+  if (Notification == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (Register) {\r
+    //\r
+    // Register a new notify\r
+    //\r
+    SdtRegisterNotify (Notification);\r
+    return EFI_SUCCESS;\r
+  } else {\r
+    //\r
+    // Unregister an old notify\r
+    //\r
+    return SdtUnregisterNotify (Notification);\r
+  }\r
+}\r
+\r
+/**\r
+  Create a handle for the first ACPI opcode in an ACPI system description table.\r
+  \r
+  @param[in]    TableKey    The table key for the ACPI table, as returned by GetTable().\r
+  @param[out]   Handle      On return, points to the newly created ACPI handle.\r
+\r
+  @retval EFI_SUCCESS       Handle created successfully.\r
+  @retval EFI_NOT_FOUND     TableKey does not refer to a valid ACPI table.  \r
+**/\r
+EFI_STATUS\r
+SdtOpenSdtTable (\r
+  IN    UINTN           TableKey,\r
+  OUT   EFI_ACPI_HANDLE *Handle\r
+  )\r
+{\r
+  EFI_ACPI_TABLE_INSTANCE   *AcpiTableInstance;\r
+  EFI_STATUS                Status;\r
+  EFI_ACPI_TABLE_LIST       *Table;\r
+  EFI_AML_HANDLE            *AmlHandle;\r
+\r
+  //\r
+  // Get the instance of the ACPI Table\r
+  //\r
+  AcpiTableInstance = SdtGetAcpiTableInstance ();\r
+\r
+  //\r
+  // Find the table\r
+  //\r
+  Status = FindTableByHandle (\r
+             TableKey,\r
+             &AcpiTableInstance->TableList,\r
+             &Table\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_NOT_FOUND;\r
+  }\r
+\r
+  AmlHandle = AllocatePool (sizeof(*AmlHandle));\r
+  ASSERT (AmlHandle != NULL);\r
+  AmlHandle->Signature       = EFI_AML_ROOT_HANDLE_SIGNATURE;\r
+  AmlHandle->Buffer          = (VOID *)((UINTN)Table->Table + sizeof(EFI_ACPI_SDT_HEADER));\r
+  AmlHandle->Size            = Table->Table->Length - sizeof(EFI_ACPI_SDT_HEADER);\r
+  AmlHandle->AmlByteEncoding = NULL;\r
+  AmlHandle->Modified        = FALSE;\r
+\r
+  //\r
+  // return the ACPI handle\r
+  //\r
+  *Handle = (EFI_ACPI_HANDLE)AmlHandle;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Create a handle for the first ACPI opcode in an ACPI system description table.\r
+  \r
+  @param[in]    TableKey    The table key for the ACPI table, as returned by GetTable().\r
+  @param[out]   Handle      On return, points to the newly created ACPI handle.\r
+\r
+  @retval EFI_SUCCESS       Handle created successfully.\r
+  @retval EFI_NOT_FOUND     TableKey does not refer to a valid ACPI table.  \r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+OpenSdt (\r
+  IN    UINTN           TableKey,\r
+  OUT   EFI_ACPI_HANDLE *Handle\r
+  )\r
+{\r
+  if (Handle == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  return SdtOpenSdtTable (TableKey, Handle);\r
+}\r
+\r
+/**\r
+  Create a handle from an ACPI opcode\r
+  \r
+  @param[in]  Buffer                 Points to the ACPI opcode.\r
+  @param[in]  BufferSize             Max buffer size.\r
+  @param[out] Handle                 Upon return, holds the handle.\r
+  \r
+  @retval   EFI_SUCCESS             Success\r
+  @retval   EFI_INVALID_PARAMETER   Buffer is NULL or Handle is NULL or Buffer points to an\r
+                                    invalid opcode.\r
+  \r
+**/\r
+EFI_STATUS\r
+SdtOpenEx (\r
+  IN    VOID            *Buffer,\r
+  IN    UINTN           BufferSize,\r
+  OUT   EFI_ACPI_HANDLE *Handle \r
+  )\r
+{\r
+  AML_BYTE_ENCODING   *AmlByteEncoding;\r
+  EFI_AML_HANDLE      *AmlHandle;\r
+\r
+  AmlByteEncoding = AmlSearchByOpByte (Buffer);\r
+  if (AmlByteEncoding == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Do not open NameString as handle\r
+  //\r
+  if ((AmlByteEncoding->Attribute & AML_IS_NAME_CHAR) != 0) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Good, find it\r
+  //\r
+  AmlHandle = AllocatePool (sizeof(*AmlHandle));\r
+  ASSERT (AmlHandle != NULL);\r
+  \r
+  AmlHandle->Signature       = EFI_AML_HANDLE_SIGNATURE;\r
+  AmlHandle->Buffer          = Buffer;\r
+  AmlHandle->AmlByteEncoding = AmlByteEncoding;\r
+  AmlHandle->Modified        = FALSE;\r
+\r
+  AmlHandle->Size = AmlGetObjectSize (AmlByteEncoding, Buffer, BufferSize);\r
+  if (AmlHandle->Size == 0) {\r
+    FreePool (AmlHandle);\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  *Handle = (EFI_ACPI_HANDLE)AmlHandle;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Create a handle from an ACPI opcode\r
+  \r
+  @param[in]  Buffer                 Points to the ACPI opcode.\r
+  @param[out] Handle                 Upon return, holds the handle.\r
+  \r
+  @retval   EFI_SUCCESS             Success\r
+  @retval   EFI_INVALID_PARAMETER   Buffer is NULL or Handle is NULL or Buffer points to an\r
+                                    invalid opcode.\r
+  \r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Open (\r
+  IN    VOID            *Buffer,\r
+  OUT   EFI_ACPI_HANDLE *Handle \r
+  )\r
+{\r
+  EFI_STATUS          Status;\r
+  UINTN               MaxSize;\r
+\r
+  //\r
+  // Check for invalid input parameters\r
+  //\r
+  if (Buffer == NULL || Handle == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  Status = SdtGetMaxAmlBufferSize (Buffer, &MaxSize);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  return SdtOpenEx (Buffer, MaxSize, Handle);\r
+}\r
+\r
+/**\r
+  Close an ACPI handle.\r
+  \r
+  @param[in] Handle Returns the handle.\r
+  \r
+  @retval EFI_SUCCESS           Success\r
+  @retval EFI_INVALID_PARAMETER Handle is NULL or does not refer to a valid ACPI object.  \r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Close (\r
+  IN EFI_ACPI_HANDLE Handle\r
+  )\r
+{\r
+  EFI_AML_HANDLE      *AmlHandle;\r
+  EFI_STATUS          Status;\r
+\r
+  //\r
+  // Check for invalid input parameters\r
+  //\r
+  if (Handle == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  AmlHandle = (EFI_AML_HANDLE *)Handle;\r
+  if ((AmlHandle->Signature != EFI_AML_ROOT_HANDLE_SIGNATURE) &&\r
+      (AmlHandle->Signature != EFI_AML_HANDLE_SIGNATURE)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Update Checksum only if modified\r
+  //\r
+  if (AmlHandle->Modified) {\r
+    Status = SdtUpdateAmlChecksum (AmlHandle->Buffer);\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  }\r
+\r
+  FreePool (AmlHandle);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Retrieve information about an ACPI object.\r
+  \r
+  @param[in]    Handle      ACPI object handle.\r
+  @param[in]    Index       Index of the data to retrieve from the object. In general, indexes read from left-to-right\r
+                            in the ACPI encoding, with index 0 always being the ACPI opcode.\r
+  @param[out]   DataType    Points to the returned data type or EFI_ACPI_DATA_TYPE_NONE if no data exists\r
+                            for the specified index.\r
+  @param[out]   Data        Upon return, points to the pointer to the data.\r
+  @param[out]   DataSize    Upon return, points to the size of Data.\r
+  \r
+  @retval       EFI_SUCCESS           Success.\r
+  @retval       EFI_INVALID_PARAMETER Handle is NULL or does not refer to a valid ACPI object.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetOption (\r
+  IN        EFI_ACPI_HANDLE     Handle,\r
+  IN        UINTN               Index,\r
+  OUT       EFI_ACPI_DATA_TYPE  *DataType,\r
+  OUT CONST VOID                **Data,\r
+  OUT       UINTN               *DataSize\r
+  )\r
+{\r
+  EFI_AML_HANDLE      *AmlHandle;\r
+  AML_BYTE_ENCODING   *AmlByteEncoding;\r
+  EFI_STATUS          Status;\r
+\r
+  ASSERT (DataType != NULL);\r
+  ASSERT (Data != NULL);\r
+  ASSERT (DataSize != NULL);\r
+\r
+  //\r
+  // Check for invalid input parameters\r
+  //\r
+  if (Handle == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  AmlHandle = (EFI_AML_HANDLE *)Handle;\r
+  //\r
+  // Do not check EFI_AML_ROOT_HANDLE_SIGNATURE because there is no option for Root handle\r
+  //\r
+  if (AmlHandle->Signature != EFI_AML_HANDLE_SIGNATURE) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  AmlByteEncoding = AmlHandle->AmlByteEncoding;\r
+  if (Index > AmlByteEncoding->MaxIndex) {\r
+    *DataType = EFI_ACPI_DATA_TYPE_NONE;\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // Parse option\r
+  //\r
+  Status = AmlParseOptionHandleCommon (AmlHandle, (AML_OP_PARSE_INDEX)Index, DataType, (VOID **)Data, DataSize);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Change information about an ACPI object.\r
+  \r
+  @param[in]  Handle    ACPI object handle.\r
+  @param[in]  Index     Index of the data to retrieve from the object. In general, indexes read from left-to-right\r
+                        in the ACPI encoding, with index 0 always being the ACPI opcode.\r
+  @param[in]  Data      Points to the data.\r
+  @param[in]  DataSize  The size of the Data.\r
+\r
+  @retval EFI_SUCCESS           Success\r
+  @retval EFI_INVALID_PARAMETER Handle is NULL or does not refer to a valid ACPI object.\r
+  @retval EFI_BAD_BUFFER_SIZE   Data cannot be accommodated in the space occupied by\r
+                                the option.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SetOption (\r
+  IN        EFI_ACPI_HANDLE Handle,\r
+  IN        UINTN           Index,\r
+  IN CONST  VOID            *Data,\r
+  IN        UINTN           DataSize\r
+  )\r
+{\r
+  EFI_AML_HANDLE      *AmlHandle;\r
+  AML_BYTE_ENCODING   *AmlByteEncoding;\r
+  EFI_STATUS          Status;\r
+  EFI_ACPI_DATA_TYPE  DataType;\r
+  VOID                *OrgData;\r
+  UINTN               OrgDataSize;\r
+\r
+  ASSERT (Data != NULL);\r
+\r
+  //\r
+  // Check for invalid input parameters\r
+  //\r
+  if (Handle == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  AmlHandle = (EFI_AML_HANDLE *)Handle;\r
+  //\r
+  // Do not check EFI_AML_ROOT_HANDLE_SIGNATURE because there is no option for Root handle\r
+  //\r
+  if (AmlHandle->Signature != EFI_AML_HANDLE_SIGNATURE) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  AmlByteEncoding = AmlHandle->AmlByteEncoding;\r
+\r
+  if (Index > AmlByteEncoding->MaxIndex) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Parse option\r
+  //\r
+  Status = AmlParseOptionHandleCommon (AmlHandle, (AML_OP_PARSE_INDEX)Index, &DataType, &OrgData, &OrgDataSize);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  if (DataType == EFI_ACPI_DATA_TYPE_NONE) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (DataSize > OrgDataSize) {\r
+    return EFI_BAD_BUFFER_SIZE;\r
+  }\r
+\r
+  //\r
+  // Update\r
+  //\r
+  CopyMem (OrgData, Data, DataSize);\r
+  AmlHandle->Modified = TRUE;\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Return the child ACPI objects.\r
+  \r
+  @param[in]        ParentHandle    Parent handle.\r
+  @param[in, out]   Handle          On entry, points to the previously returned handle or NULL to start with the first\r
+                                    handle. On return, points to the next returned ACPI handle or NULL if there are no\r
+                                    child objects.\r
+\r
+  @retval EFI_SUCCESS               Success\r
+  @retval EFI_INVALID_PARAMETER     ParentHandle is NULL or does not refer to a valid ACPI object.                                \r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetChild (\r
+  IN EFI_ACPI_HANDLE        ParentHandle,\r
+  IN OUT EFI_ACPI_HANDLE    *Handle\r
+  )\r
+{\r
+  EFI_AML_HANDLE      *AmlParentHandle;\r
+  EFI_AML_HANDLE      *AmlHandle;\r
+  VOID                *Buffer;\r
+  EFI_STATUS          Status;\r
+\r
+  ASSERT (Handle != NULL);\r
+\r
+  //\r
+  // Check for invalid input parameters\r
+  //\r
+  if (ParentHandle == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  AmlHandle       = *Handle;\r
+  if ((AmlHandle != NULL) && (AmlHandle->Signature != EFI_AML_HANDLE_SIGNATURE)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  AmlParentHandle = (EFI_AML_HANDLE *)ParentHandle;\r
+  if (AmlParentHandle->Signature == EFI_AML_ROOT_HANDLE_SIGNATURE) {\r
+    //\r
+    // Root handle\r
+    //\r
+    Status = AmlGetChildFromRoot (AmlParentHandle, AmlHandle, &Buffer);\r
+  } else if (AmlParentHandle->Signature == EFI_AML_HANDLE_SIGNATURE) {\r
+    //\r
+    // Non-root handle\r
+    //\r
+    Status = AmlGetChildFromNonRoot (AmlParentHandle, AmlHandle, &Buffer);\r
+  } else {\r
+    //\r
+    // Invalid\r
+    //\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  if (Buffer == NULL) {\r
+    *Handle = NULL;\r
+    return EFI_SUCCESS;\r
+  }\r
+  return SdtOpenEx (Buffer, (UINTN)AmlParentHandle->Buffer + AmlParentHandle->Size - (UINTN)Buffer, Handle);\r
+}\r
+\r
+/**\r
+  Returns the handle of the ACPI object representing the specified ACPI path\r
+  \r
+  @param[in]    HandleIn    Points to the handle of the object representing the starting point for the path search.\r
+  @param[in]    AmlPath     Points to the AML path.\r
+  @param[out]   HandleOut   On return, points to the ACPI object which represents AcpiPath, relative to\r
+                            HandleIn.\r
+                            \r
+  @retval EFI_SUCCESS           Success\r
+  @retval EFI_INVALID_PARAMETER HandleIn is NULL or does not refer to a valid ACPI object.                            \r
+**/\r
+EFI_STATUS\r
+SdtFindPathFromNonRoot (\r
+  IN    EFI_ACPI_HANDLE HandleIn,\r
+  IN    UINT8           *AmlPath,\r
+  OUT   EFI_ACPI_HANDLE *HandleOut\r
+  )\r
+{\r
+  EFI_AML_HANDLE      *AmlHandle;\r
+  VOID                *Buffer;\r
+  EFI_STATUS          Status;\r
+\r
+  AmlHandle = (EFI_AML_HANDLE *)HandleIn;\r
+\r
+  //\r
+  // For non-root handle, we need search from THIS node instead of ROOT.\r
+  //\r
+  Status = AmlFindPath (AmlHandle, AmlPath, &Buffer, FALSE);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  if (Buffer == NULL) {\r
+    *HandleOut = NULL;\r
+    return EFI_SUCCESS;\r
+  }\r
+  return SdtOpenEx (Buffer, (UINTN)AmlHandle->Buffer + AmlHandle->Size - (UINTN)Buffer, HandleOut);\r
+}\r
+\r
+/**\r
+  Duplicate AML handle.\r
+  \r
+  @param[in]    AmlHandle   Handle to be duplicated.\r
+                            \r
+  @return Duplicated AML handle.\r
+**/\r
+EFI_AML_HANDLE *\r
+SdtDuplicateHandle (\r
+  IN EFI_AML_HANDLE      *AmlHandle\r
+  )\r
+{\r
+  EFI_AML_HANDLE  *DstAmlHandle;\r
+\r
+  DstAmlHandle = AllocatePool (sizeof(*DstAmlHandle));\r
+  ASSERT (DstAmlHandle != NULL);\r
+  CopyMem (DstAmlHandle, (VOID *)AmlHandle, sizeof(*DstAmlHandle));\r
+\r
+  return DstAmlHandle;\r
+}\r
+\r
+/**\r
+  Returns the handle of the ACPI object representing the specified ACPI path\r
+  \r
+  @param[in]    HandleIn    Points to the handle of the object representing the starting point for the path search.\r
+  @param[in]    AmlPath     Points to the AML path.\r
+  @param[out]   HandleOut   On return, points to the ACPI object which represents AcpiPath, relative to\r
+                            HandleIn.\r
+                            \r
+  @retval EFI_SUCCESS           Success\r
+  @retval EFI_INVALID_PARAMETER HandleIn is NULL or does not refer to a valid ACPI object.                            \r
+**/\r
+EFI_STATUS\r
+SdtFindPathFromRoot (\r
+  IN    EFI_ACPI_HANDLE HandleIn,\r
+  IN    UINT8           *AmlPath,\r
+  OUT   EFI_ACPI_HANDLE *HandleOut\r
+  )\r
+{\r
+  EFI_ACPI_HANDLE     ChildHandle;\r
+  EFI_AML_HANDLE      *AmlHandle;\r
+  EFI_STATUS          Status;\r
+  VOID                *Buffer;\r
+\r
+  AmlHandle = (EFI_AML_HANDLE *)HandleIn;\r
+\r
+  //\r
+  // Handle case that AcpiPath is Root\r
+  //\r
+  if (AmlIsRootPath (AmlPath)) {\r
+    //\r
+    // Duplicate RootHandle\r
+    //\r
+    *HandleOut = (EFI_ACPI_HANDLE)SdtDuplicateHandle (AmlHandle);\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // Let children find it.\r
+  //\r
+  ChildHandle = NULL;\r
+  while (TRUE) {\r
+    Status = GetChild (HandleIn, &ChildHandle);\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+    if (ChildHandle == NULL) {\r
+      //\r
+      // Not found\r
+      //\r
+      *HandleOut = NULL;\r
+      return EFI_SUCCESS;\r
+    }\r
+\r
+    //\r
+    // More child\r
+    //\r
+    AmlHandle = (EFI_AML_HANDLE *)ChildHandle;\r
+    Status = AmlFindPath (AmlHandle, AmlPath, &Buffer, TRUE);\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+    if (Buffer != NULL) {\r
+      //\r
+      // Great! Find it, open\r
+      //\r
+      Status = SdtOpenEx (Buffer, (UINTN)AmlHandle->Buffer + AmlHandle->Size - (UINTN)Buffer, HandleOut);\r
+      if (!EFI_ERROR (Status))  {\r
+        return EFI_SUCCESS;\r
+      }\r
+      //\r
+      // Not success, try next one\r
+      //\r
+    }\r
+  }\r
+\r
+  //\r
+  // Should not run here\r
+  //\r
+}\r
+\r
+/**\r
+  Returns the handle of the ACPI object representing the specified ACPI path\r
+  \r
+  @param[in]    HandleIn    Points to the handle of the object representing the starting point for the path search.\r
+  @param[in]    AcpiPath    Points to the ACPI path, which conforms to the ACPI encoded path format.\r
+  @param[out]   HandleOut   On return, points to the ACPI object which represents AcpiPath, relative to\r
+                            HandleIn.\r
+                            \r
+  @retval EFI_SUCCESS           Success\r
+  @retval EFI_INVALID_PARAMETER HandleIn is NULL or does not refer to a valid ACPI object.                            \r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FindPath (\r
+  IN    EFI_ACPI_HANDLE HandleIn,\r
+  IN    VOID            *AcpiPath,\r
+  OUT   EFI_ACPI_HANDLE *HandleOut\r
+  )\r
+{\r
+  EFI_AML_HANDLE      *AmlHandle;\r
+  EFI_STATUS          Status;\r
+  UINT8               *AmlPath;\r
+\r
+  //\r
+  // Check for invalid input parameters\r
+  //\r
+  if (HandleIn == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  AmlHandle = (EFI_AML_HANDLE *)HandleIn;\r
+  \r
+  //\r
+  // Convert ASL path to AML path\r
+  //\r
+  AmlPath = AmlNameFromAslName (AcpiPath);\r
+  if (AmlPath == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  DEBUG_CODE_BEGIN ();\r
+  DEBUG ((EFI_D_ERROR, "AcpiSdt: FindPath - "));\r
+  AmlPrintNameString (AmlPath);\r
+  DEBUG ((EFI_D_ERROR, "\n"));\r
+  DEBUG_CODE_END ();\r
+\r
+  if (AmlHandle->Signature == EFI_AML_ROOT_HANDLE_SIGNATURE) {\r
+    //\r
+    // Root Handle\r
+    //\r
+    Status = SdtFindPathFromRoot (HandleIn, AmlPath, HandleOut);\r
+  } else if (AmlHandle->Signature == EFI_AML_HANDLE_SIGNATURE) {\r
+    //\r
+    // Non-Root handle\r
+    //\r
+    Status = SdtFindPathFromNonRoot (HandleIn, AmlPath, HandleOut);\r
+  } else {\r
+    Status = EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  FreePool (AmlPath);\r
+\r
+  return Status;\r
+}\r
+\r
+/**\r
+  ExitPmAuth Protocol notification event handler.\r
+\r
+  @param[in] Event    Event whose notification function is being invoked.\r
+  @param[in] Context  Pointer to the notification function's context.\r
+**/\r
+VOID\r
+EFIAPI\r
+ExitPmAuthNotification (\r
+  IN EFI_EVENT  Event,\r
+  IN VOID       *Context\r
+  )\r
+{\r
+  EFI_STATUS Status;\r
+  VOID       *DxeSmmReadyToLock;\r
+\r
+  //\r
+  // Add more check to locate protocol after got event, because\r
+  // the library will signal this event immediately once it is register\r
+  // just in case it is already installed.\r
+  //\r
+  Status = gBS->LocateProtocol (\r
+                  &gEfiDxeSmmReadyToLockProtocolGuid,\r
+                  NULL,\r
+                  &DxeSmmReadyToLock\r
+                  );\r
+  if (EFI_ERROR (Status)) {\r
+    return ;\r
+  }\r
+\r
+  //\r
+  // Uninstall ACPI SDT protocol, so that we can make sure no one update ACPI table from API level.\r
+  //\r
+  Status = gBS->UninstallProtocolInterface (\r
+                  mHandle,\r
+                  &gEfiAcpiSdtProtocolGuid,\r
+                  &mPrivateData->AcpiSdtProtocol\r
+                  );\r
+  ASSERT_EFI_ERROR (Status);\r
+\r
+  //\r
+  // Close event, so it will not be invoked again.\r
+  //\r
+  gBS->CloseEvent (Event);\r
+\r
+  return ;\r
+}\r
+\r
+/**\r
+  This function initializes AcpiSdt protocol in ACPI table instance.\r
+\r
+  @param[in]  AcpiTableInstance       Instance to construct\r
+**/\r
+VOID\r
+SdtAcpiTableAcpiSdtConstructor (\r
+  IN EFI_ACPI_TABLE_INSTANCE   *AcpiTableInstance\r
+  )\r
+{\r
+  VOID *Registration;\r
+\r
+  InitializeListHead (&AcpiTableInstance->NotifyList);\r
+  CopyMem (&AcpiTableInstance->AcpiSdtProtocol, &mAcpiSdtProtocolTemplate, sizeof(mAcpiSdtProtocolTemplate));\r
+\r
+  //\r
+  // Register event for ExitPmAuth, so that we can uninstall ACPI SDT protocol after ExitPmAuth.\r
+  //\r
+  EfiCreateProtocolNotifyEvent (\r
+    &gEfiDxeSmmReadyToLockProtocolGuid,\r
+    TPL_CALLBACK,\r
+    ExitPmAuthNotification,\r
+    NULL,\r
+    &Registration\r
+    );\r
+\r
+  return ;\r
+}\r
diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.h b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AcpiSdt.h
new file mode 100644 (file)
index 0000000..56187ae
--- /dev/null
@@ -0,0 +1,740 @@
+/** @file\r
+  ACPI Sdt Protocol Driver\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved. <BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#ifndef _ACPI_SDT_H_\r
+#define _ACPI_SDT_H_\r
+\r
+//\r
+// ACPI AML definition\r
+//\r
+\r
+//\r
+// Primary OpCode\r
+//\r
+#define AML_ZERO_OP                  0x00\r
+#define AML_ONE_OP                   0x01\r
+#define AML_ALIAS_OP                 0x06\r
+#define AML_NAME_OP                  0x08\r
+#define AML_BYTE_PREFIX              0x0a\r
+#define AML_WORD_PREFIX              0x0b\r
+#define AML_DWORD_PREFIX             0x0c\r
+#define AML_STRING_PREFIX            0x0d\r
+#define AML_QWORD_PREFIX             0x0e\r
+#define AML_SCOPE_OP                 0x10\r
+#define AML_BUFFER_OP                0x11\r
+#define AML_PACKAGE_OP               0x12\r
+#define AML_VAR_PACKAGE_OP           0x13\r
+#define AML_METHOD_OP                0x14\r
+#define AML_DUAL_NAME_PREFIX         0x2e\r
+#define AML_MULTI_NAME_PREFIX        0x2f\r
+#define AML_NAME_CHAR_A              0x41\r
+#define AML_NAME_CHAR_B              0x42\r
+#define AML_NAME_CHAR_C              0x43\r
+#define AML_NAME_CHAR_D              0x44\r
+#define AML_NAME_CHAR_E              0x45\r
+#define AML_NAME_CHAR_F              0x46\r
+#define AML_NAME_CHAR_G              0x47\r
+#define AML_NAME_CHAR_H              0x48\r
+#define AML_NAME_CHAR_I              0x49\r
+#define AML_NAME_CHAR_J              0x4a\r
+#define AML_NAME_CHAR_K              0x4b\r
+#define AML_NAME_CHAR_L              0x4c\r
+#define AML_NAME_CHAR_M              0x4d\r
+#define AML_NAME_CHAR_N              0x4e\r
+#define AML_NAME_CHAR_O              0x4f\r
+#define AML_NAME_CHAR_P              0x50\r
+#define AML_NAME_CHAR_Q              0x51\r
+#define AML_NAME_CHAR_R              0x52\r
+#define AML_NAME_CHAR_S              0x53\r
+#define AML_NAME_CHAR_T              0x54\r
+#define AML_NAME_CHAR_U              0x55\r
+#define AML_NAME_CHAR_V              0x56\r
+#define AML_NAME_CHAR_W              0x57\r
+#define AML_NAME_CHAR_X              0x58\r
+#define AML_NAME_CHAR_Y              0x59\r
+#define AML_NAME_CHAR_Z              0x5a\r
+#define AML_ROOT_CHAR                0x5c\r
+#define AML_PARENT_PREFIX_CHAR       0x5e\r
+#define AML_NAME_CHAR__              0x5f\r
+#define AML_LOCAL0                   0x60\r
+#define AML_LOCAL1                   0x61\r
+#define AML_LOCAL2                   0x62\r
+#define AML_LOCAL3                   0x63\r
+#define AML_LOCAL4                   0x64\r
+#define AML_LOCAL5                   0x65\r
+#define AML_LOCAL6                   0x66\r
+#define AML_LOCAL7                   0x67\r
+#define AML_ARG0                     0x68\r
+#define AML_ARG1                     0x69\r
+#define AML_ARG2                     0x6a\r
+#define AML_ARG3                     0x6b\r
+#define AML_ARG4                     0x6c\r
+#define AML_ARG5                     0x6d\r
+#define AML_ARG6                     0x6e\r
+#define AML_STORE_OP                 0x70\r
+#define AML_REF_OF_OP                0x71\r
+#define AML_ADD_OP                   0x72\r
+#define AML_CONCAT_OP                0x73\r
+#define AML_SUBTRACT_OP              0x74\r
+#define AML_INCREMENT_OP             0x75\r
+#define AML_DECREMENT_OP             0x76\r
+#define AML_MULTIPLY_OP              0x77\r
+#define AML_DIVIDE_OP                0x78\r
+#define AML_SHIFT_LEFT_OP            0x79\r
+#define AML_SHIFT_RIGHT_OP           0x7a\r
+#define AML_AND_OP                   0x7b\r
+#define AML_NAND_OP                  0x7c\r
+#define AML_OR_OP                    0x7d\r
+#define AML_NOR_OP                   0x7e\r
+#define AML_XOR_OP                   0x7f\r
+#define AML_NOT_OP                   0x80\r
+#define AML_FIND_SET_LEFT_BIT_OP     0x81\r
+#define AML_FIND_SET_RIGHT_BIT_OP    0x82\r
+#define AML_DEREF_OF_OP              0x83\r
+#define AML_CONCAT_RES_OP            0x84\r
+#define AML_MOD_OP                   0x85\r
+#define AML_NOTIFY_OP                0x86\r
+#define AML_SIZE_OF_OP               0x87\r
+#define AML_INDEX_OP                 0x88\r
+#define AML_MATCH_OP                 0x89\r
+#define AML_CREATE_DWORD_FIELD_OP    0x8a\r
+#define AML_CREATE_WORD_FIELD_OP     0x8b\r
+#define AML_CREATE_BYTE_FIELD_OP     0x8c\r
+#define AML_CREATE_BIT_FIELD_OP      0x8d\r
+#define AML_OBJECT_TYPE_OP           0x8e\r
+#define AML_CREATE_QWORD_FIELD_OP    0x8f\r
+#define AML_LAND_OP                  0x90\r
+#define AML_LOR_OP                   0x91\r
+#define AML_LNOT_OP                  0x92\r
+#define AML_LEQUAL_OP                0x93\r
+#define AML_LGREATER_OP              0x94\r
+#define AML_LLESS_OP                 0x95\r
+#define AML_TO_BUFFER_OP             0x96\r
+#define AML_TO_DEC_STRING_OP         0x97\r
+#define AML_TO_HEX_STRING_OP         0x98\r
+#define AML_TO_INTEGER_OP            0x99\r
+#define AML_TO_STRING_OP             0x9c\r
+#define AML_COPY_OBJECT_OP           0x9d\r
+#define AML_MID_OP                   0x9e\r
+#define AML_CONTINUE_OP              0x9f\r
+#define AML_IF_OP                    0xa0\r
+#define AML_ELSE_OP                  0xa1\r
+#define AML_WHILE_OP                 0xa2\r
+#define AML_NOOP_OP                  0xa3\r
+#define AML_RETURN_OP                0xa4\r
+#define AML_BREAK_OP                 0xa5\r
+#define AML_BREAK_POINT_OP           0xcc\r
+#define AML_ONES_OP                  0xff\r
+\r
+//\r
+// Extended OpCode\r
+//\r
+#define AML_EXT_OP                   0x5b\r
+\r
+#define AML_EXT_MUTEX_OP             0x01\r
+#define AML_EXT_EVENT_OP             0x02\r
+#define AML_EXT_COND_REF_OF_OP       0x12\r
+#define AML_EXT_CREATE_FIELD_OP      0x13\r
+#define AML_EXT_LOAD_TABLE_OP        0x1f\r
+#define AML_EXT_LOAD_OP              0x20\r
+#define AML_EXT_STALL_OP             0x21\r
+#define AML_EXT_SLEEP_OP             0x22\r
+#define AML_EXT_ACQUIRE_OP           0x23\r
+#define AML_EXT_SIGNAL_OP            0x24\r
+#define AML_EXT_WAIT_OP              0x25\r
+#define AML_EXT_RESET_OP             0x26\r
+#define AML_EXT_RELEASE_OP           0x27\r
+#define AML_EXT_FROM_BCD_OP          0x28\r
+#define AML_EXT_TO_BCD_OP            0x29\r
+#define AML_EXT_UNLOAD_OP            0x2a\r
+#define AML_EXT_REVISION_OP          0x30\r
+#define AML_EXT_DEBUG_OP             0x31\r
+#define AML_EXT_FATAL_OP             0x32\r
+#define AML_EXT_TIMER_OP             0x33\r
+#define AML_EXT_REGION_OP            0x80\r
+#define AML_EXT_FIELD_OP             0x81\r
+#define AML_EXT_DEVICE_OP            0x82\r
+#define AML_EXT_PROCESSOR_OP         0x83\r
+#define AML_EXT_POWER_RES_OP         0x84\r
+#define AML_EXT_THERMAL_ZONE_OP      0x85\r
+#define AML_EXT_INDEX_FIELD_OP       0x86\r
+#define AML_EXT_BANK_FIELD_OP        0x87\r
+#define AML_EXT_DATA_REGION_OP       0x88\r
+\r
+//\r
+// Privacy data structure\r
+//\r
+\r
+//\r
+// ACPI Notify Linked List Signature.\r
+//\r
+#define EFI_ACPI_NOTIFY_LIST_SIGNATURE SIGNATURE_32 ('E', 'A', 'N', 'L')\r
+\r
+//\r
+// ACPI Notify List Entry definition.\r
+//\r
+//  Signature must be set to EFI_ACPI_NOTIFY_LIST_SIGNATURE\r
+//  Link is the linked list data.\r
+//  Notification is the callback function.\r
+//\r
+typedef struct {\r
+  UINT32                   Signature;\r
+  LIST_ENTRY               Link;\r
+  EFI_ACPI_NOTIFICATION_FN Notification;\r
+} EFI_ACPI_NOTIFY_LIST;\r
+\r
+//\r
+// Containment record for ACPI Notify linked list.\r
+//\r
+#define EFI_ACPI_NOTIFY_LIST_FROM_LINK(_link)  CR (_link, EFI_ACPI_NOTIFY_LIST, Link, EFI_ACPI_NOTIFY_LIST_SIGNATURE)\r
+\r
+typedef struct _AML_BYTE_ENCODING AML_BYTE_ENCODING;\r
+typedef struct _EFI_AML_NODE_LIST EFI_AML_NODE_LIST;\r
+\r
+//\r
+// AML Node Linked List Signature.\r
+//\r
+#define EFI_AML_NODE_LIST_SIGNATURE SIGNATURE_32 ('E', 'A', 'M', 'L')\r
+\r
+//\r
+// AML Node Linked List Entry definition.\r
+//\r
+//  Signature must be set to EFI_AML_NODE_LIST_SIGNATURE\r
+//  Link is the linked list data.\r
+//  Name is the ACPI node name.\r
+//         This is listed for PATH finding.\r
+//  Buffer is the ACPI node buffer pointer, the first/second bytes are opcode.\r
+//         This buffer should not be freed.\r
+//  Size is the total size of this ACPI node buffer.\r
+//  Children is the children linked list of this node.\r
+//\r
+#define AML_NAME_SEG_SIZE  4\r
+\r
+struct _EFI_AML_NODE_LIST {\r
+  UINT32                  Signature;\r
+  UINT8                   Name[AML_NAME_SEG_SIZE];\r
+  UINT8                   *Buffer;\r
+  UINTN                   Size;\r
+  LIST_ENTRY              Link;\r
+  LIST_ENTRY              Children;\r
+  EFI_AML_NODE_LIST       *Parent;\r
+  AML_BYTE_ENCODING       *AmlByteEncoding;\r
+};\r
+\r
+//\r
+// Containment record for AML Node linked list.\r
+//\r
+#define EFI_AML_NODE_LIST_FROM_LINK(_link)  CR (_link, EFI_AML_NODE_LIST, Link, EFI_AML_NODE_LIST_SIGNATURE)\r
+\r
+//\r
+// AML Handle Signature.\r
+//\r
+#define EFI_AML_HANDLE_SIGNATURE SIGNATURE_32 ('E', 'A', 'H', 'S')\r
+#define EFI_AML_ROOT_HANDLE_SIGNATURE SIGNATURE_32 ('E', 'A', 'R', 'H')\r
+\r
+//\r
+// AML Handle Entry definition.\r
+//\r
+//  Signature must be set to EFI_AML_HANDLE_SIGNATURE or EFI_AML_ROOT_HANDLE_SIGNATURE\r
+//  Buffer is the ACPI node buffer pointer, the first/second bytes are opcode.\r
+//         This buffer should not be freed.\r
+//  Size is the total size of this ACPI node buffer.\r
+//\r
+typedef struct {\r
+  UINT32                  Signature;\r
+  UINT8                   *Buffer;\r
+  UINTN                   Size;\r
+  AML_BYTE_ENCODING       *AmlByteEncoding;\r
+  BOOLEAN                 Modified;\r
+} EFI_AML_HANDLE;\r
+\r
+typedef UINT32 AML_OP_PARSE_INDEX;\r
+\r
+#define AML_OP_PARSE_INDEX_GET_OPCODE     0\r
+#define AML_OP_PARSE_INDEX_GET_TERM1      1\r
+#define AML_OP_PARSE_INDEX_GET_TERM2      2\r
+#define AML_OP_PARSE_INDEX_GET_TERM3      3\r
+#define AML_OP_PARSE_INDEX_GET_TERM4      4\r
+#define AML_OP_PARSE_INDEX_GET_TERM5      5\r
+#define AML_OP_PARSE_INDEX_GET_TERM6      6\r
+#define AML_OP_PARSE_INDEX_GET_SIZE       (AML_OP_PARSE_INDEX)-1\r
+\r
+typedef UINT32 AML_OP_PARSE_FORMAT;\r
+#define AML_NONE         0\r
+#define AML_OPCODE       1\r
+#define AML_UINT8        2\r
+#define AML_UINT16       3\r
+#define AML_UINT32       4\r
+#define AML_UINT64       5\r
+#define AML_NAME         6\r
+#define AML_STRING       7\r
+#define AML_OBJECT       8\r
+\r
+typedef UINT32 AML_OP_ATTRIBUTE;\r
+#define AML_HAS_PKG_LENGTH       0x1     // It is ACPI attribute - if OpCode has PkgLength\r
+#define AML_IS_NAME_CHAR         0x2     // It is ACPI attribute - if this is NameChar\r
+#define AML_HAS_CHILD_OBJ        0x4     // it is ACPI attribute - if OpCode has Child Object.\r
+#define AML_IN_NAMESPACE         0x10000 // It is UEFI SDT attribute - if OpCode will be in NameSpace\r
+                                         // NOTE; Not all OBJECT will be in NameSpace\r
+                                         // For example, BankField | CreateBitField | CreateByteField | CreateDWordField | \r
+                                         //   CreateField | CreateQWordField | CreateWordField | Field | IndexField.\r
+\r
+struct _AML_BYTE_ENCODING {\r
+  UINT8                      OpCode;\r
+  UINT8                      SubOpCode;\r
+  AML_OP_PARSE_INDEX         MaxIndex;\r
+  AML_OP_PARSE_FORMAT        Format[6];\r
+  AML_OP_ATTRIBUTE           Attribute;\r
+};\r
+\r
+//\r
+// AcpiSdt protocol declaration\r
+//\r
+\r
+/**\r
+  Returns a requested ACPI table.\r
+  \r
+  The GetAcpiTable() function returns a pointer to a buffer containing the ACPI table associated\r
+  with the Index that was input. The following structures are not considered elements in the list of\r
+  ACPI tables:\r
+  - Root System Description Pointer (RSD_PTR)\r
+  - Root System Description Table (RSDT)\r
+  - Extended System Description Table (XSDT)\r
+  Version is updated with a bit map containing all the versions of ACPI of which the table is a\r
+  member.\r
+  \r
+  @param[in]    Index       The zero-based index of the table to retrieve.\r
+  @param[out]   Table       Pointer for returning the table buffer.\r
+  @param[out]   Version     On return, updated with the ACPI versions to which this table belongs. Type\r
+                            EFI_ACPI_TABLE_VERSION is defined in "Related Definitions" in the\r
+                            EFI_ACPI_SDT_PROTOCOL.    \r
+  @param[out]   TableKey    On return, points to the table key for the specified ACPI system definition table. This\r
+                            is identical to the table key used in the EFI_ACPI_TABLE_PROTOCOL.  \r
+                            \r
+  @retval EFI_SUCCESS       The function completed successfully.\r
+  @retval EFI_NOT_FOUND     The requested index is too large and a table was not found.                                  \r
+**/  \r
+EFI_STATUS\r
+EFIAPI\r
+GetAcpiTable2 (\r
+  IN  UINTN                               Index,\r
+  OUT EFI_ACPI_SDT_HEADER                 **Table,\r
+  OUT EFI_ACPI_TABLE_VERSION              *Version,\r
+  OUT UINTN                               *TableKey\r
+  );\r
+\r
+/**\r
+  Register or unregister a callback when an ACPI table is installed.\r
+  \r
+  This function registers or unregisters a function which will be called whenever a new ACPI table is\r
+  installed.\r
+  \r
+  @param[in]    Register        If TRUE, then the specified function will be registered. If FALSE, then the specified\r
+                                function will be unregistered.\r
+  @param[in]    Notification    Points to the callback function to be registered or unregistered.\r
+  \r
+  @retval EFI_SUCCESS           Callback successfully registered or unregistered.\r
+  @retval EFI_INVALID_PARAMETER Notification is NULL\r
+  @retval EFI_INVALID_PARAMETER Register is FALSE and Notification does not match a known registration function.                        \r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+RegisterNotify (\r
+  IN BOOLEAN                    Register,\r
+  IN EFI_ACPI_NOTIFICATION_FN   Notification\r
+  );\r
+\r
+/**\r
+  Create a handle for the first ACPI opcode in an ACPI system description table.\r
+  \r
+  @param[in]    TableKey    The table key for the ACPI table, as returned by GetTable().\r
+  @param[out]   Handle      On return, points to the newly created ACPI handle.\r
+\r
+  @retval EFI_SUCCESS       Handle created successfully.\r
+  @retval EFI_NOT_FOUND     TableKey does not refer to a valid ACPI table.  \r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+OpenSdt (\r
+  IN    UINTN           TableKey,\r
+  OUT   EFI_ACPI_HANDLE *Handle\r
+  );\r
+\r
+/**\r
+  Create a handle from an ACPI opcode\r
+  \r
+  @param[in]  Buffer                 Points to the ACPI opcode.\r
+  @param[out] Handle                 Upon return, holds the handle.\r
+  \r
+  @retval   EFI_SUCCESS             Success\r
+  @retval   EFI_INVALID_PARAMETER   Buffer is NULL or Handle is NULL or Buffer points to an\r
+                                    invalid opcode.\r
+  \r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Open (\r
+  IN    VOID            *Buffer,\r
+  OUT   EFI_ACPI_HANDLE *Handle \r
+  );\r
+\r
+/**\r
+  Close an ACPI handle.\r
+  \r
+  @param[in] Handle Returns the handle.\r
+  \r
+  @retval EFI_SUCCESS           Success\r
+  @retval EFI_INVALID_PARAMETER Handle is NULL or does not refer to a valid ACPI object.  \r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Close (\r
+  IN EFI_ACPI_HANDLE Handle\r
+  );\r
+\r
+/**\r
+  Retrieve information about an ACPI object.\r
+  \r
+  @param[in]    Handle      ACPI object handle.\r
+  @param[in]    Index       Index of the data to retrieve from the object. In general, indexes read from left-to-right\r
+                            in the ACPI encoding, with index 0 always being the ACPI opcode.\r
+  @param[out]   DataType    Points to the returned data type or EFI_ACPI_DATA_TYPE_NONE if no data exists\r
+                            for the specified index.\r
+  @param[out]   Data        Upon return, points to the pointer to the data.\r
+  @param[out]   DataSize    Upon return, points to the size of Data.\r
+  \r
+  @retval       EFI_SUCCESS           Success.\r
+  @retval       EFI_INVALID_PARAMETER Handle is NULL or does not refer to a valid ACPI object.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetOption (\r
+  IN        EFI_ACPI_HANDLE     Handle,\r
+  IN        UINTN               Index,\r
+  OUT       EFI_ACPI_DATA_TYPE  *DataType,\r
+  OUT CONST VOID                **Data,\r
+  OUT       UINTN               *DataSize\r
+  );\r
+\r
+/**\r
+  Change information about an ACPI object.\r
+  \r
+  @param[in]  Handle    ACPI object handle.\r
+  @param[in]  Index     Index of the data to retrieve from the object. In general, indexes read from left-to-right\r
+                        in the ACPI encoding, with index 0 always being the ACPI opcode.\r
+  @param[in]  Data      Points to the data.\r
+  @param[in]  DataSize  The size of the Data.\r
+\r
+  @retval EFI_SUCCESS           Success\r
+  @retval EFI_INVALID_PARAMETER Handle is NULL or does not refer to a valid ACPI object.\r
+  @retval EFI_BAD_BUFFER_SIZE   Data cannot be accommodated in the space occupied by\r
+                                the option.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+SetOption (\r
+  IN        EFI_ACPI_HANDLE Handle,\r
+  IN        UINTN           Index,\r
+  IN CONST  VOID            *Data,\r
+  IN        UINTN           DataSize\r
+  );\r
+\r
+/**\r
+  Return the child ACPI objects.\r
+  \r
+  @param[in]        ParentHandle    Parent handle.\r
+  @param[in, out]   Handle          On entry, points to the previously returned handle or NULL to start with the first\r
+                                    handle. On return, points to the next returned ACPI handle or NULL if there are no\r
+                                    child objects.\r
+\r
+  @retval EFI_SUCCESS               Success\r
+  @retval EFI_INVALID_PARAMETER     ParentHandle is NULL or does not refer to a valid ACPI object.                                \r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+GetChild (\r
+  IN EFI_ACPI_HANDLE        ParentHandle,\r
+  IN OUT EFI_ACPI_HANDLE    *Handle\r
+  );\r
+\r
+/**\r
+  Returns the handle of the ACPI object representing the specified ACPI path\r
+  \r
+  @param[in]    HandleIn    Points to the handle of the object representing the starting point for the path search.\r
+  @param[in]    AcpiPath    Points to the ACPI path, which conforms to the ACPI encoded path format.\r
+  @param[out]   HandleOut   On return, points to the ACPI object which represents AcpiPath, relative to\r
+                            HandleIn.\r
+                            \r
+  @retval EFI_SUCCESS           Success\r
+  @retval EFI_INVALID_PARAMETER HandleIn is NULL or does not refer to a valid ACPI object.                            \r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+FindPath (\r
+  IN    EFI_ACPI_HANDLE HandleIn,\r
+  IN    VOID            *AcpiPath,\r
+  OUT   EFI_ACPI_HANDLE *HandleOut\r
+  );\r
+\r
+//\r
+// ACPI SDT function\r
+//\r
+\r
+/**\r
+  Create a handle from an ACPI opcode\r
+  \r
+  @param[in]  Buffer                 Points to the ACPI opcode.\r
+  @param[in]  BufferSize             Max buffer size.\r
+  @param[out] Handle                 Upon return, holds the handle.\r
+  \r
+  @retval   EFI_SUCCESS             Success\r
+  @retval   EFI_INVALID_PARAMETER   Buffer is NULL or Handle is NULL or Buffer points to an\r
+                                    invalid opcode.\r
+  \r
+**/\r
+EFI_STATUS\r
+SdtOpenEx (\r
+  IN    VOID            *Buffer,\r
+  IN    UINTN           BufferSize,\r
+  OUT   EFI_ACPI_HANDLE *Handle \r
+  );\r
+\r
+//\r
+// AML support function\r
+//\r
+\r
+/**\r
+  Get AML NameString size.\r
+\r
+  @param[in]    Buffer     AML NameString.\r
+  @param[out]   BufferSize AML NameString size \r
+  \r
+  @retval       EFI_SUCCESS           Success.\r
+  @retval       EFI_INVALID_PARAMETER Buffer does not refer to a valid AML NameString.\r
+**/\r
+EFI_STATUS\r
+AmlGetNameStringSize (\r
+  IN  UINT8              *Buffer,\r
+  OUT UINTN              *BufferSize\r
+  );\r
+\r
+/**\r
+  This function retuns package length from the buffer.\r
+\r
+  @param[in]  Buffer    AML buffer\r
+  @param[out] PkgLength The total length of package.\r
+\r
+  @return The byte data count to present the package length.\r
+**/\r
+UINTN\r
+AmlGetPkgLength (\r
+  IN UINT8              *Buffer,\r
+  OUT UINTN             *PkgLength\r
+  );\r
+\r
+/**\r
+  This function returns AcpiDataType according to AmlType.\r
+\r
+  @param[in]  AmlType        AML Type.\r
+\r
+  @return AcpiDataType\r
+**/\r
+EFI_ACPI_DATA_TYPE\r
+AmlTypeToAcpiType (\r
+  IN AML_OP_PARSE_FORMAT  AmlType\r
+  );\r
+\r
+/**\r
+  This function returns AmlByteEncoding according to OpCode Byte.\r
+\r
+  @param[in]  OpByteBuffer        OpCode byte buffer.\r
+\r
+  @return AmlByteEncoding\r
+**/\r
+AML_BYTE_ENCODING *\r
+AmlSearchByOpByte (\r
+  IN UINT8                *OpByteBuffer\r
+  );\r
+\r
+/**\r
+  Return object size.\r
+  \r
+  @param[in]    AmlByteEncoding      AML Byte Encoding.\r
+  @param[in]    Buffer               AML object buffer.\r
+  @param[in]    MaxBufferSize        AML object buffer MAX size. The parser can not parse any data exceed this region.\r
+  \r
+  @return       Size of the object.\r
+**/\r
+UINTN\r
+AmlGetObjectSize (\r
+  IN AML_BYTE_ENCODING   *AmlByteEncoding,\r
+  IN UINT8               *Buffer,\r
+  IN UINTN               MaxBufferSize\r
+  );\r
+\r
+/**\r
+  Return object name.\r
+  \r
+  @param[in]    AmlHandle            AML handle.\r
+  \r
+  @return       Name of the object.\r
+**/\r
+CHAR8 *\r
+AmlGetObjectName (\r
+  IN EFI_AML_HANDLE      *AmlHandle\r
+  );\r
+\r
+/**\r
+  Retrieve information according to AmlHandle\r
+  \r
+  @param[in]    AmlHandle            AML handle.\r
+  @param[in]    Index                Index of the data to retrieve from the object. In general, indexes read from left-to-right\r
+                                     in the ACPI encoding, with index 0 always being the ACPI opcode.\r
+  @param[out]   DataType             Points to the returned data type or EFI_ACPI_DATA_TYPE_NONE if no data exists\r
+                                     for the specified index.\r
+  @param[out]   Data                 Upon return, points to the pointer to the data.\r
+  @param[out]   DataSize             Upon return, points to the size of Data.\r
+  \r
+  @retval       EFI_SUCCESS           Success.\r
+  @retval       EFI_INVALID_PARAMETER AmlHandle does not refer to a valid ACPI object.\r
+**/\r
+EFI_STATUS\r
+AmlParseOptionHandleCommon (\r
+  IN EFI_AML_HANDLE      *AmlHandle,\r
+  IN AML_OP_PARSE_INDEX  Index,\r
+  OUT EFI_ACPI_DATA_TYPE *DataType,\r
+  OUT VOID               **Data,\r
+  OUT UINTN              *DataSize\r
+  );\r
+\r
+/**\r
+  Return offset of last option.\r
+  \r
+  @param[in]    AmlHandle            AML Handle.\r
+  @param[out]   Buffer               Upon return, points to the offset after last option.\r
+  \r
+  @retval       EFI_SUCCESS           Success.\r
+  @retval       EFI_INVALID_PARAMETER AmlHandle does not refer to a valid ACPI object.\r
+**/\r
+EFI_STATUS\r
+AmlGetOffsetAfterLastOption (\r
+  IN EFI_AML_HANDLE         *AmlHandle,\r
+  OUT UINT8                 **Buffer\r
+  );\r
+\r
+/**\r
+  Return the child ACPI objects from Root Handle.\r
+  \r
+  @param[in]        AmlParentHandle Parent handle. It is Root Handle.\r
+  @param[in]        AmlHandle       The previously returned handle or NULL to start with the first handle.\r
+  @param[out]       Buffer          On return, points to the next returned ACPI handle or NULL if there are no\r
+                                    child objects.\r
+\r
+  @retval EFI_SUCCESS               Success\r
+  @retval EFI_INVALID_PARAMETER     ParentHandle is NULL or does not refer to a valid ACPI object.                                \r
+**/\r
+EFI_STATUS\r
+AmlGetChildFromRoot (\r
+  IN EFI_AML_HANDLE         *AmlParentHandle,\r
+  IN EFI_AML_HANDLE         *AmlHandle,\r
+  OUT VOID                  **Buffer\r
+  );\r
+\r
+/**\r
+  Return the child ACPI objects from Non-Root Handle.\r
+  \r
+  @param[in]        AmlParentHandle Parent handle. It is Non-Root Handle.\r
+  @param[in]        AmlHandle       The previously returned handle or NULL to start with the first handle.\r
+  @param[out]       Buffer          On return, points to the next returned ACPI handle or NULL if there are no\r
+                                    child objects.\r
+\r
+  @retval EFI_SUCCESS               Success\r
+  @retval EFI_INVALID_PARAMETER     ParentHandle is NULL or does not refer to a valid ACPI object.                                \r
+**/\r
+EFI_STATUS\r
+AmlGetChildFromNonRoot (\r
+  IN EFI_AML_HANDLE         *AmlParentHandle,\r
+  IN EFI_AML_HANDLE         *AmlHandle,\r
+  OUT VOID                  **Buffer\r
+  );\r
+\r
+/**\r
+  Return AML name according to ASL name.\r
+  The caller need free the AmlName returned.\r
+\r
+  @param[in]    AslPath     ASL name.\r
+\r
+  @return AmlName\r
+**/\r
+UINT8 *\r
+AmlNameFromAslName (\r
+  IN UINT8 *AslPath\r
+  );\r
+\r
+/**\r
+  Returns the handle of the ACPI object representing the specified ACPI AML path\r
+  \r
+  @param[in]    AmlHandle   Points to the handle of the object representing the starting point for the path search.\r
+  @param[in]    AmlPath     Points to the ACPI AML path.\r
+  @param[out]   Buffer      On return, points to the ACPI object which represents AcpiPath, relative to\r
+                            HandleIn.\r
+  @param[in]    FromRoot    TRUE means to find AML path from \ (Root) Node.\r
+                            FALSE means to find AML path from this Node (The HandleIn).\r
+                            \r
+  @retval EFI_SUCCESS           Success\r
+  @retval EFI_INVALID_PARAMETER HandleIn does not refer to a valid ACPI object.                            \r
+**/\r
+EFI_STATUS\r
+AmlFindPath (\r
+  IN    EFI_AML_HANDLE  *AmlHandle,\r
+  IN    UINT8           *AmlPath,\r
+  OUT   VOID            **Buffer,\r
+  IN    BOOLEAN         FromRoot\r
+  );\r
+\r
+/**\r
+  Print AML NameString.\r
+\r
+  @param[in] Buffer AML NameString.\r
+**/\r
+VOID\r
+AmlPrintNameString (\r
+  IN UINT8              *Buffer\r
+  );\r
+\r
+/**\r
+  Print AML NameSeg.\r
+\r
+  @param[in] Buffer AML NameSeg.\r
+**/\r
+VOID\r
+AmlPrintNameSeg (\r
+  IN UINT8              *Buffer\r
+  );\r
+\r
+/**\r
+  Check if it is AML Root name\r
+\r
+  @param[in]    Buffer AML path.\r
+  \r
+  @retval       TRUE  AML path is root.\r
+  @retval       FALSE AML path is not root.\r
+**/\r
+BOOLEAN\r
+AmlIsRootPath (\r
+  IN UINT8              *Buffer\r
+  );\r
+\r
+#endif\r
index 42abacb836b25f4d2c2297e8ea4d71249a762969..696974e32534e5ae7d838238b036de4b85e3e39c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   ACPI Table Protocol Driver\r
 \r
-  Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -21,6 +21,7 @@
 // Handle to install ACPI Table Protocol\r
 //\r
 EFI_HANDLE    mHandle = NULL;\r
+GLOBAL_REMOVE_IF_UNREFERENCED EFI_ACPI_TABLE_INSTANCE   *mPrivateData;\r
 \r
 /**\r
   Entry point of the ACPI table driver.\r
@@ -64,12 +65,24 @@ InitializeAcpiTableDxe (
   //\r
   // Install ACPI Table protocol\r
   //\r
-  Status = gBS->InstallMultipleProtocolInterfaces (\r
-                  &mHandle,\r
-                  &gEfiAcpiTableProtocolGuid,\r
-                  &PrivateData->AcpiTableProtocol,\r
-                  NULL\r
-                  );\r
+  if (FeaturePcdGet (PcdInstallAcpiSdtProtocol)) {\r
+    mPrivateData = PrivateData;\r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+                    &mHandle,\r
+                    &gEfiAcpiTableProtocolGuid,\r
+                    &PrivateData->AcpiTableProtocol,\r
+                    &gEfiAcpiSdtProtocolGuid,\r
+                    &mPrivateData->AcpiSdtProtocol,\r
+                    NULL\r
+                    );\r
+  } else {\r
+    Status = gBS->InstallMultipleProtocolInterfaces (\r
+                    &mHandle,\r
+                    &gEfiAcpiTableProtocolGuid,\r
+                    &PrivateData->AcpiTableProtocol,\r
+                    NULL\r
+                    );\r
+  }\r
   ASSERT_EFI_ERROR (Status);\r
 \r
   return Status;\r
index cb5119e4f5197f9160151b449da8658708b7561b..d9e6428cba6b358eac9a6ff32ed59c44cd5f0562 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   ACPI Table Protocol Driver\r
 \r
-  Copyright (c) 2006 - 2009, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
   This program and the accompanying materials\r
   are licensed and made available under the terms and conditions of the BSD License\r
   which accompanies this distribution.  The full text of the license may be found at\r
@@ -20,6 +20,8 @@
 \r
 #include <Protocol/AcpiTable.h>\r
 #include <Guid/Acpi.h>\r
+#include <Protocol/AcpiSystemDescriptionTable.h>\r
+#include <Protocol/DxeSmmReadyToLock.h>\r
 \r
 #include <Library/BaseLib.h>\r
 #include <Library/DebugLib.h>\r
@@ -35,6 +37,8 @@
 //\r
 #include <IndustryStandard/Acpi.h>\r
 \r
+#include "AcpiSdt.h"\r
+\r
 //\r
 // From Protocol/AcpiSupport.h\r
 //\r
@@ -93,7 +97,7 @@ typedef struct {
 } EFI_ACPI_TABLE_LIST;\r
 \r
 //\r
-// Containment record for linked list.\r
+// Containment record for ACPI Table linked list.\r
 //\r
 #define EFI_ACPI_TABLE_LIST_FROM_LINK(_link)  CR (_link, EFI_ACPI_TABLE_LIST, Link, EFI_ACPI_TABLE_LIST_SIGNATURE)\r
 \r
@@ -135,13 +139,15 @@ typedef struct {
   EFI_ACPI_3_0_FIRMWARE_ACPI_CONTROL_STRUCTURE  *Facs3;                 // Pointer to FACS table header\r
   EFI_ACPI_DESCRIPTION_HEADER                   *Dsdt1;                 // Pointer to DSDT table header\r
   EFI_ACPI_DESCRIPTION_HEADER                   *Dsdt3;                 // Pointer to DSDT table header\r
-  LIST_ENTRY                                TableList;\r
+  LIST_ENTRY                                    TableList;\r
   UINTN                                         NumberOfTableEntries1;  // Number of ACPI 1.0 tables\r
   UINTN                                         NumberOfTableEntries3;  // Number of ACPI 3.0 tables\r
   UINTN                                         CurrentHandle;\r
   BOOLEAN                                       TablesInstalled1;       // ACPI 1.0 tables published\r
   BOOLEAN                                       TablesInstalled3;       // ACPI 3.0 tables published\r
   EFI_ACPI_TABLE_PROTOCOL                       AcpiTableProtocol;\r
+  EFI_ACPI_SDT_PROTOCOL                         AcpiSdtProtocol;\r
+  LIST_ENTRY                                    NotifyList;\r
 } EFI_ACPI_TABLE_INSTANCE;\r
 \r
 //\r
@@ -194,4 +200,73 @@ InitializeAcpiTableDxe (
   IN EFI_SYSTEM_TABLE     *SystemTable\r
   );\r
 \r
+/**\r
+\r
+  This function finds the table specified by the handle and returns a pointer to it.\r
+  If the handle is not found, EFI_NOT_FOUND is returned and the contents of Table are\r
+  undefined.\r
+\r
+  @param[in]  Handle      Table to find.\r
+  @param[in]  TableList   Table list to search\r
+  @param[out] Table       Pointer to table found. \r
+\r
+  @retval EFI_SUCCESS              The function completed successfully.\r
+  @retval EFI_NOT_FOUND            No table found matching the handle specified.\r
+\r
+**/\r
+EFI_STATUS\r
+FindTableByHandle (\r
+  IN UINTN                                Handle,\r
+  IN LIST_ENTRY                           *TableList,\r
+  OUT EFI_ACPI_TABLE_LIST                 **Table\r
+  );\r
+\r
+/**\r
+\r
+  This function calculates and updates an UINT8 checksum.\r
+\r
+  @param[in]  Buffer          Pointer to buffer to checksum\r
+  @param[in]  Size            Number of bytes to checksum\r
+  @param[in]  ChecksumOffset  Offset to place the checksum result in\r
+\r
+  @retval EFI_SUCCESS             The function completed successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+AcpiPlatformChecksum (\r
+  IN VOID       *Buffer,\r
+  IN UINTN      Size,\r
+  IN UINTN      ChecksumOffset\r
+  );\r
+\r
+/**\r
+  This function invokes ACPI notification.\r
+\r
+  @param[in]  AcpiTableInstance          Instance to AcpiTable\r
+  @param[in]  Version                    Version(s) to set.\r
+  @param[in]  Handle                     Handle of the table.\r
+**/\r
+VOID\r
+SdtNotifyAcpiList (\r
+  IN EFI_ACPI_TABLE_INSTANCE   *AcpiTableInstance,\r
+  IN EFI_ACPI_TABLE_VERSION    Version,\r
+  IN UINTN                     Handle\r
+  );\r
+\r
+/**\r
+  This function initializes AcpiSdt protocol in ACPI table instance.\r
+\r
+  @param[in]  AcpiTableInstance       Instance to construct\r
+**/\r
+VOID\r
+SdtAcpiTableAcpiSdtConstructor (\r
+  IN EFI_ACPI_TABLE_INSTANCE   *AcpiTableInstance\r
+  );\r
+\r
+//\r
+// export PrivateData symbol, because we need that in AcpiSdtProtol implementation\r
+//\r
+extern EFI_HANDLE                mHandle;\r
+extern EFI_ACPI_TABLE_INSTANCE   *mPrivateData;\r
+\r
 #endif\r
index ffc6c6ee10a985e77049fac66e3bd8090f5f567c..122a1ff76ef5f71512edf6be2bf402470002ad8a 100644 (file)
   AcpiTableProtocol.c\r
   AcpiTable.h\r
   AcpiTable.c\r
+  AcpiSdt.h\r
+  AcpiSdt.c\r
+  Aml.c\r
+  AmlString.c\r
+  AmlOption.c\r
+  AmlChild.c\r
+  AmlNamespace.c\r
 \r
 [Packages]\r
   MdePkg/MdePkg.dec\r
   gEfiAcpi10TableGuid                           # ALWAYS_CONSUMED\r
   gEfiAcpiTableGuid\r
 \r
+[FeaturePcd]\r
+  gEfiMdeModulePkgTokenSpaceGuid.PcdInstallAcpiSdtProtocol\r
+\r
 [Protocols]\r
   gEfiAcpiTableProtocolGuid                     # PROTOCOL ALWAYS_PRODUCED\r
+  gEfiAcpiSdtProtocolGuid                       # PROTOCOL ALWAYS_PRODUCED\r
+  gEfiDxeSmmReadyToLockProtocolGuid             # PROTOCOL ALWAYS_CONSUMED\r
 \r
 [Depex]\r
   TRUE\r
index 23117b1ded24847a05e792f56dfaf0b4fdd9c2e9..c551d0bd5d2e3ad752edf6b0ad75fb5a7f2aa493 100644 (file)
@@ -357,6 +357,19 @@ InstallAcpiTable (
   }\r
   FreePool (AcpiTableBufferConst);\r
   \r
+  //\r
+  // Add a new table successfully, notify registed callback\r
+  //\r
+  if (FeaturePcdGet (PcdInstallAcpiSdtProtocol)) {\r
+    if (!EFI_ERROR (Status)) {\r
+      SdtNotifyAcpiList (\r
+        AcpiTableInstance,\r
+        EFI_ACPI_TABLE_VERSION_1_0B | EFI_ACPI_TABLE_VERSION_2_0 | EFI_ACPI_TABLE_VERSION_3_0,\r
+        *TableKey\r
+        );\r
+    }\r
+  }\r
+\r
   return Status;\r
 }\r
 \r
@@ -1707,6 +1720,11 @@ AcpiTableAcpiTableConstructor (
 \r
   AcpiTableInstance->AcpiTableProtocol.InstallAcpiTable   = InstallAcpiTable;\r
   AcpiTableInstance->AcpiTableProtocol.UninstallAcpiTable = UninstallAcpiTable;\r
+\r
+  if (FeaturePcdGet (PcdInstallAcpiSdtProtocol)) {\r
+    SdtAcpiTableAcpiSdtConstructor (AcpiTableInstance);\r
+  }\r
+\r
   //\r
   // Create RSDP, RSDT, XSDT structures\r
   // Allocate all buffers\r
diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/Aml.c b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/Aml.c
new file mode 100644 (file)
index 0000000..bff81a8
--- /dev/null
@@ -0,0 +1,302 @@
+/** @file\r
+  ACPI Sdt Protocol Driver\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved. <BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "AcpiTable.h"\r
+\r
+GLOBAL_REMOVE_IF_UNREFERENCED\r
+AML_BYTE_ENCODING mAmlByteEncoding[] = {\r
+  //                             OpCode                      SubOpCode              Num 1           2           3           4           5           6           Attribute\r
+/* ZeroOp - 0x00 */              {AML_ZERO_OP,               0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* OneOp  - 0x01 */              {AML_ONE_OP,                0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* AliasOp - 0x06 */             {AML_ALIAS_OP,              0,                      2, AML_NAME,   AML_NAME,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IN_NAMESPACE},\r
+/* NameOp - 0x08 */              {AML_NAME_OP,               0,                      2, AML_NAME,   AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IN_NAMESPACE},\r
+/* BytePrefix - 0x0A */          {AML_BYTE_PREFIX,           0,                      1, AML_UINT8,  AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* WordPrefix - 0x0B */          {AML_WORD_PREFIX,           0,                      1, AML_UINT16, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* DWordPrefix - 0x0C */         {AML_DWORD_PREFIX,          0,                      1, AML_UINT32, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* StringPrefix - 0x0D */        {AML_STRING_PREFIX,         0,                      1, AML_STRING, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* QWordPrefix - 0x0E */         {AML_QWORD_PREFIX,          0,                      1, AML_UINT64, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* 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},\r
+/* BufferOp - 0x11 */            {AML_BUFFER_OP,             0,                      1, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_HAS_PKG_LENGTH},\r
+/* 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},\r
+/* 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},\r
+/* 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},\r
+/* DualNamePrefix - 0x2F */      {AML_DUAL_NAME_PREFIX,      0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* MultiNamePrefix - 0x2F */     {AML_MULTI_NAME_PREFIX,     0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x41 */            {'A',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x42 */            {'B',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x43 */            {'C',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x44 */            {'D',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x45 */            {'E',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x46 */            {'F',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x47 */            {'G',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x48 */            {'H',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x49 */            {'I',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x4A */            {'J',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x4B */            {'K',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x4C */            {'L',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x4D */            {'M',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x4E */            {'N',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x4F */            {'O',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x50 */            {'P',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x51 */            {'Q',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x52 */            {'R',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x53 */            {'S',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x54 */            {'T',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x55 */            {'U',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x56 */            {'V',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x57 */            {'W',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x58 */            {'X',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x59 */            {'Y',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x5A */            {'Z',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* 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},\r
+/* 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},\r
+/* 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},\r
+/* 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},\r
+/* 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},\r
+/* LoadOp - 0x5B 0x20 */         {AML_EXT_OP,                AML_EXT_LOAD_OP,        2, AML_NAME,   AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* StallOp - 0x5B 0x21 */        {AML_EXT_OP,                AML_EXT_STALL_OP,       1, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* SleepOp - 0x5B 0x22 */        {AML_EXT_OP,                AML_EXT_SLEEP_OP,       1, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* AcquireOp - 0x5B 0x23 */      {AML_EXT_OP,                AML_EXT_ACQUIRE_OP,     2, AML_OBJECT, AML_UINT16, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* SignalOp - 0x5B 0x24 */       {AML_EXT_OP,                AML_EXT_SIGNAL_OP,      1, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* WaitOp - 0x5B 0x25 */         {AML_EXT_OP,                AML_EXT_WAIT_OP,        2, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* ResetOp - 0x5B 0x26 */        {AML_EXT_OP,                AML_EXT_RESET_OP,       1, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* ReleaseOp - 0x5B 0x27 */      {AML_EXT_OP,                AML_EXT_RELEASE_OP,     1, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* 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},\r
+/* 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},\r
+/* UnloadOp - 0x5B 0x2A */       {AML_EXT_OP,                AML_EXT_UNLOAD_OP,      1, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* RevisionOp - 0x5B 0x30 */     {AML_EXT_OP,                AML_EXT_REVISION_OP,    0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* DebugOp - 0x5B 0x31 */        {AML_EXT_OP,                AML_EXT_DEBUG_OP,       0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* FatalOp - 0x5B 0x32 */        {AML_EXT_OP,                AML_EXT_FATAL_OP,       3, AML_UINT8,  AML_UINT32, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* TimerOp - 0x5B 0x33 */        {AML_EXT_OP,                AML_EXT_TIMER_OP,       0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* 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},\r
+/* 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},\r
+/* 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},\r
+/* 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},\r
+/* 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},\r
+/* 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},\r
+/* 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},\r
+/* 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},\r
+/* 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},\r
+/* RootChar - 0x5C */            {AML_ROOT_CHAR,             0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* ParentPrefixChar - 0x5E */    {AML_PARENT_PREFIX_CHAR,    0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* NameChar - 0x5F */            {'_',                       0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_IS_NAME_CHAR},\r
+/* Local0Op - 0x60 */            {AML_LOCAL0,                0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* Local1Op - 0x61 */            {AML_LOCAL1,                0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* Local2Op - 0x62 */            {AML_LOCAL2,                0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* Local3Op - 0x63 */            {AML_LOCAL3,                0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* Local4Op - 0x64 */            {AML_LOCAL4,                0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* Local5Op - 0x65 */            {AML_LOCAL5,                0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* Local6Op - 0x66 */            {AML_LOCAL6,                0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* Local7Op - 0x67 */            {AML_LOCAL7,                0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* Arg0Op - 0x68 */              {AML_ARG0,                  0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* Arg1Op - 0x69 */              {AML_ARG1,                  0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* Arg2Op - 0x6A */              {AML_ARG2,                  0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* Arg3Op - 0x6B */              {AML_ARG3,                  0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* Arg4Op - 0x6C */              {AML_ARG4,                  0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* Arg5Op - 0x6D */              {AML_ARG5,                  0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* Arg6Op - 0x6E */              {AML_ARG6,                  0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* StoreOp - 0x70 */             {AML_STORE_OP,              0,                      2, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* RefOfOp - 0x71 */             {AML_REF_OF_OP,             0,                      1, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* AddOp - 0x72 */               {AML_ADD_OP,                0,                      3, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* ConcatOp - 0x73 */            {AML_CONCAT_OP,             0,                      3, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* SubtractOp - 0x74 */          {AML_SUBTRACT_OP,           0,                      3, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* IncrementOp - 0x75 */         {AML_INCREMENT_OP,          0,                      1, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* DecrementOp - 0x76 */         {AML_DECREMENT_OP,          0,                      1, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* MultiplyOp - 0x77 */          {AML_MULTIPLY_OP,           0,                      3, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* DivideOp - 0x78 */            {AML_DIVIDE_OP,             0,                      4, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   0},\r
+/* ShiftLeftOp - 0x79 */         {AML_SHIFT_LEFT_OP,         0,                      3, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* ShiftRightOp - 0x7A */        {AML_SHIFT_RIGHT_OP,        0,                      3, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* AndOp - 0x7B */               {AML_AND_OP,                0,                      3, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* NAndOp - 0x7C */              {AML_NAND_OP,               0,                      3, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* OrOp - 0x7D */                {AML_OR_OP,                 0,                      3, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* NorOp - 0x7E */               {AML_NOR_OP,                0,                      3, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* XOrOp - 0x7F */               {AML_XOR_OP,                0,                      3, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* NotOp - 0x80 */               {AML_NOT_OP,                0,                      2, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* FindSetLeftBitOp - 0x81 */    {AML_FIND_SET_LEFT_BIT_OP,  0,                      2, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* FindSetRightBitOp - 0x82 */   {AML_FIND_SET_RIGHT_BIT_OP, 0,                      2, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* DerefOfOp - 0x83 */           {AML_DEREF_OF_OP,           0,                      1, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* ConcatResOp - 0x84 */         {AML_CONCAT_RES_OP,         0,                      3, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* ModOp - 0x85 */               {AML_MOD_OP,                0,                      3, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* NotifyOp - 0x86 */            {AML_NOTIFY_OP,             0,                      2, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* SizeOfOp - 0x87 */            {AML_SIZE_OF_OP,            0,                      1, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* IndexOp - 0x88 */             {AML_INDEX_OP,              0,                      3, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* MatchOp - 0x89 */             {AML_MATCH_OP,              0,                      6, AML_OBJECT, AML_UINT8,  AML_OBJECT, AML_UINT8,  AML_OBJECT, AML_OBJECT, 0},\r
+/* CreateDWordFieldOp - 0x8A */  {AML_CREATE_DWORD_FIELD_OP, 0,                      3, AML_OBJECT, AML_OBJECT, AML_NAME,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* CreateWordFieldOp - 0x8B */   {AML_CREATE_WORD_FIELD_OP,  0,                      3, AML_OBJECT, AML_OBJECT, AML_NAME,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* CreateByteFieldOp - 0x8C */   {AML_CREATE_BYTE_FIELD_OP,  0,                      3, AML_OBJECT, AML_OBJECT, AML_NAME,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* CreateBitFieldOp - 0x8D */    {AML_CREATE_BIT_FIELD_OP,   0,                      3, AML_OBJECT, AML_OBJECT, AML_NAME,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* ObjectTypeOp - 0x8E */        {AML_OBJECT_TYPE_OP,        0,                      1, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* CreateQWordFieldOp - 0x8F */  {AML_CREATE_QWORD_FIELD_OP, 0,                      3, AML_OBJECT, AML_OBJECT, AML_NAME,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* LAndOp - 0x90 */              {AML_LAND_OP,               0,                      2, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* LOrOp - 0x91 */               {AML_LOR_OP,                0,                      2, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* LNotOp - 0x92 */              {AML_LNOT_OP,               0,                      1, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* LEqualOp - 0x93 */            {AML_LEQUAL_OP,             0,                      2, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* LGreaterOp - 0x94 */          {AML_LGREATER_OP,           0,                      2, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* LLessOp - 0x95 */             {AML_LLESS_OP,              0,                      2, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* ToBufferOp - 0x96 */          {AML_TO_BUFFER_OP,          0,                      2, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* ToDecimalStringOp - 0x97 */   {AML_TO_DEC_STRING_OP,      0,                      2, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* ToHexStringOp - 0x98 */       {AML_TO_HEX_STRING_OP,      0,                      2, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* ToIntegerOp - 0x99 */         {AML_TO_INTEGER_OP,         0,                      2, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* ToStringOp - 0x9C */          {AML_TO_STRING_OP,          0,                      3, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* CopyObjectOp - 0x9D */        {AML_COPY_OBJECT_OP,        0,                      2, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* MidOp - 0x9E */               {AML_MID_OP,                0,                      3, AML_OBJECT, AML_OBJECT, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* ContinueOp - 0x9F */          {AML_CONTINUE_OP,           0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* 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},\r
+/* 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},\r
+/* 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},\r
+/* NoopOp - 0xA3 */              {AML_NOOP_OP,               0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* ReturnOp - 0xA4 */            {AML_RETURN_OP,             0,                      1, AML_OBJECT, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* BreakOp - 0xA5 */             {AML_BREAK_OP,              0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* BreakPointOp - 0xCC */        {AML_BREAK_POINT_OP,        0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+/* OnesOp - 0xFF */              {AML_ONES_OP,               0,                      0, AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   AML_NONE,   0},\r
+};\r
+\r
+GLOBAL_REMOVE_IF_UNREFERENCED\r
+EFI_ACPI_DATA_TYPE  mAmlTypeToAcpiType[] = {\r
+  EFI_ACPI_DATA_TYPE_NONE,             // AML_NONE\r
+  EFI_ACPI_DATA_TYPE_OPCODE,           // AML_OPCODE\r
+  EFI_ACPI_DATA_TYPE_UINT,             // AML_UINT8\r
+  EFI_ACPI_DATA_TYPE_UINT,             // AML_UINT16\r
+  EFI_ACPI_DATA_TYPE_UINT,             // AML_UINT32\r
+  EFI_ACPI_DATA_TYPE_UINT,             // AML_UINT64\r
+  EFI_ACPI_DATA_TYPE_NAME_STRING,      // AML_NAME\r
+  EFI_ACPI_DATA_TYPE_STRING,           // AML_STRING\r
+  EFI_ACPI_DATA_TYPE_CHILD             // AML_OBJECT\r
+};\r
+\r
+/**\r
+  This function returns AmlByteEncoding according to OpCode Byte.\r
+\r
+  @param[in]  OpByteBuffer        OpCode byte buffer.\r
+\r
+  @return AmlByteEncoding\r
+**/\r
+AML_BYTE_ENCODING *\r
+AmlSearchByOpByte (\r
+  IN UINT8                *OpByteBuffer\r
+  )\r
+{\r
+  UINT8       OpCode;\r
+  UINT8       SubOpCode;\r
+  UINTN       Index;\r
+\r
+  //\r
+  // Get OpCode and SubOpCode\r
+  //\r
+  OpCode = OpByteBuffer[0];\r
+  if (OpCode == AML_EXT_OP) {\r
+    SubOpCode = OpByteBuffer[1];\r
+  } else {\r
+    SubOpCode = 0;\r
+  }\r
+\r
+  //\r
+  // Search the table\r
+  //\r
+  for (Index = 0; Index < sizeof(mAmlByteEncoding)/sizeof(mAmlByteEncoding[0]); Index++) {\r
+    if ((mAmlByteEncoding[Index].OpCode == OpCode) && (mAmlByteEncoding[Index].SubOpCode == SubOpCode)) {\r
+      return &mAmlByteEncoding[Index];\r
+    }\r
+  }\r
+  \r
+  return NULL;\r
+}\r
+\r
+/**\r
+  This function returns AcpiDataType according to AmlType.\r
+\r
+  @param[in]  AmlType        AML Type.\r
+\r
+  @return AcpiDataType\r
+**/\r
+EFI_ACPI_DATA_TYPE\r
+AmlTypeToAcpiType (\r
+  IN AML_OP_PARSE_FORMAT  AmlType\r
+  )\r
+{\r
+  if (AmlType >= sizeof(mAmlTypeToAcpiType)/sizeof(mAmlTypeToAcpiType[0])) {\r
+    ASSERT(FALSE);\r
+    return EFI_ACPI_DATA_TYPE_NONE;\r
+  }\r
+  return mAmlTypeToAcpiType [AmlType];\r
+}\r
+\r
+/**\r
+  This function retuns package length from the buffer.\r
+\r
+  @param[in]  Buffer    AML buffer\r
+  @param[out] PkgLength The total length of package.\r
+\r
+  @return The byte data count to present the package length.\r
+**/\r
+UINTN\r
+AmlGetPkgLength (\r
+  IN UINT8              *Buffer,\r
+  OUT UINTN             *PkgLength\r
+  )\r
+{\r
+  UINT8             LeadByte;\r
+  UINT8             ByteCount;\r
+  UINTN             RealLength;\r
+  UINTN             Offset;\r
+  \r
+  //\r
+  // <bit 7-6: ByteData count that follows (0-3)>\r
+  // <bit 5-4: Only used if PkgLength < 63>\r
+  // <bit 3-0: Least significant package length nybble>\r
+  //\r
+  // Note: The high 2 bits of the first byte reveal how many follow bytes are in the\r
+  // If the PkgLength has only one byte, bit 0 through 5 are used to encode the\r
+  // package length (in other words, values 0-63). If the package length value is more than\r
+  // 63, more than one byte must be used for the encoding in which case bit 4 and 5 of the\r
+  // PkgLeadByte are reserved and must be zero. If the multiple bytes encoding is used,\r
+  // bits 0-3 of the PkgLeadByte become the least significant 4 bits of the resulting\r
+  // package length value. The next ByteData will become the next least significant 8 bits\r
+  // of the resulting value and so on, up to 3 ByteData bytes. Thus, the maximum package\r
+  // length is 2**28.\r
+  // \r
+  \r
+  LeadByte = *Buffer;\r
+  ByteCount = (UINT8)((LeadByte >> 6) & 0x03);\r
+  Offset = ByteCount + 1;\r
+  RealLength = 0;\r
+\r
+  switch (ByteCount) {\r
+  case 0:\r
+    RealLength = (UINT32)LeadByte;\r
+    break;\r
+  case 1:\r
+    RealLength = *(Buffer + 1);\r
+    RealLength = (RealLength << 4) | (LeadByte & 0xF);\r
+    break;\r
+  case 2:\r
+    RealLength = *(Buffer + 1);\r
+    RealLength |= (*(Buffer + 2)) << 8;\r
+    RealLength = (RealLength << 4) | (LeadByte & 0xF);\r
+    break;\r
+  case 3:\r
+    RealLength = *(Buffer + 1);\r
+    RealLength |= (*(Buffer + 2)) << 8;\r
+    RealLength |= (*(Buffer + 3)) << 16;\r
+    RealLength = (RealLength << 4) | (LeadByte & 0xF);\r
+    break;\r
+  default:\r
+    ASSERT (0);\r
+    break;\r
+  }\r
+  \r
+  *PkgLength = RealLength;\r
+  return Offset;\r
+}\r
+\r
diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlChild.c b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlChild.c
new file mode 100644 (file)
index 0000000..d663fea
--- /dev/null
@@ -0,0 +1,278 @@
+/** @file\r
+  ACPI Sdt Protocol Driver\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved. <BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "AcpiTable.h"\r
+\r
+/**\r
+  Return the child objects buffer from AML Handle's buffer.\r
+  \r
+  @param[in]        AmlParentHandle Parent handle.\r
+  @param[in]        CurrentBuffer   The current child buffer.\r
+  @param[out]       Buffer          On return, points to the next returned child buffer or NULL if there are no\r
+                                    child buffer.\r
+\r
+  @retval EFI_SUCCESS               Success\r
+  @retval EFI_INVALID_PARAMETER     AmlParentHandle does not refer to a valid ACPI object.                                \r
+**/\r
+EFI_STATUS\r
+AmlGetChildFromObjectBuffer (\r
+  IN EFI_AML_HANDLE         *AmlParentHandle,\r
+  IN UINT8                  *CurrentBuffer,\r
+  OUT VOID                  **Buffer\r
+  )\r
+{\r
+  AML_BYTE_ENCODING   *AmlByteEncoding;\r
+  UINTN               DataSize;\r
+\r
+  //\r
+  // Root is considered as SCOPE, which has TermList.\r
+  // We need return only Object in TermList.\r
+  //\r
+  while ((UINTN)CurrentBuffer < (UINTN)(AmlParentHandle->Buffer + AmlParentHandle->Size)) {\r
+    AmlByteEncoding = AmlSearchByOpByte (CurrentBuffer);\r
+    if (AmlByteEncoding == NULL) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    //\r
+    // NOTE: We need return everything, because user might need parse the returned object.\r
+    //\r
+    if ((AmlByteEncoding->Attribute & AML_IS_NAME_CHAR) == 0) {\r
+      *Buffer = CurrentBuffer;\r
+      return EFI_SUCCESS;\r
+    }\r
+\r
+    DataSize = AmlGetObjectSize (\r
+                 AmlByteEncoding,\r
+                 CurrentBuffer,\r
+                 (UINTN)AmlParentHandle->Buffer + AmlParentHandle->Size - (UINTN)CurrentBuffer\r
+                 );\r
+    if (DataSize == 0) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    CurrentBuffer += DataSize;\r
+  }\r
+\r
+  //\r
+  // No more\r
+  //\r
+  *Buffer = NULL;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Return the child ACPI objects from Root Handle.\r
+  \r
+  @param[in]        AmlParentHandle Parent handle. It is Root Handle.\r
+  @param[in]        AmlHandle       The previously returned handle or NULL to start with the first handle.\r
+  @param[out]       Buffer          On return, points to the next returned ACPI handle or NULL if there are no\r
+                                    child objects.\r
+\r
+  @retval EFI_SUCCESS               Success\r
+  @retval EFI_INVALID_PARAMETER     ParentHandle is NULL or does not refer to a valid ACPI object.                                \r
+**/\r
+EFI_STATUS\r
+AmlGetChildFromRoot (\r
+  IN EFI_AML_HANDLE         *AmlParentHandle,\r
+  IN EFI_AML_HANDLE         *AmlHandle,\r
+  OUT VOID                  **Buffer\r
+  )\r
+{\r
+  UINT8               *CurrentBuffer;\r
+\r
+  if (AmlHandle == NULL) {\r
+    //\r
+    // First One\r
+    //\r
+    CurrentBuffer = (VOID *)AmlParentHandle->Buffer;\r
+  } else {\r
+    CurrentBuffer = (VOID *)(AmlHandle->Buffer + AmlHandle->Size);\r
+  }\r
+\r
+  return AmlGetChildFromObjectBuffer (AmlParentHandle, CurrentBuffer, Buffer);\r
+}\r
+\r
+/**\r
+  Return the child objects buffer from AML Handle's option list.\r
+  \r
+  @param[in]        AmlParentHandle Parent handle.\r
+  @param[in]        AmlHandle       The current child handle.\r
+  @param[out]       Buffer          On return, points to the next returned child buffer or NULL if there are no\r
+                                    child buffer.\r
+\r
+  @retval EFI_SUCCESS               Success\r
+  @retval EFI_INVALID_PARAMETER     AmlParentHandle does not refer to a valid ACPI object.                                \r
+**/\r
+EFI_STATUS\r
+AmlGetChildFromOptionList (\r
+  IN EFI_AML_HANDLE         *AmlParentHandle,\r
+  IN EFI_AML_HANDLE         *AmlHandle,\r
+  OUT VOID                  **Buffer\r
+  )\r
+{\r
+  EFI_ACPI_DATA_TYPE  DataType;\r
+  VOID                *Data;\r
+  UINTN               DataSize;\r
+  AML_OP_PARSE_INDEX  Index;\r
+  EFI_STATUS          Status;\r
+  AML_OP_PARSE_INDEX  MaxTerm;\r
+\r
+  Index = AML_OP_PARSE_INDEX_GET_TERM1;\r
+  MaxTerm = AmlParentHandle->AmlByteEncoding->MaxIndex;\r
+  while (Index <= MaxTerm) {\r
+    Status = AmlParseOptionHandleCommon (\r
+               AmlParentHandle,\r
+               (AML_OP_PARSE_INDEX)Index,\r
+               &DataType,\r
+               (VOID **)&Data,\r
+               &DataSize\r
+               );\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    if (DataType == EFI_ACPI_DATA_TYPE_NONE) {\r
+      //\r
+      // Not found\r
+      //\r
+      break;\r
+    }\r
+\r
+    //\r
+    // Find it, and Check Data\r
+    //\r
+    if ((DataType == EFI_ACPI_DATA_TYPE_CHILD) &&\r
+        ((UINTN)AmlHandle->Buffer < (UINTN)Data)) {\r
+      //\r
+      // Buffer < Data means current node is next one\r
+      //\r
+      *Buffer = Data;\r
+      return EFI_SUCCESS;\r
+    }\r
+    //\r
+    // Not Child\r
+    //\r
+    Index ++;\r
+  }\r
+\r
+  *Buffer = NULL;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Return the child objects buffer from AML Handle's object child list.\r
+  \r
+  @param[in]        AmlParentHandle Parent handle.\r
+  @param[in]        AmlHandle       The current child handle.\r
+  @param[out]       Buffer          On return, points to the next returned child buffer or NULL if there are no\r
+                                    child buffer.\r
+\r
+  @retval EFI_SUCCESS               Success\r
+  @retval EFI_INVALID_PARAMETER     AmlParentHandle does not refer to a valid ACPI object.                                \r
+**/\r
+EFI_STATUS\r
+AmlGetChildFromObjectChildList (\r
+  IN EFI_AML_HANDLE         *AmlParentHandle,\r
+  IN EFI_AML_HANDLE         *AmlHandle,\r
+  OUT VOID                  **Buffer\r
+  )\r
+{\r
+  EFI_STATUS          Status;\r
+  UINT8               *CurrentBuffer;\r
+\r
+  if ((AmlParentHandle->AmlByteEncoding->Attribute & AML_HAS_CHILD_OBJ) == 0) {\r
+    //\r
+    // No ObjectList\r
+    //\r
+    *Buffer = NULL;\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // Do we need add node within METHOD?\r
+  // Yes, just add Object is OK. But we need filter NameString for METHOD invoke.\r
+  //\r
+\r
+  //\r
+  // Now, we get the last node.\r
+  //\r
+  Status = AmlGetOffsetAfterLastOption (AmlParentHandle, &CurrentBuffer);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Go through all the reset buffer.\r
+  //\r
+  if ((UINTN)AmlHandle->Buffer < (UINTN)CurrentBuffer) {\r
+    //\r
+    // Buffer < Data means next node is first object\r
+    //\r
+  } else if ((UINTN)AmlHandle->Buffer + AmlHandle->Size < (UINTN)AmlParentHandle->Buffer + AmlParentHandle->Size) {\r
+    //\r
+    // There is still more node\r
+    //\r
+    CurrentBuffer = AmlHandle->Buffer + AmlHandle->Size;\r
+  } else {\r
+    //\r
+    // No more data\r
+    //\r
+    *Buffer = NULL;\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  return AmlGetChildFromObjectBuffer (AmlParentHandle, CurrentBuffer, Buffer);\r
+}\r
+\r
+/**\r
+  Return the child ACPI objects from Non-Root Handle.\r
+  \r
+  @param[in]        AmlParentHandle Parent handle. It is Non-Root Handle.\r
+  @param[in]        AmlHandle       The previously returned handle or NULL to start with the first handle.\r
+  @param[out]       Buffer          On return, points to the next returned ACPI handle or NULL if there are no\r
+                                    child objects.\r
+\r
+  @retval EFI_SUCCESS               Success\r
+  @retval EFI_INVALID_PARAMETER     ParentHandle is NULL or does not refer to a valid ACPI object.                                \r
+**/\r
+EFI_STATUS\r
+AmlGetChildFromNonRoot (\r
+  IN EFI_AML_HANDLE         *AmlParentHandle,\r
+  IN EFI_AML_HANDLE         *AmlHandle,\r
+  OUT VOID                  **Buffer\r
+  )\r
+{\r
+  EFI_STATUS          Status;\r
+\r
+  if (AmlHandle == NULL) {\r
+    //\r
+    // NULL means first one\r
+    //\r
+    AmlHandle = AmlParentHandle;\r
+  }\r
+\r
+  //\r
+  // 1. Get Option\r
+  //\r
+  Status = AmlGetChildFromOptionList (AmlParentHandle, AmlHandle, Buffer);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  if (*Buffer != NULL) {\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // 2. search ObjectList\r
+  //\r
+  return AmlGetChildFromObjectChildList (AmlParentHandle, AmlHandle, Buffer);\r
+}\r
diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlNamespace.c b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlNamespace.c
new file mode 100644 (file)
index 0000000..b62256e
--- /dev/null
@@ -0,0 +1,612 @@
+/** @file\r
+  ACPI Sdt Protocol Driver\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved. <BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "AcpiTable.h"\r
+\r
+/**\r
+  Construct node list according to the AML handle.\r
+  \r
+  @param[in]    AmlHandle            AML handle.\r
+  @param[in]    AmlRootNodeList      AML root node list.\r
+  @param[in]    AmlParentNodeList    AML parent node list.\r
+  \r
+  @retval       EFI_SUCCESS           Success.\r
+  @retval       EFI_INVALID_PARAMETER AML handle does not refer to a valid ACPI object.\r
+**/\r
+EFI_STATUS\r
+AmlConstructNodeList (\r
+  IN EFI_AML_HANDLE      *AmlHandle,\r
+  IN EFI_AML_NODE_LIST   *AmlRootNodeList,\r
+  IN EFI_AML_NODE_LIST   *AmlParentNodeList\r
+  );\r
+\r
+/**\r
+  Create AML Node.\r
+  \r
+  @param[in]    NameSeg              AML NameSeg.\r
+  @param[in]    Parent               AML parent node list.\r
+  @param[in]    AmlByteEncoding      AML Byte Encoding.\r
+  \r
+  @return       AML Node.\r
+**/\r
+EFI_AML_NODE_LIST *\r
+AmlCreateNode (\r
+  IN UINT8              *NameSeg,\r
+  IN EFI_AML_NODE_LIST  *Parent,\r
+  IN AML_BYTE_ENCODING  *AmlByteEncoding\r
+  )\r
+{\r
+  EFI_AML_NODE_LIST      *AmlNodeList;\r
+\r
+  AmlNodeList = AllocatePool (sizeof(*AmlNodeList));\r
+  ASSERT (AmlNodeList != NULL);\r
+\r
+  AmlNodeList->Signature = EFI_AML_NODE_LIST_SIGNATURE;\r
+  CopyMem (AmlNodeList->Name, NameSeg, AML_NAME_SEG_SIZE);\r
+  AmlNodeList->Buffer    = NULL;\r
+  AmlNodeList->Size      = 0;\r
+  InitializeListHead (&AmlNodeList->Link);\r
+  InitializeListHead (&AmlNodeList->Children);\r
+  AmlNodeList->Parent = Parent;\r
+  AmlNodeList->AmlByteEncoding = AmlByteEncoding;\r
+\r
+  return AmlNodeList;\r
+}\r
+\r
+/**\r
+  Find the AML NameSeg in the children of AmlParentNodeList.\r
+  \r
+  @param[in]    NameSeg              AML NameSeg.\r
+  @param[in]    AmlParentNodeList    AML parent node list.\r
+  @param[in]    Create               TRUE means to create node if not found.\r
+  \r
+  @return       AmlChildNode whoes name is same as NameSeg.\r
+**/\r
+EFI_AML_NODE_LIST *\r
+AmlFindNodeInThis (\r
+  IN UINT8               *NameSeg,\r
+  IN EFI_AML_NODE_LIST   *AmlParentNodeList,\r
+  IN BOOLEAN             Create\r
+  )\r
+{\r
+  EFI_AML_NODE_LIST      *CurrentAmlNodeList;\r
+  LIST_ENTRY             *CurrentLink;\r
+  LIST_ENTRY             *StartLink;\r
+  EFI_AML_NODE_LIST      *AmlNodeList;\r
+\r
+  StartLink   = &AmlParentNodeList->Children;\r
+  CurrentLink = StartLink->ForwardLink;\r
+\r
+  while (CurrentLink != StartLink) {\r
+    CurrentAmlNodeList = EFI_AML_NODE_LIST_FROM_LINK (CurrentLink);\r
+    //\r
+    // AML name is same as the one stored\r
+    //\r
+    if (CompareMem (CurrentAmlNodeList->Name, NameSeg, AML_NAME_SEG_SIZE) == 0) {\r
+      //\r
+      // Good! Found it\r
+      //\r
+      return CurrentAmlNodeList;\r
+    }\r
+    CurrentLink = CurrentLink->ForwardLink;\r
+  }\r
+\r
+  //\r
+  // Not found\r
+  //\r
+  if (!Create) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Create new node with NULL buffer - it means namespace not be returned.\r
+  //\r
+  AmlNodeList = AmlCreateNode (NameSeg, AmlParentNodeList, NULL);\r
+  InsertTailList (&AmlParentNodeList->Children, &AmlNodeList->Link);\r
+\r
+  return AmlNodeList;\r
+}\r
+\r
+/**\r
+  Find the AML NameString in the children of AmlParentNodeList or AmlRootNodeList.\r
+  \r
+  @param[in]    NameString           AML NameString.\r
+  @param[in]    AmlRootNodeList      AML root node list.\r
+  @param[in]    AmlParentNodeList    AML parent node list.\r
+  @param[in]    Create               TRUE means to create node if not found.\r
+  \r
+  @return       AmlChildNode whoes name is same as NameSeg.\r
+**/\r
+EFI_AML_NODE_LIST *\r
+AmlFindNodeInTheTree (\r
+  IN UINT8               *NameString,\r
+  IN EFI_AML_NODE_LIST   *AmlRootNodeList,\r
+  IN EFI_AML_NODE_LIST   *AmlParentNodeList,\r
+  IN BOOLEAN             Create\r
+  )\r
+{\r
+  UINT8               *Buffer;\r
+  EFI_AML_NODE_LIST   *AmlNodeList;\r
+  EFI_AML_NODE_LIST   *AmlCurrentNodeList;\r
+  UINT8               Index;\r
+  UINT8               SegCount;\r
+\r
+  Buffer = NameString;\r
+\r
+  //\r
+  // Handle root or parent prefix\r
+  //\r
+  if (*Buffer == AML_ROOT_CHAR) {\r
+    AmlCurrentNodeList = AmlRootNodeList;\r
+    Buffer += 1;\r
+  } else if (*Buffer == AML_PARENT_PREFIX_CHAR) {\r
+    AmlCurrentNodeList = AmlParentNodeList;\r
+    do {\r
+      if (AmlCurrentNodeList->Parent != NULL) {\r
+        AmlCurrentNodeList = AmlCurrentNodeList->Parent;\r
+      } else {\r
+        //\r
+        // Only root has no parent\r
+        //\r
+        ASSERT (AmlCurrentNodeList == AmlRootNodeList);\r
+      }\r
+      Buffer += 1;\r
+    } while (*Buffer == AML_PARENT_PREFIX_CHAR);\r
+  } else {\r
+    AmlCurrentNodeList = AmlParentNodeList;\r
+  }\r
+  \r
+  //\r
+  // Handle name segment\r
+  //\r
+  if (*Buffer == AML_DUAL_NAME_PREFIX) {\r
+    Buffer += 1;\r
+    SegCount = 2;\r
+  } else if (*Buffer == AML_MULTI_NAME_PREFIX) {\r
+    Buffer += 1;\r
+    SegCount = *Buffer;\r
+    Buffer += 1;\r
+  } else if (*Buffer == 0) {\r
+    //\r
+    // NULL name, only for Root\r
+    //\r
+    ASSERT (AmlCurrentNodeList == AmlRootNodeList);\r
+    return AmlCurrentNodeList;\r
+  } else {\r
+    SegCount = 1;\r
+  }\r
+\r
+  //\r
+  // Handle NamePath\r
+  //\r
+  Index = 0;\r
+  do {\r
+    AmlNodeList = AmlFindNodeInThis (Buffer, AmlCurrentNodeList, Create);\r
+    if (AmlNodeList == NULL) {\r
+      return NULL;\r
+    }\r
+    AmlCurrentNodeList = AmlNodeList;\r
+    Buffer += AML_NAME_SEG_SIZE;\r
+    Index ++;\r
+  } while (Index < SegCount);\r
+\r
+  return AmlNodeList;\r
+}\r
+\r
+/**\r
+  Insert the NameString to the AmlNodeList.\r
+  \r
+  @param[in]    NameString           AML NameString.\r
+  @param[in]    Buffer               Buffer for the Node.\r
+  @param[in]    Size                 Size for the Node.\r
+  @param[in]    AmlRootNodeList      AML root node list.\r
+  @param[in]    AmlParentNodeList    AML parent node list.\r
+  \r
+  @return       AmlChildNode whoes name is NameString.\r
+**/\r
+EFI_AML_NODE_LIST *\r
+AmlInsertNodeToTree (\r
+  IN UINT8               *NameString,\r
+  IN VOID                *Buffer,\r
+  IN UINTN               Size,\r
+  IN EFI_AML_NODE_LIST   *AmlRootNodeList,\r
+  IN EFI_AML_NODE_LIST   *AmlParentNodeList\r
+  )\r
+{\r
+  EFI_AML_NODE_LIST   *AmlNodeList;\r
+\r
+  AmlNodeList = AmlFindNodeInTheTree (\r
+                  NameString,\r
+                  AmlRootNodeList,\r
+                  AmlParentNodeList,\r
+                  TRUE  // Find and Create\r
+                  );\r
+  ASSERT (AmlNodeList != NULL);\r
+  if (AmlNodeList == NULL) {\r
+    return NULL;\r
+  }\r
+\r
+  //\r
+  // Check buffer\r
+  //\r
+  if (AmlNodeList->Buffer == NULL) {\r
+    //\r
+    // NULL means new added one or SCOPE_OP\r
+    //\r
+    if (*(UINT8 *)Buffer != AML_SCOPE_OP) {\r
+      //\r
+      // We need check if new one is SCOPE_OP, because SCOPE_OP just means namespace, not a real device.\r
+      // We should not return SCOPE_OP.\r
+      //\r
+      AmlNodeList->Buffer = Buffer;\r
+      AmlNodeList->Size   = Size;\r
+      AmlNodeList->AmlByteEncoding = AmlSearchByOpByte (Buffer);\r
+    }\r
+    return AmlNodeList;\r
+  }\r
+\r
+  //\r
+  // Already added\r
+  //\r
+  if (*(UINT8 *)Buffer == AML_SCOPE_OP) {\r
+    //\r
+    // The new one is SCOPE_OP, OK just return;\r
+    //\r
+    return AmlNodeList;\r
+  }\r
+\r
+  //\r
+  // Oops!!!, There must be something wrong.\r
+  //\r
+  DEBUG ((EFI_D_ERROR, "AML: Override Happen - %a!\n", NameString));\r
+  DEBUG ((EFI_D_ERROR, "AML: Existing Node - %x\n", AmlNodeList->Buffer));\r
+  DEBUG ((EFI_D_ERROR, "AML: New Buffer - %x\n", Buffer));\r
+\r
+  return NULL;\r
+}\r
+\r
+/**\r
+  Construct child node list according to the AML handle.\r
+  \r
+  @param[in]    AmlHandle            AML handle.\r
+  @param[in]    AmlRootNodeList      AML root node list.\r
+  @param[in]    AmlParentNodeList    AML parent node list.\r
+  \r
+  @retval       EFI_SUCCESS           Success.\r
+  @retval       EFI_INVALID_PARAMETER AML handle does not refer to a valid ACPI object.\r
+**/\r
+EFI_STATUS\r
+AmlConstructNodeListForChild (\r
+  IN EFI_AML_HANDLE      *AmlHandle,\r
+  IN EFI_AML_NODE_LIST   *AmlRootNodeList,\r
+  IN EFI_AML_NODE_LIST   *AmlParentNodeList\r
+  )\r
+{\r
+  AML_BYTE_ENCODING   *AmlByteEncoding;\r
+  UINT8               *Buffer;\r
+  UINTN               BufferSize;\r
+  UINT8               *CurrentBuffer;\r
+  EFI_AML_HANDLE      *AmlChildHandle;\r
+  EFI_STATUS          Status;\r
+\r
+  AmlByteEncoding = AmlHandle->AmlByteEncoding;\r
+  Buffer          = AmlHandle->Buffer;\r
+  BufferSize      = AmlHandle->Size;\r
+\r
+  //\r
+  // Check if we need recursively add node\r
+  //\r
+  if ((AmlByteEncoding->Attribute & AML_HAS_CHILD_OBJ) == 0) {\r
+    //\r
+    // No more node need to be added\r
+    //\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // Do we need add node within METHOD?\r
+  // Yes, just add Object is OK. But we need filter NameString for METHOD invoke.\r
+  //\r
+\r
+  //\r
+  // Now, we get the last node.\r
+  //\r
+  Status = AmlGetOffsetAfterLastOption (AmlHandle, &CurrentBuffer);\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Go through all the reset buffer.\r
+  //\r
+  while ((UINTN)CurrentBuffer < (UINTN)Buffer + BufferSize) {\r
+    //\r
+    // Find the child node.\r
+    //\r
+    Status = SdtOpenEx (CurrentBuffer, (UINTN)Buffer + BufferSize - (UINTN)CurrentBuffer, (EFI_ACPI_HANDLE *)&AmlChildHandle);\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // No child found, break now.\r
+      //\r
+      break;\r
+    }\r
+\r
+    //\r
+    // Good, find the child. Construct node recursively\r
+    //\r
+    Status = AmlConstructNodeList (\r
+               AmlChildHandle,\r
+               AmlRootNodeList,\r
+               AmlParentNodeList\r
+               );\r
+    if (EFI_ERROR (Status)) {\r
+      break;\r
+    }\r
+\r
+    //\r
+    // Parse next one\r
+    //\r
+    CurrentBuffer += AmlChildHandle->Size;\r
+\r
+    Close ((EFI_ACPI_HANDLE)AmlChildHandle);\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Construct node list according to the AML handle.\r
+  \r
+  @param[in]    AmlHandle            AML handle.\r
+  @param[in]    AmlRootNodeList      AML root node list.\r
+  @param[in]    AmlParentNodeList    AML parent node list.\r
+  \r
+  @retval       EFI_SUCCESS           Success.\r
+  @retval       EFI_INVALID_PARAMETER AML handle does not refer to a valid ACPI object.\r
+**/\r
+EFI_STATUS\r
+AmlConstructNodeList (\r
+  IN EFI_AML_HANDLE      *AmlHandle,\r
+  IN EFI_AML_NODE_LIST   *AmlRootNodeList,\r
+  IN EFI_AML_NODE_LIST   *AmlParentNodeList\r
+  )\r
+{\r
+  VOID                *NameString;\r
+  EFI_AML_NODE_LIST   *AmlNodeList;\r
+\r
+  //\r
+  // 1. Check if there is need to construct node for this OpCode.\r
+  //\r
+  if ((AmlHandle->AmlByteEncoding->Attribute & AML_IN_NAMESPACE) == 0) {\r
+    //\r
+    // No need to construct node, so we just skip this OpCode.\r
+    //\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // 2. Now, we need construct node for this OpCode.\r
+  //\r
+  NameString = AmlGetObjectName (AmlHandle);\r
+  if (NameString == NULL) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // Now, we need to insert node to the node list.\r
+  // NOTE: The name here could be AML NameString. So the callee need parse it.\r
+  //\r
+  AmlNodeList = AmlInsertNodeToTree (NameString, AmlHandle->Buffer, AmlHandle->Size, AmlRootNodeList, AmlParentNodeList);\r
+  ASSERT (AmlNodeList != NULL);\r
+\r
+  //\r
+  // 3. Ok, we need to parse the object list to see if there are more node to be added.\r
+  //\r
+  return AmlConstructNodeListForChild (AmlHandle, AmlRootNodeList, AmlNodeList);\r
+}\r
+\r
+/**\r
+  Destruct node list\r
+  \r
+  @param[in]    AmlParentNodeList    AML parent node list.\r
+**/\r
+VOID\r
+AmlDestructNodeList (\r
+  IN EFI_AML_NODE_LIST *AmlParentNodeList\r
+  )\r
+{\r
+  EFI_AML_NODE_LIST      *CurrentAmlNodeList;\r
+  LIST_ENTRY             *CurrentLink;\r
+  LIST_ENTRY             *StartLink;\r
+\r
+  //\r
+  // Get the children link\r
+  //\r
+  StartLink   = &AmlParentNodeList->Children;\r
+  CurrentLink = StartLink->ForwardLink;\r
+\r
+  //\r
+  // Go through all the children\r
+  //\r
+  while (CurrentLink != StartLink) {\r
+    //\r
+    // Destruct the child's list recursively\r
+    //\r
+    CurrentAmlNodeList = EFI_AML_NODE_LIST_FROM_LINK (CurrentLink);\r
+    CurrentLink = CurrentLink->ForwardLink;\r
+\r
+    //\r
+    // Remove this child from list and free the node\r
+    //\r
+    RemoveEntryList (&(CurrentAmlNodeList->Link));\r
+\r
+    AmlDestructNodeList (CurrentAmlNodeList);\r
+  }\r
+\r
+  //\r
+  // Done.\r
+  //\r
+  FreePool (AmlParentNodeList);\r
+  return ;\r
+}\r
+\r
+/**\r
+  Dump node list\r
+  \r
+  @param[in]    AmlParentNodeList    AML parent node list.\r
+  @param[in]    Level                Output debug level.\r
+**/\r
+VOID\r
+AmlDumpNodeInfo (\r
+  IN EFI_AML_NODE_LIST *AmlParentNodeList,\r
+  IN UINTN             Level\r
+  )\r
+{\r
+  EFI_AML_NODE_LIST      *CurrentAmlNodeList;\r
+  volatile LIST_ENTRY    *CurrentLink;\r
+  UINTN                  Index;\r
+\r
+  CurrentLink = AmlParentNodeList->Children.ForwardLink;\r
+\r
+  if (Level == 0) {\r
+    DEBUG ((EFI_D_ERROR, "\\"));\r
+  } else {\r
+    for (Index = 0; Index < Level; Index++) {\r
+      DEBUG ((EFI_D_ERROR, "    "));\r
+    }\r
+    AmlPrintNameSeg (AmlParentNodeList->Name);\r
+  }\r
+  DEBUG ((EFI_D_ERROR, "\n"));\r
+\r
+  while (CurrentLink != &AmlParentNodeList->Children) {\r
+    CurrentAmlNodeList = EFI_AML_NODE_LIST_FROM_LINK (CurrentLink);\r
+    AmlDumpNodeInfo (CurrentAmlNodeList, Level + 1);\r
+    CurrentLink = CurrentLink->ForwardLink;\r
+  }\r
+\r
+  return ;\r
+}\r
+\r
+/**\r
+  Returns the handle of the ACPI object representing the specified ACPI AML path\r
+  \r
+  @param[in]    AmlHandle   Points to the handle of the object representing the starting point for the path search.\r
+  @param[in]    AmlPath     Points to the ACPI AML path.\r
+  @param[out]   Buffer      On return, points to the ACPI object which represents AcpiPath, relative to\r
+                            HandleIn.\r
+  @param[in]    FromRoot    TRUE means to find AML path from \ (Root) Node.\r
+                            FALSE means to find AML path from this Node (The HandleIn).\r
+                            \r
+  @retval EFI_SUCCESS           Success\r
+  @retval EFI_INVALID_PARAMETER HandleIn does not refer to a valid ACPI object.                            \r
+**/\r
+EFI_STATUS\r
+AmlFindPath (\r
+  IN    EFI_AML_HANDLE  *AmlHandle,\r
+  IN    UINT8           *AmlPath,\r
+  OUT   VOID            **Buffer,\r
+  IN    BOOLEAN         FromRoot\r
+  )\r
+{\r
+  EFI_AML_NODE_LIST   *AmlRootNodeList;\r
+  EFI_STATUS          Status;\r
+  EFI_AML_NODE_LIST   *AmlNodeList;\r
+  UINT8               RootNameSeg[AML_NAME_SEG_SIZE];\r
+  EFI_AML_NODE_LIST   *CurrentAmlNodeList;\r
+  LIST_ENTRY          *CurrentLink;\r
+\r
+  //\r
+  // 1. create tree\r
+  //\r
+\r
+  //\r
+  // Create root handle\r
+  //\r
+  RootNameSeg[0] = AML_ROOT_CHAR;\r
+  RootNameSeg[1] = 0;\r
+  AmlRootNodeList = AmlCreateNode (RootNameSeg, NULL, AmlHandle->AmlByteEncoding);\r
+\r
+  Status = AmlConstructNodeList (\r
+             AmlHandle,\r
+             AmlRootNodeList, // Root\r
+             AmlRootNodeList  // Parent\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  DEBUG_CODE_BEGIN ();\r
+  DEBUG ((EFI_D_ERROR, "AcpiSdt: NameSpace:\n"));\r
+  AmlDumpNodeInfo (AmlRootNodeList, 0);\r
+  DEBUG_CODE_END ();\r
+\r
+  //\r
+  // 2. Search the node in the tree\r
+  //\r
+  if (FromRoot) {\r
+    //\r
+    // Search from Root\r
+    //\r
+    CurrentAmlNodeList = AmlRootNodeList;\r
+  } else {\r
+    //\r
+    // Search from this node, NOT ROOT.\r
+    // Since we insert node to ROOT one by one, we just get the first node and search from it.\r
+    //\r
+    CurrentLink = AmlRootNodeList->Children.ForwardLink;\r
+    if (CurrentLink != &AmlRootNodeList->Children) {\r
+      //\r
+      // First node\r
+      //\r
+      CurrentAmlNodeList = EFI_AML_NODE_LIST_FROM_LINK (CurrentLink);\r
+    } else {\r
+      //\r
+      // No child\r
+      //\r
+      CurrentAmlNodeList = NULL;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Search\r
+  //\r
+  if (CurrentAmlNodeList != NULL) {\r
+    DEBUG_CODE_BEGIN ();\r
+    DEBUG ((EFI_D_ERROR, "AcpiSdt: Search from: \\"));\r
+    AmlPrintNameSeg (CurrentAmlNodeList->Name);\r
+    DEBUG ((EFI_D_ERROR, "\n"));\r
+    DEBUG_CODE_END ();\r
+    AmlNodeList = AmlFindNodeInTheTree (\r
+                    AmlPath,\r
+                    AmlRootNodeList,    // Root\r
+                    CurrentAmlNodeList, // Parent\r
+                    FALSE\r
+                    );\r
+  } else {\r
+    AmlNodeList = NULL;\r
+  }\r
+\r
+  *Buffer = NULL;\r
+  Status = EFI_SUCCESS;\r
+  if (AmlNodeList != NULL && AmlNodeList->Buffer != NULL) {\r
+    *Buffer = AmlNodeList->Buffer;\r
+  }\r
+\r
+  //\r
+  // 3. free the tree\r
+  //\r
+  AmlDestructNodeList (AmlRootNodeList);\r
+\r
+  return Status;\r
+}\r
diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlOption.c b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlOption.c
new file mode 100644 (file)
index 0000000..93bbe48
--- /dev/null
@@ -0,0 +1,452 @@
+/** @file\r
+  ACPI Sdt Protocol Driver\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved. <BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "AcpiTable.h"\r
+\r
+/**\r
+  Retrieve option term according to AmlByteEncoding and Buffer.\r
+  \r
+  @param[in]    AmlByteEncoding      AML Byte Encoding.\r
+  @param[in]    Buffer               AML buffer.\r
+  @param[in]    MaxBufferSize        AML buffer MAX size. The parser can not parse any data exceed this region.\r
+  @param[in]    TermIndex            Index of the data to retrieve from the object.\r
+  @param[out]   DataType             Points to the returned data type or EFI_ACPI_DATA_TYPE_NONE if no data exists\r
+                                     for the specified index.\r
+  @param[out]   Data                 Upon return, points to the pointer to the data.\r
+  @param[out]   DataSize             Upon return, points to the size of Data.\r
+  \r
+  @retval       EFI_SUCCESS           Success.\r
+  @retval       EFI_INVALID_PARAMETER Buffer does not refer to a valid ACPI object.\r
+**/\r
+EFI_STATUS\r
+AmlParseOptionTerm (\r
+  IN AML_BYTE_ENCODING   *AmlByteEncoding,\r
+  IN UINT8               *Buffer,\r
+  IN UINTN               MaxBufferSize,\r
+  IN AML_OP_PARSE_INDEX  TermIndex,\r
+  OUT EFI_ACPI_DATA_TYPE *DataType,\r
+  OUT VOID               **Data,\r
+  OUT UINTN              *DataSize\r
+  )\r
+{\r
+  AML_BYTE_ENCODING   *ChildAmlByteEncoding;\r
+  EFI_STATUS          Status;\r
+\r
+  if (DataType != NULL) {\r
+    *DataType = AmlTypeToAcpiType (AmlByteEncoding->Format[TermIndex - 1]);\r
+  }\r
+  if (Data != NULL) {\r
+    *Data = Buffer;\r
+  }\r
+  //\r
+  // Parse term according to AML type\r
+  //\r
+  switch (AmlByteEncoding->Format[TermIndex - 1]) {\r
+  case AML_UINT8:\r
+    *DataSize = sizeof(UINT8);\r
+    break;\r
+  case AML_UINT16:\r
+    *DataSize = sizeof(UINT16);\r
+    break;\r
+  case AML_UINT32:\r
+    *DataSize = sizeof(UINT32);\r
+    break;\r
+  case AML_UINT64:\r
+    *DataSize = sizeof(UINT64);\r
+    break;\r
+  case AML_STRING:\r
+    *DataSize = AsciiStrSize((CHAR8 *)Buffer);\r
+    break;\r
+  case AML_NAME:\r
+    Status = AmlGetNameStringSize (Buffer, DataSize);\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    break;\r
+  case AML_OBJECT:\r
+    ChildAmlByteEncoding = AmlSearchByOpByte (Buffer);\r
+    if (ChildAmlByteEncoding == NULL) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+    //\r
+    // NOTE: We need override DataType here, if there is a case the AML_OBJECT is AML_NAME.\r
+    // We need convert type from EFI_ACPI_DATA_TYPE_CHILD to EFI_ACPI_DATA_TYPE_NAME_STRING.\r
+    // We should not return CHILD because there is NO OpCode for NameString.\r
+    //\r
+    if ((ChildAmlByteEncoding->Attribute & AML_IS_NAME_CHAR) != 0) {\r
+      if (DataType != NULL) {\r
+        *DataType = AmlTypeToAcpiType (AML_NAME);\r
+      }\r
+      Status = AmlGetNameStringSize (Buffer, DataSize);\r
+      if (EFI_ERROR (Status)) {\r
+        return EFI_INVALID_PARAMETER;\r
+      }\r
+      break;\r
+    }\r
+\r
+    //\r
+    // It is real AML_OBJECT\r
+    //\r
+    *DataSize = AmlGetObjectSize (\r
+                     ChildAmlByteEncoding,\r
+                     Buffer,\r
+                     MaxBufferSize\r
+                     );\r
+    if (*DataSize == 0) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    break;\r
+  case AML_NONE:\r
+    //\r
+    // No term\r
+    //\r
+  case AML_OPCODE:\r
+  default:\r
+    ASSERT (FALSE);\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  if (*DataSize > MaxBufferSize) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Retrieve information according to AmlByteEncoding and Buffer.\r
+  \r
+  @param[in]    AmlByteEncoding      AML Byte Encoding.\r
+  @param[in]    Buffer               AML buffer.\r
+  @param[in]    MaxBufferSize        AML buffer MAX size. The parser can not parse any data exceed this region.\r
+  @param[in]    Index                Index of the data to retrieve from the object. In general, indexes read from left-to-right\r
+                                     in the ACPI encoding, with index 0 always being the ACPI opcode.\r
+  @param[out]   DataType             Points to the returned data type or EFI_ACPI_DATA_TYPE_NONE if no data exists\r
+                                     for the specified index.\r
+  @param[out]   Data                 Upon return, points to the pointer to the data.\r
+  @param[out]   DataSize             Upon return, points to the size of Data.\r
+  \r
+  @retval       EFI_SUCCESS           Success.\r
+  @retval       EFI_INVALID_PARAMETER Buffer does not refer to a valid ACPI object.\r
+**/\r
+EFI_STATUS\r
+AmlParseOptionCommon (\r
+  IN AML_BYTE_ENCODING   *AmlByteEncoding,\r
+  IN UINT8               *Buffer,\r
+  IN UINTN               MaxBufferSize,\r
+  IN AML_OP_PARSE_INDEX  Index,\r
+  OUT EFI_ACPI_DATA_TYPE *DataType,\r
+  OUT VOID               **Data,\r
+  OUT UINTN              *DataSize\r
+  )\r
+{\r
+  UINT8               *CurrentBuffer;\r
+  UINTN               PkgLength;\r
+  UINTN               OpLength;\r
+  UINTN               PkgOffset;\r
+  AML_OP_PARSE_INDEX  TermIndex;\r
+  EFI_STATUS          Status;\r
+\r
+  ASSERT ((Index <= AmlByteEncoding->MaxIndex) || (Index == AML_OP_PARSE_INDEX_GET_SIZE));\r
+\r
+  //\r
+  // 0. Check if this is NAME string.\r
+  //\r
+  if ((AmlByteEncoding->Attribute & AML_IS_NAME_CHAR) != 0) {\r
+    //\r
+    // Only allow GET_SIZE\r
+    //\r
+    if (Index != AML_OP_PARSE_INDEX_GET_SIZE) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    //\r
+    // return NameString size\r
+    //\r
+    Status = AmlGetNameStringSize (Buffer, DataSize);\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    if (*DataSize > MaxBufferSize) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    return EFI_SUCCESS;\r
+  }\r
+\r
+  //\r
+  // Not NAME string, start parsing\r
+  //\r
+  CurrentBuffer = Buffer;\r
+\r
+  //\r
+  // 1. Get OpCode\r
+  //\r
+  if (Index != AML_OP_PARSE_INDEX_GET_SIZE) {\r
+    *DataType = EFI_ACPI_DATA_TYPE_OPCODE;\r
+    *Data = (VOID *)CurrentBuffer;\r
+  }\r
+  if (*CurrentBuffer == AML_EXT_OP) {\r
+    OpLength = 2;\r
+  } else {\r
+    OpLength = 1;\r
+  }\r
+  *DataSize = OpLength;\r
+  if (Index == AML_OP_PARSE_INDEX_GET_OPCODE) {\r
+    return EFI_SUCCESS;\r
+  }\r
+  if (OpLength > MaxBufferSize) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  CurrentBuffer += OpLength;\r
+\r
+  //\r
+  // 2. Skip PkgLength field, if have\r
+  //\r
+  if ((AmlByteEncoding->Attribute & AML_HAS_PKG_LENGTH) != 0) {\r
+    PkgOffset = AmlGetPkgLength(CurrentBuffer, &PkgLength);\r
+    //\r
+    // Override MaxBufferSize if it is valid PkgLength\r
+    //\r
+    if (OpLength + PkgLength > MaxBufferSize) {\r
+      return EFI_INVALID_PARAMETER;\r
+    } else {\r
+      MaxBufferSize = OpLength + PkgLength;\r
+    }\r
+  } else {\r
+    PkgOffset = 0;\r
+    PkgLength = 0;\r
+  }\r
+  CurrentBuffer += PkgOffset;\r
+\r
+  //\r
+  // 3. Get Term one by one.\r
+  //\r
+  TermIndex = AML_OP_PARSE_INDEX_GET_TERM1;\r
+  while ((Index >= TermIndex) && (TermIndex <= AmlByteEncoding->MaxIndex) && ((UINTN)CurrentBuffer < (UINTN)Buffer + MaxBufferSize)) {\r
+    Status = AmlParseOptionTerm (\r
+               AmlByteEncoding,\r
+               CurrentBuffer,\r
+               (UINTN)Buffer + MaxBufferSize - (UINTN)CurrentBuffer,\r
+               TermIndex,\r
+               DataType,\r
+               Data,\r
+               DataSize\r
+               );\r
+    if (EFI_ERROR (Status)) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+\r
+    if (Index == TermIndex) {\r
+      //\r
+      // Done\r
+      //\r
+      return EFI_SUCCESS;\r
+    }\r
+\r
+    //\r
+    // Parse next one\r
+    //\r
+    CurrentBuffer += *DataSize;\r
+    TermIndex ++;\r
+  }\r
+\r
+  //\r
+  // Finish all options, but no option found.\r
+  //\r
+  if ((UINTN)CurrentBuffer > (UINTN)Buffer + MaxBufferSize) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+  if ((UINTN)CurrentBuffer == (UINTN)Buffer + MaxBufferSize) {\r
+    if (Index != AML_OP_PARSE_INDEX_GET_SIZE) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  }\r
+\r
+  //\r
+  // 4. Finish parsing all node, return size\r
+  //\r
+  ASSERT (Index == AML_OP_PARSE_INDEX_GET_SIZE);\r
+  if ((AmlByteEncoding->Attribute & AML_HAS_PKG_LENGTH) != 0) {\r
+    *DataSize = OpLength + PkgLength;\r
+  } else {\r
+    *DataSize = (UINTN)CurrentBuffer - (UINTN)Buffer;\r
+  }\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Return object size.\r
+  \r
+  @param[in]    AmlByteEncoding      AML Byte Encoding.\r
+  @param[in]    Buffer               AML object buffer.\r
+  @param[in]    MaxBufferSize        AML object buffer MAX size. The parser can not parse any data exceed this region.\r
+  \r
+  @return       Size of the object.\r
+**/\r
+UINTN\r
+AmlGetObjectSize (\r
+  IN AML_BYTE_ENCODING   *AmlByteEncoding,\r
+  IN UINT8               *Buffer,\r
+  IN UINTN               MaxBufferSize\r
+  )\r
+{\r
+  EFI_STATUS   Status;\r
+  UINTN        DataSize;\r
+\r
+  Status = AmlParseOptionCommon (\r
+               AmlByteEncoding,\r
+               Buffer,\r
+               MaxBufferSize,\r
+               AML_OP_PARSE_INDEX_GET_SIZE,\r
+               NULL,\r
+               NULL,\r
+               &DataSize\r
+               );\r
+  if (EFI_ERROR (Status)) {\r
+    return 0;\r
+  } else {\r
+    return DataSize;\r
+  }\r
+}\r
+\r
+/**\r
+  Return object name.\r
+  \r
+  @param[in]    AmlHandle            AML handle.\r
+  \r
+  @return       Name of the object.\r
+**/\r
+CHAR8 *\r
+AmlGetObjectName (\r
+  IN EFI_AML_HANDLE      *AmlHandle\r
+  )\r
+{\r
+  AML_BYTE_ENCODING   *AmlByteEncoding;\r
+  VOID                *NameString;\r
+  UINTN               NameSize;\r
+  AML_OP_PARSE_INDEX  TermIndex;\r
+  EFI_STATUS          Status;\r
+  EFI_ACPI_DATA_TYPE  DataType;\r
+\r
+  AmlByteEncoding = AmlHandle->AmlByteEncoding;\r
+\r
+  ASSERT ((AmlByteEncoding->Attribute & AML_IN_NAMESPACE) != 0);\r
+\r
+  //\r
+  // Find out Last Name index, accroding to OpCode table.\r
+  // The last name will be the node name by design.\r
+  //\r
+  TermIndex = AmlByteEncoding->MaxIndex;\r
+  for (TermIndex = AmlByteEncoding->MaxIndex; TermIndex > 0; TermIndex--) {\r
+    if (AmlByteEncoding->Format[TermIndex - 1] == AML_NAME) {\r
+      break;\r
+    }\r
+  }\r
+  ASSERT (TermIndex != 0);\r
+\r
+  //\r
+  // Get Name for this node.\r
+  //\r
+  Status = AmlParseOptionHandleCommon (\r
+             AmlHandle,\r
+             TermIndex,\r
+             &DataType,\r
+             &NameString,\r
+             &NameSize\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return NULL;\r
+  }\r
+  ASSERT (DataType == EFI_ACPI_DATA_TYPE_NAME_STRING);\r
+\r
+  return NameString;\r
+}\r
+\r
+/**\r
+  Return offset of last option.\r
+  \r
+  @param[in]    AmlHandle            AML Handle.\r
+  @param[out]   Buffer               Upon return, points to the offset after last option.\r
+  \r
+  @retval       EFI_SUCCESS           Success.\r
+  @retval       EFI_INVALID_PARAMETER AmlHandle does not refer to a valid ACPI object.\r
+**/\r
+EFI_STATUS\r
+AmlGetOffsetAfterLastOption (\r
+  IN EFI_AML_HANDLE         *AmlHandle,\r
+  OUT UINT8                 **Buffer\r
+  )\r
+{\r
+  EFI_ACPI_DATA_TYPE  DataType;\r
+  VOID                *Data;\r
+  UINTN               DataSize;\r
+  EFI_STATUS          Status;\r
+\r
+  Status = AmlParseOptionHandleCommon (\r
+             AmlHandle,\r
+             AmlHandle->AmlByteEncoding->MaxIndex,\r
+             &DataType,\r
+             &Data,\r
+             &DataSize\r
+             );\r
+  if (EFI_ERROR (Status)) {\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  //\r
+  // We need to parse the rest buffer after last node.\r
+  //\r
+  *Buffer = (UINT8 *)((UINTN)Data + DataSize);\r
+\r
+  //\r
+  // We need skip PkgLength if no Option\r
+  //\r
+  if (DataType == EFI_ACPI_DATA_TYPE_OPCODE) {\r
+    *Buffer += AmlGetPkgLength (*Buffer, &DataSize);\r
+  }\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Retrieve information according to AmlHandle\r
+  \r
+  @param[in]    AmlHandle            AML handle.\r
+  @param[in]    Index                Index of the data to retrieve from the object. In general, indexes read from left-to-right\r
+                                     in the ACPI encoding, with index 0 always being the ACPI opcode.\r
+  @param[out]   DataType             Points to the returned data type or EFI_ACPI_DATA_TYPE_NONE if no data exists\r
+                                     for the specified index.\r
+  @param[out]   Data                 Upon return, points to the pointer to the data.\r
+  @param[out]   DataSize             Upon return, points to the size of Data.\r
+  \r
+  @retval       EFI_SUCCESS           Success.\r
+  @retval       EFI_INVALID_PARAMETER AmlHandle does not refer to a valid ACPI object.\r
+**/\r
+EFI_STATUS\r
+AmlParseOptionHandleCommon (\r
+  IN EFI_AML_HANDLE      *AmlHandle,\r
+  IN AML_OP_PARSE_INDEX  Index,\r
+  OUT EFI_ACPI_DATA_TYPE *DataType,\r
+  OUT VOID               **Data,\r
+  OUT UINTN              *DataSize\r
+  )\r
+{\r
+  return AmlParseOptionCommon (\r
+           AmlHandle->AmlByteEncoding,\r
+           AmlHandle->Buffer,\r
+           AmlHandle->Size,\r
+           Index,\r
+           DataType,\r
+           Data,\r
+           DataSize\r
+           );\r
+}\r
diff --git a/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlString.c b/MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlString.c
new file mode 100644 (file)
index 0000000..fe2c761
--- /dev/null
@@ -0,0 +1,549 @@
+/** @file\r
+  ACPI Sdt Protocol Driver\r
+\r
+  Copyright (c) 2010, Intel Corporation. All rights reserved. <BR>\r
+  This program and the accompanying materials\r
+  are licensed and made available under the terms and conditions of the BSD License\r
+  which accompanies this distribution.  The full text of the license may be found at\r
+  http://opensource.org/licenses/bsd-license.php\r
+\r
+  THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+  WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include "AcpiTable.h"\r
+\r
+/**\r
+  Check if it is AML Root name\r
+\r
+  @param[in]    Buffer AML path.\r
+  \r
+  @retval       TRUE  AML path is root.\r
+  @retval       FALSE AML path is not root.\r
+**/\r
+BOOLEAN\r
+AmlIsRootPath (\r
+  IN UINT8              *Buffer\r
+  )\r
+{\r
+  if ((Buffer[0] == AML_ROOT_CHAR) && (Buffer[1] == 0)) {\r
+    return TRUE;\r
+  } else {\r
+    return FALSE;\r
+  }\r
+}\r
+\r
+/**\r
+  Check if it is AML LeadName.\r
+\r
+  @param[in]    Ch   Char.\r
+  \r
+  @retval       TRUE  Char is AML LeadName.\r
+  @retval       FALSE Char is not AML LeadName.\r
+**/\r
+BOOLEAN\r
+AmlIsLeadName (\r
+  IN CHAR8 Ch\r
+  )\r
+{\r
+  if ((Ch == '_') || (Ch >= 'A' && Ch <= 'Z')) {\r
+    return TRUE;\r
+  } else {\r
+    return FALSE;\r
+  }\r
+}\r
+\r
+/**\r
+  Check if it is AML Name.\r
+\r
+  @param[in]    Ch   Char.\r
+  \r
+  @retval       TRUE  Char is AML Name.\r
+  @retval       FALSE Char is not AML Name.\r
+**/\r
+BOOLEAN\r
+AmlIsName (\r
+  IN CHAR8 Ch\r
+  )\r
+{\r
+  if (AmlIsLeadName (Ch) || (Ch >= '0' && Ch <= '9')) {\r
+    return TRUE;\r
+  } else {\r
+    return FALSE;\r
+  }\r
+}\r
+\r
+/**\r
+  Return is buffer is AML NameSeg.\r
+\r
+  @param[in]    Buffer     AML NameSement.\r
+  \r
+  @retval       TRUE       It is AML NameSegment.\r
+  @retval       FALSE      It is not AML NameSegment.\r
+**/\r
+BOOLEAN\r
+AmlIsNameSeg (\r
+  IN  UINT8              *Buffer\r
+  )\r
+{\r
+  UINTN  Index;\r
+  if (!AmlIsLeadName (Buffer[0])) {\r
+    return FALSE;\r
+  }\r
+  for (Index = 1; Index < AML_NAME_SEG_SIZE; Index++) {\r
+    if (!AmlIsName (Buffer[Index])) {\r
+      return FALSE;\r
+    }\r
+  }\r
+  return TRUE;\r
+}\r
+\r
+/**\r
+  Get AML NameString size.\r
+\r
+  @param[in]    Buffer     AML NameString.\r
+  @param[out]   BufferSize AML NameString size \r
+  \r
+  @retval       EFI_SUCCESS           Success.\r
+  @retval       EFI_INVALID_PARAMETER Buffer does not refer to a valid AML NameString.\r
+**/\r
+EFI_STATUS\r
+AmlGetNameStringSize (\r
+  IN  UINT8              *Buffer,\r
+  OUT UINTN              *BufferSize\r
+  )\r
+{\r
+  UINTN                 SegCount;\r
+  UINTN                 Length;\r
+  UINTN                 Index;\r
+  UINT8                 *Name;\r
+\r
+  Name = Buffer;\r
+  Length = 0;\r
+\r
+  //\r
+  // Parse root or parent prefix\r
+  //\r
+  if (*Buffer == AML_ROOT_CHAR) {\r
+    Buffer ++;\r
+    Length ++;\r
+  } else if (*Buffer == AML_PARENT_PREFIX_CHAR) {\r
+    do {\r
+      Buffer ++;\r
+      Length ++;\r
+    } while (*Buffer == AML_PARENT_PREFIX_CHAR);\r
+  }\r
+\r
+  //\r
+  // Parse name segment\r
+  //\r
+  if (*Buffer == AML_DUAL_NAME_PREFIX) {\r
+    Buffer ++;\r
+    Length ++;\r
+    SegCount = 2;\r
+  } else if (*Buffer == AML_MULTI_NAME_PREFIX) {\r
+    Buffer ++;\r
+    Length ++;\r
+    SegCount = *Buffer;\r
+    Buffer ++;\r
+    Length ++;\r
+  } else if (*Buffer == 0) {\r
+    //\r
+    // NULL Name, only for Root\r
+    //\r
+    SegCount = 0;\r
+    Buffer --;\r
+    if ((Length == 1) && (*Buffer == AML_ROOT_CHAR)) {\r
+      *BufferSize = 2;\r
+      return EFI_SUCCESS;\r
+    } else {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+  } else {\r
+    //\r
+    // NameSeg\r
+    //\r
+    SegCount = 1;\r
+  }\r
+\r
+  Index = 0;\r
+  do {\r
+    if (!AmlIsNameSeg (Buffer)) {\r
+      return EFI_INVALID_PARAMETER;\r
+    }\r
+    Buffer += AML_NAME_SEG_SIZE;\r
+    Length += AML_NAME_SEG_SIZE;\r
+    Index ++;\r
+  } while (Index < SegCount);\r
+\r
+  *BufferSize = Length;\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  Check if it is ASL LeadName.\r
+\r
+  @param[in]    Ch   Char.\r
+  \r
+  @retval       TRUE  Char is ASL LeadName.\r
+  @retval       FALSE Char is not ASL LeadName.\r
+**/\r
+BOOLEAN\r
+AmlIsAslLeadName (\r
+  IN CHAR8 Ch\r
+  )\r
+{\r
+  if (AmlIsLeadName (Ch) || (Ch >= 'a' && Ch <= 'z')) {\r
+    return TRUE;\r
+  } else {\r
+    return FALSE;\r
+  }\r
+}\r
+\r
+/**\r
+  Check if it is ASL Name.\r
+\r
+  @param[in]    Ch   Char.\r
+  \r
+  @retval       TRUE  Char is ASL Name.\r
+  @retval       FALSE Char is not ASL Name.\r
+**/\r
+BOOLEAN\r
+AmlIsAslName (\r
+  IN CHAR8 Ch\r
+  )\r
+{\r
+  if (AmlIsAslLeadName (Ch) || (Ch >= '0' && Ch <= '9')) {\r
+    return TRUE;\r
+  } else {\r
+    return FALSE;\r
+  }\r
+}\r
+\r
+/**\r
+  Get ASL NameString size.\r
+\r
+  @param[in]    Buffer   ASL NameString.\r
+  \r
+  @return       ASL NameString size.\r
+**/\r
+UINTN\r
+AmlGetAslNameSegLength (\r
+  IN UINT8 *Buffer\r
+  )\r
+{\r
+  UINTN Length;\r
+  UINTN Index;\r
+\r
+  if (*Buffer == 0) {\r
+    return 0;\r
+  }\r
+  \r
+  Length = 0;\r
+  //\r
+  // 1st\r
+  //\r
+  if (AmlIsAslLeadName (*Buffer)) {\r
+    Length ++;\r
+    Buffer ++;\r
+  }\r
+  if ((*Buffer == 0) || (*Buffer == '.')) {\r
+    return Length;\r
+  }\r
+  //\r
+  // 2, 3, 4 name char\r
+  //\r
+  for (Index = 0; Index < 3; Index++) {\r
+    if (AmlIsAslName (*Buffer)) {\r
+      Length ++;\r
+      Buffer ++;\r
+    }\r
+    if ((*Buffer == 0) || (*Buffer == '.')) {\r
+      return Length;\r
+    }\r
+  }\r
+\r
+  //\r
+  // Invalid ASL name\r
+  //\r
+  return 0;\r
+}\r
+\r
+/**\r
+  Get ASL NameString size.\r
+\r
+  @param[in]    Buffer   ASL NameString.\r
+  @param[out]   Root     On return, points to Root char number.\r
+  @param[out]   Parent   On return, points to Parent char number.\r
+  @param[out]   SegCount On return, points to Segment count.\r
+  \r
+  @return       ASL NameString size.\r
+**/\r
+UINTN\r
+AmlGetAslNameStringSize (\r
+  IN UINT8              *Buffer,\r
+  OUT UINTN             *Root,\r
+  OUT UINTN             *Parent,\r
+  OUT UINTN             *SegCount\r
+  )\r
+{\r
+  UINTN NameLength;\r
+  UINTN TotalLength;\r
+\r
+  *Root   = 0;\r
+  *Parent = 0;\r
+  *SegCount = 0;\r
+  TotalLength = 0;\r
+  NameLength = 0;\r
+  if (*Buffer == AML_ROOT_CHAR) {\r
+    *Root = 1;\r
+    Buffer ++;\r
+  } else if (*Buffer == AML_PARENT_PREFIX_CHAR) {\r
+    do {\r
+      Buffer ++;\r
+      (*Parent) ++;\r
+    } while (*Buffer == AML_PARENT_PREFIX_CHAR);\r
+  }\r
+\r
+  //\r
+  // Now parse name\r
+  //\r
+  while (*Buffer != 0) {\r
+    NameLength = AmlGetAslNameSegLength (Buffer);\r
+    if ((NameLength == 0) || (NameLength > AML_NAME_SEG_SIZE)) {\r
+      return 0;\r
+    }\r
+    (*SegCount) ++;\r
+    Buffer += NameLength;\r
+    if (*Buffer == 0) {\r
+      break;\r
+    }\r
+    Buffer ++;\r
+  }\r
+\r
+  //\r
+  // Check SegCoount\r
+  //\r
+  if (*SegCount > 0xFF) {\r
+    return 0;\r
+  }\r
+\r
+  //\r
+  // Calculate total length\r
+  //\r
+  TotalLength = *Root + *Parent + (*SegCount) * AML_NAME_SEG_SIZE;\r
+  if (*SegCount > 2) {\r
+    TotalLength += 2;\r
+  } else if (*SegCount == 2) {\r
+    TotalLength += 1;\r
+  }\r
+\r
+  //\r
+  // Add NULL char\r
+  //\r
+  TotalLength ++;\r
+\r
+  return TotalLength;\r
+}\r
+\r
+/**\r
+  Copy mem, and cast all the char in dest to be upper case.\r
+\r
+  @param[in]    DstBuffer   Destination buffer.\r
+  @param[in]    SrcBuffer   Source buffer.\r
+  @param[in]    Length      Buffer length.\r
+**/\r
+VOID\r
+AmlUpperCaseCopyMem (\r
+  IN UINT8 *DstBuffer,\r
+  IN UINT8 *SrcBuffer,\r
+  IN UINTN Length\r
+  )\r
+{\r
+  UINTN Index;\r
+\r
+  for (Index = 0; Index < Length; Index++) {\r
+    if (SrcBuffer[Index] >= 'a' && SrcBuffer[Index] <= 'z') {\r
+      DstBuffer[Index] = (UINT8)(SrcBuffer[Index] - 'a' + 'A');\r
+    } else {\r
+      DstBuffer[Index] = SrcBuffer[Index];\r
+    }\r
+  }\r
+}\r
+\r
+/**\r
+  Return AML name according to ASL name.\r
+  The caller need free the AmlName returned.\r
+\r
+  @param[in]    AslPath     ASL name.\r
+\r
+  @return AmlName\r
+**/\r
+UINT8 *\r
+AmlNameFromAslName (\r
+  IN UINT8 *AslPath\r
+  )\r
+{\r
+  UINTN Root;\r
+  UINTN Parent;\r
+  UINTN SegCount;\r
+  UINTN TotalLength;\r
+  UINTN NameLength;\r
+  UINT8 *Buffer;\r
+  UINT8 *AmlPath;\r
+  UINT8 *AmlBuffer;\r
+\r
+  TotalLength = AmlGetAslNameStringSize (AslPath, &Root, &Parent, &SegCount);\r
+  if (TotalLength == 0) {\r
+    return NULL;\r
+  }\r
+\r
+  AmlPath = AllocatePool (TotalLength);\r
+  ASSERT (AmlPath != NULL);\r
+\r
+  AmlBuffer = AmlPath;\r
+  Buffer = AslPath;\r
+\r
+  //\r
+  // Handle Root and Parent\r
+  //\r
+  if (Root == 1) {\r
+    *AmlBuffer = AML_ROOT_CHAR;\r
+    AmlBuffer ++;\r
+    Buffer ++;\r
+  } else if (Parent > 0) {\r
+    SetMem (AmlBuffer, Parent, AML_PARENT_PREFIX_CHAR);\r
+    AmlBuffer += Parent;\r
+    Buffer += Parent;\r
+  }\r
+\r
+  //\r
+  // Handle SegCount\r
+  //\r
+  if (SegCount > 2) {\r
+    *AmlBuffer = AML_MULTI_NAME_PREFIX;\r
+    AmlBuffer ++;\r
+    *AmlBuffer = (UINT8)SegCount;\r
+    AmlBuffer ++;\r
+  } else if (SegCount == 2) {\r
+    *AmlBuffer = AML_DUAL_NAME_PREFIX;\r
+    AmlBuffer ++;\r
+  }\r
+\r
+  //\r
+  // Now to name\r
+  //\r
+  while (*Buffer != 0) {\r
+    NameLength = AmlGetAslNameSegLength (Buffer);\r
+    ASSERT ((NameLength != 0) && (NameLength <= AML_NAME_SEG_SIZE));\r
+    AmlUpperCaseCopyMem (AmlBuffer, Buffer, NameLength);\r
+    SetMem (AmlBuffer + NameLength, AML_NAME_SEG_SIZE - NameLength, AML_NAME_CHAR__);\r
+    Buffer += NameLength;\r
+    AmlBuffer += AML_NAME_SEG_SIZE;\r
+    if (*Buffer == 0) {\r
+      break;\r
+    }\r
+    Buffer ++;\r
+  }\r
+\r
+  //\r
+  // Add NULL\r
+  //\r
+  AmlPath[TotalLength - 1] = 0;\r
+\r
+  return AmlPath;\r
+}\r
+\r
+/**\r
+  Print AML NameSeg.\r
+\r
+  @param[in] Buffer AML NameSeg.\r
+**/\r
+VOID\r
+AmlPrintNameSeg (\r
+  IN UINT8              *Buffer\r
+  )\r
+{\r
+  DEBUG ((EFI_D_ERROR, "%c", Buffer[0]));\r
+  if ((Buffer[1] == '_') && (Buffer[2] == '_') && (Buffer[3] == '_')) {\r
+    return ;\r
+  }\r
+  DEBUG ((EFI_D_ERROR, "%c", Buffer[1]));\r
+  if ((Buffer[2] == '_') && (Buffer[3] == '_')) {\r
+    return ;\r
+  }\r
+  DEBUG ((EFI_D_ERROR, "%c", Buffer[2]));\r
+  if (Buffer[3] == '_') {\r
+    return ;\r
+  }\r
+  DEBUG ((EFI_D_ERROR, "%c", Buffer[3]));\r
+  return ;\r
+}\r
+\r
+/**\r
+  Print AML NameString.\r
+\r
+  @param[in] Buffer AML NameString.\r
+**/\r
+VOID\r
+AmlPrintNameString (\r
+  IN UINT8              *Buffer\r
+  )\r
+{\r
+  UINT8                 SegCount;\r
+  UINT8                 Index;\r
+  UINT8                 *Name;\r
\r
+  Name = Buffer;\r
+  if (*Buffer == AML_ROOT_CHAR) {\r
+    //\r
+    // RootChar\r
+    //\r
+    Buffer ++;\r
+    DEBUG ((EFI_D_ERROR, "\\"));\r
+  } else if (*Buffer == AML_PARENT_PREFIX_CHAR) {\r
+    //\r
+    // ParentPrefixChar\r
+    //\r
+    do {\r
+      Buffer ++;\r
+      DEBUG ((EFI_D_ERROR, "^"));\r
+    } while (*Buffer == AML_PARENT_PREFIX_CHAR);\r
+  }\r
+\r
+  if (*Buffer == AML_DUAL_NAME_PREFIX) {\r
+    //\r
+    // DualName\r
+    //\r
+    Buffer ++;\r
+    SegCount = 2;\r
+  } else if (*Buffer == AML_MULTI_NAME_PREFIX) {\r
+    //\r
+    // MultiName\r
+    //\r
+    Buffer ++;\r
+    SegCount = *Buffer;\r
+    Buffer ++;\r
+  } else if (*Buffer == 0) {\r
+    //\r
+    // NULL Name\r
+    //\r
+    return ;\r
+  } else {\r
+    //\r
+    // NameSeg\r
+    //\r
+    SegCount = 1;\r
+  }\r
+  \r
+  AmlPrintNameSeg (Buffer);\r
+  Buffer += AML_NAME_SEG_SIZE;\r
+  for (Index = 0; Index < SegCount - 1; Index++) {\r
+    DEBUG ((EFI_D_ERROR, "."));\r
+    AmlPrintNameSeg (Buffer);\r
+    Buffer += AML_NAME_SEG_SIZE;\r
+  }\r
+\r
+  return ;\r
+}\r