]> git.proxmox.com Git - mirror_edk2.git/blame - DynamicTablesPkg/Library/Common/AmlLib/String/AmlString.h
DynamicTablesPkg: Apply uncrustify changes
[mirror_edk2.git] / DynamicTablesPkg / Library / Common / AmlLib / String / AmlString.h
CommitLineData
ca04956e
PG
1/** @file\r
2 AML String.\r
3\r
4 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved. <BR>\r
5 Copyright (c) 2019 - 2020, Arm Limited. All rights reserved.<BR>\r
6\r
7 SPDX-License-Identifier: BSD-2-Clause-Patent\r
8**/\r
9\r
10#ifndef AML_STRING_H_\r
11#define AML_STRING_H_\r
12\r
13/* This header file does not include internal Node definition,\r
14 i.e. AML_ROOT_NODE, AML_OBJECT_NODE, etc. The node definitions\r
15 must be included by the caller file. The function prototypes must\r
16 only expose AML_NODE_HANDLE, AML_ROOT_NODE_HANDLE, etc. node\r
17 definitions.\r
18 This allows to keep the functions defined here both internal and\r
19 potentially external. If necessary, any function of this file can\r
20 be exposed externally.\r
21 The Api folder is internal to the AmlLib, but should only use these\r
22 functions. They provide a "safe" way to interact with the AmlLib.\r
23*/\r
24\r
25#include <AmlInclude.h>\r
26\r
27/** Check NameString/path information is valid.\r
28\r
29 Root, ParentPrefix and SegCount cannot be 0 at the same time.\r
30 This function works for ASL and AML name strings.\r
31\r
32 @param [in] Root Number of root char.\r
33 Must be 0 or 1.\r
34 @param [in] ParentPrefix Number of carets char ('^').\r
35 Must be [0-255].\r
36 @param [in] SegCount Number of NameSeg (s).\r
37 Must be [0-255].\r
38\r
39 @retval TRUE id the input information is in the right boundaries.\r
40 FALSE otherwise.\r
41**/\r
42BOOLEAN\r
43EFIAPI\r
44AmlIsNameString (\r
731c67e1
MK
45 IN UINT32 Root,\r
46 IN UINT32 ParentPrefix,\r
47 IN UINT32 SegCount\r
ca04956e
PG
48 );\r
49\r
50/** Copy bytes from SrcBuffer to DstBuffer and convert to upper case.\r
51 Don't copy more than MaxDstBufferSize bytes.\r
52\r
53 @param [out] DstBuffer Destination buffer.\r
54 @param [in] MaxDstBufferSize Maximum size of DstBuffer.\r
55 Must be non-zero.\r
56 @param [in] SrcBuffer Source buffer.\r
57 @param [in] Count Count of bytes to copy from SrcBuffer.\r
58 Return success if 0.\r
59\r
60 @retval EFI_SUCCESS The function completed successfully.\r
61 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
62**/\r
63EFI_STATUS\r
64EFIAPI\r
65AmlUpperCaseMemCpyS (\r
731c67e1
MK
66 OUT CHAR8 *DstBuffer,\r
67 IN UINT32 MaxDstBufferSize,\r
68 IN CONST CHAR8 *SrcBuffer,\r
69 IN UINT32 Count\r
ca04956e
PG
70 );\r
71\r
72/** Check whether Buffer is a root path ('\').\r
73\r
74 This function works for both ASL and AML pathnames.\r
75 Buffer must be at least 2 bytes long.\r
76\r
77 @param [in] Buffer An ASL/AML path.\r
78\r
79 @retval TRUE Buffer is a root path\r
80 @retval FALSE Buffer is not a root path.\r
81**/\r
82BOOLEAN\r
83EFIAPI\r
84AmlIsRootPath (\r
731c67e1 85 IN CONST CHAR8 *Buffer\r
ca04956e
PG
86 );\r
87\r
88/** Check whether Ch is an ASL/AML LeadName.\r
89\r
90 This function works for both ASL and AML pathnames.\r
91\r
92 ACPI 6.3 specification, s19.2.2. "ASL Name and Pathname Terms":\r
93 LeadNameChar := 'A'-'Z' | 'a'-'z' | '_'\r
94\r
95 ACPI 6.3 specification, s20.2.2. "Name Objects Encoding":\r
96 LeadNameChar := 'A'-'Z' | 'a'-'z' | '_'\r
97\r
98 @param [in] Ch The char to test.\r
99\r
100 @retval TRUE Ch is an ASL/AML LeadName.\r
101 @retval FALSE Ch is not an ASL/AML LeadName.\r
102**/\r
103BOOLEAN\r
104EFIAPI\r
105AmlIsLeadNameChar (\r
731c67e1 106 IN CHAR8 Ch\r
ca04956e
PG
107 );\r
108\r
109/** Check whether Ch is an ASL/AML NameChar.\r
110\r
111 This function works for both ASL and AML pathnames.\r
112\r
113 ACPI 6.3 specification, s19.2.2. "ASL Name and Pathname Terms":\r
114 NameChar := DigitChar | LeadNameChar\r
115 LeadNameChar := 'A'-'Z' | 'a'-'z' | '_'\r
116 DigitChar := '0'-'9'\r
117\r
118 ACPI 6.3 specification, s20.2.2. "Name Objects Encoding":\r
119 NameChar := DigitChar | LeadNameChar\r
120 LeadNameChar := 'A'-'Z' | 'a'-'z' | '_'\r
121 DigitChar := '0'-'9'\r
122\r
123 @param [in] Ch The char to test.\r
124\r
125 @retval TRUE Ch is an ASL/AML NameChar.\r
126 @retval FALSE Ch is not an ASL/AML NameChar.\r
127**/\r
128BOOLEAN\r
129EFIAPI\r
130AmlIsNameChar (\r
131 IN CHAR8 Ch\r
132 );\r
133\r
134/** Check whether AslBuffer is an ASL NameSeg.\r
135\r
136 This function only works for ASL NameStrings/pathnames.\r
137 ASL NameStrings/pathnames are at most 4 chars long.\r
138\r
139 @param [in] AslBuffer Pointer in an ASL NameString/pathname.\r
140 @param [out] Size Size of the NameSeg.\r
141\r
142 @retval TRUE AslBuffer is an ASL NameSeg.\r
143 @retval FALSE AslBuffer is not an ASL NameSeg.\r
144**/\r
145BOOLEAN\r
146EFIAPI\r
147AslIsNameSeg (\r
731c67e1
MK
148 IN CONST CHAR8 *AslBuffer,\r
149 OUT UINT32 *Size\r
ca04956e
PG
150 );\r
151\r
152/** Check whether AmlBuffer is an AML NameSeg.\r
153\r
154 This function only works for AML NameStrings/pathnames.\r
155 AML NameStrings/pathnames must be 4 chars long.\r
156\r
157 @param [in] AmlBuffer Pointer in an AML NameString/pathname.\r
158\r
159 @retval TRUE AmlBuffer is an AML NameSeg.\r
160 @retval FALSE AmlBuffer is not an AML NameSeg.\r
161**/\r
162BOOLEAN\r
163EFIAPI\r
164AmlIsNameSeg (\r
731c67e1 165 IN CONST CHAR8 *AmlBuffer\r
ca04956e
PG
166 );\r
167\r
168/** Parse an ASL NameString/path.\r
169\r
170 An ASL NameString/path must be NULL terminated.\r
171 Information found in the ASL NameString/path is returned via pointers:\r
172 Root, ParentPrefix, SegCount.\r
173\r
174 @param [in] Buffer ASL NameString/path.\r
175 @param [out] Root Pointer holding the number of root char.\r
176 Can be 0 or 1.\r
177 @param [out] ParentPrefix Pointer holding the number of carets char ('^').\r
178 Can be [0-255].\r
179 @param [out] SegCount Pointer holding the number of NameSeg (s).\r
180 Can be [0-255].\r
181\r
182 @retval EFI_SUCCESS The function completed successfully.\r
183 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
184**/\r
185EFI_STATUS\r
186EFIAPI\r
187AslParseNameStringInfo (\r
731c67e1
MK
188 IN CONST CHAR8 *Buffer,\r
189 OUT UINT32 *Root,\r
190 OUT UINT32 *ParentPrefix,\r
191 OUT UINT32 *SegCount\r
ca04956e
PG
192 );\r
193\r
194/** Parse an AML NameString/path.\r
195\r
196 It is possible to determine the size of an AML NameString/path just\r
197 by sight reading it. So no overflow can occur.\r
198 Information found in the AML NameString/path is returned via pointers:\r
199 Root, ParentPrefix, SegCount.\r
200\r
201 @param [in] Buffer AML NameString/path.\r
202 @param [out] Root Pointer holding the number of root char.\r
203 Can be 0 or 1.\r
204 @param [out] ParentPrefix Pointer holding the number of carets char ('^').\r
205 Can be [0-255].\r
206 @param [out] SegCount Pointer holding the number of NameSeg(s).\r
207 Can be [0-255].\r
208\r
209 @retval EFI_SUCCESS The function completed successfully.\r
210 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
211**/\r
212EFI_STATUS\r
213EFIAPI\r
214AmlParseNameStringInfo (\r
731c67e1
MK
215 IN CONST CHAR8 *Buffer,\r
216 OUT UINT32 *Root,\r
217 OUT UINT32 *ParentPrefix,\r
218 OUT UINT32 *SegCount\r
ca04956e
PG
219 );\r
220\r
221/** Compute the ASL NameString/path size from NameString\r
222 information (Root, ParentPrefix, SegCount).\r
223\r
224 @param [in] Root Number of root char.\r
225 Can be 0 or 1.\r
226 @param [in] ParentPrefix Number of carets char ('^').\r
227 Can be [0-255].\r
228 @param [in] SegCount Pointer holding the number of NameSeg(s).\r
229 Can be [0-255].\r
230\r
231 @return Size of the ASL NameString/path.\r
232**/\r
233UINT32\r
234EFIAPI\r
235AslComputeNameStringSize (\r
731c67e1
MK
236 IN UINT32 Root,\r
237 IN UINT32 ParentPrefix,\r
238 IN UINT32 SegCount\r
ca04956e
PG
239 );\r
240\r
241/** Compute the AML NameString/path size from NameString\r
242 information (Root, ParentPrefix, SegCount).\r
243\r
244 @param [in] Root Number of root char.\r
245 Can be 0 or 1.\r
246 @param [in] ParentPrefix Number of carets char ('^').\r
247 Can be [0-255].\r
248 @param [in] SegCount Pointer holding the number of NameSeg(s).\r
249 Can be [0-255].\r
250\r
251 @return Size of the AML NameString/path.\r
252**/\r
253UINT32\r
254EFIAPI\r
255AmlComputeNameStringSize (\r
731c67e1
MK
256 IN UINT32 Root,\r
257 IN UINT32 ParentPrefix,\r
258 IN UINT32 SegCount\r
ca04956e
PG
259 );\r
260\r
261/** Get the ASL NameString/path size.\r
262\r
263 @param [in] AslPath An ASL NameString/path.\r
264 @param [out] AslPathSizePtr Pointer holding the ASL NameString/path size.\r
265\r
266 @retval EFI_SUCCESS Success.\r
267 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
268**/\r
269EFI_STATUS\r
270EFIAPI\r
271AslGetNameStringSize (\r
731c67e1
MK
272 IN CONST CHAR8 *AslPath,\r
273 OUT UINT32 *AslPathSizePtr\r
ca04956e
PG
274 );\r
275\r
276/** Get the AML NameString/path size.\r
277\r
278 @param [in] AmlPath An AML NameString/path.\r
279 @param [out] AmlPathSizePtr Pointer holding the AML NameString/path size.\r
280\r
281 @retval EFI_SUCCESS Success.\r
282 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
283**/\r
284EFI_STATUS\r
285EFIAPI\r
286AmlGetNameStringSize (\r
731c67e1
MK
287 IN CONST CHAR8 *AmlPath,\r
288 OUT UINT32 *AmlPathSizePtr\r
ca04956e
PG
289 );\r
290\r
291/** Convert an ASL NameString/path to an AML NameString/path.\r
292 The caller must free the memory allocated in this function\r
293 for AmlPath using FreePool ().\r
294\r
295 @param [in] AslPath An ASL NameString/path.\r
296 @param [out] OutAmlPath Buffer containing the AML path.\r
297\r
298 @retval EFI_SUCCESS Success.\r
299 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
300 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
301**/\r
302EFI_STATUS\r
303EFIAPI\r
304ConvertAslNameToAmlName (\r
731c67e1
MK
305 IN CONST CHAR8 *AslPath,\r
306 OUT CHAR8 **OutAmlPath\r
ca04956e
PG
307 );\r
308\r
309/** Convert an AML NameString/path to an ASL NameString/path.\r
310 The caller must free the memory allocated in this function.\r
311 using FreePool ().\r
312\r
313 @param [in] AmlPath An AML NameString/path.\r
314 @param [out] OutAslPath Buffer containing the ASL path.\r
315\r
316 @retval EFI_SUCCESS Success.\r
317 @retval EFI_INVALID_PARAMETER Invalid parameter.\r
318 @retval EFI_OUT_OF_RESOURCES Failed to allocate memory.\r
319**/\r
320EFI_STATUS\r
321EFIAPI\r
322ConvertAmlNameToAslName (\r
731c67e1
MK
323 IN CONST CHAR8 *AmlPath,\r
324 OUT CHAR8 **OutAslPath\r
ca04956e
PG
325 );\r
326\r
327/** Compare two ASL NameStrings.\r
328\r
329 @param [in] AslName1 First NameString to compare.\r
330 @param [in] AslName2 Second NameString to compare.\r
331\r
332 @retval TRUE if the two strings are identical.\r
333 @retval FALSE otherwise, or if error.\r
334**/\r
335BOOLEAN\r
336EFIAPI\r
337AslCompareNameString (\r
731c67e1
MK
338 IN CONST CHAR8 *AslName1,\r
339 IN CONST CHAR8 *AslName2\r
ca04956e
PG
340 );\r
341\r
342/** Compare two AML NameStrings.\r
343\r
344 @param [in] AmlName1 First NameString to compare.\r
345 @param [in] AmlName2 Second NameString to compare.\r
346\r
347 @retval TRUE if the two strings are identical.\r
348 @retval FALSE otherwise, or if error.\r
349**/\r
350BOOLEAN\r
351EFIAPI\r
352AmlCompareNameString (\r
731c67e1
MK
353 IN CONST CHAR8 *AmlName1,\r
354 IN CONST CHAR8 *AmlName2\r
ca04956e
PG
355 );\r
356\r
357/** Compare an AML NameString and an ASL NameString.\r
358\r
359 The ASL NameString is converted to an AML NameString before\r
360 being compared with the ASL NameString. This allows to expand\r
361 NameSegs shorter than 4 chars.\r
362 E.g.: AslName: "DEV" will be expanded to "DEV_" before being\r
363 compared.\r
364\r
365 @param [in] AmlName1 AML NameString to compare.\r
366 @param [in] AslName2 ASL NameString to compare.\r
367\r
368 @retval TRUE if the two strings are identical.\r
369 @retval FALSE otherwise, or if error.\r
370**/\r
371BOOLEAN\r
372EFIAPI\r
373CompareAmlWithAslNameString (\r
731c67e1
MK
374 IN CONST CHAR8 *AmlName1,\r
375 IN CONST CHAR8 *AslName2\r
ca04956e
PG
376 );\r
377\r
378/** Given an AmlPath, return the address of the first NameSeg.\r
379\r
380 It is possible to determine the size of an AML NameString/path just\r
381 by sight reading it. So no overflow can occur.\r
382\r
383 @param [in] AmlPath The AML pathname.\r
384 @param [in] Root The AML pathname starts with a root char.\r
385 It is an absolute path.\r
386 @param [in] ParentPrefix The AML pathname has ParentPrefix\r
387 carets in its name.\r
388\r
389 @return Pointer to the first NameSeg of the NameString.\r
390 Return NULL if AmlPath is NULL.\r
391**/\r
392CONST\r
393CHAR8 *\r
394EFIAPI\r
395AmlGetFirstNameSeg (\r
731c67e1
MK
396 IN CONST CHAR8 *AmlPath,\r
397 IN UINT32 Root,\r
398 IN UINT32 ParentPrefix\r
ca04956e
PG
399 );\r
400\r
401#endif // AML_STRING_H_\r