1 /******************************************************************************
3 * Module Name: utdebug - Debug print routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2004, 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.
45 #include <acpi/acpi.h>
47 #define _COMPONENT ACPI_UTILITIES
48 ACPI_MODULE_NAME ("utdebug")
51 #ifdef ACPI_DEBUG_OUTPUT
53 static u32 acpi_gbl_prev_thread_id = 0xFFFFFFFF;
54 static char *acpi_gbl_fn_entry_str = "----Entry";
55 static char *acpi_gbl_fn_exit_str = "----Exit-";
58 /*****************************************************************************
60 * FUNCTION: acpi_ut_init_stack_ptr_trace
66 * DESCRIPTION: Save the current stack pointer
68 ****************************************************************************/
71 acpi_ut_init_stack_ptr_trace (
77 acpi_gbl_entry_stack_pointer = ACPI_PTR_DIFF (¤t_sp, NULL);
81 /*****************************************************************************
83 * FUNCTION: acpi_ut_track_stack_ptr
89 * DESCRIPTION: Save the current stack pointer
91 ****************************************************************************/
94 acpi_ut_track_stack_ptr (
100 current_sp = ACPI_PTR_DIFF (¤t_sp, NULL);
102 if (current_sp < acpi_gbl_lowest_stack_pointer) {
103 acpi_gbl_lowest_stack_pointer = current_sp;
106 if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) {
107 acpi_gbl_deepest_nesting = acpi_gbl_nesting_level;
112 /*****************************************************************************
114 * FUNCTION: acpi_ut_debug_print
116 * PARAMETERS: debug_level - Requested debug print level
117 * proc_name - Caller's procedure name
118 * module_name - Caller's module name (for error output)
119 * line_number - Caller's line number (for error output)
120 * component_id - Caller's component ID (for error output)
122 * Format - Printf format field
123 * ... - Optional printf arguments
127 * DESCRIPTION: Print error message with prefix consisting of the module name,
128 * line number, and component ID.
130 ****************************************************************************/
132 void ACPI_INTERNAL_VAR_XFACE
133 acpi_ut_debug_print (
134 u32 requested_debug_level,
136 struct acpi_debug_print_info *dbg_info,
145 * Stay silent if the debug level or component ID is disabled
147 if (!(requested_debug_level & acpi_dbg_level) ||
148 !(dbg_info->component_id & acpi_dbg_layer)) {
153 * Thread tracking and context switch notification
155 thread_id = acpi_os_get_thread_id ();
157 if (thread_id != acpi_gbl_prev_thread_id) {
158 if (ACPI_LV_THREADS & acpi_dbg_level) {
159 acpi_os_printf ("\n**** Context Switch from TID %X to TID %X ****\n\n",
160 acpi_gbl_prev_thread_id, thread_id);
163 acpi_gbl_prev_thread_id = thread_id;
167 * Display the module name, current line number, thread ID (if requested),
168 * current procedure nesting level, and the current procedure name
170 acpi_os_printf ("%8s-%04ld ", dbg_info->module_name, line_number);
172 if (ACPI_LV_THREADS & acpi_dbg_level) {
173 acpi_os_printf ("[%04lX] ", thread_id);
176 acpi_os_printf ("[%02ld] %-22.22s: ", acpi_gbl_nesting_level, dbg_info->proc_name);
178 va_start (args, format);
179 acpi_os_vprintf (format, args);
183 /*****************************************************************************
185 * FUNCTION: acpi_ut_debug_print_raw
187 * PARAMETERS: requested_debug_level - Requested debug print level
188 * line_number - Caller's line number
189 * dbg_info - Contains:
190 * proc_name - Caller's procedure name
191 * module_name - Caller's module name
192 * component_id - Caller's component ID
193 * Format - Printf format field
194 * ... - Optional printf arguments
198 * DESCRIPTION: Print message with no headers. Has same interface as
199 * debug_print so that the same macros can be used.
201 ****************************************************************************/
203 void ACPI_INTERNAL_VAR_XFACE
204 acpi_ut_debug_print_raw (
205 u32 requested_debug_level,
207 struct acpi_debug_print_info *dbg_info,
214 if (!(requested_debug_level & acpi_dbg_level) ||
215 !(dbg_info->component_id & acpi_dbg_layer)) {
219 va_start (args, format);
220 acpi_os_vprintf (format, args);
224 /*****************************************************************************
226 * FUNCTION: acpi_ut_trace
228 * PARAMETERS: line_number - Caller's line number
229 * dbg_info - Contains:
230 * proc_name - Caller's procedure name
231 * module_name - Caller's module name
232 * component_id - Caller's component ID
236 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
239 ****************************************************************************/
244 struct acpi_debug_print_info *dbg_info)
247 acpi_gbl_nesting_level++;
248 acpi_ut_track_stack_ptr ();
250 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
251 "%s\n", acpi_gbl_fn_entry_str);
255 /*****************************************************************************
257 * FUNCTION: acpi_ut_trace_ptr
259 * PARAMETERS: line_number - Caller's line number
260 * dbg_info - Contains:
261 * proc_name - Caller's procedure name
262 * module_name - Caller's module name
263 * component_id - Caller's component ID
264 * Pointer - Pointer to display
268 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
271 ****************************************************************************/
276 struct acpi_debug_print_info *dbg_info,
279 acpi_gbl_nesting_level++;
280 acpi_ut_track_stack_ptr ();
282 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
283 "%s %p\n", acpi_gbl_fn_entry_str, pointer);
287 /*****************************************************************************
289 * FUNCTION: acpi_ut_trace_str
291 * PARAMETERS: line_number - Caller's line number
292 * dbg_info - Contains:
293 * proc_name - Caller's procedure name
294 * module_name - Caller's module name
295 * component_id - Caller's component ID
296 * String - Additional string to display
300 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
303 ****************************************************************************/
308 struct acpi_debug_print_info *dbg_info,
312 acpi_gbl_nesting_level++;
313 acpi_ut_track_stack_ptr ();
315 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
316 "%s %s\n", acpi_gbl_fn_entry_str, string);
320 /*****************************************************************************
322 * FUNCTION: acpi_ut_trace_u32
324 * PARAMETERS: line_number - Caller's line number
325 * dbg_info - Contains:
326 * proc_name - Caller's procedure name
327 * module_name - Caller's module name
328 * component_id - Caller's component ID
329 * Integer - Integer to display
333 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
336 ****************************************************************************/
341 struct acpi_debug_print_info *dbg_info,
345 acpi_gbl_nesting_level++;
346 acpi_ut_track_stack_ptr ();
348 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
349 "%s %08X\n", acpi_gbl_fn_entry_str, integer);
353 /*****************************************************************************
355 * FUNCTION: acpi_ut_exit
357 * PARAMETERS: line_number - Caller's line number
358 * dbg_info - Contains:
359 * proc_name - Caller's procedure name
360 * module_name - Caller's module name
361 * component_id - Caller's component ID
365 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
368 ****************************************************************************/
373 struct acpi_debug_print_info *dbg_info)
376 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
377 "%s\n", acpi_gbl_fn_exit_str);
379 acpi_gbl_nesting_level--;
383 /*****************************************************************************
385 * FUNCTION: acpi_ut_status_exit
387 * PARAMETERS: line_number - Caller's line number
388 * dbg_info - Contains:
389 * proc_name - Caller's procedure name
390 * module_name - Caller's module name
391 * component_id - Caller's component ID
392 * Status - Exit status code
396 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
397 * set in debug_level. Prints exit status also.
399 ****************************************************************************/
402 acpi_ut_status_exit (
404 struct acpi_debug_print_info *dbg_info,
408 if (ACPI_SUCCESS (status)) {
409 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
410 "%s %s\n", acpi_gbl_fn_exit_str,
411 acpi_format_exception (status));
414 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
415 "%s ****Exception****: %s\n", acpi_gbl_fn_exit_str,
416 acpi_format_exception (status));
419 acpi_gbl_nesting_level--;
423 /*****************************************************************************
425 * FUNCTION: acpi_ut_value_exit
427 * PARAMETERS: line_number - Caller's line number
428 * dbg_info - Contains:
429 * proc_name - Caller's procedure name
430 * module_name - Caller's module name
431 * component_id - Caller's component ID
432 * Value - Value to be printed with exit msg
436 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
437 * set in debug_level. Prints exit value also.
439 ****************************************************************************/
444 struct acpi_debug_print_info *dbg_info,
448 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
449 "%s %8.8X%8.8X\n", acpi_gbl_fn_exit_str,
450 ACPI_FORMAT_UINT64 (value));
452 acpi_gbl_nesting_level--;
456 /*****************************************************************************
458 * FUNCTION: acpi_ut_ptr_exit
460 * PARAMETERS: line_number - Caller's line number
461 * dbg_info - Contains:
462 * proc_name - Caller's procedure name
463 * module_name - Caller's module name
464 * component_id - Caller's component ID
465 * Value - Value to be printed with exit msg
469 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
470 * set in debug_level. Prints exit value also.
472 ****************************************************************************/
477 struct acpi_debug_print_info *dbg_info,
481 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
482 "%s %p\n", acpi_gbl_fn_exit_str, ptr);
484 acpi_gbl_nesting_level--;
490 /*****************************************************************************
492 * FUNCTION: acpi_ut_dump_buffer
494 * PARAMETERS: Buffer - Buffer to dump
495 * Count - Amount to dump, in bytes
496 * Display - BYTE, WORD, DWORD, or QWORD display
497 * component_iD - Caller's component ID
501 * DESCRIPTION: Generic dump buffer in both hex and ascii.
503 ****************************************************************************/
506 acpi_ut_dump_buffer (
512 acpi_native_uint i = 0;
518 /* Only dump the buffer if tracing is enabled */
520 if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
521 (component_id & acpi_dbg_layer))) {
525 if ((count < 4) || (count & 0x01)) {
526 display = DB_BYTE_DISPLAY;
529 acpi_os_printf ("\nOffset Value\n");
532 * Nasty little dump buffer routine!
535 /* Print current offset */
537 acpi_os_printf ("%05X ", (u32) i);
539 /* Print 16 hex chars */
541 for (j = 0; j < 16;) {
542 if (i + j >= count) {
543 acpi_os_printf ("\n");
547 /* Make sure that the s8 doesn't get sign-extended! */
550 /* Default is BYTE display */
554 acpi_os_printf ("%02X ",
555 *((u8 *) &buffer[i + j]));
560 case DB_WORD_DISPLAY:
562 ACPI_MOVE_16_TO_32 (&temp32, &buffer[i + j]);
563 acpi_os_printf ("%04X ", temp32);
568 case DB_DWORD_DISPLAY:
570 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]);
571 acpi_os_printf ("%08X ", temp32);
576 case DB_QWORD_DISPLAY:
578 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]);
579 acpi_os_printf ("%08X", temp32);
581 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j + 4]);
582 acpi_os_printf ("%08X ", temp32);
589 * Print the ASCII equivalent characters
590 * But watch out for the bad unprintable ones...
592 for (j = 0; j < 16; j++) {
593 if (i + j >= count) {
594 acpi_os_printf ("\n");
598 buf_char = buffer[i + j];
599 if ((buf_char > 0x1F && buf_char < 0x2E) ||
600 (buf_char > 0x2F && buf_char < 0x61) ||
601 (buf_char > 0x60 && buf_char < 0x7F)) {
602 acpi_os_printf ("%c", buf_char);
605 acpi_os_printf (".");
609 /* Done with that line. */
611 acpi_os_printf ("\n");