1 /******************************************************************************
3 * Module Name: exdebug - Support for stores to the AML Debug Object
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #include <acpi/acpi.h>
50 #define _COMPONENT ACPI_EXECUTER
51 ACPI_MODULE_NAME("exdebug")
53 static union acpi_operand_object *acpi_gbl_trace_method_object = NULL;
55 /* Local prototypes */
57 #ifdef ACPI_DEBUG_OUTPUT
58 static const char *acpi_ex_get_trace_event_name(acpi_trace_event_type type);
61 #ifndef ACPI_NO_ERROR_MESSAGES
62 /*******************************************************************************
64 * FUNCTION: acpi_ex_do_debug_object
66 * PARAMETERS: source_desc - Object to be output to "Debug Object"
67 * level - Indentation level (used for packages)
68 * index - Current package element, zero if not pkg
72 * DESCRIPTION: Handles stores to the AML Debug Object. For example:
75 * This function is not compiled if ACPI_NO_ERROR_MESSAGES is set.
77 * This function is only enabled if acpi_gbl_enable_aml_debug_object is set, or
78 * if ACPI_LV_DEBUG_OBJECT is set in the acpi_dbg_level. Thus, in the normal
79 * operational case, stores to the debug object are ignored but can be easily
80 * enabled if necessary.
82 ******************************************************************************/
85 acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
90 union acpi_operand_object *object_desc;
93 ACPI_FUNCTION_TRACE_PTR(ex_do_debug_object, source_desc);
95 /* Output must be enabled via the debug_object global or the dbg_level */
97 if (!acpi_gbl_enable_aml_debug_object &&
98 !(acpi_dbg_level & ACPI_LV_DEBUG_OBJECT)) {
103 * We will emit the current timer value (in microseconds) with each
104 * debug output. Only need the lower 26 bits. This allows for 67
105 * million microseconds or 67 seconds before rollover.
107 timer = ((u32)acpi_os_get_timer() / 10); /* (100 nanoseconds to microseconds) */
111 * Print line header as long as we are not in the middle of an
114 if (!((level > 0) && index == 0)) {
115 acpi_os_printf("[ACPI Debug %.8u] %*s", timer, level, " ");
118 /* Display the index for package output only */
121 acpi_os_printf("(%.2u) ", index - 1);
125 acpi_os_printf("[Null Object]\n");
129 if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) == ACPI_DESC_TYPE_OPERAND) {
130 acpi_os_printf("%s ",
131 acpi_ut_get_object_type_name(source_desc));
133 if (!acpi_ut_valid_internal_object(source_desc)) {
134 acpi_os_printf("%p, Invalid Internal Object!\n",
138 } else if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) ==
139 ACPI_DESC_TYPE_NAMED) {
140 acpi_os_printf("%s: %p\n",
141 acpi_ut_get_type_name(((struct
142 acpi_namespace_node *)
150 /* source_desc is of type ACPI_DESC_TYPE_OPERAND */
152 switch (source_desc->common.type) {
153 case ACPI_TYPE_INTEGER:
155 /* Output correct integer width */
157 if (acpi_gbl_integer_byte_width == 4) {
158 acpi_os_printf("0x%8.8X\n",
159 (u32)source_desc->integer.value);
161 acpi_os_printf("0x%8.8X%8.8X\n",
162 ACPI_FORMAT_UINT64(source_desc->integer.
167 case ACPI_TYPE_BUFFER:
169 acpi_os_printf("[0x%.2X]\n", (u32)source_desc->buffer.length);
170 acpi_ut_dump_buffer(source_desc->buffer.pointer,
171 (source_desc->buffer.length < 256) ?
172 source_desc->buffer.length : 256,
176 case ACPI_TYPE_STRING:
178 acpi_os_printf("[0x%.2X] \"%s\"\n",
179 source_desc->string.length,
180 source_desc->string.pointer);
183 case ACPI_TYPE_PACKAGE:
185 acpi_os_printf("[Contains 0x%.2X Elements]\n",
186 source_desc->package.count);
188 /* Output the entire contents of the package */
190 for (i = 0; i < source_desc->package.count; i++) {
191 acpi_ex_do_debug_object(source_desc->package.
192 elements[i], level + 4, i + 1);
196 case ACPI_TYPE_LOCAL_REFERENCE:
198 acpi_os_printf("[%s] ",
199 acpi_ut_get_reference_name(source_desc));
201 /* Decode the reference */
203 switch (source_desc->reference.class) {
204 case ACPI_REFCLASS_INDEX:
206 acpi_os_printf("0x%X\n", source_desc->reference.value);
209 case ACPI_REFCLASS_TABLE:
211 /* Case for ddb_handle */
213 acpi_os_printf("Table Index 0x%X\n",
214 source_desc->reference.value);
224 /* Check for valid node first, then valid object */
226 if (source_desc->reference.node) {
227 if (ACPI_GET_DESCRIPTOR_TYPE
228 (source_desc->reference.node) !=
229 ACPI_DESC_TYPE_NAMED) {
231 (" %p - Not a valid namespace node\n",
232 source_desc->reference.node);
234 acpi_os_printf("Node %p [%4.4s] ",
235 source_desc->reference.node,
236 (source_desc->reference.node)->
239 switch ((source_desc->reference.node)->type) {
241 /* These types have no attached object */
243 case ACPI_TYPE_DEVICE:
244 acpi_os_printf("Device\n");
247 case ACPI_TYPE_THERMAL:
248 acpi_os_printf("Thermal Zone\n");
253 acpi_ex_do_debug_object((source_desc->
260 } else if (source_desc->reference.object) {
261 if (ACPI_GET_DESCRIPTOR_TYPE
262 (source_desc->reference.object) ==
263 ACPI_DESC_TYPE_NAMED) {
264 acpi_ex_do_debug_object(((struct
265 acpi_namespace_node *)
266 source_desc->reference.
270 object_desc = source_desc->reference.object;
271 value = source_desc->reference.value;
273 switch (object_desc->common.type) {
274 case ACPI_TYPE_BUFFER:
276 acpi_os_printf("Buffer[%u] = 0x%2.2X\n",
278 *source_desc->reference.
282 case ACPI_TYPE_STRING:
285 ("String[%u] = \"%c\" (0x%2.2X)\n",
287 *source_desc->reference.
289 *source_desc->reference.
293 case ACPI_TYPE_PACKAGE:
295 acpi_os_printf("Package[%u] = ", value);
296 acpi_ex_do_debug_object(*source_desc->
304 ("Unknown Reference object type %X\n",
305 object_desc->common.type);
314 acpi_os_printf("%p\n", source_desc);
318 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "\n"));
323 /*******************************************************************************
325 * FUNCTION: acpi_ex_interpreter_trace_enabled
327 * PARAMETERS: name - Whether method name should be matched,
328 * this should be checked before starting
331 * RETURN: TRUE if interpreter trace is enabled.
333 * DESCRIPTION: Check whether interpreter trace is enabled
335 ******************************************************************************/
337 static u8 acpi_ex_interpreter_trace_enabled(char *name)
340 /* Check if tracing is enabled */
342 if (!(acpi_gbl_trace_flags & ACPI_TRACE_ENABLED)) {
347 * Check if tracing is filtered:
349 * 1. If the tracer is started, acpi_gbl_trace_method_object should have
350 * been filled by the trace starter
351 * 2. If the tracer is not started, acpi_gbl_trace_method_name should be
352 * matched if it is specified
353 * 3. If the tracer is oneshot style, acpi_gbl_trace_method_name should
354 * not be cleared by the trace stopper during the first match
356 if (acpi_gbl_trace_method_object) {
360 (acpi_gbl_trace_method_name &&
361 strcmp(acpi_gbl_trace_method_name, name))) {
364 if ((acpi_gbl_trace_flags & ACPI_TRACE_ONESHOT) &&
365 !acpi_gbl_trace_method_name) {
372 /*******************************************************************************
374 * FUNCTION: acpi_ex_get_trace_event_name
376 * PARAMETERS: type - Trace event type
378 * RETURN: Trace event name.
380 * DESCRIPTION: Used to obtain the full trace event name.
382 ******************************************************************************/
384 #ifdef ACPI_DEBUG_OUTPUT
386 static const char *acpi_ex_get_trace_event_name(acpi_trace_event_type type)
389 case ACPI_TRACE_AML_METHOD:
393 case ACPI_TRACE_AML_OPCODE:
397 case ACPI_TRACE_AML_REGION:
409 /*******************************************************************************
411 * FUNCTION: acpi_ex_trace_point
413 * PARAMETERS: type - Trace event type
414 * begin - TRUE if before execution
415 * aml - Executed AML address
416 * pathname - Object path
420 * DESCRIPTION: Internal interpreter execution trace.
422 ******************************************************************************/
425 acpi_ex_trace_point(acpi_trace_event_type type,
426 u8 begin, u8 *aml, char *pathname)
429 ACPI_FUNCTION_NAME(ex_trace_point);
432 ACPI_DEBUG_PRINT((ACPI_DB_TRACE_POINT,
433 "%s %s [0x%p:%s] execution.\n",
434 acpi_ex_get_trace_event_name(type),
435 begin ? "Begin" : "End", aml, pathname));
437 ACPI_DEBUG_PRINT((ACPI_DB_TRACE_POINT,
438 "%s %s [0x%p] execution.\n",
439 acpi_ex_get_trace_event_name(type),
440 begin ? "Begin" : "End", aml));
444 /*******************************************************************************
446 * FUNCTION: acpi_ex_start_trace_method
448 * PARAMETERS: method_node - Node of the method
449 * obj_desc - The method object
450 * walk_state - current state, NULL if not yet executing
455 * DESCRIPTION: Start control method execution trace
457 ******************************************************************************/
460 acpi_ex_start_trace_method(struct acpi_namespace_node *method_node,
461 union acpi_operand_object *obj_desc,
462 struct acpi_walk_state *walk_state)
465 char *pathname = NULL;
468 ACPI_FUNCTION_NAME(ex_start_trace_method);
471 pathname = acpi_ns_get_normalized_pathname(method_node, TRUE);
474 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
475 if (ACPI_FAILURE(status)) {
479 enabled = acpi_ex_interpreter_trace_enabled(pathname);
480 if (enabled && !acpi_gbl_trace_method_object) {
481 acpi_gbl_trace_method_object = obj_desc;
482 acpi_gbl_original_dbg_level = acpi_dbg_level;
483 acpi_gbl_original_dbg_layer = acpi_dbg_layer;
484 acpi_dbg_level = ACPI_TRACE_LEVEL_ALL;
485 acpi_dbg_layer = ACPI_TRACE_LAYER_ALL;
487 if (acpi_gbl_trace_dbg_level) {
488 acpi_dbg_level = acpi_gbl_trace_dbg_level;
490 if (acpi_gbl_trace_dbg_layer) {
491 acpi_dbg_layer = acpi_gbl_trace_dbg_layer;
494 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
498 ACPI_TRACE_POINT(ACPI_TRACE_AML_METHOD, TRUE,
499 obj_desc ? obj_desc->method.aml_start : NULL,
507 /*******************************************************************************
509 * FUNCTION: acpi_ex_stop_trace_method
511 * PARAMETERS: method_node - Node of the method
512 * obj_desc - The method object
513 * walk_state - current state, NULL if not yet executing
518 * DESCRIPTION: Stop control method execution trace
520 ******************************************************************************/
523 acpi_ex_stop_trace_method(struct acpi_namespace_node *method_node,
524 union acpi_operand_object *obj_desc,
525 struct acpi_walk_state *walk_state)
528 char *pathname = NULL;
531 ACPI_FUNCTION_NAME(ex_stop_trace_method);
534 pathname = acpi_ns_get_normalized_pathname(method_node, TRUE);
537 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
538 if (ACPI_FAILURE(status)) {
542 enabled = acpi_ex_interpreter_trace_enabled(NULL);
544 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
547 ACPI_TRACE_POINT(ACPI_TRACE_AML_METHOD, FALSE,
548 obj_desc ? obj_desc->method.aml_start : NULL,
552 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
553 if (ACPI_FAILURE(status)) {
557 /* Check whether the tracer should be stopped */
559 if (acpi_gbl_trace_method_object == obj_desc) {
561 /* Disable further tracing if type is one-shot */
563 if (acpi_gbl_trace_flags & ACPI_TRACE_ONESHOT) {
564 acpi_gbl_trace_method_name = NULL;
567 acpi_dbg_level = acpi_gbl_original_dbg_level;
568 acpi_dbg_layer = acpi_gbl_original_dbg_layer;
569 acpi_gbl_trace_method_object = NULL;
572 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
580 /*******************************************************************************
582 * FUNCTION: acpi_ex_start_trace_opcode
584 * PARAMETERS: op - The parser opcode object
585 * walk_state - current state, NULL if not yet executing
590 * DESCRIPTION: Start opcode execution trace
592 ******************************************************************************/
595 acpi_ex_start_trace_opcode(union acpi_parse_object *op,
596 struct acpi_walk_state *walk_state)
599 ACPI_FUNCTION_NAME(ex_start_trace_opcode);
601 if (acpi_ex_interpreter_trace_enabled(NULL)) {
602 ACPI_TRACE_POINT(ACPI_TRACE_AML_OPCODE, TRUE,
603 op->common.aml, op->common.aml_op_name);
607 /*******************************************************************************
609 * FUNCTION: acpi_ex_stop_trace_opcode
611 * PARAMETERS: op - The parser opcode object
612 * walk_state - current state, NULL if not yet executing
617 * DESCRIPTION: Stop opcode execution trace
619 ******************************************************************************/
622 acpi_ex_stop_trace_opcode(union acpi_parse_object *op,
623 struct acpi_walk_state *walk_state)
626 ACPI_FUNCTION_NAME(ex_stop_trace_opcode);
628 if (acpi_ex_interpreter_trace_enabled(NULL)) {
629 ACPI_TRACE_POINT(ACPI_TRACE_AML_OPCODE, FALSE,
630 op->common.aml, op->common.aml_op_name);