treewide: remove redundant IS_ERR() before error code check
[linux/fpc-iii.git] / drivers / acpi / acpica / extrace.c
blob832a47885b99d7b415481ef23407c42472f59bb1
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>
11 #include "accommon.h"
12 #include "acnamesp.h"
13 #include "acinterp.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);
24 #endif
26 /*******************************************************************************
28 * FUNCTION: acpi_ex_interpreter_trace_enabled
30 * PARAMETERS: name - Whether method name should be matched,
31 * this should be checked before starting
32 * the tracer
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)) {
46 return (FALSE);
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) {
60 return (TRUE);
63 if (name &&
64 (acpi_gbl_trace_method_name &&
65 strcmp(acpi_gbl_trace_method_name, name))) {
66 return (FALSE);
69 if ((acpi_gbl_trace_flags & ACPI_TRACE_ONESHOT) &&
70 !acpi_gbl_trace_method_name) {
71 return (FALSE);
74 return (TRUE);
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)
94 switch (type) {
95 case ACPI_TRACE_AML_METHOD:
97 return "Method";
99 case ACPI_TRACE_AML_OPCODE:
101 return "Opcode";
103 case ACPI_TRACE_AML_REGION:
105 return "Region";
107 default:
109 return "";
113 #endif
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
124 * RETURN: None
126 * DESCRIPTION: Internal interpreter execution trace.
128 ******************************************************************************/
130 void
131 acpi_ex_trace_point(acpi_trace_event_type type,
132 u8 begin, u8 *aml, char *pathname)
135 ACPI_FUNCTION_NAME(ex_trace_point);
137 if (pathname) {
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));
142 } else {
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
157 * a method.
159 * RETURN: None
161 * DESCRIPTION: Start control method execution trace
163 ******************************************************************************/
165 void
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;
171 u8 enabled = FALSE;
173 ACPI_FUNCTION_NAME(ex_start_trace_method);
175 if (method_node) {
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;
196 if (enabled) {
197 ACPI_TRACE_POINT(ACPI_TRACE_AML_METHOD, TRUE,
198 obj_desc ? obj_desc->method.aml_start : NULL,
199 pathname);
202 if (pathname) {
203 ACPI_FREE(pathname);
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
214 * a method.
216 * RETURN: None
218 * DESCRIPTION: Stop control method execution trace
220 ******************************************************************************/
222 void
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;
228 u8 enabled;
230 ACPI_FUNCTION_NAME(ex_stop_trace_method);
232 if (method_node) {
233 pathname = acpi_ns_get_normalized_pathname(method_node, TRUE);
236 enabled = acpi_ex_interpreter_trace_enabled(NULL);
238 if (enabled) {
239 ACPI_TRACE_POINT(ACPI_TRACE_AML_METHOD, FALSE,
240 obj_desc ? obj_desc->method.aml_start : NULL,
241 pathname);
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;
259 if (pathname) {
260 ACPI_FREE(pathname);
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
270 * a method.
272 * RETURN: None
274 * DESCRIPTION: Start opcode execution trace
276 ******************************************************************************/
278 void
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
298 * a method.
300 * RETURN: None
302 * DESCRIPTION: Stop opcode execution trace
304 ******************************************************************************/
306 void
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);