ACPICA 20050708 from Bob Moore <robert.moore@intel.com>
[linux-2.6/verdex.git] / drivers / acpi / utilities / utdebug.c
blob3d5fbc810b0ba30ecfc12dcb80f7d982fd58a8f4
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 CPU stack pointer at subsystem startup
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 CPU 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: requested_debug_level - Requested debug print level
118 * line_number - Caller's line number (for error output)
119 * function_name - Caller's procedure name
120 * module_name - Caller's module name
121 * component_id - Caller's component ID
122 * Format - Printf format field
123 * ... - Optional printf arguments
125 * RETURN: None
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,
135 u32 line_number,
136 char *function_name,
137 char *module_name,
138 u32 component_id,
139 char *format,
140 ...)
142 u32 thread_id;
143 va_list args;
147 * Stay silent if the debug level or component ID is disabled
149 if (!(requested_debug_level & acpi_dbg_level) ||
150 !(component_id & acpi_dbg_layer)) {
151 return;
155 * Thread tracking and context switch notification
157 thread_id = acpi_os_get_thread_id ();
159 if (thread_id != acpi_gbl_prev_thread_id) {
160 if (ACPI_LV_THREADS & acpi_dbg_level) {
161 acpi_os_printf (
162 "\n**** Context Switch from TID %X to TID %X ****\n\n",
163 acpi_gbl_prev_thread_id, thread_id);
166 acpi_gbl_prev_thread_id = thread_id;
170 * Display the module name, current line number, thread ID (if requested),
171 * current procedure nesting level, and the current procedure name
173 acpi_os_printf ("%8s-%04ld ", module_name, line_number);
175 if (ACPI_LV_THREADS & acpi_dbg_level) {
176 acpi_os_printf ("[%04lX] ", thread_id);
179 acpi_os_printf ("[%02ld] %-22.22s: ",
180 acpi_gbl_nesting_level, function_name);
182 va_start (args, format);
183 acpi_os_vprintf (format, args);
186 EXPORT_SYMBOL(acpi_ut_debug_print);
188 /*******************************************************************************
190 * FUNCTION: acpi_ut_debug_print_raw
192 * PARAMETERS: requested_debug_level - Requested debug print level
193 * line_number - Caller's line number
194 * function_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
200 * RETURN: None
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,
210 u32 line_number,
211 char *function_name,
212 char *module_name,
213 u32 component_id,
214 char *format,
215 ...)
217 va_list args;
220 if (!(requested_debug_level & acpi_dbg_level) ||
221 !(component_id & acpi_dbg_layer)) {
222 return;
225 va_start (args, format);
226 acpi_os_vprintf (format, args);
228 EXPORT_SYMBOL(acpi_ut_debug_print_raw);
231 /*******************************************************************************
233 * FUNCTION: acpi_ut_trace
235 * PARAMETERS: line_number - Caller's line number
236 * function_name - Caller's procedure name
237 * module_name - Caller's module name
238 * component_id - Caller's component ID
240 * RETURN: None
242 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
243 * set in debug_level
245 ******************************************************************************/
247 void
248 acpi_ut_trace (
249 u32 line_number,
250 char *function_name,
251 char *module_name,
252 u32 component_id)
255 acpi_gbl_nesting_level++;
256 acpi_ut_track_stack_ptr ();
258 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
259 line_number, function_name, module_name, component_id,
260 "%s\n", acpi_gbl_fn_entry_str);
262 EXPORT_SYMBOL(acpi_ut_trace);
265 /*******************************************************************************
267 * FUNCTION: acpi_ut_trace_ptr
269 * PARAMETERS: line_number - Caller's line number
270 * function_name - Caller's procedure name
271 * module_name - Caller's module name
272 * component_id - Caller's component ID
273 * Pointer - Pointer to display
275 * RETURN: None
277 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
278 * set in debug_level
280 ******************************************************************************/
282 void
283 acpi_ut_trace_ptr (
284 u32 line_number,
285 char *function_name,
286 char *module_name,
287 u32 component_id,
288 void *pointer)
290 acpi_gbl_nesting_level++;
291 acpi_ut_track_stack_ptr ();
293 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
294 line_number, function_name, module_name, component_id,
295 "%s %p\n", acpi_gbl_fn_entry_str, pointer);
299 /*******************************************************************************
301 * FUNCTION: acpi_ut_trace_str
303 * PARAMETERS: line_number - Caller's line number
304 * function_name - Caller's procedure name
305 * module_name - Caller's module name
306 * component_id - Caller's component ID
307 * String - Additional string to display
309 * RETURN: None
311 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
312 * set in debug_level
314 ******************************************************************************/
316 void
317 acpi_ut_trace_str (
318 u32 line_number,
319 char *function_name,
320 char *module_name,
321 u32 component_id,
322 char *string)
325 acpi_gbl_nesting_level++;
326 acpi_ut_track_stack_ptr ();
328 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
329 line_number, function_name, module_name, component_id,
330 "%s %s\n", acpi_gbl_fn_entry_str, string);
334 /*******************************************************************************
336 * FUNCTION: acpi_ut_trace_u32
338 * PARAMETERS: line_number - Caller's line number
339 * function_name - Caller's procedure name
340 * module_name - Caller's module name
341 * component_id - Caller's component ID
342 * Integer - Integer to display
344 * RETURN: None
346 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
347 * set in debug_level
349 ******************************************************************************/
351 void
352 acpi_ut_trace_u32 (
353 u32 line_number,
354 char *function_name,
355 char *module_name,
356 u32 component_id,
357 u32 integer)
360 acpi_gbl_nesting_level++;
361 acpi_ut_track_stack_ptr ();
363 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
364 line_number, function_name, module_name, component_id,
365 "%s %08X\n", acpi_gbl_fn_entry_str, integer);
369 /*******************************************************************************
371 * FUNCTION: acpi_ut_exit
373 * PARAMETERS: line_number - Caller's line number
374 * function_name - Caller's procedure name
375 * module_name - Caller's module name
376 * component_id - Caller's component ID
378 * RETURN: None
380 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
381 * set in debug_level
383 ******************************************************************************/
385 void
386 acpi_ut_exit (
387 u32 line_number,
388 char *function_name,
389 char *module_name,
390 u32 component_id)
393 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
394 line_number, function_name, module_name, component_id,
395 "%s\n", acpi_gbl_fn_exit_str);
397 acpi_gbl_nesting_level--;
399 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
412 * RETURN: None
414 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
415 * set in debug_level. Prints exit status also.
417 ******************************************************************************/
419 void
420 acpi_ut_status_exit (
421 u32 line_number,
422 char *function_name,
423 char *module_name,
424 u32 component_id,
425 acpi_status status)
428 if (ACPI_SUCCESS (status)) {
429 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
430 line_number, function_name, module_name, component_id,
431 "%s %s\n", acpi_gbl_fn_exit_str,
432 acpi_format_exception (status));
434 else {
435 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
436 line_number, function_name, module_name, component_id,
437 "%s ****Exception****: %s\n", acpi_gbl_fn_exit_str,
438 acpi_format_exception (status));
441 acpi_gbl_nesting_level--;
443 EXPORT_SYMBOL(acpi_ut_status_exit);
446 /*******************************************************************************
448 * FUNCTION: acpi_ut_value_exit
450 * PARAMETERS: line_number - Caller's line number
451 * function_name - Caller's procedure name
452 * module_name - Caller's module name
453 * component_id - Caller's component ID
454 * Value - Value to be printed with exit msg
456 * RETURN: None
458 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
459 * set in debug_level. Prints exit value also.
461 ******************************************************************************/
463 void
464 acpi_ut_value_exit (
465 u32 line_number,
466 char *function_name,
467 char *module_name,
468 u32 component_id,
469 acpi_integer value)
472 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
473 line_number, function_name, module_name, component_id,
474 "%s %8.8X%8.8X\n", acpi_gbl_fn_exit_str,
475 ACPI_FORMAT_UINT64 (value));
477 acpi_gbl_nesting_level--;
479 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
492 * RETURN: None
494 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
495 * set in debug_level. Prints exit value also.
497 ******************************************************************************/
499 void
500 acpi_ut_ptr_exit (
501 u32 line_number,
502 char *function_name,
503 char *module_name,
504 u32 component_id,
505 u8 *ptr)
508 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
509 line_number, function_name, module_name, component_id,
510 "%s %p\n", acpi_gbl_fn_exit_str, ptr);
512 acpi_gbl_nesting_level--;
515 #endif
518 /*******************************************************************************
520 * FUNCTION: acpi_ut_dump_buffer
522 * PARAMETERS: Buffer - Buffer to dump
523 * Count - Amount to dump, in bytes
524 * Display - BYTE, WORD, DWORD, or QWORD display
525 * component_iD - Caller's component ID
527 * RETURN: None
529 * DESCRIPTION: Generic dump buffer in both hex and ascii.
531 ******************************************************************************/
533 void
534 acpi_ut_dump_buffer (
535 u8 *buffer,
536 u32 count,
537 u32 display,
538 u32 component_id)
540 acpi_native_uint i = 0;
541 acpi_native_uint j;
542 u32 temp32;
543 u8 buf_char;
546 /* Only dump the buffer if tracing is enabled */
548 if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
549 (component_id & acpi_dbg_layer))) {
550 return;
553 if ((count < 4) || (count & 0x01)) {
554 display = DB_BYTE_DISPLAY;
557 /* Nasty little dump buffer routine! */
559 while (i < count) {
560 /* Print current offset */
562 acpi_os_printf ("%6.4X: ", (u32) i);
564 /* Print 16 hex chars */
566 for (j = 0; j < 16;) {
567 if (i + j >= count) {
568 /* Dump fill spaces */
570 acpi_os_printf ("%*s", ((display * 2) + 1), " ");
571 j += (acpi_native_uint) display;
572 continue;
575 switch (display) {
576 default: /* Default is BYTE display */
578 acpi_os_printf ("%02X ", buffer[i + j]);
579 break;
582 case DB_WORD_DISPLAY:
584 ACPI_MOVE_16_TO_32 (&temp32, &buffer[i + j]);
585 acpi_os_printf ("%04X ", temp32);
586 break;
589 case DB_DWORD_DISPLAY:
591 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]);
592 acpi_os_printf ("%08X ", temp32);
593 break;
596 case DB_QWORD_DISPLAY:
598 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]);
599 acpi_os_printf ("%08X", temp32);
601 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j + 4]);
602 acpi_os_printf ("%08X ", temp32);
603 break;
606 j += (acpi_native_uint) display;
610 * Print the ASCII equivalent characters
611 * But watch out for the bad unprintable ones...
613 acpi_os_printf (" ");
614 for (j = 0; j < 16; j++) {
615 if (i + j >= count) {
616 acpi_os_printf ("\n");
617 return;
620 buf_char = buffer[i + j];
621 if ((buf_char > 0x1F && buf_char < 0x2E) ||
622 (buf_char > 0x2F && buf_char < 0x61) ||
623 (buf_char > 0x60 && buf_char < 0x7F)) {
624 acpi_os_printf ("%c", buf_char);
626 else {
627 acpi_os_printf (".");
631 /* Done with that line. */
633 acpi_os_printf ("\n");
634 i += 16;
637 return;