1 /******************************************************************************
3 * Module Name: utdebug - Debug print routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2006, 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")
51 #ifdef ACPI_DEBUG_OUTPUT
52 static u32 acpi_gbl_prev_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 = ACPI_PTR_DIFF(¤t_sp, NULL);
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 current_sp = ACPI_PTR_DIFF(¤t_sp, NULL);
97 if (current_sp < acpi_gbl_lowest_stack_pointer) {
98 acpi_gbl_lowest_stack_pointer = current_sp;
101 if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) {
102 acpi_gbl_deepest_nesting = acpi_gbl_nesting_level;
106 /*******************************************************************************
108 * FUNCTION: acpi_ut_trim_function_name
110 * PARAMETERS: function_name - Ascii string containing a procedure name
112 * RETURN: Updated pointer to the function name
114 * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
115 * This allows compiler macros such as __FUNCTION__ to be used
116 * with no change to the debug output.
118 ******************************************************************************/
120 static const char *acpi_ut_trim_function_name(const char *function_name)
123 /* All Function names are longer than 4 chars, check is safe */
125 if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_MIXED) {
126 /* This is the case where the original source has not been modified */
128 return (function_name + 4);
131 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_ut_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_ut_debug_print(u32 requested_debug_level,
162 const char *function_name,
163 char *module_name, u32 component_id, char *format, ...)
169 * Stay silent if the debug level or component ID is disabled
171 if (!(requested_debug_level & acpi_dbg_level) ||
172 !(component_id & acpi_dbg_layer)) {
177 * Thread tracking and context switch notification
179 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 %X to TID %X ****\n\n",
185 acpi_gbl_prev_thread_id, 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("[%04lX] ", 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);
209 EXPORT_SYMBOL(acpi_ut_debug_print);
211 /*******************************************************************************
213 * FUNCTION: acpi_ut_debug_print_raw
215 * PARAMETERS: requested_debug_level - Requested debug print level
216 * line_number - Caller's line number
217 * function_name - Caller's procedure name
218 * module_name - Caller's module name
219 * component_id - Caller's component ID
220 * Format - Printf format field
221 * ... - Optional printf arguments
225 * DESCRIPTION: Print message with no headers. Has same interface as
226 * debug_print so that the same macros can be used.
228 ******************************************************************************/
230 void ACPI_INTERNAL_VAR_XFACE
231 acpi_ut_debug_print_raw(u32 requested_debug_level,
233 const char *function_name,
234 char *module_name, u32 component_id, char *format, ...)
238 if (!(requested_debug_level & acpi_dbg_level) ||
239 !(component_id & acpi_dbg_layer)) {
243 va_start(args, format);
244 acpi_os_vprintf(format, args);
247 EXPORT_SYMBOL(acpi_ut_debug_print_raw);
249 /*******************************************************************************
251 * FUNCTION: acpi_ut_trace
253 * PARAMETERS: line_number - Caller's line number
254 * function_name - Caller's procedure name
255 * module_name - Caller's module name
256 * component_id - Caller's component ID
260 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
263 ******************************************************************************/
266 acpi_ut_trace(u32 line_number,
267 const char *function_name, char *module_name, u32 component_id)
270 acpi_gbl_nesting_level++;
271 acpi_ut_track_stack_ptr();
273 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
274 line_number, function_name, module_name,
275 component_id, "%s\n", acpi_gbl_fn_entry_str);
278 EXPORT_SYMBOL(acpi_ut_trace);
280 /*******************************************************************************
282 * FUNCTION: acpi_ut_trace_ptr
284 * PARAMETERS: line_number - Caller's line number
285 * function_name - Caller's procedure name
286 * module_name - Caller's module name
287 * component_id - Caller's component ID
288 * Pointer - Pointer to display
292 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
295 ******************************************************************************/
298 acpi_ut_trace_ptr(u32 line_number,
299 const char *function_name,
300 char *module_name, u32 component_id, void *pointer)
302 acpi_gbl_nesting_level++;
303 acpi_ut_track_stack_ptr();
305 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
306 line_number, function_name, module_name,
307 component_id, "%s %p\n", acpi_gbl_fn_entry_str,
311 /*******************************************************************************
313 * FUNCTION: acpi_ut_trace_str
315 * PARAMETERS: line_number - Caller's line number
316 * function_name - Caller's procedure name
317 * module_name - Caller's module name
318 * component_id - Caller's component ID
319 * String - Additional string to display
323 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
326 ******************************************************************************/
329 acpi_ut_trace_str(u32 line_number,
330 const char *function_name,
331 char *module_name, u32 component_id, char *string)
334 acpi_gbl_nesting_level++;
335 acpi_ut_track_stack_ptr();
337 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
338 line_number, function_name, module_name,
339 component_id, "%s %s\n", acpi_gbl_fn_entry_str,
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 char *module_name, u32 component_id, u32 integer)
366 acpi_gbl_nesting_level++;
367 acpi_ut_track_stack_ptr();
369 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
370 line_number, function_name, module_name,
371 component_id, "%s %08X\n", acpi_gbl_fn_entry_str,
375 /*******************************************************************************
377 * FUNCTION: acpi_ut_exit
379 * PARAMETERS: line_number - Caller's line number
380 * function_name - Caller's procedure name
381 * module_name - Caller's module name
382 * component_id - Caller's component ID
386 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
389 ******************************************************************************/
392 acpi_ut_exit(u32 line_number,
393 const char *function_name, char *module_name, u32 component_id)
396 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
397 line_number, function_name, module_name,
398 component_id, "%s\n", acpi_gbl_fn_exit_str);
400 acpi_gbl_nesting_level--;
403 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 ******************************************************************************/
423 acpi_ut_status_exit(u32 line_number,
424 const char *function_name,
425 char *module_name, u32 component_id, acpi_status status)
428 if (ACPI_SUCCESS(status)) {
429 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
430 line_number, function_name, module_name,
431 component_id, "%s %s\n",
432 acpi_gbl_fn_exit_str,
433 acpi_format_exception(status));
435 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
436 line_number, function_name, module_name,
437 component_id, "%s ****Exception****: %s\n",
438 acpi_gbl_fn_exit_str,
439 acpi_format_exception(status));
442 acpi_gbl_nesting_level--;
445 EXPORT_SYMBOL(acpi_ut_status_exit);
447 /*******************************************************************************
449 * FUNCTION: acpi_ut_value_exit
451 * PARAMETERS: line_number - Caller's line number
452 * function_name - Caller's procedure name
453 * module_name - Caller's module name
454 * component_id - Caller's component ID
455 * Value - Value to be printed with exit msg
459 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
460 * set in debug_level. Prints exit value also.
462 ******************************************************************************/
465 acpi_ut_value_exit(u32 line_number,
466 const char *function_name,
467 char *module_name, u32 component_id, acpi_integer value)
470 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
471 line_number, function_name, module_name,
472 component_id, "%s %8.8X%8.8X\n",
473 acpi_gbl_fn_exit_str, ACPI_FORMAT_UINT64(value));
475 acpi_gbl_nesting_level--;
478 EXPORT_SYMBOL(acpi_ut_value_exit);
480 /*******************************************************************************
482 * FUNCTION: acpi_ut_ptr_exit
484 * PARAMETERS: line_number - Caller's line number
485 * function_name - Caller's procedure name
486 * module_name - Caller's module name
487 * component_id - Caller's component ID
488 * Ptr - Pointer to display
492 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
493 * set in debug_level. Prints exit value also.
495 ******************************************************************************/
498 acpi_ut_ptr_exit(u32 line_number,
499 const char *function_name,
500 char *module_name, u32 component_id, u8 * ptr)
503 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
504 line_number, function_name, module_name,
505 component_id, "%s %p\n", acpi_gbl_fn_exit_str, ptr);
507 acpi_gbl_nesting_level--;
512 /*******************************************************************************
514 * FUNCTION: acpi_ut_dump_buffer
516 * PARAMETERS: Buffer - Buffer to dump
517 * Count - Amount to dump, in bytes
518 * Display - BYTE, WORD, DWORD, or QWORD display
519 * component_iD - Caller's component ID
523 * DESCRIPTION: Generic dump buffer in both hex and ascii.
525 ******************************************************************************/
527 void acpi_ut_dump_buffer(u8 * buffer, u32 count, u32 display, u32 component_id)
529 acpi_native_uint i = 0;
534 /* Only dump the buffer if tracing is enabled */
536 if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
537 (component_id & acpi_dbg_layer))) {
541 if ((count < 4) || (count & 0x01)) {
542 display = DB_BYTE_DISPLAY;
545 /* Nasty little dump buffer routine! */
548 /* Print current offset */
550 acpi_os_printf("%6.4X: ", (u32) i);
552 /* Print 16 hex chars */
554 for (j = 0; j < 16;) {
555 if (i + j >= count) {
556 /* Dump fill spaces */
558 acpi_os_printf("%*s", ((display * 2) + 1), " ");
559 j += (acpi_native_uint) display;
564 default: /* Default is BYTE display */
566 acpi_os_printf("%02X ", buffer[i + j]);
569 case DB_WORD_DISPLAY:
571 ACPI_MOVE_16_TO_32(&temp32, &buffer[i + j]);
572 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);
581 case DB_QWORD_DISPLAY:
583 ACPI_MOVE_32_TO_32(&temp32, &buffer[i + j]);
584 acpi_os_printf("%08X", temp32);
586 ACPI_MOVE_32_TO_32(&temp32, &buffer[i + j + 4]);
587 acpi_os_printf("%08X ", temp32);
591 j += (acpi_native_uint) display;
595 * Print the ASCII equivalent characters but watch out for the bad
596 * unprintable ones (printable chars are 0x20 through 0x7E)
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 (ACPI_IS_PRINT(buf_char)) {
607 acpi_os_printf("%c", buf_char);
613 /* Done with that line. */
615 acpi_os_printf("\n");