dbmethod.c 11 KB

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