1 /******************************************************************************
3 * Module Name: dsfield - Dispatcher field routines
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>
52 #define _COMPONENT ACPI_DISPATCHER
53 ACPI_MODULE_NAME("dsfield")
55 /* Local prototypes */
56 #ifdef ACPI_ASL_COMPILER
59 acpi_ds_create_external_region(acpi_status lookup_status,
60 union acpi_parse_object *op,
62 struct acpi_walk_state *walk_state,
63 struct acpi_namespace_node **node);
67 acpi_ds_get_field_names(struct acpi_create_field_info *info,
68 struct acpi_walk_state *walk_state,
69 union acpi_parse_object *arg);
71 #ifdef ACPI_ASL_COMPILER
72 /*******************************************************************************
74 * FUNCTION: acpi_ds_create_external_region (iASL Disassembler only)
76 * PARAMETERS: lookup_status - Status from ns_lookup operation
77 * op - Op containing the Field definition and args
78 * path - Pathname of the region
79 * ` walk_state - Current method state
80 * node - Where the new region node is returned
84 * DESCRIPTION: Add region to the external list if NOT_FOUND. Create a new
87 ******************************************************************************/
90 acpi_ds_create_external_region(acpi_status lookup_status,
91 union acpi_parse_object *op,
93 struct acpi_walk_state *walk_state,
94 struct acpi_namespace_node **node)
97 union acpi_operand_object *obj_desc;
99 if (lookup_status != AE_NOT_FOUND) {
100 return (lookup_status);
105 * operation_region not found. Generate an External for it, and
106 * insert the name into the namespace.
108 acpi_dm_add_op_to_external_list(op, path, ACPI_TYPE_REGION, 0, 0);
110 status = acpi_ns_lookup(walk_state->scope_info, path, ACPI_TYPE_REGION,
111 ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT,
113 if (ACPI_FAILURE(status)) {
117 /* Must create and install a region object for the new node */
119 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_REGION);
121 return (AE_NO_MEMORY);
124 obj_desc->region.node = *node;
125 status = acpi_ns_attach_object(*node, obj_desc, ACPI_TYPE_REGION);
130 /*******************************************************************************
132 * FUNCTION: acpi_ds_create_buffer_field
134 * PARAMETERS: op - Current parse op (create_XXField)
135 * walk_state - Current state
139 * DESCRIPTION: Execute the create_field operators:
140 * create_bit_field_op,
141 * create_byte_field_op,
142 * create_word_field_op,
143 * create_dword_field_op,
144 * create_qword_field_op,
145 * create_field_op (all of which define a field in a buffer)
147 ******************************************************************************/
150 acpi_ds_create_buffer_field(union acpi_parse_object *op,
151 struct acpi_walk_state *walk_state)
153 union acpi_parse_object *arg;
154 struct acpi_namespace_node *node;
156 union acpi_operand_object *obj_desc;
157 union acpi_operand_object *second_desc = NULL;
160 ACPI_FUNCTION_TRACE(ds_create_buffer_field);
163 * Get the name_string argument (name of the new buffer_field)
165 if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
167 /* For create_field, name is the 4th argument */
169 arg = acpi_ps_get_arg(op, 3);
171 /* For all other create_XXXField operators, name is the 3rd argument */
173 arg = acpi_ps_get_arg(op, 2);
177 return_ACPI_STATUS(AE_AML_NO_OPERAND);
180 if (walk_state->deferred_node) {
181 node = walk_state->deferred_node;
184 /* Execute flag should always be set when this function is entered */
186 if (!(walk_state->parse_flags & ACPI_PARSE_EXECUTE)) {
187 ACPI_ERROR((AE_INFO, "Parse execute mode is not set"));
188 return_ACPI_STATUS(AE_AML_INTERNAL);
191 /* Creating new namespace node, should not already exist */
193 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
194 ACPI_NS_ERROR_IF_FOUND;
197 * Mark node temporary if we are executing a normal control
198 * method. (Don't mark if this is a module-level code method)
200 if (walk_state->method_node &&
201 !(walk_state->parse_flags & ACPI_PARSE_MODULE_LEVEL)) {
202 flags |= ACPI_NS_TEMPORARY;
205 /* Enter the name_string into the namespace */
207 status = acpi_ns_lookup(walk_state->scope_info,
208 arg->common.value.string, ACPI_TYPE_ANY,
209 ACPI_IMODE_LOAD_PASS1, flags,
211 if (ACPI_FAILURE(status)) {
212 ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
213 return_ACPI_STATUS(status);
218 * We could put the returned object (Node) on the object stack for later,
219 * but for now, we will put it in the "op" object that the parser uses,
220 * so we can get it again at the end of this scope.
222 op->common.node = node;
225 * If there is no object attached to the node, this node was just created
226 * and we need to create the field object. Otherwise, this was a lookup
227 * of an existing node and we don't want to create the field object again.
229 obj_desc = acpi_ns_get_attached_object(node);
231 return_ACPI_STATUS(AE_OK);
235 * The Field definition is not fully parsed at this time.
236 * (We must save the address of the AML for the buffer and index operands)
239 /* Create the buffer field object */
241 obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER_FIELD);
243 status = AE_NO_MEMORY;
248 * Remember location in AML stream of the field unit opcode and operands
249 * -- since the buffer and index operands must be evaluated.
251 second_desc = obj_desc->common.next_object;
252 second_desc->extra.aml_start = op->named.data;
253 second_desc->extra.aml_length = op->named.length;
254 obj_desc->buffer_field.node = node;
256 /* Attach constructed field descriptors to parent node */
258 status = acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_BUFFER_FIELD);
259 if (ACPI_FAILURE(status)) {
265 /* Remove local reference to the object */
267 acpi_ut_remove_reference(obj_desc);
268 return_ACPI_STATUS(status);
271 /*******************************************************************************
273 * FUNCTION: acpi_ds_get_field_names
275 * PARAMETERS: info - create_field info structure
276 * walk_state - Current method state
277 * arg - First parser arg for the field name list
281 * DESCRIPTION: Process all named fields in a field declaration. Names are
282 * entered into the namespace.
284 ******************************************************************************/
287 acpi_ds_get_field_names(struct acpi_create_field_info *info,
288 struct acpi_walk_state *walk_state,
289 union acpi_parse_object *arg)
293 union acpi_parse_object *child;
295 ACPI_FUNCTION_TRACE_PTR(ds_get_field_names, info);
297 /* First field starts at bit zero */
299 info->field_bit_position = 0;
301 /* Process all elements in the field list (of parse nodes) */
305 * Four types of field elements are handled:
306 * 1) name - Enters a new named field into the namespace
307 * 2) offset - specifies a bit offset
308 * 3) access_as - changes the access mode/attributes
309 * 4) connection - Associate a resource template with the field
311 switch (arg->common.aml_opcode) {
312 case AML_INT_RESERVEDFIELD_OP:
314 position = (u64)info->field_bit_position +
315 (u64)arg->common.value.size;
317 if (position > ACPI_UINT32_MAX) {
319 "Bit offset within field too large (> 0xFFFFFFFF)"));
320 return_ACPI_STATUS(AE_SUPPORT);
323 info->field_bit_position = (u32) position;
326 case AML_INT_ACCESSFIELD_OP:
327 case AML_INT_EXTACCESSFIELD_OP:
329 * Get new access_type, access_attribute, and access_length fields
330 * -- to be used for all field units that follow, until the
331 * end-of-field or another access_as keyword is encountered.
332 * NOTE. These three bytes are encoded in the integer value
333 * of the parseop for convenience.
335 * In field_flags, preserve the flag bits other than the
339 /* access_type (byte_acc, word_acc, etc.) */
341 info->field_flags = (u8)
343 field_flags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
344 ((u8)((u32)(arg->common.value.integer & 0x07))));
346 /* access_attribute (attrib_quick, attrib_byte, etc.) */
348 info->attribute = (u8)
349 ((arg->common.value.integer >> 8) & 0xFF);
351 /* access_length (for serial/buffer protocols) */
353 info->access_length = (u8)
354 ((arg->common.value.integer >> 16) & 0xFF);
357 case AML_INT_CONNECTION_OP:
359 * Clear any previous connection. New connection is used for all
360 * fields that follow, similar to access_as
362 info->resource_buffer = NULL;
363 info->connection_node = NULL;
364 info->pin_number_index = 0;
367 * A Connection() is either an actual resource descriptor (buffer)
368 * or a named reference to a resource template
370 child = arg->common.value.arg;
371 if (child->common.aml_opcode == AML_INT_BYTELIST_OP) {
372 info->resource_buffer = child->named.data;
373 info->resource_length =
374 (u16)child->named.value.integer;
376 /* Lookup the Connection() namepath, it should already exist */
378 status = acpi_ns_lookup(walk_state->scope_info,
382 ACPI_NS_DONT_OPEN_SCOPE,
384 &info->connection_node);
385 if (ACPI_FAILURE(status)) {
386 ACPI_ERROR_NAMESPACE(child->common.
389 return_ACPI_STATUS(status);
394 case AML_INT_NAMEDFIELD_OP:
396 /* Lookup the name, it should already exist */
398 status = acpi_ns_lookup(walk_state->scope_info,
399 (char *)&arg->named.name,
402 ACPI_NS_DONT_OPEN_SCOPE,
403 walk_state, &info->field_node);
404 if (ACPI_FAILURE(status)) {
405 ACPI_ERROR_NAMESPACE((char *)&arg->named.name,
407 return_ACPI_STATUS(status);
409 arg->common.node = info->field_node;
410 info->field_bit_length = arg->common.value.size;
413 * If there is no object attached to the node, this node was
414 * just created and we need to create the field object.
415 * Otherwise, this was a lookup of an existing node and we
416 * don't want to create the field object again.
418 if (!acpi_ns_get_attached_object
419 (info->field_node)) {
420 status = acpi_ex_prep_field_value(info);
421 if (ACPI_FAILURE(status)) {
422 return_ACPI_STATUS(status);
427 /* Keep track of bit position for the next field */
429 position = (u64)info->field_bit_position +
430 (u64)arg->common.value.size;
432 if (position > ACPI_UINT32_MAX) {
434 "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)",
438 return_ACPI_STATUS(AE_SUPPORT);
441 info->field_bit_position += info->field_bit_length;
442 info->pin_number_index++; /* Index relative to previous Connection() */
448 "Invalid opcode in field list: 0x%X",
449 arg->common.aml_opcode));
450 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
453 arg = arg->common.next;
456 return_ACPI_STATUS(AE_OK);
459 /*******************************************************************************
461 * FUNCTION: acpi_ds_create_field
463 * PARAMETERS: op - Op containing the Field definition and args
464 * region_node - Object for the containing Operation Region
465 * ` walk_state - Current method state
469 * DESCRIPTION: Create a new field in the specified operation region
471 ******************************************************************************/
474 acpi_ds_create_field(union acpi_parse_object *op,
475 struct acpi_namespace_node *region_node,
476 struct acpi_walk_state *walk_state)
479 union acpi_parse_object *arg;
480 struct acpi_create_field_info info;
482 ACPI_FUNCTION_TRACE_PTR(ds_create_field, op);
484 /* First arg is the name of the parent op_region (must already exist) */
486 arg = op->common.value.arg;
490 acpi_ns_lookup(walk_state->scope_info,
491 arg->common.value.name, ACPI_TYPE_REGION,
492 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
493 walk_state, ®ion_node);
494 #ifdef ACPI_ASL_COMPILER
495 status = acpi_ds_create_external_region(status, arg,
496 arg->common.value.name,
500 if (ACPI_FAILURE(status)) {
501 ACPI_ERROR_NAMESPACE(arg->common.value.name, status);
502 return_ACPI_STATUS(status);
506 memset(&info, 0, sizeof(struct acpi_create_field_info));
508 /* Second arg is the field flags */
510 arg = arg->common.next;
511 info.field_flags = (u8) arg->common.value.integer;
514 /* Each remaining arg is a Named Field */
516 info.field_type = ACPI_TYPE_LOCAL_REGION_FIELD;
517 info.region_node = region_node;
519 status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
520 return_ACPI_STATUS(status);
523 /*******************************************************************************
525 * FUNCTION: acpi_ds_init_field_objects
527 * PARAMETERS: op - Op containing the Field definition and args
528 * ` walk_state - Current method state
532 * DESCRIPTION: For each "Field Unit" name in the argument list that is
533 * part of the field declaration, enter the name into the
536 ******************************************************************************/
539 acpi_ds_init_field_objects(union acpi_parse_object *op,
540 struct acpi_walk_state *walk_state)
543 union acpi_parse_object *arg = NULL;
544 struct acpi_namespace_node *node;
548 ACPI_FUNCTION_TRACE_PTR(ds_init_field_objects, op);
550 /* Execute flag should always be set when this function is entered */
552 if (!(walk_state->parse_flags & ACPI_PARSE_EXECUTE)) {
553 if (walk_state->parse_flags & ACPI_PARSE_DEFERRED_OP) {
555 /* bank_field Op is deferred, just return OK */
557 return_ACPI_STATUS(AE_OK);
560 ACPI_ERROR((AE_INFO, "Parse deferred mode is not set"));
561 return_ACPI_STATUS(AE_AML_INTERNAL);
565 * Get the field_list argument for this opcode. This is the start of the
566 * list of field elements.
568 switch (walk_state->opcode) {
571 arg = acpi_ps_get_arg(op, 2);
572 type = ACPI_TYPE_LOCAL_REGION_FIELD;
575 case AML_BANK_FIELD_OP:
577 arg = acpi_ps_get_arg(op, 4);
578 type = ACPI_TYPE_LOCAL_BANK_FIELD;
581 case AML_INDEX_FIELD_OP:
583 arg = acpi_ps_get_arg(op, 3);
584 type = ACPI_TYPE_LOCAL_INDEX_FIELD;
589 return_ACPI_STATUS(AE_BAD_PARAMETER);
592 /* Creating new namespace node(s), should not already exist */
594 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
595 ACPI_NS_ERROR_IF_FOUND;
598 * Mark node(s) temporary if we are executing a normal control
599 * method. (Don't mark if this is a module-level code method)
601 if (walk_state->method_node &&
602 !(walk_state->parse_flags & ACPI_PARSE_MODULE_LEVEL)) {
603 flags |= ACPI_NS_TEMPORARY;
607 * Walk the list of entries in the field_list
608 * Note: field_list can be of zero length. In this case, Arg will be NULL.
612 * Ignore OFFSET/ACCESSAS/CONNECTION terms here; we are only interested
613 * in the field names in order to enter them into the namespace.
615 if (arg->common.aml_opcode == AML_INT_NAMEDFIELD_OP) {
616 status = acpi_ns_lookup(walk_state->scope_info,
617 (char *)&arg->named.name, type,
618 ACPI_IMODE_LOAD_PASS1, flags,
620 if (ACPI_FAILURE(status)) {
621 ACPI_ERROR_NAMESPACE((char *)&arg->named.name,
623 if (status != AE_ALREADY_EXISTS) {
624 return_ACPI_STATUS(status);
627 /* Name already exists, just ignore this error */
632 arg->common.node = node;
635 /* Get the next field element in the list */
637 arg = arg->common.next;
640 return_ACPI_STATUS(AE_OK);
643 /*******************************************************************************
645 * FUNCTION: acpi_ds_create_bank_field
647 * PARAMETERS: op - Op containing the Field definition and args
648 * region_node - Object for the containing Operation Region
649 * walk_state - Current method state
653 * DESCRIPTION: Create a new bank field in the specified operation region
655 ******************************************************************************/
658 acpi_ds_create_bank_field(union acpi_parse_object *op,
659 struct acpi_namespace_node *region_node,
660 struct acpi_walk_state *walk_state)
663 union acpi_parse_object *arg;
664 struct acpi_create_field_info info;
666 ACPI_FUNCTION_TRACE_PTR(ds_create_bank_field, op);
668 /* First arg is the name of the parent op_region (must already exist) */
670 arg = op->common.value.arg;
673 acpi_ns_lookup(walk_state->scope_info,
674 arg->common.value.name, ACPI_TYPE_REGION,
675 ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT,
676 walk_state, ®ion_node);
677 #ifdef ACPI_ASL_COMPILER
678 status = acpi_ds_create_external_region(status, arg,
679 arg->common.value.name,
683 if (ACPI_FAILURE(status)) {
684 ACPI_ERROR_NAMESPACE(arg->common.value.name, status);
685 return_ACPI_STATUS(status);
689 /* Second arg is the Bank Register (Field) (must already exist) */
691 arg = arg->common.next;
693 acpi_ns_lookup(walk_state->scope_info, arg->common.value.string,
694 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
695 ACPI_NS_SEARCH_PARENT, walk_state,
696 &info.register_node);
697 if (ACPI_FAILURE(status)) {
698 ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
699 return_ACPI_STATUS(status);
703 * Third arg is the bank_value
704 * This arg is a term_arg, not a constant
705 * It will be evaluated later, by acpi_ds_eval_bank_field_operands
707 arg = arg->common.next;
709 /* Fourth arg is the field flags */
711 arg = arg->common.next;
712 info.field_flags = (u8) arg->common.value.integer;
714 /* Each remaining arg is a Named Field */
716 info.field_type = ACPI_TYPE_LOCAL_BANK_FIELD;
717 info.region_node = region_node;
720 * Use Info.data_register_node to store bank_field Op
721 * It's safe because data_register_node will never be used when create
722 * bank field \we store aml_start and aml_length in the bank_field Op for
723 * late evaluation. Used in acpi_ex_prep_field_value(Info)
725 * TBD: Or, should we add a field in struct acpi_create_field_info, like
728 info.data_register_node = (struct acpi_namespace_node *)op;
730 status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
731 return_ACPI_STATUS(status);
734 /*******************************************************************************
736 * FUNCTION: acpi_ds_create_index_field
738 * PARAMETERS: op - Op containing the Field definition and args
739 * region_node - Object for the containing Operation Region
740 * ` walk_state - Current method state
744 * DESCRIPTION: Create a new index field in the specified operation region
746 ******************************************************************************/
749 acpi_ds_create_index_field(union acpi_parse_object *op,
750 struct acpi_namespace_node *region_node,
751 struct acpi_walk_state *walk_state)
754 union acpi_parse_object *arg;
755 struct acpi_create_field_info info;
757 ACPI_FUNCTION_TRACE_PTR(ds_create_index_field, op);
759 /* First arg is the name of the Index register (must already exist) */
761 arg = op->common.value.arg;
763 acpi_ns_lookup(walk_state->scope_info, arg->common.value.string,
764 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
765 ACPI_NS_SEARCH_PARENT, walk_state,
766 &info.register_node);
767 if (ACPI_FAILURE(status)) {
768 ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
769 return_ACPI_STATUS(status);
772 /* Second arg is the data register (must already exist) */
774 arg = arg->common.next;
776 acpi_ns_lookup(walk_state->scope_info, arg->common.value.string,
777 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
778 ACPI_NS_SEARCH_PARENT, walk_state,
779 &info.data_register_node);
780 if (ACPI_FAILURE(status)) {
781 ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
782 return_ACPI_STATUS(status);
785 /* Next arg is the field flags */
787 arg = arg->common.next;
788 info.field_flags = (u8) arg->common.value.integer;
790 /* Each remaining arg is a Named Field */
792 info.field_type = ACPI_TYPE_LOCAL_INDEX_FIELD;
793 info.region_node = region_node;
795 status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
796 return_ACPI_STATUS(status);