utdebug.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. /******************************************************************************
  2. *
  3. * Module Name: utdebug - Debug print routines
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2011, 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. #include "accommon.h"
  44. #define _COMPONENT ACPI_UTILITIES
  45. ACPI_MODULE_NAME("utdebug")
  46. #ifdef ACPI_DEBUG_OUTPUT
  47. static acpi_thread_id acpi_gbl_prev_thread_id;
  48. static char *acpi_gbl_fn_entry_str = "----Entry";
  49. static char *acpi_gbl_fn_exit_str = "----Exit-";
  50. /* Local prototypes */
  51. static const char *acpi_ut_trim_function_name(const char *function_name);
  52. /*******************************************************************************
  53. *
  54. * FUNCTION: acpi_ut_init_stack_ptr_trace
  55. *
  56. * PARAMETERS: None
  57. *
  58. * RETURN: None
  59. *
  60. * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
  61. *
  62. ******************************************************************************/
  63. void acpi_ut_init_stack_ptr_trace(void)
  64. {
  65. acpi_size current_sp;
  66. acpi_gbl_entry_stack_pointer = &current_sp;
  67. }
  68. /*******************************************************************************
  69. *
  70. * FUNCTION: acpi_ut_track_stack_ptr
  71. *
  72. * PARAMETERS: None
  73. *
  74. * RETURN: None
  75. *
  76. * DESCRIPTION: Save the current CPU stack pointer
  77. *
  78. ******************************************************************************/
  79. void acpi_ut_track_stack_ptr(void)
  80. {
  81. acpi_size current_sp;
  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 __func__ 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_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_debug_print(u32 requested_debug_level,
  135. u32 line_number,
  136. const char *function_name,
  137. const char *module_name,
  138. u32 component_id, const char *format, ...)
  139. {
  140. acpi_thread_id thread_id;
  141. va_list args;
  142. /*
  143. * Stay silent if the debug level or component ID is disabled
  144. */
  145. if (!(requested_debug_level & acpi_dbg_level) ||
  146. !(component_id & acpi_dbg_layer)) {
  147. return;
  148. }
  149. /*
  150. * Thread tracking and context switch notification
  151. */
  152. thread_id = acpi_os_get_thread_id();
  153. if (thread_id != acpi_gbl_prev_thread_id) {
  154. if (ACPI_LV_THREADS & acpi_dbg_level) {
  155. acpi_os_printf
  156. ("\n**** Context Switch from TID %u to TID %u ****\n\n",
  157. (u32)acpi_gbl_prev_thread_id, (u32)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("[%u] ", (u32)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_debug_print)
  177. /*******************************************************************************
  178. *
  179. * FUNCTION: acpi_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_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_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_debug_print(ACPI_LV_FUNCTIONS,
  235. line_number, function_name, module_name, component_id,
  236. "%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_debug_print(ACPI_LV_FUNCTIONS,
  263. line_number, function_name, module_name, component_id,
  264. "%s %p\n", acpi_gbl_fn_entry_str, pointer);
  265. }
  266. /*******************************************************************************
  267. *
  268. * FUNCTION: acpi_ut_trace_str
  269. *
  270. * PARAMETERS: line_number - Caller's line number
  271. * function_name - Caller's procedure name
  272. * module_name - Caller's module name
  273. * component_id - Caller's component ID
  274. * String - Additional string to display
  275. *
  276. * RETURN: None
  277. *
  278. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  279. * set in debug_level
  280. *
  281. ******************************************************************************/
  282. void
  283. acpi_ut_trace_str(u32 line_number,
  284. const char *function_name,
  285. const char *module_name, u32 component_id, char *string)
  286. {
  287. acpi_gbl_nesting_level++;
  288. acpi_ut_track_stack_ptr();
  289. acpi_debug_print(ACPI_LV_FUNCTIONS,
  290. line_number, function_name, module_name, component_id,
  291. "%s %s\n", acpi_gbl_fn_entry_str, string);
  292. }
  293. /*******************************************************************************
  294. *
  295. * FUNCTION: acpi_ut_trace_u32
  296. *
  297. * PARAMETERS: line_number - Caller's line number
  298. * function_name - Caller's procedure name
  299. * module_name - Caller's module name
  300. * component_id - Caller's component ID
  301. * Integer - Integer to display
  302. *
  303. * RETURN: None
  304. *
  305. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  306. * set in debug_level
  307. *
  308. ******************************************************************************/
  309. void
  310. acpi_ut_trace_u32(u32 line_number,
  311. const char *function_name,
  312. const char *module_name, u32 component_id, u32 integer)
  313. {
  314. acpi_gbl_nesting_level++;
  315. acpi_ut_track_stack_ptr();
  316. acpi_debug_print(ACPI_LV_FUNCTIONS,
  317. line_number, function_name, module_name, component_id,
  318. "%s %08X\n", acpi_gbl_fn_entry_str, integer);
  319. }
  320. /*******************************************************************************
  321. *
  322. * FUNCTION: acpi_ut_exit
  323. *
  324. * PARAMETERS: line_number - Caller's line number
  325. * function_name - Caller's procedure name
  326. * module_name - Caller's module name
  327. * component_id - Caller's component ID
  328. *
  329. * RETURN: None
  330. *
  331. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  332. * set in debug_level
  333. *
  334. ******************************************************************************/
  335. void
  336. acpi_ut_exit(u32 line_number,
  337. const char *function_name,
  338. const char *module_name, u32 component_id)
  339. {
  340. acpi_debug_print(ACPI_LV_FUNCTIONS,
  341. line_number, function_name, module_name, component_id,
  342. "%s\n", acpi_gbl_fn_exit_str);
  343. acpi_gbl_nesting_level--;
  344. }
  345. ACPI_EXPORT_SYMBOL(acpi_ut_exit)
  346. /*******************************************************************************
  347. *
  348. * FUNCTION: acpi_ut_status_exit
  349. *
  350. * PARAMETERS: line_number - Caller's line number
  351. * function_name - Caller's procedure name
  352. * module_name - Caller's module name
  353. * component_id - Caller's component ID
  354. * Status - Exit status code
  355. *
  356. * RETURN: None
  357. *
  358. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  359. * set in debug_level. Prints exit status also.
  360. *
  361. ******************************************************************************/
  362. void
  363. acpi_ut_status_exit(u32 line_number,
  364. const char *function_name,
  365. const char *module_name,
  366. u32 component_id, acpi_status status)
  367. {
  368. if (ACPI_SUCCESS(status)) {
  369. acpi_debug_print(ACPI_LV_FUNCTIONS,
  370. line_number, function_name, module_name,
  371. component_id, "%s %s\n", acpi_gbl_fn_exit_str,
  372. acpi_format_exception(status));
  373. } else {
  374. acpi_debug_print(ACPI_LV_FUNCTIONS,
  375. line_number, function_name, module_name,
  376. component_id, "%s ****Exception****: %s\n",
  377. acpi_gbl_fn_exit_str,
  378. acpi_format_exception(status));
  379. }
  380. acpi_gbl_nesting_level--;
  381. }
  382. ACPI_EXPORT_SYMBOL(acpi_ut_status_exit)
  383. /*******************************************************************************
  384. *
  385. * FUNCTION: acpi_ut_value_exit
  386. *
  387. * PARAMETERS: line_number - Caller's line number
  388. * function_name - Caller's procedure name
  389. * module_name - Caller's module name
  390. * component_id - Caller's component ID
  391. * Value - Value to be printed with exit msg
  392. *
  393. * RETURN: None
  394. *
  395. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  396. * set in debug_level. Prints exit value also.
  397. *
  398. ******************************************************************************/
  399. void
  400. acpi_ut_value_exit(u32 line_number,
  401. const char *function_name,
  402. const char *module_name, u32 component_id, u64 value)
  403. {
  404. acpi_debug_print(ACPI_LV_FUNCTIONS,
  405. line_number, function_name, module_name, component_id,
  406. "%s %8.8X%8.8X\n", acpi_gbl_fn_exit_str,
  407. ACPI_FORMAT_UINT64(value));
  408. acpi_gbl_nesting_level--;
  409. }
  410. ACPI_EXPORT_SYMBOL(acpi_ut_value_exit)
  411. /*******************************************************************************
  412. *
  413. * FUNCTION: acpi_ut_ptr_exit
  414. *
  415. * PARAMETERS: line_number - Caller's line number
  416. * function_name - Caller's procedure name
  417. * module_name - Caller's module name
  418. * component_id - Caller's component ID
  419. * Ptr - Pointer to display
  420. *
  421. * RETURN: None
  422. *
  423. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  424. * set in debug_level. Prints exit value also.
  425. *
  426. ******************************************************************************/
  427. void
  428. acpi_ut_ptr_exit(u32 line_number,
  429. const char *function_name,
  430. const char *module_name, u32 component_id, u8 *ptr)
  431. {
  432. acpi_debug_print(ACPI_LV_FUNCTIONS,
  433. line_number, function_name, module_name, component_id,
  434. "%s %p\n", acpi_gbl_fn_exit_str, ptr);
  435. acpi_gbl_nesting_level--;
  436. }
  437. #endif
  438. /*******************************************************************************
  439. *
  440. * FUNCTION: acpi_ut_dump_buffer
  441. *
  442. * PARAMETERS: Buffer - Buffer to dump
  443. * Count - Amount to dump, in bytes
  444. * Display - BYTE, WORD, DWORD, or QWORD display
  445. * component_iD - Caller's component ID
  446. *
  447. * RETURN: None
  448. *
  449. * DESCRIPTION: Generic dump buffer in both hex and ascii.
  450. *
  451. ******************************************************************************/
  452. void acpi_ut_dump_buffer2(u8 * buffer, u32 count, u32 display)
  453. {
  454. u32 i = 0;
  455. u32 j;
  456. u32 temp32;
  457. u8 buf_char;
  458. if (!buffer) {
  459. acpi_os_printf("Null Buffer Pointer in DumpBuffer!\n");
  460. return;
  461. }
  462. if ((count < 4) || (count & 0x01)) {
  463. display = DB_BYTE_DISPLAY;
  464. }
  465. /* Nasty little dump buffer routine! */
  466. while (i < count) {
  467. /* Print current offset */
  468. acpi_os_printf("%6.4X: ", i);
  469. /* Print 16 hex chars */
  470. for (j = 0; j < 16;) {
  471. if (i + j >= count) {
  472. /* Dump fill spaces */
  473. acpi_os_printf("%*s", ((display * 2) + 1), " ");
  474. j += display;
  475. continue;
  476. }
  477. switch (display) {
  478. case DB_BYTE_DISPLAY:
  479. default: /* Default is BYTE display */
  480. acpi_os_printf("%02X ",
  481. buffer[(acpi_size) i + j]);
  482. break;
  483. case DB_WORD_DISPLAY:
  484. ACPI_MOVE_16_TO_32(&temp32,
  485. &buffer[(acpi_size) i + j]);
  486. acpi_os_printf("%04X ", temp32);
  487. break;
  488. case DB_DWORD_DISPLAY:
  489. ACPI_MOVE_32_TO_32(&temp32,
  490. &buffer[(acpi_size) i + j]);
  491. acpi_os_printf("%08X ", temp32);
  492. break;
  493. case DB_QWORD_DISPLAY:
  494. ACPI_MOVE_32_TO_32(&temp32,
  495. &buffer[(acpi_size) i + j]);
  496. acpi_os_printf("%08X", temp32);
  497. ACPI_MOVE_32_TO_32(&temp32,
  498. &buffer[(acpi_size) i + j +
  499. 4]);
  500. acpi_os_printf("%08X ", temp32);
  501. break;
  502. }
  503. j += display;
  504. }
  505. /*
  506. * Print the ASCII equivalent characters but watch out for the bad
  507. * unprintable ones (printable chars are 0x20 through 0x7E)
  508. */
  509. acpi_os_printf(" ");
  510. for (j = 0; j < 16; j++) {
  511. if (i + j >= count) {
  512. acpi_os_printf("\n");
  513. return;
  514. }
  515. buf_char = buffer[(acpi_size) i + j];
  516. if (ACPI_IS_PRINT(buf_char)) {
  517. acpi_os_printf("%c", buf_char);
  518. } else {
  519. acpi_os_printf(".");
  520. }
  521. }
  522. /* Done with that line. */
  523. acpi_os_printf("\n");
  524. i += 16;
  525. }
  526. return;
  527. }
  528. /*******************************************************************************
  529. *
  530. * FUNCTION: acpi_ut_dump_buffer
  531. *
  532. * PARAMETERS: Buffer - Buffer to dump
  533. * Count - Amount to dump, in bytes
  534. * Display - BYTE, WORD, DWORD, or QWORD display
  535. * component_iD - Caller's component ID
  536. *
  537. * RETURN: None
  538. *
  539. * DESCRIPTION: Generic dump buffer in both hex and ascii.
  540. *
  541. ******************************************************************************/
  542. void acpi_ut_dump_buffer(u8 * buffer, u32 count, u32 display, u32 component_id)
  543. {
  544. /* Only dump the buffer if tracing is enabled */
  545. if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
  546. (component_id & acpi_dbg_layer))) {
  547. return;
  548. }
  549. acpi_ut_dump_buffer2(buffer, count, display);
  550. }