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 - 2017, 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
165void
166AcpiNsDumpRootDevices (
167    void);
168
169static ACPI_STATUS
170AcpiNsDumpOneDevice (
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
180static ACPI_STATUS
181AcpiNsDumpOneObjectPath (
182    ACPI_HANDLE             ObjHandle,
183    UINT32                  Level,
184    void                    *Context,
185    void                    **ReturnValue);
186
187static ACPI_STATUS
188AcpiNsGetMaxDepth (
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
208void
209AcpiNsPrintPathname (
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
270void
271AcpiNsDumpPathname (
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 * FUNCTION:    AcpiNsDumpOneObject
299 *
300 * PARAMETERS:  ObjHandle           - Node to be dumped
301 *              Level               - Nesting level of the handle
302 *              Context             - Passed into WalkNamespace
303 *              ReturnValue         - Not used
304 *
305 * RETURN:      Status
306 *
307 * DESCRIPTION: Dump a single Node
308 *              This procedure is a UserFunction called by AcpiNsWalkNamespace.
309 *
310 ******************************************************************************/
311
312ACPI_STATUS
313AcpiNsDumpOneObject (
314    ACPI_HANDLE             ObjHandle,
315    UINT32                  Level,
316    void                    *Context,
317    void                    **ReturnValue)
318{
319    ACPI_WALK_INFO          *Info = (ACPI_WALK_INFO *) Context;
320    ACPI_NAMESPACE_NODE     *ThisNode;
321    ACPI_OPERAND_OBJECT     *ObjDesc = NULL;
322    ACPI_OBJECT_TYPE        ObjType;
323    ACPI_OBJECT_TYPE        Type;
324    UINT32                  BytesToDump;
325    UINT32                  DbgLevel;
326    UINT32                  i;
327
328
329    ACPI_FUNCTION_NAME (NsDumpOneObject);
330
331
332    /* Is output enabled? */
333
334    if (!(AcpiDbgLevel & Info->DebugLevel))
335    {
336        return (AE_OK);
337    }
338
339    if (!ObjHandle)
340    {
341        ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Null object handle\n"));
342        return (AE_OK);
343    }
344
345    ThisNode = AcpiNsValidateHandle (ObjHandle);
346    if (!ThisNode)
347    {
348        ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Invalid object handle %p\n",
349            ObjHandle));
350        return (AE_OK);
351    }
352
353    Type = ThisNode->Type;
354
355    /* Check if the owner matches */
356
357    if ((Info->OwnerId != ACPI_OWNER_ID_MAX) &&
358        (Info->OwnerId != ThisNode->OwnerId))
359    {
360        return (AE_OK);
361    }
362
363    if (!(Info->DisplayType & ACPI_DISPLAY_SHORT))
364    {
365        /* Indent the object according to the level */
366
367        AcpiOsPrintf ("%2d%*s", (UINT32) Level - 1, (int) Level * 2, " ");
368
369        /* Check the node type and name */
370
371        if (Type > ACPI_TYPE_LOCAL_MAX)
372        {
373            ACPI_WARNING ((AE_INFO,
374                "Invalid ACPI Object Type 0x%08X", Type));
375        }
376
377        AcpiOsPrintf ("%4.4s", AcpiUtGetNodeName (ThisNode));
378    }
379
380    /* Now we can print out the pertinent information */
381
382    AcpiOsPrintf (" %-12s %p %2.2X ",
383        AcpiUtGetTypeName (Type), ThisNode, ThisNode->OwnerId);
384
385    DbgLevel = AcpiDbgLevel;
386    AcpiDbgLevel = 0;
387    ObjDesc = AcpiNsGetAttachedObject (ThisNode);
388    AcpiDbgLevel = DbgLevel;
389
390    /* Temp nodes are those nodes created by a control method */
391
392    if (ThisNode->Flags & ANOBJ_TEMPORARY)
393    {
394        AcpiOsPrintf ("(T) ");
395    }
396
397    switch (Info->DisplayType & ACPI_DISPLAY_MASK)
398    {
399    case ACPI_DISPLAY_SUMMARY:
400
401        if (!ObjDesc)
402        {
403            /* No attached object. Some types should always have an object */
404
405            switch (Type)
406            {
407            case ACPI_TYPE_INTEGER:
408            case ACPI_TYPE_PACKAGE:
409            case ACPI_TYPE_BUFFER:
410            case ACPI_TYPE_STRING:
411            case ACPI_TYPE_METHOD:
412
413                AcpiOsPrintf ("<No attached object>");
414                break;
415
416            default:
417
418                break;
419            }
420
421            AcpiOsPrintf ("\n");
422            return (AE_OK);
423        }
424
425        switch (Type)
426        {
427        case ACPI_TYPE_PROCESSOR:
428
429            AcpiOsPrintf ("ID %02X Len %02X Addr %8.8X%8.8X\n",
430                ObjDesc->Processor.ProcId, ObjDesc->Processor.Length,
431                ACPI_FORMAT_UINT64 (ObjDesc->Processor.Address));
432            break;
433
434        case ACPI_TYPE_DEVICE:
435
436            AcpiOsPrintf ("Notify Object: %p\n", ObjDesc);
437            break;
438
439        case ACPI_TYPE_METHOD:
440
441            AcpiOsPrintf ("Args %X Len %.4X Aml %p\n",
442                (UINT32) ObjDesc->Method.ParamCount,
443                ObjDesc->Method.AmlLength, ObjDesc->Method.AmlStart);
444            break;
445
446        case ACPI_TYPE_INTEGER:
447
448            AcpiOsPrintf ("= %8.8X%8.8X\n",
449                ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
450            break;
451
452        case ACPI_TYPE_PACKAGE:
453
454            if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
455            {
456                AcpiOsPrintf ("Elements %.2X\n",
457                    ObjDesc->Package.Count);
458            }
459            else
460            {
461                AcpiOsPrintf ("[Length not yet evaluated]\n");
462            }
463            break;
464
465        case ACPI_TYPE_BUFFER:
466
467            if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
468            {
469                AcpiOsPrintf ("Len %.2X",
470                    ObjDesc->Buffer.Length);
471
472                /* Dump some of the buffer */
473
474                if (ObjDesc->Buffer.Length > 0)
475                {
476                    AcpiOsPrintf (" =");
477                    for (i = 0; (i < ObjDesc->Buffer.Length && i < 12); i++)
478                    {
479                        AcpiOsPrintf (" %.2hX", ObjDesc->Buffer.Pointer[i]);
480                    }
481                }
482                AcpiOsPrintf ("\n");
483            }
484            else
485            {
486                AcpiOsPrintf ("[Length not yet evaluated]\n");
487            }
488            break;
489
490        case ACPI_TYPE_STRING:
491
492            AcpiOsPrintf ("Len %.2X ", ObjDesc->String.Length);
493            AcpiUtPrintString (ObjDesc->String.Pointer, 80);
494            AcpiOsPrintf ("\n");
495            break;
496
497        case ACPI_TYPE_REGION:
498
499            AcpiOsPrintf ("[%s]",
500                AcpiUtGetRegionName (ObjDesc->Region.SpaceId));
501            if (ObjDesc->Region.Flags & AOPOBJ_DATA_VALID)
502            {
503                AcpiOsPrintf (" Addr %8.8X%8.8X Len %.4X\n",
504                    ACPI_FORMAT_UINT64 (ObjDesc->Region.Address),
505                    ObjDesc->Region.Length);
506            }
507            else
508            {
509                AcpiOsPrintf (" [Address/Length not yet evaluated]\n");
510            }
511            break;
512
513        case ACPI_TYPE_LOCAL_REFERENCE:
514
515            AcpiOsPrintf ("[%s]\n", AcpiUtGetReferenceName (ObjDesc));
516            break;
517
518        case ACPI_TYPE_BUFFER_FIELD:
519
520            if (ObjDesc->BufferField.BufferObj &&
521                ObjDesc->BufferField.BufferObj->Buffer.Node)
522            {
523                AcpiOsPrintf ("Buf [%4.4s]",
524                    AcpiUtGetNodeName (
525                        ObjDesc->BufferField.BufferObj->Buffer.Node));
526            }
527            break;
528
529        case ACPI_TYPE_LOCAL_REGION_FIELD:
530
531            AcpiOsPrintf ("Rgn [%4.4s]",
532                AcpiUtGetNodeName (
533                    ObjDesc->CommonField.RegionObj->Region.Node));
534            break;
535
536        case ACPI_TYPE_LOCAL_BANK_FIELD:
537
538            AcpiOsPrintf ("Rgn [%4.4s] Bnk [%4.4s]",
539                AcpiUtGetNodeName (
540                    ObjDesc->CommonField.RegionObj->Region.Node),
541                AcpiUtGetNodeName (
542                    ObjDesc->BankField.BankObj->CommonField.Node));
543            break;
544
545        case ACPI_TYPE_LOCAL_INDEX_FIELD:
546
547            AcpiOsPrintf ("Idx [%4.4s] Dat [%4.4s]",
548                AcpiUtGetNodeName (
549                    ObjDesc->IndexField.IndexObj->CommonField.Node),
550                AcpiUtGetNodeName (
551                    ObjDesc->IndexField.DataObj->CommonField.Node));
552            break;
553
554        case ACPI_TYPE_LOCAL_ALIAS:
555        case ACPI_TYPE_LOCAL_METHOD_ALIAS:
556
557            AcpiOsPrintf ("Target %4.4s (%p)\n",
558                AcpiUtGetNodeName (ObjDesc), ObjDesc);
559            break;
560
561        default:
562
563            AcpiOsPrintf ("Object %p\n", ObjDesc);
564            break;
565        }
566
567        /* Common field handling */
568
569        switch (Type)
570        {
571        case ACPI_TYPE_BUFFER_FIELD:
572        case ACPI_TYPE_LOCAL_REGION_FIELD:
573        case ACPI_TYPE_LOCAL_BANK_FIELD:
574        case ACPI_TYPE_LOCAL_INDEX_FIELD:
575
576            AcpiOsPrintf (" Off %.3X Len %.2X Acc %.2hd\n",
577                (ObjDesc->CommonField.BaseByteOffset * 8)
578                    + ObjDesc->CommonField.StartFieldBitOffset,
579                ObjDesc->CommonField.BitLength,
580                ObjDesc->CommonField.AccessByteWidth);
581            break;
582
583        default:
584
585            break;
586        }
587        break;
588
589    case ACPI_DISPLAY_OBJECTS:
590
591        AcpiOsPrintf ("O:%p", ObjDesc);
592        if (!ObjDesc)
593        {
594            /* No attached object, we are done */
595
596            AcpiOsPrintf ("\n");
597            return (AE_OK);
598        }
599
600        AcpiOsPrintf ("(R%u)", ObjDesc->Common.ReferenceCount);
601
602        switch (Type)
603        {
604        case ACPI_TYPE_METHOD:
605
606            /* Name is a Method and its AML offset/length are set */
607
608            AcpiOsPrintf (" M:%p-%X\n", ObjDesc->Method.AmlStart,
609                ObjDesc->Method.AmlLength);
610            break;
611
612        case ACPI_TYPE_INTEGER:
613
614            AcpiOsPrintf (" I:%8.8X8.8%X\n",
615                ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
616            break;
617
618        case ACPI_TYPE_STRING:
619
620            AcpiOsPrintf (" S:%p-%X\n", ObjDesc->String.Pointer,
621                ObjDesc->String.Length);
622            break;
623
624        case ACPI_TYPE_BUFFER:
625
626            AcpiOsPrintf (" B:%p-%X\n", ObjDesc->Buffer.Pointer,
627                ObjDesc->Buffer.Length);
628            break;
629
630        default:
631
632            AcpiOsPrintf ("\n");
633            break;
634        }
635        break;
636
637    default:
638        AcpiOsPrintf ("\n");
639        break;
640    }
641
642    /* If debug turned off, done */
643
644    if (!(AcpiDbgLevel & ACPI_LV_VALUES))
645    {
646        return (AE_OK);
647    }
648
649    /* If there is an attached object, display it */
650
651    DbgLevel = AcpiDbgLevel;
652    AcpiDbgLevel = 0;
653    ObjDesc = AcpiNsGetAttachedObject (ThisNode);
654    AcpiDbgLevel = DbgLevel;
655
656    /* Dump attached objects */
657
658    while (ObjDesc)
659    {
660        ObjType = ACPI_TYPE_INVALID;
661        AcpiOsPrintf ("Attached Object %p: ", ObjDesc);
662
663        /* Decode the type of attached object and dump the contents */
664
665        switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
666        {
667        case ACPI_DESC_TYPE_NAMED:
668
669            AcpiOsPrintf ("(Ptr to Node)\n");
670            BytesToDump = sizeof (ACPI_NAMESPACE_NODE);
671            ACPI_DUMP_BUFFER (ObjDesc, BytesToDump);
672            break;
673
674        case ACPI_DESC_TYPE_OPERAND:
675
676            ObjType = ObjDesc->Common.Type;
677
678            if (ObjType > ACPI_TYPE_LOCAL_MAX)
679            {
680                AcpiOsPrintf (
681                    "(Pointer to ACPI Object type %.2X [UNKNOWN])\n",
682                    ObjType);
683
684                BytesToDump = 32;
685            }
686            else
687            {
688                AcpiOsPrintf (
689                    "(Pointer to ACPI Object type %.2X [%s])\n",
690                    ObjType, AcpiUtGetTypeName (ObjType));
691
692                BytesToDump = sizeof (ACPI_OPERAND_OBJECT);
693            }
694
695            ACPI_DUMP_BUFFER (ObjDesc, BytesToDump);
696            break;
697
698        default:
699
700            break;
701        }
702
703        /* If value is NOT an internal object, we are done */
704
705        if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) != ACPI_DESC_TYPE_OPERAND)
706        {
707            goto Cleanup;
708        }
709
710        /* Valid object, get the pointer to next level, if any */
711
712        switch (ObjType)
713        {
714        case ACPI_TYPE_BUFFER:
715        case ACPI_TYPE_STRING:
716            /*
717             * NOTE: takes advantage of common fields between string/buffer
718             */
719            BytesToDump = ObjDesc->String.Length;
720            ObjDesc = (void *) ObjDesc->String.Pointer;
721
722            AcpiOsPrintf ("(Buffer/String pointer %p length %X)\n",
723                ObjDesc, BytesToDump);
724            ACPI_DUMP_BUFFER (ObjDesc, BytesToDump);
725            goto Cleanup;
726
727        case ACPI_TYPE_BUFFER_FIELD:
728
729            ObjDesc = (ACPI_OPERAND_OBJECT *) ObjDesc->BufferField.BufferObj;
730            break;
731
732        case ACPI_TYPE_PACKAGE:
733
734            ObjDesc = (void *) ObjDesc->Package.Elements;
735            break;
736
737        case ACPI_TYPE_METHOD:
738
739            ObjDesc = (void *) ObjDesc->Method.AmlStart;
740            break;
741
742        case ACPI_TYPE_LOCAL_REGION_FIELD:
743
744            ObjDesc = (void *) ObjDesc->Field.RegionObj;
745            break;
746
747        case ACPI_TYPE_LOCAL_BANK_FIELD:
748
749            ObjDesc = (void *) ObjDesc->BankField.RegionObj;
750            break;
751
752        case ACPI_TYPE_LOCAL_INDEX_FIELD:
753
754            ObjDesc = (void *) ObjDesc->IndexField.IndexObj;
755            break;
756
757        default:
758
759            goto Cleanup;
760        }
761
762        ObjType = ACPI_TYPE_INVALID;   /* Terminate loop after next pass */
763    }
764
765Cleanup:
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
790void
791AcpiNsDumpObjects (
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.DebugLevel = ACPI_LV_TABLES;
819    Info.OwnerId = OwnerId;
820    Info.DisplayType = DisplayType;
821
822    (void) AcpiNsWalkNamespace (Type, StartHandle, MaxDepth,
823        ACPI_NS_WALK_NO_UNLOCK | ACPI_NS_WALK_TEMP_NODES,
824        AcpiNsDumpOneObject, NULL, (void *) &Info, NULL);
825
826    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
827}
828
829
830/*******************************************************************************
831 *
832 * FUNCTION:    AcpiNsDumpOneObjectPath, AcpiNsGetMaxDepth
833 *
834 * PARAMETERS:  ObjHandle           - Node to be dumped
835 *              Level               - Nesting level of the handle
836 *              Context             - Passed into WalkNamespace
837 *              ReturnValue         - Not used
838 *
839 * RETURN:      Status
840 *
841 * DESCRIPTION: Dump the full pathname to a namespace object. AcpNsGetMaxDepth
842 *              computes the maximum nesting depth in the namespace tree, in
843 *              order to simplify formatting in AcpiNsDumpOneObjectPath.
844 *              These procedures are UserFunctions called by AcpiNsWalkNamespace.
845 *
846 ******************************************************************************/
847
848static ACPI_STATUS
849AcpiNsDumpOneObjectPath (
850    ACPI_HANDLE             ObjHandle,
851    UINT32                  Level,
852    void                    *Context,
853    void                    **ReturnValue)
854{
855    UINT32                  MaxLevel = *((UINT32 *) Context);
856    char                    *Pathname;
857    ACPI_NAMESPACE_NODE     *Node;
858    int                     PathIndent;
859
860
861    if (!ObjHandle)
862    {
863        return (AE_OK);
864    }
865
866    Node = AcpiNsValidateHandle (ObjHandle);
867    if (!Node)
868    {
869        /* Ignore bad node during namespace walk */
870
871        return (AE_OK);
872    }
873
874    Pathname = AcpiNsGetNormalizedPathname (Node, TRUE);
875
876    PathIndent = 1;
877    if (Level <= MaxLevel)
878    {
879        PathIndent = MaxLevel - Level + 1;
880    }
881
882    AcpiOsPrintf ("%2d%*s%-12s%*s",
883        Level, Level, " ", AcpiUtGetTypeName (Node->Type),
884        PathIndent, " ");
885
886    AcpiOsPrintf ("%s\n", &Pathname[1]);
887    ACPI_FREE (Pathname);
888    return (AE_OK);
889}
890
891
892static ACPI_STATUS
893AcpiNsGetMaxDepth (
894    ACPI_HANDLE             ObjHandle,
895    UINT32                  Level,
896    void                    *Context,
897    void                    **ReturnValue)
898{
899    UINT32                  *MaxLevel = (UINT32 *) Context;
900
901
902    if (Level > *MaxLevel)
903    {
904        *MaxLevel = Level;
905    }
906    return (AE_OK);
907}
908
909
910/*******************************************************************************
911 *
912 * FUNCTION:    AcpiNsDumpObjectPaths
913 *
914 * PARAMETERS:  Type                - Object type to be dumped
915 *              DisplayType         - 0 or ACPI_DISPLAY_SUMMARY
916 *              MaxDepth            - Maximum depth of dump. Use ACPI_UINT32_MAX
917 *                                    for an effectively unlimited depth.
918 *              OwnerId             - Dump only objects owned by this ID. Use
919 *                                    ACPI_UINT32_MAX to match all owners.
920 *              StartHandle         - Where in namespace to start/end search
921 *
922 * RETURN:      None
923 *
924 * DESCRIPTION: Dump full object pathnames within the loaded namespace. Uses
925 *              AcpiNsWalkNamespace in conjunction with AcpiNsDumpOneObjectPath.
926 *
927 ******************************************************************************/
928
929void
930AcpiNsDumpObjectPaths (
931    ACPI_OBJECT_TYPE        Type,
932    UINT8                   DisplayType,
933    UINT32                  MaxDepth,
934    ACPI_OWNER_ID           OwnerId,
935    ACPI_HANDLE             StartHandle)
936{
937    ACPI_STATUS             Status;
938    UINT32                  MaxLevel = 0;
939
940
941    ACPI_FUNCTION_ENTRY ();
942
943
944    /*
945     * Just lock the entire namespace for the duration of the dump.
946     * We don't want any changes to the namespace during this time,
947     * especially the temporary nodes since we are going to display
948     * them also.
949     */
950    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
951    if (ACPI_FAILURE (Status))
952    {
953        AcpiOsPrintf ("Could not acquire namespace mutex\n");
954        return;
955    }
956
957    /* Get the max depth of the namespace tree, for formatting later */
958
959    (void) AcpiNsWalkNamespace (Type, StartHandle, MaxDepth,
960        ACPI_NS_WALK_NO_UNLOCK | ACPI_NS_WALK_TEMP_NODES,
961        AcpiNsGetMaxDepth, NULL, (void *) &MaxLevel, NULL);
962
963    /* Now dump the entire namespace */
964
965    (void) AcpiNsWalkNamespace (Type, StartHandle, MaxDepth,
966        ACPI_NS_WALK_NO_UNLOCK | ACPI_NS_WALK_TEMP_NODES,
967        AcpiNsDumpOneObjectPath, NULL, (void *) &MaxLevel, NULL);
968
969    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
970}
971
972
973/*******************************************************************************
974 *
975 * FUNCTION:    AcpiNsDumpEntry
976 *
977 * PARAMETERS:  Handle              - Node to be dumped
978 *              DebugLevel          - Output level
979 *
980 * RETURN:      None
981 *
982 * DESCRIPTION: Dump a single Node
983 *
984 ******************************************************************************/
985
986void
987AcpiNsDumpEntry (
988    ACPI_HANDLE             Handle,
989    UINT32                  DebugLevel)
990{
991    ACPI_WALK_INFO          Info;
992
993
994    ACPI_FUNCTION_ENTRY ();
995
996
997    Info.DebugLevel = DebugLevel;
998    Info.OwnerId = ACPI_OWNER_ID_MAX;
999    Info.DisplayType = ACPI_DISPLAY_SUMMARY;
1000
1001    (void) AcpiNsDumpOneObject (Handle, 1, &Info, NULL);
1002}
1003
1004
1005#ifdef ACPI_ASL_COMPILER
1006/*******************************************************************************
1007 *
1008 * FUNCTION:    AcpiNsDumpTables
1009 *
1010 * PARAMETERS:  SearchBase          - Root of subtree to be dumped, or
1011 *                                    NS_ALL to dump the entire namespace
1012 *              MaxDepth            - Maximum depth of dump. Use INT_MAX
1013 *                                    for an effectively unlimited depth.
1014 *
1015 * RETURN:      None
1016 *
1017 * DESCRIPTION: Dump the name space, or a portion of it.
1018 *
1019 ******************************************************************************/
1020
1021void
1022AcpiNsDumpTables (
1023    ACPI_HANDLE             SearchBase,
1024    UINT32                  MaxDepth)
1025{
1026    ACPI_HANDLE             SearchHandle = SearchBase;
1027
1028
1029    ACPI_FUNCTION_TRACE (NsDumpTables);
1030
1031
1032    if (!AcpiGbl_RootNode)
1033    {
1034        /*
1035         * If the name space has not been initialized,
1036         * there is nothing to dump.
1037         */
1038        ACPI_DEBUG_PRINT ((ACPI_DB_TABLES,
1039            "namespace not initialized!\n"));
1040        return_VOID;
1041    }
1042
1043    if (ACPI_NS_ALL == SearchBase)
1044    {
1045        /* Entire namespace */
1046
1047        SearchHandle = AcpiGbl_RootNode;
1048        ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "\\\n"));
1049    }
1050
1051    AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_OBJECTS, MaxDepth,
1052        ACPI_OWNER_ID_MAX, SearchHandle);
1053    return_VOID;
1054}
1055#endif
1056#endif
1057