1 /******************************************************************************
3 * Module Name: utdebug - Debug print routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2007, 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 <acpi/acpi.h>
46 #define _COMPONENT ACPI_UTILITIES
47 ACPI_MODULE_NAME("utdebug")
48 #ifdef ACPI_DEBUG_OUTPUT
49 static acpi_thread_id acpi_gbl_prev_thread_id
;
50 static char *acpi_gbl_fn_entry_str
= "----Entry";
51 static char *acpi_gbl_fn_exit_str
= "----Exit-";
53 /* Local prototypes */
55 static const char *acpi_ut_trim_function_name(const char *function_name
);
57 /*******************************************************************************
59 * FUNCTION: acpi_ut_init_stack_ptr_trace
65 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
67 ******************************************************************************/
69 void acpi_ut_init_stack_ptr_trace(void)
73 acpi_gbl_entry_stack_pointer
= ¤t_sp
;
76 /*******************************************************************************
78 * FUNCTION: acpi_ut_track_stack_ptr
84 * DESCRIPTION: Save the current CPU stack pointer
86 ******************************************************************************/
88 void acpi_ut_track_stack_ptr(void)
92 if (¤t_sp
< acpi_gbl_lowest_stack_pointer
) {
93 acpi_gbl_lowest_stack_pointer
= ¤t_sp
;
96 if (acpi_gbl_nesting_level
> acpi_gbl_deepest_nesting
) {
97 acpi_gbl_deepest_nesting
= acpi_gbl_nesting_level
;
101 /*******************************************************************************
103 * FUNCTION: acpi_ut_trim_function_name
105 * PARAMETERS: function_name - Ascii string containing a procedure name
107 * RETURN: Updated pointer to the function name
109 * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
110 * This allows compiler macros such as __func__ to be used
111 * with no change to the debug output.
113 ******************************************************************************/
115 static const char *acpi_ut_trim_function_name(const char *function_name
)
118 /* All Function names are longer than 4 chars, check is safe */
120 if (*(ACPI_CAST_PTR(u32
, function_name
)) == ACPI_PREFIX_MIXED
) {
122 /* This is the case where the original source has not been modified */
124 return (function_name
+ 4);
127 if (*(ACPI_CAST_PTR(u32
, function_name
)) == ACPI_PREFIX_LOWER
) {
129 /* This is the case where the source has been 'linuxized' */
131 return (function_name
+ 5);
134 return (function_name
);
137 /*******************************************************************************
139 * FUNCTION: acpi_ut_debug_print
141 * PARAMETERS: requested_debug_level - Requested debug print level
142 * line_number - Caller's line number (for error output)
143 * function_name - Caller's procedure name
144 * module_name - Caller's module name
145 * component_id - Caller's component ID
146 * Format - Printf format field
147 * ... - Optional printf arguments
151 * DESCRIPTION: Print error message with prefix consisting of the module name,
152 * line number, and component ID.
154 ******************************************************************************/
156 void ACPI_INTERNAL_VAR_XFACE
157 acpi_ut_debug_print(u32 requested_debug_level
,
159 const char *function_name
,
160 char *module_name
, u32 component_id
, char *format
, ...)
162 acpi_thread_id thread_id
;
166 * Stay silent if the debug level or component ID is disabled
168 if (!(requested_debug_level
& acpi_dbg_level
) ||
169 !(component_id
& acpi_dbg_layer
)) {
174 * Thread tracking and context switch notification
176 thread_id
= acpi_os_get_thread_id();
177 if (thread_id
!= acpi_gbl_prev_thread_id
) {
178 if (ACPI_LV_THREADS
& acpi_dbg_level
) {
180 ("\n**** Context Switch from TID %lX to TID %lX ****\n\n",
181 (unsigned long)acpi_gbl_prev_thread_id
,
182 (unsigned long)thread_id
);
185 acpi_gbl_prev_thread_id
= thread_id
;
189 * Display the module name, current line number, thread ID (if requested),
190 * current procedure nesting level, and the current procedure name
192 acpi_os_printf("%8s-%04ld ", module_name
, line_number
);
194 if (ACPI_LV_THREADS
& acpi_dbg_level
) {
195 acpi_os_printf("[%04lX] ", (unsigned long)thread_id
);
198 acpi_os_printf("[%02ld] %-22.22s: ",
199 acpi_gbl_nesting_level
,
200 acpi_ut_trim_function_name(function_name
));
202 va_start(args
, format
);
203 acpi_os_vprintf(format
, args
);
206 ACPI_EXPORT_SYMBOL(acpi_ut_debug_print
)
208 /*******************************************************************************
210 * FUNCTION: acpi_ut_debug_print_raw
212 * PARAMETERS: requested_debug_level - Requested debug print level
213 * line_number - Caller's line number
214 * function_name - Caller's procedure name
215 * module_name - Caller's module name
216 * component_id - Caller's component ID
217 * Format - Printf format field
218 * ... - Optional printf arguments
222 * DESCRIPTION: Print message with no headers. Has same interface as
223 * debug_print so that the same macros can be used.
225 ******************************************************************************/
226 void ACPI_INTERNAL_VAR_XFACE
227 acpi_ut_debug_print_raw(u32 requested_debug_level
,
229 const char *function_name
,
230 char *module_name
, u32 component_id
, char *format
, ...)
234 if (!(requested_debug_level
& acpi_dbg_level
) ||
235 !(component_id
& acpi_dbg_layer
)) {
239 va_start(args
, format
);
240 acpi_os_vprintf(format
, args
);
243 ACPI_EXPORT_SYMBOL(acpi_ut_debug_print_raw
)
245 /*******************************************************************************
247 * FUNCTION: acpi_ut_trace
249 * PARAMETERS: line_number - Caller's line number
250 * function_name - Caller's procedure name
251 * module_name - Caller's module name
252 * component_id - Caller's component ID
256 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
259 ******************************************************************************/
261 acpi_ut_trace(u32 line_number
,
262 const char *function_name
, char *module_name
, u32 component_id
)
265 acpi_gbl_nesting_level
++;
266 acpi_ut_track_stack_ptr();
268 acpi_ut_debug_print(ACPI_LV_FUNCTIONS
,
269 line_number
, function_name
, module_name
,
270 component_id
, "%s\n", acpi_gbl_fn_entry_str
);
273 ACPI_EXPORT_SYMBOL(acpi_ut_trace
)
275 /*******************************************************************************
277 * FUNCTION: acpi_ut_trace_ptr
279 * PARAMETERS: line_number - Caller's line number
280 * function_name - Caller's procedure name
281 * module_name - Caller's module name
282 * component_id - Caller's component ID
283 * Pointer - Pointer to display
287 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
290 ******************************************************************************/
292 acpi_ut_trace_ptr(u32 line_number
,
293 const char *function_name
,
294 char *module_name
, u32 component_id
, void *pointer
)
296 acpi_gbl_nesting_level
++;
297 acpi_ut_track_stack_ptr();
299 acpi_ut_debug_print(ACPI_LV_FUNCTIONS
,
300 line_number
, function_name
, module_name
,
301 component_id
, "%s %p\n", acpi_gbl_fn_entry_str
,
305 /*******************************************************************************
307 * FUNCTION: acpi_ut_trace_str
309 * PARAMETERS: line_number - Caller's line number
310 * function_name - Caller's procedure name
311 * module_name - Caller's module name
312 * component_id - Caller's component ID
313 * String - Additional string to display
317 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
320 ******************************************************************************/
323 acpi_ut_trace_str(u32 line_number
,
324 const char *function_name
,
325 char *module_name
, u32 component_id
, char *string
)
328 acpi_gbl_nesting_level
++;
329 acpi_ut_track_stack_ptr();
331 acpi_ut_debug_print(ACPI_LV_FUNCTIONS
,
332 line_number
, function_name
, module_name
,
333 component_id
, "%s %s\n", acpi_gbl_fn_entry_str
,
337 /*******************************************************************************
339 * FUNCTION: acpi_ut_trace_u32
341 * PARAMETERS: line_number - Caller's line number
342 * function_name - Caller's procedure name
343 * module_name - Caller's module name
344 * component_id - Caller's component ID
345 * Integer - Integer to display
349 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
352 ******************************************************************************/
355 acpi_ut_trace_u32(u32 line_number
,
356 const char *function_name
,
357 char *module_name
, u32 component_id
, u32 integer
)
360 acpi_gbl_nesting_level
++;
361 acpi_ut_track_stack_ptr();
363 acpi_ut_debug_print(ACPI_LV_FUNCTIONS
,
364 line_number
, function_name
, module_name
,
365 component_id
, "%s %08X\n", acpi_gbl_fn_entry_str
,
369 /*******************************************************************************
371 * FUNCTION: acpi_ut_exit
373 * PARAMETERS: line_number - Caller's line number
374 * function_name - Caller's procedure name
375 * module_name - Caller's module name
376 * component_id - Caller's component ID
380 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
383 ******************************************************************************/
386 acpi_ut_exit(u32 line_number
,
387 const char *function_name
, char *module_name
, u32 component_id
)
390 acpi_ut_debug_print(ACPI_LV_FUNCTIONS
,
391 line_number
, function_name
, module_name
,
392 component_id
, "%s\n", acpi_gbl_fn_exit_str
);
394 acpi_gbl_nesting_level
--;
397 ACPI_EXPORT_SYMBOL(acpi_ut_exit
)
399 /*******************************************************************************
401 * FUNCTION: acpi_ut_status_exit
403 * PARAMETERS: line_number - Caller's line number
404 * function_name - Caller's procedure name
405 * module_name - Caller's module name
406 * component_id - Caller's component ID
407 * Status - Exit status code
411 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
412 * set in debug_level. Prints exit status also.
414 ******************************************************************************/
416 acpi_ut_status_exit(u32 line_number
,
417 const char *function_name
,
418 char *module_name
, u32 component_id
, acpi_status status
)
421 if (ACPI_SUCCESS(status
)) {
422 acpi_ut_debug_print(ACPI_LV_FUNCTIONS
,
423 line_number
, function_name
, module_name
,
424 component_id
, "%s %s\n",
425 acpi_gbl_fn_exit_str
,
426 acpi_format_exception(status
));
428 acpi_ut_debug_print(ACPI_LV_FUNCTIONS
,
429 line_number
, function_name
, module_name
,
430 component_id
, "%s ****Exception****: %s\n",
431 acpi_gbl_fn_exit_str
,
432 acpi_format_exception(status
));
435 acpi_gbl_nesting_level
--;
438 ACPI_EXPORT_SYMBOL(acpi_ut_status_exit
)
440 /*******************************************************************************
442 * FUNCTION: acpi_ut_value_exit
444 * PARAMETERS: line_number - Caller's line number
445 * function_name - Caller's procedure name
446 * module_name - Caller's module name
447 * component_id - Caller's component ID
448 * Value - Value to be printed with exit msg
452 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
453 * set in debug_level. Prints exit value also.
455 ******************************************************************************/
457 acpi_ut_value_exit(u32 line_number
,
458 const char *function_name
,
459 char *module_name
, u32 component_id
, acpi_integer value
)
462 acpi_ut_debug_print(ACPI_LV_FUNCTIONS
,
463 line_number
, function_name
, module_name
,
464 component_id
, "%s %8.8X%8.8X\n",
465 acpi_gbl_fn_exit_str
, ACPI_FORMAT_UINT64(value
));
467 acpi_gbl_nesting_level
--;
470 ACPI_EXPORT_SYMBOL(acpi_ut_value_exit
)
472 /*******************************************************************************
474 * FUNCTION: acpi_ut_ptr_exit
476 * PARAMETERS: line_number - Caller's line number
477 * function_name - Caller's procedure name
478 * module_name - Caller's module name
479 * component_id - Caller's component ID
480 * Ptr - Pointer to display
484 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
485 * set in debug_level. Prints exit value also.
487 ******************************************************************************/
489 acpi_ut_ptr_exit(u32 line_number
,
490 const char *function_name
,
491 char *module_name
, u32 component_id
, u8
* ptr
)
494 acpi_ut_debug_print(ACPI_LV_FUNCTIONS
,
495 line_number
, function_name
, module_name
,
496 component_id
, "%s %p\n", acpi_gbl_fn_exit_str
, ptr
);
498 acpi_gbl_nesting_level
--;
503 /*******************************************************************************
505 * FUNCTION: acpi_ut_dump_buffer
507 * PARAMETERS: Buffer - Buffer to dump
508 * Count - Amount to dump, in bytes
509 * Display - BYTE, WORD, DWORD, or QWORD display
510 * component_iD - Caller's component ID
514 * DESCRIPTION: Generic dump buffer in both hex and ascii.
516 ******************************************************************************/
518 void acpi_ut_dump_buffer2(u8
* buffer
, u32 count
, u32 display
)
520 acpi_native_uint i
= 0;
526 acpi_os_printf("Null Buffer Pointer in DumpBuffer!\n");
530 if ((count
< 4) || (count
& 0x01)) {
531 display
= DB_BYTE_DISPLAY
;
534 /* Nasty little dump buffer routine! */
538 /* Print current offset */
540 acpi_os_printf("%6.4X: ", (u32
) i
);
542 /* Print 16 hex chars */
544 for (j
= 0; j
< 16;) {
545 if (i
+ j
>= count
) {
547 /* Dump fill spaces */
549 acpi_os_printf("%*s", ((display
* 2) + 1), " ");
550 j
+= (acpi_native_uint
) display
;
555 case DB_BYTE_DISPLAY
:
556 default: /* Default is BYTE display */
558 acpi_os_printf("%02X ", buffer
[i
+ j
]);
561 case DB_WORD_DISPLAY
:
563 ACPI_MOVE_16_TO_32(&temp32
, &buffer
[i
+ j
]);
564 acpi_os_printf("%04X ", temp32
);
567 case DB_DWORD_DISPLAY
:
569 ACPI_MOVE_32_TO_32(&temp32
, &buffer
[i
+ j
]);
570 acpi_os_printf("%08X ", temp32
);
573 case DB_QWORD_DISPLAY
:
575 ACPI_MOVE_32_TO_32(&temp32
, &buffer
[i
+ j
]);
576 acpi_os_printf("%08X", temp32
);
578 ACPI_MOVE_32_TO_32(&temp32
, &buffer
[i
+ j
+ 4]);
579 acpi_os_printf("%08X ", temp32
);
583 j
+= (acpi_native_uint
) display
;
587 * Print the ASCII equivalent characters but watch out for the bad
588 * unprintable ones (printable chars are 0x20 through 0x7E)
591 for (j
= 0; j
< 16; j
++) {
592 if (i
+ j
>= count
) {
593 acpi_os_printf("\n");
597 buf_char
= buffer
[i
+ j
];
598 if (ACPI_IS_PRINT(buf_char
)) {
599 acpi_os_printf("%c", buf_char
);
605 /* Done with that line. */
607 acpi_os_printf("\n");
614 /*******************************************************************************
616 * FUNCTION: acpi_ut_dump_buffer
618 * PARAMETERS: Buffer - Buffer to dump
619 * Count - Amount to dump, in bytes
620 * Display - BYTE, WORD, DWORD, or QWORD display
621 * component_iD - Caller's component ID
625 * DESCRIPTION: Generic dump buffer in both hex and ascii.
627 ******************************************************************************/
629 void acpi_ut_dump_buffer(u8
* buffer
, u32 count
, u32 display
, u32 component_id
)
632 /* Only dump the buffer if tracing is enabled */
634 if (!((ACPI_LV_TABLES
& acpi_dbg_level
) &&
635 (component_id
& acpi_dbg_layer
))) {
639 acpi_ut_dump_buffer2(buffer
, count
, display
);