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) {
127 /* This is the case where the original source has not been modified */
129 return (function_name + 4);
132 if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_LOWER) {
134 /* This is the case where the source has been 'linuxized' */
136 return (function_name + 5);
139 return (function_name);
142 /*******************************************************************************
144 * FUNCTION: acpi_ut_debug_print
146 * PARAMETERS: requested_debug_level - Requested debug print level
147 * line_number - Caller's line number (for error output)
148 * function_name - Caller's procedure name
149 * module_name - Caller's module name
150 * component_id - Caller's component ID
151 * Format - Printf format field
152 * ... - Optional printf arguments
156 * DESCRIPTION: Print error message with prefix consisting of the module name,
157 * line number, and component ID.
159 ******************************************************************************/
161 void ACPI_INTERNAL_VAR_XFACE
162 acpi_ut_debug_print(u32 requested_debug_level,
164 const char *function_name,
165 char *module_name, u32 component_id, char *format, ...)
171 * Stay silent if the debug level or component ID is disabled
173 if (!(requested_debug_level & acpi_dbg_level) ||
174 !(component_id & acpi_dbg_layer)) {
179 * Thread tracking and context switch notification
181 thread_id = acpi_os_get_thread_id();
183 if (thread_id != acpi_gbl_prev_thread_id) {
184 if (ACPI_LV_THREADS & acpi_dbg_level) {
186 ("\n**** Context Switch from TID %X to TID %X ****\n\n",
187 acpi_gbl_prev_thread_id, thread_id);
190 acpi_gbl_prev_thread_id = thread_id;
194 * Display the module name, current line number, thread ID (if requested),
195 * current procedure nesting level, and the current procedure name
197 acpi_os_printf("%8s-%04ld ", module_name, line_number);
199 if (ACPI_LV_THREADS & acpi_dbg_level) {
200 acpi_os_printf("[%04lX] ", thread_id);
203 acpi_os_printf("[%02ld] %-22.22s: ",
204 acpi_gbl_nesting_level,
205 acpi_ut_trim_function_name(function_name));
207 va_start(args, format);
208 acpi_os_vprintf(format, args);
211 EXPORT_SYMBOL(acpi_ut_debug_print);
213 /*******************************************************************************
215 * FUNCTION: acpi_ut_debug_print_raw
217 * PARAMETERS: requested_debug_level - Requested debug print level
218 * line_number - Caller's line number
219 * function_name - Caller's procedure name
220 * module_name - Caller's module name
221 * component_id - Caller's component ID
222 * Format - Printf format field
223 * ... - Optional printf arguments
227 * DESCRIPTION: Print message with no headers. Has same interface as
228 * debug_print so that the same macros can be used.
230 ******************************************************************************/
232 void ACPI_INTERNAL_VAR_XFACE
233 acpi_ut_debug_print_raw(u32 requested_debug_level,
235 const char *function_name,
236 char *module_name, u32 component_id, char *format, ...)
240 if (!(requested_debug_level & acpi_dbg_level) ||
241 !(component_id & acpi_dbg_layer)) {
245 va_start(args, format);
246 acpi_os_vprintf(format, args);
249 EXPORT_SYMBOL(acpi_ut_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 ******************************************************************************/
268 acpi_ut_trace(u32 line_number,
269 const char *function_name, char *module_name, u32 component_id)
272 acpi_gbl_nesting_level++;
273 acpi_ut_track_stack_ptr();
275 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
276 line_number, function_name, module_name,
277 component_id, "%s\n", acpi_gbl_fn_entry_str);
280 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 ******************************************************************************/
300 acpi_ut_trace_ptr(u32 line_number,
301 const char *function_name,
302 char *module_name, u32 component_id, void *pointer)
304 acpi_gbl_nesting_level++;
305 acpi_ut_track_stack_ptr();
307 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
308 line_number, function_name, module_name,
309 component_id, "%s %p\n", acpi_gbl_fn_entry_str,
313 /*******************************************************************************
315 * FUNCTION: acpi_ut_trace_str
317 * PARAMETERS: line_number - Caller's line number
318 * function_name - Caller's procedure name
319 * module_name - Caller's module name
320 * component_id - Caller's component ID
321 * String - Additional string to display
325 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
328 ******************************************************************************/
331 acpi_ut_trace_str(u32 line_number,
332 const char *function_name,
333 char *module_name, u32 component_id, char *string)
336 acpi_gbl_nesting_level++;
337 acpi_ut_track_stack_ptr();
339 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
340 line_number, function_name, module_name,
341 component_id, "%s %s\n", acpi_gbl_fn_entry_str,
345 /*******************************************************************************
347 * FUNCTION: acpi_ut_trace_u32
349 * PARAMETERS: line_number - Caller's line number
350 * function_name - Caller's procedure name
351 * module_name - Caller's module name
352 * component_id - Caller's component ID
353 * Integer - Integer to display
357 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
360 ******************************************************************************/
363 acpi_ut_trace_u32(u32 line_number,
364 const char *function_name,
365 char *module_name, u32 component_id, u32 integer)
368 acpi_gbl_nesting_level++;
369 acpi_ut_track_stack_ptr();
371 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
372 line_number, function_name, module_name,
373 component_id, "%s %08X\n", acpi_gbl_fn_entry_str,
377 /*******************************************************************************
379 * FUNCTION: acpi_ut_exit
381 * PARAMETERS: line_number - Caller's line number
382 * function_name - Caller's procedure name
383 * module_name - Caller's module name
384 * component_id - Caller's component ID
388 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
391 ******************************************************************************/
394 acpi_ut_exit(u32 line_number,
395 const char *function_name, char *module_name, u32 component_id)
398 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
399 line_number, function_name, module_name,
400 component_id, "%s\n", acpi_gbl_fn_exit_str);
402 acpi_gbl_nesting_level--;
405 EXPORT_SYMBOL(acpi_ut_exit);
407 /*******************************************************************************
409 * FUNCTION: acpi_ut_status_exit
411 * PARAMETERS: line_number - Caller's line number
412 * function_name - Caller's procedure name
413 * module_name - Caller's module name
414 * component_id - Caller's component ID
415 * Status - Exit status code
419 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
420 * set in debug_level. Prints exit status also.
422 ******************************************************************************/
425 acpi_ut_status_exit(u32 line_number,
426 const char *function_name,
427 char *module_name, u32 component_id, acpi_status status)
430 if (ACPI_SUCCESS(status)) {
431 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
432 line_number, function_name, module_name,
433 component_id, "%s %s\n",
434 acpi_gbl_fn_exit_str,
435 acpi_format_exception(status));
437 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
438 line_number, function_name, module_name,
439 component_id, "%s ****Exception****: %s\n",
440 acpi_gbl_fn_exit_str,
441 acpi_format_exception(status));
444 acpi_gbl_nesting_level--;
447 EXPORT_SYMBOL(acpi_ut_status_exit);
449 /*******************************************************************************
451 * FUNCTION: acpi_ut_value_exit
453 * PARAMETERS: line_number - Caller's line number
454 * function_name - Caller's procedure name
455 * module_name - Caller's module name
456 * component_id - Caller's component ID
457 * Value - Value to be printed with exit msg
461 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
462 * set in debug_level. Prints exit value also.
464 ******************************************************************************/
467 acpi_ut_value_exit(u32 line_number,
468 const char *function_name,
469 char *module_name, u32 component_id, acpi_integer value)
472 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
473 line_number, function_name, module_name,
474 component_id, "%s %8.8X%8.8X\n",
475 acpi_gbl_fn_exit_str, ACPI_FORMAT_UINT64(value));
477 acpi_gbl_nesting_level--;
480 EXPORT_SYMBOL(acpi_ut_value_exit);
482 /*******************************************************************************
484 * FUNCTION: acpi_ut_ptr_exit
486 * PARAMETERS: line_number - Caller's line number
487 * function_name - Caller's procedure name
488 * module_name - Caller's module name
489 * component_id - Caller's component ID
490 * Ptr - Pointer to display
494 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
495 * set in debug_level. Prints exit value also.
497 ******************************************************************************/
500 acpi_ut_ptr_exit(u32 line_number,
501 const char *function_name,
502 char *module_name, u32 component_id, u8 * ptr)
505 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
506 line_number, function_name, module_name,
507 component_id, "%s %p\n", acpi_gbl_fn_exit_str, ptr);
509 acpi_gbl_nesting_level--;
514 /*******************************************************************************
516 * FUNCTION: acpi_ut_dump_buffer
518 * PARAMETERS: Buffer - Buffer to dump
519 * Count - Amount to dump, in bytes
520 * Display - BYTE, WORD, DWORD, or QWORD display
521 * component_iD - Caller's component ID
525 * DESCRIPTION: Generic dump buffer in both hex and ascii.
527 ******************************************************************************/
529 void acpi_ut_dump_buffer(u8 * buffer, u32 count, u32 display, u32 component_id)
531 acpi_native_uint i = 0;
536 /* Only dump the buffer if tracing is enabled */
538 if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
539 (component_id & acpi_dbg_layer))) {
543 if ((count < 4) || (count & 0x01)) {
544 display = DB_BYTE_DISPLAY;
547 /* Nasty little dump buffer routine! */
551 /* Print current offset */
553 acpi_os_printf("%6.4X: ", (u32) i);
555 /* Print 16 hex chars */
557 for (j = 0; j < 16;) {
558 if (i + j >= count) {
560 /* Dump fill spaces */
562 acpi_os_printf("%*s", ((display * 2) + 1), " ");
563 j += (acpi_native_uint) display;
568 default: /* Default is BYTE display */
570 acpi_os_printf("%02X ", buffer[i + j]);
573 case DB_WORD_DISPLAY:
575 ACPI_MOVE_16_TO_32(&temp32, &buffer[i + j]);
576 acpi_os_printf("%04X ", temp32);
579 case DB_DWORD_DISPLAY:
581 ACPI_MOVE_32_TO_32(&temp32, &buffer[i + j]);
582 acpi_os_printf("%08X ", temp32);
585 case DB_QWORD_DISPLAY:
587 ACPI_MOVE_32_TO_32(&temp32, &buffer[i + j]);
588 acpi_os_printf("%08X", temp32);
590 ACPI_MOVE_32_TO_32(&temp32, &buffer[i + j + 4]);
591 acpi_os_printf("%08X ", temp32);
595 j += (acpi_native_uint) display;
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[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");