1 /****************************************************************************** 2 * 3 * Module Name: utdebug - Debug print/trace routines 4 * 5 *****************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2013, Intel Corp. 12 * All rights reserved. 13 * 14 * 2. License 15 * 16 * 2.1. This is your license from Intel Corp. under its intellectual property 17 * rights. You may have additional license terms from the party that provided 18 * you this software, covering your right to use that party's intellectual 19 * property rights. 20 * 21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 * copy of the source code appearing in this file ("Covered Code") an 23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 * base code distributed originally by Intel ("Original Intel Code") to copy, 25 * make derivatives, distribute, use and display any portion of the Covered 26 * Code in any form, with the right to sublicense such rights; and 27 * 28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 * license (with the right to sublicense), under only those claims of Intel 30 * patents that are infringed by the Original Intel Code, to make, use, sell, 31 * offer to sell, and import the Covered Code and derivative works thereof 32 * solely to the minimum extent necessary to exercise the above copyright 33 * license, and in no event shall the patent license extend to any additions 34 * to or modifications of the Original Intel Code. No other license or right 35 * is granted directly or by implication, estoppel or otherwise; 36 * 37 * The above copyright and patent license is granted only if the following 38 * conditions are met: 39 * 40 * 3. Conditions 41 * 42 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 * Redistribution of source code of any substantial portion of the Covered 44 * Code or modification with rights to further distribute source must include 45 * the above Copyright Notice, the above License, this list of Conditions, 46 * and the following Disclaimer and Export Compliance provision. In addition, 47 * Licensee must cause all Covered Code to which Licensee contributes to 48 * contain a file documenting the changes Licensee made to create that Covered 49 * Code and the date of any change. Licensee must include in that file the 50 * documentation of any changes made by any predecessor Licensee. Licensee 51 * must include a prominent statement that the modification is derived, 52 * directly or indirectly, from Original Intel Code. 53 * 54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 * Redistribution of source code of any substantial portion of the Covered 56 * Code or modification without rights to further distribute source must 57 * include the following Disclaimer and Export Compliance provision in the 58 * documentation and/or other materials provided with distribution. In 59 * addition, Licensee may not authorize further sublicense of source of any 60 * portion of the Covered Code, and must include terms to the effect that the 61 * license from Licensee to its licensee is limited to the intellectual 62 * property embodied in the software Licensee provides to its licensee, and 63 * not to intellectual property embodied in modifications its licensee may 64 * make. 65 * 66 * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 * substantial portion of the Covered Code or modification must reproduce the 68 * above Copyright Notice, and the following Disclaimer and Export Compliance 69 * provision in the documentation and/or other materials provided with the 70 * distribution. 71 * 72 * 3.4. Intel retains all right, title, and interest in and to the Original 73 * Intel Code. 74 * 75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 * Intel shall be used in advertising or otherwise to promote the sale, use or 77 * other dealings in products derived from or relating to the Covered Code 78 * without prior written authorization from Intel. 79 * 80 * 4. Disclaimer and Export Compliance 81 * 82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 * PARTICULAR PURPOSE. 89 * 90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 * LIMITED REMEDY. 98 * 99 * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 * software or system incorporating such software without first obtaining any 101 * required license or other approval from the U. S. Department of Commerce or 102 * any other agency or department of the United States Government. In the 103 * event Licensee exports any such software from the United States or 104 * re-exports any such software from a foreign destination, Licensee shall 105 * ensure that the distribution and export/re-export of the software is in 106 * compliance with all laws, regulations, orders, or other restrictions of the 107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 * any of its subsidiaries will export/re-export any technical data, process, 109 * software, or service, directly or indirectly, to any country for which the 110 * United States government or any agency thereof requires an export license, 111 * other governmental approval, or letter of assurance, without first obtaining 112 * such license, approval or letter. 113 * 114 *****************************************************************************/ 115 116 #define __UTDEBUG_C__ 117 118 #include "acpi.h" 119 #include "accommon.h" 120 121 #define _COMPONENT ACPI_UTILITIES 122 ACPI_MODULE_NAME ("utdebug") 123 124 125 #ifdef ACPI_DEBUG_OUTPUT 126 127 static ACPI_THREAD_ID AcpiGbl_PrevThreadId = (ACPI_THREAD_ID) 0xFFFFFFFF; 128 static char *AcpiGbl_FnEntryStr = "----Entry"; 129 static char *AcpiGbl_FnExitStr = "----Exit-"; 130 131 /* Local prototypes */ 132 133 static const char * 134 AcpiUtTrimFunctionName ( 135 const char *FunctionName); 136 137 138 /******************************************************************************* 139 * 140 * FUNCTION: AcpiUtInitStackPtrTrace 141 * 142 * PARAMETERS: None 143 * 144 * RETURN: None 145 * 146 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup 147 * 148 ******************************************************************************/ 149 150 void 151 AcpiUtInitStackPtrTrace ( 152 void) 153 { 154 ACPI_SIZE CurrentSp; 155 156 157 AcpiGbl_EntryStackPointer = &CurrentSp; 158 } 159 160 161 /******************************************************************************* 162 * 163 * FUNCTION: AcpiUtTrackStackPtr 164 * 165 * PARAMETERS: None 166 * 167 * RETURN: None 168 * 169 * DESCRIPTION: Save the current CPU stack pointer 170 * 171 ******************************************************************************/ 172 173 void 174 AcpiUtTrackStackPtr ( 175 void) 176 { 177 ACPI_SIZE CurrentSp; 178 179 180 if (&CurrentSp < AcpiGbl_LowestStackPointer) 181 { 182 AcpiGbl_LowestStackPointer = &CurrentSp; 183 } 184 185 if (AcpiGbl_NestingLevel > AcpiGbl_DeepestNesting) 186 { 187 AcpiGbl_DeepestNesting = AcpiGbl_NestingLevel; 188 } 189 } 190 191 192 /******************************************************************************* 193 * 194 * FUNCTION: AcpiUtTrimFunctionName 195 * 196 * PARAMETERS: FunctionName - Ascii string containing a procedure name 197 * 198 * RETURN: Updated pointer to the function name 199 * 200 * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present. 201 * This allows compiler macros such as __FUNCTION__ to be used 202 * with no change to the debug output. 203 * 204 ******************************************************************************/ 205 206 static const char * 207 AcpiUtTrimFunctionName ( 208 const char *FunctionName) 209 { 210 211 /* All Function names are longer than 4 chars, check is safe */ 212 213 if (*(ACPI_CAST_PTR (UINT32, FunctionName)) == ACPI_PREFIX_MIXED) 214 { 215 /* This is the case where the original source has not been modified */ 216 217 return (FunctionName + 4); 218 } 219 220 if (*(ACPI_CAST_PTR (UINT32, FunctionName)) == ACPI_PREFIX_LOWER) 221 { 222 /* This is the case where the source has been 'linuxized' */ 223 224 return (FunctionName + 5); 225 } 226 227 return (FunctionName); 228 } 229 230 231 /******************************************************************************* 232 * 233 * FUNCTION: AcpiDebugPrint 234 * 235 * PARAMETERS: RequestedDebugLevel - Requested debug print level 236 * LineNumber - Caller's line number (for error output) 237 * FunctionName - Caller's procedure name 238 * ModuleName - Caller's module name 239 * ComponentId - Caller's component ID 240 * Format - Printf format field 241 * ... - Optional printf arguments 242 * 243 * RETURN: None 244 * 245 * DESCRIPTION: Print error message with prefix consisting of the module name, 246 * line number, and component ID. 247 * 248 ******************************************************************************/ 249 250 void ACPI_INTERNAL_VAR_XFACE 251 AcpiDebugPrint ( 252 UINT32 RequestedDebugLevel, 253 UINT32 LineNumber, 254 const char *FunctionName, 255 const char *ModuleName, 256 UINT32 ComponentId, 257 const char *Format, 258 ...) 259 { 260 ACPI_THREAD_ID ThreadId; 261 va_list args; 262 263 264 /* Check if debug output enabled */ 265 266 if (!ACPI_IS_DEBUG_ENABLED (RequestedDebugLevel, ComponentId)) 267 { 268 return; 269 } 270 271 /* 272 * Thread tracking and context switch notification 273 */ 274 ThreadId = AcpiOsGetThreadId (); 275 if (ThreadId != AcpiGbl_PrevThreadId) 276 { 277 if (ACPI_LV_THREADS & AcpiDbgLevel) 278 { 279 AcpiOsPrintf ( 280 "\n**** Context Switch from TID %u to TID %u ****\n\n", 281 (UINT32) AcpiGbl_PrevThreadId, (UINT32) ThreadId); 282 } 283 284 AcpiGbl_PrevThreadId = ThreadId; 285 } 286 287 /* 288 * Display the module name, current line number, thread ID (if requested), 289 * current procedure nesting level, and the current procedure name 290 */ 291 AcpiOsPrintf ("%9s-%04ld ", ModuleName, LineNumber); 292 293 if (ACPI_LV_THREADS & AcpiDbgLevel) 294 { 295 AcpiOsPrintf ("[%u] ", (UINT32) ThreadId); 296 } 297 298 AcpiOsPrintf ("[%02ld] %-22.22s: ", 299 AcpiGbl_NestingLevel, AcpiUtTrimFunctionName (FunctionName)); 300 301 va_start (args, Format); 302 AcpiOsVprintf (Format, args); 303 va_end (args); 304 } 305 306 ACPI_EXPORT_SYMBOL (AcpiDebugPrint) 307 308 309 /******************************************************************************* 310 * 311 * FUNCTION: AcpiDebugPrintRaw 312 * 313 * PARAMETERS: RequestedDebugLevel - Requested debug print level 314 * LineNumber - Caller's line number 315 * FunctionName - Caller's procedure name 316 * ModuleName - Caller's module name 317 * ComponentId - Caller's component ID 318 * Format - Printf format field 319 * ... - Optional printf arguments 320 * 321 * RETURN: None 322 * 323 * DESCRIPTION: Print message with no headers. Has same interface as 324 * DebugPrint so that the same macros can be used. 325 * 326 ******************************************************************************/ 327 328 void ACPI_INTERNAL_VAR_XFACE 329 AcpiDebugPrintRaw ( 330 UINT32 RequestedDebugLevel, 331 UINT32 LineNumber, 332 const char *FunctionName, 333 const char *ModuleName, 334 UINT32 ComponentId, 335 const char *Format, 336 ...) 337 { 338 va_list args; 339 340 341 /* Check if debug output enabled */ 342 343 if (!ACPI_IS_DEBUG_ENABLED (RequestedDebugLevel, ComponentId)) 344 { 345 return; 346 } 347 348 va_start (args, Format); 349 AcpiOsVprintf (Format, args); 350 va_end (args); 351 } 352 353 ACPI_EXPORT_SYMBOL (AcpiDebugPrintRaw) 354 355 356 /******************************************************************************* 357 * 358 * FUNCTION: AcpiUtTrace 359 * 360 * PARAMETERS: LineNumber - Caller's line number 361 * FunctionName - Caller's procedure name 362 * ModuleName - Caller's module name 363 * ComponentId - Caller's component ID 364 * 365 * RETURN: None 366 * 367 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 368 * set in DebugLevel 369 * 370 ******************************************************************************/ 371 372 void 373 AcpiUtTrace ( 374 UINT32 LineNumber, 375 const char *FunctionName, 376 const char *ModuleName, 377 UINT32 ComponentId) 378 { 379 380 AcpiGbl_NestingLevel++; 381 AcpiUtTrackStackPtr (); 382 383 /* Check if enabled up-front for performance */ 384 385 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId)) 386 { 387 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 388 LineNumber, FunctionName, ModuleName, ComponentId, 389 "%s\n", AcpiGbl_FnEntryStr); 390 } 391 } 392 393 ACPI_EXPORT_SYMBOL (AcpiUtTrace) 394 395 396 /******************************************************************************* 397 * 398 * FUNCTION: AcpiUtTracePtr 399 * 400 * PARAMETERS: LineNumber - Caller's line number 401 * FunctionName - Caller's procedure name 402 * ModuleName - Caller's module name 403 * ComponentId - Caller's component ID 404 * Pointer - Pointer to display 405 * 406 * RETURN: None 407 * 408 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 409 * set in DebugLevel 410 * 411 ******************************************************************************/ 412 413 void 414 AcpiUtTracePtr ( 415 UINT32 LineNumber, 416 const char *FunctionName, 417 const char *ModuleName, 418 UINT32 ComponentId, 419 void *Pointer) 420 { 421 422 AcpiGbl_NestingLevel++; 423 AcpiUtTrackStackPtr (); 424 425 /* Check if enabled up-front for performance */ 426 427 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId)) 428 { 429 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 430 LineNumber, FunctionName, ModuleName, ComponentId, 431 "%s %p\n", AcpiGbl_FnEntryStr, Pointer); 432 } 433 } 434 435 436 /******************************************************************************* 437 * 438 * FUNCTION: AcpiUtTraceStr 439 * 440 * PARAMETERS: LineNumber - Caller's line number 441 * FunctionName - Caller's procedure name 442 * ModuleName - Caller's module name 443 * ComponentId - Caller's component ID 444 * String - Additional string to display 445 * 446 * RETURN: None 447 * 448 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 449 * set in DebugLevel 450 * 451 ******************************************************************************/ 452 453 void 454 AcpiUtTraceStr ( 455 UINT32 LineNumber, 456 const char *FunctionName, 457 const char *ModuleName, 458 UINT32 ComponentId, 459 char *String) 460 { 461 462 AcpiGbl_NestingLevel++; 463 AcpiUtTrackStackPtr (); 464 465 /* Check if enabled up-front for performance */ 466 467 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId)) 468 { 469 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 470 LineNumber, FunctionName, ModuleName, ComponentId, 471 "%s %s\n", AcpiGbl_FnEntryStr, String); 472 } 473 } 474 475 476 /******************************************************************************* 477 * 478 * FUNCTION: AcpiUtTraceU32 479 * 480 * PARAMETERS: LineNumber - Caller's line number 481 * FunctionName - Caller's procedure name 482 * ModuleName - Caller's module name 483 * ComponentId - Caller's component ID 484 * Integer - Integer to display 485 * 486 * RETURN: None 487 * 488 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 489 * set in DebugLevel 490 * 491 ******************************************************************************/ 492 493 void 494 AcpiUtTraceU32 ( 495 UINT32 LineNumber, 496 const char *FunctionName, 497 const char *ModuleName, 498 UINT32 ComponentId, 499 UINT32 Integer) 500 { 501 502 AcpiGbl_NestingLevel++; 503 AcpiUtTrackStackPtr (); 504 505 /* Check if enabled up-front for performance */ 506 507 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId)) 508 { 509 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 510 LineNumber, FunctionName, ModuleName, ComponentId, 511 "%s %08X\n", AcpiGbl_FnEntryStr, Integer); 512 } 513 } 514 515 516 /******************************************************************************* 517 * 518 * FUNCTION: AcpiUtExit 519 * 520 * PARAMETERS: LineNumber - Caller's line number 521 * FunctionName - Caller's procedure name 522 * ModuleName - Caller's module name 523 * ComponentId - Caller's component ID 524 * 525 * RETURN: None 526 * 527 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 528 * set in DebugLevel 529 * 530 ******************************************************************************/ 531 532 void 533 AcpiUtExit ( 534 UINT32 LineNumber, 535 const char *FunctionName, 536 const char *ModuleName, 537 UINT32 ComponentId) 538 { 539 540 /* Check if enabled up-front for performance */ 541 542 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId)) 543 { 544 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 545 LineNumber, FunctionName, ModuleName, ComponentId, 546 "%s\n", AcpiGbl_FnExitStr); 547 } 548 549 AcpiGbl_NestingLevel--; 550 } 551 552 ACPI_EXPORT_SYMBOL (AcpiUtExit) 553 554 555 /******************************************************************************* 556 * 557 * FUNCTION: AcpiUtStatusExit 558 * 559 * PARAMETERS: LineNumber - Caller's line number 560 * FunctionName - Caller's procedure name 561 * ModuleName - Caller's module name 562 * ComponentId - Caller's component ID 563 * Status - Exit status code 564 * 565 * RETURN: None 566 * 567 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 568 * set in DebugLevel. Prints exit status also. 569 * 570 ******************************************************************************/ 571 572 void 573 AcpiUtStatusExit ( 574 UINT32 LineNumber, 575 const char *FunctionName, 576 const char *ModuleName, 577 UINT32 ComponentId, 578 ACPI_STATUS Status) 579 { 580 581 /* Check if enabled up-front for performance */ 582 583 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId)) 584 { 585 if (ACPI_SUCCESS (Status)) 586 { 587 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 588 LineNumber, FunctionName, ModuleName, ComponentId, 589 "%s %s\n", AcpiGbl_FnExitStr, 590 AcpiFormatException (Status)); 591 } 592 else 593 { 594 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 595 LineNumber, FunctionName, ModuleName, ComponentId, 596 "%s ****Exception****: %s\n", AcpiGbl_FnExitStr, 597 AcpiFormatException (Status)); 598 } 599 } 600 601 AcpiGbl_NestingLevel--; 602 } 603 604 ACPI_EXPORT_SYMBOL (AcpiUtStatusExit) 605 606 607 /******************************************************************************* 608 * 609 * FUNCTION: AcpiUtValueExit 610 * 611 * PARAMETERS: LineNumber - Caller's line number 612 * FunctionName - Caller's procedure name 613 * ModuleName - Caller's module name 614 * ComponentId - Caller's component ID 615 * Value - Value to be printed with exit msg 616 * 617 * RETURN: None 618 * 619 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 620 * set in DebugLevel. Prints exit value also. 621 * 622 ******************************************************************************/ 623 624 void 625 AcpiUtValueExit ( 626 UINT32 LineNumber, 627 const char *FunctionName, 628 const char *ModuleName, 629 UINT32 ComponentId, 630 UINT64 Value) 631 { 632 633 /* Check if enabled up-front for performance */ 634 635 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId)) 636 { 637 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 638 LineNumber, FunctionName, ModuleName, ComponentId, 639 "%s %8.8X%8.8X\n", AcpiGbl_FnExitStr, 640 ACPI_FORMAT_UINT64 (Value)); 641 } 642 643 AcpiGbl_NestingLevel--; 644 } 645 646 ACPI_EXPORT_SYMBOL (AcpiUtValueExit) 647 648 649 /******************************************************************************* 650 * 651 * FUNCTION: AcpiUtPtrExit 652 * 653 * PARAMETERS: LineNumber - Caller's line number 654 * FunctionName - Caller's procedure name 655 * ModuleName - Caller's module name 656 * ComponentId - Caller's component ID 657 * Ptr - Pointer to display 658 * 659 * RETURN: None 660 * 661 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 662 * set in DebugLevel. Prints exit value also. 663 * 664 ******************************************************************************/ 665 666 void 667 AcpiUtPtrExit ( 668 UINT32 LineNumber, 669 const char *FunctionName, 670 const char *ModuleName, 671 UINT32 ComponentId, 672 UINT8 *Ptr) 673 { 674 675 /* Check if enabled up-front for performance */ 676 677 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId)) 678 { 679 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 680 LineNumber, FunctionName, ModuleName, ComponentId, 681 "%s %p\n", AcpiGbl_FnExitStr, Ptr); 682 } 683 684 AcpiGbl_NestingLevel--; 685 } 686 687 #endif 688