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