utdebug.c revision 70243
1/******************************************************************************
2 *
3 * Module Name: cmdebug - Debug print routines
4 *              $Revision: 62 $
5 *
6 *****************************************************************************/
7
8/******************************************************************************
9 *
10 * 1. Copyright Notice
11 *
12 * Some or all of this work - Copyright (c) 1999, 2000, Intel Corp.
13 * All rights reserved.
14 *
15 * 2. License
16 *
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights.  You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
20 * property rights.
21 *
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
28 *
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code.  No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
37 *
38 * The above copyright and patent license is granted only if the following
39 * conditions are met:
40 *
41 * 3. Conditions
42 *
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision.  In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change.  Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee.  Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
54 *
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution.  In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
65 * make.
66 *
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
71 * distribution.
72 *
73 * 3.4. Intel retains all right, title, and interest in and to the Original
74 * Intel Code.
75 *
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
80 *
81 * 4. Disclaimer and Export Compliance
82 *
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89 * PARTICULAR PURPOSE.
90 *
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98 * LIMITED REMEDY.
99 *
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government.  In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
114 *
115 *****************************************************************************/
116
117#define __CMDEBUG_C__
118
119#include "acpi.h"
120
121#define _COMPONENT          MISCELLANEOUS
122        MODULE_NAME         ("cmdebug")
123
124
125/*****************************************************************************
126 *
127 * FUNCTION:    Get/Set debug level
128 *
129 * DESCRIPTION: Get or set value of the debug flag
130 *
131 *              These are used to allow user's to get/set the debug level
132 *
133 ****************************************************************************/
134
135
136UINT32
137GetDebugLevel (void)
138{
139
140    return (AcpiDbgLevel);
141}
142
143void
144SetDebugLevel (
145    UINT32                  NewDebugLevel)
146{
147
148    AcpiDbgLevel = NewDebugLevel;
149}
150
151
152/*****************************************************************************
153 *
154 * FUNCTION:    FunctionTrace
155 *
156 * PARAMETERS:  ModuleName          - Caller's module name (for error output)
157 *              LineNumber          - Caller's line number (for error output)
158 *              ComponentId         - Caller's component ID (for error output)
159 *              FunctionName        - Name of Caller's function
160 *
161 * RETURN:      None
162 *
163 * DESCRIPTION: Function entry trace.  Prints only if TRACE_FUNCTIONS bit is
164 *              set in DebugLevel
165 *
166 ****************************************************************************/
167
168void
169FunctionTrace (
170    NATIVE_CHAR             *ModuleName,
171    UINT32                  LineNumber,
172    UINT32                  ComponentId,
173    NATIVE_CHAR             *FunctionName)
174{
175
176    AcpiGbl_NestingLevel++;
177
178    DebugPrint (ModuleName, LineNumber, ComponentId,
179                TRACE_FUNCTIONS,
180                " %2.2ld Entered Function: %s\n",
181                AcpiGbl_NestingLevel, FunctionName);
182}
183
184
185/*****************************************************************************
186 *
187 * FUNCTION:    FunctionTracePtr
188 *
189 * PARAMETERS:  ModuleName          - Caller's module name (for error output)
190 *              LineNumber          - Caller's line number (for error output)
191 *              ComponentId         - Caller's component ID (for error output)
192 *              FunctionName        - Name of Caller's function
193 *              Pointer             - Pointer to display
194 *
195 * RETURN:      None
196 *
197 * DESCRIPTION: Function entry trace.  Prints only if TRACE_FUNCTIONS bit is
198 *              set in DebugLevel
199 *
200 ****************************************************************************/
201
202void
203FunctionTracePtr (
204    NATIVE_CHAR             *ModuleName,
205    UINT32                  LineNumber,
206    UINT32                  ComponentId,
207    NATIVE_CHAR             *FunctionName,
208    void                    *Pointer)
209{
210
211    AcpiGbl_NestingLevel++;
212    DebugPrint (ModuleName, LineNumber, ComponentId, TRACE_FUNCTIONS,
213                " %2.2ld Entered Function: %s, %p\n",
214                AcpiGbl_NestingLevel, FunctionName, Pointer);
215}
216
217
218/*****************************************************************************
219 *
220 * FUNCTION:    FunctionTraceStr
221 *
222 * PARAMETERS:  ModuleName          - Caller's module name (for error output)
223 *              LineNumber          - Caller's line number (for error output)
224 *              ComponentId         - Caller's component ID (for error output)
225 *              FunctionName        - Name of Caller's function
226 *              String              - Additional string to display
227 *
228 * RETURN:      None
229 *
230 * DESCRIPTION: Function entry trace.  Prints only if TRACE_FUNCTIONS bit is
231 *              set in DebugLevel
232 *
233 ****************************************************************************/
234
235void
236FunctionTraceStr (
237    NATIVE_CHAR             *ModuleName,
238    UINT32                  LineNumber,
239    UINT32                  ComponentId,
240    NATIVE_CHAR             *FunctionName,
241    NATIVE_CHAR             *String)
242{
243
244    AcpiGbl_NestingLevel++;
245    DebugPrint (ModuleName, LineNumber, ComponentId, TRACE_FUNCTIONS,
246                " %2.2ld Entered Function: %s, %s\n",
247                AcpiGbl_NestingLevel, FunctionName, String);
248}
249
250
251/*****************************************************************************
252 *
253 * FUNCTION:    FunctionTraceU32
254 *
255 * PARAMETERS:  ModuleName          - Caller's module name (for error output)
256 *              LineNumber          - Caller's line number (for error output)
257 *              ComponentId         - Caller's component ID (for error output)
258 *              FunctionName        - Name of Caller's function
259 *              Integer             - Integer to display
260 *
261 * RETURN:      None
262 *
263 * DESCRIPTION: Function entry trace.  Prints only if TRACE_FUNCTIONS bit is
264 *              set in DebugLevel
265 *
266 ****************************************************************************/
267
268void
269FunctionTraceU32 (
270    NATIVE_CHAR             *ModuleName,
271    UINT32                  LineNumber,
272    UINT32                  ComponentId,
273    NATIVE_CHAR             *FunctionName,
274    UINT32                  Integer)
275{
276
277    AcpiGbl_NestingLevel++;
278    DebugPrint (ModuleName, LineNumber, ComponentId, TRACE_FUNCTIONS,
279                " %2.2ld Entered Function: %s, %lX\n",
280                AcpiGbl_NestingLevel, FunctionName, Integer);
281}
282
283
284/*****************************************************************************
285 *
286 * FUNCTION:    FunctionExit
287 *
288 * PARAMETERS:  ModuleName          - Caller's module name (for error output)
289 *              LineNumber          - Caller's line number (for error output)
290 *              ComponentId         - Caller's component ID (for error output)
291 *              FunctionName        - Name of Caller's function
292 *
293 * RETURN:      None
294 *
295 * DESCRIPTION: Function exit trace.  Prints only if TRACE_FUNCTIONS bit is
296 *              set in DebugLevel
297 *
298 ****************************************************************************/
299
300void
301FunctionExit (
302    NATIVE_CHAR             *ModuleName,
303    UINT32                  LineNumber,
304    UINT32                  ComponentId,
305    NATIVE_CHAR             *FunctionName)
306{
307
308    DebugPrint (ModuleName, LineNumber, ComponentId, TRACE_FUNCTIONS,
309                " %2.2ld Exiting Function: %s\n",
310                AcpiGbl_NestingLevel, FunctionName);
311
312    AcpiGbl_NestingLevel--;
313}
314
315
316/*****************************************************************************
317 *
318 * FUNCTION:    FunctionStatusExit
319 *
320 * PARAMETERS:  ModuleName          - Caller's module name (for error output)
321 *              LineNumber          - Caller's line number (for error output)
322 *              ComponentId         - Caller's component ID (for error output)
323 *              FunctionName        - Name of Caller's function
324 *              Status              - Exit status code
325 *
326 * RETURN:      None
327 *
328 * DESCRIPTION: Function exit trace.  Prints only if TRACE_FUNCTIONS bit is
329 *              set in DebugLevel.  Prints exit status also.
330 *
331 ****************************************************************************/
332
333void
334FunctionStatusExit (
335    NATIVE_CHAR             *ModuleName,
336    UINT32                  LineNumber,
337    UINT32                  ComponentId,
338    NATIVE_CHAR             *FunctionName,
339    ACPI_STATUS             Status)
340{
341
342    DebugPrint (ModuleName, LineNumber, ComponentId,
343        TRACE_FUNCTIONS,
344        " %2.2ld Exiting Function: %s, %s\n",
345        AcpiGbl_NestingLevel,
346        FunctionName,
347        AcpiCmFormatException (Status));
348
349    AcpiGbl_NestingLevel--;
350}
351
352
353/*****************************************************************************
354 *
355 * FUNCTION:    FunctionValueExit
356 *
357 * PARAMETERS:  ModuleName          - Caller's module name (for error output)
358 *              LineNumber          - Caller's line number (for error output)
359 *              ComponentId         - Caller's component ID (for error output)
360 *              FunctionName        - Name of Caller's function
361 *              Value               - Value to be printed with exit msg
362 *
363 * RETURN:      None
364 *
365 * DESCRIPTION: Function exit trace.  Prints only if TRACE_FUNCTIONS bit is
366 *              set in DebugLevel.  Prints exit value also.
367 *
368 ****************************************************************************/
369
370void
371FunctionValueExit (
372    NATIVE_CHAR             *ModuleName,
373    UINT32                  LineNumber,
374    UINT32                  ComponentId,
375    NATIVE_CHAR             *FunctionName,
376    NATIVE_UINT             Value)
377{
378
379    DebugPrint (ModuleName, LineNumber, ComponentId, TRACE_FUNCTIONS,
380                " %2.2ld Exiting Function: %s, %X\n",
381                AcpiGbl_NestingLevel, FunctionName, Value);
382
383    AcpiGbl_NestingLevel--;
384}
385
386
387/*****************************************************************************
388 *
389 * FUNCTION:    FunctionPtrExit
390 *
391 * PARAMETERS:  ModuleName          - Caller's module name (for error output)
392 *              LineNumber          - Caller's line number (for error output)
393 *              ComponentId         - Caller's component ID (for error output)
394 *              FunctionName        - Name of Caller's function
395 *              Value               - Value to be printed with exit msg
396 *
397 * RETURN:      None
398 *
399 * DESCRIPTION: Function exit trace.  Prints only if TRACE_FUNCTIONS bit is
400 *              set in DebugLevel.  Prints exit value also.
401 *
402 ****************************************************************************/
403
404void
405FunctionPtrExit (
406    NATIVE_CHAR             *ModuleName,
407    UINT32                  LineNumber,
408    UINT32                  ComponentId,
409    NATIVE_CHAR             *FunctionName,
410    UINT8                   *Ptr)
411{
412
413    DebugPrint (ModuleName, LineNumber, ComponentId, TRACE_FUNCTIONS,
414                " %2.2ld Exiting Function: %s, %p\n",
415                AcpiGbl_NestingLevel, FunctionName, Ptr);
416
417    AcpiGbl_NestingLevel--;
418}
419
420
421/*****************************************************************************
422 *
423 * FUNCTION:    DebugPrint
424 *
425 * PARAMETERS:  ModuleName          - Caller's module name (for error output)
426 *              LineNumber          - Caller's line number (for error output)
427 *              ComponentId         - Caller's component ID (for error output)
428 *              PrintLevel          - Requested debug print level
429 *              Format              - Printf format field
430 *              ...                 - Optional printf arguments
431 *
432 * RETURN:      None
433 *
434 * DESCRIPTION: Print error message with prefix consisting of the module name,
435 *              line number, and component ID.
436 *
437 ****************************************************************************/
438
439void
440DebugPrint (
441    NATIVE_CHAR             *ModuleName,
442    UINT32                  LineNumber,
443    UINT32                  ComponentId,
444    UINT32                  PrintLevel,
445    NATIVE_CHAR             *Format,
446    ...)
447{
448    va_list                 args;
449
450
451    /* Both the level and the component must be enabled */
452
453    if ((PrintLevel & AcpiDbgLevel) &&
454        (ComponentId & AcpiDbgLayer))
455    {
456        va_start (args, Format);
457
458        AcpiOsPrintf ("%8s-%04d: ", ModuleName, LineNumber);
459        AcpiOsVprintf (Format, args);
460    }
461}
462
463
464/*****************************************************************************
465 *
466 * FUNCTION:    DebugPrintPrefix
467 *
468 * PARAMETERS:  ModuleName          - Caller's module name (for error output)
469 *              LineNumber          - Caller's line number (for error output)
470 *              ComponentId         - Caller's component ID (for error output)
471 *
472 * RETURN:      None
473 *
474 * DESCRIPTION: Print the prefix part of an error message, consisting of the
475 *              module name, and line number
476 *
477 ****************************************************************************/
478
479void
480DebugPrintPrefix (
481    NATIVE_CHAR             *ModuleName,
482    UINT32                  LineNumber)
483{
484
485
486    AcpiOsPrintf ("%8s-%04d: ", ModuleName, LineNumber);
487}
488
489
490/*****************************************************************************
491 *
492 * FUNCTION:    DebugPrintRaw
493 *
494 * PARAMETERS:  Format              - Printf format field
495 *              ...                 - Optional printf arguments
496 *
497 * RETURN:      None
498 *
499 * DESCRIPTION: Print error message -- without module/line indentifiers
500 *
501 ****************************************************************************/
502
503void
504DebugPrintRaw (
505    NATIVE_CHAR             *Format,
506    ...)
507{
508    va_list                 args;
509
510
511    va_start (args, Format);
512
513    AcpiOsVprintf (Format, args);
514
515    va_end (args);
516}
517
518
519/*****************************************************************************
520 *
521 * FUNCTION:    AcpiCmDumpBuffer
522 *
523 * PARAMETERS:  Buffer              - Buffer to dump
524 *              Count               - Amount to dump, in bytes
525 *              ComponentID         - Caller's component ID
526 *
527 * RETURN:      None
528 *
529 * DESCRIPTION: Generic dump buffer in both hex and ascii.
530 *
531 ****************************************************************************/
532
533void
534AcpiCmDumpBuffer (
535    UINT8                   *Buffer,
536    UINT32                  Count,
537    UINT32                  Display,
538    UINT32                  ComponentId)
539{
540    UINT32                  i = 0;
541    UINT32                  j;
542    UINT32                  Temp32;
543    UINT8                   BufChar;
544
545
546    /* Only dump the buffer if tracing is enabled */
547
548    if (!((TRACE_TABLES & AcpiDbgLevel) &&
549        (ComponentId & AcpiDbgLayer)))
550    {
551        return;
552    }
553
554
555    /*
556     * Nasty little dump buffer routine!
557     */
558    while (i < Count)
559    {
560        /* Print current offset */
561
562        AcpiOsPrintf ("%05X    ", i);
563
564
565        /* Print 16 hex chars */
566
567        for (j = 0; j < 16;)
568        {
569            if (i + j >= Count)
570            {
571                AcpiOsPrintf ("\n");
572                return;
573            }
574
575            /* Make sure that the INT8 doesn't get sign-extended! */
576
577            switch (Display)
578            {
579            /* Default is BYTE display */
580
581            default:
582
583                AcpiOsPrintf ("%02X ",
584                        *((UINT8 *) &Buffer[i + j]));
585                j += 1;
586                break;
587
588
589            case DB_WORD_DISPLAY:
590
591                MOVE_UNALIGNED16_TO_32 (&Temp32,
592                                        &Buffer[i + j]);
593                AcpiOsPrintf ("%04X ", Temp32);
594                j += 2;
595                break;
596
597
598            case DB_DWORD_DISPLAY:
599
600                MOVE_UNALIGNED32_TO_32 (&Temp32,
601                                        &Buffer[i + j]);
602                AcpiOsPrintf ("%08X ", Temp32);
603                j += 4;
604                break;
605
606
607            case DB_QWORD_DISPLAY:
608
609                MOVE_UNALIGNED32_TO_32 (&Temp32,
610                                        &Buffer[i + j]);
611                AcpiOsPrintf ("%08X", Temp32);
612
613                MOVE_UNALIGNED32_TO_32 (&Temp32,
614                                        &Buffer[i + j + 4]);
615                AcpiOsPrintf ("%08X ", Temp32);
616                j += 8;
617                break;
618            }
619        }
620
621
622        /*
623         * Print the ASCII equivalent characters
624         * But watch out for the bad unprintable ones...
625         */
626
627        for (j = 0; j < 16; j++)
628        {
629            if (i + j >= Count)
630            {
631                AcpiOsPrintf ("\n");
632                return;
633            }
634
635            BufChar = Buffer[i + j];
636            if ((BufChar > 0x1F && BufChar < 0x2E) ||
637                (BufChar > 0x2F && BufChar < 0x61) ||
638                (BufChar > 0x60 && BufChar < 0x7F))
639            {
640                AcpiOsPrintf ("%c", BufChar);
641            }
642            else
643            {
644                AcpiOsPrintf (".");
645            }
646        }
647
648        /* Done with that line. */
649
650        AcpiOsPrintf ("\n");
651        i += 16;
652    }
653
654    return;
655}
656
657
658