Deleted Added
full compact
nsutils.c (99146) nsutils.c (99679)
1/******************************************************************************
2 *
3 * Module Name: nsutils - Utilities for accessing ACPI namespace, accessing
4 * parents and siblings and Scope manipulation
1/******************************************************************************
2 *
3 * Module Name: nsutils - Utilities for accessing ACPI namespace, accessing
4 * parents and siblings and Scope manipulation
5 * $Revision: 105 $
5 * $Revision: 110 $
6 *
7 *****************************************************************************/
8
9/******************************************************************************
10 *
11 * 1. Copyright Notice
12 *
13 * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.
14 * All rights reserved.
15 *
16 * 2. License
17 *
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights. You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
21 * property rights.
22 *
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
29 *
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code. No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
38 *
39 * The above copyright and patent license is granted only if the following
40 * conditions are met:
41 *
42 * 3. Conditions
43 *
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision. In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change. Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee. Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
55 *
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution. In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
66 * make.
67 *
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
72 * distribution.
73 *
74 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * Intel Code.
76 *
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
81 *
82 * 4. Disclaimer and Export Compliance
83 *
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * PARTICULAR PURPOSE.
91 *
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * LIMITED REMEDY.
100 *
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government. In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
115 *
116 *****************************************************************************/
117
118#define __NSUTILS_C__
119
120#include "acpi.h"
121#include "acnamesp.h"
6 *
7 *****************************************************************************/
8
9/******************************************************************************
10 *
11 * 1. Copyright Notice
12 *
13 * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.
14 * All rights reserved.
15 *
16 * 2. License
17 *
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights. You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
21 * property rights.
22 *
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
29 *
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code. No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
38 *
39 * The above copyright and patent license is granted only if the following
40 * conditions are met:
41 *
42 * 3. Conditions
43 *
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision. In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change. Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee. Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
55 *
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution. In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
66 * make.
67 *
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
72 * distribution.
73 *
74 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * Intel Code.
76 *
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
81 *
82 * 4. Disclaimer and Export Compliance
83 *
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * PARTICULAR PURPOSE.
91 *
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * LIMITED REMEDY.
100 *
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government. In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
115 *
116 *****************************************************************************/
117
118#define __NSUTILS_C__
119
120#include "acpi.h"
121#include "acnamesp.h"
122#include "acinterp.h"
123#include "amlcode.h"
124#include "actables.h"
125
126#define _COMPONENT ACPI_NAMESPACE
127 ACPI_MODULE_NAME ("nsutils")
128
129
130/*******************************************************************************
131 *
132 * FUNCTION: AcpiNsValidRootPrefix
133 *
134 * PARAMETERS: Prefix - Character to be checked
135 *
136 * RETURN: TRUE if a valid prefix
137 *
138 * DESCRIPTION: Check if a character is a valid ACPI Root prefix
139 *
140 ******************************************************************************/
141
142BOOLEAN
143AcpiNsValidRootPrefix (
144 NATIVE_CHAR Prefix)
145{
146
147 return ((BOOLEAN) (Prefix == '\\'));
148}
149
150
151/*******************************************************************************
152 *
153 * FUNCTION: AcpiNsValidPathSeparator
154 *
155 * PARAMETERS: Sep - Character to be checked
156 *
157 * RETURN: TRUE if a valid path separator
158 *
159 * DESCRIPTION: Check if a character is a valid ACPI path separator
160 *
161 ******************************************************************************/
162
163BOOLEAN
164AcpiNsValidPathSeparator (
165 NATIVE_CHAR Sep)
166{
167
168 return ((BOOLEAN) (Sep == '.'));
169}
170
171
172/*******************************************************************************
173 *
174 * FUNCTION: AcpiNsGetType
175 *
176 * PARAMETERS: Handle - Parent Node to be examined
177 *
178 * RETURN: Type field from Node whose handle is passed
179 *
180 ******************************************************************************/
181
182ACPI_OBJECT_TYPE
183AcpiNsGetType (
184 ACPI_NAMESPACE_NODE *Node)
185{
186 ACPI_FUNCTION_TRACE ("NsGetType");
187
188
189 if (!Node)
190 {
191 ACPI_REPORT_WARNING (("NsGetType: Null Node ptr"));
192 return_VALUE (ACPI_TYPE_ANY);
193 }
194
195 return_VALUE ((ACPI_OBJECT_TYPE) Node->Type);
196}
197
198
199/*******************************************************************************
200 *
201 * FUNCTION: AcpiNsLocal
202 *
203 * PARAMETERS: Type - A namespace object type
204 *
205 * RETURN: LOCAL if names must be found locally in objects of the
206 * passed type, 0 if enclosing scopes should be searched
207 *
208 ******************************************************************************/
209
210UINT32
211AcpiNsLocal (
212 ACPI_OBJECT_TYPE Type)
213{
214 ACPI_FUNCTION_TRACE ("NsLocal");
215
216
217 if (!AcpiUtValidObjectType (Type))
218 {
219 /* Type code out of range */
220
221 ACPI_REPORT_WARNING (("NsLocal: Invalid Object Type\n"));
222 return_VALUE (ACPI_NS_NORMAL);
223 }
224
225 return_VALUE ((UINT32) AcpiGbl_NsProperties[Type] & ACPI_NS_LOCAL);
226}
227
228
229/*******************************************************************************
230 *
231 * FUNCTION: AcpiNsGetInternalNameLength
232 *
233 * PARAMETERS: Info - Info struct initialized with the
234 * external name pointer.
235 *
236 * RETURN: Status
237 *
238 * DESCRIPTION: Calculate the length of the internal (AML) namestring
239 * corresponding to the external (ASL) namestring.
240 *
241 ******************************************************************************/
242
122#include "amlcode.h"
123#include "actables.h"
124
125#define _COMPONENT ACPI_NAMESPACE
126 ACPI_MODULE_NAME ("nsutils")
127
128
129/*******************************************************************************
130 *
131 * FUNCTION: AcpiNsValidRootPrefix
132 *
133 * PARAMETERS: Prefix - Character to be checked
134 *
135 * RETURN: TRUE if a valid prefix
136 *
137 * DESCRIPTION: Check if a character is a valid ACPI Root prefix
138 *
139 ******************************************************************************/
140
141BOOLEAN
142AcpiNsValidRootPrefix (
143 NATIVE_CHAR Prefix)
144{
145
146 return ((BOOLEAN) (Prefix == '\\'));
147}
148
149
150/*******************************************************************************
151 *
152 * FUNCTION: AcpiNsValidPathSeparator
153 *
154 * PARAMETERS: Sep - Character to be checked
155 *
156 * RETURN: TRUE if a valid path separator
157 *
158 * DESCRIPTION: Check if a character is a valid ACPI path separator
159 *
160 ******************************************************************************/
161
162BOOLEAN
163AcpiNsValidPathSeparator (
164 NATIVE_CHAR Sep)
165{
166
167 return ((BOOLEAN) (Sep == '.'));
168}
169
170
171/*******************************************************************************
172 *
173 * FUNCTION: AcpiNsGetType
174 *
175 * PARAMETERS: Handle - Parent Node to be examined
176 *
177 * RETURN: Type field from Node whose handle is passed
178 *
179 ******************************************************************************/
180
181ACPI_OBJECT_TYPE
182AcpiNsGetType (
183 ACPI_NAMESPACE_NODE *Node)
184{
185 ACPI_FUNCTION_TRACE ("NsGetType");
186
187
188 if (!Node)
189 {
190 ACPI_REPORT_WARNING (("NsGetType: Null Node ptr"));
191 return_VALUE (ACPI_TYPE_ANY);
192 }
193
194 return_VALUE ((ACPI_OBJECT_TYPE) Node->Type);
195}
196
197
198/*******************************************************************************
199 *
200 * FUNCTION: AcpiNsLocal
201 *
202 * PARAMETERS: Type - A namespace object type
203 *
204 * RETURN: LOCAL if names must be found locally in objects of the
205 * passed type, 0 if enclosing scopes should be searched
206 *
207 ******************************************************************************/
208
209UINT32
210AcpiNsLocal (
211 ACPI_OBJECT_TYPE Type)
212{
213 ACPI_FUNCTION_TRACE ("NsLocal");
214
215
216 if (!AcpiUtValidObjectType (Type))
217 {
218 /* Type code out of range */
219
220 ACPI_REPORT_WARNING (("NsLocal: Invalid Object Type\n"));
221 return_VALUE (ACPI_NS_NORMAL);
222 }
223
224 return_VALUE ((UINT32) AcpiGbl_NsProperties[Type] & ACPI_NS_LOCAL);
225}
226
227
228/*******************************************************************************
229 *
230 * FUNCTION: AcpiNsGetInternalNameLength
231 *
232 * PARAMETERS: Info - Info struct initialized with the
233 * external name pointer.
234 *
235 * RETURN: Status
236 *
237 * DESCRIPTION: Calculate the length of the internal (AML) namestring
238 * corresponding to the external (ASL) namestring.
239 *
240 ******************************************************************************/
241
243ACPI_STATUS
242void
244AcpiNsGetInternalNameLength (
245 ACPI_NAMESTRING_INFO *Info)
246{
247 NATIVE_CHAR *NextExternalChar;
248 UINT32 i;
249
250
251 ACPI_FUNCTION_ENTRY ();
252
253
254 NextExternalChar = Info->ExternalName;
255 Info->NumCarats = 0;
256 Info->NumSegments = 0;
257 Info->FullyQualified = FALSE;
258
259 /*
260 * For the internal name, the required length is 4 bytes
261 * per segment, plus 1 each for RootPrefix, MultiNamePrefixOp,
262 * segment count, trailing null (which is not really needed,
263 * but no there's harm in putting it there)
264 *
265 * strlen() + 1 covers the first NameSeg, which has no
266 * path separator
267 */
268 if (AcpiNsValidRootPrefix (NextExternalChar[0]))
269 {
270 Info->FullyQualified = TRUE;
271 NextExternalChar++;
272 }
273 else
274 {
275 /*
276 * Handle Carat prefixes
277 */
278 while (*NextExternalChar == '^')
279 {
280 Info->NumCarats++;
281 NextExternalChar++;
282 }
283 }
284
285 /*
286 * Determine the number of ACPI name "segments" by counting
287 * the number of path separators within the string. Start
288 * with one segment since the segment count is (# separators)
289 * + 1, and zero separators is ok.
290 */
291 if (*NextExternalChar)
292 {
293 Info->NumSegments = 1;
294 for (i = 0; NextExternalChar[i]; i++)
295 {
296 if (AcpiNsValidPathSeparator (NextExternalChar[i]))
297 {
298 Info->NumSegments++;
299 }
300 }
301 }
302
303 Info->Length = (ACPI_NAME_SIZE * Info->NumSegments) +
304 4 + Info->NumCarats;
305
306 Info->NextExternalChar = NextExternalChar;
243AcpiNsGetInternalNameLength (
244 ACPI_NAMESTRING_INFO *Info)
245{
246 NATIVE_CHAR *NextExternalChar;
247 UINT32 i;
248
249
250 ACPI_FUNCTION_ENTRY ();
251
252
253 NextExternalChar = Info->ExternalName;
254 Info->NumCarats = 0;
255 Info->NumSegments = 0;
256 Info->FullyQualified = FALSE;
257
258 /*
259 * For the internal name, the required length is 4 bytes
260 * per segment, plus 1 each for RootPrefix, MultiNamePrefixOp,
261 * segment count, trailing null (which is not really needed,
262 * but no there's harm in putting it there)
263 *
264 * strlen() + 1 covers the first NameSeg, which has no
265 * path separator
266 */
267 if (AcpiNsValidRootPrefix (NextExternalChar[0]))
268 {
269 Info->FullyQualified = TRUE;
270 NextExternalChar++;
271 }
272 else
273 {
274 /*
275 * Handle Carat prefixes
276 */
277 while (*NextExternalChar == '^')
278 {
279 Info->NumCarats++;
280 NextExternalChar++;
281 }
282 }
283
284 /*
285 * Determine the number of ACPI name "segments" by counting
286 * the number of path separators within the string. Start
287 * with one segment since the segment count is (# separators)
288 * + 1, and zero separators is ok.
289 */
290 if (*NextExternalChar)
291 {
292 Info->NumSegments = 1;
293 for (i = 0; NextExternalChar[i]; i++)
294 {
295 if (AcpiNsValidPathSeparator (NextExternalChar[i]))
296 {
297 Info->NumSegments++;
298 }
299 }
300 }
301
302 Info->Length = (ACPI_NAME_SIZE * Info->NumSegments) +
303 4 + Info->NumCarats;
304
305 Info->NextExternalChar = NextExternalChar;
307
308 return (AE_OK);
309}
310
311
312/*******************************************************************************
313 *
314 * FUNCTION: AcpiNsBuildInternalName
315 *
316 * PARAMETERS: Info - Info struct fully initialized
317 *
318 * RETURN: Status
319 *
320 * DESCRIPTION: Construct the internal (AML) namestring
321 * corresponding to the external (ASL) namestring.
322 *
323 ******************************************************************************/
324
325ACPI_STATUS
326AcpiNsBuildInternalName (
327 ACPI_NAMESTRING_INFO *Info)
328{
329 UINT32 NumSegments = Info->NumSegments;
330 NATIVE_CHAR *InternalName = Info->InternalName;
331 NATIVE_CHAR *ExternalName = Info->NextExternalChar;
332 NATIVE_CHAR *Result = NULL;
306}
307
308
309/*******************************************************************************
310 *
311 * FUNCTION: AcpiNsBuildInternalName
312 *
313 * PARAMETERS: Info - Info struct fully initialized
314 *
315 * RETURN: Status
316 *
317 * DESCRIPTION: Construct the internal (AML) namestring
318 * corresponding to the external (ASL) namestring.
319 *
320 ******************************************************************************/
321
322ACPI_STATUS
323AcpiNsBuildInternalName (
324 ACPI_NAMESTRING_INFO *Info)
325{
326 UINT32 NumSegments = Info->NumSegments;
327 NATIVE_CHAR *InternalName = Info->InternalName;
328 NATIVE_CHAR *ExternalName = Info->NextExternalChar;
329 NATIVE_CHAR *Result = NULL;
333 UINT32 i;
330 NATIVE_UINT i;
334
335
336 ACPI_FUNCTION_TRACE ("NsBuildInternalName");
337
338
339 /* Setup the correct prefixes, counts, and pointers */
340
341 if (Info->FullyQualified)
342 {
343 InternalName[0] = '\\';
344
345 if (NumSegments <= 1)
346 {
347 Result = &InternalName[1];
348 }
349 else if (NumSegments == 2)
350 {
351 InternalName[1] = AML_DUAL_NAME_PREFIX;
352 Result = &InternalName[2];
353 }
354 else
355 {
356 InternalName[1] = AML_MULTI_NAME_PREFIX_OP;
357 InternalName[2] = (char) NumSegments;
358 Result = &InternalName[3];
359 }
360 }
361 else
362 {
363 /*
364 * Not fully qualified.
365 * Handle Carats first, then append the name segments
366 */
367 i = 0;
368 if (Info->NumCarats)
369 {
370 for (i = 0; i < Info->NumCarats; i++)
371 {
372 InternalName[i] = '^';
373 }
374 }
375
376 if (NumSegments <= 1)
377 {
378 Result = &InternalName[i];
379 }
380 else if (NumSegments == 2)
381 {
382 InternalName[i] = AML_DUAL_NAME_PREFIX;
383 Result = &InternalName[i+1];
384 }
385 else
386 {
387 InternalName[i] = AML_MULTI_NAME_PREFIX_OP;
388 InternalName[i+1] = (char) NumSegments;
389 Result = &InternalName[i+2];
390 }
391 }
392
393 /* Build the name (minus path separators) */
394
395 for (; NumSegments; NumSegments--)
396 {
397 for (i = 0; i < ACPI_NAME_SIZE; i++)
398 {
399 if (AcpiNsValidPathSeparator (*ExternalName) ||
400 (*ExternalName == 0))
401 {
402 /* Pad the segment with underscore(s) if segment is short */
403
404 Result[i] = '_';
405 }
406 else
407 {
408 /* Convert the character to uppercase and save it */
409
331
332
333 ACPI_FUNCTION_TRACE ("NsBuildInternalName");
334
335
336 /* Setup the correct prefixes, counts, and pointers */
337
338 if (Info->FullyQualified)
339 {
340 InternalName[0] = '\\';
341
342 if (NumSegments <= 1)
343 {
344 Result = &InternalName[1];
345 }
346 else if (NumSegments == 2)
347 {
348 InternalName[1] = AML_DUAL_NAME_PREFIX;
349 Result = &InternalName[2];
350 }
351 else
352 {
353 InternalName[1] = AML_MULTI_NAME_PREFIX_OP;
354 InternalName[2] = (char) NumSegments;
355 Result = &InternalName[3];
356 }
357 }
358 else
359 {
360 /*
361 * Not fully qualified.
362 * Handle Carats first, then append the name segments
363 */
364 i = 0;
365 if (Info->NumCarats)
366 {
367 for (i = 0; i < Info->NumCarats; i++)
368 {
369 InternalName[i] = '^';
370 }
371 }
372
373 if (NumSegments <= 1)
374 {
375 Result = &InternalName[i];
376 }
377 else if (NumSegments == 2)
378 {
379 InternalName[i] = AML_DUAL_NAME_PREFIX;
380 Result = &InternalName[i+1];
381 }
382 else
383 {
384 InternalName[i] = AML_MULTI_NAME_PREFIX_OP;
385 InternalName[i+1] = (char) NumSegments;
386 Result = &InternalName[i+2];
387 }
388 }
389
390 /* Build the name (minus path separators) */
391
392 for (; NumSegments; NumSegments--)
393 {
394 for (i = 0; i < ACPI_NAME_SIZE; i++)
395 {
396 if (AcpiNsValidPathSeparator (*ExternalName) ||
397 (*ExternalName == 0))
398 {
399 /* Pad the segment with underscore(s) if segment is short */
400
401 Result[i] = '_';
402 }
403 else
404 {
405 /* Convert the character to uppercase and save it */
406
410 Result[i] = (char) ACPI_TOUPPER (*ExternalName);
407 Result[i] = (char) ACPI_TOUPPER ((int) *ExternalName);
411 ExternalName++;
412 }
413 }
414
415 /* Now we must have a path separator, or the pathname is bad */
416
417 if (!AcpiNsValidPathSeparator (*ExternalName) &&
418 (*ExternalName != 0))
419 {
420 return_ACPI_STATUS (AE_BAD_PARAMETER);
421 }
422
423 /* Move on the next segment */
424
425 ExternalName++;
426 Result += ACPI_NAME_SIZE;
427 }
428
429 /* Terminate the string */
430
431 *Result = 0;
432
433 if (Info->FullyQualified)
434 {
435 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "returning [%p] (abs) \"\\%s\"\n",
436 InternalName, InternalName));
437 }
438 else
439 {
440 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "returning [%p] (rel) \"%s\"\n",
441 InternalName, InternalName));
442 }
443
444 return_ACPI_STATUS (AE_OK);
445}
446
447
448/*******************************************************************************
449 *
450 * FUNCTION: AcpiNsInternalizeName
451 *
452 * PARAMETERS: *ExternalName - External representation of name
453 * **Converted Name - Where to return the resulting
454 * internal represention of the name
455 *
456 * RETURN: Status
457 *
458 * DESCRIPTION: Convert an external representation (e.g. "\_PR_.CPU0")
459 * to internal form (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
460 *
461 *******************************************************************************/
462
463ACPI_STATUS
464AcpiNsInternalizeName (
465 NATIVE_CHAR *ExternalName,
466 NATIVE_CHAR **ConvertedName)
467{
468 NATIVE_CHAR *InternalName;
469 ACPI_NAMESTRING_INFO Info;
470 ACPI_STATUS Status;
471
472
473 ACPI_FUNCTION_TRACE ("NsInternalizeName");
474
475
476 if ((!ExternalName) ||
477 (*ExternalName == 0) ||
478 (!ConvertedName))
479 {
480 return_ACPI_STATUS (AE_BAD_PARAMETER);
481 }
482
483 /* Get the length of the new internal name */
484
485 Info.ExternalName = ExternalName;
486 AcpiNsGetInternalNameLength (&Info);
487
488 /* We need a segment to store the internal name */
489
490 InternalName = ACPI_MEM_CALLOCATE (Info.Length);
491 if (!InternalName)
492 {
493 return_ACPI_STATUS (AE_NO_MEMORY);
494 }
495
496 /* Build the name */
497
498 Info.InternalName = InternalName;
499 Status = AcpiNsBuildInternalName (&Info);
500 if (ACPI_FAILURE (Status))
501 {
502 ACPI_MEM_FREE (InternalName);
503 return_ACPI_STATUS (Status);
504 }
505
506 *ConvertedName = InternalName;
507 return_ACPI_STATUS (AE_OK);
508}
509
510
511/*******************************************************************************
512 *
513 * FUNCTION: AcpiNsExternalizeName
514 *
515 * PARAMETERS: *InternalName - Internal representation of name
516 * **ConvertedName - Where to return the resulting
517 * external representation of name
518 *
519 * RETURN: Status
520 *
521 * DESCRIPTION: Convert internal name (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
522 * to its external form (e.g. "\_PR_.CPU0")
523 *
524 ******************************************************************************/
525
526ACPI_STATUS
527AcpiNsExternalizeName (
528 UINT32 InternalNameLength,
529 char *InternalName,
530 UINT32 *ConvertedNameLength,
531 char **ConvertedName)
532{
408 ExternalName++;
409 }
410 }
411
412 /* Now we must have a path separator, or the pathname is bad */
413
414 if (!AcpiNsValidPathSeparator (*ExternalName) &&
415 (*ExternalName != 0))
416 {
417 return_ACPI_STATUS (AE_BAD_PARAMETER);
418 }
419
420 /* Move on the next segment */
421
422 ExternalName++;
423 Result += ACPI_NAME_SIZE;
424 }
425
426 /* Terminate the string */
427
428 *Result = 0;
429
430 if (Info->FullyQualified)
431 {
432 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "returning [%p] (abs) \"\\%s\"\n",
433 InternalName, InternalName));
434 }
435 else
436 {
437 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "returning [%p] (rel) \"%s\"\n",
438 InternalName, InternalName));
439 }
440
441 return_ACPI_STATUS (AE_OK);
442}
443
444
445/*******************************************************************************
446 *
447 * FUNCTION: AcpiNsInternalizeName
448 *
449 * PARAMETERS: *ExternalName - External representation of name
450 * **Converted Name - Where to return the resulting
451 * internal represention of the name
452 *
453 * RETURN: Status
454 *
455 * DESCRIPTION: Convert an external representation (e.g. "\_PR_.CPU0")
456 * to internal form (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
457 *
458 *******************************************************************************/
459
460ACPI_STATUS
461AcpiNsInternalizeName (
462 NATIVE_CHAR *ExternalName,
463 NATIVE_CHAR **ConvertedName)
464{
465 NATIVE_CHAR *InternalName;
466 ACPI_NAMESTRING_INFO Info;
467 ACPI_STATUS Status;
468
469
470 ACPI_FUNCTION_TRACE ("NsInternalizeName");
471
472
473 if ((!ExternalName) ||
474 (*ExternalName == 0) ||
475 (!ConvertedName))
476 {
477 return_ACPI_STATUS (AE_BAD_PARAMETER);
478 }
479
480 /* Get the length of the new internal name */
481
482 Info.ExternalName = ExternalName;
483 AcpiNsGetInternalNameLength (&Info);
484
485 /* We need a segment to store the internal name */
486
487 InternalName = ACPI_MEM_CALLOCATE (Info.Length);
488 if (!InternalName)
489 {
490 return_ACPI_STATUS (AE_NO_MEMORY);
491 }
492
493 /* Build the name */
494
495 Info.InternalName = InternalName;
496 Status = AcpiNsBuildInternalName (&Info);
497 if (ACPI_FAILURE (Status))
498 {
499 ACPI_MEM_FREE (InternalName);
500 return_ACPI_STATUS (Status);
501 }
502
503 *ConvertedName = InternalName;
504 return_ACPI_STATUS (AE_OK);
505}
506
507
508/*******************************************************************************
509 *
510 * FUNCTION: AcpiNsExternalizeName
511 *
512 * PARAMETERS: *InternalName - Internal representation of name
513 * **ConvertedName - Where to return the resulting
514 * external representation of name
515 *
516 * RETURN: Status
517 *
518 * DESCRIPTION: Convert internal name (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
519 * to its external form (e.g. "\_PR_.CPU0")
520 *
521 ******************************************************************************/
522
523ACPI_STATUS
524AcpiNsExternalizeName (
525 UINT32 InternalNameLength,
526 char *InternalName,
527 UINT32 *ConvertedNameLength,
528 char **ConvertedName)
529{
533 UINT32 PrefixLength = 0;
534 UINT32 NamesIndex = 0;
535 UINT32 NumSegments = 0;
536 UINT32 i = 0;
537 UINT32 j = 0;
538 UINT32 RequiredLength;
530 NATIVE_UINT_MIN32 PrefixLength = 0;
531 NATIVE_UINT_MIN32 NamesIndex = 0;
532 NATIVE_UINT_MIN32 NumSegments = 0;
533 NATIVE_UINT_MIN32 i = 0;
534 NATIVE_UINT_MIN32 j = 0;
535 NATIVE_UINT_MIN32 RequiredLength;
539
540
541 ACPI_FUNCTION_TRACE ("NsExternalizeName");
542
543
544 if (!InternalNameLength ||
545 !InternalName ||
546 !ConvertedName)
547 {
548 return_ACPI_STATUS (AE_BAD_PARAMETER);
549 }
550
551 /*
552 * Check for a prefix (one '\' | one or more '^').
553 */
554 switch (InternalName[0])
555 {
556 case '\\':
557 PrefixLength = 1;
558 break;
559
560 case '^':
561 for (i = 0; i < InternalNameLength; i++)
562 {
563 if (InternalName[i] != '^')
564 {
565 PrefixLength = i + 1;
566 }
567 }
568
569 if (i == InternalNameLength)
570 {
571 PrefixLength = i;
572 }
573
574 break;
536
537
538 ACPI_FUNCTION_TRACE ("NsExternalizeName");
539
540
541 if (!InternalNameLength ||
542 !InternalName ||
543 !ConvertedName)
544 {
545 return_ACPI_STATUS (AE_BAD_PARAMETER);
546 }
547
548 /*
549 * Check for a prefix (one '\' | one or more '^').
550 */
551 switch (InternalName[0])
552 {
553 case '\\':
554 PrefixLength = 1;
555 break;
556
557 case '^':
558 for (i = 0; i < InternalNameLength; i++)
559 {
560 if (InternalName[i] != '^')
561 {
562 PrefixLength = i + 1;
563 }
564 }
565
566 if (i == InternalNameLength)
567 {
568 PrefixLength = i;
569 }
570
571 break;
572
573 default:
574 break;
575 }
576
577 /*
578 * Check for object names. Note that there could be 0-255 of these
579 * 4-byte elements.
580 */
581 if (PrefixLength < InternalNameLength)
582 {
583 switch (InternalName[PrefixLength])
584 {
585 case AML_MULTI_NAME_PREFIX_OP:
586
587 /* <count> 4-byte names */
588
589 NamesIndex = PrefixLength + 2;
590 NumSegments = (UINT32) (UINT8) InternalName[PrefixLength + 1];
591 break;
592
593 case AML_DUAL_NAME_PREFIX:
594
595 /* Two 4-byte names */
596
597 NamesIndex = PrefixLength + 1;
598 NumSegments = 2;
599 break;
600
601 case 0:
602
603 /* NullName */
604
605 NamesIndex = 0;
606 NumSegments = 0;
607 break;
608
609 default:
610
611 /* one 4-byte name */
612
613 NamesIndex = PrefixLength;
614 NumSegments = 1;
615 break;
616 }
617 }
618
619 /*
620 * Calculate the length of ConvertedName, which equals the length
621 * of the prefix, length of all object names, length of any required
622 * punctuation ('.') between object names, plus the NULL terminator.
623 */
624 RequiredLength = PrefixLength + (4 * NumSegments) +
625 ((NumSegments > 0) ? (NumSegments - 1) : 0) + 1;
626
627 /*
628 * Check to see if we're still in bounds. If not, there's a problem
629 * with InternalName (invalid format).
630 */
631 if (RequiredLength > InternalNameLength)
632 {
633 ACPI_REPORT_ERROR (("NsExternalizeName: Invalid internal name\n"));
634 return_ACPI_STATUS (AE_BAD_PATHNAME);
635 }
636
637 /*
638 * Build ConvertedName...
639 */
640 *ConvertedName = ACPI_MEM_CALLOCATE (RequiredLength);
641 if (!(*ConvertedName))
642 {
643 return_ACPI_STATUS (AE_NO_MEMORY);
644 }
645
646 j = 0;
647
648 for (i = 0; i < PrefixLength; i++)
649 {
650 (*ConvertedName)[j++] = InternalName[i];
651 }
652
653 if (NumSegments > 0)
654 {
655 for (i = 0; i < NumSegments; i++)
656 {
657 if (i > 0)
658 {
659 (*ConvertedName)[j++] = '.';
660 }
661
662 (*ConvertedName)[j++] = InternalName[NamesIndex++];
663 (*ConvertedName)[j++] = InternalName[NamesIndex++];
664 (*ConvertedName)[j++] = InternalName[NamesIndex++];
665 (*ConvertedName)[j++] = InternalName[NamesIndex++];
666 }
667 }
668
669 if (ConvertedNameLength)
670 {
575 }
576
577 /*
578 * Check for object names. Note that there could be 0-255 of these
579 * 4-byte elements.
580 */
581 if (PrefixLength < InternalNameLength)
582 {
583 switch (InternalName[PrefixLength])
584 {
585 case AML_MULTI_NAME_PREFIX_OP:
586
587 /* <count> 4-byte names */
588
589 NamesIndex = PrefixLength + 2;
590 NumSegments = (UINT32) (UINT8) InternalName[PrefixLength + 1];
591 break;
592
593 case AML_DUAL_NAME_PREFIX:
594
595 /* Two 4-byte names */
596
597 NamesIndex = PrefixLength + 1;
598 NumSegments = 2;
599 break;
600
601 case 0:
602
603 /* NullName */
604
605 NamesIndex = 0;
606 NumSegments = 0;
607 break;
608
609 default:
610
611 /* one 4-byte name */
612
613 NamesIndex = PrefixLength;
614 NumSegments = 1;
615 break;
616 }
617 }
618
619 /*
620 * Calculate the length of ConvertedName, which equals the length
621 * of the prefix, length of all object names, length of any required
622 * punctuation ('.') between object names, plus the NULL terminator.
623 */
624 RequiredLength = PrefixLength + (4 * NumSegments) +
625 ((NumSegments > 0) ? (NumSegments - 1) : 0) + 1;
626
627 /*
628 * Check to see if we're still in bounds. If not, there's a problem
629 * with InternalName (invalid format).
630 */
631 if (RequiredLength > InternalNameLength)
632 {
633 ACPI_REPORT_ERROR (("NsExternalizeName: Invalid internal name\n"));
634 return_ACPI_STATUS (AE_BAD_PATHNAME);
635 }
636
637 /*
638 * Build ConvertedName...
639 */
640 *ConvertedName = ACPI_MEM_CALLOCATE (RequiredLength);
641 if (!(*ConvertedName))
642 {
643 return_ACPI_STATUS (AE_NO_MEMORY);
644 }
645
646 j = 0;
647
648 for (i = 0; i < PrefixLength; i++)
649 {
650 (*ConvertedName)[j++] = InternalName[i];
651 }
652
653 if (NumSegments > 0)
654 {
655 for (i = 0; i < NumSegments; i++)
656 {
657 if (i > 0)
658 {
659 (*ConvertedName)[j++] = '.';
660 }
661
662 (*ConvertedName)[j++] = InternalName[NamesIndex++];
663 (*ConvertedName)[j++] = InternalName[NamesIndex++];
664 (*ConvertedName)[j++] = InternalName[NamesIndex++];
665 (*ConvertedName)[j++] = InternalName[NamesIndex++];
666 }
667 }
668
669 if (ConvertedNameLength)
670 {
671 *ConvertedNameLength = RequiredLength;
671 *ConvertedNameLength = (UINT32) RequiredLength;
672 }
673
674 return_ACPI_STATUS (AE_OK);
675}
676
677
678/*******************************************************************************
679 *
680 * FUNCTION: AcpiNsMapHandleToNode
681 *
682 * PARAMETERS: Handle - Handle to be converted to an Node
683 *
684 * RETURN: A Name table entry pointer
685 *
686 * DESCRIPTION: Convert a namespace handle to a real Node
687 *
688 * Note: Real integer handles allow for more verification
689 * and keep all pointers within this subsystem.
690 *
691 ******************************************************************************/
692
693ACPI_NAMESPACE_NODE *
694AcpiNsMapHandleToNode (
695 ACPI_HANDLE Handle)
696{
697
698 ACPI_FUNCTION_ENTRY ();
699
700
701 /*
702 * Simple implementation.
703 */
704 if (!Handle)
705 {
706 return (NULL);
707 }
708
709 if (Handle == ACPI_ROOT_OBJECT)
710 {
711 return (AcpiGbl_RootNode);
712 }
713
714 /* We can at least attempt to verify the handle */
715
716 if (ACPI_GET_DESCRIPTOR_TYPE (Handle) != ACPI_DESC_TYPE_NAMED)
717 {
718 return (NULL);
719 }
720
721 return ((ACPI_NAMESPACE_NODE *) Handle);
722}
723
724
725/*******************************************************************************
726 *
727 * FUNCTION: AcpiNsConvertEntryToHandle
728 *
729 * PARAMETERS: Node - Node to be converted to a Handle
730 *
731 * RETURN: An USER ACPI_HANDLE
732 *
733 * DESCRIPTION: Convert a real Node to a namespace handle
734 *
735 ******************************************************************************/
736
737ACPI_HANDLE
738AcpiNsConvertEntryToHandle (
739 ACPI_NAMESPACE_NODE *Node)
740{
741
742
743 /*
744 * Simple implementation for now;
745 */
746 return ((ACPI_HANDLE) Node);
747
748
749/* ---------------------------------------------------
750
751 if (!Node)
752 {
753 return (NULL);
754 }
755
756 if (Node == AcpiGbl_RootNode)
757 {
758 return (ACPI_ROOT_OBJECT);
759 }
760
761
762 return ((ACPI_HANDLE) Node);
763------------------------------------------------------*/
764}
765
766
767/*******************************************************************************
768 *
769 * FUNCTION: AcpiNsTerminate
770 *
771 * PARAMETERS: none
772 *
773 * RETURN: none
774 *
775 * DESCRIPTION: free memory allocated for table storage.
776 *
777 ******************************************************************************/
778
779void
780AcpiNsTerminate (void)
781{
782 ACPI_OPERAND_OBJECT *ObjDesc;
783 ACPI_NAMESPACE_NODE *ThisNode;
784
785
786 ACPI_FUNCTION_TRACE ("NsTerminate");
787
788
789 ThisNode = AcpiGbl_RootNode;
790
791 /*
792 * 1) Free the entire namespace -- all objects, tables, and stacks
793 *
794 * Delete all objects linked to the root
795 * (additional table descriptors)
796 */
797 AcpiNsDeleteNamespaceSubtree (ThisNode);
798
799 /* Detach any object(s) attached to the root */
800
801 ObjDesc = AcpiNsGetAttachedObject (ThisNode);
802 if (ObjDesc)
803 {
804 AcpiNsDetachObject (ThisNode);
805 AcpiUtRemoveReference (ObjDesc);
806 }
807
808 AcpiNsDeleteChildren (ThisNode);
809 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Namespace freed\n"));
810
811
812 /*
813 * 2) Now we can delete the ACPI tables
814 */
815 AcpiTbDeleteAcpiTables ();
816 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Tables freed\n"));
817
818 return_VOID;
819}
820
821
822/*******************************************************************************
823 *
824 * FUNCTION: AcpiNsOpensScope
825 *
826 * PARAMETERS: Type - A valid namespace type
827 *
828 * RETURN: NEWSCOPE if the passed type "opens a name scope" according
829 * to the ACPI specification, else 0
830 *
831 ******************************************************************************/
832
833UINT32
834AcpiNsOpensScope (
835 ACPI_OBJECT_TYPE Type)
836{
837 ACPI_FUNCTION_TRACE_U32 ("NsOpensScope", Type);
838
839
840 if (!AcpiUtValidObjectType (Type))
841 {
842 /* type code out of range */
843
844 ACPI_REPORT_WARNING (("NsOpensScope: Invalid Object Type %X\n", Type));
845 return_VALUE (ACPI_NS_NORMAL);
846 }
847
848 return_VALUE (((UINT32) AcpiGbl_NsProperties[Type]) & ACPI_NS_NEWSCOPE);
849}
850
851
852/*******************************************************************************
853 *
854 * FUNCTION: AcpiNsGetNodeByPath
855 *
856 * PARAMETERS: *Pathname - Name to be found, in external (ASL) format. The
857 * \ (backslash) and ^ (carat) prefixes, and the
858 * . (period) to separate segments are supported.
859 * StartNode - Root of subtree to be searched, or NS_ALL for the
860 * root of the name space. If Name is fully
861 * qualified (first INT8 is '\'), the passed value
862 * of Scope will not be accessed.
863 * Flags - Used to indicate whether to perform upsearch or
864 * not.
865 * ReturnNode - Where the Node is returned
866 *
867 * DESCRIPTION: Look up a name relative to a given scope and return the
868 * corresponding Node. NOTE: Scope can be null.
869 *
870 * MUTEX: Locks namespace
871 *
872 ******************************************************************************/
873
874ACPI_STATUS
875AcpiNsGetNodeByPath (
876 NATIVE_CHAR *Pathname,
877 ACPI_NAMESPACE_NODE *StartNode,
878 UINT32 Flags,
879 ACPI_NAMESPACE_NODE **ReturnNode)
880{
881 ACPI_GENERIC_STATE ScopeInfo;
882 ACPI_STATUS Status;
883 NATIVE_CHAR *InternalPath = NULL;
884
885
886 ACPI_FUNCTION_TRACE_PTR ("NsGetNodeByPath", Pathname);
887
888
889 if (!Pathname)
890 {
891 return_ACPI_STATUS (AE_BAD_PARAMETER);
892 }
893
894 /* Convert path to internal representation */
895
896 Status = AcpiNsInternalizeName (Pathname, &InternalPath);
897 if (ACPI_FAILURE (Status))
898 {
899 return_ACPI_STATUS (Status);
900 }
901
902 /* Must lock namespace during lookup */
903
904 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
905 if (ACPI_FAILURE (Status))
906 {
907 return_ACPI_STATUS (Status);
908 }
909
910 /* Setup lookup scope (search starting point) */
911
912 ScopeInfo.Scope.Node = StartNode;
913
914 /* Lookup the name in the namespace */
915
916 Status = AcpiNsLookup (&ScopeInfo, InternalPath,
917 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
918 (Flags | ACPI_NS_DONT_OPEN_SCOPE),
919 NULL, ReturnNode);
920 if (ACPI_FAILURE (Status))
921 {
922 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "%s, %s\n",
923 InternalPath, AcpiFormatException (Status)));
924 }
925
926 /* Cleanup */
927
928 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
929 ACPI_MEM_FREE (InternalPath);
930 return_ACPI_STATUS (Status);
931}
932
933
934/*******************************************************************************
935 *
936 * FUNCTION: AcpiNsFindParentName
937 *
938 * PARAMETERS: *ChildNode - Named Obj whose name is to be found
939 *
940 * RETURN: The ACPI name
941 *
942 * DESCRIPTION: Search for the given obj in its parent scope and return the
943 * name segment, or "????" if the parent name can't be found
944 * (which "should not happen").
945 *
946 ******************************************************************************/
947
948ACPI_NAME
949AcpiNsFindParentName (
950 ACPI_NAMESPACE_NODE *ChildNode)
951{
952 ACPI_NAMESPACE_NODE *ParentNode;
953
954
955 ACPI_FUNCTION_TRACE ("NsFindParentName");
956
957
958 if (ChildNode)
959 {
960 /* Valid entry. Get the parent Node */
961
962 ParentNode = AcpiNsGetParentNode (ChildNode);
963 if (ParentNode)
964 {
965 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Parent of %p [%4.4s] is %p [%4.4s]\n",
672 }
673
674 return_ACPI_STATUS (AE_OK);
675}
676
677
678/*******************************************************************************
679 *
680 * FUNCTION: AcpiNsMapHandleToNode
681 *
682 * PARAMETERS: Handle - Handle to be converted to an Node
683 *
684 * RETURN: A Name table entry pointer
685 *
686 * DESCRIPTION: Convert a namespace handle to a real Node
687 *
688 * Note: Real integer handles allow for more verification
689 * and keep all pointers within this subsystem.
690 *
691 ******************************************************************************/
692
693ACPI_NAMESPACE_NODE *
694AcpiNsMapHandleToNode (
695 ACPI_HANDLE Handle)
696{
697
698 ACPI_FUNCTION_ENTRY ();
699
700
701 /*
702 * Simple implementation.
703 */
704 if (!Handle)
705 {
706 return (NULL);
707 }
708
709 if (Handle == ACPI_ROOT_OBJECT)
710 {
711 return (AcpiGbl_RootNode);
712 }
713
714 /* We can at least attempt to verify the handle */
715
716 if (ACPI_GET_DESCRIPTOR_TYPE (Handle) != ACPI_DESC_TYPE_NAMED)
717 {
718 return (NULL);
719 }
720
721 return ((ACPI_NAMESPACE_NODE *) Handle);
722}
723
724
725/*******************************************************************************
726 *
727 * FUNCTION: AcpiNsConvertEntryToHandle
728 *
729 * PARAMETERS: Node - Node to be converted to a Handle
730 *
731 * RETURN: An USER ACPI_HANDLE
732 *
733 * DESCRIPTION: Convert a real Node to a namespace handle
734 *
735 ******************************************************************************/
736
737ACPI_HANDLE
738AcpiNsConvertEntryToHandle (
739 ACPI_NAMESPACE_NODE *Node)
740{
741
742
743 /*
744 * Simple implementation for now;
745 */
746 return ((ACPI_HANDLE) Node);
747
748
749/* ---------------------------------------------------
750
751 if (!Node)
752 {
753 return (NULL);
754 }
755
756 if (Node == AcpiGbl_RootNode)
757 {
758 return (ACPI_ROOT_OBJECT);
759 }
760
761
762 return ((ACPI_HANDLE) Node);
763------------------------------------------------------*/
764}
765
766
767/*******************************************************************************
768 *
769 * FUNCTION: AcpiNsTerminate
770 *
771 * PARAMETERS: none
772 *
773 * RETURN: none
774 *
775 * DESCRIPTION: free memory allocated for table storage.
776 *
777 ******************************************************************************/
778
779void
780AcpiNsTerminate (void)
781{
782 ACPI_OPERAND_OBJECT *ObjDesc;
783 ACPI_NAMESPACE_NODE *ThisNode;
784
785
786 ACPI_FUNCTION_TRACE ("NsTerminate");
787
788
789 ThisNode = AcpiGbl_RootNode;
790
791 /*
792 * 1) Free the entire namespace -- all objects, tables, and stacks
793 *
794 * Delete all objects linked to the root
795 * (additional table descriptors)
796 */
797 AcpiNsDeleteNamespaceSubtree (ThisNode);
798
799 /* Detach any object(s) attached to the root */
800
801 ObjDesc = AcpiNsGetAttachedObject (ThisNode);
802 if (ObjDesc)
803 {
804 AcpiNsDetachObject (ThisNode);
805 AcpiUtRemoveReference (ObjDesc);
806 }
807
808 AcpiNsDeleteChildren (ThisNode);
809 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Namespace freed\n"));
810
811
812 /*
813 * 2) Now we can delete the ACPI tables
814 */
815 AcpiTbDeleteAcpiTables ();
816 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Tables freed\n"));
817
818 return_VOID;
819}
820
821
822/*******************************************************************************
823 *
824 * FUNCTION: AcpiNsOpensScope
825 *
826 * PARAMETERS: Type - A valid namespace type
827 *
828 * RETURN: NEWSCOPE if the passed type "opens a name scope" according
829 * to the ACPI specification, else 0
830 *
831 ******************************************************************************/
832
833UINT32
834AcpiNsOpensScope (
835 ACPI_OBJECT_TYPE Type)
836{
837 ACPI_FUNCTION_TRACE_U32 ("NsOpensScope", Type);
838
839
840 if (!AcpiUtValidObjectType (Type))
841 {
842 /* type code out of range */
843
844 ACPI_REPORT_WARNING (("NsOpensScope: Invalid Object Type %X\n", Type));
845 return_VALUE (ACPI_NS_NORMAL);
846 }
847
848 return_VALUE (((UINT32) AcpiGbl_NsProperties[Type]) & ACPI_NS_NEWSCOPE);
849}
850
851
852/*******************************************************************************
853 *
854 * FUNCTION: AcpiNsGetNodeByPath
855 *
856 * PARAMETERS: *Pathname - Name to be found, in external (ASL) format. The
857 * \ (backslash) and ^ (carat) prefixes, and the
858 * . (period) to separate segments are supported.
859 * StartNode - Root of subtree to be searched, or NS_ALL for the
860 * root of the name space. If Name is fully
861 * qualified (first INT8 is '\'), the passed value
862 * of Scope will not be accessed.
863 * Flags - Used to indicate whether to perform upsearch or
864 * not.
865 * ReturnNode - Where the Node is returned
866 *
867 * DESCRIPTION: Look up a name relative to a given scope and return the
868 * corresponding Node. NOTE: Scope can be null.
869 *
870 * MUTEX: Locks namespace
871 *
872 ******************************************************************************/
873
874ACPI_STATUS
875AcpiNsGetNodeByPath (
876 NATIVE_CHAR *Pathname,
877 ACPI_NAMESPACE_NODE *StartNode,
878 UINT32 Flags,
879 ACPI_NAMESPACE_NODE **ReturnNode)
880{
881 ACPI_GENERIC_STATE ScopeInfo;
882 ACPI_STATUS Status;
883 NATIVE_CHAR *InternalPath = NULL;
884
885
886 ACPI_FUNCTION_TRACE_PTR ("NsGetNodeByPath", Pathname);
887
888
889 if (!Pathname)
890 {
891 return_ACPI_STATUS (AE_BAD_PARAMETER);
892 }
893
894 /* Convert path to internal representation */
895
896 Status = AcpiNsInternalizeName (Pathname, &InternalPath);
897 if (ACPI_FAILURE (Status))
898 {
899 return_ACPI_STATUS (Status);
900 }
901
902 /* Must lock namespace during lookup */
903
904 Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
905 if (ACPI_FAILURE (Status))
906 {
907 return_ACPI_STATUS (Status);
908 }
909
910 /* Setup lookup scope (search starting point) */
911
912 ScopeInfo.Scope.Node = StartNode;
913
914 /* Lookup the name in the namespace */
915
916 Status = AcpiNsLookup (&ScopeInfo, InternalPath,
917 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
918 (Flags | ACPI_NS_DONT_OPEN_SCOPE),
919 NULL, ReturnNode);
920 if (ACPI_FAILURE (Status))
921 {
922 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "%s, %s\n",
923 InternalPath, AcpiFormatException (Status)));
924 }
925
926 /* Cleanup */
927
928 (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
929 ACPI_MEM_FREE (InternalPath);
930 return_ACPI_STATUS (Status);
931}
932
933
934/*******************************************************************************
935 *
936 * FUNCTION: AcpiNsFindParentName
937 *
938 * PARAMETERS: *ChildNode - Named Obj whose name is to be found
939 *
940 * RETURN: The ACPI name
941 *
942 * DESCRIPTION: Search for the given obj in its parent scope and return the
943 * name segment, or "????" if the parent name can't be found
944 * (which "should not happen").
945 *
946 ******************************************************************************/
947
948ACPI_NAME
949AcpiNsFindParentName (
950 ACPI_NAMESPACE_NODE *ChildNode)
951{
952 ACPI_NAMESPACE_NODE *ParentNode;
953
954
955 ACPI_FUNCTION_TRACE ("NsFindParentName");
956
957
958 if (ChildNode)
959 {
960 /* Valid entry. Get the parent Node */
961
962 ParentNode = AcpiNsGetParentNode (ChildNode);
963 if (ParentNode)
964 {
965 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Parent of %p [%4.4s] is %p [%4.4s]\n",
966 ChildNode, (char *) &ChildNode->Name,
967 ParentNode, (char *) &ParentNode->Name));
966 ChildNode, ChildNode->Name.Ascii,
967 ParentNode, ParentNode->Name.Ascii));
968
969 if (ParentNode->Name.Integer)
970 {
968
969 if (ParentNode->Name.Integer)
970 {
971 return_VALUE (ParentNode->Name.Integer);
971 return_VALUE ((ACPI_NAME) ParentNode->Name.Integer);
972 }
973 }
974
975 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "unable to find parent of %p (%4.4s)\n",
972 }
973 }
974
975 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "unable to find parent of %p (%4.4s)\n",
976 ChildNode, (char *) &ChildNode->Name));
976 ChildNode, ChildNode->Name.Ascii));
977 }
978
979 return_VALUE (ACPI_UNKNOWN_NAME);
980}
981
982
983#if defined(ACPI_DEBUG) || defined(ENABLE_DEBUGGER)
984
985/*******************************************************************************
986 *
987 * FUNCTION: AcpiNsExistDownstreamSibling
988 *
989 * PARAMETERS: *Node - pointer to first Node to examine
990 *
991 * RETURN: TRUE if sibling is found, FALSE otherwise
992 *
993 * DESCRIPTION: Searches remainder of scope being processed to determine
994 * whether there is a downstream sibling to the current
995 * object. This function is used to determine what type of
996 * line drawing character to use when displaying namespace
997 * trees.
998 *
999 ******************************************************************************/
1000
1001BOOLEAN
1002AcpiNsExistDownstreamSibling (
1003 ACPI_NAMESPACE_NODE *Node)
1004{
1005
1006 if (!Node)
1007 {
1008 return (FALSE);
1009 }
1010
1011 if (Node->Name.Integer)
1012 {
1013 return (TRUE);
1014 }
1015
1016 return (FALSE);
1017}
1018
1019#endif /* ACPI_DEBUG */
1020
1021
1022/*******************************************************************************
1023 *
1024 * FUNCTION: AcpiNsGetParentNode
1025 *
1026 * PARAMETERS: Node - Current table entry
1027 *
1028 * RETURN: Parent entry of the given entry
1029 *
1030 * DESCRIPTION: Obtain the parent entry for a given entry in the namespace.
1031 *
1032 ******************************************************************************/
1033
1034
1035ACPI_NAMESPACE_NODE *
1036AcpiNsGetParentNode (
1037 ACPI_NAMESPACE_NODE *Node)
1038{
1039 ACPI_FUNCTION_ENTRY ();
1040
1041
1042 if (!Node)
1043 {
1044 return (NULL);
1045 }
1046
1047 /*
1048 * Walk to the end of this peer list.
1049 * The last entry is marked with a flag and the peer
1050 * pointer is really a pointer back to the parent.
1051 * This saves putting a parent back pointer in each and
1052 * every named object!
1053 */
1054 while (!(Node->Flags & ANOBJ_END_OF_PEER_LIST))
1055 {
1056 Node = Node->Peer;
1057 }
1058
1059
1060 return (Node->Peer);
1061}
1062
1063
1064/*******************************************************************************
1065 *
1066 * FUNCTION: AcpiNsGetNextValidNode
1067 *
1068 * PARAMETERS: Node - Current table entry
1069 *
1070 * RETURN: Next valid Node in the linked node list. NULL if no more valid
1071 * nodess
1072 *
1073 * DESCRIPTION: Find the next valid node within a name table.
1074 * Useful for implementing NULL-end-of-list loops.
1075 *
1076 ******************************************************************************/
1077
1078
1079ACPI_NAMESPACE_NODE *
1080AcpiNsGetNextValidNode (
1081 ACPI_NAMESPACE_NODE *Node)
1082{
1083
1084 /* If we are at the end of this peer list, return NULL */
1085
1086 if (Node->Flags & ANOBJ_END_OF_PEER_LIST)
1087 {
1088 return NULL;
1089 }
1090
1091 /* Otherwise just return the next peer */
1092
1093 return (Node->Peer);
1094}
1095
1096
977 }
978
979 return_VALUE (ACPI_UNKNOWN_NAME);
980}
981
982
983#if defined(ACPI_DEBUG) || defined(ENABLE_DEBUGGER)
984
985/*******************************************************************************
986 *
987 * FUNCTION: AcpiNsExistDownstreamSibling
988 *
989 * PARAMETERS: *Node - pointer to first Node to examine
990 *
991 * RETURN: TRUE if sibling is found, FALSE otherwise
992 *
993 * DESCRIPTION: Searches remainder of scope being processed to determine
994 * whether there is a downstream sibling to the current
995 * object. This function is used to determine what type of
996 * line drawing character to use when displaying namespace
997 * trees.
998 *
999 ******************************************************************************/
1000
1001BOOLEAN
1002AcpiNsExistDownstreamSibling (
1003 ACPI_NAMESPACE_NODE *Node)
1004{
1005
1006 if (!Node)
1007 {
1008 return (FALSE);
1009 }
1010
1011 if (Node->Name.Integer)
1012 {
1013 return (TRUE);
1014 }
1015
1016 return (FALSE);
1017}
1018
1019#endif /* ACPI_DEBUG */
1020
1021
1022/*******************************************************************************
1023 *
1024 * FUNCTION: AcpiNsGetParentNode
1025 *
1026 * PARAMETERS: Node - Current table entry
1027 *
1028 * RETURN: Parent entry of the given entry
1029 *
1030 * DESCRIPTION: Obtain the parent entry for a given entry in the namespace.
1031 *
1032 ******************************************************************************/
1033
1034
1035ACPI_NAMESPACE_NODE *
1036AcpiNsGetParentNode (
1037 ACPI_NAMESPACE_NODE *Node)
1038{
1039 ACPI_FUNCTION_ENTRY ();
1040
1041
1042 if (!Node)
1043 {
1044 return (NULL);
1045 }
1046
1047 /*
1048 * Walk to the end of this peer list.
1049 * The last entry is marked with a flag and the peer
1050 * pointer is really a pointer back to the parent.
1051 * This saves putting a parent back pointer in each and
1052 * every named object!
1053 */
1054 while (!(Node->Flags & ANOBJ_END_OF_PEER_LIST))
1055 {
1056 Node = Node->Peer;
1057 }
1058
1059
1060 return (Node->Peer);
1061}
1062
1063
1064/*******************************************************************************
1065 *
1066 * FUNCTION: AcpiNsGetNextValidNode
1067 *
1068 * PARAMETERS: Node - Current table entry
1069 *
1070 * RETURN: Next valid Node in the linked node list. NULL if no more valid
1071 * nodess
1072 *
1073 * DESCRIPTION: Find the next valid node within a name table.
1074 * Useful for implementing NULL-end-of-list loops.
1075 *
1076 ******************************************************************************/
1077
1078
1079ACPI_NAMESPACE_NODE *
1080AcpiNsGetNextValidNode (
1081 ACPI_NAMESPACE_NODE *Node)
1082{
1083
1084 /* If we are at the end of this peer list, return NULL */
1085
1086 if (Node->Flags & ANOBJ_END_OF_PEER_LIST)
1087 {
1088 return NULL;
1089 }
1090
1091 /* Otherwise just return the next peer */
1092
1093 return (Node->Peer);
1094}
1095
1096