Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
0002 /******************************************************************************
0003  *
0004  * Module Name: exresnte - AML Interpreter object resolution
0005  *
0006  * Copyright (C) 2000 - 2022, Intel Corp.
0007  *
0008  *****************************************************************************/
0009 
0010 #include <acpi/acpi.h>
0011 #include "accommon.h"
0012 #include "acdispat.h"
0013 #include "acinterp.h"
0014 #include "acnamesp.h"
0015 
0016 #define _COMPONENT          ACPI_EXECUTER
0017 ACPI_MODULE_NAME("exresnte")
0018 
0019 /*******************************************************************************
0020  *
0021  * FUNCTION:    acpi_ex_resolve_node_to_value
0022  *
0023  * PARAMETERS:  object_ptr      - Pointer to a location that contains
0024  *                                a pointer to a NS node, and will receive a
0025  *                                pointer to the resolved object.
0026  *              walk_state      - Current state. Valid only if executing AML
0027  *                                code. NULL if simply resolving an object
0028  *
0029  * RETURN:      Status
0030  *
0031  * DESCRIPTION: Resolve a Namespace node to a valued object
0032  *
0033  * Note: for some of the data types, the pointer attached to the Node
0034  * can be either a pointer to an actual internal object or a pointer into the
0035  * AML stream itself. These types are currently:
0036  *
0037  *      ACPI_TYPE_INTEGER
0038  *      ACPI_TYPE_STRING
0039  *      ACPI_TYPE_BUFFER
0040  *      ACPI_TYPE_MUTEX
0041  *      ACPI_TYPE_PACKAGE
0042  *
0043  ******************************************************************************/
0044 acpi_status
0045 acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr,
0046                   struct acpi_walk_state *walk_state)
0047 {
0048     acpi_status status = AE_OK;
0049     union acpi_operand_object *source_desc;
0050     union acpi_operand_object *obj_desc = NULL;
0051     struct acpi_namespace_node *node;
0052     acpi_object_type entry_type;
0053 
0054     ACPI_FUNCTION_TRACE(ex_resolve_node_to_value);
0055 
0056     /*
0057      * The stack pointer points to a struct acpi_namespace_node (Node). Get the
0058      * object that is attached to the Node.
0059      */
0060     node = *object_ptr;
0061     source_desc = acpi_ns_get_attached_object(node);
0062     entry_type = acpi_ns_get_type((acpi_handle)node);
0063 
0064     ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Entry=%p SourceDesc=%p [%s]\n",
0065               node, source_desc,
0066               acpi_ut_get_type_name(entry_type)));
0067 
0068     if ((entry_type == ACPI_TYPE_LOCAL_ALIAS) ||
0069         (entry_type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
0070 
0071         /* There is always exactly one level of indirection */
0072 
0073         node = ACPI_CAST_PTR(struct acpi_namespace_node, node->object);
0074         source_desc = acpi_ns_get_attached_object(node);
0075         entry_type = acpi_ns_get_type((acpi_handle)node);
0076         *object_ptr = node;
0077     }
0078 
0079     /*
0080      * Several object types require no further processing:
0081      * 1) Device/Thermal objects don't have a "real" subobject, return Node
0082      * 2) Method locals and arguments have a pseudo-Node
0083      * 3) 10/2007: Added method type to assist with Package construction.
0084      */
0085     if ((entry_type == ACPI_TYPE_DEVICE) ||
0086         (entry_type == ACPI_TYPE_THERMAL) ||
0087         (entry_type == ACPI_TYPE_METHOD) ||
0088         (node->flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) {
0089         return_ACPI_STATUS(AE_OK);
0090     }
0091 
0092     if (!source_desc) {
0093         ACPI_ERROR((AE_INFO, "No object attached to node [%4.4s] %p",
0094                 node->name.ascii, node));
0095         return_ACPI_STATUS(AE_AML_UNINITIALIZED_NODE);
0096     }
0097 
0098     /*
0099      * Action is based on the type of the Node, which indicates the type
0100      * of the attached object or pointer
0101      */
0102     switch (entry_type) {
0103     case ACPI_TYPE_PACKAGE:
0104 
0105         if (source_desc->common.type != ACPI_TYPE_PACKAGE) {
0106             ACPI_ERROR((AE_INFO, "Object not a Package, type %s",
0107                     acpi_ut_get_object_type_name(source_desc)));
0108             return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
0109         }
0110 
0111         status = acpi_ds_get_package_arguments(source_desc);
0112         if (ACPI_SUCCESS(status)) {
0113 
0114             /* Return an additional reference to the object */
0115 
0116             obj_desc = source_desc;
0117             acpi_ut_add_reference(obj_desc);
0118         }
0119         break;
0120 
0121     case ACPI_TYPE_BUFFER:
0122 
0123         if (source_desc->common.type != ACPI_TYPE_BUFFER) {
0124             ACPI_ERROR((AE_INFO, "Object not a Buffer, type %s",
0125                     acpi_ut_get_object_type_name(source_desc)));
0126             return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
0127         }
0128 
0129         status = acpi_ds_get_buffer_arguments(source_desc);
0130         if (ACPI_SUCCESS(status)) {
0131 
0132             /* Return an additional reference to the object */
0133 
0134             obj_desc = source_desc;
0135             acpi_ut_add_reference(obj_desc);
0136         }
0137         break;
0138 
0139     case ACPI_TYPE_STRING:
0140 
0141         if (source_desc->common.type != ACPI_TYPE_STRING) {
0142             ACPI_ERROR((AE_INFO, "Object not a String, type %s",
0143                     acpi_ut_get_object_type_name(source_desc)));
0144             return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
0145         }
0146 
0147         /* Return an additional reference to the object */
0148 
0149         obj_desc = source_desc;
0150         acpi_ut_add_reference(obj_desc);
0151         break;
0152 
0153     case ACPI_TYPE_INTEGER:
0154 
0155         if (source_desc->common.type != ACPI_TYPE_INTEGER) {
0156             ACPI_ERROR((AE_INFO, "Object not a Integer, type %s",
0157                     acpi_ut_get_object_type_name(source_desc)));
0158             return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
0159         }
0160 
0161         /* Return an additional reference to the object */
0162 
0163         obj_desc = source_desc;
0164         acpi_ut_add_reference(obj_desc);
0165         break;
0166 
0167     case ACPI_TYPE_BUFFER_FIELD:
0168     case ACPI_TYPE_LOCAL_REGION_FIELD:
0169     case ACPI_TYPE_LOCAL_BANK_FIELD:
0170     case ACPI_TYPE_LOCAL_INDEX_FIELD:
0171 
0172         ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
0173                   "FieldRead Node=%p SourceDesc=%p Type=%X\n",
0174                   node, source_desc, entry_type));
0175 
0176         status =
0177             acpi_ex_read_data_from_field(walk_state, source_desc,
0178                          &obj_desc);
0179         break;
0180 
0181         /* For these objects, just return the object attached to the Node */
0182 
0183     case ACPI_TYPE_MUTEX:
0184     case ACPI_TYPE_POWER:
0185     case ACPI_TYPE_PROCESSOR:
0186     case ACPI_TYPE_EVENT:
0187     case ACPI_TYPE_REGION:
0188 
0189         /* Return an additional reference to the object */
0190 
0191         obj_desc = source_desc;
0192         acpi_ut_add_reference(obj_desc);
0193         break;
0194 
0195         /* TYPE_ANY is untyped, and thus there is no object associated with it */
0196 
0197     case ACPI_TYPE_ANY:
0198 
0199         ACPI_ERROR((AE_INFO,
0200                 "Untyped entry %p, no attached object!", node));
0201 
0202         return_ACPI_STATUS(AE_AML_OPERAND_TYPE);    /* Cannot be AE_TYPE */
0203 
0204     case ACPI_TYPE_LOCAL_REFERENCE:
0205 
0206         switch (source_desc->reference.class) {
0207         case ACPI_REFCLASS_TABLE:   /* This is a ddb_handle */
0208         case ACPI_REFCLASS_REFOF:
0209         case ACPI_REFCLASS_INDEX:
0210 
0211             /* Return an additional reference to the object */
0212 
0213             obj_desc = source_desc;
0214             acpi_ut_add_reference(obj_desc);
0215             break;
0216 
0217         default:
0218 
0219             /* No named references are allowed here */
0220 
0221             ACPI_ERROR((AE_INFO,
0222                     "Unsupported Reference type 0x%X",
0223                     source_desc->reference.class));
0224 
0225             return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
0226         }
0227         break;
0228 
0229     default:
0230 
0231         /* Default case is for unknown types */
0232 
0233         ACPI_ERROR((AE_INFO,
0234                 "Node %p - Unknown object type 0x%X",
0235                 node, entry_type));
0236 
0237         return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
0238 
0239     }           /* switch (entry_type) */
0240 
0241     /* Return the object descriptor */
0242 
0243     *object_ptr = (void *)obj_desc;
0244     return_ACPI_STATUS(status);
0245 }