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