1 /******************************************************************************
3 * Module Name: utdebug - Debug print routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2005, R. Byron Moore
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 <linux/module.h>
46 #include <acpi/acpi.h>
48 #define _COMPONENT ACPI_UTILITIES
49 ACPI_MODULE_NAME ("utdebug")
52 #ifdef ACPI_DEBUG_OUTPUT
54 static u32 acpi_gbl_prev_thread_id = 0xFFFFFFFF;
55 static char *acpi_gbl_fn_entry_str = "----Entry";
56 static char *acpi_gbl_fn_exit_str = "----Exit-";
58 /* Local prototypes */
61 acpi_ut_trim_function_name (
62 const char *function_name);
65 /*******************************************************************************
67 * FUNCTION: acpi_ut_init_stack_ptr_trace
73 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
75 ******************************************************************************/
78 acpi_ut_init_stack_ptr_trace (
84 acpi_gbl_entry_stack_pointer = ACPI_PTR_DIFF (¤t_sp, NULL);
88 /*******************************************************************************
90 * FUNCTION: acpi_ut_track_stack_ptr
96 * DESCRIPTION: Save the current CPU stack pointer
98 ******************************************************************************/
101 acpi_ut_track_stack_ptr (
104 acpi_size current_sp;
107 current_sp = ACPI_PTR_DIFF (¤t_sp, NULL);
109 if (current_sp < acpi_gbl_lowest_stack_pointer) {
110 acpi_gbl_lowest_stack_pointer = current_sp;
113 if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) {
114 acpi_gbl_deepest_nesting = acpi_gbl_nesting_level;
119 /*******************************************************************************
121 * FUNCTION: acpi_ut_trim_function_name
123 * PARAMETERS: function_name - Ascii string containing a procedure name
125 * RETURN: Updated pointer to the function name
127 * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
128 * This allows compiler macros such as __FUNCTION__ to be used
129 * with no change to the debug output.
131 ******************************************************************************/
134 acpi_ut_trim_function_name (
135 const char *function_name)
138 /* All Function names are longer than 4 chars, check is safe */
140 if (*(ACPI_CAST_PTR (u32, function_name)) == ACPI_FUNCTION_PREFIX1) {
141 /* This is the case where the original source has not been modified */
143 return (function_name + 4);
146 if (*(ACPI_CAST_PTR (u32, function_name)) == ACPI_FUNCTION_PREFIX2) {
147 /* This is the case where the source has been 'linuxized' */
149 return (function_name + 5);
152 return (function_name);
156 /*******************************************************************************
158 * FUNCTION: acpi_ut_debug_print
160 * PARAMETERS: requested_debug_level - Requested debug print level
161 * line_number - Caller's line number (for error output)
162 * function_name - Caller's procedure name
163 * module_name - Caller's module name
164 * component_id - Caller's component ID
165 * Format - Printf format field
166 * ... - Optional printf arguments
170 * DESCRIPTION: Print error message with prefix consisting of the module name,
171 * line number, and component ID.
173 ******************************************************************************/
175 void ACPI_INTERNAL_VAR_XFACE
176 acpi_ut_debug_print (
177 u32 requested_debug_level,
179 const char *function_name,
190 * Stay silent if the debug level or component ID is disabled
192 if (!(requested_debug_level & acpi_dbg_level) ||
193 !(component_id & acpi_dbg_layer)) {
198 * Thread tracking and context switch notification
200 thread_id = acpi_os_get_thread_id ();
202 if (thread_id != acpi_gbl_prev_thread_id) {
203 if (ACPI_LV_THREADS & acpi_dbg_level) {
205 "\n**** Context Switch from TID %X to TID %X ****\n\n",
206 acpi_gbl_prev_thread_id, thread_id);
209 acpi_gbl_prev_thread_id = thread_id;
213 * Display the module name, current line number, thread ID (if requested),
214 * current procedure nesting level, and the current procedure name
216 acpi_os_printf ("%8s-%04ld ", module_name, line_number);
218 if (ACPI_LV_THREADS & acpi_dbg_level) {
219 acpi_os_printf ("[%04lX] ", thread_id);
222 acpi_os_printf ("[%02ld] %-22.22s: ",
223 acpi_gbl_nesting_level, acpi_ut_trim_function_name (function_name));
225 va_start (args, format);
226 acpi_os_vprintf (format, args);
229 EXPORT_SYMBOL(acpi_ut_debug_print);
231 /*******************************************************************************
233 * FUNCTION: acpi_ut_debug_print_raw
235 * PARAMETERS: requested_debug_level - Requested debug print level
236 * line_number - Caller's line number
237 * function_name - Caller's procedure name
238 * module_name - Caller's module name
239 * component_id - Caller's component ID
240 * Format - Printf format field
241 * ... - Optional printf arguments
245 * DESCRIPTION: Print message with no headers. Has same interface as
246 * debug_print so that the same macros can be used.
248 ******************************************************************************/
250 void ACPI_INTERNAL_VAR_XFACE
251 acpi_ut_debug_print_raw (
252 u32 requested_debug_level,
254 const char *function_name,
263 if (!(requested_debug_level & acpi_dbg_level) ||
264 !(component_id & acpi_dbg_layer)) {
268 va_start (args, format);
269 acpi_os_vprintf (format, args);
271 EXPORT_SYMBOL(acpi_ut_debug_print_raw);
274 /*******************************************************************************
276 * FUNCTION: acpi_ut_trace
278 * PARAMETERS: line_number - Caller's line number
279 * function_name - Caller's procedure name
280 * module_name - Caller's module name
281 * component_id - Caller's component ID
285 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
288 ******************************************************************************/
293 const char *function_name,
298 acpi_gbl_nesting_level++;
299 acpi_ut_track_stack_ptr ();
301 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
302 line_number, function_name, module_name, component_id,
303 "%s\n", acpi_gbl_fn_entry_str);
305 EXPORT_SYMBOL(acpi_ut_trace);
308 /*******************************************************************************
310 * FUNCTION: acpi_ut_trace_ptr
312 * PARAMETERS: line_number - Caller's line number
313 * function_name - Caller's procedure name
314 * module_name - Caller's module name
315 * component_id - Caller's component ID
316 * Pointer - Pointer to display
320 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
323 ******************************************************************************/
328 const char *function_name,
333 acpi_gbl_nesting_level++;
334 acpi_ut_track_stack_ptr ();
336 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
337 line_number, function_name, module_name, component_id,
338 "%s %p\n", acpi_gbl_fn_entry_str, pointer);
342 /*******************************************************************************
344 * FUNCTION: acpi_ut_trace_str
346 * PARAMETERS: line_number - Caller's line number
347 * function_name - Caller's procedure name
348 * module_name - Caller's module name
349 * component_id - Caller's component ID
350 * String - Additional string to display
354 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
357 ******************************************************************************/
362 const char *function_name,
368 acpi_gbl_nesting_level++;
369 acpi_ut_track_stack_ptr ();
371 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
372 line_number, function_name, module_name, component_id,
373 "%s %s\n", acpi_gbl_fn_entry_str, string);
377 /*******************************************************************************
379 * FUNCTION: acpi_ut_trace_u32
381 * PARAMETERS: line_number - Caller's line number
382 * function_name - Caller's procedure name
383 * module_name - Caller's module name
384 * component_id - Caller's component ID
385 * Integer - Integer to display
389 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
392 ******************************************************************************/
397 const char *function_name,
403 acpi_gbl_nesting_level++;
404 acpi_ut_track_stack_ptr ();
406 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
407 line_number, function_name, module_name, component_id,
408 "%s %08X\n", acpi_gbl_fn_entry_str, integer);
412 /*******************************************************************************
414 * FUNCTION: acpi_ut_exit
416 * PARAMETERS: line_number - Caller's line number
417 * function_name - Caller's procedure name
418 * module_name - Caller's module name
419 * component_id - Caller's component ID
423 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
426 ******************************************************************************/
431 const char *function_name,
436 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
437 line_number, function_name, module_name, component_id,
438 "%s\n", acpi_gbl_fn_exit_str);
440 acpi_gbl_nesting_level--;
442 EXPORT_SYMBOL(acpi_ut_exit);
445 /*******************************************************************************
447 * FUNCTION: acpi_ut_status_exit
449 * PARAMETERS: line_number - Caller's line number
450 * function_name - Caller's procedure name
451 * module_name - Caller's module name
452 * component_id - Caller's component ID
453 * Status - Exit status code
457 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
458 * set in debug_level. Prints exit status also.
460 ******************************************************************************/
463 acpi_ut_status_exit (
465 const char *function_name,
471 if (ACPI_SUCCESS (status)) {
472 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
473 line_number, function_name, module_name, component_id,
474 "%s %s\n", acpi_gbl_fn_exit_str,
475 acpi_format_exception (status));
478 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
479 line_number, function_name, module_name, component_id,
480 "%s ****Exception****: %s\n", acpi_gbl_fn_exit_str,
481 acpi_format_exception (status));
484 acpi_gbl_nesting_level--;
486 EXPORT_SYMBOL(acpi_ut_status_exit);
489 /*******************************************************************************
491 * FUNCTION: acpi_ut_value_exit
493 * PARAMETERS: line_number - Caller's line number
494 * function_name - Caller's procedure name
495 * module_name - Caller's module name
496 * component_id - Caller's component ID
497 * Value - Value to be printed with exit msg
501 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
502 * set in debug_level. Prints exit value also.
504 ******************************************************************************/
509 const char *function_name,
515 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
516 line_number, function_name, module_name, component_id,
517 "%s %8.8X%8.8X\n", acpi_gbl_fn_exit_str,
518 ACPI_FORMAT_UINT64 (value));
520 acpi_gbl_nesting_level--;
522 EXPORT_SYMBOL(acpi_ut_value_exit);
525 /*******************************************************************************
527 * FUNCTION: acpi_ut_ptr_exit
529 * PARAMETERS: line_number - Caller's line number
530 * function_name - Caller's procedure name
531 * module_name - Caller's module name
532 * component_id - Caller's component ID
533 * Ptr - Pointer to display
537 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
538 * set in debug_level. Prints exit value also.
540 ******************************************************************************/
545 const char *function_name,
551 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
552 line_number, function_name, module_name, component_id,
553 "%s %p\n", acpi_gbl_fn_exit_str, ptr);
555 acpi_gbl_nesting_level--;
561 /*******************************************************************************
563 * FUNCTION: acpi_ut_dump_buffer
565 * PARAMETERS: Buffer - Buffer to dump
566 * Count - Amount to dump, in bytes
567 * Display - BYTE, WORD, DWORD, or QWORD display
568 * component_iD - Caller's component ID
572 * DESCRIPTION: Generic dump buffer in both hex and ascii.
574 ******************************************************************************/
577 acpi_ut_dump_buffer (
583 acpi_native_uint i = 0;
589 /* Only dump the buffer if tracing is enabled */
591 if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
592 (component_id & acpi_dbg_layer))) {
596 if ((count < 4) || (count & 0x01)) {
597 display = DB_BYTE_DISPLAY;
600 /* Nasty little dump buffer routine! */
603 /* Print current offset */
605 acpi_os_printf ("%6.4X: ", (u32) i);
607 /* Print 16 hex chars */
609 for (j = 0; j < 16;) {
610 if (i + j >= count) {
611 /* Dump fill spaces */
613 acpi_os_printf ("%*s", ((display * 2) + 1), " ");
614 j += (acpi_native_uint) display;
619 default: /* Default is BYTE display */
621 acpi_os_printf ("%02X ", buffer[i + j]);
625 case DB_WORD_DISPLAY:
627 ACPI_MOVE_16_TO_32 (&temp32, &buffer[i + j]);
628 acpi_os_printf ("%04X ", temp32);
632 case DB_DWORD_DISPLAY:
634 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]);
635 acpi_os_printf ("%08X ", temp32);
639 case DB_QWORD_DISPLAY:
641 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]);
642 acpi_os_printf ("%08X", temp32);
644 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j + 4]);
645 acpi_os_printf ("%08X ", temp32);
649 j += (acpi_native_uint) display;
653 * Print the ASCII equivalent characters but watch out for the bad
654 * unprintable ones (printable chars are 0x20 through 0x7E)
656 acpi_os_printf (" ");
657 for (j = 0; j < 16; j++) {
658 if (i + j >= count) {
659 acpi_os_printf ("\n");
663 buf_char = buffer[i + j];
664 if (ACPI_IS_PRINT (buf_char)) {
665 acpi_os_printf ("%c", buf_char);
668 acpi_os_printf (".");
672 /* Done with that line. */
674 acpi_os_printf ("\n");