1 /******************************************************************************
3 * Module Name: utdebug - Debug print routines
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12 * All rights reserved.
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
72 * 3.4. Intel retains all right, title, and interest in and to the Original
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
116 #define __UTDEBUG_C__
119 #include "accommon.h"
121 #define _COMPONENT ACPI_UTILITIES
122 ACPI_MODULE_NAME ("utdebug")
125 #ifdef ACPI_DEBUG_OUTPUT
127 static ACPI_THREAD_ID AcpiGbl_PrevThreadId
= (ACPI_THREAD_ID
) 0xFFFFFFFF;
128 static char *AcpiGbl_FnEntryStr
= "----Entry";
129 static char *AcpiGbl_FnExitStr
= "----Exit-";
131 /* Local prototypes */
134 AcpiUtTrimFunctionName (
135 const char *FunctionName
);
138 /*******************************************************************************
140 * FUNCTION: AcpiUtInitStackPtrTrace
146 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
148 ******************************************************************************/
151 AcpiUtInitStackPtrTrace (
157 AcpiGbl_EntryStackPointer
= &CurrentSp
;
161 /*******************************************************************************
163 * FUNCTION: AcpiUtTrackStackPtr
169 * DESCRIPTION: Save the current CPU stack pointer
171 ******************************************************************************/
174 AcpiUtTrackStackPtr (
180 if (&CurrentSp
< AcpiGbl_LowestStackPointer
)
182 AcpiGbl_LowestStackPointer
= &CurrentSp
;
185 if (AcpiGbl_NestingLevel
> AcpiGbl_DeepestNesting
)
187 AcpiGbl_DeepestNesting
= AcpiGbl_NestingLevel
;
192 /*******************************************************************************
194 * FUNCTION: AcpiUtTrimFunctionName
196 * PARAMETERS: FunctionName - Ascii string containing a procedure name
198 * RETURN: Updated pointer to the function name
200 * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
201 * This allows compiler macros such as __FUNCTION__ to be used
202 * with no change to the debug output.
204 ******************************************************************************/
207 AcpiUtTrimFunctionName (
208 const char *FunctionName
)
211 /* All Function names are longer than 4 chars, check is safe */
213 if (*(ACPI_CAST_PTR (UINT32
, FunctionName
)) == ACPI_PREFIX_MIXED
)
215 /* This is the case where the original source has not been modified */
217 return (FunctionName
+ 4);
220 if (*(ACPI_CAST_PTR (UINT32
, FunctionName
)) == ACPI_PREFIX_LOWER
)
222 /* This is the case where the source has been 'linuxized' */
224 return (FunctionName
+ 5);
227 return (FunctionName
);
231 /*******************************************************************************
233 * FUNCTION: AcpiDebugPrint
235 * PARAMETERS: RequestedDebugLevel - Requested debug print level
236 * LineNumber - Caller's line number (for error output)
237 * FunctionName - Caller's procedure name
238 * ModuleName - Caller's module name
239 * ComponentId - Caller's component ID
240 * Format - Printf format field
241 * ... - Optional printf arguments
245 * DESCRIPTION: Print error message with prefix consisting of the module name,
246 * line number, and component ID.
248 ******************************************************************************/
250 void ACPI_INTERNAL_VAR_XFACE
252 UINT32 RequestedDebugLevel
,
254 const char *FunctionName
,
255 const char *ModuleName
,
260 ACPI_THREAD_ID ThreadId
;
265 * Stay silent if the debug level or component ID is disabled
267 if (!(RequestedDebugLevel
& AcpiDbgLevel
) ||
268 !(ComponentId
& AcpiDbgLayer
))
274 * Thread tracking and context switch notification
276 ThreadId
= AcpiOsGetThreadId ();
277 if (ThreadId
!= AcpiGbl_PrevThreadId
)
279 if (ACPI_LV_THREADS
& AcpiDbgLevel
)
282 "\n**** Context Switch from TID %p to TID %p ****\n\n",
283 ACPI_CAST_PTR (void, AcpiGbl_PrevThreadId
),
284 ACPI_CAST_PTR (void, ThreadId
));
287 AcpiGbl_PrevThreadId
= ThreadId
;
291 * Display the module name, current line number, thread ID (if requested),
292 * current procedure nesting level, and the current procedure name
294 AcpiOsPrintf ("%8s-%04ld ", ModuleName
, LineNumber
);
296 if (ACPI_LV_THREADS
& AcpiDbgLevel
)
298 AcpiOsPrintf ("[%p] ", ACPI_CAST_PTR (void, ThreadId
));
301 AcpiOsPrintf ("[%02ld] %-22.22s: ",
302 AcpiGbl_NestingLevel
, AcpiUtTrimFunctionName (FunctionName
));
304 va_start (args
, Format
);
305 AcpiOsVprintf (Format
, args
);
309 ACPI_EXPORT_SYMBOL (AcpiDebugPrint
)
312 /*******************************************************************************
314 * FUNCTION: AcpiDebugPrintRaw
316 * PARAMETERS: RequestedDebugLevel - Requested debug print level
317 * LineNumber - Caller's line number
318 * FunctionName - Caller's procedure name
319 * ModuleName - Caller's module name
320 * ComponentId - Caller's component ID
321 * Format - Printf format field
322 * ... - Optional printf arguments
326 * DESCRIPTION: Print message with no headers. Has same interface as
327 * DebugPrint so that the same macros can be used.
329 ******************************************************************************/
331 void ACPI_INTERNAL_VAR_XFACE
333 UINT32 RequestedDebugLevel
,
335 const char *FunctionName
,
336 const char *ModuleName
,
344 if (!(RequestedDebugLevel
& AcpiDbgLevel
) ||
345 !(ComponentId
& AcpiDbgLayer
))
350 va_start (args
, Format
);
351 AcpiOsVprintf (Format
, args
);
355 ACPI_EXPORT_SYMBOL (AcpiDebugPrintRaw
)
358 /*******************************************************************************
360 * FUNCTION: AcpiUtTrace
362 * PARAMETERS: LineNumber - Caller's line number
363 * FunctionName - Caller's procedure name
364 * ModuleName - Caller's module name
365 * ComponentId - Caller's component ID
369 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
372 ******************************************************************************/
377 const char *FunctionName
,
378 const char *ModuleName
,
382 AcpiGbl_NestingLevel
++;
383 AcpiUtTrackStackPtr ();
385 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
386 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
387 "%s\n", AcpiGbl_FnEntryStr
);
390 ACPI_EXPORT_SYMBOL (AcpiUtTrace
)
393 /*******************************************************************************
395 * FUNCTION: AcpiUtTracePtr
397 * PARAMETERS: LineNumber - Caller's line number
398 * FunctionName - Caller's procedure name
399 * ModuleName - Caller's module name
400 * ComponentId - Caller's component ID
401 * Pointer - Pointer to display
405 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
408 ******************************************************************************/
413 const char *FunctionName
,
414 const char *ModuleName
,
418 AcpiGbl_NestingLevel
++;
419 AcpiUtTrackStackPtr ();
421 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
422 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
423 "%s %p\n", AcpiGbl_FnEntryStr
, Pointer
);
427 /*******************************************************************************
429 * FUNCTION: AcpiUtTraceStr
431 * PARAMETERS: LineNumber - Caller's line number
432 * FunctionName - Caller's procedure name
433 * ModuleName - Caller's module name
434 * ComponentId - Caller's component ID
435 * String - Additional string to display
439 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
442 ******************************************************************************/
447 const char *FunctionName
,
448 const char *ModuleName
,
453 AcpiGbl_NestingLevel
++;
454 AcpiUtTrackStackPtr ();
456 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
457 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
458 "%s %s\n", AcpiGbl_FnEntryStr
, String
);
462 /*******************************************************************************
464 * FUNCTION: AcpiUtTraceU32
466 * PARAMETERS: LineNumber - Caller's line number
467 * FunctionName - Caller's procedure name
468 * ModuleName - Caller's module name
469 * ComponentId - Caller's component ID
470 * Integer - Integer to display
474 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
477 ******************************************************************************/
482 const char *FunctionName
,
483 const char *ModuleName
,
488 AcpiGbl_NestingLevel
++;
489 AcpiUtTrackStackPtr ();
491 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
492 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
493 "%s %08X\n", AcpiGbl_FnEntryStr
, Integer
);
497 /*******************************************************************************
499 * FUNCTION: AcpiUtExit
501 * PARAMETERS: LineNumber - Caller's line number
502 * FunctionName - Caller's procedure name
503 * ModuleName - Caller's module name
504 * ComponentId - Caller's component ID
508 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
511 ******************************************************************************/
516 const char *FunctionName
,
517 const char *ModuleName
,
521 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
522 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
523 "%s\n", AcpiGbl_FnExitStr
);
525 AcpiGbl_NestingLevel
--;
528 ACPI_EXPORT_SYMBOL (AcpiUtExit
)
531 /*******************************************************************************
533 * FUNCTION: AcpiUtStatusExit
535 * PARAMETERS: LineNumber - Caller's line number
536 * FunctionName - Caller's procedure name
537 * ModuleName - Caller's module name
538 * ComponentId - Caller's component ID
539 * Status - Exit status code
543 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
544 * set in DebugLevel. Prints exit status also.
546 ******************************************************************************/
551 const char *FunctionName
,
552 const char *ModuleName
,
557 if (ACPI_SUCCESS (Status
))
559 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
560 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
561 "%s %s\n", AcpiGbl_FnExitStr
,
562 AcpiFormatException (Status
));
566 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
567 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
568 "%s ****Exception****: %s\n", AcpiGbl_FnExitStr
,
569 AcpiFormatException (Status
));
572 AcpiGbl_NestingLevel
--;
575 ACPI_EXPORT_SYMBOL (AcpiUtStatusExit
)
578 /*******************************************************************************
580 * FUNCTION: AcpiUtValueExit
582 * PARAMETERS: LineNumber - Caller's line number
583 * FunctionName - Caller's procedure name
584 * ModuleName - Caller's module name
585 * ComponentId - Caller's component ID
586 * Value - Value to be printed with exit msg
590 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
591 * set in DebugLevel. Prints exit value also.
593 ******************************************************************************/
598 const char *FunctionName
,
599 const char *ModuleName
,
604 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
605 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
606 "%s %8.8X%8.8X\n", AcpiGbl_FnExitStr
,
607 ACPI_FORMAT_UINT64 (Value
));
609 AcpiGbl_NestingLevel
--;
612 ACPI_EXPORT_SYMBOL (AcpiUtValueExit
)
615 /*******************************************************************************
617 * FUNCTION: AcpiUtPtrExit
619 * PARAMETERS: LineNumber - Caller's line number
620 * FunctionName - Caller's procedure name
621 * ModuleName - Caller's module name
622 * ComponentId - Caller's component ID
623 * Ptr - Pointer to display
627 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
628 * set in DebugLevel. Prints exit value also.
630 ******************************************************************************/
635 const char *FunctionName
,
636 const char *ModuleName
,
641 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
642 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
643 "%s %p\n", AcpiGbl_FnExitStr
, Ptr
);
645 AcpiGbl_NestingLevel
--;
651 /*******************************************************************************
653 * FUNCTION: AcpiUtDumpBuffer
655 * PARAMETERS: Buffer - Buffer to dump
656 * Count - Amount to dump, in bytes
657 * Display - BYTE, WORD, DWORD, or QWORD display
658 * ComponentID - Caller's component ID
662 * DESCRIPTION: Generic dump buffer in both hex and ascii.
664 ******************************************************************************/
680 AcpiOsPrintf ("Null Buffer Pointer in DumpBuffer!\n");
684 if ((Count
< 4) || (Count
& 0x01))
686 Display
= DB_BYTE_DISPLAY
;
689 /* Nasty little dump buffer routine! */
693 /* Print current offset */
695 AcpiOsPrintf ("%6.4X: ", i
);
697 /* Print 16 hex chars */
703 /* Dump fill spaces */
705 AcpiOsPrintf ("%*s", ((Display
* 2) + 1), " ");
712 case DB_BYTE_DISPLAY
:
713 default: /* Default is BYTE display */
715 AcpiOsPrintf ("%02X ", Buffer
[(ACPI_SIZE
) i
+ j
]);
719 case DB_WORD_DISPLAY
:
721 ACPI_MOVE_16_TO_32 (&Temp32
, &Buffer
[(ACPI_SIZE
) i
+ j
]);
722 AcpiOsPrintf ("%04X ", Temp32
);
726 case DB_DWORD_DISPLAY
:
728 ACPI_MOVE_32_TO_32 (&Temp32
, &Buffer
[(ACPI_SIZE
) i
+ j
]);
729 AcpiOsPrintf ("%08X ", Temp32
);
733 case DB_QWORD_DISPLAY
:
735 ACPI_MOVE_32_TO_32 (&Temp32
, &Buffer
[(ACPI_SIZE
) i
+ j
]);
736 AcpiOsPrintf ("%08X", Temp32
);
738 ACPI_MOVE_32_TO_32 (&Temp32
, &Buffer
[(ACPI_SIZE
) i
+ j
+ 4]);
739 AcpiOsPrintf ("%08X ", Temp32
);
747 * Print the ASCII equivalent characters but watch out for the bad
748 * unprintable ones (printable chars are 0x20 through 0x7E)
751 for (j
= 0; j
< 16; j
++)
759 BufChar
= Buffer
[(ACPI_SIZE
) i
+ j
];
760 if (ACPI_IS_PRINT (BufChar
))
762 AcpiOsPrintf ("%c", BufChar
);
770 /* Done with that line. */
780 /*******************************************************************************
782 * FUNCTION: AcpiUtDumpBuffer
784 * PARAMETERS: Buffer - Buffer to dump
785 * Count - Amount to dump, in bytes
786 * Display - BYTE, WORD, DWORD, or QWORD display
787 * ComponentID - Caller's component ID
791 * DESCRIPTION: Generic dump buffer in both hex and ascii.
793 ******************************************************************************/
803 /* Only dump the buffer if tracing is enabled */
805 if (!((ACPI_LV_TABLES
& AcpiDbgLevel
) &&
806 (ComponentId
& AcpiDbgLayer
)))
811 AcpiUtDumpBuffer2 (Buffer
, Count
, Display
);