exstorob.c revision 69450
146686Sbrian
246686Sbrian/******************************************************************************
346686Sbrian *
446686Sbrian * Module Name: amstorob - AML Interpreter object store support, store to object
546686Sbrian *              $Revision: 17 $
646686Sbrian *
746686Sbrian *****************************************************************************/
846686Sbrian
946686Sbrian/******************************************************************************
1046686Sbrian *
1146686Sbrian * 1. Copyright Notice
1246686Sbrian *
1346686Sbrian * Some or all of this work - Copyright (c) 1999, Intel Corp.  All rights
1446686Sbrian * reserved.
1546686Sbrian *
1646686Sbrian * 2. License
1746686Sbrian *
1846686Sbrian * 2.1. This is your license from Intel Corp. under its intellectual property
1946686Sbrian * rights.  You may have additional license terms from the party that provided
2046686Sbrian * you this software, covering your right to use that party's intellectual
2146686Sbrian * property rights.
2246686Sbrian *
2346686Sbrian * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2446686Sbrian * copy of the source code appearing in this file ("Covered Code") an
2546686Sbrian * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2646686Sbrian * base code distributed originally by Intel ("Original Intel Code") to copy,
2746686Sbrian * make derivatives, distribute, use and display any portion of the Covered
2846686Sbrian * Code in any form, with the right to sublicense such rights; and
2946686Sbrian *
3046686Sbrian * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3146686Sbrian * license (with the right to sublicense), under only those claims of Intel
3246686Sbrian * patents that are infringed by the Original Intel Code, to make, use, sell,
3346686Sbrian * offer to sell, and import the Covered Code and derivative works thereof
3446686Sbrian * solely to the minimum extent necessary to exercise the above copyright
3546686Sbrian * license, and in no event shall the patent license extend to any additions
3646686Sbrian * to or modifications of the Original Intel Code.  No other license or right
3746686Sbrian * is granted directly or by implication, estoppel or otherwise;
3846686Sbrian *
3946686Sbrian * The above copyright and patent license is granted only if the following
4046686Sbrian * conditions are met:
4146686Sbrian *
4246686Sbrian * 3. Conditions
4346686Sbrian *
4446686Sbrian * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4546686Sbrian * Redistribution of source code of any substantial portion of the Covered
4646686Sbrian * Code or modification with rights to further distribute source must include
4746686Sbrian * the above Copyright Notice, the above License, this list of Conditions,
4846686Sbrian * and the following Disclaimer and Export Compliance provision.  In addition,
4946686Sbrian * Licensee must cause all Covered Code to which Licensee contributes to
5046686Sbrian * contain a file documenting the changes Licensee made to create that Covered
5146686Sbrian * Code and the date of any change.  Licensee must include in that file the
5246686Sbrian * documentation of any changes made by any predecessor Licensee.  Licensee
5346686Sbrian * must include a prominent statement that the modification is derived,
5446686Sbrian * directly or indirectly, from Original Intel Code.
5546686Sbrian *
5646686Sbrian * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5746686Sbrian * Redistribution of source code of any substantial portion of the Covered
5846686Sbrian * Code or modification without rights to further distribute source must
5946686Sbrian * include the following Disclaimer and Export Compliance provision in the
6046686Sbrian * documentation and/or other materials provided with distribution.  In
6146686Sbrian * addition, Licensee may not authorize further sublicense of source of any
6246686Sbrian * portion of the Covered Code, and must include terms to the effect that the
6346686Sbrian * license from Licensee to its licensee is limited to the intellectual
6446686Sbrian * property embodied in the software Licensee provides to its licensee, and
6546686Sbrian * not to intellectual property embodied in modifications its licensee may
6646686Sbrian * make.
6746686Sbrian *
6846686Sbrian * 3.3. Redistribution of Executable. Redistribution in executable form of any
6946686Sbrian * substantial portion of the Covered Code or modification must reproduce the
7046686Sbrian * above Copyright Notice, and the following Disclaimer and Export Compliance
7146686Sbrian * provision in the documentation and/or other materials provided with the
7246686Sbrian * distribution.
7346686Sbrian *
7446686Sbrian * 3.4. Intel retains all right, title, and interest in and to the Original
7546686Sbrian * Intel Code.
7646686Sbrian *
7746686Sbrian * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7846686Sbrian * Intel shall be used in advertising or otherwise to promote the sale, use or
7946686Sbrian * other dealings in products derived from or relating to the Covered Code
8046686Sbrian * without prior written authorization from Intel.
8146686Sbrian *
8246686Sbrian * 4. Disclaimer and Export Compliance
8346686Sbrian *
8446686Sbrian * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8546686Sbrian * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8646686Sbrian * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8746686Sbrian * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8846686Sbrian * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8946686Sbrian * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
9046686Sbrian * PARTICULAR PURPOSE.
9146686Sbrian *
9246686Sbrian * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9346686Sbrian * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9446686Sbrian * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9546686Sbrian * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9646686Sbrian * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9746686Sbrian * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9846686Sbrian * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
9946686Sbrian * LIMITED REMEDY.
10046686Sbrian *
10146686Sbrian * 4.3. Licensee shall not export, either directly or indirectly, any of this
10246686Sbrian * software or system incorporating such software without first obtaining any
10346686Sbrian * required license or other approval from the U. S. Department of Commerce or
10446686Sbrian * any other agency or department of the United States Government.  In the
10546686Sbrian * event Licensee exports any such software from the United States or
10646686Sbrian * re-exports any such software from a foreign destination, Licensee shall
10746686Sbrian * ensure that the distribution and export/re-export of the software is in
10846686Sbrian * compliance with all laws, regulations, orders, or other restrictions of the
10946686Sbrian * U.S. Export Administration Regulations. Licensee agrees that neither it nor
11046686Sbrian * any of its subsidiaries will export/re-export any technical data, process,
11146686Sbrian * software, or service, directly or indirectly, to any country for which the
11246686Sbrian * United States government or any agency thereof requires an export license,
11346686Sbrian * other governmental approval, or letter of assurance, without first obtaining
11446686Sbrian * such license, approval or letter.
11546686Sbrian *
11646686Sbrian *****************************************************************************/
11746686Sbrian
11846686Sbrian#define __AMSTOROB_C__
11946686Sbrian
12046686Sbrian#include "acpi.h"
12146686Sbrian#include "acparser.h"
12246686Sbrian#include "acdispat.h"
12346686Sbrian#include "acinterp.h"
12446686Sbrian#include "amlcode.h"
12546686Sbrian#include "acnamesp.h"
12646686Sbrian#include "actables.h"
12746686Sbrian
12846686Sbrian
12946686Sbrian#define _COMPONENT          INTERPRETER
13046686Sbrian        MODULE_NAME         ("amstorob")
13146686Sbrian
13246686Sbrian
13346686Sbrian/*******************************************************************************
13446686Sbrian *
13546686Sbrian * FUNCTION:    AcpiAmlStoreObjectToObject
13646686Sbrian *
13746686Sbrian * PARAMETERS:  *ValDesc            - Value to be stored
13846686Sbrian *              *DestDesc           - Object to receive the value
13946686Sbrian *
14046686Sbrian * RETURN:      Status
14146686Sbrian *
14246686Sbrian * DESCRIPTION: Store an object to another object.
14346686Sbrian *
14446686Sbrian *              The Assignment of an object to another (not named) object
14546686Sbrian *              is handled here.
14646686Sbrian *              The val passed in will replace the current value (if any)
14746686Sbrian *              with the input value.
14846686Sbrian *
14946686Sbrian *              When storing into an object the data is converted to the
15046686Sbrian *              target object type then stored in the object.  This means
15146686Sbrian *              that the target object type (for an initialized target) will
15246686Sbrian *              not be changed by a store operation.
15346686Sbrian *
15446686Sbrian *              This module allows destination types of Number, String,
15546686Sbrian *              and Buffer.
15646686Sbrian *
15746686Sbrian ******************************************************************************/
15846686Sbrian
15946686SbrianACPI_STATUS
16046686SbrianAcpiAmlStoreObjectToObject (
161    ACPI_OPERAND_OBJECT     *ValDesc,
162    ACPI_OPERAND_OBJECT     *DestDesc,
163    ACPI_WALK_STATE         *WalkState)
164{
165    ACPI_STATUS             Status = AE_OK;
166    UINT8                   *Buffer = NULL;
167    UINT32                  Length = 0;
168    OBJECT_TYPE_INTERNAL    DestinationType = DestDesc->Common.Type;
169
170
171    FUNCTION_TRACE ("AmlStoreObjectToObject");
172
173    DEBUG_PRINT (ACPI_INFO,
174        ("entered AcpiAmlStoreObjectToObject: Dest=%p, Val=%p\n",
175        DestDesc, ValDesc));
176
177    /*
178     *  Assuming the parameters are valid!!!
179     */
180    ACPI_ASSERT((DestDesc) && (ValDesc));
181
182    DEBUG_PRINT (ACPI_INFO, ("AmlStoreObjectToObject: Storing %s into %s\n",
183                    AcpiCmGetTypeName (ValDesc->Common.Type),
184                    AcpiCmGetTypeName (DestDesc->Common.Type)));
185
186    /*
187     *  First ensure we have a value that can be stored in the target
188     */
189    switch (DestinationType)
190    {
191        /* Type of Name's existing value */
192
193    case ACPI_TYPE_NUMBER:
194
195        /*
196         *  These cases all require only number values or values that
197         *  can be converted to numbers.
198         *
199         *  If value is not a Number, try to resolve it to one.
200         */
201
202        if (ValDesc->Common.Type != ACPI_TYPE_NUMBER)
203        {
204            /*
205             *  Initially not a number, convert
206             */
207            Status = AcpiAmlResolveToValue (&ValDesc, WalkState);
208            if (ACPI_SUCCESS (Status) &&
209                (ValDesc->Common.Type != ACPI_TYPE_NUMBER))
210            {
211                /*
212                 *  Conversion successful but still not a number
213                 */
214                DEBUG_PRINT (ACPI_ERROR,
215                    ("AmlStoreObjectToObject: Value assigned to %s must be Number, not %s\n",
216                    AcpiCmGetTypeName (DestinationType),
217                    AcpiCmGetTypeName (ValDesc->Common.Type)));
218                Status = AE_AML_OPERAND_TYPE;
219            }
220        }
221
222        break;
223
224    case ACPI_TYPE_STRING:
225    case ACPI_TYPE_BUFFER:
226
227        /*
228         *  Storing into a Field in a region or into a buffer or into
229         *  a string all is essentially the same.
230         *
231         *  If value is not a valid type, try to resolve it to one.
232         */
233
234        if ((ValDesc->Common.Type != ACPI_TYPE_NUMBER) &&
235            (ValDesc->Common.Type != ACPI_TYPE_BUFFER) &&
236            (ValDesc->Common.Type != ACPI_TYPE_STRING))
237        {
238            /*
239             *  Initially not a valid type, convert
240             */
241            Status = AcpiAmlResolveToValue (&ValDesc, WalkState);
242            if (ACPI_SUCCESS (Status) &&
243                (ValDesc->Common.Type != ACPI_TYPE_NUMBER) &&
244                (ValDesc->Common.Type != ACPI_TYPE_BUFFER) &&
245                (ValDesc->Common.Type != ACPI_TYPE_STRING))
246            {
247                /*
248                 *  Conversion successful but still not a valid type
249                 */
250                DEBUG_PRINT (ACPI_ERROR,
251                    ("AmlStoreObjectToObject: Assign wrong type %s to %s (must be type Num/Str/Buf)\n",
252                    AcpiCmGetTypeName (ValDesc->Common.Type),
253                    AcpiCmGetTypeName (DestinationType)));
254                Status = AE_AML_OPERAND_TYPE;
255            }
256        }
257        break;
258
259
260    default:
261
262        /*
263         * TBD: [Unhandled] What other combinations must be implemented?
264         */
265        Status = AE_NOT_IMPLEMENTED;
266        break;
267    }
268
269    /* Exit now if failure above */
270
271    if (ACPI_FAILURE (Status))
272    {
273        goto CleanUpAndBailOut;
274    }
275
276    /*
277     * AcpiEverything is ready to execute now,  We have
278     * a value we can handle, just perform the update
279     */
280
281    switch (DestinationType)
282    {
283
284    case ACPI_TYPE_STRING:
285
286        /*
287         *  Perform the update
288         */
289
290        switch (ValDesc->Common.Type)
291        {
292        case ACPI_TYPE_NUMBER:
293            Buffer = (UINT8 *) &ValDesc->Number.Value;
294            Length = sizeof (ValDesc->Number.Value);
295            break;
296
297        case ACPI_TYPE_BUFFER:
298            Buffer = (UINT8 *) ValDesc->Buffer.Pointer;
299            Length = ValDesc->Buffer.Length;
300            break;
301
302        case ACPI_TYPE_STRING:
303            Buffer = (UINT8 *) ValDesc->String.Pointer;
304            Length = ValDesc->String.Length;
305            break;
306        }
307
308        /*
309         *  Setting a string value replaces the old string
310         */
311
312        if (Length < DestDesc->String.Length)
313        {
314            /*
315             *  Zero fill, not willing to do pointer arithmetic for
316             *  architecture independence.  Just clear the whole thing
317             */
318            MEMSET(DestDesc->String.Pointer, 0, DestDesc->String.Length);
319            MEMCPY(DestDesc->String.Pointer, Buffer, Length);
320        }
321        else
322        {
323            /*
324             *  Free the current buffer, then allocate a buffer
325             *  large enough to hold the value
326             */
327            if ( DestDesc->String.Pointer &&
328                !AcpiTbSystemTablePointer (DestDesc->String.Pointer))
329            {
330                /*
331                 *  Only free if not a pointer into the DSDT
332                 */
333
334                AcpiCmFree(DestDesc->String.Pointer);
335            }
336
337            DestDesc->String.Pointer = AcpiCmAllocate (Length + 1);
338            DestDesc->String.Length = Length;
339
340            if (!DestDesc->String.Pointer)
341            {
342                Status = AE_NO_MEMORY;
343                goto CleanUpAndBailOut;
344            }
345
346            MEMCPY(DestDesc->String.Pointer, Buffer, Length);
347        }
348        break;
349
350
351    case ACPI_TYPE_BUFFER:
352
353        /*
354         *  Perform the update to the buffer
355         */
356
357        switch (ValDesc->Common.Type)
358        {
359        case ACPI_TYPE_NUMBER:
360            Buffer = (UINT8 *) &ValDesc->Number.Value;
361            Length = sizeof (ValDesc->Number.Value);
362            break;
363
364        case ACPI_TYPE_BUFFER:
365            Buffer = (UINT8 *) ValDesc->Buffer.Pointer;
366            Length = ValDesc->Buffer.Length;
367            break;
368
369        case ACPI_TYPE_STRING:
370            Buffer = (UINT8 *) ValDesc->String.Pointer;
371            Length = ValDesc->String.Length;
372            break;
373        }
374
375        /*
376         * If the buffer is uninitialized,
377         *  memory needs to be allocated for the copy.
378         */
379        if(0 == DestDesc->Buffer.Length)
380        {
381            DestDesc->Buffer.Pointer = AcpiCmCallocate(Length);
382            DestDesc->Buffer.Length = Length;
383
384            if (!DestDesc->Buffer.Pointer)
385            {
386                Status = AE_NO_MEMORY;
387                goto CleanUpAndBailOut;
388            }
389        }
390
391        /*
392         *  Buffer is a static allocation,
393         *  only place what will fit in the buffer.
394         */
395        if (Length <= DestDesc->Buffer.Length)
396        {
397            /*
398             *  Zero fill first, not willing to do pointer arithmetic for
399             *  architecture independence.  Just clear the whole thing
400             */
401            MEMSET(DestDesc->Buffer.Pointer, 0, DestDesc->Buffer.Length);
402            MEMCPY(DestDesc->Buffer.Pointer, Buffer, Length);
403        }
404        else
405        {
406            /*
407             *  truncate, copy only what will fit
408             */
409            MEMCPY(DestDesc->Buffer.Pointer, Buffer, DestDesc->Buffer.Length);
410            DEBUG_PRINT (ACPI_INFO,
411                ("AmlStoreObjectToObject: Truncating src buffer from %d to %d\n",
412                Length, DestDesc->Buffer.Length));
413        }
414        break;
415
416    case ACPI_TYPE_NUMBER:
417
418        DestDesc->Number.Value = ValDesc->Number.Value;
419
420        /* Truncate value if we are executing from a 32-bit ACPI table */
421
422        AcpiAmlTruncateFor32bitTable (DestDesc, WalkState);
423        break;
424
425    default:
426
427        /*
428         * All other types than Alias and the various Fields come here.
429         * Store ValDesc as the new value of the Name, and set
430         * the Name's type to that of the value being stored in it.
431         * ValDesc reference count is incremented by AttachObject.
432         */
433
434        DEBUG_PRINT (ACPI_WARN,
435            ("AmlStoreObjectToObject: Store into %s not implemented\n",
436            AcpiCmGetTypeName (DestDesc->Common.Type)));
437
438        Status = AE_NOT_IMPLEMENTED;
439        break;
440    }
441
442CleanUpAndBailOut:
443
444    return_ACPI_STATUS (Status);
445}
446
447