xref: /freebsd/sys/contrib/dev/acpica/components/namespace/nsdump.c (revision 7fdf597e96a02165cfe22ff357b857d5fa15ed8a)
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 - 2023, 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 <contrib/dev/acpica/include/acpi.h>
154 #include <contrib/dev/acpica/include/accommon.h>
155 #include <contrib/dev/acpica/include/acnamesp.h>
156 #include <contrib/dev/acpica/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_NAMESEG_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 %3.3X ",
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 (" %2.2X", 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 %.2X\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 
765 Cleanup:
766     AcpiOsPrintf ("\n");
767     return (AE_OK);
768 }
769 
770 
771 /*******************************************************************************
772  *
773  * FUNCTION:    AcpiNsDumpObjects
774  *
775  * PARAMETERS:  Type                - Object type to be dumped
776  *              DisplayType         - 0 or ACPI_DISPLAY_SUMMARY
777  *              MaxDepth            - Maximum depth of dump. Use ACPI_UINT32_MAX
778  *                                    for an effectively unlimited depth.
779  *              OwnerId             - Dump only objects owned by this ID. Use
780  *                                    ACPI_UINT32_MAX to match all owners.
781  *              StartHandle         - Where in namespace to start/end search
782  *
783  * RETURN:      None
784  *
785  * DESCRIPTION: Dump typed objects within the loaded namespace. Uses
786  *              AcpiNsWalkNamespace in conjunction with AcpiNsDumpOneObject.
787  *
788  ******************************************************************************/
789 
790 void
791 AcpiNsDumpObjects (
792     ACPI_OBJECT_TYPE        Type,
793     UINT8                   DisplayType,
794     UINT32                  MaxDepth,
795     ACPI_OWNER_ID           OwnerId,
796     ACPI_HANDLE             StartHandle)
797 {
798     ACPI_WALK_INFO          Info;
799     ACPI_STATUS             Status;
800 
801 
802     ACPI_FUNCTION_ENTRY ();
803 
804 
805     /*
806      * Just lock the entire namespace for the duration of the dump.
807      * We don't want any changes to the namespace during this time,
808      * especially the temporary nodes since we are going to display
809      * them also.
810      */
811     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
812     if (ACPI_FAILURE (Status))
813     {
814         AcpiOsPrintf ("Could not acquire namespace mutex\n");
815         return;
816     }
817 
818     Info.Count = 0;
819     Info.DebugLevel = ACPI_LV_TABLES;
820     Info.OwnerId = OwnerId;
821     Info.DisplayType = DisplayType;
822 
823     (void) AcpiNsWalkNamespace (Type, StartHandle, MaxDepth,
824         ACPI_NS_WALK_NO_UNLOCK | ACPI_NS_WALK_TEMP_NODES,
825         AcpiNsDumpOneObject, NULL, (void *) &Info, NULL);
826 
827     AcpiOsPrintf ("\nNamespace node count: %u\n\n", Info.Count);
828     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
829 }
830 
831 
832 /*******************************************************************************
833  *
834  * FUNCTION:    AcpiNsDumpOneObjectPath, AcpiNsGetMaxDepth
835  *
836  * PARAMETERS:  ObjHandle           - Node to be dumped
837  *              Level               - Nesting level of the handle
838  *              Context             - Passed into WalkNamespace
839  *              ReturnValue         - Not used
840  *
841  * RETURN:      Status
842  *
843  * DESCRIPTION: Dump the full pathname to a namespace object. AcpNsGetMaxDepth
844  *              computes the maximum nesting depth in the namespace tree, in
845  *              order to simplify formatting in AcpiNsDumpOneObjectPath.
846  *              These procedures are UserFunctions called by AcpiNsWalkNamespace.
847  *
848  ******************************************************************************/
849 
850 static ACPI_STATUS
851 AcpiNsDumpOneObjectPath (
852     ACPI_HANDLE             ObjHandle,
853     UINT32                  Level,
854     void                    *Context,
855     void                    **ReturnValue)
856 {
857     UINT32                  MaxLevel = *((UINT32 *) Context);
858     char                    *Pathname;
859     ACPI_NAMESPACE_NODE     *Node;
860     int                     PathIndent;
861 
862 
863     if (!ObjHandle)
864     {
865         return (AE_OK);
866     }
867 
868     Node = AcpiNsValidateHandle (ObjHandle);
869     if (!Node)
870     {
871         /* Ignore bad node during namespace walk */
872 
873         return (AE_OK);
874     }
875 
876     Pathname = AcpiNsGetNormalizedPathname (Node, TRUE);
877 
878     PathIndent = 1;
879     if (Level <= MaxLevel)
880     {
881         PathIndent = MaxLevel - Level + 1;
882     }
883 
884     AcpiOsPrintf ("%2d%*s%-12s%*s",
885         Level, Level, " ", AcpiUtGetTypeName (Node->Type),
886         PathIndent, " ");
887 
888     AcpiOsPrintf ("%s\n", &Pathname[1]);
889     ACPI_FREE (Pathname);
890     return (AE_OK);
891 }
892 
893 
894 static ACPI_STATUS
895 AcpiNsGetMaxDepth (
896     ACPI_HANDLE             ObjHandle,
897     UINT32                  Level,
898     void                    *Context,
899     void                    **ReturnValue)
900 {
901     UINT32                  *MaxLevel = (UINT32 *) Context;
902 
903 
904     if (Level > *MaxLevel)
905     {
906         *MaxLevel = Level;
907     }
908     return (AE_OK);
909 }
910 
911 
912 /*******************************************************************************
913  *
914  * FUNCTION:    AcpiNsDumpObjectPaths
915  *
916  * PARAMETERS:  Type                - Object type to be dumped
917  *              DisplayType         - 0 or ACPI_DISPLAY_SUMMARY
918  *              MaxDepth            - Maximum depth of dump. Use ACPI_UINT32_MAX
919  *                                    for an effectively unlimited depth.
920  *              OwnerId             - Dump only objects owned by this ID. Use
921  *                                    ACPI_UINT32_MAX to match all owners.
922  *              StartHandle         - Where in namespace to start/end search
923  *
924  * RETURN:      None
925  *
926  * DESCRIPTION: Dump full object pathnames within the loaded namespace. Uses
927  *              AcpiNsWalkNamespace in conjunction with AcpiNsDumpOneObjectPath.
928  *
929  ******************************************************************************/
930 
931 void
932 AcpiNsDumpObjectPaths (
933     ACPI_OBJECT_TYPE        Type,
934     UINT8                   DisplayType,
935     UINT32                  MaxDepth,
936     ACPI_OWNER_ID           OwnerId,
937     ACPI_HANDLE             StartHandle)
938 {
939     ACPI_STATUS             Status;
940     UINT32                  MaxLevel = 0;
941 
942 
943     ACPI_FUNCTION_ENTRY ();
944 
945 
946     /*
947      * Just lock the entire namespace for the duration of the dump.
948      * We don't want any changes to the namespace during this time,
949      * especially the temporary nodes since we are going to display
950      * them also.
951      */
952     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
953     if (ACPI_FAILURE (Status))
954     {
955         AcpiOsPrintf ("Could not acquire namespace mutex\n");
956         return;
957     }
958 
959     /* Get the max depth of the namespace tree, for formatting later */
960 
961     (void) AcpiNsWalkNamespace (Type, StartHandle, MaxDepth,
962         ACPI_NS_WALK_NO_UNLOCK | ACPI_NS_WALK_TEMP_NODES,
963         AcpiNsGetMaxDepth, NULL, (void *) &MaxLevel, NULL);
964 
965     /* Now dump the entire namespace */
966 
967     (void) AcpiNsWalkNamespace (Type, StartHandle, MaxDepth,
968         ACPI_NS_WALK_NO_UNLOCK | ACPI_NS_WALK_TEMP_NODES,
969         AcpiNsDumpOneObjectPath, NULL, (void *) &MaxLevel, NULL);
970 
971     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
972 }
973 
974 
975 /*******************************************************************************
976  *
977  * FUNCTION:    AcpiNsDumpEntry
978  *
979  * PARAMETERS:  Handle              - Node to be dumped
980  *              DebugLevel          - Output level
981  *
982  * RETURN:      None
983  *
984  * DESCRIPTION: Dump a single Node
985  *
986  ******************************************************************************/
987 
988 void
989 AcpiNsDumpEntry (
990     ACPI_HANDLE             Handle,
991     UINT32                  DebugLevel)
992 {
993     ACPI_WALK_INFO          Info;
994 
995 
996     ACPI_FUNCTION_ENTRY ();
997 
998 
999     Info.DebugLevel = DebugLevel;
1000     Info.OwnerId = ACPI_OWNER_ID_MAX;
1001     Info.DisplayType = ACPI_DISPLAY_SUMMARY;
1002 
1003     (void) AcpiNsDumpOneObject (Handle, 1, &Info, NULL);
1004 }
1005 
1006 
1007 #ifdef ACPI_ASL_COMPILER
1008 /*******************************************************************************
1009  *
1010  * FUNCTION:    AcpiNsDumpTables
1011  *
1012  * PARAMETERS:  SearchBase          - Root of subtree to be dumped, or
1013  *                                    NS_ALL to dump the entire namespace
1014  *              MaxDepth            - Maximum depth of dump. Use INT_MAX
1015  *                                    for an effectively unlimited depth.
1016  *
1017  * RETURN:      None
1018  *
1019  * DESCRIPTION: Dump the name space, or a portion of it.
1020  *
1021  ******************************************************************************/
1022 
1023 void
1024 AcpiNsDumpTables (
1025     ACPI_HANDLE             SearchBase,
1026     UINT32                  MaxDepth)
1027 {
1028     ACPI_HANDLE             SearchHandle = SearchBase;
1029 
1030 
1031     ACPI_FUNCTION_TRACE (NsDumpTables);
1032 
1033 
1034     if (!AcpiGbl_RootNode)
1035     {
1036         /*
1037          * If the name space has not been initialized,
1038          * there is nothing to dump.
1039          */
1040         ACPI_DEBUG_PRINT ((ACPI_DB_TABLES,
1041             "namespace not initialized!\n"));
1042         return_VOID;
1043     }
1044 
1045     if (ACPI_NS_ALL == SearchBase)
1046     {
1047         /* Entire namespace */
1048 
1049         SearchHandle = AcpiGbl_RootNode;
1050         ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "\\\n"));
1051     }
1052 
1053     AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_OBJECTS, MaxDepth,
1054         ACPI_OWNER_ID_MAX, SearchHandle);
1055     return_VOID;
1056 }
1057 #endif
1058 #endif
1059