utdebug.c 19 KB

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