]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - sys/contrib/dev/acpica/components/utilities/utdebug.c
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / sys / contrib / dev / acpica / components / utilities / utdebug.c
1 /******************************************************************************
2  *
3  * Module Name: utdebug - Debug print/trace routines
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2013, Intel Corp.
9  * All rights reserved.
10  *
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.
25  *
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.
29  *
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.
42  */
43
44 #define __UTDEBUG_C__
45
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
48
49 #define _COMPONENT          ACPI_UTILITIES
50         ACPI_MODULE_NAME    ("utdebug")
51
52
53 #ifdef ACPI_DEBUG_OUTPUT
54
55 static ACPI_THREAD_ID       AcpiGbl_PrevThreadId = (ACPI_THREAD_ID) 0xFFFFFFFF;
56 static char                 *AcpiGbl_FnEntryStr = "----Entry";
57 static char                 *AcpiGbl_FnExitStr  = "----Exit-";
58
59 /* Local prototypes */
60
61 static const char *
62 AcpiUtTrimFunctionName (
63     const char              *FunctionName);
64
65
66 /*******************************************************************************
67  *
68  * FUNCTION:    AcpiUtInitStackPtrTrace
69  *
70  * PARAMETERS:  None
71  *
72  * RETURN:      None
73  *
74  * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
75  *
76  ******************************************************************************/
77
78 void
79 AcpiUtInitStackPtrTrace (
80     void)
81 {
82     ACPI_SIZE               CurrentSp;
83
84
85     AcpiGbl_EntryStackPointer = &CurrentSp;
86 }
87
88
89 /*******************************************************************************
90  *
91  * FUNCTION:    AcpiUtTrackStackPtr
92  *
93  * PARAMETERS:  None
94  *
95  * RETURN:      None
96  *
97  * DESCRIPTION: Save the current CPU stack pointer
98  *
99  ******************************************************************************/
100
101 void
102 AcpiUtTrackStackPtr (
103     void)
104 {
105     ACPI_SIZE               CurrentSp;
106
107
108     if (&CurrentSp < AcpiGbl_LowestStackPointer)
109     {
110         AcpiGbl_LowestStackPointer = &CurrentSp;
111     }
112
113     if (AcpiGbl_NestingLevel > AcpiGbl_DeepestNesting)
114     {
115         AcpiGbl_DeepestNesting = AcpiGbl_NestingLevel;
116     }
117 }
118
119
120 /*******************************************************************************
121  *
122  * FUNCTION:    AcpiUtTrimFunctionName
123  *
124  * PARAMETERS:  FunctionName        - Ascii string containing a procedure name
125  *
126  * RETURN:      Updated pointer to the function name
127  *
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.
131  *
132  ******************************************************************************/
133
134 static const char *
135 AcpiUtTrimFunctionName (
136     const char              *FunctionName)
137 {
138
139     /* All Function names are longer than 4 chars, check is safe */
140
141     if (*(ACPI_CAST_PTR (UINT32, FunctionName)) == ACPI_PREFIX_MIXED)
142     {
143         /* This is the case where the original source has not been modified */
144
145         return (FunctionName + 4);
146     }
147
148     if (*(ACPI_CAST_PTR (UINT32, FunctionName)) == ACPI_PREFIX_LOWER)
149     {
150         /* This is the case where the source has been 'linuxized' */
151
152         return (FunctionName + 5);
153     }
154
155     return (FunctionName);
156 }
157
158
159 /*******************************************************************************
160  *
161  * FUNCTION:    AcpiDebugPrint
162  *
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
170  *
171  * RETURN:      None
172  *
173  * DESCRIPTION: Print error message with prefix consisting of the module name,
174  *              line number, and component ID.
175  *
176  ******************************************************************************/
177
178 void  ACPI_INTERNAL_VAR_XFACE
179 AcpiDebugPrint (
180     UINT32                  RequestedDebugLevel,
181     UINT32                  LineNumber,
182     const char              *FunctionName,
183     const char              *ModuleName,
184     UINT32                  ComponentId,
185     const char              *Format,
186     ...)
187 {
188     ACPI_THREAD_ID          ThreadId;
189     va_list                 args;
190
191
192     /* Check if debug output enabled */
193
194     if (!ACPI_IS_DEBUG_ENABLED (RequestedDebugLevel, ComponentId))
195     {
196         return;
197     }
198
199     /*
200      * Thread tracking and context switch notification
201      */
202     ThreadId = AcpiOsGetThreadId ();
203     if (ThreadId != AcpiGbl_PrevThreadId)
204     {
205         if (ACPI_LV_THREADS & AcpiDbgLevel)
206         {
207             AcpiOsPrintf (
208                 "\n**** Context Switch from TID %u to TID %u ****\n\n",
209                 (UINT32) AcpiGbl_PrevThreadId, (UINT32) ThreadId);
210         }
211
212         AcpiGbl_PrevThreadId = ThreadId;
213     }
214
215     /*
216      * Display the module name, current line number, thread ID (if requested),
217      * current procedure nesting level, and the current procedure name
218      */
219     AcpiOsPrintf ("%9s-%04ld ", ModuleName, LineNumber);
220
221     if (ACPI_LV_THREADS & AcpiDbgLevel)
222     {
223         AcpiOsPrintf ("[%u] ", (UINT32) ThreadId);
224     }
225
226     AcpiOsPrintf ("[%02ld] %-22.22s: ",
227         AcpiGbl_NestingLevel, AcpiUtTrimFunctionName (FunctionName));
228
229     va_start (args, Format);
230     AcpiOsVprintf (Format, args);
231     va_end (args);
232 }
233
234 ACPI_EXPORT_SYMBOL (AcpiDebugPrint)
235
236
237 /*******************************************************************************
238  *
239  * FUNCTION:    AcpiDebugPrintRaw
240  *
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
248  *
249  * RETURN:      None
250  *
251  * DESCRIPTION: Print message with no headers. Has same interface as
252  *              DebugPrint so that the same macros can be used.
253  *
254  ******************************************************************************/
255
256 void  ACPI_INTERNAL_VAR_XFACE
257 AcpiDebugPrintRaw (
258     UINT32                  RequestedDebugLevel,
259     UINT32                  LineNumber,
260     const char              *FunctionName,
261     const char              *ModuleName,
262     UINT32                  ComponentId,
263     const char              *Format,
264     ...)
265 {
266     va_list                 args;
267
268
269     /* Check if debug output enabled */
270
271     if (!ACPI_IS_DEBUG_ENABLED (RequestedDebugLevel, ComponentId))
272     {
273         return;
274     }
275
276     va_start (args, Format);
277     AcpiOsVprintf (Format, args);
278     va_end (args);
279 }
280
281 ACPI_EXPORT_SYMBOL (AcpiDebugPrintRaw)
282
283
284 /*******************************************************************************
285  *
286  * FUNCTION:    AcpiUtTrace
287  *
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
292  *
293  * RETURN:      None
294  *
295  * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
296  *              set in DebugLevel
297  *
298  ******************************************************************************/
299
300 void
301 AcpiUtTrace (
302     UINT32                  LineNumber,
303     const char              *FunctionName,
304     const char              *ModuleName,
305     UINT32                  ComponentId)
306 {
307
308     AcpiGbl_NestingLevel++;
309     AcpiUtTrackStackPtr ();
310
311     /* Check if enabled up-front for performance */
312
313     if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
314     {
315         AcpiDebugPrint (ACPI_LV_FUNCTIONS,
316             LineNumber, FunctionName, ModuleName, ComponentId,
317             "%s\n", AcpiGbl_FnEntryStr);
318     }
319 }
320
321 ACPI_EXPORT_SYMBOL (AcpiUtTrace)
322
323
324 /*******************************************************************************
325  *
326  * FUNCTION:    AcpiUtTracePtr
327  *
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
333  *
334  * RETURN:      None
335  *
336  * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
337  *              set in DebugLevel
338  *
339  ******************************************************************************/
340
341 void
342 AcpiUtTracePtr (
343     UINT32                  LineNumber,
344     const char              *FunctionName,
345     const char              *ModuleName,
346     UINT32                  ComponentId,
347     void                    *Pointer)
348 {
349
350     AcpiGbl_NestingLevel++;
351     AcpiUtTrackStackPtr ();
352
353     /* Check if enabled up-front for performance */
354
355     if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
356     {
357         AcpiDebugPrint (ACPI_LV_FUNCTIONS,
358             LineNumber, FunctionName, ModuleName, ComponentId,
359             "%s %p\n", AcpiGbl_FnEntryStr, Pointer);
360     }
361 }
362
363
364 /*******************************************************************************
365  *
366  * FUNCTION:    AcpiUtTraceStr
367  *
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
373  *
374  * RETURN:      None
375  *
376  * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
377  *              set in DebugLevel
378  *
379  ******************************************************************************/
380
381 void
382 AcpiUtTraceStr (
383     UINT32                  LineNumber,
384     const char              *FunctionName,
385     const char              *ModuleName,
386     UINT32                  ComponentId,
387     char                    *String)
388 {
389
390     AcpiGbl_NestingLevel++;
391     AcpiUtTrackStackPtr ();
392
393     /* Check if enabled up-front for performance */
394
395     if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
396     {
397         AcpiDebugPrint (ACPI_LV_FUNCTIONS,
398             LineNumber, FunctionName, ModuleName, ComponentId,
399             "%s %s\n", AcpiGbl_FnEntryStr, String);
400     }
401 }
402
403
404 /*******************************************************************************
405  *
406  * FUNCTION:    AcpiUtTraceU32
407  *
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
413  *
414  * RETURN:      None
415  *
416  * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
417  *              set in DebugLevel
418  *
419  ******************************************************************************/
420
421 void
422 AcpiUtTraceU32 (
423     UINT32                  LineNumber,
424     const char              *FunctionName,
425     const char              *ModuleName,
426     UINT32                  ComponentId,
427     UINT32                  Integer)
428 {
429
430     AcpiGbl_NestingLevel++;
431     AcpiUtTrackStackPtr ();
432
433     /* Check if enabled up-front for performance */
434
435     if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
436     {
437         AcpiDebugPrint (ACPI_LV_FUNCTIONS,
438             LineNumber, FunctionName, ModuleName, ComponentId,
439             "%s %08X\n", AcpiGbl_FnEntryStr, Integer);
440     }
441 }
442
443
444 /*******************************************************************************
445  *
446  * FUNCTION:    AcpiUtExit
447  *
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
452  *
453  * RETURN:      None
454  *
455  * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
456  *              set in DebugLevel
457  *
458  ******************************************************************************/
459
460 void
461 AcpiUtExit (
462     UINT32                  LineNumber,
463     const char              *FunctionName,
464     const char              *ModuleName,
465     UINT32                  ComponentId)
466 {
467
468     /* Check if enabled up-front for performance */
469
470     if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
471     {
472         AcpiDebugPrint (ACPI_LV_FUNCTIONS,
473             LineNumber, FunctionName, ModuleName, ComponentId,
474             "%s\n", AcpiGbl_FnExitStr);
475     }
476
477     AcpiGbl_NestingLevel--;
478 }
479
480 ACPI_EXPORT_SYMBOL (AcpiUtExit)
481
482
483 /*******************************************************************************
484  *
485  * FUNCTION:    AcpiUtStatusExit
486  *
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
492  *
493  * RETURN:      None
494  *
495  * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
496  *              set in DebugLevel. Prints exit status also.
497  *
498  ******************************************************************************/
499
500 void
501 AcpiUtStatusExit (
502     UINT32                  LineNumber,
503     const char              *FunctionName,
504     const char              *ModuleName,
505     UINT32                  ComponentId,
506     ACPI_STATUS             Status)
507 {
508
509     /* Check if enabled up-front for performance */
510
511     if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
512     {
513         if (ACPI_SUCCESS (Status))
514         {
515             AcpiDebugPrint (ACPI_LV_FUNCTIONS,
516                 LineNumber, FunctionName, ModuleName, ComponentId,
517                 "%s %s\n", AcpiGbl_FnExitStr,
518                 AcpiFormatException (Status));
519         }
520         else
521         {
522             AcpiDebugPrint (ACPI_LV_FUNCTIONS,
523                 LineNumber, FunctionName, ModuleName, ComponentId,
524                 "%s ****Exception****: %s\n", AcpiGbl_FnExitStr,
525                 AcpiFormatException (Status));
526         }
527     }
528
529     AcpiGbl_NestingLevel--;
530 }
531
532 ACPI_EXPORT_SYMBOL (AcpiUtStatusExit)
533
534
535 /*******************************************************************************
536  *
537  * FUNCTION:    AcpiUtValueExit
538  *
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
544  *
545  * RETURN:      None
546  *
547  * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
548  *              set in DebugLevel. Prints exit value also.
549  *
550  ******************************************************************************/
551
552 void
553 AcpiUtValueExit (
554     UINT32                  LineNumber,
555     const char              *FunctionName,
556     const char              *ModuleName,
557     UINT32                  ComponentId,
558     UINT64                  Value)
559 {
560
561     /* Check if enabled up-front for performance */
562
563     if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
564     {
565         AcpiDebugPrint (ACPI_LV_FUNCTIONS,
566             LineNumber, FunctionName, ModuleName, ComponentId,
567             "%s %8.8X%8.8X\n", AcpiGbl_FnExitStr,
568             ACPI_FORMAT_UINT64 (Value));
569     }
570
571     AcpiGbl_NestingLevel--;
572 }
573
574 ACPI_EXPORT_SYMBOL (AcpiUtValueExit)
575
576
577 /*******************************************************************************
578  *
579  * FUNCTION:    AcpiUtPtrExit
580  *
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
586  *
587  * RETURN:      None
588  *
589  * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
590  *              set in DebugLevel. Prints exit value also.
591  *
592  ******************************************************************************/
593
594 void
595 AcpiUtPtrExit (
596     UINT32                  LineNumber,
597     const char              *FunctionName,
598     const char              *ModuleName,
599     UINT32                  ComponentId,
600     UINT8                   *Ptr)
601 {
602
603     /* Check if enabled up-front for performance */
604
605     if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
606     {
607         AcpiDebugPrint (ACPI_LV_FUNCTIONS,
608             LineNumber, FunctionName, ModuleName, ComponentId,
609             "%s %p\n", AcpiGbl_FnExitStr, Ptr);
610     }
611
612     AcpiGbl_NestingLevel--;
613 }
614
615 #endif