1 /******************************************************************************
3 * Module Name: utdebug - Debug print routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2005, 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")
52 #ifdef ACPI_DEBUG_OUTPUT
54 static u32 acpi_gbl_prev_thread_id = 0xFFFFFFFF;
55 static char *acpi_gbl_fn_entry_str = "----Entry";
56 static char *acpi_gbl_fn_exit_str = "----Exit-";
59 /*******************************************************************************
61 * FUNCTION: acpi_ut_init_stack_ptr_trace
67 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
69 ******************************************************************************/
72 acpi_ut_init_stack_ptr_trace (
78 acpi_gbl_entry_stack_pointer = ACPI_PTR_DIFF (¤t_sp, NULL);
82 /*******************************************************************************
84 * FUNCTION: acpi_ut_track_stack_ptr
90 * DESCRIPTION: Save the current CPU stack pointer
92 ******************************************************************************/
95 acpi_ut_track_stack_ptr (
101 current_sp = ACPI_PTR_DIFF (¤t_sp, NULL);
103 if (current_sp < acpi_gbl_lowest_stack_pointer) {
104 acpi_gbl_lowest_stack_pointer = current_sp;
107 if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) {
108 acpi_gbl_deepest_nesting = acpi_gbl_nesting_level;
113 /*******************************************************************************
115 * FUNCTION: acpi_ut_debug_print
117 * PARAMETERS: requested_debug_level - Requested debug print level
118 * line_number - Caller's line number (for error output)
119 * dbg_info - Contains:
120 * proc_name - Caller's procedure name
121 * module_name - Caller's module name
122 * component_id - Caller's component ID
123 * Format - Printf format field
124 * ... - Optional printf arguments
128 * DESCRIPTION: Print error message with prefix consisting of the module name,
129 * line number, and component ID.
131 ******************************************************************************/
133 void ACPI_INTERNAL_VAR_XFACE
134 acpi_ut_debug_print (
135 u32 requested_debug_level,
137 struct acpi_debug_print_info *dbg_info,
146 * Stay silent if the debug level or component ID is disabled
148 if (!(requested_debug_level & acpi_dbg_level) ||
149 !(dbg_info->component_id & acpi_dbg_layer)) {
154 * Thread tracking and context switch notification
156 thread_id = acpi_os_get_thread_id ();
158 if (thread_id != acpi_gbl_prev_thread_id) {
159 if (ACPI_LV_THREADS & acpi_dbg_level) {
161 "\n**** Context Switch from TID %X to TID %X ****\n\n",
162 acpi_gbl_prev_thread_id, thread_id);
165 acpi_gbl_prev_thread_id = thread_id;
169 * Display the module name, current line number, thread ID (if requested),
170 * current procedure nesting level, and the current procedure name
172 acpi_os_printf ("%8s-%04ld ", dbg_info->module_name, line_number);
174 if (ACPI_LV_THREADS & acpi_dbg_level) {
175 acpi_os_printf ("[%04lX] ", thread_id);
178 acpi_os_printf ("[%02ld] %-22.22s: ",
179 acpi_gbl_nesting_level, dbg_info->proc_name);
181 va_start (args, format);
182 acpi_os_vprintf (format, args);
185 EXPORT_SYMBOL(acpi_ut_debug_print);
187 /*******************************************************************************
189 * FUNCTION: acpi_ut_debug_print_raw
191 * PARAMETERS: requested_debug_level - Requested debug print level
192 * line_number - Caller's line number
193 * dbg_info - Contains:
194 * proc_name - Caller's procedure name
195 * module_name - Caller's module name
196 * component_id - Caller's component ID
197 * Format - Printf format field
198 * ... - Optional printf arguments
202 * DESCRIPTION: Print message with no headers. Has same interface as
203 * debug_print so that the same macros can be used.
205 ******************************************************************************/
207 void ACPI_INTERNAL_VAR_XFACE
208 acpi_ut_debug_print_raw (
209 u32 requested_debug_level,
211 struct acpi_debug_print_info *dbg_info,
218 if (!(requested_debug_level & acpi_dbg_level) ||
219 !(dbg_info->component_id & acpi_dbg_layer)) {
223 va_start (args, format);
224 acpi_os_vprintf (format, args);
226 EXPORT_SYMBOL(acpi_ut_debug_print_raw);
229 /*******************************************************************************
231 * FUNCTION: acpi_ut_trace
233 * PARAMETERS: line_number - Caller's line number
234 * dbg_info - Contains:
235 * proc_name - Caller's procedure name
236 * module_name - Caller's module name
237 * component_id - Caller's component ID
241 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
244 ******************************************************************************/
249 struct acpi_debug_print_info *dbg_info)
252 acpi_gbl_nesting_level++;
253 acpi_ut_track_stack_ptr ();
255 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
256 "%s\n", acpi_gbl_fn_entry_str);
258 EXPORT_SYMBOL(acpi_ut_trace);
261 /*******************************************************************************
263 * FUNCTION: acpi_ut_trace_ptr
265 * PARAMETERS: line_number - Caller's line number
266 * dbg_info - Contains:
267 * proc_name - Caller's procedure name
268 * module_name - Caller's module name
269 * component_id - Caller's component ID
270 * Pointer - Pointer to display
274 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
277 ******************************************************************************/
282 struct acpi_debug_print_info *dbg_info,
285 acpi_gbl_nesting_level++;
286 acpi_ut_track_stack_ptr ();
288 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
289 "%s %p\n", acpi_gbl_fn_entry_str, pointer);
293 /*******************************************************************************
295 * FUNCTION: acpi_ut_trace_str
297 * PARAMETERS: line_number - Caller's line number
298 * dbg_info - Contains:
299 * proc_name - Caller's procedure name
300 * module_name - Caller's module name
301 * component_id - Caller's component ID
302 * String - Additional string to display
306 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
309 ******************************************************************************/
314 struct acpi_debug_print_info *dbg_info,
318 acpi_gbl_nesting_level++;
319 acpi_ut_track_stack_ptr ();
321 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
322 "%s %s\n", acpi_gbl_fn_entry_str, string);
326 /*******************************************************************************
328 * FUNCTION: acpi_ut_trace_u32
330 * PARAMETERS: line_number - Caller's line number
331 * dbg_info - Contains:
332 * proc_name - Caller's procedure name
333 * module_name - Caller's module name
334 * component_id - Caller's component ID
335 * Integer - Integer to display
339 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
342 ******************************************************************************/
347 struct acpi_debug_print_info *dbg_info,
351 acpi_gbl_nesting_level++;
352 acpi_ut_track_stack_ptr ();
354 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
355 "%s %08X\n", acpi_gbl_fn_entry_str, integer);
359 /*******************************************************************************
361 * FUNCTION: acpi_ut_exit
363 * PARAMETERS: line_number - Caller's line number
364 * dbg_info - Contains:
365 * proc_name - Caller's procedure name
366 * module_name - Caller's module name
367 * component_id - Caller's component ID
371 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
374 ******************************************************************************/
379 struct acpi_debug_print_info *dbg_info)
382 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
383 "%s\n", acpi_gbl_fn_exit_str);
385 acpi_gbl_nesting_level--;
387 EXPORT_SYMBOL(acpi_ut_exit);
390 /*******************************************************************************
392 * FUNCTION: acpi_ut_status_exit
394 * PARAMETERS: line_number - Caller's line number
395 * dbg_info - Contains:
396 * proc_name - Caller's procedure name
397 * module_name - Caller's module name
398 * component_id - Caller's component ID
399 * Status - Exit status code
403 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
404 * set in debug_level. Prints exit status also.
406 ******************************************************************************/
409 acpi_ut_status_exit (
411 struct acpi_debug_print_info *dbg_info,
415 if (ACPI_SUCCESS (status)) {
416 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
417 "%s %s\n", acpi_gbl_fn_exit_str,
418 acpi_format_exception (status));
421 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
422 "%s ****Exception****: %s\n", acpi_gbl_fn_exit_str,
423 acpi_format_exception (status));
426 acpi_gbl_nesting_level--;
428 EXPORT_SYMBOL(acpi_ut_status_exit);
431 /*******************************************************************************
433 * FUNCTION: acpi_ut_value_exit
435 * PARAMETERS: line_number - Caller's line number
436 * dbg_info - Contains:
437 * proc_name - Caller's procedure name
438 * module_name - Caller's module name
439 * component_id - Caller's component ID
440 * Value - Value to be printed with exit msg
444 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
445 * set in debug_level. Prints exit value also.
447 ******************************************************************************/
452 struct acpi_debug_print_info *dbg_info,
456 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
457 "%s %8.8X%8.8X\n", acpi_gbl_fn_exit_str,
458 ACPI_FORMAT_UINT64 (value));
460 acpi_gbl_nesting_level--;
462 EXPORT_SYMBOL(acpi_ut_value_exit);
465 /*******************************************************************************
467 * FUNCTION: acpi_ut_ptr_exit
469 * PARAMETERS: line_number - Caller's line number
470 * dbg_info - Contains:
471 * proc_name - Caller's procedure name
472 * module_name - Caller's module name
473 * component_id - Caller's component ID
474 * Ptr - Pointer to display
478 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
479 * set in debug_level. Prints exit value also.
481 ******************************************************************************/
486 struct acpi_debug_print_info *dbg_info,
490 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
491 "%s %p\n", acpi_gbl_fn_exit_str, ptr);
493 acpi_gbl_nesting_level--;
499 /*******************************************************************************
501 * FUNCTION: acpi_ut_dump_buffer
503 * PARAMETERS: Buffer - Buffer to dump
504 * Count - Amount to dump, in bytes
505 * Display - BYTE, WORD, DWORD, or QWORD display
506 * component_iD - Caller's component ID
510 * DESCRIPTION: Generic dump buffer in both hex and ascii.
512 ******************************************************************************/
515 acpi_ut_dump_buffer (
521 acpi_native_uint i = 0;
527 /* Only dump the buffer if tracing is enabled */
529 if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
530 (component_id & acpi_dbg_layer))) {
534 if ((count < 4) || (count & 0x01)) {
535 display = DB_BYTE_DISPLAY;
538 /* Nasty little dump buffer routine! */
541 /* Print current offset */
543 acpi_os_printf ("%6.4X: ", (u32) i);
545 /* Print 16 hex chars */
547 for (j = 0; j < 16;) {
548 if (i + j >= count) {
549 /* Dump fill spaces */
551 acpi_os_printf ("%*s", ((display * 2) + 1), " ");
557 default: /* Default is BYTE display */
559 acpi_os_printf ("%02X ", buffer[i + j]);
563 case DB_WORD_DISPLAY:
565 ACPI_MOVE_16_TO_32 (&temp32, &buffer[i + j]);
566 acpi_os_printf ("%04X ", temp32);
570 case DB_DWORD_DISPLAY:
572 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]);
573 acpi_os_printf ("%08X ", temp32);
577 case DB_QWORD_DISPLAY:
579 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]);
580 acpi_os_printf ("%08X", temp32);
582 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j + 4]);
583 acpi_os_printf ("%08X ", temp32);
591 * Print the ASCII equivalent characters
592 * But watch out for the bad unprintable ones...
594 acpi_os_printf (" ");
595 for (j = 0; j < 16; j++) {
596 if (i + j >= count) {
597 acpi_os_printf ("\n");
601 buf_char = buffer[i + j];
602 if ((buf_char > 0x1F && buf_char < 0x2E) ||
603 (buf_char > 0x2F && buf_char < 0x61) ||
604 (buf_char > 0x60 && buf_char < 0x7F)) {
605 acpi_os_printf ("%c", buf_char);
608 acpi_os_printf (".");
612 /* Done with that line. */
614 acpi_os_printf ("\n");