1 /******************************************************************************
3 * Module Name: utdebug - Debug print/trace routines
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2019, 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 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #define EXPORT_ACPI_INTERFACES
154 #include <contrib/dev/acpica/include/acpi.h>
155 #include <contrib/dev/acpica/include/accommon.h>
156 #include <contrib/dev/acpica/include/acinterp.h>
158 #define _COMPONENT ACPI_UTILITIES
159 ACPI_MODULE_NAME ("utdebug")
162 #ifdef ACPI_DEBUG_OUTPUT
164 static ACPI_THREAD_ID AcpiGbl_PreviousThreadId = (ACPI_THREAD_ID) 0xFFFFFFFF;
165 static const char *AcpiGbl_FunctionEntryPrefix = "----Entry";
166 static const char *AcpiGbl_FunctionExitPrefix = "----Exit-";
169 /*******************************************************************************
171 * FUNCTION: AcpiUtInitStackPtrTrace
177 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
179 ******************************************************************************/
182 AcpiUtInitStackPtrTrace (
188 AcpiGbl_EntryStackPointer = &CurrentSp;
192 /*******************************************************************************
194 * FUNCTION: AcpiUtTrackStackPtr
200 * DESCRIPTION: Save the current CPU stack pointer
202 ******************************************************************************/
205 AcpiUtTrackStackPtr (
211 if (&CurrentSp < AcpiGbl_LowestStackPointer)
213 AcpiGbl_LowestStackPointer = &CurrentSp;
216 if (AcpiGbl_NestingLevel > AcpiGbl_DeepestNesting)
218 AcpiGbl_DeepestNesting = AcpiGbl_NestingLevel;
223 /*******************************************************************************
225 * FUNCTION: AcpiUtTrimFunctionName
227 * PARAMETERS: FunctionName - Ascii string containing a procedure name
229 * RETURN: Updated pointer to the function name
231 * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
232 * This allows compiler macros such as __FUNCTION__ to be used
233 * with no change to the debug output.
235 ******************************************************************************/
238 AcpiUtTrimFunctionName (
239 const char *FunctionName)
242 /* All Function names are longer than 4 chars, check is safe */
244 if (*(ACPI_CAST_PTR (UINT32, FunctionName)) == ACPI_PREFIX_MIXED)
246 /* This is the case where the original source has not been modified */
248 return (FunctionName + 4);
251 if (*(ACPI_CAST_PTR (UINT32, FunctionName)) == ACPI_PREFIX_LOWER)
253 /* This is the case where the source has been 'linuxized' */
255 return (FunctionName + 5);
258 return (FunctionName);
262 /*******************************************************************************
264 * FUNCTION: AcpiDebugPrint
266 * PARAMETERS: RequestedDebugLevel - Requested debug print level
267 * LineNumber - Caller's line number (for error output)
268 * FunctionName - Caller's procedure name
269 * ModuleName - Caller's module name
270 * ComponentId - Caller's component ID
271 * Format - Printf format field
272 * ... - Optional printf arguments
276 * DESCRIPTION: Print error message with prefix consisting of the module name,
277 * line number, and component ID.
279 ******************************************************************************/
281 void ACPI_INTERNAL_VAR_XFACE
283 UINT32 RequestedDebugLevel,
285 const char *FunctionName,
286 const char *ModuleName,
291 ACPI_THREAD_ID ThreadId;
293 #ifdef ACPI_APPLICATION
297 /* Check if debug output enabled */
299 if (!ACPI_IS_DEBUG_ENABLED (RequestedDebugLevel, ComponentId))
305 * Thread tracking and context switch notification
307 ThreadId = AcpiOsGetThreadId ();
308 if (ThreadId != AcpiGbl_PreviousThreadId)
310 if (ACPI_LV_THREADS & AcpiDbgLevel)
313 "\n**** Context Switch from TID %u to TID %u ****\n\n",
314 (UINT32) AcpiGbl_PreviousThreadId, (UINT32) ThreadId);
317 AcpiGbl_PreviousThreadId = ThreadId;
318 AcpiGbl_NestingLevel = 0;
322 * Display the module name, current line number, thread ID (if requested),
323 * current procedure nesting level, and the current procedure name
325 AcpiOsPrintf ("%9s-%04ld ", ModuleName, LineNumber);
327 #ifdef ACPI_APPLICATION
329 * For AcpiExec/iASL only, emit the thread ID and nesting level.
330 * Note: nesting level is really only useful during a single-thread
331 * execution. Otherwise, multiple threads will keep resetting the
334 if (ACPI_LV_THREADS & AcpiDbgLevel)
336 AcpiOsPrintf ("[%u] ", (UINT32) ThreadId);
339 FillCount = 48 - AcpiGbl_NestingLevel -
340 strlen (AcpiUtTrimFunctionName (FunctionName));
346 AcpiOsPrintf ("[%02ld] %*s",
347 AcpiGbl_NestingLevel, AcpiGbl_NestingLevel + 1, " ");
348 AcpiOsPrintf ("%s%*s: ",
349 AcpiUtTrimFunctionName (FunctionName), FillCount, " ");
352 AcpiOsPrintf ("%-22.22s: ", AcpiUtTrimFunctionName (FunctionName));
355 va_start (args, Format);
356 AcpiOsVprintf (Format, args);
360 ACPI_EXPORT_SYMBOL (AcpiDebugPrint)
363 /*******************************************************************************
365 * FUNCTION: AcpiDebugPrintRaw
367 * PARAMETERS: RequestedDebugLevel - Requested debug print level
368 * LineNumber - Caller's line number
369 * FunctionName - Caller's procedure name
370 * ModuleName - Caller's module name
371 * ComponentId - Caller's component ID
372 * Format - Printf format field
373 * ... - Optional printf arguments
377 * DESCRIPTION: Print message with no headers. Has same interface as
378 * DebugPrint so that the same macros can be used.
380 ******************************************************************************/
382 void ACPI_INTERNAL_VAR_XFACE
384 UINT32 RequestedDebugLevel,
386 const char *FunctionName,
387 const char *ModuleName,
395 /* Check if debug output enabled */
397 if (!ACPI_IS_DEBUG_ENABLED (RequestedDebugLevel, ComponentId))
402 va_start (args, Format);
403 AcpiOsVprintf (Format, args);
407 ACPI_EXPORT_SYMBOL (AcpiDebugPrintRaw)
410 /*******************************************************************************
412 * FUNCTION: AcpiUtTrace
414 * PARAMETERS: LineNumber - Caller's line number
415 * FunctionName - Caller's procedure name
416 * ModuleName - Caller's module name
417 * ComponentId - Caller's component ID
421 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
424 ******************************************************************************/
429 const char *FunctionName,
430 const char *ModuleName,
434 AcpiGbl_NestingLevel++;
435 AcpiUtTrackStackPtr ();
437 /* Check if enabled up-front for performance */
439 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
441 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
442 LineNumber, FunctionName, ModuleName, ComponentId,
443 "%s\n", AcpiGbl_FunctionEntryPrefix);
447 ACPI_EXPORT_SYMBOL (AcpiUtTrace)
450 /*******************************************************************************
452 * FUNCTION: AcpiUtTracePtr
454 * PARAMETERS: LineNumber - Caller's line number
455 * FunctionName - Caller's procedure name
456 * ModuleName - Caller's module name
457 * ComponentId - Caller's component ID
458 * Pointer - Pointer to display
462 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
465 ******************************************************************************/
470 const char *FunctionName,
471 const char *ModuleName,
476 AcpiGbl_NestingLevel++;
477 AcpiUtTrackStackPtr ();
479 /* Check if enabled up-front for performance */
481 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
483 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
484 LineNumber, FunctionName, ModuleName, ComponentId,
485 "%s %p\n", AcpiGbl_FunctionEntryPrefix, Pointer);
490 /*******************************************************************************
492 * FUNCTION: AcpiUtTraceStr
494 * PARAMETERS: LineNumber - Caller's line number
495 * FunctionName - Caller's procedure name
496 * ModuleName - Caller's module name
497 * ComponentId - Caller's component ID
498 * String - Additional string to display
502 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
505 ******************************************************************************/
510 const char *FunctionName,
511 const char *ModuleName,
516 AcpiGbl_NestingLevel++;
517 AcpiUtTrackStackPtr ();
519 /* Check if enabled up-front for performance */
521 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
523 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
524 LineNumber, FunctionName, ModuleName, ComponentId,
525 "%s %s\n", AcpiGbl_FunctionEntryPrefix, String);
530 /*******************************************************************************
532 * FUNCTION: AcpiUtTraceU32
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 * Integer - Integer to display
542 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
545 ******************************************************************************/
550 const char *FunctionName,
551 const char *ModuleName,
556 AcpiGbl_NestingLevel++;
557 AcpiUtTrackStackPtr ();
559 /* Check if enabled up-front for performance */
561 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
563 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
564 LineNumber, FunctionName, ModuleName, ComponentId,
565 "%s %08X\n", AcpiGbl_FunctionEntryPrefix, Integer);
570 /*******************************************************************************
572 * FUNCTION: AcpiUtExit
574 * PARAMETERS: LineNumber - Caller's line number
575 * FunctionName - Caller's procedure name
576 * ModuleName - Caller's module name
577 * ComponentId - Caller's component ID
581 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
584 ******************************************************************************/
589 const char *FunctionName,
590 const char *ModuleName,
594 /* Check if enabled up-front for performance */
596 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
598 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
599 LineNumber, FunctionName, ModuleName, ComponentId,
600 "%s\n", AcpiGbl_FunctionExitPrefix);
603 if (AcpiGbl_NestingLevel)
605 AcpiGbl_NestingLevel--;
609 ACPI_EXPORT_SYMBOL (AcpiUtExit)
612 /*******************************************************************************
614 * FUNCTION: AcpiUtStatusExit
616 * PARAMETERS: LineNumber - Caller's line number
617 * FunctionName - Caller's procedure name
618 * ModuleName - Caller's module name
619 * ComponentId - Caller's component ID
620 * Status - Exit status code
624 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
625 * set in DebugLevel. Prints exit status also.
627 ******************************************************************************/
632 const char *FunctionName,
633 const char *ModuleName,
638 /* Check if enabled up-front for performance */
640 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
642 if (ACPI_SUCCESS (Status))
644 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
645 LineNumber, FunctionName, ModuleName, ComponentId,
646 "%s %s\n", AcpiGbl_FunctionExitPrefix,
647 AcpiFormatException (Status));
651 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
652 LineNumber, FunctionName, ModuleName, ComponentId,
653 "%s ****Exception****: %s\n", AcpiGbl_FunctionExitPrefix,
654 AcpiFormatException (Status));
658 if (AcpiGbl_NestingLevel)
660 AcpiGbl_NestingLevel--;
664 ACPI_EXPORT_SYMBOL (AcpiUtStatusExit)
667 /*******************************************************************************
669 * FUNCTION: AcpiUtValueExit
671 * PARAMETERS: LineNumber - Caller's line number
672 * FunctionName - Caller's procedure name
673 * ModuleName - Caller's module name
674 * ComponentId - Caller's component ID
675 * Value - Value to be printed with exit msg
679 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
680 * set in DebugLevel. Prints exit value also.
682 ******************************************************************************/
687 const char *FunctionName,
688 const char *ModuleName,
693 /* Check if enabled up-front for performance */
695 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
697 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
698 LineNumber, FunctionName, ModuleName, ComponentId,
699 "%s %8.8X%8.8X\n", AcpiGbl_FunctionExitPrefix,
700 ACPI_FORMAT_UINT64 (Value));
703 if (AcpiGbl_NestingLevel)
705 AcpiGbl_NestingLevel--;
709 ACPI_EXPORT_SYMBOL (AcpiUtValueExit)
712 /*******************************************************************************
714 * FUNCTION: AcpiUtPtrExit
716 * PARAMETERS: LineNumber - Caller's line number
717 * FunctionName - Caller's procedure name
718 * ModuleName - Caller's module name
719 * ComponentId - Caller's component ID
720 * Ptr - Pointer to display
724 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
725 * set in DebugLevel. Prints exit value also.
727 ******************************************************************************/
732 const char *FunctionName,
733 const char *ModuleName,
738 /* Check if enabled up-front for performance */
740 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
742 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
743 LineNumber, FunctionName, ModuleName, ComponentId,
744 "%s %p\n", AcpiGbl_FunctionExitPrefix, Ptr);
747 if (AcpiGbl_NestingLevel)
749 AcpiGbl_NestingLevel--;
754 /*******************************************************************************
756 * FUNCTION: AcpiUtStrExit
758 * PARAMETERS: LineNumber - Caller's line number
759 * FunctionName - Caller's procedure name
760 * ModuleName - Caller's module name
761 * ComponentId - Caller's component ID
762 * String - String to display
766 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
767 * set in DebugLevel. Prints exit value also.
769 ******************************************************************************/
774 const char *FunctionName,
775 const char *ModuleName,
780 /* Check if enabled up-front for performance */
782 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
784 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
785 LineNumber, FunctionName, ModuleName, ComponentId,
786 "%s %s\n", AcpiGbl_FunctionExitPrefix, String);
789 if (AcpiGbl_NestingLevel)
791 AcpiGbl_NestingLevel--;
796 /*******************************************************************************
798 * FUNCTION: AcpiTracePoint
800 * PARAMETERS: Type - Trace event type
801 * Begin - TRUE if before execution
802 * Aml - Executed AML address
803 * Pathname - Object path
804 * Pointer - Pointer to the related object
808 * DESCRIPTION: Interpreter execution trace.
810 ******************************************************************************/
814 ACPI_TRACE_EVENT_TYPE Type,
820 ACPI_FUNCTION_ENTRY ();
822 AcpiExTracePoint (Type, Begin, Aml, Pathname);
824 #ifdef ACPI_USE_SYSTEM_TRACER
825 AcpiOsTracePoint (Type, Begin, Aml, Pathname);
829 ACPI_EXPORT_SYMBOL (AcpiTracePoint)