xref: /openbmc/linux/drivers/acpi/acpica/utdebug.c (revision e23feb16)
1 /******************************************************************************
2  *
3  * Module Name: utdebug - Debug print/trace routines
4  *
5  *****************************************************************************/
6 
7 /*
8  * Copyright (C) 2000 - 2013, Intel Corp.
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 <linux/export.h>
45 #include <acpi/acpi.h>
46 #include "accommon.h"
47 
48 #define _COMPONENT          ACPI_UTILITIES
49 ACPI_MODULE_NAME("utdebug")
50 
51 #ifdef ACPI_DEBUG_OUTPUT
52 static acpi_thread_id acpi_gbl_prev_thread_id = (acpi_thread_id) 0xFFFFFFFF;
53 static char *acpi_gbl_fn_entry_str = "----Entry";
54 static char *acpi_gbl_fn_exit_str = "----Exit-";
55 
56 /* Local prototypes */
57 
58 static const char *acpi_ut_trim_function_name(const char *function_name);
59 
60 /*******************************************************************************
61  *
62  * FUNCTION:    acpi_ut_init_stack_ptr_trace
63  *
64  * PARAMETERS:  None
65  *
66  * RETURN:      None
67  *
68  * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
69  *
70  ******************************************************************************/
71 
72 void acpi_ut_init_stack_ptr_trace(void)
73 {
74 	acpi_size current_sp;
75 
76 	acpi_gbl_entry_stack_pointer = &current_sp;
77 }
78 
79 /*******************************************************************************
80  *
81  * FUNCTION:    acpi_ut_track_stack_ptr
82  *
83  * PARAMETERS:  None
84  *
85  * RETURN:      None
86  *
87  * DESCRIPTION: Save the current CPU stack pointer
88  *
89  ******************************************************************************/
90 
91 void acpi_ut_track_stack_ptr(void)
92 {
93 	acpi_size current_sp;
94 
95 	if (&current_sp < acpi_gbl_lowest_stack_pointer) {
96 		acpi_gbl_lowest_stack_pointer = &current_sp;
97 	}
98 
99 	if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) {
100 		acpi_gbl_deepest_nesting = acpi_gbl_nesting_level;
101 	}
102 }
103 
104 /*******************************************************************************
105  *
106  * FUNCTION:    acpi_ut_trim_function_name
107  *
108  * PARAMETERS:  function_name       - Ascii string containing a procedure name
109  *
110  * RETURN:      Updated pointer to the function name
111  *
112  * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
113  *              This allows compiler macros such as __FUNCTION__ to be used
114  *              with no change to the debug output.
115  *
116  ******************************************************************************/
117 
118 static const char *acpi_ut_trim_function_name(const char *function_name)
119 {
120 
121 	/* All Function names are longer than 4 chars, check is safe */
122 
123 	if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_MIXED) {
124 
125 		/* This is the case where the original source has not been modified */
126 
127 		return (function_name + 4);
128 	}
129 
130 	if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_LOWER) {
131 
132 		/* This is the case where the source has been 'linuxized' */
133 
134 		return (function_name + 5);
135 	}
136 
137 	return (function_name);
138 }
139 
140 /*******************************************************************************
141  *
142  * FUNCTION:    acpi_debug_print
143  *
144  * PARAMETERS:  requested_debug_level - Requested debug print level
145  *              line_number         - Caller's line number (for error output)
146  *              function_name       - Caller's procedure name
147  *              module_name         - Caller's module name
148  *              component_id        - Caller's component ID
149  *              format              - Printf format field
150  *              ...                 - Optional printf arguments
151  *
152  * RETURN:      None
153  *
154  * DESCRIPTION: Print error message with prefix consisting of the module name,
155  *              line number, and component ID.
156  *
157  ******************************************************************************/
158 
159 void ACPI_INTERNAL_VAR_XFACE
160 acpi_debug_print(u32 requested_debug_level,
161 		 u32 line_number,
162 		 const char *function_name,
163 		 const char *module_name,
164 		 u32 component_id, const char *format, ...)
165 {
166 	acpi_thread_id thread_id;
167 	va_list args;
168 
169 	/* Check if debug output enabled */
170 
171 	if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) {
172 		return;
173 	}
174 
175 	/*
176 	 * Thread tracking and context switch notification
177 	 */
178 	thread_id = acpi_os_get_thread_id();
179 	if (thread_id != acpi_gbl_prev_thread_id) {
180 		if (ACPI_LV_THREADS & acpi_dbg_level) {
181 			acpi_os_printf
182 			    ("\n**** Context Switch from TID %u to TID %u ****\n\n",
183 			     (u32)acpi_gbl_prev_thread_id, (u32)thread_id);
184 		}
185 
186 		acpi_gbl_prev_thread_id = thread_id;
187 	}
188 
189 	/*
190 	 * Display the module name, current line number, thread ID (if requested),
191 	 * current procedure nesting level, and the current procedure name
192 	 */
193 	acpi_os_printf("%8s-%04ld ", module_name, line_number);
194 
195 	if (ACPI_LV_THREADS & acpi_dbg_level) {
196 		acpi_os_printf("[%u] ", (u32)thread_id);
197 	}
198 
199 	acpi_os_printf("[%02ld] %-22.22s: ",
200 		       acpi_gbl_nesting_level,
201 		       acpi_ut_trim_function_name(function_name));
202 
203 	va_start(args, format);
204 	acpi_os_vprintf(format, args);
205 	va_end(args);
206 }
207 
208 ACPI_EXPORT_SYMBOL(acpi_debug_print)
209 
210 /*******************************************************************************
211  *
212  * FUNCTION:    acpi_debug_print_raw
213  *
214  * PARAMETERS:  requested_debug_level - Requested debug print level
215  *              line_number         - Caller's line number
216  *              function_name       - Caller's procedure name
217  *              module_name         - Caller's module name
218  *              component_id        - Caller's component ID
219  *              format              - Printf format field
220  *              ...                 - Optional printf arguments
221  *
222  * RETURN:      None
223  *
224  * DESCRIPTION: Print message with no headers. Has same interface as
225  *              debug_print so that the same macros can be used.
226  *
227  ******************************************************************************/
228 void ACPI_INTERNAL_VAR_XFACE
229 acpi_debug_print_raw(u32 requested_debug_level,
230 		     u32 line_number,
231 		     const char *function_name,
232 		     const char *module_name,
233 		     u32 component_id, const char *format, ...)
234 {
235 	va_list args;
236 
237 	/* Check if debug output enabled */
238 
239 	if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) {
240 		return;
241 	}
242 
243 	va_start(args, format);
244 	acpi_os_vprintf(format, args);
245 	va_end(args);
246 }
247 
248 ACPI_EXPORT_SYMBOL(acpi_debug_print_raw)
249 
250 /*******************************************************************************
251  *
252  * FUNCTION:    acpi_ut_trace
253  *
254  * PARAMETERS:  line_number         - Caller's line number
255  *              function_name       - Caller's procedure name
256  *              module_name         - Caller's module name
257  *              component_id        - Caller's component ID
258  *
259  * RETURN:      None
260  *
261  * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
262  *              set in debug_level
263  *
264  ******************************************************************************/
265 void
266 acpi_ut_trace(u32 line_number,
267 	      const char *function_name,
268 	      const char *module_name, u32 component_id)
269 {
270 
271 	acpi_gbl_nesting_level++;
272 	acpi_ut_track_stack_ptr();
273 
274 	/* Check if enabled up-front for performance */
275 
276 	if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
277 		acpi_debug_print(ACPI_LV_FUNCTIONS,
278 				 line_number, function_name, module_name,
279 				 component_id, "%s\n", acpi_gbl_fn_entry_str);
280 	}
281 }
282 
283 ACPI_EXPORT_SYMBOL(acpi_ut_trace)
284 
285 /*******************************************************************************
286  *
287  * FUNCTION:    acpi_ut_trace_ptr
288  *
289  * PARAMETERS:  line_number         - Caller's line number
290  *              function_name       - Caller's procedure name
291  *              module_name         - Caller's module name
292  *              component_id        - Caller's component ID
293  *              pointer             - Pointer to display
294  *
295  * RETURN:      None
296  *
297  * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
298  *              set in debug_level
299  *
300  ******************************************************************************/
301 void
302 acpi_ut_trace_ptr(u32 line_number,
303 		  const char *function_name,
304 		  const char *module_name, u32 component_id, void *pointer)
305 {
306 
307 	acpi_gbl_nesting_level++;
308 	acpi_ut_track_stack_ptr();
309 
310 	/* Check if enabled up-front for performance */
311 
312 	if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
313 		acpi_debug_print(ACPI_LV_FUNCTIONS,
314 				 line_number, function_name, module_name,
315 				 component_id, "%s %p\n", acpi_gbl_fn_entry_str,
316 				 pointer);
317 	}
318 }
319 
320 /*******************************************************************************
321  *
322  * FUNCTION:    acpi_ut_trace_str
323  *
324  * PARAMETERS:  line_number         - Caller's line number
325  *              function_name       - Caller's procedure name
326  *              module_name         - Caller's module name
327  *              component_id        - Caller's component ID
328  *              string              - Additional string to display
329  *
330  * RETURN:      None
331  *
332  * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
333  *              set in debug_level
334  *
335  ******************************************************************************/
336 
337 void
338 acpi_ut_trace_str(u32 line_number,
339 		  const char *function_name,
340 		  const char *module_name, u32 component_id, char *string)
341 {
342 
343 	acpi_gbl_nesting_level++;
344 	acpi_ut_track_stack_ptr();
345 
346 	/* Check if enabled up-front for performance */
347 
348 	if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
349 		acpi_debug_print(ACPI_LV_FUNCTIONS,
350 				 line_number, function_name, module_name,
351 				 component_id, "%s %s\n", acpi_gbl_fn_entry_str,
352 				 string);
353 	}
354 }
355 
356 /*******************************************************************************
357  *
358  * FUNCTION:    acpi_ut_trace_u32
359  *
360  * PARAMETERS:  line_number         - Caller's line number
361  *              function_name       - Caller's procedure name
362  *              module_name         - Caller's module name
363  *              component_id        - Caller's component ID
364  *              integer             - Integer to display
365  *
366  * RETURN:      None
367  *
368  * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
369  *              set in debug_level
370  *
371  ******************************************************************************/
372 
373 void
374 acpi_ut_trace_u32(u32 line_number,
375 		  const char *function_name,
376 		  const char *module_name, u32 component_id, u32 integer)
377 {
378 
379 	acpi_gbl_nesting_level++;
380 	acpi_ut_track_stack_ptr();
381 
382 	/* Check if enabled up-front for performance */
383 
384 	if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
385 		acpi_debug_print(ACPI_LV_FUNCTIONS,
386 				 line_number, function_name, module_name,
387 				 component_id, "%s %08X\n",
388 				 acpi_gbl_fn_entry_str, integer);
389 	}
390 }
391 
392 /*******************************************************************************
393  *
394  * FUNCTION:    acpi_ut_exit
395  *
396  * PARAMETERS:  line_number         - Caller's line number
397  *              function_name       - Caller's procedure name
398  *              module_name         - Caller's module name
399  *              component_id        - Caller's component ID
400  *
401  * RETURN:      None
402  *
403  * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
404  *              set in debug_level
405  *
406  ******************************************************************************/
407 
408 void
409 acpi_ut_exit(u32 line_number,
410 	     const char *function_name,
411 	     const char *module_name, u32 component_id)
412 {
413 
414 	/* Check if enabled up-front for performance */
415 
416 	if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
417 		acpi_debug_print(ACPI_LV_FUNCTIONS,
418 				 line_number, function_name, module_name,
419 				 component_id, "%s\n", acpi_gbl_fn_exit_str);
420 	}
421 
422 	acpi_gbl_nesting_level--;
423 }
424 
425 ACPI_EXPORT_SYMBOL(acpi_ut_exit)
426 
427 /*******************************************************************************
428  *
429  * FUNCTION:    acpi_ut_status_exit
430  *
431  * PARAMETERS:  line_number         - Caller's line number
432  *              function_name       - Caller's procedure name
433  *              module_name         - Caller's module name
434  *              component_id        - Caller's component ID
435  *              status              - Exit status code
436  *
437  * RETURN:      None
438  *
439  * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
440  *              set in debug_level. Prints exit status also.
441  *
442  ******************************************************************************/
443 void
444 acpi_ut_status_exit(u32 line_number,
445 		    const char *function_name,
446 		    const char *module_name,
447 		    u32 component_id, acpi_status status)
448 {
449 
450 	/* Check if enabled up-front for performance */
451 
452 	if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
453 		if (ACPI_SUCCESS(status)) {
454 			acpi_debug_print(ACPI_LV_FUNCTIONS,
455 					 line_number, function_name,
456 					 module_name, component_id, "%s %s\n",
457 					 acpi_gbl_fn_exit_str,
458 					 acpi_format_exception(status));
459 		} else {
460 			acpi_debug_print(ACPI_LV_FUNCTIONS,
461 					 line_number, function_name,
462 					 module_name, component_id,
463 					 "%s ****Exception****: %s\n",
464 					 acpi_gbl_fn_exit_str,
465 					 acpi_format_exception(status));
466 		}
467 	}
468 
469 	acpi_gbl_nesting_level--;
470 }
471 
472 ACPI_EXPORT_SYMBOL(acpi_ut_status_exit)
473 
474 /*******************************************************************************
475  *
476  * FUNCTION:    acpi_ut_value_exit
477  *
478  * PARAMETERS:  line_number         - Caller's line number
479  *              function_name       - Caller's procedure name
480  *              module_name         - Caller's module name
481  *              component_id        - Caller's component ID
482  *              value               - Value to be printed with exit msg
483  *
484  * RETURN:      None
485  *
486  * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
487  *              set in debug_level. Prints exit value also.
488  *
489  ******************************************************************************/
490 void
491 acpi_ut_value_exit(u32 line_number,
492 		   const char *function_name,
493 		   const char *module_name, u32 component_id, u64 value)
494 {
495 
496 	/* Check if enabled up-front for performance */
497 
498 	if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
499 		acpi_debug_print(ACPI_LV_FUNCTIONS,
500 				 line_number, function_name, module_name,
501 				 component_id, "%s %8.8X%8.8X\n",
502 				 acpi_gbl_fn_exit_str,
503 				 ACPI_FORMAT_UINT64(value));
504 	}
505 
506 	acpi_gbl_nesting_level--;
507 }
508 
509 ACPI_EXPORT_SYMBOL(acpi_ut_value_exit)
510 
511 /*******************************************************************************
512  *
513  * FUNCTION:    acpi_ut_ptr_exit
514  *
515  * PARAMETERS:  line_number         - Caller's line number
516  *              function_name       - Caller's procedure name
517  *              module_name         - Caller's module name
518  *              component_id        - Caller's component ID
519  *              ptr                 - Pointer to display
520  *
521  * RETURN:      None
522  *
523  * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
524  *              set in debug_level. Prints exit value also.
525  *
526  ******************************************************************************/
527 void
528 acpi_ut_ptr_exit(u32 line_number,
529 		 const char *function_name,
530 		 const char *module_name, u32 component_id, u8 *ptr)
531 {
532 
533 	/* Check if enabled up-front for performance */
534 
535 	if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
536 		acpi_debug_print(ACPI_LV_FUNCTIONS,
537 				 line_number, function_name, module_name,
538 				 component_id, "%s %p\n", acpi_gbl_fn_exit_str,
539 				 ptr);
540 	}
541 
542 	acpi_gbl_nesting_level--;
543 }
544 
545 #endif
546