]>
git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/Acpi/AcpiTableDxe/AmlString.c
2 ACPI Sdt Protocol Driver
4 Copyright (c) 2010, Intel Corporation. All rights reserved. <BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "AcpiTable.h"
18 Check if it is AML Root name
20 @param[in] Buffer AML path.
22 @retval TRUE AML path is root.
23 @retval FALSE AML path is not root.
30 if ((Buffer
[0] == AML_ROOT_CHAR
) && (Buffer
[1] == 0)) {
38 Check if it is AML LeadName.
42 @retval TRUE Char is AML LeadName.
43 @retval FALSE Char is not AML LeadName.
50 if ((Ch
== '_') || (Ch
>= 'A' && Ch
<= 'Z')) {
58 Check if it is AML Name.
62 @retval TRUE Char is AML Name.
63 @retval FALSE Char is not AML Name.
70 if (AmlIsLeadName (Ch
) || (Ch
>= '0' && Ch
<= '9')) {
78 Return is buffer is AML NameSeg.
80 @param[in] Buffer AML NameSement.
82 @retval TRUE It is AML NameSegment.
83 @retval FALSE It is not AML NameSegment.
91 if (!AmlIsLeadName (Buffer
[0])) {
94 for (Index
= 1; Index
< AML_NAME_SEG_SIZE
; Index
++) {
95 if (!AmlIsName (Buffer
[Index
])) {
103 Get AML NameString size.
105 @param[in] Buffer AML NameString.
106 @param[out] BufferSize AML NameString size
108 @retval EFI_SUCCESS Success.
109 @retval EFI_INVALID_PARAMETER Buffer does not refer to a valid AML NameString.
112 AmlGetNameStringSize (
114 OUT UINTN
*BufferSize
126 // Parse root or parent prefix
128 if (*Buffer
== AML_ROOT_CHAR
) {
131 } else if (*Buffer
== AML_PARENT_PREFIX_CHAR
) {
135 } while (*Buffer
== AML_PARENT_PREFIX_CHAR
);
139 // Parse name segment
141 if (*Buffer
== AML_DUAL_NAME_PREFIX
) {
145 } else if (*Buffer
== AML_MULTI_NAME_PREFIX
) {
151 } else if (*Buffer
== 0) {
153 // NULL Name, only for Root
157 if ((Length
== 1) && (*Buffer
== AML_ROOT_CHAR
)) {
161 return EFI_INVALID_PARAMETER
;
172 if (!AmlIsNameSeg (Buffer
)) {
173 return EFI_INVALID_PARAMETER
;
175 Buffer
+= AML_NAME_SEG_SIZE
;
176 Length
+= AML_NAME_SEG_SIZE
;
178 } while (Index
< SegCount
);
180 *BufferSize
= Length
;
185 Check if it is ASL LeadName.
189 @retval TRUE Char is ASL LeadName.
190 @retval FALSE Char is not ASL LeadName.
197 if (AmlIsLeadName (Ch
) || (Ch
>= 'a' && Ch
<= 'z')) {
205 Check if it is ASL Name.
209 @retval TRUE Char is ASL Name.
210 @retval FALSE Char is not ASL Name.
217 if (AmlIsAslLeadName (Ch
) || (Ch
>= '0' && Ch
<= '9')) {
225 Get ASL NameString size.
227 @param[in] Buffer ASL NameString.
229 @return ASL NameString size.
232 AmlGetAslNameSegLength (
247 if (AmlIsAslLeadName (*Buffer
)) {
251 if ((*Buffer
== 0) || (*Buffer
== '.')) {
257 for (Index
= 0; Index
< 3; Index
++) {
258 if (AmlIsAslName (*Buffer
)) {
262 if ((*Buffer
== 0) || (*Buffer
== '.')) {
274 Get ASL NameString size.
276 @param[in] Buffer ASL NameString.
277 @param[out] Root On return, points to Root char number.
278 @param[out] Parent On return, points to Parent char number.
279 @param[out] SegCount On return, points to Segment count.
281 @return ASL NameString size.
284 AmlGetAslNameStringSize (
299 if (*Buffer
== AML_ROOT_CHAR
) {
302 } else if (*Buffer
== AML_PARENT_PREFIX_CHAR
) {
306 } while (*Buffer
== AML_PARENT_PREFIX_CHAR
);
312 while (*Buffer
!= 0) {
313 NameLength
= AmlGetAslNameSegLength (Buffer
);
314 if ((NameLength
== 0) || (NameLength
> AML_NAME_SEG_SIZE
)) {
318 Buffer
+= NameLength
;
328 if (*SegCount
> 0xFF) {
333 // Calculate total length
335 TotalLength
= *Root
+ *Parent
+ (*SegCount
) * AML_NAME_SEG_SIZE
;
338 } else if (*SegCount
== 2) {
351 Copy mem, and cast all the char in dest to be upper case.
353 @param[in] DstBuffer Destination buffer.
354 @param[in] SrcBuffer Source buffer.
355 @param[in] Length Buffer length.
358 AmlUpperCaseCopyMem (
366 for (Index
= 0; Index
< Length
; Index
++) {
367 if (SrcBuffer
[Index
] >= 'a' && SrcBuffer
[Index
] <= 'z') {
368 DstBuffer
[Index
] = (UINT8
)(SrcBuffer
[Index
] - 'a' + 'A');
370 DstBuffer
[Index
] = SrcBuffer
[Index
];
376 Return AML name according to ASL name.
377 The caller need free the AmlName returned.
379 @param[in] AslPath ASL name.
397 TotalLength
= AmlGetAslNameStringSize (AslPath
, &Root
, &Parent
, &SegCount
);
398 if (TotalLength
== 0) {
402 AmlPath
= AllocatePool (TotalLength
);
403 ASSERT (AmlPath
!= NULL
);
409 // Handle Root and Parent
412 *AmlBuffer
= AML_ROOT_CHAR
;
415 } else if (Parent
> 0) {
416 SetMem (AmlBuffer
, Parent
, AML_PARENT_PREFIX_CHAR
);
425 *AmlBuffer
= AML_MULTI_NAME_PREFIX
;
427 *AmlBuffer
= (UINT8
)SegCount
;
429 } else if (SegCount
== 2) {
430 *AmlBuffer
= AML_DUAL_NAME_PREFIX
;
437 while (*Buffer
!= 0) {
438 NameLength
= AmlGetAslNameSegLength (Buffer
);
439 ASSERT ((NameLength
!= 0) && (NameLength
<= AML_NAME_SEG_SIZE
));
440 AmlUpperCaseCopyMem (AmlBuffer
, Buffer
, NameLength
);
441 SetMem (AmlBuffer
+ NameLength
, AML_NAME_SEG_SIZE
- NameLength
, AML_NAME_CHAR__
);
442 Buffer
+= NameLength
;
443 AmlBuffer
+= AML_NAME_SEG_SIZE
;
453 AmlPath
[TotalLength
- 1] = 0;
461 @param[in] Buffer AML NameSeg.
468 DEBUG ((EFI_D_ERROR
, "%c", Buffer
[0]));
469 if ((Buffer
[1] == '_') && (Buffer
[2] == '_') && (Buffer
[3] == '_')) {
472 DEBUG ((EFI_D_ERROR
, "%c", Buffer
[1]));
473 if ((Buffer
[2] == '_') && (Buffer
[3] == '_')) {
476 DEBUG ((EFI_D_ERROR
, "%c", Buffer
[2]));
477 if (Buffer
[3] == '_') {
480 DEBUG ((EFI_D_ERROR
, "%c", Buffer
[3]));
485 Print AML NameString.
487 @param[in] Buffer AML NameString.
499 if (*Buffer
== AML_ROOT_CHAR
) {
504 DEBUG ((EFI_D_ERROR
, "\\"));
505 } else if (*Buffer
== AML_PARENT_PREFIX_CHAR
) {
511 DEBUG ((EFI_D_ERROR
, "^"));
512 } while (*Buffer
== AML_PARENT_PREFIX_CHAR
);
515 if (*Buffer
== AML_DUAL_NAME_PREFIX
) {
521 } else if (*Buffer
== AML_MULTI_NAME_PREFIX
) {
528 } else if (*Buffer
== 0) {
540 AmlPrintNameSeg (Buffer
);
541 Buffer
+= AML_NAME_SEG_SIZE
;
542 for (Index
= 0; Index
< SegCount
- 1; Index
++) {
543 DEBUG ((EFI_D_ERROR
, "."));
544 AmlPrintNameSeg (Buffer
);
545 Buffer
+= AML_NAME_SEG_SIZE
;