1 /******************************************************************************
3 * Module Name: exnames - interpreter/scanner name load/execute
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
51 #define _COMPONENT ACPI_EXECUTER
52 ACPI_MODULE_NAME ("exnames")
54 /* Local prototypes */
57 AcpiExAllocateNameString (
67 /*******************************************************************************
69 * FUNCTION: AcpiExAllocateNameString
71 * PARAMETERS: PrefixCount - Count of parent levels. Special cases:
73 * NumNameSegs - count of 4-character name segments
75 * RETURN: A pointer to the allocated string segment. This segment must
76 * be deleted by the caller.
78 * DESCRIPTION: Allocate a buffer for a name string. Ensure allocated name
79 * string is long enough, and set up prefix if any.
81 ******************************************************************************/
84 AcpiExAllocateNameString (
92 ACPI_FUNCTION_TRACE (ExAllocateNameString
);
96 * Allow room for all \ and ^ prefixes, all segments and a MultiNamePrefix.
97 * Also, one byte for the null terminator.
98 * This may actually be somewhat longer than needed.
100 if (PrefixCount
== ACPI_UINT32_MAX
)
102 /* Special case for root */
104 SizeNeeded
= 1 + (ACPI_NAME_SIZE
* NumNameSegs
) + 2 + 1;
108 SizeNeeded
= PrefixCount
+ (ACPI_NAME_SIZE
* NumNameSegs
) + 2 + 1;
112 * Allocate a buffer for the name.
113 * This buffer must be deleted by the caller!
115 NameString
= ACPI_ALLOCATE (SizeNeeded
);
118 ACPI_ERROR ((AE_INFO
,
119 "Could not allocate size %u", SizeNeeded
));
123 TempPtr
= NameString
;
125 /* Set up Root or Parent prefixes if needed */
127 if (PrefixCount
== ACPI_UINT32_MAX
)
129 *TempPtr
++ = AML_ROOT_PREFIX
;
133 while (PrefixCount
--)
135 *TempPtr
++ = AML_PARENT_PREFIX
;
140 /* Set up Dual or Multi prefixes if needed */
144 /* Set up multi prefixes */
146 *TempPtr
++ = AML_MULTI_NAME_PREFIX_OP
;
147 *TempPtr
++ = (char) NumNameSegs
;
149 else if (2 == NumNameSegs
)
151 /* Set up dual prefixes */
153 *TempPtr
++ = AML_DUAL_NAME_PREFIX
;
157 * Terminate string following prefixes. AcpiExNameSegment() will
158 * append the segment(s)
162 return_PTR (NameString
);
165 /*******************************************************************************
167 * FUNCTION: AcpiExNameSegment
169 * PARAMETERS: InAmlAddress - Pointer to the name in the AML code
170 * NameString - Where to return the name. The name is appended
171 * to any existing string to form a namepath
175 * DESCRIPTION: Extract an ACPI name (4 bytes) from the AML byte stream
177 ******************************************************************************/
181 UINT8
**InAmlAddress
,
184 char *AmlAddress
= (void *) *InAmlAddress
;
185 ACPI_STATUS Status
= AE_OK
;
190 ACPI_FUNCTION_TRACE (ExNameSegment
);
194 * If first character is a digit, then we know that we aren't looking at a
197 CharBuf
[0] = *AmlAddress
;
199 if ('0' <= CharBuf
[0] && CharBuf
[0] <= '9')
201 ACPI_ERROR ((AE_INFO
, "Invalid leading digit: %c", CharBuf
[0]));
202 return_ACPI_STATUS (AE_CTRL_PENDING
);
205 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD
, "Bytes from stream:\n"));
208 (Index
< ACPI_NAME_SIZE
) && (AcpiUtValidAcpiChar (*AmlAddress
, 0));
211 CharBuf
[Index
] = *AmlAddress
++;
212 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD
, "%c\n", CharBuf
[Index
]));
216 /* Valid name segment */
220 /* Found 4 valid characters */
226 ACPI_STRCAT (NameString
, CharBuf
);
227 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
228 "Appended to - %s\n", NameString
));
232 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES
,
233 "No Name string - %s\n", CharBuf
));
239 * First character was not a valid name character,
240 * so we are looking at something other than a name.
242 ACPI_DEBUG_PRINT ((ACPI_DB_INFO
,
243 "Leading character is not alpha: %02Xh (not a name)\n",
245 Status
= AE_CTRL_PENDING
;
250 * Segment started with one or more valid characters, but fewer than
253 Status
= AE_AML_BAD_NAME
;
254 ACPI_ERROR ((AE_INFO
,
255 "Bad character 0x%02x in name, at %p",
256 *AmlAddress
, AmlAddress
));
259 *InAmlAddress
= ACPI_CAST_PTR (UINT8
, AmlAddress
);
260 return_ACPI_STATUS (Status
);
264 /*******************************************************************************
266 * FUNCTION: AcpiExGetNameString
268 * PARAMETERS: DataType - Object type to be associated with this
270 * InAmlAddress - Pointer to the namestring in the AML code
271 * OutNameString - Where the namestring is returned
272 * OutNameLength - Length of the returned string
274 * RETURN: Status, namestring and length
276 * DESCRIPTION: Extract a full namepath from the AML byte stream,
277 * including any prefixes.
279 ******************************************************************************/
282 AcpiExGetNameString (
283 ACPI_OBJECT_TYPE DataType
,
285 char **OutNameString
,
286 UINT32
*OutNameLength
)
288 ACPI_STATUS Status
= AE_OK
;
289 UINT8
*AmlAddress
= InAmlAddress
;
290 char *NameString
= NULL
;
292 UINT32 PrefixCount
= 0;
293 BOOLEAN HasPrefix
= FALSE
;
296 ACPI_FUNCTION_TRACE_PTR (ExGetNameString
, AmlAddress
);
299 if (ACPI_TYPE_LOCAL_REGION_FIELD
== DataType
||
300 ACPI_TYPE_LOCAL_BANK_FIELD
== DataType
||
301 ACPI_TYPE_LOCAL_INDEX_FIELD
== DataType
)
303 /* Disallow prefixes for types associated with FieldUnit names */
305 NameString
= AcpiExAllocateNameString (0, 1);
308 Status
= AE_NO_MEMORY
;
312 Status
= AcpiExNameSegment (&AmlAddress
, NameString
);
318 * DataType is not a field name.
319 * Examine first character of name for root or parent prefix operators
323 case AML_ROOT_PREFIX
:
325 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD
, "RootPrefix(\\) at %p\n",
329 * Remember that we have a RootPrefix --
330 * see comment in AcpiExAllocateNameString()
333 PrefixCount
= ACPI_UINT32_MAX
;
337 case AML_PARENT_PREFIX
:
339 /* Increment past possibly multiple parent prefixes */
343 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD
, "ParentPrefix (^) at %p\n",
349 } while (*AmlAddress
== AML_PARENT_PREFIX
);
356 /* Not a prefix character */
361 /* Examine first character of name for name segment prefix operator */
365 case AML_DUAL_NAME_PREFIX
:
367 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD
, "DualNamePrefix at %p\n",
371 NameString
= AcpiExAllocateNameString (PrefixCount
, 2);
374 Status
= AE_NO_MEMORY
;
378 /* Indicate that we processed a prefix */
382 Status
= AcpiExNameSegment (&AmlAddress
, NameString
);
383 if (ACPI_SUCCESS (Status
))
385 Status
= AcpiExNameSegment (&AmlAddress
, NameString
);
389 case AML_MULTI_NAME_PREFIX_OP
:
391 ACPI_DEBUG_PRINT ((ACPI_DB_LOAD
, "MultiNamePrefix at %p\n",
394 /* Fetch count of segments remaining in name path */
397 NumSegments
= *AmlAddress
;
399 NameString
= AcpiExAllocateNameString (PrefixCount
, NumSegments
);
402 Status
= AE_NO_MEMORY
;
406 /* Indicate that we processed a prefix */
411 while (NumSegments
&&
412 (Status
= AcpiExNameSegment (&AmlAddress
, NameString
)) ==
422 /* NullName valid as of 8-12-98 ASL/AML Grammar Update */
424 if (PrefixCount
== ACPI_UINT32_MAX
)
426 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
427 "NameSeg is \"\\\" followed by NULL\n"));
430 /* Consume the NULL byte */
433 NameString
= AcpiExAllocateNameString (PrefixCount
, 0);
436 Status
= AE_NO_MEMORY
;
444 /* Name segment string */
446 NameString
= AcpiExAllocateNameString (PrefixCount
, 1);
449 Status
= AE_NO_MEMORY
;
453 Status
= AcpiExNameSegment (&AmlAddress
, NameString
);
458 if (AE_CTRL_PENDING
== Status
&& HasPrefix
)
460 /* Ran out of segments after processing a prefix */
462 ACPI_ERROR ((AE_INFO
,
463 "Malformed Name at %p", NameString
));
464 Status
= AE_AML_BAD_NAME
;
467 if (ACPI_FAILURE (Status
))
471 ACPI_FREE (NameString
);
473 return_ACPI_STATUS (Status
);
476 *OutNameString
= NameString
;
477 *OutNameLength
= (UINT32
) (AmlAddress
- InAmlAddress
);
479 return_ACPI_STATUS (Status
);