[ACPICA]
[reactos.git] / reactos / drivers / bus / acpi / acpica / dispatcher / dsfield.c
1 /******************************************************************************
2 *
3 * Module Name: dsfield - Dispatcher field routines
4 *
5 *****************************************************************************/
6
7 /******************************************************************************
8 *
9 * 1. Copyright Notice
10 *
11 * Some or all of this work - Copyright (c) 1999 - 2015, Intel Corp.
12 * All rights reserved.
13 *
14 * 2. License
15 *
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
20 *
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
27 *
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
36 *
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
39 *
40 * 3. Conditions
41 *
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
53 *
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
65 *
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
71 *
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
74 *
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
79 *
80 * 4. Disclaimer and Export Compliance
81 *
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
89 *
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
98 *
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
113 *
114 *****************************************************************************/
115
116 #include "acpi.h"
117 #include "accommon.h"
118 #include "amlcode.h"
119 #include "acdispat.h"
120 #include "acinterp.h"
121 #include "acnamesp.h"
122 #include "acparser.h"
123
124
125 #define _COMPONENT ACPI_DISPATCHER
126 ACPI_MODULE_NAME ("dsfield")
127
128 /* Local prototypes */
129
130 #ifdef ACPI_ASL_COMPILER
131 #include "acdisasm.h"
132
133 static ACPI_STATUS
134 AcpiDsCreateExternalRegion (
135 ACPI_STATUS LookupStatus,
136 ACPI_PARSE_OBJECT *Op,
137 char *Path,
138 ACPI_WALK_STATE *WalkState,
139 ACPI_NAMESPACE_NODE **Node);
140 #endif
141
142 static ACPI_STATUS
143 AcpiDsGetFieldNames (
144 ACPI_CREATE_FIELD_INFO *Info,
145 ACPI_WALK_STATE *WalkState,
146 ACPI_PARSE_OBJECT *Arg);
147
148
149 #ifdef ACPI_ASL_COMPILER
150 /*******************************************************************************
151 *
152 * FUNCTION: AcpiDsCreateExternalRegion (iASL Disassembler only)
153 *
154 * PARAMETERS: LookupStatus - Status from NsLookup operation
155 * Op - Op containing the Field definition and args
156 * Path - Pathname of the region
157 * ` WalkState - Current method state
158 * Node - Where the new region node is returned
159 *
160 * RETURN: Status
161 *
162 * DESCRIPTION: Add region to the external list if NOT_FOUND. Create a new
163 * region node/object.
164 *
165 ******************************************************************************/
166
167 static ACPI_STATUS
168 AcpiDsCreateExternalRegion (
169 ACPI_STATUS LookupStatus,
170 ACPI_PARSE_OBJECT *Op,
171 char *Path,
172 ACPI_WALK_STATE *WalkState,
173 ACPI_NAMESPACE_NODE **Node)
174 {
175 ACPI_STATUS Status;
176 ACPI_OPERAND_OBJECT *ObjDesc;
177
178
179 if (LookupStatus != AE_NOT_FOUND)
180 {
181 return (LookupStatus);
182 }
183
184 /*
185 * Table disassembly:
186 * OperationRegion not found. Generate an External for it, and
187 * insert the name into the namespace.
188 */
189 AcpiDmAddOpToExternalList (Op, Path, ACPI_TYPE_REGION, 0, 0);
190
191 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_REGION,
192 ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT, WalkState, Node);
193 if (ACPI_FAILURE (Status))
194 {
195 return (Status);
196 }
197
198 /* Must create and install a region object for the new node */
199
200 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_REGION);
201 if (!ObjDesc)
202 {
203 return (AE_NO_MEMORY);
204 }
205
206 ObjDesc->Region.Node = *Node;
207 Status = AcpiNsAttachObject (*Node, ObjDesc, ACPI_TYPE_REGION);
208 return (Status);
209 }
210 #endif
211
212
213 /*******************************************************************************
214 *
215 * FUNCTION: AcpiDsCreateBufferField
216 *
217 * PARAMETERS: Op - Current parse op (CreateXXField)
218 * WalkState - Current state
219 *
220 * RETURN: Status
221 *
222 * DESCRIPTION: Execute the CreateField operators:
223 * CreateBitFieldOp,
224 * CreateByteFieldOp,
225 * CreateWordFieldOp,
226 * CreateDwordFieldOp,
227 * CreateQwordFieldOp,
228 * CreateFieldOp (all of which define a field in a buffer)
229 *
230 ******************************************************************************/
231
232 ACPI_STATUS
233 AcpiDsCreateBufferField (
234 ACPI_PARSE_OBJECT *Op,
235 ACPI_WALK_STATE *WalkState)
236 {
237 ACPI_PARSE_OBJECT *Arg;
238 ACPI_NAMESPACE_NODE *Node;
239 ACPI_STATUS Status;
240 ACPI_OPERAND_OBJECT *ObjDesc;
241 ACPI_OPERAND_OBJECT *SecondDesc = NULL;
242 UINT32 Flags;
243
244
245 ACPI_FUNCTION_TRACE (DsCreateBufferField);
246
247
248 /*
249 * Get the NameString argument (name of the new BufferField)
250 */
251 if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)
252 {
253 /* For CreateField, name is the 4th argument */
254
255 Arg = AcpiPsGetArg (Op, 3);
256 }
257 else
258 {
259 /* For all other CreateXXXField operators, name is the 3rd argument */
260
261 Arg = AcpiPsGetArg (Op, 2);
262 }
263
264 if (!Arg)
265 {
266 return_ACPI_STATUS (AE_AML_NO_OPERAND);
267 }
268
269 if (WalkState->DeferredNode)
270 {
271 Node = WalkState->DeferredNode;
272 Status = AE_OK;
273 }
274 else
275 {
276 /* Execute flag should always be set when this function is entered */
277
278 if (!(WalkState->ParseFlags & ACPI_PARSE_EXECUTE))
279 {
280 return_ACPI_STATUS (AE_AML_INTERNAL);
281 }
282
283 /* Creating new namespace node, should not already exist */
284
285 Flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
286 ACPI_NS_ERROR_IF_FOUND;
287
288 /*
289 * Mark node temporary if we are executing a normal control
290 * method. (Don't mark if this is a module-level code method)
291 */
292 if (WalkState->MethodNode &&
293 !(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
294 {
295 Flags |= ACPI_NS_TEMPORARY;
296 }
297
298 /* Enter the NameString into the namespace */
299
300 Status = AcpiNsLookup (WalkState->ScopeInfo,
301 Arg->Common.Value.String, ACPI_TYPE_ANY,
302 ACPI_IMODE_LOAD_PASS1, Flags, WalkState, &Node);
303 if (ACPI_FAILURE (Status))
304 {
305 ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
306 return_ACPI_STATUS (Status);
307 }
308 }
309
310 /*
311 * We could put the returned object (Node) on the object stack for later,
312 * but for now, we will put it in the "op" object that the parser uses,
313 * so we can get it again at the end of this scope.
314 */
315 Op->Common.Node = Node;
316
317 /*
318 * If there is no object attached to the node, this node was just created
319 * and we need to create the field object. Otherwise, this was a lookup
320 * of an existing node and we don't want to create the field object again.
321 */
322 ObjDesc = AcpiNsGetAttachedObject (Node);
323 if (ObjDesc)
324 {
325 return_ACPI_STATUS (AE_OK);
326 }
327
328 /*
329 * The Field definition is not fully parsed at this time.
330 * (We must save the address of the AML for the buffer and index operands)
331 */
332
333 /* Create the buffer field object */
334
335 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER_FIELD);
336 if (!ObjDesc)
337 {
338 Status = AE_NO_MEMORY;
339 goto Cleanup;
340 }
341
342 /*
343 * Remember location in AML stream of the field unit opcode and operands
344 * -- since the buffer and index operands must be evaluated.
345 */
346 SecondDesc = ObjDesc->Common.NextObject;
347 SecondDesc->Extra.AmlStart = Op->Named.Data;
348 SecondDesc->Extra.AmlLength = Op->Named.Length;
349 ObjDesc->BufferField.Node = Node;
350
351 /* Attach constructed field descriptors to parent node */
352
353 Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_BUFFER_FIELD);
354 if (ACPI_FAILURE (Status))
355 {
356 goto Cleanup;
357 }
358
359
360 Cleanup:
361
362 /* Remove local reference to the object */
363
364 AcpiUtRemoveReference (ObjDesc);
365 return_ACPI_STATUS (Status);
366 }
367
368
369 /*******************************************************************************
370 *
371 * FUNCTION: AcpiDsGetFieldNames
372 *
373 * PARAMETERS: Info - CreateField info structure
374 * ` WalkState - Current method state
375 * Arg - First parser arg for the field name list
376 *
377 * RETURN: Status
378 *
379 * DESCRIPTION: Process all named fields in a field declaration. Names are
380 * entered into the namespace.
381 *
382 ******************************************************************************/
383
384 static ACPI_STATUS
385 AcpiDsGetFieldNames (
386 ACPI_CREATE_FIELD_INFO *Info,
387 ACPI_WALK_STATE *WalkState,
388 ACPI_PARSE_OBJECT *Arg)
389 {
390 ACPI_STATUS Status;
391 UINT64 Position;
392 ACPI_PARSE_OBJECT *Child;
393
394
395 ACPI_FUNCTION_TRACE_PTR (DsGetFieldNames, Info);
396
397
398 /* First field starts at bit zero */
399
400 Info->FieldBitPosition = 0;
401
402 /* Process all elements in the field list (of parse nodes) */
403
404 while (Arg)
405 {
406 /*
407 * Four types of field elements are handled:
408 * 1) Name - Enters a new named field into the namespace
409 * 2) Offset - specifies a bit offset
410 * 3) AccessAs - changes the access mode/attributes
411 * 4) Connection - Associate a resource template with the field
412 */
413 switch (Arg->Common.AmlOpcode)
414 {
415 case AML_INT_RESERVEDFIELD_OP:
416
417 Position = (UINT64) Info->FieldBitPosition +
418 (UINT64) Arg->Common.Value.Size;
419
420 if (Position > ACPI_UINT32_MAX)
421 {
422 ACPI_ERROR ((AE_INFO,
423 "Bit offset within field too large (> 0xFFFFFFFF)"));
424 return_ACPI_STATUS (AE_SUPPORT);
425 }
426
427 Info->FieldBitPosition = (UINT32) Position;
428 break;
429
430 case AML_INT_ACCESSFIELD_OP:
431 case AML_INT_EXTACCESSFIELD_OP:
432 /*
433 * Get new AccessType, AccessAttribute, and AccessLength fields
434 * -- to be used for all field units that follow, until the
435 * end-of-field or another AccessAs keyword is encountered.
436 * NOTE. These three bytes are encoded in the integer value
437 * of the parseop for convenience.
438 *
439 * In FieldFlags, preserve the flag bits other than the
440 * ACCESS_TYPE bits.
441 */
442
443 /* AccessType (ByteAcc, WordAcc, etc.) */
444
445 Info->FieldFlags = (UINT8)
446 ((Info->FieldFlags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
447 ((UINT8) ((UINT32) (Arg->Common.Value.Integer & 0x07))));
448
449 /* AccessAttribute (AttribQuick, AttribByte, etc.) */
450
451 Info->Attribute = (UINT8)
452 ((Arg->Common.Value.Integer >> 8) & 0xFF);
453
454 /* AccessLength (for serial/buffer protocols) */
455
456 Info->AccessLength = (UINT8)
457 ((Arg->Common.Value.Integer >> 16) & 0xFF);
458 break;
459
460 case AML_INT_CONNECTION_OP:
461 /*
462 * Clear any previous connection. New connection is used for all
463 * fields that follow, similar to AccessAs
464 */
465 Info->ResourceBuffer = NULL;
466 Info->ConnectionNode = NULL;
467 Info->PinNumberIndex = 0;
468
469 /*
470 * A Connection() is either an actual resource descriptor (buffer)
471 * or a named reference to a resource template
472 */
473 Child = Arg->Common.Value.Arg;
474 if (Child->Common.AmlOpcode == AML_INT_BYTELIST_OP)
475 {
476 Info->ResourceBuffer = Child->Named.Data;
477 Info->ResourceLength = (UINT16) Child->Named.Value.Integer;
478 }
479 else
480 {
481 /* Lookup the Connection() namepath, it should already exist */
482
483 Status = AcpiNsLookup (WalkState->ScopeInfo,
484 Child->Common.Value.Name, ACPI_TYPE_ANY,
485 ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE,
486 WalkState, &Info->ConnectionNode);
487 if (ACPI_FAILURE (Status))
488 {
489 ACPI_ERROR_NAMESPACE (Child->Common.Value.Name, Status);
490 return_ACPI_STATUS (Status);
491 }
492 }
493 break;
494
495 case AML_INT_NAMEDFIELD_OP:
496
497 /* Lookup the name, it should already exist */
498
499 Status = AcpiNsLookup (WalkState->ScopeInfo,
500 (char *) &Arg->Named.Name, Info->FieldType,
501 ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE,
502 WalkState, &Info->FieldNode);
503 if (ACPI_FAILURE (Status))
504 {
505 ACPI_ERROR_NAMESPACE ((char *) &Arg->Named.Name, Status);
506 return_ACPI_STATUS (Status);
507 }
508 else
509 {
510 Arg->Common.Node = Info->FieldNode;
511 Info->FieldBitLength = Arg->Common.Value.Size;
512
513 /*
514 * If there is no object attached to the node, this node was
515 * just created and we need to create the field object.
516 * Otherwise, this was a lookup of an existing node and we
517 * don't want to create the field object again.
518 */
519 if (!AcpiNsGetAttachedObject (Info->FieldNode))
520 {
521 Status = AcpiExPrepFieldValue (Info);
522 if (ACPI_FAILURE (Status))
523 {
524 return_ACPI_STATUS (Status);
525 }
526 }
527 }
528
529 /* Keep track of bit position for the next field */
530
531 Position = (UINT64) Info->FieldBitPosition +
532 (UINT64) Arg->Common.Value.Size;
533
534 if (Position > ACPI_UINT32_MAX)
535 {
536 ACPI_ERROR ((AE_INFO,
537 "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)",
538 ACPI_CAST_PTR (char, &Info->FieldNode->Name)));
539 return_ACPI_STATUS (AE_SUPPORT);
540 }
541
542 Info->FieldBitPosition += Info->FieldBitLength;
543 Info->PinNumberIndex++; /* Index relative to previous Connection() */
544 break;
545
546 default:
547
548 ACPI_ERROR ((AE_INFO,
549 "Invalid opcode in field list: 0x%X",
550 Arg->Common.AmlOpcode));
551 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
552 }
553
554 Arg = Arg->Common.Next;
555 }
556
557 return_ACPI_STATUS (AE_OK);
558 }
559
560
561 /*******************************************************************************
562 *
563 * FUNCTION: AcpiDsCreateField
564 *
565 * PARAMETERS: Op - Op containing the Field definition and args
566 * RegionNode - Object for the containing Operation Region
567 * ` WalkState - Current method state
568 *
569 * RETURN: Status
570 *
571 * DESCRIPTION: Create a new field in the specified operation region
572 *
573 ******************************************************************************/
574
575 ACPI_STATUS
576 AcpiDsCreateField (
577 ACPI_PARSE_OBJECT *Op,
578 ACPI_NAMESPACE_NODE *RegionNode,
579 ACPI_WALK_STATE *WalkState)
580 {
581 ACPI_STATUS Status;
582 ACPI_PARSE_OBJECT *Arg;
583 ACPI_CREATE_FIELD_INFO Info;
584
585
586 ACPI_FUNCTION_TRACE_PTR (DsCreateField, Op);
587
588
589 /* First arg is the name of the parent OpRegion (must already exist) */
590
591 Arg = Op->Common.Value.Arg;
592
593 if (!RegionNode)
594 {
595 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.Name,
596 ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,
597 ACPI_NS_SEARCH_PARENT, WalkState, &RegionNode);
598 #ifdef ACPI_ASL_COMPILER
599 Status = AcpiDsCreateExternalRegion (Status, Arg,
600 Arg->Common.Value.Name, WalkState, &RegionNode);
601 #endif
602 if (ACPI_FAILURE (Status))
603 {
604 ACPI_ERROR_NAMESPACE (Arg->Common.Value.Name, Status);
605 return_ACPI_STATUS (Status);
606 }
607 }
608
609 memset (&Info, 0, sizeof (ACPI_CREATE_FIELD_INFO));
610
611 /* Second arg is the field flags */
612
613 Arg = Arg->Common.Next;
614 Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
615 Info.Attribute = 0;
616
617 /* Each remaining arg is a Named Field */
618
619 Info.FieldType = ACPI_TYPE_LOCAL_REGION_FIELD;
620 Info.RegionNode = RegionNode;
621
622 Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
623 return_ACPI_STATUS (Status);
624 }
625
626
627 /*******************************************************************************
628 *
629 * FUNCTION: AcpiDsInitFieldObjects
630 *
631 * PARAMETERS: Op - Op containing the Field definition and args
632 * ` WalkState - Current method state
633 *
634 * RETURN: Status
635 *
636 * DESCRIPTION: For each "Field Unit" name in the argument list that is
637 * part of the field declaration, enter the name into the
638 * namespace.
639 *
640 ******************************************************************************/
641
642 ACPI_STATUS
643 AcpiDsInitFieldObjects (
644 ACPI_PARSE_OBJECT *Op,
645 ACPI_WALK_STATE *WalkState)
646 {
647 ACPI_STATUS Status;
648 ACPI_PARSE_OBJECT *Arg = NULL;
649 ACPI_NAMESPACE_NODE *Node;
650 UINT8 Type = 0;
651 UINT32 Flags;
652
653
654 ACPI_FUNCTION_TRACE_PTR (DsInitFieldObjects, Op);
655
656
657 /* Execute flag should always be set when this function is entered */
658
659 if (!(WalkState->ParseFlags & ACPI_PARSE_EXECUTE))
660 {
661 if (WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)
662 {
663 /* BankField Op is deferred, just return OK */
664
665 return_ACPI_STATUS (AE_OK);
666 }
667
668 return_ACPI_STATUS (AE_AML_INTERNAL);
669 }
670
671 /*
672 * Get the FieldList argument for this opcode. This is the start of the
673 * list of field elements.
674 */
675 switch (WalkState->Opcode)
676 {
677 case AML_FIELD_OP:
678
679 Arg = AcpiPsGetArg (Op, 2);
680 Type = ACPI_TYPE_LOCAL_REGION_FIELD;
681 break;
682
683 case AML_BANK_FIELD_OP:
684
685 Arg = AcpiPsGetArg (Op, 4);
686 Type = ACPI_TYPE_LOCAL_BANK_FIELD;
687 break;
688
689 case AML_INDEX_FIELD_OP:
690
691 Arg = AcpiPsGetArg (Op, 3);
692 Type = ACPI_TYPE_LOCAL_INDEX_FIELD;
693 break;
694
695 default:
696
697 return_ACPI_STATUS (AE_BAD_PARAMETER);
698 }
699
700 /* Creating new namespace node(s), should not already exist */
701
702 Flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
703 ACPI_NS_ERROR_IF_FOUND;
704
705 /*
706 * Mark node(s) temporary if we are executing a normal control
707 * method. (Don't mark if this is a module-level code method)
708 */
709 if (WalkState->MethodNode &&
710 !(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
711 {
712 Flags |= ACPI_NS_TEMPORARY;
713 }
714
715 /*
716 * Walk the list of entries in the FieldList
717 * Note: FieldList can be of zero length. In this case, Arg will be NULL.
718 */
719 while (Arg)
720 {
721 /*
722 * Ignore OFFSET/ACCESSAS/CONNECTION terms here; we are only interested
723 * in the field names in order to enter them into the namespace.
724 */
725 if (Arg->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
726 {
727 Status = AcpiNsLookup (WalkState->ScopeInfo,
728 (char *) &Arg->Named.Name, Type, ACPI_IMODE_LOAD_PASS1,
729 Flags, WalkState, &Node);
730 if (ACPI_FAILURE (Status))
731 {
732 ACPI_ERROR_NAMESPACE ((char *) &Arg->Named.Name, Status);
733 if (Status != AE_ALREADY_EXISTS)
734 {
735 return_ACPI_STATUS (Status);
736 }
737
738 /* Name already exists, just ignore this error */
739
740 Status = AE_OK;
741 }
742
743 Arg->Common.Node = Node;
744 }
745
746 /* Get the next field element in the list */
747
748 Arg = Arg->Common.Next;
749 }
750
751 return_ACPI_STATUS (AE_OK);
752 }
753
754
755 /*******************************************************************************
756 *
757 * FUNCTION: AcpiDsCreateBankField
758 *
759 * PARAMETERS: Op - Op containing the Field definition and args
760 * RegionNode - Object for the containing Operation Region
761 * WalkState - Current method state
762 *
763 * RETURN: Status
764 *
765 * DESCRIPTION: Create a new bank field in the specified operation region
766 *
767 ******************************************************************************/
768
769 ACPI_STATUS
770 AcpiDsCreateBankField (
771 ACPI_PARSE_OBJECT *Op,
772 ACPI_NAMESPACE_NODE *RegionNode,
773 ACPI_WALK_STATE *WalkState)
774 {
775 ACPI_STATUS Status;
776 ACPI_PARSE_OBJECT *Arg;
777 ACPI_CREATE_FIELD_INFO Info;
778
779
780 ACPI_FUNCTION_TRACE_PTR (DsCreateBankField, Op);
781
782
783 /* First arg is the name of the parent OpRegion (must already exist) */
784
785 Arg = Op->Common.Value.Arg;
786 if (!RegionNode)
787 {
788 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.Name,
789 ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,
790 ACPI_NS_SEARCH_PARENT, WalkState, &RegionNode);
791 #ifdef ACPI_ASL_COMPILER
792 Status = AcpiDsCreateExternalRegion (Status, Arg,
793 Arg->Common.Value.Name, WalkState, &RegionNode);
794 #endif
795 if (ACPI_FAILURE (Status))
796 {
797 ACPI_ERROR_NAMESPACE (Arg->Common.Value.Name, Status);
798 return_ACPI_STATUS (Status);
799 }
800 }
801
802 /* Second arg is the Bank Register (Field) (must already exist) */
803
804 Arg = Arg->Common.Next;
805 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
806 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
807 ACPI_NS_SEARCH_PARENT, WalkState, &Info.RegisterNode);
808 if (ACPI_FAILURE (Status))
809 {
810 ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
811 return_ACPI_STATUS (Status);
812 }
813
814 /*
815 * Third arg is the BankValue
816 * This arg is a TermArg, not a constant
817 * It will be evaluated later, by AcpiDsEvalBankFieldOperands
818 */
819 Arg = Arg->Common.Next;
820
821 /* Fourth arg is the field flags */
822
823 Arg = Arg->Common.Next;
824 Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
825
826 /* Each remaining arg is a Named Field */
827
828 Info.FieldType = ACPI_TYPE_LOCAL_BANK_FIELD;
829 Info.RegionNode = RegionNode;
830
831 /*
832 * Use Info.DataRegisterNode to store BankField Op
833 * It's safe because DataRegisterNode will never be used when create
834 * bank field \we store AmlStart and AmlLength in the BankField Op for
835 * late evaluation. Used in AcpiExPrepFieldValue(Info)
836 *
837 * TBD: Or, should we add a field in ACPI_CREATE_FIELD_INFO, like
838 * "void *ParentOp"?
839 */
840 Info.DataRegisterNode = (ACPI_NAMESPACE_NODE*) Op;
841
842 Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
843 return_ACPI_STATUS (Status);
844 }
845
846
847 /*******************************************************************************
848 *
849 * FUNCTION: AcpiDsCreateIndexField
850 *
851 * PARAMETERS: Op - Op containing the Field definition and args
852 * RegionNode - Object for the containing Operation Region
853 * ` WalkState - Current method state
854 *
855 * RETURN: Status
856 *
857 * DESCRIPTION: Create a new index field in the specified operation region
858 *
859 ******************************************************************************/
860
861 ACPI_STATUS
862 AcpiDsCreateIndexField (
863 ACPI_PARSE_OBJECT *Op,
864 ACPI_NAMESPACE_NODE *RegionNode,
865 ACPI_WALK_STATE *WalkState)
866 {
867 ACPI_STATUS Status;
868 ACPI_PARSE_OBJECT *Arg;
869 ACPI_CREATE_FIELD_INFO Info;
870
871
872 ACPI_FUNCTION_TRACE_PTR (DsCreateIndexField, Op);
873
874
875 /* First arg is the name of the Index register (must already exist) */
876
877 Arg = Op->Common.Value.Arg;
878 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
879 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
880 ACPI_NS_SEARCH_PARENT, WalkState, &Info.RegisterNode);
881 if (ACPI_FAILURE (Status))
882 {
883 ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
884 return_ACPI_STATUS (Status);
885 }
886
887 /* Second arg is the data register (must already exist) */
888
889 Arg = Arg->Common.Next;
890 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
891 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
892 ACPI_NS_SEARCH_PARENT, WalkState, &Info.DataRegisterNode);
893 if (ACPI_FAILURE (Status))
894 {
895 ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
896 return_ACPI_STATUS (Status);
897 }
898
899 /* Next arg is the field flags */
900
901 Arg = Arg->Common.Next;
902 Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
903
904 /* Each remaining arg is a Named Field */
905
906 Info.FieldType = ACPI_TYPE_LOCAL_INDEX_FIELD;
907 Info.RegionNode = RegionNode;
908
909 Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
910 return_ACPI_STATUS (Status);
911 }