]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/contrib/dev/acpica/dsutils.c
Vendor import of the Intel ACPI CA 20010816 update.
[FreeBSD/FreeBSD.git] / sys / contrib / dev / acpica / dsutils.c
1 /*******************************************************************************
2  *
3  * Module Name: dsutils - Dispatcher utilities
4  *              $Revision: 68 $
5  *
6  ******************************************************************************/
7
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.
13  * All rights reserved.
14  *
15  * 2. License
16  *
17  * 2.1. This is your license from Intel Corp. under its intellectual property
18  * rights.  You may have additional license terms from the party that provided
19  * you this software, covering your right to use that party's intellectual
20  * property rights.
21  *
22  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23  * copy of the source code appearing in this file ("Covered Code") an
24  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25  * base code distributed originally by Intel ("Original Intel Code") to copy,
26  * make derivatives, distribute, use and display any portion of the Covered
27  * Code in any form, with the right to sublicense such rights; and
28  *
29  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30  * license (with the right to sublicense), under only those claims of Intel
31  * patents that are infringed by the Original Intel Code, to make, use, sell,
32  * offer to sell, and import the Covered Code and derivative works thereof
33  * solely to the minimum extent necessary to exercise the above copyright
34  * license, and in no event shall the patent license extend to any additions
35  * to or modifications of the Original Intel Code.  No other license or right
36  * is granted directly or by implication, estoppel or otherwise;
37  *
38  * The above copyright and patent license is granted only if the following
39  * conditions are met:
40  *
41  * 3. Conditions
42  *
43  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44  * Redistribution of source code of any substantial portion of the Covered
45  * Code or modification with rights to further distribute source must include
46  * the above Copyright Notice, the above License, this list of Conditions,
47  * and the following Disclaimer and Export Compliance provision.  In addition,
48  * Licensee must cause all Covered Code to which Licensee contributes to
49  * contain a file documenting the changes Licensee made to create that Covered
50  * Code and the date of any change.  Licensee must include in that file the
51  * documentation of any changes made by any predecessor Licensee.  Licensee
52  * must include a prominent statement that the modification is derived,
53  * directly or indirectly, from Original Intel Code.
54  *
55  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56  * Redistribution of source code of any substantial portion of the Covered
57  * Code or modification without rights to further distribute source must
58  * include the following Disclaimer and Export Compliance provision in the
59  * documentation and/or other materials provided with distribution.  In
60  * addition, Licensee may not authorize further sublicense of source of any
61  * portion of the Covered Code, and must include terms to the effect that the
62  * license from Licensee to its licensee is limited to the intellectual
63  * property embodied in the software Licensee provides to its licensee, and
64  * not to intellectual property embodied in modifications its licensee may
65  * make.
66  *
67  * 3.3. Redistribution of Executable. Redistribution in executable form of any
68  * substantial portion of the Covered Code or modification must reproduce the
69  * above Copyright Notice, and the following Disclaimer and Export Compliance
70  * provision in the documentation and/or other materials provided with the
71  * distribution.
72  *
73  * 3.4. Intel retains all right, title, and interest in and to the Original
74  * Intel Code.
75  *
76  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77  * Intel shall be used in advertising or otherwise to promote the sale, use or
78  * other dealings in products derived from or relating to the Covered Code
79  * without prior written authorization from Intel.
80  *
81  * 4. Disclaimer and Export Compliance
82  *
83  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89  * PARTICULAR PURPOSE.
90  *
91  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98  * LIMITED REMEDY.
99  *
100  * 4.3. Licensee shall not export, either directly or indirectly, any of this
101  * software or system incorporating such software without first obtaining any
102  * required license or other approval from the U. S. Department of Commerce or
103  * any other agency or department of the United States Government.  In the
104  * event Licensee exports any such software from the United States or
105  * re-exports any such software from a foreign destination, Licensee shall
106  * ensure that the distribution and export/re-export of the software is in
107  * compliance with all laws, regulations, orders, or other restrictions of the
108  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109  * any of its subsidiaries will export/re-export any technical data, process,
110  * software, or service, directly or indirectly, to any country for which the
111  * United States government or any agency thereof requires an export license,
112  * other governmental approval, or letter of assurance, without first obtaining
113  * such license, approval or letter.
114  *
115  *****************************************************************************/
116
117 #define __DSUTILS_C__
118
119 #include "acpi.h"
120 #include "acparser.h"
121 #include "amlcode.h"
122 #include "acdispat.h"
123 #include "acinterp.h"
124 #include "acnamesp.h"
125 #include "acdebug.h"
126
127 #define _COMPONENT          ACPI_DISPATCHER
128         MODULE_NAME         ("dsutils")
129
130
131 /*******************************************************************************
132  *
133  * FUNCTION:    AcpiDsIsResultUsed
134  *
135  * PARAMETERS:  Op
136  *              ResultObj
137  *              WalkState
138  *
139  * RETURN:      Status
140  *
141  * DESCRIPTION: Check if a result object will be used by the parent
142  *
143  ******************************************************************************/
144
145 BOOLEAN
146 AcpiDsIsResultUsed (
147     ACPI_PARSE_OBJECT       *Op,
148     ACPI_WALK_STATE         *WalkState)
149 {
150     ACPI_OPCODE_INFO        *ParentInfo;
151
152
153     FUNCTION_TRACE_PTR ("DsIsResultUsed", Op);
154
155
156     /* Must have both an Op and a Result Object */
157
158     if (!Op)
159     {
160         ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null Op\n"));
161         return_VALUE (TRUE);
162     }
163
164
165     /*
166      * If there is no parent, the result can't possibly be used!
167      * (An executing method typically has no parent, since each
168      * method is parsed separately)  However, a method that is
169      * invoked from another method has a parent.
170      */
171     if (!Op->Parent)
172     {
173         return_VALUE (FALSE);
174     }
175
176
177     /*
178      * Get info on the parent.  The root Op is AML_SCOPE
179      */
180
181     ParentInfo = AcpiPsGetOpcodeInfo (Op->Parent->Opcode);
182     if (ACPI_GET_OP_TYPE (ParentInfo) != ACPI_OP_TYPE_OPCODE)
183     {
184         ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown parent opcode. Op=%X\n", Op));
185         return_VALUE (FALSE);
186     }
187
188
189     /*
190      * Decide what to do with the result based on the parent.  If
191      * the parent opcode will not use the result, delete the object.
192      * Otherwise leave it as is, it will be deleted when it is used
193      * as an operand later.
194      */
195
196     switch (ACPI_GET_OP_CLASS (ParentInfo))
197     {
198     /*
199      * In these cases, the parent will never use the return object
200      */
201     case OPTYPE_CONTROL:        /* IF, ELSE, WHILE only */
202
203         switch (Op->Parent->Opcode)
204         {
205         case AML_RETURN_OP:
206
207             /* Never delete the return value associated with a return opcode */
208
209             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, 
210                 "Result used, [RETURN] opcode=%X Op=%X\n", Op->Opcode, Op));
211             return_VALUE (TRUE);
212             break;
213
214         case AML_IF_OP:
215         case AML_WHILE_OP:
216
217             /*
218              * If we are executing the predicate AND this is the predicate op,
219              * we will use the return value!
220              */
221
222             if ((WalkState->ControlState->Common.State == CONTROL_PREDICATE_EXECUTING) &&
223                 (WalkState->ControlState->Control.PredicateOp == Op))
224             {
225                 ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
226                     "Result used as a predicate, [IF/WHILE] opcode=%X Op=%X\n",
227                     Op->Opcode, Op));
228                 return_VALUE (TRUE);
229             }
230
231             break;
232         }
233
234
235         /* Fall through to not used case below */
236
237
238     case OPTYPE_NAMED_OBJECT:   /* Scope, method, etc. */
239
240         /*
241          * These opcodes allow TermArg(s) as operands and therefore
242          * method calls.  The result is used.
243          */
244         if ((Op->Parent->Opcode == AML_REGION_OP)               ||
245             (Op->Parent->Opcode == AML_CREATE_FIELD_OP)         ||
246             (Op->Parent->Opcode == AML_CREATE_BIT_FIELD_OP)     ||
247             (Op->Parent->Opcode == AML_CREATE_BYTE_FIELD_OP)    ||
248             (Op->Parent->Opcode == AML_CREATE_WORD_FIELD_OP)    ||
249             (Op->Parent->Opcode == AML_CREATE_DWORD_FIELD_OP)   ||
250             (Op->Parent->Opcode == AML_CREATE_QWORD_FIELD_OP))
251         {
252             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
253                 "Result used, [Region or CreateField] opcode=%X Op=%X\n",
254                 Op->Opcode, Op));
255             return_VALUE (TRUE);
256         }
257
258         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, 
259             "Result not used, Parent opcode=%X Op=%X\n", Op->Opcode, Op));
260
261         return_VALUE (FALSE);
262         break;
263
264     /*
265      * In all other cases. the parent will actually use the return
266      * object, so keep it.
267      */
268     default:
269         break;
270     }
271
272     return_VALUE (TRUE);
273 }
274
275
276 /*******************************************************************************
277  *
278  * FUNCTION:    AcpiDsDeleteResultIfNotUsed
279  *
280  * PARAMETERS:  Op
281  *              ResultObj
282  *              WalkState
283  *
284  * RETURN:      Status
285  *
286  * DESCRIPTION: Used after interpretation of an opcode.  If there is an internal
287  *              result descriptor, check if the parent opcode will actually use
288  *              this result.  If not, delete the result now so that it will
289  *              not become orphaned.
290  *
291  ******************************************************************************/
292
293 void
294 AcpiDsDeleteResultIfNotUsed (
295     ACPI_PARSE_OBJECT       *Op,
296     ACPI_OPERAND_OBJECT     *ResultObj,
297     ACPI_WALK_STATE         *WalkState)
298 {
299     ACPI_OPERAND_OBJECT     *ObjDesc;
300     ACPI_STATUS             Status;
301
302
303     FUNCTION_TRACE_PTR ("DsDeleteResultIfNotUsed", ResultObj);
304
305
306     if (!Op)
307     {
308         ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null Op\n"));
309         return_VOID;
310     }
311
312     if (!ResultObj)
313     {
314         return_VOID;
315     }
316
317
318     if (!AcpiDsIsResultUsed (Op, WalkState))
319     {
320         /*
321          * Must pop the result stack (ObjDesc should be equal to ResultObj)
322          */
323         Status = AcpiDsResultPop (&ObjDesc, WalkState);
324         if (ACPI_SUCCESS (Status))
325         {
326             AcpiUtRemoveReference (ResultObj);
327         }
328     }
329
330     return_VOID;
331 }
332
333
334 /*******************************************************************************
335  *
336  * FUNCTION:    AcpiDsCreateOperand
337  *
338  * PARAMETERS:  WalkState
339  *              Arg
340  *
341  * RETURN:      Status
342  *
343  * DESCRIPTION: Translate a parse tree object that is an argument to an AML
344  *              opcode to the equivalent interpreter object.  This may include
345  *              looking up a name or entering a new name into the internal
346  *              namespace.
347  *
348  ******************************************************************************/
349
350 ACPI_STATUS
351 AcpiDsCreateOperand (
352     ACPI_WALK_STATE         *WalkState,
353     ACPI_PARSE_OBJECT       *Arg,
354     UINT32                  ArgIndex)
355 {
356     ACPI_STATUS             Status = AE_OK;
357     NATIVE_CHAR             *NameString;
358     UINT32                  NameLength;
359     ACPI_OBJECT_TYPE8       DataType;
360     ACPI_OPERAND_OBJECT     *ObjDesc;
361     ACPI_PARSE_OBJECT       *ParentOp;
362     UINT16                  Opcode;
363     UINT32                  Flags;
364     OPERATING_MODE          InterpreterMode;
365
366
367     FUNCTION_TRACE_PTR ("DsCreateOperand", Arg);
368
369
370     /* A valid name must be looked up in the namespace */
371
372     if ((Arg->Opcode == AML_INT_NAMEPATH_OP) &&
373         (Arg->Value.String))
374     {
375         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Getting a name: Arg=%p\n", Arg));
376
377         /* Get the entire name string from the AML stream */
378
379         Status = AcpiExGetNameString (ACPI_TYPE_ANY, Arg->Value.Buffer,
380                         &NameString, &NameLength);
381
382         if (ACPI_FAILURE (Status))
383         {
384             return_ACPI_STATUS (Status);
385         }
386
387         /*
388          * All prefixes have been handled, and the name is
389          * in NameString
390          */
391
392         /*
393          * Differentiate between a namespace "create" operation
394          * versus a "lookup" operation (IMODE_LOAD_PASS2 vs.
395          * IMODE_EXECUTE) in order to support the creation of
396          * namespace objects during the execution of control methods.
397          */
398         ParentOp = Arg->Parent;
399         if ((AcpiPsIsNodeOp (ParentOp->Opcode)) &&
400             (ParentOp->Opcode != AML_INT_METHODCALL_OP) &&
401             (ParentOp->Opcode != AML_REGION_OP) &&
402             (ParentOp->Opcode != AML_INT_NAMEPATH_OP))
403         {
404             /* Enter name into namespace if not found */
405
406             InterpreterMode = IMODE_LOAD_PASS2;
407         }
408
409         else
410         {
411             /* Return a failure if name not found */
412
413             InterpreterMode = IMODE_EXECUTE;
414         }
415
416         Status = AcpiNsLookup (WalkState->ScopeInfo, NameString,
417                                 ACPI_TYPE_ANY, InterpreterMode,
418                                 NS_SEARCH_PARENT | NS_DONT_OPEN_SCOPE,
419                                 WalkState,
420                                 (ACPI_NAMESPACE_NODE **) &ObjDesc);
421
422         /* Free the namestring created above */
423
424         ACPI_MEM_FREE (NameString);
425
426         /*
427          * The only case where we pass through (ignore) a NOT_FOUND
428          * error is for the CondRefOf opcode.
429          */
430
431         if (Status == AE_NOT_FOUND)
432         {
433             if (ParentOp->Opcode == AML_COND_REF_OF_OP)
434             {
435                 /*
436                  * For the Conditional Reference op, it's OK if
437                  * the name is not found;  We just need a way to
438                  * indicate this to the interpreter, set the
439                  * object to the root
440                  */
441                 ObjDesc = (ACPI_OPERAND_OBJECT  *) AcpiGbl_RootNode;
442                 Status = AE_OK;
443             }
444
445             else
446             {
447                 /*
448                  * We just plain didn't find it -- which is a
449                  * very serious error at this point
450                  */
451                 Status = AE_AML_NAME_NOT_FOUND;
452             }
453         }
454
455         /* Check status from the lookup */
456
457         if (ACPI_FAILURE (Status))
458         {
459             return_ACPI_STATUS (Status);
460         }
461
462         /* Put the resulting object onto the current object stack */
463
464         Status = AcpiDsObjStackPush (ObjDesc, WalkState);
465         if (ACPI_FAILURE (Status))
466         {
467             return_ACPI_STATUS (Status);
468         }
469         DEBUGGER_EXEC (AcpiDbDisplayArgumentObject (ObjDesc, WalkState));
470     }
471
472
473     else
474     {
475         /* Check for null name case */
476
477         if (Arg->Opcode == AML_INT_NAMEPATH_OP)
478         {
479             /*
480              * If the name is null, this means that this is an
481              * optional result parameter that was not specified
482              * in the original ASL.  Create an Reference for a
483              * placeholder
484              */
485             Opcode = AML_ZERO_OP;       /* Has no arguments! */
486
487             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Null namepath: Arg=%p\n", Arg));
488
489             /*
490              * TBD: [Investigate] anything else needed for the
491              * zero op lvalue?
492              */
493         }
494
495         else
496         {
497             Opcode = Arg->Opcode;
498         }
499
500
501         /* Get the data type of the argument */
502
503         DataType = AcpiDsMapOpcodeToDataType (Opcode, &Flags);
504         if (DataType == INTERNAL_TYPE_INVALID)
505         {
506             return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
507         }
508
509         if (Flags & OP_HAS_RETURN_VALUE)
510         {
511             ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
512                 "Argument previously created, already stacked \n"));
513
514             DEBUGGER_EXEC (AcpiDbDisplayArgumentObject (WalkState->Operands [WalkState->NumOperands - 1], WalkState));
515
516             /*
517              * Use value that was already previously returned
518              * by the evaluation of this argument
519              */
520             Status = AcpiDsResultPopFromBottom (&ObjDesc, WalkState);
521             if (ACPI_FAILURE (Status))
522             {
523                 /*
524                  * Only error is underflow, and this indicates
525                  * a missing or null operand!
526                  */
527                 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Missing or null operand, %s\n", 
528                     AcpiFormatException (Status)));
529                 return_ACPI_STATUS (Status);
530             }
531
532         }
533
534         else
535         {
536             /* Create an ACPI_INTERNAL_OBJECT for the argument */
537
538             ObjDesc = AcpiUtCreateInternalObject (DataType);
539             if (!ObjDesc)
540             {
541                 return_ACPI_STATUS (AE_NO_MEMORY);
542             }
543
544             /* Initialize the new object */
545
546             Status = AcpiDsInitObjectFromOp (WalkState, Arg,
547                                                 Opcode, &ObjDesc);
548             if (ACPI_FAILURE (Status))
549             {
550                 AcpiUtDeleteObjectDesc (ObjDesc);
551                 return_ACPI_STATUS (Status);
552             }
553        }
554
555         /* Put the operand object on the object stack */
556
557         Status = AcpiDsObjStackPush (ObjDesc, WalkState);
558         if (ACPI_FAILURE (Status))
559         {
560             return_ACPI_STATUS (Status);
561         }
562
563         DEBUGGER_EXEC (AcpiDbDisplayArgumentObject (ObjDesc, WalkState));
564     }
565
566     return_ACPI_STATUS (AE_OK);
567 }
568
569
570 /*******************************************************************************
571  *
572  * FUNCTION:    AcpiDsCreateOperands
573  *
574  * PARAMETERS:  FirstArg            - First argument of a parser argument tree
575  *
576  * RETURN:      Status
577  *
578  * DESCRIPTION: Convert an operator's arguments from a parse tree format to
579  *              namespace objects and place those argument object on the object
580  *              stack in preparation for evaluation by the interpreter.
581  *
582  ******************************************************************************/
583
584 ACPI_STATUS
585 AcpiDsCreateOperands (
586     ACPI_WALK_STATE         *WalkState,
587     ACPI_PARSE_OBJECT       *FirstArg)
588 {
589     ACPI_STATUS             Status = AE_OK;
590     ACPI_PARSE_OBJECT       *Arg;
591     UINT32                  ArgCount = 0;
592
593
594     FUNCTION_TRACE_PTR ("DsCreateOperands", FirstArg);
595
596     /* For all arguments in the list... */
597
598     Arg = FirstArg;
599     while (Arg)
600     {
601         Status = AcpiDsCreateOperand (WalkState, Arg, ArgCount);
602         if (ACPI_FAILURE (Status))
603         {
604             goto Cleanup;
605         }
606
607         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Arg #%d (%p) done, Arg1=%p\n",
608             ArgCount, Arg, FirstArg));
609
610         /* Move on to next argument, if any */
611
612         Arg = Arg->Next;
613         ArgCount++;
614     }
615
616     return_ACPI_STATUS (Status);
617
618
619 Cleanup:
620     /*
621      * We must undo everything done above; meaning that we must
622      * pop everything off of the operand stack and delete those
623      * objects
624      */
625
626     AcpiDsObjStackPopAndDelete (ArgCount, WalkState);
627
628     ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "While creating Arg %d - %s\n",
629         (ArgCount + 1), AcpiFormatException (Status)));
630     return_ACPI_STATUS (Status);
631 }
632
633
634 /*******************************************************************************
635  *
636  * FUNCTION:    AcpiDsResolveOperands
637  *
638  * PARAMETERS:  WalkState           - Current walk state with operands on stack
639  *
640  * RETURN:      Status
641  *
642  * DESCRIPTION: Resolve all operands to their values.  Used to prepare
643  *              arguments to a control method invocation (a call from one
644  *              method to another.)
645  *
646  ******************************************************************************/
647
648 ACPI_STATUS
649 AcpiDsResolveOperands (
650     ACPI_WALK_STATE         *WalkState)
651 {
652     UINT32                  i;
653     ACPI_STATUS             Status = AE_OK;
654
655
656     FUNCTION_TRACE_PTR ("DsResolveOperands", WalkState);
657
658
659     /*
660      * Attempt to resolve each of the valid operands
661      * Method arguments are passed by value, not by reference
662      */
663
664     /*
665      * TBD: [Investigate] Note from previous parser:
666      *   RefOf problem with AcpiExResolveToValue() conversion.
667      */
668
669     for (i = 0; i < WalkState->NumOperands; i++)
670     {
671         Status = AcpiExResolveToValue (&WalkState->Operands[i], WalkState);
672         if (ACPI_FAILURE (Status))
673         {
674             break;
675         }
676     }
677
678     return_ACPI_STATUS (Status);
679 }
680
681
682 /*******************************************************************************
683  *
684  * FUNCTION:    AcpiDsMapOpcodeToDataType
685  *
686  * PARAMETERS:  Opcode          - AML opcode to map
687  *              OutFlags        - Additional info about the opcode
688  *
689  * RETURN:      The ACPI type associated with the opcode
690  *
691  * DESCRIPTION: Convert a raw AML opcode to the associated ACPI data type,
692  *              if any.  If the opcode returns a value as part of the
693  *              intepreter execution, a flag is returned in OutFlags.
694  *
695  ******************************************************************************/
696
697 ACPI_OBJECT_TYPE8
698 AcpiDsMapOpcodeToDataType (
699     UINT16                  Opcode,
700     UINT32                  *OutFlags)
701 {
702     ACPI_OBJECT_TYPE8       DataType = INTERNAL_TYPE_INVALID;
703     ACPI_OPCODE_INFO        *OpInfo;
704     UINT32                  Flags = 0;
705
706
707     PROC_NAME ("DsMapOpcodeToDataType");
708
709
710     OpInfo = AcpiPsGetOpcodeInfo (Opcode);
711     if (ACPI_GET_OP_TYPE (OpInfo) != ACPI_OP_TYPE_OPCODE)
712     {
713         /* Unknown opcode */
714
715         ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown AML opcode: %x\n", Opcode));
716         return (DataType);
717     }
718
719     switch (ACPI_GET_OP_CLASS (OpInfo))
720     {
721
722     case OPTYPE_LITERAL:
723
724         switch (Opcode)
725         {
726         case AML_BYTE_OP:
727         case AML_WORD_OP:
728         case AML_DWORD_OP:
729         case AML_QWORD_OP:
730
731             DataType = ACPI_TYPE_INTEGER;
732             break;
733
734
735         case AML_STRING_OP:
736
737             DataType = ACPI_TYPE_STRING;
738             break;
739
740         case AML_INT_NAMEPATH_OP:
741             DataType = INTERNAL_TYPE_REFERENCE;
742             break;
743
744         default:
745             ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, 
746                 "Unknown (type LITERAL) AML opcode: %x\n", Opcode));
747             break;
748         }
749         break;
750
751
752     case OPTYPE_DATA_TERM:
753
754         switch (Opcode)
755         {
756         case AML_BUFFER_OP:
757
758             DataType = ACPI_TYPE_BUFFER;
759             break;
760
761         case AML_PACKAGE_OP:
762         case AML_VAR_PACKAGE_OP:
763
764             DataType = ACPI_TYPE_PACKAGE;
765             break;
766
767         default:
768             ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
769                 "Unknown (type DATA_TERM) AML opcode: %x\n", Opcode));
770             break;
771         }
772         break;
773
774
775     case OPTYPE_CONSTANT:
776     case OPTYPE_METHOD_ARGUMENT:
777     case OPTYPE_LOCAL_VARIABLE:
778
779         DataType = INTERNAL_TYPE_REFERENCE;
780         break;
781
782
783     case OPTYPE_MONADIC2:
784     case OPTYPE_MONADIC2R:
785     case OPTYPE_DYADIC2:
786     case OPTYPE_DYADIC2R:
787     case OPTYPE_DYADIC2S:
788     case OPTYPE_TRIADIC:
789     case OPTYPE_QUADRADIC:
790     case OPTYPE_HEXADIC:
791     case OPTYPE_RETURN:
792
793         Flags = OP_HAS_RETURN_VALUE;
794         DataType = ACPI_TYPE_ANY;
795         break;
796
797
798     case OPTYPE_METHOD_CALL:
799
800         Flags = OP_HAS_RETURN_VALUE;
801         DataType = ACPI_TYPE_METHOD;
802         break;
803
804
805     case OPTYPE_NAMED_OBJECT:
806
807         DataType = AcpiDsMapNamedOpcodeToDataType (Opcode);
808         break;
809
810
811     case OPTYPE_DYADIC1:
812     case OPTYPE_CONTROL:
813
814         /* No mapping needed at this time */
815
816         break;
817
818
819     default:
820
821         ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
822             "Unimplemented data type opcode: %x\n", Opcode));
823         break;
824     }
825
826     /* Return flags to caller if requested */
827
828     if (OutFlags)
829     {
830         *OutFlags = Flags;
831     }
832
833     return (DataType);
834 }
835
836
837 /*******************************************************************************
838  *
839  * FUNCTION:    AcpiDsMapNamedOpcodeToDataType
840  *
841  * PARAMETERS:  Opcode              - The Named AML opcode to map
842  *
843  * RETURN:      The ACPI type associated with the named opcode
844  *
845  * DESCRIPTION: Convert a raw Named AML opcode to the associated data type.
846  *              Named opcodes are a subsystem of the AML opcodes.
847  *
848  ******************************************************************************/
849
850 ACPI_OBJECT_TYPE8
851 AcpiDsMapNamedOpcodeToDataType (
852     UINT16                  Opcode)
853 {
854     ACPI_OBJECT_TYPE8       DataType;
855
856
857     /* Decode Opcode */
858
859     switch (Opcode)
860     {
861     case AML_SCOPE_OP:
862         DataType = INTERNAL_TYPE_SCOPE;
863         break;
864
865     case AML_DEVICE_OP:
866         DataType = ACPI_TYPE_DEVICE;
867         break;
868
869     case AML_THERMAL_ZONE_OP:
870         DataType = ACPI_TYPE_THERMAL;
871         break;
872
873     case AML_METHOD_OP:
874         DataType = ACPI_TYPE_METHOD;
875         break;
876
877     case AML_POWER_RES_OP:
878         DataType = ACPI_TYPE_POWER;
879         break;
880
881     case AML_PROCESSOR_OP:
882         DataType = ACPI_TYPE_PROCESSOR;
883         break;
884
885     case AML_FIELD_OP:                              /* FieldOp */
886         DataType = INTERNAL_TYPE_FIELD_DEFN;
887         break;
888
889     case AML_INDEX_FIELD_OP:                        /* IndexFieldOp */
890         DataType = INTERNAL_TYPE_INDEX_FIELD_DEFN;
891         break;
892
893     case AML_BANK_FIELD_OP:                         /* BankFieldOp */
894         DataType = INTERNAL_TYPE_BANK_FIELD_DEFN;
895         break;
896
897     case AML_INT_NAMEDFIELD_OP:                     /* NO CASE IN ORIGINAL  */
898         DataType = ACPI_TYPE_ANY;
899         break;
900
901     case AML_NAME_OP:                               /* NameOp - special code in original */
902     case AML_INT_NAMEPATH_OP:
903         DataType = ACPI_TYPE_ANY;
904         break;
905
906     case AML_ALIAS_OP:
907         DataType = INTERNAL_TYPE_ALIAS;
908         break;
909
910     case AML_MUTEX_OP:
911         DataType = ACPI_TYPE_MUTEX;
912         break;
913
914     case AML_EVENT_OP:
915         DataType = ACPI_TYPE_EVENT;
916         break;
917
918     case AML_REGION_OP:
919         DataType = ACPI_TYPE_REGION;
920         break;
921
922
923     default:
924         DataType = ACPI_TYPE_ANY;
925         break;
926
927     }
928
929     return (DataType);
930 }
931
932