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