ACPICA: Executer: Add interpreter tracing mode for method tracing facility
[deliverable/linux.git] / drivers / acpi / acpica / exdebug.c
CommitLineData
4cdf1a56
LM
1/******************************************************************************
2 *
3 * Module Name: exdebug - Support for stores to the AML Debug Object
4 *
5 *****************************************************************************/
6
7/*
82a80941 8 * Copyright (C) 2000 - 2015, Intel Corp.
4cdf1a56
LM
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"
ab6c5733 46#include "acnamesp.h"
4cdf1a56 47#include "acinterp.h"
ab6c5733 48#include "acparser.h"
4cdf1a56
LM
49
50#define _COMPONENT ACPI_EXECUTER
51ACPI_MODULE_NAME("exdebug")
52
ab6c5733
LZ
53static union acpi_operand_object *acpi_gbl_trace_method_object = NULL;
54
4cdf1a56
LM
55#ifndef ACPI_NO_ERROR_MESSAGES
56/*******************************************************************************
57 *
58 * FUNCTION: acpi_ex_do_debug_object
59 *
60 * PARAMETERS: source_desc - Object to be output to "Debug Object"
ba494bee
BM
61 * level - Indentation level (used for packages)
62 * index - Current package element, zero if not pkg
4cdf1a56
LM
63 *
64 * RETURN: None
65 *
66 * DESCRIPTION: Handles stores to the AML Debug Object. For example:
67 * Store(INT1, Debug)
68 *
69 * This function is not compiled if ACPI_NO_ERROR_MESSAGES is set.
70 *
71 * This function is only enabled if acpi_gbl_enable_aml_debug_object is set, or
72 * if ACPI_LV_DEBUG_OBJECT is set in the acpi_dbg_level. Thus, in the normal
73 * operational case, stores to the debug object are ignored but can be easily
74 * enabled if necessary.
75 *
76 ******************************************************************************/
ab6c5733 77
4cdf1a56
LM
78void
79acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
80 u32 level, u32 index)
81{
82 u32 i;
1aae3b97 83 u32 timer;
fde175e3
BM
84 union acpi_operand_object *object_desc;
85 u32 value;
4cdf1a56
LM
86
87 ACPI_FUNCTION_TRACE_PTR(ex_do_debug_object, source_desc);
88
89 /* Output must be enabled via the debug_object global or the dbg_level */
90
91 if (!acpi_gbl_enable_aml_debug_object &&
92 !(acpi_dbg_level & ACPI_LV_DEBUG_OBJECT)) {
93 return_VOID;
94 }
95
1aae3b97
BM
96 /*
97 * We will emit the current timer value (in microseconds) with each
98 * debug output. Only need the lower 26 bits. This allows for 67
99 * million microseconds or 67 seconds before rollover.
100 */
101 timer = ((u32)acpi_os_get_timer() / 10); /* (100 nanoseconds to microseconds) */
102 timer &= 0x03FFFFFF;
103
4cdf1a56
LM
104 /*
105 * Print line header as long as we are not in the middle of an
106 * object display
107 */
108 if (!((level > 0) && index == 0)) {
1aae3b97 109 acpi_os_printf("[ACPI Debug %.8u] %*s", timer, level, " ");
4cdf1a56
LM
110 }
111
112 /* Display the index for package output only */
113
114 if (index > 0) {
115 acpi_os_printf("(%.2u) ", index - 1);
116 }
117
118 if (!source_desc) {
119 acpi_os_printf("[Null Object]\n");
120 return_VOID;
121 }
122
123 if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) == ACPI_DESC_TYPE_OPERAND) {
124 acpi_os_printf("%s ",
125 acpi_ut_get_object_type_name(source_desc));
126
127 if (!acpi_ut_valid_internal_object(source_desc)) {
128 acpi_os_printf("%p, Invalid Internal Object!\n",
129 source_desc);
130 return_VOID;
131 }
132 } else if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) ==
133 ACPI_DESC_TYPE_NAMED) {
134 acpi_os_printf("%s: %p\n",
135 acpi_ut_get_type_name(((struct
136 acpi_namespace_node *)
137 source_desc)->type),
138 source_desc);
139 return_VOID;
140 } else {
141 return_VOID;
142 }
143
144 /* source_desc is of type ACPI_DESC_TYPE_OPERAND */
145
146 switch (source_desc->common.type) {
147 case ACPI_TYPE_INTEGER:
148
149 /* Output correct integer width */
150
151 if (acpi_gbl_integer_byte_width == 4) {
152 acpi_os_printf("0x%8.8X\n",
153 (u32)source_desc->integer.value);
154 } else {
155 acpi_os_printf("0x%8.8X%8.8X\n",
156 ACPI_FORMAT_UINT64(source_desc->integer.
157 value));
158 }
159 break;
160
161 case ACPI_TYPE_BUFFER:
162
163 acpi_os_printf("[0x%.2X]\n", (u32)source_desc->buffer.length);
97171c6b
BM
164 acpi_ut_dump_buffer(source_desc->buffer.pointer,
165 (source_desc->buffer.length < 256) ?
166 source_desc->buffer.length : 256,
167 DB_BYTE_DISPLAY, 0);
4cdf1a56
LM
168 break;
169
170 case ACPI_TYPE_STRING:
171
172 acpi_os_printf("[0x%.2X] \"%s\"\n",
173 source_desc->string.length,
174 source_desc->string.pointer);
175 break;
176
177 case ACPI_TYPE_PACKAGE:
178
179 acpi_os_printf("[Contains 0x%.2X Elements]\n",
180 source_desc->package.count);
181
182 /* Output the entire contents of the package */
183
184 for (i = 0; i < source_desc->package.count; i++) {
185 acpi_ex_do_debug_object(source_desc->package.
186 elements[i], level + 4, i + 1);
187 }
188 break;
189
190 case ACPI_TYPE_LOCAL_REFERENCE:
191
192 acpi_os_printf("[%s] ",
193 acpi_ut_get_reference_name(source_desc));
194
195 /* Decode the reference */
196
197 switch (source_desc->reference.class) {
198 case ACPI_REFCLASS_INDEX:
199
200 acpi_os_printf("0x%X\n", source_desc->reference.value);
201 break;
202
203 case ACPI_REFCLASS_TABLE:
204
205 /* Case for ddb_handle */
206
207 acpi_os_printf("Table Index 0x%X\n",
208 source_desc->reference.value);
68aafc35 209 return_VOID;
4cdf1a56
LM
210
211 default:
1d1ea1b7 212
4cdf1a56
LM
213 break;
214 }
215
216 acpi_os_printf(" ");
217
218 /* Check for valid node first, then valid object */
219
220 if (source_desc->reference.node) {
221 if (ACPI_GET_DESCRIPTOR_TYPE
222 (source_desc->reference.node) !=
223 ACPI_DESC_TYPE_NAMED) {
224 acpi_os_printf
225 (" %p - Not a valid namespace node\n",
226 source_desc->reference.node);
227 } else {
228 acpi_os_printf("Node %p [%4.4s] ",
229 source_desc->reference.node,
230 (source_desc->reference.node)->
231 name.ascii);
232
233 switch ((source_desc->reference.node)->type) {
234
235 /* These types have no attached object */
236
237 case ACPI_TYPE_DEVICE:
238 acpi_os_printf("Device\n");
239 break;
240
241 case ACPI_TYPE_THERMAL:
242 acpi_os_printf("Thermal Zone\n");
243 break;
244
245 default:
1d1ea1b7 246
4cdf1a56
LM
247 acpi_ex_do_debug_object((source_desc->
248 reference.
249 node)->object,
250 level + 4, 0);
251 break;
252 }
253 }
254 } else if (source_desc->reference.object) {
255 if (ACPI_GET_DESCRIPTOR_TYPE
256 (source_desc->reference.object) ==
257 ACPI_DESC_TYPE_NAMED) {
258 acpi_ex_do_debug_object(((struct
259 acpi_namespace_node *)
260 source_desc->reference.
261 object)->object,
262 level + 4, 0);
263 } else {
fde175e3
BM
264 object_desc = source_desc->reference.object;
265 value = source_desc->reference.value;
266
267 switch (object_desc->common.type) {
268 case ACPI_TYPE_BUFFER:
269
270 acpi_os_printf("Buffer[%u] = 0x%2.2X\n",
271 value,
272 *source_desc->reference.
273 index_pointer);
274 break;
275
276 case ACPI_TYPE_STRING:
277
278 acpi_os_printf
279 ("String[%u] = \"%c\" (0x%2.2X)\n",
280 value,
281 *source_desc->reference.
282 index_pointer,
283 *source_desc->reference.
284 index_pointer);
285 break;
286
287 case ACPI_TYPE_PACKAGE:
288
289 acpi_os_printf("Package[%u] = ", value);
290 acpi_ex_do_debug_object(*source_desc->
291 reference.where,
292 level + 4, 0);
293 break;
294
295 default:
296
297 acpi_os_printf
298 ("Unknown Reference object type %X\n",
299 object_desc->common.type);
300 break;
301 }
4cdf1a56
LM
302 }
303 }
304 break;
305
306 default:
307
308 acpi_os_printf("%p\n", source_desc);
309 break;
310 }
311
312 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "\n"));
313 return_VOID;
314}
315#endif
ab6c5733
LZ
316
317/*******************************************************************************
318 *
319 * FUNCTION: acpi_ex_interpreter_trace_enabled
320 *
321 * PARAMETERS: name - Whether method name should be matched,
322 * this should be checked before starting
323 * the tracer
324 *
325 * RETURN: TRUE if interpreter trace is enabled.
326 *
327 * DESCRIPTION: Check whether interpreter trace is enabled
328 *
329 ******************************************************************************/
330
331static u8 acpi_ex_interpreter_trace_enabled(char *name)
332{
333
334 /* Check if tracing is enabled */
335
336 if (!(acpi_gbl_trace_flags & ACPI_TRACE_ENABLED)) {
337 return (FALSE);
338 }
339
340 /*
341 * Check if tracing is filtered:
342 *
343 * 1. If the tracer is started, acpi_gbl_trace_method_object should have
344 * been filled by the trace starter
345 * 2. If the tracer is not started, acpi_gbl_trace_method_name should be
346 * matched if it is specified
347 * 3. If the tracer is oneshot style, acpi_gbl_trace_method_name should
348 * not be cleared by the trace stopper during the first match
349 */
350 if (acpi_gbl_trace_method_object) {
351 return (TRUE);
352 }
353 if (name &&
354 (acpi_gbl_trace_method_name &&
355 strcmp(acpi_gbl_trace_method_name, name))) {
356 return (FALSE);
357 }
358 if ((acpi_gbl_trace_flags & ACPI_TRACE_ONESHOT) &&
359 !acpi_gbl_trace_method_name) {
360 return (FALSE);
361 }
362
363 return (TRUE);
364}
365
366/*******************************************************************************
367 *
368 * FUNCTION: acpi_ex_start_trace_method
369 *
370 * PARAMETERS: method_node - Node of the method
371 * obj_desc - The method object
372 * walk_state - current state, NULL if not yet executing
373 * a method.
374 *
375 * RETURN: None
376 *
377 * DESCRIPTION: Start control method execution trace
378 *
379 ******************************************************************************/
380
381void
382acpi_ex_start_trace_method(struct acpi_namespace_node *method_node,
383 union acpi_operand_object *obj_desc,
384 struct acpi_walk_state *walk_state)
385{
386 acpi_status status;
387 char *pathname = NULL;
388 u8 enabled = FALSE;
389
390 ACPI_FUNCTION_NAME(ex_start_trace_method);
391
392 if (method_node) {
393 pathname = acpi_ns_get_normalized_pathname(method_node, TRUE);
394 }
395
396 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
397 if (ACPI_FAILURE(status)) {
398 goto exit;
399 }
400
401 enabled = acpi_ex_interpreter_trace_enabled(pathname);
402 if (enabled && !acpi_gbl_trace_method_object) {
403 acpi_gbl_trace_method_object = obj_desc;
404 acpi_gbl_original_dbg_level = acpi_dbg_level;
405 acpi_gbl_original_dbg_layer = acpi_dbg_layer;
406 acpi_dbg_level = ACPI_TRACE_LEVEL_ALL;
407 acpi_dbg_layer = ACPI_TRACE_LAYER_ALL;
408
409 if (acpi_gbl_trace_dbg_level) {
410 acpi_dbg_level = acpi_gbl_trace_dbg_level;
411 }
412 if (acpi_gbl_trace_dbg_layer) {
413 acpi_dbg_layer = acpi_gbl_trace_dbg_layer;
414 }
415 }
416 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
417
418exit:
419 if (enabled) {
420 if (pathname) {
421 ACPI_DEBUG_PRINT((ACPI_DB_TRACE_POINT,
422 "Begin method [0x%p:%s] execution.\n",
423 obj_desc->method.aml_start,
424 pathname));
425 } else {
426 ACPI_DEBUG_PRINT((ACPI_DB_TRACE_POINT,
427 "Begin method [0x%p] execution.\n",
428 obj_desc->method.aml_start));
429 }
430 }
431 if (pathname) {
432 ACPI_FREE(pathname);
433 }
434}
435
436/*******************************************************************************
437 *
438 * FUNCTION: acpi_ex_stop_trace_method
439 *
440 * PARAMETERS: method_node - Node of the method
441 * obj_desc - The method object
442 * walk_state - current state, NULL if not yet executing
443 * a method.
444 *
445 * RETURN: None
446 *
447 * DESCRIPTION: Stop control method execution trace
448 *
449 ******************************************************************************/
450
451void
452acpi_ex_stop_trace_method(struct acpi_namespace_node *method_node,
453 union acpi_operand_object *obj_desc,
454 struct acpi_walk_state *walk_state)
455{
456 acpi_status status;
457 char *pathname = NULL;
458 u8 enabled;
459
460 ACPI_FUNCTION_NAME(ex_stop_trace_method);
461
462 if (method_node) {
463 pathname = acpi_ns_get_normalized_pathname(method_node, TRUE);
464 }
465
466 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
467 if (ACPI_FAILURE(status)) {
468 goto exit_path;
469 }
470
471 enabled = acpi_ex_interpreter_trace_enabled(NULL);
472
473 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
474
475 if (enabled) {
476 if (pathname) {
477 ACPI_DEBUG_PRINT((ACPI_DB_TRACE_POINT,
478 "End method [0x%p:%s] execution.\n",
479 obj_desc->method.aml_start,
480 pathname));
481 } else {
482 ACPI_DEBUG_PRINT((ACPI_DB_TRACE_POINT,
483 "End method [0x%p] execution.\n",
484 obj_desc->method.aml_start));
485 }
486 }
487
488 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
489 if (ACPI_FAILURE(status)) {
490 goto exit_path;
491 }
492
493 /* Check whether the tracer should be stopped */
494
495 if (acpi_gbl_trace_method_object == obj_desc) {
496
497 /* Disable further tracing if type is one-shot */
498
499 if (acpi_gbl_trace_flags & ACPI_TRACE_ONESHOT) {
500 acpi_gbl_trace_method_name = NULL;
501 }
502
503 acpi_dbg_level = acpi_gbl_original_dbg_level;
504 acpi_dbg_layer = acpi_gbl_original_dbg_layer;
505 acpi_gbl_trace_method_object = NULL;
506 }
507
508 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
509
510exit_path:
511 if (pathname) {
512 ACPI_FREE(pathname);
513 }
514}
515
516/*******************************************************************************
517 *
518 * FUNCTION: acpi_ex_start_trace_opcode
519 *
520 * PARAMETERS: op - The parser opcode object
521 * walk_state - current state, NULL if not yet executing
522 * a method.
523 *
524 * RETURN: None
525 *
526 * DESCRIPTION: Start opcode execution trace
527 *
528 ******************************************************************************/
529
530void
531acpi_ex_start_trace_opcode(union acpi_parse_object *op,
532 struct acpi_walk_state *walk_state)
533{
534
535 ACPI_FUNCTION_NAME(ex_start_trace_opcode);
536
537 if (acpi_ex_interpreter_trace_enabled(NULL)) {
538 if (walk_state->op_info) {
539 ACPI_DEBUG_PRINT((ACPI_DB_TRACE_POINT,
540 "Begin opcode: %s[0x%p] Class=0x%02x, Type=0x%02x, Flags=0x%04x.\n",
541 op->common.aml_op_name,
542 op->common.aml,
543 walk_state->op_info->class,
544 walk_state->op_info->type,
545 walk_state->op_info->flags));
546 } else {
547 ACPI_DEBUG_PRINT((ACPI_DB_TRACE_POINT,
548 "Begin opcode: %s[0x%p].\n",
549 op->common.aml_op_name,
550 op->common.aml));
551 }
552 }
553}
554
555/*******************************************************************************
556 *
557 * FUNCTION: acpi_ex_stop_trace_opcode
558 *
559 * PARAMETERS: op - The parser opcode object
560 * walk_state - current state, NULL if not yet executing
561 * a method.
562 *
563 * RETURN: None
564 *
565 * DESCRIPTION: Stop opcode execution trace
566 *
567 ******************************************************************************/
568
569void
570acpi_ex_stop_trace_opcode(union acpi_parse_object *op,
571 struct acpi_walk_state *walk_state)
572{
573
574 ACPI_FUNCTION_NAME(ex_stop_trace_opcode);
575
576 if (acpi_ex_interpreter_trace_enabled(NULL)) {
577 ACPI_DEBUG_PRINT((ACPI_DB_TRACE_POINT,
578 "End opcode: %s[0x%p].\n",
579 op->common.aml_op_name, op->common.aml));
580 }
581}
This page took 0.292846 seconds and 5 git commands to generate.