utdebug.c 18 KB

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