File: /usr/src/linux/drivers/acpi/utilities/utdebug.c

1     /******************************************************************************
2      *
3      * Module Name: utdebug - Debug print routines
4      *              $Revision: 87 $
5      *
6      *****************************************************************************/
7     
8     /*
9      *  Copyright (C) 2000, 2001 R. Byron Moore
10      *
11      *  This program is free software; you can redistribute it and/or modify
12      *  it under the terms of the GNU General Public License as published by
13      *  the Free Software Foundation; either version 2 of the License, or
14      *  (at your option) any later version.
15      *
16      *  This program is distributed in the hope that it will be useful,
17      *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18      *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19      *  GNU General Public License for more details.
20      *
21      *  You should have received a copy of the GNU General Public License
22      *  along with this program; if not, write to the Free Software
23      *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24      */
25     
26     
27     #include "acpi.h"
28     
29     #define _COMPONENT          ACPI_UTILITIES
30     	 MODULE_NAME         ("utdebug")
31     
32     
33     u32             acpi_gbl_prev_thread_id = 0xFFFFFFFF;
34     char            *acpi_gbl_fn_entry_str = "----Entry";
35     char            *acpi_gbl_fn_exit_str = "----Exit-";
36     
37     
38     #ifdef ACPI_DEBUG
39     
40     
41     /*****************************************************************************
42      *
43      * FUNCTION:    Acpi_ut_init_stack_ptr_trace
44      *
45      * PARAMETERS:  None
46      *
47      * RETURN:      None
48      *
49      * DESCRIPTION: Save the current stack pointer
50      *
51      ****************************************************************************/
52     
53     void
54     acpi_ut_init_stack_ptr_trace (
55     	void)
56     {
57     	u32                 current_sp;
58     
59     
60     	acpi_gbl_entry_stack_pointer = (u32) &current_sp;
61     }
62     
63     
64     /*****************************************************************************
65      *
66      * FUNCTION:    Acpi_ut_track_stack_ptr
67      *
68      * PARAMETERS:  None
69      *
70      * RETURN:      None
71      *
72      * DESCRIPTION: Save the current stack pointer
73      *
74      ****************************************************************************/
75     
76     void
77     acpi_ut_track_stack_ptr (
78     	void)
79     {
80     	u32                 current_sp;
81     
82     	current_sp = (u32) &current_sp;
83     
84     	if (current_sp < acpi_gbl_lowest_stack_pointer) {
85     		acpi_gbl_lowest_stack_pointer = current_sp;
86     	}
87     
88     	if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) {
89     		acpi_gbl_deepest_nesting = acpi_gbl_nesting_level;
90     
91     		if (acpi_gbl_deepest_nesting == 34) {
92     			acpi_os_printf ("hit deepest nesting\n");
93     		}
94     	}
95     }
96     
97     
98     /*****************************************************************************
99      *
100      * FUNCTION:    Acpi_ut_debug_print
101      *
102      * PARAMETERS:  Debug_level         - Requested debug print level
103      *              Proc_name           - Caller's procedure name
104      *              Module_name         - Caller's module name (for error output)
105      *              Line_number         - Caller's line number (for error output)
106      *              Component_id        - Caller's component ID (for error output)
107      *
108      *              Format              - Printf format field
109      *              ...                 - Optional printf arguments
110      *
111      * RETURN:      None
112      *
113      * DESCRIPTION: Print error message with prefix consisting of the module name,
114      *              line number, and component ID.
115      *
116      ****************************************************************************/
117     
118     void
119     acpi_ut_debug_print (
120     	u32                     requested_debug_level,
121     	u32                     line_number,
122     	ACPI_DEBUG_PRINT_INFO   *dbg_info,
123     	char                    *format,
124     	...)
125     {
126     	u32                     thread_id;
127     	va_list                 args;
128     
129     
130     	/*
131     	 * Stay silent if the debug level or component ID is disabled
132     	 */
133     	if (!(requested_debug_level & acpi_dbg_level) ||
134     		!(dbg_info->component_id & acpi_dbg_layer)) {
135     		return;
136     	}
137     
138     
139     	/*
140     	 * Thread tracking and context switch notification
141     	 */
142     	thread_id = acpi_os_get_thread_id ();
143     
144     	if (thread_id != acpi_gbl_prev_thread_id) {
145     		if (ACPI_LV_THREADS & acpi_dbg_level) {
146     			acpi_os_printf ("\n**** Context Switch from TID %X to TID %X ****\n\n",
147     				acpi_gbl_prev_thread_id, thread_id);
148     		}
149     
150     		acpi_gbl_prev_thread_id = thread_id;
151     	}
152     
153     	/*
154     	 * Display the module name, current line number, thread ID (if requested),
155     	 * current procedure nesting level, and the current procedure name
156     	 */
157     	acpi_os_printf ("%8s-%04d ", dbg_info->module_name, line_number);
158     
159     	if (ACPI_LV_THREADS & acpi_dbg_level) {
160     		acpi_os_printf ("[%04X] ", thread_id, acpi_gbl_nesting_level, dbg_info->proc_name);
161     	}
162     
163     	acpi_os_printf ("[%02d] %-22.22s: ", acpi_gbl_nesting_level, dbg_info->proc_name);
164     
165     
166     	va_start (args, format);
167     	acpi_os_vprintf (format, args);
168     }
169     
170     
171     /*****************************************************************************
172      *
173      * FUNCTION:    Acpi_ut_debug_print_raw
174      *
175      * PARAMETERS:  Requested_debug_level - Requested debug print level
176      *              Line_number         - Caller's line number
177      *              Dbg_info            - Contains:
178      *                  Proc_name           - Caller's procedure name
179      *                  Module_name         - Caller's module name
180      *                  Component_id        - Caller's component ID
181      *              Format              - Printf format field
182      *              ...                 - Optional printf arguments
183      *
184      * RETURN:      None
185      *
186      * DESCRIPTION: Print message with no headers.  Has same interface as
187      *              Debug_print so that the same macros can be used.
188      *
189      ****************************************************************************/
190     
191     void
192     acpi_ut_debug_print_raw (
193     	u32                     requested_debug_level,
194     	u32                     line_number,
195     	ACPI_DEBUG_PRINT_INFO   *dbg_info,
196     	char                    *format,
197     	...)
198     {
199     	va_list                 args;
200     
201     
202     	if (!(requested_debug_level & acpi_dbg_level) ||
203     		!(dbg_info->component_id & acpi_dbg_layer)) {
204     		return;
205     	}
206     
207     	va_start (args, format);
208     
209     	acpi_os_vprintf (format, args);
210     }
211     
212     
213     /*****************************************************************************
214      *
215      * FUNCTION:    Acpi_ut_trace
216      *
217      * PARAMETERS:  Line_number         - Caller's line number
218      *              Dbg_info            - Contains:
219      *                  Proc_name           - Caller's procedure name
220      *                  Module_name         - Caller's module name
221      *                  Component_id        - Caller's component ID
222      *
223      * RETURN:      None
224      *
225      * DESCRIPTION: Function entry trace.  Prints only if TRACE_FUNCTIONS bit is
226      *              set in Debug_level
227      *
228      ****************************************************************************/
229     
230     void
231     acpi_ut_trace (
232     	u32                     line_number,
233     	ACPI_DEBUG_PRINT_INFO   *dbg_info)
234     {
235     
236     	acpi_gbl_nesting_level++;
237     	acpi_ut_track_stack_ptr ();
238     
239     	acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
240     			"%s\n", acpi_gbl_fn_entry_str);
241     }
242     
243     
244     /*****************************************************************************
245      *
246      * FUNCTION:    Acpi_ut_trace_ptr
247      *
248      * PARAMETERS:  Line_number         - Caller's line number
249      *              Dbg_info            - Contains:
250      *                  Proc_name           - Caller's procedure name
251      *                  Module_name         - Caller's module name
252      *                  Component_id        - Caller's component ID
253      *              Pointer             - Pointer to display
254      *
255      * RETURN:      None
256      *
257      * DESCRIPTION: Function entry trace.  Prints only if TRACE_FUNCTIONS bit is
258      *              set in Debug_level
259      *
260      ****************************************************************************/
261     
262     void
263     acpi_ut_trace_ptr (
264     	u32                     line_number,
265     	ACPI_DEBUG_PRINT_INFO   *dbg_info,
266     	void                    *pointer)
267     {
268     	acpi_gbl_nesting_level++;
269     	acpi_ut_track_stack_ptr ();
270     
271     	acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
272     			"%s %p\n", acpi_gbl_fn_entry_str, pointer);
273     }
274     
275     
276     /*****************************************************************************
277      *
278      * FUNCTION:    Acpi_ut_trace_str
279      *
280      * PARAMETERS:  Line_number         - Caller's line number
281      *              Dbg_info            - Contains:
282      *                  Proc_name           - Caller's procedure name
283      *                  Module_name         - Caller's module name
284      *                  Component_id        - Caller's component ID
285      *              String              - Additional string to display
286      *
287      * RETURN:      None
288      *
289      * DESCRIPTION: Function entry trace.  Prints only if TRACE_FUNCTIONS bit is
290      *              set in Debug_level
291      *
292      ****************************************************************************/
293     
294     void
295     acpi_ut_trace_str (
296     	u32                     line_number,
297     	ACPI_DEBUG_PRINT_INFO   *dbg_info,
298     	NATIVE_CHAR             *string)
299     {
300     
301     	acpi_gbl_nesting_level++;
302     	acpi_ut_track_stack_ptr ();
303     
304     	acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
305     			"%s %s\n", acpi_gbl_fn_entry_str, string);
306     }
307     
308     
309     /*****************************************************************************
310      *
311      * FUNCTION:    Acpi_ut_trace_u32
312      *
313      * PARAMETERS:  Line_number         - Caller's line number
314      *              Dbg_info            - Contains:
315      *                  Proc_name           - Caller's procedure name
316      *                  Module_name         - Caller's module name
317      *                  Component_id        - Caller's component ID
318      *              Integer             - Integer to display
319      *
320      * RETURN:      None
321      *
322      * DESCRIPTION: Function entry trace.  Prints only if TRACE_FUNCTIONS bit is
323      *              set in Debug_level
324      *
325      ****************************************************************************/
326     
327     void
328     acpi_ut_trace_u32 (
329     	u32                     line_number,
330     	ACPI_DEBUG_PRINT_INFO   *dbg_info,
331     	u32                     integer)
332     {
333     
334     	acpi_gbl_nesting_level++;
335     	acpi_ut_track_stack_ptr ();
336     
337     	acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
338     			"%s %08X\n", acpi_gbl_fn_entry_str, integer);
339     }
340     
341     
342     /*****************************************************************************
343      *
344      * FUNCTION:    Acpi_ut_exit
345      *
346      * PARAMETERS:  Line_number         - Caller's line number
347      *              Dbg_info            - Contains:
348      *                  Proc_name           - Caller's procedure name
349      *                  Module_name         - Caller's module name
350      *                  Component_id        - Caller's component ID
351      *
352      * RETURN:      None
353      *
354      * DESCRIPTION: Function exit trace.  Prints only if TRACE_FUNCTIONS bit is
355      *              set in Debug_level
356      *
357      ****************************************************************************/
358     
359     void
360     acpi_ut_exit (
361     	u32                     line_number,
362     	ACPI_DEBUG_PRINT_INFO   *dbg_info)
363     {
364     
365     	acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
366     			"%s\n", acpi_gbl_fn_exit_str);
367     
368     	acpi_gbl_nesting_level--;
369     }
370     
371     
372     /*****************************************************************************
373      *
374      * FUNCTION:    Acpi_ut_status_exit
375      *
376      * PARAMETERS:  Line_number         - Caller's line number
377      *              Dbg_info            - Contains:
378      *                  Proc_name           - Caller's procedure name
379      *                  Module_name         - Caller's module name
380      *                  Component_id        - Caller's component ID
381      *              Status              - Exit status code
382      *
383      * RETURN:      None
384      *
385      * DESCRIPTION: Function exit trace.  Prints only if TRACE_FUNCTIONS bit is
386      *              set in Debug_level. Prints exit status also.
387      *
388      ****************************************************************************/
389     
390     void
391     acpi_ut_status_exit (
392     	u32                     line_number,
393     	ACPI_DEBUG_PRINT_INFO   *dbg_info,
394     	acpi_status             status)
395     {
396     
397     	if (ACPI_SUCCESS (status)) {
398     		acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
399     				"%s %s\n", acpi_gbl_fn_exit_str,
400     				acpi_format_exception (status));
401     	}
402     	else {
403     		acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
404     				"%s ****Exception****: %s\n", acpi_gbl_fn_exit_str,
405     				acpi_format_exception (status));
406     	}
407     
408     	acpi_gbl_nesting_level--;
409     }
410     
411     
412     /*****************************************************************************
413      *
414      * FUNCTION:    Acpi_ut_value_exit
415      *
416      * PARAMETERS:  Line_number         - Caller's line number
417      *              Dbg_info            - Contains:
418      *                  Proc_name           - Caller's procedure name
419      *                  Module_name         - Caller's module name
420      *                  Component_id        - Caller's component ID
421      *              Value               - Value to be printed with exit msg
422      *
423      * RETURN:      None
424      *
425      * DESCRIPTION: Function exit trace.  Prints only if TRACE_FUNCTIONS bit is
426      *              set in Debug_level. Prints exit value also.
427      *
428      ****************************************************************************/
429     
430     void
431     acpi_ut_value_exit (
432     	u32                     line_number,
433     	ACPI_DEBUG_PRINT_INFO   *dbg_info,
434     	acpi_integer            value)
435     {
436     
437     	acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
438     			"%s %08X\n", acpi_gbl_fn_exit_str, value);
439     
440     	acpi_gbl_nesting_level--;
441     }
442     
443     
444     /*****************************************************************************
445      *
446      * FUNCTION:    Acpi_ut_ptr_exit
447      *
448      * PARAMETERS:  Line_number         - Caller's line number
449      *              Dbg_info            - Contains:
450      *                  Proc_name           - Caller's procedure name
451      *                  Module_name         - Caller's module name
452      *                  Component_id        - Caller's component ID
453      *              Value               - Value to be printed with exit msg
454      *
455      * RETURN:      None
456      *
457      * DESCRIPTION: Function exit trace.  Prints only if TRACE_FUNCTIONS bit is
458      *              set in Debug_level. Prints exit value also.
459      *
460      ****************************************************************************/
461     
462     void
463     acpi_ut_ptr_exit (
464     	u32                     line_number,
465     	ACPI_DEBUG_PRINT_INFO   *dbg_info,
466     	u8                      *ptr)
467     {
468     
469     	acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
470     			"%s %p\n", acpi_gbl_fn_exit_str, ptr);
471     
472     	acpi_gbl_nesting_level--;
473     }
474     
475     #endif
476     
477     
478     /*****************************************************************************
479      *
480      * FUNCTION:    Acpi_ut_dump_buffer
481      *
482      * PARAMETERS:  Buffer              - Buffer to dump
483      *              Count               - Amount to dump, in bytes
484      *              Display             - BYTE, WORD, DWORD, or QWORD display
485      *              Component_iD        - Caller's component ID
486      *
487      * RETURN:      None
488      *
489      * DESCRIPTION: Generic dump buffer in both hex and ascii.
490      *
491      ****************************************************************************/
492     
493     void
494     acpi_ut_dump_buffer (
495     	u8                      *buffer,
496     	u32                     count,
497     	u32                     display,
498     	u32                     component_id)
499     {
500     	u32                     i = 0;
501     	u32                     j;
502     	u32                     temp32;
503     	u8                      buf_char;
504     
505     
506     	/* Only dump the buffer if tracing is enabled */
507     
508     	if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
509     		(component_id & acpi_dbg_layer))) {
510     		return;
511     	}
512     
513     
514     	/*
515     	 * Nasty little dump buffer routine!
516     	 */
517     	while (i < count) {
518     		/* Print current offset */
519     
520     		acpi_os_printf ("%05X  ", i);
521     
522     
523     		/* Print 16 hex chars */
524     
525     		for (j = 0; j < 16;) {
526     			if (i + j >= count) {
527     				acpi_os_printf ("\n");
528     				return;
529     			}
530     
531     			/* Make sure that the s8 doesn't get sign-extended! */
532     
533     			switch (display) {
534     			/* Default is BYTE display */
535     
536     			default:
537     
538     				acpi_os_printf ("%02X ",
539     						*((u8 *) &buffer[i + j]));
540     				j += 1;
541     				break;
542     
543     
544     			case DB_WORD_DISPLAY:
545     
546     				MOVE_UNALIGNED16_TO_32 (&temp32,
547     						 &buffer[i + j]);
548     				acpi_os_printf ("%04X ", temp32);
549     				j += 2;
550     				break;
551     
552     
553     			case DB_DWORD_DISPLAY:
554     
555     				MOVE_UNALIGNED32_TO_32 (&temp32,
556     						 &buffer[i + j]);
557     				acpi_os_printf ("%08X ", temp32);
558     				j += 4;
559     				break;
560     
561     
562     			case DB_QWORD_DISPLAY:
563     
564     				MOVE_UNALIGNED32_TO_32 (&temp32,
565     						 &buffer[i + j]);
566     				acpi_os_printf ("%08X", temp32);
567     
568     				MOVE_UNALIGNED32_TO_32 (&temp32,
569     						 &buffer[i + j + 4]);
570     				acpi_os_printf ("%08X ", temp32);
571     				j += 8;
572     				break;
573     			}
574     		}
575     
576     
577     		/*
578     		 * Print the ASCII equivalent characters
579     		 * But watch out for the bad unprintable ones...
580     		 */
581     
582     		for (j = 0; j < 16; j++) {
583     			if (i + j >= count) {
584     				acpi_os_printf ("\n");
585     				return;
586     			}
587     
588     			buf_char = buffer[i + j];
589     			if ((buf_char > 0x1F && buf_char < 0x2E) ||
590     				(buf_char > 0x2F && buf_char < 0x61) ||
591     				(buf_char > 0x60 && buf_char < 0x7F)) {
592     				acpi_os_printf ("%c", buf_char);
593     			}
594     			else {
595     				acpi_os_printf (".");
596     			}
597     		}
598     
599     		/* Done with that line. */
600     
601     		acpi_os_printf ("\n");
602     		i += 16;
603     	}
604     
605     	return;
606     }
607     
608