From: Abner Chang <abner.ch...@amd.com>

Signed-off-by: Abner Chang <abner.ch...@amd.com>
Cc: Abdul Lateef Attar <abdat...@amd.com>
---
 .../AMD/AmdPlatformPkg/AmdPlatformPkg.dec     |   3 +
 .../AMD/AmdPlatformPkg/AmdPlatformPkg.dsc     |  69 ++++
 .../DxeAcpiSdtParserLib.inf                   |  33 ++
 .../Include/Library/AmdAcpiSdtParserLib.h     | 118 ++++++
 .../DxeAcpiSdtParserLib/DxeAcpiSdtParserLib.c | 382 ++++++++++++++++++
 .../DxeAcpiSdtParserLib.uni                   |  12 +
 6 files changed, 617 insertions(+)
 create mode 100644 
Platform/AMD/AmdPlatformPkg/Library/DxeAcpiSdtParserLib/DxeAcpiSdtParserLib.inf
 create mode 100644 
Platform/AMD/AmdPlatformPkg/Include/Library/AmdAcpiSdtParserLib.h
 create mode 100644 
Platform/AMD/AmdPlatformPkg/Library/DxeAcpiSdtParserLib/DxeAcpiSdtParserLib.c
 create mode 100644 
Platform/AMD/AmdPlatformPkg/Library/DxeAcpiSdtParserLib/DxeAcpiSdtParserLib.uni

diff --git a/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dec 
b/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dec
index 1fe7f94dc7..9cc9ed1ceb 100644
--- a/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dec
+++ b/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dec
@@ -14,5 +14,8 @@
   PACKAGE_GUID      = 2CB1238B-18E2-4837-B714-9DAB2B30A3C2
   PACKAGE_VERSION   = 1.0
 
+[Includes]
+  Include
+
 [Guids]
   gAmdPlatformPkgTokenSpaceGuid   = { 0x663DE733, 0x70E0, 0x4D37, { 0xBB, 
0x30, 0x7D, 0x9E, 0xAF, 0x9B, 0xDA, 0xE9 }}
diff --git a/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc 
b/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc
index d3368c87ee..a1c16d109d 100644
--- a/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc
+++ b/Platform/AMD/AmdPlatformPkg/AmdPlatformPkg.dsc
@@ -20,3 +20,72 @@
 
 [Packages]
   AmdPlatformPkg/AmdPlatformPkg.dec
+
+!include MdePkg/MdeLibs.dsc.inc
+
+[LibraryClasses.Common]
+  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
+  IoLib|MdePkg/Library/BaseIoLibIntrinsic/BaseIoLibIntrinsic.inf
+  
UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
+  
UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
+  
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
+  UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
+  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
+  
DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf
+
+  #
+  # Debug libraries
+  #
+  
DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseDebugPrintErrorLevelLib.inf
+!if $(TARGET) == RELEASE
+  DebugLib|MdePkg/Library/BaseDebugLibNull/BaseDebugLibNull.inf
+!else
+  DebugLib|MdePkg/Library/BaseDebugLibSerialPort/BaseDebugLibSerialPort.inf
+!endif
+
+  BaseLib|MdePkg/Library/BaseLib/BaseLib.inf
+  PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf
+  
SynchronizationLib|MdePkg/Library/BaseSynchronizationLib/BaseSynchronizationLib.inf
+  HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
+  DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
+  BaseMemoryLib|MdePkg/Library/BaseMemoryLibRepStr/BaseMemoryLibRepStr.inf
+  PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf
+  SerialPortLib|MdePkg/Library/BaseSerialPortLibNull/BaseSerialPortLibNull.inf
+  UefiLib|MdePkg/Library/UefiLib/UefiLib.inf
+  HiiLib|MdeModulePkg/Library/UefiHiiLib/UefiHiiLib.inf
+  
UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServicesLib.inf
+  DxeServicesLib|MdePkg/Library/DxeServicesLib/DxeServicesLib.inf
+  
DxeServicesTableLib|MdePkg/Library/DxeServicesTableLib/DxeServicesTableLib.inf
+  
UefiDriverEntryPoint|MdePkg/Library/UefiDriverEntryPoint/UefiDriverEntryPoint.inf
+  
UefiBootServicesTableLib|MdePkg/Library/UefiBootServicesTableLib/UefiBootServicesTableLib.inf
+  
UefiRuntimeServicesTableLib|MdePkg/Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf
+  UefiRuntimeLib|MdePkg/Library/UefiRuntimeLib/UefiRuntimeLib.inf
+
+  #
+  # CryptLib
+  #
+  IntrinsicLib|CryptoPkg/Library/IntrinsicLib/IntrinsicLib.inf
+  OpensslLib|CryptoPkg/Library/OpensslLib/OpensslLib.inf
+  BaseCryptLib|CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
+  RngLib|MdePkg/Library/BaseRngLib/BaseRngLib.inf
+
+  #
+  # Secureboot library
+  #
+  
SecureBootVariableLib|SecurityPkg/Library/SecureBootVariableLib/SecureBootVariableLib.inf
+  
SecureBootVariableProvisionLib|SecurityPkg/Library/SecureBootVariableProvisionLib/SecureBootVariableProvisionLib.inf
+  
PlatformPKProtectionLib|SecurityPkg/Library/PlatformPKProtectionLibVarPolicy/PlatformPKProtectionLibVarPolicy.inf
+
+  #
+  # Platform - Replace the modules in this section in platform DSC file.
+  #
+  TimerLib|MdePkg/Library/BaseTimerLibNullTemplate/BaseTimerLibNullTemplate.inf
+
+[LibraryClasses.common.DXE_CORE, LibraryClasses.common.DXE_SMM_DRIVER, 
LibraryClasses.common.SMM_CORE, LibraryClasses.common.DXE_DRIVER, 
LibraryClasses.common.DXE_RUNTIME_DRIVER, LibraryClasses.common.UEFI_DRIVER, 
LibraryClasses.common.UEFI_APPLICATION]
+  
MemoryAllocationLib|MdePkg/Library/UefiMemoryAllocationLib/UefiMemoryAllocationLib.inf
+  
ReportStatusCodeLib|MdeModulePkg/Library/DxeReportStatusCodeLib/DxeReportStatusCodeLib.inf
+  
AcpiSdtParserLib|AmdPlatformPkg/Library/DxeAcpiSdtParserLib/DxeAcpiSdtParserLib.inf
+
+[Components]
+  AmdPlatformPkg/Library/DxeAcpiSdtParserLib/DxeAcpiSdtParserLib.inf
+
diff --git 
a/Platform/AMD/AmdPlatformPkg/Library/DxeAcpiSdtParserLib/DxeAcpiSdtParserLib.inf
 
b/Platform/AMD/AmdPlatformPkg/Library/DxeAcpiSdtParserLib/DxeAcpiSdtParserLib.inf
new file mode 100644
index 0000000000..e2336de053
--- /dev/null
+++ 
b/Platform/AMD/AmdPlatformPkg/Library/DxeAcpiSdtParserLib/DxeAcpiSdtParserLib.inf
@@ -0,0 +1,33 @@
+## @file
+#  INF file of AMD ACPI SDT parser library
+#
+#  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = DxeAcpiSdtParserLib
+  MODULE_UNI_FILE                = DxeAcpiSdtParserLib.uni
+  FILE_GUID                      = CBA6011E-6C92-443C-9F7D-0A60BA629A16
+  MODULE_TYPE                    = DXE_DRIVER
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = AcpiSdtParserLib
+
+#
+# The following information is for reference only and not required by the 
build tools.
+#
+#  VALID_ARCHITECTURES           = IA32 X64 IPF EBC
+#
+
+[Sources]
+  DxeAcpiSdtParserLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  MdeModulePkg/MdeModulePkg.dec
+
+[LibraryClasses]
+  BaseLib
+  BaseMemoryLib
+  DebugLib
diff --git a/Platform/AMD/AmdPlatformPkg/Include/Library/AmdAcpiSdtParserLib.h 
b/Platform/AMD/AmdPlatformPkg/Include/Library/AmdAcpiSdtParserLib.h
new file mode 100644
index 0000000000..9b0079d556
--- /dev/null
+++ b/Platform/AMD/AmdPlatformPkg/Include/Library/AmdAcpiSdtParserLib.h
@@ -0,0 +1,118 @@
+/** @file
+  Header file of AMD ACPI SDT Parser
+
+  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+/*
+  Verify SDT Header
+
+  @param[in,out]  Buffer      Current ACPI Table Pointer
+  @param[in,out]  Size        Current Size of ACPI Table
+  @param[in]      NameString  NameString to Locate
+
+  @retval EFI_SUCCESS       Requested Scope found.
+  @retval EFI_NOT_FOUND     Requested Scope not found.
+*/
+EFI_STATUS
+EFIAPI
+VerifySdtTableHeader (
+  IN OUT  VOID    *Buffer,
+  IN OUT  UINT32  Size,
+  IN      CHAR8   *NameString
+  );
+
+/*
+  Locate ACPI Device
+
+  DefDevice := DeviceOp PkgLength NameString TermList
+  DeviceOp := ExtOpPrefix 0x82
+
+  ExtOpPrefix := 0x5B
+
+  PkgLength := PkgLeadByte |
+               <PkgLeadByte ByteData> |
+               <PkgLeadByte ByteData ByteData> |
+               <PkgLeadByte ByteData ByteData ByteData>
+
+  PkgLeadByte := <bit 7-6: ByteData count that follows (0-3)>
+               <bit 5-4: Only used if PkgLength < 63>
+               <bit 3-0: Least significant package length nybble>
+
+  @param(in,out)  Buffer      Current ACPI Table Pointer
+  @param(in,out)  Size        Current Size of ACPI Table
+  @param(in)      NameString  NameString to Locate
+
+  @retval EFI_SUCCESS       Requested Scope found.
+  @retval EFI_NOT_FOUND     Requested Scope not found.
+*/
+EFI_STATUS
+EFIAPI
+LocateAcpiDefDeviceTermList (
+  IN OUT  VOID    **Buffer,
+  IN OUT  UINT32  *Size,
+  IN      CHAR8   *NameString
+  );
+
+/*
+  Locate ACPI Named Object
+
+  DefName := NameOp NameString DataRefObject
+  NameOp := 0x08
+
+  @param[in,out]  Buffer      Current ACPI Table Pointer
+  @param[in,out]  Size        Current Size of ACPI Table
+  @param[in]      NameString  NameString to Locate
+
+  @retval EFI_SUCCESS       Requested Scope found.
+  @retval EFI_NOT_FOUND     Requested Scope not found.
+*/
+EFI_STATUS
+EFIAPI
+LocateAcpiDefNameDataRefObject (
+  IN OUT  VOID    **Buffer,
+  IN OUT  UINT32  *Size,
+  IN      CHAR8   *NameString
+  );
+
+/*
+  Locate ACPI Buffer ByteList
+
+  DefBuffer := BufferOp PkgLength BufferSize ByteList
+  BufferOp := 0x11
+  BufferSize := TermArg => Integer
+
+  TermArg := Type2Opcode | DataObject | ArgObj | LocalObj
+
+  @param[in,out]  Buffer      Current ACPI Table Pointer
+  @param[in,out]  Size        Current Size of ACPI Table
+
+  @retval EFI_SUCCESS       Requested Scope found.
+  @retval EFI_NOT_FOUND     Requested Scope not found.
+*/
+EFI_STATUS
+EFIAPI
+LocateAcpiDefBufferByteList (
+  IN OUT  VOID    **Buffer,
+  IN OUT  UINT32  *Size
+  );
+
+/*
+  Locate ACPI DefName Buffer ByteList
+
+  @param[in,out]  Buffer      Current ACPI Table Pointer
+  @param[in,out]  Size        Current Size of ACPI Table
+  @param[in]      NameString  NameString to Locate
+
+  @retval EFI_SUCCESS       Requested Scope found.
+  @retval EFI_NOT_FOUND     Requested Scope not found.
+*/
+EFI_STATUS
+EFIAPI
+LocateAcpiDefNameDefBufferByteList (
+  IN OUT  VOID    **Buffer,
+  IN OUT  UINT32  *Size,
+  IN      CHAR8   *NameString
+  );
diff --git 
a/Platform/AMD/AmdPlatformPkg/Library/DxeAcpiSdtParserLib/DxeAcpiSdtParserLib.c 
b/Platform/AMD/AmdPlatformPkg/Library/DxeAcpiSdtParserLib/DxeAcpiSdtParserLib.c
new file mode 100644
index 0000000000..b8c40114c2
--- /dev/null
+++ 
b/Platform/AMD/AmdPlatformPkg/Library/DxeAcpiSdtParserLib/DxeAcpiSdtParserLib.c
@@ -0,0 +1,382 @@
+/** @file
+  Implementation of AMD ACPI SDT Parser Library
+
+  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <Base.h>
+#include <Library/BaseLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <IndustryStandard/AcpiAml.h>
+#include <Library/DebugLib.h>
+#include <Library/AmdAcpiSdtParserLib.h>
+
+/*
+  Calculate PkgLength
+
+  @param[in]   Buffer     Current ACPI Table Pointer
+  @param[out]  PkgLength  NameString to Locate
+
+  @retval Number of bytes that make up the PkgLength
+*/
+UINT32
+AmlGetPkgLength (
+  IN UINT8    *Buffer,
+  OUT UINT32  *PkgLength
+  )
+{
+  UINT32 Bytes;
+  UINT32 Length;
+
+  Bytes = (UINT32)((Buffer[0] >> 6) & 0x3) + 1;
+  switch (Bytes) {
+    case 1:
+      Length = (UINT32)Buffer[0];
+      break;
+
+    case 2:
+      Length =  (UINT32)(Buffer[0] & 0x0F);
+      Length += (UINT32)(Buffer[1] & 0xFF) << 4;
+      break;
+
+    case 3:
+      Length =  (UINT32)(Buffer[0] & 0x0F);
+      Length += (UINT32)(Buffer[1] & 0xFF) << 4;
+      Length += (UINT32)(Buffer[2] & 0xFF) << 12;
+      break;
+
+    default: /* 4 bytes */
+      Length =  (UINT32)(Buffer[0] & 0x0F);
+      Length += (UINT32)(Buffer[1] & 0xFF) << 4;
+      Length += (UINT32)(Buffer[2] & 0xFF) << 12;
+      Length += (UINT32)(Buffer[3] & 0xFF) << 20;
+      break;
+  }
+
+  *PkgLength = Length;
+  return Bytes;
+}
+
+/*
+  Find ACPI NameString through brute force.
+
+  @param[in,out]  Buffer      Current ACPI Table Pointer
+  @param[in,out]  Size        Current Size of ACPI Table
+  @param[in]      NameString  NameString to Locate
+
+  @retval EFI_SUCCESS       Requested NameString found.
+  @retval EFI_NOT_FOUND     Requested NameString not found.
+*/
+EFI_STATUS
+EFIAPI
+ScanAcpiTableNameString(
+  IN OUT  VOID    **Buffer,
+  IN OUT  UINT32  *Size,
+  IN      CHAR8   *NameString
+  )
+{
+  UINT32  RemainingSize;
+  UINTN   NameStringLength;
+  UINT8   *CurrentLocation;
+
+  RemainingSize = *Size;
+  CurrentLocation = (UINT8 *)*Buffer;
+  NameStringLength = AsciiStrLen (NameString);
+  while (RemainingSize > 0) {
+    if (CompareMem (CurrentLocation, NameString, NameStringLength) == 0) {
+      break;
+    }
+    CurrentLocation++;
+    RemainingSize--;
+  }
+  if (RemainingSize == 0) {
+    DEBUG((DEBUG_ERROR, "%a: Did Not Find NameString %a\n", __func__, 
NameString));
+    *Buffer = NULL;
+    *Size = 0;
+    return EFI_NOT_FOUND;
+  }
+  *Buffer = CurrentLocation;
+  *Size = RemainingSize;
+  return EFI_SUCCESS;
+}
+
+/*
+  Verify SDT Header
+
+  @param[in,out]  Buffer      Current ACPI Table Pointer
+  @param[in,out]  Size        Current Size of ACPI Table
+  @param[in]      NameString  NameString to Locate
+
+  @retval EFI_SUCCESS       Requested Scope found.
+  @retval EFI_NOT_FOUND     Requested Scope not found.
+*/
+EFI_STATUS
+EFIAPI
+VerifySdtTableHeader (
+  IN OUT  VOID    *Buffer,
+  IN OUT  UINT32  Size,
+  IN      CHAR8   *NameString
+  )
+{
+  EFI_STATUS                  Status;
+  EFI_ACPI_DESCRIPTION_HEADER *CurrentTable;
+  UINT32                      Length;
+
+  Status = EFI_NOT_FOUND;
+  CurrentTable = (EFI_ACPI_DESCRIPTION_HEADER *)Buffer;
+  Length = (UINT32)AsciiStrLen (NameString);
+  if (CompareMem (&CurrentTable->Signature, NameString, Length) == 0 &&
+      CurrentTable->Length == Size) {
+    Status = EFI_SUCCESS;
+  }
+  if (EFI_ERROR (Status)) {
+    DEBUG ((DEBUG_ERROR, "%a: Table provided does not match %a\n", __func__, 
NameString));
+  }
+  return  Status;
+}
+
+/*
+  Locate ACPI Device
+
+  DefDevice := DeviceOp PkgLength NameString TermList
+  DeviceOp := ExtOpPrefix 0x82
+
+  ExtOpPrefix := 0x5B
+
+  PkgLength := PkgLeadByte |
+               <PkgLeadByte ByteData> |
+               <PkgLeadByte ByteData ByteData> |
+               <PkgLeadByte ByteData ByteData ByteData>
+
+  PkgLeadByte := <bit 7-6: ByteData count that follows (0-3)>
+               <bit 5-4: Only used if PkgLength < 63>
+               <bit 3-0: Least significant package length nybble>
+
+  @param[in,out]  Buffer      Current ACPI Table Pointer
+  @param[in,out]  Size        Current Size of ACPI Table
+  @param[in]      NameString  NameString to Locate
+
+  @retval EFI_SUCCESS       Requested Scope found.
+  @retval EFI_NOT_FOUND     Requested Scope not found.
+*/
+EFI_STATUS
+EFIAPI
+LocateAcpiDefDeviceTermList (
+  IN OUT  VOID    **Buffer,
+  IN OUT  UINT32  *Size,
+  IN      CHAR8   *NameString
+  )
+{
+  EFI_STATUS  Status;
+  UINT32      RemainingSize;
+  UINT8       *CurrentLocation;
+  UINT8       *OpLocation;
+  UINT32      TermListSize;
+  UINT32      PkgLengthSize;
+  UINT32      NameStringLength;
+
+  CurrentLocation = *Buffer;
+  RemainingSize = *Size;
+  NameStringLength = (UINT32)AsciiStrnLenS (NameString, RemainingSize);
+
+  // Locate NameString
+  while (RemainingSize > 0) {
+    Status = ScanAcpiTableNameString ((VOID **)&CurrentLocation,
+                                      &RemainingSize,
+                                      NameString);
+    if (EFI_ERROR (Status)) {
+      ASSERT_EFI_ERROR (Status);
+      return Status;
+    }
+
+    // Look backwards for Op Code
+    for (OpLocation = CurrentLocation - 5;
+          OpLocation < CurrentLocation;
+          OpLocation++) {
+      if (*(UINT16 *)OpLocation == (AML_EXT_OP | (AML_EXT_DEVICE_OP << 8))) {
+        break;
+      }
+    }
+    if (OpLocation < CurrentLocation) {
+      PkgLengthSize = AmlGetPkgLength(OpLocation + 2, &TermListSize);
+
+      // Point to TermList and set size
+      CurrentLocation += NameStringLength;
+      TermListSize -= (PkgLengthSize + NameStringLength);
+      *Buffer = CurrentLocation;
+      *Size = TermListSize;
+      return EFI_SUCCESS;
+    } else {
+
+        // Not DeviceOp, so skip NameString and keep searching.
+      CurrentLocation += NameStringLength;
+      RemainingSize -= NameStringLength;
+    }
+    CurrentLocation++;
+    RemainingSize--;
+  }
+  ASSERT (FALSE);
+  return EFI_NOT_FOUND;
+}
+
+/*
+  Locate ACPI Named Object
+
+  DefName := NameOp NameString DataRefObject
+  NameOp := 0x08
+
+  @param[in,out]  Buffer      Current ACPI Table Pointer
+  @param[in,out]  Size        Current Size of ACPI Table
+  @param[in]      NameString  NameString to Locate
+
+  @retval EFI_SUCCESS       Requested Scope found.
+  @retval EFI_NOT_FOUND     Requested Scope not found.
+*/
+EFI_STATUS
+EFIAPI
+LocateAcpiDefNameDataRefObject (
+  IN OUT  VOID    **Buffer,
+  IN OUT  UINT32  *Size,
+  IN      CHAR8   *NameString
+  )
+{
+  EFI_STATUS  Status;
+  UINT32      RemainingSize;
+  UINT8       *CurrentLocation;
+  UINT32      NameStringLength;
+
+  CurrentLocation = *Buffer;
+  RemainingSize = *Size;
+  NameStringLength = (UINT32)AsciiStrnLenS (NameString, RemainingSize);
+
+  // Locate NameString
+  while (RemainingSize > 0) {
+    Status = ScanAcpiTableNameString ((VOID **)&CurrentLocation,
+                                      &RemainingSize,
+                                      NameString);
+    if (EFI_ERROR (Status)) {
+      ASSERT_EFI_ERROR (Status);
+      return Status;
+    }
+
+    // Look backwards for Op Code
+    if (*(CurrentLocation - 1) == AML_NAME_OP) {
+      // Point to DataRefObject and set size
+      CurrentLocation += NameStringLength;
+      *Buffer = CurrentLocation;
+      *Size = RemainingSize - NameStringLength;
+      return EFI_SUCCESS;
+    } else {
+
+      // Not DeviceOp, so skip NameString and keep searching.
+      CurrentLocation += NameStringLength;
+      RemainingSize -= NameStringLength;
+    }
+    CurrentLocation++;
+    RemainingSize--;
+  }
+  ASSERT (FALSE);
+  return EFI_NOT_FOUND;
+}
+
+/*
+  Locate ACPI Buffer ByteList
+
+  DefBuffer := BufferOp PkgLength BufferSize ByteList
+  BufferOp := 0x11
+  BufferSize := TermArg => Integer
+
+  TermArg := Type2Opcode | DataObject | ArgObj | LocalObj
+
+  @param[in,out]  Buffer      Current ACPI Table Pointer
+  @param[in,out]  Size        Current Size of ACPI Table
+
+  @retval EFI_SUCCESS       Requested Scope found.
+  @retval EFI_NOT_FOUND     Requested Scope not found.
+*/
+EFI_STATUS
+EFIAPI
+LocateAcpiDefBufferByteList (
+  IN OUT  VOID    **Buffer,
+  IN OUT  UINT32  *Size
+  )
+{
+  UINT32      RemainingSize;
+  UINT8       *CurrentLocation;
+  UINT32      PkgLength;
+  UINT32      PkgLengthSize;
+
+  CurrentLocation = *Buffer;
+  RemainingSize = *Size;
+  if (*CurrentLocation != AML_BUFFER_OP) {
+    ASSERT (FALSE);
+    return EFI_NOT_FOUND;
+  }
+  CurrentLocation++;
+  RemainingSize--;
+
+  // Get PackageLength and number PkgLenght Bytes
+  PkgLengthSize = AmlGetPkgLength (CurrentLocation, &PkgLength);
+  CurrentLocation += PkgLengthSize;
+  RemainingSize -= PkgLengthSize;
+
+  // Get Buffer Size and point to ByteList
+  CurrentLocation += 1;
+  switch (*(CurrentLocation - 1)) {
+    case AML_BYTE_PREFIX:
+      RemainingSize = *CurrentLocation;
+      CurrentLocation += sizeof (UINT8);
+      break;
+    case AML_WORD_PREFIX:
+      RemainingSize = *(UINT16 *)CurrentLocation;
+      CurrentLocation += sizeof (UINT16);
+      break;
+    case AML_DWORD_PREFIX:
+      RemainingSize = *(UINT32 *)CurrentLocation;
+      CurrentLocation += sizeof (UINT32);
+      break;
+    default:
+      ASSERT (FALSE);
+      return EFI_NOT_FOUND;
+  }
+  *Buffer = CurrentLocation;
+  *Size = RemainingSize;
+
+  return EFI_SUCCESS;
+}
+
+/*
+  Locate ACPI DefName Buffer ByteList
+
+  @param[in,out]  Buffer      Current ACPI Table Pointer
+  @param[in,out]  Size        Current Size of ACPI Table
+  @param[in]      NameString  NameString to Locate
+
+  @retval EFI_SUCCESS       Requested Scope found.
+  @retval EFI_NOT_FOUND     Requested Scope not found.
+*/
+EFI_STATUS
+EFIAPI
+LocateAcpiDefNameDefBufferByteList (
+  IN OUT  VOID    **Buffer,
+  IN OUT  UINT32  *Size,
+  IN      CHAR8   *NameString
+  )
+{
+  EFI_STATUS  Status;
+
+  Status = LocateAcpiDefNameDataRefObject (
+              Buffer,
+              Size,
+              NameString
+              );
+  if (EFI_ERROR (Status)) {
+    ASSERT_EFI_ERROR (Status);
+    return Status;
+  }
+  Status = LocateAcpiDefBufferByteList (Buffer, Size);
+  ASSERT_EFI_ERROR (Status);
+  return Status;
+}
diff --git 
a/Platform/AMD/AmdPlatformPkg/Library/DxeAcpiSdtParserLib/DxeAcpiSdtParserLib.uni
 
b/Platform/AMD/AmdPlatformPkg/Library/DxeAcpiSdtParserLib/DxeAcpiSdtParserLib.uni
new file mode 100644
index 0000000000..c674e75bc1
--- /dev/null
+++ 
b/Platform/AMD/AmdPlatformPkg/Library/DxeAcpiSdtParserLib/DxeAcpiSdtParserLib.uni
@@ -0,0 +1,12 @@
+## @file
+#  UNI file of AMD ACPI SDT parser library
+#
+#  Copyright (C) 2023 Advanced Micro Devices, Inc. All rights reserved.
+#
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+#string STR_MODULE_ABSTRACT             #language en-US "AMD Dxe ACPI SDT 
parser Library instance"
+
+#string STR_MODULE_DESCRIPTION          #language en-US "AMD Dxe ACPI SDT 
parser Library instance."
+
-- 
2.37.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#106231): https://edk2.groups.io/g/devel/message/106231
Mute This Topic: https://groups.io/mt/99668651/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to