MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / acpi / utilities / utdebug.c
blob4fc32d5964f6116a634f95e894d3231df5c94c79
1 /******************************************************************************
3 * Module Name: utdebug - Debug print routines
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2004, 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.
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
62 * PARAMETERS: None
64 * RETURN: None
66 * DESCRIPTION: Save the current stack pointer
68 ****************************************************************************/
70 void
71 acpi_ut_init_stack_ptr_trace (
72 void)
74 u32 current_sp;
77 acpi_gbl_entry_stack_pointer = ACPI_PTR_DIFF (&current_sp, NULL);
81 /*****************************************************************************
83 * FUNCTION: acpi_ut_track_stack_ptr
85 * PARAMETERS: None
87 * RETURN: None
89 * DESCRIPTION: Save the current stack pointer
91 ****************************************************************************/
93 void
94 acpi_ut_track_stack_ptr (
95 void)
97 acpi_size current_sp;
100 current_sp = ACPI_PTR_DIFF (&current_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
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 struct acpi_debug_print_info *dbg_info,
137 char *format,
138 ...)
140 u32 thread_id;
141 va_list args;
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)) {
149 return;
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
196 * RETURN: None
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,
206 u32 line_number,
207 struct acpi_debug_print_info *dbg_info,
208 char *format,
209 ...)
211 va_list args;
214 if (!(requested_debug_level & acpi_dbg_level) ||
215 !(dbg_info->component_id & acpi_dbg_layer)) {
216 return;
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
234 * RETURN: None
236 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
237 * set in debug_level
239 ****************************************************************************/
241 void
242 acpi_ut_trace (
243 u32 line_number,
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
266 * RETURN: None
268 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
269 * set in debug_level
271 ****************************************************************************/
273 void
274 acpi_ut_trace_ptr (
275 u32 line_number,
276 struct acpi_debug_print_info *dbg_info,
277 void *pointer)
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
298 * RETURN: None
300 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
301 * set in debug_level
303 ****************************************************************************/
305 void
306 acpi_ut_trace_str (
307 u32 line_number,
308 struct acpi_debug_print_info *dbg_info,
309 char *string)
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
331 * RETURN: None
333 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
334 * set in debug_level
336 ****************************************************************************/
338 void
339 acpi_ut_trace_u32 (
340 u32 line_number,
341 struct acpi_debug_print_info *dbg_info,
342 u32 integer)
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
363 * RETURN: None
365 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
366 * set in debug_level
368 ****************************************************************************/
370 void
371 acpi_ut_exit (
372 u32 line_number,
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
394 * RETURN: None
396 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
397 * set in debug_level. Prints exit status also.
399 ****************************************************************************/
401 void
402 acpi_ut_status_exit (
403 u32 line_number,
404 struct acpi_debug_print_info *dbg_info,
405 acpi_status status)
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));
413 else {
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
434 * RETURN: None
436 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
437 * set in debug_level. Prints exit value also.
439 ****************************************************************************/
441 void
442 acpi_ut_value_exit (
443 u32 line_number,
444 struct acpi_debug_print_info *dbg_info,
445 acpi_integer value)
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
467 * RETURN: None
469 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
470 * set in debug_level. Prints exit value also.
472 ****************************************************************************/
474 void
475 acpi_ut_ptr_exit (
476 u32 line_number,
477 struct acpi_debug_print_info *dbg_info,
478 u8 *ptr)
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--;
487 #endif
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
499 * RETURN: None
501 * DESCRIPTION: Generic dump buffer in both hex and ascii.
503 ****************************************************************************/
505 void
506 acpi_ut_dump_buffer (
507 u8 *buffer,
508 u32 count,
509 u32 display,
510 u32 component_id)
512 acpi_native_uint i = 0;
513 acpi_native_uint j;
514 u32 temp32;
515 u8 buf_char;
518 /* Only dump the buffer if tracing is enabled */
520 if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
521 (component_id & acpi_dbg_layer))) {
522 return;
525 if ((count < 4) || (count & 0x01)) {
526 display = DB_BYTE_DISPLAY;
529 acpi_os_printf ("\nOffset Value\n");
532 * Nasty little dump buffer routine!
534 while (i < count) {
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");
544 return;
547 /* Make sure that the s8 doesn't get sign-extended! */
549 switch (display) {
550 /* Default is BYTE display */
552 default:
554 acpi_os_printf ("%02X ",
555 *((u8 *) &buffer[i + j]));
556 j += 1;
557 break;
560 case DB_WORD_DISPLAY:
562 ACPI_MOVE_16_TO_32 (&temp32, &buffer[i + j]);
563 acpi_os_printf ("%04X ", temp32);
564 j += 2;
565 break;
568 case DB_DWORD_DISPLAY:
570 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]);
571 acpi_os_printf ("%08X ", temp32);
572 j += 4;
573 break;
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);
583 j += 8;
584 break;
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");
595 return;
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);
604 else {
605 acpi_os_printf (".");
609 /* Done with that line. */
611 acpi_os_printf ("\n");
612 i += 16;
615 return;