dmnames.c revision 1.1.1.3 1 /*******************************************************************************
2 *
3 * Module Name: dmnames - AML disassembler, names, namestrings, pathnames
4 *
5 ******************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2013, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
25 *
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.
29 *
30 * NO WARRANTY
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.
42 */
43
44
45 #include "acpi.h"
46 #include "accommon.h"
47 #include "amlcode.h"
48 #include "acnamesp.h"
49 #include "acdisasm.h"
50
51
52 #ifdef ACPI_DISASSEMBLER
53
54 #define _COMPONENT ACPI_CA_DEBUGGER
55 ACPI_MODULE_NAME ("dmnames")
56
57 /* Local prototypes */
58
59 #ifdef ACPI_OBSOLETE_FUNCTIONS
60 void
61 AcpiDmDisplayPath (
62 ACPI_PARSE_OBJECT *Op);
63 #endif
64
65
66 /*******************************************************************************
67 *
68 * FUNCTION: AcpiDmDumpName
69 *
70 * PARAMETERS: Name - 4 character ACPI name
71 *
72 * RETURN: Final length of name
73 *
74 * DESCRIPTION: Dump an ACPI name, minus any trailing underscores.
75 *
76 ******************************************************************************/
77
78 UINT32
79 AcpiDmDumpName (
80 UINT32 Name)
81 {
82 UINT32 i;
83 UINT32 Length;
84 char NewName[4];
85
86
87 /* Copy name locally in case the original name is not writeable */
88
89 *ACPI_CAST_PTR (UINT32, &NewName[0]) = Name;
90
91 /* Ensure that the name is printable, even if we have to fix it */
92
93 AcpiUtRepairName (NewName);
94
95 /* Remove all trailing underscores from the name */
96
97 Length = ACPI_NAME_SIZE;
98 for (i = (ACPI_NAME_SIZE - 1); i != 0; i--)
99 {
100 if (NewName[i] == '_')
101 {
102 Length--;
103 }
104 else
105 {
106 break;
107 }
108 }
109
110 /* Dump the name, up to the start of the trailing underscores */
111
112 for (i = 0; i < Length; i++)
113 {
114 AcpiOsPrintf ("%c", NewName[i]);
115 }
116
117 return (Length);
118 }
119
120
121 /*******************************************************************************
122 *
123 * FUNCTION: AcpiPsDisplayObjectPathname
124 *
125 * PARAMETERS: WalkState - Current walk state
126 * Op - Object whose pathname is to be obtained
127 *
128 * RETURN: Status
129 *
130 * DESCRIPTION: Diplay the pathname associated with a named object. Two
131 * versions. One searches the parse tree (for parser-only
132 * applications suchas AcpiDump), and the other searches the
133 * ACPI namespace (the parse tree is probably deleted)
134 *
135 ******************************************************************************/
136
137 ACPI_STATUS
138 AcpiPsDisplayObjectPathname (
139 ACPI_WALK_STATE *WalkState,
140 ACPI_PARSE_OBJECT *Op)
141 {
142 ACPI_STATUS Status;
143 ACPI_NAMESPACE_NODE *Node;
144 ACPI_BUFFER Buffer;
145 UINT32 DebugLevel;
146
147
148 /* Save current debug level so we don't get extraneous debug output */
149
150 DebugLevel = AcpiDbgLevel;
151 AcpiDbgLevel = 0;
152
153 /* Just get the Node out of the Op object */
154
155 Node = Op->Common.Node;
156 if (!Node)
157 {
158 /* Node not defined in this scope, look it up */
159
160 Status = AcpiNsLookup (WalkState->ScopeInfo, Op->Common.Value.String,
161 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
162 WalkState, &(Node));
163
164 if (ACPI_FAILURE (Status))
165 {
166 /*
167 * We can't get the pathname since the object
168 * is not in the namespace. This can happen during single
169 * stepping where a dynamic named object is *about* to be created.
170 */
171 AcpiOsPrintf (" [Path not found]");
172 goto Exit;
173 }
174
175 /* Save it for next time. */
176
177 Op->Common.Node = Node;
178 }
179
180 /* Convert NamedDesc/handle to a full pathname */
181
182 Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
183 Status = AcpiNsHandleToPathname (Node, &Buffer);
184 if (ACPI_FAILURE (Status))
185 {
186 AcpiOsPrintf ("****Could not get pathname****)");
187 goto Exit;
188 }
189
190 AcpiOsPrintf (" (Path %s)", (char *) Buffer.Pointer);
191 ACPI_FREE (Buffer.Pointer);
192
193
194 Exit:
195 /* Restore the debug level */
196
197 AcpiDbgLevel = DebugLevel;
198 return (Status);
199 }
200
201
202 /*******************************************************************************
203 *
204 * FUNCTION: AcpiDmNamestring
205 *
206 * PARAMETERS: Name - ACPI Name string to store
207 *
208 * RETURN: None
209 *
210 * DESCRIPTION: Decode and dump an ACPI namestring. Handles prefix characters
211 *
212 ******************************************************************************/
213
214 void
215 AcpiDmNamestring (
216 char *Name)
217 {
218 UINT32 SegCount;
219
220
221 if (!Name)
222 {
223 return;
224 }
225
226 /* Handle all Scope Prefix operators */
227
228 while (ACPI_IS_ROOT_PREFIX (ACPI_GET8 (Name)) ||
229 ACPI_IS_PARENT_PREFIX (ACPI_GET8 (Name)))
230 {
231 /* Append prefix character */
232
233 AcpiOsPrintf ("%1c", ACPI_GET8 (Name));
234 Name++;
235 }
236
237 switch (ACPI_GET8 (Name))
238 {
239 case 0:
240
241 SegCount = 0;
242 break;
243
244 case AML_DUAL_NAME_PREFIX:
245
246 SegCount = 2;
247 Name++;
248 break;
249
250 case AML_MULTI_NAME_PREFIX_OP:
251
252 SegCount = (UINT32) ACPI_GET8 (Name + 1);
253 Name += 2;
254 break;
255
256 default:
257
258 SegCount = 1;
259 break;
260 }
261
262 while (SegCount)
263 {
264 /* Append Name segment */
265
266 AcpiDmDumpName (*ACPI_CAST_PTR (UINT32, Name));
267
268 SegCount--;
269 if (SegCount)
270 {
271 /* Not last name, append dot separator */
272
273 AcpiOsPrintf (".");
274 }
275 Name += ACPI_NAME_SIZE;
276 }
277 }
278
279
280 #ifdef ACPI_OBSOLETE_FUNCTIONS
281 /*******************************************************************************
282 *
283 * FUNCTION: AcpiDmDisplayPath
284 *
285 * PARAMETERS: Op - Named Op whose path is to be constructed
286 *
287 * RETURN: None
288 *
289 * DESCRIPTION: Walk backwards from current scope and display the name
290 * of each previous level of scope up to the root scope
291 * (like "pwd" does with file systems)
292 *
293 ******************************************************************************/
294
295 void
296 AcpiDmDisplayPath (
297 ACPI_PARSE_OBJECT *Op)
298 {
299 ACPI_PARSE_OBJECT *Prev;
300 ACPI_PARSE_OBJECT *Search;
301 UINT32 Name;
302 BOOLEAN DoDot = FALSE;
303 ACPI_PARSE_OBJECT *NamePath;
304 const ACPI_OPCODE_INFO *OpInfo;
305
306
307 /* We are only interested in named objects */
308
309 OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
310 if (!(OpInfo->Flags & AML_NSNODE))
311 {
312 return;
313 }
314
315 if (OpInfo->Flags & AML_CREATE)
316 {
317 /* Field creation - check for a fully qualified namepath */
318
319 if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)
320 {
321 NamePath = AcpiPsGetArg (Op, 3);
322 }
323 else
324 {
325 NamePath = AcpiPsGetArg (Op, 2);
326 }
327
328 if ((NamePath) &&
329 (NamePath->Common.Value.String) &&
330 (ACPI_IS_ROOT_PREFIX (NamePath->Common.Value.String[0])))
331 {
332 AcpiDmNamestring (NamePath->Common.Value.String);
333 return;
334 }
335 }
336
337 Prev = NULL; /* Start with Root Node */
338
339 while (Prev != Op)
340 {
341 /* Search upwards in the tree to find scope with "prev" as its parent */
342
343 Search = Op;
344 for (; ;)
345 {
346 if (Search->Common.Parent == Prev)
347 {
348 break;
349 }
350
351 /* Go up one level */
352
353 Search = Search->Common.Parent;
354 }
355
356 if (Prev)
357 {
358 OpInfo = AcpiPsGetOpcodeInfo (Search->Common.AmlOpcode);
359 if (!(OpInfo->Flags & AML_FIELD))
360 {
361 /* Below root scope, append scope name */
362
363 if (DoDot)
364 {
365 /* Append dot */
366
367 AcpiOsPrintf (".");
368 }
369
370 if (OpInfo->Flags & AML_CREATE)
371 {
372 if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)
373 {
374 NamePath = AcpiPsGetArg (Op, 3);
375 }
376 else
377 {
378 NamePath = AcpiPsGetArg (Op, 2);
379 }
380
381 if ((NamePath) &&
382 (NamePath->Common.Value.String))
383 {
384 AcpiDmDumpName (NamePath->Common.Value.String);
385 }
386 }
387 else
388 {
389 Name = AcpiPsGetName (Search);
390 AcpiDmDumpName ((char *) &Name);
391 }
392
393 DoDot = TRUE;
394 }
395 }
396 Prev = Search;
397 }
398 }
399
400
401 /*******************************************************************************
402 *
403 * FUNCTION: AcpiDmValidateName
404 *
405 * PARAMETERS: Name - 4 character ACPI name
406 *
407 * RETURN: None
408 *
409 * DESCRIPTION: Lookup the name
410 *
411 ******************************************************************************/
412
413 void
414 AcpiDmValidateName (
415 char *Name,
416 ACPI_PARSE_OBJECT *Op)
417 {
418
419 if ((!Name) ||
420 (!Op->Common.Parent))
421 {
422 return;
423 }
424
425 if (!Op->Common.Node)
426 {
427 AcpiOsPrintf (
428 " /**** Name not found or not accessible from this scope ****/ ");
429 }
430
431 ACPI_PARSE_OBJECT *TargetOp;
432
433
434 if ((!Name) ||
435 (!Op->Common.Parent))
436 {
437 return;
438 }
439
440 TargetOp = AcpiPsFind (Op, Name, 0, 0);
441 if (!TargetOp)
442 {
443 /*
444 * Didn't find the name in the parse tree. This may be
445 * a problem, or it may simply be one of the predefined names
446 * (such as _OS_). Rather than worry about looking up all
447 * the predefined names, just display the name as given
448 */
449 AcpiOsPrintf (
450 " /**** Name not found or not accessible from this scope ****/ ");
451 }
452 }
453 #endif
454
455 #endif
456