]>
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.
86 if (!AmlIsLeadName (Buffer
[0])) {
90 for (Index
= 1; Index
< AML_NAME_SEG_SIZE
; Index
++) {
91 if (!AmlIsName (Buffer
[Index
])) {
100 Get AML NameString size.
102 @param[in] Buffer AML NameString.
103 @param[out] BufferSize AML NameString size
105 @retval EFI_SUCCESS Success.
106 @retval EFI_INVALID_PARAMETER Buffer does not refer to a valid AML NameString.
109 AmlGetNameStringSize (
111 OUT UINTN
*BufferSize
121 // Parse root or parent prefix
123 if (*Buffer
== AML_ROOT_CHAR
) {
126 } else if (*Buffer
== AML_PARENT_PREFIX_CHAR
) {
130 } while (*Buffer
== AML_PARENT_PREFIX_CHAR
);
134 // Parse name segment
136 if (*Buffer
== AML_DUAL_NAME_PREFIX
) {
140 } else if (*Buffer
== AML_MULTI_NAME_PREFIX
) {
146 } else if (*Buffer
== 0) {
148 // NULL Name, only for Root
152 if ((Length
== 1) && (*Buffer
== AML_ROOT_CHAR
)) {
156 return EFI_INVALID_PARAMETER
;
167 if (!AmlIsNameSeg (Buffer
)) {
168 return EFI_INVALID_PARAMETER
;
171 Buffer
+= AML_NAME_SEG_SIZE
;
172 Length
+= AML_NAME_SEG_SIZE
;
174 } while (Index
< SegCount
);
176 *BufferSize
= Length
;
181 Check if it is ASL LeadName.
185 @retval TRUE Char is ASL LeadName.
186 @retval FALSE Char is not ASL LeadName.
193 if (AmlIsLeadName (Ch
) || ((Ch
>= 'a') && (Ch
<= 'z'))) {
201 Check if it is ASL Name.
205 @retval TRUE Char is ASL Name.
206 @retval FALSE Char is not ASL Name.
213 if (AmlIsAslLeadName (Ch
) || ((Ch
>= '0') && (Ch
<= '9'))) {
221 Get ASL NameString size.
223 @param[in] Buffer ASL NameString.
225 @return ASL NameString size.
228 AmlGetAslNameSegLength (
243 if (AmlIsAslLeadName (*Buffer
)) {
248 if ((*Buffer
== 0) || (*Buffer
== '.')) {
255 for (Index
= 0; Index
< 3; Index
++) {
256 if (AmlIsAslName (*Buffer
)) {
261 if ((*Buffer
== 0) || (*Buffer
== '.')) {
273 Get ASL NameString size.
275 @param[in] Buffer ASL NameString.
276 @param[out] Root On return, points to Root char number.
277 @param[out] Parent On return, points to Parent char number.
278 @param[out] SegCount On return, points to Segment count.
280 @return ASL NameString size.
283 AmlGetAslNameStringSize (
298 if (*Buffer
== AML_ROOT_CHAR
) {
301 } else if (*Buffer
== AML_PARENT_PREFIX_CHAR
) {
305 } while (*Buffer
== AML_PARENT_PREFIX_CHAR
);
311 while (*Buffer
!= 0) {
312 NameLength
= AmlGetAslNameSegLength (Buffer
);
313 if ((NameLength
== 0) || (NameLength
> AML_NAME_SEG_SIZE
)) {
318 Buffer
+= NameLength
;
329 if (*SegCount
> 0xFF) {
334 // Calculate total length
336 TotalLength
= *Root
+ *Parent
+ (*SegCount
) * AML_NAME_SEG_SIZE
;
339 } else if (*SegCount
== 2) {
352 Copy mem, and cast all the char in dest to be upper case.
354 @param[in] DstBuffer Destination buffer.
355 @param[in] SrcBuffer Source buffer.
356 @param[in] Length Buffer length.
359 AmlUpperCaseCopyMem (
367 for (Index
= 0; Index
< Length
; Index
++) {
368 if ((SrcBuffer
[Index
] >= 'a') && (SrcBuffer
[Index
] <= 'z')) {
369 DstBuffer
[Index
] = (UINT8
)(SrcBuffer
[Index
] - 'a' + 'A');
371 DstBuffer
[Index
] = SrcBuffer
[Index
];
377 Return AML name according to ASL name.
378 The caller need free the AmlName returned.
380 @param[in] AslPath ASL name.
398 TotalLength
= AmlGetAslNameStringSize (AslPath
, &Root
, &Parent
, &SegCount
);
399 if (TotalLength
== 0) {
403 AmlPath
= AllocatePool (TotalLength
);
404 ASSERT (AmlPath
!= NULL
);
410 // Handle Root and Parent
413 *AmlBuffer
= AML_ROOT_CHAR
;
416 } else if (Parent
> 0) {
417 SetMem (AmlBuffer
, Parent
, AML_PARENT_PREFIX_CHAR
);
426 *AmlBuffer
= AML_MULTI_NAME_PREFIX
;
428 *AmlBuffer
= (UINT8
)SegCount
;
430 } else if (SegCount
== 2) {
431 *AmlBuffer
= AML_DUAL_NAME_PREFIX
;
438 while (*Buffer
!= 0) {
439 NameLength
= AmlGetAslNameSegLength (Buffer
);
440 ASSERT ((NameLength
!= 0) && (NameLength
<= AML_NAME_SEG_SIZE
));
441 AmlUpperCaseCopyMem (AmlBuffer
, Buffer
, NameLength
);
442 SetMem (AmlBuffer
+ NameLength
, AML_NAME_SEG_SIZE
- NameLength
, AML_NAME_CHAR__
);
443 Buffer
+= NameLength
;
444 AmlBuffer
+= AML_NAME_SEG_SIZE
;
455 AmlPath
[TotalLength
- 1] = 0;
463 @param[in] Buffer AML NameSeg.
470 DEBUG ((DEBUG_ERROR
, "%c", Buffer
[0]));
471 if ((Buffer
[1] == '_') && (Buffer
[2] == '_') && (Buffer
[3] == '_')) {
475 DEBUG ((DEBUG_ERROR
, "%c", Buffer
[1]));
476 if ((Buffer
[2] == '_') && (Buffer
[3] == '_')) {
480 DEBUG ((DEBUG_ERROR
, "%c", Buffer
[2]));
481 if (Buffer
[3] == '_') {
485 DEBUG ((DEBUG_ERROR
, "%c", Buffer
[3]));
490 Print AML NameString.
492 @param[in] Buffer AML NameString.
502 if (*Buffer
== AML_ROOT_CHAR
) {
507 DEBUG ((DEBUG_ERROR
, "\\"));
508 } else if (*Buffer
== AML_PARENT_PREFIX_CHAR
) {
514 DEBUG ((DEBUG_ERROR
, "^"));
515 } while (*Buffer
== AML_PARENT_PREFIX_CHAR
);
518 if (*Buffer
== AML_DUAL_NAME_PREFIX
) {
524 } else if (*Buffer
== AML_MULTI_NAME_PREFIX
) {
531 } else if (*Buffer
== 0) {
543 AmlPrintNameSeg (Buffer
);
544 Buffer
+= AML_NAME_SEG_SIZE
;
545 for (Index
= 0; Index
< SegCount
- 1; Index
++) {
546 DEBUG ((DEBUG_ERROR
, "."));
547 AmlPrintNameSeg (Buffer
);
548 Buffer
+= AML_NAME_SEG_SIZE
;