1 /******************************************************************************
3 * Module Name: utdebug - Debug print routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, 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
;
169 /* Check if debug output enabled */
171 if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level
, component_id
)) {
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 /* Check if debug output enabled */
239 if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level
, component_id
)) {
243 va_start(args
, format
);
244 acpi_os_vprintf(format
, args
);
248 ACPI_EXPORT_SYMBOL(acpi_debug_print_raw
)
250 /*******************************************************************************
252 * FUNCTION: acpi_ut_trace
254 * PARAMETERS: line_number - Caller's line number
255 * function_name - Caller's procedure name
256 * module_name - Caller's module name
257 * component_id - Caller's component ID
261 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
264 ******************************************************************************/
266 acpi_ut_trace(u32 line_number
,
267 const char *function_name
,
268 const char *module_name
, u32 component_id
)
271 acpi_gbl_nesting_level
++;
272 acpi_ut_track_stack_ptr();
274 /* Check if enabled up-front for performance */
276 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
277 acpi_debug_print(ACPI_LV_FUNCTIONS
,
278 line_number
, function_name
, module_name
,
279 component_id
, "%s\n", acpi_gbl_fn_entry_str
);
283 ACPI_EXPORT_SYMBOL(acpi_ut_trace
)
285 /*******************************************************************************
287 * FUNCTION: acpi_ut_trace_ptr
289 * PARAMETERS: line_number - Caller's line number
290 * function_name - Caller's procedure name
291 * module_name - Caller's module name
292 * component_id - Caller's component ID
293 * pointer - Pointer to display
297 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
300 ******************************************************************************/
302 acpi_ut_trace_ptr(u32 line_number
,
303 const char *function_name
,
304 const char *module_name
, u32 component_id
, void *pointer
)
307 acpi_gbl_nesting_level
++;
308 acpi_ut_track_stack_ptr();
310 /* Check if enabled up-front for performance */
312 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
313 acpi_debug_print(ACPI_LV_FUNCTIONS
,
314 line_number
, function_name
, module_name
,
315 component_id
, "%s %p\n", acpi_gbl_fn_entry_str
,
320 /*******************************************************************************
322 * FUNCTION: acpi_ut_trace_str
324 * PARAMETERS: line_number - Caller's line number
325 * function_name - Caller's procedure name
326 * module_name - Caller's module name
327 * component_id - Caller's component ID
328 * string - Additional string to display
332 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
335 ******************************************************************************/
338 acpi_ut_trace_str(u32 line_number
,
339 const char *function_name
,
340 const char *module_name
, u32 component_id
, char *string
)
343 acpi_gbl_nesting_level
++;
344 acpi_ut_track_stack_ptr();
346 /* Check if enabled up-front for performance */
348 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
349 acpi_debug_print(ACPI_LV_FUNCTIONS
,
350 line_number
, function_name
, module_name
,
351 component_id
, "%s %s\n", acpi_gbl_fn_entry_str
,
356 /*******************************************************************************
358 * FUNCTION: acpi_ut_trace_u32
360 * PARAMETERS: line_number - Caller's line number
361 * function_name - Caller's procedure name
362 * module_name - Caller's module name
363 * component_id - Caller's component ID
364 * integer - Integer to display
368 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
371 ******************************************************************************/
374 acpi_ut_trace_u32(u32 line_number
,
375 const char *function_name
,
376 const char *module_name
, u32 component_id
, u32 integer
)
379 acpi_gbl_nesting_level
++;
380 acpi_ut_track_stack_ptr();
382 /* Check if enabled up-front for performance */
384 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
385 acpi_debug_print(ACPI_LV_FUNCTIONS
,
386 line_number
, function_name
, module_name
,
387 component_id
, "%s %08X\n",
388 acpi_gbl_fn_entry_str
, integer
);
392 /*******************************************************************************
394 * FUNCTION: acpi_ut_exit
396 * PARAMETERS: line_number - Caller's line number
397 * function_name - Caller's procedure name
398 * module_name - Caller's module name
399 * component_id - Caller's component ID
403 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
406 ******************************************************************************/
409 acpi_ut_exit(u32 line_number
,
410 const char *function_name
,
411 const char *module_name
, u32 component_id
)
414 /* Check if enabled up-front for performance */
416 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
417 acpi_debug_print(ACPI_LV_FUNCTIONS
,
418 line_number
, function_name
, module_name
,
419 component_id
, "%s\n", acpi_gbl_fn_exit_str
);
422 acpi_gbl_nesting_level
--;
425 ACPI_EXPORT_SYMBOL(acpi_ut_exit
)
427 /*******************************************************************************
429 * FUNCTION: acpi_ut_status_exit
431 * PARAMETERS: line_number - Caller's line number
432 * function_name - Caller's procedure name
433 * module_name - Caller's module name
434 * component_id - Caller's component ID
435 * status - Exit status code
439 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
440 * set in debug_level. Prints exit status also.
442 ******************************************************************************/
444 acpi_ut_status_exit(u32 line_number
,
445 const char *function_name
,
446 const char *module_name
,
447 u32 component_id
, acpi_status status
)
450 /* Check if enabled up-front for performance */
452 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
453 if (ACPI_SUCCESS(status
)) {
454 acpi_debug_print(ACPI_LV_FUNCTIONS
,
455 line_number
, function_name
,
456 module_name
, component_id
, "%s %s\n",
457 acpi_gbl_fn_exit_str
,
458 acpi_format_exception(status
));
460 acpi_debug_print(ACPI_LV_FUNCTIONS
,
461 line_number
, function_name
,
462 module_name
, component_id
,
463 "%s ****Exception****: %s\n",
464 acpi_gbl_fn_exit_str
,
465 acpi_format_exception(status
));
469 acpi_gbl_nesting_level
--;
472 ACPI_EXPORT_SYMBOL(acpi_ut_status_exit
)
474 /*******************************************************************************
476 * FUNCTION: acpi_ut_value_exit
478 * PARAMETERS: line_number - Caller's line number
479 * function_name - Caller's procedure name
480 * module_name - Caller's module name
481 * component_id - Caller's component ID
482 * value - Value to be printed with exit msg
486 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
487 * set in debug_level. Prints exit value also.
489 ******************************************************************************/
491 acpi_ut_value_exit(u32 line_number
,
492 const char *function_name
,
493 const char *module_name
, u32 component_id
, u64 value
)
496 /* Check if enabled up-front for performance */
498 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
499 acpi_debug_print(ACPI_LV_FUNCTIONS
,
500 line_number
, function_name
, module_name
,
501 component_id
, "%s %8.8X%8.8X\n",
502 acpi_gbl_fn_exit_str
,
503 ACPI_FORMAT_UINT64(value
));
506 acpi_gbl_nesting_level
--;
509 ACPI_EXPORT_SYMBOL(acpi_ut_value_exit
)
511 /*******************************************************************************
513 * FUNCTION: acpi_ut_ptr_exit
515 * PARAMETERS: line_number - Caller's line number
516 * function_name - Caller's procedure name
517 * module_name - Caller's module name
518 * component_id - Caller's component ID
519 * ptr - Pointer to display
523 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
524 * set in debug_level. Prints exit value also.
526 ******************************************************************************/
528 acpi_ut_ptr_exit(u32 line_number
,
529 const char *function_name
,
530 const char *module_name
, u32 component_id
, u8
*ptr
)
533 /* Check if enabled up-front for performance */
535 if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS
, component_id
)) {
536 acpi_debug_print(ACPI_LV_FUNCTIONS
,
537 line_number
, function_name
, module_name
,
538 component_id
, "%s %p\n", acpi_gbl_fn_exit_str
,
542 acpi_gbl_nesting_level
--;
547 /*******************************************************************************
549 * FUNCTION: acpi_ut_dump_buffer
551 * PARAMETERS: buffer - Buffer to dump
552 * count - Amount to dump, in bytes
553 * display - BYTE, WORD, DWORD, or QWORD display
554 * offset - Beginning buffer offset (display only)
558 * DESCRIPTION: Generic dump buffer in both hex and ascii.
560 ******************************************************************************/
562 void acpi_ut_dump_buffer(u8
*buffer
, u32 count
, u32 display
, u32 base_offset
)
570 acpi_os_printf("Null Buffer Pointer in DumpBuffer!\n");
574 if ((count
< 4) || (count
& 0x01)) {
575 display
= DB_BYTE_DISPLAY
;
578 /* Nasty little dump buffer routine! */
582 /* Print current offset */
584 acpi_os_printf("%6.4X: ", (base_offset
+ i
));
586 /* Print 16 hex chars */
588 for (j
= 0; j
< 16;) {
589 if (i
+ j
>= count
) {
591 /* Dump fill spaces */
593 acpi_os_printf("%*s", ((display
* 2) + 1), " ");
599 case DB_BYTE_DISPLAY
:
600 default: /* Default is BYTE display */
602 acpi_os_printf("%02X ",
603 buffer
[(acpi_size
) i
+ j
]);
606 case DB_WORD_DISPLAY
:
608 ACPI_MOVE_16_TO_32(&temp32
,
609 &buffer
[(acpi_size
) i
+ j
]);
610 acpi_os_printf("%04X ", temp32
);
613 case DB_DWORD_DISPLAY
:
615 ACPI_MOVE_32_TO_32(&temp32
,
616 &buffer
[(acpi_size
) i
+ j
]);
617 acpi_os_printf("%08X ", temp32
);
620 case DB_QWORD_DISPLAY
:
622 ACPI_MOVE_32_TO_32(&temp32
,
623 &buffer
[(acpi_size
) i
+ j
]);
624 acpi_os_printf("%08X", temp32
);
626 ACPI_MOVE_32_TO_32(&temp32
,
627 &buffer
[(acpi_size
) i
+ j
+
629 acpi_os_printf("%08X ", temp32
);
637 * Print the ASCII equivalent characters but watch out for the bad
638 * unprintable ones (printable chars are 0x20 through 0x7E)
641 for (j
= 0; j
< 16; j
++) {
642 if (i
+ j
>= count
) {
643 acpi_os_printf("\n");
647 buf_char
= buffer
[(acpi_size
) i
+ j
];
648 if (ACPI_IS_PRINT(buf_char
)) {
649 acpi_os_printf("%c", buf_char
);
655 /* Done with that line. */
657 acpi_os_printf("\n");
664 /*******************************************************************************
666 * FUNCTION: acpi_ut_debug_dump_buffer
668 * PARAMETERS: buffer - Buffer to dump
669 * count - Amount to dump, in bytes
670 * display - BYTE, WORD, DWORD, or QWORD display
671 * component_ID - Caller's component ID
675 * DESCRIPTION: Generic dump buffer in both hex and ascii.
677 ******************************************************************************/
680 acpi_ut_debug_dump_buffer(u8
*buffer
, u32 count
, u32 display
, u32 component_id
)
683 /* Only dump the buffer if tracing is enabled */
685 if (!((ACPI_LV_TABLES
& acpi_dbg_level
) &&
686 (component_id
& acpi_dbg_layer
))) {
690 acpi_ut_dump_buffer(buffer
, count
, display
, 0);