From: "PierreGondois" <pierre.gondois@arm.com>
To: devel@edk2.groups.io, Sami Mujawar <sami.mujawar@arm.com>,
Alexei.Fedorov@arm.com, Joey Gouly <joey.gouly@arm.com>
Subject: [PATCH v2 05/10] DynamicTablesPkg: Add AmlGetEisaIdFromString() to AcpiHelperLib
Date: Thu, 30 Sep 2021 08:48:16 +0100 [thread overview]
Message-ID: <20210930074821.12546-6-Pierre.Gondois@arm.com> (raw)
In-Reply-To: <20210930074821.12546-1-Pierre.Gondois@arm.com>
From: Pierre Gondois <Pierre.Gondois@arm.com>
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>
---
.../Include/Library/AcpiHelperLib.h | 17 +++++
.../Library/Common/AcpiHelperLib/AcpiHelper.c | 69 +++++++++++++++++++
2 files changed, 86 insertions(+)
diff --git a/DynamicTablesPkg/Include/Library/AcpiHelperLib.h b/DynamicTablesPkg/Include/Library/AcpiHelperLib.h
index 094392a1a6d0..a93e95e91987 100644
--- a/DynamicTablesPkg/Include/Library/AcpiHelperLib.h
+++ b/DynamicTablesPkg/Include/Library/AcpiHelperLib.h
@@ -73,4 +73,21 @@ IsValidAcpiId (
IN CONST CHAR8 * Hid
);
+/** Convert a EisaId string to its compressed UINT32 equivalent.
+
+ Cf. ACPI 6.4 specification, s19.3.4 "ASL Macros": "Eisaid"
+
+ @param [in] EisaIdStr Input EisaId string.
+ @param [out] EisaIdInt Output EisaId UINT32 (compressed).
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+**/
+EFI_STATUS
+EFIAPI
+AmlGetEisaIdFromString (
+ IN CONST CHAR8 * EisaIdStr,
+ OUT UINT32 * EisaIdInt
+ );
+
#endif // ACPI_HELPER_LIB_H_
diff --git a/DynamicTablesPkg/Library/Common/AcpiHelperLib/AcpiHelper.c b/DynamicTablesPkg/Library/Common/AcpiHelperLib/AcpiHelper.c
index 0b566f0502ac..5afd257e4980 100644
--- a/DynamicTablesPkg/Library/Common/AcpiHelperLib/AcpiHelper.c
+++ b/DynamicTablesPkg/Library/Common/AcpiHelperLib/AcpiHelper.c
@@ -139,3 +139,72 @@ IsValidAcpiId (
return TRUE;
}
+
+/** Convert a EisaId string to its compressed UINT32 equivalent.
+
+ Cf. ACPI 6.4 specification, s19.3.4 "ASL Macros": "Eisaid"
+
+ @param [in] EisaIdStr Input EisaId string.
+ @param [out] EisaIdInt Output EisaId UINT32 (compressed).
+
+ @retval EFI_SUCCESS The function completed successfully.
+ @retval EFI_INVALID_PARAMETER Invalid parameter.
+**/
+EFI_STATUS
+EFIAPI
+AmlGetEisaIdFromString (
+ IN CONST CHAR8 * EisaIdStr,
+ OUT UINT32 * EisaIdInt
+ )
+{
+ if ((EisaIdStr == NULL) ||
+ (!IsValidPnpId (EisaIdStr)) ||
+ (EisaIdInt == NULL)) {
+ ASSERT (0);
+ return EFI_INVALID_PARAMETER;
+ }
+
+ /* Cf. ACPI 6.4 specification, s19.3.4 "ASL Macros": "Eisaid"
+
+ Converts and compresses the 7-character text argument into its corresponding
+ 4-byte numeric EISA ID encoding (Integer). This can be used when declaring
+ IDs for devices that are EISA IDs.
+
+ The algorithm used to convert the TextID is as shown in the following
+ example:
+ Starting with a seven character input string "PNP0303", we want to create
+ a DWordConst. This string contains a three character manufacturer code
+ "PNP", a three character hex product identifier "030", and a one character
+ revision identifier "3".
+ The compressed manufacturer code is created as follows:
+ 1) Find hex ASCII value for each letter
+ 2) Subtract 40h from each ASCII value
+ 3) Retain 5 least significant bits for each letter and discard remaining
+ 0's:
+
+ Byte 0:
+ Bit 7: reserved (0)
+ Bit 6-2: 1st character of compressed mfg code "P"
+ Bit 1-0: Upper 2 bits of 2nd character of mfg code "N"
+ Byte 1:
+ Bit 7-5: Lower 3 bits of 2nd character of mfg code "N"
+ Bit 4-0: 3rd character of mfg code "P"
+ Byte 2:
+ Bit 7-4: 1st hex digit of product number "0"
+ Bit 3-0: 2nd hex digit of product number "3"
+ Byte 3:
+ Bit 7-4: 3rd hex digit of product number "0"
+ Bit 3-0: 4th hex digit of product number "3"
+ */
+ *EisaIdInt = SwapBytes32 (
+ ((EisaIdStr[0] - 0x40) << 26) |
+ ((EisaIdStr[1] - 0x40) << 21) |
+ ((EisaIdStr[2] - 0x40) << 16) |
+ (HexFromAscii (EisaIdStr[3]) << 12) |
+ (HexFromAscii (EisaIdStr[4]) << 8) |
+ (HexFromAscii (EisaIdStr[5]) << 4) |
+ (HexFromAscii (EisaIdStr[6]))
+ );
+
+ return EFI_SUCCESS;
+}
--
2.17.1
next prev parent reply other threads:[~2021-09-30 7:48 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-09-30 7:48 [PATCH v2 00/10] Various DynamicTablesPkg modifications PierreGondois
2021-09-30 7:48 ` [PATCH v2 01/10] DynamicTablesPkg: Extract AcpiHelperLib from TableHelperLib PierreGondois
2021-09-30 7:48 ` [PATCH v2 02/10] DynamicTablesPkg: Update TableHelperLib.inf PierreGondois
2021-09-30 7:48 ` [PATCH v2 03/10] DynamicTablesPkg: Rename single char input parameter PierreGondois
2021-09-30 7:48 ` [PATCH v2 04/10] DynamicTablesPkg: Add HexFromAscii() to AcpiHelperLib PierreGondois
2021-09-30 7:48 ` PierreGondois [this message]
2021-09-30 7:48 ` [PATCH v2 06/10] DynamicTablesPkg: Add Configuration Manager Object parser PierreGondois
2021-09-30 7:48 ` [PATCH v2 07/10] DynamicTablesPkg: Use %a formatter in AmlDbgPrint PierreGondois
2021-09-30 7:48 ` [PATCH v2 08/10] DynamicTablesPkg: Update DynamicTablesPkg.ci.yaml PierreGondois
2021-09-30 7:48 ` [PATCH v2 09/10] DynamicTablesPkg: Deprecate Crs specific methods in AmlLib PierreGondois
2021-09-30 7:48 ` [PATCH v2 10/10] DynamicTablesPkg: Rework AmlResourceDataCodegen.c/h PierreGondois
2021-10-01 12:04 ` [PATCH v2 00/10] Various DynamicTablesPkg modifications Sami Mujawar
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210930074821.12546-6-Pierre.Gondois@arm.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox