utdebug.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642
  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. char *module_name, u32 component_id, char *format, ...)
  137. {
  138. acpi_thread_id thread_id;
  139. va_list args;
  140. /*
  141. * Stay silent if the debug level or component ID is disabled
  142. */
  143. if (!(requested_debug_level & acpi_dbg_level) ||
  144. !(component_id & acpi_dbg_layer)) {
  145. return;
  146. }
  147. /*
  148. * Thread tracking and context switch notification
  149. */
  150. thread_id = acpi_os_get_thread_id();
  151. if (thread_id != acpi_gbl_prev_thread_id) {
  152. if (ACPI_LV_THREADS & acpi_dbg_level) {
  153. acpi_os_printf
  154. ("\n**** Context Switch from TID %lX to TID %lX ****\n\n",
  155. (unsigned long)acpi_gbl_prev_thread_id,
  156. (unsigned long)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] ", (unsigned long)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. va_end(args);
  174. }
  175. ACPI_EXPORT_SYMBOL(acpi_ut_debug_print)
  176. /*******************************************************************************
  177. *
  178. * FUNCTION: acpi_ut_debug_print_raw
  179. *
  180. * PARAMETERS: requested_debug_level - Requested debug print level
  181. * line_number - Caller's line number
  182. * function_name - Caller's procedure name
  183. * module_name - Caller's module name
  184. * component_id - Caller's component ID
  185. * Format - Printf format field
  186. * ... - Optional printf arguments
  187. *
  188. * RETURN: None
  189. *
  190. * DESCRIPTION: Print message with no headers. Has same interface as
  191. * debug_print so that the same macros can be used.
  192. *
  193. ******************************************************************************/
  194. void ACPI_INTERNAL_VAR_XFACE
  195. acpi_ut_debug_print_raw(u32 requested_debug_level,
  196. u32 line_number,
  197. const char *function_name,
  198. char *module_name, u32 component_id, char *format, ...)
  199. {
  200. va_list args;
  201. if (!(requested_debug_level & acpi_dbg_level) ||
  202. !(component_id & acpi_dbg_layer)) {
  203. return;
  204. }
  205. va_start(args, format);
  206. acpi_os_vprintf(format, args);
  207. va_end(args);
  208. }
  209. ACPI_EXPORT_SYMBOL(acpi_ut_debug_print_raw)
  210. /*******************************************************************************
  211. *
  212. * FUNCTION: acpi_ut_trace
  213. *
  214. * PARAMETERS: line_number - Caller's line number
  215. * function_name - Caller's procedure name
  216. * module_name - Caller's module name
  217. * component_id - Caller's component ID
  218. *
  219. * RETURN: None
  220. *
  221. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  222. * set in debug_level
  223. *
  224. ******************************************************************************/
  225. void
  226. acpi_ut_trace(u32 line_number,
  227. const char *function_name, char *module_name, u32 component_id)
  228. {
  229. acpi_gbl_nesting_level++;
  230. acpi_ut_track_stack_ptr();
  231. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  232. line_number, function_name, module_name,
  233. component_id, "%s\n", acpi_gbl_fn_entry_str);
  234. }
  235. ACPI_EXPORT_SYMBOL(acpi_ut_trace)
  236. /*******************************************************************************
  237. *
  238. * FUNCTION: acpi_ut_trace_ptr
  239. *
  240. * PARAMETERS: line_number - Caller's line number
  241. * function_name - Caller's procedure name
  242. * module_name - Caller's module name
  243. * component_id - Caller's component ID
  244. * Pointer - Pointer to display
  245. *
  246. * RETURN: None
  247. *
  248. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  249. * set in debug_level
  250. *
  251. ******************************************************************************/
  252. void
  253. acpi_ut_trace_ptr(u32 line_number,
  254. const char *function_name,
  255. char *module_name, u32 component_id, void *pointer)
  256. {
  257. acpi_gbl_nesting_level++;
  258. acpi_ut_track_stack_ptr();
  259. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  260. line_number, function_name, module_name,
  261. component_id, "%s %p\n", acpi_gbl_fn_entry_str,
  262. pointer);
  263. }
  264. /*******************************************************************************
  265. *
  266. * FUNCTION: acpi_ut_trace_str
  267. *
  268. * PARAMETERS: line_number - Caller's line number
  269. * function_name - Caller's procedure name
  270. * module_name - Caller's module name
  271. * component_id - Caller's component ID
  272. * String - Additional string to display
  273. *
  274. * RETURN: None
  275. *
  276. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  277. * set in debug_level
  278. *
  279. ******************************************************************************/
  280. void
  281. acpi_ut_trace_str(u32 line_number,
  282. const char *function_name,
  283. char *module_name, u32 component_id, char *string)
  284. {
  285. acpi_gbl_nesting_level++;
  286. acpi_ut_track_stack_ptr();
  287. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  288. line_number, function_name, module_name,
  289. component_id, "%s %s\n", acpi_gbl_fn_entry_str,
  290. string);
  291. }
  292. /*******************************************************************************
  293. *
  294. * FUNCTION: acpi_ut_trace_u32
  295. *
  296. * PARAMETERS: line_number - Caller's line number
  297. * function_name - Caller's procedure name
  298. * module_name - Caller's module name
  299. * component_id - Caller's component ID
  300. * Integer - Integer to display
  301. *
  302. * RETURN: None
  303. *
  304. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  305. * set in debug_level
  306. *
  307. ******************************************************************************/
  308. void
  309. acpi_ut_trace_u32(u32 line_number,
  310. const char *function_name,
  311. char *module_name, u32 component_id, u32 integer)
  312. {
  313. acpi_gbl_nesting_level++;
  314. acpi_ut_track_stack_ptr();
  315. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  316. line_number, function_name, module_name,
  317. component_id, "%s %08X\n", acpi_gbl_fn_entry_str,
  318. 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, char *module_name, u32 component_id)
  338. {
  339. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  340. line_number, function_name, module_name,
  341. component_id, "%s\n", acpi_gbl_fn_exit_str);
  342. acpi_gbl_nesting_level--;
  343. }
  344. ACPI_EXPORT_SYMBOL(acpi_ut_exit)
  345. /*******************************************************************************
  346. *
  347. * FUNCTION: acpi_ut_status_exit
  348. *
  349. * PARAMETERS: line_number - Caller's line number
  350. * function_name - Caller's procedure name
  351. * module_name - Caller's module name
  352. * component_id - Caller's component ID
  353. * Status - Exit status code
  354. *
  355. * RETURN: None
  356. *
  357. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  358. * set in debug_level. Prints exit status also.
  359. *
  360. ******************************************************************************/
  361. void
  362. acpi_ut_status_exit(u32 line_number,
  363. const char *function_name,
  364. char *module_name, u32 component_id, acpi_status status)
  365. {
  366. if (ACPI_SUCCESS(status)) {
  367. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  368. line_number, function_name, module_name,
  369. component_id, "%s %s\n",
  370. acpi_gbl_fn_exit_str,
  371. acpi_format_exception(status));
  372. } else {
  373. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  374. line_number, function_name, module_name,
  375. component_id, "%s ****Exception****: %s\n",
  376. acpi_gbl_fn_exit_str,
  377. acpi_format_exception(status));
  378. }
  379. acpi_gbl_nesting_level--;
  380. }
  381. ACPI_EXPORT_SYMBOL(acpi_ut_status_exit)
  382. /*******************************************************************************
  383. *
  384. * FUNCTION: acpi_ut_value_exit
  385. *
  386. * PARAMETERS: line_number - Caller's line number
  387. * function_name - Caller's procedure name
  388. * module_name - Caller's module name
  389. * component_id - Caller's component ID
  390. * Value - Value to be printed with exit msg
  391. *
  392. * RETURN: None
  393. *
  394. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  395. * set in debug_level. Prints exit value also.
  396. *
  397. ******************************************************************************/
  398. void
  399. acpi_ut_value_exit(u32 line_number,
  400. const char *function_name,
  401. char *module_name, u32 component_id, acpi_integer value)
  402. {
  403. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  404. line_number, function_name, module_name,
  405. component_id, "%s %8.8X%8.8X\n",
  406. acpi_gbl_fn_exit_str, ACPI_FORMAT_UINT64(value));
  407. acpi_gbl_nesting_level--;
  408. }
  409. ACPI_EXPORT_SYMBOL(acpi_ut_value_exit)
  410. /*******************************************************************************
  411. *
  412. * FUNCTION: acpi_ut_ptr_exit
  413. *
  414. * PARAMETERS: line_number - Caller's line number
  415. * function_name - Caller's procedure name
  416. * module_name - Caller's module name
  417. * component_id - Caller's component ID
  418. * Ptr - Pointer to display
  419. *
  420. * RETURN: None
  421. *
  422. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  423. * set in debug_level. Prints exit value also.
  424. *
  425. ******************************************************************************/
  426. void
  427. acpi_ut_ptr_exit(u32 line_number,
  428. const char *function_name,
  429. char *module_name, u32 component_id, u8 * ptr)
  430. {
  431. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  432. line_number, function_name, module_name,
  433. component_id, "%s %p\n", acpi_gbl_fn_exit_str, ptr);
  434. acpi_gbl_nesting_level--;
  435. }
  436. #endif
  437. /*******************************************************************************
  438. *
  439. * FUNCTION: acpi_ut_dump_buffer
  440. *
  441. * PARAMETERS: Buffer - Buffer to dump
  442. * Count - Amount to dump, in bytes
  443. * Display - BYTE, WORD, DWORD, or QWORD display
  444. * component_iD - Caller's component ID
  445. *
  446. * RETURN: None
  447. *
  448. * DESCRIPTION: Generic dump buffer in both hex and ascii.
  449. *
  450. ******************************************************************************/
  451. void acpi_ut_dump_buffer2(u8 * buffer, u32 count, u32 display)
  452. {
  453. acpi_native_uint i = 0;
  454. acpi_native_uint j;
  455. u32 temp32;
  456. u8 buf_char;
  457. if (!buffer) {
  458. acpi_os_printf("Null Buffer Pointer in DumpBuffer!\n");
  459. return;
  460. }
  461. if ((count < 4) || (count & 0x01)) {
  462. display = DB_BYTE_DISPLAY;
  463. }
  464. /* Nasty little dump buffer routine! */
  465. while (i < count) {
  466. /* Print current offset */
  467. acpi_os_printf("%6.4X: ", (u32) i);
  468. /* Print 16 hex chars */
  469. for (j = 0; j < 16;) {
  470. if (i + j >= count) {
  471. /* Dump fill spaces */
  472. acpi_os_printf("%*s", ((display * 2) + 1), " ");
  473. j += (acpi_native_uint) display;
  474. continue;
  475. }
  476. switch (display) {
  477. case DB_BYTE_DISPLAY:
  478. default: /* Default is BYTE display */
  479. acpi_os_printf("%02X ", buffer[i + j]);
  480. break;
  481. case DB_WORD_DISPLAY:
  482. ACPI_MOVE_16_TO_32(&temp32, &buffer[i + j]);
  483. acpi_os_printf("%04X ", temp32);
  484. break;
  485. case DB_DWORD_DISPLAY:
  486. ACPI_MOVE_32_TO_32(&temp32, &buffer[i + j]);
  487. acpi_os_printf("%08X ", temp32);
  488. break;
  489. case DB_QWORD_DISPLAY:
  490. ACPI_MOVE_32_TO_32(&temp32, &buffer[i + j]);
  491. acpi_os_printf("%08X", temp32);
  492. ACPI_MOVE_32_TO_32(&temp32, &buffer[i + j + 4]);
  493. acpi_os_printf("%08X ", temp32);
  494. break;
  495. }
  496. j += (acpi_native_uint) display;
  497. }
  498. /*
  499. * Print the ASCII equivalent characters but watch out for the bad
  500. * unprintable ones (printable chars are 0x20 through 0x7E)
  501. */
  502. acpi_os_printf(" ");
  503. for (j = 0; j < 16; j++) {
  504. if (i + j >= count) {
  505. acpi_os_printf("\n");
  506. return;
  507. }
  508. buf_char = buffer[i + j];
  509. if (ACPI_IS_PRINT(buf_char)) {
  510. acpi_os_printf("%c", buf_char);
  511. } else {
  512. acpi_os_printf(".");
  513. }
  514. }
  515. /* Done with that line. */
  516. acpi_os_printf("\n");
  517. i += 16;
  518. }
  519. return;
  520. }
  521. /*******************************************************************************
  522. *
  523. * FUNCTION: acpi_ut_dump_buffer
  524. *
  525. * PARAMETERS: Buffer - Buffer to dump
  526. * Count - Amount to dump, in bytes
  527. * Display - BYTE, WORD, DWORD, or QWORD display
  528. * component_iD - Caller's component ID
  529. *
  530. * RETURN: None
  531. *
  532. * DESCRIPTION: Generic dump buffer in both hex and ascii.
  533. *
  534. ******************************************************************************/
  535. void acpi_ut_dump_buffer(u8 * buffer, u32 count, u32 display, u32 component_id)
  536. {
  537. /* Only dump the buffer if tracing is enabled */
  538. if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
  539. (component_id & acpi_dbg_layer))) {
  540. return;
  541. }
  542. acpi_ut_dump_buffer2(buffer, count, display);
  543. }