xref: /minix3/minix/drivers/power/acpi/executer/exstore.c (revision 433d6423c39e34ec4b79c950597bb2d236f886be)
1*433d6423SLionel Sambuc /******************************************************************************
2*433d6423SLionel Sambuc  *
3*433d6423SLionel Sambuc  * Module Name: exstore - AML Interpreter object store support
4*433d6423SLionel Sambuc  *
5*433d6423SLionel Sambuc  *****************************************************************************/
6*433d6423SLionel Sambuc 
7*433d6423SLionel Sambuc /******************************************************************************
8*433d6423SLionel Sambuc  *
9*433d6423SLionel Sambuc  * 1. Copyright Notice
10*433d6423SLionel Sambuc  *
11*433d6423SLionel Sambuc  * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12*433d6423SLionel Sambuc  * All rights reserved.
13*433d6423SLionel Sambuc  *
14*433d6423SLionel Sambuc  * 2. License
15*433d6423SLionel Sambuc  *
16*433d6423SLionel Sambuc  * 2.1. This is your license from Intel Corp. under its intellectual property
17*433d6423SLionel Sambuc  * rights.  You may have additional license terms from the party that provided
18*433d6423SLionel Sambuc  * you this software, covering your right to use that party's intellectual
19*433d6423SLionel Sambuc  * property rights.
20*433d6423SLionel Sambuc  *
21*433d6423SLionel Sambuc  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22*433d6423SLionel Sambuc  * copy of the source code appearing in this file ("Covered Code") an
23*433d6423SLionel Sambuc  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24*433d6423SLionel Sambuc  * base code distributed originally by Intel ("Original Intel Code") to copy,
25*433d6423SLionel Sambuc  * make derivatives, distribute, use and display any portion of the Covered
26*433d6423SLionel Sambuc  * Code in any form, with the right to sublicense such rights; and
27*433d6423SLionel Sambuc  *
28*433d6423SLionel Sambuc  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29*433d6423SLionel Sambuc  * license (with the right to sublicense), under only those claims of Intel
30*433d6423SLionel Sambuc  * patents that are infringed by the Original Intel Code, to make, use, sell,
31*433d6423SLionel Sambuc  * offer to sell, and import the Covered Code and derivative works thereof
32*433d6423SLionel Sambuc  * solely to the minimum extent necessary to exercise the above copyright
33*433d6423SLionel Sambuc  * license, and in no event shall the patent license extend to any additions
34*433d6423SLionel Sambuc  * to or modifications of the Original Intel Code.  No other license or right
35*433d6423SLionel Sambuc  * is granted directly or by implication, estoppel or otherwise;
36*433d6423SLionel Sambuc  *
37*433d6423SLionel Sambuc  * The above copyright and patent license is granted only if the following
38*433d6423SLionel Sambuc  * conditions are met:
39*433d6423SLionel Sambuc  *
40*433d6423SLionel Sambuc  * 3. Conditions
41*433d6423SLionel Sambuc  *
42*433d6423SLionel Sambuc  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43*433d6423SLionel Sambuc  * Redistribution of source code of any substantial portion of the Covered
44*433d6423SLionel Sambuc  * Code or modification with rights to further distribute source must include
45*433d6423SLionel Sambuc  * the above Copyright Notice, the above License, this list of Conditions,
46*433d6423SLionel Sambuc  * and the following Disclaimer and Export Compliance provision.  In addition,
47*433d6423SLionel Sambuc  * Licensee must cause all Covered Code to which Licensee contributes to
48*433d6423SLionel Sambuc  * contain a file documenting the changes Licensee made to create that Covered
49*433d6423SLionel Sambuc  * Code and the date of any change.  Licensee must include in that file the
50*433d6423SLionel Sambuc  * documentation of any changes made by any predecessor Licensee.  Licensee
51*433d6423SLionel Sambuc  * must include a prominent statement that the modification is derived,
52*433d6423SLionel Sambuc  * directly or indirectly, from Original Intel Code.
53*433d6423SLionel Sambuc  *
54*433d6423SLionel Sambuc  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55*433d6423SLionel Sambuc  * Redistribution of source code of any substantial portion of the Covered
56*433d6423SLionel Sambuc  * Code or modification without rights to further distribute source must
57*433d6423SLionel Sambuc  * include the following Disclaimer and Export Compliance provision in the
58*433d6423SLionel Sambuc  * documentation and/or other materials provided with distribution.  In
59*433d6423SLionel Sambuc  * addition, Licensee may not authorize further sublicense of source of any
60*433d6423SLionel Sambuc  * portion of the Covered Code, and must include terms to the effect that the
61*433d6423SLionel Sambuc  * license from Licensee to its licensee is limited to the intellectual
62*433d6423SLionel Sambuc  * property embodied in the software Licensee provides to its licensee, and
63*433d6423SLionel Sambuc  * not to intellectual property embodied in modifications its licensee may
64*433d6423SLionel Sambuc  * make.
65*433d6423SLionel Sambuc  *
66*433d6423SLionel Sambuc  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67*433d6423SLionel Sambuc  * substantial portion of the Covered Code or modification must reproduce the
68*433d6423SLionel Sambuc  * above Copyright Notice, and the following Disclaimer and Export Compliance
69*433d6423SLionel Sambuc  * provision in the documentation and/or other materials provided with the
70*433d6423SLionel Sambuc  * distribution.
71*433d6423SLionel Sambuc  *
72*433d6423SLionel Sambuc  * 3.4. Intel retains all right, title, and interest in and to the Original
73*433d6423SLionel Sambuc  * Intel Code.
74*433d6423SLionel Sambuc  *
75*433d6423SLionel Sambuc  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76*433d6423SLionel Sambuc  * Intel shall be used in advertising or otherwise to promote the sale, use or
77*433d6423SLionel Sambuc  * other dealings in products derived from or relating to the Covered Code
78*433d6423SLionel Sambuc  * without prior written authorization from Intel.
79*433d6423SLionel Sambuc  *
80*433d6423SLionel Sambuc  * 4. Disclaimer and Export Compliance
81*433d6423SLionel Sambuc  *
82*433d6423SLionel Sambuc  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83*433d6423SLionel Sambuc  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84*433d6423SLionel Sambuc  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
85*433d6423SLionel Sambuc  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
86*433d6423SLionel Sambuc  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
87*433d6423SLionel Sambuc  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88*433d6423SLionel Sambuc  * PARTICULAR PURPOSE.
89*433d6423SLionel Sambuc  *
90*433d6423SLionel Sambuc  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91*433d6423SLionel Sambuc  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92*433d6423SLionel Sambuc  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93*433d6423SLionel Sambuc  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94*433d6423SLionel Sambuc  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95*433d6423SLionel Sambuc  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
96*433d6423SLionel Sambuc  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97*433d6423SLionel Sambuc  * LIMITED REMEDY.
98*433d6423SLionel Sambuc  *
99*433d6423SLionel Sambuc  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100*433d6423SLionel Sambuc  * software or system incorporating such software without first obtaining any
101*433d6423SLionel Sambuc  * required license or other approval from the U. S. Department of Commerce or
102*433d6423SLionel Sambuc  * any other agency or department of the United States Government.  In the
103*433d6423SLionel Sambuc  * event Licensee exports any such software from the United States or
104*433d6423SLionel Sambuc  * re-exports any such software from a foreign destination, Licensee shall
105*433d6423SLionel Sambuc  * ensure that the distribution and export/re-export of the software is in
106*433d6423SLionel Sambuc  * compliance with all laws, regulations, orders, or other restrictions of the
107*433d6423SLionel Sambuc  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108*433d6423SLionel Sambuc  * any of its subsidiaries will export/re-export any technical data, process,
109*433d6423SLionel Sambuc  * software, or service, directly or indirectly, to any country for which the
110*433d6423SLionel Sambuc  * United States government or any agency thereof requires an export license,
111*433d6423SLionel Sambuc  * other governmental approval, or letter of assurance, without first obtaining
112*433d6423SLionel Sambuc  * such license, approval or letter.
113*433d6423SLionel Sambuc  *
114*433d6423SLionel Sambuc  *****************************************************************************/
115*433d6423SLionel Sambuc 
116*433d6423SLionel Sambuc #define __EXSTORE_C__
117*433d6423SLionel Sambuc 
118*433d6423SLionel Sambuc #include "acpi.h"
119*433d6423SLionel Sambuc #include "accommon.h"
120*433d6423SLionel Sambuc #include "acdispat.h"
121*433d6423SLionel Sambuc #include "acinterp.h"
122*433d6423SLionel Sambuc #include "amlcode.h"
123*433d6423SLionel Sambuc #include "acnamesp.h"
124*433d6423SLionel Sambuc 
125*433d6423SLionel Sambuc 
126*433d6423SLionel Sambuc #define _COMPONENT          ACPI_EXECUTER
127*433d6423SLionel Sambuc         ACPI_MODULE_NAME    ("exstore")
128*433d6423SLionel Sambuc 
129*433d6423SLionel Sambuc /* Local prototypes */
130*433d6423SLionel Sambuc 
131*433d6423SLionel Sambuc static ACPI_STATUS
132*433d6423SLionel Sambuc AcpiExStoreObjectToIndex (
133*433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *ValDesc,
134*433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *DestDesc,
135*433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState);
136*433d6423SLionel Sambuc 
137*433d6423SLionel Sambuc 
138*433d6423SLionel Sambuc /*******************************************************************************
139*433d6423SLionel Sambuc  *
140*433d6423SLionel Sambuc  * FUNCTION:    AcpiExStore
141*433d6423SLionel Sambuc  *
142*433d6423SLionel Sambuc  * PARAMETERS:  *SourceDesc         - Value to be stored
143*433d6423SLionel Sambuc  *              *DestDesc           - Where to store it.  Must be an NS node
144*433d6423SLionel Sambuc  *                                    or an ACPI_OPERAND_OBJECT of type
145*433d6423SLionel Sambuc  *                                    Reference;
146*433d6423SLionel Sambuc  *              WalkState           - Current walk state
147*433d6423SLionel Sambuc  *
148*433d6423SLionel Sambuc  * RETURN:      Status
149*433d6423SLionel Sambuc  *
150*433d6423SLionel Sambuc  * DESCRIPTION: Store the value described by SourceDesc into the location
151*433d6423SLionel Sambuc  *              described by DestDesc.  Called by various interpreter
152*433d6423SLionel Sambuc  *              functions to store the result of an operation into
153*433d6423SLionel Sambuc  *              the destination operand -- not just simply the actual "Store"
154*433d6423SLionel Sambuc  *              ASL operator.
155*433d6423SLionel Sambuc  *
156*433d6423SLionel Sambuc  ******************************************************************************/
157*433d6423SLionel Sambuc 
158*433d6423SLionel Sambuc ACPI_STATUS
159*433d6423SLionel Sambuc AcpiExStore (
160*433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *SourceDesc,
161*433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *DestDesc,
162*433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState)
163*433d6423SLionel Sambuc {
164*433d6423SLionel Sambuc     ACPI_STATUS             Status = AE_OK;
165*433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *RefDesc = DestDesc;
166*433d6423SLionel Sambuc 
167*433d6423SLionel Sambuc 
168*433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE_PTR (ExStore, DestDesc);
169*433d6423SLionel Sambuc 
170*433d6423SLionel Sambuc 
171*433d6423SLionel Sambuc     /* Validate parameters */
172*433d6423SLionel Sambuc 
173*433d6423SLionel Sambuc     if (!SourceDesc || !DestDesc)
174*433d6423SLionel Sambuc     {
175*433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO, "Null parameter"));
176*433d6423SLionel Sambuc         return_ACPI_STATUS (AE_AML_NO_OPERAND);
177*433d6423SLionel Sambuc     }
178*433d6423SLionel Sambuc 
179*433d6423SLionel Sambuc     /* DestDesc can be either a namespace node or an ACPI object */
180*433d6423SLionel Sambuc 
181*433d6423SLionel Sambuc     if (ACPI_GET_DESCRIPTOR_TYPE (DestDesc) == ACPI_DESC_TYPE_NAMED)
182*433d6423SLionel Sambuc     {
183*433d6423SLionel Sambuc         /*
184*433d6423SLionel Sambuc          * Dest is a namespace node,
185*433d6423SLionel Sambuc          * Storing an object into a Named node.
186*433d6423SLionel Sambuc          */
187*433d6423SLionel Sambuc         Status = AcpiExStoreObjectToNode (SourceDesc,
188*433d6423SLionel Sambuc                     (ACPI_NAMESPACE_NODE *) DestDesc, WalkState,
189*433d6423SLionel Sambuc                     ACPI_IMPLICIT_CONVERSION);
190*433d6423SLionel Sambuc 
191*433d6423SLionel Sambuc         return_ACPI_STATUS (Status);
192*433d6423SLionel Sambuc     }
193*433d6423SLionel Sambuc 
194*433d6423SLionel Sambuc     /* Destination object must be a Reference or a Constant object */
195*433d6423SLionel Sambuc 
196*433d6423SLionel Sambuc     switch (DestDesc->Common.Type)
197*433d6423SLionel Sambuc     {
198*433d6423SLionel Sambuc     case ACPI_TYPE_LOCAL_REFERENCE:
199*433d6423SLionel Sambuc         break;
200*433d6423SLionel Sambuc 
201*433d6423SLionel Sambuc     case ACPI_TYPE_INTEGER:
202*433d6423SLionel Sambuc 
203*433d6423SLionel Sambuc         /* Allow stores to Constants -- a Noop as per ACPI spec */
204*433d6423SLionel Sambuc 
205*433d6423SLionel Sambuc         if (DestDesc->Common.Flags & AOPOBJ_AML_CONSTANT)
206*433d6423SLionel Sambuc         {
207*433d6423SLionel Sambuc             return_ACPI_STATUS (AE_OK);
208*433d6423SLionel Sambuc         }
209*433d6423SLionel Sambuc 
210*433d6423SLionel Sambuc         /*lint -fallthrough */
211*433d6423SLionel Sambuc 
212*433d6423SLionel Sambuc     default:
213*433d6423SLionel Sambuc 
214*433d6423SLionel Sambuc         /* Destination is not a Reference object */
215*433d6423SLionel Sambuc 
216*433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO,
217*433d6423SLionel Sambuc             "Target is not a Reference or Constant object - %s [%p]",
218*433d6423SLionel Sambuc             AcpiUtGetObjectTypeName (DestDesc), DestDesc));
219*433d6423SLionel Sambuc 
220*433d6423SLionel Sambuc         return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
221*433d6423SLionel Sambuc     }
222*433d6423SLionel Sambuc 
223*433d6423SLionel Sambuc     /*
224*433d6423SLionel Sambuc      * Examine the Reference class. These cases are handled:
225*433d6423SLionel Sambuc      *
226*433d6423SLionel Sambuc      * 1) Store to Name (Change the object associated with a name)
227*433d6423SLionel Sambuc      * 2) Store to an indexed area of a Buffer or Package
228*433d6423SLionel Sambuc      * 3) Store to a Method Local or Arg
229*433d6423SLionel Sambuc      * 4) Store to the debug object
230*433d6423SLionel Sambuc      */
231*433d6423SLionel Sambuc     switch (RefDesc->Reference.Class)
232*433d6423SLionel Sambuc     {
233*433d6423SLionel Sambuc     case ACPI_REFCLASS_REFOF:
234*433d6423SLionel Sambuc 
235*433d6423SLionel Sambuc         /* Storing an object into a Name "container" */
236*433d6423SLionel Sambuc 
237*433d6423SLionel Sambuc         Status = AcpiExStoreObjectToNode (SourceDesc,
238*433d6423SLionel Sambuc                     RefDesc->Reference.Object,
239*433d6423SLionel Sambuc                     WalkState, ACPI_IMPLICIT_CONVERSION);
240*433d6423SLionel Sambuc         break;
241*433d6423SLionel Sambuc 
242*433d6423SLionel Sambuc 
243*433d6423SLionel Sambuc     case ACPI_REFCLASS_INDEX:
244*433d6423SLionel Sambuc 
245*433d6423SLionel Sambuc         /* Storing to an Index (pointer into a packager or buffer) */
246*433d6423SLionel Sambuc 
247*433d6423SLionel Sambuc         Status = AcpiExStoreObjectToIndex (SourceDesc, RefDesc, WalkState);
248*433d6423SLionel Sambuc         break;
249*433d6423SLionel Sambuc 
250*433d6423SLionel Sambuc 
251*433d6423SLionel Sambuc     case ACPI_REFCLASS_LOCAL:
252*433d6423SLionel Sambuc     case ACPI_REFCLASS_ARG:
253*433d6423SLionel Sambuc 
254*433d6423SLionel Sambuc         /* Store to a method local/arg  */
255*433d6423SLionel Sambuc 
256*433d6423SLionel Sambuc         Status = AcpiDsStoreObjectToLocal (RefDesc->Reference.Class,
257*433d6423SLionel Sambuc                     RefDesc->Reference.Value, SourceDesc, WalkState);
258*433d6423SLionel Sambuc         break;
259*433d6423SLionel Sambuc 
260*433d6423SLionel Sambuc 
261*433d6423SLionel Sambuc     case ACPI_REFCLASS_DEBUG:
262*433d6423SLionel Sambuc 
263*433d6423SLionel Sambuc         /*
264*433d6423SLionel Sambuc          * Storing to the Debug object causes the value stored to be
265*433d6423SLionel Sambuc          * displayed and otherwise has no effect -- see ACPI Specification
266*433d6423SLionel Sambuc          */
267*433d6423SLionel Sambuc         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
268*433d6423SLionel Sambuc             "**** Write to Debug Object: Object %p %s ****:\n\n",
269*433d6423SLionel Sambuc             SourceDesc, AcpiUtGetObjectTypeName (SourceDesc)));
270*433d6423SLionel Sambuc 
271*433d6423SLionel Sambuc         ACPI_DEBUG_OBJECT (SourceDesc, 0, 0);
272*433d6423SLionel Sambuc         break;
273*433d6423SLionel Sambuc 
274*433d6423SLionel Sambuc 
275*433d6423SLionel Sambuc     default:
276*433d6423SLionel Sambuc 
277*433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO, "Unknown Reference Class 0x%2.2X",
278*433d6423SLionel Sambuc             RefDesc->Reference.Class));
279*433d6423SLionel Sambuc         ACPI_DUMP_ENTRY (RefDesc, ACPI_LV_INFO);
280*433d6423SLionel Sambuc 
281*433d6423SLionel Sambuc         Status = AE_AML_INTERNAL;
282*433d6423SLionel Sambuc         break;
283*433d6423SLionel Sambuc     }
284*433d6423SLionel Sambuc 
285*433d6423SLionel Sambuc     return_ACPI_STATUS (Status);
286*433d6423SLionel Sambuc }
287*433d6423SLionel Sambuc 
288*433d6423SLionel Sambuc 
289*433d6423SLionel Sambuc /*******************************************************************************
290*433d6423SLionel Sambuc  *
291*433d6423SLionel Sambuc  * FUNCTION:    AcpiExStoreObjectToIndex
292*433d6423SLionel Sambuc  *
293*433d6423SLionel Sambuc  * PARAMETERS:  *SourceDesc             - Value to be stored
294*433d6423SLionel Sambuc  *              *DestDesc               - Named object to receive the value
295*433d6423SLionel Sambuc  *              WalkState               - Current walk state
296*433d6423SLionel Sambuc  *
297*433d6423SLionel Sambuc  * RETURN:      Status
298*433d6423SLionel Sambuc  *
299*433d6423SLionel Sambuc  * DESCRIPTION: Store the object to indexed Buffer or Package element
300*433d6423SLionel Sambuc  *
301*433d6423SLionel Sambuc  ******************************************************************************/
302*433d6423SLionel Sambuc 
303*433d6423SLionel Sambuc static ACPI_STATUS
304*433d6423SLionel Sambuc AcpiExStoreObjectToIndex (
305*433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *SourceDesc,
306*433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *IndexDesc,
307*433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState)
308*433d6423SLionel Sambuc {
309*433d6423SLionel Sambuc     ACPI_STATUS             Status = AE_OK;
310*433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *ObjDesc;
311*433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *NewDesc;
312*433d6423SLionel Sambuc     UINT8                   Value = 0;
313*433d6423SLionel Sambuc     UINT32                  i;
314*433d6423SLionel Sambuc 
315*433d6423SLionel Sambuc 
316*433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (ExStoreObjectToIndex);
317*433d6423SLionel Sambuc 
318*433d6423SLionel Sambuc 
319*433d6423SLionel Sambuc     /*
320*433d6423SLionel Sambuc      * Destination must be a reference pointer, and
321*433d6423SLionel Sambuc      * must point to either a buffer or a package
322*433d6423SLionel Sambuc      */
323*433d6423SLionel Sambuc     switch (IndexDesc->Reference.TargetType)
324*433d6423SLionel Sambuc     {
325*433d6423SLionel Sambuc     case ACPI_TYPE_PACKAGE:
326*433d6423SLionel Sambuc         /*
327*433d6423SLionel Sambuc          * Storing to a package element. Copy the object and replace
328*433d6423SLionel Sambuc          * any existing object with the new object. No implicit
329*433d6423SLionel Sambuc          * conversion is performed.
330*433d6423SLionel Sambuc          *
331*433d6423SLionel Sambuc          * The object at *(IndexDesc->Reference.Where) is the
332*433d6423SLionel Sambuc          * element within the package that is to be modified.
333*433d6423SLionel Sambuc          * The parent package object is at IndexDesc->Reference.Object
334*433d6423SLionel Sambuc          */
335*433d6423SLionel Sambuc         ObjDesc = *(IndexDesc->Reference.Where);
336*433d6423SLionel Sambuc 
337*433d6423SLionel Sambuc         if (SourceDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE &&
338*433d6423SLionel Sambuc             SourceDesc->Reference.Class == ACPI_REFCLASS_TABLE)
339*433d6423SLionel Sambuc         {
340*433d6423SLionel Sambuc             /* This is a DDBHandle, just add a reference to it */
341*433d6423SLionel Sambuc 
342*433d6423SLionel Sambuc             AcpiUtAddReference (SourceDesc);
343*433d6423SLionel Sambuc             NewDesc = SourceDesc;
344*433d6423SLionel Sambuc         }
345*433d6423SLionel Sambuc         else
346*433d6423SLionel Sambuc         {
347*433d6423SLionel Sambuc             /* Normal object, copy it */
348*433d6423SLionel Sambuc 
349*433d6423SLionel Sambuc             Status = AcpiUtCopyIobjectToIobject (SourceDesc, &NewDesc, WalkState);
350*433d6423SLionel Sambuc             if (ACPI_FAILURE (Status))
351*433d6423SLionel Sambuc             {
352*433d6423SLionel Sambuc                 return_ACPI_STATUS (Status);
353*433d6423SLionel Sambuc             }
354*433d6423SLionel Sambuc         }
355*433d6423SLionel Sambuc 
356*433d6423SLionel Sambuc         if (ObjDesc)
357*433d6423SLionel Sambuc         {
358*433d6423SLionel Sambuc             /* Decrement reference count by the ref count of the parent package */
359*433d6423SLionel Sambuc 
360*433d6423SLionel Sambuc             for (i = 0;
361*433d6423SLionel Sambuc                  i < ((ACPI_OPERAND_OBJECT *)
362*433d6423SLionel Sambuc                         IndexDesc->Reference.Object)->Common.ReferenceCount;
363*433d6423SLionel Sambuc                  i++)
364*433d6423SLionel Sambuc             {
365*433d6423SLionel Sambuc                 AcpiUtRemoveReference (ObjDesc);
366*433d6423SLionel Sambuc             }
367*433d6423SLionel Sambuc         }
368*433d6423SLionel Sambuc 
369*433d6423SLionel Sambuc         *(IndexDesc->Reference.Where) = NewDesc;
370*433d6423SLionel Sambuc 
371*433d6423SLionel Sambuc         /* Increment ref count by the ref count of the parent package-1 */
372*433d6423SLionel Sambuc 
373*433d6423SLionel Sambuc         for (i = 1;
374*433d6423SLionel Sambuc              i < ((ACPI_OPERAND_OBJECT *)
375*433d6423SLionel Sambuc                     IndexDesc->Reference.Object)->Common.ReferenceCount;
376*433d6423SLionel Sambuc              i++)
377*433d6423SLionel Sambuc         {
378*433d6423SLionel Sambuc             AcpiUtAddReference (NewDesc);
379*433d6423SLionel Sambuc         }
380*433d6423SLionel Sambuc 
381*433d6423SLionel Sambuc         break;
382*433d6423SLionel Sambuc 
383*433d6423SLionel Sambuc 
384*433d6423SLionel Sambuc     case ACPI_TYPE_BUFFER_FIELD:
385*433d6423SLionel Sambuc 
386*433d6423SLionel Sambuc         /*
387*433d6423SLionel Sambuc          * Store into a Buffer or String (not actually a real BufferField)
388*433d6423SLionel Sambuc          * at a location defined by an Index.
389*433d6423SLionel Sambuc          *
390*433d6423SLionel Sambuc          * The first 8-bit element of the source object is written to the
391*433d6423SLionel Sambuc          * 8-bit Buffer location defined by the Index destination object,
392*433d6423SLionel Sambuc          * according to the ACPI 2.0 specification.
393*433d6423SLionel Sambuc          */
394*433d6423SLionel Sambuc 
395*433d6423SLionel Sambuc         /*
396*433d6423SLionel Sambuc          * Make sure the target is a Buffer or String. An error should
397*433d6423SLionel Sambuc          * not happen here, since the ReferenceObject was constructed
398*433d6423SLionel Sambuc          * by the INDEX_OP code.
399*433d6423SLionel Sambuc          */
400*433d6423SLionel Sambuc         ObjDesc = IndexDesc->Reference.Object;
401*433d6423SLionel Sambuc         if ((ObjDesc->Common.Type != ACPI_TYPE_BUFFER) &&
402*433d6423SLionel Sambuc             (ObjDesc->Common.Type != ACPI_TYPE_STRING))
403*433d6423SLionel Sambuc         {
404*433d6423SLionel Sambuc             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
405*433d6423SLionel Sambuc         }
406*433d6423SLionel Sambuc 
407*433d6423SLionel Sambuc         /*
408*433d6423SLionel Sambuc          * The assignment of the individual elements will be slightly
409*433d6423SLionel Sambuc          * different for each source type.
410*433d6423SLionel Sambuc          */
411*433d6423SLionel Sambuc         switch (SourceDesc->Common.Type)
412*433d6423SLionel Sambuc         {
413*433d6423SLionel Sambuc         case ACPI_TYPE_INTEGER:
414*433d6423SLionel Sambuc 
415*433d6423SLionel Sambuc             /* Use the least-significant byte of the integer */
416*433d6423SLionel Sambuc 
417*433d6423SLionel Sambuc             Value = (UINT8) (SourceDesc->Integer.Value);
418*433d6423SLionel Sambuc             break;
419*433d6423SLionel Sambuc 
420*433d6423SLionel Sambuc         case ACPI_TYPE_BUFFER:
421*433d6423SLionel Sambuc         case ACPI_TYPE_STRING:
422*433d6423SLionel Sambuc 
423*433d6423SLionel Sambuc             /* Note: Takes advantage of common string/buffer fields */
424*433d6423SLionel Sambuc 
425*433d6423SLionel Sambuc             Value = SourceDesc->Buffer.Pointer[0];
426*433d6423SLionel Sambuc             break;
427*433d6423SLionel Sambuc 
428*433d6423SLionel Sambuc         default:
429*433d6423SLionel Sambuc 
430*433d6423SLionel Sambuc             /* All other types are invalid */
431*433d6423SLionel Sambuc 
432*433d6423SLionel Sambuc             ACPI_ERROR ((AE_INFO,
433*433d6423SLionel Sambuc                 "Source must be Integer/Buffer/String type, not %s",
434*433d6423SLionel Sambuc                 AcpiUtGetObjectTypeName (SourceDesc)));
435*433d6423SLionel Sambuc             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
436*433d6423SLionel Sambuc         }
437*433d6423SLionel Sambuc 
438*433d6423SLionel Sambuc         /* Store the source value into the target buffer byte */
439*433d6423SLionel Sambuc 
440*433d6423SLionel Sambuc         ObjDesc->Buffer.Pointer[IndexDesc->Reference.Value] = Value;
441*433d6423SLionel Sambuc         break;
442*433d6423SLionel Sambuc 
443*433d6423SLionel Sambuc 
444*433d6423SLionel Sambuc     default:
445*433d6423SLionel Sambuc         ACPI_ERROR ((AE_INFO,
446*433d6423SLionel Sambuc             "Target is not a Package or BufferField"));
447*433d6423SLionel Sambuc         Status = AE_AML_OPERAND_TYPE;
448*433d6423SLionel Sambuc         break;
449*433d6423SLionel Sambuc     }
450*433d6423SLionel Sambuc 
451*433d6423SLionel Sambuc     return_ACPI_STATUS (Status);
452*433d6423SLionel Sambuc }
453*433d6423SLionel Sambuc 
454*433d6423SLionel Sambuc 
455*433d6423SLionel Sambuc /*******************************************************************************
456*433d6423SLionel Sambuc  *
457*433d6423SLionel Sambuc  * FUNCTION:    AcpiExStoreObjectToNode
458*433d6423SLionel Sambuc  *
459*433d6423SLionel Sambuc  * PARAMETERS:  SourceDesc              - Value to be stored
460*433d6423SLionel Sambuc  *              Node                    - Named object to receive the value
461*433d6423SLionel Sambuc  *              WalkState               - Current walk state
462*433d6423SLionel Sambuc  *              ImplicitConversion      - Perform implicit conversion (yes/no)
463*433d6423SLionel Sambuc  *
464*433d6423SLionel Sambuc  * RETURN:      Status
465*433d6423SLionel Sambuc  *
466*433d6423SLionel Sambuc  * DESCRIPTION: Store the object to the named object.
467*433d6423SLionel Sambuc  *
468*433d6423SLionel Sambuc  *              The Assignment of an object to a named object is handled here
469*433d6423SLionel Sambuc  *              The value passed in will replace the current value (if any)
470*433d6423SLionel Sambuc  *              with the input value.
471*433d6423SLionel Sambuc  *
472*433d6423SLionel Sambuc  *              When storing into an object the data is converted to the
473*433d6423SLionel Sambuc  *              target object type then stored in the object.  This means
474*433d6423SLionel Sambuc  *              that the target object type (for an initialized target) will
475*433d6423SLionel Sambuc  *              not be changed by a store operation.
476*433d6423SLionel Sambuc  *
477*433d6423SLionel Sambuc  *              Assumes parameters are already validated.
478*433d6423SLionel Sambuc  *
479*433d6423SLionel Sambuc  ******************************************************************************/
480*433d6423SLionel Sambuc 
481*433d6423SLionel Sambuc ACPI_STATUS
482*433d6423SLionel Sambuc AcpiExStoreObjectToNode (
483*433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *SourceDesc,
484*433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     *Node,
485*433d6423SLionel Sambuc     ACPI_WALK_STATE         *WalkState,
486*433d6423SLionel Sambuc     UINT8                   ImplicitConversion)
487*433d6423SLionel Sambuc {
488*433d6423SLionel Sambuc     ACPI_STATUS             Status = AE_OK;
489*433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *TargetDesc;
490*433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *NewDesc;
491*433d6423SLionel Sambuc     ACPI_OBJECT_TYPE        TargetType;
492*433d6423SLionel Sambuc 
493*433d6423SLionel Sambuc 
494*433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE_PTR (ExStoreObjectToNode, SourceDesc);
495*433d6423SLionel Sambuc 
496*433d6423SLionel Sambuc 
497*433d6423SLionel Sambuc     /* Get current type of the node, and object attached to Node */
498*433d6423SLionel Sambuc 
499*433d6423SLionel Sambuc     TargetType = AcpiNsGetType (Node);
500*433d6423SLionel Sambuc     TargetDesc = AcpiNsGetAttachedObject (Node);
501*433d6423SLionel Sambuc 
502*433d6423SLionel Sambuc     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Storing %p(%s) into node %p(%s)\n",
503*433d6423SLionel Sambuc         SourceDesc, AcpiUtGetObjectTypeName (SourceDesc),
504*433d6423SLionel Sambuc               Node, AcpiUtGetTypeName (TargetType)));
505*433d6423SLionel Sambuc 
506*433d6423SLionel Sambuc     /*
507*433d6423SLionel Sambuc      * Resolve the source object to an actual value
508*433d6423SLionel Sambuc      * (If it is a reference object)
509*433d6423SLionel Sambuc      */
510*433d6423SLionel Sambuc     Status = AcpiExResolveObject (&SourceDesc, TargetType, WalkState);
511*433d6423SLionel Sambuc     if (ACPI_FAILURE (Status))
512*433d6423SLionel Sambuc     {
513*433d6423SLionel Sambuc         return_ACPI_STATUS (Status);
514*433d6423SLionel Sambuc     }
515*433d6423SLionel Sambuc 
516*433d6423SLionel Sambuc     /* If no implicit conversion, drop into the default case below */
517*433d6423SLionel Sambuc 
518*433d6423SLionel Sambuc     if ((!ImplicitConversion) ||
519*433d6423SLionel Sambuc           ((WalkState->Opcode == AML_COPY_OP) &&
520*433d6423SLionel Sambuc            (TargetType != ACPI_TYPE_LOCAL_REGION_FIELD) &&
521*433d6423SLionel Sambuc            (TargetType != ACPI_TYPE_LOCAL_BANK_FIELD) &&
522*433d6423SLionel Sambuc            (TargetType != ACPI_TYPE_LOCAL_INDEX_FIELD)))
523*433d6423SLionel Sambuc     {
524*433d6423SLionel Sambuc         /*
525*433d6423SLionel Sambuc          * Force execution of default (no implicit conversion). Note:
526*433d6423SLionel Sambuc          * CopyObject does not perform an implicit conversion, as per the ACPI
527*433d6423SLionel Sambuc          * spec -- except in case of region/bank/index fields -- because these
528*433d6423SLionel Sambuc          * objects must retain their original type permanently.
529*433d6423SLionel Sambuc          */
530*433d6423SLionel Sambuc         TargetType = ACPI_TYPE_ANY;
531*433d6423SLionel Sambuc     }
532*433d6423SLionel Sambuc 
533*433d6423SLionel Sambuc     /* Do the actual store operation */
534*433d6423SLionel Sambuc 
535*433d6423SLionel Sambuc     switch (TargetType)
536*433d6423SLionel Sambuc     {
537*433d6423SLionel Sambuc     case ACPI_TYPE_BUFFER_FIELD:
538*433d6423SLionel Sambuc     case ACPI_TYPE_LOCAL_REGION_FIELD:
539*433d6423SLionel Sambuc     case ACPI_TYPE_LOCAL_BANK_FIELD:
540*433d6423SLionel Sambuc     case ACPI_TYPE_LOCAL_INDEX_FIELD:
541*433d6423SLionel Sambuc 
542*433d6423SLionel Sambuc         /* For fields, copy the source data to the target field. */
543*433d6423SLionel Sambuc 
544*433d6423SLionel Sambuc         Status = AcpiExWriteDataToField (SourceDesc, TargetDesc,
545*433d6423SLionel Sambuc                     &WalkState->ResultObj);
546*433d6423SLionel Sambuc         break;
547*433d6423SLionel Sambuc 
548*433d6423SLionel Sambuc 
549*433d6423SLionel Sambuc     case ACPI_TYPE_INTEGER:
550*433d6423SLionel Sambuc     case ACPI_TYPE_STRING:
551*433d6423SLionel Sambuc     case ACPI_TYPE_BUFFER:
552*433d6423SLionel Sambuc 
553*433d6423SLionel Sambuc         /*
554*433d6423SLionel Sambuc          * These target types are all of type Integer/String/Buffer, and
555*433d6423SLionel Sambuc          * therefore support implicit conversion before the store.
556*433d6423SLionel Sambuc          *
557*433d6423SLionel Sambuc          * Copy and/or convert the source object to a new target object
558*433d6423SLionel Sambuc          */
559*433d6423SLionel Sambuc         Status = AcpiExStoreObjectToObject (SourceDesc, TargetDesc,
560*433d6423SLionel Sambuc                     &NewDesc, WalkState);
561*433d6423SLionel Sambuc         if (ACPI_FAILURE (Status))
562*433d6423SLionel Sambuc         {
563*433d6423SLionel Sambuc             return_ACPI_STATUS (Status);
564*433d6423SLionel Sambuc         }
565*433d6423SLionel Sambuc 
566*433d6423SLionel Sambuc         if (NewDesc != TargetDesc)
567*433d6423SLionel Sambuc         {
568*433d6423SLionel Sambuc             /*
569*433d6423SLionel Sambuc              * Store the new NewDesc as the new value of the Name, and set
570*433d6423SLionel Sambuc              * the Name's type to that of the value being stored in it.
571*433d6423SLionel Sambuc              * SourceDesc reference count is incremented by AttachObject.
572*433d6423SLionel Sambuc              *
573*433d6423SLionel Sambuc              * Note: This may change the type of the node if an explicit store
574*433d6423SLionel Sambuc              * has been performed such that the node/object type has been
575*433d6423SLionel Sambuc              * changed.
576*433d6423SLionel Sambuc              */
577*433d6423SLionel Sambuc             Status = AcpiNsAttachObject (Node, NewDesc, NewDesc->Common.Type);
578*433d6423SLionel Sambuc 
579*433d6423SLionel Sambuc             ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
580*433d6423SLionel Sambuc                 "Store %s into %s via Convert/Attach\n",
581*433d6423SLionel Sambuc                 AcpiUtGetObjectTypeName (SourceDesc),
582*433d6423SLionel Sambuc                 AcpiUtGetObjectTypeName (NewDesc)));
583*433d6423SLionel Sambuc         }
584*433d6423SLionel Sambuc         break;
585*433d6423SLionel Sambuc 
586*433d6423SLionel Sambuc 
587*433d6423SLionel Sambuc     default:
588*433d6423SLionel Sambuc 
589*433d6423SLionel Sambuc         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
590*433d6423SLionel Sambuc             "Storing %s (%p) directly into node (%p) with no implicit conversion\n",
591*433d6423SLionel Sambuc             AcpiUtGetObjectTypeName (SourceDesc), SourceDesc, Node));
592*433d6423SLionel Sambuc 
593*433d6423SLionel Sambuc         /* No conversions for all other types.  Just attach the source object */
594*433d6423SLionel Sambuc 
595*433d6423SLionel Sambuc         Status = AcpiNsAttachObject (Node, SourceDesc,
596*433d6423SLionel Sambuc                     SourceDesc->Common.Type);
597*433d6423SLionel Sambuc         break;
598*433d6423SLionel Sambuc     }
599*433d6423SLionel Sambuc 
600*433d6423SLionel Sambuc     return_ACPI_STATUS (Status);
601*433d6423SLionel Sambuc }
602*433d6423SLionel Sambuc 
603*433d6423SLionel Sambuc 
604