aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/acpi/utilities/utdebug.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-16 18:20:36 -0400
commit1da177e4c3f41524e886b7f1b8a0c1fc7321cac2 (patch)
tree0bba044c4ce775e45a88a51686b5d9f90697ea9d /drivers/acpi/utilities/utdebug.c
Linux-2.6.12-rc2v2.6.12-rc2
Initial git repository build. I'm not bothering with the full history, even though we have it. We can create a separate "historical" git archive of that later if we want to, and in the meantime it's about 3.2GB when imported into git - space that would just make the early git days unnecessarily complicated, when we don't have a lot of good infrastructure for it. Let it rip!
Diffstat (limited to 'drivers/acpi/utilities/utdebug.c')
-rw-r--r--drivers/acpi/utilities/utdebug.c624
1 files changed, 624 insertions, 0 deletions
diff --git a/drivers/acpi/utilities/utdebug.c b/drivers/acpi/utilities/utdebug.c
new file mode 100644
index 000000000000..985c5d045b78
--- /dev/null
+++ b/drivers/acpi/utilities/utdebug.c
@@ -0,0 +1,624 @@
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
54static u32 acpi_gbl_prev_thread_id = 0xFFFFFFFF;
55static char *acpi_gbl_fn_entry_str = "----Entry";
56static char *acpi_gbl_fn_exit_str = "----Exit-";
57
58
59/*****************************************************************************
60 *
61 * FUNCTION: acpi_ut_init_stack_ptr_trace
62 *
63 * PARAMETERS: None
64 *
65 * RETURN: None
66 *
67 * DESCRIPTION: Save the current stack pointer
68 *
69 ****************************************************************************/
70
71void
72acpi_ut_init_stack_ptr_trace (
73 void)
74{
75 u32 current_sp;
76
77
78 acpi_gbl_entry_stack_pointer = ACPI_PTR_DIFF (&current_sp, NULL);
79}
80
81
82/*****************************************************************************
83 *
84 * FUNCTION: acpi_ut_track_stack_ptr
85 *
86 * PARAMETERS: None
87 *
88 * RETURN: None
89 *
90 * DESCRIPTION: Save the current stack pointer
91 *
92 ****************************************************************************/
93
94void
95acpi_ut_track_stack_ptr (
96 void)
97{
98 acpi_size current_sp;
99
100
101 current_sp = ACPI_PTR_DIFF (&current_sp, NULL);
102
103 if (current_sp < acpi_gbl_lowest_stack_pointer) {
104 acpi_gbl_lowest_stack_pointer = current_sp;
105 }
106
107 if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) {
108 acpi_gbl_deepest_nesting = acpi_gbl_nesting_level;
109 }
110}
111
112
113/*****************************************************************************
114 *
115 * FUNCTION: acpi_ut_debug_print
116 *
117 * PARAMETERS: debug_level - Requested debug print level
118 * proc_name - Caller's procedure name
119 * module_name - Caller's module name (for error output)
120 * line_number - Caller's line number (for error output)
121 * component_id - Caller's component ID (for error output)
122 *
123 * Format - Printf format field
124 * ... - Optional printf arguments
125 *
126 * RETURN: None
127 *
128 * DESCRIPTION: Print error message with prefix consisting of the module name,
129 * line number, and component ID.
130 *
131 ****************************************************************************/
132
133void ACPI_INTERNAL_VAR_XFACE
134acpi_ut_debug_print (
135 u32 requested_debug_level,
136 u32 line_number,
137 struct acpi_debug_print_info *dbg_info,
138 char *format,
139 ...)
140{
141 u32 thread_id;
142 va_list args;
143
144
145 /*
146 * Stay silent if the debug level or component ID is disabled
147 */
148 if (!(requested_debug_level & acpi_dbg_level) ||
149 !(dbg_info->component_id & acpi_dbg_layer)) {
150 return;
151 }
152
153 /*
154 * Thread tracking and context switch notification
155 */
156 thread_id = acpi_os_get_thread_id ();
157
158 if (thread_id != acpi_gbl_prev_thread_id) {
159 if (ACPI_LV_THREADS & acpi_dbg_level) {
160 acpi_os_printf ("\n**** Context Switch from TID %X to TID %X ****\n\n",
161 acpi_gbl_prev_thread_id, thread_id);
162 }
163
164 acpi_gbl_prev_thread_id = thread_id;
165 }
166
167 /*
168 * Display the module name, current line number, thread ID (if requested),
169 * current procedure nesting level, and the current procedure name
170 */
171 acpi_os_printf ("%8s-%04ld ", dbg_info->module_name, line_number);
172
173 if (ACPI_LV_THREADS & acpi_dbg_level) {
174 acpi_os_printf ("[%04lX] ", thread_id);
175 }
176
177 acpi_os_printf ("[%02ld] %-22.22s: ", acpi_gbl_nesting_level, dbg_info->proc_name);
178
179 va_start (args, format);
180 acpi_os_vprintf (format, args);
181}
182EXPORT_SYMBOL(acpi_ut_debug_print);
183
184
185/*****************************************************************************
186 *
187 * FUNCTION: acpi_ut_debug_print_raw
188 *
189 * PARAMETERS: requested_debug_level - Requested debug print level
190 * line_number - Caller's line number
191 * dbg_info - Contains:
192 * proc_name - Caller's procedure name
193 * module_name - Caller's module name
194 * component_id - Caller's component ID
195 * Format - Printf format field
196 * ... - Optional printf arguments
197 *
198 * RETURN: None
199 *
200 * DESCRIPTION: Print message with no headers. Has same interface as
201 * debug_print so that the same macros can be used.
202 *
203 ****************************************************************************/
204
205void ACPI_INTERNAL_VAR_XFACE
206acpi_ut_debug_print_raw (
207 u32 requested_debug_level,
208 u32 line_number,
209 struct acpi_debug_print_info *dbg_info,
210 char *format,
211 ...)
212{
213 va_list args;
214
215
216 if (!(requested_debug_level & acpi_dbg_level) ||
217 !(dbg_info->component_id & acpi_dbg_layer)) {
218 return;
219 }
220
221 va_start (args, format);
222 acpi_os_vprintf (format, args);
223}
224EXPORT_SYMBOL(acpi_ut_debug_print_raw);
225
226
227/*****************************************************************************
228 *
229 * FUNCTION: acpi_ut_trace
230 *
231 * PARAMETERS: line_number - Caller's line number
232 * dbg_info - Contains:
233 * proc_name - Caller's procedure name
234 * module_name - Caller's module name
235 * component_id - Caller's component ID
236 *
237 * RETURN: None
238 *
239 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
240 * set in debug_level
241 *
242 ****************************************************************************/
243
244void
245acpi_ut_trace (
246 u32 line_number,
247 struct acpi_debug_print_info *dbg_info)
248{
249
250 acpi_gbl_nesting_level++;
251 acpi_ut_track_stack_ptr ();
252
253 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
254 "%s\n", acpi_gbl_fn_entry_str);
255}
256EXPORT_SYMBOL(acpi_ut_trace);
257
258
259/*****************************************************************************
260 *
261 * FUNCTION: acpi_ut_trace_ptr
262 *
263 * PARAMETERS: line_number - Caller's line number
264 * dbg_info - Contains:
265 * proc_name - Caller's procedure name
266 * module_name - Caller's module name
267 * component_id - Caller's component ID
268 * Pointer - Pointer to display
269 *
270 * RETURN: None
271 *
272 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
273 * set in debug_level
274 *
275 ****************************************************************************/
276
277void
278acpi_ut_trace_ptr (
279 u32 line_number,
280 struct acpi_debug_print_info *dbg_info,
281 void *pointer)
282{
283 acpi_gbl_nesting_level++;
284 acpi_ut_track_stack_ptr ();
285
286 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
287 "%s %p\n", acpi_gbl_fn_entry_str, pointer);
288}
289
290
291/*****************************************************************************
292 *
293 * FUNCTION: acpi_ut_trace_str
294 *
295 * PARAMETERS: line_number - Caller's line number
296 * dbg_info - Contains:
297 * proc_name - Caller's procedure name
298 * module_name - Caller's module name
299 * component_id - Caller's component ID
300 * String - Additional string to display
301 *
302 * RETURN: None
303 *
304 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
305 * set in debug_level
306 *
307 ****************************************************************************/
308
309void
310acpi_ut_trace_str (
311 u32 line_number,
312 struct acpi_debug_print_info *dbg_info,
313 char *string)
314{
315
316 acpi_gbl_nesting_level++;
317 acpi_ut_track_stack_ptr ();
318
319 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
320 "%s %s\n", acpi_gbl_fn_entry_str, string);
321}
322
323
324/*****************************************************************************
325 *
326 * FUNCTION: acpi_ut_trace_u32
327 *
328 * PARAMETERS: line_number - Caller's line number
329 * dbg_info - Contains:
330 * proc_name - Caller's procedure name
331 * module_name - Caller's module name
332 * component_id - Caller's component ID
333 * Integer - Integer to display
334 *
335 * RETURN: None
336 *
337 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
338 * set in debug_level
339 *
340 ****************************************************************************/
341
342void
343acpi_ut_trace_u32 (
344 u32 line_number,
345 struct acpi_debug_print_info *dbg_info,
346 u32 integer)
347{
348
349 acpi_gbl_nesting_level++;
350 acpi_ut_track_stack_ptr ();
351
352 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
353 "%s %08X\n", acpi_gbl_fn_entry_str, integer);
354}
355
356
357/*****************************************************************************
358 *
359 * FUNCTION: acpi_ut_exit
360 *
361 * PARAMETERS: line_number - Caller's line number
362 * dbg_info - Contains:
363 * proc_name - Caller's procedure name
364 * module_name - Caller's module name
365 * component_id - Caller's component ID
366 *
367 * RETURN: None
368 *
369 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
370 * set in debug_level
371 *
372 ****************************************************************************/
373
374void
375acpi_ut_exit (
376 u32 line_number,
377 struct acpi_debug_print_info *dbg_info)
378{
379
380 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
381 "%s\n", acpi_gbl_fn_exit_str);
382
383 acpi_gbl_nesting_level--;
384}
385EXPORT_SYMBOL(acpi_ut_exit);
386
387
388/*****************************************************************************
389 *
390 * FUNCTION: acpi_ut_status_exit
391 *
392 * PARAMETERS: line_number - Caller's line number
393 * dbg_info - Contains:
394 * proc_name - Caller's procedure name
395 * module_name - Caller's module name
396 * component_id - Caller's component ID
397 * Status - Exit status code
398 *
399 * RETURN: None
400 *
401 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
402 * set in debug_level. Prints exit status also.
403 *
404 ****************************************************************************/
405
406void
407acpi_ut_status_exit (
408 u32 line_number,
409 struct acpi_debug_print_info *dbg_info,
410 acpi_status status)
411{
412
413 if (ACPI_SUCCESS (status)) {
414 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
415 "%s %s\n", acpi_gbl_fn_exit_str,
416 acpi_format_exception (status));
417 }
418 else {
419 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
420 "%s ****Exception****: %s\n", acpi_gbl_fn_exit_str,
421 acpi_format_exception (status));
422 }
423
424 acpi_gbl_nesting_level--;
425}
426EXPORT_SYMBOL(acpi_ut_status_exit);
427
428
429/*****************************************************************************
430 *
431 * FUNCTION: acpi_ut_value_exit
432 *
433 * PARAMETERS: line_number - Caller's line number
434 * dbg_info - Contains:
435 * proc_name - Caller's procedure name
436 * module_name - Caller's module name
437 * component_id - Caller's component ID
438 * Value - Value to be printed with exit msg
439 *
440 * RETURN: None
441 *
442 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
443 * set in debug_level. Prints exit value also.
444 *
445 ****************************************************************************/
446
447void
448acpi_ut_value_exit (
449 u32 line_number,
450 struct acpi_debug_print_info *dbg_info,
451 acpi_integer value)
452{
453
454 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
455 "%s %8.8X%8.8X\n", acpi_gbl_fn_exit_str,
456 ACPI_FORMAT_UINT64 (value));
457
458 acpi_gbl_nesting_level--;
459}
460EXPORT_SYMBOL(acpi_ut_value_exit);
461
462
463/*****************************************************************************
464 *
465 * FUNCTION: acpi_ut_ptr_exit
466 *
467 * PARAMETERS: line_number - Caller's line number
468 * dbg_info - Contains:
469 * proc_name - Caller's procedure name
470 * module_name - Caller's module name
471 * component_id - Caller's component ID
472 * Value - Value to be printed with exit msg
473 *
474 * RETURN: None
475 *
476 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
477 * set in debug_level. Prints exit value also.
478 *
479 ****************************************************************************/
480
481void
482acpi_ut_ptr_exit (
483 u32 line_number,
484 struct acpi_debug_print_info *dbg_info,
485 u8 *ptr)
486{
487
488 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
489 "%s %p\n", acpi_gbl_fn_exit_str, ptr);
490
491 acpi_gbl_nesting_level--;
492}
493
494#endif
495
496
497/*****************************************************************************
498 *
499 * FUNCTION: acpi_ut_dump_buffer
500 *
501 * PARAMETERS: Buffer - Buffer to dump
502 * Count - Amount to dump, in bytes
503 * Display - BYTE, WORD, DWORD, or QWORD display
504 * component_iD - Caller's component ID
505 *
506 * RETURN: None
507 *
508 * DESCRIPTION: Generic dump buffer in both hex and ascii.
509 *
510 ****************************************************************************/
511
512void
513acpi_ut_dump_buffer (
514 u8 *buffer,
515 u32 count,
516 u32 display,
517 u32 component_id)
518{
519 acpi_native_uint i = 0;
520 acpi_native_uint j;
521 u32 temp32;
522 u8 buf_char;
523
524
525 /* Only dump the buffer if tracing is enabled */
526
527 if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
528 (component_id & acpi_dbg_layer))) {
529 return;
530 }
531
532 if ((count < 4) || (count & 0x01)) {
533 display = DB_BYTE_DISPLAY;
534 }
535
536 acpi_os_printf ("\nOffset Value\n");
537
538 /*
539 * Nasty little dump buffer routine!
540 */
541 while (i < count) {
542 /* Print current offset */
543
544 acpi_os_printf ("%05X ", (u32) i);
545
546 /* Print 16 hex chars */
547
548 for (j = 0; j < 16;) {
549 if (i + j >= count) {
550 acpi_os_printf ("\n");
551 return;
552 }
553
554 /* Make sure that the s8 doesn't get sign-extended! */
555
556 switch (display) {
557 /* Default is BYTE display */
558
559 default:
560
561 acpi_os_printf ("%02X ",
562 *((u8 *) &buffer[i + j]));
563 j += 1;
564 break;
565
566
567 case DB_WORD_DISPLAY:
568
569 ACPI_MOVE_16_TO_32 (&temp32, &buffer[i + j]);
570 acpi_os_printf ("%04X ", temp32);
571 j += 2;
572 break;
573
574
575 case DB_DWORD_DISPLAY:
576
577 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]);
578 acpi_os_printf ("%08X ", temp32);
579 j += 4;
580 break;
581
582
583 case DB_QWORD_DISPLAY:
584
585 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]);
586 acpi_os_printf ("%08X", temp32);
587
588 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j + 4]);
589 acpi_os_printf ("%08X ", temp32);
590 j += 8;
591 break;
592 }
593 }
594
595 /*
596 * Print the ASCII equivalent characters
597 * But watch out for the bad unprintable ones...
598 */
599 for (j = 0; j < 16; j++) {
600 if (i + j >= count) {
601 acpi_os_printf ("\n");
602 return;
603 }
604
605 buf_char = buffer[i + j];
606 if ((buf_char > 0x1F && buf_char < 0x2E) ||
607 (buf_char > 0x2F && buf_char < 0x61) ||
608 (buf_char > 0x60 && buf_char < 0x7F)) {
609 acpi_os_printf ("%c", buf_char);
610 }
611 else {
612 acpi_os_printf (".");
613 }
614 }
615
616 /* Done with that line. */
617
618 acpi_os_printf ("\n");
619 i += 16;
620 }
621
622 return;
623}
624