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-";
59 /*****************************************************************************
61 * FUNCTION: acpi_ut_init_stack_ptr_trace
67 * DESCRIPTION: Save the current stack pointer
69 ****************************************************************************/
72 acpi_ut_init_stack_ptr_trace (
78 acpi_gbl_entry_stack_pointer
= ACPI_PTR_DIFF (¤t_sp
, NULL
);
82 /*****************************************************************************
84 * FUNCTION: acpi_ut_track_stack_ptr
90 * DESCRIPTION: Save the current stack pointer
92 ****************************************************************************/
95 acpi_ut_track_stack_ptr (
101 current_sp
= ACPI_PTR_DIFF (¤t_sp
, NULL
);
103 if (current_sp
< acpi_gbl_lowest_stack_pointer
) {
104 acpi_gbl_lowest_stack_pointer
= current_sp
;
107 if (acpi_gbl_nesting_level
> acpi_gbl_deepest_nesting
) {
108 acpi_gbl_deepest_nesting
= acpi_gbl_nesting_level
;
113 /*****************************************************************************
115 * FUNCTION: acpi_ut_debug_print
117 * PARAMETERS: debug_level - Requested debug print level
118 * proc_name - Caller's procedure name
119 * module_name - Caller's module name (for error output)
120 * line_number - Caller's line number (for error output)
121 * component_id - Caller's component ID (for error output)
123 * Format - Printf format field
124 * ... - Optional printf arguments
128 * DESCRIPTION: Print error message with prefix consisting of the module name,
129 * line number, and component ID.
131 ****************************************************************************/
133 void ACPI_INTERNAL_VAR_XFACE
134 acpi_ut_debug_print (
135 u32 requested_debug_level
,
137 struct acpi_debug_print_info
*dbg_info
,
146 * Stay silent if the debug level or component ID is disabled
148 if (!(requested_debug_level
& acpi_dbg_level
) ||
149 !(dbg_info
->component_id
& acpi_dbg_layer
)) {
154 * Thread tracking and context switch notification
156 thread_id
= acpi_os_get_thread_id ();
158 if (thread_id
!= acpi_gbl_prev_thread_id
) {
159 if (ACPI_LV_THREADS
& acpi_dbg_level
) {
160 acpi_os_printf ("\n**** Context Switch from TID %X to TID %X ****\n\n",
161 acpi_gbl_prev_thread_id
, thread_id
);
164 acpi_gbl_prev_thread_id
= thread_id
;
168 * Display the module name, current line number, thread ID (if requested),
169 * current procedure nesting level, and the current procedure name
171 acpi_os_printf ("%8s-%04ld ", dbg_info
->module_name
, line_number
);
173 if (ACPI_LV_THREADS
& acpi_dbg_level
) {
174 acpi_os_printf ("[%04lX] ", thread_id
);
177 acpi_os_printf ("[%02ld] %-22.22s: ", acpi_gbl_nesting_level
, dbg_info
->proc_name
);
179 va_start (args
, format
);
180 acpi_os_vprintf (format
, args
);
182 EXPORT_SYMBOL(acpi_ut_debug_print
);
185 /*****************************************************************************
187 * FUNCTION: acpi_ut_debug_print_raw
189 * PARAMETERS: requested_debug_level - Requested debug print level
190 * line_number - Caller's line number
191 * dbg_info - Contains:
192 * proc_name - Caller's procedure name
193 * module_name - Caller's module name
194 * component_id - Caller's component ID
195 * Format - Printf format field
196 * ... - Optional printf arguments
200 * DESCRIPTION: Print message with no headers. Has same interface as
201 * debug_print so that the same macros can be used.
203 ****************************************************************************/
205 void ACPI_INTERNAL_VAR_XFACE
206 acpi_ut_debug_print_raw (
207 u32 requested_debug_level
,
209 struct acpi_debug_print_info
*dbg_info
,
216 if (!(requested_debug_level
& acpi_dbg_level
) ||
217 !(dbg_info
->component_id
& acpi_dbg_layer
)) {
221 va_start (args
, format
);
222 acpi_os_vprintf (format
, args
);
224 EXPORT_SYMBOL(acpi_ut_debug_print_raw
);
227 /*****************************************************************************
229 * FUNCTION: acpi_ut_trace
231 * PARAMETERS: line_number - Caller's line number
232 * dbg_info - Contains:
233 * proc_name - Caller's procedure name
234 * module_name - Caller's module name
235 * component_id - Caller's component ID
239 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
242 ****************************************************************************/
247 struct acpi_debug_print_info
*dbg_info
)
250 acpi_gbl_nesting_level
++;
251 acpi_ut_track_stack_ptr ();
253 acpi_ut_debug_print (ACPI_LV_FUNCTIONS
, line_number
, dbg_info
,
254 "%s\n", acpi_gbl_fn_entry_str
);
256 EXPORT_SYMBOL(acpi_ut_trace
);
259 /*****************************************************************************
261 * FUNCTION: acpi_ut_trace_ptr
263 * PARAMETERS: line_number - Caller's line number
264 * dbg_info - Contains:
265 * proc_name - Caller's procedure name
266 * module_name - Caller's module name
267 * component_id - Caller's component ID
268 * Pointer - Pointer to display
272 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
275 ****************************************************************************/
280 struct acpi_debug_print_info
*dbg_info
,
283 acpi_gbl_nesting_level
++;
284 acpi_ut_track_stack_ptr ();
286 acpi_ut_debug_print (ACPI_LV_FUNCTIONS
, line_number
, dbg_info
,
287 "%s %p\n", acpi_gbl_fn_entry_str
, pointer
);
291 /*****************************************************************************
293 * FUNCTION: acpi_ut_trace_str
295 * PARAMETERS: line_number - Caller's line number
296 * dbg_info - Contains:
297 * proc_name - Caller's procedure name
298 * module_name - Caller's module name
299 * component_id - Caller's component ID
300 * String - Additional string to display
304 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
307 ****************************************************************************/
312 struct acpi_debug_print_info
*dbg_info
,
316 acpi_gbl_nesting_level
++;
317 acpi_ut_track_stack_ptr ();
319 acpi_ut_debug_print (ACPI_LV_FUNCTIONS
, line_number
, dbg_info
,
320 "%s %s\n", acpi_gbl_fn_entry_str
, string
);
324 /*****************************************************************************
326 * FUNCTION: acpi_ut_trace_u32
328 * PARAMETERS: line_number - Caller's line number
329 * dbg_info - Contains:
330 * proc_name - Caller's procedure name
331 * module_name - Caller's module name
332 * component_id - Caller's component ID
333 * Integer - Integer to display
337 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
340 ****************************************************************************/
345 struct acpi_debug_print_info
*dbg_info
,
349 acpi_gbl_nesting_level
++;
350 acpi_ut_track_stack_ptr ();
352 acpi_ut_debug_print (ACPI_LV_FUNCTIONS
, line_number
, dbg_info
,
353 "%s %08X\n", acpi_gbl_fn_entry_str
, integer
);
357 /*****************************************************************************
359 * FUNCTION: acpi_ut_exit
361 * PARAMETERS: line_number - Caller's line number
362 * dbg_info - Contains:
363 * proc_name - Caller's procedure name
364 * module_name - Caller's module name
365 * component_id - Caller's component ID
369 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
372 ****************************************************************************/
377 struct acpi_debug_print_info
*dbg_info
)
380 acpi_ut_debug_print (ACPI_LV_FUNCTIONS
, line_number
, dbg_info
,
381 "%s\n", acpi_gbl_fn_exit_str
);
383 acpi_gbl_nesting_level
--;
385 EXPORT_SYMBOL(acpi_ut_exit
);
388 /*****************************************************************************
390 * FUNCTION: acpi_ut_status_exit
392 * PARAMETERS: line_number - Caller's line number
393 * dbg_info - Contains:
394 * proc_name - Caller's procedure name
395 * module_name - Caller's module name
396 * component_id - Caller's component ID
397 * Status - Exit status code
401 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
402 * set in debug_level. Prints exit status also.
404 ****************************************************************************/
407 acpi_ut_status_exit (
409 struct acpi_debug_print_info
*dbg_info
,
413 if (ACPI_SUCCESS (status
)) {
414 acpi_ut_debug_print (ACPI_LV_FUNCTIONS
, line_number
, dbg_info
,
415 "%s %s\n", acpi_gbl_fn_exit_str
,
416 acpi_format_exception (status
));
419 acpi_ut_debug_print (ACPI_LV_FUNCTIONS
, line_number
, dbg_info
,
420 "%s ****Exception****: %s\n", acpi_gbl_fn_exit_str
,
421 acpi_format_exception (status
));
424 acpi_gbl_nesting_level
--;
426 EXPORT_SYMBOL(acpi_ut_status_exit
);
429 /*****************************************************************************
431 * FUNCTION: acpi_ut_value_exit
433 * PARAMETERS: line_number - Caller's line number
434 * dbg_info - Contains:
435 * proc_name - Caller's procedure name
436 * module_name - Caller's module name
437 * component_id - Caller's component ID
438 * Value - Value to be printed with exit msg
442 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
443 * set in debug_level. Prints exit value also.
445 ****************************************************************************/
450 struct acpi_debug_print_info
*dbg_info
,
454 acpi_ut_debug_print (ACPI_LV_FUNCTIONS
, line_number
, dbg_info
,
455 "%s %8.8X%8.8X\n", acpi_gbl_fn_exit_str
,
456 ACPI_FORMAT_UINT64 (value
));
458 acpi_gbl_nesting_level
--;
460 EXPORT_SYMBOL(acpi_ut_value_exit
);
463 /*****************************************************************************
465 * FUNCTION: acpi_ut_ptr_exit
467 * PARAMETERS: line_number - Caller's line number
468 * dbg_info - Contains:
469 * proc_name - Caller's procedure name
470 * module_name - Caller's module name
471 * component_id - Caller's component ID
472 * Value - Value to be printed with exit msg
476 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
477 * set in debug_level. Prints exit value also.
479 ****************************************************************************/
484 struct acpi_debug_print_info
*dbg_info
,
488 acpi_ut_debug_print (ACPI_LV_FUNCTIONS
, line_number
, dbg_info
,
489 "%s %p\n", acpi_gbl_fn_exit_str
, ptr
);
491 acpi_gbl_nesting_level
--;
497 /*****************************************************************************
499 * FUNCTION: acpi_ut_dump_buffer
501 * PARAMETERS: Buffer - Buffer to dump
502 * Count - Amount to dump, in bytes
503 * Display - BYTE, WORD, DWORD, or QWORD display
504 * component_iD - Caller's component ID
508 * DESCRIPTION: Generic dump buffer in both hex and ascii.
510 ****************************************************************************/
513 acpi_ut_dump_buffer (
519 acpi_native_uint i
= 0;
525 /* Only dump the buffer if tracing is enabled */
527 if (!((ACPI_LV_TABLES
& acpi_dbg_level
) &&
528 (component_id
& acpi_dbg_layer
))) {
532 if ((count
< 4) || (count
& 0x01)) {
533 display
= DB_BYTE_DISPLAY
;
536 acpi_os_printf ("\nOffset Value\n");
539 * Nasty little dump buffer routine!
542 /* Print current offset */
544 acpi_os_printf ("%05X ", (u32
) i
);
546 /* Print 16 hex chars */
548 for (j
= 0; j
< 16;) {
549 if (i
+ j
>= count
) {
550 acpi_os_printf ("\n");
554 /* Make sure that the s8 doesn't get sign-extended! */
557 /* Default is BYTE display */
561 acpi_os_printf ("%02X ",
562 *((u8
*) &buffer
[i
+ j
]));
567 case DB_WORD_DISPLAY
:
569 ACPI_MOVE_16_TO_32 (&temp32
, &buffer
[i
+ j
]);
570 acpi_os_printf ("%04X ", temp32
);
575 case DB_DWORD_DISPLAY
:
577 ACPI_MOVE_32_TO_32 (&temp32
, &buffer
[i
+ j
]);
578 acpi_os_printf ("%08X ", temp32
);
583 case DB_QWORD_DISPLAY
:
585 ACPI_MOVE_32_TO_32 (&temp32
, &buffer
[i
+ j
]);
586 acpi_os_printf ("%08X", temp32
);
588 ACPI_MOVE_32_TO_32 (&temp32
, &buffer
[i
+ j
+ 4]);
589 acpi_os_printf ("%08X ", temp32
);
596 * Print the ASCII equivalent characters
597 * But watch out for the bad unprintable ones...
599 for (j
= 0; j
< 16; j
++) {
600 if (i
+ j
>= count
) {
601 acpi_os_printf ("\n");
605 buf_char
= buffer
[i
+ j
];
606 if ((buf_char
> 0x1F && buf_char
< 0x2E) ||
607 (buf_char
> 0x2F && buf_char
< 0x61) ||
608 (buf_char
> 0x60 && buf_char
< 0x7F)) {
609 acpi_os_printf ("%c", buf_char
);
612 acpi_os_printf (".");
616 /* Done with that line. */
618 acpi_os_printf ("\n");