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 <acpi/acpi.h>
46 #define _COMPONENT ACPI_UTILITIES
47 ACPI_MODULE_NAME("utdebug")
49 #ifdef ACPI_DEBUG_OUTPUT
50 static acpi_thread_id acpi_gbl_prev_thread_id;
51 static char *acpi_gbl_fn_entry_str = "----Entry";
52 static char *acpi_gbl_fn_exit_str = "----Exit-";
54 /* Local prototypes */
56 static const char *acpi_ut_trim_function_name(const char *function_name);
58 /*******************************************************************************
60 * FUNCTION: acpi_ut_init_stack_ptr_trace
66 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
68 ******************************************************************************/
70 void acpi_ut_init_stack_ptr_trace(void)
74 acpi_gbl_entry_stack_pointer = ACPI_PTR_DIFF(¤t_sp, NULL);
77 /*******************************************************************************
79 * FUNCTION: acpi_ut_track_stack_ptr
85 * DESCRIPTION: Save the current CPU stack pointer
87 ******************************************************************************/
89 void acpi_ut_track_stack_ptr(void)
93 current_sp = ACPI_PTR_DIFF(¤t_sp, NULL);
95 if (current_sp < acpi_gbl_lowest_stack_pointer) {
96 acpi_gbl_lowest_stack_pointer = current_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_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, ...)
165 acpi_thread_id thread_id;
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();
180 if (thread_id != acpi_gbl_prev_thread_id) {
181 if (ACPI_LV_THREADS & acpi_dbg_level) {
183 ("\n**** Context Switch from TID %lX to TID %lX ****\n\n",
184 (unsigned long) acpi_gbl_prev_thread_id,
185 (unsigned long) 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 ACPI_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 ******************************************************************************/
229 void ACPI_INTERNAL_VAR_XFACE
230 acpi_ut_debug_print_raw(u32 requested_debug_level,
232 const char *function_name,
233 char *module_name, u32 component_id, char *format, ...)
237 if (!(requested_debug_level & acpi_dbg_level) ||
238 !(component_id & acpi_dbg_layer)) {
242 va_start(args, format);
243 acpi_os_vprintf(format, args);
246 ACPI_EXPORT_SYMBOL(acpi_ut_debug_print_raw)
248 /*******************************************************************************
250 * FUNCTION: acpi_ut_trace
252 * PARAMETERS: line_number - Caller's line number
253 * function_name - Caller's procedure name
254 * module_name - Caller's module name
255 * component_id - Caller's component ID
259 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
262 ******************************************************************************/
264 acpi_ut_trace(u32 line_number,
265 const char *function_name, char *module_name, u32 component_id)
268 acpi_gbl_nesting_level++;
269 acpi_ut_track_stack_ptr();
271 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
272 line_number, function_name, module_name,
273 component_id, "%s\n", acpi_gbl_fn_entry_str);
276 ACPI_EXPORT_SYMBOL(acpi_ut_trace)
278 /*******************************************************************************
280 * FUNCTION: acpi_ut_trace_ptr
282 * PARAMETERS: line_number - Caller's line number
283 * function_name - Caller's procedure name
284 * module_name - Caller's module name
285 * component_id - Caller's component ID
286 * Pointer - Pointer to display
290 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
293 ******************************************************************************/
295 acpi_ut_trace_ptr(u32 line_number,
296 const char *function_name,
297 char *module_name, u32 component_id, void *pointer)
299 acpi_gbl_nesting_level++;
300 acpi_ut_track_stack_ptr();
302 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
303 line_number, function_name, module_name,
304 component_id, "%s %p\n", acpi_gbl_fn_entry_str,
308 /*******************************************************************************
310 * FUNCTION: acpi_ut_trace_str
312 * PARAMETERS: line_number - Caller's line number
313 * function_name - Caller's procedure name
314 * module_name - Caller's module name
315 * component_id - Caller's component ID
316 * String - Additional string to display
320 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
323 ******************************************************************************/
326 acpi_ut_trace_str(u32 line_number,
327 const char *function_name,
328 char *module_name, u32 component_id, char *string)
331 acpi_gbl_nesting_level++;
332 acpi_ut_track_stack_ptr();
334 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
335 line_number, function_name, module_name,
336 component_id, "%s %s\n", acpi_gbl_fn_entry_str,
340 /*******************************************************************************
342 * FUNCTION: acpi_ut_trace_u32
344 * PARAMETERS: line_number - Caller's line number
345 * function_name - Caller's procedure name
346 * module_name - Caller's module name
347 * component_id - Caller's component ID
348 * Integer - Integer to display
352 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
355 ******************************************************************************/
358 acpi_ut_trace_u32(u32 line_number,
359 const char *function_name,
360 char *module_name, u32 component_id, u32 integer)
363 acpi_gbl_nesting_level++;
364 acpi_ut_track_stack_ptr();
366 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
367 line_number, function_name, module_name,
368 component_id, "%s %08X\n", acpi_gbl_fn_entry_str,
372 /*******************************************************************************
374 * FUNCTION: acpi_ut_exit
376 * PARAMETERS: line_number - Caller's line number
377 * function_name - Caller's procedure name
378 * module_name - Caller's module name
379 * component_id - Caller's component ID
383 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
386 ******************************************************************************/
389 acpi_ut_exit(u32 line_number,
390 const char *function_name, char *module_name, u32 component_id)
393 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
394 line_number, function_name, module_name,
395 component_id, "%s\n", acpi_gbl_fn_exit_str);
397 acpi_gbl_nesting_level--;
400 ACPI_EXPORT_SYMBOL(acpi_ut_exit)
402 /*******************************************************************************
404 * FUNCTION: acpi_ut_status_exit
406 * PARAMETERS: line_number - Caller's line number
407 * function_name - Caller's procedure name
408 * module_name - Caller's module name
409 * component_id - Caller's component ID
410 * Status - Exit status code
414 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
415 * set in debug_level. Prints exit status also.
417 ******************************************************************************/
419 acpi_ut_status_exit(u32 line_number,
420 const char *function_name,
421 char *module_name, u32 component_id, acpi_status status)
424 if (ACPI_SUCCESS(status)) {
425 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
426 line_number, function_name, module_name,
427 component_id, "%s %s\n",
428 acpi_gbl_fn_exit_str,
429 acpi_format_exception(status));
431 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
432 line_number, function_name, module_name,
433 component_id, "%s ****Exception****: %s\n",
434 acpi_gbl_fn_exit_str,
435 acpi_format_exception(status));
438 acpi_gbl_nesting_level--;
441 ACPI_EXPORT_SYMBOL(acpi_ut_status_exit)
443 /*******************************************************************************
445 * FUNCTION: acpi_ut_value_exit
447 * PARAMETERS: line_number - Caller's line number
448 * function_name - Caller's procedure name
449 * module_name - Caller's module name
450 * component_id - Caller's component ID
451 * Value - Value to be printed with exit msg
455 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
456 * set in debug_level. Prints exit value also.
458 ******************************************************************************/
460 acpi_ut_value_exit(u32 line_number,
461 const char *function_name,
462 char *module_name, u32 component_id, acpi_integer value)
465 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
466 line_number, function_name, module_name,
467 component_id, "%s %8.8X%8.8X\n",
468 acpi_gbl_fn_exit_str, ACPI_FORMAT_UINT64(value));
470 acpi_gbl_nesting_level--;
473 ACPI_EXPORT_SYMBOL(acpi_ut_value_exit)
475 /*******************************************************************************
477 * FUNCTION: acpi_ut_ptr_exit
479 * PARAMETERS: line_number - Caller's line number
480 * function_name - Caller's procedure name
481 * module_name - Caller's module name
482 * component_id - Caller's component ID
483 * Ptr - Pointer to display
487 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
488 * set in debug_level. Prints exit value also.
490 ******************************************************************************/
492 acpi_ut_ptr_exit(u32 line_number,
493 const char *function_name,
494 char *module_name, u32 component_id, u8 * ptr)
497 acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
498 line_number, function_name, module_name,
499 component_id, "%s %p\n", acpi_gbl_fn_exit_str, ptr);
501 acpi_gbl_nesting_level--;
506 /*******************************************************************************
508 * FUNCTION: acpi_ut_dump_buffer
510 * PARAMETERS: Buffer - Buffer to dump
511 * Count - Amount to dump, in bytes
512 * Display - BYTE, WORD, DWORD, or QWORD display
513 * component_iD - Caller's component ID
517 * DESCRIPTION: Generic dump buffer in both hex and ascii.
519 ******************************************************************************/
521 void acpi_ut_dump_buffer2(u8 * buffer, u32 count, u32 display)
523 acpi_native_uint i = 0;
528 if ((count < 4) || (count & 0x01)) {
529 display = DB_BYTE_DISPLAY;
532 /* Nasty little dump buffer routine! */
536 /* Print current offset */
538 acpi_os_printf("%6.4X: ", (u32) i);
540 /* Print 16 hex chars */
542 for (j = 0; j < 16;) {
543 if (i + j >= count) {
545 /* Dump fill spaces */
547 acpi_os_printf("%*s", ((display * 2) + 1), " ");
548 j += (acpi_native_uint) display;
553 case DB_BYTE_DISPLAY:
554 default: /* Default is BYTE display */
556 acpi_os_printf("%02X ", buffer[i + j]);
559 case DB_WORD_DISPLAY:
561 ACPI_MOVE_16_TO_32(&temp32, &buffer[i + j]);
562 acpi_os_printf("%04X ", temp32);
565 case DB_DWORD_DISPLAY:
567 ACPI_MOVE_32_TO_32(&temp32, &buffer[i + j]);
568 acpi_os_printf("%08X ", temp32);
571 case DB_QWORD_DISPLAY:
573 ACPI_MOVE_32_TO_32(&temp32, &buffer[i + j]);
574 acpi_os_printf("%08X", temp32);
576 ACPI_MOVE_32_TO_32(&temp32, &buffer[i + j + 4]);
577 acpi_os_printf("%08X ", temp32);
581 j += (acpi_native_uint) display;
585 * Print the ASCII equivalent characters but watch out for the bad
586 * unprintable ones (printable chars are 0x20 through 0x7E)
589 for (j = 0; j < 16; j++) {
590 if (i + j >= count) {
591 acpi_os_printf("\n");
595 buf_char = buffer[i + j];
596 if (ACPI_IS_PRINT(buf_char)) {
597 acpi_os_printf("%c", buf_char);
603 /* Done with that line. */
605 acpi_os_printf("\n");
612 /*******************************************************************************
614 * FUNCTION: acpi_ut_dump_buffer
616 * PARAMETERS: Buffer - Buffer to dump
617 * Count - Amount to dump, in bytes
618 * Display - BYTE, WORD, DWORD, or QWORD display
619 * component_iD - Caller's component ID
623 * DESCRIPTION: Generic dump buffer in both hex and ascii.
625 ******************************************************************************/
627 void acpi_ut_dump_buffer(u8 * buffer, u32 count, u32 display, u32 component_id)
630 /* Only dump the buffer if tracing is enabled */
632 if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
633 (component_id & acpi_dbg_layer))) {
637 acpi_ut_dump_buffer2(buffer, count, display);