TianoCore EDK2 master
Loading...
Searching...
No Matches
AcpiHelper.c
Go to the documentation of this file.
1
9#include <Library/BaseLib.h>
10#include <Library/DebugLib.h>
11
12// Module specific include files.
14
23UINT8
24EFIAPI
26 IN UINT8 Hex
27 )
28{
29 if (Hex < 10) {
30 return (UINT8)(Hex + '0');
31 }
32
33 if (Hex < 16) {
34 return (UINT8)(Hex - 10 + 'A');
35 }
36
37 ASSERT (FALSE);
38 return (UINT8)-1;
39}
40
50UINT8
51EFIAPI
53 IN CHAR8 Char
54 )
55{
56 if ((Char >= '0') && (Char <= '9')) {
57 return (UINT8)(Char - '0');
58 }
59
60 if ((Char >= 'A') && (Char <= 'F')) {
61 return (UINT8)(Char - 'A' + 10);
62 }
63
64 if ((Char >= 'a') && (Char <= 'f')) {
65 return (UINT8)(Char - 'a' + 10);
66 }
67
68 ASSERT (FALSE);
69 return (UINT8)-1;
70}
71
79BOOLEAN
81 IN CONST CHAR8 *Hid
82 )
83{
84 UINTN Index;
85
86 if (AsciiStrLen (Hid) != 7) {
87 return FALSE;
88 }
89
90 // A valid PNP ID must be of the form "AAA####"
91 // where A is an uppercase letter and # is a hex digit.
92 for (Index = 0; Index < 3; Index++) {
93 if (!IS_UPPER_CHAR (Hid[Index])) {
94 return FALSE;
95 }
96 }
97
98 for (Index = 3; Index < 7; Index++) {
99 if (!IS_UPPER_HEX (Hid[Index])) {
100 return FALSE;
101 }
102 }
103
104 return TRUE;
105}
106
114BOOLEAN
116 IN CONST CHAR8 *Hid
117 )
118{
119 UINTN Index;
120
121 if (AsciiStrLen (Hid) != 8) {
122 return FALSE;
123 }
124
125 // A valid ACPI ID must be of the form "NNNN####"
126 // where N is an uppercase letter or a digit ('0'-'9')
127 // and # is a hex digit.
128 for (Index = 0; Index < 4; Index++) {
129 if (!(IS_UPPER_CHAR (Hid[Index]) || IS_DIGIT (Hid[Index]))) {
130 return FALSE;
131 }
132 }
133
134 for (Index = 4; Index < 8; Index++) {
135 if (!IS_UPPER_HEX (Hid[Index])) {
136 return FALSE;
137 }
138 }
139
140 return TRUE;
141}
142
154EFIAPI
156 IN CONST CHAR8 *EisaIdStr,
157 OUT UINT32 *EisaIdInt
158 )
159{
160 if ((EisaIdStr == NULL) ||
161 (!IsValidPnpId (EisaIdStr)) ||
162 (EisaIdInt == NULL))
163 {
164 ASSERT (0);
165 return EFI_INVALID_PARAMETER;
166 }
167
168 /* Cf. ACPI 6.4 specification, s19.3.4 "ASL Macros": "Eisaid"
169
170 Converts and compresses the 7-character text argument into its corresponding
171 4-byte numeric EISA ID encoding (Integer). This can be used when declaring
172 IDs for devices that are EISA IDs.
173
174 The algorithm used to convert the TextID is as shown in the following
175 example:
176 Starting with a seven character input string "PNP0303", we want to create
177 a DWordConst. This string contains a three character manufacturer code
178 "PNP", a three character hex product identifier "030", and a one character
179 revision identifier "3".
180 The compressed manufacturer code is created as follows:
181 1) Find hex ASCII value for each letter
182 2) Subtract 40h from each ASCII value
183 3) Retain 5 least significant bits for each letter and discard remaining
184 0's:
185
186 Byte 0:
187 Bit 7: reserved (0)
188 Bit 6-2: 1st character of compressed mfg code "P"
189 Bit 1-0: Upper 2 bits of 2nd character of mfg code "N"
190 Byte 1:
191 Bit 7-5: Lower 3 bits of 2nd character of mfg code "N"
192 Bit 4-0: 3rd character of mfg code "P"
193 Byte 2:
194 Bit 7-4: 1st hex digit of product number "0"
195 Bit 3-0: 2nd hex digit of product number "3"
196 Byte 3:
197 Bit 7-4: 3rd hex digit of product number "0"
198 Bit 3-0: 4th hex digit of product number "3"
199 */
200 *EisaIdInt = SwapBytes32 (
201 ((EisaIdStr[0] - 0x40) << 26) |
202 ((EisaIdStr[1] - 0x40) << 21) |
203 ((EisaIdStr[2] - 0x40) << 16) |
204 (HexFromAscii (EisaIdStr[3]) << 12) |
205 (HexFromAscii (EisaIdStr[4]) << 8) |
206 (HexFromAscii (EisaIdStr[5]) << 4) |
207 (HexFromAscii (EisaIdStr[6]))
208 );
209
210 return EFI_SUCCESS;
211}
UINT64 UINTN
EFI_STATUS EFIAPI AmlGetEisaIdFromString(IN CONST CHAR8 *EisaIdStr, OUT UINT32 *EisaIdInt)
Definition: AcpiHelper.c:155
BOOLEAN IsValidAcpiId(IN CONST CHAR8 *Hid)
Definition: AcpiHelper.c:115
UINT8 EFIAPI AsciiFromHex(IN UINT8 Hex)
Definition: AcpiHelper.c:25
BOOLEAN IsValidPnpId(IN CONST CHAR8 *Hid)
Definition: AcpiHelper.c:80
UINT8 EFIAPI HexFromAscii(IN CHAR8 Char)
Definition: AcpiHelper.c:52
#define IS_UPPER_CHAR(x)
Definition: AcpiHelperLib.h:13
#define IS_DIGIT(x)
Definition: AcpiHelperLib.h:17
#define IS_UPPER_HEX(x)
Definition: AcpiHelperLib.h:21
UINTN EFIAPI AsciiStrLen(IN CONST CHAR8 *String)
Definition: String.c:641
UINT32 EFIAPI SwapBytes32(IN UINT32 Value)
Definition: SwapBytes32.c:25
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112