exdebug.c revision 281075
1/******************************************************************************
2 *
3 * Module Name: exdebug - Support for stores to the AML Debug Object
4 *
5 *****************************************************************************/
6
7/*
8 * Copyright (C) 2000 - 2015, 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#include <contrib/dev/acpica/include/acpi.h>
45#include <contrib/dev/acpica/include/accommon.h>
46#include <contrib/dev/acpica/include/acinterp.h>
47
48
49#define _COMPONENT          ACPI_EXECUTER
50        ACPI_MODULE_NAME    ("exdebug")
51
52
53#ifndef ACPI_NO_ERROR_MESSAGES
54/*******************************************************************************
55 *
56 * FUNCTION:    AcpiExDoDebugObject
57 *
58 * PARAMETERS:  SourceDesc          - Object to be output to "Debug Object"
59 *              Level               - Indentation level (used for packages)
60 *              Index               - Current package element, zero if not pkg
61 *
62 * RETURN:      None
63 *
64 * DESCRIPTION: Handles stores to the AML Debug Object. For example:
65 *              Store(INT1, Debug)
66 *
67 * This function is not compiled if ACPI_NO_ERROR_MESSAGES is set.
68 *
69 * This function is only enabled if AcpiGbl_EnableAmlDebugObject is set, or
70 * if ACPI_LV_DEBUG_OBJECT is set in the AcpiDbgLevel. Thus, in the normal
71 * operational case, stores to the debug object are ignored but can be easily
72 * enabled if necessary.
73 *
74 ******************************************************************************/
75
76void
77AcpiExDoDebugObject (
78    ACPI_OPERAND_OBJECT     *SourceDesc,
79    UINT32                  Level,
80    UINT32                  Index)
81{
82    UINT32                  i;
83    UINT32                  Timer;
84
85
86    ACPI_FUNCTION_TRACE_PTR (ExDoDebugObject, SourceDesc);
87
88
89    /* Output must be enabled via the DebugObject global or the DbgLevel */
90
91    if (!AcpiGbl_EnableAmlDebugObject &&
92        !(AcpiDbgLevel & ACPI_LV_DEBUG_OBJECT))
93    {
94        return_VOID;
95    }
96
97    /*
98     * We will emit the current timer value (in microseconds) with each
99     * debug output. Only need the lower 26 bits. This allows for 67
100     * million microseconds or 67 seconds before rollover.
101     */
102    Timer = ((UINT32) AcpiOsGetTimer () / 10); /* (100 nanoseconds to microseconds) */
103    Timer &= 0x03FFFFFF;
104
105    /*
106     * Print line header as long as we are not in the middle of an
107     * object display
108     */
109    if (!((Level > 0) && Index == 0))
110    {
111        AcpiOsPrintf ("[ACPI Debug %.8u] %*s", Timer, Level, " ");
112    }
113
114    /* Display the index for package output only */
115
116    if (Index > 0)
117    {
118       AcpiOsPrintf ("(%.2u) ", Index-1);
119    }
120
121    if (!SourceDesc)
122    {
123        AcpiOsPrintf ("[Null Object]\n");
124        return_VOID;
125    }
126
127    if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_OPERAND)
128    {
129        AcpiOsPrintf ("%s ", AcpiUtGetObjectTypeName (SourceDesc));
130
131        if (!AcpiUtValidInternalObject (SourceDesc))
132        {
133           AcpiOsPrintf ("%p, Invalid Internal Object!\n", SourceDesc);
134           return_VOID;
135        }
136    }
137    else if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_NAMED)
138    {
139        AcpiOsPrintf ("%s: %p\n",
140            AcpiUtGetTypeName (((ACPI_NAMESPACE_NODE *) SourceDesc)->Type),
141            SourceDesc);
142        return_VOID;
143    }
144    else
145    {
146        return_VOID;
147    }
148
149    /* SourceDesc is of type ACPI_DESC_TYPE_OPERAND */
150
151    switch (SourceDesc->Common.Type)
152    {
153    case ACPI_TYPE_INTEGER:
154
155        /* Output correct integer width */
156
157        if (AcpiGbl_IntegerByteWidth == 4)
158        {
159            AcpiOsPrintf ("0x%8.8X\n",
160                (UINT32) SourceDesc->Integer.Value);
161        }
162        else
163        {
164            AcpiOsPrintf ("0x%8.8X%8.8X\n",
165                ACPI_FORMAT_UINT64 (SourceDesc->Integer.Value));
166        }
167        break;
168
169    case ACPI_TYPE_BUFFER:
170
171        AcpiOsPrintf ("[0x%.2X]\n", (UINT32) SourceDesc->Buffer.Length);
172        AcpiUtDumpBuffer (SourceDesc->Buffer.Pointer,
173            (SourceDesc->Buffer.Length < 256) ?
174                SourceDesc->Buffer.Length : 256, DB_BYTE_DISPLAY, 0);
175        break;
176
177    case ACPI_TYPE_STRING:
178
179        AcpiOsPrintf ("[0x%.2X] \"%s\"\n",
180            SourceDesc->String.Length, SourceDesc->String.Pointer);
181        break;
182
183    case ACPI_TYPE_PACKAGE:
184
185        AcpiOsPrintf ("[Contains 0x%.2X Elements]\n",
186            SourceDesc->Package.Count);
187
188        /* Output the entire contents of the package */
189
190        for (i = 0; i < SourceDesc->Package.Count; i++)
191        {
192            AcpiExDoDebugObject (SourceDesc->Package.Elements[i],
193                Level+4, i+1);
194        }
195        break;
196
197    case ACPI_TYPE_LOCAL_REFERENCE:
198
199        AcpiOsPrintf ("[%s] ", AcpiUtGetReferenceName (SourceDesc));
200
201        /* Decode the reference */
202
203        switch (SourceDesc->Reference.Class)
204        {
205        case ACPI_REFCLASS_INDEX:
206
207            AcpiOsPrintf ("0x%X\n", SourceDesc->Reference.Value);
208            break;
209
210        case ACPI_REFCLASS_TABLE:
211
212            /* Case for DdbHandle */
213
214            AcpiOsPrintf ("Table Index 0x%X\n", SourceDesc->Reference.Value);
215            return_VOID;
216
217        default:
218
219            break;
220        }
221
222        AcpiOsPrintf ("  ");
223
224        /* Check for valid node first, then valid object */
225
226        if (SourceDesc->Reference.Node)
227        {
228            if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc->Reference.Node) !=
229                    ACPI_DESC_TYPE_NAMED)
230            {
231                AcpiOsPrintf (" %p - Not a valid namespace node\n",
232                    SourceDesc->Reference.Node);
233            }
234            else
235            {
236                AcpiOsPrintf ("Node %p [%4.4s] ", SourceDesc->Reference.Node,
237                    (SourceDesc->Reference.Node)->Name.Ascii);
238
239                switch ((SourceDesc->Reference.Node)->Type)
240                {
241                /* These types have no attached object */
242
243                case ACPI_TYPE_DEVICE:
244                    AcpiOsPrintf ("Device\n");
245                    break;
246
247                case ACPI_TYPE_THERMAL:
248                    AcpiOsPrintf ("Thermal Zone\n");
249                    break;
250
251                default:
252
253                    AcpiExDoDebugObject ((SourceDesc->Reference.Node)->Object,
254                        Level+4, 0);
255                    break;
256                }
257            }
258        }
259        else if (SourceDesc->Reference.Object)
260        {
261            if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc->Reference.Object) ==
262                    ACPI_DESC_TYPE_NAMED)
263            {
264                AcpiExDoDebugObject (((ACPI_NAMESPACE_NODE *)
265                    SourceDesc->Reference.Object)->Object,
266                    Level+4, 0);
267            }
268            else
269            {
270                AcpiExDoDebugObject (SourceDesc->Reference.Object,
271                    Level+4, 0);
272            }
273        }
274        break;
275
276    default:
277
278        AcpiOsPrintf ("%p\n", SourceDesc);
279        break;
280    }
281
282    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC, "\n"));
283    return_VOID;
284}
285#endif
286