utdebug.c 18 KB

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