1 /******************************************************************************
3 * Module Name: utdebug - Debug print/trace routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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 #define EXPORT_ACPI_INTERFACES
46 #include <acpi/acpi.h>
49 #define _COMPONENT ACPI_UTILITIES
50 ACPI_MODULE_NAME("utdebug")
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-";
57 /* Local prototypes */
59 static const char *acpi_ut_trim_function_name(const char *function_name);
61 /*******************************************************************************
63 * FUNCTION: acpi_ut_init_stack_ptr_trace
69 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
71 ******************************************************************************/
73 void acpi_ut_init_stack_ptr_trace(void)
77 acpi_gbl_entry_stack_pointer = ¤t_sp;
80 /*******************************************************************************
82 * FUNCTION: acpi_ut_track_stack_ptr
88 * DESCRIPTION: Save the current CPU stack pointer
90 ******************************************************************************/
92 void acpi_ut_track_stack_ptr(void)
96 if (¤t_sp < acpi_gbl_lowest_stack_pointer) {
97 acpi_gbl_lowest_stack_pointer = ¤t_sp;
100 if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) {
101 acpi_gbl_deepest_nesting = acpi_gbl_nesting_level;
105 /*******************************************************************************
107 * FUNCTION: acpi_ut_trim_function_name
109 * PARAMETERS: function_name - Ascii string containing a procedure name
111 * RETURN: Updated pointer to the function name
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.
117 ******************************************************************************/
119 static const char *acpi_ut_trim_function_name(const char *function_name)
122 /* All Function names are longer than 4 chars, check is safe */
124 if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_MIXED) {
126 /* This is the case where the original source has not been modified */
128 return (function_name + 4);
131 if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_LOWER) {
133 /* This is the case where the source has been 'linuxized' */
135 return (function_name + 5);
138 return (function_name);
141 /*******************************************************************************
143 * FUNCTION: acpi_debug_print
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
155 * DESCRIPTION: Print error message with prefix consisting of the module name,
156 * line number, and component ID.
158 ******************************************************************************/
160 void ACPI_INTERNAL_VAR_XFACE
161 acpi_debug_print(u32 requested_debug_level,
163 const char *function_name,
164 const char *module_name,
165 u32 component_id, const char *format, ...)
167 acpi_thread_id thread_id;
170 /* Check if debug output enabled */
172 if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) {
177 * Thread tracking and context switch notification
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) {
183 ("\n**** Context Switch from TID %u to TID %u ****\n\n",
184 (u32)acpi_gbl_prev_thread_id, (u32)thread_id);
187 acpi_gbl_prev_thread_id = thread_id;
191 * Display the module name, current line number, thread ID (if requested),
192 * current procedure nesting level, and the current procedure name
194 acpi_os_printf("%9s-%04ld ", module_name, line_number);
196 if (ACPI_LV_THREADS & acpi_dbg_level) {
197 acpi_os_printf("[%u] ", (u32)thread_id);
200 acpi_os_printf("[%02ld] %-22.22s: ",
201 acpi_gbl_nesting_level,
202 acpi_ut_trim_function_name(function_name));
204 va_start(args, format);
205 acpi_os_vprintf(format, args);
209 ACPI_EXPORT_SYMBOL(acpi_debug_print)
211 /*******************************************************************************
213 * FUNCTION: acpi_debug_print_raw
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
225 * DESCRIPTION: Print message with no headers. Has same interface as
226 * debug_print so that the same macros can be used.
228 ******************************************************************************/
229 void ACPI_INTERNAL_VAR_XFACE
230 acpi_debug_print_raw(u32 requested_debug_level,
232 const char *function_name,
233 const char *module_name,
234 u32 component_id, const char *format, ...)
238 /* Check if debug output enabled */
240 if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) {
244 va_start(args, format);
245 acpi_os_vprintf(format, args);
249 ACPI_EXPORT_SYMBOL(acpi_debug_print_raw)
251 /*******************************************************************************
253 * FUNCTION: acpi_ut_trace
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
262 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
265 ******************************************************************************/
267 acpi_ut_trace(u32 line_number,
268 const char *function_name,
269 const char *module_name, u32 component_id)
272 acpi_gbl_nesting_level++;
273 acpi_ut_track_stack_ptr();
275 /* Check if enabled up-front for performance */
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);
284 ACPI_EXPORT_SYMBOL(acpi_ut_trace)
286 /*******************************************************************************
288 * FUNCTION: acpi_ut_trace_ptr
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
298 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
301 ******************************************************************************/
303 acpi_ut_trace_ptr(u32 line_number,
304 const char *function_name,
305 const char *module_name, u32 component_id, void *pointer)
308 acpi_gbl_nesting_level++;
309 acpi_ut_track_stack_ptr();
311 /* Check if enabled up-front for performance */
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,
321 /*******************************************************************************
323 * FUNCTION: acpi_ut_trace_str
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
333 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
336 ******************************************************************************/
339 acpi_ut_trace_str(u32 line_number,
340 const char *function_name,
341 const char *module_name, u32 component_id, char *string)
344 acpi_gbl_nesting_level++;
345 acpi_ut_track_stack_ptr();
347 /* Check if enabled up-front for performance */
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,
357 /*******************************************************************************
359 * FUNCTION: acpi_ut_trace_u32
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
369 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
372 ******************************************************************************/
375 acpi_ut_trace_u32(u32 line_number,
376 const char *function_name,
377 const char *module_name, u32 component_id, u32 integer)
380 acpi_gbl_nesting_level++;
381 acpi_ut_track_stack_ptr();
383 /* Check if enabled up-front for performance */
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);
393 /*******************************************************************************
395 * FUNCTION: acpi_ut_exit
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
404 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
407 ******************************************************************************/
410 acpi_ut_exit(u32 line_number,
411 const char *function_name,
412 const char *module_name, u32 component_id)
415 /* Check if enabled up-front for performance */
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);
423 acpi_gbl_nesting_level--;
426 ACPI_EXPORT_SYMBOL(acpi_ut_exit)
428 /*******************************************************************************
430 * FUNCTION: acpi_ut_status_exit
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
440 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
441 * set in debug_level. Prints exit status also.
443 ******************************************************************************/
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)
451 /* Check if enabled up-front for performance */
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));
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));
470 acpi_gbl_nesting_level--;
473 ACPI_EXPORT_SYMBOL(acpi_ut_status_exit)
475 /*******************************************************************************
477 * FUNCTION: acpi_ut_value_exit
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
487 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
488 * set in debug_level. Prints exit value also.
490 ******************************************************************************/
492 acpi_ut_value_exit(u32 line_number,
493 const char *function_name,
494 const char *module_name, u32 component_id, u64 value)
497 /* Check if enabled up-front for performance */
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));
507 acpi_gbl_nesting_level--;
510 ACPI_EXPORT_SYMBOL(acpi_ut_value_exit)
512 /*******************************************************************************
514 * FUNCTION: acpi_ut_ptr_exit
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
524 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
525 * set in debug_level. Prints exit value also.
527 ******************************************************************************/
529 acpi_ut_ptr_exit(u32 line_number,
530 const char *function_name,
531 const char *module_name, u32 component_id, u8 *ptr)
534 /* Check if enabled up-front for performance */
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,
543 acpi_gbl_nesting_level--;