utdebug.c revision 77424
1/****************************************************************************** 2 * 3 * Module Name: utdebug - Debug print routines 4 * $Revision: 72 $ 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, 346 " %2.2ld Exiting Function: %s, %s\n", 347 AcpiGbl_NestingLevel, 348 FunctionName, 349 AcpiUtFormatException (Status)); 350 351 AcpiGbl_NestingLevel--; 352} 353 354 355/***************************************************************************** 356 * 357 * FUNCTION: FunctionValueExit 358 * 359 * PARAMETERS: ModuleName - Caller's module name (for error output) 360 * LineNumber - Caller's line number (for error output) 361 * ComponentId - Caller's component ID (for error output) 362 * FunctionName - Name of Caller's function 363 * Value - Value to be printed with exit msg 364 * 365 * RETURN: None 366 * 367 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 368 * set in DebugLevel. Prints exit value also. 369 * 370 ****************************************************************************/ 371 372void 373FunctionValueExit ( 374 NATIVE_CHAR *ModuleName, 375 UINT32 LineNumber, 376 UINT32 ComponentId, 377 NATIVE_CHAR *FunctionName, 378 ACPI_INTEGER Value) 379{ 380 381 DebugPrint (ModuleName, LineNumber, ComponentId, TRACE_FUNCTIONS, 382 " %2.2ld Exiting Function: %s, %X\n", 383 AcpiGbl_NestingLevel, FunctionName, Value); 384 385 AcpiGbl_NestingLevel--; 386} 387 388 389/***************************************************************************** 390 * 391 * FUNCTION: FunctionPtrExit 392 * 393 * PARAMETERS: ModuleName - Caller's module name (for error output) 394 * LineNumber - Caller's line number (for error output) 395 * ComponentId - Caller's component ID (for error output) 396 * FunctionName - Name of Caller's function 397 * Value - Value to be printed with exit msg 398 * 399 * RETURN: None 400 * 401 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 402 * set in DebugLevel. Prints exit value also. 403 * 404 ****************************************************************************/ 405 406void 407FunctionPtrExit ( 408 NATIVE_CHAR *ModuleName, 409 UINT32 LineNumber, 410 UINT32 ComponentId, 411 NATIVE_CHAR *FunctionName, 412 UINT8 *Ptr) 413{ 414 415 DebugPrint (ModuleName, LineNumber, ComponentId, TRACE_FUNCTIONS, 416 " %2.2ld Exiting Function: %s, %p\n", 417 AcpiGbl_NestingLevel, FunctionName, Ptr); 418 419 AcpiGbl_NestingLevel--; 420} 421 422 423/***************************************************************************** 424 * 425 * FUNCTION: DebugPrint 426 * 427 * PARAMETERS: ModuleName - Caller's module name (for error output) 428 * LineNumber - Caller's line number (for error output) 429 * ComponentId - Caller's component ID (for error output) 430 * PrintLevel - Requested debug print level 431 * Format - Printf format field 432 * ... - Optional printf arguments 433 * 434 * RETURN: None 435 * 436 * DESCRIPTION: Print error message with prefix consisting of the module name, 437 * line number, and component ID. 438 * 439 ****************************************************************************/ 440 441void 442DebugPrint ( 443 NATIVE_CHAR *ModuleName, 444 UINT32 LineNumber, 445 UINT32 ComponentId, 446 UINT32 PrintLevel, 447 NATIVE_CHAR *Format, 448 ...) 449{ 450 va_list args; 451 UINT32 ThreadId; 452 453 454 ThreadId = AcpiOsGetThreadId (); 455 456 457 /* Both the level and the component must be enabled */ 458 459 if ((PrintLevel & AcpiDbgLevel) && 460 (ComponentId & AcpiDbgLayer)) 461 { 462 va_start (args, Format); 463 464 if (ThreadId != PrevThreadId) 465 { 466 if (TRACE_THREADS & AcpiDbgLevel) 467 { 468 AcpiOsPrintf ("\n**** Context Switch from TID %X to TID %X ****\n\n", 469 PrevThreadId, ThreadId); 470 } 471 472 PrevThreadId = ThreadId; 473 } 474 475 if (TRACE_THREADS & AcpiDbgLevel) 476 { 477 AcpiOsPrintf ("%8s-%04d[%04X]: ", ModuleName, LineNumber, ThreadId); 478 } 479 else 480 { 481 AcpiOsPrintf ("%8s-%04d: ", ModuleName, LineNumber); 482 } 483 484 AcpiOsVprintf (Format, args); 485 } 486} 487 488 489/***************************************************************************** 490 * 491 * FUNCTION: DebugPrintPrefix 492 * 493 * PARAMETERS: ModuleName - Caller's module name (for error output) 494 * LineNumber - Caller's line number (for error output) 495 * ComponentId - Caller's component ID (for error output) 496 * 497 * RETURN: None 498 * 499 * DESCRIPTION: Print the prefix part of an error message, consisting of the 500 * module name, and line number 501 * 502 ****************************************************************************/ 503 504void 505DebugPrintPrefix ( 506 NATIVE_CHAR *ModuleName, 507 UINT32 LineNumber) 508{ 509 UINT32 ThreadId; 510 511 512 ThreadId = AcpiOsGetThreadId (); 513 514 if (ThreadId != PrevThreadId) 515 { 516 if (TRACE_THREADS & AcpiDbgLevel) 517 { 518 AcpiOsPrintf ("\n**** Context Switch from TID %X to TID %X ****\n\n", 519 PrevThreadId, ThreadId); 520 } 521 522 PrevThreadId = ThreadId; 523 } 524 525 if (TRACE_THREADS & AcpiDbgLevel) 526 { 527 AcpiOsPrintf ("%8s-%04d[%04X]: ", ModuleName, LineNumber, ThreadId); 528 } 529 else 530 { 531 AcpiOsPrintf ("%8s-%04d: ", ModuleName, LineNumber); 532 } 533 534} 535 536 537/***************************************************************************** 538 * 539 * FUNCTION: DebugPrintRaw 540 * 541 * PARAMETERS: Format - Printf format field 542 * ... - Optional printf arguments 543 * 544 * RETURN: None 545 * 546 * DESCRIPTION: Print error message -- without module/line indentifiers 547 * 548 ****************************************************************************/ 549 550void 551DebugPrintRaw ( 552 NATIVE_CHAR *Format, 553 ...) 554{ 555 va_list args; 556 557 558 va_start (args, Format); 559 560 AcpiOsVprintf (Format, args); 561 562 va_end (args); 563} 564 565 566/***************************************************************************** 567 * 568 * FUNCTION: AcpiUtDumpBuffer 569 * 570 * PARAMETERS: Buffer - Buffer to dump 571 * Count - Amount to dump, in bytes 572 * ComponentID - Caller's component ID 573 * 574 * RETURN: None 575 * 576 * DESCRIPTION: Generic dump buffer in both hex and ascii. 577 * 578 ****************************************************************************/ 579 580void 581AcpiUtDumpBuffer ( 582 UINT8 *Buffer, 583 UINT32 Count, 584 UINT32 Display, 585 UINT32 ComponentId) 586{ 587 UINT32 i = 0; 588 UINT32 j; 589 UINT32 Temp32; 590 UINT8 BufChar; 591 592 593 /* Only dump the buffer if tracing is enabled */ 594 595 if (!((TRACE_TABLES & AcpiDbgLevel) && 596 (ComponentId & AcpiDbgLayer))) 597 { 598 return; 599 } 600 601 602 /* 603 * Nasty little dump buffer routine! 604 */ 605 while (i < Count) 606 { 607 /* Print current offset */ 608 609 AcpiOsPrintf ("%05X ", i); 610 611 612 /* Print 16 hex chars */ 613 614 for (j = 0; j < 16;) 615 { 616 if (i + j >= Count) 617 { 618 AcpiOsPrintf ("\n"); 619 return; 620 } 621 622 /* Make sure that the INT8 doesn't get sign-extended! */ 623 624 switch (Display) 625 { 626 /* Default is BYTE display */ 627 628 default: 629 630 AcpiOsPrintf ("%02X ", 631 *((UINT8 *) &Buffer[i + j])); 632 j += 1; 633 break; 634 635 636 case DB_WORD_DISPLAY: 637 638 MOVE_UNALIGNED16_TO_32 (&Temp32, 639 &Buffer[i + j]); 640 AcpiOsPrintf ("%04X ", Temp32); 641 j += 2; 642 break; 643 644 645 case DB_DWORD_DISPLAY: 646 647 MOVE_UNALIGNED32_TO_32 (&Temp32, 648 &Buffer[i + j]); 649 AcpiOsPrintf ("%08X ", Temp32); 650 j += 4; 651 break; 652 653 654 case DB_QWORD_DISPLAY: 655 656 MOVE_UNALIGNED32_TO_32 (&Temp32, 657 &Buffer[i + j]); 658 AcpiOsPrintf ("%08X", Temp32); 659 660 MOVE_UNALIGNED32_TO_32 (&Temp32, 661 &Buffer[i + j + 4]); 662 AcpiOsPrintf ("%08X ", Temp32); 663 j += 8; 664 break; 665 } 666 } 667 668 669 /* 670 * Print the ASCII equivalent characters 671 * But watch out for the bad unprintable ones... 672 */ 673 674 for (j = 0; j < 16; j++) 675 { 676 if (i + j >= Count) 677 { 678 AcpiOsPrintf ("\n"); 679 return; 680 } 681 682 BufChar = Buffer[i + j]; 683 if ((BufChar > 0x1F && BufChar < 0x2E) || 684 (BufChar > 0x2F && BufChar < 0x61) || 685 (BufChar > 0x60 && BufChar < 0x7F)) 686 { 687 AcpiOsPrintf ("%c", BufChar); 688 } 689 else 690 { 691 AcpiOsPrintf ("."); 692 } 693 } 694 695 /* Done with that line. */ 696 697 AcpiOsPrintf ("\n"); 698 i += 16; 699 } 700 701 return; 702} 703 704 705