utdebug.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563
  1. /******************************************************************************
  2. *
  3. * Module Name: utdebug - Debug print/trace routines
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2013, Intel Corp.
  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. #define EXPORT_ACPI_INTERFACES
  43. #include <acpi/acpi.h>
  44. #include "accommon.h"
  45. #define _COMPONENT ACPI_UTILITIES
  46. ACPI_MODULE_NAME("utdebug")
  47. #ifdef ACPI_DEBUG_OUTPUT
  48. static acpi_thread_id acpi_gbl_prev_thread_id = (acpi_thread_id) 0xFFFFFFFF;
  49. static char *acpi_gbl_fn_entry_str = "----Entry";
  50. static char *acpi_gbl_fn_exit_str = "----Exit-";
  51. /* Local prototypes */
  52. static const char *acpi_ut_trim_function_name(const char *function_name);
  53. /*******************************************************************************
  54. *
  55. * FUNCTION: acpi_ut_init_stack_ptr_trace
  56. *
  57. * PARAMETERS: None
  58. *
  59. * RETURN: None
  60. *
  61. * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
  62. *
  63. ******************************************************************************/
  64. void acpi_ut_init_stack_ptr_trace(void)
  65. {
  66. acpi_size current_sp;
  67. acpi_gbl_entry_stack_pointer = &current_sp;
  68. }
  69. /*******************************************************************************
  70. *
  71. * FUNCTION: acpi_ut_track_stack_ptr
  72. *
  73. * PARAMETERS: None
  74. *
  75. * RETURN: None
  76. *
  77. * DESCRIPTION: Save the current CPU stack pointer
  78. *
  79. ******************************************************************************/
  80. void acpi_ut_track_stack_ptr(void)
  81. {
  82. acpi_size current_sp;
  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_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_debug_print(u32 requested_debug_level,
  136. u32 line_number,
  137. const char *function_name,
  138. const char *module_name,
  139. u32 component_id, const char *format, ...)
  140. {
  141. acpi_thread_id thread_id;
  142. va_list args;
  143. /* Check if debug output enabled */
  144. if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) {
  145. return;
  146. }
  147. /*
  148. * Thread tracking and context switch notification
  149. */
  150. thread_id = acpi_os_get_thread_id();
  151. if (thread_id != acpi_gbl_prev_thread_id) {
  152. if (ACPI_LV_THREADS & acpi_dbg_level) {
  153. acpi_os_printf
  154. ("\n**** Context Switch from TID %u to TID %u ****\n\n",
  155. (u32)acpi_gbl_prev_thread_id, (u32)thread_id);
  156. }
  157. acpi_gbl_prev_thread_id = thread_id;
  158. acpi_gbl_nesting_level = 0;
  159. }
  160. /*
  161. * Display the module name, current line number, thread ID (if requested),
  162. * current procedure nesting level, and the current procedure name
  163. */
  164. acpi_os_printf("%9s-%04ld ", module_name, line_number);
  165. #ifdef ACPI_EXEC_APP
  166. /*
  167. * For acpi_exec only, emit the thread ID and nesting level.
  168. * Note: nesting level is really only useful during a single-thread
  169. * execution. Otherwise, multiple threads will keep resetting the
  170. * level.
  171. */
  172. if (ACPI_LV_THREADS & acpi_dbg_level) {
  173. acpi_os_printf("[%u] ", (u32)thread_id);
  174. }
  175. acpi_os_printf("[%02ld] ", acpi_gbl_nesting_level);
  176. #endif
  177. acpi_os_printf("%-22.22s: ", acpi_ut_trim_function_name(function_name));
  178. va_start(args, format);
  179. acpi_os_vprintf(format, args);
  180. va_end(args);
  181. }
  182. ACPI_EXPORT_SYMBOL(acpi_debug_print)
  183. /*******************************************************************************
  184. *
  185. * FUNCTION: acpi_debug_print_raw
  186. *
  187. * PARAMETERS: requested_debug_level - Requested debug print level
  188. * line_number - Caller's line number
  189. * function_name - Caller's procedure name
  190. * module_name - Caller's module name
  191. * component_id - Caller's component ID
  192. * format - Printf format field
  193. * ... - Optional printf arguments
  194. *
  195. * RETURN: None
  196. *
  197. * DESCRIPTION: Print message with no headers. Has same interface as
  198. * debug_print so that the same macros can be used.
  199. *
  200. ******************************************************************************/
  201. void ACPI_INTERNAL_VAR_XFACE
  202. acpi_debug_print_raw(u32 requested_debug_level,
  203. u32 line_number,
  204. const char *function_name,
  205. const char *module_name,
  206. u32 component_id, const char *format, ...)
  207. {
  208. va_list args;
  209. /* Check if debug output enabled */
  210. if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) {
  211. return;
  212. }
  213. va_start(args, format);
  214. acpi_os_vprintf(format, args);
  215. va_end(args);
  216. }
  217. ACPI_EXPORT_SYMBOL(acpi_debug_print_raw)
  218. /*******************************************************************************
  219. *
  220. * FUNCTION: acpi_ut_trace
  221. *
  222. * PARAMETERS: line_number - Caller's line number
  223. * function_name - Caller's procedure name
  224. * module_name - Caller's module name
  225. * component_id - Caller's component ID
  226. *
  227. * RETURN: None
  228. *
  229. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  230. * set in debug_level
  231. *
  232. ******************************************************************************/
  233. void
  234. acpi_ut_trace(u32 line_number,
  235. const char *function_name,
  236. const char *module_name, u32 component_id)
  237. {
  238. acpi_gbl_nesting_level++;
  239. acpi_ut_track_stack_ptr();
  240. /* Check if enabled up-front for performance */
  241. if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
  242. acpi_debug_print(ACPI_LV_FUNCTIONS,
  243. line_number, function_name, module_name,
  244. component_id, "%s\n", acpi_gbl_fn_entry_str);
  245. }
  246. }
  247. ACPI_EXPORT_SYMBOL(acpi_ut_trace)
  248. /*******************************************************************************
  249. *
  250. * FUNCTION: acpi_ut_trace_ptr
  251. *
  252. * PARAMETERS: line_number - Caller's line number
  253. * function_name - Caller's procedure name
  254. * module_name - Caller's module name
  255. * component_id - Caller's component ID
  256. * pointer - Pointer to display
  257. *
  258. * RETURN: None
  259. *
  260. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  261. * set in debug_level
  262. *
  263. ******************************************************************************/
  264. void
  265. acpi_ut_trace_ptr(u32 line_number,
  266. const char *function_name,
  267. const char *module_name, u32 component_id, void *pointer)
  268. {
  269. acpi_gbl_nesting_level++;
  270. acpi_ut_track_stack_ptr();
  271. /* Check if enabled up-front for performance */
  272. if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
  273. acpi_debug_print(ACPI_LV_FUNCTIONS,
  274. line_number, function_name, module_name,
  275. component_id, "%s %p\n", acpi_gbl_fn_entry_str,
  276. pointer);
  277. }
  278. }
  279. /*******************************************************************************
  280. *
  281. * FUNCTION: acpi_ut_trace_str
  282. *
  283. * PARAMETERS: line_number - Caller's line number
  284. * function_name - Caller's procedure name
  285. * module_name - Caller's module name
  286. * component_id - Caller's component ID
  287. * string - Additional string to display
  288. *
  289. * RETURN: None
  290. *
  291. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  292. * set in debug_level
  293. *
  294. ******************************************************************************/
  295. void
  296. acpi_ut_trace_str(u32 line_number,
  297. const char *function_name,
  298. const char *module_name, u32 component_id, char *string)
  299. {
  300. acpi_gbl_nesting_level++;
  301. acpi_ut_track_stack_ptr();
  302. /* Check if enabled up-front for performance */
  303. if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
  304. acpi_debug_print(ACPI_LV_FUNCTIONS,
  305. line_number, function_name, module_name,
  306. component_id, "%s %s\n", acpi_gbl_fn_entry_str,
  307. string);
  308. }
  309. }
  310. /*******************************************************************************
  311. *
  312. * FUNCTION: acpi_ut_trace_u32
  313. *
  314. * PARAMETERS: line_number - Caller's line number
  315. * function_name - Caller's procedure name
  316. * module_name - Caller's module name
  317. * component_id - Caller's component ID
  318. * integer - Integer to display
  319. *
  320. * RETURN: None
  321. *
  322. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  323. * set in debug_level
  324. *
  325. ******************************************************************************/
  326. void
  327. acpi_ut_trace_u32(u32 line_number,
  328. const char *function_name,
  329. const char *module_name, u32 component_id, u32 integer)
  330. {
  331. acpi_gbl_nesting_level++;
  332. acpi_ut_track_stack_ptr();
  333. /* Check if enabled up-front for performance */
  334. if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
  335. acpi_debug_print(ACPI_LV_FUNCTIONS,
  336. line_number, function_name, module_name,
  337. component_id, "%s %08X\n",
  338. acpi_gbl_fn_entry_str, integer);
  339. }
  340. }
  341. /*******************************************************************************
  342. *
  343. * FUNCTION: acpi_ut_exit
  344. *
  345. * PARAMETERS: line_number - Caller's line number
  346. * function_name - Caller's procedure name
  347. * module_name - Caller's module name
  348. * component_id - Caller's component ID
  349. *
  350. * RETURN: None
  351. *
  352. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  353. * set in debug_level
  354. *
  355. ******************************************************************************/
  356. void
  357. acpi_ut_exit(u32 line_number,
  358. const char *function_name,
  359. const char *module_name, u32 component_id)
  360. {
  361. /* Check if enabled up-front for performance */
  362. if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
  363. acpi_debug_print(ACPI_LV_FUNCTIONS,
  364. line_number, function_name, module_name,
  365. component_id, "%s\n", acpi_gbl_fn_exit_str);
  366. }
  367. if (acpi_gbl_nesting_level) {
  368. acpi_gbl_nesting_level--;
  369. }
  370. }
  371. ACPI_EXPORT_SYMBOL(acpi_ut_exit)
  372. /*******************************************************************************
  373. *
  374. * FUNCTION: acpi_ut_status_exit
  375. *
  376. * PARAMETERS: line_number - Caller's line number
  377. * function_name - Caller's procedure name
  378. * module_name - Caller's module name
  379. * component_id - Caller's component ID
  380. * status - Exit status code
  381. *
  382. * RETURN: None
  383. *
  384. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  385. * set in debug_level. Prints exit status also.
  386. *
  387. ******************************************************************************/
  388. void
  389. acpi_ut_status_exit(u32 line_number,
  390. const char *function_name,
  391. const char *module_name,
  392. u32 component_id, acpi_status status)
  393. {
  394. /* Check if enabled up-front for performance */
  395. if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
  396. if (ACPI_SUCCESS(status)) {
  397. acpi_debug_print(ACPI_LV_FUNCTIONS,
  398. line_number, function_name,
  399. module_name, component_id, "%s %s\n",
  400. acpi_gbl_fn_exit_str,
  401. acpi_format_exception(status));
  402. } else {
  403. acpi_debug_print(ACPI_LV_FUNCTIONS,
  404. line_number, function_name,
  405. module_name, component_id,
  406. "%s ****Exception****: %s\n",
  407. acpi_gbl_fn_exit_str,
  408. acpi_format_exception(status));
  409. }
  410. }
  411. if (acpi_gbl_nesting_level) {
  412. acpi_gbl_nesting_level--;
  413. }
  414. }
  415. ACPI_EXPORT_SYMBOL(acpi_ut_status_exit)
  416. /*******************************************************************************
  417. *
  418. * FUNCTION: acpi_ut_value_exit
  419. *
  420. * PARAMETERS: line_number - Caller's line number
  421. * function_name - Caller's procedure name
  422. * module_name - Caller's module name
  423. * component_id - Caller's component ID
  424. * value - Value to be printed with exit msg
  425. *
  426. * RETURN: None
  427. *
  428. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  429. * set in debug_level. Prints exit value also.
  430. *
  431. ******************************************************************************/
  432. void
  433. acpi_ut_value_exit(u32 line_number,
  434. const char *function_name,
  435. const char *module_name, u32 component_id, u64 value)
  436. {
  437. /* Check if enabled up-front for performance */
  438. if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
  439. acpi_debug_print(ACPI_LV_FUNCTIONS,
  440. line_number, function_name, module_name,
  441. component_id, "%s %8.8X%8.8X\n",
  442. acpi_gbl_fn_exit_str,
  443. ACPI_FORMAT_UINT64(value));
  444. }
  445. if (acpi_gbl_nesting_level) {
  446. acpi_gbl_nesting_level--;
  447. }
  448. }
  449. ACPI_EXPORT_SYMBOL(acpi_ut_value_exit)
  450. /*******************************************************************************
  451. *
  452. * FUNCTION: acpi_ut_ptr_exit
  453. *
  454. * PARAMETERS: line_number - Caller's line number
  455. * function_name - Caller's procedure name
  456. * module_name - Caller's module name
  457. * component_id - Caller's component ID
  458. * ptr - Pointer to display
  459. *
  460. * RETURN: None
  461. *
  462. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  463. * set in debug_level. Prints exit value also.
  464. *
  465. ******************************************************************************/
  466. void
  467. acpi_ut_ptr_exit(u32 line_number,
  468. const char *function_name,
  469. const char *module_name, u32 component_id, u8 *ptr)
  470. {
  471. /* Check if enabled up-front for performance */
  472. if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
  473. acpi_debug_print(ACPI_LV_FUNCTIONS,
  474. line_number, function_name, module_name,
  475. component_id, "%s %p\n", acpi_gbl_fn_exit_str,
  476. ptr);
  477. }
  478. if (acpi_gbl_nesting_level) {
  479. acpi_gbl_nesting_level--;
  480. }
  481. }
  482. #endif