* Sync up to trunk head (r65481).
[reactos.git] / drivers / bus / acpi / acpica / utilities / utdebug.c
1 /******************************************************************************
2 *
3 * Module Name: utdebug - Debug print/trace routines
4 *
5 *****************************************************************************/
6
7 /******************************************************************************
8 *
9 * 1. Copyright Notice
10 *
11 * Some or all of this work - Copyright (c) 1999 - 2014, Intel Corp.
12 * All rights reserved.
13 *
14 * 2. License
15 *
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
20 *
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
27 *
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
36 *
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
39 *
40 * 3. Conditions
41 *
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
53 *
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
65 *
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
71 *
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
74 *
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
79 *
80 * 4. Disclaimer and Export Compliance
81 *
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
89 *
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
98 *
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
113 *
114 *****************************************************************************/
115
116 #define __UTDEBUG_C__
117 #define EXPORT_ACPI_INTERFACES
118
119 #include "acpi.h"
120 #include "accommon.h"
121
122 #define _COMPONENT ACPI_UTILITIES
123 ACPI_MODULE_NAME ("utdebug")
124
125
126 #ifdef ACPI_DEBUG_OUTPUT
127
128 static ACPI_THREAD_ID AcpiGbl_PrevThreadId = (ACPI_THREAD_ID) 0xFFFFFFFF;
129 static char *AcpiGbl_FnEntryStr = "----Entry";
130 static char *AcpiGbl_FnExitStr = "----Exit-";
131
132 /* Local prototypes */
133
134 static const char *
135 AcpiUtTrimFunctionName (
136 const char *FunctionName);
137
138
139 /*******************************************************************************
140 *
141 * FUNCTION: AcpiUtInitStackPtrTrace
142 *
143 * PARAMETERS: None
144 *
145 * RETURN: None
146 *
147 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
148 *
149 ******************************************************************************/
150
151 void
152 AcpiUtInitStackPtrTrace (
153 void)
154 {
155 ACPI_SIZE CurrentSp;
156
157
158 AcpiGbl_EntryStackPointer = &CurrentSp;
159 }
160
161
162 /*******************************************************************************
163 *
164 * FUNCTION: AcpiUtTrackStackPtr
165 *
166 * PARAMETERS: None
167 *
168 * RETURN: None
169 *
170 * DESCRIPTION: Save the current CPU stack pointer
171 *
172 ******************************************************************************/
173
174 void
175 AcpiUtTrackStackPtr (
176 void)
177 {
178 ACPI_SIZE CurrentSp;
179
180
181 if (&CurrentSp < AcpiGbl_LowestStackPointer)
182 {
183 AcpiGbl_LowestStackPointer = &CurrentSp;
184 }
185
186 if (AcpiGbl_NestingLevel > AcpiGbl_DeepestNesting)
187 {
188 AcpiGbl_DeepestNesting = AcpiGbl_NestingLevel;
189 }
190 }
191
192
193 /*******************************************************************************
194 *
195 * FUNCTION: AcpiUtTrimFunctionName
196 *
197 * PARAMETERS: FunctionName - Ascii string containing a procedure name
198 *
199 * RETURN: Updated pointer to the function name
200 *
201 * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
202 * This allows compiler macros such as __FUNCTION__ to be used
203 * with no change to the debug output.
204 *
205 ******************************************************************************/
206
207 static const char *
208 AcpiUtTrimFunctionName (
209 const char *FunctionName)
210 {
211
212 /* All Function names are longer than 4 chars, check is safe */
213
214 if (*(ACPI_CAST_PTR (UINT32, FunctionName)) == ACPI_PREFIX_MIXED)
215 {
216 /* This is the case where the original source has not been modified */
217
218 return (FunctionName + 4);
219 }
220
221 if (*(ACPI_CAST_PTR (UINT32, FunctionName)) == ACPI_PREFIX_LOWER)
222 {
223 /* This is the case where the source has been 'linuxized' */
224
225 return (FunctionName + 5);
226 }
227
228 return (FunctionName);
229 }
230
231
232 /*******************************************************************************
233 *
234 * FUNCTION: AcpiDebugPrint
235 *
236 * PARAMETERS: RequestedDebugLevel - Requested debug print level
237 * LineNumber - Caller's line number (for error output)
238 * FunctionName - Caller's procedure name
239 * ModuleName - Caller's module name
240 * ComponentId - Caller's component ID
241 * Format - Printf format field
242 * ... - Optional printf arguments
243 *
244 * RETURN: None
245 *
246 * DESCRIPTION: Print error message with prefix consisting of the module name,
247 * line number, and component ID.
248 *
249 ******************************************************************************/
250
251 void ACPI_INTERNAL_VAR_XFACE
252 AcpiDebugPrint (
253 UINT32 RequestedDebugLevel,
254 UINT32 LineNumber,
255 const char *FunctionName,
256 const char *ModuleName,
257 UINT32 ComponentId,
258 const char *Format,
259 ...)
260 {
261 ACPI_THREAD_ID ThreadId;
262 va_list args;
263
264
265 /* Check if debug output enabled */
266
267 if (!ACPI_IS_DEBUG_ENABLED (RequestedDebugLevel, ComponentId))
268 {
269 return;
270 }
271
272 /*
273 * Thread tracking and context switch notification
274 */
275 ThreadId = AcpiOsGetThreadId ();
276 if (ThreadId != AcpiGbl_PrevThreadId)
277 {
278 if (ACPI_LV_THREADS & AcpiDbgLevel)
279 {
280 AcpiOsPrintf (
281 "\n**** Context Switch from TID %u to TID %u ****\n\n",
282 (UINT32) AcpiGbl_PrevThreadId, (UINT32) ThreadId);
283 }
284
285 AcpiGbl_PrevThreadId = ThreadId;
286 AcpiGbl_NestingLevel = 0;
287 }
288
289 /*
290 * Display the module name, current line number, thread ID (if requested),
291 * current procedure nesting level, and the current procedure name
292 */
293 AcpiOsPrintf ("%9s-%04ld ", ModuleName, LineNumber);
294
295 #ifdef ACPI_APPLICATION
296 /*
297 * For AcpiExec/iASL only, emit the thread ID and nesting level.
298 * Note: nesting level is really only useful during a single-thread
299 * execution. Otherwise, multiple threads will keep resetting the
300 * level.
301 */
302 if (ACPI_LV_THREADS & AcpiDbgLevel)
303 {
304 AcpiOsPrintf ("[%u] ", (UINT32) ThreadId);
305 }
306
307 AcpiOsPrintf ("[%02ld] ", AcpiGbl_NestingLevel);
308 #endif
309
310 AcpiOsPrintf ("%-22.22s: ", AcpiUtTrimFunctionName (FunctionName));
311
312 va_start (args, Format);
313 AcpiOsVprintf (Format, args);
314 va_end (args);
315 }
316
317 ACPI_EXPORT_SYMBOL (AcpiDebugPrint)
318
319
320 /*******************************************************************************
321 *
322 * FUNCTION: AcpiDebugPrintRaw
323 *
324 * PARAMETERS: RequestedDebugLevel - Requested debug print level
325 * LineNumber - Caller's line number
326 * FunctionName - Caller's procedure name
327 * ModuleName - Caller's module name
328 * ComponentId - Caller's component ID
329 * Format - Printf format field
330 * ... - Optional printf arguments
331 *
332 * RETURN: None
333 *
334 * DESCRIPTION: Print message with no headers. Has same interface as
335 * DebugPrint so that the same macros can be used.
336 *
337 ******************************************************************************/
338
339 void ACPI_INTERNAL_VAR_XFACE
340 AcpiDebugPrintRaw (
341 UINT32 RequestedDebugLevel,
342 UINT32 LineNumber,
343 const char *FunctionName,
344 const char *ModuleName,
345 UINT32 ComponentId,
346 const char *Format,
347 ...)
348 {
349 va_list args;
350
351
352 /* Check if debug output enabled */
353
354 if (!ACPI_IS_DEBUG_ENABLED (RequestedDebugLevel, ComponentId))
355 {
356 return;
357 }
358
359 va_start (args, Format);
360 AcpiOsVprintf (Format, args);
361 va_end (args);
362 }
363
364 ACPI_EXPORT_SYMBOL (AcpiDebugPrintRaw)
365
366
367 /*******************************************************************************
368 *
369 * FUNCTION: AcpiUtTrace
370 *
371 * PARAMETERS: LineNumber - Caller's line number
372 * FunctionName - Caller's procedure name
373 * ModuleName - Caller's module name
374 * ComponentId - Caller's component ID
375 *
376 * RETURN: None
377 *
378 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
379 * set in DebugLevel
380 *
381 ******************************************************************************/
382
383 void
384 AcpiUtTrace (
385 UINT32 LineNumber,
386 const char *FunctionName,
387 const char *ModuleName,
388 UINT32 ComponentId)
389 {
390
391 AcpiGbl_NestingLevel++;
392 AcpiUtTrackStackPtr ();
393
394 /* Check if enabled up-front for performance */
395
396 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
397 {
398 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
399 LineNumber, FunctionName, ModuleName, ComponentId,
400 "%s\n", AcpiGbl_FnEntryStr);
401 }
402 }
403
404 ACPI_EXPORT_SYMBOL (AcpiUtTrace)
405
406
407 /*******************************************************************************
408 *
409 * FUNCTION: AcpiUtTracePtr
410 *
411 * PARAMETERS: LineNumber - Caller's line number
412 * FunctionName - Caller's procedure name
413 * ModuleName - Caller's module name
414 * ComponentId - Caller's component ID
415 * Pointer - Pointer to display
416 *
417 * RETURN: None
418 *
419 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
420 * set in DebugLevel
421 *
422 ******************************************************************************/
423
424 void
425 AcpiUtTracePtr (
426 UINT32 LineNumber,
427 const char *FunctionName,
428 const char *ModuleName,
429 UINT32 ComponentId,
430 void *Pointer)
431 {
432
433 AcpiGbl_NestingLevel++;
434 AcpiUtTrackStackPtr ();
435
436 /* Check if enabled up-front for performance */
437
438 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
439 {
440 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
441 LineNumber, FunctionName, ModuleName, ComponentId,
442 "%s %p\n", AcpiGbl_FnEntryStr, Pointer);
443 }
444 }
445
446
447 /*******************************************************************************
448 *
449 * FUNCTION: AcpiUtTraceStr
450 *
451 * PARAMETERS: LineNumber - Caller's line number
452 * FunctionName - Caller's procedure name
453 * ModuleName - Caller's module name
454 * ComponentId - Caller's component ID
455 * String - Additional string to display
456 *
457 * RETURN: None
458 *
459 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
460 * set in DebugLevel
461 *
462 ******************************************************************************/
463
464 void
465 AcpiUtTraceStr (
466 UINT32 LineNumber,
467 const char *FunctionName,
468 const char *ModuleName,
469 UINT32 ComponentId,
470 char *String)
471 {
472
473 AcpiGbl_NestingLevel++;
474 AcpiUtTrackStackPtr ();
475
476 /* Check if enabled up-front for performance */
477
478 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
479 {
480 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
481 LineNumber, FunctionName, ModuleName, ComponentId,
482 "%s %s\n", AcpiGbl_FnEntryStr, String);
483 }
484 }
485
486
487 /*******************************************************************************
488 *
489 * FUNCTION: AcpiUtTraceU32
490 *
491 * PARAMETERS: LineNumber - Caller's line number
492 * FunctionName - Caller's procedure name
493 * ModuleName - Caller's module name
494 * ComponentId - Caller's component ID
495 * Integer - Integer to display
496 *
497 * RETURN: None
498 *
499 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
500 * set in DebugLevel
501 *
502 ******************************************************************************/
503
504 void
505 AcpiUtTraceU32 (
506 UINT32 LineNumber,
507 const char *FunctionName,
508 const char *ModuleName,
509 UINT32 ComponentId,
510 UINT32 Integer)
511 {
512
513 AcpiGbl_NestingLevel++;
514 AcpiUtTrackStackPtr ();
515
516 /* Check if enabled up-front for performance */
517
518 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
519 {
520 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
521 LineNumber, FunctionName, ModuleName, ComponentId,
522 "%s %08X\n", AcpiGbl_FnEntryStr, Integer);
523 }
524 }
525
526
527 /*******************************************************************************
528 *
529 * FUNCTION: AcpiUtExit
530 *
531 * PARAMETERS: LineNumber - Caller's line number
532 * FunctionName - Caller's procedure name
533 * ModuleName - Caller's module name
534 * ComponentId - Caller's component ID
535 *
536 * RETURN: None
537 *
538 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
539 * set in DebugLevel
540 *
541 ******************************************************************************/
542
543 void
544 AcpiUtExit (
545 UINT32 LineNumber,
546 const char *FunctionName,
547 const char *ModuleName,
548 UINT32 ComponentId)
549 {
550
551 /* Check if enabled up-front for performance */
552
553 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
554 {
555 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
556 LineNumber, FunctionName, ModuleName, ComponentId,
557 "%s\n", AcpiGbl_FnExitStr);
558 }
559
560 if (AcpiGbl_NestingLevel)
561 {
562 AcpiGbl_NestingLevel--;
563 }
564 }
565
566 ACPI_EXPORT_SYMBOL (AcpiUtExit)
567
568
569 /*******************************************************************************
570 *
571 * FUNCTION: AcpiUtStatusExit
572 *
573 * PARAMETERS: LineNumber - Caller's line number
574 * FunctionName - Caller's procedure name
575 * ModuleName - Caller's module name
576 * ComponentId - Caller's component ID
577 * Status - Exit status code
578 *
579 * RETURN: None
580 *
581 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
582 * set in DebugLevel. Prints exit status also.
583 *
584 ******************************************************************************/
585
586 void
587 AcpiUtStatusExit (
588 UINT32 LineNumber,
589 const char *FunctionName,
590 const char *ModuleName,
591 UINT32 ComponentId,
592 ACPI_STATUS Status)
593 {
594
595 /* Check if enabled up-front for performance */
596
597 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
598 {
599 if (ACPI_SUCCESS (Status))
600 {
601 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
602 LineNumber, FunctionName, ModuleName, ComponentId,
603 "%s %s\n", AcpiGbl_FnExitStr,
604 AcpiFormatException (Status));
605 }
606 else
607 {
608 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
609 LineNumber, FunctionName, ModuleName, ComponentId,
610 "%s ****Exception****: %s\n", AcpiGbl_FnExitStr,
611 AcpiFormatException (Status));
612 }
613 }
614
615 if (AcpiGbl_NestingLevel)
616 {
617 AcpiGbl_NestingLevel--;
618 }
619 }
620
621 ACPI_EXPORT_SYMBOL (AcpiUtStatusExit)
622
623
624 /*******************************************************************************
625 *
626 * FUNCTION: AcpiUtValueExit
627 *
628 * PARAMETERS: LineNumber - Caller's line number
629 * FunctionName - Caller's procedure name
630 * ModuleName - Caller's module name
631 * ComponentId - Caller's component ID
632 * Value - Value to be printed with exit msg
633 *
634 * RETURN: None
635 *
636 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
637 * set in DebugLevel. Prints exit value also.
638 *
639 ******************************************************************************/
640
641 void
642 AcpiUtValueExit (
643 UINT32 LineNumber,
644 const char *FunctionName,
645 const char *ModuleName,
646 UINT32 ComponentId,
647 UINT64 Value)
648 {
649
650 /* Check if enabled up-front for performance */
651
652 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
653 {
654 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
655 LineNumber, FunctionName, ModuleName, ComponentId,
656 "%s %8.8X%8.8X\n", AcpiGbl_FnExitStr,
657 ACPI_FORMAT_UINT64 (Value));
658 }
659
660 if (AcpiGbl_NestingLevel)
661 {
662 AcpiGbl_NestingLevel--;
663 }
664 }
665
666 ACPI_EXPORT_SYMBOL (AcpiUtValueExit)
667
668
669 /*******************************************************************************
670 *
671 * FUNCTION: AcpiUtPtrExit
672 *
673 * PARAMETERS: LineNumber - Caller's line number
674 * FunctionName - Caller's procedure name
675 * ModuleName - Caller's module name
676 * ComponentId - Caller's component ID
677 * Ptr - Pointer to display
678 *
679 * RETURN: None
680 *
681 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
682 * set in DebugLevel. Prints exit value also.
683 *
684 ******************************************************************************/
685
686 void
687 AcpiUtPtrExit (
688 UINT32 LineNumber,
689 const char *FunctionName,
690 const char *ModuleName,
691 UINT32 ComponentId,
692 UINT8 *Ptr)
693 {
694
695 /* Check if enabled up-front for performance */
696
697 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
698 {
699 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
700 LineNumber, FunctionName, ModuleName, ComponentId,
701 "%s %p\n", AcpiGbl_FnExitStr, Ptr);
702 }
703
704 if (AcpiGbl_NestingLevel)
705 {
706 AcpiGbl_NestingLevel--;
707 }
708 }
709
710 #endif