1 /******************************************************************************
3 * Module Name: dsopcode - Dispatcher support for regions and fields
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2017, 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>
54 #define _COMPONENT ACPI_DISPATCHER
55 ACPI_MODULE_NAME("dsopcode")
57 /* Local prototypes */
59 acpi_ds_init_buffer_field(u16 aml_opcode,
60 union acpi_operand_object *obj_desc,
61 union acpi_operand_object *buffer_desc,
62 union acpi_operand_object *offset_desc,
63 union acpi_operand_object *length_desc,
64 union acpi_operand_object *result_desc);
66 /*******************************************************************************
68 * FUNCTION: acpi_ds_initialize_region
70 * PARAMETERS: obj_handle - Region namespace node
74 * DESCRIPTION: Front end to ev_initialize_region
76 ******************************************************************************/
78 acpi_status acpi_ds_initialize_region(acpi_handle obj_handle)
80 union acpi_operand_object *obj_desc;
83 obj_desc = acpi_ns_get_attached_object(obj_handle);
85 /* Namespace is NOT locked */
87 status = acpi_ev_initialize_region(obj_desc);
91 /*******************************************************************************
93 * FUNCTION: acpi_ds_init_buffer_field
95 * PARAMETERS: aml_opcode - create_xxx_field
96 * obj_desc - buffer_field object
97 * buffer_desc - Host Buffer
98 * offset_desc - Offset into buffer
99 * length_desc - Length of field (CREATE_FIELD_OP only)
100 * result_desc - Where to store the result
104 * DESCRIPTION: Perform actual initialization of a buffer field
106 ******************************************************************************/
109 acpi_ds_init_buffer_field(u16 aml_opcode,
110 union acpi_operand_object *obj_desc,
111 union acpi_operand_object *buffer_desc,
112 union acpi_operand_object *offset_desc,
113 union acpi_operand_object *length_desc,
114 union acpi_operand_object *result_desc)
122 ACPI_FUNCTION_TRACE_PTR(ds_init_buffer_field, obj_desc);
124 /* Host object must be a Buffer */
126 if (buffer_desc->common.type != ACPI_TYPE_BUFFER) {
128 "Target of Create Field is not a Buffer object - %s",
129 acpi_ut_get_object_type_name(buffer_desc)));
131 status = AE_AML_OPERAND_TYPE;
136 * The last parameter to all of these opcodes (result_desc) started
137 * out as a name_string, and should therefore now be a NS node
138 * after resolution in acpi_ex_resolve_operands().
140 if (ACPI_GET_DESCRIPTOR_TYPE(result_desc) != ACPI_DESC_TYPE_NAMED) {
142 "(%s) destination not a NS Node [%s]",
143 acpi_ps_get_opcode_name(aml_opcode),
144 acpi_ut_get_descriptor_name(result_desc)));
146 status = AE_AML_OPERAND_TYPE;
150 offset = (u32) offset_desc->integer.value;
153 * Setup the Bit offsets and counts, according to the opcode
155 switch (aml_opcode) {
156 case AML_CREATE_FIELD_OP:
158 /* Offset is in bits, count is in bits */
160 field_flags = AML_FIELD_ACCESS_BYTE;
162 bit_count = (u32) length_desc->integer.value;
164 /* Must have a valid (>0) bit count */
166 if (bit_count == 0) {
168 "Attempt to CreateField of length zero"));
169 status = AE_AML_OPERAND_VALUE;
174 case AML_CREATE_BIT_FIELD_OP:
176 /* Offset is in bits, Field is one bit */
180 field_flags = AML_FIELD_ACCESS_BYTE;
183 case AML_CREATE_BYTE_FIELD_OP:
185 /* Offset is in bytes, field is one byte */
187 bit_offset = 8 * offset;
189 field_flags = AML_FIELD_ACCESS_BYTE;
192 case AML_CREATE_WORD_FIELD_OP:
194 /* Offset is in bytes, field is one word */
196 bit_offset = 8 * offset;
198 field_flags = AML_FIELD_ACCESS_WORD;
201 case AML_CREATE_DWORD_FIELD_OP:
203 /* Offset is in bytes, field is one dword */
205 bit_offset = 8 * offset;
207 field_flags = AML_FIELD_ACCESS_DWORD;
210 case AML_CREATE_QWORD_FIELD_OP:
212 /* Offset is in bytes, field is one qword */
214 bit_offset = 8 * offset;
216 field_flags = AML_FIELD_ACCESS_QWORD;
222 "Unknown field creation opcode 0x%02X",
224 status = AE_AML_BAD_OPCODE;
228 /* Entire field must fit within the current length of the buffer */
230 if ((bit_offset + bit_count) > (8 * (u32)buffer_desc->buffer.length)) {
232 "Field [%4.4s] at bit offset/length %u/%u "
233 "exceeds size of target Buffer (%u bits)",
234 acpi_ut_get_node_name(result_desc), bit_offset,
235 bit_count, 8 * (u32)buffer_desc->buffer.length));
236 status = AE_AML_BUFFER_LIMIT;
241 * Initialize areas of the field object that are common to all fields
242 * For field_flags, use LOCK_RULE = 0 (NO_LOCK),
243 * UPDATE_RULE = 0 (UPDATE_PRESERVE)
246 acpi_ex_prep_common_field_object(obj_desc, field_flags, 0,
247 bit_offset, bit_count);
248 if (ACPI_FAILURE(status)) {
252 obj_desc->buffer_field.buffer_obj = buffer_desc;
254 /* Reference count for buffer_desc inherits obj_desc count */
256 buffer_desc->common.reference_count = (u16)
257 (buffer_desc->common.reference_count +
258 obj_desc->common.reference_count);
262 /* Always delete the operands */
264 acpi_ut_remove_reference(offset_desc);
265 acpi_ut_remove_reference(buffer_desc);
267 if (aml_opcode == AML_CREATE_FIELD_OP) {
268 acpi_ut_remove_reference(length_desc);
271 /* On failure, delete the result descriptor */
273 if (ACPI_FAILURE(status)) {
274 acpi_ut_remove_reference(result_desc); /* Result descriptor */
276 /* Now the address and length are valid for this buffer_field */
278 obj_desc->buffer_field.flags |= AOPOBJ_DATA_VALID;
281 return_ACPI_STATUS(status);
284 /*******************************************************************************
286 * FUNCTION: acpi_ds_eval_buffer_field_operands
288 * PARAMETERS: walk_state - Current walk
289 * op - A valid buffer_field Op object
293 * DESCRIPTION: Get buffer_field Buffer and Index
294 * Called from acpi_ds_exec_end_op during buffer_field parse tree walk
296 ******************************************************************************/
299 acpi_ds_eval_buffer_field_operands(struct acpi_walk_state *walk_state,
300 union acpi_parse_object *op)
303 union acpi_operand_object *obj_desc;
304 struct acpi_namespace_node *node;
305 union acpi_parse_object *next_op;
307 ACPI_FUNCTION_TRACE_PTR(ds_eval_buffer_field_operands, op);
310 * This is where we evaluate the address and length fields of the
311 * create_xxx_field declaration
313 node = op->common.node;
315 /* next_op points to the op that holds the Buffer */
317 next_op = op->common.value.arg;
319 /* Evaluate/create the address and length operands */
321 status = acpi_ds_create_operands(walk_state, next_op);
322 if (ACPI_FAILURE(status)) {
323 return_ACPI_STATUS(status);
326 obj_desc = acpi_ns_get_attached_object(node);
328 return_ACPI_STATUS(AE_NOT_EXIST);
331 /* Resolve the operands */
334 acpi_ex_resolve_operands(op->common.aml_opcode, ACPI_WALK_OPERANDS,
336 if (ACPI_FAILURE(status)) {
337 ACPI_ERROR((AE_INFO, "(%s) bad operand(s), status 0x%X",
338 acpi_ps_get_opcode_name(op->common.aml_opcode),
341 return_ACPI_STATUS(status);
344 /* Initialize the Buffer Field */
346 if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
348 /* NOTE: Slightly different operands for this opcode */
351 acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc,
352 walk_state->operands[0],
353 walk_state->operands[1],
354 walk_state->operands[2],
355 walk_state->operands[3]);
357 /* All other, create_xxx_field opcodes */
360 acpi_ds_init_buffer_field(op->common.aml_opcode, obj_desc,
361 walk_state->operands[0],
362 walk_state->operands[1], NULL,
363 walk_state->operands[2]);
366 return_ACPI_STATUS(status);
369 /*******************************************************************************
371 * FUNCTION: acpi_ds_eval_region_operands
373 * PARAMETERS: walk_state - Current walk
374 * op - A valid region Op object
378 * DESCRIPTION: Get region address and length
379 * Called from acpi_ds_exec_end_op during op_region parse tree walk
381 ******************************************************************************/
384 acpi_ds_eval_region_operands(struct acpi_walk_state *walk_state,
385 union acpi_parse_object *op)
388 union acpi_operand_object *obj_desc;
389 union acpi_operand_object *operand_desc;
390 struct acpi_namespace_node *node;
391 union acpi_parse_object *next_op;
393 ACPI_FUNCTION_TRACE_PTR(ds_eval_region_operands, op);
396 * This is where we evaluate the address and length fields of the
397 * op_region declaration
399 node = op->common.node;
401 /* next_op points to the op that holds the space_ID */
403 next_op = op->common.value.arg;
405 /* next_op points to address op */
407 next_op = next_op->common.next;
409 /* Evaluate/create the address and length operands */
411 status = acpi_ds_create_operands(walk_state, next_op);
412 if (ACPI_FAILURE(status)) {
413 return_ACPI_STATUS(status);
416 /* Resolve the length and address operands to numbers */
419 acpi_ex_resolve_operands(op->common.aml_opcode, ACPI_WALK_OPERANDS,
421 if (ACPI_FAILURE(status)) {
422 return_ACPI_STATUS(status);
425 obj_desc = acpi_ns_get_attached_object(node);
427 return_ACPI_STATUS(AE_NOT_EXIST);
431 * Get the length operand and save it
434 operand_desc = walk_state->operands[walk_state->num_operands - 1];
436 obj_desc->region.length = (u32) operand_desc->integer.value;
437 acpi_ut_remove_reference(operand_desc);
440 * Get the address and save it
441 * (at top of stack - 1)
443 operand_desc = walk_state->operands[walk_state->num_operands - 2];
445 obj_desc->region.address = (acpi_physical_address)
446 operand_desc->integer.value;
447 acpi_ut_remove_reference(operand_desc);
449 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
451 ACPI_FORMAT_UINT64(obj_desc->region.address),
452 obj_desc->region.length));
454 status = acpi_ut_add_address_range(obj_desc->region.space_id,
455 obj_desc->region.address,
456 obj_desc->region.length, node);
458 /* Now the address and length are valid for this opregion */
460 obj_desc->region.flags |= AOPOBJ_DATA_VALID;
461 return_ACPI_STATUS(status);
464 /*******************************************************************************
466 * FUNCTION: acpi_ds_eval_table_region_operands
468 * PARAMETERS: walk_state - Current walk
469 * op - A valid region Op object
473 * DESCRIPTION: Get region address and length.
474 * Called from acpi_ds_exec_end_op during data_table_region parse
477 ******************************************************************************/
480 acpi_ds_eval_table_region_operands(struct acpi_walk_state *walk_state,
481 union acpi_parse_object *op)
484 union acpi_operand_object *obj_desc;
485 union acpi_operand_object **operand;
486 struct acpi_namespace_node *node;
487 union acpi_parse_object *next_op;
488 struct acpi_table_header *table;
491 ACPI_FUNCTION_TRACE_PTR(ds_eval_table_region_operands, op);
494 * This is where we evaluate the Signature string, oem_id string,
495 * and oem_table_id string of the Data Table Region declaration
497 node = op->common.node;
499 /* next_op points to Signature string op */
501 next_op = op->common.value.arg;
504 * Evaluate/create the Signature string, oem_id string,
505 * and oem_table_id string operands
507 status = acpi_ds_create_operands(walk_state, next_op);
508 if (ACPI_FAILURE(status)) {
509 return_ACPI_STATUS(status);
512 operand = &walk_state->operands[0];
515 * Resolve the Signature string, oem_id string,
516 * and oem_table_id string operands
519 acpi_ex_resolve_operands(op->common.aml_opcode, ACPI_WALK_OPERANDS,
521 if (ACPI_FAILURE(status)) {
525 /* Find the ACPI table */
527 status = acpi_tb_find_table(operand[0]->string.pointer,
528 operand[1]->string.pointer,
529 operand[2]->string.pointer, &table_index);
530 if (ACPI_FAILURE(status)) {
531 if (status == AE_NOT_FOUND) {
533 "ACPI Table [%4.4s] OEM:(%s, %s) not found in RSDT/XSDT",
534 operand[0]->string.pointer,
535 operand[1]->string.pointer,
536 operand[2]->string.pointer));
541 status = acpi_get_table_by_index(table_index, &table);
542 if (ACPI_FAILURE(status)) {
546 obj_desc = acpi_ns_get_attached_object(node);
548 status = AE_NOT_EXIST;
552 obj_desc->region.address = ACPI_PTR_TO_PHYSADDR(table);
553 obj_desc->region.length = table->length;
555 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
557 ACPI_FORMAT_UINT64(obj_desc->region.address),
558 obj_desc->region.length));
560 /* Now the address and length are valid for this opregion */
562 obj_desc->region.flags |= AOPOBJ_DATA_VALID;
565 acpi_ut_remove_reference(operand[0]);
566 acpi_ut_remove_reference(operand[1]);
567 acpi_ut_remove_reference(operand[2]);
569 return_ACPI_STATUS(status);
572 /*******************************************************************************
574 * FUNCTION: acpi_ds_eval_data_object_operands
576 * PARAMETERS: walk_state - Current walk
577 * op - A valid data_object Op object
578 * obj_desc - data_object
582 * DESCRIPTION: Get the operands and complete the following data object types:
585 ******************************************************************************/
588 acpi_ds_eval_data_object_operands(struct acpi_walk_state *walk_state,
589 union acpi_parse_object *op,
590 union acpi_operand_object *obj_desc)
593 union acpi_operand_object *arg_desc;
596 ACPI_FUNCTION_TRACE(ds_eval_data_object_operands);
598 /* The first operand (for all of these data objects) is the length */
601 * Set proper index into operand stack for acpi_ds_obj_stack_push
602 * invoked inside acpi_ds_create_operand.
604 walk_state->operand_index = walk_state->num_operands;
606 /* Ignore if child is not valid */
608 if (!op->common.value.arg) {
610 "Dispatch: Missing child while executing TermArg for %X",
611 op->common.aml_opcode));
612 return_ACPI_STATUS(AE_OK);
615 status = acpi_ds_create_operand(walk_state, op->common.value.arg, 1);
616 if (ACPI_FAILURE(status)) {
617 return_ACPI_STATUS(status);
620 status = acpi_ex_resolve_operands(walk_state->opcode,
622 operands[walk_state->num_operands -
624 if (ACPI_FAILURE(status)) {
625 return_ACPI_STATUS(status);
628 /* Extract length operand */
630 arg_desc = walk_state->operands[walk_state->num_operands - 1];
631 length = (u32) arg_desc->integer.value;
633 /* Cleanup for length operand */
635 status = acpi_ds_obj_stack_pop(1, walk_state);
636 if (ACPI_FAILURE(status)) {
637 return_ACPI_STATUS(status);
640 acpi_ut_remove_reference(arg_desc);
643 * Create the actual data object
645 switch (op->common.aml_opcode) {
649 acpi_ds_build_internal_buffer_obj(walk_state, op, length,
654 case AML_VARIABLE_PACKAGE_OP:
657 acpi_ds_build_internal_package_obj(walk_state, op, length,
663 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
666 if (ACPI_SUCCESS(status)) {
668 * Return the object in the walk_state, unless the parent is a package -
669 * in this case, the return object will be stored in the parse tree
672 if ((!op->common.parent) ||
673 ((op->common.parent->common.aml_opcode != AML_PACKAGE_OP) &&
674 (op->common.parent->common.aml_opcode !=
675 AML_VARIABLE_PACKAGE_OP)
676 && (op->common.parent->common.aml_opcode !=
678 walk_state->result_obj = obj_desc;
682 return_ACPI_STATUS(status);
685 /*******************************************************************************
687 * FUNCTION: acpi_ds_eval_bank_field_operands
689 * PARAMETERS: walk_state - Current walk
690 * op - A valid bank_field Op object
694 * DESCRIPTION: Get bank_field bank_value
695 * Called from acpi_ds_exec_end_op during bank_field parse tree walk
697 ******************************************************************************/
700 acpi_ds_eval_bank_field_operands(struct acpi_walk_state *walk_state,
701 union acpi_parse_object *op)
704 union acpi_operand_object *obj_desc;
705 union acpi_operand_object *operand_desc;
706 struct acpi_namespace_node *node;
707 union acpi_parse_object *next_op;
708 union acpi_parse_object *arg;
710 ACPI_FUNCTION_TRACE_PTR(ds_eval_bank_field_operands, op);
713 * This is where we evaluate the bank_value field of the
714 * bank_field declaration
717 /* next_op points to the op that holds the Region */
719 next_op = op->common.value.arg;
721 /* next_op points to the op that holds the Bank Register */
723 next_op = next_op->common.next;
725 /* next_op points to the op that holds the Bank Value */
727 next_op = next_op->common.next;
730 * Set proper index into operand stack for acpi_ds_obj_stack_push
731 * invoked inside acpi_ds_create_operand.
733 * We use walk_state->Operands[0] to store the evaluated bank_value
735 walk_state->operand_index = 0;
737 status = acpi_ds_create_operand(walk_state, next_op, 0);
738 if (ACPI_FAILURE(status)) {
739 return_ACPI_STATUS(status);
742 status = acpi_ex_resolve_to_value(&walk_state->operands[0], walk_state);
743 if (ACPI_FAILURE(status)) {
744 return_ACPI_STATUS(status);
747 ACPI_DUMP_OPERANDS(ACPI_WALK_OPERANDS,
748 acpi_ps_get_opcode_name(op->common.aml_opcode), 1);
750 * Get the bank_value operand and save it
753 operand_desc = walk_state->operands[0];
755 /* Arg points to the start Bank Field */
757 arg = acpi_ps_get_arg(op, 4);
760 /* Ignore OFFSET and ACCESSAS terms here */
762 if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) {
763 node = arg->common.node;
765 obj_desc = acpi_ns_get_attached_object(node);
767 return_ACPI_STATUS(AE_NOT_EXIST);
770 obj_desc->bank_field.value =
771 (u32) operand_desc->integer.value;
774 /* Move to next field in the list */
776 arg = arg->common.next;
779 acpi_ut_remove_reference(operand_desc);
780 return_ACPI_STATUS(status);