xref: /titanic_51/usr/src/uts/intel/io/acpica/executer/exresolv.c (revision 613a2f6ba31e891e3d947a356daf5e563d43c1ce)
1 
2 /******************************************************************************
3  *
4  * Module Name: exresolv - AML Interpreter object resolution
5  *
6  *****************************************************************************/
7 
8 /******************************************************************************
9  *
10  * 1. Copyright Notice
11  *
12  * Some or all of this work - Copyright (c) 1999 - 2009, 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 __EXRESOLV_C__
118 
119 #include "acpi.h"
120 #include "accommon.h"
121 #include "amlcode.h"
122 #include "acdispat.h"
123 #include "acinterp.h"
124 #include "acnamesp.h"
125 
126 
127 #define _COMPONENT          ACPI_EXECUTER
128         ACPI_MODULE_NAME    ("exresolv")
129 
130 /* Local prototypes */
131 
132 static ACPI_STATUS
133 AcpiExResolveObjectToValue (
134     ACPI_OPERAND_OBJECT     **StackPtr,
135     ACPI_WALK_STATE         *WalkState);
136 
137 
138 /*******************************************************************************
139  *
140  * FUNCTION:    AcpiExResolveToValue
141  *
142  * PARAMETERS:  **StackPtr          - Points to entry on ObjStack, which can
143  *                                    be either an (ACPI_OPERAND_OBJECT *)
144  *                                    or an ACPI_HANDLE.
145  *              WalkState           - Current method state
146  *
147  * RETURN:      Status
148  *
149  * DESCRIPTION: Convert Reference objects to values
150  *
151  ******************************************************************************/
152 
153 ACPI_STATUS
154 AcpiExResolveToValue (
155     ACPI_OPERAND_OBJECT     **StackPtr,
156     ACPI_WALK_STATE         *WalkState)
157 {
158     ACPI_STATUS             Status;
159 
160 
161     ACPI_FUNCTION_TRACE_PTR (ExResolveToValue, StackPtr);
162 
163 
164     if (!StackPtr || !*StackPtr)
165     {
166         ACPI_ERROR ((AE_INFO, "Internal - null pointer"));
167         return_ACPI_STATUS (AE_AML_NO_OPERAND);
168     }
169 
170     /*
171      * The entity pointed to by the StackPtr can be either
172      * 1) A valid ACPI_OPERAND_OBJECT, or
173      * 2) A ACPI_NAMESPACE_NODE (NamedObj)
174      */
175     if (ACPI_GET_DESCRIPTOR_TYPE (*StackPtr) == ACPI_DESC_TYPE_OPERAND)
176     {
177         Status = AcpiExResolveObjectToValue (StackPtr, WalkState);
178         if (ACPI_FAILURE (Status))
179         {
180             return_ACPI_STATUS (Status);
181         }
182 
183         if (!*StackPtr)
184         {
185             ACPI_ERROR ((AE_INFO, "Internal - null pointer"));
186             return_ACPI_STATUS (AE_AML_NO_OPERAND);
187         }
188     }
189 
190     /*
191      * Object on the stack may have changed if AcpiExResolveObjectToValue()
192      * was called (i.e., we can't use an _else_ here.)
193      */
194     if (ACPI_GET_DESCRIPTOR_TYPE (*StackPtr) == ACPI_DESC_TYPE_NAMED)
195     {
196         Status = AcpiExResolveNodeToValue (
197                         ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, StackPtr),
198                         WalkState);
199         if (ACPI_FAILURE (Status))
200         {
201             return_ACPI_STATUS (Status);
202         }
203     }
204 
205     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Resolved object %p\n", *StackPtr));
206     return_ACPI_STATUS (AE_OK);
207 }
208 
209 
210 /*******************************************************************************
211  *
212  * FUNCTION:    AcpiExResolveObjectToValue
213  *
214  * PARAMETERS:  StackPtr        - Pointer to an internal object
215  *              WalkState       - Current method state
216  *
217  * RETURN:      Status
218  *
219  * DESCRIPTION: Retrieve the value from an internal object. The Reference type
220  *              uses the associated AML opcode to determine the value.
221  *
222  ******************************************************************************/
223 
224 static ACPI_STATUS
225 AcpiExResolveObjectToValue (
226     ACPI_OPERAND_OBJECT     **StackPtr,
227     ACPI_WALK_STATE         *WalkState)
228 {
229     ACPI_STATUS             Status = AE_OK;
230     ACPI_OPERAND_OBJECT     *StackDesc;
231     ACPI_OPERAND_OBJECT     *ObjDesc = NULL;
232     UINT8                   RefType;
233 
234 
235     ACPI_FUNCTION_TRACE (ExResolveObjectToValue);
236 
237 
238     StackDesc = *StackPtr;
239 
240     /* This is an ACPI_OPERAND_OBJECT  */
241 
242     switch (StackDesc->Common.Type)
243     {
244     case ACPI_TYPE_LOCAL_REFERENCE:
245 
246         RefType = StackDesc->Reference.Class;
247 
248         switch (RefType)
249         {
250         case ACPI_REFCLASS_LOCAL:
251         case ACPI_REFCLASS_ARG:
252 
253             /*
254              * Get the local from the method's state info
255              * Note: this increments the local's object reference count
256              */
257             Status = AcpiDsMethodDataGetValue (RefType,
258                             StackDesc->Reference.Value, WalkState, &ObjDesc);
259             if (ACPI_FAILURE (Status))
260             {
261                 return_ACPI_STATUS (Status);
262             }
263 
264             ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Arg/Local %X] ValueObj is %p\n",
265                 StackDesc->Reference.Value, ObjDesc));
266 
267             /*
268              * Now we can delete the original Reference Object and
269              * replace it with the resolved value
270              */
271             AcpiUtRemoveReference (StackDesc);
272             *StackPtr = ObjDesc;
273             break;
274 
275 
276         case ACPI_REFCLASS_INDEX:
277 
278             switch (StackDesc->Reference.TargetType)
279             {
280             case ACPI_TYPE_BUFFER_FIELD:
281 
282                 /* Just return - do not dereference */
283                 break;
284 
285 
286             case ACPI_TYPE_PACKAGE:
287 
288                 /* If method call or CopyObject - do not dereference */
289 
290                 if ((WalkState->Opcode == AML_INT_METHODCALL_OP) ||
291                     (WalkState->Opcode == AML_COPY_OP))
292                 {
293                     break;
294                 }
295 
296                 /* Otherwise, dereference the PackageIndex to a package element */
297 
298                 ObjDesc = *StackDesc->Reference.Where;
299                 if (ObjDesc)
300                 {
301                     /*
302                      * Valid object descriptor, copy pointer to return value
303                      * (i.e., dereference the package index)
304                      * Delete the ref object, increment the returned object
305                      */
306                     AcpiUtRemoveReference (StackDesc);
307                     AcpiUtAddReference (ObjDesc);
308                     *StackPtr = ObjDesc;
309                 }
310                 else
311                 {
312                     /*
313                      * A NULL object descriptor means an uninitialized element of
314                      * the package, can't dereference it
315                      */
316                     ACPI_ERROR ((AE_INFO,
317                         "Attempt to dereference an Index to NULL package element Idx=%p",
318                         StackDesc));
319                     Status = AE_AML_UNINITIALIZED_ELEMENT;
320                 }
321                 break;
322 
323 
324             default:
325 
326                 /* Invalid reference object */
327 
328                 ACPI_ERROR ((AE_INFO,
329                     "Unknown TargetType %X in Index/Reference object %p",
330                     StackDesc->Reference.TargetType, StackDesc));
331                 Status = AE_AML_INTERNAL;
332                 break;
333             }
334             break;
335 
336 
337         case ACPI_REFCLASS_REFOF:
338         case ACPI_REFCLASS_DEBUG:
339         case ACPI_REFCLASS_TABLE:
340 
341             /* Just leave the object as-is, do not dereference */
342 
343             break;
344 
345         case ACPI_REFCLASS_NAME:   /* Reference to a named object */
346 
347             /* Dereference the name */
348 
349             if ((StackDesc->Reference.Node->Type == ACPI_TYPE_DEVICE) ||
350                 (StackDesc->Reference.Node->Type == ACPI_TYPE_THERMAL))
351             {
352                 /* These node types do not have 'real' subobjects */
353 
354                 *StackPtr = (void *) StackDesc->Reference.Node;
355             }
356             else
357             {
358                 /* Get the object pointed to by the namespace node */
359 
360                 *StackPtr = (StackDesc->Reference.Node)->Object;
361                 AcpiUtAddReference (*StackPtr);
362             }
363 
364             AcpiUtRemoveReference (StackDesc);
365             break;
366 
367         default:
368 
369             ACPI_ERROR ((AE_INFO,
370                 "Unknown Reference type %X in %p", RefType, StackDesc));
371             Status = AE_AML_INTERNAL;
372             break;
373         }
374         break;
375 
376 
377     case ACPI_TYPE_BUFFER:
378 
379         Status = AcpiDsGetBufferArguments (StackDesc);
380         break;
381 
382 
383     case ACPI_TYPE_PACKAGE:
384 
385         Status = AcpiDsGetPackageArguments (StackDesc);
386         break;
387 
388 
389     case ACPI_TYPE_BUFFER_FIELD:
390     case ACPI_TYPE_LOCAL_REGION_FIELD:
391     case ACPI_TYPE_LOCAL_BANK_FIELD:
392     case ACPI_TYPE_LOCAL_INDEX_FIELD:
393 
394         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "FieldRead SourceDesc=%p Type=%X\n",
395             StackDesc, StackDesc->Common.Type));
396 
397         Status = AcpiExReadDataFromField (WalkState, StackDesc, &ObjDesc);
398 
399         /* Remove a reference to the original operand, then override */
400 
401         AcpiUtRemoveReference (*StackPtr);
402         *StackPtr = (void *) ObjDesc;
403         break;
404 
405     default:
406         break;
407     }
408 
409     return_ACPI_STATUS (Status);
410 }
411 
412 
413 /*******************************************************************************
414  *
415  * FUNCTION:    AcpiExResolveMultiple
416  *
417  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
418  *              Operand             - Starting point for resolution
419  *              ReturnType          - Where the object type is returned
420  *              ReturnDesc          - Where the resolved object is returned
421  *
422  * RETURN:      Status
423  *
424  * DESCRIPTION: Return the base object and type.  Traverse a reference list if
425  *              necessary to get to the base object.
426  *
427  ******************************************************************************/
428 
429 ACPI_STATUS
430 AcpiExResolveMultiple (
431     ACPI_WALK_STATE         *WalkState,
432     ACPI_OPERAND_OBJECT     *Operand,
433     ACPI_OBJECT_TYPE        *ReturnType,
434     ACPI_OPERAND_OBJECT     **ReturnDesc)
435 {
436     ACPI_OPERAND_OBJECT     *ObjDesc = (void *) Operand;
437     ACPI_NAMESPACE_NODE     *Node;
438     ACPI_OBJECT_TYPE        Type;
439     ACPI_STATUS             Status;
440 
441 
442     ACPI_FUNCTION_TRACE (AcpiExResolveMultiple);
443 
444 
445     /* Operand can be either a namespace node or an operand descriptor */
446 
447     switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
448     {
449     case ACPI_DESC_TYPE_OPERAND:
450         Type = ObjDesc->Common.Type;
451         break;
452 
453     case ACPI_DESC_TYPE_NAMED:
454         Type = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type;
455         ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) ObjDesc);
456 
457         /* If we had an Alias node, use the attached object for type info */
458 
459         if (Type == ACPI_TYPE_LOCAL_ALIAS)
460         {
461             Type = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type;
462             ObjDesc = AcpiNsGetAttachedObject ((ACPI_NAMESPACE_NODE *) ObjDesc);
463         }
464         break;
465 
466     default:
467         return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
468     }
469 
470     /* If type is anything other than a reference, we are done */
471 
472     if (Type != ACPI_TYPE_LOCAL_REFERENCE)
473     {
474         goto Exit;
475     }
476 
477     /*
478      * For reference objects created via the RefOf, Index, or Load/LoadTable
479      * operators, we need to get to the base object (as per the ACPI
480      * specification of the ObjectType and SizeOf operators). This means
481      * traversing the list of possibly many nested references.
482      */
483     while (ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)
484     {
485         switch (ObjDesc->Reference.Class)
486         {
487         case ACPI_REFCLASS_REFOF:
488         case ACPI_REFCLASS_NAME:
489 
490             /* Dereference the reference pointer */
491 
492             if (ObjDesc->Reference.Class == ACPI_REFCLASS_REFOF)
493             {
494                 Node = ObjDesc->Reference.Object;
495             }
496             else /* AML_INT_NAMEPATH_OP */
497             {
498                 Node = ObjDesc->Reference.Node;
499             }
500 
501             /* All "References" point to a NS node */
502 
503             if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
504             {
505                 ACPI_ERROR ((AE_INFO,
506                     "Not a NS node %p [%s]",
507                     Node, AcpiUtGetDescriptorName (Node)));
508                 return_ACPI_STATUS (AE_AML_INTERNAL);
509             }
510 
511             /* Get the attached object */
512 
513             ObjDesc = AcpiNsGetAttachedObject (Node);
514             if (!ObjDesc)
515             {
516                 /* No object, use the NS node type */
517 
518                 Type = AcpiNsGetType (Node);
519                 goto Exit;
520             }
521 
522             /* Check for circular references */
523 
524             if (ObjDesc == Operand)
525             {
526                 return_ACPI_STATUS (AE_AML_CIRCULAR_REFERENCE);
527             }
528             break;
529 
530 
531         case ACPI_REFCLASS_INDEX:
532 
533             /* Get the type of this reference (index into another object) */
534 
535             Type = ObjDesc->Reference.TargetType;
536             if (Type != ACPI_TYPE_PACKAGE)
537             {
538                 goto Exit;
539             }
540 
541             /*
542              * The main object is a package, we want to get the type
543              * of the individual package element that is referenced by
544              * the index.
545              *
546              * This could of course in turn be another reference object.
547              */
548             ObjDesc = *(ObjDesc->Reference.Where);
549             if (!ObjDesc)
550             {
551                 /* NULL package elements are allowed */
552 
553                 Type = 0; /* Uninitialized */
554                 goto Exit;
555             }
556             break;
557 
558 
559         case ACPI_REFCLASS_TABLE:
560 
561             Type = ACPI_TYPE_DDB_HANDLE;
562             goto Exit;
563 
564 
565         case ACPI_REFCLASS_LOCAL:
566         case ACPI_REFCLASS_ARG:
567 
568             if (ReturnDesc)
569             {
570                 Status = AcpiDsMethodDataGetValue (ObjDesc->Reference.Class,
571                             ObjDesc->Reference.Value, WalkState, &ObjDesc);
572                 if (ACPI_FAILURE (Status))
573                 {
574                     return_ACPI_STATUS (Status);
575                 }
576                 AcpiUtRemoveReference (ObjDesc);
577             }
578             else
579             {
580                 Status = AcpiDsMethodDataGetNode (ObjDesc->Reference.Class,
581                             ObjDesc->Reference.Value, WalkState, &Node);
582                 if (ACPI_FAILURE (Status))
583                 {
584                     return_ACPI_STATUS (Status);
585                 }
586 
587                 ObjDesc = AcpiNsGetAttachedObject (Node);
588                 if (!ObjDesc)
589                 {
590                     Type = ACPI_TYPE_ANY;
591                     goto Exit;
592                 }
593             }
594             break;
595 
596 
597         case ACPI_REFCLASS_DEBUG:
598 
599             /* The Debug Object is of type "DebugObject" */
600 
601             Type = ACPI_TYPE_DEBUG_OBJECT;
602             goto Exit;
603 
604 
605         default:
606 
607             ACPI_ERROR ((AE_INFO,
608                 "Unknown Reference Class %2.2X", ObjDesc->Reference.Class));
609             return_ACPI_STATUS (AE_AML_INTERNAL);
610         }
611     }
612 
613     /*
614      * Now we are guaranteed to have an object that has not been created
615      * via the RefOf or Index operators.
616      */
617     Type = ObjDesc->Common.Type;
618 
619 
620 Exit:
621     /* Convert internal types to external types */
622 
623     switch (Type)
624     {
625     case ACPI_TYPE_LOCAL_REGION_FIELD:
626     case ACPI_TYPE_LOCAL_BANK_FIELD:
627     case ACPI_TYPE_LOCAL_INDEX_FIELD:
628 
629         Type = ACPI_TYPE_FIELD_UNIT;
630         break;
631 
632     case ACPI_TYPE_LOCAL_SCOPE:
633 
634         /* Per ACPI Specification, Scope is untyped */
635 
636         Type = ACPI_TYPE_ANY;
637         break;
638 
639     default:
640         /* No change to Type required */
641         break;
642     }
643 
644     *ReturnType = Type;
645     if (ReturnDesc)
646     {
647         *ReturnDesc = ObjDesc;
648     }
649     return_ACPI_STATUS (AE_OK);
650 }
651 
652 
653