1*4882a593Smuzhiyun // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2*4882a593Smuzhiyun /*******************************************************************************
3*4882a593Smuzhiyun *
4*4882a593Smuzhiyun * Module Name: dsutils - Dispatcher utilities
5*4882a593Smuzhiyun *
6*4882a593Smuzhiyun ******************************************************************************/
7*4882a593Smuzhiyun
8*4882a593Smuzhiyun #include <acpi/acpi.h>
9*4882a593Smuzhiyun #include "accommon.h"
10*4882a593Smuzhiyun #include "acparser.h"
11*4882a593Smuzhiyun #include "amlcode.h"
12*4882a593Smuzhiyun #include "acdispat.h"
13*4882a593Smuzhiyun #include "acinterp.h"
14*4882a593Smuzhiyun #include "acnamesp.h"
15*4882a593Smuzhiyun #include "acdebug.h"
16*4882a593Smuzhiyun
17*4882a593Smuzhiyun #define _COMPONENT ACPI_DISPATCHER
18*4882a593Smuzhiyun ACPI_MODULE_NAME("dsutils")
19*4882a593Smuzhiyun
20*4882a593Smuzhiyun /*******************************************************************************
21*4882a593Smuzhiyun *
22*4882a593Smuzhiyun * FUNCTION: acpi_ds_clear_implicit_return
23*4882a593Smuzhiyun *
24*4882a593Smuzhiyun * PARAMETERS: walk_state - Current State
25*4882a593Smuzhiyun *
26*4882a593Smuzhiyun * RETURN: None.
27*4882a593Smuzhiyun *
28*4882a593Smuzhiyun * DESCRIPTION: Clear and remove a reference on an implicit return value. Used
29*4882a593Smuzhiyun * to delete "stale" return values (if enabled, the return value
30*4882a593Smuzhiyun * from every operator is saved at least momentarily, in case the
31*4882a593Smuzhiyun * parent method exits.)
32*4882a593Smuzhiyun *
33*4882a593Smuzhiyun ******************************************************************************/
acpi_ds_clear_implicit_return(struct acpi_walk_state * walk_state)34*4882a593Smuzhiyun void acpi_ds_clear_implicit_return(struct acpi_walk_state *walk_state)
35*4882a593Smuzhiyun {
36*4882a593Smuzhiyun ACPI_FUNCTION_NAME(ds_clear_implicit_return);
37*4882a593Smuzhiyun
38*4882a593Smuzhiyun /*
39*4882a593Smuzhiyun * Slack must be enabled for this feature
40*4882a593Smuzhiyun */
41*4882a593Smuzhiyun if (!acpi_gbl_enable_interpreter_slack) {
42*4882a593Smuzhiyun return;
43*4882a593Smuzhiyun }
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun if (walk_state->implicit_return_obj) {
46*4882a593Smuzhiyun /*
47*4882a593Smuzhiyun * Delete any "stale" implicit return. However, in
48*4882a593Smuzhiyun * complex statements, the implicit return value can be
49*4882a593Smuzhiyun * bubbled up several levels.
50*4882a593Smuzhiyun */
51*4882a593Smuzhiyun ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
52*4882a593Smuzhiyun "Removing reference on stale implicit return obj %p\n",
53*4882a593Smuzhiyun walk_state->implicit_return_obj));
54*4882a593Smuzhiyun
55*4882a593Smuzhiyun acpi_ut_remove_reference(walk_state->implicit_return_obj);
56*4882a593Smuzhiyun walk_state->implicit_return_obj = NULL;
57*4882a593Smuzhiyun }
58*4882a593Smuzhiyun }
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun /*******************************************************************************
61*4882a593Smuzhiyun *
62*4882a593Smuzhiyun * FUNCTION: acpi_ds_do_implicit_return
63*4882a593Smuzhiyun *
64*4882a593Smuzhiyun * PARAMETERS: return_desc - The return value
65*4882a593Smuzhiyun * walk_state - Current State
66*4882a593Smuzhiyun * add_reference - True if a reference should be added to the
67*4882a593Smuzhiyun * return object
68*4882a593Smuzhiyun *
69*4882a593Smuzhiyun * RETURN: TRUE if implicit return enabled, FALSE otherwise
70*4882a593Smuzhiyun *
71*4882a593Smuzhiyun * DESCRIPTION: Implements the optional "implicit return". We save the result
72*4882a593Smuzhiyun * of every ASL operator and control method invocation in case the
73*4882a593Smuzhiyun * parent method exit. Before storing a new return value, we
74*4882a593Smuzhiyun * delete the previous return value.
75*4882a593Smuzhiyun *
76*4882a593Smuzhiyun ******************************************************************************/
77*4882a593Smuzhiyun
78*4882a593Smuzhiyun u8
acpi_ds_do_implicit_return(union acpi_operand_object * return_desc,struct acpi_walk_state * walk_state,u8 add_reference)79*4882a593Smuzhiyun acpi_ds_do_implicit_return(union acpi_operand_object *return_desc,
80*4882a593Smuzhiyun struct acpi_walk_state *walk_state, u8 add_reference)
81*4882a593Smuzhiyun {
82*4882a593Smuzhiyun ACPI_FUNCTION_NAME(ds_do_implicit_return);
83*4882a593Smuzhiyun
84*4882a593Smuzhiyun /*
85*4882a593Smuzhiyun * Slack must be enabled for this feature, and we must
86*4882a593Smuzhiyun * have a valid return object
87*4882a593Smuzhiyun */
88*4882a593Smuzhiyun if ((!acpi_gbl_enable_interpreter_slack) || (!return_desc)) {
89*4882a593Smuzhiyun return (FALSE);
90*4882a593Smuzhiyun }
91*4882a593Smuzhiyun
92*4882a593Smuzhiyun ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
93*4882a593Smuzhiyun "Result %p will be implicitly returned; Prev=%p\n",
94*4882a593Smuzhiyun return_desc, walk_state->implicit_return_obj));
95*4882a593Smuzhiyun
96*4882a593Smuzhiyun /*
97*4882a593Smuzhiyun * Delete any "stale" implicit return value first. However, in
98*4882a593Smuzhiyun * complex statements, the implicit return value can be
99*4882a593Smuzhiyun * bubbled up several levels, so we don't clear the value if it
100*4882a593Smuzhiyun * is the same as the return_desc.
101*4882a593Smuzhiyun */
102*4882a593Smuzhiyun if (walk_state->implicit_return_obj) {
103*4882a593Smuzhiyun if (walk_state->implicit_return_obj == return_desc) {
104*4882a593Smuzhiyun return (TRUE);
105*4882a593Smuzhiyun }
106*4882a593Smuzhiyun acpi_ds_clear_implicit_return(walk_state);
107*4882a593Smuzhiyun }
108*4882a593Smuzhiyun
109*4882a593Smuzhiyun /* Save the implicit return value, add a reference if requested */
110*4882a593Smuzhiyun
111*4882a593Smuzhiyun walk_state->implicit_return_obj = return_desc;
112*4882a593Smuzhiyun if (add_reference) {
113*4882a593Smuzhiyun acpi_ut_add_reference(return_desc);
114*4882a593Smuzhiyun }
115*4882a593Smuzhiyun
116*4882a593Smuzhiyun return (TRUE);
117*4882a593Smuzhiyun }
118*4882a593Smuzhiyun
119*4882a593Smuzhiyun /*******************************************************************************
120*4882a593Smuzhiyun *
121*4882a593Smuzhiyun * FUNCTION: acpi_ds_is_result_used
122*4882a593Smuzhiyun *
123*4882a593Smuzhiyun * PARAMETERS: op - Current Op
124*4882a593Smuzhiyun * walk_state - Current State
125*4882a593Smuzhiyun *
126*4882a593Smuzhiyun * RETURN: TRUE if result is used, FALSE otherwise
127*4882a593Smuzhiyun *
128*4882a593Smuzhiyun * DESCRIPTION: Check if a result object will be used by the parent
129*4882a593Smuzhiyun *
130*4882a593Smuzhiyun ******************************************************************************/
131*4882a593Smuzhiyun
132*4882a593Smuzhiyun u8
acpi_ds_is_result_used(union acpi_parse_object * op,struct acpi_walk_state * walk_state)133*4882a593Smuzhiyun acpi_ds_is_result_used(union acpi_parse_object * op,
134*4882a593Smuzhiyun struct acpi_walk_state * walk_state)
135*4882a593Smuzhiyun {
136*4882a593Smuzhiyun const struct acpi_opcode_info *parent_info;
137*4882a593Smuzhiyun
138*4882a593Smuzhiyun ACPI_FUNCTION_TRACE_PTR(ds_is_result_used, op);
139*4882a593Smuzhiyun
140*4882a593Smuzhiyun /* Must have both an Op and a Result Object */
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun if (!op) {
143*4882a593Smuzhiyun ACPI_ERROR((AE_INFO, "Null Op"));
144*4882a593Smuzhiyun return_UINT8(TRUE);
145*4882a593Smuzhiyun }
146*4882a593Smuzhiyun
147*4882a593Smuzhiyun /*
148*4882a593Smuzhiyun * We know that this operator is not a
149*4882a593Smuzhiyun * Return() operator (would not come here.) The following code is the
150*4882a593Smuzhiyun * optional support for a so-called "implicit return". Some AML code
151*4882a593Smuzhiyun * assumes that the last value of the method is "implicitly" returned
152*4882a593Smuzhiyun * to the caller. Just save the last result as the return value.
153*4882a593Smuzhiyun * NOTE: this is optional because the ASL language does not actually
154*4882a593Smuzhiyun * support this behavior.
155*4882a593Smuzhiyun */
156*4882a593Smuzhiyun (void)acpi_ds_do_implicit_return(walk_state->result_obj, walk_state,
157*4882a593Smuzhiyun TRUE);
158*4882a593Smuzhiyun
159*4882a593Smuzhiyun /*
160*4882a593Smuzhiyun * Now determine if the parent will use the result
161*4882a593Smuzhiyun *
162*4882a593Smuzhiyun * If there is no parent, or the parent is a scope_op, we are executing
163*4882a593Smuzhiyun * at the method level. An executing method typically has no parent,
164*4882a593Smuzhiyun * since each method is parsed separately. A method invoked externally
165*4882a593Smuzhiyun * via execute_control_method has a scope_op as the parent.
166*4882a593Smuzhiyun */
167*4882a593Smuzhiyun if ((!op->common.parent) ||
168*4882a593Smuzhiyun (op->common.parent->common.aml_opcode == AML_SCOPE_OP)) {
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun /* No parent, the return value cannot possibly be used */
171*4882a593Smuzhiyun
172*4882a593Smuzhiyun ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
173*4882a593Smuzhiyun "At Method level, result of [%s] not used\n",
174*4882a593Smuzhiyun acpi_ps_get_opcode_name(op->common.
175*4882a593Smuzhiyun aml_opcode)));
176*4882a593Smuzhiyun return_UINT8(FALSE);
177*4882a593Smuzhiyun }
178*4882a593Smuzhiyun
179*4882a593Smuzhiyun /* Get info on the parent. The root_op is AML_SCOPE */
180*4882a593Smuzhiyun
181*4882a593Smuzhiyun parent_info =
182*4882a593Smuzhiyun acpi_ps_get_opcode_info(op->common.parent->common.aml_opcode);
183*4882a593Smuzhiyun if (parent_info->class == AML_CLASS_UNKNOWN) {
184*4882a593Smuzhiyun ACPI_ERROR((AE_INFO, "Unknown parent opcode Op=%p", op));
185*4882a593Smuzhiyun return_UINT8(FALSE);
186*4882a593Smuzhiyun }
187*4882a593Smuzhiyun
188*4882a593Smuzhiyun /*
189*4882a593Smuzhiyun * Decide what to do with the result based on the parent. If
190*4882a593Smuzhiyun * the parent opcode will not use the result, delete the object.
191*4882a593Smuzhiyun * Otherwise leave it as is, it will be deleted when it is used
192*4882a593Smuzhiyun * as an operand later.
193*4882a593Smuzhiyun */
194*4882a593Smuzhiyun switch (parent_info->class) {
195*4882a593Smuzhiyun case AML_CLASS_CONTROL:
196*4882a593Smuzhiyun
197*4882a593Smuzhiyun switch (op->common.parent->common.aml_opcode) {
198*4882a593Smuzhiyun case AML_RETURN_OP:
199*4882a593Smuzhiyun
200*4882a593Smuzhiyun /* Never delete the return value associated with a return opcode */
201*4882a593Smuzhiyun
202*4882a593Smuzhiyun goto result_used;
203*4882a593Smuzhiyun
204*4882a593Smuzhiyun case AML_IF_OP:
205*4882a593Smuzhiyun case AML_WHILE_OP:
206*4882a593Smuzhiyun /*
207*4882a593Smuzhiyun * If we are executing the predicate AND this is the predicate op,
208*4882a593Smuzhiyun * we will use the return value
209*4882a593Smuzhiyun */
210*4882a593Smuzhiyun if ((walk_state->control_state->common.state ==
211*4882a593Smuzhiyun ACPI_CONTROL_PREDICATE_EXECUTING) &&
212*4882a593Smuzhiyun (walk_state->control_state->control.predicate_op ==
213*4882a593Smuzhiyun op)) {
214*4882a593Smuzhiyun goto result_used;
215*4882a593Smuzhiyun }
216*4882a593Smuzhiyun break;
217*4882a593Smuzhiyun
218*4882a593Smuzhiyun default:
219*4882a593Smuzhiyun
220*4882a593Smuzhiyun /* Ignore other control opcodes */
221*4882a593Smuzhiyun
222*4882a593Smuzhiyun break;
223*4882a593Smuzhiyun }
224*4882a593Smuzhiyun
225*4882a593Smuzhiyun /* The general control opcode returns no result */
226*4882a593Smuzhiyun
227*4882a593Smuzhiyun goto result_not_used;
228*4882a593Smuzhiyun
229*4882a593Smuzhiyun case AML_CLASS_CREATE:
230*4882a593Smuzhiyun /*
231*4882a593Smuzhiyun * These opcodes allow term_arg(s) as operands and therefore
232*4882a593Smuzhiyun * the operands can be method calls. The result is used.
233*4882a593Smuzhiyun */
234*4882a593Smuzhiyun goto result_used;
235*4882a593Smuzhiyun
236*4882a593Smuzhiyun case AML_CLASS_NAMED_OBJECT:
237*4882a593Smuzhiyun
238*4882a593Smuzhiyun if ((op->common.parent->common.aml_opcode == AML_REGION_OP) ||
239*4882a593Smuzhiyun (op->common.parent->common.aml_opcode == AML_DATA_REGION_OP)
240*4882a593Smuzhiyun || (op->common.parent->common.aml_opcode == AML_PACKAGE_OP)
241*4882a593Smuzhiyun || (op->common.parent->common.aml_opcode == AML_BUFFER_OP)
242*4882a593Smuzhiyun || (op->common.parent->common.aml_opcode ==
243*4882a593Smuzhiyun AML_VARIABLE_PACKAGE_OP)
244*4882a593Smuzhiyun || (op->common.parent->common.aml_opcode ==
245*4882a593Smuzhiyun AML_INT_EVAL_SUBTREE_OP)
246*4882a593Smuzhiyun || (op->common.parent->common.aml_opcode ==
247*4882a593Smuzhiyun AML_BANK_FIELD_OP)) {
248*4882a593Smuzhiyun /*
249*4882a593Smuzhiyun * These opcodes allow term_arg(s) as operands and therefore
250*4882a593Smuzhiyun * the operands can be method calls. The result is used.
251*4882a593Smuzhiyun */
252*4882a593Smuzhiyun goto result_used;
253*4882a593Smuzhiyun }
254*4882a593Smuzhiyun
255*4882a593Smuzhiyun goto result_not_used;
256*4882a593Smuzhiyun
257*4882a593Smuzhiyun default:
258*4882a593Smuzhiyun /*
259*4882a593Smuzhiyun * In all other cases. the parent will actually use the return
260*4882a593Smuzhiyun * object, so keep it.
261*4882a593Smuzhiyun */
262*4882a593Smuzhiyun goto result_used;
263*4882a593Smuzhiyun }
264*4882a593Smuzhiyun
265*4882a593Smuzhiyun result_used:
266*4882a593Smuzhiyun ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
267*4882a593Smuzhiyun "Result of [%s] used by Parent [%s] Op=%p\n",
268*4882a593Smuzhiyun acpi_ps_get_opcode_name(op->common.aml_opcode),
269*4882a593Smuzhiyun acpi_ps_get_opcode_name(op->common.parent->common.
270*4882a593Smuzhiyun aml_opcode), op));
271*4882a593Smuzhiyun
272*4882a593Smuzhiyun return_UINT8(TRUE);
273*4882a593Smuzhiyun
274*4882a593Smuzhiyun result_not_used:
275*4882a593Smuzhiyun ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
276*4882a593Smuzhiyun "Result of [%s] not used by Parent [%s] Op=%p\n",
277*4882a593Smuzhiyun acpi_ps_get_opcode_name(op->common.aml_opcode),
278*4882a593Smuzhiyun acpi_ps_get_opcode_name(op->common.parent->common.
279*4882a593Smuzhiyun aml_opcode), op));
280*4882a593Smuzhiyun
281*4882a593Smuzhiyun return_UINT8(FALSE);
282*4882a593Smuzhiyun }
283*4882a593Smuzhiyun
284*4882a593Smuzhiyun /*******************************************************************************
285*4882a593Smuzhiyun *
286*4882a593Smuzhiyun * FUNCTION: acpi_ds_delete_result_if_not_used
287*4882a593Smuzhiyun *
288*4882a593Smuzhiyun * PARAMETERS: op - Current parse Op
289*4882a593Smuzhiyun * result_obj - Result of the operation
290*4882a593Smuzhiyun * walk_state - Current state
291*4882a593Smuzhiyun *
292*4882a593Smuzhiyun * RETURN: Status
293*4882a593Smuzhiyun *
294*4882a593Smuzhiyun * DESCRIPTION: Used after interpretation of an opcode. If there is an internal
295*4882a593Smuzhiyun * result descriptor, check if the parent opcode will actually use
296*4882a593Smuzhiyun * this result. If not, delete the result now so that it will
297*4882a593Smuzhiyun * not become orphaned.
298*4882a593Smuzhiyun *
299*4882a593Smuzhiyun ******************************************************************************/
300*4882a593Smuzhiyun
301*4882a593Smuzhiyun void
acpi_ds_delete_result_if_not_used(union acpi_parse_object * op,union acpi_operand_object * result_obj,struct acpi_walk_state * walk_state)302*4882a593Smuzhiyun acpi_ds_delete_result_if_not_used(union acpi_parse_object *op,
303*4882a593Smuzhiyun union acpi_operand_object *result_obj,
304*4882a593Smuzhiyun struct acpi_walk_state *walk_state)
305*4882a593Smuzhiyun {
306*4882a593Smuzhiyun union acpi_operand_object *obj_desc;
307*4882a593Smuzhiyun acpi_status status;
308*4882a593Smuzhiyun
309*4882a593Smuzhiyun ACPI_FUNCTION_TRACE_PTR(ds_delete_result_if_not_used, result_obj);
310*4882a593Smuzhiyun
311*4882a593Smuzhiyun if (!op) {
312*4882a593Smuzhiyun ACPI_ERROR((AE_INFO, "Null Op"));
313*4882a593Smuzhiyun return_VOID;
314*4882a593Smuzhiyun }
315*4882a593Smuzhiyun
316*4882a593Smuzhiyun if (!result_obj) {
317*4882a593Smuzhiyun return_VOID;
318*4882a593Smuzhiyun }
319*4882a593Smuzhiyun
320*4882a593Smuzhiyun if (!acpi_ds_is_result_used(op, walk_state)) {
321*4882a593Smuzhiyun
322*4882a593Smuzhiyun /* Must pop the result stack (obj_desc should be equal to result_obj) */
323*4882a593Smuzhiyun
324*4882a593Smuzhiyun status = acpi_ds_result_pop(&obj_desc, walk_state);
325*4882a593Smuzhiyun if (ACPI_SUCCESS(status)) {
326*4882a593Smuzhiyun acpi_ut_remove_reference(result_obj);
327*4882a593Smuzhiyun }
328*4882a593Smuzhiyun }
329*4882a593Smuzhiyun
330*4882a593Smuzhiyun return_VOID;
331*4882a593Smuzhiyun }
332*4882a593Smuzhiyun
333*4882a593Smuzhiyun /*******************************************************************************
334*4882a593Smuzhiyun *
335*4882a593Smuzhiyun * FUNCTION: acpi_ds_resolve_operands
336*4882a593Smuzhiyun *
337*4882a593Smuzhiyun * PARAMETERS: walk_state - Current walk state with operands on stack
338*4882a593Smuzhiyun *
339*4882a593Smuzhiyun * RETURN: Status
340*4882a593Smuzhiyun *
341*4882a593Smuzhiyun * DESCRIPTION: Resolve all operands to their values. Used to prepare
342*4882a593Smuzhiyun * arguments to a control method invocation (a call from one
343*4882a593Smuzhiyun * method to another.)
344*4882a593Smuzhiyun *
345*4882a593Smuzhiyun ******************************************************************************/
346*4882a593Smuzhiyun
acpi_ds_resolve_operands(struct acpi_walk_state * walk_state)347*4882a593Smuzhiyun acpi_status acpi_ds_resolve_operands(struct acpi_walk_state *walk_state)
348*4882a593Smuzhiyun {
349*4882a593Smuzhiyun u32 i;
350*4882a593Smuzhiyun acpi_status status = AE_OK;
351*4882a593Smuzhiyun
352*4882a593Smuzhiyun ACPI_FUNCTION_TRACE_PTR(ds_resolve_operands, walk_state);
353*4882a593Smuzhiyun
354*4882a593Smuzhiyun /*
355*4882a593Smuzhiyun * Attempt to resolve each of the valid operands
356*4882a593Smuzhiyun * Method arguments are passed by reference, not by value. This means
357*4882a593Smuzhiyun * that the actual objects are passed, not copies of the objects.
358*4882a593Smuzhiyun */
359*4882a593Smuzhiyun for (i = 0; i < walk_state->num_operands; i++) {
360*4882a593Smuzhiyun status =
361*4882a593Smuzhiyun acpi_ex_resolve_to_value(&walk_state->operands[i],
362*4882a593Smuzhiyun walk_state);
363*4882a593Smuzhiyun if (ACPI_FAILURE(status)) {
364*4882a593Smuzhiyun break;
365*4882a593Smuzhiyun }
366*4882a593Smuzhiyun }
367*4882a593Smuzhiyun
368*4882a593Smuzhiyun return_ACPI_STATUS(status);
369*4882a593Smuzhiyun }
370*4882a593Smuzhiyun
371*4882a593Smuzhiyun /*******************************************************************************
372*4882a593Smuzhiyun *
373*4882a593Smuzhiyun * FUNCTION: acpi_ds_clear_operands
374*4882a593Smuzhiyun *
375*4882a593Smuzhiyun * PARAMETERS: walk_state - Current walk state with operands on stack
376*4882a593Smuzhiyun *
377*4882a593Smuzhiyun * RETURN: None
378*4882a593Smuzhiyun *
379*4882a593Smuzhiyun * DESCRIPTION: Clear all operands on the current walk state operand stack.
380*4882a593Smuzhiyun *
381*4882a593Smuzhiyun ******************************************************************************/
382*4882a593Smuzhiyun
acpi_ds_clear_operands(struct acpi_walk_state * walk_state)383*4882a593Smuzhiyun void acpi_ds_clear_operands(struct acpi_walk_state *walk_state)
384*4882a593Smuzhiyun {
385*4882a593Smuzhiyun u32 i;
386*4882a593Smuzhiyun
387*4882a593Smuzhiyun ACPI_FUNCTION_TRACE_PTR(ds_clear_operands, walk_state);
388*4882a593Smuzhiyun
389*4882a593Smuzhiyun /* Remove a reference on each operand on the stack */
390*4882a593Smuzhiyun
391*4882a593Smuzhiyun for (i = 0; i < walk_state->num_operands; i++) {
392*4882a593Smuzhiyun /*
393*4882a593Smuzhiyun * Remove a reference to all operands, including both
394*4882a593Smuzhiyun * "Arguments" and "Targets".
395*4882a593Smuzhiyun */
396*4882a593Smuzhiyun acpi_ut_remove_reference(walk_state->operands[i]);
397*4882a593Smuzhiyun walk_state->operands[i] = NULL;
398*4882a593Smuzhiyun }
399*4882a593Smuzhiyun
400*4882a593Smuzhiyun walk_state->num_operands = 0;
401*4882a593Smuzhiyun return_VOID;
402*4882a593Smuzhiyun }
403*4882a593Smuzhiyun
404*4882a593Smuzhiyun /*******************************************************************************
405*4882a593Smuzhiyun *
406*4882a593Smuzhiyun * FUNCTION: acpi_ds_create_operand
407*4882a593Smuzhiyun *
408*4882a593Smuzhiyun * PARAMETERS: walk_state - Current walk state
409*4882a593Smuzhiyun * arg - Parse object for the argument
410*4882a593Smuzhiyun * arg_index - Which argument (zero based)
411*4882a593Smuzhiyun *
412*4882a593Smuzhiyun * RETURN: Status
413*4882a593Smuzhiyun *
414*4882a593Smuzhiyun * DESCRIPTION: Translate a parse tree object that is an argument to an AML
415*4882a593Smuzhiyun * opcode to the equivalent interpreter object. This may include
416*4882a593Smuzhiyun * looking up a name or entering a new name into the internal
417*4882a593Smuzhiyun * namespace.
418*4882a593Smuzhiyun *
419*4882a593Smuzhiyun ******************************************************************************/
420*4882a593Smuzhiyun
421*4882a593Smuzhiyun acpi_status
acpi_ds_create_operand(struct acpi_walk_state * walk_state,union acpi_parse_object * arg,u32 arg_index)422*4882a593Smuzhiyun acpi_ds_create_operand(struct acpi_walk_state *walk_state,
423*4882a593Smuzhiyun union acpi_parse_object *arg, u32 arg_index)
424*4882a593Smuzhiyun {
425*4882a593Smuzhiyun acpi_status status = AE_OK;
426*4882a593Smuzhiyun char *name_string;
427*4882a593Smuzhiyun u32 name_length;
428*4882a593Smuzhiyun union acpi_operand_object *obj_desc;
429*4882a593Smuzhiyun union acpi_parse_object *parent_op;
430*4882a593Smuzhiyun u16 opcode;
431*4882a593Smuzhiyun acpi_interpreter_mode interpreter_mode;
432*4882a593Smuzhiyun const struct acpi_opcode_info *op_info;
433*4882a593Smuzhiyun
434*4882a593Smuzhiyun ACPI_FUNCTION_TRACE_PTR(ds_create_operand, arg);
435*4882a593Smuzhiyun
436*4882a593Smuzhiyun /* A valid name must be looked up in the namespace */
437*4882a593Smuzhiyun
438*4882a593Smuzhiyun if ((arg->common.aml_opcode == AML_INT_NAMEPATH_OP) &&
439*4882a593Smuzhiyun (arg->common.value.string) &&
440*4882a593Smuzhiyun !(arg->common.flags & ACPI_PARSEOP_IN_STACK)) {
441*4882a593Smuzhiyun ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH, "Getting a name: Arg=%p\n",
442*4882a593Smuzhiyun arg));
443*4882a593Smuzhiyun
444*4882a593Smuzhiyun /* Get the entire name string from the AML stream */
445*4882a593Smuzhiyun
446*4882a593Smuzhiyun status = acpi_ex_get_name_string(ACPI_TYPE_ANY,
447*4882a593Smuzhiyun arg->common.value.buffer,
448*4882a593Smuzhiyun &name_string, &name_length);
449*4882a593Smuzhiyun
450*4882a593Smuzhiyun if (ACPI_FAILURE(status)) {
451*4882a593Smuzhiyun return_ACPI_STATUS(status);
452*4882a593Smuzhiyun }
453*4882a593Smuzhiyun
454*4882a593Smuzhiyun /* All prefixes have been handled, and the name is in name_string */
455*4882a593Smuzhiyun
456*4882a593Smuzhiyun /*
457*4882a593Smuzhiyun * Special handling for buffer_field declarations. This is a deferred
458*4882a593Smuzhiyun * opcode that unfortunately defines the field name as the last
459*4882a593Smuzhiyun * parameter instead of the first. We get here when we are performing
460*4882a593Smuzhiyun * the deferred execution, so the actual name of the field is already
461*4882a593Smuzhiyun * in the namespace. We don't want to attempt to look it up again
462*4882a593Smuzhiyun * because we may be executing in a different scope than where the
463*4882a593Smuzhiyun * actual opcode exists.
464*4882a593Smuzhiyun */
465*4882a593Smuzhiyun if ((walk_state->deferred_node) &&
466*4882a593Smuzhiyun (walk_state->deferred_node->type == ACPI_TYPE_BUFFER_FIELD)
467*4882a593Smuzhiyun && (arg_index == (u32)
468*4882a593Smuzhiyun ((walk_state->opcode == AML_CREATE_FIELD_OP) ? 3 : 2))) {
469*4882a593Smuzhiyun obj_desc =
470*4882a593Smuzhiyun ACPI_CAST_PTR(union acpi_operand_object,
471*4882a593Smuzhiyun walk_state->deferred_node);
472*4882a593Smuzhiyun status = AE_OK;
473*4882a593Smuzhiyun } else { /* All other opcodes */
474*4882a593Smuzhiyun
475*4882a593Smuzhiyun /*
476*4882a593Smuzhiyun * Differentiate between a namespace "create" operation
477*4882a593Smuzhiyun * versus a "lookup" operation (IMODE_LOAD_PASS2 vs.
478*4882a593Smuzhiyun * IMODE_EXECUTE) in order to support the creation of
479*4882a593Smuzhiyun * namespace objects during the execution of control methods.
480*4882a593Smuzhiyun */
481*4882a593Smuzhiyun parent_op = arg->common.parent;
482*4882a593Smuzhiyun op_info =
483*4882a593Smuzhiyun acpi_ps_get_opcode_info(parent_op->common.
484*4882a593Smuzhiyun aml_opcode);
485*4882a593Smuzhiyun
486*4882a593Smuzhiyun if ((op_info->flags & AML_NSNODE) &&
487*4882a593Smuzhiyun (parent_op->common.aml_opcode !=
488*4882a593Smuzhiyun AML_INT_METHODCALL_OP)
489*4882a593Smuzhiyun && (parent_op->common.aml_opcode != AML_REGION_OP)
490*4882a593Smuzhiyun && (parent_op->common.aml_opcode !=
491*4882a593Smuzhiyun AML_INT_NAMEPATH_OP)) {
492*4882a593Smuzhiyun
493*4882a593Smuzhiyun /* Enter name into namespace if not found */
494*4882a593Smuzhiyun
495*4882a593Smuzhiyun interpreter_mode = ACPI_IMODE_LOAD_PASS2;
496*4882a593Smuzhiyun } else {
497*4882a593Smuzhiyun /* Return a failure if name not found */
498*4882a593Smuzhiyun
499*4882a593Smuzhiyun interpreter_mode = ACPI_IMODE_EXECUTE;
500*4882a593Smuzhiyun }
501*4882a593Smuzhiyun
502*4882a593Smuzhiyun status =
503*4882a593Smuzhiyun acpi_ns_lookup(walk_state->scope_info, name_string,
504*4882a593Smuzhiyun ACPI_TYPE_ANY, interpreter_mode,
505*4882a593Smuzhiyun ACPI_NS_SEARCH_PARENT |
506*4882a593Smuzhiyun ACPI_NS_DONT_OPEN_SCOPE, walk_state,
507*4882a593Smuzhiyun ACPI_CAST_INDIRECT_PTR(struct
508*4882a593Smuzhiyun acpi_namespace_node,
509*4882a593Smuzhiyun &obj_desc));
510*4882a593Smuzhiyun /*
511*4882a593Smuzhiyun * The only case where we pass through (ignore) a NOT_FOUND
512*4882a593Smuzhiyun * error is for the cond_ref_of opcode.
513*4882a593Smuzhiyun */
514*4882a593Smuzhiyun if (status == AE_NOT_FOUND) {
515*4882a593Smuzhiyun if (parent_op->common.aml_opcode ==
516*4882a593Smuzhiyun AML_CONDITIONAL_REF_OF_OP) {
517*4882a593Smuzhiyun /*
518*4882a593Smuzhiyun * For the Conditional Reference op, it's OK if
519*4882a593Smuzhiyun * the name is not found; We just need a way to
520*4882a593Smuzhiyun * indicate this to the interpreter, set the
521*4882a593Smuzhiyun * object to the root
522*4882a593Smuzhiyun */
523*4882a593Smuzhiyun obj_desc =
524*4882a593Smuzhiyun ACPI_CAST_PTR(union
525*4882a593Smuzhiyun acpi_operand_object,
526*4882a593Smuzhiyun acpi_gbl_root_node);
527*4882a593Smuzhiyun status = AE_OK;
528*4882a593Smuzhiyun } else if (parent_op->common.aml_opcode ==
529*4882a593Smuzhiyun AML_EXTERNAL_OP) {
530*4882a593Smuzhiyun /*
531*4882a593Smuzhiyun * This opcode should never appear here. It is used only
532*4882a593Smuzhiyun * by AML disassemblers and is surrounded by an If(0)
533*4882a593Smuzhiyun * by the ASL compiler.
534*4882a593Smuzhiyun *
535*4882a593Smuzhiyun * Therefore, if we see it here, it is a serious error.
536*4882a593Smuzhiyun */
537*4882a593Smuzhiyun status = AE_AML_BAD_OPCODE;
538*4882a593Smuzhiyun } else {
539*4882a593Smuzhiyun /*
540*4882a593Smuzhiyun * We just plain didn't find it -- which is a
541*4882a593Smuzhiyun * very serious error at this point
542*4882a593Smuzhiyun */
543*4882a593Smuzhiyun status = AE_AML_NAME_NOT_FOUND;
544*4882a593Smuzhiyun }
545*4882a593Smuzhiyun }
546*4882a593Smuzhiyun
547*4882a593Smuzhiyun if (ACPI_FAILURE(status)) {
548*4882a593Smuzhiyun ACPI_ERROR_NAMESPACE(walk_state->scope_info,
549*4882a593Smuzhiyun name_string, status);
550*4882a593Smuzhiyun }
551*4882a593Smuzhiyun }
552*4882a593Smuzhiyun
553*4882a593Smuzhiyun /* Free the namestring created above */
554*4882a593Smuzhiyun
555*4882a593Smuzhiyun ACPI_FREE(name_string);
556*4882a593Smuzhiyun
557*4882a593Smuzhiyun /* Check status from the lookup */
558*4882a593Smuzhiyun
559*4882a593Smuzhiyun if (ACPI_FAILURE(status)) {
560*4882a593Smuzhiyun return_ACPI_STATUS(status);
561*4882a593Smuzhiyun }
562*4882a593Smuzhiyun
563*4882a593Smuzhiyun /* Put the resulting object onto the current object stack */
564*4882a593Smuzhiyun
565*4882a593Smuzhiyun status = acpi_ds_obj_stack_push(obj_desc, walk_state);
566*4882a593Smuzhiyun if (ACPI_FAILURE(status)) {
567*4882a593Smuzhiyun return_ACPI_STATUS(status);
568*4882a593Smuzhiyun }
569*4882a593Smuzhiyun
570*4882a593Smuzhiyun acpi_db_display_argument_object(obj_desc, walk_state);
571*4882a593Smuzhiyun } else {
572*4882a593Smuzhiyun /* Check for null name case */
573*4882a593Smuzhiyun
574*4882a593Smuzhiyun if ((arg->common.aml_opcode == AML_INT_NAMEPATH_OP) &&
575*4882a593Smuzhiyun !(arg->common.flags & ACPI_PARSEOP_IN_STACK)) {
576*4882a593Smuzhiyun /*
577*4882a593Smuzhiyun * If the name is null, this means that this is an
578*4882a593Smuzhiyun * optional result parameter that was not specified
579*4882a593Smuzhiyun * in the original ASL. Create a Zero Constant for a
580*4882a593Smuzhiyun * placeholder. (Store to a constant is a Noop.)
581*4882a593Smuzhiyun */
582*4882a593Smuzhiyun opcode = AML_ZERO_OP; /* Has no arguments! */
583*4882a593Smuzhiyun
584*4882a593Smuzhiyun ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
585*4882a593Smuzhiyun "Null namepath: Arg=%p\n", arg));
586*4882a593Smuzhiyun } else {
587*4882a593Smuzhiyun opcode = arg->common.aml_opcode;
588*4882a593Smuzhiyun }
589*4882a593Smuzhiyun
590*4882a593Smuzhiyun /* Get the object type of the argument */
591*4882a593Smuzhiyun
592*4882a593Smuzhiyun op_info = acpi_ps_get_opcode_info(opcode);
593*4882a593Smuzhiyun if (op_info->object_type == ACPI_TYPE_INVALID) {
594*4882a593Smuzhiyun return_ACPI_STATUS(AE_NOT_IMPLEMENTED);
595*4882a593Smuzhiyun }
596*4882a593Smuzhiyun
597*4882a593Smuzhiyun if ((op_info->flags & AML_HAS_RETVAL) ||
598*4882a593Smuzhiyun (arg->common.flags & ACPI_PARSEOP_IN_STACK)) {
599*4882a593Smuzhiyun /*
600*4882a593Smuzhiyun * Use value that was already previously returned
601*4882a593Smuzhiyun * by the evaluation of this argument
602*4882a593Smuzhiyun */
603*4882a593Smuzhiyun status = acpi_ds_result_pop(&obj_desc, walk_state);
604*4882a593Smuzhiyun if (ACPI_FAILURE(status)) {
605*4882a593Smuzhiyun /*
606*4882a593Smuzhiyun * Only error is underflow, and this indicates
607*4882a593Smuzhiyun * a missing or null operand!
608*4882a593Smuzhiyun */
609*4882a593Smuzhiyun ACPI_EXCEPTION((AE_INFO, status,
610*4882a593Smuzhiyun "Missing or null operand"));
611*4882a593Smuzhiyun return_ACPI_STATUS(status);
612*4882a593Smuzhiyun }
613*4882a593Smuzhiyun } else {
614*4882a593Smuzhiyun /* Create an ACPI_INTERNAL_OBJECT for the argument */
615*4882a593Smuzhiyun
616*4882a593Smuzhiyun obj_desc =
617*4882a593Smuzhiyun acpi_ut_create_internal_object(op_info->
618*4882a593Smuzhiyun object_type);
619*4882a593Smuzhiyun if (!obj_desc) {
620*4882a593Smuzhiyun return_ACPI_STATUS(AE_NO_MEMORY);
621*4882a593Smuzhiyun }
622*4882a593Smuzhiyun
623*4882a593Smuzhiyun /* Initialize the new object */
624*4882a593Smuzhiyun
625*4882a593Smuzhiyun status =
626*4882a593Smuzhiyun acpi_ds_init_object_from_op(walk_state, arg, opcode,
627*4882a593Smuzhiyun &obj_desc);
628*4882a593Smuzhiyun if (ACPI_FAILURE(status)) {
629*4882a593Smuzhiyun acpi_ut_delete_object_desc(obj_desc);
630*4882a593Smuzhiyun return_ACPI_STATUS(status);
631*4882a593Smuzhiyun }
632*4882a593Smuzhiyun }
633*4882a593Smuzhiyun
634*4882a593Smuzhiyun /* Put the operand object on the object stack */
635*4882a593Smuzhiyun
636*4882a593Smuzhiyun status = acpi_ds_obj_stack_push(obj_desc, walk_state);
637*4882a593Smuzhiyun if (ACPI_FAILURE(status)) {
638*4882a593Smuzhiyun return_ACPI_STATUS(status);
639*4882a593Smuzhiyun }
640*4882a593Smuzhiyun
641*4882a593Smuzhiyun acpi_db_display_argument_object(obj_desc, walk_state);
642*4882a593Smuzhiyun }
643*4882a593Smuzhiyun
644*4882a593Smuzhiyun return_ACPI_STATUS(AE_OK);
645*4882a593Smuzhiyun }
646*4882a593Smuzhiyun
647*4882a593Smuzhiyun /*******************************************************************************
648*4882a593Smuzhiyun *
649*4882a593Smuzhiyun * FUNCTION: acpi_ds_create_operands
650*4882a593Smuzhiyun *
651*4882a593Smuzhiyun * PARAMETERS: walk_state - Current state
652*4882a593Smuzhiyun * first_arg - First argument of a parser argument tree
653*4882a593Smuzhiyun *
654*4882a593Smuzhiyun * RETURN: Status
655*4882a593Smuzhiyun *
656*4882a593Smuzhiyun * DESCRIPTION: Convert an operator's arguments from a parse tree format to
657*4882a593Smuzhiyun * namespace objects and place those argument object on the object
658*4882a593Smuzhiyun * stack in preparation for evaluation by the interpreter.
659*4882a593Smuzhiyun *
660*4882a593Smuzhiyun ******************************************************************************/
661*4882a593Smuzhiyun
662*4882a593Smuzhiyun acpi_status
acpi_ds_create_operands(struct acpi_walk_state * walk_state,union acpi_parse_object * first_arg)663*4882a593Smuzhiyun acpi_ds_create_operands(struct acpi_walk_state *walk_state,
664*4882a593Smuzhiyun union acpi_parse_object *first_arg)
665*4882a593Smuzhiyun {
666*4882a593Smuzhiyun acpi_status status = AE_OK;
667*4882a593Smuzhiyun union acpi_parse_object *arg;
668*4882a593Smuzhiyun union acpi_parse_object *arguments[ACPI_OBJ_NUM_OPERANDS];
669*4882a593Smuzhiyun u32 arg_count = 0;
670*4882a593Smuzhiyun u32 index = walk_state->num_operands;
671*4882a593Smuzhiyun u32 i;
672*4882a593Smuzhiyun
673*4882a593Smuzhiyun ACPI_FUNCTION_TRACE_PTR(ds_create_operands, first_arg);
674*4882a593Smuzhiyun
675*4882a593Smuzhiyun /* Get all arguments in the list */
676*4882a593Smuzhiyun
677*4882a593Smuzhiyun arg = first_arg;
678*4882a593Smuzhiyun while (arg) {
679*4882a593Smuzhiyun if (index >= ACPI_OBJ_NUM_OPERANDS) {
680*4882a593Smuzhiyun return_ACPI_STATUS(AE_BAD_DATA);
681*4882a593Smuzhiyun }
682*4882a593Smuzhiyun
683*4882a593Smuzhiyun arguments[index] = arg;
684*4882a593Smuzhiyun walk_state->operands[index] = NULL;
685*4882a593Smuzhiyun
686*4882a593Smuzhiyun /* Move on to next argument, if any */
687*4882a593Smuzhiyun
688*4882a593Smuzhiyun arg = arg->common.next;
689*4882a593Smuzhiyun arg_count++;
690*4882a593Smuzhiyun index++;
691*4882a593Smuzhiyun }
692*4882a593Smuzhiyun
693*4882a593Smuzhiyun ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
694*4882a593Smuzhiyun "NumOperands %d, ArgCount %d, Index %d\n",
695*4882a593Smuzhiyun walk_state->num_operands, arg_count, index));
696*4882a593Smuzhiyun
697*4882a593Smuzhiyun /* Create the interpreter arguments, in reverse order */
698*4882a593Smuzhiyun
699*4882a593Smuzhiyun index--;
700*4882a593Smuzhiyun for (i = 0; i < arg_count; i++) {
701*4882a593Smuzhiyun arg = arguments[index];
702*4882a593Smuzhiyun walk_state->operand_index = (u8)index;
703*4882a593Smuzhiyun
704*4882a593Smuzhiyun status = acpi_ds_create_operand(walk_state, arg, index);
705*4882a593Smuzhiyun if (ACPI_FAILURE(status)) {
706*4882a593Smuzhiyun goto cleanup;
707*4882a593Smuzhiyun }
708*4882a593Smuzhiyun
709*4882a593Smuzhiyun ACPI_DEBUG_PRINT((ACPI_DB_DISPATCH,
710*4882a593Smuzhiyun "Created Arg #%u (%p) %u args total\n",
711*4882a593Smuzhiyun index, arg, arg_count));
712*4882a593Smuzhiyun index--;
713*4882a593Smuzhiyun }
714*4882a593Smuzhiyun
715*4882a593Smuzhiyun return_ACPI_STATUS(status);
716*4882a593Smuzhiyun
717*4882a593Smuzhiyun cleanup:
718*4882a593Smuzhiyun /*
719*4882a593Smuzhiyun * We must undo everything done above; meaning that we must
720*4882a593Smuzhiyun * pop everything off of the operand stack and delete those
721*4882a593Smuzhiyun * objects
722*4882a593Smuzhiyun */
723*4882a593Smuzhiyun acpi_ds_obj_stack_pop_and_delete(arg_count, walk_state);
724*4882a593Smuzhiyun
725*4882a593Smuzhiyun ACPI_EXCEPTION((AE_INFO, status, "While creating Arg %u", index));
726*4882a593Smuzhiyun return_ACPI_STATUS(status);
727*4882a593Smuzhiyun }
728*4882a593Smuzhiyun
729*4882a593Smuzhiyun /*****************************************************************************
730*4882a593Smuzhiyun *
731*4882a593Smuzhiyun * FUNCTION: acpi_ds_evaluate_name_path
732*4882a593Smuzhiyun *
733*4882a593Smuzhiyun * PARAMETERS: walk_state - Current state of the parse tree walk,
734*4882a593Smuzhiyun * the opcode of current operation should be
735*4882a593Smuzhiyun * AML_INT_NAMEPATH_OP
736*4882a593Smuzhiyun *
737*4882a593Smuzhiyun * RETURN: Status
738*4882a593Smuzhiyun *
739*4882a593Smuzhiyun * DESCRIPTION: Translate the -name_path- parse tree object to the equivalent
740*4882a593Smuzhiyun * interpreter object, convert it to value, if needed, duplicate
741*4882a593Smuzhiyun * it, if needed, and push it onto the current result stack.
742*4882a593Smuzhiyun *
743*4882a593Smuzhiyun ****************************************************************************/
744*4882a593Smuzhiyun
acpi_ds_evaluate_name_path(struct acpi_walk_state * walk_state)745*4882a593Smuzhiyun acpi_status acpi_ds_evaluate_name_path(struct acpi_walk_state *walk_state)
746*4882a593Smuzhiyun {
747*4882a593Smuzhiyun acpi_status status = AE_OK;
748*4882a593Smuzhiyun union acpi_parse_object *op = walk_state->op;
749*4882a593Smuzhiyun union acpi_operand_object **operand = &walk_state->operands[0];
750*4882a593Smuzhiyun union acpi_operand_object *new_obj_desc;
751*4882a593Smuzhiyun u8 type;
752*4882a593Smuzhiyun
753*4882a593Smuzhiyun ACPI_FUNCTION_TRACE_PTR(ds_evaluate_name_path, walk_state);
754*4882a593Smuzhiyun
755*4882a593Smuzhiyun if (!op->common.parent) {
756*4882a593Smuzhiyun
757*4882a593Smuzhiyun /* This happens after certain exception processing */
758*4882a593Smuzhiyun
759*4882a593Smuzhiyun goto exit;
760*4882a593Smuzhiyun }
761*4882a593Smuzhiyun
762*4882a593Smuzhiyun if ((op->common.parent->common.aml_opcode == AML_PACKAGE_OP) ||
763*4882a593Smuzhiyun (op->common.parent->common.aml_opcode == AML_VARIABLE_PACKAGE_OP) ||
764*4882a593Smuzhiyun (op->common.parent->common.aml_opcode == AML_REF_OF_OP)) {
765*4882a593Smuzhiyun
766*4882a593Smuzhiyun /* TBD: Should we specify this feature as a bit of op_info->Flags of these opcodes? */
767*4882a593Smuzhiyun
768*4882a593Smuzhiyun goto exit;
769*4882a593Smuzhiyun }
770*4882a593Smuzhiyun
771*4882a593Smuzhiyun status = acpi_ds_create_operand(walk_state, op, 0);
772*4882a593Smuzhiyun if (ACPI_FAILURE(status)) {
773*4882a593Smuzhiyun goto exit;
774*4882a593Smuzhiyun }
775*4882a593Smuzhiyun
776*4882a593Smuzhiyun if (op->common.flags & ACPI_PARSEOP_TARGET) {
777*4882a593Smuzhiyun new_obj_desc = *operand;
778*4882a593Smuzhiyun goto push_result;
779*4882a593Smuzhiyun }
780*4882a593Smuzhiyun
781*4882a593Smuzhiyun type = (*operand)->common.type;
782*4882a593Smuzhiyun
783*4882a593Smuzhiyun status = acpi_ex_resolve_to_value(operand, walk_state);
784*4882a593Smuzhiyun if (ACPI_FAILURE(status)) {
785*4882a593Smuzhiyun goto exit;
786*4882a593Smuzhiyun }
787*4882a593Smuzhiyun
788*4882a593Smuzhiyun if (type == ACPI_TYPE_INTEGER) {
789*4882a593Smuzhiyun
790*4882a593Smuzhiyun /* It was incremented by acpi_ex_resolve_to_value */
791*4882a593Smuzhiyun
792*4882a593Smuzhiyun acpi_ut_remove_reference(*operand);
793*4882a593Smuzhiyun
794*4882a593Smuzhiyun status =
795*4882a593Smuzhiyun acpi_ut_copy_iobject_to_iobject(*operand, &new_obj_desc,
796*4882a593Smuzhiyun walk_state);
797*4882a593Smuzhiyun if (ACPI_FAILURE(status)) {
798*4882a593Smuzhiyun goto exit;
799*4882a593Smuzhiyun }
800*4882a593Smuzhiyun } else {
801*4882a593Smuzhiyun /*
802*4882a593Smuzhiyun * The object either was anew created or is
803*4882a593Smuzhiyun * a Namespace node - don't decrement it.
804*4882a593Smuzhiyun */
805*4882a593Smuzhiyun new_obj_desc = *operand;
806*4882a593Smuzhiyun }
807*4882a593Smuzhiyun
808*4882a593Smuzhiyun /* Cleanup for name-path operand */
809*4882a593Smuzhiyun
810*4882a593Smuzhiyun status = acpi_ds_obj_stack_pop(1, walk_state);
811*4882a593Smuzhiyun if (ACPI_FAILURE(status)) {
812*4882a593Smuzhiyun walk_state->result_obj = new_obj_desc;
813*4882a593Smuzhiyun goto exit;
814*4882a593Smuzhiyun }
815*4882a593Smuzhiyun
816*4882a593Smuzhiyun push_result:
817*4882a593Smuzhiyun
818*4882a593Smuzhiyun walk_state->result_obj = new_obj_desc;
819*4882a593Smuzhiyun
820*4882a593Smuzhiyun status = acpi_ds_result_push(walk_state->result_obj, walk_state);
821*4882a593Smuzhiyun if (ACPI_SUCCESS(status)) {
822*4882a593Smuzhiyun
823*4882a593Smuzhiyun /* Force to take it from stack */
824*4882a593Smuzhiyun
825*4882a593Smuzhiyun op->common.flags |= ACPI_PARSEOP_IN_STACK;
826*4882a593Smuzhiyun }
827*4882a593Smuzhiyun
828*4882a593Smuzhiyun exit:
829*4882a593Smuzhiyun
830*4882a593Smuzhiyun return_ACPI_STATUS(status);
831*4882a593Smuzhiyun }
832