utdebug.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. /******************************************************************************
  2. *
  3. * Module Name: utdebug - Debug print routines
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2006, R. Byron Moore
  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. u32 current_sp;
  65. acpi_gbl_entry_stack_pointer = ACPI_PTR_DIFF(&current_sp, NULL);
  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. current_sp = ACPI_PTR_DIFF(&current_sp, NULL);
  82. if (current_sp < acpi_gbl_lowest_stack_pointer) {
  83. acpi_gbl_lowest_stack_pointer = current_sp;
  84. }
  85. if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) {
  86. acpi_gbl_deepest_nesting = acpi_gbl_nesting_level;
  87. }
  88. }
  89. /*******************************************************************************
  90. *
  91. * FUNCTION: acpi_ut_trim_function_name
  92. *
  93. * PARAMETERS: function_name - Ascii string containing a procedure name
  94. *
  95. * RETURN: Updated pointer to the function name
  96. *
  97. * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
  98. * This allows compiler macros such as __FUNCTION__ to be used
  99. * with no change to the debug output.
  100. *
  101. ******************************************************************************/
  102. static const char *acpi_ut_trim_function_name(const char *function_name)
  103. {
  104. /* All Function names are longer than 4 chars, check is safe */
  105. if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_MIXED) {
  106. /* This is the case where the original source has not been modified */
  107. return (function_name + 4);
  108. }
  109. if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_LOWER) {
  110. /* This is the case where the source has been 'linuxized' */
  111. return (function_name + 5);
  112. }
  113. return (function_name);
  114. }
  115. /*******************************************************************************
  116. *
  117. * FUNCTION: acpi_ut_debug_print
  118. *
  119. * PARAMETERS: requested_debug_level - Requested debug print level
  120. * line_number - Caller's line number (for error output)
  121. * function_name - Caller's procedure name
  122. * module_name - Caller's module name
  123. * component_id - Caller's component ID
  124. * Format - Printf format field
  125. * ... - Optional printf arguments
  126. *
  127. * RETURN: None
  128. *
  129. * DESCRIPTION: Print error message with prefix consisting of the module name,
  130. * line number, and component ID.
  131. *
  132. ******************************************************************************/
  133. void ACPI_INTERNAL_VAR_XFACE
  134. acpi_ut_debug_print(u32 requested_debug_level,
  135. u32 line_number,
  136. const char *function_name,
  137. char *module_name, u32 component_id, 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 %X to TID %X ****\n\n",
  156. (u32) acpi_gbl_prev_thread_id, (u32) thread_id);
  157. }
  158. acpi_gbl_prev_thread_id = thread_id;
  159. }
  160. /*
  161. * Display the module name, current line number, thread ID (if requested),
  162. * current procedure nesting level, and the current procedure name
  163. */
  164. acpi_os_printf("%8s-%04ld ", module_name, line_number);
  165. if (ACPI_LV_THREADS & acpi_dbg_level) {
  166. acpi_os_printf("[%04lX] ", thread_id);
  167. }
  168. acpi_os_printf("[%02ld] %-22.22s: ",
  169. acpi_gbl_nesting_level,
  170. acpi_ut_trim_function_name(function_name));
  171. va_start(args, format);
  172. acpi_os_vprintf(format, args);
  173. }
  174. ACPI_EXPORT_SYMBOL(acpi_ut_debug_print)
  175. /*******************************************************************************
  176. *
  177. * FUNCTION: acpi_ut_debug_print_raw
  178. *
  179. * PARAMETERS: requested_debug_level - Requested debug print level
  180. * line_number - Caller's line number
  181. * function_name - Caller's procedure name
  182. * module_name - Caller's module name
  183. * component_id - Caller's component ID
  184. * Format - Printf format field
  185. * ... - Optional printf arguments
  186. *
  187. * RETURN: None
  188. *
  189. * DESCRIPTION: Print message with no headers. Has same interface as
  190. * debug_print so that the same macros can be used.
  191. *
  192. ******************************************************************************/
  193. void ACPI_INTERNAL_VAR_XFACE
  194. acpi_ut_debug_print_raw(u32 requested_debug_level,
  195. u32 line_number,
  196. const char *function_name,
  197. char *module_name, u32 component_id, char *format, ...)
  198. {
  199. va_list args;
  200. if (!(requested_debug_level & acpi_dbg_level) ||
  201. !(component_id & acpi_dbg_layer)) {
  202. return;
  203. }
  204. va_start(args, format);
  205. acpi_os_vprintf(format, args);
  206. }
  207. ACPI_EXPORT_SYMBOL(acpi_ut_debug_print_raw)
  208. /*******************************************************************************
  209. *
  210. * FUNCTION: acpi_ut_trace
  211. *
  212. * PARAMETERS: line_number - Caller's line number
  213. * function_name - Caller's procedure name
  214. * module_name - Caller's module name
  215. * component_id - Caller's component ID
  216. *
  217. * RETURN: None
  218. *
  219. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  220. * set in debug_level
  221. *
  222. ******************************************************************************/
  223. void
  224. acpi_ut_trace(u32 line_number,
  225. const char *function_name, char *module_name, u32 component_id)
  226. {
  227. acpi_gbl_nesting_level++;
  228. acpi_ut_track_stack_ptr();
  229. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  230. line_number, function_name, module_name,
  231. component_id, "%s\n", acpi_gbl_fn_entry_str);
  232. }
  233. ACPI_EXPORT_SYMBOL(acpi_ut_trace)
  234. /*******************************************************************************
  235. *
  236. * FUNCTION: acpi_ut_trace_ptr
  237. *
  238. * PARAMETERS: line_number - Caller's line number
  239. * function_name - Caller's procedure name
  240. * module_name - Caller's module name
  241. * component_id - Caller's component ID
  242. * Pointer - Pointer to display
  243. *
  244. * RETURN: None
  245. *
  246. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  247. * set in debug_level
  248. *
  249. ******************************************************************************/
  250. void
  251. acpi_ut_trace_ptr(u32 line_number,
  252. const char *function_name,
  253. char *module_name, u32 component_id, void *pointer)
  254. {
  255. acpi_gbl_nesting_level++;
  256. acpi_ut_track_stack_ptr();
  257. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  258. line_number, function_name, module_name,
  259. component_id, "%s %p\n", acpi_gbl_fn_entry_str,
  260. pointer);
  261. }
  262. /*******************************************************************************
  263. *
  264. * FUNCTION: acpi_ut_trace_str
  265. *
  266. * PARAMETERS: line_number - Caller's line number
  267. * function_name - Caller's procedure name
  268. * module_name - Caller's module name
  269. * component_id - Caller's component ID
  270. * String - Additional string 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. void
  279. acpi_ut_trace_str(u32 line_number,
  280. const char *function_name,
  281. char *module_name, u32 component_id, char *string)
  282. {
  283. acpi_gbl_nesting_level++;
  284. acpi_ut_track_stack_ptr();
  285. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  286. line_number, function_name, module_name,
  287. component_id, "%s %s\n", acpi_gbl_fn_entry_str,
  288. string);
  289. }
  290. /*******************************************************************************
  291. *
  292. * FUNCTION: acpi_ut_trace_u32
  293. *
  294. * PARAMETERS: line_number - Caller's line number
  295. * function_name - Caller's procedure name
  296. * module_name - Caller's module name
  297. * component_id - Caller's component ID
  298. * Integer - Integer to display
  299. *
  300. * RETURN: None
  301. *
  302. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  303. * set in debug_level
  304. *
  305. ******************************************************************************/
  306. void
  307. acpi_ut_trace_u32(u32 line_number,
  308. const char *function_name,
  309. char *module_name, u32 component_id, u32 integer)
  310. {
  311. acpi_gbl_nesting_level++;
  312. acpi_ut_track_stack_ptr();
  313. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  314. line_number, function_name, module_name,
  315. component_id, "%s %08X\n", acpi_gbl_fn_entry_str,
  316. integer);
  317. }
  318. /*******************************************************************************
  319. *
  320. * FUNCTION: acpi_ut_exit
  321. *
  322. * PARAMETERS: line_number - Caller's line number
  323. * function_name - Caller's procedure name
  324. * module_name - Caller's module name
  325. * component_id - Caller's component ID
  326. *
  327. * RETURN: None
  328. *
  329. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  330. * set in debug_level
  331. *
  332. ******************************************************************************/
  333. void
  334. acpi_ut_exit(u32 line_number,
  335. const char *function_name, char *module_name, u32 component_id)
  336. {
  337. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  338. line_number, function_name, module_name,
  339. component_id, "%s\n", acpi_gbl_fn_exit_str);
  340. acpi_gbl_nesting_level--;
  341. }
  342. ACPI_EXPORT_SYMBOL(acpi_ut_exit)
  343. /*******************************************************************************
  344. *
  345. * FUNCTION: acpi_ut_status_exit
  346. *
  347. * PARAMETERS: line_number - Caller's line number
  348. * function_name - Caller's procedure name
  349. * module_name - Caller's module name
  350. * component_id - Caller's component ID
  351. * Status - Exit status code
  352. *
  353. * RETURN: None
  354. *
  355. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  356. * set in debug_level. Prints exit status also.
  357. *
  358. ******************************************************************************/
  359. void
  360. acpi_ut_status_exit(u32 line_number,
  361. const char *function_name,
  362. char *module_name, u32 component_id, acpi_status status)
  363. {
  364. if (ACPI_SUCCESS(status)) {
  365. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  366. line_number, function_name, module_name,
  367. component_id, "%s %s\n",
  368. acpi_gbl_fn_exit_str,
  369. acpi_format_exception(status));
  370. } else {
  371. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  372. line_number, function_name, module_name,
  373. component_id, "%s ****Exception****: %s\n",
  374. acpi_gbl_fn_exit_str,
  375. acpi_format_exception(status));
  376. }
  377. acpi_gbl_nesting_level--;
  378. }
  379. ACPI_EXPORT_SYMBOL(acpi_ut_status_exit)
  380. /*******************************************************************************
  381. *
  382. * FUNCTION: acpi_ut_value_exit
  383. *
  384. * PARAMETERS: line_number - Caller's line number
  385. * function_name - Caller's procedure name
  386. * module_name - Caller's module name
  387. * component_id - Caller's component ID
  388. * Value - Value to be printed with exit msg
  389. *
  390. * RETURN: None
  391. *
  392. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  393. * set in debug_level. Prints exit value also.
  394. *
  395. ******************************************************************************/
  396. void
  397. acpi_ut_value_exit(u32 line_number,
  398. const char *function_name,
  399. char *module_name, u32 component_id, acpi_integer value)
  400. {
  401. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  402. line_number, function_name, module_name,
  403. component_id, "%s %8.8X%8.8X\n",
  404. acpi_gbl_fn_exit_str, ACPI_FORMAT_UINT64(value));
  405. acpi_gbl_nesting_level--;
  406. }
  407. ACPI_EXPORT_SYMBOL(acpi_ut_value_exit)
  408. /*******************************************************************************
  409. *
  410. * FUNCTION: acpi_ut_ptr_exit
  411. *
  412. * PARAMETERS: line_number - Caller's line number
  413. * function_name - Caller's procedure name
  414. * module_name - Caller's module name
  415. * component_id - Caller's component ID
  416. * Ptr - Pointer to display
  417. *
  418. * RETURN: None
  419. *
  420. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  421. * set in debug_level. Prints exit value also.
  422. *
  423. ******************************************************************************/
  424. void
  425. acpi_ut_ptr_exit(u32 line_number,
  426. const char *function_name,
  427. char *module_name, u32 component_id, u8 * ptr)
  428. {
  429. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  430. line_number, function_name, module_name,
  431. component_id, "%s %p\n", acpi_gbl_fn_exit_str, ptr);
  432. acpi_gbl_nesting_level--;
  433. }
  434. #endif
  435. /*******************************************************************************
  436. *
  437. * FUNCTION: acpi_ut_dump_buffer
  438. *
  439. * PARAMETERS: Buffer - Buffer to dump
  440. * Count - Amount to dump, in bytes
  441. * Display - BYTE, WORD, DWORD, or QWORD display
  442. * component_iD - Caller's component ID
  443. *
  444. * RETURN: None
  445. *
  446. * DESCRIPTION: Generic dump buffer in both hex and ascii.
  447. *
  448. ******************************************************************************/
  449. void acpi_ut_dump_buffer2(u8 * buffer, u32 count, u32 display)
  450. {
  451. acpi_native_uint i = 0;
  452. acpi_native_uint j;
  453. u32 temp32;
  454. u8 buf_char;
  455. if ((count < 4) || (count & 0x01)) {
  456. display = DB_BYTE_DISPLAY;
  457. }
  458. /* Nasty little dump buffer routine! */
  459. while (i < count) {
  460. /* Print current offset */
  461. acpi_os_printf("%6.4X: ", (u32) i);
  462. /* Print 16 hex chars */
  463. for (j = 0; j < 16;) {
  464. if (i + j >= count) {
  465. /* Dump fill spaces */
  466. acpi_os_printf("%*s", ((display * 2) + 1), " ");
  467. j += (acpi_native_uint) display;
  468. continue;
  469. }
  470. switch (display) {
  471. case DB_BYTE_DISPLAY:
  472. default: /* Default is BYTE display */
  473. acpi_os_printf("%02X ", buffer[i + j]);
  474. break;
  475. case DB_WORD_DISPLAY:
  476. ACPI_MOVE_16_TO_32(&temp32, &buffer[i + j]);
  477. acpi_os_printf("%04X ", temp32);
  478. break;
  479. case DB_DWORD_DISPLAY:
  480. ACPI_MOVE_32_TO_32(&temp32, &buffer[i + j]);
  481. acpi_os_printf("%08X ", temp32);
  482. break;
  483. case DB_QWORD_DISPLAY:
  484. ACPI_MOVE_32_TO_32(&temp32, &buffer[i + j]);
  485. acpi_os_printf("%08X", temp32);
  486. ACPI_MOVE_32_TO_32(&temp32, &buffer[i + j + 4]);
  487. acpi_os_printf("%08X ", temp32);
  488. break;
  489. }
  490. j += (acpi_native_uint) display;
  491. }
  492. /*
  493. * Print the ASCII equivalent characters but watch out for the bad
  494. * unprintable ones (printable chars are 0x20 through 0x7E)
  495. */
  496. acpi_os_printf(" ");
  497. for (j = 0; j < 16; j++) {
  498. if (i + j >= count) {
  499. acpi_os_printf("\n");
  500. return;
  501. }
  502. buf_char = buffer[i + j];
  503. if (ACPI_IS_PRINT(buf_char)) {
  504. acpi_os_printf("%c", buf_char);
  505. } else {
  506. acpi_os_printf(".");
  507. }
  508. }
  509. /* Done with that line. */
  510. acpi_os_printf("\n");
  511. i += 16;
  512. }
  513. return;
  514. }
  515. /*******************************************************************************
  516. *
  517. * FUNCTION: acpi_ut_dump_buffer
  518. *
  519. * PARAMETERS: Buffer - Buffer to dump
  520. * Count - Amount to dump, in bytes
  521. * Display - BYTE, WORD, DWORD, or QWORD display
  522. * component_iD - Caller's component ID
  523. *
  524. * RETURN: None
  525. *
  526. * DESCRIPTION: Generic dump buffer in both hex and ascii.
  527. *
  528. ******************************************************************************/
  529. void acpi_ut_dump_buffer(u8 * buffer, u32 count, u32 display, u32 component_id)
  530. {
  531. /* Only dump the buffer if tracing is enabled */
  532. if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
  533. (component_id & acpi_dbg_layer))) {
  534. return;
  535. }
  536. acpi_ut_dump_buffer2(buffer, count, display);
  537. }