1 /****************************************************************************** 2 * 3 * Module Name: utdebug - Debug print routines 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2011, Intel Corp. 9 * All rights reserved. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions, and the following disclaimer, 16 * without modification. 17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18 * substantially similar to the "NO WARRANTY" disclaimer below 19 * ("Disclaimer") and any redistribution must be conditioned upon 20 * including a substantially similar Disclaimer requirement for further 21 * binary redistribution. 22 * 3. Neither the names of the above-listed copyright holders nor the names 23 * of any contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * Alternatively, this software may be distributed under the terms of the 27 * GNU General Public License ("GPL") version 2 as published by the Free 28 * Software Foundation. 29 * 30 * NO WARRANTY 31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41 * POSSIBILITY OF SUCH DAMAGES. 42 */ 43 44 #define __UTDEBUG_C__ 45 46 #include "acpi.h" 47 #include "accommon.h" 48 49 #define _COMPONENT ACPI_UTILITIES 50 ACPI_MODULE_NAME ("utdebug") 51 52 53 #ifdef ACPI_DEBUG_OUTPUT 54 55 static ACPI_THREAD_ID AcpiGbl_PrevThreadId = (ACPI_THREAD_ID) 0xFFFFFFFF; 56 static char *AcpiGbl_FnEntryStr = "----Entry"; 57 static char *AcpiGbl_FnExitStr = "----Exit-"; 58 59 /* Local prototypes */ 60 61 static const char * 62 AcpiUtTrimFunctionName ( 63 const char *FunctionName); 64 65 66 /******************************************************************************* 67 * 68 * FUNCTION: AcpiUtInitStackPtrTrace 69 * 70 * PARAMETERS: None 71 * 72 * RETURN: None 73 * 74 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup 75 * 76 ******************************************************************************/ 77 78 void 79 AcpiUtInitStackPtrTrace ( 80 void) 81 { 82 ACPI_SIZE CurrentSp; 83 84 85 AcpiGbl_EntryStackPointer = &CurrentSp; 86 } 87 88 89 /******************************************************************************* 90 * 91 * FUNCTION: AcpiUtTrackStackPtr 92 * 93 * PARAMETERS: None 94 * 95 * RETURN: None 96 * 97 * DESCRIPTION: Save the current CPU stack pointer 98 * 99 ******************************************************************************/ 100 101 void 102 AcpiUtTrackStackPtr ( 103 void) 104 { 105 ACPI_SIZE CurrentSp; 106 107 108 if (&CurrentSp < AcpiGbl_LowestStackPointer) 109 { 110 AcpiGbl_LowestStackPointer = &CurrentSp; 111 } 112 113 if (AcpiGbl_NestingLevel > AcpiGbl_DeepestNesting) 114 { 115 AcpiGbl_DeepestNesting = AcpiGbl_NestingLevel; 116 } 117 } 118 119 120 /******************************************************************************* 121 * 122 * FUNCTION: AcpiUtTrimFunctionName 123 * 124 * PARAMETERS: FunctionName - Ascii string containing a procedure name 125 * 126 * RETURN: Updated pointer to the function name 127 * 128 * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present. 129 * This allows compiler macros such as __FUNCTION__ to be used 130 * with no change to the debug output. 131 * 132 ******************************************************************************/ 133 134 static const char * 135 AcpiUtTrimFunctionName ( 136 const char *FunctionName) 137 { 138 139 /* All Function names are longer than 4 chars, check is safe */ 140 141 if (*(ACPI_CAST_PTR (UINT32, FunctionName)) == ACPI_PREFIX_MIXED) 142 { 143 /* This is the case where the original source has not been modified */ 144 145 return (FunctionName + 4); 146 } 147 148 if (*(ACPI_CAST_PTR (UINT32, FunctionName)) == ACPI_PREFIX_LOWER) 149 { 150 /* This is the case where the source has been 'linuxized' */ 151 152 return (FunctionName + 5); 153 } 154 155 return (FunctionName); 156 } 157 158 159 /******************************************************************************* 160 * 161 * FUNCTION: AcpiDebugPrint 162 * 163 * PARAMETERS: RequestedDebugLevel - Requested debug print level 164 * LineNumber - Caller's line number (for error output) 165 * FunctionName - Caller's procedure name 166 * ModuleName - Caller's module name 167 * ComponentId - Caller's component ID 168 * Format - Printf format field 169 * ... - Optional printf arguments 170 * 171 * RETURN: None 172 * 173 * DESCRIPTION: Print error message with prefix consisting of the module name, 174 * line number, and component ID. 175 * 176 ******************************************************************************/ 177 178 void ACPI_INTERNAL_VAR_XFACE 179 AcpiDebugPrint ( 180 UINT32 RequestedDebugLevel, 181 UINT32 LineNumber, 182 const char *FunctionName, 183 const char *ModuleName, 184 UINT32 ComponentId, 185 const char *Format, 186 ...) 187 { 188 ACPI_THREAD_ID ThreadId; 189 va_list args; 190 191 192 /* 193 * Stay silent if the debug level or component ID is disabled 194 */ 195 if (!(RequestedDebugLevel & AcpiDbgLevel) || 196 !(ComponentId & AcpiDbgLayer)) 197 { 198 return; 199 } 200 201 /* 202 * Thread tracking and context switch notification 203 */ 204 ThreadId = AcpiOsGetThreadId (); 205 if (ThreadId != AcpiGbl_PrevThreadId) 206 { 207 if (ACPI_LV_THREADS & AcpiDbgLevel) 208 { 209 AcpiOsPrintf ( 210 "\n**** Context Switch from TID %u to TID %u ****\n\n", 211 (UINT32) AcpiGbl_PrevThreadId, (UINT32) ThreadId); 212 } 213 214 AcpiGbl_PrevThreadId = ThreadId; 215 } 216 217 /* 218 * Display the module name, current line number, thread ID (if requested), 219 * current procedure nesting level, and the current procedure name 220 */ 221 AcpiOsPrintf ("%8s-%04ld ", ModuleName, LineNumber); 222 223 if (ACPI_LV_THREADS & AcpiDbgLevel) 224 { 225 AcpiOsPrintf ("[%u] ", (UINT32) ThreadId); 226 } 227 228 AcpiOsPrintf ("[%02ld] %-22.22s: ", 229 AcpiGbl_NestingLevel, AcpiUtTrimFunctionName (FunctionName)); 230 231 va_start (args, Format); 232 AcpiOsVprintf (Format, args); 233 va_end (args); 234 } 235 236 ACPI_EXPORT_SYMBOL (AcpiDebugPrint) 237 238 239 /******************************************************************************* 240 * 241 * FUNCTION: AcpiDebugPrintRaw 242 * 243 * PARAMETERS: RequestedDebugLevel - Requested debug print level 244 * LineNumber - Caller's line number 245 * FunctionName - Caller's procedure name 246 * ModuleName - Caller's module name 247 * ComponentId - Caller's component ID 248 * Format - Printf format field 249 * ... - Optional printf arguments 250 * 251 * RETURN: None 252 * 253 * DESCRIPTION: Print message with no headers. Has same interface as 254 * DebugPrint so that the same macros can be used. 255 * 256 ******************************************************************************/ 257 258 void ACPI_INTERNAL_VAR_XFACE 259 AcpiDebugPrintRaw ( 260 UINT32 RequestedDebugLevel, 261 UINT32 LineNumber, 262 const char *FunctionName, 263 const char *ModuleName, 264 UINT32 ComponentId, 265 const char *Format, 266 ...) 267 { 268 va_list args; 269 270 271 if (!(RequestedDebugLevel & AcpiDbgLevel) || 272 !(ComponentId & AcpiDbgLayer)) 273 { 274 return; 275 } 276 277 va_start (args, Format); 278 AcpiOsVprintf (Format, args); 279 va_end (args); 280 } 281 282 ACPI_EXPORT_SYMBOL (AcpiDebugPrintRaw) 283 284 285 /******************************************************************************* 286 * 287 * FUNCTION: AcpiUtTrace 288 * 289 * PARAMETERS: LineNumber - Caller's line number 290 * FunctionName - Caller's procedure name 291 * ModuleName - Caller's module name 292 * ComponentId - Caller's component ID 293 * 294 * RETURN: None 295 * 296 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 297 * set in DebugLevel 298 * 299 ******************************************************************************/ 300 301 void 302 AcpiUtTrace ( 303 UINT32 LineNumber, 304 const char *FunctionName, 305 const char *ModuleName, 306 UINT32 ComponentId) 307 { 308 309 AcpiGbl_NestingLevel++; 310 AcpiUtTrackStackPtr (); 311 312 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 313 LineNumber, FunctionName, ModuleName, ComponentId, 314 "%s\n", AcpiGbl_FnEntryStr); 315 } 316 317 ACPI_EXPORT_SYMBOL (AcpiUtTrace) 318 319 320 /******************************************************************************* 321 * 322 * FUNCTION: AcpiUtTracePtr 323 * 324 * PARAMETERS: LineNumber - Caller's line number 325 * FunctionName - Caller's procedure name 326 * ModuleName - Caller's module name 327 * ComponentId - Caller's component ID 328 * Pointer - Pointer to display 329 * 330 * RETURN: None 331 * 332 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 333 * set in DebugLevel 334 * 335 ******************************************************************************/ 336 337 void 338 AcpiUtTracePtr ( 339 UINT32 LineNumber, 340 const char *FunctionName, 341 const char *ModuleName, 342 UINT32 ComponentId, 343 void *Pointer) 344 { 345 AcpiGbl_NestingLevel++; 346 AcpiUtTrackStackPtr (); 347 348 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 349 LineNumber, FunctionName, ModuleName, ComponentId, 350 "%s %p\n", AcpiGbl_FnEntryStr, Pointer); 351 } 352 353 354 /******************************************************************************* 355 * 356 * FUNCTION: AcpiUtTraceStr 357 * 358 * PARAMETERS: LineNumber - Caller's line number 359 * FunctionName - Caller's procedure name 360 * ModuleName - Caller's module name 361 * ComponentId - Caller's component ID 362 * String - Additional string to display 363 * 364 * RETURN: None 365 * 366 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 367 * set in DebugLevel 368 * 369 ******************************************************************************/ 370 371 void 372 AcpiUtTraceStr ( 373 UINT32 LineNumber, 374 const char *FunctionName, 375 const char *ModuleName, 376 UINT32 ComponentId, 377 char *String) 378 { 379 380 AcpiGbl_NestingLevel++; 381 AcpiUtTrackStackPtr (); 382 383 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 384 LineNumber, FunctionName, ModuleName, ComponentId, 385 "%s %s\n", AcpiGbl_FnEntryStr, String); 386 } 387 388 389 /******************************************************************************* 390 * 391 * FUNCTION: AcpiUtTraceU32 392 * 393 * PARAMETERS: LineNumber - Caller's line number 394 * FunctionName - Caller's procedure name 395 * ModuleName - Caller's module name 396 * ComponentId - Caller's component ID 397 * Integer - Integer to display 398 * 399 * RETURN: None 400 * 401 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 402 * set in DebugLevel 403 * 404 ******************************************************************************/ 405 406 void 407 AcpiUtTraceU32 ( 408 UINT32 LineNumber, 409 const char *FunctionName, 410 const char *ModuleName, 411 UINT32 ComponentId, 412 UINT32 Integer) 413 { 414 415 AcpiGbl_NestingLevel++; 416 AcpiUtTrackStackPtr (); 417 418 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 419 LineNumber, FunctionName, ModuleName, ComponentId, 420 "%s %08X\n", AcpiGbl_FnEntryStr, Integer); 421 } 422 423 424 /******************************************************************************* 425 * 426 * FUNCTION: AcpiUtExit 427 * 428 * PARAMETERS: LineNumber - Caller's line number 429 * FunctionName - Caller's procedure name 430 * ModuleName - Caller's module name 431 * ComponentId - Caller's component ID 432 * 433 * RETURN: None 434 * 435 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 436 * set in DebugLevel 437 * 438 ******************************************************************************/ 439 440 void 441 AcpiUtExit ( 442 UINT32 LineNumber, 443 const char *FunctionName, 444 const char *ModuleName, 445 UINT32 ComponentId) 446 { 447 448 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 449 LineNumber, FunctionName, ModuleName, ComponentId, 450 "%s\n", AcpiGbl_FnExitStr); 451 452 AcpiGbl_NestingLevel--; 453 } 454 455 ACPI_EXPORT_SYMBOL (AcpiUtExit) 456 457 458 /******************************************************************************* 459 * 460 * FUNCTION: AcpiUtStatusExit 461 * 462 * PARAMETERS: LineNumber - Caller's line number 463 * FunctionName - Caller's procedure name 464 * ModuleName - Caller's module name 465 * ComponentId - Caller's component ID 466 * Status - Exit status code 467 * 468 * RETURN: None 469 * 470 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 471 * set in DebugLevel. Prints exit status also. 472 * 473 ******************************************************************************/ 474 475 void 476 AcpiUtStatusExit ( 477 UINT32 LineNumber, 478 const char *FunctionName, 479 const char *ModuleName, 480 UINT32 ComponentId, 481 ACPI_STATUS Status) 482 { 483 484 if (ACPI_SUCCESS (Status)) 485 { 486 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 487 LineNumber, FunctionName, ModuleName, ComponentId, 488 "%s %s\n", AcpiGbl_FnExitStr, 489 AcpiFormatException (Status)); 490 } 491 else 492 { 493 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 494 LineNumber, FunctionName, ModuleName, ComponentId, 495 "%s ****Exception****: %s\n", AcpiGbl_FnExitStr, 496 AcpiFormatException (Status)); 497 } 498 499 AcpiGbl_NestingLevel--; 500 } 501 502 ACPI_EXPORT_SYMBOL (AcpiUtStatusExit) 503 504 505 /******************************************************************************* 506 * 507 * FUNCTION: AcpiUtValueExit 508 * 509 * PARAMETERS: LineNumber - Caller's line number 510 * FunctionName - Caller's procedure name 511 * ModuleName - Caller's module name 512 * ComponentId - Caller's component ID 513 * Value - Value to be printed with exit msg 514 * 515 * RETURN: None 516 * 517 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 518 * set in DebugLevel. Prints exit value also. 519 * 520 ******************************************************************************/ 521 522 void 523 AcpiUtValueExit ( 524 UINT32 LineNumber, 525 const char *FunctionName, 526 const char *ModuleName, 527 UINT32 ComponentId, 528 UINT64 Value) 529 { 530 531 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 532 LineNumber, FunctionName, ModuleName, ComponentId, 533 "%s %8.8X%8.8X\n", AcpiGbl_FnExitStr, 534 ACPI_FORMAT_UINT64 (Value)); 535 536 AcpiGbl_NestingLevel--; 537 } 538 539 ACPI_EXPORT_SYMBOL (AcpiUtValueExit) 540 541 542 /******************************************************************************* 543 * 544 * FUNCTION: AcpiUtPtrExit 545 * 546 * PARAMETERS: LineNumber - Caller's line number 547 * FunctionName - Caller's procedure name 548 * ModuleName - Caller's module name 549 * ComponentId - Caller's component ID 550 * Ptr - Pointer to display 551 * 552 * RETURN: None 553 * 554 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 555 * set in DebugLevel. Prints exit value also. 556 * 557 ******************************************************************************/ 558 559 void 560 AcpiUtPtrExit ( 561 UINT32 LineNumber, 562 const char *FunctionName, 563 const char *ModuleName, 564 UINT32 ComponentId, 565 UINT8 *Ptr) 566 { 567 568 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 569 LineNumber, FunctionName, ModuleName, ComponentId, 570 "%s %p\n", AcpiGbl_FnExitStr, Ptr); 571 572 AcpiGbl_NestingLevel--; 573 } 574 575 #endif 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 593 void 594 AcpiUtDumpBuffer2 ( 595 UINT8 *Buffer, 596 UINT32 Count, 597 UINT32 Display) 598 { 599 UINT32 i = 0; 600 UINT32 j; 601 UINT32 Temp32; 602 UINT8 BufChar; 603 604 605 if (!Buffer) 606 { 607 AcpiOsPrintf ("Null Buffer Pointer in DumpBuffer!\n"); 608 return; 609 } 610 611 if ((Count < 4) || (Count & 0x01)) 612 { 613 Display = DB_BYTE_DISPLAY; 614 } 615 616 /* Nasty little dump buffer routine! */ 617 618 while (i < Count) 619 { 620 /* Print current offset */ 621 622 AcpiOsPrintf ("%6.4X: ", i); 623 624 /* Print 16 hex chars */ 625 626 for (j = 0; j < 16;) 627 { 628 if (i + j >= Count) 629 { 630 /* Dump fill spaces */ 631 632 AcpiOsPrintf ("%*s", ((Display * 2) + 1), " "); 633 j += Display; 634 continue; 635 } 636 637 switch (Display) 638 { 639 case DB_BYTE_DISPLAY: 640 default: /* Default is BYTE display */ 641 642 AcpiOsPrintf ("%02X ", Buffer[(ACPI_SIZE) i + j]); 643 break; 644 645 646 case DB_WORD_DISPLAY: 647 648 ACPI_MOVE_16_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]); 649 AcpiOsPrintf ("%04X ", Temp32); 650 break; 651 652 653 case DB_DWORD_DISPLAY: 654 655 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]); 656 AcpiOsPrintf ("%08X ", Temp32); 657 break; 658 659 660 case DB_QWORD_DISPLAY: 661 662 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j]); 663 AcpiOsPrintf ("%08X", Temp32); 664 665 ACPI_MOVE_32_TO_32 (&Temp32, &Buffer[(ACPI_SIZE) i + j + 4]); 666 AcpiOsPrintf ("%08X ", Temp32); 667 break; 668 } 669 670 j += Display; 671 } 672 673 /* 674 * Print the ASCII equivalent characters but watch out for the bad 675 * unprintable ones (printable chars are 0x20 through 0x7E) 676 */ 677 AcpiOsPrintf (" "); 678 for (j = 0; j < 16; j++) 679 { 680 if (i + j >= Count) 681 { 682 AcpiOsPrintf ("\n"); 683 return; 684 } 685 686 BufChar = Buffer[(ACPI_SIZE) i + j]; 687 if (ACPI_IS_PRINT (BufChar)) 688 { 689 AcpiOsPrintf ("%c", BufChar); 690 } 691 else 692 { 693 AcpiOsPrintf ("."); 694 } 695 } 696 697 /* Done with that line. */ 698 699 AcpiOsPrintf ("\n"); 700 i += 16; 701 } 702 703 return; 704 } 705 706 707 /******************************************************************************* 708 * 709 * FUNCTION: AcpiUtDumpBuffer 710 * 711 * PARAMETERS: Buffer - Buffer to dump 712 * Count - Amount to dump, in bytes 713 * Display - BYTE, WORD, DWORD, or QWORD display 714 * ComponentID - Caller's component ID 715 * 716 * RETURN: None 717 * 718 * DESCRIPTION: Generic dump buffer in both hex and ascii. 719 * 720 ******************************************************************************/ 721 722 void 723 AcpiUtDumpBuffer ( 724 UINT8 *Buffer, 725 UINT32 Count, 726 UINT32 Display, 727 UINT32 ComponentId) 728 { 729 730 /* Only dump the buffer if tracing is enabled */ 731 732 if (!((ACPI_LV_TABLES & AcpiDbgLevel) && 733 (ComponentId & AcpiDbgLayer))) 734 { 735 return; 736 } 737 738 AcpiUtDumpBuffer2 (Buffer, Count, Display); 739 } 740 741 742