126f3cdf0SGordon Ross /******************************************************************************
226f3cdf0SGordon Ross *
326f3cdf0SGordon Ross * Module Name: exdebug - Support for stores to the AML Debug Object
426f3cdf0SGordon Ross *
526f3cdf0SGordon Ross *****************************************************************************/
626f3cdf0SGordon Ross
726f3cdf0SGordon Ross /*
8*cb565728SJerry Jelinek * Copyright (C) 2000 - 2016, Intel Corp.
926f3cdf0SGordon Ross * All rights reserved.
1026f3cdf0SGordon Ross *
1126f3cdf0SGordon Ross * Redistribution and use in source and binary forms, with or without
1226f3cdf0SGordon Ross * modification, are permitted provided that the following conditions
1326f3cdf0SGordon Ross * are met:
1426f3cdf0SGordon Ross * 1. Redistributions of source code must retain the above copyright
1526f3cdf0SGordon Ross * notice, this list of conditions, and the following disclaimer,
1626f3cdf0SGordon Ross * without modification.
1726f3cdf0SGordon Ross * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1826f3cdf0SGordon Ross * substantially similar to the "NO WARRANTY" disclaimer below
1926f3cdf0SGordon Ross * ("Disclaimer") and any redistribution must be conditioned upon
2026f3cdf0SGordon Ross * including a substantially similar Disclaimer requirement for further
2126f3cdf0SGordon Ross * binary redistribution.
2226f3cdf0SGordon Ross * 3. Neither the names of the above-listed copyright holders nor the names
2326f3cdf0SGordon Ross * of any contributors may be used to endorse or promote products derived
2426f3cdf0SGordon Ross * from this software without specific prior written permission.
2526f3cdf0SGordon Ross *
2626f3cdf0SGordon Ross * Alternatively, this software may be distributed under the terms of the
2726f3cdf0SGordon Ross * GNU General Public License ("GPL") version 2 as published by the Free
2826f3cdf0SGordon Ross * Software Foundation.
2926f3cdf0SGordon Ross *
3026f3cdf0SGordon Ross * NO WARRANTY
3126f3cdf0SGordon Ross * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3226f3cdf0SGordon Ross * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3326f3cdf0SGordon Ross * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3426f3cdf0SGordon Ross * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3526f3cdf0SGordon Ross * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3626f3cdf0SGordon Ross * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3726f3cdf0SGordon Ross * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3826f3cdf0SGordon Ross * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3926f3cdf0SGordon Ross * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4026f3cdf0SGordon Ross * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4126f3cdf0SGordon Ross * POSSIBILITY OF SUCH DAMAGES.
4226f3cdf0SGordon Ross */
4326f3cdf0SGordon Ross
4426f3cdf0SGordon Ross #include "acpi.h"
4526f3cdf0SGordon Ross #include "accommon.h"
4626f3cdf0SGordon Ross #include "acinterp.h"
4726f3cdf0SGordon Ross
4826f3cdf0SGordon Ross
4926f3cdf0SGordon Ross #define _COMPONENT ACPI_EXECUTER
5026f3cdf0SGordon Ross ACPI_MODULE_NAME ("exdebug")
5126f3cdf0SGordon Ross
5226f3cdf0SGordon Ross
5326f3cdf0SGordon Ross #ifndef ACPI_NO_ERROR_MESSAGES
5426f3cdf0SGordon Ross /*******************************************************************************
5526f3cdf0SGordon Ross *
5626f3cdf0SGordon Ross * FUNCTION: AcpiExDoDebugObject
5726f3cdf0SGordon Ross *
5826f3cdf0SGordon Ross * PARAMETERS: SourceDesc - Object to be output to "Debug Object"
5926f3cdf0SGordon Ross * Level - Indentation level (used for packages)
6026f3cdf0SGordon Ross * Index - Current package element, zero if not pkg
6126f3cdf0SGordon Ross *
6226f3cdf0SGordon Ross * RETURN: None
6326f3cdf0SGordon Ross *
6426f3cdf0SGordon Ross * DESCRIPTION: Handles stores to the AML Debug Object. For example:
6526f3cdf0SGordon Ross * Store(INT1, Debug)
6626f3cdf0SGordon Ross *
6726f3cdf0SGordon Ross * This function is not compiled if ACPI_NO_ERROR_MESSAGES is set.
6826f3cdf0SGordon Ross *
6926f3cdf0SGordon Ross * This function is only enabled if AcpiGbl_EnableAmlDebugObject is set, or
7026f3cdf0SGordon Ross * if ACPI_LV_DEBUG_OBJECT is set in the AcpiDbgLevel. Thus, in the normal
7126f3cdf0SGordon Ross * operational case, stores to the debug object are ignored but can be easily
7226f3cdf0SGordon Ross * enabled if necessary.
7326f3cdf0SGordon Ross *
7426f3cdf0SGordon Ross ******************************************************************************/
7526f3cdf0SGordon Ross
7626f3cdf0SGordon Ross void
AcpiExDoDebugObject(ACPI_OPERAND_OBJECT * SourceDesc,UINT32 Level,UINT32 Index)7726f3cdf0SGordon Ross AcpiExDoDebugObject (
7826f3cdf0SGordon Ross ACPI_OPERAND_OBJECT *SourceDesc,
7926f3cdf0SGordon Ross UINT32 Level,
8026f3cdf0SGordon Ross UINT32 Index)
8126f3cdf0SGordon Ross {
8226f3cdf0SGordon Ross UINT32 i;
83*cb565728SJerry Jelinek UINT32 Timer;
84*cb565728SJerry Jelinek ACPI_OPERAND_OBJECT *ObjectDesc;
85*cb565728SJerry Jelinek UINT32 Value;
8626f3cdf0SGordon Ross
8726f3cdf0SGordon Ross
8826f3cdf0SGordon Ross ACPI_FUNCTION_TRACE_PTR (ExDoDebugObject, SourceDesc);
8926f3cdf0SGordon Ross
9026f3cdf0SGordon Ross
9126f3cdf0SGordon Ross /* Output must be enabled via the DebugObject global or the DbgLevel */
9226f3cdf0SGordon Ross
9326f3cdf0SGordon Ross if (!AcpiGbl_EnableAmlDebugObject &&
9426f3cdf0SGordon Ross !(AcpiDbgLevel & ACPI_LV_DEBUG_OBJECT))
9526f3cdf0SGordon Ross {
9626f3cdf0SGordon Ross return_VOID;
9726f3cdf0SGordon Ross }
9826f3cdf0SGordon Ross
99*cb565728SJerry Jelinek /* Null string or newline -- don't emit the line header */
100*cb565728SJerry Jelinek
101*cb565728SJerry Jelinek if (SourceDesc &&
102*cb565728SJerry Jelinek (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_OPERAND) &&
103*cb565728SJerry Jelinek (SourceDesc->Common.Type == ACPI_TYPE_STRING))
104*cb565728SJerry Jelinek {
105*cb565728SJerry Jelinek if ((SourceDesc->String.Length == 0) ||
106*cb565728SJerry Jelinek ((SourceDesc->String.Length == 1) &&
107*cb565728SJerry Jelinek (*SourceDesc->String.Pointer == '\n')))
108*cb565728SJerry Jelinek {
109*cb565728SJerry Jelinek AcpiOsPrintf ("\n");
110*cb565728SJerry Jelinek return_VOID;
111*cb565728SJerry Jelinek }
112*cb565728SJerry Jelinek }
113*cb565728SJerry Jelinek
11426f3cdf0SGordon Ross /*
11526f3cdf0SGordon Ross * Print line header as long as we are not in the middle of an
11626f3cdf0SGordon Ross * object display
11726f3cdf0SGordon Ross */
11826f3cdf0SGordon Ross if (!((Level > 0) && Index == 0))
11926f3cdf0SGordon Ross {
120*cb565728SJerry Jelinek if (AcpiGbl_DisplayDebugTimer)
121*cb565728SJerry Jelinek {
122*cb565728SJerry Jelinek /*
123*cb565728SJerry Jelinek * We will emit the current timer value (in microseconds) with each
124*cb565728SJerry Jelinek * debug output. Only need the lower 26 bits. This allows for 67
125*cb565728SJerry Jelinek * million microseconds or 67 seconds before rollover.
126*cb565728SJerry Jelinek *
127*cb565728SJerry Jelinek * Convert 100 nanosecond units to microseconds
128*cb565728SJerry Jelinek */
129*cb565728SJerry Jelinek Timer = ((UINT32) AcpiOsGetTimer () / 10);
130*cb565728SJerry Jelinek Timer &= 0x03FFFFFF;
131*cb565728SJerry Jelinek
132*cb565728SJerry Jelinek AcpiOsPrintf ("[ACPI Debug T=0x%8.8X] %*s", Timer, Level, " ");
133*cb565728SJerry Jelinek }
134*cb565728SJerry Jelinek else
135*cb565728SJerry Jelinek {
13626f3cdf0SGordon Ross AcpiOsPrintf ("[ACPI Debug] %*s", Level, " ");
13726f3cdf0SGordon Ross }
138*cb565728SJerry Jelinek }
13926f3cdf0SGordon Ross
14026f3cdf0SGordon Ross /* Display the index for package output only */
14126f3cdf0SGordon Ross
14226f3cdf0SGordon Ross if (Index > 0)
14326f3cdf0SGordon Ross {
14426f3cdf0SGordon Ross AcpiOsPrintf ("(%.2u) ", Index - 1);
14526f3cdf0SGordon Ross }
14626f3cdf0SGordon Ross
14726f3cdf0SGordon Ross if (!SourceDesc)
14826f3cdf0SGordon Ross {
14926f3cdf0SGordon Ross AcpiOsPrintf ("[Null Object]\n");
15026f3cdf0SGordon Ross return_VOID;
15126f3cdf0SGordon Ross }
15226f3cdf0SGordon Ross
15326f3cdf0SGordon Ross if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_OPERAND)
15426f3cdf0SGordon Ross {
155*cb565728SJerry Jelinek /* No object type prefix needed for integers and strings */
156*cb565728SJerry Jelinek
157*cb565728SJerry Jelinek if ((SourceDesc->Common.Type != ACPI_TYPE_INTEGER) &&
158*cb565728SJerry Jelinek (SourceDesc->Common.Type != ACPI_TYPE_STRING))
159*cb565728SJerry Jelinek {
16026f3cdf0SGordon Ross AcpiOsPrintf ("%s ", AcpiUtGetObjectTypeName (SourceDesc));
161*cb565728SJerry Jelinek }
16226f3cdf0SGordon Ross
16326f3cdf0SGordon Ross if (!AcpiUtValidInternalObject (SourceDesc))
16426f3cdf0SGordon Ross {
16526f3cdf0SGordon Ross AcpiOsPrintf ("%p, Invalid Internal Object!\n", SourceDesc);
16626f3cdf0SGordon Ross return_VOID;
16726f3cdf0SGordon Ross }
16826f3cdf0SGordon Ross }
16926f3cdf0SGordon Ross else if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc) == ACPI_DESC_TYPE_NAMED)
17026f3cdf0SGordon Ross {
171*cb565728SJerry Jelinek AcpiOsPrintf ("%s (Node %p)\n",
17226f3cdf0SGordon Ross AcpiUtGetTypeName (((ACPI_NAMESPACE_NODE *) SourceDesc)->Type),
17326f3cdf0SGordon Ross SourceDesc);
17426f3cdf0SGordon Ross return_VOID;
17526f3cdf0SGordon Ross }
17626f3cdf0SGordon Ross else
17726f3cdf0SGordon Ross {
17826f3cdf0SGordon Ross return_VOID;
17926f3cdf0SGordon Ross }
18026f3cdf0SGordon Ross
18126f3cdf0SGordon Ross /* SourceDesc is of type ACPI_DESC_TYPE_OPERAND */
18226f3cdf0SGordon Ross
18326f3cdf0SGordon Ross switch (SourceDesc->Common.Type)
18426f3cdf0SGordon Ross {
18526f3cdf0SGordon Ross case ACPI_TYPE_INTEGER:
18626f3cdf0SGordon Ross
18726f3cdf0SGordon Ross /* Output correct integer width */
18826f3cdf0SGordon Ross
18926f3cdf0SGordon Ross if (AcpiGbl_IntegerByteWidth == 4)
19026f3cdf0SGordon Ross {
19126f3cdf0SGordon Ross AcpiOsPrintf ("0x%8.8X\n",
19226f3cdf0SGordon Ross (UINT32) SourceDesc->Integer.Value);
19326f3cdf0SGordon Ross }
19426f3cdf0SGordon Ross else
19526f3cdf0SGordon Ross {
19626f3cdf0SGordon Ross AcpiOsPrintf ("0x%8.8X%8.8X\n",
19726f3cdf0SGordon Ross ACPI_FORMAT_UINT64 (SourceDesc->Integer.Value));
19826f3cdf0SGordon Ross }
19926f3cdf0SGordon Ross break;
20026f3cdf0SGordon Ross
20126f3cdf0SGordon Ross case ACPI_TYPE_BUFFER:
20226f3cdf0SGordon Ross
20326f3cdf0SGordon Ross AcpiOsPrintf ("[0x%.2X]\n", (UINT32) SourceDesc->Buffer.Length);
204*cb565728SJerry Jelinek AcpiUtDumpBuffer (SourceDesc->Buffer.Pointer,
20526f3cdf0SGordon Ross (SourceDesc->Buffer.Length < 256) ?
206*cb565728SJerry Jelinek SourceDesc->Buffer.Length : 256, DB_BYTE_DISPLAY, 0);
20726f3cdf0SGordon Ross break;
20826f3cdf0SGordon Ross
20926f3cdf0SGordon Ross case ACPI_TYPE_STRING:
21026f3cdf0SGordon Ross
211*cb565728SJerry Jelinek AcpiOsPrintf ("\"%s\"\n", SourceDesc->String.Pointer);
21226f3cdf0SGordon Ross break;
21326f3cdf0SGordon Ross
21426f3cdf0SGordon Ross case ACPI_TYPE_PACKAGE:
21526f3cdf0SGordon Ross
216*cb565728SJerry Jelinek AcpiOsPrintf ("(Contains 0x%.2X Elements):\n",
21726f3cdf0SGordon Ross SourceDesc->Package.Count);
21826f3cdf0SGordon Ross
21926f3cdf0SGordon Ross /* Output the entire contents of the package */
22026f3cdf0SGordon Ross
22126f3cdf0SGordon Ross for (i = 0; i < SourceDesc->Package.Count; i++)
22226f3cdf0SGordon Ross {
22326f3cdf0SGordon Ross AcpiExDoDebugObject (SourceDesc->Package.Elements[i],
22426f3cdf0SGordon Ross Level + 4, i + 1);
22526f3cdf0SGordon Ross }
22626f3cdf0SGordon Ross break;
22726f3cdf0SGordon Ross
22826f3cdf0SGordon Ross case ACPI_TYPE_LOCAL_REFERENCE:
22926f3cdf0SGordon Ross
23026f3cdf0SGordon Ross AcpiOsPrintf ("[%s] ", AcpiUtGetReferenceName (SourceDesc));
23126f3cdf0SGordon Ross
23226f3cdf0SGordon Ross /* Decode the reference */
23326f3cdf0SGordon Ross
23426f3cdf0SGordon Ross switch (SourceDesc->Reference.Class)
23526f3cdf0SGordon Ross {
23626f3cdf0SGordon Ross case ACPI_REFCLASS_INDEX:
23726f3cdf0SGordon Ross
23826f3cdf0SGordon Ross AcpiOsPrintf ("0x%X\n", SourceDesc->Reference.Value);
23926f3cdf0SGordon Ross break;
24026f3cdf0SGordon Ross
24126f3cdf0SGordon Ross case ACPI_REFCLASS_TABLE:
24226f3cdf0SGordon Ross
24326f3cdf0SGordon Ross /* Case for DdbHandle */
24426f3cdf0SGordon Ross
24526f3cdf0SGordon Ross AcpiOsPrintf ("Table Index 0x%X\n", SourceDesc->Reference.Value);
246*cb565728SJerry Jelinek return_VOID;
24726f3cdf0SGordon Ross
24826f3cdf0SGordon Ross default:
249*cb565728SJerry Jelinek
25026f3cdf0SGordon Ross break;
25126f3cdf0SGordon Ross }
25226f3cdf0SGordon Ross
25326f3cdf0SGordon Ross AcpiOsPrintf (" ");
25426f3cdf0SGordon Ross
25526f3cdf0SGordon Ross /* Check for valid node first, then valid object */
25626f3cdf0SGordon Ross
25726f3cdf0SGordon Ross if (SourceDesc->Reference.Node)
25826f3cdf0SGordon Ross {
25926f3cdf0SGordon Ross if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc->Reference.Node) !=
26026f3cdf0SGordon Ross ACPI_DESC_TYPE_NAMED)
26126f3cdf0SGordon Ross {
26226f3cdf0SGordon Ross AcpiOsPrintf (" %p - Not a valid namespace node\n",
26326f3cdf0SGordon Ross SourceDesc->Reference.Node);
26426f3cdf0SGordon Ross }
26526f3cdf0SGordon Ross else
26626f3cdf0SGordon Ross {
26726f3cdf0SGordon Ross AcpiOsPrintf ("Node %p [%4.4s] ", SourceDesc->Reference.Node,
26826f3cdf0SGordon Ross (SourceDesc->Reference.Node)->Name.Ascii);
26926f3cdf0SGordon Ross
27026f3cdf0SGordon Ross switch ((SourceDesc->Reference.Node)->Type)
27126f3cdf0SGordon Ross {
27226f3cdf0SGordon Ross /* These types have no attached object */
27326f3cdf0SGordon Ross
27426f3cdf0SGordon Ross case ACPI_TYPE_DEVICE:
27526f3cdf0SGordon Ross AcpiOsPrintf ("Device\n");
27626f3cdf0SGordon Ross break;
27726f3cdf0SGordon Ross
27826f3cdf0SGordon Ross case ACPI_TYPE_THERMAL:
27926f3cdf0SGordon Ross AcpiOsPrintf ("Thermal Zone\n");
28026f3cdf0SGordon Ross break;
28126f3cdf0SGordon Ross
28226f3cdf0SGordon Ross default:
283*cb565728SJerry Jelinek
28426f3cdf0SGordon Ross AcpiExDoDebugObject ((SourceDesc->Reference.Node)->Object,
28526f3cdf0SGordon Ross Level + 4, 0);
28626f3cdf0SGordon Ross break;
28726f3cdf0SGordon Ross }
28826f3cdf0SGordon Ross }
28926f3cdf0SGordon Ross }
29026f3cdf0SGordon Ross else if (SourceDesc->Reference.Object)
29126f3cdf0SGordon Ross {
29226f3cdf0SGordon Ross if (ACPI_GET_DESCRIPTOR_TYPE (SourceDesc->Reference.Object) ==
29326f3cdf0SGordon Ross ACPI_DESC_TYPE_NAMED)
29426f3cdf0SGordon Ross {
295*cb565728SJerry Jelinek /* Reference object is a namespace node */
296*cb565728SJerry Jelinek
297*cb565728SJerry Jelinek AcpiExDoDebugObject (ACPI_CAST_PTR (ACPI_OPERAND_OBJECT,
298*cb565728SJerry Jelinek SourceDesc->Reference.Object),
29926f3cdf0SGordon Ross Level + 4, 0);
30026f3cdf0SGordon Ross }
30126f3cdf0SGordon Ross else
30226f3cdf0SGordon Ross {
303*cb565728SJerry Jelinek ObjectDesc = SourceDesc->Reference.Object;
304*cb565728SJerry Jelinek Value = SourceDesc->Reference.Value;
305*cb565728SJerry Jelinek
306*cb565728SJerry Jelinek switch (ObjectDesc->Common.Type)
307*cb565728SJerry Jelinek {
308*cb565728SJerry Jelinek case ACPI_TYPE_BUFFER:
309*cb565728SJerry Jelinek
310*cb565728SJerry Jelinek AcpiOsPrintf ("Buffer[%u] = 0x%2.2X\n",
311*cb565728SJerry Jelinek Value, *SourceDesc->Reference.IndexPointer);
312*cb565728SJerry Jelinek break;
313*cb565728SJerry Jelinek
314*cb565728SJerry Jelinek case ACPI_TYPE_STRING:
315*cb565728SJerry Jelinek
316*cb565728SJerry Jelinek AcpiOsPrintf ("String[%u] = \"%c\" (0x%2.2X)\n",
317*cb565728SJerry Jelinek Value, *SourceDesc->Reference.IndexPointer,
318*cb565728SJerry Jelinek *SourceDesc->Reference.IndexPointer);
319*cb565728SJerry Jelinek break;
320*cb565728SJerry Jelinek
321*cb565728SJerry Jelinek case ACPI_TYPE_PACKAGE:
322*cb565728SJerry Jelinek
323*cb565728SJerry Jelinek AcpiOsPrintf ("Package[%u] = ", Value);
324*cb565728SJerry Jelinek if (!(*SourceDesc->Reference.Where))
325*cb565728SJerry Jelinek {
326*cb565728SJerry Jelinek AcpiOsPrintf ("[Uninitialized Package Element]\n");
327*cb565728SJerry Jelinek }
328*cb565728SJerry Jelinek else
329*cb565728SJerry Jelinek {
330*cb565728SJerry Jelinek AcpiExDoDebugObject (*SourceDesc->Reference.Where,
33126f3cdf0SGordon Ross Level+4, 0);
33226f3cdf0SGordon Ross }
333*cb565728SJerry Jelinek break;
334*cb565728SJerry Jelinek
335*cb565728SJerry Jelinek default:
336*cb565728SJerry Jelinek
337*cb565728SJerry Jelinek AcpiOsPrintf ("Unknown Reference object type %X\n",
338*cb565728SJerry Jelinek ObjectDesc->Common.Type);
339*cb565728SJerry Jelinek break;
340*cb565728SJerry Jelinek }
341*cb565728SJerry Jelinek }
34226f3cdf0SGordon Ross }
34326f3cdf0SGordon Ross break;
34426f3cdf0SGordon Ross
34526f3cdf0SGordon Ross default:
34626f3cdf0SGordon Ross
347*cb565728SJerry Jelinek AcpiOsPrintf ("(Descriptor %p)\n", SourceDesc);
34826f3cdf0SGordon Ross break;
34926f3cdf0SGordon Ross }
35026f3cdf0SGordon Ross
35126f3cdf0SGordon Ross ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC, "\n"));
35226f3cdf0SGordon Ross return_VOID;
35326f3cdf0SGordon Ross }
35426f3cdf0SGordon Ross #endif
355