d14434b2341f4ca9b76b10311bc714ba6d0a3b77
[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 - 2014, 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 Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_REGION,
191 ACPI_IMODE_LOAD_PASS1, ACPI_NS_SEARCH_PARENT, WalkState, Node);
192 if (ACPI_FAILURE (Status))
193 {
194 return (Status);
195 }
196
197 /* Must create and install a region object for the new node */
198
199 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_REGION);
200 if (!ObjDesc)
201 {
202 return (AE_NO_MEMORY);
203 }
204
205 ObjDesc->Region.Node = *Node;
206 Status = AcpiNsAttachObject (*Node, ObjDesc, ACPI_TYPE_REGION);
207 return (Status);
208 }
209 #endif
210
211
212 /*******************************************************************************
213 *
214 * FUNCTION: AcpiDsCreateBufferField
215 *
216 * PARAMETERS: Op - Current parse op (CreateXXField)
217 * WalkState - Current state
218 *
219 * RETURN: Status
220 *
221 * DESCRIPTION: Execute the CreateField operators:
222 * CreateBitFieldOp,
223 * CreateByteFieldOp,
224 * CreateWordFieldOp,
225 * CreateDwordFieldOp,
226 * CreateQwordFieldOp,
227 * CreateFieldOp (all of which define a field in a buffer)
228 *
229 ******************************************************************************/
230
231 ACPI_STATUS
232 AcpiDsCreateBufferField (
233 ACPI_PARSE_OBJECT *Op,
234 ACPI_WALK_STATE *WalkState)
235 {
236 ACPI_PARSE_OBJECT *Arg;
237 ACPI_NAMESPACE_NODE *Node;
238 ACPI_STATUS Status;
239 ACPI_OPERAND_OBJECT *ObjDesc;
240 ACPI_OPERAND_OBJECT *SecondDesc = NULL;
241 UINT32 Flags;
242
243
244 ACPI_FUNCTION_TRACE (DsCreateBufferField);
245
246
247 /*
248 * Get the NameString argument (name of the new BufferField)
249 */
250 if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)
251 {
252 /* For CreateField, name is the 4th argument */
253
254 Arg = AcpiPsGetArg (Op, 3);
255 }
256 else
257 {
258 /* For all other CreateXXXField operators, name is the 3rd argument */
259
260 Arg = AcpiPsGetArg (Op, 2);
261 }
262
263 if (!Arg)
264 {
265 return_ACPI_STATUS (AE_AML_NO_OPERAND);
266 }
267
268 if (WalkState->DeferredNode)
269 {
270 Node = WalkState->DeferredNode;
271 Status = AE_OK;
272 }
273 else
274 {
275 /* Execute flag should always be set when this function is entered */
276
277 if (!(WalkState->ParseFlags & ACPI_PARSE_EXECUTE))
278 {
279 return_ACPI_STATUS (AE_AML_INTERNAL);
280 }
281
282 /* Creating new namespace node, should not already exist */
283
284 Flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
285 ACPI_NS_ERROR_IF_FOUND;
286
287 /*
288 * Mark node temporary if we are executing a normal control
289 * method. (Don't mark if this is a module-level code method)
290 */
291 if (WalkState->MethodNode &&
292 !(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
293 {
294 Flags |= ACPI_NS_TEMPORARY;
295 }
296
297 /* Enter the NameString into the namespace */
298
299 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
300 ACPI_TYPE_ANY, ACPI_IMODE_LOAD_PASS1,
301 Flags, WalkState, &Node);
302 if (ACPI_FAILURE (Status))
303 {
304 ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
305 return_ACPI_STATUS (Status);
306 }
307 }
308
309 /*
310 * We could put the returned object (Node) on the object stack for later,
311 * but for now, we will put it in the "op" object that the parser uses,
312 * so we can get it again at the end of this scope.
313 */
314 Op->Common.Node = Node;
315
316 /*
317 * If there is no object attached to the node, this node was just created
318 * and we need to create the field object. Otherwise, this was a lookup
319 * of an existing node and we don't want to create the field object again.
320 */
321 ObjDesc = AcpiNsGetAttachedObject (Node);
322 if (ObjDesc)
323 {
324 return_ACPI_STATUS (AE_OK);
325 }
326
327 /*
328 * The Field definition is not fully parsed at this time.
329 * (We must save the address of the AML for the buffer and index operands)
330 */
331
332 /* Create the buffer field object */
333
334 ObjDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER_FIELD);
335 if (!ObjDesc)
336 {
337 Status = AE_NO_MEMORY;
338 goto Cleanup;
339 }
340
341 /*
342 * Remember location in AML stream of the field unit opcode and operands --
343 * since the buffer and index operands must be evaluated.
344 */
345 SecondDesc = ObjDesc->Common.NextObject;
346 SecondDesc->Extra.AmlStart = Op->Named.Data;
347 SecondDesc->Extra.AmlLength = Op->Named.Length;
348 ObjDesc->BufferField.Node = Node;
349
350 /* Attach constructed field descriptors to parent node */
351
352 Status = AcpiNsAttachObject (Node, ObjDesc, ACPI_TYPE_BUFFER_FIELD);
353 if (ACPI_FAILURE (Status))
354 {
355 goto Cleanup;
356 }
357
358
359 Cleanup:
360
361 /* Remove local reference to the object */
362
363 AcpiUtRemoveReference (ObjDesc);
364 return_ACPI_STATUS (Status);
365 }
366
367
368 /*******************************************************************************
369 *
370 * FUNCTION: AcpiDsGetFieldNames
371 *
372 * PARAMETERS: Info - CreateField info structure
373 * ` WalkState - Current method state
374 * Arg - First parser arg for the field name list
375 *
376 * RETURN: Status
377 *
378 * DESCRIPTION: Process all named fields in a field declaration. Names are
379 * entered into the namespace.
380 *
381 ******************************************************************************/
382
383 static ACPI_STATUS
384 AcpiDsGetFieldNames (
385 ACPI_CREATE_FIELD_INFO *Info,
386 ACPI_WALK_STATE *WalkState,
387 ACPI_PARSE_OBJECT *Arg)
388 {
389 ACPI_STATUS Status;
390 UINT64 Position;
391 ACPI_PARSE_OBJECT *Child;
392
393
394 ACPI_FUNCTION_TRACE_PTR (DsGetFieldNames, Info);
395
396
397 /* First field starts at bit zero */
398
399 Info->FieldBitPosition = 0;
400
401 /* Process all elements in the field list (of parse nodes) */
402
403 while (Arg)
404 {
405 /*
406 * Four types of field elements are handled:
407 * 1) Name - Enters a new named field into the namespace
408 * 2) Offset - specifies a bit offset
409 * 3) AccessAs - changes the access mode/attributes
410 * 4) Connection - Associate a resource template with the field
411 */
412 switch (Arg->Common.AmlOpcode)
413 {
414 case AML_INT_RESERVEDFIELD_OP:
415
416 Position = (UINT64) Info->FieldBitPosition
417 + (UINT64) Arg->Common.Value.Size;
418
419 if (Position > ACPI_UINT32_MAX)
420 {
421 ACPI_ERROR ((AE_INFO,
422 "Bit offset within field too large (> 0xFFFFFFFF)"));
423 return_ACPI_STATUS (AE_SUPPORT);
424 }
425
426 Info->FieldBitPosition = (UINT32) Position;
427 break;
428
429 case AML_INT_ACCESSFIELD_OP:
430 case AML_INT_EXTACCESSFIELD_OP:
431 /*
432 * Get new AccessType, AccessAttribute, and AccessLength fields
433 * -- to be used for all field units that follow, until the
434 * end-of-field or another AccessAs keyword is encountered.
435 * NOTE. These three bytes are encoded in the integer value
436 * of the parseop for convenience.
437 *
438 * In FieldFlags, preserve the flag bits other than the
439 * ACCESS_TYPE bits.
440 */
441
442 /* AccessType (ByteAcc, WordAcc, etc.) */
443
444 Info->FieldFlags = (UINT8)
445 ((Info->FieldFlags & ~(AML_FIELD_ACCESS_TYPE_MASK)) |
446 ((UINT8) ((UINT32) (Arg->Common.Value.Integer & 0x07))));
447
448 /* AccessAttribute (AttribQuick, AttribByte, etc.) */
449
450 Info->Attribute = (UINT8) ((Arg->Common.Value.Integer >> 8) & 0xFF);
451
452 /* AccessLength (for serial/buffer protocols) */
453
454 Info->AccessLength = (UINT8) ((Arg->Common.Value.Integer >> 16) & 0xFF);
455 break;
456
457 case AML_INT_CONNECTION_OP:
458 /*
459 * Clear any previous connection. New connection is used for all
460 * fields that follow, similar to AccessAs
461 */
462 Info->ResourceBuffer = NULL;
463 Info->ConnectionNode = NULL;
464 Info->PinNumberIndex = 0;
465
466 /*
467 * A Connection() is either an actual resource descriptor (buffer)
468 * or a named reference to a resource template
469 */
470 Child = Arg->Common.Value.Arg;
471 if (Child->Common.AmlOpcode == AML_INT_BYTELIST_OP)
472 {
473 Info->ResourceBuffer = Child->Named.Data;
474 Info->ResourceLength = (UINT16) Child->Named.Value.Integer;
475 }
476 else
477 {
478 /* Lookup the Connection() namepath, it should already exist */
479
480 Status = AcpiNsLookup (WalkState->ScopeInfo,
481 Child->Common.Value.Name, ACPI_TYPE_ANY,
482 ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE,
483 WalkState, &Info->ConnectionNode);
484 if (ACPI_FAILURE (Status))
485 {
486 ACPI_ERROR_NAMESPACE (Child->Common.Value.Name, Status);
487 return_ACPI_STATUS (Status);
488 }
489 }
490 break;
491
492 case AML_INT_NAMEDFIELD_OP:
493
494 /* Lookup the name, it should already exist */
495
496 Status = AcpiNsLookup (WalkState->ScopeInfo,
497 (char *) &Arg->Named.Name, Info->FieldType,
498 ACPI_IMODE_EXECUTE, ACPI_NS_DONT_OPEN_SCOPE,
499 WalkState, &Info->FieldNode);
500 if (ACPI_FAILURE (Status))
501 {
502 ACPI_ERROR_NAMESPACE ((char *) &Arg->Named.Name, Status);
503 return_ACPI_STATUS (Status);
504 }
505 else
506 {
507 Arg->Common.Node = Info->FieldNode;
508 Info->FieldBitLength = Arg->Common.Value.Size;
509
510 /*
511 * If there is no object attached to the node, this node was
512 * just created and we need to create the field object.
513 * Otherwise, this was a lookup of an existing node and we
514 * don't want to create the field object again.
515 */
516 if (!AcpiNsGetAttachedObject (Info->FieldNode))
517 {
518 Status = AcpiExPrepFieldValue (Info);
519 if (ACPI_FAILURE (Status))
520 {
521 return_ACPI_STATUS (Status);
522 }
523 }
524 }
525
526 /* Keep track of bit position for the next field */
527
528 Position = (UINT64) Info->FieldBitPosition
529 + (UINT64) Arg->Common.Value.Size;
530
531 if (Position > ACPI_UINT32_MAX)
532 {
533 ACPI_ERROR ((AE_INFO,
534 "Field [%4.4s] bit offset too large (> 0xFFFFFFFF)",
535 ACPI_CAST_PTR (char, &Info->FieldNode->Name)));
536 return_ACPI_STATUS (AE_SUPPORT);
537 }
538
539 Info->FieldBitPosition += Info->FieldBitLength;
540 Info->PinNumberIndex++; /* Index relative to previous Connection() */
541 break;
542
543 default:
544
545 ACPI_ERROR ((AE_INFO,
546 "Invalid opcode in field list: 0x%X", Arg->Common.AmlOpcode));
547 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
548 }
549
550 Arg = Arg->Common.Next;
551 }
552
553 return_ACPI_STATUS (AE_OK);
554 }
555
556
557 /*******************************************************************************
558 *
559 * FUNCTION: AcpiDsCreateField
560 *
561 * PARAMETERS: Op - Op containing the Field definition and args
562 * RegionNode - Object for the containing Operation Region
563 * ` WalkState - Current method state
564 *
565 * RETURN: Status
566 *
567 * DESCRIPTION: Create a new field in the specified operation region
568 *
569 ******************************************************************************/
570
571 ACPI_STATUS
572 AcpiDsCreateField (
573 ACPI_PARSE_OBJECT *Op,
574 ACPI_NAMESPACE_NODE *RegionNode,
575 ACPI_WALK_STATE *WalkState)
576 {
577 ACPI_STATUS Status;
578 ACPI_PARSE_OBJECT *Arg;
579 ACPI_CREATE_FIELD_INFO Info;
580
581
582 ACPI_FUNCTION_TRACE_PTR (DsCreateField, Op);
583
584
585 /* First arg is the name of the parent OpRegion (must already exist) */
586
587 Arg = Op->Common.Value.Arg;
588
589 if (!RegionNode)
590 {
591 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.Name,
592 ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,
593 ACPI_NS_SEARCH_PARENT, WalkState, &RegionNode);
594 #ifdef ACPI_ASL_COMPILER
595 Status = AcpiDsCreateExternalRegion (Status, Arg,
596 Arg->Common.Value.Name, WalkState, &RegionNode);
597 #endif
598 if (ACPI_FAILURE (Status))
599 {
600 ACPI_ERROR_NAMESPACE (Arg->Common.Value.Name, Status);
601 return_ACPI_STATUS (Status);
602 }
603 }
604
605 ACPI_MEMSET (&Info, 0, sizeof (ACPI_CREATE_FIELD_INFO));
606
607 /* Second arg is the field flags */
608
609 Arg = Arg->Common.Next;
610 Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
611 Info.Attribute = 0;
612
613 /* Each remaining arg is a Named Field */
614
615 Info.FieldType = ACPI_TYPE_LOCAL_REGION_FIELD;
616 Info.RegionNode = RegionNode;
617
618 Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
619 return_ACPI_STATUS (Status);
620 }
621
622
623 /*******************************************************************************
624 *
625 * FUNCTION: AcpiDsInitFieldObjects
626 *
627 * PARAMETERS: Op - Op containing the Field definition and args
628 * ` WalkState - Current method state
629 *
630 * RETURN: Status
631 *
632 * DESCRIPTION: For each "Field Unit" name in the argument list that is
633 * part of the field declaration, enter the name into the
634 * namespace.
635 *
636 ******************************************************************************/
637
638 ACPI_STATUS
639 AcpiDsInitFieldObjects (
640 ACPI_PARSE_OBJECT *Op,
641 ACPI_WALK_STATE *WalkState)
642 {
643 ACPI_STATUS Status;
644 ACPI_PARSE_OBJECT *Arg = NULL;
645 ACPI_NAMESPACE_NODE *Node;
646 UINT8 Type = 0;
647 UINT32 Flags;
648
649
650 ACPI_FUNCTION_TRACE_PTR (DsInitFieldObjects, Op);
651
652
653 /* Execute flag should always be set when this function is entered */
654
655 if (!(WalkState->ParseFlags & ACPI_PARSE_EXECUTE))
656 {
657 if (WalkState->ParseFlags & ACPI_PARSE_DEFERRED_OP)
658 {
659 /* BankField Op is deferred, just return OK */
660
661 return_ACPI_STATUS (AE_OK);
662 }
663
664 return_ACPI_STATUS (AE_AML_INTERNAL);
665 }
666
667 /*
668 * Get the FieldList argument for this opcode. This is the start of the
669 * list of field elements.
670 */
671 switch (WalkState->Opcode)
672 {
673 case AML_FIELD_OP:
674
675 Arg = AcpiPsGetArg (Op, 2);
676 Type = ACPI_TYPE_LOCAL_REGION_FIELD;
677 break;
678
679 case AML_BANK_FIELD_OP:
680
681 Arg = AcpiPsGetArg (Op, 4);
682 Type = ACPI_TYPE_LOCAL_BANK_FIELD;
683 break;
684
685 case AML_INDEX_FIELD_OP:
686
687 Arg = AcpiPsGetArg (Op, 3);
688 Type = ACPI_TYPE_LOCAL_INDEX_FIELD;
689 break;
690
691 default:
692
693 return_ACPI_STATUS (AE_BAD_PARAMETER);
694 }
695
696 /* Creating new namespace node(s), should not already exist */
697
698 Flags = ACPI_NS_NO_UPSEARCH | ACPI_NS_DONT_OPEN_SCOPE |
699 ACPI_NS_ERROR_IF_FOUND;
700
701 /*
702 * Mark node(s) temporary if we are executing a normal control
703 * method. (Don't mark if this is a module-level code method)
704 */
705 if (WalkState->MethodNode &&
706 !(WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL))
707 {
708 Flags |= ACPI_NS_TEMPORARY;
709 }
710
711 /*
712 * Walk the list of entries in the FieldList
713 * Note: FieldList can be of zero length. In this case, Arg will be NULL.
714 */
715 while (Arg)
716 {
717 /*
718 * Ignore OFFSET/ACCESSAS/CONNECTION terms here; we are only interested
719 * in the field names in order to enter them into the namespace.
720 */
721 if (Arg->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
722 {
723 Status = AcpiNsLookup (WalkState->ScopeInfo,
724 (char *) &Arg->Named.Name, Type, ACPI_IMODE_LOAD_PASS1,
725 Flags, WalkState, &Node);
726 if (ACPI_FAILURE (Status))
727 {
728 ACPI_ERROR_NAMESPACE ((char *) &Arg->Named.Name, Status);
729 if (Status != AE_ALREADY_EXISTS)
730 {
731 return_ACPI_STATUS (Status);
732 }
733
734 /* Name already exists, just ignore this error */
735
736 Status = AE_OK;
737 }
738
739 Arg->Common.Node = Node;
740 }
741
742 /* Get the next field element in the list */
743
744 Arg = Arg->Common.Next;
745 }
746
747 return_ACPI_STATUS (AE_OK);
748 }
749
750
751 /*******************************************************************************
752 *
753 * FUNCTION: AcpiDsCreateBankField
754 *
755 * PARAMETERS: Op - Op containing the Field definition and args
756 * RegionNode - Object for the containing Operation Region
757 * WalkState - Current method state
758 *
759 * RETURN: Status
760 *
761 * DESCRIPTION: Create a new bank field in the specified operation region
762 *
763 ******************************************************************************/
764
765 ACPI_STATUS
766 AcpiDsCreateBankField (
767 ACPI_PARSE_OBJECT *Op,
768 ACPI_NAMESPACE_NODE *RegionNode,
769 ACPI_WALK_STATE *WalkState)
770 {
771 ACPI_STATUS Status;
772 ACPI_PARSE_OBJECT *Arg;
773 ACPI_CREATE_FIELD_INFO Info;
774
775
776 ACPI_FUNCTION_TRACE_PTR (DsCreateBankField, Op);
777
778
779 /* First arg is the name of the parent OpRegion (must already exist) */
780
781 Arg = Op->Common.Value.Arg;
782 if (!RegionNode)
783 {
784 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.Name,
785 ACPI_TYPE_REGION, ACPI_IMODE_EXECUTE,
786 ACPI_NS_SEARCH_PARENT, WalkState, &RegionNode);
787 #ifdef ACPI_ASL_COMPILER
788 Status = AcpiDsCreateExternalRegion (Status, Arg,
789 Arg->Common.Value.Name, WalkState, &RegionNode);
790 #endif
791 if (ACPI_FAILURE (Status))
792 {
793 ACPI_ERROR_NAMESPACE (Arg->Common.Value.Name, Status);
794 return_ACPI_STATUS (Status);
795 }
796 }
797
798 /* Second arg is the Bank Register (Field) (must already exist) */
799
800 Arg = Arg->Common.Next;
801 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
802 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
803 ACPI_NS_SEARCH_PARENT, WalkState, &Info.RegisterNode);
804 if (ACPI_FAILURE (Status))
805 {
806 ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
807 return_ACPI_STATUS (Status);
808 }
809
810 /*
811 * Third arg is the BankValue
812 * This arg is a TermArg, not a constant
813 * It will be evaluated later, by AcpiDsEvalBankFieldOperands
814 */
815 Arg = Arg->Common.Next;
816
817 /* Fourth arg is the field flags */
818
819 Arg = Arg->Common.Next;
820 Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
821
822 /* Each remaining arg is a Named Field */
823
824 Info.FieldType = ACPI_TYPE_LOCAL_BANK_FIELD;
825 Info.RegionNode = RegionNode;
826
827 /*
828 * Use Info.DataRegisterNode to store BankField Op
829 * It's safe because DataRegisterNode will never be used when create bank field
830 * We store AmlStart and AmlLength in the BankField Op for late evaluation
831 * Used in AcpiExPrepFieldValue(Info)
832 *
833 * TBD: Or, should we add a field in ACPI_CREATE_FIELD_INFO, like "void *ParentOp"?
834 */
835 Info.DataRegisterNode = (ACPI_NAMESPACE_NODE*) Op;
836
837 Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
838 return_ACPI_STATUS (Status);
839 }
840
841
842 /*******************************************************************************
843 *
844 * FUNCTION: AcpiDsCreateIndexField
845 *
846 * PARAMETERS: Op - Op containing the Field definition and args
847 * RegionNode - Object for the containing Operation Region
848 * ` WalkState - Current method state
849 *
850 * RETURN: Status
851 *
852 * DESCRIPTION: Create a new index field in the specified operation region
853 *
854 ******************************************************************************/
855
856 ACPI_STATUS
857 AcpiDsCreateIndexField (
858 ACPI_PARSE_OBJECT *Op,
859 ACPI_NAMESPACE_NODE *RegionNode,
860 ACPI_WALK_STATE *WalkState)
861 {
862 ACPI_STATUS Status;
863 ACPI_PARSE_OBJECT *Arg;
864 ACPI_CREATE_FIELD_INFO Info;
865
866
867 ACPI_FUNCTION_TRACE_PTR (DsCreateIndexField, Op);
868
869
870 /* First arg is the name of the Index register (must already exist) */
871
872 Arg = Op->Common.Value.Arg;
873 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
874 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
875 ACPI_NS_SEARCH_PARENT, WalkState, &Info.RegisterNode);
876 if (ACPI_FAILURE (Status))
877 {
878 ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
879 return_ACPI_STATUS (Status);
880 }
881
882 /* Second arg is the data register (must already exist) */
883
884 Arg = Arg->Common.Next;
885 Status = AcpiNsLookup (WalkState->ScopeInfo, Arg->Common.Value.String,
886 ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
887 ACPI_NS_SEARCH_PARENT, WalkState, &Info.DataRegisterNode);
888 if (ACPI_FAILURE (Status))
889 {
890 ACPI_ERROR_NAMESPACE (Arg->Common.Value.String, Status);
891 return_ACPI_STATUS (Status);
892 }
893
894 /* Next arg is the field flags */
895
896 Arg = Arg->Common.Next;
897 Info.FieldFlags = (UINT8) Arg->Common.Value.Integer;
898
899 /* Each remaining arg is a Named Field */
900
901 Info.FieldType = ACPI_TYPE_LOCAL_INDEX_FIELD;
902 Info.RegionNode = RegionNode;
903
904 Status = AcpiDsGetFieldNames (&Info, WalkState, Arg->Common.Next);
905 return_ACPI_STATUS (Status);
906 }