xref: /illumos-gate/usr/src/common/acpica/namespace/nsdump.c (revision 9b9d39d2a32ff806d2431dbcc50968ef1e6d46b2)
1 /******************************************************************************
2  *
3  * Module Name: nsdump - table dumping routines for debug
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights. You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25 
26  * make derivatives, distribute, use and display any portion of the Covered
27  * Code in any form, with the right to sublicense such rights; and
28  *
29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30  * license (with the right to sublicense), under only those claims of Intel
31  * patents that are infringed by the Original Intel Code, to make, use, sell,
32  * offer to sell, and import the Covered Code and derivative works thereof
33  * solely to the minimum extent necessary to exercise the above copyright
34  * license, and in no event shall the patent license extend to any additions
35  * to or modifications of the Original Intel Code. No other license or right
36  * is granted directly or by implication, estoppel or otherwise;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44  * Redistribution of source code of any substantial portion of the Covered
45  * Code or modification with rights to further distribute source must include
46  * the above Copyright Notice, the above License, this list of Conditions,
47  * and the following Disclaimer and Export Compliance provision. In addition,
48  * Licensee must cause all Covered Code to which Licensee contributes to
49  * contain a file documenting the changes Licensee made to create that Covered
50  * Code and the date of any change. Licensee must include in that file the
51  * documentation of any changes made by any predecessor Licensee. Licensee
52  * must include a prominent statement that the modification is derived,
53  * directly or indirectly, from Original Intel Code.
54  *
55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56  * Redistribution of source code of any substantial portion of the Covered
57  * Code or modification without rights to further distribute source must
58  * include the following Disclaimer and Export Compliance provision in the
59  * documentation and/or other materials provided with distribution. In
60  * addition, Licensee may not authorize further sublicense of source of any
61  * portion of the Covered Code, and must include terms to the effect that the
62  * license from Licensee to its licensee is limited to the intellectual
63  * property embodied in the software Licensee provides to its licensee, and
64  * not to intellectual property embodied in modifications its licensee may
65  * make.
66  *
67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68  * substantial portion of the Covered Code or modification must reproduce the
69  * above Copyright Notice, and the following Disclaimer and Export Compliance
70  * provision in the documentation and/or other materials provided with the
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77  * Intel shall be used in advertising or otherwise to promote the sale, use or
78  * other dealings in products derived from or relating to the Covered Code
79  * without prior written authorization from Intel.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89  * PARTICULAR PURPOSE.
90  *
91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98  * LIMITED REMEDY.
99  *
100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101  * software or system incorporating such software without first obtaining any
102  * required license or other approval from the U. S. Department of Commerce or
103  * any other agency or department of the United States Government. In the
104  * event Licensee exports any such software from the United States or
105  * re-exports any such software from a foreign destination, Licensee shall
106  * ensure that the distribution and export/re-export of the software is in
107  * compliance with all laws, regulations, orders, or other restrictions of the
108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109  * any of its subsidiaries will export/re-export any technical data, process,
110  * software, or service, directly or indirectly, to any country for which the
111  * United States government or any agency thereof requires an export license,
112  * other governmental approval, or letter of assurance, without first obtaining
113  * such license, approval or letter.
114  *
115  *****************************************************************************
116  *
117  * Alternatively, you may choose to be licensed under the terms of the
118  * following license:
119  *
120  * Redistribution and use in source and binary forms, with or without
121  * modification, are permitted provided that the following conditions
122  * are met:
123  * 1. Redistributions of source code must retain the above copyright
124  *    notice, this list of conditions, and the following disclaimer,
125  *    without modification.
126  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
127  *    substantially similar to the "NO WARRANTY" disclaimer below
128  *    ("Disclaimer") and any redistribution must be conditioned upon
129  *    including a substantially similar Disclaimer requirement for further
130  *    binary redistribution.
131  * 3. Neither the names of the above-listed copyright holders nor the names
132  *    of any contributors may be used to endorse or promote products derived
133  *    from this software without specific prior written permission.
134  *
135  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
136  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
137  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
138  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
139  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
140  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
141  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
142  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
143  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
144  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
145  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146  *
147  * Alternatively, you may choose to be licensed under the terms of the
148  * GNU General Public License ("GPL") version 2 as published by the Free
149  * Software Foundation.
150  *
151  *****************************************************************************/
152 
153 #include "acpi.h"
154 #include "accommon.h"
155 #include "acnamesp.h"
156 #include "acoutput.h"
157 
158 
159 #define _COMPONENT          ACPI_NAMESPACE
160         ACPI_MODULE_NAME    ("nsdump")
161 
162 /* Local prototypes */
163 
164 #ifdef ACPI_OBSOLETE_FUNCTIONS
165 void
166 AcpiNsDumpRootDevices (
167     void);
168 
169 static ACPI_STATUS
170 AcpiNsDumpOneDevice (
171     ACPI_HANDLE             ObjHandle,
172     UINT32                  Level,
173     void                    *Context,
174     void                    **ReturnValue);
175 #endif
176 
177 
178 #if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
179 
180 static ACPI_STATUS
181 AcpiNsDumpOneObjectPath (
182     ACPI_HANDLE             ObjHandle,
183     UINT32                  Level,
184     void                    *Context,
185     void                    **ReturnValue);
186 
187 static ACPI_STATUS
188 AcpiNsGetMaxDepth (
189     ACPI_HANDLE             ObjHandle,
190     UINT32                  Level,
191     void                    *Context,
192     void                    **ReturnValue);
193 
194 
195 /*******************************************************************************
196  *
197  * FUNCTION:    AcpiNsPrintPathname
198  *
199  * PARAMETERS:  NumSegments         - Number of ACPI name segments
200  *              Pathname            - The compressed (internal) path
201  *
202  * RETURN:      None
203  *
204  * DESCRIPTION: Print an object's full namespace pathname
205  *
206  ******************************************************************************/
207 
208 void
209 AcpiNsPrintPathname (
210     UINT32                  NumSegments,
211     const char              *Pathname)
212 {
213     UINT32                  i;
214 
215 
216     ACPI_FUNCTION_NAME (NsPrintPathname);
217 
218 
219     /* Check if debug output enabled */
220 
221     if (!ACPI_IS_DEBUG_ENABLED (ACPI_LV_NAMES, ACPI_NAMESPACE))
222     {
223         return;
224     }
225 
226     /* Print the entire name */
227 
228     ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "["));
229 
230     while (NumSegments)
231     {
232         for (i = 0; i < 4; i++)
233         {
234             isprint ((int) Pathname[i]) ?
235                 AcpiOsPrintf ("%c", Pathname[i]) :
236                 AcpiOsPrintf ("?");
237         }
238 
239         Pathname += ACPI_NAME_SIZE;
240         NumSegments--;
241         if (NumSegments)
242         {
243             AcpiOsPrintf (".");
244         }
245     }
246 
247     AcpiOsPrintf ("]\n");
248 }
249 
250 
251 #ifdef ACPI_OBSOLETE_FUNCTIONS
252 /* Not used at this time, perhaps later */
253 
254 /*******************************************************************************
255  *
256  * FUNCTION:    AcpiNsDumpPathname
257  *
258  * PARAMETERS:  Handle              - Object
259  *              Msg                 - Prefix message
260  *              Level               - Desired debug level
261  *              Component           - Caller's component ID
262  *
263  * RETURN:      None
264  *
265  * DESCRIPTION: Print an object's full namespace pathname
266  *              Manages allocation/freeing of a pathname buffer
267  *
268  ******************************************************************************/
269 
270 void
271 AcpiNsDumpPathname (
272     ACPI_HANDLE             Handle,
273     const char              *Msg,
274     UINT32                  Level,
275     UINT32                  Component)
276 {
277 
278     ACPI_FUNCTION_TRACE (NsDumpPathname);
279 
280 
281     /* Do this only if the requested debug level and component are enabled */
282 
283     if (!ACPI_IS_DEBUG_ENABLED (Level, Component))
284     {
285         return_VOID;
286     }
287 
288     /* Convert handle to a full pathname and print it (with supplied message) */
289 
290     AcpiNsPrintNodePathname (Handle, Msg);
291     AcpiOsPrintf ("\n");
292     return_VOID;
293 }
294 #endif
295 
296 
297 /*******************************************************************************
298  *
299  * FUNCTION:    AcpiNsDumpOneObject
300  *
301  * PARAMETERS:  ObjHandle           - Node to be dumped
302  *              Level               - Nesting level of the handle
303  *              Context             - Passed into WalkNamespace
304  *              ReturnValue         - Not used
305  *
306  * RETURN:      Status
307  *
308  * DESCRIPTION: Dump a single Node
309  *              This procedure is a UserFunction called by AcpiNsWalkNamespace.
310  *
311  ******************************************************************************/
312 
313 ACPI_STATUS
314 AcpiNsDumpOneObject (
315     ACPI_HANDLE             ObjHandle,
316     UINT32                  Level,
317     void                    *Context,
318     void                    **ReturnValue)
319 {
320     ACPI_WALK_INFO          *Info = (ACPI_WALK_INFO *) Context;
321     ACPI_NAMESPACE_NODE     *ThisNode;
322     ACPI_OPERAND_OBJECT     *ObjDesc = NULL;
323     ACPI_OBJECT_TYPE        ObjType;
324     ACPI_OBJECT_TYPE        Type;
325     UINT32                  BytesToDump;
326     UINT32                  DbgLevel;
327     UINT32                  i;
328 
329 
330     ACPI_FUNCTION_NAME (NsDumpOneObject);
331 
332 
333     /* Is output enabled? */
334 
335     if (!(AcpiDbgLevel & Info->DebugLevel))
336     {
337         return (AE_OK);
338     }
339 
340     if (!ObjHandle)
341     {
342         ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Null object handle\n"));
343         return (AE_OK);
344     }
345 
346     ThisNode = AcpiNsValidateHandle (ObjHandle);
347     if (!ThisNode)
348     {
349         ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Invalid object handle %p\n",
350             ObjHandle));
351         return (AE_OK);
352     }
353 
354     Type = ThisNode->Type;
355     Info->Count++;
356 
357     /* Check if the owner matches */
358 
359     if ((Info->OwnerId != ACPI_OWNER_ID_MAX) &&
360         (Info->OwnerId != ThisNode->OwnerId))
361     {
362         return (AE_OK);
363     }
364 
365     if (!(Info->DisplayType & ACPI_DISPLAY_SHORT))
366     {
367         /* Indent the object according to the level */
368 
369         AcpiOsPrintf ("%2d%*s", (UINT32) Level - 1, (int) Level * 2, " ");
370 
371         /* Check the node type and name */
372 
373         if (Type > ACPI_TYPE_LOCAL_MAX)
374         {
375             ACPI_WARNING ((AE_INFO,
376                 "Invalid ACPI Object Type 0x%08X", Type));
377         }
378 
379         AcpiOsPrintf ("%4.4s", AcpiUtGetNodeName (ThisNode));
380     }
381 
382     /* Now we can print out the pertinent information */
383 
384     AcpiOsPrintf (" %-12s %p %2.2X ",
385         AcpiUtGetTypeName (Type), ThisNode, ThisNode->OwnerId);
386 
387     DbgLevel = AcpiDbgLevel;
388     AcpiDbgLevel = 0;
389     ObjDesc = AcpiNsGetAttachedObject (ThisNode);
390     AcpiDbgLevel = DbgLevel;
391 
392     /* Temp nodes are those nodes created by a control method */
393 
394     if (ThisNode->Flags & ANOBJ_TEMPORARY)
395     {
396         AcpiOsPrintf ("(T) ");
397     }
398 
399     switch (Info->DisplayType & ACPI_DISPLAY_MASK)
400     {
401     case ACPI_DISPLAY_SUMMARY:
402 
403         if (!ObjDesc)
404         {
405             /* No attached object. Some types should always have an object */
406 
407             switch (Type)
408             {
409             case ACPI_TYPE_INTEGER:
410             case ACPI_TYPE_PACKAGE:
411             case ACPI_TYPE_BUFFER:
412             case ACPI_TYPE_STRING:
413             case ACPI_TYPE_METHOD:
414 
415                 AcpiOsPrintf ("<No attached object>");
416                 break;
417 
418             default:
419 
420                 break;
421             }
422 
423             AcpiOsPrintf ("\n");
424             return (AE_OK);
425         }
426 
427         switch (Type)
428         {
429         case ACPI_TYPE_PROCESSOR:
430 
431             AcpiOsPrintf ("ID %02X Len %02X Addr %8.8X%8.8X\n",
432                 ObjDesc->Processor.ProcId, ObjDesc->Processor.Length,
433                 ACPI_FORMAT_UINT64 (ObjDesc->Processor.Address));
434             break;
435 
436         case ACPI_TYPE_DEVICE:
437 
438             AcpiOsPrintf ("Notify Object: %p\n", ObjDesc);
439             break;
440 
441         case ACPI_TYPE_METHOD:
442 
443             AcpiOsPrintf ("Args %X Len %.4X Aml %p\n",
444                 (UINT32) ObjDesc->Method.ParamCount,
445                 ObjDesc->Method.AmlLength, ObjDesc->Method.AmlStart);
446             break;
447 
448         case ACPI_TYPE_INTEGER:
449 
450             AcpiOsPrintf ("= %8.8X%8.8X\n",
451                 ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
452             break;
453 
454         case ACPI_TYPE_PACKAGE:
455 
456             if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
457             {
458                 AcpiOsPrintf ("Elements %.2X\n",
459                     ObjDesc->Package.Count);
460             }
461             else
462             {
463                 AcpiOsPrintf ("[Length not yet evaluated]\n");
464             }
465             break;
466 
467         case ACPI_TYPE_BUFFER:
468 
469             if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
470             {
471                 AcpiOsPrintf ("Len %.2X",
472                     ObjDesc->Buffer.Length);
473 
474                 /* Dump some of the buffer */
475 
476                 if (ObjDesc->Buffer.Length > 0)
477                 {
478                     AcpiOsPrintf (" =");
479                     for (i = 0; (i < ObjDesc->Buffer.Length && i < 12); i++)
480                     {
481                         AcpiOsPrintf (" %.2hX", ObjDesc->Buffer.Pointer[i]);
482                     }
483                 }
484                 AcpiOsPrintf ("\n");
485             }
486             else
487             {
488                 AcpiOsPrintf ("[Length not yet evaluated]\n");
489             }
490             break;
491 
492         case ACPI_TYPE_STRING:
493 
494             AcpiOsPrintf ("Len %.2X ", ObjDesc->String.Length);
495             AcpiUtPrintString (ObjDesc->String.Pointer, 80);
496             AcpiOsPrintf ("\n");
497             break;
498 
499         case ACPI_TYPE_REGION:
500 
501             AcpiOsPrintf ("[%s]",
502                 AcpiUtGetRegionName (ObjDesc->Region.SpaceId));
503             if (ObjDesc->Region.Flags & AOPOBJ_DATA_VALID)
504             {
505                 AcpiOsPrintf (" Addr %8.8X%8.8X Len %.4X\n",
506                     ACPI_FORMAT_UINT64 (ObjDesc->Region.Address),
507                     ObjDesc->Region.Length);
508             }
509             else
510             {
511                 AcpiOsPrintf (" [Address/Length not yet evaluated]\n");
512             }
513             break;
514 
515         case ACPI_TYPE_LOCAL_REFERENCE:
516 
517             AcpiOsPrintf ("[%s]\n", AcpiUtGetReferenceName (ObjDesc));
518             break;
519 
520         case ACPI_TYPE_BUFFER_FIELD:
521 
522             if (ObjDesc->BufferField.BufferObj &&
523                 ObjDesc->BufferField.BufferObj->Buffer.Node)
524             {
525                 AcpiOsPrintf ("Buf [%4.4s]",
526                     AcpiUtGetNodeName (
527                         ObjDesc->BufferField.BufferObj->Buffer.Node));
528             }
529             break;
530 
531         case ACPI_TYPE_LOCAL_REGION_FIELD:
532 
533             AcpiOsPrintf ("Rgn [%4.4s]",
534                 AcpiUtGetNodeName (
535                     ObjDesc->CommonField.RegionObj->Region.Node));
536             break;
537 
538         case ACPI_TYPE_LOCAL_BANK_FIELD:
539 
540             AcpiOsPrintf ("Rgn [%4.4s] Bnk [%4.4s]",
541                 AcpiUtGetNodeName (
542                     ObjDesc->CommonField.RegionObj->Region.Node),
543                 AcpiUtGetNodeName (
544                     ObjDesc->BankField.BankObj->CommonField.Node));
545             break;
546 
547         case ACPI_TYPE_LOCAL_INDEX_FIELD:
548 
549             AcpiOsPrintf ("Idx [%4.4s] Dat [%4.4s]",
550                 AcpiUtGetNodeName (
551                     ObjDesc->IndexField.IndexObj->CommonField.Node),
552                 AcpiUtGetNodeName (
553                     ObjDesc->IndexField.DataObj->CommonField.Node));
554             break;
555 
556         case ACPI_TYPE_LOCAL_ALIAS:
557         case ACPI_TYPE_LOCAL_METHOD_ALIAS:
558 
559             AcpiOsPrintf ("Target %4.4s (%p)\n",
560                 AcpiUtGetNodeName (ObjDesc), ObjDesc);
561             break;
562 
563         default:
564 
565             AcpiOsPrintf ("Object %p\n", ObjDesc);
566             break;
567         }
568 
569         /* Common field handling */
570 
571         switch (Type)
572         {
573         case ACPI_TYPE_BUFFER_FIELD:
574         case ACPI_TYPE_LOCAL_REGION_FIELD:
575         case ACPI_TYPE_LOCAL_BANK_FIELD:
576         case ACPI_TYPE_LOCAL_INDEX_FIELD:
577 
578             AcpiOsPrintf (" Off %.3X Len %.2X Acc %.2hd\n",
579                 (ObjDesc->CommonField.BaseByteOffset * 8)
580                     + ObjDesc->CommonField.StartFieldBitOffset,
581                 ObjDesc->CommonField.BitLength,
582                 ObjDesc->CommonField.AccessByteWidth);
583             break;
584 
585         default:
586 
587             break;
588         }
589         break;
590 
591     case ACPI_DISPLAY_OBJECTS:
592 
593         AcpiOsPrintf ("O:%p", ObjDesc);
594         if (!ObjDesc)
595         {
596             /* No attached object, we are done */
597 
598             AcpiOsPrintf ("\n");
599             return (AE_OK);
600         }
601 
602         AcpiOsPrintf ("(R%u)", ObjDesc->Common.ReferenceCount);
603 
604         switch (Type)
605         {
606         case ACPI_TYPE_METHOD:
607 
608             /* Name is a Method and its AML offset/length are set */
609 
610             AcpiOsPrintf (" M:%p-%X\n", ObjDesc->Method.AmlStart,
611                 ObjDesc->Method.AmlLength);
612             break;
613 
614         case ACPI_TYPE_INTEGER:
615 
616             AcpiOsPrintf (" I:%8.8X8.8%X\n",
617                 ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
618             break;
619 
620         case ACPI_TYPE_STRING:
621 
622             AcpiOsPrintf (" S:%p-%X\n", ObjDesc->String.Pointer,
623                 ObjDesc->String.Length);
624             break;
625 
626         case ACPI_TYPE_BUFFER:
627 
628             AcpiOsPrintf (" B:%p-%X\n", ObjDesc->Buffer.Pointer,
629                 ObjDesc->Buffer.Length);
630             break;
631 
632         default:
633 
634             AcpiOsPrintf ("\n");
635             break;
636         }
637         break;
638 
639     default:
640         AcpiOsPrintf ("\n");
641         break;
642     }
643 
644     /* If debug turned off, done */
645 
646     if (!(AcpiDbgLevel & ACPI_LV_VALUES))
647     {
648         return (AE_OK);
649     }
650 
651     /* If there is an attached object, display it */
652 
653     DbgLevel = AcpiDbgLevel;
654     AcpiDbgLevel = 0;
655     ObjDesc = AcpiNsGetAttachedObject (ThisNode);
656     AcpiDbgLevel = DbgLevel;
657 
658     /* Dump attached objects */
659 
660     while (ObjDesc)
661     {
662         ObjType = ACPI_TYPE_INVALID;
663         AcpiOsPrintf ("Attached Object %p: ", ObjDesc);
664 
665         /* Decode the type of attached object and dump the contents */
666 
667         switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
668         {
669         case ACPI_DESC_TYPE_NAMED:
670 
671             AcpiOsPrintf ("(Ptr to Node)\n");
672             BytesToDump = sizeof (ACPI_NAMESPACE_NODE);
673             ACPI_DUMP_BUFFER (ObjDesc, BytesToDump);
674             break;
675 
676         case ACPI_DESC_TYPE_OPERAND:
677 
678             ObjType = ObjDesc->Common.Type;
679 
680             if (ObjType > ACPI_TYPE_LOCAL_MAX)
681             {
682                 AcpiOsPrintf (
683                     "(Pointer to ACPI Object type %.2X [UNKNOWN])\n",
684                     ObjType);
685 
686                 BytesToDump = 32;
687             }
688             else
689             {
690                 AcpiOsPrintf (
691                     "(Pointer to ACPI Object type %.2X [%s])\n",
692                     ObjType, AcpiUtGetTypeName (ObjType));
693 
694                 BytesToDump = sizeof (ACPI_OPERAND_OBJECT);
695             }
696 
697             ACPI_DUMP_BUFFER (ObjDesc, BytesToDump);
698             break;
699 
700         default:
701 
702             break;
703         }
704 
705         /* If value is NOT an internal object, we are done */
706 
707         if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) != ACPI_DESC_TYPE_OPERAND)
708         {
709             goto Cleanup;
710         }
711 
712         /* Valid object, get the pointer to next level, if any */
713 
714         switch (ObjType)
715         {
716         case ACPI_TYPE_BUFFER:
717         case ACPI_TYPE_STRING:
718             /*
719              * NOTE: takes advantage of common fields between string/buffer
720              */
721             BytesToDump = ObjDesc->String.Length;
722             ObjDesc = (void *) ObjDesc->String.Pointer;
723 
724             AcpiOsPrintf ("(Buffer/String pointer %p length %X)\n",
725                 ObjDesc, BytesToDump);
726             ACPI_DUMP_BUFFER (ObjDesc, BytesToDump);
727             goto Cleanup;
728 
729         case ACPI_TYPE_BUFFER_FIELD:
730 
731             ObjDesc = (ACPI_OPERAND_OBJECT *) ObjDesc->BufferField.BufferObj;
732             break;
733 
734         case ACPI_TYPE_PACKAGE:
735 
736             ObjDesc = (void *) ObjDesc->Package.Elements;
737             break;
738 
739         case ACPI_TYPE_METHOD:
740 
741             ObjDesc = (void *) ObjDesc->Method.AmlStart;
742             break;
743 
744         case ACPI_TYPE_LOCAL_REGION_FIELD:
745 
746             ObjDesc = (void *) ObjDesc->Field.RegionObj;
747             break;
748 
749         case ACPI_TYPE_LOCAL_BANK_FIELD:
750 
751             ObjDesc = (void *) ObjDesc->BankField.RegionObj;
752             break;
753 
754         case ACPI_TYPE_LOCAL_INDEX_FIELD:
755 
756             ObjDesc = (void *) ObjDesc->IndexField.IndexObj;
757             break;
758 
759         default:
760 
761             goto Cleanup;
762         }
763 
764         ObjType = ACPI_TYPE_INVALID;   /* Terminate loop after next pass */
765     }
766 
767 Cleanup:
768     AcpiOsPrintf ("\n");
769     return (AE_OK);
770 }
771 
772 
773 /*******************************************************************************
774  *
775  * FUNCTION:    AcpiNsDumpObjects
776  *
777  * PARAMETERS:  Type                - Object type to be dumped
778  *              DisplayType         - 0 or ACPI_DISPLAY_SUMMARY
779  *              MaxDepth            - Maximum depth of dump. Use ACPI_UINT32_MAX
780  *                                    for an effectively unlimited depth.
781  *              OwnerId             - Dump only objects owned by this ID. Use
782  *                                    ACPI_UINT32_MAX to match all owners.
783  *              StartHandle         - Where in namespace to start/end search
784  *
785  * RETURN:      None
786  *
787  * DESCRIPTION: Dump typed objects within the loaded namespace. Uses
788  *              AcpiNsWalkNamespace in conjunction with AcpiNsDumpOneObject.
789  *
790  ******************************************************************************/
791 
792 void
793 AcpiNsDumpObjects (
794     ACPI_OBJECT_TYPE        Type,
795     UINT8                   DisplayType,
796     UINT32                  MaxDepth,
797     ACPI_OWNER_ID           OwnerId,
798     ACPI_HANDLE             StartHandle)
799 {
800     ACPI_WALK_INFO          Info;
801     ACPI_STATUS             Status;
802 
803 
804     ACPI_FUNCTION_ENTRY ();
805 
806 
807     /*
808      * Just lock the entire namespace for the duration of the dump.
809      * We don't want any changes to the namespace during this time,
810      * especially the temporary nodes since we are going to display
811      * them also.
812      */
813     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
814     if (ACPI_FAILURE (Status))
815     {
816         AcpiOsPrintf ("Could not acquire namespace mutex\n");
817         return;
818     }
819 
820     Info.Count = 0;
821     Info.DebugLevel = ACPI_LV_TABLES;
822     Info.OwnerId = OwnerId;
823     Info.DisplayType = DisplayType;
824 
825     (void) AcpiNsWalkNamespace (Type, StartHandle, MaxDepth,
826         ACPI_NS_WALK_NO_UNLOCK | ACPI_NS_WALK_TEMP_NODES,
827         AcpiNsDumpOneObject, NULL, (void *) &Info, NULL);
828 
829     AcpiOsPrintf ("\nNamespace node count: %u\n\n", Info.Count);
830     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
831 }
832 
833 
834 /*******************************************************************************
835  *
836  * FUNCTION:    AcpiNsDumpOneObjectPath, AcpiNsGetMaxDepth
837  *
838  * PARAMETERS:  ObjHandle           - Node to be dumped
839  *              Level               - Nesting level of the handle
840  *              Context             - Passed into WalkNamespace
841  *              ReturnValue         - Not used
842  *
843  * RETURN:      Status
844  *
845  * DESCRIPTION: Dump the full pathname to a namespace object. AcpNsGetMaxDepth
846  *              computes the maximum nesting depth in the namespace tree, in
847  *              order to simplify formatting in AcpiNsDumpOneObjectPath.
848  *              These procedures are UserFunctions called by AcpiNsWalkNamespace.
849  *
850  ******************************************************************************/
851 
852 static ACPI_STATUS
853 AcpiNsDumpOneObjectPath (
854     ACPI_HANDLE             ObjHandle,
855     UINT32                  Level,
856     void                    *Context,
857     void                    **ReturnValue)
858 {
859     UINT32                  MaxLevel = *((UINT32 *) Context);
860     char                    *Pathname;
861     ACPI_NAMESPACE_NODE     *Node;
862     int                     PathIndent;
863 
864 
865     if (!ObjHandle)
866     {
867         return (AE_OK);
868     }
869 
870     Node = AcpiNsValidateHandle (ObjHandle);
871     if (!Node)
872     {
873         /* Ignore bad node during namespace walk */
874 
875         return (AE_OK);
876     }
877 
878     Pathname = AcpiNsGetNormalizedPathname (Node, TRUE);
879 
880     PathIndent = 1;
881     if (Level <= MaxLevel)
882     {
883         PathIndent = MaxLevel - Level + 1;
884     }
885 
886     AcpiOsPrintf ("%2d%*s%-12s%*s",
887         Level, Level, " ", AcpiUtGetTypeName (Node->Type),
888         PathIndent, " ");
889 
890     AcpiOsPrintf ("%s\n", &Pathname[1]);
891     ACPI_FREE (Pathname);
892     return (AE_OK);
893 }
894 
895 
896 static ACPI_STATUS
897 AcpiNsGetMaxDepth (
898     ACPI_HANDLE             ObjHandle,
899     UINT32                  Level,
900     void                    *Context,
901     void                    **ReturnValue)
902 {
903     UINT32                  *MaxLevel = (UINT32 *) Context;
904 
905 
906     if (Level > *MaxLevel)
907     {
908         *MaxLevel = Level;
909     }
910     return (AE_OK);
911 }
912 
913 
914 /*******************************************************************************
915  *
916  * FUNCTION:    AcpiNsDumpObjectPaths
917  *
918  * PARAMETERS:  Type                - Object type to be dumped
919  *              DisplayType         - 0 or ACPI_DISPLAY_SUMMARY
920  *              MaxDepth            - Maximum depth of dump. Use ACPI_UINT32_MAX
921  *                                    for an effectively unlimited depth.
922  *              OwnerId             - Dump only objects owned by this ID. Use
923  *                                    ACPI_UINT32_MAX to match all owners.
924  *              StartHandle         - Where in namespace to start/end search
925  *
926  * RETURN:      None
927  *
928  * DESCRIPTION: Dump full object pathnames within the loaded namespace. Uses
929  *              AcpiNsWalkNamespace in conjunction with AcpiNsDumpOneObjectPath.
930  *
931  ******************************************************************************/
932 
933 void
934 AcpiNsDumpObjectPaths (
935     ACPI_OBJECT_TYPE        Type,
936     UINT8                   DisplayType,
937     UINT32                  MaxDepth,
938     ACPI_OWNER_ID           OwnerId,
939     ACPI_HANDLE             StartHandle)
940 {
941     ACPI_STATUS             Status;
942     UINT32                  MaxLevel = 0;
943 
944 
945     ACPI_FUNCTION_ENTRY ();
946 
947 
948     /*
949      * Just lock the entire namespace for the duration of the dump.
950      * We don't want any changes to the namespace during this time,
951      * especially the temporary nodes since we are going to display
952      * them also.
953      */
954     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
955     if (ACPI_FAILURE (Status))
956     {
957         AcpiOsPrintf ("Could not acquire namespace mutex\n");
958         return;
959     }
960 
961     /* Get the max depth of the namespace tree, for formatting later */
962 
963     (void) AcpiNsWalkNamespace (Type, StartHandle, MaxDepth,
964         ACPI_NS_WALK_NO_UNLOCK | ACPI_NS_WALK_TEMP_NODES,
965         AcpiNsGetMaxDepth, NULL, (void *) &MaxLevel, NULL);
966 
967     /* Now dump the entire namespace */
968 
969     (void) AcpiNsWalkNamespace (Type, StartHandle, MaxDepth,
970         ACPI_NS_WALK_NO_UNLOCK | ACPI_NS_WALK_TEMP_NODES,
971         AcpiNsDumpOneObjectPath, NULL, (void *) &MaxLevel, NULL);
972 
973     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
974 }
975 
976 
977 /*******************************************************************************
978  *
979  * FUNCTION:    AcpiNsDumpEntry
980  *
981  * PARAMETERS:  Handle              - Node to be dumped
982  *              DebugLevel          - Output level
983  *
984  * RETURN:      None
985  *
986  * DESCRIPTION: Dump a single Node
987  *
988  ******************************************************************************/
989 
990 void
991 AcpiNsDumpEntry (
992     ACPI_HANDLE             Handle,
993     UINT32                  DebugLevel)
994 {
995     ACPI_WALK_INFO          Info;
996 
997 
998     ACPI_FUNCTION_ENTRY ();
999 
1000 
1001     Info.DebugLevel = DebugLevel;
1002     Info.OwnerId = ACPI_OWNER_ID_MAX;
1003     Info.DisplayType = ACPI_DISPLAY_SUMMARY;
1004 
1005     (void) AcpiNsDumpOneObject (Handle, 1, &Info, NULL);
1006 }
1007 
1008 
1009 #ifdef ACPI_ASL_COMPILER
1010 /*******************************************************************************
1011  *
1012  * FUNCTION:    AcpiNsDumpTables
1013  *
1014  * PARAMETERS:  SearchBase          - Root of subtree to be dumped, or
1015  *                                    NS_ALL to dump the entire namespace
1016  *              MaxDepth            - Maximum depth of dump. Use INT_MAX
1017  *                                    for an effectively unlimited depth.
1018  *
1019  * RETURN:      None
1020  *
1021  * DESCRIPTION: Dump the name space, or a portion of it.
1022  *
1023  ******************************************************************************/
1024 
1025 void
1026 AcpiNsDumpTables (
1027     ACPI_HANDLE             SearchBase,
1028     UINT32                  MaxDepth)
1029 {
1030     ACPI_HANDLE             SearchHandle = SearchBase;
1031 
1032 
1033     ACPI_FUNCTION_TRACE (NsDumpTables);
1034 
1035 
1036     if (!AcpiGbl_RootNode)
1037     {
1038         /*
1039          * If the name space has not been initialized,
1040          * there is nothing to dump.
1041          */
1042         ACPI_DEBUG_PRINT ((ACPI_DB_TABLES,
1043             "namespace not initialized!\n"));
1044         return_VOID;
1045     }
1046 
1047     if (ACPI_NS_ALL == SearchBase)
1048     {
1049         /* Entire namespace */
1050 
1051         SearchHandle = AcpiGbl_RootNode;
1052         ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "\\\n"));
1053     }
1054 
1055     AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_OBJECTS, MaxDepth,
1056         ACPI_OWNER_ID_MAX, SearchHandle);
1057     return_VOID;
1058 }
1059 #endif
1060 #endif
1061