1 /******************************************************************************
2 *
3 * Module Name: utdebug - Debug print/trace routines
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2014, 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 EXPORT_ACPI_INTERFACES
45
46 #include "acpi.h"
47 #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
AcpiUtInitStackPtrTrace(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
AcpiUtTrackStackPtr(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 *
AcpiUtTrimFunctionName(const char * FunctionName)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
AcpiDebugPrint(UINT32 RequestedDebugLevel,UINT32 LineNumber,const char * FunctionName,const char * ModuleName,UINT32 ComponentId,const char * Format,...)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 AcpiGbl_NestingLevel = 0;
214 }
215
216 /*
217 * Display the module name, current line number, thread ID (if requested),
218 * current procedure nesting level, and the current procedure name
219 */
220 AcpiOsPrintf ("%9s-%04ld ", ModuleName, LineNumber);
221
222 #ifdef ACPI_APPLICATION
223 /*
224 * For AcpiExec/iASL only, emit the thread ID and nesting level.
225 * Note: nesting level is really only useful during a single-thread
226 * execution. Otherwise, multiple threads will keep resetting the
227 * level.
228 */
229 if (ACPI_LV_THREADS & AcpiDbgLevel)
230 {
231 AcpiOsPrintf ("[%u] ", (UINT32) ThreadId);
232 }
233
234 AcpiOsPrintf ("[%02ld] ", AcpiGbl_NestingLevel);
235 #endif
236
237 AcpiOsPrintf ("%-22.22s: ", AcpiUtTrimFunctionName (FunctionName));
238
239 va_start (args, Format);
240 AcpiOsVprintf (Format, args);
241 va_end (args);
242 }
243
ACPI_EXPORT_SYMBOL(AcpiDebugPrint)244 ACPI_EXPORT_SYMBOL (AcpiDebugPrint)
245
246
247 /*******************************************************************************
248 *
249 * FUNCTION: AcpiDebugPrintRaw
250 *
251 * PARAMETERS: RequestedDebugLevel - Requested debug print level
252 * LineNumber - Caller's line number
253 * FunctionName - Caller's procedure name
254 * ModuleName - Caller's module name
255 * ComponentId - Caller's component ID
256 * Format - Printf format field
257 * ... - Optional printf arguments
258 *
259 * RETURN: None
260 *
261 * DESCRIPTION: Print message with no headers. Has same interface as
262 * DebugPrint so that the same macros can be used.
263 *
264 ******************************************************************************/
265
266 void ACPI_INTERNAL_VAR_XFACE
267 AcpiDebugPrintRaw (
268 UINT32 RequestedDebugLevel,
269 UINT32 LineNumber,
270 const char *FunctionName,
271 const char *ModuleName,
272 UINT32 ComponentId,
273 const char *Format,
274 ...)
275 {
276 va_list args;
277
278
279 /* Check if debug output enabled */
280
281 if (!ACPI_IS_DEBUG_ENABLED (RequestedDebugLevel, ComponentId))
282 {
283 return;
284 }
285
286 va_start (args, Format);
287 AcpiOsVprintf (Format, args);
288 va_end (args);
289 }
290
ACPI_EXPORT_SYMBOL(AcpiDebugPrintRaw)291 ACPI_EXPORT_SYMBOL (AcpiDebugPrintRaw)
292
293
294 /*******************************************************************************
295 *
296 * FUNCTION: AcpiUtTrace
297 *
298 * PARAMETERS: LineNumber - Caller's line number
299 * FunctionName - Caller's procedure name
300 * ModuleName - Caller's module name
301 * ComponentId - Caller's component ID
302 *
303 * RETURN: None
304 *
305 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
306 * set in DebugLevel
307 *
308 ******************************************************************************/
309
310 void
311 AcpiUtTrace (
312 UINT32 LineNumber,
313 const char *FunctionName,
314 const char *ModuleName,
315 UINT32 ComponentId)
316 {
317
318 AcpiGbl_NestingLevel++;
319 AcpiUtTrackStackPtr ();
320
321 /* Check if enabled up-front for performance */
322
323 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
324 {
325 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
326 LineNumber, FunctionName, ModuleName, ComponentId,
327 "%s\n", AcpiGbl_FnEntryStr);
328 }
329 }
330
ACPI_EXPORT_SYMBOL(AcpiUtTrace)331 ACPI_EXPORT_SYMBOL (AcpiUtTrace)
332
333
334 /*******************************************************************************
335 *
336 * FUNCTION: AcpiUtTracePtr
337 *
338 * PARAMETERS: LineNumber - Caller's line number
339 * FunctionName - Caller's procedure name
340 * ModuleName - Caller's module name
341 * ComponentId - Caller's component ID
342 * Pointer - Pointer to display
343 *
344 * RETURN: None
345 *
346 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
347 * set in DebugLevel
348 *
349 ******************************************************************************/
350
351 void
352 AcpiUtTracePtr (
353 UINT32 LineNumber,
354 const char *FunctionName,
355 const char *ModuleName,
356 UINT32 ComponentId,
357 void *Pointer)
358 {
359
360 AcpiGbl_NestingLevel++;
361 AcpiUtTrackStackPtr ();
362
363 /* Check if enabled up-front for performance */
364
365 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
366 {
367 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
368 LineNumber, FunctionName, ModuleName, ComponentId,
369 "%s %p\n", AcpiGbl_FnEntryStr, Pointer);
370 }
371 }
372
373
374 /*******************************************************************************
375 *
376 * FUNCTION: AcpiUtTraceStr
377 *
378 * PARAMETERS: LineNumber - Caller's line number
379 * FunctionName - Caller's procedure name
380 * ModuleName - Caller's module name
381 * ComponentId - Caller's component ID
382 * String - Additional string to display
383 *
384 * RETURN: None
385 *
386 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
387 * set in DebugLevel
388 *
389 ******************************************************************************/
390
391 void
AcpiUtTraceStr(UINT32 LineNumber,const char * FunctionName,const char * ModuleName,UINT32 ComponentId,char * String)392 AcpiUtTraceStr (
393 UINT32 LineNumber,
394 const char *FunctionName,
395 const char *ModuleName,
396 UINT32 ComponentId,
397 char *String)
398 {
399
400 AcpiGbl_NestingLevel++;
401 AcpiUtTrackStackPtr ();
402
403 /* Check if enabled up-front for performance */
404
405 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
406 {
407 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
408 LineNumber, FunctionName, ModuleName, ComponentId,
409 "%s %s\n", AcpiGbl_FnEntryStr, String);
410 }
411 }
412
413
414 /*******************************************************************************
415 *
416 * FUNCTION: AcpiUtTraceU32
417 *
418 * PARAMETERS: LineNumber - Caller's line number
419 * FunctionName - Caller's procedure name
420 * ModuleName - Caller's module name
421 * ComponentId - Caller's component ID
422 * Integer - Integer to display
423 *
424 * RETURN: None
425 *
426 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
427 * set in DebugLevel
428 *
429 ******************************************************************************/
430
431 void
AcpiUtTraceU32(UINT32 LineNumber,const char * FunctionName,const char * ModuleName,UINT32 ComponentId,UINT32 Integer)432 AcpiUtTraceU32 (
433 UINT32 LineNumber,
434 const char *FunctionName,
435 const char *ModuleName,
436 UINT32 ComponentId,
437 UINT32 Integer)
438 {
439
440 AcpiGbl_NestingLevel++;
441 AcpiUtTrackStackPtr ();
442
443 /* Check if enabled up-front for performance */
444
445 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
446 {
447 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
448 LineNumber, FunctionName, ModuleName, ComponentId,
449 "%s %08X\n", AcpiGbl_FnEntryStr, Integer);
450 }
451 }
452
453
454 /*******************************************************************************
455 *
456 * FUNCTION: AcpiUtExit
457 *
458 * PARAMETERS: LineNumber - Caller's line number
459 * FunctionName - Caller's procedure name
460 * ModuleName - Caller's module name
461 * ComponentId - Caller's component ID
462 *
463 * RETURN: None
464 *
465 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
466 * set in DebugLevel
467 *
468 ******************************************************************************/
469
470 void
AcpiUtExit(UINT32 LineNumber,const char * FunctionName,const char * ModuleName,UINT32 ComponentId)471 AcpiUtExit (
472 UINT32 LineNumber,
473 const char *FunctionName,
474 const char *ModuleName,
475 UINT32 ComponentId)
476 {
477
478 /* Check if enabled up-front for performance */
479
480 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
481 {
482 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
483 LineNumber, FunctionName, ModuleName, ComponentId,
484 "%s\n", AcpiGbl_FnExitStr);
485 }
486
487 if (AcpiGbl_NestingLevel)
488 {
489 AcpiGbl_NestingLevel--;
490 }
491 }
492
ACPI_EXPORT_SYMBOL(AcpiUtExit)493 ACPI_EXPORT_SYMBOL (AcpiUtExit)
494
495
496 /*******************************************************************************
497 *
498 * FUNCTION: AcpiUtStatusExit
499 *
500 * PARAMETERS: LineNumber - Caller's line number
501 * FunctionName - Caller's procedure name
502 * ModuleName - Caller's module name
503 * ComponentId - Caller's component ID
504 * Status - Exit status code
505 *
506 * RETURN: None
507 *
508 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
509 * set in DebugLevel. Prints exit status also.
510 *
511 ******************************************************************************/
512
513 void
514 AcpiUtStatusExit (
515 UINT32 LineNumber,
516 const char *FunctionName,
517 const char *ModuleName,
518 UINT32 ComponentId,
519 ACPI_STATUS Status)
520 {
521
522 /* Check if enabled up-front for performance */
523
524 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
525 {
526 if (ACPI_SUCCESS (Status))
527 {
528 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
529 LineNumber, FunctionName, ModuleName, ComponentId,
530 "%s %s\n", AcpiGbl_FnExitStr,
531 AcpiFormatException (Status));
532 }
533 else
534 {
535 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
536 LineNumber, FunctionName, ModuleName, ComponentId,
537 "%s ****Exception****: %s\n", AcpiGbl_FnExitStr,
538 AcpiFormatException (Status));
539 }
540 }
541
542 if (AcpiGbl_NestingLevel)
543 {
544 AcpiGbl_NestingLevel--;
545 }
546 }
547
ACPI_EXPORT_SYMBOL(AcpiUtStatusExit)548 ACPI_EXPORT_SYMBOL (AcpiUtStatusExit)
549
550
551 /*******************************************************************************
552 *
553 * FUNCTION: AcpiUtValueExit
554 *
555 * PARAMETERS: LineNumber - Caller's line number
556 * FunctionName - Caller's procedure name
557 * ModuleName - Caller's module name
558 * ComponentId - Caller's component ID
559 * Value - Value to be printed with exit msg
560 *
561 * RETURN: None
562 *
563 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
564 * set in DebugLevel. Prints exit value also.
565 *
566 ******************************************************************************/
567
568 void
569 AcpiUtValueExit (
570 UINT32 LineNumber,
571 const char *FunctionName,
572 const char *ModuleName,
573 UINT32 ComponentId,
574 UINT64 Value)
575 {
576
577 /* Check if enabled up-front for performance */
578
579 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
580 {
581 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
582 LineNumber, FunctionName, ModuleName, ComponentId,
583 "%s %8.8X%8.8X\n", AcpiGbl_FnExitStr,
584 ACPI_FORMAT_UINT64 (Value));
585 }
586
587 if (AcpiGbl_NestingLevel)
588 {
589 AcpiGbl_NestingLevel--;
590 }
591 }
592
ACPI_EXPORT_SYMBOL(AcpiUtValueExit)593 ACPI_EXPORT_SYMBOL (AcpiUtValueExit)
594
595
596 /*******************************************************************************
597 *
598 * FUNCTION: AcpiUtPtrExit
599 *
600 * PARAMETERS: LineNumber - Caller's line number
601 * FunctionName - Caller's procedure name
602 * ModuleName - Caller's module name
603 * ComponentId - Caller's component ID
604 * Ptr - Pointer to display
605 *
606 * RETURN: None
607 *
608 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
609 * set in DebugLevel. Prints exit value also.
610 *
611 ******************************************************************************/
612
613 void
614 AcpiUtPtrExit (
615 UINT32 LineNumber,
616 const char *FunctionName,
617 const char *ModuleName,
618 UINT32 ComponentId,
619 UINT8 *Ptr)
620 {
621
622 /* Check if enabled up-front for performance */
623
624 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId))
625 {
626 AcpiDebugPrint (ACPI_LV_FUNCTIONS,
627 LineNumber, FunctionName, ModuleName, ComponentId,
628 "%s %p\n", AcpiGbl_FnExitStr, Ptr);
629 }
630
631 if (AcpiGbl_NestingLevel)
632 {
633 AcpiGbl_NestingLevel--;
634 }
635 }
636
637 #endif
638
639
640 #ifdef ACPI_APPLICATION
641 /*******************************************************************************
642 *
643 * FUNCTION: AcpiLogError
644 *
645 * PARAMETERS: Format - Printf format field
646 * ... - Optional printf arguments
647 *
648 * RETURN: None
649 *
650 * DESCRIPTION: Print error message to the console, used by applications.
651 *
652 ******************************************************************************/
653
654 void ACPI_INTERNAL_VAR_XFACE
AcpiLogError(const char * Format,...)655 AcpiLogError (
656 const char *Format,
657 ...)
658 {
659 va_list Args;
660
661 va_start (Args, Format);
662 (void) AcpiUtFileVprintf (ACPI_FILE_ERR, Format, Args);
663 va_end (Args);
664 }
665
666 ACPI_EXPORT_SYMBOL (AcpiLogError)
667 #endif
668