dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / cmd / acpi / common / utdebug.c
blob6a298d175b3429eff0b05f98ff08bd539a14a78e
1 /******************************************************************************
3 * Module Name: utdebug - Debug print/trace routines
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2016, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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 "acpi.h"
47 #include "accommon.h"
48 #include "acinterp.h"
50 #define _COMPONENT ACPI_UTILITIES
51 ACPI_MODULE_NAME ("utdebug")
54 #ifdef ACPI_DEBUG_OUTPUT
56 static ACPI_THREAD_ID AcpiGbl_PreviousThreadId = (ACPI_THREAD_ID) 0xFFFFFFFF;
57 static const char *AcpiGbl_FunctionEntryPrefix = "----Entry";
58 static const char *AcpiGbl_FunctionExitPrefix = "----Exit-";
61 /*******************************************************************************
63 * FUNCTION: AcpiUtInitStackPtrTrace
65 * PARAMETERS: None
67 * RETURN: None
69 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
71 ******************************************************************************/
73 void
74 AcpiUtInitStackPtrTrace (
75 void)
77 ACPI_SIZE CurrentSp;
80 AcpiGbl_EntryStackPointer = &CurrentSp;
84 /*******************************************************************************
86 * FUNCTION: AcpiUtTrackStackPtr
88 * PARAMETERS: None
90 * RETURN: None
92 * DESCRIPTION: Save the current CPU stack pointer
94 ******************************************************************************/
96 void
97 AcpiUtTrackStackPtr (
98 void)
100 ACPI_SIZE CurrentSp;
103 if (&CurrentSp < AcpiGbl_LowestStackPointer)
105 AcpiGbl_LowestStackPointer = &CurrentSp;
108 if (AcpiGbl_NestingLevel > AcpiGbl_DeepestNesting)
110 AcpiGbl_DeepestNesting = AcpiGbl_NestingLevel;
115 /*******************************************************************************
117 * FUNCTION: AcpiUtTrimFunctionName
119 * PARAMETERS: FunctionName - Ascii string containing a procedure name
121 * RETURN: Updated pointer to the function name
123 * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
124 * This allows compiler macros such as __FUNCTION__ to be used
125 * with no change to the debug output.
127 ******************************************************************************/
129 static const char *
130 AcpiUtTrimFunctionName (
131 const char *FunctionName)
134 /* All Function names are longer than 4 chars, check is safe */
136 if (*(ACPI_CAST_PTR (UINT32, FunctionName)) == ACPI_PREFIX_MIXED)
138 /* This is the case where the original source has not been modified */
140 return (FunctionName + 4);
143 if (*(ACPI_CAST_PTR (UINT32, FunctionName)) == ACPI_PREFIX_LOWER)
145 /* This is the case where the source has been 'linuxized' */
147 return (FunctionName + 5);
150 return (FunctionName);
154 /*******************************************************************************
156 * FUNCTION: AcpiDebugPrint
158 * PARAMETERS: RequestedDebugLevel - Requested debug print level
159 * LineNumber - Caller's line number (for error output)
160 * FunctionName - Caller's procedure name
161 * ModuleName - Caller's module name
162 * ComponentId - Caller's component ID
163 * Format - Printf format field
164 * ... - Optional printf arguments
166 * RETURN: None
168 * DESCRIPTION: Print error message with prefix consisting of the module name,
169 * line number, and component ID.
171 ******************************************************************************/
173 void ACPI_INTERNAL_VAR_XFACE
174 AcpiDebugPrint (
175 UINT32 RequestedDebugLevel,
176 UINT32 LineNumber,
177 const char *FunctionName,
178 const char *ModuleName,
179 UINT32 ComponentId,
180 const char *Format,
181 ...)
183 ACPI_THREAD_ID ThreadId;
184 va_list args;
187 /* Check if debug output enabled */
189 if (!ACPI_IS_DEBUG_ENABLED (RequestedDebugLevel, ComponentId))
191 return;
195 * Thread tracking and context switch notification
197 ThreadId = AcpiOsGetThreadId ();
198 if (ThreadId != AcpiGbl_PreviousThreadId)
200 if (ACPI_LV_THREADS & AcpiDbgLevel)
202 AcpiOsPrintf (
203 "\n**** Context Switch from TID %u to TID %u ****\n\n",
204 (UINT32) AcpiGbl_PreviousThreadId, (UINT32) ThreadId);
207 AcpiGbl_PreviousThreadId = ThreadId;
208 AcpiGbl_NestingLevel = 0;
212 * Display the module name, current line number, thread ID (if requested),
213 * current procedure nesting level, and the current procedure name
215 AcpiOsPrintf ("%9s-%04ld ", ModuleName, LineNumber);
217 #ifdef ACPI_APPLICATION
219 * For AcpiExec/iASL only, emit the thread ID and nesting level.
220 * Note: nesting level is really only useful during a single-thread
221 * execution. Otherwise, multiple threads will keep resetting the
222 * level.
224 if (ACPI_LV_THREADS & AcpiDbgLevel)
226 AcpiOsPrintf ("[%u] ", (UINT32) ThreadId);
229 AcpiOsPrintf ("[%02ld] ", AcpiGbl_NestingLevel);
230 #endif
232 AcpiOsPrintf ("%-22.22s: ", AcpiUtTrimFunctionName (FunctionName));
234 va_start (args, Format);
235 AcpiOsVprintf (Format, args);
236 va_end (args);
239 ACPI_EXPORT_SYMBOL (AcpiDebugPrint)
242 /*******************************************************************************
244 * FUNCTION: AcpiDebugPrintRaw
246 * PARAMETERS: RequestedDebugLevel - Requested debug print level
247 * LineNumber - Caller's line number
248 * FunctionName - Caller's procedure name
249 * ModuleName - Caller's module name
250 * ComponentId - Caller's component ID
251 * Format - Printf format field
252 * ... - Optional printf arguments
254 * RETURN: None
256 * DESCRIPTION: Print message with no headers. Has same interface as
257 * DebugPrint so that the same macros can be used.
259 ******************************************************************************/
261 void ACPI_INTERNAL_VAR_XFACE
262 AcpiDebugPrintRaw (
263 UINT32 RequestedDebugLevel,
264 UINT32 LineNumber,
265 const char *FunctionName,
266 const char *ModuleName,
267 UINT32 ComponentId,
268 const char *Format,
269 ...)
271 va_list args;
274 /* Check if debug output enabled */
276 if (!ACPI_IS_DEBUG_ENABLED (RequestedDebugLevel, ComponentId))
278 return;
281 va_start (args, Format);
282 AcpiOsVprintf (Format, args);
283 va_end (args);
286 ACPI_EXPORT_SYMBOL (AcpiDebugPrintRaw)
289 /*******************************************************************************
291 * FUNCTION: AcpiUtTrace
293 * PARAMETERS: LineNumber - Caller's line number
294 * FunctionName - Caller's procedure name
295 * ModuleName - Caller's module name
296 * ComponentId - Caller's component ID
298 * RETURN: None
300 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
301 * set in DebugLevel
303 ******************************************************************************/
305 void
306 AcpiUtTrace (
307 UINT32 LineNumber,
308 const char *FunctionName,
309 const char *ModuleName,
310 UINT32 ComponentId)
313 AcpiGbl_NestingLevel++;
314 AcpiUtTrackStackPtr ();
316 /* Check if enabled up-front for performance */
318 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
320 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
321 LineNumber, FunctionName, ModuleName, ComponentId,
322 "%s\n", AcpiGbl_FunctionEntryPrefix);
326 ACPI_EXPORT_SYMBOL (AcpiUtTrace)
329 /*******************************************************************************
331 * FUNCTION: AcpiUtTracePtr
333 * PARAMETERS: LineNumber - Caller's line number
334 * FunctionName - Caller's procedure name
335 * ModuleName - Caller's module name
336 * ComponentId - Caller's component ID
337 * Pointer - Pointer to display
339 * RETURN: None
341 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
342 * set in DebugLevel
344 ******************************************************************************/
346 void
347 AcpiUtTracePtr (
348 UINT32 LineNumber,
349 const char *FunctionName,
350 const char *ModuleName,
351 UINT32 ComponentId,
352 const void *Pointer)
355 AcpiGbl_NestingLevel++;
356 AcpiUtTrackStackPtr ();
358 /* Check if enabled up-front for performance */
360 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
362 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
363 LineNumber, FunctionName, ModuleName, ComponentId,
364 "%s %p\n", AcpiGbl_FunctionEntryPrefix, Pointer);
369 /*******************************************************************************
371 * FUNCTION: AcpiUtTraceStr
373 * PARAMETERS: LineNumber - Caller's line number
374 * FunctionName - Caller's procedure name
375 * ModuleName - Caller's module name
376 * ComponentId - Caller's component ID
377 * String - Additional string to display
379 * RETURN: None
381 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
382 * set in DebugLevel
384 ******************************************************************************/
386 void
387 AcpiUtTraceStr (
388 UINT32 LineNumber,
389 const char *FunctionName,
390 const char *ModuleName,
391 UINT32 ComponentId,
392 const char *String)
395 AcpiGbl_NestingLevel++;
396 AcpiUtTrackStackPtr ();
398 /* Check if enabled up-front for performance */
400 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
402 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
403 LineNumber, FunctionName, ModuleName, ComponentId,
404 "%s %s\n", AcpiGbl_FunctionEntryPrefix, String);
409 /*******************************************************************************
411 * FUNCTION: AcpiUtTraceU32
413 * PARAMETERS: LineNumber - Caller's line number
414 * FunctionName - Caller's procedure name
415 * ModuleName - Caller's module name
416 * ComponentId - Caller's component ID
417 * Integer - Integer to display
419 * RETURN: None
421 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
422 * set in DebugLevel
424 ******************************************************************************/
426 void
427 AcpiUtTraceU32 (
428 UINT32 LineNumber,
429 const char *FunctionName,
430 const char *ModuleName,
431 UINT32 ComponentId,
432 UINT32 Integer)
435 AcpiGbl_NestingLevel++;
436 AcpiUtTrackStackPtr ();
438 /* Check if enabled up-front for performance */
440 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
442 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
443 LineNumber, FunctionName, ModuleName, ComponentId,
444 "%s %08X\n", AcpiGbl_FunctionEntryPrefix, Integer);
449 /*******************************************************************************
451 * FUNCTION: AcpiUtExit
453 * PARAMETERS: LineNumber - Caller's line number
454 * FunctionName - Caller's procedure name
455 * ModuleName - Caller's module name
456 * ComponentId - Caller's component ID
458 * RETURN: None
460 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
461 * set in DebugLevel
463 ******************************************************************************/
465 void
466 AcpiUtExit (
467 UINT32 LineNumber,
468 const char *FunctionName,
469 const char *ModuleName,
470 UINT32 ComponentId)
473 /* Check if enabled up-front for performance */
475 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
477 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
478 LineNumber, FunctionName, ModuleName, ComponentId,
479 "%s\n", AcpiGbl_FunctionExitPrefix);
482 if (AcpiGbl_NestingLevel)
484 AcpiGbl_NestingLevel--;
488 ACPI_EXPORT_SYMBOL (AcpiUtExit)
491 /*******************************************************************************
493 * FUNCTION: AcpiUtStatusExit
495 * PARAMETERS: LineNumber - Caller's line number
496 * FunctionName - Caller's procedure name
497 * ModuleName - Caller's module name
498 * ComponentId - Caller's component ID
499 * Status - Exit status code
501 * RETURN: None
503 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
504 * set in DebugLevel. Prints exit status also.
506 ******************************************************************************/
508 void
509 AcpiUtStatusExit (
510 UINT32 LineNumber,
511 const char *FunctionName,
512 const char *ModuleName,
513 UINT32 ComponentId,
514 ACPI_STATUS Status)
517 /* Check if enabled up-front for performance */
519 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
521 if (ACPI_SUCCESS (Status))
523 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
524 LineNumber, FunctionName, ModuleName, ComponentId,
525 "%s %s\n", AcpiGbl_FunctionExitPrefix,
526 AcpiFormatException (Status));
528 else
530 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
531 LineNumber, FunctionName, ModuleName, ComponentId,
532 "%s ****Exception****: %s\n", AcpiGbl_FunctionExitPrefix,
533 AcpiFormatException (Status));
537 if (AcpiGbl_NestingLevel)
539 AcpiGbl_NestingLevel--;
543 ACPI_EXPORT_SYMBOL (AcpiUtStatusExit)
546 /*******************************************************************************
548 * FUNCTION: AcpiUtValueExit
550 * PARAMETERS: LineNumber - Caller's line number
551 * FunctionName - Caller's procedure name
552 * ModuleName - Caller's module name
553 * ComponentId - Caller's component ID
554 * Value - Value to be printed with exit msg
556 * RETURN: None
558 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
559 * set in DebugLevel. Prints exit value also.
561 ******************************************************************************/
563 void
564 AcpiUtValueExit (
565 UINT32 LineNumber,
566 const char *FunctionName,
567 const char *ModuleName,
568 UINT32 ComponentId,
569 UINT64 Value)
572 /* Check if enabled up-front for performance */
574 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
576 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
577 LineNumber, FunctionName, ModuleName, ComponentId,
578 "%s %8.8X%8.8X\n", AcpiGbl_FunctionExitPrefix,
579 ACPI_FORMAT_UINT64 (Value));
582 if (AcpiGbl_NestingLevel)
584 AcpiGbl_NestingLevel--;
588 ACPI_EXPORT_SYMBOL (AcpiUtValueExit)
591 /*******************************************************************************
593 * FUNCTION: AcpiUtPtrExit
595 * PARAMETERS: LineNumber - Caller's line number
596 * FunctionName - Caller's procedure name
597 * ModuleName - Caller's module name
598 * ComponentId - Caller's component ID
599 * Ptr - Pointer to display
601 * RETURN: None
603 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
604 * set in DebugLevel. Prints exit value also.
606 ******************************************************************************/
608 void
609 AcpiUtPtrExit (
610 UINT32 LineNumber,
611 const char *FunctionName,
612 const char *ModuleName,
613 UINT32 ComponentId,
614 UINT8 *Ptr)
617 /* Check if enabled up-front for performance */
619 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
621 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
622 LineNumber, FunctionName, ModuleName, ComponentId,
623 "%s %p\n", AcpiGbl_FunctionExitPrefix, Ptr);
626 if (AcpiGbl_NestingLevel)
628 AcpiGbl_NestingLevel--;
633 /*******************************************************************************
635 * FUNCTION: AcpiUtStrExit
637 * PARAMETERS: LineNumber - Caller's line number
638 * FunctionName - Caller's procedure name
639 * ModuleName - Caller's module name
640 * ComponentId - Caller's component ID
641 * String - String to display
643 * RETURN: None
645 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
646 * set in DebugLevel. Prints exit value also.
648 ******************************************************************************/
650 void
651 AcpiUtStrExit (
652 UINT32 LineNumber,
653 const char *FunctionName,
654 const char *ModuleName,
655 UINT32 ComponentId,
656 const char *String)
659 /* Check if enabled up-front for performance */
661 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
663 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
664 LineNumber, FunctionName, ModuleName, ComponentId,
665 "%s %s\n", AcpiGbl_FunctionExitPrefix, String);
668 if (AcpiGbl_NestingLevel)
670 AcpiGbl_NestingLevel--;
675 /*******************************************************************************
677 * FUNCTION: AcpiTracePoint
679 * PARAMETERS: Type - Trace event type
680 * Begin - TRUE if before execution
681 * Aml - Executed AML address
682 * Pathname - Object path
683 * Pointer - Pointer to the related object
685 * RETURN: None
687 * DESCRIPTION: Interpreter execution trace.
689 ******************************************************************************/
691 void
692 AcpiTracePoint (
693 ACPI_TRACE_EVENT_TYPE Type,
694 BOOLEAN Begin,
695 UINT8 *Aml,
696 char *Pathname)
699 ACPI_FUNCTION_ENTRY ();
701 AcpiExTracePoint (Type, Begin, Aml, Pathname);
703 #ifdef ACPI_USE_SYSTEM_TRACER
704 AcpiOsTracePoint (Type, Begin, Aml, Pathname);
705 #endif
708 ACPI_EXPORT_SYMBOL (AcpiTracePoint)
710 #endif
713 #ifdef ACPI_APPLICATION
714 /*******************************************************************************
716 * FUNCTION: AcpiLogError
718 * PARAMETERS: Format - Printf format field
719 * ... - Optional printf arguments
721 * RETURN: None
723 * DESCRIPTION: Print error message to the console, used by applications.
725 ******************************************************************************/
727 void ACPI_INTERNAL_VAR_XFACE
728 AcpiLogError (
729 const char *Format,
730 ...)
732 va_list Args;
734 va_start (Args, Format);
735 (void) AcpiUtFileVprintf (ACPI_FILE_ERR, Format, Args);
736 va_end (Args);
739 ACPI_EXPORT_SYMBOL (AcpiLogError)
740 #endif