utdebug.c revision 80062
1/****************************************************************************** 2 * 3 * Module Name: utdebug - Debug print routines 4 * $Revision: 73 $ 5 * 6 *****************************************************************************/ 7 8/****************************************************************************** 9 * 10 * 1. Copyright Notice 11 * 12 * Some or all of this work - Copyright (c) 1999, 2000, 2001, 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 __UTDEBUG_C__ 118 119#include "acpi.h" 120 121#define _COMPONENT ACPI_UTILITIES 122 MODULE_NAME ("utdebug") 123 124 125UINT32 PrevThreadId = 0xFFFFFFFF; 126 127/***************************************************************************** 128 * 129 * FUNCTION: Get/Set debug level 130 * 131 * DESCRIPTION: Get or set value of the debug flag 132 * 133 * These are used to allow user's to get/set the debug level 134 * 135 ****************************************************************************/ 136 137 138UINT32 139GetDebugLevel (void) 140{ 141 142 return (AcpiDbgLevel); 143} 144 145void 146SetDebugLevel ( 147 UINT32 NewDebugLevel) 148{ 149 150 AcpiDbgLevel = NewDebugLevel; 151} 152 153 154/***************************************************************************** 155 * 156 * FUNCTION: FunctionTrace 157 * 158 * PARAMETERS: ModuleName - Caller's module name (for error output) 159 * LineNumber - Caller's line number (for error output) 160 * ComponentId - Caller's component ID (for error output) 161 * FunctionName - Name of Caller's function 162 * 163 * RETURN: None 164 * 165 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 166 * set in DebugLevel 167 * 168 ****************************************************************************/ 169 170void 171FunctionTrace ( 172 NATIVE_CHAR *ModuleName, 173 UINT32 LineNumber, 174 UINT32 ComponentId, 175 NATIVE_CHAR *FunctionName) 176{ 177 178 AcpiGbl_NestingLevel++; 179 180 DebugPrint (ModuleName, LineNumber, ComponentId, 181 TRACE_FUNCTIONS, 182 " %2.2ld Entered Function: %s\n", 183 AcpiGbl_NestingLevel, FunctionName); 184} 185 186 187/***************************************************************************** 188 * 189 * FUNCTION: FunctionTracePtr 190 * 191 * PARAMETERS: ModuleName - Caller's module name (for error output) 192 * LineNumber - Caller's line number (for error output) 193 * ComponentId - Caller's component ID (for error output) 194 * FunctionName - Name of Caller's function 195 * Pointer - Pointer to display 196 * 197 * RETURN: None 198 * 199 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 200 * set in DebugLevel 201 * 202 ****************************************************************************/ 203 204void 205FunctionTracePtr ( 206 NATIVE_CHAR *ModuleName, 207 UINT32 LineNumber, 208 UINT32 ComponentId, 209 NATIVE_CHAR *FunctionName, 210 void *Pointer) 211{ 212 213 AcpiGbl_NestingLevel++; 214 DebugPrint (ModuleName, LineNumber, ComponentId, TRACE_FUNCTIONS, 215 " %2.2ld Entered Function: %s, %p\n", 216 AcpiGbl_NestingLevel, FunctionName, Pointer); 217} 218 219 220/***************************************************************************** 221 * 222 * FUNCTION: FunctionTraceStr 223 * 224 * PARAMETERS: ModuleName - Caller's module name (for error output) 225 * LineNumber - Caller's line number (for error output) 226 * ComponentId - Caller's component ID (for error output) 227 * FunctionName - Name of Caller's function 228 * String - Additional string to display 229 * 230 * RETURN: None 231 * 232 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 233 * set in DebugLevel 234 * 235 ****************************************************************************/ 236 237void 238FunctionTraceStr ( 239 NATIVE_CHAR *ModuleName, 240 UINT32 LineNumber, 241 UINT32 ComponentId, 242 NATIVE_CHAR *FunctionName, 243 NATIVE_CHAR *String) 244{ 245 246 AcpiGbl_NestingLevel++; 247 DebugPrint (ModuleName, LineNumber, ComponentId, TRACE_FUNCTIONS, 248 " %2.2ld Entered Function: %s, %s\n", 249 AcpiGbl_NestingLevel, FunctionName, String); 250} 251 252 253/***************************************************************************** 254 * 255 * FUNCTION: FunctionTraceU32 256 * 257 * PARAMETERS: ModuleName - Caller's module name (for error output) 258 * LineNumber - Caller's line number (for error output) 259 * ComponentId - Caller's component ID (for error output) 260 * FunctionName - Name of Caller's function 261 * Integer - Integer to display 262 * 263 * RETURN: None 264 * 265 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 266 * set in DebugLevel 267 * 268 ****************************************************************************/ 269 270void 271FunctionTraceU32 ( 272 NATIVE_CHAR *ModuleName, 273 UINT32 LineNumber, 274 UINT32 ComponentId, 275 NATIVE_CHAR *FunctionName, 276 UINT32 Integer) 277{ 278 279 AcpiGbl_NestingLevel++; 280 DebugPrint (ModuleName, LineNumber, ComponentId, TRACE_FUNCTIONS, 281 " %2.2ld Entered Function: %s, %lX\n", 282 AcpiGbl_NestingLevel, FunctionName, Integer); 283} 284 285 286/***************************************************************************** 287 * 288 * FUNCTION: FunctionExit 289 * 290 * PARAMETERS: ModuleName - Caller's module name (for error output) 291 * LineNumber - Caller's line number (for error output) 292 * ComponentId - Caller's component ID (for error output) 293 * FunctionName - Name of Caller's function 294 * 295 * RETURN: None 296 * 297 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 298 * set in DebugLevel 299 * 300 ****************************************************************************/ 301 302void 303FunctionExit ( 304 NATIVE_CHAR *ModuleName, 305 UINT32 LineNumber, 306 UINT32 ComponentId, 307 NATIVE_CHAR *FunctionName) 308{ 309 310 DebugPrint (ModuleName, LineNumber, ComponentId, TRACE_FUNCTIONS, 311 " %2.2ld Exiting Function: %s\n", 312 AcpiGbl_NestingLevel, FunctionName); 313 314 AcpiGbl_NestingLevel--; 315} 316 317 318/***************************************************************************** 319 * 320 * FUNCTION: FunctionStatusExit 321 * 322 * PARAMETERS: ModuleName - Caller's module name (for error output) 323 * LineNumber - Caller's line number (for error output) 324 * ComponentId - Caller's component ID (for error output) 325 * FunctionName - Name of Caller's function 326 * Status - Exit status code 327 * 328 * RETURN: None 329 * 330 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 331 * set in DebugLevel. Prints exit status also. 332 * 333 ****************************************************************************/ 334 335void 336FunctionStatusExit ( 337 NATIVE_CHAR *ModuleName, 338 UINT32 LineNumber, 339 UINT32 ComponentId, 340 NATIVE_CHAR *FunctionName, 341 ACPI_STATUS Status) 342{ 343 344 DebugPrint (ModuleName, LineNumber, ComponentId, 345 TRACE_FUNCTIONS, " %2.2ld Exiting Function: %s, %s\n", 346 AcpiGbl_NestingLevel, FunctionName, AcpiFormatException (Status)); 347 348 AcpiGbl_NestingLevel--; 349} 350 351 352/***************************************************************************** 353 * 354 * FUNCTION: FunctionValueExit 355 * 356 * PARAMETERS: ModuleName - Caller's module name (for error output) 357 * LineNumber - Caller's line number (for error output) 358 * ComponentId - Caller's component ID (for error output) 359 * FunctionName - Name of Caller's function 360 * Value - Value to be printed with exit msg 361 * 362 * RETURN: None 363 * 364 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 365 * set in DebugLevel. Prints exit value also. 366 * 367 ****************************************************************************/ 368 369void 370FunctionValueExit ( 371 NATIVE_CHAR *ModuleName, 372 UINT32 LineNumber, 373 UINT32 ComponentId, 374 NATIVE_CHAR *FunctionName, 375 ACPI_INTEGER Value) 376{ 377 378 DebugPrint (ModuleName, LineNumber, ComponentId, TRACE_FUNCTIONS, 379 " %2.2ld Exiting Function: %s, %X\n", 380 AcpiGbl_NestingLevel, FunctionName, Value); 381 382 AcpiGbl_NestingLevel--; 383} 384 385 386/***************************************************************************** 387 * 388 * FUNCTION: FunctionPtrExit 389 * 390 * PARAMETERS: ModuleName - Caller's module name (for error output) 391 * LineNumber - Caller's line number (for error output) 392 * ComponentId - Caller's component ID (for error output) 393 * FunctionName - Name of Caller's function 394 * Value - Value to be printed with exit msg 395 * 396 * RETURN: None 397 * 398 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 399 * set in DebugLevel. Prints exit value also. 400 * 401 ****************************************************************************/ 402 403void 404FunctionPtrExit ( 405 NATIVE_CHAR *ModuleName, 406 UINT32 LineNumber, 407 UINT32 ComponentId, 408 NATIVE_CHAR *FunctionName, 409 UINT8 *Ptr) 410{ 411 412 DebugPrint (ModuleName, LineNumber, ComponentId, TRACE_FUNCTIONS, 413 " %2.2ld Exiting Function: %s, %p\n", 414 AcpiGbl_NestingLevel, FunctionName, Ptr); 415 416 AcpiGbl_NestingLevel--; 417} 418 419 420/***************************************************************************** 421 * 422 * FUNCTION: DebugPrint 423 * 424 * PARAMETERS: ModuleName - Caller's module name (for error output) 425 * LineNumber - Caller's line number (for error output) 426 * ComponentId - Caller's component ID (for error output) 427 * PrintLevel - Requested debug print level 428 * Format - Printf format field 429 * ... - Optional printf arguments 430 * 431 * RETURN: None 432 * 433 * DESCRIPTION: Print error message with prefix consisting of the module name, 434 * line number, and component ID. 435 * 436 ****************************************************************************/ 437 438void 439DebugPrint ( 440 NATIVE_CHAR *ModuleName, 441 UINT32 LineNumber, 442 UINT32 ComponentId, 443 UINT32 PrintLevel, 444 NATIVE_CHAR *Format, 445 ...) 446{ 447 va_list args; 448 UINT32 ThreadId; 449 450 451 ThreadId = AcpiOsGetThreadId (); 452 453 454 /* Both the level and the component must be enabled */ 455 456 if ((PrintLevel & AcpiDbgLevel) && 457 (ComponentId & AcpiDbgLayer)) 458 { 459 va_start (args, Format); 460 461 if (ThreadId != PrevThreadId) 462 { 463 if (TRACE_THREADS & AcpiDbgLevel) 464 { 465 AcpiOsPrintf ("\n**** Context Switch from TID %X to TID %X ****\n\n", 466 PrevThreadId, ThreadId); 467 } 468 469 PrevThreadId = ThreadId; 470 } 471 472 if (TRACE_THREADS & AcpiDbgLevel) 473 { 474 AcpiOsPrintf ("%8s-%04d[%04X]: ", ModuleName, LineNumber, ThreadId); 475 } 476 else 477 { 478 AcpiOsPrintf ("%8s-%04d: ", ModuleName, LineNumber); 479 } 480 481 AcpiOsVprintf (Format, args); 482 } 483} 484 485 486/***************************************************************************** 487 * 488 * FUNCTION: DebugPrintPrefix 489 * 490 * PARAMETERS: ModuleName - Caller's module name (for error output) 491 * LineNumber - Caller's line number (for error output) 492 * ComponentId - Caller's component ID (for error output) 493 * 494 * RETURN: None 495 * 496 * DESCRIPTION: Print the prefix part of an error message, consisting of the 497 * module name, and line number 498 * 499 ****************************************************************************/ 500 501void 502DebugPrintPrefix ( 503 NATIVE_CHAR *ModuleName, 504 UINT32 LineNumber) 505{ 506 UINT32 ThreadId; 507 508 509 ThreadId = AcpiOsGetThreadId (); 510 511 if (ThreadId != PrevThreadId) 512 { 513 if (TRACE_THREADS & AcpiDbgLevel) 514 { 515 AcpiOsPrintf ("\n**** Context Switch from TID %X to TID %X ****\n\n", 516 PrevThreadId, ThreadId); 517 } 518 519 PrevThreadId = ThreadId; 520 } 521 522 if (TRACE_THREADS & AcpiDbgLevel) 523 { 524 AcpiOsPrintf ("%8s-%04d[%04X]: ", ModuleName, LineNumber, ThreadId); 525 } 526 else 527 { 528 AcpiOsPrintf ("%8s-%04d: ", ModuleName, LineNumber); 529 } 530 531} 532 533 534/***************************************************************************** 535 * 536 * FUNCTION: DebugPrintRaw 537 * 538 * PARAMETERS: Format - Printf format field 539 * ... - Optional printf arguments 540 * 541 * RETURN: None 542 * 543 * DESCRIPTION: Print error message -- without module/line indentifiers 544 * 545 ****************************************************************************/ 546 547void 548DebugPrintRaw ( 549 NATIVE_CHAR *Format, 550 ...) 551{ 552 va_list args; 553 554 555 va_start (args, Format); 556 557 AcpiOsVprintf (Format, args); 558 559 va_end (args); 560} 561 562 563/***************************************************************************** 564 * 565 * FUNCTION: AcpiUtDumpBuffer 566 * 567 * PARAMETERS: Buffer - Buffer to dump 568 * Count - Amount to dump, in bytes 569 * ComponentID - Caller's component ID 570 * 571 * RETURN: None 572 * 573 * DESCRIPTION: Generic dump buffer in both hex and ascii. 574 * 575 ****************************************************************************/ 576 577void 578AcpiUtDumpBuffer ( 579 UINT8 *Buffer, 580 UINT32 Count, 581 UINT32 Display, 582 UINT32 ComponentId) 583{ 584 UINT32 i = 0; 585 UINT32 j; 586 UINT32 Temp32; 587 UINT8 BufChar; 588 589 590 /* Only dump the buffer if tracing is enabled */ 591 592 if (!((TRACE_TABLES & AcpiDbgLevel) && 593 (ComponentId & AcpiDbgLayer))) 594 { 595 return; 596 } 597 598 599 /* 600 * Nasty little dump buffer routine! 601 */ 602 while (i < Count) 603 { 604 /* Print current offset */ 605 606 AcpiOsPrintf ("%05X ", i); 607 608 609 /* Print 16 hex chars */ 610 611 for (j = 0; j < 16;) 612 { 613 if (i + j >= Count) 614 { 615 AcpiOsPrintf ("\n"); 616 return; 617 } 618 619 /* Make sure that the INT8 doesn't get sign-extended! */ 620 621 switch (Display) 622 { 623 /* Default is BYTE display */ 624 625 default: 626 627 AcpiOsPrintf ("%02X ", 628 *((UINT8 *) &Buffer[i + j])); 629 j += 1; 630 break; 631 632 633 case DB_WORD_DISPLAY: 634 635 MOVE_UNALIGNED16_TO_32 (&Temp32, 636 &Buffer[i + j]); 637 AcpiOsPrintf ("%04X ", Temp32); 638 j += 2; 639 break; 640 641 642 case DB_DWORD_DISPLAY: 643 644 MOVE_UNALIGNED32_TO_32 (&Temp32, 645 &Buffer[i + j]); 646 AcpiOsPrintf ("%08X ", Temp32); 647 j += 4; 648 break; 649 650 651 case DB_QWORD_DISPLAY: 652 653 MOVE_UNALIGNED32_TO_32 (&Temp32, 654 &Buffer[i + j]); 655 AcpiOsPrintf ("%08X", Temp32); 656 657 MOVE_UNALIGNED32_TO_32 (&Temp32, 658 &Buffer[i + j + 4]); 659 AcpiOsPrintf ("%08X ", Temp32); 660 j += 8; 661 break; 662 } 663 } 664 665 666 /* 667 * Print the ASCII equivalent characters 668 * But watch out for the bad unprintable ones... 669 */ 670 671 for (j = 0; j < 16; j++) 672 { 673 if (i + j >= Count) 674 { 675 AcpiOsPrintf ("\n"); 676 return; 677 } 678 679 BufChar = Buffer[i + j]; 680 if ((BufChar > 0x1F && BufChar < 0x2E) || 681 (BufChar > 0x2F && BufChar < 0x61) || 682 (BufChar > 0x60 && BufChar < 0x7F)) 683 { 684 AcpiOsPrintf ("%c", BufChar); 685 } 686 else 687 { 688 AcpiOsPrintf ("."); 689 } 690 } 691 692 /* Done with that line. */ 693 694 AcpiOsPrintf ("\n"); 695 i += 16; 696 } 697 698 return; 699} 700 701 702