1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: extrace - Support for interpreter execution tracing
6 * Copyright (C) 2000 - 2020, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
15 #define _COMPONENT ACPI_EXECUTER
16 ACPI_MODULE_NAME("extrace")
18 static union acpi_operand_object
*acpi_gbl_trace_method_object
= NULL
;
20 /* Local prototypes */
22 #ifdef ACPI_DEBUG_OUTPUT
23 static const char *acpi_ex_get_trace_event_name(acpi_trace_event_type type
);
26 /*******************************************************************************
28 * FUNCTION: acpi_ex_interpreter_trace_enabled
30 * PARAMETERS: name - Whether method name should be matched,
31 * this should be checked before starting
34 * RETURN: TRUE if interpreter trace is enabled.
36 * DESCRIPTION: Check whether interpreter trace is enabled
38 ******************************************************************************/
40 static u8
acpi_ex_interpreter_trace_enabled(char *name
)
43 /* Check if tracing is enabled */
45 if (!(acpi_gbl_trace_flags
& ACPI_TRACE_ENABLED
)) {
50 * Check if tracing is filtered:
52 * 1. If the tracer is started, acpi_gbl_trace_method_object should have
53 * been filled by the trace starter
54 * 2. If the tracer is not started, acpi_gbl_trace_method_name should be
55 * matched if it is specified
56 * 3. If the tracer is oneshot style, acpi_gbl_trace_method_name should
57 * not be cleared by the trace stopper during the first match
59 if (acpi_gbl_trace_method_object
) {
64 (acpi_gbl_trace_method_name
&&
65 strcmp(acpi_gbl_trace_method_name
, name
))) {
69 if ((acpi_gbl_trace_flags
& ACPI_TRACE_ONESHOT
) &&
70 !acpi_gbl_trace_method_name
) {
77 /*******************************************************************************
79 * FUNCTION: acpi_ex_get_trace_event_name
81 * PARAMETERS: type - Trace event type
83 * RETURN: Trace event name.
85 * DESCRIPTION: Used to obtain the full trace event name.
87 ******************************************************************************/
89 #ifdef ACPI_DEBUG_OUTPUT
91 static const char *acpi_ex_get_trace_event_name(acpi_trace_event_type type
)
95 case ACPI_TRACE_AML_METHOD
:
99 case ACPI_TRACE_AML_OPCODE
:
103 case ACPI_TRACE_AML_REGION
:
115 /*******************************************************************************
117 * FUNCTION: acpi_ex_trace_point
119 * PARAMETERS: type - Trace event type
120 * begin - TRUE if before execution
121 * aml - Executed AML address
122 * pathname - Object path
126 * DESCRIPTION: Internal interpreter execution trace.
128 ******************************************************************************/
131 acpi_ex_trace_point(acpi_trace_event_type type
,
132 u8 begin
, u8
*aml
, char *pathname
)
135 ACPI_FUNCTION_NAME(ex_trace_point
);
138 ACPI_DEBUG_PRINT((ACPI_DB_TRACE_POINT
,
139 "%s %s [0x%p:%s] execution.\n",
140 acpi_ex_get_trace_event_name(type
),
141 begin
? "Begin" : "End", aml
, pathname
));
143 ACPI_DEBUG_PRINT((ACPI_DB_TRACE_POINT
,
144 "%s %s [0x%p] execution.\n",
145 acpi_ex_get_trace_event_name(type
),
146 begin
? "Begin" : "End", aml
));
150 /*******************************************************************************
152 * FUNCTION: acpi_ex_start_trace_method
154 * PARAMETERS: method_node - Node of the method
155 * obj_desc - The method object
156 * walk_state - current state, NULL if not yet executing
161 * DESCRIPTION: Start control method execution trace
163 ******************************************************************************/
166 acpi_ex_start_trace_method(struct acpi_namespace_node
*method_node
,
167 union acpi_operand_object
*obj_desc
,
168 struct acpi_walk_state
*walk_state
)
170 char *pathname
= NULL
;
173 ACPI_FUNCTION_NAME(ex_start_trace_method
);
176 pathname
= acpi_ns_get_normalized_pathname(method_node
, TRUE
);
179 enabled
= acpi_ex_interpreter_trace_enabled(pathname
);
180 if (enabled
&& !acpi_gbl_trace_method_object
) {
181 acpi_gbl_trace_method_object
= obj_desc
;
182 acpi_gbl_original_dbg_level
= acpi_dbg_level
;
183 acpi_gbl_original_dbg_layer
= acpi_dbg_layer
;
184 acpi_dbg_level
= ACPI_TRACE_LEVEL_ALL
;
185 acpi_dbg_layer
= ACPI_TRACE_LAYER_ALL
;
187 if (acpi_gbl_trace_dbg_level
) {
188 acpi_dbg_level
= acpi_gbl_trace_dbg_level
;
191 if (acpi_gbl_trace_dbg_layer
) {
192 acpi_dbg_layer
= acpi_gbl_trace_dbg_layer
;
197 ACPI_TRACE_POINT(ACPI_TRACE_AML_METHOD
, TRUE
,
198 obj_desc
? obj_desc
->method
.aml_start
: NULL
,
207 /*******************************************************************************
209 * FUNCTION: acpi_ex_stop_trace_method
211 * PARAMETERS: method_node - Node of the method
212 * obj_desc - The method object
213 * walk_state - current state, NULL if not yet executing
218 * DESCRIPTION: Stop control method execution trace
220 ******************************************************************************/
223 acpi_ex_stop_trace_method(struct acpi_namespace_node
*method_node
,
224 union acpi_operand_object
*obj_desc
,
225 struct acpi_walk_state
*walk_state
)
227 char *pathname
= NULL
;
230 ACPI_FUNCTION_NAME(ex_stop_trace_method
);
233 pathname
= acpi_ns_get_normalized_pathname(method_node
, TRUE
);
236 enabled
= acpi_ex_interpreter_trace_enabled(NULL
);
239 ACPI_TRACE_POINT(ACPI_TRACE_AML_METHOD
, FALSE
,
240 obj_desc
? obj_desc
->method
.aml_start
: NULL
,
244 /* Check whether the tracer should be stopped */
246 if (acpi_gbl_trace_method_object
== obj_desc
) {
248 /* Disable further tracing if type is one-shot */
250 if (acpi_gbl_trace_flags
& ACPI_TRACE_ONESHOT
) {
251 acpi_gbl_trace_method_name
= NULL
;
254 acpi_dbg_level
= acpi_gbl_original_dbg_level
;
255 acpi_dbg_layer
= acpi_gbl_original_dbg_layer
;
256 acpi_gbl_trace_method_object
= NULL
;
264 /*******************************************************************************
266 * FUNCTION: acpi_ex_start_trace_opcode
268 * PARAMETERS: op - The parser opcode object
269 * walk_state - current state, NULL if not yet executing
274 * DESCRIPTION: Start opcode execution trace
276 ******************************************************************************/
279 acpi_ex_start_trace_opcode(union acpi_parse_object
*op
,
280 struct acpi_walk_state
*walk_state
)
283 ACPI_FUNCTION_NAME(ex_start_trace_opcode
);
285 if (acpi_ex_interpreter_trace_enabled(NULL
) &&
286 (acpi_gbl_trace_flags
& ACPI_TRACE_OPCODE
)) {
287 ACPI_TRACE_POINT(ACPI_TRACE_AML_OPCODE
, TRUE
,
288 op
->common
.aml
, op
->common
.aml_op_name
);
292 /*******************************************************************************
294 * FUNCTION: acpi_ex_stop_trace_opcode
296 * PARAMETERS: op - The parser opcode object
297 * walk_state - current state, NULL if not yet executing
302 * DESCRIPTION: Stop opcode execution trace
304 ******************************************************************************/
307 acpi_ex_stop_trace_opcode(union acpi_parse_object
*op
,
308 struct acpi_walk_state
*walk_state
)
311 ACPI_FUNCTION_NAME(ex_stop_trace_opcode
);
313 if (acpi_ex_interpreter_trace_enabled(NULL
) &&
314 (acpi_gbl_trace_flags
& ACPI_TRACE_OPCODE
)) {
315 ACPI_TRACE_POINT(ACPI_TRACE_AML_OPCODE
, FALSE
,
316 op
->common
.aml
, op
->common
.aml_op_name
);