1 /******************************************************************************
3 * Module Name: utdebug - Debug print routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2012, 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 <linux/export.h>
45 #include <acpi/acpi.h>
48 #define _COMPONENT ACPI_UTILITIES
49 ACPI_MODULE_NAME("utdebug")
51 #ifdef ACPI_DEBUG_OUTPUT
52 static acpi_thread_id acpi_gbl_prev_thread_id
= (acpi_thread_id
) 0xFFFFFFFF;
53 static char *acpi_gbl_fn_entry_str
= "----Entry";
54 static char *acpi_gbl_fn_exit_str
= "----Exit-";
56 /* Local prototypes */
58 static const char *acpi_ut_trim_function_name(const char *function_name
);
60 /*******************************************************************************
62 * FUNCTION: acpi_ut_init_stack_ptr_trace
68 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
70 ******************************************************************************/
72 void acpi_ut_init_stack_ptr_trace(void)
76 acpi_gbl_entry_stack_pointer
= ¤t_sp
;
79 /*******************************************************************************
81 * FUNCTION: acpi_ut_track_stack_ptr
87 * DESCRIPTION: Save the current CPU stack pointer
89 ******************************************************************************/
91 void acpi_ut_track_stack_ptr(void)
95 if (¤t_sp
< acpi_gbl_lowest_stack_pointer
) {
96 acpi_gbl_lowest_stack_pointer
= ¤t_sp
;
99 if (acpi_gbl_nesting_level
> acpi_gbl_deepest_nesting
) {
100 acpi_gbl_deepest_nesting
= acpi_gbl_nesting_level
;
104 /*******************************************************************************
106 * FUNCTION: acpi_ut_trim_function_name
108 * PARAMETERS: function_name - Ascii string containing a procedure name
110 * RETURN: Updated pointer to the function name
112 * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
113 * This allows compiler macros such as __FUNCTION__ to be used
114 * with no change to the debug output.
116 ******************************************************************************/
118 static const char *acpi_ut_trim_function_name(const char *function_name
)
121 /* All Function names are longer than 4 chars, check is safe */
123 if (*(ACPI_CAST_PTR(u32
, function_name
)) == ACPI_PREFIX_MIXED
) {
125 /* This is the case where the original source has not been modified */
127 return (function_name
+ 4);
130 if (*(ACPI_CAST_PTR(u32
, function_name
)) == ACPI_PREFIX_LOWER
) {
132 /* This is the case where the source has been 'linuxized' */
134 return (function_name
+ 5);
137 return (function_name
);
140 /*******************************************************************************
142 * FUNCTION: acpi_debug_print
144 * PARAMETERS: requested_debug_level - Requested debug print level
145 * line_number - Caller's line number (for error output)
146 * function_name - Caller's procedure name
147 * module_name - Caller's module name
148 * component_id - Caller's component ID
149 * format - Printf format field
150 * ... - Optional printf arguments
154 * DESCRIPTION: Print error message with prefix consisting of the module name,
155 * line number, and component ID.
157 ******************************************************************************/
159 void ACPI_INTERNAL_VAR_XFACE
160 acpi_debug_print(u32 requested_debug_level
,
162 const char *function_name
,
163 const char *module_name
,
164 u32 component_id
, const char *format
, ...)
166 acpi_thread_id thread_id
;
170 * Stay silent if the debug level or component ID is disabled
172 if (!(requested_debug_level
& acpi_dbg_level
) ||
173 !(component_id
& acpi_dbg_layer
)) {
178 * Thread tracking and context switch notification
180 thread_id
= acpi_os_get_thread_id();
181 if (thread_id
!= acpi_gbl_prev_thread_id
) {
182 if (ACPI_LV_THREADS
& acpi_dbg_level
) {
184 ("\n**** Context Switch from TID %u to TID %u ****\n\n",
185 (u32
)acpi_gbl_prev_thread_id
, (u32
)thread_id
);
188 acpi_gbl_prev_thread_id
= thread_id
;
192 * Display the module name, current line number, thread ID (if requested),
193 * current procedure nesting level, and the current procedure name
195 acpi_os_printf("%8s-%04ld ", module_name
, line_number
);
197 if (ACPI_LV_THREADS
& acpi_dbg_level
) {
198 acpi_os_printf("[%u] ", (u32
)thread_id
);
201 acpi_os_printf("[%02ld] %-22.22s: ",
202 acpi_gbl_nesting_level
,
203 acpi_ut_trim_function_name(function_name
));
205 va_start(args
, format
);
206 acpi_os_vprintf(format
, args
);
210 ACPI_EXPORT_SYMBOL(acpi_debug_print
)
212 /*******************************************************************************
214 * FUNCTION: acpi_debug_print_raw
216 * PARAMETERS: requested_debug_level - Requested debug print level
217 * line_number - Caller's line number
218 * function_name - Caller's procedure name
219 * module_name - Caller's module name
220 * component_id - Caller's component ID
221 * format - Printf format field
222 * ... - Optional printf arguments
226 * DESCRIPTION: Print message with no headers. Has same interface as
227 * debug_print so that the same macros can be used.
229 ******************************************************************************/
230 void ACPI_INTERNAL_VAR_XFACE
231 acpi_debug_print_raw(u32 requested_debug_level
,
233 const char *function_name
,
234 const char *module_name
,
235 u32 component_id
, const char *format
, ...)
239 if (!(requested_debug_level
& acpi_dbg_level
) ||
240 !(component_id
& acpi_dbg_layer
)) {
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 acpi_debug_print(ACPI_LV_FUNCTIONS
,
276 line_number
, function_name
, module_name
, component_id
,
277 "%s\n", acpi_gbl_fn_entry_str
);
280 ACPI_EXPORT_SYMBOL(acpi_ut_trace
)
282 /*******************************************************************************
284 * FUNCTION: acpi_ut_trace_ptr
286 * PARAMETERS: line_number - Caller's line number
287 * function_name - Caller's procedure name
288 * module_name - Caller's module name
289 * component_id - Caller's component ID
290 * pointer - Pointer to display
294 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
297 ******************************************************************************/
299 acpi_ut_trace_ptr(u32 line_number
,
300 const char *function_name
,
301 const char *module_name
, u32 component_id
, void *pointer
)
304 acpi_gbl_nesting_level
++;
305 acpi_ut_track_stack_ptr();
307 acpi_debug_print(ACPI_LV_FUNCTIONS
,
308 line_number
, function_name
, module_name
, component_id
,
309 "%s %p\n", acpi_gbl_fn_entry_str
, pointer
);
312 /*******************************************************************************
314 * FUNCTION: acpi_ut_trace_str
316 * PARAMETERS: line_number - Caller's line number
317 * function_name - Caller's procedure name
318 * module_name - Caller's module name
319 * component_id - Caller's component ID
320 * string - Additional string to display
324 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
327 ******************************************************************************/
330 acpi_ut_trace_str(u32 line_number
,
331 const char *function_name
,
332 const char *module_name
, u32 component_id
, char *string
)
335 acpi_gbl_nesting_level
++;
336 acpi_ut_track_stack_ptr();
338 acpi_debug_print(ACPI_LV_FUNCTIONS
,
339 line_number
, function_name
, module_name
, component_id
,
340 "%s %s\n", acpi_gbl_fn_entry_str
, string
);
343 /*******************************************************************************
345 * FUNCTION: acpi_ut_trace_u32
347 * PARAMETERS: line_number - Caller's line number
348 * function_name - Caller's procedure name
349 * module_name - Caller's module name
350 * component_id - Caller's component ID
351 * integer - Integer to display
355 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
358 ******************************************************************************/
361 acpi_ut_trace_u32(u32 line_number
,
362 const char *function_name
,
363 const char *module_name
, u32 component_id
, u32 integer
)
366 acpi_gbl_nesting_level
++;
367 acpi_ut_track_stack_ptr();
369 acpi_debug_print(ACPI_LV_FUNCTIONS
,
370 line_number
, function_name
, module_name
, component_id
,
371 "%s %08X\n", acpi_gbl_fn_entry_str
, integer
);
374 /*******************************************************************************
376 * FUNCTION: acpi_ut_exit
378 * PARAMETERS: line_number - Caller's line number
379 * function_name - Caller's procedure name
380 * module_name - Caller's module name
381 * component_id - Caller's component ID
385 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
388 ******************************************************************************/
391 acpi_ut_exit(u32 line_number
,
392 const char *function_name
,
393 const char *module_name
, u32 component_id
)
396 acpi_debug_print(ACPI_LV_FUNCTIONS
,
397 line_number
, function_name
, module_name
, component_id
,
398 "%s\n", acpi_gbl_fn_exit_str
);
400 acpi_gbl_nesting_level
--;
403 ACPI_EXPORT_SYMBOL(acpi_ut_exit
)
405 /*******************************************************************************
407 * FUNCTION: acpi_ut_status_exit
409 * PARAMETERS: line_number - Caller's line number
410 * function_name - Caller's procedure name
411 * module_name - Caller's module name
412 * component_id - Caller's component ID
413 * status - Exit status code
417 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
418 * set in debug_level. Prints exit status also.
420 ******************************************************************************/
422 acpi_ut_status_exit(u32 line_number
,
423 const char *function_name
,
424 const char *module_name
,
425 u32 component_id
, acpi_status status
)
428 if (ACPI_SUCCESS(status
)) {
429 acpi_debug_print(ACPI_LV_FUNCTIONS
,
430 line_number
, function_name
, module_name
,
431 component_id
, "%s %s\n", acpi_gbl_fn_exit_str
,
432 acpi_format_exception(status
));
434 acpi_debug_print(ACPI_LV_FUNCTIONS
,
435 line_number
, function_name
, module_name
,
436 component_id
, "%s ****Exception****: %s\n",
437 acpi_gbl_fn_exit_str
,
438 acpi_format_exception(status
));
441 acpi_gbl_nesting_level
--;
444 ACPI_EXPORT_SYMBOL(acpi_ut_status_exit
)
446 /*******************************************************************************
448 * FUNCTION: acpi_ut_value_exit
450 * PARAMETERS: line_number - Caller's line number
451 * function_name - Caller's procedure name
452 * module_name - Caller's module name
453 * component_id - Caller's component ID
454 * value - Value to be printed with exit msg
458 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
459 * set in debug_level. Prints exit value also.
461 ******************************************************************************/
463 acpi_ut_value_exit(u32 line_number
,
464 const char *function_name
,
465 const char *module_name
, u32 component_id
, u64 value
)
468 acpi_debug_print(ACPI_LV_FUNCTIONS
,
469 line_number
, function_name
, module_name
, component_id
,
470 "%s %8.8X%8.8X\n", acpi_gbl_fn_exit_str
,
471 ACPI_FORMAT_UINT64(value
));
473 acpi_gbl_nesting_level
--;
476 ACPI_EXPORT_SYMBOL(acpi_ut_value_exit
)
478 /*******************************************************************************
480 * FUNCTION: acpi_ut_ptr_exit
482 * PARAMETERS: line_number - Caller's line number
483 * function_name - Caller's procedure name
484 * module_name - Caller's module name
485 * component_id - Caller's component ID
486 * ptr - Pointer to display
490 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
491 * set in debug_level. Prints exit value also.
493 ******************************************************************************/
495 acpi_ut_ptr_exit(u32 line_number
,
496 const char *function_name
,
497 const char *module_name
, u32 component_id
, u8
*ptr
)
500 acpi_debug_print(ACPI_LV_FUNCTIONS
,
501 line_number
, function_name
, module_name
, component_id
,
502 "%s %p\n", acpi_gbl_fn_exit_str
, ptr
);
504 acpi_gbl_nesting_level
--;
509 /*******************************************************************************
511 * FUNCTION: acpi_ut_dump_buffer
513 * PARAMETERS: buffer - Buffer to dump
514 * count - Amount to dump, in bytes
515 * display - BYTE, WORD, DWORD, or QWORD display
516 * offset - Beginning buffer offset (display only)
520 * DESCRIPTION: Generic dump buffer in both hex and ascii.
522 ******************************************************************************/
524 void acpi_ut_dump_buffer(u8
*buffer
, u32 count
, u32 display
, u32 base_offset
)
532 acpi_os_printf("Null Buffer Pointer in DumpBuffer!\n");
536 if ((count
< 4) || (count
& 0x01)) {
537 display
= DB_BYTE_DISPLAY
;
540 /* Nasty little dump buffer routine! */
544 /* Print current offset */
546 acpi_os_printf("%6.4X: ", (base_offset
+ i
));
548 /* Print 16 hex chars */
550 for (j
= 0; j
< 16;) {
551 if (i
+ j
>= count
) {
553 /* Dump fill spaces */
555 acpi_os_printf("%*s", ((display
* 2) + 1), " ");
561 case DB_BYTE_DISPLAY
:
562 default: /* Default is BYTE display */
564 acpi_os_printf("%02X ",
565 buffer
[(acpi_size
) i
+ j
]);
568 case DB_WORD_DISPLAY
:
570 ACPI_MOVE_16_TO_32(&temp32
,
571 &buffer
[(acpi_size
) i
+ j
]);
572 acpi_os_printf("%04X ", temp32
);
575 case DB_DWORD_DISPLAY
:
577 ACPI_MOVE_32_TO_32(&temp32
,
578 &buffer
[(acpi_size
) i
+ j
]);
579 acpi_os_printf("%08X ", temp32
);
582 case DB_QWORD_DISPLAY
:
584 ACPI_MOVE_32_TO_32(&temp32
,
585 &buffer
[(acpi_size
) i
+ j
]);
586 acpi_os_printf("%08X", temp32
);
588 ACPI_MOVE_32_TO_32(&temp32
,
589 &buffer
[(acpi_size
) i
+ j
+
591 acpi_os_printf("%08X ", temp32
);
599 * Print the ASCII equivalent characters but watch out for the bad
600 * unprintable ones (printable chars are 0x20 through 0x7E)
603 for (j
= 0; j
< 16; j
++) {
604 if (i
+ j
>= count
) {
605 acpi_os_printf("\n");
609 buf_char
= buffer
[(acpi_size
) i
+ j
];
610 if (ACPI_IS_PRINT(buf_char
)) {
611 acpi_os_printf("%c", buf_char
);
617 /* Done with that line. */
619 acpi_os_printf("\n");
626 /*******************************************************************************
628 * FUNCTION: acpi_ut_debug_dump_buffer
630 * PARAMETERS: buffer - Buffer to dump
631 * count - Amount to dump, in bytes
632 * display - BYTE, WORD, DWORD, or QWORD display
633 * component_ID - Caller's component ID
637 * DESCRIPTION: Generic dump buffer in both hex and ascii.
639 ******************************************************************************/
642 acpi_ut_debug_dump_buffer(u8
*buffer
, u32 count
, u32 display
, u32 component_id
)
645 /* Only dump the buffer if tracing is enabled */
647 if (!((ACPI_LV_TABLES
& acpi_dbg_level
) &&
648 (component_id
& acpi_dbg_layer
))) {
652 acpi_ut_dump_buffer(buffer
, count
, display
, 0);