1/******************************************************************************
2 *
3 * Module Name: exdebug - Support for stores to the AML Debug Object
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2011, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 *    notice, this list of conditions, and the following disclaimer,
16 *    without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 *    substantially similar to the "NO WARRANTY" disclaimer below
19 *    ("Disclaimer") and any redistribution must be conditioned upon
20 *    including a substantially similar Disclaimer requirement for further
21 *    binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 *    of any contributors may be used to endorse or promote products derived
24 *    from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44#define __EXDEBUG_C__
45
46#include "acpi.h"
47#include "accommon.h"
48#include "acinterp.h"
49
50
51#define _COMPONENT          ACPI_EXECUTER
52        ACPI_MODULE_NAME    ("exdebug")
53
54
55#ifndef ACPI_NO_ERROR_MESSAGES
56/*******************************************************************************
57 *
58 * FUNCTION:    AcpiExDoDebugObject
59 *
60 * PARAMETERS:  SourceDesc          - Object to be output to "Debug Object"
61 *              Level               - Indentation level (used for packages)
62 *              Index               - Current package element, zero if not pkg
63 *
64 * RETURN:      None
65 *
66 * DESCRIPTION: Handles stores to the AML Debug Object. For example:
67 *              Store(INT1, Debug)
68 *
69 * This function is not compiled if ACPI_NO_ERROR_MESSAGES is set.
70 *
71 * This function is only enabled if AcpiGbl_EnableAmlDebugObject is set.
72 * Thus, in the normal operational case, stores to the debug object are
73 * ignored but can be easily enabled if necessary.
74 *
75 ******************************************************************************/
76
77void
78AcpiExDoDebugObject (
79    ACPI_OPERAND_OBJECT     *SourceDesc,
80    UINT32                  Level,
81    UINT32                  Index)
82{
83    UINT32                  i;
84
85
86    ACPI_FUNCTION_TRACE_PTR (ExDoDebugObject, SourceDesc);
87
88
89    /* Output must be enabled via the DebugObject global */
90
91    if (!AcpiGbl_EnableAmlDebugObject)
92    {
93        return_VOID;
94    }
95
96    /*
97     * Print line header as long as we are not in the middle of an
98     * object display
99     */
100    if (!((Level > 0) && Index == 0))
101    {
102        AcpiOsPrintf ("[ACPI Debug] %*s", Level, " ");
103    }
104
105    /* Display the index for package output only */
106
107    if (Index > 0)
108    {
109       AcpiOsPrintf ("(%.2u) ", Index-1);
110    }
111
112    if (!SourceDesc)
113    {
114        AcpiOsPrintf ("[Null Object]\n");
115        return_VOID;
116    }
117
118    if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_OPERAND)
119    {
120        AcpiOsPrintf ("%s ", AcpiUtGetObjectTypeName (SourceDesc));
121
122        if (!AcpiUtValidInternalObject (SourceDesc))
123        {
124           AcpiOsPrintf ("%p, Invalid Internal Object!\n", SourceDesc);
125           return_VOID;
126        }
127    }
128    else if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_NAMED)
129    {
130        AcpiOsPrintf ("%s: %p\n",
131            AcpiUtGetTypeName (((ACPI_NAMESPACE_NODE *) SourceDesc)->Type),
132            SourceDesc);
133        return_VOID;
134    }
135    else
136    {
137        return_VOID;
138    }
139
140    /* SourceDesc is of type ACPI_DESC_TYPE_OPERAND */
141
142    switch (SourceDesc->Common.Type)
143    {
144    case ACPI_TYPE_INTEGER:
145
146        /* Output correct integer width */
147
148        if (AcpiGbl_IntegerByteWidth == 4)
149        {
150            AcpiOsPrintf ("0x%8.8X\n",
151                (UINT32) SourceDesc->Integer.Value);
152        }
153        else
154        {
155            AcpiOsPrintf ("0x%8.8X%8.8X\n",
156                ACPI_FORMAT_UINT64 (SourceDesc->Integer.Value));
157        }
158        break;
159
160    case ACPI_TYPE_BUFFER:
161
162        AcpiOsPrintf ("[0x%.2X]\n", (UINT32) SourceDesc->Buffer.Length);
163        AcpiUtDumpBuffer2 (SourceDesc->Buffer.Pointer,
164            (SourceDesc->Buffer.Length < 256) ?
165                SourceDesc->Buffer.Length : 256, DB_BYTE_DISPLAY);
166        break;
167
168    case ACPI_TYPE_STRING:
169
170        AcpiOsPrintf ("[0x%.2X] \"%s\"\n",
171            SourceDesc->String.Length, SourceDesc->String.Pointer);
172        break;
173
174    case ACPI_TYPE_PACKAGE:
175
176        AcpiOsPrintf ("[Contains 0x%.2X Elements]\n",
177            SourceDesc->Package.Count);
178
179        /* Output the entire contents of the package */
180
181        for (i = 0; i < SourceDesc->Package.Count; i++)
182        {
183            AcpiExDoDebugObject (SourceDesc->Package.Elements[i],
184                Level+4, i+1);
185        }
186        break;
187
188    case ACPI_TYPE_LOCAL_REFERENCE:
189
190        AcpiOsPrintf ("[%s] ", AcpiUtGetReferenceName (SourceDesc));
191
192        /* Decode the reference */
193
194        switch (SourceDesc->Reference.Class)
195        {
196        case ACPI_REFCLASS_INDEX:
197
198            AcpiOsPrintf ("0x%X\n", SourceDesc->Reference.Value);
199            break;
200
201        case ACPI_REFCLASS_TABLE:
202
203            /* Case for DdbHandle */
204
205            AcpiOsPrintf ("Table Index 0x%X\n", SourceDesc->Reference.Value);
206            return;
207
208        default:
209            break;
210        }
211
212        AcpiOsPrintf ("  ");
213
214        /* Check for valid node first, then valid object */
215
216        if (SourceDesc->Reference.Node)
217        {
218            if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc->Reference.Node) !=
219                    ACPI_DESC_TYPE_NAMED)
220            {
221                AcpiOsPrintf (" %p - Not a valid namespace node\n",
222                    SourceDesc->Reference.Node);
223            }
224            else
225            {
226                AcpiOsPrintf ("Node %p [%4.4s] ", SourceDesc->Reference.Node,
227                    (SourceDesc->Reference.Node)->Name.Ascii);
228
229                switch ((SourceDesc->Reference.Node)->Type)
230                {
231                /* These types have no attached object */
232
233                case ACPI_TYPE_DEVICE:
234                    AcpiOsPrintf ("Device\n");
235                    break;
236
237                case ACPI_TYPE_THERMAL:
238                    AcpiOsPrintf ("Thermal Zone\n");
239                    break;
240
241                default:
242                    AcpiExDoDebugObject ((SourceDesc->Reference.Node)->Object,
243                        Level+4, 0);
244                    break;
245                }
246            }
247        }
248        else if (SourceDesc->Reference.Object)
249        {
250            if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc->Reference.Object) ==
251                    ACPI_DESC_TYPE_NAMED)
252            {
253                AcpiExDoDebugObject (((ACPI_NAMESPACE_NODE *)
254                    SourceDesc->Reference.Object)->Object,
255                    Level+4, 0);
256            }
257            else
258            {
259                AcpiExDoDebugObject (SourceDesc->Reference.Object,
260                    Level+4, 0);
261            }
262        }
263        break;
264
265    default:
266
267        AcpiOsPrintf ("%p\n", SourceDesc);
268        break;
269    }
270
271    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC, "\n"));
272    return_VOID;
273}
274#endif
275
276
277