dbobject.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533
  1. /*******************************************************************************
  2. *
  3. * Module Name: dbobject - ACPI object decode and display
  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 "acdebug.h"
  46. #define _COMPONENT ACPI_CA_DEBUGGER
  47. ACPI_MODULE_NAME("dbobject")
  48. /* Local prototypes */
  49. static void acpi_db_decode_node(struct acpi_namespace_node *node);
  50. /*******************************************************************************
  51. *
  52. * FUNCTION: acpi_db_dump_method_info
  53. *
  54. * PARAMETERS: status - Method execution status
  55. * walk_state - Current state of the parse tree walk
  56. *
  57. * RETURN: None
  58. *
  59. * DESCRIPTION: Called when a method has been aborted because of an error.
  60. * Dumps the method execution stack, and the method locals/args,
  61. * and disassembles the AML opcode that failed.
  62. *
  63. ******************************************************************************/
  64. void
  65. acpi_db_dump_method_info(acpi_status status, struct acpi_walk_state *walk_state)
  66. {
  67. struct acpi_thread_state *thread;
  68. /* Ignore control codes, they are not errors */
  69. if ((status & AE_CODE_MASK) == AE_CODE_CONTROL) {
  70. return;
  71. }
  72. /* We may be executing a deferred opcode */
  73. if (walk_state->deferred_node) {
  74. acpi_os_printf("Executing subtree for Buffer/Package/Region\n");
  75. return;
  76. }
  77. /*
  78. * If there is no Thread, we are not actually executing a method.
  79. * This can happen when the iASL compiler calls the interpreter
  80. * to perform constant folding.
  81. */
  82. thread = walk_state->thread;
  83. if (!thread) {
  84. return;
  85. }
  86. /* Display the method locals and arguments */
  87. acpi_os_printf("\n");
  88. acpi_db_decode_locals(walk_state);
  89. acpi_os_printf("\n");
  90. acpi_db_decode_arguments(walk_state);
  91. acpi_os_printf("\n");
  92. }
  93. /*******************************************************************************
  94. *
  95. * FUNCTION: acpi_db_decode_internal_object
  96. *
  97. * PARAMETERS: obj_desc - Object to be displayed
  98. *
  99. * RETURN: None
  100. *
  101. * DESCRIPTION: Short display of an internal object. Numbers/Strings/Buffers.
  102. *
  103. ******************************************************************************/
  104. void acpi_db_decode_internal_object(union acpi_operand_object *obj_desc)
  105. {
  106. u32 i;
  107. if (!obj_desc) {
  108. acpi_os_printf(" Uninitialized");
  109. return;
  110. }
  111. if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) != ACPI_DESC_TYPE_OPERAND) {
  112. acpi_os_printf(" %p [%s]", obj_desc,
  113. acpi_ut_get_descriptor_name(obj_desc));
  114. return;
  115. }
  116. acpi_os_printf(" %s", acpi_ut_get_object_type_name(obj_desc));
  117. switch (obj_desc->common.type) {
  118. case ACPI_TYPE_INTEGER:
  119. acpi_os_printf(" %8.8X%8.8X",
  120. ACPI_FORMAT_UINT64(obj_desc->integer.value));
  121. break;
  122. case ACPI_TYPE_STRING:
  123. acpi_os_printf("(%u) \"%.24s",
  124. obj_desc->string.length,
  125. obj_desc->string.pointer);
  126. if (obj_desc->string.length > 24) {
  127. acpi_os_printf("...");
  128. } else {
  129. acpi_os_printf("\"");
  130. }
  131. break;
  132. case ACPI_TYPE_BUFFER:
  133. acpi_os_printf("(%u)", obj_desc->buffer.length);
  134. for (i = 0; (i < 8) && (i < obj_desc->buffer.length); i++) {
  135. acpi_os_printf(" %2.2X", obj_desc->buffer.pointer[i]);
  136. }
  137. break;
  138. default:
  139. acpi_os_printf(" %p", obj_desc);
  140. break;
  141. }
  142. }
  143. /*******************************************************************************
  144. *
  145. * FUNCTION: acpi_db_decode_node
  146. *
  147. * PARAMETERS: node - Object to be displayed
  148. *
  149. * RETURN: None
  150. *
  151. * DESCRIPTION: Short display of a namespace node
  152. *
  153. ******************************************************************************/
  154. static void acpi_db_decode_node(struct acpi_namespace_node *node)
  155. {
  156. acpi_os_printf("<Node> Name %4.4s",
  157. acpi_ut_get_node_name(node));
  158. if (node->flags & ANOBJ_METHOD_ARG) {
  159. acpi_os_printf(" [Method Arg]");
  160. }
  161. if (node->flags & ANOBJ_METHOD_LOCAL) {
  162. acpi_os_printf(" [Method Local]");
  163. }
  164. switch (node->type) {
  165. /* These types have no attached object */
  166. case ACPI_TYPE_DEVICE:
  167. acpi_os_printf(" Device");
  168. break;
  169. case ACPI_TYPE_THERMAL:
  170. acpi_os_printf(" Thermal Zone");
  171. break;
  172. default:
  173. acpi_db_decode_internal_object(acpi_ns_get_attached_object
  174. (node));
  175. break;
  176. }
  177. }
  178. /*******************************************************************************
  179. *
  180. * FUNCTION: acpi_db_display_internal_object
  181. *
  182. * PARAMETERS: obj_desc - Object to be displayed
  183. * walk_state - Current walk state
  184. *
  185. * RETURN: None
  186. *
  187. * DESCRIPTION: Short display of an internal object
  188. *
  189. ******************************************************************************/
  190. void
  191. acpi_db_display_internal_object(union acpi_operand_object *obj_desc,
  192. struct acpi_walk_state *walk_state)
  193. {
  194. u8 type;
  195. acpi_os_printf("%p ", obj_desc);
  196. if (!obj_desc) {
  197. acpi_os_printf("<Null Object>\n");
  198. return;
  199. }
  200. /* Decode the object type */
  201. switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) {
  202. case ACPI_DESC_TYPE_PARSER:
  203. acpi_os_printf("<Parser> ");
  204. break;
  205. case ACPI_DESC_TYPE_NAMED:
  206. acpi_db_decode_node((struct acpi_namespace_node *)obj_desc);
  207. break;
  208. case ACPI_DESC_TYPE_OPERAND:
  209. type = obj_desc->common.type;
  210. if (type > ACPI_TYPE_LOCAL_MAX) {
  211. acpi_os_printf(" Type %X [Invalid Type]", (u32)type);
  212. return;
  213. }
  214. /* Decode the ACPI object type */
  215. switch (obj_desc->common.type) {
  216. case ACPI_TYPE_LOCAL_REFERENCE:
  217. acpi_os_printf("[%s] ",
  218. acpi_ut_get_reference_name(obj_desc));
  219. /* Decode the refererence */
  220. switch (obj_desc->reference.class) {
  221. case ACPI_REFCLASS_LOCAL:
  222. acpi_os_printf("%X ",
  223. obj_desc->reference.value);
  224. if (walk_state) {
  225. obj_desc = walk_state->local_variables
  226. [obj_desc->reference.value].object;
  227. acpi_os_printf("%p", obj_desc);
  228. acpi_db_decode_internal_object
  229. (obj_desc);
  230. }
  231. break;
  232. case ACPI_REFCLASS_ARG:
  233. acpi_os_printf("%X ",
  234. obj_desc->reference.value);
  235. if (walk_state) {
  236. obj_desc = walk_state->arguments
  237. [obj_desc->reference.value].object;
  238. acpi_os_printf("%p", obj_desc);
  239. acpi_db_decode_internal_object
  240. (obj_desc);
  241. }
  242. break;
  243. case ACPI_REFCLASS_INDEX:
  244. switch (obj_desc->reference.target_type) {
  245. case ACPI_TYPE_BUFFER_FIELD:
  246. acpi_os_printf("%p",
  247. obj_desc->reference.
  248. object);
  249. acpi_db_decode_internal_object
  250. (obj_desc->reference.object);
  251. break;
  252. case ACPI_TYPE_PACKAGE:
  253. acpi_os_printf("%p",
  254. obj_desc->reference.
  255. where);
  256. if (!obj_desc->reference.where) {
  257. acpi_os_printf
  258. (" Uninitialized WHERE pointer");
  259. } else {
  260. acpi_db_decode_internal_object(*
  261. (obj_desc->
  262. reference.
  263. where));
  264. }
  265. break;
  266. default:
  267. acpi_os_printf
  268. ("Unknown index target type");
  269. break;
  270. }
  271. break;
  272. case ACPI_REFCLASS_REFOF:
  273. if (!obj_desc->reference.object) {
  274. acpi_os_printf
  275. ("Uninitialized reference subobject pointer");
  276. break;
  277. }
  278. /* Reference can be to a Node or an Operand object */
  279. switch (ACPI_GET_DESCRIPTOR_TYPE
  280. (obj_desc->reference.object)) {
  281. case ACPI_DESC_TYPE_NAMED:
  282. acpi_db_decode_node(obj_desc->reference.
  283. object);
  284. break;
  285. case ACPI_DESC_TYPE_OPERAND:
  286. acpi_db_decode_internal_object
  287. (obj_desc->reference.object);
  288. break;
  289. default:
  290. break;
  291. }
  292. break;
  293. case ACPI_REFCLASS_NAME:
  294. acpi_db_decode_node(obj_desc->reference.node);
  295. break;
  296. case ACPI_REFCLASS_DEBUG:
  297. case ACPI_REFCLASS_TABLE:
  298. acpi_os_printf("\n");
  299. break;
  300. default: /* Unknown reference class */
  301. acpi_os_printf("%2.2X\n",
  302. obj_desc->reference.class);
  303. break;
  304. }
  305. break;
  306. default:
  307. acpi_os_printf("<Obj> ");
  308. acpi_db_decode_internal_object(obj_desc);
  309. break;
  310. }
  311. break;
  312. default:
  313. acpi_os_printf("<Not a valid ACPI Object Descriptor> [%s]",
  314. acpi_ut_get_descriptor_name(obj_desc));
  315. break;
  316. }
  317. acpi_os_printf("\n");
  318. }
  319. /*******************************************************************************
  320. *
  321. * FUNCTION: acpi_db_decode_locals
  322. *
  323. * PARAMETERS: walk_state - State for current method
  324. *
  325. * RETURN: None
  326. *
  327. * DESCRIPTION: Display all locals for the currently running control method
  328. *
  329. ******************************************************************************/
  330. void acpi_db_decode_locals(struct acpi_walk_state *walk_state)
  331. {
  332. u32 i;
  333. union acpi_operand_object *obj_desc;
  334. struct acpi_namespace_node *node;
  335. u8 display_locals = FALSE;
  336. obj_desc = walk_state->method_desc;
  337. node = walk_state->method_node;
  338. if (!node) {
  339. acpi_os_printf
  340. ("No method node (Executing subtree for buffer or opregion)\n");
  341. return;
  342. }
  343. if (node->type != ACPI_TYPE_METHOD) {
  344. acpi_os_printf("Executing subtree for Buffer/Package/Region\n");
  345. return;
  346. }
  347. /* Are any locals actually set? */
  348. for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++) {
  349. obj_desc = walk_state->local_variables[i].object;
  350. if (obj_desc) {
  351. display_locals = TRUE;
  352. break;
  353. }
  354. }
  355. /* If any are set, only display the ones that are set */
  356. if (display_locals) {
  357. acpi_os_printf
  358. ("\nInitialized Local Variables for method [%4.4s]:\n",
  359. acpi_ut_get_node_name(node));
  360. for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++) {
  361. obj_desc = walk_state->local_variables[i].object;
  362. if (obj_desc) {
  363. acpi_os_printf(" Local%X: ", i);
  364. acpi_db_display_internal_object(obj_desc,
  365. walk_state);
  366. }
  367. }
  368. } else {
  369. acpi_os_printf
  370. ("No Local Variables are initialized for method [%4.4s]\n",
  371. acpi_ut_get_node_name(node));
  372. }
  373. }
  374. /*******************************************************************************
  375. *
  376. * FUNCTION: acpi_db_decode_arguments
  377. *
  378. * PARAMETERS: walk_state - State for current method
  379. *
  380. * RETURN: None
  381. *
  382. * DESCRIPTION: Display all arguments for the currently running control method
  383. *
  384. ******************************************************************************/
  385. void acpi_db_decode_arguments(struct acpi_walk_state *walk_state)
  386. {
  387. u32 i;
  388. union acpi_operand_object *obj_desc;
  389. struct acpi_namespace_node *node;
  390. u8 display_args = FALSE;
  391. node = walk_state->method_node;
  392. obj_desc = walk_state->method_desc;
  393. if (!node) {
  394. acpi_os_printf
  395. ("No method node (Executing subtree for buffer or opregion)\n");
  396. return;
  397. }
  398. if (node->type != ACPI_TYPE_METHOD) {
  399. acpi_os_printf("Executing subtree for Buffer/Package/Region\n");
  400. return;
  401. }
  402. /* Are any arguments actually set? */
  403. for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++) {
  404. obj_desc = walk_state->arguments[i].object;
  405. if (obj_desc) {
  406. display_args = TRUE;
  407. break;
  408. }
  409. }
  410. /* If any are set, only display the ones that are set */
  411. if (display_args) {
  412. acpi_os_printf("Initialized Arguments for Method [%4.4s]: "
  413. "(%X arguments defined for method invocation)\n",
  414. acpi_ut_get_node_name(node),
  415. obj_desc->method.param_count);
  416. for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++) {
  417. obj_desc = walk_state->arguments[i].object;
  418. if (obj_desc) {
  419. acpi_os_printf(" Arg%u: ", i);
  420. acpi_db_display_internal_object(obj_desc,
  421. walk_state);
  422. }
  423. }
  424. } else {
  425. acpi_os_printf
  426. ("No Arguments are initialized for method [%4.4s]\n",
  427. acpi_ut_get_node_name(node));
  428. }
  429. }