[ACPI] ACPICA 20050729 from Bob Moore
[deliverable/linux.git] / drivers / acpi / utilities / utdebug.c
1 /******************************************************************************
2 *
3 * Module Name: utdebug - Debug print routines
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2005, 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 #include <linux/module.h>
45
46 #include <acpi/acpi.h>
47
48 #define _COMPONENT ACPI_UTILITIES
49 ACPI_MODULE_NAME ("utdebug")
50
51
52 #ifdef ACPI_DEBUG_OUTPUT
53
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-";
57
58 /* Local prototypes */
59
60 static const char *
61 acpi_ut_trim_function_name (
62 const char *function_name);
63
64
65 /*******************************************************************************
66 *
67 * FUNCTION: acpi_ut_init_stack_ptr_trace
68 *
69 * PARAMETERS: None
70 *
71 * RETURN: None
72 *
73 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
74 *
75 ******************************************************************************/
76
77 void
78 acpi_ut_init_stack_ptr_trace (
79 void)
80 {
81 u32 current_sp;
82
83
84 acpi_gbl_entry_stack_pointer = ACPI_PTR_DIFF (&current_sp, NULL);
85 }
86
87
88 /*******************************************************************************
89 *
90 * FUNCTION: acpi_ut_track_stack_ptr
91 *
92 * PARAMETERS: None
93 *
94 * RETURN: None
95 *
96 * DESCRIPTION: Save the current CPU stack pointer
97 *
98 ******************************************************************************/
99
100 void
101 acpi_ut_track_stack_ptr (
102 void)
103 {
104 acpi_size current_sp;
105
106
107 current_sp = ACPI_PTR_DIFF (&current_sp, NULL);
108
109 if (current_sp < acpi_gbl_lowest_stack_pointer) {
110 acpi_gbl_lowest_stack_pointer = current_sp;
111 }
112
113 if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) {
114 acpi_gbl_deepest_nesting = acpi_gbl_nesting_level;
115 }
116 }
117
118
119 /*******************************************************************************
120 *
121 * FUNCTION: acpi_ut_trim_function_name
122 *
123 * PARAMETERS: function_name - Ascii string containing a procedure name
124 *
125 * RETURN: Updated pointer to the function name
126 *
127 * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
128 * This allows compiler macros such as __FUNCTION__ to be used
129 * with no change to the debug output.
130 *
131 ******************************************************************************/
132
133 static const char *
134 acpi_ut_trim_function_name (
135 const char *function_name)
136 {
137
138 /* All Function names are longer than 4 chars, check is safe */
139
140 if (*(ACPI_CAST_PTR (u32, function_name)) == ACPI_FUNCTION_PREFIX1) {
141 /* This is the case where the original source has not been modified */
142
143 return (function_name + 4);
144 }
145
146 if (*(ACPI_CAST_PTR (u32, function_name)) == ACPI_FUNCTION_PREFIX2) {
147 /* This is the case where the source has been 'linuxized' */
148
149 return (function_name + 5);
150 }
151
152 return (function_name);
153 }
154
155
156 /*******************************************************************************
157 *
158 * FUNCTION: acpi_ut_debug_print
159 *
160 * PARAMETERS: requested_debug_level - Requested debug print level
161 * line_number - Caller's line number (for error output)
162 * function_name - Caller's procedure name
163 * module_name - Caller's module name
164 * component_id - Caller's component ID
165 * Format - Printf format field
166 * ... - Optional printf arguments
167 *
168 * RETURN: None
169 *
170 * DESCRIPTION: Print error message with prefix consisting of the module name,
171 * line number, and component ID.
172 *
173 ******************************************************************************/
174
175 void ACPI_INTERNAL_VAR_XFACE
176 acpi_ut_debug_print (
177 u32 requested_debug_level,
178 u32 line_number,
179 const char *function_name,
180 char *module_name,
181 u32 component_id,
182 char *format,
183 ...)
184 {
185 u32 thread_id;
186 va_list args;
187
188
189 /*
190 * Stay silent if the debug level or component ID is disabled
191 */
192 if (!(requested_debug_level & acpi_dbg_level) ||
193 !(component_id & acpi_dbg_layer)) {
194 return;
195 }
196
197 /*
198 * Thread tracking and context switch notification
199 */
200 thread_id = acpi_os_get_thread_id ();
201
202 if (thread_id != acpi_gbl_prev_thread_id) {
203 if (ACPI_LV_THREADS & acpi_dbg_level) {
204 acpi_os_printf (
205 "\n**** Context Switch from TID %X to TID %X ****\n\n",
206 acpi_gbl_prev_thread_id, thread_id);
207 }
208
209 acpi_gbl_prev_thread_id = thread_id;
210 }
211
212 /*
213 * Display the module name, current line number, thread ID (if requested),
214 * current procedure nesting level, and the current procedure name
215 */
216 acpi_os_printf ("%8s-%04ld ", module_name, line_number);
217
218 if (ACPI_LV_THREADS & acpi_dbg_level) {
219 acpi_os_printf ("[%04lX] ", thread_id);
220 }
221
222 acpi_os_printf ("[%02ld] %-22.22s: ",
223 acpi_gbl_nesting_level, acpi_ut_trim_function_name (function_name));
224
225 va_start (args, format);
226 acpi_os_vprintf (format, args);
227 }
228
229 EXPORT_SYMBOL(acpi_ut_debug_print);
230
231 /*******************************************************************************
232 *
233 * FUNCTION: acpi_ut_debug_print_raw
234 *
235 * PARAMETERS: requested_debug_level - Requested debug print level
236 * line_number - Caller's line number
237 * function_name - Caller's procedure name
238 * module_name - Caller's module name
239 * component_id - Caller's component ID
240 * Format - Printf format field
241 * ... - Optional printf arguments
242 *
243 * RETURN: None
244 *
245 * DESCRIPTION: Print message with no headers. Has same interface as
246 * debug_print so that the same macros can be used.
247 *
248 ******************************************************************************/
249
250 void ACPI_INTERNAL_VAR_XFACE
251 acpi_ut_debug_print_raw (
252 u32 requested_debug_level,
253 u32 line_number,
254 const char *function_name,
255 char *module_name,
256 u32 component_id,
257 char *format,
258 ...)
259 {
260 va_list args;
261
262
263 if (!(requested_debug_level & acpi_dbg_level) ||
264 !(component_id & acpi_dbg_layer)) {
265 return;
266 }
267
268 va_start (args, format);
269 acpi_os_vprintf (format, args);
270 }
271 EXPORT_SYMBOL(acpi_ut_debug_print_raw);
272
273
274 /*******************************************************************************
275 *
276 * FUNCTION: acpi_ut_trace
277 *
278 * PARAMETERS: line_number - Caller's line number
279 * function_name - Caller's procedure name
280 * module_name - Caller's module name
281 * component_id - Caller's component ID
282 *
283 * RETURN: None
284 *
285 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
286 * set in debug_level
287 *
288 ******************************************************************************/
289
290 void
291 acpi_ut_trace (
292 u32 line_number,
293 const char *function_name,
294 char *module_name,
295 u32 component_id)
296 {
297
298 acpi_gbl_nesting_level++;
299 acpi_ut_track_stack_ptr ();
300
301 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
302 line_number, function_name, module_name, component_id,
303 "%s\n", acpi_gbl_fn_entry_str);
304 }
305 EXPORT_SYMBOL(acpi_ut_trace);
306
307
308 /*******************************************************************************
309 *
310 * FUNCTION: acpi_ut_trace_ptr
311 *
312 * PARAMETERS: line_number - Caller's line number
313 * function_name - Caller's procedure name
314 * module_name - Caller's module name
315 * component_id - Caller's component ID
316 * Pointer - Pointer to display
317 *
318 * RETURN: None
319 *
320 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
321 * set in debug_level
322 *
323 ******************************************************************************/
324
325 void
326 acpi_ut_trace_ptr (
327 u32 line_number,
328 const char *function_name,
329 char *module_name,
330 u32 component_id,
331 void *pointer)
332 {
333 acpi_gbl_nesting_level++;
334 acpi_ut_track_stack_ptr ();
335
336 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
337 line_number, function_name, module_name, component_id,
338 "%s %p\n", acpi_gbl_fn_entry_str, pointer);
339 }
340
341
342 /*******************************************************************************
343 *
344 * FUNCTION: acpi_ut_trace_str
345 *
346 * PARAMETERS: line_number - Caller's line number
347 * function_name - Caller's procedure name
348 * module_name - Caller's module name
349 * component_id - Caller's component ID
350 * String - Additional string to display
351 *
352 * RETURN: None
353 *
354 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
355 * set in debug_level
356 *
357 ******************************************************************************/
358
359 void
360 acpi_ut_trace_str (
361 u32 line_number,
362 const char *function_name,
363 char *module_name,
364 u32 component_id,
365 char *string)
366 {
367
368 acpi_gbl_nesting_level++;
369 acpi_ut_track_stack_ptr ();
370
371 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
372 line_number, function_name, module_name, component_id,
373 "%s %s\n", acpi_gbl_fn_entry_str, string);
374 }
375
376
377 /*******************************************************************************
378 *
379 * FUNCTION: acpi_ut_trace_u32
380 *
381 * PARAMETERS: line_number - Caller's line number
382 * function_name - Caller's procedure name
383 * module_name - Caller's module name
384 * component_id - Caller's component ID
385 * Integer - Integer to display
386 *
387 * RETURN: None
388 *
389 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
390 * set in debug_level
391 *
392 ******************************************************************************/
393
394 void
395 acpi_ut_trace_u32 (
396 u32 line_number,
397 const char *function_name,
398 char *module_name,
399 u32 component_id,
400 u32 integer)
401 {
402
403 acpi_gbl_nesting_level++;
404 acpi_ut_track_stack_ptr ();
405
406 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
407 line_number, function_name, module_name, component_id,
408 "%s %08X\n", acpi_gbl_fn_entry_str, integer);
409 }
410
411
412 /*******************************************************************************
413 *
414 * FUNCTION: acpi_ut_exit
415 *
416 * PARAMETERS: line_number - Caller's line number
417 * function_name - Caller's procedure name
418 * module_name - Caller's module name
419 * component_id - Caller's component ID
420 *
421 * RETURN: None
422 *
423 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
424 * set in debug_level
425 *
426 ******************************************************************************/
427
428 void
429 acpi_ut_exit (
430 u32 line_number,
431 const char *function_name,
432 char *module_name,
433 u32 component_id)
434 {
435
436 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
437 line_number, function_name, module_name, component_id,
438 "%s\n", acpi_gbl_fn_exit_str);
439
440 acpi_gbl_nesting_level--;
441 }
442 EXPORT_SYMBOL(acpi_ut_exit);
443
444
445 /*******************************************************************************
446 *
447 * FUNCTION: acpi_ut_status_exit
448 *
449 * PARAMETERS: line_number - Caller's line number
450 * function_name - Caller's procedure name
451 * module_name - Caller's module name
452 * component_id - Caller's component ID
453 * Status - Exit status code
454 *
455 * RETURN: None
456 *
457 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
458 * set in debug_level. Prints exit status also.
459 *
460 ******************************************************************************/
461
462 void
463 acpi_ut_status_exit (
464 u32 line_number,
465 const char *function_name,
466 char *module_name,
467 u32 component_id,
468 acpi_status status)
469 {
470
471 if (ACPI_SUCCESS (status)) {
472 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
473 line_number, function_name, module_name, component_id,
474 "%s %s\n", acpi_gbl_fn_exit_str,
475 acpi_format_exception (status));
476 }
477 else {
478 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
479 line_number, function_name, module_name, component_id,
480 "%s ****Exception****: %s\n", acpi_gbl_fn_exit_str,
481 acpi_format_exception (status));
482 }
483
484 acpi_gbl_nesting_level--;
485 }
486 EXPORT_SYMBOL(acpi_ut_status_exit);
487
488
489 /*******************************************************************************
490 *
491 * FUNCTION: acpi_ut_value_exit
492 *
493 * PARAMETERS: line_number - Caller's line number
494 * function_name - Caller's procedure name
495 * module_name - Caller's module name
496 * component_id - Caller's component ID
497 * Value - Value to be printed with exit msg
498 *
499 * RETURN: None
500 *
501 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
502 * set in debug_level. Prints exit value also.
503 *
504 ******************************************************************************/
505
506 void
507 acpi_ut_value_exit (
508 u32 line_number,
509 const char *function_name,
510 char *module_name,
511 u32 component_id,
512 acpi_integer value)
513 {
514
515 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
516 line_number, function_name, module_name, component_id,
517 "%s %8.8X%8.8X\n", acpi_gbl_fn_exit_str,
518 ACPI_FORMAT_UINT64 (value));
519
520 acpi_gbl_nesting_level--;
521 }
522 EXPORT_SYMBOL(acpi_ut_value_exit);
523
524
525 /*******************************************************************************
526 *
527 * FUNCTION: acpi_ut_ptr_exit
528 *
529 * PARAMETERS: line_number - Caller's line number
530 * function_name - Caller's procedure name
531 * module_name - Caller's module name
532 * component_id - Caller's component ID
533 * Ptr - Pointer to display
534 *
535 * RETURN: None
536 *
537 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
538 * set in debug_level. Prints exit value also.
539 *
540 ******************************************************************************/
541
542 void
543 acpi_ut_ptr_exit (
544 u32 line_number,
545 const char *function_name,
546 char *module_name,
547 u32 component_id,
548 u8 *ptr)
549 {
550
551 acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
552 line_number, function_name, module_name, component_id,
553 "%s %p\n", acpi_gbl_fn_exit_str, ptr);
554
555 acpi_gbl_nesting_level--;
556 }
557
558 #endif
559
560
561 /*******************************************************************************
562 *
563 * FUNCTION: acpi_ut_dump_buffer
564 *
565 * PARAMETERS: Buffer - Buffer to dump
566 * Count - Amount to dump, in bytes
567 * Display - BYTE, WORD, DWORD, or QWORD display
568 * component_iD - Caller's component ID
569 *
570 * RETURN: None
571 *
572 * DESCRIPTION: Generic dump buffer in both hex and ascii.
573 *
574 ******************************************************************************/
575
576 void
577 acpi_ut_dump_buffer (
578 u8 *buffer,
579 u32 count,
580 u32 display,
581 u32 component_id)
582 {
583 acpi_native_uint i = 0;
584 acpi_native_uint j;
585 u32 temp32;
586 u8 buf_char;
587
588
589 /* Only dump the buffer if tracing is enabled */
590
591 if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
592 (component_id & acpi_dbg_layer))) {
593 return;
594 }
595
596 if ((count < 4) || (count & 0x01)) {
597 display = DB_BYTE_DISPLAY;
598 }
599
600 /* Nasty little dump buffer routine! */
601
602 while (i < count) {
603 /* Print current offset */
604
605 acpi_os_printf ("%6.4X: ", (u32) i);
606
607 /* Print 16 hex chars */
608
609 for (j = 0; j < 16;) {
610 if (i + j >= count) {
611 /* Dump fill spaces */
612
613 acpi_os_printf ("%*s", ((display * 2) + 1), " ");
614 j += (acpi_native_uint) display;
615 continue;
616 }
617
618 switch (display) {
619 default: /* Default is BYTE display */
620
621 acpi_os_printf ("%02X ", buffer[i + j]);
622 break;
623
624
625 case DB_WORD_DISPLAY:
626
627 ACPI_MOVE_16_TO_32 (&temp32, &buffer[i + j]);
628 acpi_os_printf ("%04X ", temp32);
629 break;
630
631
632 case DB_DWORD_DISPLAY:
633
634 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]);
635 acpi_os_printf ("%08X ", temp32);
636 break;
637
638
639 case DB_QWORD_DISPLAY:
640
641 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]);
642 acpi_os_printf ("%08X", temp32);
643
644 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j + 4]);
645 acpi_os_printf ("%08X ", temp32);
646 break;
647 }
648
649 j += (acpi_native_uint) display;
650 }
651
652 /*
653 * Print the ASCII equivalent characters but watch out for the bad
654 * unprintable ones (printable chars are 0x20 through 0x7E)
655 */
656 acpi_os_printf (" ");
657 for (j = 0; j < 16; j++) {
658 if (i + j >= count) {
659 acpi_os_printf ("\n");
660 return;
661 }
662
663 buf_char = buffer[i + j];
664 if (ACPI_IS_PRINT (buf_char)) {
665 acpi_os_printf ("%c", buf_char);
666 }
667 else {
668 acpi_os_printf (".");
669 }
670 }
671
672 /* Done with that line. */
673
674 acpi_os_printf ("\n");
675 i += 16;
676 }
677
678 return;
679 }
680
This page took 0.077656 seconds and 5 git commands to generate.