dbmethod.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501
  1. /*******************************************************************************
  2. *
  3. * Module Name: dbmethod - Debug commands for control methods
  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. #include <acpi/acpi.h>
  43. #include "accommon.h"
  44. #include "acdispat.h"
  45. #include "acnamesp.h"
  46. #include "acdebug.h"
  47. #include "acparser.h"
  48. #include "acpredef.h"
  49. #define _COMPONENT ACPI_CA_DEBUGGER
  50. ACPI_MODULE_NAME("dbmethod")
  51. /* Local prototypes */
  52. static acpi_status
  53. acpi_db_walk_for_execute(acpi_handle obj_handle,
  54. u32 nesting_level, void *context, void **return_value);
  55. /*******************************************************************************
  56. *
  57. * FUNCTION: acpi_db_set_method_breakpoint
  58. *
  59. * PARAMETERS: location - AML offset of breakpoint
  60. * walk_state - Current walk info
  61. * op - Current Op (from parse walk)
  62. *
  63. * RETURN: None
  64. *
  65. * DESCRIPTION: Set a breakpoint in a control method at the specified
  66. * AML offset
  67. *
  68. ******************************************************************************/
  69. void
  70. acpi_db_set_method_breakpoint(char *location,
  71. struct acpi_walk_state *walk_state,
  72. union acpi_parse_object *op)
  73. {
  74. u32 address;
  75. u32 aml_offset;
  76. if (!op) {
  77. acpi_os_printf("There is no method currently executing\n");
  78. return;
  79. }
  80. /* Get and verify the breakpoint address */
  81. address = strtoul(location, NULL, 16);
  82. aml_offset = (u32)ACPI_PTR_DIFF(op->common.aml,
  83. walk_state->parser_state.aml_start);
  84. if (address <= aml_offset) {
  85. acpi_os_printf("Breakpoint %X is beyond current address %X\n",
  86. address, aml_offset);
  87. }
  88. /* Save breakpoint in current walk */
  89. walk_state->user_breakpoint = address;
  90. acpi_os_printf("Breakpoint set at AML offset %X\n", address);
  91. }
  92. /*******************************************************************************
  93. *
  94. * FUNCTION: acpi_db_set_method_call_breakpoint
  95. *
  96. * PARAMETERS: op - Current Op (from parse walk)
  97. *
  98. * RETURN: None
  99. *
  100. * DESCRIPTION: Set a breakpoint in a control method at the specified
  101. * AML offset
  102. *
  103. ******************************************************************************/
  104. void acpi_db_set_method_call_breakpoint(union acpi_parse_object *op)
  105. {
  106. if (!op) {
  107. acpi_os_printf("There is no method currently executing\n");
  108. return;
  109. }
  110. acpi_gbl_step_to_next_call = TRUE;
  111. }
  112. /*******************************************************************************
  113. *
  114. * FUNCTION: acpi_db_set_method_data
  115. *
  116. * PARAMETERS: type_arg - L for local, A for argument
  117. * index_arg - which one
  118. * value_arg - Value to set.
  119. *
  120. * RETURN: None
  121. *
  122. * DESCRIPTION: Set a local or argument for the running control method.
  123. * NOTE: only object supported is Number.
  124. *
  125. ******************************************************************************/
  126. void acpi_db_set_method_data(char *type_arg, char *index_arg, char *value_arg)
  127. {
  128. char type;
  129. u32 index;
  130. u32 value;
  131. struct acpi_walk_state *walk_state;
  132. union acpi_operand_object *obj_desc;
  133. acpi_status status;
  134. struct acpi_namespace_node *node;
  135. /* Validate type_arg */
  136. acpi_ut_strupr(type_arg);
  137. type = type_arg[0];
  138. if ((type != 'L') && (type != 'A') && (type != 'N')) {
  139. acpi_os_printf("Invalid SET operand: %s\n", type_arg);
  140. return;
  141. }
  142. value = strtoul(value_arg, NULL, 16);
  143. if (type == 'N') {
  144. node = acpi_db_convert_to_node(index_arg);
  145. if (!node) {
  146. return;
  147. }
  148. if (node->type != ACPI_TYPE_INTEGER) {
  149. acpi_os_printf("Can only set Integer nodes\n");
  150. return;
  151. }
  152. obj_desc = node->object;
  153. obj_desc->integer.value = value;
  154. return;
  155. }
  156. /* Get the index and value */
  157. index = strtoul(index_arg, NULL, 16);
  158. walk_state = acpi_ds_get_current_walk_state(acpi_gbl_current_walk_list);
  159. if (!walk_state) {
  160. acpi_os_printf("There is no method currently executing\n");
  161. return;
  162. }
  163. /* Create and initialize the new object */
  164. obj_desc = acpi_ut_create_integer_object((u64)value);
  165. if (!obj_desc) {
  166. acpi_os_printf("Could not create an internal object\n");
  167. return;
  168. }
  169. /* Store the new object into the target */
  170. switch (type) {
  171. case 'A':
  172. /* Set a method argument */
  173. if (index > ACPI_METHOD_MAX_ARG) {
  174. acpi_os_printf("Arg%u - Invalid argument name\n",
  175. index);
  176. goto cleanup;
  177. }
  178. status = acpi_ds_store_object_to_local(ACPI_REFCLASS_ARG,
  179. index, obj_desc,
  180. walk_state);
  181. if (ACPI_FAILURE(status)) {
  182. goto cleanup;
  183. }
  184. obj_desc = walk_state->arguments[index].object;
  185. acpi_os_printf("Arg%u: ", index);
  186. acpi_db_display_internal_object(obj_desc, walk_state);
  187. break;
  188. case 'L':
  189. /* Set a method local */
  190. if (index > ACPI_METHOD_MAX_LOCAL) {
  191. acpi_os_printf
  192. ("Local%u - Invalid local variable name\n", index);
  193. goto cleanup;
  194. }
  195. status = acpi_ds_store_object_to_local(ACPI_REFCLASS_LOCAL,
  196. index, obj_desc,
  197. walk_state);
  198. if (ACPI_FAILURE(status)) {
  199. goto cleanup;
  200. }
  201. obj_desc = walk_state->local_variables[index].object;
  202. acpi_os_printf("Local%u: ", index);
  203. acpi_db_display_internal_object(obj_desc, walk_state);
  204. break;
  205. default:
  206. break;
  207. }
  208. cleanup:
  209. acpi_ut_remove_reference(obj_desc);
  210. }
  211. /*******************************************************************************
  212. *
  213. * FUNCTION: acpi_db_disassemble_aml
  214. *
  215. * PARAMETERS: statements - Number of statements to disassemble
  216. * op - Current Op (from parse walk)
  217. *
  218. * RETURN: None
  219. *
  220. * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
  221. * of statements specified.
  222. *
  223. ******************************************************************************/
  224. void acpi_db_disassemble_aml(char *statements, union acpi_parse_object *op)
  225. {
  226. u32 num_statements = 8;
  227. if (!op) {
  228. acpi_os_printf("There is no method currently executing\n");
  229. return;
  230. }
  231. if (statements) {
  232. num_statements = strtoul(statements, NULL, 0);
  233. }
  234. #ifdef ACPI_DISASSEMBLER
  235. acpi_dm_disassemble(NULL, op, num_statements);
  236. #endif
  237. }
  238. /*******************************************************************************
  239. *
  240. * FUNCTION: acpi_db_disassemble_method
  241. *
  242. * PARAMETERS: name - Name of control method
  243. *
  244. * RETURN: None
  245. *
  246. * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
  247. * of statements specified.
  248. *
  249. ******************************************************************************/
  250. acpi_status acpi_db_disassemble_method(char *name)
  251. {
  252. acpi_status status;
  253. union acpi_parse_object *op;
  254. struct acpi_walk_state *walk_state;
  255. union acpi_operand_object *obj_desc;
  256. struct acpi_namespace_node *method;
  257. method = acpi_db_convert_to_node(name);
  258. if (!method) {
  259. return (AE_BAD_PARAMETER);
  260. }
  261. if (method->type != ACPI_TYPE_METHOD) {
  262. ACPI_ERROR((AE_INFO, "%s (%s): Object must be a control method",
  263. name, acpi_ut_get_type_name(method->type)));
  264. return (AE_BAD_PARAMETER);
  265. }
  266. obj_desc = method->object;
  267. op = acpi_ps_create_scope_op(obj_desc->method.aml_start);
  268. if (!op) {
  269. return (AE_NO_MEMORY);
  270. }
  271. /* Create and initialize a new walk state */
  272. walk_state = acpi_ds_create_walk_state(0, op, NULL, NULL);
  273. if (!walk_state) {
  274. return (AE_NO_MEMORY);
  275. }
  276. status = acpi_ds_init_aml_walk(walk_state, op, NULL,
  277. obj_desc->method.aml_start,
  278. obj_desc->method.aml_length, NULL,
  279. ACPI_IMODE_LOAD_PASS1);
  280. if (ACPI_FAILURE(status)) {
  281. return (status);
  282. }
  283. status = acpi_ut_allocate_owner_id(&obj_desc->method.owner_id);
  284. walk_state->owner_id = obj_desc->method.owner_id;
  285. /* Push start scope on scope stack and make it current */
  286. status = acpi_ds_scope_stack_push(method, method->type, walk_state);
  287. if (ACPI_FAILURE(status)) {
  288. return (status);
  289. }
  290. /* Parse the entire method AML including deferred operators */
  291. walk_state->parse_flags &= ~ACPI_PARSE_DELETE_TREE;
  292. walk_state->parse_flags |= ACPI_PARSE_DISASSEMBLE;
  293. status = acpi_ps_parse_aml(walk_state);
  294. #ifdef ACPI_DISASSEMBLER
  295. (void)acpi_dm_parse_deferred_ops(op);
  296. /* Now we can disassemble the method */
  297. acpi_gbl_dm_opt_verbose = FALSE;
  298. acpi_dm_disassemble(NULL, op, 0);
  299. acpi_gbl_dm_opt_verbose = TRUE;
  300. #endif
  301. acpi_ps_delete_parse_tree(op);
  302. /* Method cleanup */
  303. acpi_ns_delete_namespace_subtree(method);
  304. acpi_ns_delete_namespace_by_owner(obj_desc->method.owner_id);
  305. acpi_ut_release_owner_id(&obj_desc->method.owner_id);
  306. return (AE_OK);
  307. }
  308. /*******************************************************************************
  309. *
  310. * FUNCTION: acpi_db_walk_for_execute
  311. *
  312. * PARAMETERS: Callback from walk_namespace
  313. *
  314. * RETURN: Status
  315. *
  316. * DESCRIPTION: Batch execution module. Currently only executes predefined
  317. * ACPI names.
  318. *
  319. ******************************************************************************/
  320. static acpi_status
  321. acpi_db_walk_for_execute(acpi_handle obj_handle,
  322. u32 nesting_level, void *context, void **return_value)
  323. {
  324. struct acpi_namespace_node *node =
  325. (struct acpi_namespace_node *)obj_handle;
  326. struct acpi_db_execute_walk *info =
  327. (struct acpi_db_execute_walk *)context;
  328. struct acpi_buffer return_obj;
  329. acpi_status status;
  330. char *pathname;
  331. u32 i;
  332. struct acpi_device_info *obj_info;
  333. struct acpi_object_list param_objects;
  334. union acpi_object params[ACPI_METHOD_NUM_ARGS];
  335. const union acpi_predefined_info *predefined;
  336. predefined = acpi_ut_match_predefined_method(node->name.ascii);
  337. if (!predefined) {
  338. return (AE_OK);
  339. }
  340. if (node->type == ACPI_TYPE_LOCAL_SCOPE) {
  341. return (AE_OK);
  342. }
  343. pathname = acpi_ns_get_external_pathname(node);
  344. if (!pathname) {
  345. return (AE_OK);
  346. }
  347. /* Get the object info for number of method parameters */
  348. status = acpi_get_object_info(obj_handle, &obj_info);
  349. if (ACPI_FAILURE(status)) {
  350. return (status);
  351. }
  352. param_objects.pointer = NULL;
  353. param_objects.count = 0;
  354. if (obj_info->type == ACPI_TYPE_METHOD) {
  355. /* Setup default parameters */
  356. for (i = 0; i < obj_info->param_count; i++) {
  357. params[i].type = ACPI_TYPE_INTEGER;
  358. params[i].integer.value = 1;
  359. }
  360. param_objects.pointer = params;
  361. param_objects.count = obj_info->param_count;
  362. }
  363. ACPI_FREE(obj_info);
  364. return_obj.pointer = NULL;
  365. return_obj.length = ACPI_ALLOCATE_BUFFER;
  366. /* Do the actual method execution */
  367. acpi_gbl_method_executing = TRUE;
  368. status = acpi_evaluate_object(node, NULL, &param_objects, &return_obj);
  369. acpi_os_printf("%-32s returned %s\n", pathname,
  370. acpi_format_exception(status));
  371. acpi_gbl_method_executing = FALSE;
  372. ACPI_FREE(pathname);
  373. /* Ignore status from method execution */
  374. status = AE_OK;
  375. /* Update count, check if we have executed enough methods */
  376. info->count++;
  377. if (info->count >= info->max_count) {
  378. status = AE_CTRL_TERMINATE;
  379. }
  380. return (status);
  381. }
  382. /*******************************************************************************
  383. *
  384. * FUNCTION: acpi_db_evaluate_predefined_names
  385. *
  386. * PARAMETERS: None
  387. *
  388. * RETURN: None
  389. *
  390. * DESCRIPTION: Namespace batch execution. Execute predefined names in the
  391. * namespace, up to the max count, if specified.
  392. *
  393. ******************************************************************************/
  394. void acpi_db_evaluate_predefined_names(void)
  395. {
  396. struct acpi_db_execute_walk info;
  397. info.count = 0;
  398. info.max_count = ACPI_UINT32_MAX;
  399. /* Search all nodes in namespace */
  400. (void)acpi_walk_namespace(ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
  401. ACPI_UINT32_MAX, acpi_db_walk_for_execute,
  402. NULL, (void *)&info, NULL);
  403. acpi_os_printf("Evaluated %u predefined names in the namespace\n",
  404. info.count);
  405. }