utdebug.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654
  1. /******************************************************************************
  2. *
  3. * Module Name: utdebug - Debug print routines
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2008, Intel Corp.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted provided that the following conditions
  12. * are met:
  13. * 1. Redistributions of source code must retain the above copyright
  14. * notice, this list of conditions, and the following disclaimer,
  15. * without modification.
  16. * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  17. * substantially similar to the "NO WARRANTY" disclaimer below
  18. * ("Disclaimer") and any redistribution must be conditioned upon
  19. * including a substantially similar Disclaimer requirement for further
  20. * binary redistribution.
  21. * 3. Neither the names of the above-listed copyright holders nor the names
  22. * of any contributors may be used to endorse or promote products derived
  23. * from this software without specific prior written permission.
  24. *
  25. * Alternatively, this software may be distributed under the terms of the
  26. * GNU General Public License ("GPL") version 2 as published by the Free
  27. * Software Foundation.
  28. *
  29. * NO WARRANTY
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  31. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  32. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
  33. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  34. * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  35. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  36. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  37. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  38. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
  39. * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  40. * POSSIBILITY OF SUCH DAMAGES.
  41. */
  42. #include <acpi/acpi.h>
  43. #define _COMPONENT ACPI_UTILITIES
  44. ACPI_MODULE_NAME("utdebug")
  45. #ifdef ACPI_DEBUG_OUTPUT
  46. static acpi_thread_id acpi_gbl_prev_thread_id;
  47. static char *acpi_gbl_fn_entry_str = "----Entry";
  48. static char *acpi_gbl_fn_exit_str = "----Exit-";
  49. /* Local prototypes */
  50. static const char *acpi_ut_trim_function_name(const char *function_name);
  51. /*******************************************************************************
  52. *
  53. * FUNCTION: acpi_ut_init_stack_ptr_trace
  54. *
  55. * PARAMETERS: None
  56. *
  57. * RETURN: None
  58. *
  59. * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
  60. *
  61. ******************************************************************************/
  62. void acpi_ut_init_stack_ptr_trace(void)
  63. {
  64. acpi_size current_sp;
  65. acpi_gbl_entry_stack_pointer = &current_sp;
  66. }
  67. /*******************************************************************************
  68. *
  69. * FUNCTION: acpi_ut_track_stack_ptr
  70. *
  71. * PARAMETERS: None
  72. *
  73. * RETURN: None
  74. *
  75. * DESCRIPTION: Save the current CPU stack pointer
  76. *
  77. ******************************************************************************/
  78. void acpi_ut_track_stack_ptr(void)
  79. {
  80. acpi_size current_sp;
  81. if (&current_sp < acpi_gbl_lowest_stack_pointer) {
  82. acpi_gbl_lowest_stack_pointer = &current_sp;
  83. }
  84. if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) {
  85. acpi_gbl_deepest_nesting = acpi_gbl_nesting_level;
  86. }
  87. }
  88. /*******************************************************************************
  89. *
  90. * FUNCTION: acpi_ut_trim_function_name
  91. *
  92. * PARAMETERS: function_name - Ascii string containing a procedure name
  93. *
  94. * RETURN: Updated pointer to the function name
  95. *
  96. * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
  97. * This allows compiler macros such as __func__ to be used
  98. * with no change to the debug output.
  99. *
  100. ******************************************************************************/
  101. static const char *acpi_ut_trim_function_name(const char *function_name)
  102. {
  103. /* All Function names are longer than 4 chars, check is safe */
  104. if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_MIXED) {
  105. /* This is the case where the original source has not been modified */
  106. return (function_name + 4);
  107. }
  108. if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_LOWER) {
  109. /* This is the case where the source has been 'linuxized' */
  110. return (function_name + 5);
  111. }
  112. return (function_name);
  113. }
  114. /*******************************************************************************
  115. *
  116. * FUNCTION: acpi_ut_debug_print
  117. *
  118. * PARAMETERS: requested_debug_level - Requested debug print level
  119. * line_number - Caller's line number (for error output)
  120. * function_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. void ACPI_INTERNAL_VAR_XFACE
  133. acpi_ut_debug_print(u32 requested_debug_level,
  134. u32 line_number,
  135. const char *function_name,
  136. const char *module_name,
  137. u32 component_id, const char *format, ...)
  138. {
  139. acpi_thread_id thread_id;
  140. va_list args;
  141. /*
  142. * Stay silent if the debug level or component ID is disabled
  143. */
  144. if (!(requested_debug_level & acpi_dbg_level) ||
  145. !(component_id & acpi_dbg_layer)) {
  146. return;
  147. }
  148. /*
  149. * Thread tracking and context switch notification
  150. */
  151. thread_id = acpi_os_get_thread_id();
  152. if (thread_id != acpi_gbl_prev_thread_id) {
  153. if (ACPI_LV_THREADS & acpi_dbg_level) {
  154. acpi_os_printf
  155. ("\n**** Context Switch from TID %lX to TID %lX ****\n\n",
  156. (unsigned long)acpi_gbl_prev_thread_id,
  157. (unsigned long)thread_id);
  158. }
  159. acpi_gbl_prev_thread_id = thread_id;
  160. }
  161. /*
  162. * Display the module name, current line number, thread ID (if requested),
  163. * current procedure nesting level, and the current procedure name
  164. */
  165. acpi_os_printf("%8s-%04ld ", module_name, line_number);
  166. if (ACPI_LV_THREADS & acpi_dbg_level) {
  167. acpi_os_printf("[%04lX] ", (unsigned long)thread_id);
  168. }
  169. acpi_os_printf("[%02ld] %-22.22s: ",
  170. acpi_gbl_nesting_level,
  171. acpi_ut_trim_function_name(function_name));
  172. va_start(args, format);
  173. acpi_os_vprintf(format, args);
  174. va_end(args);
  175. }
  176. ACPI_EXPORT_SYMBOL(acpi_ut_debug_print)
  177. /*******************************************************************************
  178. *
  179. * FUNCTION: acpi_ut_debug_print_raw
  180. *
  181. * PARAMETERS: requested_debug_level - Requested debug print level
  182. * line_number - Caller's line number
  183. * function_name - Caller's procedure name
  184. * module_name - Caller's module name
  185. * component_id - Caller's component ID
  186. * Format - Printf format field
  187. * ... - Optional printf arguments
  188. *
  189. * RETURN: None
  190. *
  191. * DESCRIPTION: Print message with no headers. Has same interface as
  192. * debug_print so that the same macros can be used.
  193. *
  194. ******************************************************************************/
  195. void ACPI_INTERNAL_VAR_XFACE
  196. acpi_ut_debug_print_raw(u32 requested_debug_level,
  197. u32 line_number,
  198. const char *function_name,
  199. const char *module_name,
  200. u32 component_id, const char *format, ...)
  201. {
  202. va_list args;
  203. if (!(requested_debug_level & acpi_dbg_level) ||
  204. !(component_id & acpi_dbg_layer)) {
  205. return;
  206. }
  207. va_start(args, format);
  208. acpi_os_vprintf(format, args);
  209. va_end(args);
  210. }
  211. ACPI_EXPORT_SYMBOL(acpi_ut_debug_print_raw)
  212. /*******************************************************************************
  213. *
  214. * FUNCTION: acpi_ut_trace
  215. *
  216. * PARAMETERS: line_number - Caller's line number
  217. * function_name - Caller's procedure name
  218. * module_name - Caller's module name
  219. * component_id - Caller's component ID
  220. *
  221. * RETURN: None
  222. *
  223. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  224. * set in debug_level
  225. *
  226. ******************************************************************************/
  227. void
  228. acpi_ut_trace(u32 line_number,
  229. const char *function_name,
  230. const char *module_name, u32 component_id)
  231. {
  232. acpi_gbl_nesting_level++;
  233. acpi_ut_track_stack_ptr();
  234. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  235. line_number, function_name, module_name,
  236. component_id, "%s\n", acpi_gbl_fn_entry_str);
  237. }
  238. ACPI_EXPORT_SYMBOL(acpi_ut_trace)
  239. /*******************************************************************************
  240. *
  241. * FUNCTION: acpi_ut_trace_ptr
  242. *
  243. * PARAMETERS: line_number - Caller's line number
  244. * function_name - Caller's procedure name
  245. * module_name - Caller's module name
  246. * component_id - Caller's component ID
  247. * Pointer - Pointer to display
  248. *
  249. * RETURN: None
  250. *
  251. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  252. * set in debug_level
  253. *
  254. ******************************************************************************/
  255. void
  256. acpi_ut_trace_ptr(u32 line_number,
  257. const char *function_name,
  258. const char *module_name, u32 component_id, void *pointer)
  259. {
  260. acpi_gbl_nesting_level++;
  261. acpi_ut_track_stack_ptr();
  262. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  263. line_number, function_name, module_name,
  264. component_id, "%s %p\n", acpi_gbl_fn_entry_str,
  265. pointer);
  266. }
  267. /*******************************************************************************
  268. *
  269. * FUNCTION: acpi_ut_trace_str
  270. *
  271. * PARAMETERS: line_number - Caller's line number
  272. * function_name - Caller's procedure name
  273. * module_name - Caller's module name
  274. * component_id - Caller's component ID
  275. * String - Additional string to display
  276. *
  277. * RETURN: None
  278. *
  279. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  280. * set in debug_level
  281. *
  282. ******************************************************************************/
  283. void
  284. acpi_ut_trace_str(u32 line_number,
  285. const char *function_name,
  286. const char *module_name, u32 component_id, char *string)
  287. {
  288. acpi_gbl_nesting_level++;
  289. acpi_ut_track_stack_ptr();
  290. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  291. line_number, function_name, module_name,
  292. component_id, "%s %s\n", acpi_gbl_fn_entry_str,
  293. string);
  294. }
  295. /*******************************************************************************
  296. *
  297. * FUNCTION: acpi_ut_trace_u32
  298. *
  299. * PARAMETERS: line_number - Caller's line number
  300. * function_name - Caller's procedure name
  301. * module_name - Caller's module name
  302. * component_id - Caller's component ID
  303. * Integer - Integer to display
  304. *
  305. * RETURN: None
  306. *
  307. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  308. * set in debug_level
  309. *
  310. ******************************************************************************/
  311. void
  312. acpi_ut_trace_u32(u32 line_number,
  313. const char *function_name,
  314. const char *module_name, u32 component_id, u32 integer)
  315. {
  316. acpi_gbl_nesting_level++;
  317. acpi_ut_track_stack_ptr();
  318. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  319. line_number, function_name, module_name,
  320. component_id, "%s %08X\n", acpi_gbl_fn_entry_str,
  321. integer);
  322. }
  323. /*******************************************************************************
  324. *
  325. * FUNCTION: acpi_ut_exit
  326. *
  327. * PARAMETERS: line_number - Caller's line number
  328. * function_name - Caller's procedure name
  329. * module_name - Caller's module name
  330. * component_id - Caller's component ID
  331. *
  332. * RETURN: None
  333. *
  334. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  335. * set in debug_level
  336. *
  337. ******************************************************************************/
  338. void
  339. acpi_ut_exit(u32 line_number,
  340. const char *function_name,
  341. const char *module_name, u32 component_id)
  342. {
  343. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  344. line_number, function_name, module_name,
  345. component_id, "%s\n", acpi_gbl_fn_exit_str);
  346. acpi_gbl_nesting_level--;
  347. }
  348. ACPI_EXPORT_SYMBOL(acpi_ut_exit)
  349. /*******************************************************************************
  350. *
  351. * FUNCTION: acpi_ut_status_exit
  352. *
  353. * PARAMETERS: line_number - Caller's line number
  354. * function_name - Caller's procedure name
  355. * module_name - Caller's module name
  356. * component_id - Caller's component ID
  357. * Status - Exit status code
  358. *
  359. * RETURN: None
  360. *
  361. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  362. * set in debug_level. Prints exit status also.
  363. *
  364. ******************************************************************************/
  365. void
  366. acpi_ut_status_exit(u32 line_number,
  367. const char *function_name,
  368. const char *module_name,
  369. u32 component_id, acpi_status status)
  370. {
  371. if (ACPI_SUCCESS(status)) {
  372. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  373. line_number, function_name, module_name,
  374. component_id, "%s %s\n",
  375. acpi_gbl_fn_exit_str,
  376. acpi_format_exception(status));
  377. } else {
  378. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  379. line_number, function_name, module_name,
  380. component_id, "%s ****Exception****: %s\n",
  381. acpi_gbl_fn_exit_str,
  382. acpi_format_exception(status));
  383. }
  384. acpi_gbl_nesting_level--;
  385. }
  386. ACPI_EXPORT_SYMBOL(acpi_ut_status_exit)
  387. /*******************************************************************************
  388. *
  389. * FUNCTION: acpi_ut_value_exit
  390. *
  391. * PARAMETERS: line_number - Caller's line number
  392. * function_name - Caller's procedure name
  393. * module_name - Caller's module name
  394. * component_id - Caller's component ID
  395. * Value - Value to be printed with exit msg
  396. *
  397. * RETURN: None
  398. *
  399. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  400. * set in debug_level. Prints exit value also.
  401. *
  402. ******************************************************************************/
  403. void
  404. acpi_ut_value_exit(u32 line_number,
  405. const char *function_name,
  406. const char *module_name,
  407. u32 component_id, acpi_integer value)
  408. {
  409. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  410. line_number, function_name, module_name,
  411. component_id, "%s %8.8X%8.8X\n",
  412. acpi_gbl_fn_exit_str, ACPI_FORMAT_UINT64(value));
  413. acpi_gbl_nesting_level--;
  414. }
  415. ACPI_EXPORT_SYMBOL(acpi_ut_value_exit)
  416. /*******************************************************************************
  417. *
  418. * FUNCTION: acpi_ut_ptr_exit
  419. *
  420. * PARAMETERS: line_number - Caller's line number
  421. * function_name - Caller's procedure name
  422. * module_name - Caller's module name
  423. * component_id - Caller's component ID
  424. * Ptr - Pointer to display
  425. *
  426. * RETURN: None
  427. *
  428. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  429. * set in debug_level. Prints exit value also.
  430. *
  431. ******************************************************************************/
  432. void
  433. acpi_ut_ptr_exit(u32 line_number,
  434. const char *function_name,
  435. const char *module_name, u32 component_id, u8 *ptr)
  436. {
  437. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  438. line_number, function_name, module_name,
  439. component_id, "%s %p\n", acpi_gbl_fn_exit_str, ptr);
  440. acpi_gbl_nesting_level--;
  441. }
  442. #endif
  443. /*******************************************************************************
  444. *
  445. * FUNCTION: acpi_ut_dump_buffer
  446. *
  447. * PARAMETERS: Buffer - Buffer to dump
  448. * Count - Amount to dump, in bytes
  449. * Display - BYTE, WORD, DWORD, or QWORD display
  450. * component_iD - Caller's component ID
  451. *
  452. * RETURN: None
  453. *
  454. * DESCRIPTION: Generic dump buffer in both hex and ascii.
  455. *
  456. ******************************************************************************/
  457. void acpi_ut_dump_buffer2(u8 * buffer, u32 count, u32 display)
  458. {
  459. u32 i = 0;
  460. u32 j;
  461. u32 temp32;
  462. u8 buf_char;
  463. if (!buffer) {
  464. acpi_os_printf("Null Buffer Pointer in DumpBuffer!\n");
  465. return;
  466. }
  467. if ((count < 4) || (count & 0x01)) {
  468. display = DB_BYTE_DISPLAY;
  469. }
  470. /* Nasty little dump buffer routine! */
  471. while (i < count) {
  472. /* Print current offset */
  473. acpi_os_printf("%6.4X: ", i);
  474. /* Print 16 hex chars */
  475. for (j = 0; j < 16;) {
  476. if (i + j >= count) {
  477. /* Dump fill spaces */
  478. acpi_os_printf("%*s", ((display * 2) + 1), " ");
  479. j += display;
  480. continue;
  481. }
  482. switch (display) {
  483. case DB_BYTE_DISPLAY:
  484. default: /* Default is BYTE display */
  485. acpi_os_printf("%02X ",
  486. buffer[(acpi_size) i + j]);
  487. break;
  488. case DB_WORD_DISPLAY:
  489. ACPI_MOVE_16_TO_32(&temp32,
  490. &buffer[(acpi_size) i + j]);
  491. acpi_os_printf("%04X ", temp32);
  492. break;
  493. case DB_DWORD_DISPLAY:
  494. ACPI_MOVE_32_TO_32(&temp32,
  495. &buffer[(acpi_size) i + j]);
  496. acpi_os_printf("%08X ", temp32);
  497. break;
  498. case DB_QWORD_DISPLAY:
  499. ACPI_MOVE_32_TO_32(&temp32,
  500. &buffer[(acpi_size) i + j]);
  501. acpi_os_printf("%08X", temp32);
  502. ACPI_MOVE_32_TO_32(&temp32,
  503. &buffer[(acpi_size) i + j +
  504. 4]);
  505. acpi_os_printf("%08X ", temp32);
  506. break;
  507. }
  508. j += display;
  509. }
  510. /*
  511. * Print the ASCII equivalent characters but watch out for the bad
  512. * unprintable ones (printable chars are 0x20 through 0x7E)
  513. */
  514. acpi_os_printf(" ");
  515. for (j = 0; j < 16; j++) {
  516. if (i + j >= count) {
  517. acpi_os_printf("\n");
  518. return;
  519. }
  520. buf_char = buffer[(acpi_size) i + j];
  521. if (ACPI_IS_PRINT(buf_char)) {
  522. acpi_os_printf("%c", buf_char);
  523. } else {
  524. acpi_os_printf(".");
  525. }
  526. }
  527. /* Done with that line. */
  528. acpi_os_printf("\n");
  529. i += 16;
  530. }
  531. return;
  532. }
  533. /*******************************************************************************
  534. *
  535. * FUNCTION: acpi_ut_dump_buffer
  536. *
  537. * PARAMETERS: Buffer - Buffer to dump
  538. * Count - Amount to dump, in bytes
  539. * Display - BYTE, WORD, DWORD, or QWORD display
  540. * component_iD - Caller's component ID
  541. *
  542. * RETURN: None
  543. *
  544. * DESCRIPTION: Generic dump buffer in both hex and ascii.
  545. *
  546. ******************************************************************************/
  547. void acpi_ut_dump_buffer(u8 * buffer, u32 count, u32 display, u32 component_id)
  548. {
  549. /* Only dump the buffer if tracing is enabled */
  550. if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
  551. (component_id & acpi_dbg_layer))) {
  552. return;
  553. }
  554. acpi_ut_dump_buffer2(buffer, count, display);
  555. }