exresnte.c revision 241973
1239324Simp/****************************************************************************** 2239324Simp * 3239324Simp * Module Name: exresnte - AML Interpreter object resolution 4239324Simp * 5239324Simp *****************************************************************************/ 6239324Simp 7239324Simp/* 8239324Simp * Copyright (C) 2000 - 2012, Intel Corp. 9239324Simp * All rights reserved. 10239324Simp * 11239324Simp * Redistribution and use in source and binary forms, with or without 12239324Simp * modification, are permitted provided that the following conditions 13239324Simp * are met: 14239324Simp * 1. Redistributions of source code must retain the above copyright 15266383Sian * notice, this list of conditions, and the following disclaimer, 16266383Sian * without modification. 17239324Simp * 2. Redistributions in binary form must reproduce at minimum a disclaimer 18239324Simp * substantially similar to the "NO WARRANTY" disclaimer below 19239324Simp * ("Disclaimer") and any redistribution must be conditioned upon 20239324Simp * including a substantially similar Disclaimer requirement for further 21239324Simp * binary redistribution. 22239324Simp * 3. Neither the names of the above-listed copyright holders nor the names 23239324Simp * of any contributors may be used to endorse or promote products derived 24239324Simp * from this software without specific prior written permission. 25266328Sian * 26239324Simp * Alternatively, this software may be distributed under the terms of the 27239324Simp * GNU General Public License ("GPL") version 2 as published by the Free 28239324Simp * Software Foundation. 29266328Sian * 30266328Sian * NO WARRANTY 31266328Sian * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 32266328Sian * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 33266328Sian * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 34266328Sian * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 35266328Sian * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 36266328Sian * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 37239324Simp * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 38239324Simp * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 39266328Sian * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 40266328Sian * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 41266328Sian * POSSIBILITY OF SUCH DAMAGES. 42266328Sian */ 43239324Simp 44239324Simp#define __EXRESNTE_C__ 45239324Simp 46266328Sian#include <contrib/dev/acpica/include/acpi.h> 47266328Sian#include <contrib/dev/acpica/include/accommon.h> 48266331Sian#include <contrib/dev/acpica/include/acdispat.h> 49266328Sian#include <contrib/dev/acpica/include/acinterp.h> 50266328Sian#include <contrib/dev/acpica/include/acnamesp.h> 51266328Sian 52266328Sian 53266328Sian#define _COMPONENT ACPI_EXECUTER 54266328Sian ACPI_MODULE_NAME ("exresnte") 55266328Sian 56266328Sian 57266328Sian/******************************************************************************* 58266328Sian * 59239324Simp * FUNCTION: AcpiExResolveNodeToValue 60239324Simp * 61239324Simp * PARAMETERS: ObjectPtr - Pointer to a location that contains 62239324Simp * a pointer to a NS node, and will receive a 63239324Simp * pointer to the resolved object. 64239324Simp * WalkState - Current state. Valid only if executing AML 65239324Simp * code. NULL if simply resolving an object 66239324Simp * 67239324Simp * RETURN: Status 68239324Simp * 69239324Simp * DESCRIPTION: Resolve a Namespace node to a valued object 70239324Simp * 71239324Simp * Note: for some of the data types, the pointer attached to the Node 72239324Simp * can be either a pointer to an actual internal object or a pointer into the 73239324Simp * AML stream itself. These types are currently: 74239324Simp * 75239324Simp * ACPI_TYPE_INTEGER 76239324Simp * ACPI_TYPE_STRING 77239324Simp * ACPI_TYPE_BUFFER 78239324Simp * ACPI_TYPE_MUTEX 79266328Sian * ACPI_TYPE_PACKAGE 80266328Sian * 81266328Sian ******************************************************************************/ 82266328Sian 83266328SianACPI_STATUS 84239324SimpAcpiExResolveNodeToValue ( 85239324Simp ACPI_NAMESPACE_NODE **ObjectPtr, 86239324Simp ACPI_WALK_STATE *WalkState) 87239324Simp 88239324Simp{ 89239324Simp ACPI_STATUS Status = AE_OK; 90239324Simp ACPI_OPERAND_OBJECT *SourceDesc; 91239324Simp ACPI_OPERAND_OBJECT *ObjDesc = NULL; 92239324Simp ACPI_NAMESPACE_NODE *Node; 93239324Simp ACPI_OBJECT_TYPE EntryType; 94239324Simp 95239324Simp 96239324Simp ACPI_FUNCTION_TRACE (ExResolveNodeToValue); 97239324Simp 98239324Simp 99239324Simp /* 100266328Sian * The stack pointer points to a ACPI_NAMESPACE_NODE (Node). Get the 101266328Sian * object that is attached to the Node. 102266328Sian */ 103266328Sian Node = *ObjectPtr; 104239324Simp SourceDesc = AcpiNsGetAttachedObject (Node); 105278676Sian EntryType = AcpiNsGetType ((ACPI_HANDLE) Node); 106266328Sian 107266328Sian ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Entry=%p SourceDesc=%p [%s]\n", 108278676Sian Node, SourceDesc, AcpiUtGetTypeName (EntryType))); 109239324Simp 110239324Simp if ((EntryType == ACPI_TYPE_LOCAL_ALIAS) || 111266328Sian (EntryType == ACPI_TYPE_LOCAL_METHOD_ALIAS)) 112266328Sian { 113266328Sian /* There is always exactly one level of indirection */ 114266328Sian 115 Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Node->Object); 116 SourceDesc = AcpiNsGetAttachedObject (Node); 117 EntryType = AcpiNsGetType ((ACPI_HANDLE) Node); 118 *ObjectPtr = Node; 119 } 120 121 /* 122 * Several object types require no further processing: 123 * 1) Device/Thermal objects don't have a "real" subobject, return the Node 124 * 2) Method locals and arguments have a pseudo-Node 125 * 3) 10/2007: Added method type to assist with Package construction. 126 */ 127 if ((EntryType == ACPI_TYPE_DEVICE) || 128 (EntryType == ACPI_TYPE_THERMAL) || 129 (EntryType == ACPI_TYPE_METHOD) || 130 (Node->Flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) 131 { 132 return_ACPI_STATUS (AE_OK); 133 } 134 135 if (!SourceDesc) 136 { 137 ACPI_ERROR ((AE_INFO, "No object attached to node %p", 138 Node)); 139 return_ACPI_STATUS (AE_AML_NO_OPERAND); 140 } 141 142 /* 143 * Action is based on the type of the Node, which indicates the type 144 * of the attached object or pointer 145 */ 146 switch (EntryType) 147 { 148 case ACPI_TYPE_PACKAGE: 149 150 if (SourceDesc->Common.Type != ACPI_TYPE_PACKAGE) 151 { 152 ACPI_ERROR ((AE_INFO, "Object not a Package, type %s", 153 AcpiUtGetObjectTypeName (SourceDesc))); 154 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 155 } 156 157 Status = AcpiDsGetPackageArguments (SourceDesc); 158 if (ACPI_SUCCESS (Status)) 159 { 160 /* Return an additional reference to the object */ 161 162 ObjDesc = SourceDesc; 163 AcpiUtAddReference (ObjDesc); 164 } 165 break; 166 167 168 case ACPI_TYPE_BUFFER: 169 170 if (SourceDesc->Common.Type != ACPI_TYPE_BUFFER) 171 { 172 ACPI_ERROR ((AE_INFO, "Object not a Buffer, type %s", 173 AcpiUtGetObjectTypeName (SourceDesc))); 174 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 175 } 176 177 Status = AcpiDsGetBufferArguments (SourceDesc); 178 if (ACPI_SUCCESS (Status)) 179 { 180 /* Return an additional reference to the object */ 181 182 ObjDesc = SourceDesc; 183 AcpiUtAddReference (ObjDesc); 184 } 185 break; 186 187 188 case ACPI_TYPE_STRING: 189 190 if (SourceDesc->Common.Type != ACPI_TYPE_STRING) 191 { 192 ACPI_ERROR ((AE_INFO, "Object not a String, type %s", 193 AcpiUtGetObjectTypeName (SourceDesc))); 194 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 195 } 196 197 /* Return an additional reference to the object */ 198 199 ObjDesc = SourceDesc; 200 AcpiUtAddReference (ObjDesc); 201 break; 202 203 204 case ACPI_TYPE_INTEGER: 205 206 if (SourceDesc->Common.Type != ACPI_TYPE_INTEGER) 207 { 208 ACPI_ERROR ((AE_INFO, "Object not a Integer, type %s", 209 AcpiUtGetObjectTypeName (SourceDesc))); 210 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 211 } 212 213 /* Return an additional reference to the object */ 214 215 ObjDesc = SourceDesc; 216 AcpiUtAddReference (ObjDesc); 217 break; 218 219 220 case ACPI_TYPE_BUFFER_FIELD: 221 case ACPI_TYPE_LOCAL_REGION_FIELD: 222 case ACPI_TYPE_LOCAL_BANK_FIELD: 223 case ACPI_TYPE_LOCAL_INDEX_FIELD: 224 225 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 226 "FieldRead Node=%p SourceDesc=%p Type=%X\n", 227 Node, SourceDesc, EntryType)); 228 229 Status = AcpiExReadDataFromField (WalkState, SourceDesc, &ObjDesc); 230 break; 231 232 /* For these objects, just return the object attached to the Node */ 233 234 case ACPI_TYPE_MUTEX: 235 case ACPI_TYPE_POWER: 236 case ACPI_TYPE_PROCESSOR: 237 case ACPI_TYPE_EVENT: 238 case ACPI_TYPE_REGION: 239 240 /* Return an additional reference to the object */ 241 242 ObjDesc = SourceDesc; 243 AcpiUtAddReference (ObjDesc); 244 break; 245 246 /* TYPE_ANY is untyped, and thus there is no object associated with it */ 247 248 case ACPI_TYPE_ANY: 249 250 ACPI_ERROR ((AE_INFO, 251 "Untyped entry %p, no attached object!", Node)); 252 253 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); /* Cannot be AE_TYPE */ 254 255 256 case ACPI_TYPE_LOCAL_REFERENCE: 257 258 switch (SourceDesc->Reference.Class) 259 { 260 case ACPI_REFCLASS_TABLE: /* This is a DdbHandle */ 261 case ACPI_REFCLASS_REFOF: 262 case ACPI_REFCLASS_INDEX: 263 264 /* Return an additional reference to the object */ 265 266 ObjDesc = SourceDesc; 267 AcpiUtAddReference (ObjDesc); 268 break; 269 270 default: 271 /* No named references are allowed here */ 272 273 ACPI_ERROR ((AE_INFO, 274 "Unsupported Reference type 0x%X", 275 SourceDesc->Reference.Class)); 276 277 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 278 } 279 break; 280 281 282 default: 283 284 /* Default case is for unknown types */ 285 286 ACPI_ERROR ((AE_INFO, 287 "Node %p - Unknown object type 0x%X", 288 Node, EntryType)); 289 290 return_ACPI_STATUS (AE_AML_OPERAND_TYPE); 291 292 } /* switch (EntryType) */ 293 294 295 /* Return the object descriptor */ 296 297 *ObjectPtr = (void *) ObjDesc; 298 return_ACPI_STATUS (Status); 299} 300