at v2.6.13 620 lines 18 kB view raw
1/****************************************************************************** 2 * 3 * Module Name: utdebug - Debug print routines 4 * 5 *****************************************************************************/ 6 7/* 8 * Copyright (C) 2000 - 2005, R. Byron Moore 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#include <linux/module.h> 45 46#include <acpi/acpi.h> 47 48#define _COMPONENT ACPI_UTILITIES 49 ACPI_MODULE_NAME ("utdebug") 50 51 52#ifdef ACPI_DEBUG_OUTPUT 53 54static u32 acpi_gbl_prev_thread_id = 0xFFFFFFFF; 55static char *acpi_gbl_fn_entry_str = "----Entry"; 56static char *acpi_gbl_fn_exit_str = "----Exit-"; 57 58 59/******************************************************************************* 60 * 61 * FUNCTION: acpi_ut_init_stack_ptr_trace 62 * 63 * PARAMETERS: None 64 * 65 * RETURN: None 66 * 67 * DESCRIPTION: Save the current CPU stack pointer at subsystem startup 68 * 69 ******************************************************************************/ 70 71void 72acpi_ut_init_stack_ptr_trace ( 73 void) 74{ 75 u32 current_sp; 76 77 78 acpi_gbl_entry_stack_pointer = ACPI_PTR_DIFF (&current_sp, NULL); 79} 80 81 82/******************************************************************************* 83 * 84 * FUNCTION: acpi_ut_track_stack_ptr 85 * 86 * PARAMETERS: None 87 * 88 * RETURN: None 89 * 90 * DESCRIPTION: Save the current CPU stack pointer 91 * 92 ******************************************************************************/ 93 94void 95acpi_ut_track_stack_ptr ( 96 void) 97{ 98 acpi_size current_sp; 99 100 101 current_sp = ACPI_PTR_DIFF (&current_sp, NULL); 102 103 if (current_sp < acpi_gbl_lowest_stack_pointer) { 104 acpi_gbl_lowest_stack_pointer = current_sp; 105 } 106 107 if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) { 108 acpi_gbl_deepest_nesting = acpi_gbl_nesting_level; 109 } 110} 111 112 113/******************************************************************************* 114 * 115 * FUNCTION: acpi_ut_debug_print 116 * 117 * PARAMETERS: requested_debug_level - Requested debug print level 118 * line_number - Caller's line number (for error output) 119 * dbg_info - Contains: 120 * proc_name - Caller's procedure name 121 * module_name - Caller's module name 122 * component_id - Caller's component ID 123 * Format - Printf format field 124 * ... - Optional printf arguments 125 * 126 * RETURN: None 127 * 128 * DESCRIPTION: Print error message with prefix consisting of the module name, 129 * line number, and component ID. 130 * 131 ******************************************************************************/ 132 133void ACPI_INTERNAL_VAR_XFACE 134acpi_ut_debug_print ( 135 u32 requested_debug_level, 136 u32 line_number, 137 struct acpi_debug_print_info *dbg_info, 138 char *format, 139 ...) 140{ 141 u32 thread_id; 142 va_list args; 143 144 145 /* 146 * Stay silent if the debug level or component ID is disabled 147 */ 148 if (!(requested_debug_level & acpi_dbg_level) || 149 !(dbg_info->component_id & acpi_dbg_layer)) { 150 return; 151 } 152 153 /* 154 * Thread tracking and context switch notification 155 */ 156 thread_id = acpi_os_get_thread_id (); 157 158 if (thread_id != acpi_gbl_prev_thread_id) { 159 if (ACPI_LV_THREADS & acpi_dbg_level) { 160 acpi_os_printf ( 161 "\n**** Context Switch from TID %X to TID %X ****\n\n", 162 acpi_gbl_prev_thread_id, thread_id); 163 } 164 165 acpi_gbl_prev_thread_id = thread_id; 166 } 167 168 /* 169 * Display the module name, current line number, thread ID (if requested), 170 * current procedure nesting level, and the current procedure name 171 */ 172 acpi_os_printf ("%8s-%04ld ", dbg_info->module_name, line_number); 173 174 if (ACPI_LV_THREADS & acpi_dbg_level) { 175 acpi_os_printf ("[%04lX] ", thread_id); 176 } 177 178 acpi_os_printf ("[%02ld] %-22.22s: ", 179 acpi_gbl_nesting_level, dbg_info->proc_name); 180 181 va_start (args, format); 182 acpi_os_vprintf (format, args); 183} 184 185EXPORT_SYMBOL(acpi_ut_debug_print); 186 187/******************************************************************************* 188 * 189 * FUNCTION: acpi_ut_debug_print_raw 190 * 191 * PARAMETERS: requested_debug_level - Requested debug print level 192 * line_number - Caller's line number 193 * dbg_info - Contains: 194 * proc_name - Caller's procedure name 195 * module_name - Caller's module name 196 * component_id - Caller's component ID 197 * Format - Printf format field 198 * ... - Optional printf arguments 199 * 200 * RETURN: None 201 * 202 * DESCRIPTION: Print message with no headers. Has same interface as 203 * debug_print so that the same macros can be used. 204 * 205 ******************************************************************************/ 206 207void ACPI_INTERNAL_VAR_XFACE 208acpi_ut_debug_print_raw ( 209 u32 requested_debug_level, 210 u32 line_number, 211 struct acpi_debug_print_info *dbg_info, 212 char *format, 213 ...) 214{ 215 va_list args; 216 217 218 if (!(requested_debug_level & acpi_dbg_level) || 219 !(dbg_info->component_id & acpi_dbg_layer)) { 220 return; 221 } 222 223 va_start (args, format); 224 acpi_os_vprintf (format, args); 225} 226EXPORT_SYMBOL(acpi_ut_debug_print_raw); 227 228 229/******************************************************************************* 230 * 231 * FUNCTION: acpi_ut_trace 232 * 233 * PARAMETERS: line_number - Caller's line number 234 * dbg_info - Contains: 235 * proc_name - Caller's procedure name 236 * module_name - Caller's module name 237 * component_id - Caller's component ID 238 * 239 * RETURN: None 240 * 241 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 242 * set in debug_level 243 * 244 ******************************************************************************/ 245 246void 247acpi_ut_trace ( 248 u32 line_number, 249 struct acpi_debug_print_info *dbg_info) 250{ 251 252 acpi_gbl_nesting_level++; 253 acpi_ut_track_stack_ptr (); 254 255 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info, 256 "%s\n", acpi_gbl_fn_entry_str); 257} 258EXPORT_SYMBOL(acpi_ut_trace); 259 260 261/******************************************************************************* 262 * 263 * FUNCTION: acpi_ut_trace_ptr 264 * 265 * PARAMETERS: line_number - Caller's line number 266 * dbg_info - Contains: 267 * proc_name - Caller's procedure name 268 * module_name - Caller's module name 269 * component_id - Caller's component ID 270 * Pointer - Pointer to display 271 * 272 * RETURN: None 273 * 274 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 275 * set in debug_level 276 * 277 ******************************************************************************/ 278 279void 280acpi_ut_trace_ptr ( 281 u32 line_number, 282 struct acpi_debug_print_info *dbg_info, 283 void *pointer) 284{ 285 acpi_gbl_nesting_level++; 286 acpi_ut_track_stack_ptr (); 287 288 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info, 289 "%s %p\n", acpi_gbl_fn_entry_str, pointer); 290} 291 292 293/******************************************************************************* 294 * 295 * FUNCTION: acpi_ut_trace_str 296 * 297 * PARAMETERS: line_number - Caller's line number 298 * dbg_info - Contains: 299 * proc_name - Caller's procedure name 300 * module_name - Caller's module name 301 * component_id - Caller's component ID 302 * String - Additional string to display 303 * 304 * RETURN: None 305 * 306 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 307 * set in debug_level 308 * 309 ******************************************************************************/ 310 311void 312acpi_ut_trace_str ( 313 u32 line_number, 314 struct acpi_debug_print_info *dbg_info, 315 char *string) 316{ 317 318 acpi_gbl_nesting_level++; 319 acpi_ut_track_stack_ptr (); 320 321 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info, 322 "%s %s\n", acpi_gbl_fn_entry_str, string); 323} 324 325 326/******************************************************************************* 327 * 328 * FUNCTION: acpi_ut_trace_u32 329 * 330 * PARAMETERS: line_number - Caller's line number 331 * dbg_info - Contains: 332 * proc_name - Caller's procedure name 333 * module_name - Caller's module name 334 * component_id - Caller's component ID 335 * Integer - Integer to display 336 * 337 * RETURN: None 338 * 339 * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is 340 * set in debug_level 341 * 342 ******************************************************************************/ 343 344void 345acpi_ut_trace_u32 ( 346 u32 line_number, 347 struct acpi_debug_print_info *dbg_info, 348 u32 integer) 349{ 350 351 acpi_gbl_nesting_level++; 352 acpi_ut_track_stack_ptr (); 353 354 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info, 355 "%s %08X\n", acpi_gbl_fn_entry_str, integer); 356} 357 358 359/******************************************************************************* 360 * 361 * FUNCTION: acpi_ut_exit 362 * 363 * PARAMETERS: line_number - Caller's line number 364 * dbg_info - Contains: 365 * proc_name - Caller's procedure name 366 * module_name - Caller's module name 367 * component_id - Caller's component ID 368 * 369 * RETURN: None 370 * 371 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 372 * set in debug_level 373 * 374 ******************************************************************************/ 375 376void 377acpi_ut_exit ( 378 u32 line_number, 379 struct acpi_debug_print_info *dbg_info) 380{ 381 382 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info, 383 "%s\n", acpi_gbl_fn_exit_str); 384 385 acpi_gbl_nesting_level--; 386} 387EXPORT_SYMBOL(acpi_ut_exit); 388 389 390/******************************************************************************* 391 * 392 * FUNCTION: acpi_ut_status_exit 393 * 394 * PARAMETERS: line_number - Caller's line number 395 * dbg_info - Contains: 396 * proc_name - Caller's procedure name 397 * module_name - Caller's module name 398 * component_id - Caller's component ID 399 * Status - Exit status code 400 * 401 * RETURN: None 402 * 403 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 404 * set in debug_level. Prints exit status also. 405 * 406 ******************************************************************************/ 407 408void 409acpi_ut_status_exit ( 410 u32 line_number, 411 struct acpi_debug_print_info *dbg_info, 412 acpi_status status) 413{ 414 415 if (ACPI_SUCCESS (status)) { 416 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info, 417 "%s %s\n", acpi_gbl_fn_exit_str, 418 acpi_format_exception (status)); 419 } 420 else { 421 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info, 422 "%s ****Exception****: %s\n", acpi_gbl_fn_exit_str, 423 acpi_format_exception (status)); 424 } 425 426 acpi_gbl_nesting_level--; 427} 428EXPORT_SYMBOL(acpi_ut_status_exit); 429 430 431/******************************************************************************* 432 * 433 * FUNCTION: acpi_ut_value_exit 434 * 435 * PARAMETERS: line_number - Caller's line number 436 * dbg_info - Contains: 437 * proc_name - Caller's procedure name 438 * module_name - Caller's module name 439 * component_id - Caller's component ID 440 * Value - Value to be printed with exit msg 441 * 442 * RETURN: None 443 * 444 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 445 * set in debug_level. Prints exit value also. 446 * 447 ******************************************************************************/ 448 449void 450acpi_ut_value_exit ( 451 u32 line_number, 452 struct acpi_debug_print_info *dbg_info, 453 acpi_integer value) 454{ 455 456 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info, 457 "%s %8.8X%8.8X\n", acpi_gbl_fn_exit_str, 458 ACPI_FORMAT_UINT64 (value)); 459 460 acpi_gbl_nesting_level--; 461} 462EXPORT_SYMBOL(acpi_ut_value_exit); 463 464 465/******************************************************************************* 466 * 467 * FUNCTION: acpi_ut_ptr_exit 468 * 469 * PARAMETERS: line_number - Caller's line number 470 * dbg_info - Contains: 471 * proc_name - Caller's procedure name 472 * module_name - Caller's module name 473 * component_id - Caller's component ID 474 * Ptr - Pointer to display 475 * 476 * RETURN: None 477 * 478 * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is 479 * set in debug_level. Prints exit value also. 480 * 481 ******************************************************************************/ 482 483void 484acpi_ut_ptr_exit ( 485 u32 line_number, 486 struct acpi_debug_print_info *dbg_info, 487 u8 *ptr) 488{ 489 490 acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info, 491 "%s %p\n", acpi_gbl_fn_exit_str, ptr); 492 493 acpi_gbl_nesting_level--; 494} 495 496#endif 497 498 499/******************************************************************************* 500 * 501 * FUNCTION: acpi_ut_dump_buffer 502 * 503 * PARAMETERS: Buffer - Buffer to dump 504 * Count - Amount to dump, in bytes 505 * Display - BYTE, WORD, DWORD, or QWORD display 506 * component_iD - Caller's component ID 507 * 508 * RETURN: None 509 * 510 * DESCRIPTION: Generic dump buffer in both hex and ascii. 511 * 512 ******************************************************************************/ 513 514void 515acpi_ut_dump_buffer ( 516 u8 *buffer, 517 u32 count, 518 u32 display, 519 u32 component_id) 520{ 521 acpi_native_uint i = 0; 522 acpi_native_uint j; 523 u32 temp32; 524 u8 buf_char; 525 526 527 /* Only dump the buffer if tracing is enabled */ 528 529 if (!((ACPI_LV_TABLES & acpi_dbg_level) && 530 (component_id & acpi_dbg_layer))) { 531 return; 532 } 533 534 if ((count < 4) || (count & 0x01)) { 535 display = DB_BYTE_DISPLAY; 536 } 537 538 /* Nasty little dump buffer routine! */ 539 540 while (i < count) { 541 /* Print current offset */ 542 543 acpi_os_printf ("%6.4X: ", (u32) i); 544 545 /* Print 16 hex chars */ 546 547 for (j = 0; j < 16;) { 548 if (i + j >= count) { 549 /* Dump fill spaces */ 550 551 acpi_os_printf ("%*s", ((display * 2) + 1), " "); 552 j += display; 553 continue; 554 } 555 556 switch (display) { 557 default: /* Default is BYTE display */ 558 559 acpi_os_printf ("%02X ", buffer[i + j]); 560 break; 561 562 563 case DB_WORD_DISPLAY: 564 565 ACPI_MOVE_16_TO_32 (&temp32, &buffer[i + j]); 566 acpi_os_printf ("%04X ", temp32); 567 break; 568 569 570 case DB_DWORD_DISPLAY: 571 572 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]); 573 acpi_os_printf ("%08X ", temp32); 574 break; 575 576 577 case DB_QWORD_DISPLAY: 578 579 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]); 580 acpi_os_printf ("%08X", temp32); 581 582 ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j + 4]); 583 acpi_os_printf ("%08X ", temp32); 584 break; 585 } 586 587 j += display; 588 } 589 590 /* 591 * Print the ASCII equivalent characters 592 * But watch out for the bad unprintable ones... 593 */ 594 acpi_os_printf (" "); 595 for (j = 0; j < 16; j++) { 596 if (i + j >= count) { 597 acpi_os_printf ("\n"); 598 return; 599 } 600 601 buf_char = buffer[i + j]; 602 if ((buf_char > 0x1F && buf_char < 0x2E) || 603 (buf_char > 0x2F && buf_char < 0x61) || 604 (buf_char > 0x60 && buf_char < 0x7F)) { 605 acpi_os_printf ("%c", buf_char); 606 } 607 else { 608 acpi_os_printf ("."); 609 } 610 } 611 612 /* Done with that line. */ 613 614 acpi_os_printf ("\n"); 615 i += 16; 616 } 617 618 return; 619} 620