1 /******************************************************************************
3 * Module Name: utdebug - Debug print routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, 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;
193 * Stay silent if the debug level or component ID is disabled
195 if (!(RequestedDebugLevel & AcpiDbgLevel) ||
196 !(ComponentId & AcpiDbgLayer))
202 * Thread tracking and context switch notification
204 ThreadId = AcpiOsGetThreadId ();
205 if (ThreadId != AcpiGbl_PrevThreadId)
207 if (ACPI_LV_THREADS & AcpiDbgLevel)
210 "\n**** Context Switch from TID %u to TID %u ****\n\n",
211 (UINT32) AcpiGbl_PrevThreadId, (UINT32) ThreadId);
214 AcpiGbl_PrevThreadId = ThreadId;
218 * Display the module name, current line number, thread ID (if requested),
219 * current procedure nesting level, and the current procedure name
221 AcpiOsPrintf ("%8s-%04ld ", ModuleName, LineNumber);
223 if (ACPI_LV_THREADS & AcpiDbgLevel)
225 AcpiOsPrintf ("[%u] ", (UINT32) ThreadId);
228 AcpiOsPrintf ("[%02ld] %-22.22s: ",
229 AcpiGbl_NestingLevel, AcpiUtTrimFunctionName (FunctionName));
231 va_start (args, Format);
232 AcpiOsVprintf (Format, args);
236 ACPI_EXPORT_SYMBOL (AcpiDebugPrint)
239 /*******************************************************************************
241 * FUNCTION: AcpiDebugPrintRaw
243 * PARAMETERS: RequestedDebugLevel - Requested debug print level
244 * LineNumber - Caller's line number
245 * FunctionName - Caller's procedure name
246 * ModuleName - Caller's module name
247 * ComponentId - Caller's component ID
248 * Format - Printf format field
249 * ... - Optional printf arguments
253 * DESCRIPTION: Print message with no headers. Has same interface as
254 * DebugPrint so that the same macros can be used.
256 ******************************************************************************/
258 void ACPI_INTERNAL_VAR_XFACE
260 UINT32 RequestedDebugLevel,
262 const char *FunctionName,
263 const char *ModuleName,
271 if (!(RequestedDebugLevel & AcpiDbgLevel) ||
272 !(ComponentId & AcpiDbgLayer))
277 va_start (args, Format);
278 AcpiOsVprintf (Format, args);
282 ACPI_EXPORT_SYMBOL (AcpiDebugPrintRaw)
285 /*******************************************************************************
287 * FUNCTION: AcpiUtTrace
289 * PARAMETERS: LineNumber - Caller's line number
290 * FunctionName - Caller's procedure name
291 * ModuleName - Caller's module name
292 * ComponentId - Caller's component ID
296 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
299 ******************************************************************************/
304 const char *FunctionName,
305 const char *ModuleName,
309 AcpiGbl_NestingLevel++;
310 AcpiUtTrackStackPtr ();
312 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
313 LineNumber, FunctionName, ModuleName, ComponentId,
314 "%s\n", AcpiGbl_FnEntryStr);
317 ACPI_EXPORT_SYMBOL (AcpiUtTrace)
320 /*******************************************************************************
322 * FUNCTION: AcpiUtTracePtr
324 * PARAMETERS: LineNumber - Caller's line number
325 * FunctionName - Caller's procedure name
326 * ModuleName - Caller's module name
327 * ComponentId - Caller's component ID
328 * Pointer - Pointer to display
332 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
335 ******************************************************************************/
340 const char *FunctionName,
341 const char *ModuleName,
345 AcpiGbl_NestingLevel++;
346 AcpiUtTrackStackPtr ();
348 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
349 LineNumber, FunctionName, ModuleName, ComponentId,
350 "%s %p\n", AcpiGbl_FnEntryStr, Pointer);
354 /*******************************************************************************
356 * FUNCTION: AcpiUtTraceStr
358 * PARAMETERS: LineNumber - Caller's line number
359 * FunctionName - Caller's procedure name
360 * ModuleName - Caller's module name
361 * ComponentId - Caller's component ID
362 * String - Additional string to display
366 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
369 ******************************************************************************/
374 const char *FunctionName,
375 const char *ModuleName,
380 AcpiGbl_NestingLevel++;
381 AcpiUtTrackStackPtr ();
383 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
384 LineNumber, FunctionName, ModuleName, ComponentId,
385 "%s %s\n", AcpiGbl_FnEntryStr, String);
389 /*******************************************************************************
391 * FUNCTION: AcpiUtTraceU32
393 * PARAMETERS: LineNumber - Caller's line number
394 * FunctionName - Caller's procedure name
395 * ModuleName - Caller's module name
396 * ComponentId - Caller's component ID
397 * Integer - Integer to display
401 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
404 ******************************************************************************/
409 const char *FunctionName,
410 const char *ModuleName,
415 AcpiGbl_NestingLevel++;
416 AcpiUtTrackStackPtr ();
418 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
419 LineNumber, FunctionName, ModuleName, ComponentId,
420 "%s %08X\n", AcpiGbl_FnEntryStr, Integer);
424 /*******************************************************************************
426 * FUNCTION: AcpiUtExit
428 * PARAMETERS: LineNumber - Caller's line number
429 * FunctionName - Caller's procedure name
430 * ModuleName - Caller's module name
431 * ComponentId - Caller's component ID
435 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
438 ******************************************************************************/
443 const char *FunctionName,
444 const char *ModuleName,
448 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
449 LineNumber, FunctionName, ModuleName, ComponentId,
450 "%s\n", AcpiGbl_FnExitStr);
452 AcpiGbl_NestingLevel--;
455 ACPI_EXPORT_SYMBOL (AcpiUtExit)
458 /*******************************************************************************
460 * FUNCTION: AcpiUtStatusExit
462 * PARAMETERS: LineNumber - Caller's line number
463 * FunctionName - Caller's procedure name
464 * ModuleName - Caller's module name
465 * ComponentId - Caller's component ID
466 * Status - Exit status code
470 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
471 * set in DebugLevel. Prints exit status also.
473 ******************************************************************************/
478 const char *FunctionName,
479 const char *ModuleName,
484 if (ACPI_SUCCESS (Status))
486 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
487 LineNumber, FunctionName, ModuleName, ComponentId,
488 "%s %s\n", AcpiGbl_FnExitStr,
489 AcpiFormatException (Status));
493 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
494 LineNumber, FunctionName, ModuleName, ComponentId,
495 "%s ****Exception****: %s\n", AcpiGbl_FnExitStr,
496 AcpiFormatException (Status));
499 AcpiGbl_NestingLevel--;
502 ACPI_EXPORT_SYMBOL (AcpiUtStatusExit)
505 /*******************************************************************************
507 * FUNCTION: AcpiUtValueExit
509 * PARAMETERS: LineNumber - Caller's line number
510 * FunctionName - Caller's procedure name
511 * ModuleName - Caller's module name
512 * ComponentId - Caller's component ID
513 * Value - Value to be printed with exit msg
517 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
518 * set in DebugLevel. Prints exit value also.
520 ******************************************************************************/
525 const char *FunctionName,
526 const char *ModuleName,
531 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
532 LineNumber, FunctionName, ModuleName, ComponentId,
533 "%s %8.8X%8.8X\n", AcpiGbl_FnExitStr,
534 ACPI_FORMAT_UINT64 (Value));
536 AcpiGbl_NestingLevel--;
539 ACPI_EXPORT_SYMBOL (AcpiUtValueExit)
542 /*******************************************************************************
544 * FUNCTION: AcpiUtPtrExit
546 * PARAMETERS: LineNumber - Caller's line number
547 * FunctionName - Caller's procedure name
548 * ModuleName - Caller's module name
549 * ComponentId - Caller's component ID
550 * Ptr - Pointer to display
554 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
555 * set in DebugLevel. Prints exit value also.
557 ******************************************************************************/
562 const char *FunctionName,
563 const char *ModuleName,
568 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
569 LineNumber, FunctionName, ModuleName, ComponentId,
570 "%s %p\n", AcpiGbl_FnExitStr, Ptr);
572 AcpiGbl_NestingLevel--;
578 /*******************************************************************************
580 * FUNCTION: AcpiUtDumpBuffer
582 * PARAMETERS: Buffer - Buffer to dump
583 * Count - Amount to dump, in bytes
584 * Display - BYTE, WORD, DWORD, or QWORD display
585 * ComponentID - Caller's component ID
589 * DESCRIPTION: Generic dump buffer in both hex and ascii.
591 ******************************************************************************/
607 AcpiOsPrintf ("Null Buffer Pointer in DumpBuffer!\n");
611 if ((Count < 4) || (Count & 0x01))
613 Display = DB_BYTE_DISPLAY;
616 /* Nasty little dump buffer routine! */
620 /* Print current offset */
622 AcpiOsPrintf ("%6.4X: ", i);
624 /* Print 16 hex chars */
630 /* Dump fill spaces */
632 AcpiOsPrintf ("%*s", ((Display * 2) + 1), " ");
639 case DB_BYTE_DISPLAY:
640 default: /* Default is BYTE display */
642 AcpiOsPrintf ("%02X ", Buffer[(ACPI_SIZE) i + j]);
646 case DB_WORD_DISPLAY:
648 ACPI_MOVE_16_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
649 AcpiOsPrintf ("%04X ", Temp32);
653 case DB_DWORD_DISPLAY:
655 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
656 AcpiOsPrintf ("%08X ", Temp32);
660 case DB_QWORD_DISPLAY:
662 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]);
663 AcpiOsPrintf ("%08X", Temp32);
665 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j + 4]);
666 AcpiOsPrintf ("%08X ", Temp32);
674 * Print the ASCII equivalent characters but watch out for the bad
675 * unprintable ones (printable chars are 0x20 through 0x7E)
678 for (j = 0; j < 16; j++)
686 BufChar = Buffer[(ACPI_SIZE) i + j];
687 if (ACPI_IS_PRINT (BufChar))
689 AcpiOsPrintf ("%c", BufChar);
697 /* Done with that line. */
707 /*******************************************************************************
709 * FUNCTION: AcpiUtDumpBuffer
711 * PARAMETERS: Buffer - Buffer to dump
712 * Count - Amount to dump, in bytes
713 * Display - BYTE, WORD, DWORD, or QWORD display
714 * ComponentID - Caller's component ID
718 * DESCRIPTION: Generic dump buffer in both hex and ascii.
720 ******************************************************************************/
730 /* Only dump the buffer if tracing is enabled */
732 if (!((ACPI_LV_TABLES & AcpiDbgLevel) &&
733 (ComponentId & AcpiDbgLayer)))
738 AcpiUtDumpBuffer2 (Buffer, Count, Display);