utdebug.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  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. #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 %lX to TID %lX ****\n\n",
  157. (unsigned long)acpi_gbl_prev_thread_id,
  158. (unsigned long)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("[%04lX] ", (unsigned long)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,
  404. u32 component_id, acpi_integer value)
  405. {
  406. acpi_debug_print(ACPI_LV_FUNCTIONS,
  407. line_number, function_name, module_name, component_id,
  408. "%s %8.8X%8.8X\n", acpi_gbl_fn_exit_str,
  409. ACPI_FORMAT_UINT64(value));
  410. acpi_gbl_nesting_level--;
  411. }
  412. ACPI_EXPORT_SYMBOL(acpi_ut_value_exit)
  413. /*******************************************************************************
  414. *
  415. * FUNCTION: acpi_ut_ptr_exit
  416. *
  417. * PARAMETERS: line_number - Caller's line number
  418. * function_name - Caller's procedure name
  419. * module_name - Caller's module name
  420. * component_id - Caller's component ID
  421. * Ptr - Pointer to display
  422. *
  423. * RETURN: None
  424. *
  425. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  426. * set in debug_level. Prints exit value also.
  427. *
  428. ******************************************************************************/
  429. void
  430. acpi_ut_ptr_exit(u32 line_number,
  431. const char *function_name,
  432. const char *module_name, u32 component_id, u8 *ptr)
  433. {
  434. acpi_debug_print(ACPI_LV_FUNCTIONS,
  435. line_number, function_name, module_name, component_id,
  436. "%s %p\n", acpi_gbl_fn_exit_str, ptr);
  437. acpi_gbl_nesting_level--;
  438. }
  439. #endif
  440. /*******************************************************************************
  441. *
  442. * FUNCTION: acpi_ut_dump_buffer
  443. *
  444. * PARAMETERS: Buffer - Buffer to dump
  445. * Count - Amount to dump, in bytes
  446. * Display - BYTE, WORD, DWORD, or QWORD display
  447. * component_iD - Caller's component ID
  448. *
  449. * RETURN: None
  450. *
  451. * DESCRIPTION: Generic dump buffer in both hex and ascii.
  452. *
  453. ******************************************************************************/
  454. void acpi_ut_dump_buffer2(u8 * buffer, u32 count, u32 display)
  455. {
  456. u32 i = 0;
  457. u32 j;
  458. u32 temp32;
  459. u8 buf_char;
  460. if (!buffer) {
  461. acpi_os_printf("Null Buffer Pointer in DumpBuffer!\n");
  462. return;
  463. }
  464. if ((count < 4) || (count & 0x01)) {
  465. display = DB_BYTE_DISPLAY;
  466. }
  467. /* Nasty little dump buffer routine! */
  468. while (i < count) {
  469. /* Print current offset */
  470. acpi_os_printf("%6.4X: ", i);
  471. /* Print 16 hex chars */
  472. for (j = 0; j < 16;) {
  473. if (i + j >= count) {
  474. /* Dump fill spaces */
  475. acpi_os_printf("%*s", ((display * 2) + 1), " ");
  476. j += display;
  477. continue;
  478. }
  479. switch (display) {
  480. case DB_BYTE_DISPLAY:
  481. default: /* Default is BYTE display */
  482. acpi_os_printf("%02X ",
  483. buffer[(acpi_size) i + j]);
  484. break;
  485. case DB_WORD_DISPLAY:
  486. ACPI_MOVE_16_TO_32(&temp32,
  487. &buffer[(acpi_size) i + j]);
  488. acpi_os_printf("%04X ", temp32);
  489. break;
  490. case DB_DWORD_DISPLAY:
  491. ACPI_MOVE_32_TO_32(&temp32,
  492. &buffer[(acpi_size) i + j]);
  493. acpi_os_printf("%08X ", temp32);
  494. break;
  495. case DB_QWORD_DISPLAY:
  496. ACPI_MOVE_32_TO_32(&temp32,
  497. &buffer[(acpi_size) i + j]);
  498. acpi_os_printf("%08X", temp32);
  499. ACPI_MOVE_32_TO_32(&temp32,
  500. &buffer[(acpi_size) i + j +
  501. 4]);
  502. acpi_os_printf("%08X ", temp32);
  503. break;
  504. }
  505. j += display;
  506. }
  507. /*
  508. * Print the ASCII equivalent characters but watch out for the bad
  509. * unprintable ones (printable chars are 0x20 through 0x7E)
  510. */
  511. acpi_os_printf(" ");
  512. for (j = 0; j < 16; j++) {
  513. if (i + j >= count) {
  514. acpi_os_printf("\n");
  515. return;
  516. }
  517. buf_char = buffer[(acpi_size) i + j];
  518. if (ACPI_IS_PRINT(buf_char)) {
  519. acpi_os_printf("%c", buf_char);
  520. } else {
  521. acpi_os_printf(".");
  522. }
  523. }
  524. /* Done with that line. */
  525. acpi_os_printf("\n");
  526. i += 16;
  527. }
  528. return;
  529. }
  530. /*******************************************************************************
  531. *
  532. * FUNCTION: acpi_ut_dump_buffer
  533. *
  534. * PARAMETERS: Buffer - Buffer to dump
  535. * Count - Amount to dump, in bytes
  536. * Display - BYTE, WORD, DWORD, or QWORD display
  537. * component_iD - Caller's component ID
  538. *
  539. * RETURN: None
  540. *
  541. * DESCRIPTION: Generic dump buffer in both hex and ascii.
  542. *
  543. ******************************************************************************/
  544. void acpi_ut_dump_buffer(u8 * buffer, u32 count, u32 display, u32 component_id)
  545. {
  546. /* Only dump the buffer if tracing is enabled */
  547. if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
  548. (component_id & acpi_dbg_layer))) {
  549. return;
  550. }
  551. acpi_ut_dump_buffer2(buffer, count, display);
  552. }