1433d6423SLionel Sambuc /******************************************************************************
2433d6423SLionel Sambuc *
3433d6423SLionel Sambuc * Module Name: exstore - AML Interpreter object store support
4433d6423SLionel Sambuc *
5433d6423SLionel Sambuc *****************************************************************************/
6433d6423SLionel Sambuc
7*29492bb7SDavid van Moolenbroek /*
8*29492bb7SDavid van Moolenbroek * Copyright (C) 2000 - 2014, Intel Corp.
9433d6423SLionel Sambuc * All rights reserved.
10433d6423SLionel Sambuc *
11*29492bb7SDavid van Moolenbroek * Redistribution and use in source and binary forms, with or without
12*29492bb7SDavid van Moolenbroek * modification, are permitted provided that the following conditions
13*29492bb7SDavid van Moolenbroek * are met:
14*29492bb7SDavid van Moolenbroek * 1. Redistributions of source code must retain the above copyright
15*29492bb7SDavid van Moolenbroek * notice, this list of conditions, and the following disclaimer,
16*29492bb7SDavid van Moolenbroek * without modification.
17*29492bb7SDavid van Moolenbroek * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*29492bb7SDavid van Moolenbroek * substantially similar to the "NO WARRANTY" disclaimer below
19*29492bb7SDavid van Moolenbroek * ("Disclaimer") and any redistribution must be conditioned upon
20*29492bb7SDavid van Moolenbroek * including a substantially similar Disclaimer requirement for further
21*29492bb7SDavid van Moolenbroek * binary redistribution.
22*29492bb7SDavid van Moolenbroek * 3. Neither the names of the above-listed copyright holders nor the names
23*29492bb7SDavid van Moolenbroek * of any contributors may be used to endorse or promote products derived
24*29492bb7SDavid van Moolenbroek * from this software without specific prior written permission.
25433d6423SLionel Sambuc *
26*29492bb7SDavid van Moolenbroek * Alternatively, this software may be distributed under the terms of the
27*29492bb7SDavid van Moolenbroek * GNU General Public License ("GPL") version 2 as published by the Free
28*29492bb7SDavid van Moolenbroek * Software Foundation.
29433d6423SLionel Sambuc *
30*29492bb7SDavid van Moolenbroek * NO WARRANTY
31*29492bb7SDavid van Moolenbroek * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*29492bb7SDavid van Moolenbroek * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*29492bb7SDavid van Moolenbroek * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*29492bb7SDavid van Moolenbroek * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*29492bb7SDavid van Moolenbroek * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*29492bb7SDavid van Moolenbroek * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*29492bb7SDavid van Moolenbroek * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*29492bb7SDavid van Moolenbroek * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*29492bb7SDavid van Moolenbroek * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*29492bb7SDavid van Moolenbroek * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*29492bb7SDavid van Moolenbroek * POSSIBILITY OF SUCH DAMAGES.
42*29492bb7SDavid van Moolenbroek */
43433d6423SLionel Sambuc
44433d6423SLionel Sambuc #include "acpi.h"
45433d6423SLionel Sambuc #include "accommon.h"
46433d6423SLionel Sambuc #include "acdispat.h"
47433d6423SLionel Sambuc #include "acinterp.h"
48433d6423SLionel Sambuc #include "amlcode.h"
49433d6423SLionel Sambuc #include "acnamesp.h"
50433d6423SLionel Sambuc
51433d6423SLionel Sambuc
52433d6423SLionel Sambuc #define _COMPONENT ACPI_EXECUTER
53433d6423SLionel Sambuc ACPI_MODULE_NAME ("exstore")
54433d6423SLionel Sambuc
55433d6423SLionel Sambuc /* Local prototypes */
56433d6423SLionel Sambuc
57433d6423SLionel Sambuc static ACPI_STATUS
58433d6423SLionel Sambuc AcpiExStoreObjectToIndex (
59433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *ValDesc,
60433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *DestDesc,
61433d6423SLionel Sambuc ACPI_WALK_STATE *WalkState);
62433d6423SLionel Sambuc
63*29492bb7SDavid van Moolenbroek static ACPI_STATUS
64*29492bb7SDavid van Moolenbroek AcpiExStoreDirectToNode (
65*29492bb7SDavid van Moolenbroek ACPI_OPERAND_OBJECT *SourceDesc,
66*29492bb7SDavid van Moolenbroek ACPI_NAMESPACE_NODE *Node,
67*29492bb7SDavid van Moolenbroek ACPI_WALK_STATE *WalkState);
68*29492bb7SDavid van Moolenbroek
69433d6423SLionel Sambuc
70433d6423SLionel Sambuc /*******************************************************************************
71433d6423SLionel Sambuc *
72433d6423SLionel Sambuc * FUNCTION: AcpiExStore
73433d6423SLionel Sambuc *
74433d6423SLionel Sambuc * PARAMETERS: *SourceDesc - Value to be stored
75433d6423SLionel Sambuc * *DestDesc - Where to store it. Must be an NS node
76*29492bb7SDavid van Moolenbroek * or ACPI_OPERAND_OBJECT of type
77433d6423SLionel Sambuc * Reference;
78433d6423SLionel Sambuc * WalkState - Current walk state
79433d6423SLionel Sambuc *
80433d6423SLionel Sambuc * RETURN: Status
81433d6423SLionel Sambuc *
82433d6423SLionel Sambuc * DESCRIPTION: Store the value described by SourceDesc into the location
83433d6423SLionel Sambuc * described by DestDesc. Called by various interpreter
84433d6423SLionel Sambuc * functions to store the result of an operation into
85433d6423SLionel Sambuc * the destination operand -- not just simply the actual "Store"
86433d6423SLionel Sambuc * ASL operator.
87433d6423SLionel Sambuc *
88433d6423SLionel Sambuc ******************************************************************************/
89433d6423SLionel Sambuc
90433d6423SLionel Sambuc ACPI_STATUS
AcpiExStore(ACPI_OPERAND_OBJECT * SourceDesc,ACPI_OPERAND_OBJECT * DestDesc,ACPI_WALK_STATE * WalkState)91433d6423SLionel Sambuc AcpiExStore (
92433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *SourceDesc,
93433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *DestDesc,
94433d6423SLionel Sambuc ACPI_WALK_STATE *WalkState)
95433d6423SLionel Sambuc {
96433d6423SLionel Sambuc ACPI_STATUS Status = AE_OK;
97433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *RefDesc = DestDesc;
98433d6423SLionel Sambuc
99433d6423SLionel Sambuc
100433d6423SLionel Sambuc ACPI_FUNCTION_TRACE_PTR (ExStore, DestDesc);
101433d6423SLionel Sambuc
102433d6423SLionel Sambuc
103433d6423SLionel Sambuc /* Validate parameters */
104433d6423SLionel Sambuc
105433d6423SLionel Sambuc if (!SourceDesc || !DestDesc)
106433d6423SLionel Sambuc {
107433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO, "Null parameter"));
108433d6423SLionel Sambuc return_ACPI_STATUS (AE_AML_NO_OPERAND);
109433d6423SLionel Sambuc }
110433d6423SLionel Sambuc
111433d6423SLionel Sambuc /* DestDesc can be either a namespace node or an ACPI object */
112433d6423SLionel Sambuc
113433d6423SLionel Sambuc if (ACPI_GET_DESCRIPTOR_TYPE (DestDesc) == ACPI_DESC_TYPE_NAMED)
114433d6423SLionel Sambuc {
115433d6423SLionel Sambuc /*
116433d6423SLionel Sambuc * Dest is a namespace node,
117433d6423SLionel Sambuc * Storing an object into a Named node.
118433d6423SLionel Sambuc */
119433d6423SLionel Sambuc Status = AcpiExStoreObjectToNode (SourceDesc,
120433d6423SLionel Sambuc (ACPI_NAMESPACE_NODE *) DestDesc, WalkState,
121433d6423SLionel Sambuc ACPI_IMPLICIT_CONVERSION);
122433d6423SLionel Sambuc
123433d6423SLionel Sambuc return_ACPI_STATUS (Status);
124433d6423SLionel Sambuc }
125433d6423SLionel Sambuc
126433d6423SLionel Sambuc /* Destination object must be a Reference or a Constant object */
127433d6423SLionel Sambuc
128433d6423SLionel Sambuc switch (DestDesc->Common.Type)
129433d6423SLionel Sambuc {
130433d6423SLionel Sambuc case ACPI_TYPE_LOCAL_REFERENCE:
131*29492bb7SDavid van Moolenbroek
132433d6423SLionel Sambuc break;
133433d6423SLionel Sambuc
134433d6423SLionel Sambuc case ACPI_TYPE_INTEGER:
135433d6423SLionel Sambuc
136433d6423SLionel Sambuc /* Allow stores to Constants -- a Noop as per ACPI spec */
137433d6423SLionel Sambuc
138433d6423SLionel Sambuc if (DestDesc->Common.Flags & AOPOBJ_AML_CONSTANT)
139433d6423SLionel Sambuc {
140433d6423SLionel Sambuc return_ACPI_STATUS (AE_OK);
141433d6423SLionel Sambuc }
142433d6423SLionel Sambuc
143433d6423SLionel Sambuc /*lint -fallthrough */
144433d6423SLionel Sambuc
145433d6423SLionel Sambuc default:
146433d6423SLionel Sambuc
147433d6423SLionel Sambuc /* Destination is not a Reference object */
148433d6423SLionel Sambuc
149433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO,
150433d6423SLionel Sambuc "Target is not a Reference or Constant object - %s [%p]",
151433d6423SLionel Sambuc AcpiUtGetObjectTypeName (DestDesc), DestDesc));
152433d6423SLionel Sambuc
153433d6423SLionel Sambuc return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
154433d6423SLionel Sambuc }
155433d6423SLionel Sambuc
156433d6423SLionel Sambuc /*
157433d6423SLionel Sambuc * Examine the Reference class. These cases are handled:
158433d6423SLionel Sambuc *
159433d6423SLionel Sambuc * 1) Store to Name (Change the object associated with a name)
160433d6423SLionel Sambuc * 2) Store to an indexed area of a Buffer or Package
161433d6423SLionel Sambuc * 3) Store to a Method Local or Arg
162433d6423SLionel Sambuc * 4) Store to the debug object
163433d6423SLionel Sambuc */
164433d6423SLionel Sambuc switch (RefDesc->Reference.Class)
165433d6423SLionel Sambuc {
166433d6423SLionel Sambuc case ACPI_REFCLASS_REFOF:
167433d6423SLionel Sambuc
168433d6423SLionel Sambuc /* Storing an object into a Name "container" */
169433d6423SLionel Sambuc
170433d6423SLionel Sambuc Status = AcpiExStoreObjectToNode (SourceDesc,
171433d6423SLionel Sambuc RefDesc->Reference.Object,
172433d6423SLionel Sambuc WalkState, ACPI_IMPLICIT_CONVERSION);
173433d6423SLionel Sambuc break;
174433d6423SLionel Sambuc
175433d6423SLionel Sambuc case ACPI_REFCLASS_INDEX:
176433d6423SLionel Sambuc
177433d6423SLionel Sambuc /* Storing to an Index (pointer into a packager or buffer) */
178433d6423SLionel Sambuc
179433d6423SLionel Sambuc Status = AcpiExStoreObjectToIndex (SourceDesc, RefDesc, WalkState);
180433d6423SLionel Sambuc break;
181433d6423SLionel Sambuc
182433d6423SLionel Sambuc case ACPI_REFCLASS_LOCAL:
183433d6423SLionel Sambuc case ACPI_REFCLASS_ARG:
184433d6423SLionel Sambuc
185433d6423SLionel Sambuc /* Store to a method local/arg */
186433d6423SLionel Sambuc
187433d6423SLionel Sambuc Status = AcpiDsStoreObjectToLocal (RefDesc->Reference.Class,
188433d6423SLionel Sambuc RefDesc->Reference.Value, SourceDesc, WalkState);
189433d6423SLionel Sambuc break;
190433d6423SLionel Sambuc
191433d6423SLionel Sambuc case ACPI_REFCLASS_DEBUG:
192433d6423SLionel Sambuc /*
193433d6423SLionel Sambuc * Storing to the Debug object causes the value stored to be
194433d6423SLionel Sambuc * displayed and otherwise has no effect -- see ACPI Specification
195433d6423SLionel Sambuc */
196433d6423SLionel Sambuc ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
197433d6423SLionel Sambuc "**** Write to Debug Object: Object %p %s ****:\n\n",
198433d6423SLionel Sambuc SourceDesc, AcpiUtGetObjectTypeName (SourceDesc)));
199433d6423SLionel Sambuc
200433d6423SLionel Sambuc ACPI_DEBUG_OBJECT (SourceDesc, 0, 0);
201433d6423SLionel Sambuc break;
202433d6423SLionel Sambuc
203433d6423SLionel Sambuc default:
204433d6423SLionel Sambuc
205433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO, "Unknown Reference Class 0x%2.2X",
206433d6423SLionel Sambuc RefDesc->Reference.Class));
207433d6423SLionel Sambuc ACPI_DUMP_ENTRY (RefDesc, ACPI_LV_INFO);
208433d6423SLionel Sambuc
209433d6423SLionel Sambuc Status = AE_AML_INTERNAL;
210433d6423SLionel Sambuc break;
211433d6423SLionel Sambuc }
212433d6423SLionel Sambuc
213433d6423SLionel Sambuc return_ACPI_STATUS (Status);
214433d6423SLionel Sambuc }
215433d6423SLionel Sambuc
216433d6423SLionel Sambuc
217433d6423SLionel Sambuc /*******************************************************************************
218433d6423SLionel Sambuc *
219433d6423SLionel Sambuc * FUNCTION: AcpiExStoreObjectToIndex
220433d6423SLionel Sambuc *
221433d6423SLionel Sambuc * PARAMETERS: *SourceDesc - Value to be stored
222433d6423SLionel Sambuc * *DestDesc - Named object to receive the value
223433d6423SLionel Sambuc * WalkState - Current walk state
224433d6423SLionel Sambuc *
225433d6423SLionel Sambuc * RETURN: Status
226433d6423SLionel Sambuc *
227433d6423SLionel Sambuc * DESCRIPTION: Store the object to indexed Buffer or Package element
228433d6423SLionel Sambuc *
229433d6423SLionel Sambuc ******************************************************************************/
230433d6423SLionel Sambuc
231433d6423SLionel Sambuc static ACPI_STATUS
AcpiExStoreObjectToIndex(ACPI_OPERAND_OBJECT * SourceDesc,ACPI_OPERAND_OBJECT * IndexDesc,ACPI_WALK_STATE * WalkState)232433d6423SLionel Sambuc AcpiExStoreObjectToIndex (
233433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *SourceDesc,
234433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *IndexDesc,
235433d6423SLionel Sambuc ACPI_WALK_STATE *WalkState)
236433d6423SLionel Sambuc {
237433d6423SLionel Sambuc ACPI_STATUS Status = AE_OK;
238433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *ObjDesc;
239433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *NewDesc;
240433d6423SLionel Sambuc UINT8 Value = 0;
241433d6423SLionel Sambuc UINT32 i;
242433d6423SLionel Sambuc
243433d6423SLionel Sambuc
244433d6423SLionel Sambuc ACPI_FUNCTION_TRACE (ExStoreObjectToIndex);
245433d6423SLionel Sambuc
246433d6423SLionel Sambuc
247433d6423SLionel Sambuc /*
248433d6423SLionel Sambuc * Destination must be a reference pointer, and
249433d6423SLionel Sambuc * must point to either a buffer or a package
250433d6423SLionel Sambuc */
251433d6423SLionel Sambuc switch (IndexDesc->Reference.TargetType)
252433d6423SLionel Sambuc {
253433d6423SLionel Sambuc case ACPI_TYPE_PACKAGE:
254433d6423SLionel Sambuc /*
255433d6423SLionel Sambuc * Storing to a package element. Copy the object and replace
256433d6423SLionel Sambuc * any existing object with the new object. No implicit
257433d6423SLionel Sambuc * conversion is performed.
258433d6423SLionel Sambuc *
259433d6423SLionel Sambuc * The object at *(IndexDesc->Reference.Where) is the
260433d6423SLionel Sambuc * element within the package that is to be modified.
261433d6423SLionel Sambuc * The parent package object is at IndexDesc->Reference.Object
262433d6423SLionel Sambuc */
263433d6423SLionel Sambuc ObjDesc = *(IndexDesc->Reference.Where);
264433d6423SLionel Sambuc
265433d6423SLionel Sambuc if (SourceDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE &&
266433d6423SLionel Sambuc SourceDesc->Reference.Class == ACPI_REFCLASS_TABLE)
267433d6423SLionel Sambuc {
268433d6423SLionel Sambuc /* This is a DDBHandle, just add a reference to it */
269433d6423SLionel Sambuc
270433d6423SLionel Sambuc AcpiUtAddReference (SourceDesc);
271433d6423SLionel Sambuc NewDesc = SourceDesc;
272433d6423SLionel Sambuc }
273433d6423SLionel Sambuc else
274433d6423SLionel Sambuc {
275433d6423SLionel Sambuc /* Normal object, copy it */
276433d6423SLionel Sambuc
277433d6423SLionel Sambuc Status = AcpiUtCopyIobjectToIobject (SourceDesc, &NewDesc, WalkState);
278433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
279433d6423SLionel Sambuc {
280433d6423SLionel Sambuc return_ACPI_STATUS (Status);
281433d6423SLionel Sambuc }
282433d6423SLionel Sambuc }
283433d6423SLionel Sambuc
284433d6423SLionel Sambuc if (ObjDesc)
285433d6423SLionel Sambuc {
286433d6423SLionel Sambuc /* Decrement reference count by the ref count of the parent package */
287433d6423SLionel Sambuc
288433d6423SLionel Sambuc for (i = 0;
289433d6423SLionel Sambuc i < ((ACPI_OPERAND_OBJECT *)
290433d6423SLionel Sambuc IndexDesc->Reference.Object)->Common.ReferenceCount;
291433d6423SLionel Sambuc i++)
292433d6423SLionel Sambuc {
293433d6423SLionel Sambuc AcpiUtRemoveReference (ObjDesc);
294433d6423SLionel Sambuc }
295433d6423SLionel Sambuc }
296433d6423SLionel Sambuc
297433d6423SLionel Sambuc *(IndexDesc->Reference.Where) = NewDesc;
298433d6423SLionel Sambuc
299433d6423SLionel Sambuc /* Increment ref count by the ref count of the parent package-1 */
300433d6423SLionel Sambuc
301433d6423SLionel Sambuc for (i = 1;
302433d6423SLionel Sambuc i < ((ACPI_OPERAND_OBJECT *)
303433d6423SLionel Sambuc IndexDesc->Reference.Object)->Common.ReferenceCount;
304433d6423SLionel Sambuc i++)
305433d6423SLionel Sambuc {
306433d6423SLionel Sambuc AcpiUtAddReference (NewDesc);
307433d6423SLionel Sambuc }
308433d6423SLionel Sambuc
309433d6423SLionel Sambuc break;
310433d6423SLionel Sambuc
311433d6423SLionel Sambuc case ACPI_TYPE_BUFFER_FIELD:
312433d6423SLionel Sambuc /*
313433d6423SLionel Sambuc * Store into a Buffer or String (not actually a real BufferField)
314433d6423SLionel Sambuc * at a location defined by an Index.
315433d6423SLionel Sambuc *
316433d6423SLionel Sambuc * The first 8-bit element of the source object is written to the
317433d6423SLionel Sambuc * 8-bit Buffer location defined by the Index destination object,
318433d6423SLionel Sambuc * according to the ACPI 2.0 specification.
319433d6423SLionel Sambuc */
320433d6423SLionel Sambuc
321433d6423SLionel Sambuc /*
322433d6423SLionel Sambuc * Make sure the target is a Buffer or String. An error should
323433d6423SLionel Sambuc * not happen here, since the ReferenceObject was constructed
324433d6423SLionel Sambuc * by the INDEX_OP code.
325433d6423SLionel Sambuc */
326433d6423SLionel Sambuc ObjDesc = IndexDesc->Reference.Object;
327433d6423SLionel Sambuc if ((ObjDesc->Common.Type != ACPI_TYPE_BUFFER) &&
328433d6423SLionel Sambuc (ObjDesc->Common.Type != ACPI_TYPE_STRING))
329433d6423SLionel Sambuc {
330433d6423SLionel Sambuc return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
331433d6423SLionel Sambuc }
332433d6423SLionel Sambuc
333433d6423SLionel Sambuc /*
334433d6423SLionel Sambuc * The assignment of the individual elements will be slightly
335433d6423SLionel Sambuc * different for each source type.
336433d6423SLionel Sambuc */
337433d6423SLionel Sambuc switch (SourceDesc->Common.Type)
338433d6423SLionel Sambuc {
339433d6423SLionel Sambuc case ACPI_TYPE_INTEGER:
340433d6423SLionel Sambuc
341433d6423SLionel Sambuc /* Use the least-significant byte of the integer */
342433d6423SLionel Sambuc
343433d6423SLionel Sambuc Value = (UINT8) (SourceDesc->Integer.Value);
344433d6423SLionel Sambuc break;
345433d6423SLionel Sambuc
346433d6423SLionel Sambuc case ACPI_TYPE_BUFFER:
347433d6423SLionel Sambuc case ACPI_TYPE_STRING:
348433d6423SLionel Sambuc
349433d6423SLionel Sambuc /* Note: Takes advantage of common string/buffer fields */
350433d6423SLionel Sambuc
351433d6423SLionel Sambuc Value = SourceDesc->Buffer.Pointer[0];
352433d6423SLionel Sambuc break;
353433d6423SLionel Sambuc
354433d6423SLionel Sambuc default:
355433d6423SLionel Sambuc
356433d6423SLionel Sambuc /* All other types are invalid */
357433d6423SLionel Sambuc
358433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO,
359433d6423SLionel Sambuc "Source must be Integer/Buffer/String type, not %s",
360433d6423SLionel Sambuc AcpiUtGetObjectTypeName (SourceDesc)));
361433d6423SLionel Sambuc return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
362433d6423SLionel Sambuc }
363433d6423SLionel Sambuc
364433d6423SLionel Sambuc /* Store the source value into the target buffer byte */
365433d6423SLionel Sambuc
366433d6423SLionel Sambuc ObjDesc->Buffer.Pointer[IndexDesc->Reference.Value] = Value;
367433d6423SLionel Sambuc break;
368433d6423SLionel Sambuc
369433d6423SLionel Sambuc default:
370433d6423SLionel Sambuc ACPI_ERROR ((AE_INFO,
371433d6423SLionel Sambuc "Target is not a Package or BufferField"));
372433d6423SLionel Sambuc Status = AE_AML_OPERAND_TYPE;
373433d6423SLionel Sambuc break;
374433d6423SLionel Sambuc }
375433d6423SLionel Sambuc
376433d6423SLionel Sambuc return_ACPI_STATUS (Status);
377433d6423SLionel Sambuc }
378433d6423SLionel Sambuc
379433d6423SLionel Sambuc
380433d6423SLionel Sambuc /*******************************************************************************
381433d6423SLionel Sambuc *
382433d6423SLionel Sambuc * FUNCTION: AcpiExStoreObjectToNode
383433d6423SLionel Sambuc *
384433d6423SLionel Sambuc * PARAMETERS: SourceDesc - Value to be stored
385433d6423SLionel Sambuc * Node - Named object to receive the value
386433d6423SLionel Sambuc * WalkState - Current walk state
387433d6423SLionel Sambuc * ImplicitConversion - Perform implicit conversion (yes/no)
388433d6423SLionel Sambuc *
389433d6423SLionel Sambuc * RETURN: Status
390433d6423SLionel Sambuc *
391433d6423SLionel Sambuc * DESCRIPTION: Store the object to the named object.
392433d6423SLionel Sambuc *
393433d6423SLionel Sambuc * The Assignment of an object to a named object is handled here
394433d6423SLionel Sambuc * The value passed in will replace the current value (if any)
395433d6423SLionel Sambuc * with the input value.
396433d6423SLionel Sambuc *
397433d6423SLionel Sambuc * When storing into an object the data is converted to the
398433d6423SLionel Sambuc * target object type then stored in the object. This means
399433d6423SLionel Sambuc * that the target object type (for an initialized target) will
400*29492bb7SDavid van Moolenbroek * not be changed by a store operation. A CopyObject can change
401*29492bb7SDavid van Moolenbroek * the target type, however.
402*29492bb7SDavid van Moolenbroek *
403*29492bb7SDavid van Moolenbroek * The ImplicitConversion flag is set to NO/FALSE only when
404*29492bb7SDavid van Moolenbroek * storing to an ArgX -- as per the rules of the ACPI spec.
405433d6423SLionel Sambuc *
406433d6423SLionel Sambuc * Assumes parameters are already validated.
407433d6423SLionel Sambuc *
408433d6423SLionel Sambuc ******************************************************************************/
409433d6423SLionel Sambuc
410433d6423SLionel Sambuc ACPI_STATUS
AcpiExStoreObjectToNode(ACPI_OPERAND_OBJECT * SourceDesc,ACPI_NAMESPACE_NODE * Node,ACPI_WALK_STATE * WalkState,UINT8 ImplicitConversion)411433d6423SLionel Sambuc AcpiExStoreObjectToNode (
412433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *SourceDesc,
413433d6423SLionel Sambuc ACPI_NAMESPACE_NODE *Node,
414433d6423SLionel Sambuc ACPI_WALK_STATE *WalkState,
415433d6423SLionel Sambuc UINT8 ImplicitConversion)
416433d6423SLionel Sambuc {
417433d6423SLionel Sambuc ACPI_STATUS Status = AE_OK;
418433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *TargetDesc;
419433d6423SLionel Sambuc ACPI_OPERAND_OBJECT *NewDesc;
420433d6423SLionel Sambuc ACPI_OBJECT_TYPE TargetType;
421433d6423SLionel Sambuc
422433d6423SLionel Sambuc
423433d6423SLionel Sambuc ACPI_FUNCTION_TRACE_PTR (ExStoreObjectToNode, SourceDesc);
424433d6423SLionel Sambuc
425433d6423SLionel Sambuc
426433d6423SLionel Sambuc /* Get current type of the node, and object attached to Node */
427433d6423SLionel Sambuc
428433d6423SLionel Sambuc TargetType = AcpiNsGetType (Node);
429433d6423SLionel Sambuc TargetDesc = AcpiNsGetAttachedObject (Node);
430433d6423SLionel Sambuc
431*29492bb7SDavid van Moolenbroek ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Storing %p (%s) to node %p (%s)\n",
432433d6423SLionel Sambuc SourceDesc, AcpiUtGetObjectTypeName (SourceDesc),
433433d6423SLionel Sambuc Node, AcpiUtGetTypeName (TargetType)));
434433d6423SLionel Sambuc
435433d6423SLionel Sambuc /*
436433d6423SLionel Sambuc * Resolve the source object to an actual value
437433d6423SLionel Sambuc * (If it is a reference object)
438433d6423SLionel Sambuc */
439433d6423SLionel Sambuc Status = AcpiExResolveObject (&SourceDesc, TargetType, WalkState);
440433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
441433d6423SLionel Sambuc {
442433d6423SLionel Sambuc return_ACPI_STATUS (Status);
443433d6423SLionel Sambuc }
444433d6423SLionel Sambuc
445433d6423SLionel Sambuc /* Do the actual store operation */
446433d6423SLionel Sambuc
447433d6423SLionel Sambuc switch (TargetType)
448433d6423SLionel Sambuc {
449433d6423SLionel Sambuc case ACPI_TYPE_INTEGER:
450433d6423SLionel Sambuc case ACPI_TYPE_STRING:
451433d6423SLionel Sambuc case ACPI_TYPE_BUFFER:
452433d6423SLionel Sambuc /*
453*29492bb7SDavid van Moolenbroek * The simple data types all support implicit source operand
454*29492bb7SDavid van Moolenbroek * conversion before the store.
455433d6423SLionel Sambuc */
456*29492bb7SDavid van Moolenbroek
457*29492bb7SDavid van Moolenbroek if ((WalkState->Opcode == AML_COPY_OP) ||
458*29492bb7SDavid van Moolenbroek !ImplicitConversion)
459*29492bb7SDavid van Moolenbroek {
460*29492bb7SDavid van Moolenbroek /*
461*29492bb7SDavid van Moolenbroek * However, CopyObject and Stores to ArgX do not perform
462*29492bb7SDavid van Moolenbroek * an implicit conversion, as per the ACPI specification.
463*29492bb7SDavid van Moolenbroek * A direct store is performed instead.
464*29492bb7SDavid van Moolenbroek */
465*29492bb7SDavid van Moolenbroek Status = AcpiExStoreDirectToNode (SourceDesc, Node,
466*29492bb7SDavid van Moolenbroek WalkState);
467*29492bb7SDavid van Moolenbroek break;
468*29492bb7SDavid van Moolenbroek }
469*29492bb7SDavid van Moolenbroek
470*29492bb7SDavid van Moolenbroek /* Store with implicit source operand conversion support */
471*29492bb7SDavid van Moolenbroek
472433d6423SLionel Sambuc Status = AcpiExStoreObjectToObject (SourceDesc, TargetDesc,
473433d6423SLionel Sambuc &NewDesc, WalkState);
474433d6423SLionel Sambuc if (ACPI_FAILURE (Status))
475433d6423SLionel Sambuc {
476433d6423SLionel Sambuc return_ACPI_STATUS (Status);
477433d6423SLionel Sambuc }
478433d6423SLionel Sambuc
479433d6423SLionel Sambuc if (NewDesc != TargetDesc)
480433d6423SLionel Sambuc {
481433d6423SLionel Sambuc /*
482433d6423SLionel Sambuc * Store the new NewDesc as the new value of the Name, and set
483433d6423SLionel Sambuc * the Name's type to that of the value being stored in it.
484433d6423SLionel Sambuc * SourceDesc reference count is incremented by AttachObject.
485433d6423SLionel Sambuc *
486*29492bb7SDavid van Moolenbroek * Note: This may change the type of the node if an explicit
487*29492bb7SDavid van Moolenbroek * store has been performed such that the node/object type
488*29492bb7SDavid van Moolenbroek * has been changed.
489433d6423SLionel Sambuc */
490*29492bb7SDavid van Moolenbroek Status = AcpiNsAttachObject (Node, NewDesc,
491*29492bb7SDavid van Moolenbroek NewDesc->Common.Type);
492433d6423SLionel Sambuc
493433d6423SLionel Sambuc ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
494433d6423SLionel Sambuc "Store %s into %s via Convert/Attach\n",
495433d6423SLionel Sambuc AcpiUtGetObjectTypeName (SourceDesc),
496433d6423SLionel Sambuc AcpiUtGetObjectTypeName (NewDesc)));
497433d6423SLionel Sambuc }
498433d6423SLionel Sambuc break;
499433d6423SLionel Sambuc
500*29492bb7SDavid van Moolenbroek case ACPI_TYPE_BUFFER_FIELD:
501*29492bb7SDavid van Moolenbroek case ACPI_TYPE_LOCAL_REGION_FIELD:
502*29492bb7SDavid van Moolenbroek case ACPI_TYPE_LOCAL_BANK_FIELD:
503*29492bb7SDavid van Moolenbroek case ACPI_TYPE_LOCAL_INDEX_FIELD:
504*29492bb7SDavid van Moolenbroek /*
505*29492bb7SDavid van Moolenbroek * For all fields, always write the source data to the target
506*29492bb7SDavid van Moolenbroek * field. Any required implicit source operand conversion is
507*29492bb7SDavid van Moolenbroek * performed in the function below as necessary. Note, field
508*29492bb7SDavid van Moolenbroek * objects must retain their original type permanently.
509*29492bb7SDavid van Moolenbroek */
510*29492bb7SDavid van Moolenbroek Status = AcpiExWriteDataToField (SourceDesc, TargetDesc,
511*29492bb7SDavid van Moolenbroek &WalkState->ResultObj);
512*29492bb7SDavid van Moolenbroek break;
513433d6423SLionel Sambuc
514433d6423SLionel Sambuc default:
515*29492bb7SDavid van Moolenbroek /*
516*29492bb7SDavid van Moolenbroek * No conversions for all other types. Directly store a copy of
517*29492bb7SDavid van Moolenbroek * the source object. This is the ACPI spec-defined behavior for
518*29492bb7SDavid van Moolenbroek * the CopyObject operator.
519*29492bb7SDavid van Moolenbroek *
520*29492bb7SDavid van Moolenbroek * NOTE: For the Store operator, this is a departure from the
521*29492bb7SDavid van Moolenbroek * ACPI spec, which states "If conversion is impossible, abort
522*29492bb7SDavid van Moolenbroek * the running control method". Instead, this code implements
523*29492bb7SDavid van Moolenbroek * "If conversion is impossible, treat the Store operation as
524*29492bb7SDavid van Moolenbroek * a CopyObject".
525*29492bb7SDavid van Moolenbroek */
526*29492bb7SDavid van Moolenbroek Status = AcpiExStoreDirectToNode (SourceDesc, Node,
527*29492bb7SDavid van Moolenbroek WalkState);
528433d6423SLionel Sambuc break;
529433d6423SLionel Sambuc }
530433d6423SLionel Sambuc
531433d6423SLionel Sambuc return_ACPI_STATUS (Status);
532433d6423SLionel Sambuc }
533433d6423SLionel Sambuc
534433d6423SLionel Sambuc
535*29492bb7SDavid van Moolenbroek /*******************************************************************************
536*29492bb7SDavid van Moolenbroek *
537*29492bb7SDavid van Moolenbroek * FUNCTION: AcpiExStoreDirectToNode
538*29492bb7SDavid van Moolenbroek *
539*29492bb7SDavid van Moolenbroek * PARAMETERS: SourceDesc - Value to be stored
540*29492bb7SDavid van Moolenbroek * Node - Named object to receive the value
541*29492bb7SDavid van Moolenbroek * WalkState - Current walk state
542*29492bb7SDavid van Moolenbroek *
543*29492bb7SDavid van Moolenbroek * RETURN: Status
544*29492bb7SDavid van Moolenbroek *
545*29492bb7SDavid van Moolenbroek * DESCRIPTION: "Store" an object directly to a node. This involves a copy
546*29492bb7SDavid van Moolenbroek * and an attach.
547*29492bb7SDavid van Moolenbroek *
548*29492bb7SDavid van Moolenbroek ******************************************************************************/
549*29492bb7SDavid van Moolenbroek
550*29492bb7SDavid van Moolenbroek static ACPI_STATUS
AcpiExStoreDirectToNode(ACPI_OPERAND_OBJECT * SourceDesc,ACPI_NAMESPACE_NODE * Node,ACPI_WALK_STATE * WalkState)551*29492bb7SDavid van Moolenbroek AcpiExStoreDirectToNode (
552*29492bb7SDavid van Moolenbroek ACPI_OPERAND_OBJECT *SourceDesc,
553*29492bb7SDavid van Moolenbroek ACPI_NAMESPACE_NODE *Node,
554*29492bb7SDavid van Moolenbroek ACPI_WALK_STATE *WalkState)
555*29492bb7SDavid van Moolenbroek {
556*29492bb7SDavid van Moolenbroek ACPI_STATUS Status;
557*29492bb7SDavid van Moolenbroek ACPI_OPERAND_OBJECT *NewDesc;
558*29492bb7SDavid van Moolenbroek
559*29492bb7SDavid van Moolenbroek
560*29492bb7SDavid van Moolenbroek ACPI_FUNCTION_TRACE (ExStoreDirectToNode);
561*29492bb7SDavid van Moolenbroek
562*29492bb7SDavid van Moolenbroek
563*29492bb7SDavid van Moolenbroek ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
564*29492bb7SDavid van Moolenbroek "Storing [%s] (%p) directly into node [%s] (%p)"
565*29492bb7SDavid van Moolenbroek " with no implicit conversion\n",
566*29492bb7SDavid van Moolenbroek AcpiUtGetObjectTypeName (SourceDesc), SourceDesc,
567*29492bb7SDavid van Moolenbroek AcpiUtGetTypeName (Node->Type), Node));
568*29492bb7SDavid van Moolenbroek
569*29492bb7SDavid van Moolenbroek /* Copy the source object to a new object */
570*29492bb7SDavid van Moolenbroek
571*29492bb7SDavid van Moolenbroek Status = AcpiUtCopyIobjectToIobject (SourceDesc, &NewDesc, WalkState);
572*29492bb7SDavid van Moolenbroek if (ACPI_FAILURE (Status))
573*29492bb7SDavid van Moolenbroek {
574*29492bb7SDavid van Moolenbroek return_ACPI_STATUS (Status);
575*29492bb7SDavid van Moolenbroek }
576*29492bb7SDavid van Moolenbroek
577*29492bb7SDavid van Moolenbroek /* Attach the new object to the node */
578*29492bb7SDavid van Moolenbroek
579*29492bb7SDavid van Moolenbroek Status = AcpiNsAttachObject (Node, NewDesc, NewDesc->Common.Type);
580*29492bb7SDavid van Moolenbroek AcpiUtRemoveReference (NewDesc);
581*29492bb7SDavid van Moolenbroek return_ACPI_STATUS (Status);
582*29492bb7SDavid van Moolenbroek }
583