utdebug.c 20 KB

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