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