utdebug.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624
  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 stack pointer
  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 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: debug_level - Requested debug print level
  97. * proc_name - Caller's procedure name
  98. * module_name - Caller's module name (for error output)
  99. * line_number - Caller's line number (for error output)
  100. * component_id - Caller's component ID (for error output)
  101. *
  102. * Format - Printf format field
  103. * ... - Optional printf arguments
  104. *
  105. * RETURN: None
  106. *
  107. * DESCRIPTION: Print error message with prefix consisting of the module name,
  108. * line number, and component ID.
  109. *
  110. ****************************************************************************/
  111. void ACPI_INTERNAL_VAR_XFACE
  112. acpi_ut_debug_print (
  113. u32 requested_debug_level,
  114. u32 line_number,
  115. struct acpi_debug_print_info *dbg_info,
  116. char *format,
  117. ...)
  118. {
  119. u32 thread_id;
  120. va_list args;
  121. /*
  122. * Stay silent if the debug level or component ID is disabled
  123. */
  124. if (!(requested_debug_level & acpi_dbg_level) ||
  125. !(dbg_info->component_id & acpi_dbg_layer)) {
  126. return;
  127. }
  128. /*
  129. * Thread tracking and context switch notification
  130. */
  131. thread_id = acpi_os_get_thread_id ();
  132. if (thread_id != acpi_gbl_prev_thread_id) {
  133. if (ACPI_LV_THREADS & acpi_dbg_level) {
  134. acpi_os_printf ("\n**** Context Switch from TID %X to TID %X ****\n\n",
  135. acpi_gbl_prev_thread_id, thread_id);
  136. }
  137. acpi_gbl_prev_thread_id = thread_id;
  138. }
  139. /*
  140. * Display the module name, current line number, thread ID (if requested),
  141. * current procedure nesting level, and the current procedure name
  142. */
  143. acpi_os_printf ("%8s-%04ld ", dbg_info->module_name, line_number);
  144. if (ACPI_LV_THREADS & acpi_dbg_level) {
  145. acpi_os_printf ("[%04lX] ", thread_id);
  146. }
  147. acpi_os_printf ("[%02ld] %-22.22s: ", acpi_gbl_nesting_level, dbg_info->proc_name);
  148. va_start (args, format);
  149. acpi_os_vprintf (format, args);
  150. }
  151. EXPORT_SYMBOL(acpi_ut_debug_print);
  152. /*****************************************************************************
  153. *
  154. * FUNCTION: acpi_ut_debug_print_raw
  155. *
  156. * PARAMETERS: requested_debug_level - Requested debug print level
  157. * line_number - Caller's line number
  158. * dbg_info - Contains:
  159. * proc_name - Caller's procedure name
  160. * module_name - Caller's module name
  161. * component_id - Caller's component ID
  162. * Format - Printf format field
  163. * ... - Optional printf arguments
  164. *
  165. * RETURN: None
  166. *
  167. * DESCRIPTION: Print message with no headers. Has same interface as
  168. * debug_print so that the same macros can be used.
  169. *
  170. ****************************************************************************/
  171. void ACPI_INTERNAL_VAR_XFACE
  172. acpi_ut_debug_print_raw (
  173. u32 requested_debug_level,
  174. u32 line_number,
  175. struct acpi_debug_print_info *dbg_info,
  176. char *format,
  177. ...)
  178. {
  179. va_list args;
  180. if (!(requested_debug_level & acpi_dbg_level) ||
  181. !(dbg_info->component_id & acpi_dbg_layer)) {
  182. return;
  183. }
  184. va_start (args, format);
  185. acpi_os_vprintf (format, args);
  186. }
  187. EXPORT_SYMBOL(acpi_ut_debug_print_raw);
  188. /*****************************************************************************
  189. *
  190. * FUNCTION: acpi_ut_trace
  191. *
  192. * PARAMETERS: line_number - Caller's line number
  193. * dbg_info - Contains:
  194. * proc_name - Caller's procedure name
  195. * module_name - Caller's module name
  196. * component_id - Caller's component ID
  197. *
  198. * RETURN: None
  199. *
  200. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  201. * set in debug_level
  202. *
  203. ****************************************************************************/
  204. void
  205. acpi_ut_trace (
  206. u32 line_number,
  207. struct acpi_debug_print_info *dbg_info)
  208. {
  209. acpi_gbl_nesting_level++;
  210. acpi_ut_track_stack_ptr ();
  211. acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
  212. "%s\n", acpi_gbl_fn_entry_str);
  213. }
  214. EXPORT_SYMBOL(acpi_ut_trace);
  215. /*****************************************************************************
  216. *
  217. * FUNCTION: acpi_ut_trace_ptr
  218. *
  219. * PARAMETERS: line_number - Caller's line number
  220. * dbg_info - Contains:
  221. * proc_name - Caller's procedure name
  222. * module_name - Caller's module name
  223. * component_id - Caller's component ID
  224. * Pointer - Pointer to display
  225. *
  226. * RETURN: None
  227. *
  228. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  229. * set in debug_level
  230. *
  231. ****************************************************************************/
  232. void
  233. acpi_ut_trace_ptr (
  234. u32 line_number,
  235. struct acpi_debug_print_info *dbg_info,
  236. void *pointer)
  237. {
  238. acpi_gbl_nesting_level++;
  239. acpi_ut_track_stack_ptr ();
  240. acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
  241. "%s %p\n", acpi_gbl_fn_entry_str, pointer);
  242. }
  243. /*****************************************************************************
  244. *
  245. * FUNCTION: acpi_ut_trace_str
  246. *
  247. * PARAMETERS: line_number - Caller's line number
  248. * dbg_info - Contains:
  249. * proc_name - Caller's procedure name
  250. * module_name - Caller's module name
  251. * component_id - Caller's component ID
  252. * String - Additional string to display
  253. *
  254. * RETURN: None
  255. *
  256. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  257. * set in debug_level
  258. *
  259. ****************************************************************************/
  260. void
  261. acpi_ut_trace_str (
  262. u32 line_number,
  263. struct acpi_debug_print_info *dbg_info,
  264. char *string)
  265. {
  266. acpi_gbl_nesting_level++;
  267. acpi_ut_track_stack_ptr ();
  268. acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
  269. "%s %s\n", acpi_gbl_fn_entry_str, string);
  270. }
  271. /*****************************************************************************
  272. *
  273. * FUNCTION: acpi_ut_trace_u32
  274. *
  275. * PARAMETERS: line_number - Caller's line number
  276. * dbg_info - Contains:
  277. * proc_name - Caller's procedure name
  278. * module_name - Caller's module name
  279. * component_id - Caller's component ID
  280. * Integer - Integer to display
  281. *
  282. * RETURN: None
  283. *
  284. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  285. * set in debug_level
  286. *
  287. ****************************************************************************/
  288. void
  289. acpi_ut_trace_u32 (
  290. u32 line_number,
  291. struct acpi_debug_print_info *dbg_info,
  292. u32 integer)
  293. {
  294. acpi_gbl_nesting_level++;
  295. acpi_ut_track_stack_ptr ();
  296. acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
  297. "%s %08X\n", acpi_gbl_fn_entry_str, integer);
  298. }
  299. /*****************************************************************************
  300. *
  301. * FUNCTION: acpi_ut_exit
  302. *
  303. * PARAMETERS: line_number - Caller's line number
  304. * dbg_info - Contains:
  305. * proc_name - Caller's procedure name
  306. * module_name - Caller's module name
  307. * component_id - Caller's component ID
  308. *
  309. * RETURN: None
  310. *
  311. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  312. * set in debug_level
  313. *
  314. ****************************************************************************/
  315. void
  316. acpi_ut_exit (
  317. u32 line_number,
  318. struct acpi_debug_print_info *dbg_info)
  319. {
  320. acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
  321. "%s\n", acpi_gbl_fn_exit_str);
  322. acpi_gbl_nesting_level--;
  323. }
  324. EXPORT_SYMBOL(acpi_ut_exit);
  325. /*****************************************************************************
  326. *
  327. * FUNCTION: acpi_ut_status_exit
  328. *
  329. * PARAMETERS: line_number - Caller's line number
  330. * dbg_info - Contains:
  331. * proc_name - Caller's procedure name
  332. * module_name - Caller's module name
  333. * component_id - Caller's component ID
  334. * Status - Exit status code
  335. *
  336. * RETURN: None
  337. *
  338. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  339. * set in debug_level. Prints exit status also.
  340. *
  341. ****************************************************************************/
  342. void
  343. acpi_ut_status_exit (
  344. u32 line_number,
  345. struct acpi_debug_print_info *dbg_info,
  346. acpi_status status)
  347. {
  348. if (ACPI_SUCCESS (status)) {
  349. acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
  350. "%s %s\n", acpi_gbl_fn_exit_str,
  351. acpi_format_exception (status));
  352. }
  353. else {
  354. acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
  355. "%s ****Exception****: %s\n", acpi_gbl_fn_exit_str,
  356. acpi_format_exception (status));
  357. }
  358. acpi_gbl_nesting_level--;
  359. }
  360. EXPORT_SYMBOL(acpi_ut_status_exit);
  361. /*****************************************************************************
  362. *
  363. * FUNCTION: acpi_ut_value_exit
  364. *
  365. * PARAMETERS: line_number - Caller's line number
  366. * dbg_info - Contains:
  367. * proc_name - Caller's procedure name
  368. * module_name - Caller's module name
  369. * component_id - Caller's component ID
  370. * Value - Value to be printed with exit msg
  371. *
  372. * RETURN: None
  373. *
  374. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  375. * set in debug_level. Prints exit value also.
  376. *
  377. ****************************************************************************/
  378. void
  379. acpi_ut_value_exit (
  380. u32 line_number,
  381. struct acpi_debug_print_info *dbg_info,
  382. acpi_integer value)
  383. {
  384. acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
  385. "%s %8.8X%8.8X\n", acpi_gbl_fn_exit_str,
  386. ACPI_FORMAT_UINT64 (value));
  387. acpi_gbl_nesting_level--;
  388. }
  389. EXPORT_SYMBOL(acpi_ut_value_exit);
  390. /*****************************************************************************
  391. *
  392. * FUNCTION: acpi_ut_ptr_exit
  393. *
  394. * PARAMETERS: line_number - Caller's line number
  395. * dbg_info - Contains:
  396. * proc_name - Caller's procedure name
  397. * module_name - Caller's module name
  398. * component_id - Caller's component ID
  399. * Value - Value to be printed with exit msg
  400. *
  401. * RETURN: None
  402. *
  403. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  404. * set in debug_level. Prints exit value also.
  405. *
  406. ****************************************************************************/
  407. void
  408. acpi_ut_ptr_exit (
  409. u32 line_number,
  410. struct acpi_debug_print_info *dbg_info,
  411. u8 *ptr)
  412. {
  413. acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
  414. "%s %p\n", acpi_gbl_fn_exit_str, ptr);
  415. acpi_gbl_nesting_level--;
  416. }
  417. #endif
  418. /*****************************************************************************
  419. *
  420. * FUNCTION: acpi_ut_dump_buffer
  421. *
  422. * PARAMETERS: Buffer - Buffer to dump
  423. * Count - Amount to dump, in bytes
  424. * Display - BYTE, WORD, DWORD, or QWORD display
  425. * component_iD - Caller's component ID
  426. *
  427. * RETURN: None
  428. *
  429. * DESCRIPTION: Generic dump buffer in both hex and ascii.
  430. *
  431. ****************************************************************************/
  432. void
  433. acpi_ut_dump_buffer (
  434. u8 *buffer,
  435. u32 count,
  436. u32 display,
  437. u32 component_id)
  438. {
  439. acpi_native_uint i = 0;
  440. acpi_native_uint j;
  441. u32 temp32;
  442. u8 buf_char;
  443. /* Only dump the buffer if tracing is enabled */
  444. if (!((ACPI_LV_TABLES & acpi_dbg_level) &&
  445. (component_id & acpi_dbg_layer))) {
  446. return;
  447. }
  448. if ((count < 4) || (count & 0x01)) {
  449. display = DB_BYTE_DISPLAY;
  450. }
  451. acpi_os_printf ("\nOffset Value\n");
  452. /*
  453. * Nasty little dump buffer routine!
  454. */
  455. while (i < count) {
  456. /* Print current offset */
  457. acpi_os_printf ("%05X ", (u32) i);
  458. /* Print 16 hex chars */
  459. for (j = 0; j < 16;) {
  460. if (i + j >= count) {
  461. acpi_os_printf ("\n");
  462. return;
  463. }
  464. /* Make sure that the s8 doesn't get sign-extended! */
  465. switch (display) {
  466. /* Default is BYTE display */
  467. default:
  468. acpi_os_printf ("%02X ",
  469. *((u8 *) &buffer[i + j]));
  470. j += 1;
  471. break;
  472. case DB_WORD_DISPLAY:
  473. ACPI_MOVE_16_TO_32 (&temp32, &buffer[i + j]);
  474. acpi_os_printf ("%04X ", temp32);
  475. j += 2;
  476. break;
  477. case DB_DWORD_DISPLAY:
  478. ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]);
  479. acpi_os_printf ("%08X ", temp32);
  480. j += 4;
  481. break;
  482. case DB_QWORD_DISPLAY:
  483. ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j]);
  484. acpi_os_printf ("%08X", temp32);
  485. ACPI_MOVE_32_TO_32 (&temp32, &buffer[i + j + 4]);
  486. acpi_os_printf ("%08X ", temp32);
  487. j += 8;
  488. break;
  489. }
  490. }
  491. /*
  492. * Print the ASCII equivalent characters
  493. * But watch out for the bad unprintable ones...
  494. */
  495. for (j = 0; j < 16; j++) {
  496. if (i + j >= count) {
  497. acpi_os_printf ("\n");
  498. return;
  499. }
  500. buf_char = buffer[i + j];
  501. if ((buf_char > 0x1F && buf_char < 0x2E) ||
  502. (buf_char > 0x2F && buf_char < 0x61) ||
  503. (buf_char > 0x60 && buf_char < 0x7F)) {
  504. acpi_os_printf ("%c", buf_char);
  505. }
  506. else {
  507. acpi_os_printf (".");
  508. }
  509. }
  510. /* Done with that line. */
  511. acpi_os_printf ("\n");
  512. i += 16;
  513. }
  514. return;
  515. }