1 /******************************************************************************
2  *
3  * Module Name: dsopcode - Dispatcher support for regions and fields
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2017, 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  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
122  * 1. Redistributions of source code must retain the above copyright
123  *    notice, this list of conditions, and the following disclaimer,
124  *    without modification.
125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126  *    substantially similar to the "NO WARRANTY" disclaimer below
127  *    ("Disclaimer") and any redistribution must be conditioned upon
128  *    including a substantially similar Disclaimer requirement for further
129  *    binary redistribution.
130  * 3. Neither the names of the above-listed copyright holders nor the names
131  *    of any contributors may be used to endorse or promote products derived
132  *    from this software without specific prior written permission.
133  *
134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145  *
146  * Alternatively, you may choose to be licensed under the terms of the
147  * GNU General Public License ("GPL") version 2 as published by the Free
148  * Software Foundation.
149  *
150  *****************************************************************************/
151 
152 #include "acpi.h"
153 #include "accommon.h"
154 #include "acparser.h"
155 #include "amlcode.h"
156 #include "acdispat.h"
157 #include "acinterp.h"
158 #include "acnamesp.h"
159 #include "acevents.h"
160 #include "actables.h"
161 
162 #define _COMPONENT          ACPI_DISPATCHER
163         ACPI_MODULE_NAME    ("dsopcode")
164 
165 /* Local prototypes */
166 
167 static ACPI_STATUS
168 AcpiDsInitBufferField (
169     UINT16                  AmlOpcode,
170     ACPI_OPERAND_OBJECT     *ObjDesc,
171     ACPI_OPERAND_OBJECT     *BufferDesc,
172     ACPI_OPERAND_OBJECT     *OffsetDesc,
173     ACPI_OPERAND_OBJECT     *LengthDesc,
174     ACPI_OPERAND_OBJECT     *ResultDesc);
175 
176 
177 /*******************************************************************************
178  *
179  * FUNCTION:    AcpiDsInitializeRegion
180  *
181  * PARAMETERS:  ObjHandle       - Region namespace node
182  *
183  * RETURN:      Status
184  *
185  * DESCRIPTION: Front end to EvInitializeRegion
186  *
187  ******************************************************************************/
188 
189 ACPI_STATUS
190 AcpiDsInitializeRegion (
191     ACPI_HANDLE             ObjHandle)
192 {
193     ACPI_OPERAND_OBJECT     *ObjDesc;
194     ACPI_STATUS             Status;
195 
196 
197     ObjDesc = AcpiNsGetAttachedObject (ObjHandle);
198 
199     /* Namespace is NOT locked */
200 
201     Status = AcpiEvInitializeRegion (ObjDesc);
202     return (Status);
203 }
204 
205 
206 /*******************************************************************************
207  *
208  * FUNCTION:    AcpiDsInitBufferField
209  *
210  * PARAMETERS:  AmlOpcode       - CreateXxxField
211  *              ObjDesc         - BufferField object
212  *              BufferDesc      - Host Buffer
213  *              OffsetDesc      - Offset into buffer
214  *              LengthDesc      - Length of field (CREATE_FIELD_OP only)
215  *              ResultDesc      - Where to store the result
216  *
217  * RETURN:      Status
218  *
219  * DESCRIPTION: Perform actual initialization of a buffer field
220  *
221  ******************************************************************************/
222 
223 static ACPI_STATUS
224 AcpiDsInitBufferField (
225     UINT16                  AmlOpcode,
226     ACPI_OPERAND_OBJECT     *ObjDesc,
227     ACPI_OPERAND_OBJECT     *BufferDesc,
228     ACPI_OPERAND_OBJECT     *OffsetDesc,
229     ACPI_OPERAND_OBJECT     *LengthDesc,
230     ACPI_OPERAND_OBJECT     *ResultDesc)
231 {
232     UINT32                  Offset;
233     UINT32                  BitOffset;
234     UINT32                  BitCount;
235     UINT8                   FieldFlags;
236     ACPI_STATUS             Status;
237 
238 
239     ACPI_FUNCTION_TRACE_PTR (DsInitBufferField, ObjDesc);
240 
241 
242     /* Host object must be a Buffer */
243 
244     if (BufferDesc->Common.Type != ACPI_TYPE_BUFFER)
245     {
246         ACPI_ERROR ((AE_INFO,
247             "Target of Create Field is not a Buffer object - %s",
248             AcpiUtGetObjectTypeName (BufferDesc)));
249 
250         Status = AE_AML_OPERAND_TYPE;
251         goto Cleanup;
252     }
253 
254     /*
255      * The last parameter to all of these opcodes (ResultDesc) started
256      * out as a NameString, and should therefore now be a NS node
257      * after resolution in AcpiExResolveOperands().
258      */
259     if (ACPI_GET_DESCRIPTOR_TYPE (ResultDesc) != ACPI_DESC_TYPE_NAMED)
260     {
261         ACPI_ERROR ((AE_INFO,
262             "(%s) destination not a NS Node [%s]",
263             AcpiPsGetOpcodeName (AmlOpcode),
264             AcpiUtGetDescriptorName (ResultDesc)));
265 
266         Status = AE_AML_OPERAND_TYPE;
267         goto Cleanup;
268     }
269 
270     Offset = (UINT32) OffsetDesc->Integer.Value;
271 
272     /*
273      * Setup the Bit offsets and counts, according to the opcode
274      */
275     switch (AmlOpcode)
276     {
277     case AML_CREATE_FIELD_OP:
278 
279         /* Offset is in bits, count is in bits */
280 
281         FieldFlags = AML_FIELD_ACCESS_BYTE;
282         BitOffset  = Offset;
283         BitCount   = (UINT32) LengthDesc->Integer.Value;
284 
285         /* Must have a valid (>0) bit count */
286 
287         if (BitCount == 0)
288         {
289             ACPI_ERROR ((AE_INFO,
290                 "Attempt to CreateField of length zero"));
291             Status = AE_AML_OPERAND_VALUE;
292             goto Cleanup;
293         }
294         break;
295 
296     case AML_CREATE_BIT_FIELD_OP:
297 
298         /* Offset is in bits, Field is one bit */
299 
300         BitOffset  = Offset;
301         BitCount   = 1;
302         FieldFlags = AML_FIELD_ACCESS_BYTE;
303         break;
304 
305     case AML_CREATE_BYTE_FIELD_OP:
306 
307         /* Offset is in bytes, field is one byte */
308 
309         BitOffset  = 8 * Offset;
310         BitCount   = 8;
311         FieldFlags = AML_FIELD_ACCESS_BYTE;
312         break;
313 
314     case AML_CREATE_WORD_FIELD_OP:
315 
316         /* Offset is in bytes, field is one word */
317 
318         BitOffset  = 8 * Offset;
319         BitCount   = 16;
320         FieldFlags = AML_FIELD_ACCESS_WORD;
321         break;
322 
323     case AML_CREATE_DWORD_FIELD_OP:
324 
325         /* Offset is in bytes, field is one dword */
326 
327         BitOffset  = 8 * Offset;
328         BitCount   = 32;
329         FieldFlags = AML_FIELD_ACCESS_DWORD;
330         break;
331 
332     case AML_CREATE_QWORD_FIELD_OP:
333 
334         /* Offset is in bytes, field is one qword */
335 
336         BitOffset  = 8 * Offset;
337         BitCount   = 64;
338         FieldFlags = AML_FIELD_ACCESS_QWORD;
339         break;
340 
341     default:
342 
343         ACPI_ERROR ((AE_INFO,
344             "Unknown field creation opcode 0x%02X",
345             AmlOpcode));
346         Status = AE_AML_BAD_OPCODE;
347         goto Cleanup;
348     }
349 
350     /* Entire field must fit within the current length of the buffer */
351 
352     if ((BitOffset + BitCount) >
353         (8 * (UINT32) BufferDesc->Buffer.Length))
354     {
355         ACPI_ERROR ((AE_INFO,
356             "Field [%4.4s] at %u exceeds Buffer [%4.4s] size %u (bits)",
357             AcpiUtGetNodeName (ResultDesc),
358             BitOffset + BitCount,
359             AcpiUtGetNodeName (BufferDesc->Buffer.Node),
360             8 * (UINT32) BufferDesc->Buffer.Length));
361         Status = AE_AML_BUFFER_LIMIT;
362         goto Cleanup;
363     }
364 
365     /*
366      * Initialize areas of the field object that are common to all fields
367      * For FieldFlags, use LOCK_RULE = 0 (NO_LOCK),
368      * UPDATE_RULE = 0 (UPDATE_PRESERVE)
369      */
370     Status = AcpiExPrepCommonFieldObject (
371         ObjDesc, FieldFlags, 0, BitOffset, BitCount);
372     if (ACPI_FAILURE (Status))
373     {
374         goto Cleanup;
375     }
376 
377     ObjDesc->BufferField.BufferObj = BufferDesc;
378 
379     /* Reference count for BufferDesc inherits ObjDesc count */
380 
381     BufferDesc->Common.ReferenceCount = (UINT16)
382         (BufferDesc->Common.ReferenceCount + ObjDesc->Common.ReferenceCount);
383 
384 
385 Cleanup:
386 
387     /* Always delete the operands */
388 
389     AcpiUtRemoveReference (OffsetDesc);
390     AcpiUtRemoveReference (BufferDesc);
391 
392     if (AmlOpcode == AML_CREATE_FIELD_OP)
393     {
394         AcpiUtRemoveReference (LengthDesc);
395     }
396 
397     /* On failure, delete the result descriptor */
398 
399     if (ACPI_FAILURE (Status))
400     {
401         AcpiUtRemoveReference (ResultDesc);     /* Result descriptor */
402     }
403     else
404     {
405         /* Now the address and length are valid for this BufferField */
406 
407         ObjDesc->BufferField.Flags |= AOPOBJ_DATA_VALID;
408     }
409 
410     return_ACPI_STATUS (Status);
411 }
412 
413 
414 /*******************************************************************************
415  *
416  * FUNCTION:    AcpiDsEvalBufferFieldOperands
417  *
418  * PARAMETERS:  WalkState       - Current walk
419  *              Op              - A valid BufferField Op object
420  *
421  * RETURN:      Status
422  *
423  * DESCRIPTION: Get BufferField Buffer and Index
424  *              Called from AcpiDsExecEndOp during BufferField parse tree walk
425  *
426  ******************************************************************************/
427 
428 ACPI_STATUS
429 AcpiDsEvalBufferFieldOperands (
430     ACPI_WALK_STATE         *WalkState,
431     ACPI_PARSE_OBJECT       *Op)
432 {
433     ACPI_STATUS             Status;
434     ACPI_OPERAND_OBJECT     *ObjDesc;
435     ACPI_NAMESPACE_NODE     *Node;
436     ACPI_PARSE_OBJECT       *NextOp;
437 
438 
439     ACPI_FUNCTION_TRACE_PTR (DsEvalBufferFieldOperands, Op);
440 
441 
442     /*
443      * This is where we evaluate the address and length fields of the
444      * CreateXxxField declaration
445      */
446     Node =  Op->Common.Node;
447 
448     /* NextOp points to the op that holds the Buffer */
449 
450     NextOp = Op->Common.Value.Arg;
451 
452     /* Evaluate/create the address and length operands */
453 
454     Status = AcpiDsCreateOperands (WalkState, NextOp);
455     if (ACPI_FAILURE (Status))
456     {
457         return_ACPI_STATUS (Status);
458     }
459 
460     ObjDesc = AcpiNsGetAttachedObject (Node);
461     if (!ObjDesc)
462     {
463         return_ACPI_STATUS (AE_NOT_EXIST);
464     }
465 
466     /* Resolve the operands */
467 
468     Status = AcpiExResolveOperands (
469         Op->Common.AmlOpcode, ACPI_WALK_OPERANDS, WalkState);
470     if (ACPI_FAILURE (Status))
471     {
472         ACPI_ERROR ((AE_INFO, "(%s) bad operand(s), status 0x%X",
473             AcpiPsGetOpcodeName (Op->Common.AmlOpcode), Status));
474 
475         return_ACPI_STATUS (Status);
476     }
477 
478     /* Initialize the Buffer Field */
479 
480     if (Op->Common.AmlOpcode == AML_CREATE_FIELD_OP)
481     {
482         /* NOTE: Slightly different operands for this opcode */
483 
484         Status = AcpiDsInitBufferField (Op->Common.AmlOpcode, ObjDesc,
485             WalkState->Operands[0], WalkState->Operands[1],
486             WalkState->Operands[2], WalkState->Operands[3]);
487     }
488     else
489     {
490         /* All other, CreateXxxField opcodes */
491 
492         Status = AcpiDsInitBufferField (Op->Common.AmlOpcode, ObjDesc,
493             WalkState->Operands[0], WalkState->Operands[1],
494             NULL, WalkState->Operands[2]);
495     }
496 
497     return_ACPI_STATUS (Status);
498 }
499 
500 
501 /*******************************************************************************
502  *
503  * FUNCTION:    AcpiDsEvalRegionOperands
504  *
505  * PARAMETERS:  WalkState       - Current walk
506  *              Op              - A valid region Op object
507  *
508  * RETURN:      Status
509  *
510  * DESCRIPTION: Get region address and length
511  *              Called from AcpiDsExecEndOp during OpRegion parse tree walk
512  *
513  ******************************************************************************/
514 
515 ACPI_STATUS
516 AcpiDsEvalRegionOperands (
517     ACPI_WALK_STATE         *WalkState,
518     ACPI_PARSE_OBJECT       *Op)
519 {
520     ACPI_STATUS             Status;
521     ACPI_OPERAND_OBJECT     *ObjDesc;
522     ACPI_OPERAND_OBJECT     *OperandDesc;
523     ACPI_NAMESPACE_NODE     *Node;
524     ACPI_PARSE_OBJECT       *NextOp;
525 
526 
527     ACPI_FUNCTION_TRACE_PTR (DsEvalRegionOperands, Op);
528 
529 
530     /*
531      * This is where we evaluate the address and length fields of the
532      * OpRegion declaration
533      */
534     Node =  Op->Common.Node;
535 
536     /* NextOp points to the op that holds the SpaceID */
537 
538     NextOp = Op->Common.Value.Arg;
539 
540     /* NextOp points to address op */
541 
542     NextOp = NextOp->Common.Next;
543 
544     /* Evaluate/create the address and length operands */
545 
546     Status = AcpiDsCreateOperands (WalkState, NextOp);
547     if (ACPI_FAILURE (Status))
548     {
549         return_ACPI_STATUS (Status);
550     }
551 
552     /* Resolve the length and address operands to numbers */
553 
554     Status = AcpiExResolveOperands (
555         Op->Common.AmlOpcode, ACPI_WALK_OPERANDS, WalkState);
556     if (ACPI_FAILURE (Status))
557     {
558         return_ACPI_STATUS (Status);
559     }
560 
561     ObjDesc = AcpiNsGetAttachedObject (Node);
562     if (!ObjDesc)
563     {
564         return_ACPI_STATUS (AE_NOT_EXIST);
565     }
566 
567     /*
568      * Get the length operand and save it
569      * (at Top of stack)
570      */
571     OperandDesc = WalkState->Operands[WalkState->NumOperands - 1];
572 
573     ObjDesc->Region.Length = (UINT32) OperandDesc->Integer.Value;
574     AcpiUtRemoveReference (OperandDesc);
575 
576     /*
577      * Get the address and save it
578      * (at top of stack - 1)
579      */
580     OperandDesc = WalkState->Operands[WalkState->NumOperands - 2];
581 
582     ObjDesc->Region.Address = (ACPI_PHYSICAL_ADDRESS)
583         OperandDesc->Integer.Value;
584     AcpiUtRemoveReference (OperandDesc);
585 
586     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
587         ObjDesc, ACPI_FORMAT_UINT64 (ObjDesc->Region.Address),
588         ObjDesc->Region.Length));
589 
590     /* Now the address and length are valid for this opregion */
591 
592     ObjDesc->Region.Flags |= AOPOBJ_DATA_VALID;
593     return_ACPI_STATUS (Status);
594 }
595 
596 
597 /*******************************************************************************
598  *
599  * FUNCTION:    AcpiDsEvalTableRegionOperands
600  *
601  * PARAMETERS:  WalkState       - Current walk
602  *              Op              - A valid region Op object
603  *
604  * RETURN:      Status
605  *
606  * DESCRIPTION: Get region address and length.
607  *              Called from AcpiDsExecEndOp during DataTableRegion parse
608  *              tree walk.
609  *
610  ******************************************************************************/
611 
612 ACPI_STATUS
613 AcpiDsEvalTableRegionOperands (
614     ACPI_WALK_STATE         *WalkState,
615     ACPI_PARSE_OBJECT       *Op)
616 {
617     ACPI_STATUS             Status;
618     ACPI_OPERAND_OBJECT     *ObjDesc;
619     ACPI_OPERAND_OBJECT     **Operand;
620     ACPI_NAMESPACE_NODE     *Node;
621     ACPI_PARSE_OBJECT       *NextOp;
622     ACPI_TABLE_HEADER       *Table;
623     UINT32                  TableIndex;
624 
625 
626     ACPI_FUNCTION_TRACE_PTR (DsEvalTableRegionOperands, Op);
627 
628 
629     /*
630      * This is where we evaluate the Signature string, OemId string,
631      * and OemTableId string of the Data Table Region declaration
632      */
633     Node =  Op->Common.Node;
634 
635     /* NextOp points to Signature string op */
636 
637     NextOp = Op->Common.Value.Arg;
638 
639     /*
640      * Evaluate/create the Signature string, OemId string,
641      * and OemTableId string operands
642      */
643     Status = AcpiDsCreateOperands (WalkState, NextOp);
644     if (ACPI_FAILURE (Status))
645     {
646         return_ACPI_STATUS (Status);
647     }
648 
649     Operand = &WalkState->Operands[0];
650 
651     /*
652      * Resolve the Signature string, OemId string,
653      * and OemTableId string operands
654      */
655     Status = AcpiExResolveOperands (
656         Op->Common.AmlOpcode, ACPI_WALK_OPERANDS, WalkState);
657     if (ACPI_FAILURE (Status))
658     {
659         goto Cleanup;
660     }
661 
662     /* Find the ACPI table */
663 
664     Status = AcpiTbFindTable (
665         Operand[0]->String.Pointer,
666         Operand[1]->String.Pointer,
667         Operand[2]->String.Pointer, &TableIndex);
668     if (ACPI_FAILURE (Status))
669     {
670         if (Status == AE_NOT_FOUND)
671         {
672             ACPI_ERROR ((AE_INFO,
673                 "ACPI Table [%4.4s] OEM:(%s, %s) not found in RSDT/XSDT",
674                 Operand[0]->String.Pointer,
675                 Operand[1]->String.Pointer,
676                 Operand[2]->String.Pointer));
677         }
678         goto Cleanup;
679     }
680 
681     Status = AcpiGetTableByIndex (TableIndex, &Table);
682     if (ACPI_FAILURE (Status))
683     {
684         goto Cleanup;
685     }
686 
687     ObjDesc = AcpiNsGetAttachedObject (Node);
688     if (!ObjDesc)
689     {
690         Status = AE_NOT_EXIST;
691         goto Cleanup;
692     }
693 
694     ObjDesc->Region.Address = ACPI_PTR_TO_PHYSADDR (Table);
695     ObjDesc->Region.Length = Table->Length;
696 
697     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "RgnObj %p Addr %8.8X%8.8X Len %X\n",
698         ObjDesc, ACPI_FORMAT_UINT64 (ObjDesc->Region.Address),
699         ObjDesc->Region.Length));
700 
701     /* Now the address and length are valid for this opregion */
702 
703     ObjDesc->Region.Flags |= AOPOBJ_DATA_VALID;
704 
705 Cleanup:
706     AcpiUtRemoveReference (Operand[0]);
707     AcpiUtRemoveReference (Operand[1]);
708     AcpiUtRemoveReference (Operand[2]);
709 
710     return_ACPI_STATUS (Status);
711 }
712 
713 
714 /*******************************************************************************
715  *
716  * FUNCTION:    AcpiDsEvalDataObjectOperands
717  *
718  * PARAMETERS:  WalkState       - Current walk
719  *              Op              - A valid DataObject Op object
720  *              ObjDesc         - DataObject
721  *
722  * RETURN:      Status
723  *
724  * DESCRIPTION: Get the operands and complete the following data object types:
725  *              Buffer, Package.
726  *
727  ******************************************************************************/
728 
729 ACPI_STATUS
730 AcpiDsEvalDataObjectOperands (
731     ACPI_WALK_STATE         *WalkState,
732     ACPI_PARSE_OBJECT       *Op,
733     ACPI_OPERAND_OBJECT     *ObjDesc)
734 {
735     ACPI_STATUS             Status;
736     ACPI_OPERAND_OBJECT     *ArgDesc;
737     UINT32                  Length;
738 
739 
740     ACPI_FUNCTION_TRACE (DsEvalDataObjectOperands);
741 
742 
743     /* The first operand (for all of these data objects) is the length */
744 
745     /*
746      * Set proper index into operand stack for AcpiDsObjStackPush
747      * invoked inside AcpiDsCreateOperand.
748      */
749     WalkState->OperandIndex = WalkState->NumOperands;
750 
751     Status = AcpiDsCreateOperand (WalkState, Op->Common.Value.Arg, 1);
752     if (ACPI_FAILURE (Status))
753     {
754         return_ACPI_STATUS (Status);
755     }
756 
757     Status = AcpiExResolveOperands (WalkState->Opcode,
758         &(WalkState->Operands [WalkState->NumOperands -1]),
759         WalkState);
760     if (ACPI_FAILURE (Status))
761     {
762         return_ACPI_STATUS (Status);
763     }
764 
765     /* Extract length operand */
766 
767     ArgDesc = WalkState->Operands [WalkState->NumOperands - 1];
768     Length = (UINT32) ArgDesc->Integer.Value;
769 
770     /* Cleanup for length operand */
771 
772     Status = AcpiDsObjStackPop (1, WalkState);
773     if (ACPI_FAILURE (Status))
774     {
775         return_ACPI_STATUS (Status);
776     }
777 
778     AcpiUtRemoveReference (ArgDesc);
779 
780     /*
781      * Create the actual data object
782      */
783     switch (Op->Common.AmlOpcode)
784     {
785     case AML_BUFFER_OP:
786 
787         Status = AcpiDsBuildInternalBufferObj (
788             WalkState, Op, Length, &ObjDesc);
789         break;
790 
791     case AML_PACKAGE_OP:
792     case AML_VARIABLE_PACKAGE_OP:
793 
794         Status = AcpiDsBuildInternalPackageObj (
795             WalkState, Op, Length, &ObjDesc);
796         break;
797 
798     default:
799 
800         return_ACPI_STATUS (AE_AML_BAD_OPCODE);
801     }
802 
803     if (ACPI_SUCCESS (Status))
804     {
805         /*
806          * Return the object in the WalkState, unless the parent is a package -
807          * in this case, the return object will be stored in the parse tree
808          * for the package.
809          */
810         if ((!Op->Common.Parent) ||
811             ((Op->Common.Parent->Common.AmlOpcode != AML_PACKAGE_OP) &&
812              (Op->Common.Parent->Common.AmlOpcode != AML_VARIABLE_PACKAGE_OP) &&
813              (Op->Common.Parent->Common.AmlOpcode != AML_NAME_OP)))
814         {
815             WalkState->ResultObj = ObjDesc;
816         }
817     }
818 
819     return_ACPI_STATUS (Status);
820 }
821 
822 
823 /*******************************************************************************
824  *
825  * FUNCTION:    AcpiDsEvalBankFieldOperands
826  *
827  * PARAMETERS:  WalkState       - Current walk
828  *              Op              - A valid BankField Op object
829  *
830  * RETURN:      Status
831  *
832  * DESCRIPTION: Get BankField BankValue
833  *              Called from AcpiDsExecEndOp during BankField parse tree walk
834  *
835  ******************************************************************************/
836 
837 ACPI_STATUS
838 AcpiDsEvalBankFieldOperands (
839     ACPI_WALK_STATE         *WalkState,
840     ACPI_PARSE_OBJECT       *Op)
841 {
842     ACPI_STATUS             Status;
843     ACPI_OPERAND_OBJECT     *ObjDesc;
844     ACPI_OPERAND_OBJECT     *OperandDesc;
845     ACPI_NAMESPACE_NODE     *Node;
846     ACPI_PARSE_OBJECT       *NextOp;
847     ACPI_PARSE_OBJECT       *Arg;
848 
849 
850     ACPI_FUNCTION_TRACE_PTR (DsEvalBankFieldOperands, Op);
851 
852 
853     /*
854      * This is where we evaluate the BankValue field of the
855      * BankField declaration
856      */
857 
858     /* NextOp points to the op that holds the Region */
859 
860     NextOp = Op->Common.Value.Arg;
861 
862     /* NextOp points to the op that holds the Bank Register */
863 
864     NextOp = NextOp->Common.Next;
865 
866     /* NextOp points to the op that holds the Bank Value */
867 
868     NextOp = NextOp->Common.Next;
869 
870     /*
871      * Set proper index into operand stack for AcpiDsObjStackPush
872      * invoked inside AcpiDsCreateOperand.
873      *
874      * We use WalkState->Operands[0] to store the evaluated BankValue
875      */
876     WalkState->OperandIndex = 0;
877 
878     Status = AcpiDsCreateOperand (WalkState, NextOp, 0);
879     if (ACPI_FAILURE (Status))
880     {
881         return_ACPI_STATUS (Status);
882     }
883 
884     Status = AcpiExResolveToValue (&WalkState->Operands[0], WalkState);
885     if (ACPI_FAILURE (Status))
886     {
887         return_ACPI_STATUS (Status);
888     }
889 
890     ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS,
891         AcpiPsGetOpcodeName (Op->Common.AmlOpcode), 1);
892     /*
893      * Get the BankValue operand and save it
894      * (at Top of stack)
895      */
896     OperandDesc = WalkState->Operands[0];
897 
898     /* Arg points to the start Bank Field */
899 
900     Arg = AcpiPsGetArg (Op, 4);
901     while (Arg)
902     {
903         /* Ignore OFFSET and ACCESSAS terms here */
904 
905         if (Arg->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)
906         {
907             Node = Arg->Common.Node;
908 
909             ObjDesc = AcpiNsGetAttachedObject (Node);
910             if (!ObjDesc)
911             {
912                 return_ACPI_STATUS (AE_NOT_EXIST);
913             }
914 
915             ObjDesc->BankField.Value = (UINT32) OperandDesc->Integer.Value;
916         }
917 
918         /* Move to next field in the list */
919 
920         Arg = Arg->Common.Next;
921     }
922 
923     AcpiUtRemoveReference (OperandDesc);
924     return_ACPI_STATUS (Status);
925 }
926