1 /*******************************************************************************
3 * Module Name: dbmethod - Debug commands for control methods
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2018, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include <acpi/acpi.h>
52 #define _COMPONENT ACPI_CA_DEBUGGER
53 ACPI_MODULE_NAME("dbmethod")
55 /* Local prototypes */
57 acpi_db_walk_for_execute(acpi_handle obj_handle
,
58 u32 nesting_level
, void *context
, void **return_value
);
60 /*******************************************************************************
62 * FUNCTION: acpi_db_set_method_breakpoint
64 * PARAMETERS: location - AML offset of breakpoint
65 * walk_state - Current walk info
66 * op - Current Op (from parse walk)
70 * DESCRIPTION: Set a breakpoint in a control method at the specified
73 ******************************************************************************/
76 acpi_db_set_method_breakpoint(char *location
,
77 struct acpi_walk_state
*walk_state
,
78 union acpi_parse_object
*op
)
84 acpi_os_printf("There is no method currently executing\n");
88 /* Get and verify the breakpoint address */
90 address
= strtoul(location
, NULL
, 16);
91 aml_offset
= (u32
)ACPI_PTR_DIFF(op
->common
.aml
,
92 walk_state
->parser_state
.aml_start
);
93 if (address
<= aml_offset
) {
94 acpi_os_printf("Breakpoint %X is beyond current address %X\n",
98 /* Save breakpoint in current walk */
100 walk_state
->user_breakpoint
= address
;
101 acpi_os_printf("Breakpoint set at AML offset %X\n", address
);
104 /*******************************************************************************
106 * FUNCTION: acpi_db_set_method_call_breakpoint
108 * PARAMETERS: op - Current Op (from parse walk)
112 * DESCRIPTION: Set a breakpoint in a control method at the specified
115 ******************************************************************************/
117 void acpi_db_set_method_call_breakpoint(union acpi_parse_object
*op
)
121 acpi_os_printf("There is no method currently executing\n");
125 acpi_gbl_step_to_next_call
= TRUE
;
128 /*******************************************************************************
130 * FUNCTION: acpi_db_set_method_data
132 * PARAMETERS: type_arg - L for local, A for argument
133 * index_arg - which one
134 * value_arg - Value to set.
138 * DESCRIPTION: Set a local or argument for the running control method.
139 * NOTE: only object supported is Number.
141 ******************************************************************************/
143 void acpi_db_set_method_data(char *type_arg
, char *index_arg
, char *value_arg
)
148 struct acpi_walk_state
*walk_state
;
149 union acpi_operand_object
*obj_desc
;
151 struct acpi_namespace_node
*node
;
153 /* Validate type_arg */
155 acpi_ut_strupr(type_arg
);
157 if ((type
!= 'L') && (type
!= 'A') && (type
!= 'N')) {
158 acpi_os_printf("Invalid SET operand: %s\n", type_arg
);
162 value
= strtoul(value_arg
, NULL
, 16);
165 node
= acpi_db_convert_to_node(index_arg
);
170 if (node
->type
!= ACPI_TYPE_INTEGER
) {
171 acpi_os_printf("Can only set Integer nodes\n");
174 obj_desc
= node
->object
;
175 obj_desc
->integer
.value
= value
;
179 /* Get the index and value */
181 index
= strtoul(index_arg
, NULL
, 16);
183 walk_state
= acpi_ds_get_current_walk_state(acpi_gbl_current_walk_list
);
185 acpi_os_printf("There is no method currently executing\n");
189 /* Create and initialize the new object */
191 obj_desc
= acpi_ut_create_integer_object((u64
)value
);
193 acpi_os_printf("Could not create an internal object\n");
197 /* Store the new object into the target */
202 /* Set a method argument */
204 if (index
> ACPI_METHOD_MAX_ARG
) {
205 acpi_os_printf("Arg%u - Invalid argument name\n",
210 status
= acpi_ds_store_object_to_local(ACPI_REFCLASS_ARG
,
213 if (ACPI_FAILURE(status
)) {
217 obj_desc
= walk_state
->arguments
[index
].object
;
219 acpi_os_printf("Arg%u: ", index
);
220 acpi_db_display_internal_object(obj_desc
, walk_state
);
225 /* Set a method local */
227 if (index
> ACPI_METHOD_MAX_LOCAL
) {
229 ("Local%u - Invalid local variable name\n", index
);
233 status
= acpi_ds_store_object_to_local(ACPI_REFCLASS_LOCAL
,
236 if (ACPI_FAILURE(status
)) {
240 obj_desc
= walk_state
->local_variables
[index
].object
;
242 acpi_os_printf("Local%u: ", index
);
243 acpi_db_display_internal_object(obj_desc
, walk_state
);
252 acpi_ut_remove_reference(obj_desc
);
255 /*******************************************************************************
257 * FUNCTION: acpi_db_disassemble_aml
259 * PARAMETERS: statements - Number of statements to disassemble
260 * op - Current Op (from parse walk)
264 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
265 * of statements specified.
267 ******************************************************************************/
269 void acpi_db_disassemble_aml(char *statements
, union acpi_parse_object
*op
)
271 u32 num_statements
= 8;
274 acpi_os_printf("There is no method currently executing\n");
279 num_statements
= strtoul(statements
, NULL
, 0);
281 #ifdef ACPI_DISASSEMBLER
282 acpi_dm_disassemble(NULL
, op
, num_statements
);
286 /*******************************************************************************
288 * FUNCTION: acpi_db_disassemble_method
290 * PARAMETERS: name - Name of control method
294 * DESCRIPTION: Display disassembled AML (ASL) starting from Op for the number
295 * of statements specified.
297 ******************************************************************************/
299 acpi_status
acpi_db_disassemble_method(char *name
)
302 union acpi_parse_object
*op
;
303 struct acpi_walk_state
*walk_state
;
304 union acpi_operand_object
*obj_desc
;
305 struct acpi_namespace_node
*method
;
307 method
= acpi_db_convert_to_node(name
);
309 return (AE_BAD_PARAMETER
);
312 if (method
->type
!= ACPI_TYPE_METHOD
) {
313 ACPI_ERROR((AE_INFO
, "%s (%s): Object must be a control method",
314 name
, acpi_ut_get_type_name(method
->type
)));
315 return (AE_BAD_PARAMETER
);
318 obj_desc
= method
->object
;
320 op
= acpi_ps_create_scope_op(obj_desc
->method
.aml_start
);
322 return (AE_NO_MEMORY
);
325 /* Create and initialize a new walk state */
327 walk_state
= acpi_ds_create_walk_state(0, op
, NULL
, NULL
);
329 return (AE_NO_MEMORY
);
332 status
= acpi_ds_init_aml_walk(walk_state
, op
, NULL
,
333 obj_desc
->method
.aml_start
,
334 obj_desc
->method
.aml_length
, NULL
,
335 ACPI_IMODE_LOAD_PASS1
);
336 if (ACPI_FAILURE(status
)) {
340 status
= acpi_ut_allocate_owner_id(&obj_desc
->method
.owner_id
);
341 walk_state
->owner_id
= obj_desc
->method
.owner_id
;
343 /* Push start scope on scope stack and make it current */
345 status
= acpi_ds_scope_stack_push(method
, method
->type
, walk_state
);
346 if (ACPI_FAILURE(status
)) {
350 /* Parse the entire method AML including deferred operators */
352 walk_state
->parse_flags
&= ~ACPI_PARSE_DELETE_TREE
;
353 walk_state
->parse_flags
|= ACPI_PARSE_DISASSEMBLE
;
355 status
= acpi_ps_parse_aml(walk_state
);
357 #ifdef ACPI_DISASSEMBLER
358 (void)acpi_dm_parse_deferred_ops(op
);
360 /* Now we can disassemble the method */
362 acpi_gbl_dm_opt_verbose
= FALSE
;
363 acpi_dm_disassemble(NULL
, op
, 0);
364 acpi_gbl_dm_opt_verbose
= TRUE
;
367 acpi_ps_delete_parse_tree(op
);
371 acpi_ns_delete_namespace_subtree(method
);
372 acpi_ns_delete_namespace_by_owner(obj_desc
->method
.owner_id
);
373 acpi_ut_release_owner_id(&obj_desc
->method
.owner_id
);
377 /*******************************************************************************
379 * FUNCTION: acpi_db_walk_for_execute
381 * PARAMETERS: Callback from walk_namespace
385 * DESCRIPTION: Batch execution module. Currently only executes predefined
388 ******************************************************************************/
391 acpi_db_walk_for_execute(acpi_handle obj_handle
,
392 u32 nesting_level
, void *context
, void **return_value
)
394 struct acpi_namespace_node
*node
=
395 (struct acpi_namespace_node
*)obj_handle
;
396 struct acpi_db_execute_walk
*info
=
397 (struct acpi_db_execute_walk
*)context
;
398 struct acpi_buffer return_obj
;
402 struct acpi_device_info
*obj_info
;
403 struct acpi_object_list param_objects
;
404 union acpi_object params
[ACPI_METHOD_NUM_ARGS
];
405 const union acpi_predefined_info
*predefined
;
407 predefined
= acpi_ut_match_predefined_method(node
->name
.ascii
);
412 if (node
->type
== ACPI_TYPE_LOCAL_SCOPE
) {
416 pathname
= acpi_ns_get_external_pathname(node
);
421 /* Get the object info for number of method parameters */
423 status
= acpi_get_object_info(obj_handle
, &obj_info
);
424 if (ACPI_FAILURE(status
)) {
429 param_objects
.pointer
= NULL
;
430 param_objects
.count
= 0;
432 if (obj_info
->type
== ACPI_TYPE_METHOD
) {
434 /* Setup default parameters */
436 for (i
= 0; i
< obj_info
->param_count
; i
++) {
437 params
[i
].type
= ACPI_TYPE_INTEGER
;
438 params
[i
].integer
.value
= 1;
441 param_objects
.pointer
= params
;
442 param_objects
.count
= obj_info
->param_count
;
446 return_obj
.pointer
= NULL
;
447 return_obj
.length
= ACPI_ALLOCATE_BUFFER
;
449 /* Do the actual method execution */
451 acpi_gbl_method_executing
= TRUE
;
453 status
= acpi_evaluate_object(node
, NULL
, ¶m_objects
, &return_obj
);
455 acpi_os_printf("%-32s returned %s\n", pathname
,
456 acpi_format_exception(status
));
457 acpi_gbl_method_executing
= FALSE
;
460 /* Ignore status from method execution */
464 /* Update count, check if we have executed enough methods */
467 if (info
->count
>= info
->max_count
) {
468 status
= AE_CTRL_TERMINATE
;
474 /*******************************************************************************
476 * FUNCTION: acpi_db_evaluate_predefined_names
482 * DESCRIPTION: Namespace batch execution. Execute predefined names in the
483 * namespace, up to the max count, if specified.
485 ******************************************************************************/
487 void acpi_db_evaluate_predefined_names(void)
489 struct acpi_db_execute_walk info
;
492 info
.max_count
= ACPI_UINT32_MAX
;
494 /* Search all nodes in namespace */
496 (void)acpi_walk_namespace(ACPI_TYPE_ANY
, ACPI_ROOT_OBJECT
,
497 ACPI_UINT32_MAX
, acpi_db_walk_for_execute
,
498 NULL
, (void *)&info
, NULL
);
500 acpi_os_printf("Evaluated %u predefined names in the namespace\n",