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