]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - drivers/acpi/acpica/dsopcode.c
ACPICA: adding SPDX headers
[mirror_ubuntu-hirsute-kernel.git] / drivers / acpi / acpica / dsopcode.c
CommitLineData
95857638 1// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
1da177e4
LT
2/******************************************************************************
3 *
02582e9b 4 * Module Name: dsopcode - Dispatcher support for regions and fields
1da177e4 5 *
da6f8320 6 * Copyright (C) 2000 - 2018, Intel Corp.
1da177e4 7 *
95857638 8 *****************************************************************************/
1da177e4 9
1da177e4 10#include <acpi/acpi.h>
e2f7a777
LB
11#include "accommon.h"
12#include "acparser.h"
13#include "amlcode.h"
14#include "acdispat.h"
15#include "acinterp.h"
16#include "acnamesp.h"
17#include "acevents.h"
18#include "actables.h"
1da177e4
LT
19
20#define _COMPONENT ACPI_DISPATCHER
4be44fcd 21ACPI_MODULE_NAME("dsopcode")
1da177e4 22
44f6c012 23/* Local prototypes */
44f6c012 24static acpi_status
4be44fcd
LB
25acpi_ds_init_buffer_field(u16 aml_opcode,
26 union acpi_operand_object *obj_desc,
27 union acpi_operand_object *buffer_desc,
28 union acpi_operand_object *offset_desc,
29 union acpi_operand_object *length_desc,
30 union acpi_operand_object *result_desc);
44f6c012 31
44f6c012 32/*******************************************************************************
1da177e4
LT
33 *
34 * FUNCTION: acpi_ds_initialize_region
35 *
44f6c012 36 * PARAMETERS: obj_handle - Region namespace node
1da177e4
LT
37 *
38 * RETURN: Status
39 *
40 * DESCRIPTION: Front end to ev_initialize_region
41 *
44f6c012 42 ******************************************************************************/
1da177e4 43
4be44fcd 44acpi_status acpi_ds_initialize_region(acpi_handle obj_handle)
1da177e4 45{
4be44fcd
LB
46 union acpi_operand_object *obj_desc;
47 acpi_status status;
1da177e4 48
4be44fcd 49 obj_desc = acpi_ns_get_attached_object(obj_handle);
1da177e4
LT
50
51 /* Namespace is NOT locked */
52
760235cd 53 status = acpi_ev_initialize_region(obj_desc);
1da177e4
LT
54 return (status);
55}
56
44f6c012 57/*******************************************************************************
1da177e4
LT
58 *
59 * FUNCTION: acpi_ds_init_buffer_field
60 *
61 * PARAMETERS: aml_opcode - create_xxx_field
62 * obj_desc - buffer_field object
63 * buffer_desc - Host Buffer
64 * offset_desc - Offset into buffer
44f6c012
RM
65 * length_desc - Length of field (CREATE_FIELD_OP only)
66 * result_desc - Where to store the result
1da177e4
LT
67 *
68 * RETURN: Status
69 *
70 * DESCRIPTION: Perform actual initialization of a buffer field
71 *
44f6c012 72 ******************************************************************************/
1da177e4 73
44f6c012 74static acpi_status
4be44fcd
LB
75acpi_ds_init_buffer_field(u16 aml_opcode,
76 union acpi_operand_object *obj_desc,
77 union acpi_operand_object *buffer_desc,
78 union acpi_operand_object *offset_desc,
79 union acpi_operand_object *length_desc,
80 union acpi_operand_object *result_desc)
1da177e4 81{
4be44fcd
LB
82 u32 offset;
83 u32 bit_offset;
84 u32 bit_count;
85 u8 field_flags;
86 acpi_status status;
1da177e4 87
b229cf92 88 ACPI_FUNCTION_TRACE_PTR(ds_init_buffer_field, obj_desc);
1da177e4
LT
89
90 /* Host object must be a Buffer */
91
3371c19c 92 if (buffer_desc->common.type != ACPI_TYPE_BUFFER) {
b8e4d893
BM
93 ACPI_ERROR((AE_INFO,
94 "Target of Create Field is not a Buffer object - %s",
95 acpi_ut_get_object_type_name(buffer_desc)));
1da177e4
LT
96
97 status = AE_AML_OPERAND_TYPE;
98 goto cleanup;
99 }
100
101 /*
102 * The last parameter to all of these opcodes (result_desc) started
103 * out as a name_string, and should therefore now be a NS node
104 * after resolution in acpi_ex_resolve_operands().
105 */
4be44fcd 106 if (ACPI_GET_DESCRIPTOR_TYPE(result_desc) != ACPI_DESC_TYPE_NAMED) {
b8e4d893
BM
107 ACPI_ERROR((AE_INFO,
108 "(%s) destination not a NS Node [%s]",
109 acpi_ps_get_opcode_name(aml_opcode),
110 acpi_ut_get_descriptor_name(result_desc)));
1da177e4
LT
111
112 status = AE_AML_OPERAND_TYPE;
113 goto cleanup;
114 }
115
116 offset = (u32) offset_desc->integer.value;
117
118 /*
119 * Setup the Bit offsets and counts, according to the opcode
120 */
121 switch (aml_opcode) {
122 case AML_CREATE_FIELD_OP:
123
124 /* Offset is in bits, count is in bits */
125
44f6c012 126 field_flags = AML_FIELD_ACCESS_BYTE;
1da177e4 127 bit_offset = offset;
4be44fcd 128 bit_count = (u32) length_desc->integer.value;
44f6c012
RM
129
130 /* Must have a valid (>0) bit count */
131
132 if (bit_count == 0) {
b8e4d893 133 ACPI_ERROR((AE_INFO,
b229cf92 134 "Attempt to CreateField of length zero"));
44f6c012
RM
135 status = AE_AML_OPERAND_VALUE;
136 goto cleanup;
137 }
1da177e4
LT
138 break;
139
140 case AML_CREATE_BIT_FIELD_OP:
141
142 /* Offset is in bits, Field is one bit */
143
144 bit_offset = offset;
4be44fcd 145 bit_count = 1;
1da177e4
LT
146 field_flags = AML_FIELD_ACCESS_BYTE;
147 break;
148
149 case AML_CREATE_BYTE_FIELD_OP:
150
151 /* Offset is in bytes, field is one byte */
152
153 bit_offset = 8 * offset;
4be44fcd 154 bit_count = 8;
1da177e4
LT
155 field_flags = AML_FIELD_ACCESS_BYTE;
156 break;
157
158 case AML_CREATE_WORD_FIELD_OP:
159
160 /* Offset is in bytes, field is one word */
161
162 bit_offset = 8 * offset;
4be44fcd 163 bit_count = 16;
1da177e4
LT
164 field_flags = AML_FIELD_ACCESS_WORD;
165 break;
166
167 case AML_CREATE_DWORD_FIELD_OP:
168
169 /* Offset is in bytes, field is one dword */
170
171 bit_offset = 8 * offset;
4be44fcd 172 bit_count = 32;
1da177e4
LT
173 field_flags = AML_FIELD_ACCESS_DWORD;
174 break;
175
176 case AML_CREATE_QWORD_FIELD_OP:
177
178 /* Offset is in bytes, field is one qword */
179
180 bit_offset = 8 * offset;
4be44fcd 181 bit_count = 64;
1da177e4
LT
182 field_flags = AML_FIELD_ACCESS_QWORD;
183 break;
184
185 default:
186
b8e4d893 187 ACPI_ERROR((AE_INFO,
f6a22b0b
BM
188 "Unknown field creation opcode 0x%02X",
189 aml_opcode));
1da177e4
LT
190 status = AE_AML_BAD_OPCODE;
191 goto cleanup;
192 }
193
194 /* Entire field must fit within the current length of the buffer */
195
5e2d9e91 196 if ((bit_offset + bit_count) > (8 * (u32)buffer_desc->buffer.length)) {
b8e4d893 197 ACPI_ERROR((AE_INFO,
5e2d9e91
BM
198 "Field [%4.4s] at bit offset/length %u/%u "
199 "exceeds size of target Buffer (%u bits)",
200 acpi_ut_get_node_name(result_desc), bit_offset,
201 bit_count, 8 * (u32)buffer_desc->buffer.length));
1da177e4
LT
202 status = AE_AML_BUFFER_LIMIT;
203 goto cleanup;
204 }
205
206 /*
207 * Initialize areas of the field object that are common to all fields
44f6c012
RM
208 * For field_flags, use LOCK_RULE = 0 (NO_LOCK),
209 * UPDATE_RULE = 0 (UPDATE_PRESERVE)
1da177e4 210 */
1fad8738
BM
211 status =
212 acpi_ex_prep_common_field_object(obj_desc, field_flags, 0,
213 bit_offset, bit_count);
4be44fcd 214 if (ACPI_FAILURE(status)) {
1da177e4
LT
215 goto cleanup;
216 }
217
218 obj_desc->buffer_field.buffer_obj = buffer_desc;
219
220 /* Reference count for buffer_desc inherits obj_desc count */
221
44f6c012 222 buffer_desc->common.reference_count = (u16)
4be44fcd
LB
223 (buffer_desc->common.reference_count +
224 obj_desc->common.reference_count);
1da177e4 225
10622bf8 226cleanup:
1da177e4
LT
227
228 /* Always delete the operands */
229
4be44fcd
LB
230 acpi_ut_remove_reference(offset_desc);
231 acpi_ut_remove_reference(buffer_desc);
1da177e4
LT
232
233 if (aml_opcode == AML_CREATE_FIELD_OP) {
4be44fcd 234 acpi_ut_remove_reference(length_desc);
1da177e4
LT
235 }
236
237 /* On failure, delete the result descriptor */
238
4be44fcd
LB
239 if (ACPI_FAILURE(status)) {
240 acpi_ut_remove_reference(result_desc); /* Result descriptor */
241 } else {
1da177e4
LT
242 /* Now the address and length are valid for this buffer_field */
243
244 obj_desc->buffer_field.flags |= AOPOBJ_DATA_VALID;
245 }
246
4be44fcd 247 return_ACPI_STATUS(status);
1da177e4
LT
248}
249
44f6c012 250/*******************************************************************************
1da177e4
LT
251 *
252 * FUNCTION: acpi_ds_eval_buffer_field_operands
253 *
254 * PARAMETERS: walk_state - Current walk
ba494bee 255 * op - A valid buffer_field Op object
1da177e4
LT
256 *
257 * RETURN: Status
258 *
259 * DESCRIPTION: Get buffer_field Buffer and Index
260 * Called from acpi_ds_exec_end_op during buffer_field parse tree walk
261 *
44f6c012 262 ******************************************************************************/
1da177e4
LT
263
264acpi_status
4be44fcd
LB
265acpi_ds_eval_buffer_field_operands(struct acpi_walk_state *walk_state,
266 union acpi_parse_object *op)
1da177e4 267{
4be44fcd
LB
268 acpi_status status;
269 union acpi_operand_object *obj_desc;
270 struct acpi_namespace_node *node;
271 union acpi_parse_object *next_op;
1da177e4 272
b229cf92 273 ACPI_FUNCTION_TRACE_PTR(ds_eval_buffer_field_operands, op);
1da177e4
LT
274
275 /*
276 * This is where we evaluate the address and length fields of the
277 * create_xxx_field declaration
278 */
4be44fcd 279 node = op->common.node;
1da177e4
LT
280
281 /* next_op points to the op that holds the Buffer */
282
283 next_op = op->common.value.arg;
284
285 /* Evaluate/create the address and length operands */
286
4be44fcd
LB
287 status = acpi_ds_create_operands(walk_state, next_op);
288 if (ACPI_FAILURE(status)) {
289 return_ACPI_STATUS(status);
1da177e4
LT
290 }
291
4be44fcd 292 obj_desc = acpi_ns_get_attached_object(node);
1da177e4 293 if (!obj_desc) {
4be44fcd 294 return_ACPI_STATUS(AE_NOT_EXIST);
1da177e4
LT
295 }
296
297 /* Resolve the operands */
298
1fad8738
BM
299 status =
300 acpi_ex_resolve_operands(op->common.aml_opcode, ACPI_WALK_OPERANDS,
301 walk_state);
4be44fcd 302 if (ACPI_FAILURE(status)) {
f6a22b0b 303 ACPI_ERROR((AE_INFO, "(%s) bad operand(s), status 0x%X",
b8e4d893
BM
304 acpi_ps_get_opcode_name(op->common.aml_opcode),
305 status));
1da177e4 306
4be44fcd 307 return_ACPI_STATUS(status);
1da177e4
LT
308 }
309
310 /* Initialize the Buffer Field */
311
312 if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
52fc0b02 313
1da177e4
LT
314 /* NOTE: Slightly different operands for this opcode */
315
4be44fcd
LB
316 status =
317 acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc,
318 walk_state->operands[0],
319 walk_state->operands[1],
320 walk_state->operands[2],
321 walk_state->operands[3]);
322 } else {
1da177e4
LT
323 /* All other, create_xxx_field opcodes */
324
4be44fcd
LB
325 status =
326 acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc,
327 walk_state->operands[0],
328 walk_state->operands[1], NULL,
329 walk_state->operands[2]);
1da177e4
LT
330 }
331
4be44fcd 332 return_ACPI_STATUS(status);
1da177e4
LT
333}
334
44f6c012 335/*******************************************************************************
1da177e4
LT
336 *
337 * FUNCTION: acpi_ds_eval_region_operands
338 *
339 * PARAMETERS: walk_state - Current walk
ba494bee 340 * op - A valid region Op object
1da177e4
LT
341 *
342 * RETURN: Status
343 *
344 * DESCRIPTION: Get region address and length
345 * Called from acpi_ds_exec_end_op during op_region parse tree walk
346 *
44f6c012 347 ******************************************************************************/
1da177e4
LT
348
349acpi_status
4be44fcd
LB
350acpi_ds_eval_region_operands(struct acpi_walk_state *walk_state,
351 union acpi_parse_object *op)
1da177e4 352{
4be44fcd
LB
353 acpi_status status;
354 union acpi_operand_object *obj_desc;
355 union acpi_operand_object *operand_desc;
356 struct acpi_namespace_node *node;
357 union acpi_parse_object *next_op;
1da177e4 358
b229cf92 359 ACPI_FUNCTION_TRACE_PTR(ds_eval_region_operands, op);
1da177e4
LT
360
361 /*
44f6c012
RM
362 * This is where we evaluate the address and length fields of the
363 * op_region declaration
1da177e4 364 */
4be44fcd 365 node = op->common.node;
1da177e4 366
ba494bee 367 /* next_op points to the op that holds the space_ID */
1da177e4
LT
368
369 next_op = op->common.value.arg;
370
371 /* next_op points to address op */
372
373 next_op = next_op->common.next;
374
375 /* Evaluate/create the address and length operands */
376
4be44fcd
LB
377 status = acpi_ds_create_operands(walk_state, next_op);
378 if (ACPI_FAILURE(status)) {
379 return_ACPI_STATUS(status);
1da177e4
LT
380 }
381
382 /* Resolve the length and address operands to numbers */
383
1fad8738
BM
384 status =
385 acpi_ex_resolve_operands(op->common.aml_opcode, ACPI_WALK_OPERANDS,
386 walk_state);
4be44fcd
LB
387 if (ACPI_FAILURE(status)) {
388 return_ACPI_STATUS(status);
1da177e4
LT
389 }
390
4be44fcd 391 obj_desc = acpi_ns_get_attached_object(node);
1da177e4 392 if (!obj_desc) {
4be44fcd 393 return_ACPI_STATUS(AE_NOT_EXIST);
1da177e4
LT
394 }
395
396 /*
397 * Get the length operand and save it
398 * (at Top of stack)
399 */
400 operand_desc = walk_state->operands[walk_state->num_operands - 1];
401
402 obj_desc->region.length = (u32) operand_desc->integer.value;
4be44fcd 403 acpi_ut_remove_reference(operand_desc);
1da177e4
LT
404
405 /*
406 * Get the address and save it
407 * (at top of stack - 1)
408 */
409 operand_desc = walk_state->operands[walk_state->num_operands - 2];
410
44f6c012 411 obj_desc->region.address = (acpi_physical_address)
4be44fcd
LB
412 operand_desc->integer.value;
413 acpi_ut_remove_reference(operand_desc);
1da177e4 414
b229cf92 415 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
4be44fcd 416 obj_desc,
1d0a0b2f 417 ACPI_FORMAT_UINT64(obj_desc->region.address),
4be44fcd 418 obj_desc->region.length));
1da177e4
LT
419
420 /* Now the address and length are valid for this opregion */
421
422 obj_desc->region.flags |= AOPOBJ_DATA_VALID;
4be44fcd 423 return_ACPI_STATUS(status);
1da177e4
LT
424}
425
941f48bb
LM
426/*******************************************************************************
427 *
428 * FUNCTION: acpi_ds_eval_table_region_operands
429 *
430 * PARAMETERS: walk_state - Current walk
ba494bee 431 * op - A valid region Op object
941f48bb
LM
432 *
433 * RETURN: Status
434 *
9ad19ac4
BM
435 * DESCRIPTION: Get region address and length.
436 * Called from acpi_ds_exec_end_op during data_table_region parse
437 * tree walk.
941f48bb
LM
438 *
439 ******************************************************************************/
440
441acpi_status
442acpi_ds_eval_table_region_operands(struct acpi_walk_state *walk_state,
443 union acpi_parse_object *op)
444{
445 acpi_status status;
446 union acpi_operand_object *obj_desc;
447 union acpi_operand_object **operand;
448 struct acpi_namespace_node *node;
449 union acpi_parse_object *next_op;
941f48bb 450 struct acpi_table_header *table;
9f41fd8a 451 u32 table_index;
941f48bb
LM
452
453 ACPI_FUNCTION_TRACE_PTR(ds_eval_table_region_operands, op);
454
455 /*
75c8044f
LZ
456 * This is where we evaluate the Signature string, oem_id string,
457 * and oem_table_id string of the Data Table Region declaration
941f48bb
LM
458 */
459 node = op->common.node;
460
75c8044f 461 /* next_op points to Signature string op */
941f48bb
LM
462
463 next_op = op->common.value.arg;
464
465 /*
75c8044f
LZ
466 * Evaluate/create the Signature string, oem_id string,
467 * and oem_table_id string operands
941f48bb
LM
468 */
469 status = acpi_ds_create_operands(walk_state, next_op);
470 if (ACPI_FAILURE(status)) {
471 return_ACPI_STATUS(status);
472 }
473
9f41fd8a
BM
474 operand = &walk_state->operands[0];
475
941f48bb 476 /*
75c8044f
LZ
477 * Resolve the Signature string, oem_id string,
478 * and oem_table_id string operands
941f48bb 479 */
1fad8738
BM
480 status =
481 acpi_ex_resolve_operands(op->common.aml_opcode, ACPI_WALK_OPERANDS,
482 walk_state);
941f48bb 483 if (ACPI_FAILURE(status)) {
9f41fd8a 484 goto cleanup;
941f48bb
LM
485 }
486
941f48bb
LM
487 /* Find the ACPI table */
488
489 status = acpi_tb_find_table(operand[0]->string.pointer,
490 operand[1]->string.pointer,
491 operand[2]->string.pointer, &table_index);
492 if (ACPI_FAILURE(status)) {
9f41fd8a
BM
493 if (status == AE_NOT_FOUND) {
494 ACPI_ERROR((AE_INFO,
495 "ACPI Table [%4.4s] OEM:(%s, %s) not found in RSDT/XSDT",
496 operand[0]->string.pointer,
497 operand[1]->string.pointer,
498 operand[2]->string.pointer));
499 }
500 goto cleanup;
941f48bb
LM
501 }
502
941f48bb
LM
503 status = acpi_get_table_by_index(table_index, &table);
504 if (ACPI_FAILURE(status)) {
9f41fd8a 505 goto cleanup;
941f48bb
LM
506 }
507
508 obj_desc = acpi_ns_get_attached_object(node);
509 if (!obj_desc) {
9f41fd8a
BM
510 status = AE_NOT_EXIST;
511 goto cleanup;
941f48bb
LM
512 }
513
6d3fd3cc 514 obj_desc->region.address = ACPI_PTR_TO_PHYSADDR(table);
941f48bb
LM
515 obj_desc->region.length = table->length;
516
517 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
518 obj_desc,
1d0a0b2f 519 ACPI_FORMAT_UINT64(obj_desc->region.address),
941f48bb
LM
520 obj_desc->region.length));
521
522 /* Now the address and length are valid for this opregion */
523
524 obj_desc->region.flags |= AOPOBJ_DATA_VALID;
525
9f41fd8a
BM
526cleanup:
527 acpi_ut_remove_reference(operand[0]);
528 acpi_ut_remove_reference(operand[1]);
529 acpi_ut_remove_reference(operand[2]);
530
941f48bb
LM
531 return_ACPI_STATUS(status);
532}
533
44f6c012 534/*******************************************************************************
1da177e4
LT
535 *
536 * FUNCTION: acpi_ds_eval_data_object_operands
537 *
538 * PARAMETERS: walk_state - Current walk
ba494bee 539 * op - A valid data_object Op object
1da177e4
LT
540 * obj_desc - data_object
541 *
542 * RETURN: Status
543 *
544 * DESCRIPTION: Get the operands and complete the following data object types:
545 * Buffer, Package.
546 *
44f6c012 547 ******************************************************************************/
1da177e4
LT
548
549acpi_status
4be44fcd
LB
550acpi_ds_eval_data_object_operands(struct acpi_walk_state *walk_state,
551 union acpi_parse_object *op,
552 union acpi_operand_object *obj_desc)
1da177e4 553{
4be44fcd
LB
554 acpi_status status;
555 union acpi_operand_object *arg_desc;
556 u32 length;
1da177e4 557
b229cf92 558 ACPI_FUNCTION_TRACE(ds_eval_data_object_operands);
1da177e4
LT
559
560 /* The first operand (for all of these data objects) is the length */
561
773069d4
BM
562 /*
563 * Set proper index into operand stack for acpi_ds_obj_stack_push
564 * invoked inside acpi_ds_create_operand.
565 */
566 walk_state->operand_index = walk_state->num_operands;
567
a62a7117
BM
568 /* Ignore if child is not valid */
569
570 if (!op->common.value.arg) {
571 ACPI_ERROR((AE_INFO,
1ef63231
BM
572 "Missing child while evaluating opcode %4.4X, Op %p",
573 op->common.aml_opcode, op));
a62a7117
BM
574 return_ACPI_STATUS(AE_OK);
575 }
576
4be44fcd
LB
577 status = acpi_ds_create_operand(walk_state, op->common.value.arg, 1);
578 if (ACPI_FAILURE(status)) {
579 return_ACPI_STATUS(status);
1da177e4
LT
580 }
581
4be44fcd
LB
582 status = acpi_ex_resolve_operands(walk_state->opcode,
583 &(walk_state->
584 operands[walk_state->num_operands -
585 1]), walk_state);
586 if (ACPI_FAILURE(status)) {
587 return_ACPI_STATUS(status);
1da177e4
LT
588 }
589
590 /* Extract length operand */
591
4be44fcd 592 arg_desc = walk_state->operands[walk_state->num_operands - 1];
1da177e4
LT
593 length = (u32) arg_desc->integer.value;
594
595 /* Cleanup for length operand */
596
4be44fcd
LB
597 status = acpi_ds_obj_stack_pop(1, walk_state);
598 if (ACPI_FAILURE(status)) {
599 return_ACPI_STATUS(status);
1da177e4
LT
600 }
601
4be44fcd 602 acpi_ut_remove_reference(arg_desc);
1da177e4
LT
603
604 /*
605 * Create the actual data object
606 */
607 switch (op->common.aml_opcode) {
608 case AML_BUFFER_OP:
609
4be44fcd
LB
610 status =
611 acpi_ds_build_internal_buffer_obj(walk_state, op, length,
612 &obj_desc);
1da177e4
LT
613 break;
614
615 case AML_PACKAGE_OP:
9ff5a21a 616 case AML_VARIABLE_PACKAGE_OP:
1da177e4 617
4be44fcd
LB
618 status =
619 acpi_ds_build_internal_package_obj(walk_state, op, length,
620 &obj_desc);
1da177e4
LT
621 break;
622
623 default:
1d1ea1b7 624
4be44fcd 625 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
1da177e4
LT
626 }
627
4be44fcd 628 if (ACPI_SUCCESS(status)) {
1da177e4 629 /*
44f6c012 630 * Return the object in the walk_state, unless the parent is a package -
1da177e4
LT
631 * in this case, the return object will be stored in the parse tree
632 * for the package.
633 */
634 if ((!op->common.parent) ||
4be44fcd
LB
635 ((op->common.parent->common.aml_opcode != AML_PACKAGE_OP) &&
636 (op->common.parent->common.aml_opcode !=
9ff5a21a 637 AML_VARIABLE_PACKAGE_OP)
1f86e8c1
LZ
638 && (op->common.parent->common.aml_opcode !=
639 AML_NAME_OP))) {
1da177e4
LT
640 walk_state->result_obj = obj_desc;
641 }
642 }
643
4be44fcd 644 return_ACPI_STATUS(status);
1da177e4
LT
645}
646
ef805d95
LM
647/*******************************************************************************
648 *
649 * FUNCTION: acpi_ds_eval_bank_field_operands
650 *
651 * PARAMETERS: walk_state - Current walk
ba494bee 652 * op - A valid bank_field Op object
ef805d95
LM
653 *
654 * RETURN: Status
655 *
656 * DESCRIPTION: Get bank_field bank_value
657 * Called from acpi_ds_exec_end_op during bank_field parse tree walk
658 *
659 ******************************************************************************/
660
661acpi_status
662acpi_ds_eval_bank_field_operands(struct acpi_walk_state *walk_state,
663 union acpi_parse_object *op)
664{
665 acpi_status status;
666 union acpi_operand_object *obj_desc;
667 union acpi_operand_object *operand_desc;
668 struct acpi_namespace_node *node;
669 union acpi_parse_object *next_op;
670 union acpi_parse_object *arg;
671
672 ACPI_FUNCTION_TRACE_PTR(ds_eval_bank_field_operands, op);
673
674 /*
675 * This is where we evaluate the bank_value field of the
676 * bank_field declaration
677 */
678
679 /* next_op points to the op that holds the Region */
680
681 next_op = op->common.value.arg;
682
683 /* next_op points to the op that holds the Bank Register */
684
685 next_op = next_op->common.next;
686
687 /* next_op points to the op that holds the Bank Value */
688
689 next_op = next_op->common.next;
690
691 /*
692 * Set proper index into operand stack for acpi_ds_obj_stack_push
693 * invoked inside acpi_ds_create_operand.
694 *
695 * We use walk_state->Operands[0] to store the evaluated bank_value
696 */
697 walk_state->operand_index = 0;
698
699 status = acpi_ds_create_operand(walk_state, next_op, 0);
700 if (ACPI_FAILURE(status)) {
701 return_ACPI_STATUS(status);
702 }
703
704 status = acpi_ex_resolve_to_value(&walk_state->operands[0], walk_state);
705 if (ACPI_FAILURE(status)) {
706 return_ACPI_STATUS(status);
707 }
708
71d993e1
BM
709 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS,
710 acpi_ps_get_opcode_name(op->common.aml_opcode), 1);
ef805d95
LM
711 /*
712 * Get the bank_value operand and save it
713 * (at Top of stack)
714 */
715 operand_desc = walk_state->operands[0];
716
717 /* Arg points to the start Bank Field */
718
719 arg = acpi_ps_get_arg(op, 4);
720 while (arg) {
721
722 /* Ignore OFFSET and ACCESSAS terms here */
723
724 if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) {
725 node = arg->common.node;
726
727 obj_desc = acpi_ns_get_attached_object(node);
728 if (!obj_desc) {
729 return_ACPI_STATUS(AE_NOT_EXIST);
730 }
731
732 obj_desc->bank_field.value =
733 (u32) operand_desc->integer.value;
734 }
735
736 /* Move to next field in the list */
737
738 arg = arg->common.next;
739 }
740
741 acpi_ut_remove_reference(operand_desc);
742 return_ACPI_STATUS(status);
743}