1 /******************************************************************************
3 * Module Name: utdebug - Debug print 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.
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;
216 * Display the module name, current line number, thread ID (if requested),
217 * current procedure nesting level, and the current procedure name
219 AcpiOsPrintf ("%8s-%04ld ", ModuleName, LineNumber);
221 if (ACPI_LV_THREADS & AcpiDbgLevel)
223 AcpiOsPrintf ("[%u] ", (UINT32) ThreadId);
226 AcpiOsPrintf ("[%02ld] %-22.22s: ",
227 AcpiGbl_NestingLevel, AcpiUtTrimFunctionName (FunctionName));
229 va_start (args, Format);
230 AcpiOsVprintf (Format, args);
234 ACPI_EXPORT_SYMBOL (AcpiDebugPrint)
237 /*******************************************************************************
239 * FUNCTION: AcpiDebugPrintRaw
241 * PARAMETERS: RequestedDebugLevel - Requested debug print level
242 * LineNumber - Caller's line number
243 * FunctionName - Caller's procedure name
244 * ModuleName - Caller's module name
245 * ComponentId - Caller's component ID
246 * Format - Printf format field
247 * ... - Optional printf arguments
251 * DESCRIPTION: Print message with no headers. Has same interface as
252 * DebugPrint so that the same macros can be used.
254 ******************************************************************************/
256 void ACPI_INTERNAL_VAR_XFACE
258 UINT32 RequestedDebugLevel,
260 const char *FunctionName,
261 const char *ModuleName,
269 /* Check if debug output enabled */
271 if (!ACPI_IS_DEBUG_ENABLED (RequestedDebugLevel, ComponentId))
276 va_start (args, Format);
277 AcpiOsVprintf (Format, args);
281 ACPI_EXPORT_SYMBOL (AcpiDebugPrintRaw)
284 /*******************************************************************************
286 * FUNCTION: AcpiUtTrace
288 * PARAMETERS: LineNumber - Caller's line number
289 * FunctionName - Caller's procedure name
290 * ModuleName - Caller's module name
291 * ComponentId - Caller's component ID
295 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
298 ******************************************************************************/
303 const char *FunctionName,
304 const char *ModuleName,
308 AcpiGbl_NestingLevel++;
309 AcpiUtTrackStackPtr ();
311 /* Check if enabled up-front for performance */
313 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
315 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
316 LineNumber, FunctionName, ModuleName, ComponentId,
317 "%s\n", AcpiGbl_FnEntryStr);
321 ACPI_EXPORT_SYMBOL (AcpiUtTrace)
324 /*******************************************************************************
326 * FUNCTION: AcpiUtTracePtr
328 * PARAMETERS: LineNumber - Caller's line number
329 * FunctionName - Caller's procedure name
330 * ModuleName - Caller's module name
331 * ComponentId - Caller's component ID
332 * Pointer - Pointer to display
336 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
339 ******************************************************************************/
344 const char *FunctionName,
345 const char *ModuleName,
350 AcpiGbl_NestingLevel++;
351 AcpiUtTrackStackPtr ();
353 /* Check if enabled up-front for performance */
355 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
357 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
358 LineNumber, FunctionName, ModuleName, ComponentId,
359 "%s %p\n", AcpiGbl_FnEntryStr, Pointer);
364 /*******************************************************************************
366 * FUNCTION: AcpiUtTraceStr
368 * PARAMETERS: LineNumber - Caller's line number
369 * FunctionName - Caller's procedure name
370 * ModuleName - Caller's module name
371 * ComponentId - Caller's component ID
372 * String - Additional string to display
376 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
379 ******************************************************************************/
384 const char *FunctionName,
385 const char *ModuleName,
390 AcpiGbl_NestingLevel++;
391 AcpiUtTrackStackPtr ();
393 /* Check if enabled up-front for performance */
395 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
397 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
398 LineNumber, FunctionName, ModuleName, ComponentId,
399 "%s %s\n", AcpiGbl_FnEntryStr, String);
404 /*******************************************************************************
406 * FUNCTION: AcpiUtTraceU32
408 * PARAMETERS: LineNumber - Caller's line number
409 * FunctionName - Caller's procedure name
410 * ModuleName - Caller's module name
411 * ComponentId - Caller's component ID
412 * Integer - Integer to display
416 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
419 ******************************************************************************/
424 const char *FunctionName,
425 const char *ModuleName,
430 AcpiGbl_NestingLevel++;
431 AcpiUtTrackStackPtr ();
433 /* Check if enabled up-front for performance */
435 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
437 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
438 LineNumber, FunctionName, ModuleName, ComponentId,
439 "%s %08X\n", AcpiGbl_FnEntryStr, Integer);
444 /*******************************************************************************
446 * FUNCTION: AcpiUtExit
448 * PARAMETERS: LineNumber - Caller's line number
449 * FunctionName - Caller's procedure name
450 * ModuleName - Caller's module name
451 * ComponentId - Caller's component ID
455 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
458 ******************************************************************************/
463 const char *FunctionName,
464 const char *ModuleName,
468 /* Check if enabled up-front for performance */
470 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
472 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
473 LineNumber, FunctionName, ModuleName, ComponentId,
474 "%s\n", AcpiGbl_FnExitStr);
477 AcpiGbl_NestingLevel--;
480 ACPI_EXPORT_SYMBOL (AcpiUtExit)
483 /*******************************************************************************
485 * FUNCTION: AcpiUtStatusExit
487 * PARAMETERS: LineNumber - Caller's line number
488 * FunctionName - Caller's procedure name
489 * ModuleName - Caller's module name
490 * ComponentId - Caller's component ID
491 * Status - Exit status code
495 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
496 * set in DebugLevel. Prints exit status also.
498 ******************************************************************************/
503 const char *FunctionName,
504 const char *ModuleName,
509 /* Check if enabled up-front for performance */
511 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
513 if (ACPI_SUCCESS (Status))
515 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
516 LineNumber, FunctionName, ModuleName, ComponentId,
517 "%s %s\n", AcpiGbl_FnExitStr,
518 AcpiFormatException (Status));
522 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
523 LineNumber, FunctionName, ModuleName, ComponentId,
524 "%s ****Exception****: %s\n", AcpiGbl_FnExitStr,
525 AcpiFormatException (Status));
529 AcpiGbl_NestingLevel--;
532 ACPI_EXPORT_SYMBOL (AcpiUtStatusExit)
535 /*******************************************************************************
537 * FUNCTION: AcpiUtValueExit
539 * PARAMETERS: LineNumber - Caller's line number
540 * FunctionName - Caller's procedure name
541 * ModuleName - Caller's module name
542 * ComponentId - Caller's component ID
543 * Value - Value to be printed with exit msg
547 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
548 * set in DebugLevel. Prints exit value also.
550 ******************************************************************************/
555 const char *FunctionName,
556 const char *ModuleName,
561 /* Check if enabled up-front for performance */
563 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
565 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
566 LineNumber, FunctionName, ModuleName, ComponentId,
567 "%s %8.8X%8.8X\n", AcpiGbl_FnExitStr,
568 ACPI_FORMAT_UINT64 (Value));
571 AcpiGbl_NestingLevel--;
574 ACPI_EXPORT_SYMBOL (AcpiUtValueExit)
577 /*******************************************************************************
579 * FUNCTION: AcpiUtPtrExit
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 * Ptr - Pointer to display
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 /* Check if enabled up-front for performance */
605 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
607 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
608 LineNumber, FunctionName, ModuleName, ComponentId,
609 "%s %p\n", AcpiGbl_FnExitStr, Ptr);
612 AcpiGbl_NestingLevel--;
618 /*******************************************************************************
620 * FUNCTION: AcpiUtDumpBuffer
622 * PARAMETERS: Buffer - Buffer to dump
623 * Count - Amount to dump, in bytes
624 * Display - BYTE, WORD, DWORD, or QWORD display
625 * Offset - Beginning buffer offset (display only)
629 * DESCRIPTION: Generic dump buffer in both hex and ascii.
631 ******************************************************************************/
648 AcpiOsPrintf ("Null Buffer Pointer in DumpBuffer!\n");
652 if ((Count < 4) || (Count & 0x01))
654 Display = DB_BYTE_DISPLAY;
657 /* Nasty little dump buffer routine! */
661 /* Print current offset */
663 AcpiOsPrintf ("%6.4X: ", (BaseOffset + i));
665 /* Print 16 hex chars */
671 /* Dump fill spaces */
673 AcpiOsPrintf ("%*s", ((Display * 2) + 1), " ");
680 case DB_BYTE_DISPLAY:
681 default: /* Default is BYTE display */
683 AcpiOsPrintf ("%02X ", Buffer[(ACPI_SIZE) i + j]);
687 case DB_WORD_DISPLAY:
689 ACPI_MOVE_16_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
690 AcpiOsPrintf ("%04X ", Temp32);
694 case DB_DWORD_DISPLAY:
696 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
697 AcpiOsPrintf ("%08X ", Temp32);
701 case DB_QWORD_DISPLAY:
703 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
704 AcpiOsPrintf ("%08X", Temp32);
706 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j + 4]);
707 AcpiOsPrintf ("%08X ", Temp32);
715 * Print the ASCII equivalent characters but watch out for the bad
716 * unprintable ones (printable chars are 0x20 through 0x7E)
719 for (j = 0; j < 16; j++)
727 BufChar = Buffer[(ACPI_SIZE) i + j];
728 if (ACPI_IS_PRINT (BufChar))
730 AcpiOsPrintf ("%c", BufChar);
738 /* Done with that line. */
748 /*******************************************************************************
750 * FUNCTION: AcpiUtDebugDumpBuffer
752 * PARAMETERS: Buffer - Buffer to dump
753 * Count - Amount to dump, in bytes
754 * Display - BYTE, WORD, DWORD, or QWORD display
755 * ComponentID - Caller's component ID
759 * DESCRIPTION: Generic dump buffer in both hex and ascii.
761 ******************************************************************************/
764 AcpiUtDebugDumpBuffer (
771 /* Only dump the buffer if tracing is enabled */
773 if (!((ACPI_LV_TABLES & AcpiDbgLevel) &&
774 (ComponentId & AcpiDbgLayer)))
779 AcpiUtDumpBuffer (Buffer, Count, Display, 0);