1 /******************************************************************************
3 * Module Name: utdebug - Debug print/trace routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, 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.
45 #define EXPORT_ACPI_INTERFACES
50 #define _COMPONENT ACPI_UTILITIES
51 ACPI_MODULE_NAME ("utdebug")
54 #ifdef ACPI_DEBUG_OUTPUT
56 static ACPI_THREAD_ID AcpiGbl_PrevThreadId
= (ACPI_THREAD_ID
) 0xFFFFFFFF;
57 static char *AcpiGbl_FnEntryStr
= "----Entry";
58 static char *AcpiGbl_FnExitStr
= "----Exit-";
60 /* Local prototypes */
63 AcpiUtTrimFunctionName (
64 const char *FunctionName
);
67 /*******************************************************************************
69 * FUNCTION: AcpiUtInitStackPtrTrace
75 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
77 ******************************************************************************/
80 AcpiUtInitStackPtrTrace (
86 AcpiGbl_EntryStackPointer
= &CurrentSp
;
90 /*******************************************************************************
92 * FUNCTION: AcpiUtTrackStackPtr
98 * DESCRIPTION: Save the current CPU stack pointer
100 ******************************************************************************/
103 AcpiUtTrackStackPtr (
109 if (&CurrentSp
< AcpiGbl_LowestStackPointer
)
111 AcpiGbl_LowestStackPointer
= &CurrentSp
;
114 if (AcpiGbl_NestingLevel
> AcpiGbl_DeepestNesting
)
116 AcpiGbl_DeepestNesting
= AcpiGbl_NestingLevel
;
121 /*******************************************************************************
123 * FUNCTION: AcpiUtTrimFunctionName
125 * PARAMETERS: FunctionName - Ascii string containing a procedure name
127 * RETURN: Updated pointer to the function name
129 * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
130 * This allows compiler macros such as __FUNCTION__ to be used
131 * with no change to the debug output.
133 ******************************************************************************/
136 AcpiUtTrimFunctionName (
137 const char *FunctionName
)
140 /* All Function names are longer than 4 chars, check is safe */
142 if (*(ACPI_CAST_PTR (UINT32
, FunctionName
)) == ACPI_PREFIX_MIXED
)
144 /* This is the case where the original source has not been modified */
146 return (FunctionName
+ 4);
149 if (*(ACPI_CAST_PTR (UINT32
, FunctionName
)) == ACPI_PREFIX_LOWER
)
151 /* This is the case where the source has been 'linuxized' */
153 return (FunctionName
+ 5);
156 return (FunctionName
);
160 /*******************************************************************************
162 * FUNCTION: AcpiDebugPrint
164 * PARAMETERS: RequestedDebugLevel - Requested debug print level
165 * LineNumber - Caller's line number (for error output)
166 * FunctionName - Caller's procedure name
167 * ModuleName - Caller's module name
168 * ComponentId - Caller's component ID
169 * Format - Printf format field
170 * ... - Optional printf arguments
174 * DESCRIPTION: Print error message with prefix consisting of the module name,
175 * line number, and component ID.
177 ******************************************************************************/
179 void ACPI_INTERNAL_VAR_XFACE
181 UINT32 RequestedDebugLevel
,
183 const char *FunctionName
,
184 const char *ModuleName
,
189 ACPI_THREAD_ID ThreadId
;
193 /* Check if debug output enabled */
195 if (!ACPI_IS_DEBUG_ENABLED (RequestedDebugLevel
, ComponentId
))
201 * Thread tracking and context switch notification
203 ThreadId
= AcpiOsGetThreadId ();
204 if (ThreadId
!= AcpiGbl_PrevThreadId
)
206 if (ACPI_LV_THREADS
& AcpiDbgLevel
)
209 "\n**** Context Switch from TID %u to TID %u ****\n\n",
210 (UINT32
) AcpiGbl_PrevThreadId
, (UINT32
) ThreadId
);
213 AcpiGbl_PrevThreadId
= ThreadId
;
214 AcpiGbl_NestingLevel
= 0;
218 * Display the module name, current line number, thread ID (if requested),
219 * current procedure nesting level, and the current procedure name
221 AcpiOsPrintf ("%9s-%04ld ", ModuleName
, LineNumber
);
225 * For AcpiExec only, emit the thread ID and nesting level.
226 * Note: nesting level is really only useful during a single-thread
227 * execution. Otherwise, multiple threads will keep resetting the
230 if (ACPI_LV_THREADS
& AcpiDbgLevel
)
232 AcpiOsPrintf ("[%u] ", (UINT32
) ThreadId
);
235 AcpiOsPrintf ("[%02ld] ", AcpiGbl_NestingLevel
);
238 AcpiOsPrintf ("%-22.22s: ", AcpiUtTrimFunctionName (FunctionName
));
240 va_start (args
, Format
);
241 AcpiOsVprintf (Format
, args
);
245 ACPI_EXPORT_SYMBOL (AcpiDebugPrint
)
248 /*******************************************************************************
250 * FUNCTION: AcpiDebugPrintRaw
252 * PARAMETERS: RequestedDebugLevel - Requested debug print level
253 * LineNumber - Caller's line number
254 * FunctionName - Caller's procedure name
255 * ModuleName - Caller's module name
256 * ComponentId - Caller's component ID
257 * Format - Printf format field
258 * ... - Optional printf arguments
262 * DESCRIPTION: Print message with no headers. Has same interface as
263 * DebugPrint so that the same macros can be used.
265 ******************************************************************************/
267 void ACPI_INTERNAL_VAR_XFACE
269 UINT32 RequestedDebugLevel
,
271 const char *FunctionName
,
272 const char *ModuleName
,
280 /* Check if debug output enabled */
282 if (!ACPI_IS_DEBUG_ENABLED (RequestedDebugLevel
, ComponentId
))
287 va_start (args
, Format
);
288 AcpiOsVprintf (Format
, args
);
292 ACPI_EXPORT_SYMBOL (AcpiDebugPrintRaw
)
295 /*******************************************************************************
297 * FUNCTION: AcpiUtTrace
299 * PARAMETERS: LineNumber - Caller's line number
300 * FunctionName - Caller's procedure name
301 * ModuleName - Caller's module name
302 * ComponentId - Caller's component ID
306 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
309 ******************************************************************************/
314 const char *FunctionName
,
315 const char *ModuleName
,
319 AcpiGbl_NestingLevel
++;
320 AcpiUtTrackStackPtr ();
322 /* Check if enabled up-front for performance */
324 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS
, ComponentId
))
326 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
327 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
328 "%s\n", AcpiGbl_FnEntryStr
);
332 ACPI_EXPORT_SYMBOL (AcpiUtTrace
)
335 /*******************************************************************************
337 * FUNCTION: AcpiUtTracePtr
339 * PARAMETERS: LineNumber - Caller's line number
340 * FunctionName - Caller's procedure name
341 * ModuleName - Caller's module name
342 * ComponentId - Caller's component ID
343 * Pointer - Pointer to display
347 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
350 ******************************************************************************/
355 const char *FunctionName
,
356 const char *ModuleName
,
361 AcpiGbl_NestingLevel
++;
362 AcpiUtTrackStackPtr ();
364 /* Check if enabled up-front for performance */
366 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS
, ComponentId
))
368 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
369 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
370 "%s %p\n", AcpiGbl_FnEntryStr
, Pointer
);
375 /*******************************************************************************
377 * FUNCTION: AcpiUtTraceStr
379 * PARAMETERS: LineNumber - Caller's line number
380 * FunctionName - Caller's procedure name
381 * ModuleName - Caller's module name
382 * ComponentId - Caller's component ID
383 * String - Additional string to display
387 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
390 ******************************************************************************/
395 const char *FunctionName
,
396 const char *ModuleName
,
401 AcpiGbl_NestingLevel
++;
402 AcpiUtTrackStackPtr ();
404 /* Check if enabled up-front for performance */
406 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS
, ComponentId
))
408 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
409 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
410 "%s %s\n", AcpiGbl_FnEntryStr
, String
);
415 /*******************************************************************************
417 * FUNCTION: AcpiUtTraceU32
419 * PARAMETERS: LineNumber - Caller's line number
420 * FunctionName - Caller's procedure name
421 * ModuleName - Caller's module name
422 * ComponentId - Caller's component ID
423 * Integer - Integer to display
427 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
430 ******************************************************************************/
435 const char *FunctionName
,
436 const char *ModuleName
,
441 AcpiGbl_NestingLevel
++;
442 AcpiUtTrackStackPtr ();
444 /* Check if enabled up-front for performance */
446 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS
, ComponentId
))
448 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
449 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
450 "%s %08X\n", AcpiGbl_FnEntryStr
, Integer
);
455 /*******************************************************************************
457 * FUNCTION: AcpiUtExit
459 * PARAMETERS: LineNumber - Caller's line number
460 * FunctionName - Caller's procedure name
461 * ModuleName - Caller's module name
462 * ComponentId - Caller's component ID
466 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
469 ******************************************************************************/
474 const char *FunctionName
,
475 const char *ModuleName
,
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\n", AcpiGbl_FnExitStr
);
488 if (AcpiGbl_NestingLevel
)
490 AcpiGbl_NestingLevel
--;
494 ACPI_EXPORT_SYMBOL (AcpiUtExit
)
497 /*******************************************************************************
499 * FUNCTION: AcpiUtStatusExit
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
505 * Status - Exit status code
509 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
510 * set in DebugLevel. Prints exit status also.
512 ******************************************************************************/
517 const char *FunctionName
,
518 const char *ModuleName
,
523 /* Check if enabled up-front for performance */
525 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS
, ComponentId
))
527 if (ACPI_SUCCESS (Status
))
529 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
530 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
531 "%s %s\n", AcpiGbl_FnExitStr
,
532 AcpiFormatException (Status
));
536 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
537 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
538 "%s ****Exception****: %s\n", AcpiGbl_FnExitStr
,
539 AcpiFormatException (Status
));
543 if (AcpiGbl_NestingLevel
)
545 AcpiGbl_NestingLevel
--;
549 ACPI_EXPORT_SYMBOL (AcpiUtStatusExit
)
552 /*******************************************************************************
554 * FUNCTION: AcpiUtValueExit
556 * PARAMETERS: LineNumber - Caller's line number
557 * FunctionName - Caller's procedure name
558 * ModuleName - Caller's module name
559 * ComponentId - Caller's component ID
560 * Value - Value to be printed with exit msg
564 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
565 * set in DebugLevel. Prints exit value also.
567 ******************************************************************************/
572 const char *FunctionName
,
573 const char *ModuleName
,
578 /* Check if enabled up-front for performance */
580 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS
, ComponentId
))
582 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
583 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
584 "%s %8.8X%8.8X\n", AcpiGbl_FnExitStr
,
585 ACPI_FORMAT_UINT64 (Value
));
588 if (AcpiGbl_NestingLevel
)
590 AcpiGbl_NestingLevel
--;
594 ACPI_EXPORT_SYMBOL (AcpiUtValueExit
)
597 /*******************************************************************************
599 * FUNCTION: AcpiUtPtrExit
601 * PARAMETERS: LineNumber - Caller's line number
602 * FunctionName - Caller's procedure name
603 * ModuleName - Caller's module name
604 * ComponentId - Caller's component ID
605 * Ptr - Pointer to display
609 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
610 * set in DebugLevel. Prints exit value also.
612 ******************************************************************************/
617 const char *FunctionName
,
618 const char *ModuleName
,
623 /* Check if enabled up-front for performance */
625 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS
, ComponentId
))
627 AcpiDebugPrint (ACPI_LV_FUNCTIONS
,
628 LineNumber
, FunctionName
, ModuleName
, ComponentId
,
629 "%s %p\n", AcpiGbl_FnExitStr
, Ptr
);
632 if (AcpiGbl_NestingLevel
)
634 AcpiGbl_NestingLevel
--;