utdebug.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620
  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 <linux/module.h>
  43. #include <acpi/acpi.h>
  44. #define _COMPONENT ACPI_UTILITIES
  45. ACPI_MODULE_NAME("utdebug")
  46. #ifdef ACPI_DEBUG_OUTPUT
  47. static u32 acpi_gbl_prev_thread_id = 0xFFFFFFFF;
  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. u32 current_sp;
  66. acpi_gbl_entry_stack_pointer = ACPI_PTR_DIFF(&current_sp, NULL);
  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. current_sp = ACPI_PTR_DIFF(&current_sp, NULL);
  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 __FUNCTION__ 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_ut_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_ut_debug_print(u32 requested_debug_level,
  136. u32 line_number,
  137. const char *function_name,
  138. char *module_name, u32 component_id, char *format, ...)
  139. {
  140. u32 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 %X to TID %X ****\n\n",
  157. acpi_gbl_prev_thread_id, 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("[%04lX] ", 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. }
  175. 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. }
  208. EXPORT_SYMBOL(acpi_ut_debug_print_raw);
  209. /*******************************************************************************
  210. *
  211. * FUNCTION: acpi_ut_trace
  212. *
  213. * PARAMETERS: line_number - Caller's line number
  214. * function_name - Caller's procedure name
  215. * module_name - Caller's module name
  216. * component_id - Caller's component ID
  217. *
  218. * RETURN: None
  219. *
  220. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  221. * set in debug_level
  222. *
  223. ******************************************************************************/
  224. void
  225. acpi_ut_trace(u32 line_number,
  226. const char *function_name, char *module_name, u32 component_id)
  227. {
  228. acpi_gbl_nesting_level++;
  229. acpi_ut_track_stack_ptr();
  230. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  231. line_number, function_name, module_name,
  232. component_id, "%s\n", acpi_gbl_fn_entry_str);
  233. }
  234. EXPORT_SYMBOL(acpi_ut_trace);
  235. /*******************************************************************************
  236. *
  237. * FUNCTION: acpi_ut_trace_ptr
  238. *
  239. * PARAMETERS: line_number - Caller's line number
  240. * function_name - Caller's procedure name
  241. * module_name - Caller's module name
  242. * component_id - Caller's component ID
  243. * Pointer - Pointer to display
  244. *
  245. * RETURN: None
  246. *
  247. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  248. * set in debug_level
  249. *
  250. ******************************************************************************/
  251. void
  252. acpi_ut_trace_ptr(u32 line_number,
  253. const char *function_name,
  254. char *module_name, u32 component_id, void *pointer)
  255. {
  256. acpi_gbl_nesting_level++;
  257. acpi_ut_track_stack_ptr();
  258. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  259. line_number, function_name, module_name,
  260. component_id, "%s %p\n", acpi_gbl_fn_entry_str,
  261. pointer);
  262. }
  263. /*******************************************************************************
  264. *
  265. * FUNCTION: acpi_ut_trace_str
  266. *
  267. * PARAMETERS: line_number - Caller's line number
  268. * function_name - Caller's procedure name
  269. * module_name - Caller's module name
  270. * component_id - Caller's component ID
  271. * String - Additional string to display
  272. *
  273. * RETURN: None
  274. *
  275. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  276. * set in debug_level
  277. *
  278. ******************************************************************************/
  279. void
  280. acpi_ut_trace_str(u32 line_number,
  281. const char *function_name,
  282. char *module_name, u32 component_id, char *string)
  283. {
  284. acpi_gbl_nesting_level++;
  285. acpi_ut_track_stack_ptr();
  286. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  287. line_number, function_name, module_name,
  288. component_id, "%s %s\n", acpi_gbl_fn_entry_str,
  289. string);
  290. }
  291. /*******************************************************************************
  292. *
  293. * FUNCTION: acpi_ut_trace_u32
  294. *
  295. * PARAMETERS: line_number - Caller's line number
  296. * function_name - Caller's procedure name
  297. * module_name - Caller's module name
  298. * component_id - Caller's component ID
  299. * Integer - Integer to display
  300. *
  301. * RETURN: None
  302. *
  303. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  304. * set in debug_level
  305. *
  306. ******************************************************************************/
  307. void
  308. acpi_ut_trace_u32(u32 line_number,
  309. const char *function_name,
  310. char *module_name, u32 component_id, u32 integer)
  311. {
  312. acpi_gbl_nesting_level++;
  313. acpi_ut_track_stack_ptr();
  314. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  315. line_number, function_name, module_name,
  316. component_id, "%s %08X\n", acpi_gbl_fn_entry_str,
  317. integer);
  318. }
  319. /*******************************************************************************
  320. *
  321. * FUNCTION: acpi_ut_exit
  322. *
  323. * PARAMETERS: line_number - Caller's line number
  324. * function_name - Caller's procedure name
  325. * module_name - Caller's module name
  326. * component_id - Caller's component ID
  327. *
  328. * RETURN: None
  329. *
  330. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  331. * set in debug_level
  332. *
  333. ******************************************************************************/
  334. void
  335. acpi_ut_exit(u32 line_number,
  336. const char *function_name, char *module_name, u32 component_id)
  337. {
  338. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  339. line_number, function_name, module_name,
  340. component_id, "%s\n", acpi_gbl_fn_exit_str);
  341. acpi_gbl_nesting_level--;
  342. }
  343. EXPORT_SYMBOL(acpi_ut_exit);
  344. /*******************************************************************************
  345. *
  346. * FUNCTION: acpi_ut_status_exit
  347. *
  348. * PARAMETERS: line_number - Caller's line number
  349. * function_name - Caller's procedure name
  350. * module_name - Caller's module name
  351. * component_id - Caller's component ID
  352. * Status - Exit status code
  353. *
  354. * RETURN: None
  355. *
  356. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  357. * set in debug_level. Prints exit status also.
  358. *
  359. ******************************************************************************/
  360. void
  361. acpi_ut_status_exit(u32 line_number,
  362. const char *function_name,
  363. char *module_name, u32 component_id, acpi_status status)
  364. {
  365. if (ACPI_SUCCESS(status)) {
  366. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  367. line_number, function_name, module_name,
  368. component_id, "%s %s\n",
  369. acpi_gbl_fn_exit_str,
  370. acpi_format_exception(status));
  371. } else {
  372. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  373. line_number, function_name, module_name,
  374. component_id, "%s ****Exception****: %s\n",
  375. acpi_gbl_fn_exit_str,
  376. acpi_format_exception(status));
  377. }
  378. acpi_gbl_nesting_level--;
  379. }
  380. EXPORT_SYMBOL(acpi_ut_status_exit);
  381. /*******************************************************************************
  382. *
  383. * FUNCTION: acpi_ut_value_exit
  384. *
  385. * PARAMETERS: line_number - Caller's line number
  386. * function_name - Caller's procedure name
  387. * module_name - Caller's module name
  388. * component_id - Caller's component ID
  389. * Value - Value to be printed with exit msg
  390. *
  391. * RETURN: None
  392. *
  393. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  394. * set in debug_level. Prints exit value also.
  395. *
  396. ******************************************************************************/
  397. void
  398. acpi_ut_value_exit(u32 line_number,
  399. const char *function_name,
  400. char *module_name, u32 component_id, acpi_integer value)
  401. {
  402. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  403. line_number, function_name, module_name,
  404. component_id, "%s %8.8X%8.8X\n",
  405. acpi_gbl_fn_exit_str, ACPI_FORMAT_UINT64(value));
  406. acpi_gbl_nesting_level--;
  407. }
  408. EXPORT_SYMBOL(acpi_ut_value_exit);
  409. /*******************************************************************************
  410. *
  411. * FUNCTION: acpi_ut_ptr_exit
  412. *
  413. * PARAMETERS: line_number - Caller's line number
  414. * function_name - Caller's procedure name
  415. * module_name - Caller's module name
  416. * component_id - Caller's component ID
  417. * Ptr - Pointer to display
  418. *
  419. * RETURN: None
  420. *
  421. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  422. * set in debug_level. Prints exit value also.
  423. *
  424. ******************************************************************************/
  425. void
  426. acpi_ut_ptr_exit(u32 line_number,
  427. const char *function_name,
  428. char *module_name, u32 component_id, u8 * ptr)
  429. {
  430. acpi_ut_debug_print(ACPI_LV_FUNCTIONS,
  431. line_number, function_name, module_name,
  432. component_id, "%s %p\n", acpi_gbl_fn_exit_str, ptr);
  433. acpi_gbl_nesting_level--;
  434. }
  435. #endif
  436. /*******************************************************************************
  437. *
  438. * FUNCTION: acpi_ut_dump_buffer
  439. *
  440. * PARAMETERS: Buffer - Buffer to dump
  441. * Count - Amount to dump, in bytes
  442. * Display - BYTE, WORD, DWORD, or QWORD display
  443. * component_iD - Caller's component ID
  444. *
  445. * RETURN: None
  446. *
  447. * DESCRIPTION: Generic dump buffer in both hex and ascii.
  448. *
  449. ******************************************************************************/
  450. void acpi_ut_dump_buffer(u8 * buffer, u32 count, u32 display, u32 component_id)
  451. {
  452. acpi_native_uint i = 0;
  453. acpi_native_uint j;
  454. u32 temp32;
  455. u8 buf_char;
  456. /* Only dump the buffer if tracing is enabled */
  457. if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
  458. (component_id & acpi_dbg_layer))) {
  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. default: /* Default is BYTE display */
  478. acpi_os_printf("%02X ", buffer[i + j]);
  479. break;
  480. case DB_WORD_DISPLAY:
  481. ACPI_MOVE_16_TO_32(&temp32, &buffer[i + j]);
  482. acpi_os_printf("%04X ", temp32);
  483. break;
  484. case DB_DWORD_DISPLAY:
  485. ACPI_MOVE_32_TO_32(&temp32, &buffer[i + j]);
  486. acpi_os_printf("%08X ", temp32);
  487. break;
  488. case DB_QWORD_DISPLAY:
  489. ACPI_MOVE_32_TO_32(&temp32, &buffer[i + j]);
  490. acpi_os_printf("%08X", temp32);
  491. ACPI_MOVE_32_TO_32(&temp32, &buffer[i + j + 4]);
  492. acpi_os_printf("%08X ", temp32);
  493. break;
  494. }
  495. j += (acpi_native_uint) display;
  496. }
  497. /*
  498. * Print the ASCII equivalent characters but watch out for the bad
  499. * unprintable ones (printable chars are 0x20 through 0x7E)
  500. */
  501. acpi_os_printf(" ");
  502. for (j = 0; j < 16; j++) {
  503. if (i + j >= count) {
  504. acpi_os_printf("\n");
  505. return;
  506. }
  507. buf_char = buffer[i + j];
  508. if (ACPI_IS_PRINT(buf_char)) {
  509. acpi_os_printf("%c", buf_char);
  510. } else {
  511. acpi_os_printf(".");
  512. }
  513. }
  514. /* Done with that line. */
  515. acpi_os_printf("\n");
  516. i += 16;
  517. }
  518. return;
  519. }