Linux-2.6.12-rc2
[linux-2.6/kvm.git] / drivers / acpi / utilities / utdebug.c
blob985c5d045b78dd17cd47c0b7336612f8eaf16752
1 /******************************************************************************
3 * Module Name: utdebug - Debug print routines
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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
63 * PARAMETERS: None
65 * RETURN: None
67 * DESCRIPTION: Save the current stack pointer
69 ****************************************************************************/
71 void
72 acpi_ut_init_stack_ptr_trace (
73 void)
75 u32 current_sp;
78 acpi_gbl_entry_stack_pointer = ACPI_PTR_DIFF (&current_sp, NULL);
82 /*****************************************************************************
84 * FUNCTION: acpi_ut_track_stack_ptr
86 * PARAMETERS: None
88 * RETURN: None
90 * DESCRIPTION: Save the current stack pointer
92 ****************************************************************************/
94 void
95 acpi_ut_track_stack_ptr (
96 void)
98 acpi_size current_sp;
101 current_sp = ACPI_PTR_DIFF (&current_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: debug_level - Requested debug print level
118 * proc_name - Caller's procedure name
119 * module_name - Caller's module name (for error output)
120 * line_number - Caller's line number (for error output)
121 * component_id - Caller's component ID (for error output)
123 * Format - Printf format field
124 * ... - Optional printf arguments
126 * RETURN: None
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,
136 u32 line_number,
137 struct acpi_debug_print_info *dbg_info,
138 char *format,
139 ...)
141 u32 thread_id;
142 va_list args;
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)) {
150 return;
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) {
160 acpi_os_printf ("\n**** Context Switch from TID %X to TID %X ****\n\n",
161 acpi_gbl_prev_thread_id, thread_id);
164 acpi_gbl_prev_thread_id = thread_id;
168 * Display the module name, current line number, thread ID (if requested),
169 * current procedure nesting level, and the current procedure name
171 acpi_os_printf ("%8s-%04ld ", dbg_info->module_name, line_number);
173 if (ACPI_LV_THREADS & acpi_dbg_level) {
174 acpi_os_printf ("[%04lX] ", thread_id);
177 acpi_os_printf ("[%02ld] %-22.22s: ", acpi_gbl_nesting_level, dbg_info->proc_name);
179 va_start (args, format);
180 acpi_os_vprintf (format, args);
182 EXPORT_SYMBOL(acpi_ut_debug_print);
185 /*****************************************************************************
187 * FUNCTION: acpi_ut_debug_print_raw
189 * PARAMETERS: requested_debug_level - Requested debug print level
190 * line_number - Caller's line number
191 * dbg_info - Contains:
192 * proc_name - Caller's procedure name
193 * module_name - Caller's module name
194 * component_id - Caller's component ID
195 * Format - Printf format field
196 * ... - Optional printf arguments
198 * RETURN: None
200 * DESCRIPTION: Print message with no headers. Has same interface as
201 * debug_print so that the same macros can be used.
203 ****************************************************************************/
205 void ACPI_INTERNAL_VAR_XFACE
206 acpi_ut_debug_print_raw (
207 u32 requested_debug_level,
208 u32 line_number,
209 struct acpi_debug_print_info *dbg_info,
210 char *format,
211 ...)
213 va_list args;
216 if (!(requested_debug_level & acpi_dbg_level) ||
217 !(dbg_info->component_id & acpi_dbg_layer)) {
218 return;
221 va_start (args, format);
222 acpi_os_vprintf (format, args);
224 EXPORT_SYMBOL(acpi_ut_debug_print_raw);
227 /*****************************************************************************
229 * FUNCTION: acpi_ut_trace
231 * PARAMETERS: line_number - Caller's line number
232 * dbg_info - Contains:
233 * proc_name - Caller's procedure name
234 * module_name - Caller's module name
235 * component_id - Caller's component ID
237 * RETURN: None
239 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
240 * set in debug_level
242 ****************************************************************************/
244 void
245 acpi_ut_trace (
246 u32 line_number,
247 struct acpi_debug_print_info *dbg_info)
250 acpi_gbl_nesting_level++;
251 acpi_ut_track_stack_ptr ();
253 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
254 "%s\n", acpi_gbl_fn_entry_str);
256 EXPORT_SYMBOL(acpi_ut_trace);
259 /*****************************************************************************
261 * FUNCTION: acpi_ut_trace_ptr
263 * PARAMETERS: line_number - Caller's line number
264 * dbg_info - Contains:
265 * proc_name - Caller's procedure name
266 * module_name - Caller's module name
267 * component_id - Caller's component ID
268 * Pointer - Pointer to display
270 * RETURN: None
272 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
273 * set in debug_level
275 ****************************************************************************/
277 void
278 acpi_ut_trace_ptr (
279 u32 line_number,
280 struct acpi_debug_print_info *dbg_info,
281 void *pointer)
283 acpi_gbl_nesting_level++;
284 acpi_ut_track_stack_ptr ();
286 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
287 "%s %p\n", acpi_gbl_fn_entry_str, pointer);
291 /*****************************************************************************
293 * FUNCTION: acpi_ut_trace_str
295 * PARAMETERS: line_number - Caller's line number
296 * dbg_info - Contains:
297 * proc_name - Caller's procedure name
298 * module_name - Caller's module name
299 * component_id - Caller's component ID
300 * String - Additional string to display
302 * RETURN: None
304 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
305 * set in debug_level
307 ****************************************************************************/
309 void
310 acpi_ut_trace_str (
311 u32 line_number,
312 struct acpi_debug_print_info *dbg_info,
313 char *string)
316 acpi_gbl_nesting_level++;
317 acpi_ut_track_stack_ptr ();
319 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
320 "%s %s\n", acpi_gbl_fn_entry_str, string);
324 /*****************************************************************************
326 * FUNCTION: acpi_ut_trace_u32
328 * PARAMETERS: line_number - Caller's line number
329 * dbg_info - Contains:
330 * proc_name - Caller's procedure name
331 * module_name - Caller's module name
332 * component_id - Caller's component ID
333 * Integer - Integer to display
335 * RETURN: None
337 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
338 * set in debug_level
340 ****************************************************************************/
342 void
343 acpi_ut_trace_u32 (
344 u32 line_number,
345 struct acpi_debug_print_info *dbg_info,
346 u32 integer)
349 acpi_gbl_nesting_level++;
350 acpi_ut_track_stack_ptr ();
352 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
353 "%s %08X\n", acpi_gbl_fn_entry_str, integer);
357 /*****************************************************************************
359 * FUNCTION: acpi_ut_exit
361 * PARAMETERS: line_number - Caller's line number
362 * dbg_info - Contains:
363 * proc_name - Caller's procedure name
364 * module_name - Caller's module name
365 * component_id - Caller's component ID
367 * RETURN: None
369 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
370 * set in debug_level
372 ****************************************************************************/
374 void
375 acpi_ut_exit (
376 u32 line_number,
377 struct acpi_debug_print_info *dbg_info)
380 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
381 "%s\n", acpi_gbl_fn_exit_str);
383 acpi_gbl_nesting_level--;
385 EXPORT_SYMBOL(acpi_ut_exit);
388 /*****************************************************************************
390 * FUNCTION: acpi_ut_status_exit
392 * PARAMETERS: line_number - Caller's line number
393 * dbg_info - Contains:
394 * proc_name - Caller's procedure name
395 * module_name - Caller's module name
396 * component_id - Caller's component ID
397 * Status - Exit status code
399 * RETURN: None
401 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
402 * set in debug_level. Prints exit status also.
404 ****************************************************************************/
406 void
407 acpi_ut_status_exit (
408 u32 line_number,
409 struct acpi_debug_print_info *dbg_info,
410 acpi_status status)
413 if (ACPI_SUCCESS (status)) {
414 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
415 "%s %s\n", acpi_gbl_fn_exit_str,
416 acpi_format_exception (status));
418 else {
419 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
420 "%s ****Exception****: %s\n", acpi_gbl_fn_exit_str,
421 acpi_format_exception (status));
424 acpi_gbl_nesting_level--;
426 EXPORT_SYMBOL(acpi_ut_status_exit);
429 /*****************************************************************************
431 * FUNCTION: acpi_ut_value_exit
433 * PARAMETERS: line_number - Caller's line number
434 * dbg_info - Contains:
435 * proc_name - Caller's procedure name
436 * module_name - Caller's module name
437 * component_id - Caller's component ID
438 * Value - Value to be printed with exit msg
440 * RETURN: None
442 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
443 * set in debug_level. Prints exit value also.
445 ****************************************************************************/
447 void
448 acpi_ut_value_exit (
449 u32 line_number,
450 struct acpi_debug_print_info *dbg_info,
451 acpi_integer value)
454 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
455 "%s %8.8X%8.8X\n", acpi_gbl_fn_exit_str,
456 ACPI_FORMAT_UINT64 (value));
458 acpi_gbl_nesting_level--;
460 EXPORT_SYMBOL(acpi_ut_value_exit);
463 /*****************************************************************************
465 * FUNCTION: acpi_ut_ptr_exit
467 * PARAMETERS: line_number - Caller's line number
468 * dbg_info - Contains:
469 * proc_name - Caller's procedure name
470 * module_name - Caller's module name
471 * component_id - Caller's component ID
472 * Value - Value to be printed with exit msg
474 * RETURN: None
476 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
477 * set in debug_level. Prints exit value also.
479 ****************************************************************************/
481 void
482 acpi_ut_ptr_exit (
483 u32 line_number,
484 struct acpi_debug_print_info *dbg_info,
485 u8 *ptr)
488 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
489 "%s %p\n", acpi_gbl_fn_exit_str, ptr);
491 acpi_gbl_nesting_level--;
494 #endif
497 /*****************************************************************************
499 * FUNCTION: acpi_ut_dump_buffer
501 * PARAMETERS: Buffer - Buffer to dump
502 * Count - Amount to dump, in bytes
503 * Display - BYTE, WORD, DWORD, or QWORD display
504 * component_iD - Caller's component ID
506 * RETURN: None
508 * DESCRIPTION: Generic dump buffer in both hex and ascii.
510 ****************************************************************************/
512 void
513 acpi_ut_dump_buffer (
514 u8 *buffer,
515 u32 count,
516 u32 display,
517 u32 component_id)
519 acpi_native_uint i = 0;
520 acpi_native_uint j;
521 u32 temp32;
522 u8 buf_char;
525 /* Only dump the buffer if tracing is enabled */
527 if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
528 (component_id & acpi_dbg_layer))) {
529 return;
532 if ((count < 4) || (count & 0x01)) {
533 display = DB_BYTE_DISPLAY;
536 acpi_os_printf ("\nOffset Value\n");
539 * Nasty little dump buffer routine!
541 while (i < count) {
542 /* Print current offset */
544 acpi_os_printf ("%05X ", (u32) i);
546 /* Print 16 hex chars */
548 for (j = 0; j < 16;) {
549 if (i + j >= count) {
550 acpi_os_printf ("\n");
551 return;
554 /* Make sure that the s8 doesn't get sign-extended! */
556 switch (display) {
557 /* Default is BYTE display */
559 default:
561 acpi_os_printf ("%02X ",
562 *((u8 *) &buffer[i + j]));
563 j += 1;
564 break;
567 case DB_WORD_DISPLAY:
569 ACPI_MOVE_16_TO_32 (&temp32, &buffer[i + j]);
570 acpi_os_printf ("%04X ", temp32);
571 j += 2;
572 break;
575 case DB_DWORD_DISPLAY:
577 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]);
578 acpi_os_printf ("%08X ", temp32);
579 j += 4;
580 break;
583 case DB_QWORD_DISPLAY:
585 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]);
586 acpi_os_printf ("%08X", temp32);
588 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j + 4]);
589 acpi_os_printf ("%08X ", temp32);
590 j += 8;
591 break;
596 * Print the ASCII equivalent characters
597 * But watch out for the bad unprintable ones...
599 for (j = 0; j < 16; j++) {
600 if (i + j >= count) {
601 acpi_os_printf ("\n");
602 return;
605 buf_char = buffer[i + j];
606 if ((buf_char > 0x1F && buf_char < 0x2E) ||
607 (buf_char > 0x2F && buf_char < 0x61) ||
608 (buf_char > 0x60 && buf_char < 0x7F)) {
609 acpi_os_printf ("%c", buf_char);
611 else {
612 acpi_os_printf (".");
616 /* Done with that line. */
618 acpi_os_printf ("\n");
619 i += 16;
622 return;