]> git.proxmox.com Git - mirror_edk2.git/commitdiff
DynamicTablesPkg: Add AmlGetEisaIdFromString() to AcpiHelperLib
authorPierre Gondois <Pierre.Gondois@arm.com>
Thu, 30 Sep 2021 07:48:16 +0000 (08:48 +0100)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 1 Oct 2021 10:57:43 +0000 (10:57 +0000)
Add a function converting a 7 characters string to its UINT32
EISAID. The algorithm used to create the EISAID is described
in the ACPI 6.4 specification, s19.3.4 "ASL Macros".

Reviewed-by: Sami Mujawar <sami.mujawar@arm.com>
Signed-off-by: Pierre Gondois <Pierre.Gondois@arm.com>
DynamicTablesPkg/Include/Library/AcpiHelperLib.h
DynamicTablesPkg/Library/Common/AcpiHelperLib/AcpiHelper.c

index 094392a1a6d0ecf648d8562bf315c49bc88480d6..a93e95e919870ae204447c5eb05c1267bde9e4db 100644 (file)
@@ -73,4 +73,21 @@ IsValidAcpiId (
   IN  CONST CHAR8  * Hid\r
   );\r
 \r
+/** Convert a EisaId string to its compressed UINT32 equivalent.\r
+\r
+  Cf. ACPI 6.4 specification, s19.3.4 "ASL Macros": "Eisaid"\r
+\r
+  @param  [in]  EisaIdStr   Input EisaId string.\r
+  @param  [out] EisaIdInt   Output EisaId UINT32 (compressed).\r
+\r
+  @retval EFI_SUCCESS             The function completed successfully.\r
+  @retval EFI_INVALID_PARAMETER   Invalid parameter.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AmlGetEisaIdFromString (\r
+  IN  CONST CHAR8   * EisaIdStr,\r
+  OUT       UINT32  * EisaIdInt\r
+  );\r
+\r
 #endif // ACPI_HELPER_LIB_H_\r
index 0b566f0502ac8bfbbf45e0d8ff72f3d526419e36..5afd257e49804320c67302d2e411a8ca8347b15f 100644 (file)
@@ -139,3 +139,72 @@ IsValidAcpiId (
 \r
   return TRUE;\r
 }\r
+\r
+/** Convert a EisaId string to its compressed UINT32 equivalent.\r
+\r
+  Cf. ACPI 6.4 specification, s19.3.4 "ASL Macros": "Eisaid"\r
+\r
+  @param  [in]  EisaIdStr   Input EisaId string.\r
+  @param  [out] EisaIdInt   Output EisaId UINT32 (compressed).\r
+\r
+  @retval EFI_SUCCESS             The function completed successfully.\r
+  @retval EFI_INVALID_PARAMETER   Invalid parameter.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+AmlGetEisaIdFromString (\r
+  IN  CONST CHAR8   * EisaIdStr,\r
+  OUT       UINT32  * EisaIdInt\r
+  )\r
+{\r
+  if ((EisaIdStr == NULL)         ||\r
+      (!IsValidPnpId (EisaIdStr)) ||\r
+      (EisaIdInt == NULL)) {\r
+    ASSERT (0);\r
+    return EFI_INVALID_PARAMETER;\r
+  }\r
+\r
+  /* Cf. ACPI 6.4 specification, s19.3.4 "ASL Macros": "Eisaid"\r
+\r
+  Converts and compresses the 7-character text argument into its corresponding\r
+  4-byte numeric EISA ID encoding (Integer). This can be used when declaring\r
+  IDs for devices that are EISA IDs.\r
+\r
+  The algorithm used to convert the TextID is as shown in the following\r
+  example:\r
+    Starting with a seven character input string "PNP0303", we want to create\r
+    a DWordConst. This string contains a three character manufacturer code\r
+    "PNP", a three character hex product identifier "030", and a one character\r
+    revision identifier "3".\r
+    The compressed manufacturer code is created as follows:\r
+      1) Find hex ASCII value for each letter\r
+      2) Subtract 40h from each ASCII value\r
+      3) Retain 5 least significant bits for each letter and discard remaining\r
+         0's:\r
+\r
+      Byte 0:\r
+        Bit 7: reserved (0)\r
+        Bit 6-2: 1st character of compressed mfg code "P"\r
+        Bit 1-0: Upper 2 bits of 2nd character of mfg code "N"\r
+      Byte 1:\r
+        Bit 7-5: Lower 3 bits of 2nd character of mfg code "N"\r
+        Bit 4-0: 3rd character of mfg code "P"\r
+      Byte 2:\r
+        Bit 7-4: 1st hex digit of product number "0"\r
+        Bit 3-0: 2nd hex digit of product number "3"\r
+      Byte 3:\r
+        Bit 7-4: 3rd hex digit of product number "0"\r
+        Bit 3-0: 4th hex digit of product number "3"\r
+  */\r
+  *EisaIdInt = SwapBytes32 (\r
+    ((EisaIdStr[0] - 0x40) << 26)       |\r
+    ((EisaIdStr[1] - 0x40) << 21)       |\r
+    ((EisaIdStr[2] - 0x40) << 16)       |\r
+    (HexFromAscii (EisaIdStr[3]) << 12) |\r
+    (HexFromAscii (EisaIdStr[4]) << 8)  |\r
+    (HexFromAscii (EisaIdStr[5]) << 4)  |\r
+    (HexFromAscii (EisaIdStr[6]))\r
+    );\r
+\r
+  return EFI_SUCCESS;\r
+}\r