1 /****************************************************************************** 2 * 3 * Module Name: utdebug - Debug print/trace routines 4 * 5 *****************************************************************************/ 6 7 /* 8 * Copyright (C) 2000 - 2014, 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 #define EXPORT_ACPI_INTERFACES 46 47 #include <contrib/dev/acpica/include/acpi.h> 48 #include <contrib/dev/acpica/include/accommon.h> 49 50 #define _COMPONENT ACPI_UTILITIES 51 ACPI_MODULE_NAME ("utdebug") 52 53 54 #ifdef ACPI_DEBUG_OUTPUT 55 56 static ACPI_THREAD_ID AcpiGbl_PrevThreadId = (ACPI_THREAD_ID) 0xFFFFFFFF; 57 static char *AcpiGbl_FnEntryStr = "----Entry"; 58 static char *AcpiGbl_FnExitStr = "----Exit-"; 59 60 /* Local prototypes */ 61 62 static const char * 63 AcpiUtTrimFunctionName ( 64 const char *FunctionName); 65 66 67 /******************************************************************************* 68 * 69 * FUNCTION: AcpiUtInitStackPtrTrace 70 * 71 * PARAMETERS: None 72 * 73 * RETURN: None 74 * 75 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup 76 * 77 ******************************************************************************/ 78 79 void 80 AcpiUtInitStackPtrTrace ( 81 void) 82 { 83 ACPI_SIZE CurrentSp; 84 85 86 AcpiGbl_EntryStackPointer = &CurrentSp; 87 } 88 89 90 /******************************************************************************* 91 * 92 * FUNCTION: AcpiUtTrackStackPtr 93 * 94 * PARAMETERS: None 95 * 96 * RETURN: None 97 * 98 * DESCRIPTION: Save the current CPU stack pointer 99 * 100 ******************************************************************************/ 101 102 void 103 AcpiUtTrackStackPtr ( 104 void) 105 { 106 ACPI_SIZE CurrentSp; 107 108 109 if (&CurrentSp < AcpiGbl_LowestStackPointer) 110 { 111 AcpiGbl_LowestStackPointer = &CurrentSp; 112 } 113 114 if (AcpiGbl_NestingLevel > AcpiGbl_DeepestNesting) 115 { 116 AcpiGbl_DeepestNesting = AcpiGbl_NestingLevel; 117 } 118 } 119 120 121 /******************************************************************************* 122 * 123 * FUNCTION: AcpiUtTrimFunctionName 124 * 125 * PARAMETERS: FunctionName - Ascii string containing a procedure name 126 * 127 * RETURN: Updated pointer to the function name 128 * 129 * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present. 130 * This allows compiler macros such as __FUNCTION__ to be used 131 * with no change to the debug output. 132 * 133 ******************************************************************************/ 134 135 static const char * 136 AcpiUtTrimFunctionName ( 137 const char *FunctionName) 138 { 139 140 /* All Function names are longer than 4 chars, check is safe */ 141 142 if (*(ACPI_CAST_PTR (UINT32, FunctionName)) == ACPI_PREFIX_MIXED) 143 { 144 /* This is the case where the original source has not been modified */ 145 146 return (FunctionName + 4); 147 } 148 149 if (*(ACPI_CAST_PTR (UINT32, FunctionName)) == ACPI_PREFIX_LOWER) 150 { 151 /* This is the case where the source has been 'linuxized' */ 152 153 return (FunctionName + 5); 154 } 155 156 return (FunctionName); 157 } 158 159 160 /******************************************************************************* 161 * 162 * FUNCTION: AcpiDebugPrint 163 * 164 * PARAMETERS: RequestedDebugLevel - Requested debug print level 165 * LineNumber - Caller's line number (for error output) 166 * FunctionName - Caller's procedure name 167 * ModuleName - Caller's module name 168 * ComponentId - Caller's component ID 169 * Format - Printf format field 170 * ... - Optional printf arguments 171 * 172 * RETURN: None 173 * 174 * DESCRIPTION: Print error message with prefix consisting of the module name, 175 * line number, and component ID. 176 * 177 ******************************************************************************/ 178 179 void ACPI_INTERNAL_VAR_XFACE 180 AcpiDebugPrint ( 181 UINT32 RequestedDebugLevel, 182 UINT32 LineNumber, 183 const char *FunctionName, 184 const char *ModuleName, 185 UINT32 ComponentId, 186 const char *Format, 187 ...) 188 { 189 ACPI_THREAD_ID ThreadId; 190 va_list args; 191 192 193 /* Check if debug output enabled */ 194 195 if (!ACPI_IS_DEBUG_ENABLED (RequestedDebugLevel, ComponentId)) 196 { 197 return; 198 } 199 200 /* 201 * Thread tracking and context switch notification 202 */ 203 ThreadId = AcpiOsGetThreadId (); 204 if (ThreadId != AcpiGbl_PrevThreadId) 205 { 206 if (ACPI_LV_THREADS & AcpiDbgLevel) 207 { 208 AcpiOsPrintf ( 209 "\n**** Context Switch from TID %u to TID %u ****\n\n", 210 (UINT32) AcpiGbl_PrevThreadId, (UINT32) ThreadId); 211 } 212 213 AcpiGbl_PrevThreadId = ThreadId; 214 AcpiGbl_NestingLevel = 0; 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 ("%9s-%04ld ", ModuleName, LineNumber); 222 223 #ifdef ACPI_APPLICATION 224 /* 225 * For AcpiExec/iASL only, emit the thread ID and nesting level. 226 * Note: nesting level is really only useful during a single-thread 227 * execution. Otherwise, multiple threads will keep resetting the 228 * level. 229 */ 230 if (ACPI_LV_THREADS & AcpiDbgLevel) 231 { 232 AcpiOsPrintf ("[%u] ", (UINT32) ThreadId); 233 } 234 235 AcpiOsPrintf ("[%02ld] ", AcpiGbl_NestingLevel); 236 #endif 237 238 AcpiOsPrintf ("%-22.22s: ", AcpiUtTrimFunctionName (FunctionName)); 239 240 va_start (args, Format); 241 AcpiOsVprintf (Format, args); 242 va_end (args); 243 } 244 245 ACPI_EXPORT_SYMBOL (AcpiDebugPrint) 246 247 248 /******************************************************************************* 249 * 250 * FUNCTION: AcpiDebugPrintRaw 251 * 252 * PARAMETERS: RequestedDebugLevel - Requested debug print level 253 * LineNumber - Caller's line number 254 * FunctionName - Caller's procedure name 255 * ModuleName - Caller's module name 256 * ComponentId - Caller's component ID 257 * Format - Printf format field 258 * ... - Optional printf arguments 259 * 260 * RETURN: None 261 * 262 * DESCRIPTION: Print message with no headers. Has same interface as 263 * DebugPrint so that the same macros can be used. 264 * 265 ******************************************************************************/ 266 267 void ACPI_INTERNAL_VAR_XFACE 268 AcpiDebugPrintRaw ( 269 UINT32 RequestedDebugLevel, 270 UINT32 LineNumber, 271 const char *FunctionName, 272 const char *ModuleName, 273 UINT32 ComponentId, 274 const char *Format, 275 ...) 276 { 277 va_list args; 278 279 280 /* Check if debug output enabled */ 281 282 if (!ACPI_IS_DEBUG_ENABLED (RequestedDebugLevel, ComponentId)) 283 { 284 return; 285 } 286 287 va_start (args, Format); 288 AcpiOsVprintf (Format, args); 289 va_end (args); 290 } 291 292 ACPI_EXPORT_SYMBOL (AcpiDebugPrintRaw) 293 294 295 /******************************************************************************* 296 * 297 * FUNCTION: AcpiUtTrace 298 * 299 * PARAMETERS: LineNumber - Caller's line number 300 * FunctionName - Caller's procedure name 301 * ModuleName - Caller's module name 302 * ComponentId - Caller's component ID 303 * 304 * RETURN: None 305 * 306 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 307 * set in DebugLevel 308 * 309 ******************************************************************************/ 310 311 void 312 AcpiUtTrace ( 313 UINT32 LineNumber, 314 const char *FunctionName, 315 const char *ModuleName, 316 UINT32 ComponentId) 317 { 318 319 AcpiGbl_NestingLevel++; 320 AcpiUtTrackStackPtr (); 321 322 /* Check if enabled up-front for performance */ 323 324 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId)) 325 { 326 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 327 LineNumber, FunctionName, ModuleName, ComponentId, 328 "%s\n", AcpiGbl_FnEntryStr); 329 } 330 } 331 332 ACPI_EXPORT_SYMBOL (AcpiUtTrace) 333 334 335 /******************************************************************************* 336 * 337 * FUNCTION: AcpiUtTracePtr 338 * 339 * PARAMETERS: LineNumber - Caller's line number 340 * FunctionName - Caller's procedure name 341 * ModuleName - Caller's module name 342 * ComponentId - Caller's component ID 343 * Pointer - Pointer to display 344 * 345 * RETURN: None 346 * 347 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 348 * set in DebugLevel 349 * 350 ******************************************************************************/ 351 352 void 353 AcpiUtTracePtr ( 354 UINT32 LineNumber, 355 const char *FunctionName, 356 const char *ModuleName, 357 UINT32 ComponentId, 358 void *Pointer) 359 { 360 361 AcpiGbl_NestingLevel++; 362 AcpiUtTrackStackPtr (); 363 364 /* Check if enabled up-front for performance */ 365 366 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId)) 367 { 368 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 369 LineNumber, FunctionName, ModuleName, ComponentId, 370 "%s %p\n", AcpiGbl_FnEntryStr, Pointer); 371 } 372 } 373 374 375 /******************************************************************************* 376 * 377 * FUNCTION: AcpiUtTraceStr 378 * 379 * PARAMETERS: LineNumber - Caller's line number 380 * FunctionName - Caller's procedure name 381 * ModuleName - Caller's module name 382 * ComponentId - Caller's component ID 383 * String - Additional string to display 384 * 385 * RETURN: None 386 * 387 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 388 * set in DebugLevel 389 * 390 ******************************************************************************/ 391 392 void 393 AcpiUtTraceStr ( 394 UINT32 LineNumber, 395 const char *FunctionName, 396 const char *ModuleName, 397 UINT32 ComponentId, 398 char *String) 399 { 400 401 AcpiGbl_NestingLevel++; 402 AcpiUtTrackStackPtr (); 403 404 /* Check if enabled up-front for performance */ 405 406 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId)) 407 { 408 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 409 LineNumber, FunctionName, ModuleName, ComponentId, 410 "%s %s\n", AcpiGbl_FnEntryStr, String); 411 } 412 } 413 414 415 /******************************************************************************* 416 * 417 * FUNCTION: AcpiUtTraceU32 418 * 419 * PARAMETERS: LineNumber - Caller's line number 420 * FunctionName - Caller's procedure name 421 * ModuleName - Caller's module name 422 * ComponentId - Caller's component ID 423 * Integer - Integer to display 424 * 425 * RETURN: None 426 * 427 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 428 * set in DebugLevel 429 * 430 ******************************************************************************/ 431 432 void 433 AcpiUtTraceU32 ( 434 UINT32 LineNumber, 435 const char *FunctionName, 436 const char *ModuleName, 437 UINT32 ComponentId, 438 UINT32 Integer) 439 { 440 441 AcpiGbl_NestingLevel++; 442 AcpiUtTrackStackPtr (); 443 444 /* Check if enabled up-front for performance */ 445 446 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId)) 447 { 448 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 449 LineNumber, FunctionName, ModuleName, ComponentId, 450 "%s %08X\n", AcpiGbl_FnEntryStr, Integer); 451 } 452 } 453 454 455 /******************************************************************************* 456 * 457 * FUNCTION: AcpiUtExit 458 * 459 * PARAMETERS: LineNumber - Caller's line number 460 * FunctionName - Caller's procedure name 461 * ModuleName - Caller's module name 462 * ComponentId - Caller's component ID 463 * 464 * RETURN: None 465 * 466 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 467 * set in DebugLevel 468 * 469 ******************************************************************************/ 470 471 void 472 AcpiUtExit ( 473 UINT32 LineNumber, 474 const char *FunctionName, 475 const char *ModuleName, 476 UINT32 ComponentId) 477 { 478 479 /* Check if enabled up-front for performance */ 480 481 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId)) 482 { 483 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 484 LineNumber, FunctionName, ModuleName, ComponentId, 485 "%s\n", AcpiGbl_FnExitStr); 486 } 487 488 if (AcpiGbl_NestingLevel) 489 { 490 AcpiGbl_NestingLevel--; 491 } 492 } 493 494 ACPI_EXPORT_SYMBOL (AcpiUtExit) 495 496 497 /******************************************************************************* 498 * 499 * FUNCTION: AcpiUtStatusExit 500 * 501 * PARAMETERS: LineNumber - Caller's line number 502 * FunctionName - Caller's procedure name 503 * ModuleName - Caller's module name 504 * ComponentId - Caller's component ID 505 * Status - Exit status code 506 * 507 * RETURN: None 508 * 509 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 510 * set in DebugLevel. Prints exit status also. 511 * 512 ******************************************************************************/ 513 514 void 515 AcpiUtStatusExit ( 516 UINT32 LineNumber, 517 const char *FunctionName, 518 const char *ModuleName, 519 UINT32 ComponentId, 520 ACPI_STATUS Status) 521 { 522 523 /* Check if enabled up-front for performance */ 524 525 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId)) 526 { 527 if (ACPI_SUCCESS (Status)) 528 { 529 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 530 LineNumber, FunctionName, ModuleName, ComponentId, 531 "%s %s\n", AcpiGbl_FnExitStr, 532 AcpiFormatException (Status)); 533 } 534 else 535 { 536 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 537 LineNumber, FunctionName, ModuleName, ComponentId, 538 "%s ****Exception****: %s\n", AcpiGbl_FnExitStr, 539 AcpiFormatException (Status)); 540 } 541 } 542 543 if (AcpiGbl_NestingLevel) 544 { 545 AcpiGbl_NestingLevel--; 546 } 547 } 548 549 ACPI_EXPORT_SYMBOL (AcpiUtStatusExit) 550 551 552 /******************************************************************************* 553 * 554 * FUNCTION: AcpiUtValueExit 555 * 556 * PARAMETERS: LineNumber - Caller's line number 557 * FunctionName - Caller's procedure name 558 * ModuleName - Caller's module name 559 * ComponentId - Caller's component ID 560 * Value - Value to be printed with exit msg 561 * 562 * RETURN: None 563 * 564 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 565 * set in DebugLevel. Prints exit value also. 566 * 567 ******************************************************************************/ 568 569 void 570 AcpiUtValueExit ( 571 UINT32 LineNumber, 572 const char *FunctionName, 573 const char *ModuleName, 574 UINT32 ComponentId, 575 UINT64 Value) 576 { 577 578 /* Check if enabled up-front for performance */ 579 580 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId)) 581 { 582 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 583 LineNumber, FunctionName, ModuleName, ComponentId, 584 "%s %8.8X%8.8X\n", AcpiGbl_FnExitStr, 585 ACPI_FORMAT_UINT64 (Value)); 586 } 587 588 if (AcpiGbl_NestingLevel) 589 { 590 AcpiGbl_NestingLevel--; 591 } 592 } 593 594 ACPI_EXPORT_SYMBOL (AcpiUtValueExit) 595 596 597 /******************************************************************************* 598 * 599 * FUNCTION: AcpiUtPtrExit 600 * 601 * PARAMETERS: LineNumber - Caller's line number 602 * FunctionName - Caller's procedure name 603 * ModuleName - Caller's module name 604 * ComponentId - Caller's component ID 605 * Ptr - Pointer to display 606 * 607 * RETURN: None 608 * 609 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 610 * set in DebugLevel. Prints exit value also. 611 * 612 ******************************************************************************/ 613 614 void 615 AcpiUtPtrExit ( 616 UINT32 LineNumber, 617 const char *FunctionName, 618 const char *ModuleName, 619 UINT32 ComponentId, 620 UINT8 *Ptr) 621 { 622 623 /* Check if enabled up-front for performance */ 624 625 if (ACPI_IS_DEBUG_ENABLED (ACPI_LV_FUNCTIONS, ComponentId)) 626 { 627 AcpiDebugPrint (ACPI_LV_FUNCTIONS, 628 LineNumber, FunctionName, ModuleName, ComponentId, 629 "%s %p\n", AcpiGbl_FnExitStr, Ptr); 630 } 631 632 if (AcpiGbl_NestingLevel) 633 { 634 AcpiGbl_NestingLevel--; 635 } 636 } 637 638 #endif 639 640 641 #ifdef ACPI_APPLICATION 642 /******************************************************************************* 643 * 644 * FUNCTION: AcpiLogError 645 * 646 * PARAMETERS: Format - Printf format field 647 * ... - Optional printf arguments 648 * 649 * RETURN: None 650 * 651 * DESCRIPTION: Print error message to the console, used by applications. 652 * 653 ******************************************************************************/ 654 655 void ACPI_INTERNAL_VAR_XFACE 656 AcpiLogError ( 657 const char *Format, 658 ...) 659 { 660 va_list Args; 661 662 va_start (Args, Format); 663 (void) AcpiUtFileVprintf (ACPI_FILE_ERR, Format, Args); 664 va_end (Args); 665 } 666 667 ACPI_EXPORT_SYMBOL (AcpiLogError) 668 #endif 669