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