utdebug.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. /******************************************************************************
  2. *
  3. * Module Name: utdebug - Debug print routines
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2005, 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. /*******************************************************************************
  51. *
  52. * FUNCTION: acpi_ut_init_stack_ptr_trace
  53. *
  54. * PARAMETERS: None
  55. *
  56. * RETURN: None
  57. *
  58. * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
  59. *
  60. ******************************************************************************/
  61. void
  62. acpi_ut_init_stack_ptr_trace (
  63. 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
  80. acpi_ut_track_stack_ptr (
  81. void)
  82. {
  83. acpi_size current_sp;
  84. current_sp = ACPI_PTR_DIFF (&current_sp, NULL);
  85. if (current_sp < acpi_gbl_lowest_stack_pointer) {
  86. acpi_gbl_lowest_stack_pointer = current_sp;
  87. }
  88. if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) {
  89. acpi_gbl_deepest_nesting = acpi_gbl_nesting_level;
  90. }
  91. }
  92. /*******************************************************************************
  93. *
  94. * FUNCTION: acpi_ut_debug_print
  95. *
  96. * PARAMETERS: requested_debug_level - Requested debug print level
  97. * line_number - Caller's line number (for error output)
  98. * function_name - Caller's procedure name
  99. * module_name - Caller's module name
  100. * component_id - Caller's component ID
  101. * Format - Printf format field
  102. * ... - Optional printf arguments
  103. *
  104. * RETURN: None
  105. *
  106. * DESCRIPTION: Print error message with prefix consisting of the module name,
  107. * line number, and component ID.
  108. *
  109. ******************************************************************************/
  110. void ACPI_INTERNAL_VAR_XFACE
  111. acpi_ut_debug_print (
  112. u32 requested_debug_level,
  113. u32 line_number,
  114. char *function_name,
  115. char *module_name,
  116. u32 component_id,
  117. char *format,
  118. ...)
  119. {
  120. u32 thread_id;
  121. va_list args;
  122. /*
  123. * Stay silent if the debug level or component ID is disabled
  124. */
  125. if (!(requested_debug_level & acpi_dbg_level) ||
  126. !(component_id & acpi_dbg_layer)) {
  127. return;
  128. }
  129. /*
  130. * Thread tracking and context switch notification
  131. */
  132. thread_id = acpi_os_get_thread_id ();
  133. if (thread_id != acpi_gbl_prev_thread_id) {
  134. if (ACPI_LV_THREADS & acpi_dbg_level) {
  135. acpi_os_printf (
  136. "\n**** Context Switch from TID %X to TID %X ****\n\n",
  137. acpi_gbl_prev_thread_id, thread_id);
  138. }
  139. acpi_gbl_prev_thread_id = thread_id;
  140. }
  141. /*
  142. * Display the module name, current line number, thread ID (if requested),
  143. * current procedure nesting level, and the current procedure name
  144. */
  145. acpi_os_printf ("%8s-%04ld ", module_name, line_number);
  146. if (ACPI_LV_THREADS & acpi_dbg_level) {
  147. acpi_os_printf ("[%04lX] ", thread_id);
  148. }
  149. acpi_os_printf ("[%02ld] %-22.22s: ",
  150. acpi_gbl_nesting_level, function_name);
  151. va_start (args, format);
  152. acpi_os_vprintf (format, args);
  153. }
  154. EXPORT_SYMBOL(acpi_ut_debug_print);
  155. /*******************************************************************************
  156. *
  157. * FUNCTION: acpi_ut_debug_print_raw
  158. *
  159. * PARAMETERS: requested_debug_level - Requested debug print level
  160. * line_number - Caller's line number
  161. * function_name - Caller's procedure name
  162. * module_name - Caller's module name
  163. * component_id - Caller's component ID
  164. * Format - Printf format field
  165. * ... - Optional printf arguments
  166. *
  167. * RETURN: None
  168. *
  169. * DESCRIPTION: Print message with no headers. Has same interface as
  170. * debug_print so that the same macros can be used.
  171. *
  172. ******************************************************************************/
  173. void ACPI_INTERNAL_VAR_XFACE
  174. acpi_ut_debug_print_raw (
  175. u32 requested_debug_level,
  176. u32 line_number,
  177. char *function_name,
  178. char *module_name,
  179. u32 component_id,
  180. char *format,
  181. ...)
  182. {
  183. va_list args;
  184. if (!(requested_debug_level & acpi_dbg_level) ||
  185. !(component_id & acpi_dbg_layer)) {
  186. return;
  187. }
  188. va_start (args, format);
  189. acpi_os_vprintf (format, args);
  190. }
  191. EXPORT_SYMBOL(acpi_ut_debug_print_raw);
  192. /*******************************************************************************
  193. *
  194. * FUNCTION: acpi_ut_trace
  195. *
  196. * PARAMETERS: line_number - Caller's line number
  197. * function_name - Caller's procedure name
  198. * module_name - Caller's module name
  199. * component_id - Caller's component ID
  200. *
  201. * RETURN: None
  202. *
  203. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  204. * set in debug_level
  205. *
  206. ******************************************************************************/
  207. void
  208. acpi_ut_trace (
  209. u32 line_number,
  210. char *function_name,
  211. char *module_name,
  212. u32 component_id)
  213. {
  214. acpi_gbl_nesting_level++;
  215. acpi_ut_track_stack_ptr ();
  216. acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
  217. line_number, function_name, module_name, component_id,
  218. "%s\n", acpi_gbl_fn_entry_str);
  219. }
  220. EXPORT_SYMBOL(acpi_ut_trace);
  221. /*******************************************************************************
  222. *
  223. * FUNCTION: acpi_ut_trace_ptr
  224. *
  225. * PARAMETERS: line_number - Caller's line number
  226. * function_name - Caller's procedure name
  227. * module_name - Caller's module name
  228. * component_id - Caller's component ID
  229. * Pointer - Pointer to display
  230. *
  231. * RETURN: None
  232. *
  233. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  234. * set in debug_level
  235. *
  236. ******************************************************************************/
  237. void
  238. acpi_ut_trace_ptr (
  239. u32 line_number,
  240. char *function_name,
  241. char *module_name,
  242. u32 component_id,
  243. void *pointer)
  244. {
  245. acpi_gbl_nesting_level++;
  246. acpi_ut_track_stack_ptr ();
  247. acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
  248. line_number, function_name, module_name, component_id,
  249. "%s %p\n", acpi_gbl_fn_entry_str, pointer);
  250. }
  251. /*******************************************************************************
  252. *
  253. * FUNCTION: acpi_ut_trace_str
  254. *
  255. * PARAMETERS: line_number - Caller's line number
  256. * function_name - Caller's procedure name
  257. * module_name - Caller's module name
  258. * component_id - Caller's component ID
  259. * String - Additional string to display
  260. *
  261. * RETURN: None
  262. *
  263. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  264. * set in debug_level
  265. *
  266. ******************************************************************************/
  267. void
  268. acpi_ut_trace_str (
  269. u32 line_number,
  270. char *function_name,
  271. char *module_name,
  272. u32 component_id,
  273. char *string)
  274. {
  275. acpi_gbl_nesting_level++;
  276. acpi_ut_track_stack_ptr ();
  277. acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
  278. line_number, function_name, module_name, component_id,
  279. "%s %s\n", acpi_gbl_fn_entry_str, string);
  280. }
  281. /*******************************************************************************
  282. *
  283. * FUNCTION: acpi_ut_trace_u32
  284. *
  285. * PARAMETERS: line_number - Caller's line number
  286. * function_name - Caller's procedure name
  287. * module_name - Caller's module name
  288. * component_id - Caller's component ID
  289. * Integer - Integer to display
  290. *
  291. * RETURN: None
  292. *
  293. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  294. * set in debug_level
  295. *
  296. ******************************************************************************/
  297. void
  298. acpi_ut_trace_u32 (
  299. u32 line_number,
  300. char *function_name,
  301. char *module_name,
  302. u32 component_id,
  303. u32 integer)
  304. {
  305. acpi_gbl_nesting_level++;
  306. acpi_ut_track_stack_ptr ();
  307. acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
  308. line_number, function_name, module_name, component_id,
  309. "%s %08X\n", acpi_gbl_fn_entry_str, integer);
  310. }
  311. /*******************************************************************************
  312. *
  313. * FUNCTION: acpi_ut_exit
  314. *
  315. * PARAMETERS: line_number - Caller's line number
  316. * function_name - Caller's procedure name
  317. * module_name - Caller's module name
  318. * component_id - Caller's component ID
  319. *
  320. * RETURN: None
  321. *
  322. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  323. * set in debug_level
  324. *
  325. ******************************************************************************/
  326. void
  327. acpi_ut_exit (
  328. u32 line_number,
  329. char *function_name,
  330. char *module_name,
  331. u32 component_id)
  332. {
  333. acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
  334. line_number, function_name, module_name, component_id,
  335. "%s\n", acpi_gbl_fn_exit_str);
  336. acpi_gbl_nesting_level--;
  337. }
  338. EXPORT_SYMBOL(acpi_ut_exit);
  339. /*******************************************************************************
  340. *
  341. * FUNCTION: acpi_ut_status_exit
  342. *
  343. * PARAMETERS: line_number - Caller's line number
  344. * function_name - Caller's procedure name
  345. * module_name - Caller's module name
  346. * component_id - Caller's component ID
  347. * Status - Exit status code
  348. *
  349. * RETURN: None
  350. *
  351. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  352. * set in debug_level. Prints exit status also.
  353. *
  354. ******************************************************************************/
  355. void
  356. acpi_ut_status_exit (
  357. u32 line_number,
  358. char *function_name,
  359. char *module_name,
  360. u32 component_id,
  361. acpi_status status)
  362. {
  363. if (ACPI_SUCCESS (status)) {
  364. acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
  365. line_number, function_name, module_name, component_id,
  366. "%s %s\n", acpi_gbl_fn_exit_str,
  367. acpi_format_exception (status));
  368. }
  369. else {
  370. acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
  371. line_number, function_name, module_name, component_id,
  372. "%s ****Exception****: %s\n", acpi_gbl_fn_exit_str,
  373. acpi_format_exception (status));
  374. }
  375. acpi_gbl_nesting_level--;
  376. }
  377. EXPORT_SYMBOL(acpi_ut_status_exit);
  378. /*******************************************************************************
  379. *
  380. * FUNCTION: acpi_ut_value_exit
  381. *
  382. * PARAMETERS: line_number - Caller's line number
  383. * function_name - Caller's procedure name
  384. * module_name - Caller's module name
  385. * component_id - Caller's component ID
  386. * Value - Value to be printed with exit msg
  387. *
  388. * RETURN: None
  389. *
  390. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  391. * set in debug_level. Prints exit value also.
  392. *
  393. ******************************************************************************/
  394. void
  395. acpi_ut_value_exit (
  396. u32 line_number,
  397. char *function_name,
  398. char *module_name,
  399. u32 component_id,
  400. acpi_integer value)
  401. {
  402. acpi_ut_debug_print (ACPI_LV_FUNCTIONS,
  403. line_number, function_name, module_name, component_id,
  404. "%s %8.8X%8.8X\n", acpi_gbl_fn_exit_str,
  405. 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 (
  427. u32 line_number,
  428. char *function_name,
  429. char *module_name,
  430. u32 component_id,
  431. u8 *ptr)
  432. {
  433. acpi_ut_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
  454. acpi_ut_dump_buffer (
  455. u8 *buffer,
  456. u32 count,
  457. u32 display,
  458. u32 component_id)
  459. {
  460. acpi_native_uint i = 0;
  461. acpi_native_uint j;
  462. u32 temp32;
  463. u8 buf_char;
  464. /* Only dump the buffer if tracing is enabled */
  465. if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
  466. (component_id & acpi_dbg_layer))) {
  467. return;
  468. }
  469. if ((count < 4) || (count & 0x01)) {
  470. display = DB_BYTE_DISPLAY;
  471. }
  472. /* Nasty little dump buffer routine! */
  473. while (i < count) {
  474. /* Print current offset */
  475. acpi_os_printf ("%6.4X: ", (u32) i);
  476. /* Print 16 hex chars */
  477. for (j = 0; j < 16;) {
  478. if (i + j >= count) {
  479. /* Dump fill spaces */
  480. acpi_os_printf ("%*s", ((display * 2) + 1), " ");
  481. j += (acpi_native_uint) display;
  482. continue;
  483. }
  484. switch (display) {
  485. default: /* Default is BYTE display */
  486. acpi_os_printf ("%02X ", buffer[i + j]);
  487. break;
  488. case DB_WORD_DISPLAY:
  489. ACPI_MOVE_16_TO_32 (&temp32, &buffer[i + j]);
  490. acpi_os_printf ("%04X ", temp32);
  491. break;
  492. case DB_DWORD_DISPLAY:
  493. ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]);
  494. acpi_os_printf ("%08X ", temp32);
  495. break;
  496. case DB_QWORD_DISPLAY:
  497. ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]);
  498. acpi_os_printf ("%08X", temp32);
  499. ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j + 4]);
  500. acpi_os_printf ("%08X ", temp32);
  501. break;
  502. }
  503. j += (acpi_native_uint) display;
  504. }
  505. /*
  506. * Print the ASCII equivalent characters
  507. * But watch out for the bad unprintable ones...
  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[i + j];
  516. if ((buf_char > 0x1F && buf_char < 0x2E) ||
  517. (buf_char > 0x2F && buf_char < 0x61) ||
  518. (buf_char > 0x60 && buf_char < 0x7F)) {
  519. acpi_os_printf ("%c", buf_char);
  520. }
  521. else {
  522. acpi_os_printf (".");
  523. }
  524. }
  525. /* Done with that line. */
  526. acpi_os_printf ("\n");
  527. i += 16;
  528. }
  529. return;
  530. }