167754Smsmith/******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: nsdump - table dumping routines for debug
467754Smsmith *
567754Smsmith *****************************************************************************/
667754Smsmith
7217365Sjkim/*
8306536Sjkim * Copyright (C) 2000 - 2016, Intel Corp.
970243Smsmith * All rights reserved.
1067754Smsmith *
11217365Sjkim * Redistribution and use in source and binary forms, with or without
12217365Sjkim * modification, are permitted provided that the following conditions
13217365Sjkim * are met:
14217365Sjkim * 1. Redistributions of source code must retain the above copyright
15217365Sjkim *    notice, this list of conditions, and the following disclaimer,
16217365Sjkim *    without modification.
17217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18217365Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
19217365Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
20217365Sjkim *    including a substantially similar Disclaimer requirement for further
21217365Sjkim *    binary redistribution.
22217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
23217365Sjkim *    of any contributors may be used to endorse or promote products derived
24217365Sjkim *    from this software without specific prior written permission.
2567754Smsmith *
26217365Sjkim * Alternatively, this software may be distributed under the terms of the
27217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
28217365Sjkim * Software Foundation.
2967754Smsmith *
30217365Sjkim * NO WARRANTY
31217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41217365Sjkim * POSSIBILITY OF SUCH DAMAGES.
42217365Sjkim */
4367754Smsmith
44193341Sjkim#include <contrib/dev/acpica/include/acpi.h>
45193341Sjkim#include <contrib/dev/acpica/include/accommon.h>
46193341Sjkim#include <contrib/dev/acpica/include/acnamesp.h>
47245582Sjkim#include <contrib/dev/acpica/include/acoutput.h>
4867754Smsmith
4967754Smsmith
5077424Smsmith#define _COMPONENT          ACPI_NAMESPACE
5191116Smsmith        ACPI_MODULE_NAME    ("nsdump")
5267754Smsmith
53151937Sjkim/* Local prototypes */
54123315Snjl
55151937Sjkim#ifdef ACPI_OBSOLETE_FUNCTIONS
56151937Sjkimvoid
57151937SjkimAcpiNsDumpRootDevices (
58151937Sjkim    void);
59151937Sjkim
60151937Sjkimstatic ACPI_STATUS
61151937SjkimAcpiNsDumpOneDevice (
62151937Sjkim    ACPI_HANDLE             ObjHandle,
63151937Sjkim    UINT32                  Level,
64151937Sjkim    void                    *Context,
65151937Sjkim    void                    **ReturnValue);
66151937Sjkim#endif
67151937Sjkim
68151937Sjkim
69102550Siwasaki#if defined(ACPI_DEBUG_OUTPUT) || defined(ACPI_DEBUGGER)
70254745Sjkim
71254745Sjkimstatic ACPI_STATUS
72254745SjkimAcpiNsDumpOneObjectPath (
73254745Sjkim    ACPI_HANDLE             ObjHandle,
74254745Sjkim    UINT32                  Level,
75254745Sjkim    void                    *Context,
76254745Sjkim    void                    **ReturnValue);
77254745Sjkim
78254745Sjkimstatic ACPI_STATUS
79254745SjkimAcpiNsGetMaxDepth (
80254745Sjkim    ACPI_HANDLE             ObjHandle,
81254745Sjkim    UINT32                  Level,
82254745Sjkim    void                    *Context,
83254745Sjkim    void                    **ReturnValue);
84254745Sjkim
85254745Sjkim
8677424Smsmith/*******************************************************************************
8767754Smsmith *
8887031Smsmith * FUNCTION:    AcpiNsPrintPathname
8987031Smsmith *
90151937Sjkim * PARAMETERS:  NumSegments         - Number of ACPI name segments
9187031Smsmith *              Pathname            - The compressed (internal) path
9287031Smsmith *
93151937Sjkim * RETURN:      None
94151937Sjkim *
9587031Smsmith * DESCRIPTION: Print an object's full namespace pathname
9687031Smsmith *
9787031Smsmith ******************************************************************************/
9887031Smsmith
9987031Smsmithvoid
10087031SmsmithAcpiNsPrintPathname (
10187031Smsmith    UINT32                  NumSegments,
102306536Sjkim    const char              *Pathname)
10387031Smsmith{
104193267Sjkim    UINT32                  i;
105151937Sjkim
106151937Sjkim
107167802Sjkim    ACPI_FUNCTION_NAME (NsPrintPathname);
10887031Smsmith
10987031Smsmith
110245582Sjkim    /* Check if debug output enabled */
111245582Sjkim
112245582Sjkim    if (!ACPI_IS_DEBUG_ENABLED (ACPI_LV_NAMES, ACPI_NAMESPACE))
11387031Smsmith    {
11487031Smsmith        return;
11587031Smsmith    }
11687031Smsmith
117123315Snjl    /* Print the entire name */
11887031Smsmith
11987031Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "["));
12087031Smsmith
12191116Smsmith    while (NumSegments)
12287031Smsmith    {
123151937Sjkim        for (i = 0; i < 4; i++)
124151937Sjkim        {
125306536Sjkim            isprint ((int) Pathname[i]) ?
126151937Sjkim                AcpiOsPrintf ("%c", Pathname[i]) :
127151937Sjkim                AcpiOsPrintf ("?");
128151937Sjkim        }
129151937Sjkim
13091116Smsmith        Pathname += ACPI_NAME_SIZE;
13191116Smsmith        NumSegments--;
13291116Smsmith        if (NumSegments)
13391116Smsmith        {
13491116Smsmith            AcpiOsPrintf (".");
13591116Smsmith        }
13687031Smsmith    }
13787031Smsmith
13887031Smsmith    AcpiOsPrintf ("]\n");
13987031Smsmith}
14087031Smsmith
14187031Smsmith
142306536Sjkim#ifdef ACPI_OBSOLETE_FUNCTIONS
143306536Sjkim/* Not used at this time, perhaps later */
144306536Sjkim
14587031Smsmith/*******************************************************************************
14687031Smsmith *
14767754Smsmith * FUNCTION:    AcpiNsDumpPathname
14867754Smsmith *
14967754Smsmith * PARAMETERS:  Handle              - Object
15067754Smsmith *              Msg                 - Prefix message
15167754Smsmith *              Level               - Desired debug level
15267754Smsmith *              Component           - Caller's component ID
15367754Smsmith *
154151937Sjkim * RETURN:      None
155151937Sjkim *
15667754Smsmith * DESCRIPTION: Print an object's full namespace pathname
15767754Smsmith *              Manages allocation/freeing of a pathname buffer
15867754Smsmith *
15977424Smsmith ******************************************************************************/
16067754Smsmith
161114237Snjlvoid
16267754SmsmithAcpiNsDumpPathname (
16367754Smsmith    ACPI_HANDLE             Handle,
164306536Sjkim    const char              *Msg,
16567754Smsmith    UINT32                  Level,
16667754Smsmith    UINT32                  Component)
16767754Smsmith{
16867754Smsmith
169167802Sjkim    ACPI_FUNCTION_TRACE (NsDumpPathname);
17067754Smsmith
17183174Smsmith
17267754Smsmith    /* Do this only if the requested debug level and component are enabled */
17367754Smsmith
174245582Sjkim    if (!ACPI_IS_DEBUG_ENABLED (Level, Component))
17567754Smsmith    {
176114237Snjl        return_VOID;
17767754Smsmith    }
17867754Smsmith
17967754Smsmith    /* Convert handle to a full pathname and print it (with supplied message) */
18067754Smsmith
181114237Snjl    AcpiNsPrintNodePathname (Handle, Msg);
182114237Snjl    AcpiOsPrintf ("\n");
183114237Snjl    return_VOID;
18467754Smsmith}
185306536Sjkim#endif
18667754Smsmith
18777424Smsmith/*******************************************************************************
18867754Smsmith *
18967754Smsmith * FUNCTION:    AcpiNsDumpOneObject
19067754Smsmith *
191151937Sjkim * PARAMETERS:  ObjHandle           - Node to be dumped
19267754Smsmith *              Level               - Nesting level of the handle
19367754Smsmith *              Context             - Passed into WalkNamespace
194151937Sjkim *              ReturnValue         - Not used
19567754Smsmith *
196151937Sjkim * RETURN:      Status
197151937Sjkim *
19867754Smsmith * DESCRIPTION: Dump a single Node
19967754Smsmith *              This procedure is a UserFunction called by AcpiNsWalkNamespace.
20067754Smsmith *
20177424Smsmith ******************************************************************************/
20267754Smsmith
20367754SmsmithACPI_STATUS
20467754SmsmithAcpiNsDumpOneObject (
20567754Smsmith    ACPI_HANDLE             ObjHandle,
20667754Smsmith    UINT32                  Level,
20767754Smsmith    void                    *Context,
20867754Smsmith    void                    **ReturnValue)
20967754Smsmith{
21067754Smsmith    ACPI_WALK_INFO          *Info = (ACPI_WALK_INFO *) Context;
21167754Smsmith    ACPI_NAMESPACE_NODE     *ThisNode;
21267754Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc = NULL;
21391116Smsmith    ACPI_OBJECT_TYPE        ObjType;
21491116Smsmith    ACPI_OBJECT_TYPE        Type;
21567754Smsmith    UINT32                  BytesToDump;
216107325Siwasaki    UINT32                  DbgLevel;
21785756Smsmith    UINT32                  i;
21867754Smsmith
21967754Smsmith
220167802Sjkim    ACPI_FUNCTION_NAME (NsDumpOneObject);
22182367Smsmith
22282367Smsmith
223107325Siwasaki    /* Is output enabled? */
22467754Smsmith
22567754Smsmith    if (!(AcpiDbgLevel & Info->DebugLevel))
22667754Smsmith    {
22767754Smsmith        return (AE_OK);
22867754Smsmith    }
22967754Smsmith
23067754Smsmith    if (!ObjHandle)
23167754Smsmith    {
23282367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Null object handle\n"));
23367754Smsmith        return (AE_OK);
23467754Smsmith    }
23567754Smsmith
236200553Sjkim    ThisNode = AcpiNsValidateHandle (ObjHandle);
237193267Sjkim    if (!ThisNode)
238193267Sjkim    {
239193267Sjkim        ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Invalid object handle %p\n",
240193267Sjkim            ObjHandle));
241193267Sjkim        return (AE_OK);
242193267Sjkim    }
243193267Sjkim
244107325Siwasaki    Type = ThisNode->Type;
245107325Siwasaki
24667754Smsmith    /* Check if the owner matches */
24767754Smsmith
248151937Sjkim    if ((Info->OwnerId != ACPI_OWNER_ID_MAX) &&
24967754Smsmith        (Info->OwnerId != ThisNode->OwnerId))
25067754Smsmith    {
25167754Smsmith        return (AE_OK);
25267754Smsmith    }
25367754Smsmith
254151937Sjkim    if (!(Info->DisplayType & ACPI_DISPLAY_SHORT))
255151937Sjkim    {
256151937Sjkim        /* Indent the object according to the level */
25767754Smsmith
258151937Sjkim        AcpiOsPrintf ("%2d%*s", (UINT32) Level - 1, (int) Level * 2, " ");
25967754Smsmith
260151937Sjkim        /* Check the node type and name */
26167754Smsmith
262151937Sjkim        if (Type > ACPI_TYPE_LOCAL_MAX)
263151937Sjkim        {
264306536Sjkim            ACPI_WARNING ((AE_INFO,
265306536Sjkim                "Invalid ACPI Object Type 0x%08X", Type));
266151937Sjkim        }
26767754Smsmith
268151937Sjkim        AcpiOsPrintf ("%4.4s", AcpiUtGetNodeName (ThisNode));
26967754Smsmith    }
27067754Smsmith
271193267Sjkim    /* Now we can print out the pertinent information */
272193267Sjkim
273167802Sjkim    AcpiOsPrintf (" %-12s %p %2.2X ",
274306536Sjkim        AcpiUtGetTypeName (Type), ThisNode, ThisNode->OwnerId);
27567754Smsmith
27691116Smsmith    DbgLevel = AcpiDbgLevel;
27791116Smsmith    AcpiDbgLevel = 0;
27887031Smsmith    ObjDesc = AcpiNsGetAttachedObject (ThisNode);
27991116Smsmith    AcpiDbgLevel = DbgLevel;
28067754Smsmith
281167802Sjkim    /* Temp nodes are those nodes created by a control method */
282167802Sjkim
283167802Sjkim    if (ThisNode->Flags & ANOBJ_TEMPORARY)
284167802Sjkim    {
285167802Sjkim        AcpiOsPrintf ("(T) ");
286167802Sjkim    }
287167802Sjkim
288151937Sjkim    switch (Info->DisplayType & ACPI_DISPLAY_MASK)
28967754Smsmith    {
29085756Smsmith    case ACPI_DISPLAY_SUMMARY:
29167754Smsmith
29285756Smsmith        if (!ObjDesc)
29385756Smsmith        {
294233250Sjkim            /* No attached object. Some types should always have an object */
29567754Smsmith
296233250Sjkim            switch (Type)
297233250Sjkim            {
298233250Sjkim            case ACPI_TYPE_INTEGER:
299233250Sjkim            case ACPI_TYPE_PACKAGE:
300233250Sjkim            case ACPI_TYPE_BUFFER:
301233250Sjkim            case ACPI_TYPE_STRING:
302233250Sjkim            case ACPI_TYPE_METHOD:
303250838Sjkim
304233250Sjkim                AcpiOsPrintf ("<No attached object>");
305233250Sjkim                break;
306233250Sjkim
307233250Sjkim            default:
308250838Sjkim
309233250Sjkim                break;
310233250Sjkim            }
311233250Sjkim
31287031Smsmith            AcpiOsPrintf ("\n");
31385756Smsmith            return (AE_OK);
31485756Smsmith        }
31567754Smsmith
31685756Smsmith        switch (Type)
31785756Smsmith        {
31885756Smsmith        case ACPI_TYPE_PROCESSOR:
319102550Siwasaki
320281687Sjkim            AcpiOsPrintf ("ID %02X Len %02X Addr %8.8X%8.8X\n",
321138287Smarks                ObjDesc->Processor.ProcId, ObjDesc->Processor.Length,
322281687Sjkim                ACPI_FORMAT_UINT64 (ObjDesc->Processor.Address));
32385756Smsmith            break;
32467754Smsmith
32585756Smsmith        case ACPI_TYPE_DEVICE:
326102550Siwasaki
327123315Snjl            AcpiOsPrintf ("Notify Object: %p\n", ObjDesc);
32885756Smsmith            break;
32967754Smsmith
33085756Smsmith        case ACPI_TYPE_METHOD:
331102550Siwasaki
332107325Siwasaki            AcpiOsPrintf ("Args %X Len %.4X Aml %p\n",
333138287Smarks                (UINT32) ObjDesc->Method.ParamCount,
334138287Smarks                ObjDesc->Method.AmlLength, ObjDesc->Method.AmlStart);
33585756Smsmith            break;
33667754Smsmith
33785756Smsmith        case ACPI_TYPE_INTEGER:
338102550Siwasaki
339107325Siwasaki            AcpiOsPrintf ("= %8.8X%8.8X\n",
340138287Smarks                ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
34185756Smsmith            break;
34267754Smsmith
34385756Smsmith        case ACPI_TYPE_PACKAGE:
34499146Siwasaki
34599146Siwasaki            if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
34699146Siwasaki            {
347107325Siwasaki                AcpiOsPrintf ("Elements %.2X\n",
348138287Smarks                    ObjDesc->Package.Count);
34999146Siwasaki            }
35099146Siwasaki            else
35199146Siwasaki            {
352107325Siwasaki                AcpiOsPrintf ("[Length not yet evaluated]\n");
35399146Siwasaki            }
35485756Smsmith            break;
35567754Smsmith
35685756Smsmith        case ACPI_TYPE_BUFFER:
35767754Smsmith
35899146Siwasaki            if (ObjDesc->Common.Flags & AOPOBJ_DATA_VALID)
35999146Siwasaki            {
360107325Siwasaki                AcpiOsPrintf ("Len %.2X",
361306536Sjkim                    ObjDesc->Buffer.Length);
36267754Smsmith
36399146Siwasaki                /* Dump some of the buffer */
36499146Siwasaki
36599146Siwasaki                if (ObjDesc->Buffer.Length > 0)
36685756Smsmith                {
36799146Siwasaki                    AcpiOsPrintf (" =");
36899146Siwasaki                    for (i = 0; (i < ObjDesc->Buffer.Length && i < 12); i++)
36999146Siwasaki                    {
37099679Siwasaki                        AcpiOsPrintf (" %.2hX", ObjDesc->Buffer.Pointer[i]);
37199146Siwasaki                    }
37285756Smsmith                }
37399146Siwasaki                AcpiOsPrintf ("\n");
37485756Smsmith            }
37599146Siwasaki            else
37699146Siwasaki            {
377107325Siwasaki                AcpiOsPrintf ("[Length not yet evaluated]\n");
37899146Siwasaki            }
37985756Smsmith            break;
38067754Smsmith
38185756Smsmith        case ACPI_TYPE_STRING:
382102550Siwasaki
383107325Siwasaki            AcpiOsPrintf ("Len %.2X ", ObjDesc->String.Length);
384306536Sjkim            AcpiUtPrintString (ObjDesc->String.Pointer, 80);
38587031Smsmith            AcpiOsPrintf ("\n");
38685756Smsmith            break;
38767754Smsmith
38885756Smsmith        case ACPI_TYPE_REGION:
389102550Siwasaki
390138287Smarks            AcpiOsPrintf ("[%s]",
391138287Smarks                AcpiUtGetRegionName (ObjDesc->Region.SpaceId));
39285756Smsmith            if (ObjDesc->Region.Flags & AOPOBJ_DATA_VALID)
39385756Smsmith            {
39487031Smsmith                AcpiOsPrintf (" Addr %8.8X%8.8X Len %.4X\n",
395281687Sjkim                    ACPI_FORMAT_UINT64 (ObjDesc->Region.Address),
396138287Smarks                    ObjDesc->Region.Length);
39785756Smsmith            }
39885756Smsmith            else
39985756Smsmith            {
40099146Siwasaki                AcpiOsPrintf (" [Address/Length not yet evaluated]\n");
40185756Smsmith            }
40285756Smsmith            break;
40367754Smsmith
404107325Siwasaki        case ACPI_TYPE_LOCAL_REFERENCE:
405102550Siwasaki
406193267Sjkim            AcpiOsPrintf ("[%s]\n", AcpiUtGetReferenceName (ObjDesc));
40785756Smsmith            break;
40867754Smsmith
40985756Smsmith        case ACPI_TYPE_BUFFER_FIELD:
410102550Siwasaki
41187031Smsmith            if (ObjDesc->BufferField.BufferObj &&
41287031Smsmith                ObjDesc->BufferField.BufferObj->Buffer.Node)
41387031Smsmith            {
414107325Siwasaki                AcpiOsPrintf ("Buf [%4.4s]",
415193267Sjkim                    AcpiUtGetNodeName (
416193267Sjkim                        ObjDesc->BufferField.BufferObj->Buffer.Node));
41787031Smsmith            }
41885756Smsmith            break;
41985756Smsmith
420107325Siwasaki        case ACPI_TYPE_LOCAL_REGION_FIELD:
421102550Siwasaki
422107325Siwasaki            AcpiOsPrintf ("Rgn [%4.4s]",
423193267Sjkim                AcpiUtGetNodeName (
424193267Sjkim                    ObjDesc->CommonField.RegionObj->Region.Node));
42585756Smsmith            break;
42685756Smsmith
427107325Siwasaki        case ACPI_TYPE_LOCAL_BANK_FIELD:
428102550Siwasaki
429107325Siwasaki            AcpiOsPrintf ("Rgn [%4.4s] Bnk [%4.4s]",
430193267Sjkim                AcpiUtGetNodeName (
431193267Sjkim                    ObjDesc->CommonField.RegionObj->Region.Node),
432193267Sjkim                AcpiUtGetNodeName (
433193267Sjkim                    ObjDesc->BankField.BankObj->CommonField.Node));
43485756Smsmith            break;
43585756Smsmith
436107325Siwasaki        case ACPI_TYPE_LOCAL_INDEX_FIELD:
437102550Siwasaki
438107325Siwasaki            AcpiOsPrintf ("Idx [%4.4s] Dat [%4.4s]",
439193267Sjkim                AcpiUtGetNodeName (
440193267Sjkim                    ObjDesc->IndexField.IndexObj->CommonField.Node),
441193267Sjkim                AcpiUtGetNodeName (
442193267Sjkim                    ObjDesc->IndexField.DataObj->CommonField.Node));
44385756Smsmith            break;
44485756Smsmith
445107325Siwasaki        case ACPI_TYPE_LOCAL_ALIAS:
446128212Snjl        case ACPI_TYPE_LOCAL_METHOD_ALIAS:
447104470Siwasaki
448138287Smarks            AcpiOsPrintf ("Target %4.4s (%p)\n",
449138287Smarks                AcpiUtGetNodeName (ObjDesc), ObjDesc);
450104470Siwasaki            break;
451104470Siwasaki
45285756Smsmith        default:
453102550Siwasaki
454107325Siwasaki            AcpiOsPrintf ("Object %p\n", ObjDesc);
45585756Smsmith            break;
45685756Smsmith        }
45785756Smsmith
45885756Smsmith        /* Common field handling */
45985756Smsmith
46085756Smsmith        switch (Type)
46185756Smsmith        {
46285756Smsmith        case ACPI_TYPE_BUFFER_FIELD:
463107325Siwasaki        case ACPI_TYPE_LOCAL_REGION_FIELD:
464107325Siwasaki        case ACPI_TYPE_LOCAL_BANK_FIELD:
465107325Siwasaki        case ACPI_TYPE_LOCAL_INDEX_FIELD:
466107325Siwasaki
467123315Snjl            AcpiOsPrintf (" Off %.3X Len %.2X Acc %.2hd\n",
468138287Smarks                (ObjDesc->CommonField.BaseByteOffset * 8)
469138287Smarks                    + ObjDesc->CommonField.StartFieldBitOffset,
470138287Smarks                ObjDesc->CommonField.BitLength,
471138287Smarks                ObjDesc->CommonField.AccessByteWidth);
47285756Smsmith            break;
473102550Siwasaki
47499679Siwasaki        default:
475250838Sjkim
47699679Siwasaki            break;
47785756Smsmith        }
47867754Smsmith        break;
47967754Smsmith
48085756Smsmith    case ACPI_DISPLAY_OBJECTS:
48167754Smsmith
482107325Siwasaki        AcpiOsPrintf ("O:%p", ObjDesc);
48385756Smsmith        if (!ObjDesc)
48485756Smsmith        {
48585756Smsmith            /* No attached object, we are done */
48685756Smsmith
48787031Smsmith            AcpiOsPrintf ("\n");
48885756Smsmith            return (AE_OK);
48985756Smsmith        }
49085756Smsmith
491209746Sjkim        AcpiOsPrintf ("(R%u)", ObjDesc->Common.ReferenceCount);
49285756Smsmith
49385756Smsmith        switch (Type)
49485756Smsmith        {
49585756Smsmith        case ACPI_TYPE_METHOD:
49685756Smsmith
49785756Smsmith            /* Name is a Method and its AML offset/length are set */
49885756Smsmith
49987031Smsmith            AcpiOsPrintf (" M:%p-%X\n", ObjDesc->Method.AmlStart,
500193267Sjkim                ObjDesc->Method.AmlLength);
50185756Smsmith            break;
50285756Smsmith
50385756Smsmith        case ACPI_TYPE_INTEGER:
50485756Smsmith
505123315Snjl            AcpiOsPrintf (" I:%8.8X8.8%X\n",
506193267Sjkim                ACPI_FORMAT_UINT64 (ObjDesc->Integer.Value));
50785756Smsmith            break;
50885756Smsmith
50985756Smsmith        case ACPI_TYPE_STRING:
51085756Smsmith
51187031Smsmith            AcpiOsPrintf (" S:%p-%X\n", ObjDesc->String.Pointer,
512193267Sjkim                ObjDesc->String.Length);
51385756Smsmith            break;
51485756Smsmith
51585756Smsmith        case ACPI_TYPE_BUFFER:
51685756Smsmith
51787031Smsmith            AcpiOsPrintf (" B:%p-%X\n", ObjDesc->Buffer.Pointer,
518193267Sjkim                ObjDesc->Buffer.Length);
51985756Smsmith            break;
52085756Smsmith
52185756Smsmith        default:
52285756Smsmith
52387031Smsmith            AcpiOsPrintf ("\n");
52485756Smsmith            break;
52585756Smsmith        }
52667754Smsmith        break;
52787031Smsmith
52887031Smsmith    default:
52987031Smsmith        AcpiOsPrintf ("\n");
53087031Smsmith        break;
53167754Smsmith    }
53267754Smsmith
53367754Smsmith    /* If debug turned off, done */
53467754Smsmith
53582367Smsmith    if (!(AcpiDbgLevel & ACPI_LV_VALUES))
53667754Smsmith    {
53767754Smsmith        return (AE_OK);
53867754Smsmith    }
53967754Smsmith
54067754Smsmith    /* If there is an attached object, display it */
54167754Smsmith
542306536Sjkim    DbgLevel = AcpiDbgLevel;
54391116Smsmith    AcpiDbgLevel = 0;
544306536Sjkim    ObjDesc = AcpiNsGetAttachedObject (ThisNode);
54591116Smsmith    AcpiDbgLevel = DbgLevel;
54667754Smsmith
54767754Smsmith    /* Dump attached objects */
54867754Smsmith
54985756Smsmith    while (ObjDesc)
55067754Smsmith    {
551107325Siwasaki        ObjType = ACPI_TYPE_INVALID;
552151937Sjkim        AcpiOsPrintf ("Attached Object %p: ", ObjDesc);
55367754Smsmith
55467754Smsmith        /* Decode the type of attached object and dump the contents */
55567754Smsmith
55691116Smsmith        switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
55791116Smsmith        {
55891116Smsmith        case ACPI_DESC_TYPE_NAMED:
55967754Smsmith
56087031Smsmith            AcpiOsPrintf ("(Ptr to Node)\n");
56167754Smsmith            BytesToDump = sizeof (ACPI_NAMESPACE_NODE);
562151937Sjkim            ACPI_DUMP_BUFFER (ObjDesc, BytesToDump);
56391116Smsmith            break;
56467754Smsmith
56599679Siwasaki        case ACPI_DESC_TYPE_OPERAND:
56691116Smsmith
567193267Sjkim            ObjType = ObjDesc->Common.Type;
56867754Smsmith
569107325Siwasaki            if (ObjType > ACPI_TYPE_LOCAL_MAX)
57067754Smsmith            {
571306536Sjkim                AcpiOsPrintf (
572306536Sjkim                    "(Pointer to ACPI Object type %.2X [UNKNOWN])\n",
573138287Smarks                    ObjType);
574306536Sjkim
57567754Smsmith                BytesToDump = 32;
57667754Smsmith            }
57767754Smsmith            else
57867754Smsmith            {
579306536Sjkim                AcpiOsPrintf (
580306536Sjkim                    "(Pointer to ACPI Object type %.2X [%s])\n",
581151937Sjkim                    ObjType, AcpiUtGetTypeName (ObjType));
582306536Sjkim
58367754Smsmith                BytesToDump = sizeof (ACPI_OPERAND_OBJECT);
58467754Smsmith            }
585151937Sjkim
586151937Sjkim            ACPI_DUMP_BUFFER (ObjDesc, BytesToDump);
58791116Smsmith            break;
58891116Smsmith
58991116Smsmith        default:
59091116Smsmith
59191116Smsmith            break;
59267754Smsmith        }
59367754Smsmith
59467754Smsmith        /* If value is NOT an internal object, we are done */
59567754Smsmith
59699679Siwasaki        if (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc) != ACPI_DESC_TYPE_OPERAND)
59767754Smsmith        {
59867754Smsmith            goto Cleanup;
59967754Smsmith        }
60067754Smsmith
601193267Sjkim        /* Valid object, get the pointer to next level, if any */
602193267Sjkim
60367754Smsmith        switch (ObjType)
60467754Smsmith        {
605151937Sjkim        case ACPI_TYPE_BUFFER:
60667754Smsmith        case ACPI_TYPE_STRING:
607151937Sjkim            /*
608151937Sjkim             * NOTE: takes advantage of common fields between string/buffer
609151937Sjkim             */
610151937Sjkim            BytesToDump = ObjDesc->String.Length;
61199679Siwasaki            ObjDesc = (void *) ObjDesc->String.Pointer;
612306536Sjkim
613306536Sjkim            AcpiOsPrintf ("(Buffer/String pointer %p length %X)\n",
614151937Sjkim                ObjDesc, BytesToDump);
615151937Sjkim            ACPI_DUMP_BUFFER (ObjDesc, BytesToDump);
616151937Sjkim            goto Cleanup;
61767754Smsmith
61877424Smsmith        case ACPI_TYPE_BUFFER_FIELD:
619250838Sjkim
62085756Smsmith            ObjDesc = (ACPI_OPERAND_OBJECT *) ObjDesc->BufferField.BufferObj;
62177424Smsmith            break;
62277424Smsmith
62367754Smsmith        case ACPI_TYPE_PACKAGE:
624250838Sjkim
62599679Siwasaki            ObjDesc = (void *) ObjDesc->Package.Elements;
62667754Smsmith            break;
62767754Smsmith
62867754Smsmith        case ACPI_TYPE_METHOD:
629250838Sjkim
63099679Siwasaki            ObjDesc = (void *) ObjDesc->Method.AmlStart;
63167754Smsmith            break;
63267754Smsmith
633107325Siwasaki        case ACPI_TYPE_LOCAL_REGION_FIELD:
634250838Sjkim
63599679Siwasaki            ObjDesc = (void *) ObjDesc->Field.RegionObj;
63667754Smsmith            break;
63767754Smsmith
638107325Siwasaki        case ACPI_TYPE_LOCAL_BANK_FIELD:
639250838Sjkim
64099679Siwasaki            ObjDesc = (void *) ObjDesc->BankField.RegionObj;
64167754Smsmith            break;
64267754Smsmith
643107325Siwasaki        case ACPI_TYPE_LOCAL_INDEX_FIELD:
644252279Sjkim
64599679Siwasaki            ObjDesc = (void *) ObjDesc->IndexField.IndexObj;
64667754Smsmith            break;
64767754Smsmith
64899679Siwasaki        default:
649250838Sjkim
65067754Smsmith            goto Cleanup;
65167754Smsmith        }
65267754Smsmith
653107325Siwasaki        ObjType = ACPI_TYPE_INVALID;   /* Terminate loop after next pass */
65467754Smsmith    }
65567754Smsmith
65667754SmsmithCleanup:
65787031Smsmith    AcpiOsPrintf ("\n");
65867754Smsmith    return (AE_OK);
65967754Smsmith}
66067754Smsmith
66167754Smsmith
66277424Smsmith/*******************************************************************************
66367754Smsmith *
66467754Smsmith * FUNCTION:    AcpiNsDumpObjects
66567754Smsmith *
66667754Smsmith * PARAMETERS:  Type                - Object type to be dumped
667151937Sjkim *              DisplayType         - 0 or ACPI_DISPLAY_SUMMARY
668138287Smarks *              MaxDepth            - Maximum depth of dump. Use ACPI_UINT32_MAX
66967754Smsmith *                                    for an effectively unlimited depth.
670193267Sjkim *              OwnerId             - Dump only objects owned by this ID. Use
67167754Smsmith *                                    ACPI_UINT32_MAX to match all owners.
67267754Smsmith *              StartHandle         - Where in namespace to start/end search
67367754Smsmith *
674151937Sjkim * RETURN:      None
675151937Sjkim *
676193267Sjkim * DESCRIPTION: Dump typed objects within the loaded namespace. Uses
677193267Sjkim *              AcpiNsWalkNamespace in conjunction with AcpiNsDumpOneObject.
67867754Smsmith *
67977424Smsmith ******************************************************************************/
68067754Smsmith
68167754Smsmithvoid
68267754SmsmithAcpiNsDumpObjects (
68391116Smsmith    ACPI_OBJECT_TYPE        Type,
68485756Smsmith    UINT8                   DisplayType,
68567754Smsmith    UINT32                  MaxDepth,
686151937Sjkim    ACPI_OWNER_ID           OwnerId,
68767754Smsmith    ACPI_HANDLE             StartHandle)
68867754Smsmith{
68967754Smsmith    ACPI_WALK_INFO          Info;
690217365Sjkim    ACPI_STATUS             Status;
69167754Smsmith
69267754Smsmith
69391116Smsmith    ACPI_FUNCTION_ENTRY ();
69483174Smsmith
69583174Smsmith
696217365Sjkim    /*
697217365Sjkim     * Just lock the entire namespace for the duration of the dump.
698217365Sjkim     * We don't want any changes to the namespace during this time,
699217365Sjkim     * especially the temporary nodes since we are going to display
700217365Sjkim     * them also.
701217365Sjkim     */
702217365Sjkim    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
703217365Sjkim    if (ACPI_FAILURE (Status))
704217365Sjkim    {
705217365Sjkim        AcpiOsPrintf ("Could not acquire namespace mutex\n");
706217365Sjkim        return;
707217365Sjkim    }
708217365Sjkim
70982367Smsmith    Info.DebugLevel = ACPI_LV_TABLES;
71067754Smsmith    Info.OwnerId = OwnerId;
71185756Smsmith    Info.DisplayType = DisplayType;
71267754Smsmith
713102550Siwasaki    (void) AcpiNsWalkNamespace (Type, StartHandle, MaxDepth,
714306536Sjkim        ACPI_NS_WALK_NO_UNLOCK | ACPI_NS_WALK_TEMP_NODES,
715306536Sjkim        AcpiNsDumpOneObject, NULL, (void *) &Info, NULL);
716217365Sjkim
717217365Sjkim    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
71867754Smsmith}
71967754Smsmith
72067754Smsmith
72177424Smsmith/*******************************************************************************
72267754Smsmith *
723254745Sjkim * FUNCTION:    AcpiNsDumpOneObjectPath, AcpiNsGetMaxDepth
724254745Sjkim *
725254745Sjkim * PARAMETERS:  ObjHandle           - Node to be dumped
726254745Sjkim *              Level               - Nesting level of the handle
727254745Sjkim *              Context             - Passed into WalkNamespace
728254745Sjkim *              ReturnValue         - Not used
729254745Sjkim *
730254745Sjkim * RETURN:      Status
731254745Sjkim *
732254745Sjkim * DESCRIPTION: Dump the full pathname to a namespace object. AcpNsGetMaxDepth
733254745Sjkim *              computes the maximum nesting depth in the namespace tree, in
734254745Sjkim *              order to simplify formatting in AcpiNsDumpOneObjectPath.
735254745Sjkim *              These procedures are UserFunctions called by AcpiNsWalkNamespace.
736254745Sjkim *
737254745Sjkim ******************************************************************************/
738254745Sjkim
739254745Sjkimstatic ACPI_STATUS
740254745SjkimAcpiNsDumpOneObjectPath (
741254745Sjkim    ACPI_HANDLE             ObjHandle,
742254745Sjkim    UINT32                  Level,
743254745Sjkim    void                    *Context,
744254745Sjkim    void                    **ReturnValue)
745254745Sjkim{
746254745Sjkim    UINT32                  MaxLevel = *((UINT32 *) Context);
747254745Sjkim    char                    *Pathname;
748254745Sjkim    ACPI_NAMESPACE_NODE     *Node;
749254745Sjkim    int                     PathIndent;
750254745Sjkim
751254745Sjkim
752254745Sjkim    if (!ObjHandle)
753254745Sjkim    {
754254745Sjkim        return (AE_OK);
755254745Sjkim    }
756254745Sjkim
757254745Sjkim    Node = AcpiNsValidateHandle (ObjHandle);
758281075Sdim    if (!Node)
759281075Sdim    {
760281075Sdim        /* Ignore bad node during namespace walk */
761281075Sdim
762281075Sdim        return (AE_OK);
763281075Sdim    }
764281075Sdim
765306536Sjkim    Pathname = AcpiNsGetNormalizedPathname (Node, TRUE);
766254745Sjkim
767254745Sjkim    PathIndent = 1;
768254745Sjkim    if (Level <= MaxLevel)
769254745Sjkim    {
770254745Sjkim        PathIndent = MaxLevel - Level + 1;
771254745Sjkim    }
772254745Sjkim
773254745Sjkim    AcpiOsPrintf ("%2d%*s%-12s%*s",
774254745Sjkim        Level, Level, " ", AcpiUtGetTypeName (Node->Type),
775254745Sjkim        PathIndent, " ");
776254745Sjkim
777254745Sjkim    AcpiOsPrintf ("%s\n", &Pathname[1]);
778254745Sjkim    ACPI_FREE (Pathname);
779254745Sjkim    return (AE_OK);
780254745Sjkim}
781254745Sjkim
782254745Sjkim
783254745Sjkimstatic ACPI_STATUS
784254745SjkimAcpiNsGetMaxDepth (
785254745Sjkim    ACPI_HANDLE             ObjHandle,
786254745Sjkim    UINT32                  Level,
787254745Sjkim    void                    *Context,
788254745Sjkim    void                    **ReturnValue)
789254745Sjkim{
790254745Sjkim    UINT32                  *MaxLevel = (UINT32 *) Context;
791254745Sjkim
792254745Sjkim
793254745Sjkim    if (Level > *MaxLevel)
794254745Sjkim    {
795254745Sjkim        *MaxLevel = Level;
796254745Sjkim    }
797254745Sjkim    return (AE_OK);
798254745Sjkim}
799254745Sjkim
800254745Sjkim
801254745Sjkim/*******************************************************************************
802254745Sjkim *
803254745Sjkim * FUNCTION:    AcpiNsDumpObjectPaths
804254745Sjkim *
805254745Sjkim * PARAMETERS:  Type                - Object type to be dumped
806254745Sjkim *              DisplayType         - 0 or ACPI_DISPLAY_SUMMARY
807254745Sjkim *              MaxDepth            - Maximum depth of dump. Use ACPI_UINT32_MAX
808254745Sjkim *                                    for an effectively unlimited depth.
809254745Sjkim *              OwnerId             - Dump only objects owned by this ID. Use
810254745Sjkim *                                    ACPI_UINT32_MAX to match all owners.
811254745Sjkim *              StartHandle         - Where in namespace to start/end search
812254745Sjkim *
813254745Sjkim * RETURN:      None
814254745Sjkim *
815254745Sjkim * DESCRIPTION: Dump full object pathnames within the loaded namespace. Uses
816254745Sjkim *              AcpiNsWalkNamespace in conjunction with AcpiNsDumpOneObjectPath.
817254745Sjkim *
818254745Sjkim ******************************************************************************/
819254745Sjkim
820254745Sjkimvoid
821254745SjkimAcpiNsDumpObjectPaths (
822254745Sjkim    ACPI_OBJECT_TYPE        Type,
823254745Sjkim    UINT8                   DisplayType,
824254745Sjkim    UINT32                  MaxDepth,
825254745Sjkim    ACPI_OWNER_ID           OwnerId,
826254745Sjkim    ACPI_HANDLE             StartHandle)
827254745Sjkim{
828254745Sjkim    ACPI_STATUS             Status;
829254745Sjkim    UINT32                  MaxLevel = 0;
830254745Sjkim
831254745Sjkim
832254745Sjkim    ACPI_FUNCTION_ENTRY ();
833254745Sjkim
834254745Sjkim
835254745Sjkim    /*
836254745Sjkim     * Just lock the entire namespace for the duration of the dump.
837254745Sjkim     * We don't want any changes to the namespace during this time,
838254745Sjkim     * especially the temporary nodes since we are going to display
839254745Sjkim     * them also.
840254745Sjkim     */
841254745Sjkim    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
842254745Sjkim    if (ACPI_FAILURE (Status))
843254745Sjkim    {
844254745Sjkim        AcpiOsPrintf ("Could not acquire namespace mutex\n");
845254745Sjkim        return;
846254745Sjkim    }
847254745Sjkim
848254745Sjkim    /* Get the max depth of the namespace tree, for formatting later */
849254745Sjkim
850254745Sjkim    (void) AcpiNsWalkNamespace (Type, StartHandle, MaxDepth,
851306536Sjkim        ACPI_NS_WALK_NO_UNLOCK | ACPI_NS_WALK_TEMP_NODES,
852306536Sjkim        AcpiNsGetMaxDepth, NULL, (void *) &MaxLevel, NULL);
853254745Sjkim
854254745Sjkim    /* Now dump the entire namespace */
855254745Sjkim
856254745Sjkim    (void) AcpiNsWalkNamespace (Type, StartHandle, MaxDepth,
857306536Sjkim        ACPI_NS_WALK_NO_UNLOCK | ACPI_NS_WALK_TEMP_NODES,
858306536Sjkim        AcpiNsDumpOneObjectPath, NULL, (void *) &MaxLevel, NULL);
859254745Sjkim
860254745Sjkim    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
861254745Sjkim}
862254745Sjkim
863254745Sjkim
864254745Sjkim/*******************************************************************************
865254745Sjkim *
866151937Sjkim * FUNCTION:    AcpiNsDumpEntry
867151937Sjkim *
868151937Sjkim * PARAMETERS:  Handle              - Node to be dumped
869151937Sjkim *              DebugLevel          - Output level
870151937Sjkim *
871151937Sjkim * RETURN:      None
872151937Sjkim *
873151937Sjkim * DESCRIPTION: Dump a single Node
874151937Sjkim *
875151937Sjkim ******************************************************************************/
876151937Sjkim
877151937Sjkimvoid
878151937SjkimAcpiNsDumpEntry (
879151937Sjkim    ACPI_HANDLE             Handle,
880151937Sjkim    UINT32                  DebugLevel)
881151937Sjkim{
882151937Sjkim    ACPI_WALK_INFO          Info;
883151937Sjkim
884151937Sjkim
885151937Sjkim    ACPI_FUNCTION_ENTRY ();
886151937Sjkim
887151937Sjkim
888151937Sjkim    Info.DebugLevel = DebugLevel;
889151937Sjkim    Info.OwnerId = ACPI_OWNER_ID_MAX;
890151937Sjkim    Info.DisplayType = ACPI_DISPLAY_SUMMARY;
891151937Sjkim
892151937Sjkim    (void) AcpiNsDumpOneObject (Handle, 1, &Info, NULL);
893151937Sjkim}
894151937Sjkim
895151937Sjkim
896151937Sjkim#ifdef ACPI_ASL_COMPILER
897151937Sjkim/*******************************************************************************
898151937Sjkim *
89967754Smsmith * FUNCTION:    AcpiNsDumpTables
90067754Smsmith *
90167754Smsmith * PARAMETERS:  SearchBase          - Root of subtree to be dumped, or
90267754Smsmith *                                    NS_ALL to dump the entire namespace
903241973Sjkim *              MaxDepth            - Maximum depth of dump. Use INT_MAX
90467754Smsmith *                                    for an effectively unlimited depth.
90567754Smsmith *
906151937Sjkim * RETURN:      None
907151937Sjkim *
90867754Smsmith * DESCRIPTION: Dump the name space, or a portion of it.
90967754Smsmith *
91077424Smsmith ******************************************************************************/
91167754Smsmith
91267754Smsmithvoid
91367754SmsmithAcpiNsDumpTables (
91467754Smsmith    ACPI_HANDLE             SearchBase,
91567754Smsmith    UINT32                  MaxDepth)
91667754Smsmith{
91767754Smsmith    ACPI_HANDLE             SearchHandle = SearchBase;
91867754Smsmith
91967754Smsmith
920167802Sjkim    ACPI_FUNCTION_TRACE (NsDumpTables);
92167754Smsmith
92267754Smsmith
92367754Smsmith    if (!AcpiGbl_RootNode)
92467754Smsmith    {
92567754Smsmith        /*
92667754Smsmith         * If the name space has not been initialized,
92767754Smsmith         * there is nothing to dump.
92867754Smsmith         */
929306536Sjkim        ACPI_DEBUG_PRINT ((ACPI_DB_TABLES,
930306536Sjkim            "namespace not initialized!\n"));
93167754Smsmith        return_VOID;
93267754Smsmith    }
93367754Smsmith
93491116Smsmith    if (ACPI_NS_ALL == SearchBase)
93567754Smsmith    {
936151937Sjkim        /* Entire namespace */
93767754Smsmith
93867754Smsmith        SearchHandle = AcpiGbl_RootNode;
93982367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_TABLES, "\\\n"));
94067754Smsmith    }
94167754Smsmith
94287031Smsmith    AcpiNsDumpObjects (ACPI_TYPE_ANY, ACPI_DISPLAY_OBJECTS, MaxDepth,
943306536Sjkim        ACPI_OWNER_ID_MAX, SearchHandle);
94467754Smsmith    return_VOID;
94567754Smsmith}
94667754Smsmith#endif
947151937Sjkim#endif
948