1 /******************************************************************************
3 * Module Name: utdebug - Debug print routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, 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 #include <acpi/acpi.h>
47 #define _COMPONENT ACPI_UTILITIES
48 ACPI_MODULE_NAME("utdebug")
49 #ifdef ACPI_DEBUG_OUTPUT
50 static acpi_thread_id acpi_gbl_prev_thread_id
;
51 static char *acpi_gbl_fn_entry_str
= "----Entry";
52 static char *acpi_gbl_fn_exit_str
= "----Exit-";
54 /* Local prototypes */
56 static const char *acpi_ut_trim_function_name(const char *function_name
);
58 /*******************************************************************************
60 * FUNCTION: acpi_ut_init_stack_ptr_trace
66 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
68 ******************************************************************************/
70 void acpi_ut_init_stack_ptr_trace(void)
74 acpi_gbl_entry_stack_pointer
= ¤t_sp
;
77 /*******************************************************************************
79 * FUNCTION: acpi_ut_track_stack_ptr
85 * DESCRIPTION: Save the current CPU stack pointer
87 ******************************************************************************/
89 void acpi_ut_track_stack_ptr(void)
93 if (¤t_sp
< acpi_gbl_lowest_stack_pointer
) {
94 acpi_gbl_lowest_stack_pointer
= ¤t_sp
;
97 if (acpi_gbl_nesting_level
> acpi_gbl_deepest_nesting
) {
98 acpi_gbl_deepest_nesting
= acpi_gbl_nesting_level
;
102 /*******************************************************************************
104 * FUNCTION: acpi_ut_trim_function_name
106 * PARAMETERS: function_name - Ascii string containing a procedure name
108 * RETURN: Updated pointer to the function name
110 * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
111 * This allows compiler macros such as __func__ to be used
112 * with no change to the debug output.
114 ******************************************************************************/
116 static const char *acpi_ut_trim_function_name(const char *function_name
)
119 /* All Function names are longer than 4 chars, check is safe */
121 if (*(ACPI_CAST_PTR(u32
, function_name
)) == ACPI_PREFIX_MIXED
) {
123 /* This is the case where the original source has not been modified */
125 return (function_name
+ 4);
128 if (*(ACPI_CAST_PTR(u32
, function_name
)) == ACPI_PREFIX_LOWER
) {
130 /* This is the case where the source has been 'linuxized' */
132 return (function_name
+ 5);
135 return (function_name
);
138 /*******************************************************************************
140 * FUNCTION: acpi_debug_print
142 * PARAMETERS: requested_debug_level - Requested debug print level
143 * line_number - Caller's line number (for error output)
144 * function_name - Caller's procedure name
145 * module_name - Caller's module name
146 * component_id - Caller's component ID
147 * Format - Printf format field
148 * ... - Optional printf arguments
152 * DESCRIPTION: Print error message with prefix consisting of the module name,
153 * line number, and component ID.
155 ******************************************************************************/
157 void ACPI_INTERNAL_VAR_XFACE
158 acpi_debug_print(u32 requested_debug_level
,
160 const char *function_name
,
161 const char *module_name
,
162 u32 component_id
, const char *format
, ...)
164 acpi_thread_id thread_id
;
168 * Stay silent if the debug level or component ID is disabled
170 if (!(requested_debug_level
& acpi_dbg_level
) ||
171 !(component_id
& acpi_dbg_layer
)) {
176 * Thread tracking and context switch notification
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
) {
182 ("\n**** Context Switch from TID %u to TID %u ****\n\n",
183 (u32
)acpi_gbl_prev_thread_id
, (u32
)thread_id
);
186 acpi_gbl_prev_thread_id
= thread_id
;
190 * Display the module name, current line number, thread ID (if requested),
191 * current procedure nesting level, and the current procedure name
193 acpi_os_printf("%8s-%04ld ", module_name
, line_number
);
195 if (ACPI_LV_THREADS
& acpi_dbg_level
) {
196 acpi_os_printf("[%u] ", (u32
)thread_id
);
199 acpi_os_printf("[%02ld] %-22.22s: ",
200 acpi_gbl_nesting_level
,
201 acpi_ut_trim_function_name(function_name
));
203 va_start(args
, format
);
204 acpi_os_vprintf(format
, args
);
208 ACPI_EXPORT_SYMBOL(acpi_debug_print
)
210 /*******************************************************************************
212 * FUNCTION: acpi_debug_print_raw
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
224 * DESCRIPTION: Print message with no headers. Has same interface as
225 * debug_print so that the same macros can be used.
227 ******************************************************************************/
228 void ACPI_INTERNAL_VAR_XFACE
229 acpi_debug_print_raw(u32 requested_debug_level
,
231 const char *function_name
,
232 const char *module_name
,
233 u32 component_id
, const char *format
, ...)
237 if (!(requested_debug_level
& acpi_dbg_level
) ||
238 !(component_id
& acpi_dbg_layer
)) {
242 va_start(args
, format
);
243 acpi_os_vprintf(format
, args
);
247 ACPI_EXPORT_SYMBOL(acpi_debug_print_raw
)
249 /*******************************************************************************
251 * FUNCTION: acpi_ut_trace
253 * PARAMETERS: line_number - Caller's line number
254 * function_name - Caller's procedure name
255 * module_name - Caller's module name
256 * component_id - Caller's component ID
260 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
263 ******************************************************************************/
265 acpi_ut_trace(u32 line_number
,
266 const char *function_name
,
267 const char *module_name
, u32 component_id
)
270 acpi_gbl_nesting_level
++;
271 acpi_ut_track_stack_ptr();
273 acpi_debug_print(ACPI_LV_FUNCTIONS
,
274 line_number
, function_name
, module_name
, component_id
,
275 "%s\n", acpi_gbl_fn_entry_str
);
278 ACPI_EXPORT_SYMBOL(acpi_ut_trace
)
280 /*******************************************************************************
282 * FUNCTION: acpi_ut_trace_ptr
284 * PARAMETERS: line_number - Caller's line number
285 * function_name - Caller's procedure name
286 * module_name - Caller's module name
287 * component_id - Caller's component ID
288 * Pointer - Pointer to display
292 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
295 ******************************************************************************/
297 acpi_ut_trace_ptr(u32 line_number
,
298 const char *function_name
,
299 const char *module_name
, u32 component_id
, void *pointer
)
301 acpi_gbl_nesting_level
++;
302 acpi_ut_track_stack_ptr();
304 acpi_debug_print(ACPI_LV_FUNCTIONS
,
305 line_number
, function_name
, module_name
, component_id
,
306 "%s %p\n", acpi_gbl_fn_entry_str
, pointer
);
309 /*******************************************************************************
311 * FUNCTION: acpi_ut_trace_str
313 * PARAMETERS: line_number - Caller's line number
314 * function_name - Caller's procedure name
315 * module_name - Caller's module name
316 * component_id - Caller's component ID
317 * String - Additional string to display
321 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
324 ******************************************************************************/
327 acpi_ut_trace_str(u32 line_number
,
328 const char *function_name
,
329 const char *module_name
, u32 component_id
, char *string
)
332 acpi_gbl_nesting_level
++;
333 acpi_ut_track_stack_ptr();
335 acpi_debug_print(ACPI_LV_FUNCTIONS
,
336 line_number
, function_name
, module_name
, component_id
,
337 "%s %s\n", acpi_gbl_fn_entry_str
, string
);
340 /*******************************************************************************
342 * FUNCTION: acpi_ut_trace_u32
344 * PARAMETERS: line_number - Caller's line number
345 * function_name - Caller's procedure name
346 * module_name - Caller's module name
347 * component_id - Caller's component ID
348 * Integer - Integer to display
352 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
355 ******************************************************************************/
358 acpi_ut_trace_u32(u32 line_number
,
359 const char *function_name
,
360 const char *module_name
, u32 component_id
, u32 integer
)
363 acpi_gbl_nesting_level
++;
364 acpi_ut_track_stack_ptr();
366 acpi_debug_print(ACPI_LV_FUNCTIONS
,
367 line_number
, function_name
, module_name
, component_id
,
368 "%s %08X\n", acpi_gbl_fn_entry_str
, integer
);
371 /*******************************************************************************
373 * FUNCTION: acpi_ut_exit
375 * PARAMETERS: line_number - Caller's line number
376 * function_name - Caller's procedure name
377 * module_name - Caller's module name
378 * component_id - Caller's component ID
382 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
385 ******************************************************************************/
388 acpi_ut_exit(u32 line_number
,
389 const char *function_name
,
390 const char *module_name
, u32 component_id
)
393 acpi_debug_print(ACPI_LV_FUNCTIONS
,
394 line_number
, function_name
, module_name
, component_id
,
395 "%s\n", acpi_gbl_fn_exit_str
);
397 acpi_gbl_nesting_level
--;
400 ACPI_EXPORT_SYMBOL(acpi_ut_exit
)
402 /*******************************************************************************
404 * FUNCTION: acpi_ut_status_exit
406 * PARAMETERS: line_number - Caller's line number
407 * function_name - Caller's procedure name
408 * module_name - Caller's module name
409 * component_id - Caller's component ID
410 * Status - Exit status code
414 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
415 * set in debug_level. Prints exit status also.
417 ******************************************************************************/
419 acpi_ut_status_exit(u32 line_number
,
420 const char *function_name
,
421 const char *module_name
,
422 u32 component_id
, acpi_status status
)
425 if (ACPI_SUCCESS(status
)) {
426 acpi_debug_print(ACPI_LV_FUNCTIONS
,
427 line_number
, function_name
, module_name
,
428 component_id
, "%s %s\n", acpi_gbl_fn_exit_str
,
429 acpi_format_exception(status
));
431 acpi_debug_print(ACPI_LV_FUNCTIONS
,
432 line_number
, function_name
, module_name
,
433 component_id
, "%s ****Exception****: %s\n",
434 acpi_gbl_fn_exit_str
,
435 acpi_format_exception(status
));
438 acpi_gbl_nesting_level
--;
441 ACPI_EXPORT_SYMBOL(acpi_ut_status_exit
)
443 /*******************************************************************************
445 * FUNCTION: acpi_ut_value_exit
447 * PARAMETERS: line_number - Caller's line number
448 * function_name - Caller's procedure name
449 * module_name - Caller's module name
450 * component_id - Caller's component ID
451 * Value - Value to be printed with exit msg
455 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
456 * set in debug_level. Prints exit value also.
458 ******************************************************************************/
460 acpi_ut_value_exit(u32 line_number
,
461 const char *function_name
,
462 const char *module_name
, u32 component_id
, u64 value
)
465 acpi_debug_print(ACPI_LV_FUNCTIONS
,
466 line_number
, function_name
, module_name
, component_id
,
467 "%s %8.8X%8.8X\n", acpi_gbl_fn_exit_str
,
468 ACPI_FORMAT_UINT64(value
));
470 acpi_gbl_nesting_level
--;
473 ACPI_EXPORT_SYMBOL(acpi_ut_value_exit
)
475 /*******************************************************************************
477 * FUNCTION: acpi_ut_ptr_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 * Ptr - Pointer to display
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_ptr_exit(u32 line_number
,
493 const char *function_name
,
494 const char *module_name
, u32 component_id
, u8
*ptr
)
497 acpi_debug_print(ACPI_LV_FUNCTIONS
,
498 line_number
, function_name
, module_name
, component_id
,
499 "%s %p\n", acpi_gbl_fn_exit_str
, ptr
);
501 acpi_gbl_nesting_level
--;
506 /*******************************************************************************
508 * FUNCTION: acpi_ut_dump_buffer
510 * PARAMETERS: Buffer - Buffer to dump
511 * Count - Amount to dump, in bytes
512 * Display - BYTE, WORD, DWORD, or QWORD display
513 * component_iD - Caller's component ID
517 * DESCRIPTION: Generic dump buffer in both hex and ascii.
519 ******************************************************************************/
521 void acpi_ut_dump_buffer2(u8
* buffer
, u32 count
, u32 display
)
529 acpi_os_printf("Null Buffer Pointer in DumpBuffer!\n");
533 if ((count
< 4) || (count
& 0x01)) {
534 display
= DB_BYTE_DISPLAY
;
537 /* Nasty little dump buffer routine! */
541 /* Print current offset */
543 acpi_os_printf("%6.4X: ", i
);
545 /* Print 16 hex chars */
547 for (j
= 0; j
< 16;) {
548 if (i
+ j
>= count
) {
550 /* Dump fill spaces */
552 acpi_os_printf("%*s", ((display
* 2) + 1), " ");
558 case DB_BYTE_DISPLAY
:
559 default: /* Default is BYTE display */
561 acpi_os_printf("%02X ",
562 buffer
[(acpi_size
) i
+ j
]);
565 case DB_WORD_DISPLAY
:
567 ACPI_MOVE_16_TO_32(&temp32
,
568 &buffer
[(acpi_size
) i
+ j
]);
569 acpi_os_printf("%04X ", temp32
);
572 case DB_DWORD_DISPLAY
:
574 ACPI_MOVE_32_TO_32(&temp32
,
575 &buffer
[(acpi_size
) i
+ j
]);
576 acpi_os_printf("%08X ", temp32
);
579 case DB_QWORD_DISPLAY
:
581 ACPI_MOVE_32_TO_32(&temp32
,
582 &buffer
[(acpi_size
) i
+ j
]);
583 acpi_os_printf("%08X", temp32
);
585 ACPI_MOVE_32_TO_32(&temp32
,
586 &buffer
[(acpi_size
) i
+ j
+
588 acpi_os_printf("%08X ", temp32
);
596 * Print the ASCII equivalent characters but watch out for the bad
597 * unprintable ones (printable chars are 0x20 through 0x7E)
600 for (j
= 0; j
< 16; j
++) {
601 if (i
+ j
>= count
) {
602 acpi_os_printf("\n");
606 buf_char
= buffer
[(acpi_size
) i
+ j
];
607 if (ACPI_IS_PRINT(buf_char
)) {
608 acpi_os_printf("%c", buf_char
);
614 /* Done with that line. */
616 acpi_os_printf("\n");
623 /*******************************************************************************
625 * FUNCTION: acpi_ut_dump_buffer
627 * PARAMETERS: Buffer - Buffer to dump
628 * Count - Amount to dump, in bytes
629 * Display - BYTE, WORD, DWORD, or QWORD display
630 * component_iD - Caller's component ID
634 * DESCRIPTION: Generic dump buffer in both hex and ascii.
636 ******************************************************************************/
638 void acpi_ut_dump_buffer(u8
* buffer
, u32 count
, u32 display
, u32 component_id
)
641 /* Only dump the buffer if tracing is enabled */
643 if (!((ACPI_LV_TABLES
& acpi_dbg_level
) &&
644 (component_id
& acpi_dbg_layer
))) {
648 acpi_ut_dump_buffer2(buffer
, count
, display
);