exstore.c revision 204773
167754Smsmith/****************************************************************************** 267754Smsmith * 377424Smsmith * Module Name: exstore - AML Interpreter object store support 467754Smsmith * 567754Smsmith *****************************************************************************/ 667754Smsmith 767754Smsmith/****************************************************************************** 867754Smsmith * 967754Smsmith * 1. Copyright Notice 1067754Smsmith * 11202771Sjkim * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp. 1270243Smsmith * All rights reserved. 1367754Smsmith * 1467754Smsmith * 2. License 1567754Smsmith * 1667754Smsmith * 2.1. This is your license from Intel Corp. under its intellectual property 1767754Smsmith * rights. You may have additional license terms from the party that provided 1867754Smsmith * you this software, covering your right to use that party's intellectual 1967754Smsmith * property rights. 2067754Smsmith * 2167754Smsmith * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 2267754Smsmith * copy of the source code appearing in this file ("Covered Code") an 2367754Smsmith * irrevocable, perpetual, worldwide license under Intel's copyrights in the 2467754Smsmith * base code distributed originally by Intel ("Original Intel Code") to copy, 2567754Smsmith * make derivatives, distribute, use and display any portion of the Covered 2667754Smsmith * Code in any form, with the right to sublicense such rights; and 2767754Smsmith * 2867754Smsmith * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 2967754Smsmith * license (with the right to sublicense), under only those claims of Intel 3067754Smsmith * patents that are infringed by the Original Intel Code, to make, use, sell, 3167754Smsmith * offer to sell, and import the Covered Code and derivative works thereof 3267754Smsmith * solely to the minimum extent necessary to exercise the above copyright 3367754Smsmith * license, and in no event shall the patent license extend to any additions 3467754Smsmith * to or modifications of the Original Intel Code. No other license or right 3567754Smsmith * is granted directly or by implication, estoppel or otherwise; 3667754Smsmith * 3767754Smsmith * The above copyright and patent license is granted only if the following 3867754Smsmith * conditions are met: 3967754Smsmith * 4067754Smsmith * 3. Conditions 4167754Smsmith * 4267754Smsmith * 3.1. Redistribution of Source with Rights to Further Distribute Source. 4367754Smsmith * Redistribution of source code of any substantial portion of the Covered 4467754Smsmith * Code or modification with rights to further distribute source must include 4567754Smsmith * the above Copyright Notice, the above License, this list of Conditions, 4667754Smsmith * and the following Disclaimer and Export Compliance provision. In addition, 4767754Smsmith * Licensee must cause all Covered Code to which Licensee contributes to 4867754Smsmith * contain a file documenting the changes Licensee made to create that Covered 4967754Smsmith * Code and the date of any change. Licensee must include in that file the 5067754Smsmith * documentation of any changes made by any predecessor Licensee. Licensee 5167754Smsmith * must include a prominent statement that the modification is derived, 5267754Smsmith * directly or indirectly, from Original Intel Code. 5367754Smsmith * 5467754Smsmith * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 5567754Smsmith * Redistribution of source code of any substantial portion of the Covered 5667754Smsmith * Code or modification without rights to further distribute source must 5767754Smsmith * include the following Disclaimer and Export Compliance provision in the 5867754Smsmith * documentation and/or other materials provided with distribution. In 5967754Smsmith * addition, Licensee may not authorize further sublicense of source of any 6067754Smsmith * portion of the Covered Code, and must include terms to the effect that the 6167754Smsmith * license from Licensee to its licensee is limited to the intellectual 6267754Smsmith * property embodied in the software Licensee provides to its licensee, and 6367754Smsmith * not to intellectual property embodied in modifications its licensee may 6467754Smsmith * make. 6567754Smsmith * 6667754Smsmith * 3.3. Redistribution of Executable. Redistribution in executable form of any 6767754Smsmith * substantial portion of the Covered Code or modification must reproduce the 6867754Smsmith * above Copyright Notice, and the following Disclaimer and Export Compliance 6967754Smsmith * provision in the documentation and/or other materials provided with the 7067754Smsmith * distribution. 7167754Smsmith * 7267754Smsmith * 3.4. Intel retains all right, title, and interest in and to the Original 7367754Smsmith * Intel Code. 7467754Smsmith * 7567754Smsmith * 3.5. Neither the name Intel nor any other trademark owned or controlled by 7667754Smsmith * Intel shall be used in advertising or otherwise to promote the sale, use or 7767754Smsmith * other dealings in products derived from or relating to the Covered Code 7867754Smsmith * without prior written authorization from Intel. 7967754Smsmith * 8067754Smsmith * 4. Disclaimer and Export Compliance 8167754Smsmith * 8267754Smsmith * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 8367754Smsmith * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 8467754Smsmith * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 8567754Smsmith * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 8667754Smsmith * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 8767754Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 8867754Smsmith * PARTICULAR PURPOSE. 8967754Smsmith * 9067754Smsmith * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 9167754Smsmith * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 9267754Smsmith * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 9367754Smsmith * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 9467754Smsmith * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 9567754Smsmith * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 9667754Smsmith * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 9767754Smsmith * LIMITED REMEDY. 9867754Smsmith * 9967754Smsmith * 4.3. Licensee shall not export, either directly or indirectly, any of this 10067754Smsmith * software or system incorporating such software without first obtaining any 10167754Smsmith * required license or other approval from the U. S. Department of Commerce or 10267754Smsmith * any other agency or department of the United States Government. In the 10367754Smsmith * event Licensee exports any such software from the United States or 10467754Smsmith * re-exports any such software from a foreign destination, Licensee shall 10567754Smsmith * ensure that the distribution and export/re-export of the software is in 10667754Smsmith * compliance with all laws, regulations, orders, or other restrictions of the 10767754Smsmith * U.S. Export Administration Regulations. Licensee agrees that neither it nor 10867754Smsmith * any of its subsidiaries will export/re-export any technical data, process, 10967754Smsmith * software, or service, directly or indirectly, to any country for which the 11067754Smsmith * United States government or any agency thereof requires an export license, 11167754Smsmith * other governmental approval, or letter of assurance, without first obtaining 11267754Smsmith * such license, approval or letter. 11367754Smsmith * 11467754Smsmith *****************************************************************************/ 11567754Smsmith 11677424Smsmith#define __EXSTORE_C__ 11767754Smsmith 118193341Sjkim#include <contrib/dev/acpica/include/acpi.h> 119193341Sjkim#include <contrib/dev/acpica/include/accommon.h> 120193341Sjkim#include <contrib/dev/acpica/include/acdispat.h> 121193341Sjkim#include <contrib/dev/acpica/include/acinterp.h> 122193341Sjkim#include <contrib/dev/acpica/include/amlcode.h> 123193341Sjkim#include <contrib/dev/acpica/include/acnamesp.h> 12467754Smsmith 12567754Smsmith 12677424Smsmith#define _COMPONENT ACPI_EXECUTER 12791116Smsmith ACPI_MODULE_NAME ("exstore") 12867754Smsmith 129151937Sjkim/* Local prototypes */ 13067754Smsmith 131151937Sjkimstatic ACPI_STATUS 132151937SjkimAcpiExStoreObjectToIndex ( 133151937Sjkim ACPI_OPERAND_OBJECT *ValDesc, 134151937Sjkim ACPI_OPERAND_OBJECT *DestDesc, 135151937Sjkim ACPI_WALK_STATE *WalkState); 136151937Sjkim 137151937Sjkim 13867754Smsmith/******************************************************************************* 13967754Smsmith * 14077424Smsmith * FUNCTION: AcpiExStore 14167754Smsmith * 14285756Smsmith * PARAMETERS: *SourceDesc - Value to be stored 14377424Smsmith * *DestDesc - Where to store it. Must be an NS node 14477424Smsmith * or an ACPI_OPERAND_OBJECT of type 14587031Smsmith * Reference; 14687031Smsmith * WalkState - Current walk state 14767754Smsmith * 14867754Smsmith * RETURN: Status 14967754Smsmith * 15085756Smsmith * DESCRIPTION: Store the value described by SourceDesc into the location 15167754Smsmith * described by DestDesc. Called by various interpreter 15267754Smsmith * functions to store the result of an operation into 15391116Smsmith * the destination operand -- not just simply the actual "Store" 15487031Smsmith * ASL operator. 15567754Smsmith * 15667754Smsmith ******************************************************************************/ 15767754Smsmith 15867754SmsmithACPI_STATUS 15977424SmsmithAcpiExStore ( 16085756Smsmith ACPI_OPERAND_OBJECT *SourceDesc, 16167754Smsmith ACPI_OPERAND_OBJECT *DestDesc, 16267754Smsmith ACPI_WALK_STATE *WalkState) 16367754Smsmith{ 16467754Smsmith ACPI_STATUS Status = AE_OK; 16571867Smsmith ACPI_OPERAND_OBJECT *RefDesc = DestDesc; 16667754Smsmith 16767754Smsmith 168167802Sjkim ACPI_FUNCTION_TRACE_PTR (ExStore, DestDesc); 16967754Smsmith 17067754Smsmith 17167754Smsmith /* Validate parameters */ 17267754Smsmith 17385756Smsmith if (!SourceDesc || !DestDesc) 17467754Smsmith { 175167802Sjkim ACPI_ERROR ((AE_INFO, "Null parameter")); 17667754Smsmith return_ACPI_STATUS (AE_AML_NO_OPERAND); 17767754Smsmith } 17867754Smsmith 17971867Smsmith /* DestDesc can be either a namespace node or an ACPI object */ 18067754Smsmith 18191116Smsmith if (ACPI_GET_DESCRIPTOR_TYPE (DestDesc) == ACPI_DESC_TYPE_NAMED) 18267754Smsmith { 18377424Smsmith /* 18471867Smsmith * Dest is a namespace node, 185107325Siwasaki * Storing an object into a Named node. 18671867Smsmith */ 18785756Smsmith Status = AcpiExStoreObjectToNode (SourceDesc, 188128212Snjl (ACPI_NAMESPACE_NODE *) DestDesc, WalkState, 189128212Snjl ACPI_IMPLICIT_CONVERSION); 19067754Smsmith 19171867Smsmith return_ACPI_STATUS (Status); 19267754Smsmith } 19367754Smsmith 19499679Siwasaki /* Destination object must be a Reference or a Constant object */ 19567754Smsmith 196193267Sjkim switch (DestDesc->Common.Type) 197102550Siwasaki { 198107325Siwasaki case ACPI_TYPE_LOCAL_REFERENCE: 19999679Siwasaki break; 20099679Siwasaki 20199679Siwasaki case ACPI_TYPE_INTEGER: 20299679Siwasaki 20399679Siwasaki /* Allow stores to Constants -- a Noop as per ACPI spec */ 20499679Siwasaki 20599679Siwasaki if (DestDesc->Common.Flags & AOPOBJ_AML_CONSTANT) 20699679Siwasaki { 20799679Siwasaki return_ACPI_STATUS (AE_OK); 20899679Siwasaki } 20999679Siwasaki 210104470Siwasaki /*lint -fallthrough */ 21199679Siwasaki 21299679Siwasaki default: 21399679Siwasaki 214126372Snjl /* Destination is not a Reference object */ 21567754Smsmith 216167802Sjkim ACPI_ERROR ((AE_INFO, 217167802Sjkim "Target is not a Reference or Constant object - %s [%p]", 218138287Smarks AcpiUtGetObjectTypeName (DestDesc), DestDesc)); 21967754Smsmith 22067754Smsmith return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 22167754Smsmith } 22267754Smsmith 22377424Smsmith /* 224193267Sjkim * Examine the Reference class. These cases are handled: 22571867Smsmith * 22671867Smsmith * 1) Store to Name (Change the object associated with a name) 22771867Smsmith * 2) Store to an indexed area of a Buffer or Package 22871867Smsmith * 3) Store to a Method Local or Arg 22971867Smsmith * 4) Store to the debug object 23071867Smsmith */ 231193267Sjkim switch (RefDesc->Reference.Class) 23267754Smsmith { 233193267Sjkim case ACPI_REFCLASS_REFOF: 23467754Smsmith 23571867Smsmith /* Storing an object into a Name "container" */ 23671867Smsmith 237151937Sjkim Status = AcpiExStoreObjectToNode (SourceDesc, 238151937Sjkim RefDesc->Reference.Object, 239151937Sjkim WalkState, ACPI_IMPLICIT_CONVERSION); 24071867Smsmith break; 24167754Smsmith 24267754Smsmith 243193267Sjkim case ACPI_REFCLASS_INDEX: 24467754Smsmith 24571867Smsmith /* Storing to an Index (pointer into a packager or buffer) */ 24667754Smsmith 24785756Smsmith Status = AcpiExStoreObjectToIndex (SourceDesc, RefDesc, WalkState); 24871867Smsmith break; 24971867Smsmith 25071867Smsmith 251193267Sjkim case ACPI_REFCLASS_LOCAL: 252193267Sjkim case ACPI_REFCLASS_ARG: 25371867Smsmith 25477424Smsmith /* Store to a method local/arg */ 25571867Smsmith 256193267Sjkim Status = AcpiDsStoreObjectToLocal (RefDesc->Reference.Class, 257193267Sjkim RefDesc->Reference.Value, SourceDesc, WalkState); 25871867Smsmith break; 25971867Smsmith 26071867Smsmith 261193267Sjkim case ACPI_REFCLASS_DEBUG: 26271867Smsmith 26367754Smsmith /* 26471867Smsmith * Storing to the Debug object causes the value stored to be 26571867Smsmith * displayed and otherwise has no effect -- see ACPI Specification 26667754Smsmith */ 267138287Smarks ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 268138287Smarks "**** Write to Debug Object: Object %p %s ****:\n\n", 269138287Smarks SourceDesc, AcpiUtGetObjectTypeName (SourceDesc))); 27077424Smsmith 271204773Sjkim ACPI_DEBUG_OBJECT (SourceDesc, 0, 0); 27271867Smsmith break; 27371867Smsmith 27471867Smsmith 27571867Smsmith default: 27671867Smsmith 277204773Sjkim ACPI_ERROR ((AE_INFO, "Unknown Reference Class 0x%2.2X", 278193267Sjkim RefDesc->Reference.Class)); 279193267Sjkim ACPI_DUMP_ENTRY (RefDesc, ACPI_LV_INFO); 28071867Smsmith 28171867Smsmith Status = AE_AML_INTERNAL; 28271867Smsmith break; 28399679Siwasaki } 28471867Smsmith 28571867Smsmith return_ACPI_STATUS (Status); 28671867Smsmith} 28771867Smsmith 28871867Smsmith 28971867Smsmith/******************************************************************************* 29071867Smsmith * 29177424Smsmith * FUNCTION: AcpiExStoreObjectToIndex 29271867Smsmith * 29387031Smsmith * PARAMETERS: *SourceDesc - Value to be stored 29487031Smsmith * *DestDesc - Named object to receive the value 29587031Smsmith * WalkState - Current walk state 29671867Smsmith * 29771867Smsmith * RETURN: Status 29871867Smsmith * 29987031Smsmith * DESCRIPTION: Store the object to indexed Buffer or Package element 30071867Smsmith * 30171867Smsmith ******************************************************************************/ 30271867Smsmith 303151937Sjkimstatic ACPI_STATUS 30477424SmsmithAcpiExStoreObjectToIndex ( 30585756Smsmith ACPI_OPERAND_OBJECT *SourceDesc, 30691116Smsmith ACPI_OPERAND_OBJECT *IndexDesc, 30771867Smsmith ACPI_WALK_STATE *WalkState) 30871867Smsmith{ 30971867Smsmith ACPI_STATUS Status = AE_OK; 31071867Smsmith ACPI_OPERAND_OBJECT *ObjDesc; 31191116Smsmith ACPI_OPERAND_OBJECT *NewDesc; 31271867Smsmith UINT8 Value = 0; 313126372Snjl UINT32 i; 31471867Smsmith 31571867Smsmith 316167802Sjkim ACPI_FUNCTION_TRACE (ExStoreObjectToIndex); 31771867Smsmith 31871867Smsmith 31971867Smsmith /* 32071867Smsmith * Destination must be a reference pointer, and 32171867Smsmith * must point to either a buffer or a package 32271867Smsmith */ 32391116Smsmith switch (IndexDesc->Reference.TargetType) 32471867Smsmith { 32571867Smsmith case ACPI_TYPE_PACKAGE: 32671867Smsmith /* 327138287Smarks * Storing to a package element. Copy the object and replace 328138287Smarks * any existing object with the new object. No implicit 329138287Smarks * conversion is performed. 330138287Smarks * 33191116Smsmith * The object at *(IndexDesc->Reference.Where) is the 33291116Smsmith * element within the package that is to be modified. 333126372Snjl * The parent package object is at IndexDesc->Reference.Object 33491116Smsmith */ 33591116Smsmith ObjDesc = *(IndexDesc->Reference.Where); 33685756Smsmith 337193267Sjkim if (SourceDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE && 338193267Sjkim SourceDesc->Reference.Class == ACPI_REFCLASS_TABLE) 33991116Smsmith { 340193267Sjkim /* This is a DDBHandle, just add a reference to it */ 341193267Sjkim 342193267Sjkim AcpiUtAddReference (SourceDesc); 343193267Sjkim NewDesc = SourceDesc; 34491116Smsmith } 345193267Sjkim else 346193267Sjkim { 347193267Sjkim /* Normal object, copy it */ 34867754Smsmith 349193267Sjkim Status = AcpiUtCopyIobjectToIobject (SourceDesc, &NewDesc, WalkState); 350193267Sjkim if (ACPI_FAILURE (Status)) 351193267Sjkim { 352193267Sjkim return_ACPI_STATUS (Status); 353193267Sjkim } 354193267Sjkim } 355193267Sjkim 356138287Smarks if (ObjDesc) 35791116Smsmith { 358138287Smarks /* Decrement reference count by the ref count of the parent package */ 359104470Siwasaki 360151937Sjkim for (i = 0; 361151937Sjkim i < ((ACPI_OPERAND_OBJECT *) 362151937Sjkim IndexDesc->Reference.Object)->Common.ReferenceCount; 363151937Sjkim i++) 364104470Siwasaki { 365138287Smarks AcpiUtRemoveReference (ObjDesc); 366104470Siwasaki } 367138287Smarks } 368151937Sjkim 369138287Smarks *(IndexDesc->Reference.Where) = NewDesc; 370126372Snjl 371151937Sjkim /* Increment ref count by the ref count of the parent package-1 */ 372126372Snjl 373151937Sjkim for (i = 1; 374151937Sjkim i < ((ACPI_OPERAND_OBJECT *) 375151937Sjkim IndexDesc->Reference.Object)->Common.ReferenceCount; 376151937Sjkim i++) 377138287Smarks { 378138287Smarks AcpiUtAddReference (NewDesc); 37967754Smsmith } 380151937Sjkim 38171867Smsmith break; 38267754Smsmith 38367754Smsmith 38471867Smsmith case ACPI_TYPE_BUFFER_FIELD: 38577424Smsmith 38667754Smsmith /* 387138287Smarks * Store into a Buffer or String (not actually a real BufferField) 388138287Smarks * at a location defined by an Index. 38967754Smsmith * 39087031Smsmith * The first 8-bit element of the source object is written to the 39187031Smsmith * 8-bit Buffer location defined by the Index destination object, 39287031Smsmith * according to the ACPI 2.0 specification. 39367754Smsmith */ 39467754Smsmith 39567754Smsmith /* 396138287Smarks * Make sure the target is a Buffer or String. An error should 397138287Smarks * not happen here, since the ReferenceObject was constructed 398138287Smarks * by the INDEX_OP code. 39967754Smsmith */ 40091116Smsmith ObjDesc = IndexDesc->Reference.Object; 401193267Sjkim if ((ObjDesc->Common.Type != ACPI_TYPE_BUFFER) && 402193267Sjkim (ObjDesc->Common.Type != ACPI_TYPE_STRING)) 40367754Smsmith { 40471867Smsmith return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 40567754Smsmith } 40667754Smsmith 40767754Smsmith /* 40867754Smsmith * The assignment of the individual elements will be slightly 40967754Smsmith * different for each source type. 41067754Smsmith */ 411193267Sjkim switch (SourceDesc->Common.Type) 41267754Smsmith { 41371867Smsmith case ACPI_TYPE_INTEGER: 41487031Smsmith 41587031Smsmith /* Use the least-significant byte of the integer */ 41687031Smsmith 41787031Smsmith Value = (UINT8) (SourceDesc->Integer.Value); 41867754Smsmith break; 41967754Smsmith 42087031Smsmith case ACPI_TYPE_BUFFER: 421138287Smarks case ACPI_TYPE_STRING: 42277424Smsmith 423138287Smarks /* Note: Takes advantage of common string/buffer fields */ 424138287Smarks 42587031Smsmith Value = SourceDesc->Buffer.Pointer[0]; 42667754Smsmith break; 42767754Smsmith 42867754Smsmith default: 42977424Smsmith 43087031Smsmith /* All other types are invalid */ 43177424Smsmith 432167802Sjkim ACPI_ERROR ((AE_INFO, 433167802Sjkim "Source must be Integer/Buffer/String type, not %s", 43499679Siwasaki AcpiUtGetObjectTypeName (SourceDesc))); 43587031Smsmith return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 43667754Smsmith } 43787031Smsmith 43887031Smsmith /* Store the source value into the target buffer byte */ 43987031Smsmith 440193267Sjkim ObjDesc->Buffer.Pointer[IndexDesc->Reference.Value] = Value; 44171867Smsmith break; 44267754Smsmith 44367754Smsmith 44471867Smsmith default: 445167802Sjkim ACPI_ERROR ((AE_INFO, 446167802Sjkim "Target is not a Package or BufferField")); 44771867Smsmith Status = AE_AML_OPERAND_TYPE; 44867754Smsmith break; 44971867Smsmith } 45067754Smsmith 45171867Smsmith return_ACPI_STATUS (Status); 45271867Smsmith} 45367754Smsmith 45467754Smsmith 45571867Smsmith/******************************************************************************* 45671867Smsmith * 45777424Smsmith * FUNCTION: AcpiExStoreObjectToNode 45871867Smsmith * 45987031Smsmith * PARAMETERS: SourceDesc - Value to be stored 46087031Smsmith * Node - Named object to receive the value 46187031Smsmith * WalkState - Current walk state 462128212Snjl * ImplicitConversion - Perform implicit conversion (yes/no) 46371867Smsmith * 46471867Smsmith * RETURN: Status 46571867Smsmith * 46671867Smsmith * DESCRIPTION: Store the object to the named object. 46771867Smsmith * 46871867Smsmith * The Assignment of an object to a named object is handled here 46987031Smsmith * The value passed in will replace the current value (if any) 47071867Smsmith * with the input value. 47171867Smsmith * 47271867Smsmith * When storing into an object the data is converted to the 47371867Smsmith * target object type then stored in the object. This means 47471867Smsmith * that the target object type (for an initialized target) will 47571867Smsmith * not be changed by a store operation. 47671867Smsmith * 47787031Smsmith * Assumes parameters are already validated. 47871867Smsmith * 47971867Smsmith ******************************************************************************/ 48067754Smsmith 48171867SmsmithACPI_STATUS 48277424SmsmithAcpiExStoreObjectToNode ( 48371867Smsmith ACPI_OPERAND_OBJECT *SourceDesc, 48471867Smsmith ACPI_NAMESPACE_NODE *Node, 485128212Snjl ACPI_WALK_STATE *WalkState, 486128212Snjl UINT8 ImplicitConversion) 48771867Smsmith{ 48871867Smsmith ACPI_STATUS Status = AE_OK; 48971867Smsmith ACPI_OPERAND_OBJECT *TargetDesc; 49091116Smsmith ACPI_OPERAND_OBJECT *NewDesc; 49191116Smsmith ACPI_OBJECT_TYPE TargetType; 49267754Smsmith 49371867Smsmith 494167802Sjkim ACPI_FUNCTION_TRACE_PTR (ExStoreObjectToNode, SourceDesc); 49571867Smsmith 49683174Smsmith 497151937Sjkim /* Get current type of the node, and object attached to Node */ 498151937Sjkim 49971867Smsmith TargetType = AcpiNsGetType (Node); 50071867Smsmith TargetDesc = AcpiNsGetAttachedObject (Node); 50171867Smsmith 50299146Siwasaki ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Storing %p(%s) into node %p(%s)\n", 50399679Siwasaki SourceDesc, AcpiUtGetObjectTypeName (SourceDesc), 50491116Smsmith Node, AcpiUtGetTypeName (TargetType))); 50571867Smsmith 50671867Smsmith /* 50771867Smsmith * Resolve the source object to an actual value 50877424Smsmith * (If it is a reference object) 50971867Smsmith */ 51077424Smsmith Status = AcpiExResolveObject (&SourceDesc, TargetType, WalkState); 51171867Smsmith if (ACPI_FAILURE (Status)) 51271867Smsmith { 51371867Smsmith return_ACPI_STATUS (Status); 51471867Smsmith } 51571867Smsmith 516128212Snjl /* If no implicit conversion, drop into the default case below */ 517128212Snjl 518193267Sjkim if ((!ImplicitConversion) || 519193267Sjkim ((WalkState->Opcode == AML_COPY_OP) && 520193267Sjkim (TargetType != ACPI_TYPE_LOCAL_REGION_FIELD) && 521193267Sjkim (TargetType != ACPI_TYPE_LOCAL_BANK_FIELD) && 522193267Sjkim (TargetType != ACPI_TYPE_LOCAL_INDEX_FIELD))) 523128212Snjl { 524193267Sjkim /* 525193267Sjkim * Force execution of default (no implicit conversion). Note: 526193267Sjkim * CopyObject does not perform an implicit conversion, as per the ACPI 527193267Sjkim * spec -- except in case of region/bank/index fields -- because these 528193267Sjkim * objects must retain their original type permanently. 529193267Sjkim */ 530128212Snjl TargetType = ACPI_TYPE_ANY; 531128212Snjl } 532128212Snjl 533151937Sjkim /* Do the actual store operation */ 534151937Sjkim 53571867Smsmith switch (TargetType) 53671867Smsmith { 53777424Smsmith case ACPI_TYPE_BUFFER_FIELD: 538107325Siwasaki case ACPI_TYPE_LOCAL_REGION_FIELD: 539107325Siwasaki case ACPI_TYPE_LOCAL_BANK_FIELD: 540107325Siwasaki case ACPI_TYPE_LOCAL_INDEX_FIELD: 54171867Smsmith 542151937Sjkim /* For fields, copy the source data to the target field. */ 543151937Sjkim 544151937Sjkim Status = AcpiExWriteDataToField (SourceDesc, TargetDesc, 545151937Sjkim &WalkState->ResultObj); 54667754Smsmith break; 54767754Smsmith 54867754Smsmith 54971867Smsmith case ACPI_TYPE_INTEGER: 55071867Smsmith case ACPI_TYPE_STRING: 55171867Smsmith case ACPI_TYPE_BUFFER: 55267754Smsmith 55377424Smsmith /* 55471867Smsmith * These target types are all of type Integer/String/Buffer, and 55571867Smsmith * therefore support implicit conversion before the store. 55677424Smsmith * 55777424Smsmith * Copy and/or convert the source object to a new target object 55867754Smsmith */ 559151937Sjkim Status = AcpiExStoreObjectToObject (SourceDesc, TargetDesc, 560151937Sjkim &NewDesc, WalkState); 56171867Smsmith if (ACPI_FAILURE (Status)) 56267754Smsmith { 56371867Smsmith return_ACPI_STATUS (Status); 56467754Smsmith } 56567754Smsmith 56691116Smsmith if (NewDesc != TargetDesc) 56791116Smsmith { 56891116Smsmith /* 56991116Smsmith * Store the new NewDesc as the new value of the Name, and set 57091116Smsmith * the Name's type to that of the value being stored in it. 57191116Smsmith * SourceDesc reference count is incremented by AttachObject. 572104470Siwasaki * 573104470Siwasaki * Note: This may change the type of the node if an explicit store 574104470Siwasaki * has been performed such that the node/object type has been 575104470Siwasaki * changed. 57691116Smsmith */ 577104470Siwasaki Status = AcpiNsAttachObject (Node, NewDesc, NewDesc->Common.Type); 57885756Smsmith 57999146Siwasaki ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 58091116Smsmith "Store %s into %s via Convert/Attach\n", 58199679Siwasaki AcpiUtGetObjectTypeName (SourceDesc), 58299679Siwasaki AcpiUtGetObjectTypeName (NewDesc))); 58391116Smsmith } 58467754Smsmith break; 58567754Smsmith 58677424Smsmith 58767754Smsmith default: 58867754Smsmith 58999146Siwasaki ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 590151937Sjkim "Storing %s (%p) directly into node (%p) with no implicit conversion\n", 59199679Siwasaki AcpiUtGetObjectTypeName (SourceDesc), SourceDesc, Node)); 59284491Smsmith 59371867Smsmith /* No conversions for all other types. Just attach the source object */ 59467754Smsmith 595151937Sjkim Status = AcpiNsAttachObject (Node, SourceDesc, 596193267Sjkim SourceDesc->Common.Type); 59771867Smsmith break; 59871867Smsmith } 59967754Smsmith 60071867Smsmith return_ACPI_STATUS (Status); 60171867Smsmith} 60267754Smsmith 60367754Smsmith 604