Merge remote-tracking branches 'asoc/fix/rt5514', 'asoc/fix/rt5616', 'asoc/fix/rt5659...
[sfrench/cifs-2.6.git] / drivers / acpi / acpica / dsfield.c
1 /******************************************************************************
2  *
3  * Module Name: dsfield - Dispatcher field routines
4  *
5  *****************************************************************************/
6
7 /*
8  * Copyright (C) 2000 - 2017, Intel Corp.
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
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.
25  *
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.
29  *
30  * NO WARRANTY
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.
42  */
43
44 #include <acpi/acpi.h>
45 #include "accommon.h"
46 #include "amlcode.h"
47 #include "acdispat.h"
48 #include "acinterp.h"
49 #include "acnamesp.h"
50 #include "acparser.h"
51
52 #define _COMPONENT          ACPI_DISPATCHER
53 ACPI_MODULE_NAME("dsfield")
54
55 /* Local prototypes */
56 #ifdef ACPI_ASL_COMPILER
57 #include "acdisasm.h"
58 static acpi_status
59 acpi_ds_create_external_region(acpi_status lookup_status,
60                                union acpi_parse_object *op,
61                                char *path,
62                                struct acpi_walk_state *walk_state,
63                                struct acpi_namespace_node **node);
64 #endif
65
66 static acpi_status
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);
70
71 #ifdef ACPI_ASL_COMPILER
72 /*******************************************************************************
73  *
74  * FUNCTION:    acpi_ds_create_external_region (iASL Disassembler only)
75  *
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
81  *
82  * RETURN:      Status
83  *
84  * DESCRIPTION: Add region to the external list if NOT_FOUND. Create a new
85  *              region node/object.
86  *
87  ******************************************************************************/
88
89 static acpi_status
90 acpi_ds_create_external_region(acpi_status lookup_status,
91                                union acpi_parse_object *op,
92                                char *path,
93                                struct acpi_walk_state *walk_state,
94                                struct acpi_namespace_node **node)
95 {
96         acpi_status status;
97         union acpi_operand_object *obj_desc;
98
99         if (lookup_status != AE_NOT_FOUND) {
100                 return (lookup_status);
101         }
102
103         /*
104          * Table disassembly:
105          * operation_region not found. Generate an External for it, and
106          * insert the name into the namespace.
107          */
108         acpi_dm_add_op_to_external_list(op, path, ACPI_TYPE_REGION, 0, 0);
109
110         status = acpi_ns_lookup(walk_state->scope_info, path, ACPI_TYPE_REGION,
111                                 ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT,
112                                 walk_state, node);
113         if (ACPI_FAILURE(status)) {
114                 return (status);
115         }
116
117         /* Must create and install a region object for the new node */
118
119         obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_REGION);
120         if (!obj_desc) {
121                 return (AE_NO_MEMORY);
122         }
123
124         obj_desc->region.node = *node;
125         status = acpi_ns_attach_object(*node, obj_desc, ACPI_TYPE_REGION);
126         return (status);
127 }
128 #endif
129
130 /*******************************************************************************
131  *
132  * FUNCTION:    acpi_ds_create_buffer_field
133  *
134  * PARAMETERS:  op                  - Current parse op (create_XXField)
135  *              walk_state          - Current state
136  *
137  * RETURN:      Status
138  *
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)
146  *
147  ******************************************************************************/
148
149 acpi_status
150 acpi_ds_create_buffer_field(union acpi_parse_object *op,
151                             struct acpi_walk_state *walk_state)
152 {
153         union acpi_parse_object *arg;
154         struct acpi_namespace_node *node;
155         acpi_status status;
156         union acpi_operand_object *obj_desc;
157         union acpi_operand_object *second_desc = NULL;
158         u32 flags;
159
160         ACPI_FUNCTION_TRACE(ds_create_buffer_field);
161
162         /*
163          * Get the name_string argument (name of the new buffer_field)
164          */
165         if (op->common.aml_opcode == AML_CREATE_FIELD_OP) {
166
167                 /* For create_field, name is the 4th argument */
168
169                 arg = acpi_ps_get_arg(op, 3);
170         } else {
171                 /* For all other create_XXXField operators, name is the 3rd argument */
172
173                 arg = acpi_ps_get_arg(op, 2);
174         }
175
176         if (!arg) {
177                 return_ACPI_STATUS(AE_AML_NO_OPERAND);
178         }
179
180         if (walk_state->deferred_node) {
181                 node = walk_state->deferred_node;
182                 status = AE_OK;
183         } else {
184                 /* Execute flag should always be set when this function is entered */
185
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);
189                 }
190
191                 /* Creating new namespace node, should not already exist */
192
193                 flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
194                     ACPI_NS_ERROR_IF_FOUND;
195
196                 /*
197                  * Mark node temporary if we are executing a normal control
198                  * method. (Don't mark if this is a module-level code method)
199                  */
200                 if (walk_state->method_node &&
201                     !(walk_state->parse_flags & ACPI_PARSE_MODULE_LEVEL)) {
202                         flags |= ACPI_NS_TEMPORARY;
203                 }
204
205                 /* Enter the name_string into the namespace */
206
207                 status = acpi_ns_lookup(walk_state->scope_info,
208                                         arg->common.value.string, ACPI_TYPE_ANY,
209                                         ACPI_IMODE_LOAD_PASS1, flags,
210                                         walk_state, &node);
211                 if (ACPI_FAILURE(status)) {
212                         ACPI_ERROR_NAMESPACE(arg->common.value.string, status);
213                         return_ACPI_STATUS(status);
214                 }
215         }
216
217         /*
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.
221          */
222         op->common.node = node;
223
224         /*
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.
228          */
229         obj_desc = acpi_ns_get_attached_object(node);
230         if (obj_desc) {
231                 return_ACPI_STATUS(AE_OK);
232         }
233
234         /*
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)
237          */
238
239         /* Create the buffer field object */
240
241         obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER_FIELD);
242         if (!obj_desc) {
243                 status = AE_NO_MEMORY;
244                 goto cleanup;
245         }
246
247         /*
248          * Remember location in AML stream of the field unit opcode and operands
249          * -- since the buffer and index operands must be evaluated.
250          */
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;
255
256         /* Attach constructed field descriptors to parent node */
257
258         status = acpi_ns_attach_object(node, obj_desc, ACPI_TYPE_BUFFER_FIELD);
259         if (ACPI_FAILURE(status)) {
260                 goto cleanup;
261         }
262
263 cleanup:
264
265         /* Remove local reference to the object */
266
267         acpi_ut_remove_reference(obj_desc);
268         return_ACPI_STATUS(status);
269 }
270
271 /*******************************************************************************
272  *
273  * FUNCTION:    acpi_ds_get_field_names
274  *
275  * PARAMETERS:  info            - create_field info structure
276  *  `           walk_state      - Current method state
277  *              arg             - First parser arg for the field name list
278  *
279  * RETURN:      Status
280  *
281  * DESCRIPTION: Process all named fields in a field declaration. Names are
282  *              entered into the namespace.
283  *
284  ******************************************************************************/
285
286 static acpi_status
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)
290 {
291         acpi_status status;
292         u64 position;
293         union acpi_parse_object *child;
294
295         ACPI_FUNCTION_TRACE_PTR(ds_get_field_names, info);
296
297         /* First field starts at bit zero */
298
299         info->field_bit_position = 0;
300
301         /* Process all elements in the field list (of parse nodes) */
302
303         while (arg) {
304                 /*
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
310                  */
311                 switch (arg->common.aml_opcode) {
312                 case AML_INT_RESERVEDFIELD_OP:
313
314                         position = (u64)info->field_bit_position +
315                             (u64)arg->common.value.size;
316
317                         if (position > ACPI_UINT32_MAX) {
318                                 ACPI_ERROR((AE_INFO,
319                                             "Bit offset within field too large (> 0xFFFFFFFF)"));
320                                 return_ACPI_STATUS(AE_SUPPORT);
321                         }
322
323                         info->field_bit_position = (u32) position;
324                         break;
325
326                 case AML_INT_ACCESSFIELD_OP:
327                 case AML_INT_EXTACCESSFIELD_OP:
328                         /*
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.
334                          *
335                          * In field_flags, preserve the flag bits other than the
336                          * ACCESS_TYPE bits.
337                          */
338
339                         /* access_type (byte_acc, word_acc, etc.) */
340
341                         info->field_flags = (u8)
342                             ((info->
343                               field_flags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
344                              ((u8)((u32)(arg->common.value.integer & 0x07))));
345
346                         /* access_attribute (attrib_quick, attrib_byte, etc.) */
347
348                         info->attribute = (u8)
349                             ((arg->common.value.integer >> 8) & 0xFF);
350
351                         /* access_length (for serial/buffer protocols) */
352
353                         info->access_length = (u8)
354                             ((arg->common.value.integer >> 16) & 0xFF);
355                         break;
356
357                 case AML_INT_CONNECTION_OP:
358                         /*
359                          * Clear any previous connection. New connection is used for all
360                          * fields that follow, similar to access_as
361                          */
362                         info->resource_buffer = NULL;
363                         info->connection_node = NULL;
364                         info->pin_number_index = 0;
365
366                         /*
367                          * A Connection() is either an actual resource descriptor (buffer)
368                          * or a named reference to a resource template
369                          */
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;
375                         } else {
376                                 /* Lookup the Connection() namepath, it should already exist */
377
378                                 status = acpi_ns_lookup(walk_state->scope_info,
379                                                         child->common.value.
380                                                         name, ACPI_TYPE_ANY,
381                                                         ACPI_IMODE_EXECUTE,
382                                                         ACPI_NS_DONT_OPEN_SCOPE,
383                                                         walk_state,
384                                                         &info->connection_node);
385                                 if (ACPI_FAILURE(status)) {
386                                         ACPI_ERROR_NAMESPACE(child->common.
387                                                              value.name,
388                                                              status);
389                                         return_ACPI_STATUS(status);
390                                 }
391                         }
392                         break;
393
394                 case AML_INT_NAMEDFIELD_OP:
395
396                         /* Lookup the name, it should already exist */
397
398                         status = acpi_ns_lookup(walk_state->scope_info,
399                                                 (char *)&arg->named.name,
400                                                 info->field_type,
401                                                 ACPI_IMODE_EXECUTE,
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,
406                                                      status);
407                                 return_ACPI_STATUS(status);
408                         } else {
409                                 arg->common.node = info->field_node;
410                                 info->field_bit_length = arg->common.value.size;
411
412                                 /*
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.
417                                  */
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);
423                                         }
424                                 }
425                         }
426
427                         /* Keep track of bit position for the next field */
428
429                         position = (u64)info->field_bit_position +
430                             (u64)arg->common.value.size;
431
432                         if (position > ACPI_UINT32_MAX) {
433                                 ACPI_ERROR((AE_INFO,
434                                             "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)",
435                                             ACPI_CAST_PTR(char,
436                                                           &info->field_node->
437                                                           name)));
438                                 return_ACPI_STATUS(AE_SUPPORT);
439                         }
440
441                         info->field_bit_position += info->field_bit_length;
442                         info->pin_number_index++;       /* Index relative to previous Connection() */
443                         break;
444
445                 default:
446
447                         ACPI_ERROR((AE_INFO,
448                                     "Invalid opcode in field list: 0x%X",
449                                     arg->common.aml_opcode));
450                         return_ACPI_STATUS(AE_AML_BAD_OPCODE);
451                 }
452
453                 arg = arg->common.next;
454         }
455
456         return_ACPI_STATUS(AE_OK);
457 }
458
459 /*******************************************************************************
460  *
461  * FUNCTION:    acpi_ds_create_field
462  *
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
466  *
467  * RETURN:      Status
468  *
469  * DESCRIPTION: Create a new field in the specified operation region
470  *
471  ******************************************************************************/
472
473 acpi_status
474 acpi_ds_create_field(union acpi_parse_object *op,
475                      struct acpi_namespace_node *region_node,
476                      struct acpi_walk_state *walk_state)
477 {
478         acpi_status status;
479         union acpi_parse_object *arg;
480         struct acpi_create_field_info info;
481
482         ACPI_FUNCTION_TRACE_PTR(ds_create_field, op);
483
484         /* First arg is the name of the parent op_region (must already exist) */
485
486         arg = op->common.value.arg;
487
488         if (!region_node) {
489                 status =
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, &region_node);
494 #ifdef ACPI_ASL_COMPILER
495                 status = acpi_ds_create_external_region(status, arg,
496                                                         arg->common.value.name,
497                                                         walk_state,
498                                                         &region_node);
499 #endif
500                 if (ACPI_FAILURE(status)) {
501                         ACPI_ERROR_NAMESPACE(arg->common.value.name, status);
502                         return_ACPI_STATUS(status);
503                 }
504         }
505
506         memset(&info, 0, sizeof(struct acpi_create_field_info));
507
508         /* Second arg is the field flags */
509
510         arg = arg->common.next;
511         info.field_flags = (u8) arg->common.value.integer;
512         info.attribute = 0;
513
514         /* Each remaining arg is a Named Field */
515
516         info.field_type = ACPI_TYPE_LOCAL_REGION_FIELD;
517         info.region_node = region_node;
518
519         status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
520         return_ACPI_STATUS(status);
521 }
522
523 /*******************************************************************************
524  *
525  * FUNCTION:    acpi_ds_init_field_objects
526  *
527  * PARAMETERS:  op              - Op containing the Field definition and args
528  *  `           walk_state      - Current method state
529  *
530  * RETURN:      Status
531  *
532  * DESCRIPTION: For each "Field Unit" name in the argument list that is
533  *              part of the field declaration, enter the name into the
534  *              namespace.
535  *
536  ******************************************************************************/
537
538 acpi_status
539 acpi_ds_init_field_objects(union acpi_parse_object *op,
540                            struct acpi_walk_state *walk_state)
541 {
542         acpi_status status;
543         union acpi_parse_object *arg = NULL;
544         struct acpi_namespace_node *node;
545         u8 type = 0;
546         u32 flags;
547
548         ACPI_FUNCTION_TRACE_PTR(ds_init_field_objects, op);
549
550         /* Execute flag should always be set when this function is entered */
551
552         if (!(walk_state->parse_flags & ACPI_PARSE_EXECUTE)) {
553                 if (walk_state->parse_flags & ACPI_PARSE_DEFERRED_OP) {
554
555                         /* bank_field Op is deferred, just return OK */
556
557                         return_ACPI_STATUS(AE_OK);
558                 }
559
560                 ACPI_ERROR((AE_INFO, "Parse deferred mode is not set"));
561                 return_ACPI_STATUS(AE_AML_INTERNAL);
562         }
563
564         /*
565          * Get the field_list argument for this opcode. This is the start of the
566          * list of field elements.
567          */
568         switch (walk_state->opcode) {
569         case AML_FIELD_OP:
570
571                 arg = acpi_ps_get_arg(op, 2);
572                 type = ACPI_TYPE_LOCAL_REGION_FIELD;
573                 break;
574
575         case AML_BANK_FIELD_OP:
576
577                 arg = acpi_ps_get_arg(op, 4);
578                 type = ACPI_TYPE_LOCAL_BANK_FIELD;
579                 break;
580
581         case AML_INDEX_FIELD_OP:
582
583                 arg = acpi_ps_get_arg(op, 3);
584                 type = ACPI_TYPE_LOCAL_INDEX_FIELD;
585                 break;
586
587         default:
588
589                 return_ACPI_STATUS(AE_BAD_PARAMETER);
590         }
591
592         /* Creating new namespace node(s), should not already exist */
593
594         flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
595             ACPI_NS_ERROR_IF_FOUND;
596
597         /*
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)
600          */
601         if (walk_state->method_node &&
602             !(walk_state->parse_flags & ACPI_PARSE_MODULE_LEVEL)) {
603                 flags |= ACPI_NS_TEMPORARY;
604         }
605
606         /*
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.
609          */
610         while (arg) {
611                 /*
612                  * Ignore OFFSET/ACCESSAS/CONNECTION terms here; we are only interested
613                  * in the field names in order to enter them into the namespace.
614                  */
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,
619                                                 walk_state, &node);
620                         if (ACPI_FAILURE(status)) {
621                                 ACPI_ERROR_NAMESPACE((char *)&arg->named.name,
622                                                      status);
623                                 if (status != AE_ALREADY_EXISTS) {
624                                         return_ACPI_STATUS(status);
625                                 }
626
627                                 /* Name already exists, just ignore this error */
628
629                                 status = AE_OK;
630                         }
631
632                         arg->common.node = node;
633                 }
634
635                 /* Get the next field element in the list */
636
637                 arg = arg->common.next;
638         }
639
640         return_ACPI_STATUS(AE_OK);
641 }
642
643 /*******************************************************************************
644  *
645  * FUNCTION:    acpi_ds_create_bank_field
646  *
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
650  *
651  * RETURN:      Status
652  *
653  * DESCRIPTION: Create a new bank field in the specified operation region
654  *
655  ******************************************************************************/
656
657 acpi_status
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)
661 {
662         acpi_status status;
663         union acpi_parse_object *arg;
664         struct acpi_create_field_info info;
665
666         ACPI_FUNCTION_TRACE_PTR(ds_create_bank_field, op);
667
668         /* First arg is the name of the parent op_region (must already exist) */
669
670         arg = op->common.value.arg;
671         if (!region_node) {
672                 status =
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, &region_node);
677 #ifdef ACPI_ASL_COMPILER
678                 status = acpi_ds_create_external_region(status, arg,
679                                                         arg->common.value.name,
680                                                         walk_state,
681                                                         &region_node);
682 #endif
683                 if (ACPI_FAILURE(status)) {
684                         ACPI_ERROR_NAMESPACE(arg->common.value.name, status);
685                         return_ACPI_STATUS(status);
686                 }
687         }
688
689         /* Second arg is the Bank Register (Field) (must already exist) */
690
691         arg = arg->common.next;
692         status =
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);
700         }
701
702         /*
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
706          */
707         arg = arg->common.next;
708
709         /* Fourth arg is the field flags */
710
711         arg = arg->common.next;
712         info.field_flags = (u8) arg->common.value.integer;
713
714         /* Each remaining arg is a Named Field */
715
716         info.field_type = ACPI_TYPE_LOCAL_BANK_FIELD;
717         info.region_node = region_node;
718
719         /*
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)
724          *
725          * TBD: Or, should we add a field in struct acpi_create_field_info, like
726          * "void *ParentOp"?
727          */
728         info.data_register_node = (struct acpi_namespace_node *)op;
729
730         status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
731         return_ACPI_STATUS(status);
732 }
733
734 /*******************************************************************************
735  *
736  * FUNCTION:    acpi_ds_create_index_field
737  *
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
741  *
742  * RETURN:      Status
743  *
744  * DESCRIPTION: Create a new index field in the specified operation region
745  *
746  ******************************************************************************/
747
748 acpi_status
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)
752 {
753         acpi_status status;
754         union acpi_parse_object *arg;
755         struct acpi_create_field_info info;
756
757         ACPI_FUNCTION_TRACE_PTR(ds_create_index_field, op);
758
759         /* First arg is the name of the Index register (must already exist) */
760
761         arg = op->common.value.arg;
762         status =
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);
770         }
771
772         /* Second arg is the data register (must already exist) */
773
774         arg = arg->common.next;
775         status =
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);
783         }
784
785         /* Next arg is the field flags */
786
787         arg = arg->common.next;
788         info.field_flags = (u8) arg->common.value.integer;
789
790         /* Each remaining arg is a Named Field */
791
792         info.field_type = ACPI_TYPE_LOCAL_INDEX_FIELD;
793         info.region_node = region_node;
794
795         status = acpi_ds_get_field_names(&info, walk_state, arg->common.next);
796         return_ACPI_STATUS(status);
797 }