Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/evalenti/linux...
[linux/fpc-iii.git] / drivers / acpi / acpica / extrace.c
blobb52e84841c1a0d30ec37cd8cd19d0a476461718a
1 /******************************************************************************
3 * Module Name: extrace - Support for interpreter execution tracing
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2016, Intel Corp.
9 * All rights reserved.
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.
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.
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.
44 #include <acpi/acpi.h>
45 #include "accommon.h"
46 #include "acnamesp.h"
47 #include "acinterp.h"
49 #define _COMPONENT ACPI_EXECUTER
50 ACPI_MODULE_NAME("extrace")
52 static union acpi_operand_object *acpi_gbl_trace_method_object = NULL;
54 /* Local prototypes */
56 #ifdef ACPI_DEBUG_OUTPUT
57 static const char *acpi_ex_get_trace_event_name(acpi_trace_event_type type);
58 #endif
60 /*******************************************************************************
62 * FUNCTION: acpi_ex_interpreter_trace_enabled
64 * PARAMETERS: name - Whether method name should be matched,
65 * this should be checked before starting
66 * the tracer
68 * RETURN: TRUE if interpreter trace is enabled.
70 * DESCRIPTION: Check whether interpreter trace is enabled
72 ******************************************************************************/
74 static u8 acpi_ex_interpreter_trace_enabled(char *name)
77 /* Check if tracing is enabled */
79 if (!(acpi_gbl_trace_flags & ACPI_TRACE_ENABLED)) {
80 return (FALSE);
84 * Check if tracing is filtered:
86 * 1. If the tracer is started, acpi_gbl_trace_method_object should have
87 * been filled by the trace starter
88 * 2. If the tracer is not started, acpi_gbl_trace_method_name should be
89 * matched if it is specified
90 * 3. If the tracer is oneshot style, acpi_gbl_trace_method_name should
91 * not be cleared by the trace stopper during the first match
93 if (acpi_gbl_trace_method_object) {
94 return (TRUE);
97 if (name &&
98 (acpi_gbl_trace_method_name &&
99 strcmp(acpi_gbl_trace_method_name, name))) {
100 return (FALSE);
103 if ((acpi_gbl_trace_flags & ACPI_TRACE_ONESHOT) &&
104 !acpi_gbl_trace_method_name) {
105 return (FALSE);
108 return (TRUE);
111 /*******************************************************************************
113 * FUNCTION: acpi_ex_get_trace_event_name
115 * PARAMETERS: type - Trace event type
117 * RETURN: Trace event name.
119 * DESCRIPTION: Used to obtain the full trace event name.
121 ******************************************************************************/
123 #ifdef ACPI_DEBUG_OUTPUT
125 static const char *acpi_ex_get_trace_event_name(acpi_trace_event_type type)
128 switch (type) {
129 case ACPI_TRACE_AML_METHOD:
131 return "Method";
133 case ACPI_TRACE_AML_OPCODE:
135 return "Opcode";
137 case ACPI_TRACE_AML_REGION:
139 return "Region";
141 default:
143 return "";
147 #endif
149 /*******************************************************************************
151 * FUNCTION: acpi_ex_trace_point
153 * PARAMETERS: type - Trace event type
154 * begin - TRUE if before execution
155 * aml - Executed AML address
156 * pathname - Object path
158 * RETURN: None
160 * DESCRIPTION: Internal interpreter execution trace.
162 ******************************************************************************/
164 void
165 acpi_ex_trace_point(acpi_trace_event_type type,
166 u8 begin, u8 *aml, char *pathname)
169 ACPI_FUNCTION_NAME(ex_trace_point);
171 if (pathname) {
172 ACPI_DEBUG_PRINT((ACPI_DB_TRACE_POINT,
173 "%s %s [0x%p:%s] execution.\n",
174 acpi_ex_get_trace_event_name(type),
175 begin ? "Begin" : "End", aml, pathname));
176 } else {
177 ACPI_DEBUG_PRINT((ACPI_DB_TRACE_POINT,
178 "%s %s [0x%p] execution.\n",
179 acpi_ex_get_trace_event_name(type),
180 begin ? "Begin" : "End", aml));
184 /*******************************************************************************
186 * FUNCTION: acpi_ex_start_trace_method
188 * PARAMETERS: method_node - Node of the method
189 * obj_desc - The method object
190 * walk_state - current state, NULL if not yet executing
191 * a method.
193 * RETURN: None
195 * DESCRIPTION: Start control method execution trace
197 ******************************************************************************/
199 void
200 acpi_ex_start_trace_method(struct acpi_namespace_node *method_node,
201 union acpi_operand_object *obj_desc,
202 struct acpi_walk_state *walk_state)
204 acpi_status status;
205 char *pathname = NULL;
206 u8 enabled = FALSE;
208 ACPI_FUNCTION_NAME(ex_start_trace_method);
210 if (method_node) {
211 pathname = acpi_ns_get_normalized_pathname(method_node, TRUE);
214 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
215 if (ACPI_FAILURE(status)) {
216 goto exit;
219 enabled = acpi_ex_interpreter_trace_enabled(pathname);
220 if (enabled && !acpi_gbl_trace_method_object) {
221 acpi_gbl_trace_method_object = obj_desc;
222 acpi_gbl_original_dbg_level = acpi_dbg_level;
223 acpi_gbl_original_dbg_layer = acpi_dbg_layer;
224 acpi_dbg_level = ACPI_TRACE_LEVEL_ALL;
225 acpi_dbg_layer = ACPI_TRACE_LAYER_ALL;
227 if (acpi_gbl_trace_dbg_level) {
228 acpi_dbg_level = acpi_gbl_trace_dbg_level;
231 if (acpi_gbl_trace_dbg_layer) {
232 acpi_dbg_layer = acpi_gbl_trace_dbg_layer;
236 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
238 exit:
239 if (enabled) {
240 ACPI_TRACE_POINT(ACPI_TRACE_AML_METHOD, TRUE,
241 obj_desc ? obj_desc->method.aml_start : NULL,
242 pathname);
245 if (pathname) {
246 ACPI_FREE(pathname);
250 /*******************************************************************************
252 * FUNCTION: acpi_ex_stop_trace_method
254 * PARAMETERS: method_node - Node of the method
255 * obj_desc - The method object
256 * walk_state - current state, NULL if not yet executing
257 * a method.
259 * RETURN: None
261 * DESCRIPTION: Stop control method execution trace
263 ******************************************************************************/
265 void
266 acpi_ex_stop_trace_method(struct acpi_namespace_node *method_node,
267 union acpi_operand_object *obj_desc,
268 struct acpi_walk_state *walk_state)
270 acpi_status status;
271 char *pathname = NULL;
272 u8 enabled;
274 ACPI_FUNCTION_NAME(ex_stop_trace_method);
276 if (method_node) {
277 pathname = acpi_ns_get_normalized_pathname(method_node, TRUE);
280 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
281 if (ACPI_FAILURE(status)) {
282 goto exit_path;
285 enabled = acpi_ex_interpreter_trace_enabled(NULL);
287 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
289 if (enabled) {
290 ACPI_TRACE_POINT(ACPI_TRACE_AML_METHOD, FALSE,
291 obj_desc ? obj_desc->method.aml_start : NULL,
292 pathname);
295 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
296 if (ACPI_FAILURE(status)) {
297 goto exit_path;
300 /* Check whether the tracer should be stopped */
302 if (acpi_gbl_trace_method_object == obj_desc) {
304 /* Disable further tracing if type is one-shot */
306 if (acpi_gbl_trace_flags & ACPI_TRACE_ONESHOT) {
307 acpi_gbl_trace_method_name = NULL;
310 acpi_dbg_level = acpi_gbl_original_dbg_level;
311 acpi_dbg_layer = acpi_gbl_original_dbg_layer;
312 acpi_gbl_trace_method_object = NULL;
315 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
317 exit_path:
318 if (pathname) {
319 ACPI_FREE(pathname);
323 /*******************************************************************************
325 * FUNCTION: acpi_ex_start_trace_opcode
327 * PARAMETERS: op - The parser opcode object
328 * walk_state - current state, NULL if not yet executing
329 * a method.
331 * RETURN: None
333 * DESCRIPTION: Start opcode execution trace
335 ******************************************************************************/
337 void
338 acpi_ex_start_trace_opcode(union acpi_parse_object *op,
339 struct acpi_walk_state *walk_state)
342 ACPI_FUNCTION_NAME(ex_start_trace_opcode);
344 if (acpi_ex_interpreter_trace_enabled(NULL) &&
345 (acpi_gbl_trace_flags & ACPI_TRACE_OPCODE)) {
346 ACPI_TRACE_POINT(ACPI_TRACE_AML_OPCODE, TRUE,
347 op->common.aml, op->common.aml_op_name);
351 /*******************************************************************************
353 * FUNCTION: acpi_ex_stop_trace_opcode
355 * PARAMETERS: op - The parser opcode object
356 * walk_state - current state, NULL if not yet executing
357 * a method.
359 * RETURN: None
361 * DESCRIPTION: Stop opcode execution trace
363 ******************************************************************************/
365 void
366 acpi_ex_stop_trace_opcode(union acpi_parse_object *op,
367 struct acpi_walk_state *walk_state)
370 ACPI_FUNCTION_NAME(ex_stop_trace_opcode);
372 if (acpi_ex_interpreter_trace_enabled(NULL) &&
373 (acpi_gbl_trace_flags & ACPI_TRACE_OPCODE)) {
374 ACPI_TRACE_POINT(ACPI_TRACE_AML_OPCODE, FALSE,
375 op->common.aml, op->common.aml_op_name);