167754Smsmith/****************************************************************************** 267754Smsmith * 377424Smsmith * Module Name: exresnte - AML Interpreter object resolution 467754Smsmith * 567754Smsmith *****************************************************************************/ 667754Smsmith 7217365Sjkim/* 8306536Sjkim * Copyright (C) 2000 - 2016, Intel Corp. 970243Smsmith * All rights reserved. 1067754Smsmith * 11217365Sjkim * Redistribution and use in source and binary forms, with or without 12217365Sjkim * modification, are permitted provided that the following conditions 13217365Sjkim * are met: 14217365Sjkim * 1. Redistributions of source code must retain the above copyright 15217365Sjkim * notice, this list of conditions, and the following disclaimer, 16217365Sjkim * without modification. 17217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18217365Sjkim * substantially similar to the "NO WARRANTY" disclaimer below 19217365Sjkim * ("Disclaimer") and any redistribution must be conditioned upon 20217365Sjkim * including a substantially similar Disclaimer requirement for further 21217365Sjkim * binary redistribution. 22217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names 23217365Sjkim * of any contributors may be used to endorse or promote products derived 24217365Sjkim * from this software without specific prior written permission. 2567754Smsmith * 26217365Sjkim * Alternatively, this software may be distributed under the terms of the 27217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free 28217365Sjkim * Software Foundation. 2967754Smsmith * 30217365Sjkim * NO WARRANTY 31217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41217365Sjkim * POSSIBILITY OF SUCH DAMAGES. 42217365Sjkim */ 4367754Smsmith 44193341Sjkim#include <contrib/dev/acpica/include/acpi.h> 45193341Sjkim#include <contrib/dev/acpica/include/accommon.h> 46193341Sjkim#include <contrib/dev/acpica/include/acdispat.h> 47193341Sjkim#include <contrib/dev/acpica/include/acinterp.h> 48193341Sjkim#include <contrib/dev/acpica/include/acnamesp.h> 4967754Smsmith 5067754Smsmith 5177424Smsmith#define _COMPONENT ACPI_EXECUTER 5291116Smsmith ACPI_MODULE_NAME ("exresnte") 5367754Smsmith 5467754Smsmith 5567754Smsmith/******************************************************************************* 5667754Smsmith * 5777424Smsmith * FUNCTION: AcpiExResolveNodeToValue 5867754Smsmith * 5985756Smsmith * PARAMETERS: ObjectPtr - Pointer to a location that contains 6092388Smsmith * a pointer to a NS node, and will receive a 6185756Smsmith * pointer to the resolved object. 62241973Sjkim * WalkState - Current state. Valid only if executing AML 63241973Sjkim * code. NULL if simply resolving an object 6467754Smsmith * 6567754Smsmith * RETURN: Status 6667754Smsmith * 6785756Smsmith * DESCRIPTION: Resolve a Namespace node to a valued object 6867754Smsmith * 6967754Smsmith * Note: for some of the data types, the pointer attached to the Node 7067754Smsmith * can be either a pointer to an actual internal object or a pointer into the 71241973Sjkim * AML stream itself. These types are currently: 7267754Smsmith * 7371867Smsmith * ACPI_TYPE_INTEGER 7467754Smsmith * ACPI_TYPE_STRING 7567754Smsmith * ACPI_TYPE_BUFFER 7667754Smsmith * ACPI_TYPE_MUTEX 7767754Smsmith * ACPI_TYPE_PACKAGE 7867754Smsmith * 7967754Smsmith ******************************************************************************/ 8067754Smsmith 8167754SmsmithACPI_STATUS 8277424SmsmithAcpiExResolveNodeToValue ( 8385756Smsmith ACPI_NAMESPACE_NODE **ObjectPtr, 8469450Smsmith ACPI_WALK_STATE *WalkState) 8569450Smsmith 8667754Smsmith{ 8767754Smsmith ACPI_STATUS Status = AE_OK; 8885756Smsmith ACPI_OPERAND_OBJECT *SourceDesc; 8967754Smsmith ACPI_OPERAND_OBJECT *ObjDesc = NULL; 9067754Smsmith ACPI_NAMESPACE_NODE *Node; 9191116Smsmith ACPI_OBJECT_TYPE EntryType; 9267754Smsmith 9367754Smsmith 94167802Sjkim ACPI_FUNCTION_TRACE (ExResolveNodeToValue); 9567754Smsmith 9667754Smsmith 9767754Smsmith /* 98241973Sjkim * The stack pointer points to a ACPI_NAMESPACE_NODE (Node). Get the 9977424Smsmith * object that is attached to the Node. 10067754Smsmith */ 101306536Sjkim Node = *ObjectPtr; 10287031Smsmith SourceDesc = AcpiNsGetAttachedObject (Node); 103306536Sjkim EntryType = AcpiNsGetType ((ACPI_HANDLE) Node); 10467754Smsmith 105107325Siwasaki ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Entry=%p SourceDesc=%p [%s]\n", 106107325Siwasaki Node, SourceDesc, AcpiUtGetTypeName (EntryType))); 10767754Smsmith 108128212Snjl if ((EntryType == ACPI_TYPE_LOCAL_ALIAS) || 109128212Snjl (EntryType == ACPI_TYPE_LOCAL_METHOD_ALIAS)) 110104470Siwasaki { 111104470Siwasaki /* There is always exactly one level of indirection */ 112104470Siwasaki 113306536Sjkim Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Node->Object); 114104470Siwasaki SourceDesc = AcpiNsGetAttachedObject (Node); 115306536Sjkim EntryType = AcpiNsGetType ((ACPI_HANDLE) Node); 116104470Siwasaki *ObjectPtr = Node; 117104470Siwasaki } 118104470Siwasaki 11967754Smsmith /* 12082367Smsmith * Several object types require no further processing: 121306536Sjkim * 1) Device/Thermal objects don't have a "real" subobject, return Node 12282367Smsmith * 2) Method locals and arguments have a pseudo-Node 123193267Sjkim * 3) 10/2007: Added method type to assist with Package construction. 12467754Smsmith */ 125167802Sjkim if ((EntryType == ACPI_TYPE_DEVICE) || 126167802Sjkim (EntryType == ACPI_TYPE_THERMAL) || 127193267Sjkim (EntryType == ACPI_TYPE_METHOD) || 12869746Smsmith (Node->Flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) 12967754Smsmith { 13067754Smsmith return_ACPI_STATUS (AE_OK); 13167754Smsmith } 13267754Smsmith 13385756Smsmith if (!SourceDesc) 13467754Smsmith { 135281075Sdim ACPI_ERROR ((AE_INFO, "No object attached to node [%4.4s] %p", 136281075Sdim Node->Name.Ascii, Node)); 137306536Sjkim return_ACPI_STATUS (AE_AML_UNINITIALIZED_NODE); 13867754Smsmith } 13967754Smsmith 14067754Smsmith /* 14167754Smsmith * Action is based on the type of the Node, which indicates the type 14267754Smsmith * of the attached object or pointer 14367754Smsmith */ 14467754Smsmith switch (EntryType) 14567754Smsmith { 14667754Smsmith case ACPI_TYPE_PACKAGE: 14767754Smsmith 148193267Sjkim if (SourceDesc->Common.Type != ACPI_TYPE_PACKAGE) 14967754Smsmith { 150167802Sjkim ACPI_ERROR ((AE_INFO, "Object not a Package, type %s", 15199679Siwasaki AcpiUtGetObjectTypeName (SourceDesc))); 15267754Smsmith return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 15367754Smsmith } 15467754Smsmith 15599146Siwasaki Status = AcpiDsGetPackageArguments (SourceDesc); 15699146Siwasaki if (ACPI_SUCCESS (Status)) 15799146Siwasaki { 15899146Siwasaki /* Return an additional reference to the object */ 15967754Smsmith 16099146Siwasaki ObjDesc = SourceDesc; 16199146Siwasaki AcpiUtAddReference (ObjDesc); 16299146Siwasaki } 16367754Smsmith break; 16467754Smsmith 16567754Smsmith case ACPI_TYPE_BUFFER: 16667754Smsmith 167193267Sjkim if (SourceDesc->Common.Type != ACPI_TYPE_BUFFER) 16867754Smsmith { 169167802Sjkim ACPI_ERROR ((AE_INFO, "Object not a Buffer, type %s", 17099679Siwasaki AcpiUtGetObjectTypeName (SourceDesc))); 17167754Smsmith return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 17267754Smsmith } 17367754Smsmith 17499146Siwasaki Status = AcpiDsGetBufferArguments (SourceDesc); 17599146Siwasaki if (ACPI_SUCCESS (Status)) 17699146Siwasaki { 17799146Siwasaki /* Return an additional reference to the object */ 17867754Smsmith 17999146Siwasaki ObjDesc = SourceDesc; 18099146Siwasaki AcpiUtAddReference (ObjDesc); 18199146Siwasaki } 18267754Smsmith break; 18367754Smsmith 18467754Smsmith case ACPI_TYPE_STRING: 18567754Smsmith 186193267Sjkim if (SourceDesc->Common.Type != ACPI_TYPE_STRING) 18767754Smsmith { 188167802Sjkim ACPI_ERROR ((AE_INFO, "Object not a String, type %s", 18999679Siwasaki AcpiUtGetObjectTypeName (SourceDesc))); 19082367Smsmith return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 19167754Smsmith } 19267754Smsmith 19382367Smsmith /* Return an additional reference to the object */ 19467754Smsmith 19585756Smsmith ObjDesc = SourceDesc; 19682367Smsmith AcpiUtAddReference (ObjDesc); 19767754Smsmith break; 19867754Smsmith 19971867Smsmith case ACPI_TYPE_INTEGER: 20067754Smsmith 201193267Sjkim if (SourceDesc->Common.Type != ACPI_TYPE_INTEGER) 20267754Smsmith { 203167802Sjkim ACPI_ERROR ((AE_INFO, "Object not a Integer, type %s", 20499679Siwasaki AcpiUtGetObjectTypeName (SourceDesc))); 20567754Smsmith return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 20667754Smsmith } 20767754Smsmith 20867754Smsmith /* Return an additional reference to the object */ 20967754Smsmith 21085756Smsmith ObjDesc = SourceDesc; 21177424Smsmith AcpiUtAddReference (ObjDesc); 21267754Smsmith break; 21367754Smsmith 21477424Smsmith case ACPI_TYPE_BUFFER_FIELD: 215107325Siwasaki case ACPI_TYPE_LOCAL_REGION_FIELD: 216107325Siwasaki case ACPI_TYPE_LOCAL_BANK_FIELD: 217107325Siwasaki case ACPI_TYPE_LOCAL_INDEX_FIELD: 21867754Smsmith 219151937Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 220151937Sjkim "FieldRead Node=%p SourceDesc=%p Type=%X\n", 22185756Smsmith Node, SourceDesc, EntryType)); 22267754Smsmith 22399146Siwasaki Status = AcpiExReadDataFromField (WalkState, SourceDesc, &ObjDesc); 22467754Smsmith break; 22567754Smsmith 226151937Sjkim /* For these objects, just return the object attached to the Node */ 227151937Sjkim 22867754Smsmith case ACPI_TYPE_MUTEX: 22967754Smsmith case ACPI_TYPE_POWER: 23067754Smsmith case ACPI_TYPE_PROCESSOR: 23167754Smsmith case ACPI_TYPE_EVENT: 23267754Smsmith case ACPI_TYPE_REGION: 23367754Smsmith 23467754Smsmith /* Return an additional reference to the object */ 23567754Smsmith 23685756Smsmith ObjDesc = SourceDesc; 23777424Smsmith AcpiUtAddReference (ObjDesc); 23867754Smsmith break; 23967754Smsmith 240104470Siwasaki /* TYPE_ANY is untyped, and thus there is no object associated with it */ 24167754Smsmith 24267754Smsmith case ACPI_TYPE_ANY: 24367754Smsmith 244167802Sjkim ACPI_ERROR ((AE_INFO, 245167802Sjkim "Untyped entry %p, no attached object!", Node)); 24667754Smsmith 24767754Smsmith return_ACPI_STATUS (AE_AML_OPERAND_TYPE); /* Cannot be AE_TYPE */ 24867754Smsmith 249107325Siwasaki case ACPI_TYPE_LOCAL_REFERENCE: 25067754Smsmith 251193267Sjkim switch (SourceDesc->Reference.Class) 252123315Snjl { 253193267Sjkim case ACPI_REFCLASS_TABLE: /* This is a DdbHandle */ 254193267Sjkim case ACPI_REFCLASS_REFOF: 255193267Sjkim case ACPI_REFCLASS_INDEX: 25667754Smsmith 257123315Snjl /* Return an additional reference to the object */ 25867754Smsmith 259123315Snjl ObjDesc = SourceDesc; 260123315Snjl AcpiUtAddReference (ObjDesc); 261123315Snjl break; 26267754Smsmith 263123315Snjl default: 264250838Sjkim 265123315Snjl /* No named references are allowed here */ 26667754Smsmith 267167802Sjkim ACPI_ERROR ((AE_INFO, 268204773Sjkim "Unsupported Reference type 0x%X", 269193267Sjkim SourceDesc->Reference.Class)); 270123315Snjl 271123315Snjl return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 272123315Snjl } 273123315Snjl break; 274123315Snjl 27567754Smsmith default: 27667754Smsmith 277151937Sjkim /* Default case is for unknown types */ 278151937Sjkim 279167802Sjkim ACPI_ERROR ((AE_INFO, 280204773Sjkim "Node %p - Unknown object type 0x%X", 28167754Smsmith Node, EntryType)); 28267754Smsmith 28367754Smsmith return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 28467754Smsmith 28567754Smsmith } /* switch (EntryType) */ 28667754Smsmith 28767754Smsmith 288151937Sjkim /* Return the object descriptor */ 28967754Smsmith 29085756Smsmith *ObjectPtr = (void *) ObjDesc; 29167754Smsmith return_ACPI_STATUS (Status); 29267754Smsmith} 293