ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / drivers / acpi / utilities / utdebug.c
1 /******************************************************************************
2  *
3  * Module Name: utdebug - Debug print routines
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2004, R. Byron Moore
9  * All rights reserved.
10  *
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.
25  *
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.
29  *
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.
42  */
43
44
45 #include <acpi/acpi.h>
46
47 #define _COMPONENT          ACPI_UTILITIES
48          ACPI_MODULE_NAME    ("utdebug")
49
50
51 #ifdef ACPI_DEBUG_OUTPUT
52
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-";
56
57
58 /*****************************************************************************
59  *
60  * FUNCTION:    acpi_ut_init_stack_ptr_trace
61  *
62  * PARAMETERS:  None
63  *
64  * RETURN:      None
65  *
66  * DESCRIPTION: Save the current stack pointer
67  *
68  ****************************************************************************/
69
70 void
71 acpi_ut_init_stack_ptr_trace (
72         void)
73 {
74         u32                         current_sp;
75
76
77         acpi_gbl_entry_stack_pointer = ACPI_PTR_DIFF (&current_sp, NULL);
78 }
79
80
81 /*****************************************************************************
82  *
83  * FUNCTION:    acpi_ut_track_stack_ptr
84  *
85  * PARAMETERS:  None
86  *
87  * RETURN:      None
88  *
89  * DESCRIPTION: Save the current stack pointer
90  *
91  ****************************************************************************/
92
93 void
94 acpi_ut_track_stack_ptr (
95         void)
96 {
97         acpi_size                   current_sp;
98
99
100         current_sp = ACPI_PTR_DIFF (&current_sp, NULL);
101
102         if (current_sp < acpi_gbl_lowest_stack_pointer) {
103                 acpi_gbl_lowest_stack_pointer = current_sp;
104         }
105
106         if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) {
107                 acpi_gbl_deepest_nesting = acpi_gbl_nesting_level;
108         }
109 }
110
111
112 /*****************************************************************************
113  *
114  * FUNCTION:    acpi_ut_debug_print
115  *
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)
121  *
122  *              Format              - Printf format field
123  *              ...                 - Optional printf arguments
124  *
125  * RETURN:      None
126  *
127  * DESCRIPTION: Print error message with prefix consisting of the module name,
128  *              line number, and component ID.
129  *
130  ****************************************************************************/
131
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         ...)
139 {
140         u32                             thread_id;
141         va_list                 args;
142
143
144         /*
145          * Stay silent if the debug level or component ID is disabled
146          */
147         if (!(requested_debug_level & acpi_dbg_level) ||
148                 !(dbg_info->component_id & acpi_dbg_layer)) {
149                 return;
150         }
151
152         /*
153          * Thread tracking and context switch notification
154          */
155         thread_id = acpi_os_get_thread_id ();
156
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);
161                 }
162
163                 acpi_gbl_prev_thread_id = thread_id;
164         }
165
166         /*
167          * Display the module name, current line number, thread ID (if requested),
168          * current procedure nesting level, and the current procedure name
169          */
170         acpi_os_printf ("%8s-%04ld ", dbg_info->module_name, line_number);
171
172         if (ACPI_LV_THREADS & acpi_dbg_level) {
173                 acpi_os_printf ("[%04lX] ", thread_id);
174         }
175
176         acpi_os_printf ("[%02ld] %-22.22s: ", acpi_gbl_nesting_level, dbg_info->proc_name);
177
178         va_start (args, format);
179         acpi_os_vprintf (format, args);
180 }
181
182
183 /*****************************************************************************
184  *
185  * FUNCTION:    acpi_ut_debug_print_raw
186  *
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
195  *
196  * RETURN:      None
197  *
198  * DESCRIPTION: Print message with no headers.  Has same interface as
199  *              debug_print so that the same macros can be used.
200  *
201  ****************************************************************************/
202
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         ...)
210 {
211         va_list                 args;
212
213
214         if (!(requested_debug_level & acpi_dbg_level) ||
215                 !(dbg_info->component_id & acpi_dbg_layer)) {
216                 return;
217         }
218
219         va_start (args, format);
220         acpi_os_vprintf (format, args);
221 }
222
223
224 /*****************************************************************************
225  *
226  * FUNCTION:    acpi_ut_trace
227  *
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
233  *
234  * RETURN:      None
235  *
236  * DESCRIPTION: Function entry trace.  Prints only if TRACE_FUNCTIONS bit is
237  *              set in debug_level
238  *
239  ****************************************************************************/
240
241 void
242 acpi_ut_trace (
243         u32                             line_number,
244         struct acpi_debug_print_info    *dbg_info)
245 {
246
247         acpi_gbl_nesting_level++;
248         acpi_ut_track_stack_ptr ();
249
250         acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
251                         "%s\n", acpi_gbl_fn_entry_str);
252 }
253
254
255 /*****************************************************************************
256  *
257  * FUNCTION:    acpi_ut_trace_ptr
258  *
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
265  *
266  * RETURN:      None
267  *
268  * DESCRIPTION: Function entry trace.  Prints only if TRACE_FUNCTIONS bit is
269  *              set in debug_level
270  *
271  ****************************************************************************/
272
273 void
274 acpi_ut_trace_ptr (
275         u32                             line_number,
276         struct acpi_debug_print_info    *dbg_info,
277         void                            *pointer)
278 {
279         acpi_gbl_nesting_level++;
280         acpi_ut_track_stack_ptr ();
281
282         acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
283                         "%s %p\n", acpi_gbl_fn_entry_str, pointer);
284 }
285
286
287 /*****************************************************************************
288  *
289  * FUNCTION:    acpi_ut_trace_str
290  *
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
297  *
298  * RETURN:      None
299  *
300  * DESCRIPTION: Function entry trace.  Prints only if TRACE_FUNCTIONS bit is
301  *              set in debug_level
302  *
303  ****************************************************************************/
304
305 void
306 acpi_ut_trace_str (
307         u32                             line_number,
308         struct acpi_debug_print_info    *dbg_info,
309         char                            *string)
310 {
311
312         acpi_gbl_nesting_level++;
313         acpi_ut_track_stack_ptr ();
314
315         acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
316                         "%s %s\n", acpi_gbl_fn_entry_str, string);
317 }
318
319
320 /*****************************************************************************
321  *
322  * FUNCTION:    acpi_ut_trace_u32
323  *
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
330  *
331  * RETURN:      None
332  *
333  * DESCRIPTION: Function entry trace.  Prints only if TRACE_FUNCTIONS bit is
334  *              set in debug_level
335  *
336  ****************************************************************************/
337
338 void
339 acpi_ut_trace_u32 (
340         u32                             line_number,
341         struct acpi_debug_print_info    *dbg_info,
342         u32                             integer)
343 {
344
345         acpi_gbl_nesting_level++;
346         acpi_ut_track_stack_ptr ();
347
348         acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
349                         "%s %08X\n", acpi_gbl_fn_entry_str, integer);
350 }
351
352
353 /*****************************************************************************
354  *
355  * FUNCTION:    acpi_ut_exit
356  *
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
362  *
363  * RETURN:      None
364  *
365  * DESCRIPTION: Function exit trace.  Prints only if TRACE_FUNCTIONS bit is
366  *              set in debug_level
367  *
368  ****************************************************************************/
369
370 void
371 acpi_ut_exit (
372         u32                             line_number,
373         struct acpi_debug_print_info    *dbg_info)
374 {
375
376         acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
377                         "%s\n", acpi_gbl_fn_exit_str);
378
379         acpi_gbl_nesting_level--;
380 }
381
382
383 /*****************************************************************************
384  *
385  * FUNCTION:    acpi_ut_status_exit
386  *
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
393  *
394  * RETURN:      None
395  *
396  * DESCRIPTION: Function exit trace.  Prints only if TRACE_FUNCTIONS bit is
397  *              set in debug_level. Prints exit status also.
398  *
399  ****************************************************************************/
400
401 void
402 acpi_ut_status_exit (
403         u32                             line_number,
404         struct acpi_debug_print_info    *dbg_info,
405         acpi_status                     status)
406 {
407
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));
412         }
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));
417         }
418
419         acpi_gbl_nesting_level--;
420 }
421
422
423 /*****************************************************************************
424  *
425  * FUNCTION:    acpi_ut_value_exit
426  *
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
433  *
434  * RETURN:      None
435  *
436  * DESCRIPTION: Function exit trace.  Prints only if TRACE_FUNCTIONS bit is
437  *              set in debug_level. Prints exit value also.
438  *
439  ****************************************************************************/
440
441 void
442 acpi_ut_value_exit (
443         u32                             line_number,
444         struct acpi_debug_print_info    *dbg_info,
445         acpi_integer                    value)
446 {
447
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));
451
452         acpi_gbl_nesting_level--;
453 }
454
455
456 /*****************************************************************************
457  *
458  * FUNCTION:    acpi_ut_ptr_exit
459  *
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
466  *
467  * RETURN:      None
468  *
469  * DESCRIPTION: Function exit trace.  Prints only if TRACE_FUNCTIONS bit is
470  *              set in debug_level. Prints exit value also.
471  *
472  ****************************************************************************/
473
474 void
475 acpi_ut_ptr_exit (
476         u32                             line_number,
477         struct acpi_debug_print_info    *dbg_info,
478         u8                              *ptr)
479 {
480
481         acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
482                         "%s %p\n", acpi_gbl_fn_exit_str, ptr);
483
484         acpi_gbl_nesting_level--;
485 }
486
487 #endif
488
489
490 /*****************************************************************************
491  *
492  * FUNCTION:    acpi_ut_dump_buffer
493  *
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
498  *
499  * RETURN:      None
500  *
501  * DESCRIPTION: Generic dump buffer in both hex and ascii.
502  *
503  ****************************************************************************/
504
505 void
506 acpi_ut_dump_buffer (
507         u8                              *buffer,
508         u32                             count,
509         u32                             display,
510         u32                             component_id)
511 {
512         acpi_native_uint                i = 0;
513         acpi_native_uint                j;
514         u32                             temp32;
515         u8                              buf_char;
516
517
518         /* Only dump the buffer if tracing is enabled */
519
520         if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
521                 (component_id & acpi_dbg_layer))) {
522                 return;
523         }
524
525         if ((count < 4) || (count & 0x01)) {
526                 display = DB_BYTE_DISPLAY;
527         }
528
529         acpi_os_printf ("\nOffset Value\n");
530
531         /*
532          * Nasty little dump buffer routine!
533          */
534         while (i < count) {
535                 /* Print current offset */
536
537                 acpi_os_printf ("%05X  ", (u32) i);
538
539                 /* Print 16 hex chars */
540
541                 for (j = 0; j < 16;) {
542                         if (i + j >= count) {
543                                 acpi_os_printf ("\n");
544                                 return;
545                         }
546
547                         /* Make sure that the s8 doesn't get sign-extended! */
548
549                         switch (display) {
550                         /* Default is BYTE display */
551
552                         default:
553
554                                 acpi_os_printf ("%02X ",
555                                                 *((u8 *) &buffer[i + j]));
556                                 j += 1;
557                                 break;
558
559
560                         case DB_WORD_DISPLAY:
561
562                                 ACPI_MOVE_16_TO_32 (&temp32, &buffer[i + j]);
563                                 acpi_os_printf ("%04X ", temp32);
564                                 j += 2;
565                                 break;
566
567
568                         case DB_DWORD_DISPLAY:
569
570                                 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]);
571                                 acpi_os_printf ("%08X ", temp32);
572                                 j += 4;
573                                 break;
574
575
576                         case DB_QWORD_DISPLAY:
577
578                                 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]);
579                                 acpi_os_printf ("%08X", temp32);
580
581                                 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j + 4]);
582                                 acpi_os_printf ("%08X ", temp32);
583                                 j += 8;
584                                 break;
585                         }
586                 }
587
588                 /*
589                  * Print the ASCII equivalent characters
590                  * But watch out for the bad unprintable ones...
591                  */
592                 for (j = 0; j < 16; j++) {
593                         if (i + j >= count) {
594                                 acpi_os_printf ("\n");
595                                 return;
596                         }
597
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);
603                         }
604                         else {
605                                 acpi_os_printf (".");
606                         }
607                 }
608
609                 /* Done with that line. */
610
611                 acpi_os_printf ("\n");
612                 i += 16;
613         }
614
615         return;
616 }
617