utdebug.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. /******************************************************************************
  2. *
  3. * Module Name: utdebug - Debug print/trace routines
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2015, 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. #include "acinterp.h"
  46. #define _COMPONENT ACPI_UTILITIES
  47. ACPI_MODULE_NAME("utdebug")
  48. #ifdef ACPI_DEBUG_OUTPUT
  49. static acpi_thread_id acpi_gbl_prev_thread_id = (acpi_thread_id) 0xFFFFFFFF;
  50. static char *acpi_gbl_fn_entry_str = "----Entry";
  51. static char *acpi_gbl_fn_exit_str = "----Exit-";
  52. /* Local prototypes */
  53. static const char *acpi_ut_trim_function_name(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 acpi_ut_init_stack_ptr_trace(void)
  66. {
  67. acpi_size current_sp;
  68. acpi_gbl_entry_stack_pointer = &current_sp;
  69. }
  70. /*******************************************************************************
  71. *
  72. * FUNCTION: acpi_ut_track_stack_ptr
  73. *
  74. * PARAMETERS: None
  75. *
  76. * RETURN: None
  77. *
  78. * DESCRIPTION: Save the current CPU stack pointer
  79. *
  80. ******************************************************************************/
  81. void acpi_ut_track_stack_ptr(void)
  82. {
  83. acpi_size current_sp;
  84. if (&current_sp < acpi_gbl_lowest_stack_pointer) {
  85. acpi_gbl_lowest_stack_pointer = &current_sp;
  86. }
  87. if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) {
  88. acpi_gbl_deepest_nesting = acpi_gbl_nesting_level;
  89. }
  90. }
  91. /*******************************************************************************
  92. *
  93. * FUNCTION: acpi_ut_trim_function_name
  94. *
  95. * PARAMETERS: function_name - Ascii string containing a procedure name
  96. *
  97. * RETURN: Updated pointer to the function name
  98. *
  99. * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
  100. * This allows compiler macros such as __func__ to be used
  101. * with no change to the debug output.
  102. *
  103. ******************************************************************************/
  104. static const char *acpi_ut_trim_function_name(const char *function_name)
  105. {
  106. /* All Function names are longer than 4 chars, check is safe */
  107. if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_MIXED) {
  108. /* This is the case where the original source has not been modified */
  109. return (function_name + 4);
  110. }
  111. if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_LOWER) {
  112. /* This is the case where the source has been 'linuxized' */
  113. return (function_name + 5);
  114. }
  115. return (function_name);
  116. }
  117. /*******************************************************************************
  118. *
  119. * FUNCTION: acpi_debug_print
  120. *
  121. * PARAMETERS: requested_debug_level - Requested debug print level
  122. * line_number - Caller's line number (for error output)
  123. * function_name - Caller's procedure name
  124. * module_name - Caller's module name
  125. * component_id - Caller's component ID
  126. * format - Printf format field
  127. * ... - Optional printf arguments
  128. *
  129. * RETURN: None
  130. *
  131. * DESCRIPTION: Print error message with prefix consisting of the module name,
  132. * line number, and component ID.
  133. *
  134. ******************************************************************************/
  135. void ACPI_INTERNAL_VAR_XFACE
  136. acpi_debug_print(u32 requested_debug_level,
  137. u32 line_number,
  138. const char *function_name,
  139. const char *module_name,
  140. u32 component_id, const char *format, ...)
  141. {
  142. acpi_thread_id thread_id;
  143. va_list args;
  144. /* Check if debug output enabled */
  145. if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) {
  146. return;
  147. }
  148. /*
  149. * Thread tracking and context switch notification
  150. */
  151. thread_id = acpi_os_get_thread_id();
  152. if (thread_id != acpi_gbl_prev_thread_id) {
  153. if (ACPI_LV_THREADS & acpi_dbg_level) {
  154. acpi_os_printf
  155. ("\n**** Context Switch from TID %u to TID %u ****\n\n",
  156. (u32)acpi_gbl_prev_thread_id, (u32)thread_id);
  157. }
  158. acpi_gbl_prev_thread_id = thread_id;
  159. acpi_gbl_nesting_level = 0;
  160. }
  161. /*
  162. * Display the module name, current line number, thread ID (if requested),
  163. * current procedure nesting level, and the current procedure name
  164. */
  165. acpi_os_printf("%9s-%04ld ", module_name, line_number);
  166. #ifdef ACPI_APPLICATION
  167. /*
  168. * For acpi_exec/iASL only, emit the thread ID and nesting level.
  169. * Note: nesting level is really only useful during a single-thread
  170. * execution. Otherwise, multiple threads will keep resetting the
  171. * level.
  172. */
  173. if (ACPI_LV_THREADS & acpi_dbg_level) {
  174. acpi_os_printf("[%u] ", (u32)thread_id);
  175. }
  176. acpi_os_printf("[%02ld] ", acpi_gbl_nesting_level);
  177. #endif
  178. acpi_os_printf("%-22.22s: ", acpi_ut_trim_function_name(function_name));
  179. va_start(args, format);
  180. acpi_os_vprintf(format, args);
  181. va_end(args);
  182. }
  183. ACPI_EXPORT_SYMBOL(acpi_debug_print)
  184. /*******************************************************************************
  185. *
  186. * FUNCTION: acpi_debug_print_raw
  187. *
  188. * PARAMETERS: requested_debug_level - Requested debug print level
  189. * line_number - Caller's line number
  190. * function_name - Caller's procedure name
  191. * module_name - Caller's module name
  192. * component_id - Caller's component ID
  193. * format - Printf format field
  194. * ... - Optional printf arguments
  195. *
  196. * RETURN: None
  197. *
  198. * DESCRIPTION: Print message with no headers. Has same interface as
  199. * debug_print so that the same macros can be used.
  200. *
  201. ******************************************************************************/
  202. void ACPI_INTERNAL_VAR_XFACE
  203. acpi_debug_print_raw(u32 requested_debug_level,
  204. u32 line_number,
  205. const char *function_name,
  206. const char *module_name,
  207. u32 component_id, const char *format, ...)
  208. {
  209. va_list args;
  210. /* Check if debug output enabled */
  211. if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) {
  212. return;
  213. }
  214. va_start(args, format);
  215. acpi_os_vprintf(format, args);
  216. va_end(args);
  217. }
  218. ACPI_EXPORT_SYMBOL(acpi_debug_print_raw)
  219. /*******************************************************************************
  220. *
  221. * FUNCTION: acpi_ut_trace
  222. *
  223. * PARAMETERS: line_number - Caller's line number
  224. * function_name - Caller's procedure name
  225. * module_name - Caller's module name
  226. * component_id - Caller's component ID
  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(u32 line_number,
  236. const char *function_name,
  237. const char *module_name, u32 component_id)
  238. {
  239. acpi_gbl_nesting_level++;
  240. acpi_ut_track_stack_ptr();
  241. /* Check if enabled up-front for performance */
  242. if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
  243. acpi_debug_print(ACPI_LV_FUNCTIONS,
  244. line_number, function_name, module_name,
  245. component_id, "%s\n", acpi_gbl_fn_entry_str);
  246. }
  247. }
  248. ACPI_EXPORT_SYMBOL(acpi_ut_trace)
  249. /*******************************************************************************
  250. *
  251. * FUNCTION: acpi_ut_trace_ptr
  252. *
  253. * PARAMETERS: line_number - Caller's line number
  254. * function_name - Caller's procedure name
  255. * module_name - Caller's module name
  256. * component_id - Caller's component ID
  257. * pointer - Pointer to display
  258. *
  259. * RETURN: None
  260. *
  261. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  262. * set in debug_level
  263. *
  264. ******************************************************************************/
  265. void
  266. acpi_ut_trace_ptr(u32 line_number,
  267. const char *function_name,
  268. const char *module_name, u32 component_id, void *pointer)
  269. {
  270. acpi_gbl_nesting_level++;
  271. acpi_ut_track_stack_ptr();
  272. /* Check if enabled up-front for performance */
  273. if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
  274. acpi_debug_print(ACPI_LV_FUNCTIONS,
  275. line_number, function_name, module_name,
  276. component_id, "%s %p\n", acpi_gbl_fn_entry_str,
  277. pointer);
  278. }
  279. }
  280. /*******************************************************************************
  281. *
  282. * FUNCTION: acpi_ut_trace_str
  283. *
  284. * PARAMETERS: line_number - Caller's line number
  285. * function_name - Caller's procedure name
  286. * module_name - Caller's module name
  287. * component_id - Caller's component ID
  288. * string - Additional string to display
  289. *
  290. * RETURN: None
  291. *
  292. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  293. * set in debug_level
  294. *
  295. ******************************************************************************/
  296. void
  297. acpi_ut_trace_str(u32 line_number,
  298. const char *function_name,
  299. const char *module_name, u32 component_id, char *string)
  300. {
  301. acpi_gbl_nesting_level++;
  302. acpi_ut_track_stack_ptr();
  303. /* Check if enabled up-front for performance */
  304. if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
  305. acpi_debug_print(ACPI_LV_FUNCTIONS,
  306. line_number, function_name, module_name,
  307. component_id, "%s %s\n", acpi_gbl_fn_entry_str,
  308. string);
  309. }
  310. }
  311. /*******************************************************************************
  312. *
  313. * FUNCTION: acpi_ut_trace_u32
  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. * integer - Integer to display
  320. *
  321. * RETURN: None
  322. *
  323. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  324. * set in debug_level
  325. *
  326. ******************************************************************************/
  327. void
  328. acpi_ut_trace_u32(u32 line_number,
  329. const char *function_name,
  330. const char *module_name, u32 component_id, u32 integer)
  331. {
  332. acpi_gbl_nesting_level++;
  333. acpi_ut_track_stack_ptr();
  334. /* Check if enabled up-front for performance */
  335. if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
  336. acpi_debug_print(ACPI_LV_FUNCTIONS,
  337. line_number, function_name, module_name,
  338. component_id, "%s %08X\n",
  339. acpi_gbl_fn_entry_str, integer);
  340. }
  341. }
  342. /*******************************************************************************
  343. *
  344. * FUNCTION: acpi_ut_exit
  345. *
  346. * PARAMETERS: line_number - Caller's line number
  347. * function_name - Caller's procedure name
  348. * module_name - Caller's module name
  349. * component_id - Caller's component ID
  350. *
  351. * RETURN: None
  352. *
  353. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  354. * set in debug_level
  355. *
  356. ******************************************************************************/
  357. void
  358. acpi_ut_exit(u32 line_number,
  359. const char *function_name,
  360. const char *module_name, u32 component_id)
  361. {
  362. /* Check if enabled up-front for performance */
  363. if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
  364. acpi_debug_print(ACPI_LV_FUNCTIONS,
  365. line_number, function_name, module_name,
  366. component_id, "%s\n", acpi_gbl_fn_exit_str);
  367. }
  368. if (acpi_gbl_nesting_level) {
  369. acpi_gbl_nesting_level--;
  370. }
  371. }
  372. ACPI_EXPORT_SYMBOL(acpi_ut_exit)
  373. /*******************************************************************************
  374. *
  375. * FUNCTION: acpi_ut_status_exit
  376. *
  377. * PARAMETERS: line_number - Caller's line number
  378. * function_name - Caller's procedure name
  379. * module_name - Caller's module name
  380. * component_id - Caller's component ID
  381. * status - Exit status code
  382. *
  383. * RETURN: None
  384. *
  385. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  386. * set in debug_level. Prints exit status also.
  387. *
  388. ******************************************************************************/
  389. void
  390. acpi_ut_status_exit(u32 line_number,
  391. const char *function_name,
  392. const char *module_name,
  393. u32 component_id, acpi_status status)
  394. {
  395. /* Check if enabled up-front for performance */
  396. if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
  397. if (ACPI_SUCCESS(status)) {
  398. acpi_debug_print(ACPI_LV_FUNCTIONS,
  399. line_number, function_name,
  400. module_name, component_id, "%s %s\n",
  401. acpi_gbl_fn_exit_str,
  402. acpi_format_exception(status));
  403. } else {
  404. acpi_debug_print(ACPI_LV_FUNCTIONS,
  405. line_number, function_name,
  406. module_name, component_id,
  407. "%s ****Exception****: %s\n",
  408. acpi_gbl_fn_exit_str,
  409. acpi_format_exception(status));
  410. }
  411. }
  412. if (acpi_gbl_nesting_level) {
  413. acpi_gbl_nesting_level--;
  414. }
  415. }
  416. ACPI_EXPORT_SYMBOL(acpi_ut_status_exit)
  417. /*******************************************************************************
  418. *
  419. * FUNCTION: acpi_ut_value_exit
  420. *
  421. * PARAMETERS: line_number - Caller's line number
  422. * function_name - Caller's procedure name
  423. * module_name - Caller's module name
  424. * component_id - Caller's component ID
  425. * value - Value to be printed with exit msg
  426. *
  427. * RETURN: None
  428. *
  429. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  430. * set in debug_level. Prints exit value also.
  431. *
  432. ******************************************************************************/
  433. void
  434. acpi_ut_value_exit(u32 line_number,
  435. const char *function_name,
  436. const char *module_name, u32 component_id, u64 value)
  437. {
  438. /* Check if enabled up-front for performance */
  439. if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
  440. acpi_debug_print(ACPI_LV_FUNCTIONS,
  441. line_number, function_name, module_name,
  442. component_id, "%s %8.8X%8.8X\n",
  443. acpi_gbl_fn_exit_str,
  444. ACPI_FORMAT_UINT64(value));
  445. }
  446. if (acpi_gbl_nesting_level) {
  447. acpi_gbl_nesting_level--;
  448. }
  449. }
  450. ACPI_EXPORT_SYMBOL(acpi_ut_value_exit)
  451. /*******************************************************************************
  452. *
  453. * FUNCTION: acpi_ut_ptr_exit
  454. *
  455. * PARAMETERS: line_number - Caller's line number
  456. * function_name - Caller's procedure name
  457. * module_name - Caller's module name
  458. * component_id - Caller's component ID
  459. * ptr - Pointer to display
  460. *
  461. * RETURN: None
  462. *
  463. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  464. * set in debug_level. Prints exit value also.
  465. *
  466. ******************************************************************************/
  467. void
  468. acpi_ut_ptr_exit(u32 line_number,
  469. const char *function_name,
  470. const char *module_name, u32 component_id, u8 *ptr)
  471. {
  472. /* Check if enabled up-front for performance */
  473. if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
  474. acpi_debug_print(ACPI_LV_FUNCTIONS,
  475. line_number, function_name, module_name,
  476. component_id, "%s %p\n", acpi_gbl_fn_exit_str,
  477. ptr);
  478. }
  479. if (acpi_gbl_nesting_level) {
  480. acpi_gbl_nesting_level--;
  481. }
  482. }
  483. /*******************************************************************************
  484. *
  485. * FUNCTION: acpi_trace_point
  486. *
  487. * PARAMETERS: type - Trace event type
  488. * begin - TRUE if before execution
  489. * aml - Executed AML address
  490. * pathname - Object path
  491. * pointer - Pointer to the related object
  492. *
  493. * RETURN: None
  494. *
  495. * DESCRIPTION: Interpreter execution trace.
  496. *
  497. ******************************************************************************/
  498. void
  499. acpi_trace_point(acpi_trace_event_type type, u8 begin, u8 *aml, char *pathname)
  500. {
  501. ACPI_FUNCTION_ENTRY();
  502. acpi_ex_trace_point(type, begin, aml, pathname);
  503. #ifdef ACPI_USE_SYSTEM_TRACER
  504. acpi_os_trace_point(type, begin, aml, pathname);
  505. #endif
  506. }
  507. ACPI_EXPORT_SYMBOL(acpi_trace_point)
  508. #endif
  509. #ifdef ACPI_APPLICATION
  510. /*******************************************************************************
  511. *
  512. * FUNCTION: acpi_log_error
  513. *
  514. * PARAMETERS: format - Printf format field
  515. * ... - Optional printf arguments
  516. *
  517. * RETURN: None
  518. *
  519. * DESCRIPTION: Print error message to the console, used by applications.
  520. *
  521. ******************************************************************************/
  522. void ACPI_INTERNAL_VAR_XFACE acpi_log_error(const char *format, ...)
  523. {
  524. va_list args;
  525. va_start(args, format);
  526. (void)acpi_ut_file_vprintf(ACPI_FILE_ERR, format, args);
  527. va_end(args);
  528. }
  529. ACPI_EXPORT_SYMBOL(acpi_log_error)
  530. #endif