utdebug.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631
  1. /******************************************************************************
  2. *
  3. * Module Name: utdebug - Debug print/trace routines
  4. *
  5. *****************************************************************************/
  6. /*
  7. * Copyright (C) 2000 - 2016, 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_previous_thread_id = (acpi_thread_id) 0xFFFFFFFF;
  50. static const char *acpi_gbl_function_entry_prefix = "----Entry";
  51. static const char *acpi_gbl_function_exit_prefix = "----Exit-";
  52. /*******************************************************************************
  53. *
  54. * FUNCTION: acpi_ut_init_stack_ptr_trace
  55. *
  56. * PARAMETERS: None
  57. *
  58. * RETURN: None
  59. *
  60. * DESCRIPTION: Save the current CPU stack pointer at subsystem startup
  61. *
  62. ******************************************************************************/
  63. void acpi_ut_init_stack_ptr_trace(void)
  64. {
  65. acpi_size current_sp;
  66. acpi_gbl_entry_stack_pointer = &current_sp;
  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 acpi_ut_track_stack_ptr(void)
  80. {
  81. acpi_size current_sp;
  82. if (&current_sp < acpi_gbl_lowest_stack_pointer) {
  83. acpi_gbl_lowest_stack_pointer = &current_sp;
  84. }
  85. if (acpi_gbl_nesting_level > acpi_gbl_deepest_nesting) {
  86. acpi_gbl_deepest_nesting = acpi_gbl_nesting_level;
  87. }
  88. }
  89. /*******************************************************************************
  90. *
  91. * FUNCTION: acpi_ut_trim_function_name
  92. *
  93. * PARAMETERS: function_name - Ascii string containing a procedure name
  94. *
  95. * RETURN: Updated pointer to the function name
  96. *
  97. * DESCRIPTION: Remove the "Acpi" prefix from the function name, if present.
  98. * This allows compiler macros such as __func__ to be used
  99. * with no change to the debug output.
  100. *
  101. ******************************************************************************/
  102. static const char *acpi_ut_trim_function_name(const char *function_name)
  103. {
  104. /* All Function names are longer than 4 chars, check is safe */
  105. if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_MIXED) {
  106. /* This is the case where the original source has not been modified */
  107. return (function_name + 4);
  108. }
  109. if (*(ACPI_CAST_PTR(u32, function_name)) == ACPI_PREFIX_LOWER) {
  110. /* This is the case where the source has been 'linuxized' */
  111. return (function_name + 5);
  112. }
  113. return (function_name);
  114. }
  115. /*******************************************************************************
  116. *
  117. * FUNCTION: acpi_debug_print
  118. *
  119. * PARAMETERS: requested_debug_level - Requested debug print level
  120. * line_number - Caller's line number (for error output)
  121. * function_name - Caller's procedure name
  122. * module_name - Caller's module name
  123. * component_id - Caller's component ID
  124. * format - Printf format field
  125. * ... - Optional printf arguments
  126. *
  127. * RETURN: None
  128. *
  129. * DESCRIPTION: Print error message with prefix consisting of the module name,
  130. * line number, and component ID.
  131. *
  132. ******************************************************************************/
  133. void ACPI_INTERNAL_VAR_XFACE
  134. acpi_debug_print(u32 requested_debug_level,
  135. u32 line_number,
  136. const char *function_name,
  137. const char *module_name,
  138. u32 component_id, const char *format, ...)
  139. {
  140. acpi_thread_id thread_id;
  141. va_list args;
  142. /* Check if debug output enabled */
  143. if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) {
  144. return;
  145. }
  146. /*
  147. * Thread tracking and context switch notification
  148. */
  149. thread_id = acpi_os_get_thread_id();
  150. if (thread_id != acpi_gbl_previous_thread_id) {
  151. if (ACPI_LV_THREADS & acpi_dbg_level) {
  152. acpi_os_printf
  153. ("\n**** Context Switch from TID %u to TID %u ****\n\n",
  154. (u32)acpi_gbl_previous_thread_id, (u32)thread_id);
  155. }
  156. acpi_gbl_previous_thread_id = thread_id;
  157. acpi_gbl_nesting_level = 0;
  158. }
  159. /*
  160. * Display the module name, current line number, thread ID (if requested),
  161. * current procedure nesting level, and the current procedure name
  162. */
  163. acpi_os_printf("%9s-%04ld ", module_name, line_number);
  164. #ifdef ACPI_APPLICATION
  165. /*
  166. * For acpi_exec/iASL only, emit the thread ID and nesting level.
  167. * Note: nesting level is really only useful during a single-thread
  168. * execution. Otherwise, multiple threads will keep resetting the
  169. * level.
  170. */
  171. if (ACPI_LV_THREADS & acpi_dbg_level) {
  172. acpi_os_printf("[%u] ", (u32)thread_id);
  173. }
  174. acpi_os_printf("[%02ld] ", acpi_gbl_nesting_level);
  175. #endif
  176. acpi_os_printf("%-22.22s: ", acpi_ut_trim_function_name(function_name));
  177. va_start(args, format);
  178. acpi_os_vprintf(format, args);
  179. va_end(args);
  180. }
  181. ACPI_EXPORT_SYMBOL(acpi_debug_print)
  182. /*******************************************************************************
  183. *
  184. * FUNCTION: acpi_debug_print_raw
  185. *
  186. * PARAMETERS: requested_debug_level - Requested debug print level
  187. * line_number - Caller's line number
  188. * function_name - Caller's procedure name
  189. * module_name - Caller's module name
  190. * component_id - Caller's component ID
  191. * format - Printf format field
  192. * ... - Optional printf arguments
  193. *
  194. * RETURN: None
  195. *
  196. * DESCRIPTION: Print message with no headers. Has same interface as
  197. * debug_print so that the same macros can be used.
  198. *
  199. ******************************************************************************/
  200. void ACPI_INTERNAL_VAR_XFACE
  201. acpi_debug_print_raw(u32 requested_debug_level,
  202. u32 line_number,
  203. const char *function_name,
  204. const char *module_name,
  205. u32 component_id, const char *format, ...)
  206. {
  207. va_list args;
  208. /* Check if debug output enabled */
  209. if (!ACPI_IS_DEBUG_ENABLED(requested_debug_level, component_id)) {
  210. return;
  211. }
  212. va_start(args, format);
  213. acpi_os_vprintf(format, args);
  214. va_end(args);
  215. }
  216. ACPI_EXPORT_SYMBOL(acpi_debug_print_raw)
  217. /*******************************************************************************
  218. *
  219. * FUNCTION: acpi_ut_trace
  220. *
  221. * PARAMETERS: line_number - Caller's line number
  222. * function_name - Caller's procedure name
  223. * module_name - Caller's module name
  224. * component_id - Caller's component ID
  225. *
  226. * RETURN: None
  227. *
  228. * DESCRIPTION: Function entry trace. Prints only if TRACE_FUNCTIONS bit is
  229. * set in debug_level
  230. *
  231. ******************************************************************************/
  232. void
  233. acpi_ut_trace(u32 line_number,
  234. const char *function_name,
  235. const char *module_name, u32 component_id)
  236. {
  237. acpi_gbl_nesting_level++;
  238. acpi_ut_track_stack_ptr();
  239. /* Check if enabled up-front for performance */
  240. if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
  241. acpi_debug_print(ACPI_LV_FUNCTIONS,
  242. line_number, function_name, module_name,
  243. component_id, "%s\n",
  244. acpi_gbl_function_entry_prefix);
  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,
  268. u32 component_id, const 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",
  277. acpi_gbl_function_entry_prefix, 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, const 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",
  308. acpi_gbl_function_entry_prefix, 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_function_entry_prefix, 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",
  367. acpi_gbl_function_exit_prefix);
  368. }
  369. if (acpi_gbl_nesting_level) {
  370. acpi_gbl_nesting_level--;
  371. }
  372. }
  373. ACPI_EXPORT_SYMBOL(acpi_ut_exit)
  374. /*******************************************************************************
  375. *
  376. * FUNCTION: acpi_ut_status_exit
  377. *
  378. * PARAMETERS: line_number - Caller's line number
  379. * function_name - Caller's procedure name
  380. * module_name - Caller's module name
  381. * component_id - Caller's component ID
  382. * status - Exit status code
  383. *
  384. * RETURN: None
  385. *
  386. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  387. * set in debug_level. Prints exit status also.
  388. *
  389. ******************************************************************************/
  390. void
  391. acpi_ut_status_exit(u32 line_number,
  392. const char *function_name,
  393. const char *module_name,
  394. u32 component_id, acpi_status status)
  395. {
  396. /* Check if enabled up-front for performance */
  397. if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
  398. if (ACPI_SUCCESS(status)) {
  399. acpi_debug_print(ACPI_LV_FUNCTIONS,
  400. line_number, function_name,
  401. module_name, component_id, "%s %s\n",
  402. acpi_gbl_function_exit_prefix,
  403. acpi_format_exception(status));
  404. } else {
  405. acpi_debug_print(ACPI_LV_FUNCTIONS,
  406. line_number, function_name,
  407. module_name, component_id,
  408. "%s ****Exception****: %s\n",
  409. acpi_gbl_function_exit_prefix,
  410. acpi_format_exception(status));
  411. }
  412. }
  413. if (acpi_gbl_nesting_level) {
  414. acpi_gbl_nesting_level--;
  415. }
  416. }
  417. ACPI_EXPORT_SYMBOL(acpi_ut_status_exit)
  418. /*******************************************************************************
  419. *
  420. * FUNCTION: acpi_ut_value_exit
  421. *
  422. * PARAMETERS: line_number - Caller's line number
  423. * function_name - Caller's procedure name
  424. * module_name - Caller's module name
  425. * component_id - Caller's component ID
  426. * value - Value to be printed with exit msg
  427. *
  428. * RETURN: None
  429. *
  430. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  431. * set in debug_level. Prints exit value also.
  432. *
  433. ******************************************************************************/
  434. void
  435. acpi_ut_value_exit(u32 line_number,
  436. const char *function_name,
  437. const char *module_name, u32 component_id, u64 value)
  438. {
  439. /* Check if enabled up-front for performance */
  440. if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
  441. acpi_debug_print(ACPI_LV_FUNCTIONS,
  442. line_number, function_name, module_name,
  443. component_id, "%s %8.8X%8.8X\n",
  444. acpi_gbl_function_exit_prefix,
  445. ACPI_FORMAT_UINT64(value));
  446. }
  447. if (acpi_gbl_nesting_level) {
  448. acpi_gbl_nesting_level--;
  449. }
  450. }
  451. ACPI_EXPORT_SYMBOL(acpi_ut_value_exit)
  452. /*******************************************************************************
  453. *
  454. * FUNCTION: acpi_ut_ptr_exit
  455. *
  456. * PARAMETERS: line_number - Caller's line number
  457. * function_name - Caller's procedure name
  458. * module_name - Caller's module name
  459. * component_id - Caller's component ID
  460. * ptr - Pointer to display
  461. *
  462. * RETURN: None
  463. *
  464. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  465. * set in debug_level. Prints exit value also.
  466. *
  467. ******************************************************************************/
  468. void
  469. acpi_ut_ptr_exit(u32 line_number,
  470. const char *function_name,
  471. const char *module_name, u32 component_id, u8 *ptr)
  472. {
  473. /* Check if enabled up-front for performance */
  474. if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
  475. acpi_debug_print(ACPI_LV_FUNCTIONS,
  476. line_number, function_name, module_name,
  477. component_id, "%s %p\n",
  478. acpi_gbl_function_exit_prefix, ptr);
  479. }
  480. if (acpi_gbl_nesting_level) {
  481. acpi_gbl_nesting_level--;
  482. }
  483. }
  484. /*******************************************************************************
  485. *
  486. * FUNCTION: acpi_ut_str_exit
  487. *
  488. * PARAMETERS: line_number - Caller's line number
  489. * function_name - Caller's procedure name
  490. * module_name - Caller's module name
  491. * component_id - Caller's component ID
  492. * string - String to display
  493. *
  494. * RETURN: None
  495. *
  496. * DESCRIPTION: Function exit trace. Prints only if TRACE_FUNCTIONS bit is
  497. * set in debug_level. Prints exit value also.
  498. *
  499. ******************************************************************************/
  500. void
  501. acpi_ut_str_exit(u32 line_number,
  502. const char *function_name,
  503. const char *module_name, u32 component_id, const char *string)
  504. {
  505. /* Check if enabled up-front for performance */
  506. if (ACPI_IS_DEBUG_ENABLED(ACPI_LV_FUNCTIONS, component_id)) {
  507. acpi_debug_print(ACPI_LV_FUNCTIONS,
  508. line_number, function_name, module_name,
  509. component_id, "%s %s\n",
  510. acpi_gbl_function_exit_prefix, string);
  511. }
  512. if (acpi_gbl_nesting_level) {
  513. acpi_gbl_nesting_level--;
  514. }
  515. }
  516. /*******************************************************************************
  517. *
  518. * FUNCTION: acpi_trace_point
  519. *
  520. * PARAMETERS: type - Trace event type
  521. * begin - TRUE if before execution
  522. * aml - Executed AML address
  523. * pathname - Object path
  524. * pointer - Pointer to the related object
  525. *
  526. * RETURN: None
  527. *
  528. * DESCRIPTION: Interpreter execution trace.
  529. *
  530. ******************************************************************************/
  531. void
  532. acpi_trace_point(acpi_trace_event_type type, u8 begin, u8 *aml, char *pathname)
  533. {
  534. ACPI_FUNCTION_ENTRY();
  535. acpi_ex_trace_point(type, begin, aml, pathname);
  536. #ifdef ACPI_USE_SYSTEM_TRACER
  537. acpi_os_trace_point(type, begin, aml, pathname);
  538. #endif
  539. }
  540. ACPI_EXPORT_SYMBOL(acpi_trace_point)
  541. #endif