exdebug.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634
  1. /******************************************************************************
  2. *
  3. * Module Name: exdebug - Support for stores to the AML Debug Object
  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. #include <acpi/acpi.h>
  43. #include "accommon.h"
  44. #include "acnamesp.h"
  45. #include "acinterp.h"
  46. #include "acparser.h"
  47. #define _COMPONENT ACPI_EXECUTER
  48. ACPI_MODULE_NAME("exdebug")
  49. static union acpi_operand_object *acpi_gbl_trace_method_object = NULL;
  50. /* Local prototypes */
  51. #ifdef ACPI_DEBUG_OUTPUT
  52. static const char *acpi_ex_get_trace_event_name(acpi_trace_event_type type);
  53. #endif
  54. #ifndef ACPI_NO_ERROR_MESSAGES
  55. /*******************************************************************************
  56. *
  57. * FUNCTION: acpi_ex_do_debug_object
  58. *
  59. * PARAMETERS: source_desc - Object to be output to "Debug Object"
  60. * level - Indentation level (used for packages)
  61. * index - Current package element, zero if not pkg
  62. *
  63. * RETURN: None
  64. *
  65. * DESCRIPTION: Handles stores to the AML Debug Object. For example:
  66. * Store(INT1, Debug)
  67. *
  68. * This function is not compiled if ACPI_NO_ERROR_MESSAGES is set.
  69. *
  70. * This function is only enabled if acpi_gbl_enable_aml_debug_object is set, or
  71. * if ACPI_LV_DEBUG_OBJECT is set in the acpi_dbg_level. Thus, in the normal
  72. * operational case, stores to the debug object are ignored but can be easily
  73. * enabled if necessary.
  74. *
  75. ******************************************************************************/
  76. void
  77. acpi_ex_do_debug_object(union acpi_operand_object *source_desc,
  78. u32 level, u32 index)
  79. {
  80. u32 i;
  81. u32 timer;
  82. union acpi_operand_object *object_desc;
  83. u32 value;
  84. ACPI_FUNCTION_TRACE_PTR(ex_do_debug_object, source_desc);
  85. /* Output must be enabled via the debug_object global or the dbg_level */
  86. if (!acpi_gbl_enable_aml_debug_object &&
  87. !(acpi_dbg_level & ACPI_LV_DEBUG_OBJECT)) {
  88. return_VOID;
  89. }
  90. /*
  91. * We will emit the current timer value (in microseconds) with each
  92. * debug output. Only need the lower 26 bits. This allows for 67
  93. * million microseconds or 67 seconds before rollover.
  94. */
  95. timer = ((u32)acpi_os_get_timer() / 10); /* (100 nanoseconds to microseconds) */
  96. timer &= 0x03FFFFFF;
  97. /*
  98. * Print line header as long as we are not in the middle of an
  99. * object display
  100. */
  101. if (!((level > 0) && index == 0)) {
  102. acpi_os_printf("[ACPI Debug %.8u] %*s", timer, level, " ");
  103. }
  104. /* Display the index for package output only */
  105. if (index > 0) {
  106. acpi_os_printf("(%.2u) ", index - 1);
  107. }
  108. if (!source_desc) {
  109. acpi_os_printf("[Null Object]\n");
  110. return_VOID;
  111. }
  112. if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) == ACPI_DESC_TYPE_OPERAND) {
  113. acpi_os_printf("%s ",
  114. acpi_ut_get_object_type_name(source_desc));
  115. if (!acpi_ut_valid_internal_object(source_desc)) {
  116. acpi_os_printf("%p, Invalid Internal Object!\n",
  117. source_desc);
  118. return_VOID;
  119. }
  120. } else if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) ==
  121. ACPI_DESC_TYPE_NAMED) {
  122. acpi_os_printf("%s: %p\n",
  123. acpi_ut_get_type_name(((struct
  124. acpi_namespace_node *)
  125. source_desc)->type),
  126. source_desc);
  127. return_VOID;
  128. } else {
  129. return_VOID;
  130. }
  131. /* source_desc is of type ACPI_DESC_TYPE_OPERAND */
  132. switch (source_desc->common.type) {
  133. case ACPI_TYPE_INTEGER:
  134. /* Output correct integer width */
  135. if (acpi_gbl_integer_byte_width == 4) {
  136. acpi_os_printf("0x%8.8X\n",
  137. (u32)source_desc->integer.value);
  138. } else {
  139. acpi_os_printf("0x%8.8X%8.8X\n",
  140. ACPI_FORMAT_UINT64(source_desc->integer.
  141. value));
  142. }
  143. break;
  144. case ACPI_TYPE_BUFFER:
  145. acpi_os_printf("[0x%.2X]\n", (u32)source_desc->buffer.length);
  146. acpi_ut_dump_buffer(source_desc->buffer.pointer,
  147. (source_desc->buffer.length < 256) ?
  148. source_desc->buffer.length : 256,
  149. DB_BYTE_DISPLAY, 0);
  150. break;
  151. case ACPI_TYPE_STRING:
  152. acpi_os_printf("[0x%.2X] \"%s\"\n",
  153. source_desc->string.length,
  154. source_desc->string.pointer);
  155. break;
  156. case ACPI_TYPE_PACKAGE:
  157. acpi_os_printf("[Contains 0x%.2X Elements]\n",
  158. source_desc->package.count);
  159. /* Output the entire contents of the package */
  160. for (i = 0; i < source_desc->package.count; i++) {
  161. acpi_ex_do_debug_object(source_desc->package.
  162. elements[i], level + 4, i + 1);
  163. }
  164. break;
  165. case ACPI_TYPE_LOCAL_REFERENCE:
  166. acpi_os_printf("[%s] ",
  167. acpi_ut_get_reference_name(source_desc));
  168. /* Decode the reference */
  169. switch (source_desc->reference.class) {
  170. case ACPI_REFCLASS_INDEX:
  171. acpi_os_printf("0x%X\n", source_desc->reference.value);
  172. break;
  173. case ACPI_REFCLASS_TABLE:
  174. /* Case for ddb_handle */
  175. acpi_os_printf("Table Index 0x%X\n",
  176. source_desc->reference.value);
  177. return_VOID;
  178. default:
  179. break;
  180. }
  181. acpi_os_printf(" ");
  182. /* Check for valid node first, then valid object */
  183. if (source_desc->reference.node) {
  184. if (ACPI_GET_DESCRIPTOR_TYPE
  185. (source_desc->reference.node) !=
  186. ACPI_DESC_TYPE_NAMED) {
  187. acpi_os_printf
  188. (" %p - Not a valid namespace node\n",
  189. source_desc->reference.node);
  190. } else {
  191. acpi_os_printf("Node %p [%4.4s] ",
  192. source_desc->reference.node,
  193. (source_desc->reference.node)->
  194. name.ascii);
  195. switch ((source_desc->reference.node)->type) {
  196. /* These types have no attached object */
  197. case ACPI_TYPE_DEVICE:
  198. acpi_os_printf("Device\n");
  199. break;
  200. case ACPI_TYPE_THERMAL:
  201. acpi_os_printf("Thermal Zone\n");
  202. break;
  203. default:
  204. acpi_ex_do_debug_object((source_desc->
  205. reference.
  206. node)->object,
  207. level + 4, 0);
  208. break;
  209. }
  210. }
  211. } else if (source_desc->reference.object) {
  212. if (ACPI_GET_DESCRIPTOR_TYPE
  213. (source_desc->reference.object) ==
  214. ACPI_DESC_TYPE_NAMED) {
  215. acpi_ex_do_debug_object(((struct
  216. acpi_namespace_node *)
  217. source_desc->reference.
  218. object)->object,
  219. level + 4, 0);
  220. } else {
  221. object_desc = source_desc->reference.object;
  222. value = source_desc->reference.value;
  223. switch (object_desc->common.type) {
  224. case ACPI_TYPE_BUFFER:
  225. acpi_os_printf("Buffer[%u] = 0x%2.2X\n",
  226. value,
  227. *source_desc->reference.
  228. index_pointer);
  229. break;
  230. case ACPI_TYPE_STRING:
  231. acpi_os_printf
  232. ("String[%u] = \"%c\" (0x%2.2X)\n",
  233. value,
  234. *source_desc->reference.
  235. index_pointer,
  236. *source_desc->reference.
  237. index_pointer);
  238. break;
  239. case ACPI_TYPE_PACKAGE:
  240. acpi_os_printf("Package[%u] = ", value);
  241. acpi_ex_do_debug_object(*source_desc->
  242. reference.where,
  243. level + 4, 0);
  244. break;
  245. default:
  246. acpi_os_printf
  247. ("Unknown Reference object type %X\n",
  248. object_desc->common.type);
  249. break;
  250. }
  251. }
  252. }
  253. break;
  254. default:
  255. acpi_os_printf("%p\n", source_desc);
  256. break;
  257. }
  258. ACPI_DEBUG_PRINT_RAW((ACPI_DB_EXEC, "\n"));
  259. return_VOID;
  260. }
  261. #endif
  262. /*******************************************************************************
  263. *
  264. * FUNCTION: acpi_ex_interpreter_trace_enabled
  265. *
  266. * PARAMETERS: name - Whether method name should be matched,
  267. * this should be checked before starting
  268. * the tracer
  269. *
  270. * RETURN: TRUE if interpreter trace is enabled.
  271. *
  272. * DESCRIPTION: Check whether interpreter trace is enabled
  273. *
  274. ******************************************************************************/
  275. static u8 acpi_ex_interpreter_trace_enabled(char *name)
  276. {
  277. /* Check if tracing is enabled */
  278. if (!(acpi_gbl_trace_flags & ACPI_TRACE_ENABLED)) {
  279. return (FALSE);
  280. }
  281. /*
  282. * Check if tracing is filtered:
  283. *
  284. * 1. If the tracer is started, acpi_gbl_trace_method_object should have
  285. * been filled by the trace starter
  286. * 2. If the tracer is not started, acpi_gbl_trace_method_name should be
  287. * matched if it is specified
  288. * 3. If the tracer is oneshot style, acpi_gbl_trace_method_name should
  289. * not be cleared by the trace stopper during the first match
  290. */
  291. if (acpi_gbl_trace_method_object) {
  292. return (TRUE);
  293. }
  294. if (name &&
  295. (acpi_gbl_trace_method_name &&
  296. strcmp(acpi_gbl_trace_method_name, name))) {
  297. return (FALSE);
  298. }
  299. if ((acpi_gbl_trace_flags & ACPI_TRACE_ONESHOT) &&
  300. !acpi_gbl_trace_method_name) {
  301. return (FALSE);
  302. }
  303. return (TRUE);
  304. }
  305. /*******************************************************************************
  306. *
  307. * FUNCTION: acpi_ex_get_trace_event_name
  308. *
  309. * PARAMETERS: type - Trace event type
  310. *
  311. * RETURN: Trace event name.
  312. *
  313. * DESCRIPTION: Used to obtain the full trace event name.
  314. *
  315. ******************************************************************************/
  316. #ifdef ACPI_DEBUG_OUTPUT
  317. static const char *acpi_ex_get_trace_event_name(acpi_trace_event_type type)
  318. {
  319. switch (type) {
  320. case ACPI_TRACE_AML_METHOD:
  321. return "Method";
  322. case ACPI_TRACE_AML_OPCODE:
  323. return "Opcode";
  324. case ACPI_TRACE_AML_REGION:
  325. return "Region";
  326. default:
  327. return "";
  328. }
  329. }
  330. #endif
  331. /*******************************************************************************
  332. *
  333. * FUNCTION: acpi_ex_trace_point
  334. *
  335. * PARAMETERS: type - Trace event type
  336. * begin - TRUE if before execution
  337. * aml - Executed AML address
  338. * pathname - Object path
  339. *
  340. * RETURN: None
  341. *
  342. * DESCRIPTION: Internal interpreter execution trace.
  343. *
  344. ******************************************************************************/
  345. void
  346. acpi_ex_trace_point(acpi_trace_event_type type,
  347. u8 begin, u8 *aml, char *pathname)
  348. {
  349. ACPI_FUNCTION_NAME(ex_trace_point);
  350. if (pathname) {
  351. ACPI_DEBUG_PRINT((ACPI_DB_TRACE_POINT,
  352. "%s %s [0x%p:%s] execution.\n",
  353. acpi_ex_get_trace_event_name(type),
  354. begin ? "Begin" : "End", aml, pathname));
  355. } else {
  356. ACPI_DEBUG_PRINT((ACPI_DB_TRACE_POINT,
  357. "%s %s [0x%p] execution.\n",
  358. acpi_ex_get_trace_event_name(type),
  359. begin ? "Begin" : "End", aml));
  360. }
  361. }
  362. /*******************************************************************************
  363. *
  364. * FUNCTION: acpi_ex_start_trace_method
  365. *
  366. * PARAMETERS: method_node - Node of the method
  367. * obj_desc - The method object
  368. * walk_state - current state, NULL if not yet executing
  369. * a method.
  370. *
  371. * RETURN: None
  372. *
  373. * DESCRIPTION: Start control method execution trace
  374. *
  375. ******************************************************************************/
  376. void
  377. acpi_ex_start_trace_method(struct acpi_namespace_node *method_node,
  378. union acpi_operand_object *obj_desc,
  379. struct acpi_walk_state *walk_state)
  380. {
  381. acpi_status status;
  382. char *pathname = NULL;
  383. u8 enabled = FALSE;
  384. ACPI_FUNCTION_NAME(ex_start_trace_method);
  385. if (method_node) {
  386. pathname = acpi_ns_get_normalized_pathname(method_node, TRUE);
  387. }
  388. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  389. if (ACPI_FAILURE(status)) {
  390. goto exit;
  391. }
  392. enabled = acpi_ex_interpreter_trace_enabled(pathname);
  393. if (enabled && !acpi_gbl_trace_method_object) {
  394. acpi_gbl_trace_method_object = obj_desc;
  395. acpi_gbl_original_dbg_level = acpi_dbg_level;
  396. acpi_gbl_original_dbg_layer = acpi_dbg_layer;
  397. acpi_dbg_level = ACPI_TRACE_LEVEL_ALL;
  398. acpi_dbg_layer = ACPI_TRACE_LAYER_ALL;
  399. if (acpi_gbl_trace_dbg_level) {
  400. acpi_dbg_level = acpi_gbl_trace_dbg_level;
  401. }
  402. if (acpi_gbl_trace_dbg_layer) {
  403. acpi_dbg_layer = acpi_gbl_trace_dbg_layer;
  404. }
  405. }
  406. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  407. exit:
  408. if (enabled) {
  409. ACPI_TRACE_POINT(ACPI_TRACE_AML_METHOD, TRUE,
  410. obj_desc ? obj_desc->method.aml_start : NULL,
  411. pathname);
  412. }
  413. if (pathname) {
  414. ACPI_FREE(pathname);
  415. }
  416. }
  417. /*******************************************************************************
  418. *
  419. * FUNCTION: acpi_ex_stop_trace_method
  420. *
  421. * PARAMETERS: method_node - Node of the method
  422. * obj_desc - The method object
  423. * walk_state - current state, NULL if not yet executing
  424. * a method.
  425. *
  426. * RETURN: None
  427. *
  428. * DESCRIPTION: Stop control method execution trace
  429. *
  430. ******************************************************************************/
  431. void
  432. acpi_ex_stop_trace_method(struct acpi_namespace_node *method_node,
  433. union acpi_operand_object *obj_desc,
  434. struct acpi_walk_state *walk_state)
  435. {
  436. acpi_status status;
  437. char *pathname = NULL;
  438. u8 enabled;
  439. ACPI_FUNCTION_NAME(ex_stop_trace_method);
  440. if (method_node) {
  441. pathname = acpi_ns_get_normalized_pathname(method_node, TRUE);
  442. }
  443. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  444. if (ACPI_FAILURE(status)) {
  445. goto exit_path;
  446. }
  447. enabled = acpi_ex_interpreter_trace_enabled(NULL);
  448. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  449. if (enabled) {
  450. ACPI_TRACE_POINT(ACPI_TRACE_AML_METHOD, FALSE,
  451. obj_desc ? obj_desc->method.aml_start : NULL,
  452. pathname);
  453. }
  454. status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
  455. if (ACPI_FAILURE(status)) {
  456. goto exit_path;
  457. }
  458. /* Check whether the tracer should be stopped */
  459. if (acpi_gbl_trace_method_object == obj_desc) {
  460. /* Disable further tracing if type is one-shot */
  461. if (acpi_gbl_trace_flags & ACPI_TRACE_ONESHOT) {
  462. acpi_gbl_trace_method_name = NULL;
  463. }
  464. acpi_dbg_level = acpi_gbl_original_dbg_level;
  465. acpi_dbg_layer = acpi_gbl_original_dbg_layer;
  466. acpi_gbl_trace_method_object = NULL;
  467. }
  468. (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
  469. exit_path:
  470. if (pathname) {
  471. ACPI_FREE(pathname);
  472. }
  473. }
  474. /*******************************************************************************
  475. *
  476. * FUNCTION: acpi_ex_start_trace_opcode
  477. *
  478. * PARAMETERS: op - The parser opcode object
  479. * walk_state - current state, NULL if not yet executing
  480. * a method.
  481. *
  482. * RETURN: None
  483. *
  484. * DESCRIPTION: Start opcode execution trace
  485. *
  486. ******************************************************************************/
  487. void
  488. acpi_ex_start_trace_opcode(union acpi_parse_object *op,
  489. struct acpi_walk_state *walk_state)
  490. {
  491. ACPI_FUNCTION_NAME(ex_start_trace_opcode);
  492. if (acpi_ex_interpreter_trace_enabled(NULL) &&
  493. (acpi_gbl_trace_flags & ACPI_TRACE_OPCODE)) {
  494. ACPI_TRACE_POINT(ACPI_TRACE_AML_OPCODE, TRUE,
  495. op->common.aml, op->common.aml_op_name);
  496. }
  497. }
  498. /*******************************************************************************
  499. *
  500. * FUNCTION: acpi_ex_stop_trace_opcode
  501. *
  502. * PARAMETERS: op - The parser opcode object
  503. * walk_state - current state, NULL if not yet executing
  504. * a method.
  505. *
  506. * RETURN: None
  507. *
  508. * DESCRIPTION: Stop opcode execution trace
  509. *
  510. ******************************************************************************/
  511. void
  512. acpi_ex_stop_trace_opcode(union acpi_parse_object *op,
  513. struct acpi_walk_state *walk_state)
  514. {
  515. ACPI_FUNCTION_NAME(ex_stop_trace_opcode);
  516. if (acpi_ex_interpreter_trace_enabled(NULL) &&
  517. (acpi_gbl_trace_flags & ACPI_TRACE_OPCODE)) {
  518. ACPI_TRACE_POINT(ACPI_TRACE_AML_OPCODE, FALSE,
  519. op->common.aml, op->common.aml_op_name);
  520. }
  521. }