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__
118 #include <contrib/dev/acpica/include/acpi.h>
119 #include <contrib/dev/acpica/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 %u to TID %u ****\n\n",
283 (UINT32) AcpiGbl_PrevThreadId, (UINT32) ThreadId);
286 AcpiGbl_PrevThreadId = ThreadId;
290 * Display the module name, current line number, thread ID (if requested),
291 * current procedure nesting level, and the current procedure name
293 AcpiOsPrintf ("%8s-%04ld ", ModuleName, LineNumber);
295 if (ACPI_LV_THREADS & AcpiDbgLevel)
297 AcpiOsPrintf ("[%u] ", (UINT32) ThreadId);
300 AcpiOsPrintf ("[%02ld] %-22.22s: ",
301 AcpiGbl_NestingLevel, AcpiUtTrimFunctionName (FunctionName));
303 va_start (args, Format);
304 AcpiOsVprintf (Format, args);
308 ACPI_EXPORT_SYMBOL (AcpiDebugPrint)
311 /*******************************************************************************
313 * FUNCTION: AcpiDebugPrintRaw
315 * PARAMETERS: RequestedDebugLevel - Requested debug print level
316 * LineNumber - Caller's line number
317 * FunctionName - Caller's procedure name
318 * ModuleName - Caller's module name
319 * ComponentId - Caller's component ID
320 * Format - Printf format field
321 * ... - Optional printf arguments
325 * DESCRIPTION: Print message with no headers. Has same interface as
326 * DebugPrint so that the same macros can be used.
328 ******************************************************************************/
330 void ACPI_INTERNAL_VAR_XFACE
332 UINT32 RequestedDebugLevel,
334 const char *FunctionName,
335 const char *ModuleName,
343 if (!(RequestedDebugLevel & AcpiDbgLevel) ||
344 !(ComponentId & AcpiDbgLayer))
349 va_start (args, Format);
350 AcpiOsVprintf (Format, args);
354 ACPI_EXPORT_SYMBOL (AcpiDebugPrintRaw)
357 /*******************************************************************************
359 * FUNCTION: AcpiUtTrace
361 * PARAMETERS: LineNumber - Caller's line number
362 * FunctionName - Caller's procedure name
363 * ModuleName - Caller's module name
364 * ComponentId - Caller's component ID
368 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
371 ******************************************************************************/
376 const char *FunctionName,
377 const char *ModuleName,
381 AcpiGbl_NestingLevel++;
382 AcpiUtTrackStackPtr ();
384 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
385 LineNumber, FunctionName, ModuleName, ComponentId,
386 "%s\n", AcpiGbl_FnEntryStr);
389 ACPI_EXPORT_SYMBOL (AcpiUtTrace)
392 /*******************************************************************************
394 * FUNCTION: AcpiUtTracePtr
396 * PARAMETERS: LineNumber - Caller's line number
397 * FunctionName - Caller's procedure name
398 * ModuleName - Caller's module name
399 * ComponentId - Caller's component ID
400 * Pointer - Pointer to display
404 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
407 ******************************************************************************/
412 const char *FunctionName,
413 const char *ModuleName,
417 AcpiGbl_NestingLevel++;
418 AcpiUtTrackStackPtr ();
420 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
421 LineNumber, FunctionName, ModuleName, ComponentId,
422 "%s %p\n", AcpiGbl_FnEntryStr, Pointer);
426 /*******************************************************************************
428 * FUNCTION: AcpiUtTraceStr
430 * PARAMETERS: LineNumber - Caller's line number
431 * FunctionName - Caller's procedure name
432 * ModuleName - Caller's module name
433 * ComponentId - Caller's component ID
434 * String - Additional string to display
438 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
441 ******************************************************************************/
446 const char *FunctionName,
447 const char *ModuleName,
452 AcpiGbl_NestingLevel++;
453 AcpiUtTrackStackPtr ();
455 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
456 LineNumber, FunctionName, ModuleName, ComponentId,
457 "%s %s\n", AcpiGbl_FnEntryStr, String);
461 /*******************************************************************************
463 * FUNCTION: AcpiUtTraceU32
465 * PARAMETERS: LineNumber - Caller's line number
466 * FunctionName - Caller's procedure name
467 * ModuleName - Caller's module name
468 * ComponentId - Caller's component ID
469 * Integer - Integer to display
473 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
476 ******************************************************************************/
481 const char *FunctionName,
482 const char *ModuleName,
487 AcpiGbl_NestingLevel++;
488 AcpiUtTrackStackPtr ();
490 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
491 LineNumber, FunctionName, ModuleName, ComponentId,
492 "%s %08X\n", AcpiGbl_FnEntryStr, Integer);
496 /*******************************************************************************
498 * FUNCTION: AcpiUtExit
500 * PARAMETERS: LineNumber - Caller's line number
501 * FunctionName - Caller's procedure name
502 * ModuleName - Caller's module name
503 * ComponentId - Caller's component ID
507 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
510 ******************************************************************************/
515 const char *FunctionName,
516 const char *ModuleName,
520 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
521 LineNumber, FunctionName, ModuleName, ComponentId,
522 "%s\n", AcpiGbl_FnExitStr);
524 AcpiGbl_NestingLevel--;
527 ACPI_EXPORT_SYMBOL (AcpiUtExit)
530 /*******************************************************************************
532 * FUNCTION: AcpiUtStatusExit
534 * PARAMETERS: LineNumber - Caller's line number
535 * FunctionName - Caller's procedure name
536 * ModuleName - Caller's module name
537 * ComponentId - Caller's component ID
538 * Status - Exit status code
542 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
543 * set in DebugLevel. Prints exit status also.
545 ******************************************************************************/
550 const char *FunctionName,
551 const char *ModuleName,
556 if (ACPI_SUCCESS (Status))
558 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
559 LineNumber, FunctionName, ModuleName, ComponentId,
560 "%s %s\n", AcpiGbl_FnExitStr,
561 AcpiFormatException (Status));
565 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
566 LineNumber, FunctionName, ModuleName, ComponentId,
567 "%s ****Exception****: %s\n", AcpiGbl_FnExitStr,
568 AcpiFormatException (Status));
571 AcpiGbl_NestingLevel--;
574 ACPI_EXPORT_SYMBOL (AcpiUtStatusExit)
577 /*******************************************************************************
579 * FUNCTION: AcpiUtValueExit
581 * PARAMETERS: LineNumber - Caller's line number
582 * FunctionName - Caller's procedure name
583 * ModuleName - Caller's module name
584 * ComponentId - Caller's component ID
585 * Value - Value to be printed with exit msg
589 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
590 * set in DebugLevel. Prints exit value also.
592 ******************************************************************************/
597 const char *FunctionName,
598 const char *ModuleName,
603 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
604 LineNumber, FunctionName, ModuleName, ComponentId,
605 "%s %8.8X%8.8X\n", AcpiGbl_FnExitStr,
606 ACPI_FORMAT_UINT64 (Value));
608 AcpiGbl_NestingLevel--;
611 ACPI_EXPORT_SYMBOL (AcpiUtValueExit)
614 /*******************************************************************************
616 * FUNCTION: AcpiUtPtrExit
618 * PARAMETERS: LineNumber - Caller's line number
619 * FunctionName - Caller's procedure name
620 * ModuleName - Caller's module name
621 * ComponentId - Caller's component ID
622 * Ptr - Pointer to display
626 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
627 * set in DebugLevel. Prints exit value also.
629 ******************************************************************************/
634 const char *FunctionName,
635 const char *ModuleName,
640 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
641 LineNumber, FunctionName, ModuleName, ComponentId,
642 "%s %p\n", AcpiGbl_FnExitStr, Ptr);
644 AcpiGbl_NestingLevel--;
650 /*******************************************************************************
652 * FUNCTION: AcpiUtDumpBuffer
654 * PARAMETERS: Buffer - Buffer to dump
655 * Count - Amount to dump, in bytes
656 * Display - BYTE, WORD, DWORD, or QWORD display
657 * ComponentID - Caller's component ID
661 * DESCRIPTION: Generic dump buffer in both hex and ascii.
663 ******************************************************************************/
679 AcpiOsPrintf ("Null Buffer Pointer in DumpBuffer!\n");
683 if ((Count < 4) || (Count & 0x01))
685 Display = DB_BYTE_DISPLAY;
688 /* Nasty little dump buffer routine! */
692 /* Print current offset */
694 AcpiOsPrintf ("%6.4X: ", i);
696 /* Print 16 hex chars */
702 /* Dump fill spaces */
704 AcpiOsPrintf ("%*s", ((Display * 2) + 1), " ");
711 case DB_BYTE_DISPLAY:
712 default: /* Default is BYTE display */
714 AcpiOsPrintf ("%02X ", Buffer[(ACPI_SIZE) i + j]);
718 case DB_WORD_DISPLAY:
720 ACPI_MOVE_16_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
721 AcpiOsPrintf ("%04X ", Temp32);
725 case DB_DWORD_DISPLAY:
727 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
728 AcpiOsPrintf ("%08X ", Temp32);
732 case DB_QWORD_DISPLAY:
734 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
735 AcpiOsPrintf ("%08X", Temp32);
737 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j + 4]);
738 AcpiOsPrintf ("%08X ", Temp32);
746 * Print the ASCII equivalent characters but watch out for the bad
747 * unprintable ones (printable chars are 0x20 through 0x7E)
750 for (j = 0; j < 16; j++)
758 BufChar = Buffer[(ACPI_SIZE) i + j];
759 if (ACPI_IS_PRINT (BufChar))
761 AcpiOsPrintf ("%c", BufChar);
769 /* Done with that line. */
779 /*******************************************************************************
781 * FUNCTION: AcpiUtDumpBuffer
783 * PARAMETERS: Buffer - Buffer to dump
784 * Count - Amount to dump, in bytes
785 * Display - BYTE, WORD, DWORD, or QWORD display
786 * ComponentID - Caller's component ID
790 * DESCRIPTION: Generic dump buffer in both hex and ascii.
792 ******************************************************************************/
802 /* Only dump the buffer if tracing is enabled */
804 if (!((ACPI_LV_TABLES & AcpiDbgLevel) &&
805 (ComponentId & AcpiDbgLayer)))
810 AcpiUtDumpBuffer2 (Buffer, Count, Display);