]>
git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlString.c
2 ACPI Sdt Protocol Driver
4 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved. <BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
12 Check if it is AML Root name
14 @param[in] Buffer AML path.
16 @retval TRUE AML path is root.
17 @retval FALSE AML path is not root.
24 if ((Buffer
[0] == AML_ROOT_CHAR
) && (Buffer
[1] == 0)) {
32 Check if it is AML LeadName.
36 @retval TRUE Char is AML LeadName.
37 @retval FALSE Char is not AML LeadName.
44 if ((Ch
== '_') || (Ch
>= 'A' && Ch
<= 'Z')) {
52 Check if it is AML Name.
56 @retval TRUE Char is AML Name.
57 @retval FALSE Char is not AML Name.
64 if (AmlIsLeadName (Ch
) || (Ch
>= '0' && Ch
<= '9')) {
72 Return is buffer is AML NameSeg.
74 @param[in] Buffer AML NameSement.
76 @retval TRUE It is AML NameSegment.
77 @retval FALSE It is not AML NameSegment.
85 if (!AmlIsLeadName (Buffer
[0])) {
88 for (Index
= 1; Index
< AML_NAME_SEG_SIZE
; Index
++) {
89 if (!AmlIsName (Buffer
[Index
])) {
97 Get AML NameString size.
99 @param[in] Buffer AML NameString.
100 @param[out] BufferSize AML NameString size
102 @retval EFI_SUCCESS Success.
103 @retval EFI_INVALID_PARAMETER Buffer does not refer to a valid AML NameString.
106 AmlGetNameStringSize (
108 OUT UINTN
*BufferSize
118 // Parse root or parent prefix
120 if (*Buffer
== AML_ROOT_CHAR
) {
123 } else if (*Buffer
== AML_PARENT_PREFIX_CHAR
) {
127 } while (*Buffer
== AML_PARENT_PREFIX_CHAR
);
131 // Parse name segment
133 if (*Buffer
== AML_DUAL_NAME_PREFIX
) {
137 } else if (*Buffer
== AML_MULTI_NAME_PREFIX
) {
143 } else if (*Buffer
== 0) {
145 // NULL Name, only for Root
149 if ((Length
== 1) && (*Buffer
== AML_ROOT_CHAR
)) {
153 return EFI_INVALID_PARAMETER
;
164 if (!AmlIsNameSeg (Buffer
)) {
165 return EFI_INVALID_PARAMETER
;
167 Buffer
+= AML_NAME_SEG_SIZE
;
168 Length
+= AML_NAME_SEG_SIZE
;
170 } while (Index
< SegCount
);
172 *BufferSize
= Length
;
177 Check if it is ASL LeadName.
181 @retval TRUE Char is ASL LeadName.
182 @retval FALSE Char is not ASL LeadName.
189 if (AmlIsLeadName (Ch
) || (Ch
>= 'a' && Ch
<= 'z')) {
197 Check if it is ASL Name.
201 @retval TRUE Char is ASL Name.
202 @retval FALSE Char is not ASL Name.
209 if (AmlIsAslLeadName (Ch
) || (Ch
>= '0' && Ch
<= '9')) {
217 Get ASL NameString size.
219 @param[in] Buffer ASL NameString.
221 @return ASL NameString size.
224 AmlGetAslNameSegLength (
239 if (AmlIsAslLeadName (*Buffer
)) {
243 if ((*Buffer
== 0) || (*Buffer
== '.')) {
249 for (Index
= 0; Index
< 3; Index
++) {
250 if (AmlIsAslName (*Buffer
)) {
254 if ((*Buffer
== 0) || (*Buffer
== '.')) {
266 Get ASL NameString size.
268 @param[in] Buffer ASL NameString.
269 @param[out] Root On return, points to Root char number.
270 @param[out] Parent On return, points to Parent char number.
271 @param[out] SegCount On return, points to Segment count.
273 @return ASL NameString size.
276 AmlGetAslNameStringSize (
291 if (*Buffer
== AML_ROOT_CHAR
) {
294 } else if (*Buffer
== AML_PARENT_PREFIX_CHAR
) {
298 } while (*Buffer
== AML_PARENT_PREFIX_CHAR
);
304 while (*Buffer
!= 0) {
305 NameLength
= AmlGetAslNameSegLength (Buffer
);
306 if ((NameLength
== 0) || (NameLength
> AML_NAME_SEG_SIZE
)) {
310 Buffer
+= NameLength
;
320 if (*SegCount
> 0xFF) {
325 // Calculate total length
327 TotalLength
= *Root
+ *Parent
+ (*SegCount
) * AML_NAME_SEG_SIZE
;
330 } else if (*SegCount
== 2) {
343 Copy mem, and cast all the char in dest to be upper case.
345 @param[in] DstBuffer Destination buffer.
346 @param[in] SrcBuffer Source buffer.
347 @param[in] Length Buffer length.
350 AmlUpperCaseCopyMem (
358 for (Index
= 0; Index
< Length
; Index
++) {
359 if (SrcBuffer
[Index
] >= 'a' && SrcBuffer
[Index
] <= 'z') {
360 DstBuffer
[Index
] = (UINT8
)(SrcBuffer
[Index
] - 'a' + 'A');
362 DstBuffer
[Index
] = SrcBuffer
[Index
];
368 Return AML name according to ASL name.
369 The caller need free the AmlName returned.
371 @param[in] AslPath ASL name.
389 TotalLength
= AmlGetAslNameStringSize (AslPath
, &Root
, &Parent
, &SegCount
);
390 if (TotalLength
== 0) {
394 AmlPath
= AllocatePool (TotalLength
);
395 ASSERT (AmlPath
!= NULL
);
401 // Handle Root and Parent
404 *AmlBuffer
= AML_ROOT_CHAR
;
407 } else if (Parent
> 0) {
408 SetMem (AmlBuffer
, Parent
, AML_PARENT_PREFIX_CHAR
);
417 *AmlBuffer
= AML_MULTI_NAME_PREFIX
;
419 *AmlBuffer
= (UINT8
)SegCount
;
421 } else if (SegCount
== 2) {
422 *AmlBuffer
= AML_DUAL_NAME_PREFIX
;
429 while (*Buffer
!= 0) {
430 NameLength
= AmlGetAslNameSegLength (Buffer
);
431 ASSERT ((NameLength
!= 0) && (NameLength
<= AML_NAME_SEG_SIZE
));
432 AmlUpperCaseCopyMem (AmlBuffer
, Buffer
, NameLength
);
433 SetMem (AmlBuffer
+ NameLength
, AML_NAME_SEG_SIZE
- NameLength
, AML_NAME_CHAR__
);
434 Buffer
+= NameLength
;
435 AmlBuffer
+= AML_NAME_SEG_SIZE
;
445 AmlPath
[TotalLength
- 1] = 0;
453 @param[in] Buffer AML NameSeg.
460 DEBUG ((EFI_D_ERROR
, "%c", Buffer
[0]));
461 if ((Buffer
[1] == '_') && (Buffer
[2] == '_') && (Buffer
[3] == '_')) {
464 DEBUG ((EFI_D_ERROR
, "%c", Buffer
[1]));
465 if ((Buffer
[2] == '_') && (Buffer
[3] == '_')) {
468 DEBUG ((EFI_D_ERROR
, "%c", Buffer
[2]));
469 if (Buffer
[3] == '_') {
472 DEBUG ((EFI_D_ERROR
, "%c", Buffer
[3]));
477 Print AML NameString.
479 @param[in] Buffer AML NameString.
489 if (*Buffer
== AML_ROOT_CHAR
) {
494 DEBUG ((EFI_D_ERROR
, "\\"));
495 } else if (*Buffer
== AML_PARENT_PREFIX_CHAR
) {
501 DEBUG ((EFI_D_ERROR
, "^"));
502 } while (*Buffer
== AML_PARENT_PREFIX_CHAR
);
505 if (*Buffer
== AML_DUAL_NAME_PREFIX
) {
511 } else if (*Buffer
== AML_MULTI_NAME_PREFIX
) {
518 } else if (*Buffer
== 0) {
530 AmlPrintNameSeg (Buffer
);
531 Buffer
+= AML_NAME_SEG_SIZE
;
532 for (Index
= 0; Index
< SegCount
- 1; Index
++) {
533 DEBUG ((EFI_D_ERROR
, "."));
534 AmlPrintNameSeg (Buffer
);
535 Buffer
+= AML_NAME_SEG_SIZE
;