Path: blob/main/sys/contrib/dev/acpica/components/executer/exstoren.c
48521 views
/******************************************************************************1*2* Module Name: exstoren - AML Interpreter object store support,3* Store to Node (namespace object)4*5*****************************************************************************/67/******************************************************************************8*9* 1. Copyright Notice10*11* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.12* All rights reserved.13*14* 2. License15*16* 2.1. This is your license from Intel Corp. under its intellectual property17* rights. You may have additional license terms from the party that provided18* you this software, covering your right to use that party's intellectual19* property rights.20*21* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a22* copy of the source code appearing in this file ("Covered Code") an23* irrevocable, perpetual, worldwide license under Intel's copyrights in the24* base code distributed originally by Intel ("Original Intel Code") to copy,25* make derivatives, distribute, use and display any portion of the Covered26* Code in any form, with the right to sublicense such rights; and27*28* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent29* license (with the right to sublicense), under only those claims of Intel30* patents that are infringed by the Original Intel Code, to make, use, sell,31* offer to sell, and import the Covered Code and derivative works thereof32* solely to the minimum extent necessary to exercise the above copyright33* license, and in no event shall the patent license extend to any additions34* to or modifications of the Original Intel Code. No other license or right35* is granted directly or by implication, estoppel or otherwise;36*37* The above copyright and patent license is granted only if the following38* conditions are met:39*40* 3. Conditions41*42* 3.1. Redistribution of Source with Rights to Further Distribute Source.43* Redistribution of source code of any substantial portion of the Covered44* Code or modification with rights to further distribute source must include45* the above Copyright Notice, the above License, this list of Conditions,46* and the following Disclaimer and Export Compliance provision. In addition,47* Licensee must cause all Covered Code to which Licensee contributes to48* contain a file documenting the changes Licensee made to create that Covered49* Code and the date of any change. Licensee must include in that file the50* documentation of any changes made by any predecessor Licensee. Licensee51* must include a prominent statement that the modification is derived,52* directly or indirectly, from Original Intel Code.53*54* 3.2. Redistribution of Source with no Rights to Further Distribute Source.55* Redistribution of source code of any substantial portion of the Covered56* Code or modification without rights to further distribute source must57* include the following Disclaimer and Export Compliance provision in the58* documentation and/or other materials provided with distribution. In59* addition, Licensee may not authorize further sublicense of source of any60* portion of the Covered Code, and must include terms to the effect that the61* license from Licensee to its licensee is limited to the intellectual62* property embodied in the software Licensee provides to its licensee, and63* not to intellectual property embodied in modifications its licensee may64* make.65*66* 3.3. Redistribution of Executable. Redistribution in executable form of any67* substantial portion of the Covered Code or modification must reproduce the68* above Copyright Notice, and the following Disclaimer and Export Compliance69* provision in the documentation and/or other materials provided with the70* distribution.71*72* 3.4. Intel retains all right, title, and interest in and to the Original73* Intel Code.74*75* 3.5. Neither the name Intel nor any other trademark owned or controlled by76* Intel shall be used in advertising or otherwise to promote the sale, use or77* other dealings in products derived from or relating to the Covered Code78* without prior written authorization from Intel.79*80* 4. Disclaimer and Export Compliance81*82* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED83* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE84* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,85* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY86* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY87* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A88* PARTICULAR PURPOSE.89*90* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES91* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR92* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,93* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY94* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL95* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS96* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY97* LIMITED REMEDY.98*99* 4.3. Licensee shall not export, either directly or indirectly, any of this100* software or system incorporating such software without first obtaining any101* required license or other approval from the U. S. Department of Commerce or102* any other agency or department of the United States Government. In the103* event Licensee exports any such software from the United States or104* re-exports any such software from a foreign destination, Licensee shall105* ensure that the distribution and export/re-export of the software is in106* compliance with all laws, regulations, orders, or other restrictions of the107* U.S. Export Administration Regulations. Licensee agrees that neither it nor108* any of its subsidiaries will export/re-export any technical data, process,109* software, or service, directly or indirectly, to any country for which the110* United States government or any agency thereof requires an export license,111* other governmental approval, or letter of assurance, without first obtaining112* such license, approval or letter.113*114*****************************************************************************115*116* Alternatively, you may choose to be licensed under the terms of the117* following license:118*119* Redistribution and use in source and binary forms, with or without120* modification, are permitted provided that the following conditions121* are met:122* 1. Redistributions of source code must retain the above copyright123* notice, this list of conditions, and the following disclaimer,124* without modification.125* 2. Redistributions in binary form must reproduce at minimum a disclaimer126* substantially similar to the "NO WARRANTY" disclaimer below127* ("Disclaimer") and any redistribution must be conditioned upon128* including a substantially similar Disclaimer requirement for further129* binary redistribution.130* 3. Neither the names of the above-listed copyright holders nor the names131* of any contributors may be used to endorse or promote products derived132* from this software without specific prior written permission.133*134* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS135* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT136* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR137* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT138* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,139* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT140* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,141* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY142* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT143* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE144* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.145*146* Alternatively, you may choose to be licensed under the terms of the147* GNU General Public License ("GPL") version 2 as published by the Free148* Software Foundation.149*150*****************************************************************************/151152#include <contrib/dev/acpica/include/acpi.h>153#include <contrib/dev/acpica/include/accommon.h>154#include <contrib/dev/acpica/include/acinterp.h>155#include <contrib/dev/acpica/include/amlcode.h>156157158#define _COMPONENT ACPI_EXECUTER159ACPI_MODULE_NAME ("exstoren")160161162/*******************************************************************************163*164* FUNCTION: AcpiExResolveObject165*166* PARAMETERS: SourceDescPtr - Pointer to the source object167* TargetType - Current type of the target168* WalkState - Current walk state169*170* RETURN: Status, resolved object in SourceDescPtr.171*172* DESCRIPTION: Resolve an object. If the object is a reference, dereference173* it and return the actual object in the SourceDescPtr.174*175******************************************************************************/176177ACPI_STATUS178AcpiExResolveObject (179ACPI_OPERAND_OBJECT **SourceDescPtr,180ACPI_OBJECT_TYPE TargetType,181ACPI_WALK_STATE *WalkState)182{183ACPI_OPERAND_OBJECT *SourceDesc = *SourceDescPtr;184ACPI_STATUS Status = AE_OK;185186187ACPI_FUNCTION_TRACE (ExResolveObject);188189190/* Ensure we have a Target that can be stored to */191192switch (TargetType)193{194case ACPI_TYPE_BUFFER_FIELD:195case ACPI_TYPE_LOCAL_REGION_FIELD:196case ACPI_TYPE_LOCAL_BANK_FIELD:197case ACPI_TYPE_LOCAL_INDEX_FIELD:198/*199* These cases all require only Integers or values that200* can be converted to Integers (Strings or Buffers)201*/202case ACPI_TYPE_INTEGER:203case ACPI_TYPE_STRING:204case ACPI_TYPE_BUFFER:205/*206* Stores into a Field/Region or into a Integer/Buffer/String207* are all essentially the same. This case handles the208* "interchangeable" types Integer, String, and Buffer.209*/210if (SourceDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)211{212/* Resolve a reference object first */213214Status = AcpiExResolveToValue (SourceDescPtr, WalkState);215if (ACPI_FAILURE (Status))216{217break;218}219}220221/* For CopyObject, no further validation necessary */222223if (WalkState->Opcode == AML_COPY_OBJECT_OP)224{225break;226}227228/* Must have a Integer, Buffer, or String */229230if ((SourceDesc->Common.Type != ACPI_TYPE_INTEGER) &&231(SourceDesc->Common.Type != ACPI_TYPE_BUFFER) &&232(SourceDesc->Common.Type != ACPI_TYPE_STRING) &&233!((SourceDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&234(SourceDesc->Reference.Class== ACPI_REFCLASS_TABLE)))235{236/* Conversion successful but still not a valid type */237238ACPI_ERROR ((AE_INFO,239"Cannot assign type [%s] to [%s] (must be type Int/Str/Buf)",240AcpiUtGetObjectTypeName (SourceDesc),241AcpiUtGetTypeName (TargetType)));242243Status = AE_AML_OPERAND_TYPE;244}245break;246247case ACPI_TYPE_LOCAL_ALIAS:248case ACPI_TYPE_LOCAL_METHOD_ALIAS:249/*250* All aliases should have been resolved earlier, during the251* operand resolution phase.252*/253ACPI_ERROR ((AE_INFO, "Store into an unresolved Alias object"));254Status = AE_AML_INTERNAL;255break;256257case ACPI_TYPE_PACKAGE:258default:259/*260* All other types than Alias and the various Fields come here,261* including the untyped case - ACPI_TYPE_ANY.262*/263break;264}265266return_ACPI_STATUS (Status);267}268269270/*******************************************************************************271*272* FUNCTION: AcpiExStoreObjectToObject273*274* PARAMETERS: SourceDesc - Object to store275* DestDesc - Object to receive a copy of the source276* NewDesc - New object if DestDesc is obsoleted277* WalkState - Current walk state278*279* RETURN: Status280*281* DESCRIPTION: "Store" an object to another object. This may include282* converting the source type to the target type (implicit283* conversion), and a copy of the value of the source to284* the target.285*286* The Assignment of an object to another (not named) object287* is handled here.288* The Source passed in will replace the current value (if any)289* with the input value.290*291* When storing into an object the data is converted to the292* target object type then stored in the object. This means293* that the target object type (for an initialized target) will294* not be changed by a store operation.295*296* This module allows destination types of Number, String,297* Buffer, and Package.298*299* Assumes parameters are already validated. NOTE: SourceDesc300* resolution (from a reference object) must be performed by301* the caller if necessary.302*303******************************************************************************/304305ACPI_STATUS306AcpiExStoreObjectToObject (307ACPI_OPERAND_OBJECT *SourceDesc,308ACPI_OPERAND_OBJECT *DestDesc,309ACPI_OPERAND_OBJECT **NewDesc,310ACPI_WALK_STATE *WalkState)311{312ACPI_OPERAND_OBJECT *ActualSrcDesc;313ACPI_STATUS Status = AE_OK;314315316ACPI_FUNCTION_TRACE_PTR (ExStoreObjectToObject, SourceDesc);317318319ActualSrcDesc = SourceDesc;320if (!DestDesc)321{322/*323* There is no destination object (An uninitialized node or324* package element), so we can simply copy the source object325* creating a new destination object326*/327Status = AcpiUtCopyIobjectToIobject (ActualSrcDesc, NewDesc, WalkState);328return_ACPI_STATUS (Status);329}330331if (SourceDesc->Common.Type != DestDesc->Common.Type)332{333/*334* The source type does not match the type of the destination.335* Perform the "implicit conversion" of the source to the current type336* of the target as per the ACPI specification.337*338* If no conversion performed, ActualSrcDesc = SourceDesc.339* Otherwise, ActualSrcDesc is a temporary object to hold the340* converted object.341*/342Status = AcpiExConvertToTargetType (DestDesc->Common.Type,343SourceDesc, &ActualSrcDesc, WalkState);344if (ACPI_FAILURE (Status))345{346return_ACPI_STATUS (Status);347}348349if (SourceDesc == ActualSrcDesc)350{351/*352* No conversion was performed. Return the SourceDesc as the353* new object.354*/355*NewDesc = SourceDesc;356return_ACPI_STATUS (AE_OK);357}358}359360/*361* We now have two objects of identical types, and we can perform a362* copy of the *value* of the source object.363*/364switch (DestDesc->Common.Type)365{366case ACPI_TYPE_INTEGER:367368DestDesc->Integer.Value = ActualSrcDesc->Integer.Value;369370/* Truncate value if we are executing from a 32-bit ACPI table */371372(void) AcpiExTruncateFor32bitTable (DestDesc);373break;374375case ACPI_TYPE_STRING:376377Status = AcpiExStoreStringToString (ActualSrcDesc, DestDesc);378break;379380case ACPI_TYPE_BUFFER:381382Status = AcpiExStoreBufferToBuffer (ActualSrcDesc, DestDesc);383break;384385case ACPI_TYPE_PACKAGE:386387Status = AcpiUtCopyIobjectToIobject (ActualSrcDesc, &DestDesc,388WalkState);389break;390391default:392/*393* All other types come here.394*/395ACPI_WARNING ((AE_INFO, "Store into type [%s] not implemented",396AcpiUtGetObjectTypeName (DestDesc)));397398Status = AE_NOT_IMPLEMENTED;399break;400}401402if (ActualSrcDesc != SourceDesc)403{404/* Delete the intermediate (temporary) source object */405406AcpiUtRemoveReference (ActualSrcDesc);407}408409*NewDesc = DestDesc;410return_ACPI_STATUS (Status);411}412413414