utdebug.c 18 KB

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