utdebug.c revision 85756
1/****************************************************************************** 2 * 3 * Module Name: utdebug - Debug print routines 4 * $Revision: 90 $ 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 AcpiGbl_PrevThreadId = 0xFFFFFFFF; 126char *AcpiGbl_FnEntryStr = "----Entry"; 127char *AcpiGbl_FnExitStr = "----Exit-"; 128 129 130 131#ifdef ACPI_DEBUG 132 133 134/***************************************************************************** 135 * 136 * FUNCTION: AcpiUtInitStackPtrTrace 137 * 138 * PARAMETERS: None 139 * 140 * RETURN: None 141 * 142 * DESCRIPTION: Save the current stack pointer 143 * 144 ****************************************************************************/ 145 146void 147AcpiUtInitStackPtrTrace ( 148 void) 149{ 150 UINT32 CurrentSp; 151 152 153 AcpiGbl_EntryStackPointer = (UINT32) &CurrentSp; 154} 155 156 157/***************************************************************************** 158 * 159 * FUNCTION: AcpiUtTrackStackPtr 160 * 161 * PARAMETERS: None 162 * 163 * RETURN: None 164 * 165 * DESCRIPTION: Save the current stack pointer 166 * 167 ****************************************************************************/ 168 169void 170AcpiUtTrackStackPtr ( 171 void) 172{ 173 UINT32 CurrentSp; 174 175 CurrentSp = (UINT32) &CurrentSp; 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 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 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, HIDWORD(Value), LODWORD(Value)); 537 538 AcpiGbl_NestingLevel--; 539} 540 541 542/***************************************************************************** 543 * 544 * FUNCTION: AcpiUtPtrExit 545 * 546 * PARAMETERS: LineNumber - Caller's line number 547 * DbgInfo - Contains: 548 * ProcName - Caller's procedure name 549 * ModuleName - Caller's module name 550 * ComponentId - Caller's component ID 551 * Value - Value to be printed with exit msg 552 * 553 * RETURN: None 554 * 555 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 556 * set in DebugLevel. Prints exit value also. 557 * 558 ****************************************************************************/ 559 560void 561AcpiUtPtrExit ( 562 UINT32 LineNumber, 563 ACPI_DEBUG_PRINT_INFO *DbgInfo, 564 UINT8 *Ptr) 565{ 566 567 AcpiUtDebugPrint (ACPI_LV_FUNCTIONS, LineNumber, DbgInfo, 568 "%s %p\n", AcpiGbl_FnExitStr, Ptr); 569 570 AcpiGbl_NestingLevel--; 571} 572 573#endif 574 575 576 577 578/***************************************************************************** 579 * 580 * FUNCTION: AcpiUtDumpBuffer 581 * 582 * PARAMETERS: Buffer - Buffer to dump 583 * Count - Amount to dump, in bytes 584 * Display - BYTE, WORD, DWORD, or QWORD display 585 * ComponentID - Caller's component ID 586 * 587 * RETURN: None 588 * 589 * DESCRIPTION: Generic dump buffer in both hex and ascii. 590 * 591 ****************************************************************************/ 592 593void 594AcpiUtDumpBuffer ( 595 UINT8 *Buffer, 596 UINT32 Count, 597 UINT32 Display, 598 UINT32 ComponentId) 599{ 600 UINT32 i = 0; 601 UINT32 j; 602 UINT32 Temp32; 603 UINT8 BufChar; 604 605 606 /* Only dump the buffer if tracing is enabled */ 607 608 if (!((ACPI_LV_TABLES & AcpiDbgLevel) && 609 (ComponentId & AcpiDbgLayer))) 610 { 611 return; 612 } 613 614 615 /* 616 * Nasty little dump buffer routine! 617 */ 618 while (i < Count) 619 { 620 /* Print current offset */ 621 622 AcpiOsPrintf ("%05X ", i); 623 624 625 /* Print 16 hex chars */ 626 627 for (j = 0; j < 16;) 628 { 629 if (i + j >= Count) 630 { 631 AcpiOsPrintf ("\n"); 632 return; 633 } 634 635 /* Make sure that the INT8 doesn't get sign-extended! */ 636 637 switch (Display) 638 { 639 /* Default is BYTE display */ 640 641 default: 642 643 AcpiOsPrintf ("%02X ", 644 *((UINT8 *) &Buffer[i + j])); 645 j += 1; 646 break; 647 648 649 case DB_WORD_DISPLAY: 650 651 MOVE_UNALIGNED16_TO_32 (&Temp32, 652 &Buffer[i + j]); 653 AcpiOsPrintf ("%04X ", Temp32); 654 j += 2; 655 break; 656 657 658 case DB_DWORD_DISPLAY: 659 660 MOVE_UNALIGNED32_TO_32 (&Temp32, 661 &Buffer[i + j]); 662 AcpiOsPrintf ("%08X ", Temp32); 663 j += 4; 664 break; 665 666 667 case DB_QWORD_DISPLAY: 668 669 MOVE_UNALIGNED32_TO_32 (&Temp32, 670 &Buffer[i + j]); 671 AcpiOsPrintf ("%08X", Temp32); 672 673 MOVE_UNALIGNED32_TO_32 (&Temp32, 674 &Buffer[i + j + 4]); 675 AcpiOsPrintf ("%08X ", Temp32); 676 j += 8; 677 break; 678 } 679 } 680 681 682 /* 683 * Print the ASCII equivalent characters 684 * But watch out for the bad unprintable ones... 685 */ 686 687 for (j = 0; j < 16; j++) 688 { 689 if (i + j >= Count) 690 { 691 AcpiOsPrintf ("\n"); 692 return; 693 } 694 695 BufChar = Buffer[i + j]; 696 if ((BufChar > 0x1F && BufChar < 0x2E) || 697 (BufChar > 0x2F && BufChar < 0x61) || 698 (BufChar > 0x60 && BufChar < 0x7F)) 699 { 700 AcpiOsPrintf ("%c", BufChar); 701 } 702 else 703 { 704 AcpiOsPrintf ("."); 705 } 706 } 707 708 /* Done with that line. */ 709 710 AcpiOsPrintf ("\n"); 711 i += 16; 712 } 713 714 return; 715} 716 717