1 /******************************************************************************
3 * Module Name: utdebug - Debug print/trace routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #define EXPORT_ACPI_INTERFACES
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
49 #define _COMPONENT ACPI_UTILITIES
50 ACPI_MODULE_NAME ("utdebug")
53 #ifdef ACPI_DEBUG_OUTPUT
55 static ACPI_THREAD_ID AcpiGbl_PrevThreadId = (ACPI_THREAD_ID) 0xFFFFFFFF;
56 static char *AcpiGbl_FnEntryStr = "----Entry";
57 static char *AcpiGbl_FnExitStr = "----Exit-";
59 /* Local prototypes */
62 AcpiUtTrimFunctionName (
63 const char *FunctionName);
66 /*******************************************************************************
68 * FUNCTION: AcpiUtInitStackPtrTrace
74 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
76 ******************************************************************************/
79 AcpiUtInitStackPtrTrace (
85 AcpiGbl_EntryStackPointer = &CurrentSp;
89 /*******************************************************************************
91 * FUNCTION: AcpiUtTrackStackPtr
97 * DESCRIPTION: Save the current CPU stack pointer
99 ******************************************************************************/
102 AcpiUtTrackStackPtr (
108 if (&CurrentSp < AcpiGbl_LowestStackPointer)
110 AcpiGbl_LowestStackPointer = &CurrentSp;
113 if (AcpiGbl_NestingLevel > AcpiGbl_DeepestNesting)
115 AcpiGbl_DeepestNesting = AcpiGbl_NestingLevel;
120 /*******************************************************************************
122 * FUNCTION: AcpiUtTrimFunctionName
124 * PARAMETERS: FunctionName - Ascii string containing a procedure name
126 * RETURN: Updated pointer to the function name
128 * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
129 * This allows compiler macros such as __FUNCTION__ to be used
130 * with no change to the debug output.
132 ******************************************************************************/
135 AcpiUtTrimFunctionName (
136 const char *FunctionName)
139 /* All Function names are longer than 4 chars, check is safe */
141 if (*(ACPI_CAST_PTR (UINT32, FunctionName)) == ACPI_PREFIX_MIXED)
143 /* This is the case where the original source has not been modified */
145 return (FunctionName + 4);
148 if (*(ACPI_CAST_PTR (UINT32, FunctionName)) == ACPI_PREFIX_LOWER)
150 /* This is the case where the source has been 'linuxized' */
152 return (FunctionName + 5);
155 return (FunctionName);
159 /*******************************************************************************
161 * FUNCTION: AcpiDebugPrint
163 * PARAMETERS: RequestedDebugLevel - Requested debug print level
164 * LineNumber - Caller's line number (for error output)
165 * FunctionName - Caller's procedure name
166 * ModuleName - Caller's module name
167 * ComponentId - Caller's component ID
168 * Format - Printf format field
169 * ... - Optional printf arguments
173 * DESCRIPTION: Print error message with prefix consisting of the module name,
174 * line number, and component ID.
176 ******************************************************************************/
178 void ACPI_INTERNAL_VAR_XFACE
180 UINT32 RequestedDebugLevel,
182 const char *FunctionName,
183 const char *ModuleName,
188 ACPI_THREAD_ID ThreadId;
192 /* Check if debug output enabled */
194 if (!ACPI_IS_DEBUG_ENABLED (RequestedDebugLevel, ComponentId))
200 * Thread tracking and context switch notification
202 ThreadId = AcpiOsGetThreadId ();
203 if (ThreadId != AcpiGbl_PrevThreadId)
205 if (ACPI_LV_THREADS & AcpiDbgLevel)
208 "\n**** Context Switch from TID %u to TID %u ****\n\n",
209 (UINT32) AcpiGbl_PrevThreadId, (UINT32) ThreadId);
212 AcpiGbl_PrevThreadId = ThreadId;
213 AcpiGbl_NestingLevel = 0;
217 * Display the module name, current line number, thread ID (if requested),
218 * current procedure nesting level, and the current procedure name
220 AcpiOsPrintf ("%9s-%04ld ", ModuleName, LineNumber);
222 #ifdef ACPI_APPLICATION
224 * For AcpiExec/iASL only, emit the thread ID and nesting level.
225 * Note: nesting level is really only useful during a single-thread
226 * execution. Otherwise, multiple threads will keep resetting the
229 if (ACPI_LV_THREADS & AcpiDbgLevel)
231 AcpiOsPrintf ("[%u] ", (UINT32) ThreadId);
234 AcpiOsPrintf ("[%02ld] ", AcpiGbl_NestingLevel);
237 AcpiOsPrintf ("%-22.22s: ", AcpiUtTrimFunctionName (FunctionName));
239 va_start (args, Format);
240 AcpiOsVprintf (Format, args);
244 ACPI_EXPORT_SYMBOL (AcpiDebugPrint)
247 /*******************************************************************************
249 * FUNCTION: AcpiDebugPrintRaw
251 * PARAMETERS: RequestedDebugLevel - Requested debug print level
252 * LineNumber - Caller's line number
253 * FunctionName - Caller's procedure name
254 * ModuleName - Caller's module name
255 * ComponentId - Caller's component ID
256 * Format - Printf format field
257 * ... - Optional printf arguments
261 * DESCRIPTION: Print message with no headers. Has same interface as
262 * DebugPrint so that the same macros can be used.
264 ******************************************************************************/
266 void ACPI_INTERNAL_VAR_XFACE
268 UINT32 RequestedDebugLevel,
270 const char *FunctionName,
271 const char *ModuleName,
279 /* Check if debug output enabled */
281 if (!ACPI_IS_DEBUG_ENABLED (RequestedDebugLevel, ComponentId))
286 va_start (args, Format);
287 AcpiOsVprintf (Format, args);
291 ACPI_EXPORT_SYMBOL (AcpiDebugPrintRaw)
294 /*******************************************************************************
296 * FUNCTION: AcpiUtTrace
298 * PARAMETERS: LineNumber - Caller's line number
299 * FunctionName - Caller's procedure name
300 * ModuleName - Caller's module name
301 * ComponentId - Caller's component ID
305 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
308 ******************************************************************************/
313 const char *FunctionName,
314 const char *ModuleName,
318 AcpiGbl_NestingLevel++;
319 AcpiUtTrackStackPtr ();
321 /* Check if enabled up-front for performance */
323 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
325 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
326 LineNumber, FunctionName, ModuleName, ComponentId,
327 "%s\n", AcpiGbl_FnEntryStr);
331 ACPI_EXPORT_SYMBOL (AcpiUtTrace)
334 /*******************************************************************************
336 * FUNCTION: AcpiUtTracePtr
338 * PARAMETERS: LineNumber - Caller's line number
339 * FunctionName - Caller's procedure name
340 * ModuleName - Caller's module name
341 * ComponentId - Caller's component ID
342 * Pointer - Pointer to display
346 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
349 ******************************************************************************/
354 const char *FunctionName,
355 const char *ModuleName,
360 AcpiGbl_NestingLevel++;
361 AcpiUtTrackStackPtr ();
363 /* Check if enabled up-front for performance */
365 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
367 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
368 LineNumber, FunctionName, ModuleName, ComponentId,
369 "%s %p\n", AcpiGbl_FnEntryStr, Pointer);
374 /*******************************************************************************
376 * FUNCTION: AcpiUtTraceStr
378 * PARAMETERS: LineNumber - Caller's line number
379 * FunctionName - Caller's procedure name
380 * ModuleName - Caller's module name
381 * ComponentId - Caller's component ID
382 * String - Additional string to display
386 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
389 ******************************************************************************/
394 const char *FunctionName,
395 const char *ModuleName,
400 AcpiGbl_NestingLevel++;
401 AcpiUtTrackStackPtr ();
403 /* Check if enabled up-front for performance */
405 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
407 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
408 LineNumber, FunctionName, ModuleName, ComponentId,
409 "%s %s\n", AcpiGbl_FnEntryStr, String);
414 /*******************************************************************************
416 * FUNCTION: AcpiUtTraceU32
418 * PARAMETERS: LineNumber - Caller's line number
419 * FunctionName - Caller's procedure name
420 * ModuleName - Caller's module name
421 * ComponentId - Caller's component ID
422 * Integer - Integer to display
426 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
429 ******************************************************************************/
434 const char *FunctionName,
435 const char *ModuleName,
440 AcpiGbl_NestingLevel++;
441 AcpiUtTrackStackPtr ();
443 /* Check if enabled up-front for performance */
445 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
447 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
448 LineNumber, FunctionName, ModuleName, ComponentId,
449 "%s %08X\n", AcpiGbl_FnEntryStr, Integer);
454 /*******************************************************************************
456 * FUNCTION: AcpiUtExit
458 * PARAMETERS: LineNumber - Caller's line number
459 * FunctionName - Caller's procedure name
460 * ModuleName - Caller's module name
461 * ComponentId - Caller's component ID
465 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
468 ******************************************************************************/
473 const char *FunctionName,
474 const char *ModuleName,
478 /* Check if enabled up-front for performance */
480 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
482 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
483 LineNumber, FunctionName, ModuleName, ComponentId,
484 "%s\n", AcpiGbl_FnExitStr);
487 if (AcpiGbl_NestingLevel)
489 AcpiGbl_NestingLevel--;
493 ACPI_EXPORT_SYMBOL (AcpiUtExit)
496 /*******************************************************************************
498 * FUNCTION: AcpiUtStatusExit
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
504 * Status - Exit status code
508 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
509 * set in DebugLevel. Prints exit status also.
511 ******************************************************************************/
516 const char *FunctionName,
517 const char *ModuleName,
522 /* Check if enabled up-front for performance */
524 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
526 if (ACPI_SUCCESS (Status))
528 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
529 LineNumber, FunctionName, ModuleName, ComponentId,
530 "%s %s\n", AcpiGbl_FnExitStr,
531 AcpiFormatException (Status));
535 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
536 LineNumber, FunctionName, ModuleName, ComponentId,
537 "%s ****Exception****: %s\n", AcpiGbl_FnExitStr,
538 AcpiFormatException (Status));
542 if (AcpiGbl_NestingLevel)
544 AcpiGbl_NestingLevel--;
548 ACPI_EXPORT_SYMBOL (AcpiUtStatusExit)
551 /*******************************************************************************
553 * FUNCTION: AcpiUtValueExit
555 * PARAMETERS: LineNumber - Caller's line number
556 * FunctionName - Caller's procedure name
557 * ModuleName - Caller's module name
558 * ComponentId - Caller's component ID
559 * Value - Value to be printed with exit msg
563 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
564 * set in DebugLevel. Prints exit value also.
566 ******************************************************************************/
571 const char *FunctionName,
572 const char *ModuleName,
577 /* Check if enabled up-front for performance */
579 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
581 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
582 LineNumber, FunctionName, ModuleName, ComponentId,
583 "%s %8.8X%8.8X\n", AcpiGbl_FnExitStr,
584 ACPI_FORMAT_UINT64 (Value));
587 if (AcpiGbl_NestingLevel)
589 AcpiGbl_NestingLevel--;
593 ACPI_EXPORT_SYMBOL (AcpiUtValueExit)
596 /*******************************************************************************
598 * FUNCTION: AcpiUtPtrExit
600 * PARAMETERS: LineNumber - Caller's line number
601 * FunctionName - Caller's procedure name
602 * ModuleName - Caller's module name
603 * ComponentId - Caller's component ID
604 * Ptr - Pointer to display
608 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
609 * set in DebugLevel. Prints exit value also.
611 ******************************************************************************/
616 const char *FunctionName,
617 const char *ModuleName,
622 /* Check if enabled up-front for performance */
624 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
626 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
627 LineNumber, FunctionName, ModuleName, ComponentId,
628 "%s %p\n", AcpiGbl_FnExitStr, Ptr);
631 if (AcpiGbl_NestingLevel)
633 AcpiGbl_NestingLevel--;
640 #ifdef ACPI_APPLICATION
641 /*******************************************************************************
643 * FUNCTION: AcpiLogError
645 * PARAMETERS: Format - Printf format field
646 * ... - Optional printf arguments
650 * DESCRIPTION: Print error message to the console, used by applications.
652 ******************************************************************************/
654 void ACPI_INTERNAL_VAR_XFACE
661 va_start (Args, Format);
662 (void) AcpiUtFileVprintf (ACPI_FILE_ERR, Format, Args);
666 ACPI_EXPORT_SYMBOL (AcpiLogError)