2 /******************************************************************************
 
   4  * Module Name: exresop - AML Interpreter operand/object resolution
 
   6  *****************************************************************************/
 
   9  * Copyright (C) 2000 - 2008, Intel Corp.
 
  10  * All rights reserved.
 
  12  * Redistribution and use in source and binary forms, with or without
 
  13  * modification, are permitted provided that the following conditions
 
  15  * 1. Redistributions of source code must retain the above copyright
 
  16  *    notice, this list of conditions, and the following disclaimer,
 
  17  *    without modification.
 
  18  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
 
  19  *    substantially similar to the "NO WARRANTY" disclaimer below
 
  20  *    ("Disclaimer") and any redistribution must be conditioned upon
 
  21  *    including a substantially similar Disclaimer requirement for further
 
  22  *    binary redistribution.
 
  23  * 3. Neither the names of the above-listed copyright holders nor the names
 
  24  *    of any contributors may be used to endorse or promote products derived
 
  25  *    from this software without specific prior written permission.
 
  27  * Alternatively, this software may be distributed under the terms of the
 
  28  * GNU General Public License ("GPL") version 2 as published by the Free
 
  29  * Software Foundation.
 
  32  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 
  33  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 
  34  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
 
  35  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 
  36  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 
  37  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 
  38  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 
  39  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 
  40  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 
  41  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 
  42  * POSSIBILITY OF SUCH DAMAGES.
 
  45 #include <acpi/acpi.h>
 
  52 #define _COMPONENT          ACPI_EXECUTER
 
  53 ACPI_MODULE_NAME("exresop")
 
  55 /* Local prototypes */
 
  57 acpi_ex_check_object_type(acpi_object_type type_needed,
 
  58                           acpi_object_type this_type, void *object);
 
  60 /*******************************************************************************
 
  62  * FUNCTION:    acpi_ex_check_object_type
 
  64  * PARAMETERS:  type_needed         Object type needed
 
  65  *              this_type           Actual object type
 
  66  *              Object              Object pointer
 
  70  * DESCRIPTION: Check required type against actual type
 
  72  ******************************************************************************/
 
  75 acpi_ex_check_object_type(acpi_object_type type_needed,
 
  76                           acpi_object_type this_type, void *object)
 
  78         ACPI_FUNCTION_ENTRY();
 
  80         if (type_needed == ACPI_TYPE_ANY) {
 
  82                 /* All types OK, so we don't perform any typechecks */
 
  87         if (type_needed == ACPI_TYPE_LOCAL_REFERENCE) {
 
  89                  * Allow the AML "Constant" opcodes (Zero, One, etc.) to be reference
 
  90                  * objects and thus allow them to be targets.  (As per the ACPI
 
  91                  * specification, a store to a constant is a noop.)
 
  93                 if ((this_type == ACPI_TYPE_INTEGER) &&
 
  94                     (((union acpi_operand_object *)object)->common.
 
  95                      flags & AOPOBJ_AML_CONSTANT)) {
 
 100         if (type_needed != this_type) {
 
 102                             "Needed type [%s], found [%s] %p",
 
 103                             acpi_ut_get_type_name(type_needed),
 
 104                             acpi_ut_get_type_name(this_type), object));
 
 106                 return (AE_AML_OPERAND_TYPE);
 
 112 /*******************************************************************************
 
 114  * FUNCTION:    acpi_ex_resolve_operands
 
 116  * PARAMETERS:  Opcode              - Opcode being interpreted
 
 117  *              stack_ptr           - Pointer to the operand stack to be
 
 119  *              walk_state          - Current state
 
 123  * DESCRIPTION: Convert multiple input operands to the types required by the
 
 126  *      Each 5-bit group in arg_types represents one required
 
 127  *      operand and indicates the required Type. The corresponding operand
 
 128  *      will be converted to the required type if possible, otherwise we
 
 129  *      abort with an exception.
 
 131  ******************************************************************************/
 
 134 acpi_ex_resolve_operands(u16 opcode,
 
 135                          union acpi_operand_object ** stack_ptr,
 
 136                          struct acpi_walk_state * walk_state)
 
 138         union acpi_operand_object *obj_desc;
 
 139         acpi_status status = AE_OK;
 
 142         const struct acpi_opcode_info *op_info;
 
 144         acpi_object_type type_needed;
 
 147         ACPI_FUNCTION_TRACE_U32(ex_resolve_operands, opcode);
 
 149         op_info = acpi_ps_get_opcode_info(opcode);
 
 150         if (op_info->class == AML_CLASS_UNKNOWN) {
 
 151                 return_ACPI_STATUS(AE_AML_BAD_OPCODE);
 
 154         arg_types = op_info->runtime_args;
 
 155         if (arg_types == ARGI_INVALID_OPCODE) {
 
 156                 ACPI_ERROR((AE_INFO, "Unknown AML opcode %X", opcode));
 
 158                 return_ACPI_STATUS(AE_AML_INTERNAL);
 
 161         ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
 
 162                           "Opcode %X [%s] RequiredOperandTypes=%8.8X\n",
 
 163                           opcode, op_info->name, arg_types));
 
 166          * Normal exit is with (arg_types == 0) at end of argument list.
 
 167          * Function will return an exception from within the loop upon
 
 168          * finding an entry which is not (or cannot be converted
 
 169          * to) the required type; if stack underflows; or upon
 
 170          * finding a NULL stack entry (which should not happen).
 
 172         while (GET_CURRENT_ARG_TYPE(arg_types)) {
 
 173                 if (!stack_ptr || !*stack_ptr) {
 
 174                         ACPI_ERROR((AE_INFO, "Null stack entry at %p",
 
 177                         return_ACPI_STATUS(AE_AML_INTERNAL);
 
 180                 /* Extract useful items */
 
 182                 obj_desc = *stack_ptr;
 
 184                 /* Decode the descriptor type */
 
 186                 switch (ACPI_GET_DESCRIPTOR_TYPE(obj_desc)) {
 
 187                 case ACPI_DESC_TYPE_NAMED:
 
 192                             ((struct acpi_namespace_node *)obj_desc)->type;
 
 195                          * Resolve an alias object. The construction of these objects
 
 196                          * guarantees that there is only one level of alias indirection;
 
 197                          * thus, the attached object is always the aliased namespace node
 
 199                         if (object_type == ACPI_TYPE_LOCAL_ALIAS) {
 
 201                                     acpi_ns_get_attached_object((struct
 
 204                                 *stack_ptr = obj_desc;
 
 206                                     ((struct acpi_namespace_node *)obj_desc)->
 
 211                 case ACPI_DESC_TYPE_OPERAND:
 
 213                         /* ACPI internal object */
 
 215                         object_type = ACPI_GET_OBJECT_TYPE(obj_desc);
 
 217                         /* Check for bad acpi_object_type */
 
 219                         if (!acpi_ut_valid_object_type(object_type)) {
 
 221                                             "Bad operand object type [%X]",
 
 224                                 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
 
 227                         if (object_type == (u8) ACPI_TYPE_LOCAL_REFERENCE) {
 
 229                                 /* Validate the Reference */
 
 231                                 switch (obj_desc->reference.class) {
 
 232                                 case ACPI_REFCLASS_DEBUG:
 
 234                                         target_op = AML_DEBUG_OP;
 
 236                                         /*lint -fallthrough */
 
 238                                 case ACPI_REFCLASS_ARG:
 
 239                                 case ACPI_REFCLASS_LOCAL:
 
 240                                 case ACPI_REFCLASS_INDEX:
 
 241                                 case ACPI_REFCLASS_REFOF:
 
 242                                 case ACPI_REFCLASS_TABLE:       /* ddb_handle from LOAD_OP or LOAD_TABLE_OP */
 
 243                                 case ACPI_REFCLASS_NAME:        /* Reference to a named object */
 
 245                                         ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
 
 246                                                           "Operand is a Reference, Class [%s] %2.2X\n",
 
 247                                                           acpi_ut_get_reference_name
 
 256                                                     "Unknown Reference Class %2.2X in %p",
 
 257                                                     obj_desc->reference.class,
 
 260                                         return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
 
 267                         /* Invalid descriptor */
 
 269                         ACPI_ERROR((AE_INFO, "Invalid descriptor %p [%s]",
 
 271                                     acpi_ut_get_descriptor_name(obj_desc)));
 
 273                         return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
 
 276                 /* Get one argument type, point to the next */
 
 278                 this_arg_type = GET_CURRENT_ARG_TYPE(arg_types);
 
 279                 INCREMENT_ARG_LIST(arg_types);
 
 282                  * Handle cases where the object does not need to be
 
 283                  * resolved to a value
 
 285                 switch (this_arg_type) {
 
 286                 case ARGI_REF_OR_STRING:        /* Can be a String or Reference */
 
 288                         if ((ACPI_GET_DESCRIPTOR_TYPE(obj_desc) ==
 
 289                              ACPI_DESC_TYPE_OPERAND)
 
 290                             && (ACPI_GET_OBJECT_TYPE(obj_desc) ==
 
 293                                  * String found - the string references a named object and
 
 294                                  * must be resolved to a node
 
 300                          * Else not a string - fall through to the normal Reference
 
 303                         /*lint -fallthrough */
 
 305                 case ARGI_REFERENCE:    /* References: */
 
 306                 case ARGI_INTEGER_REF:
 
 307                 case ARGI_OBJECT_REF:
 
 308                 case ARGI_DEVICE_REF:
 
 309                 case ARGI_TARGETREF:    /* Allows implicit conversion rules before store */
 
 310                 case ARGI_FIXED_TARGET: /* No implicit conversion before store to target */
 
 311                 case ARGI_SIMPLE_TARGET:        /* Name, Local, or Arg - no implicit conversion  */
 
 314                          * Need an operand of type ACPI_TYPE_LOCAL_REFERENCE
 
 315                          * A Namespace Node is OK as-is
 
 317                         if (ACPI_GET_DESCRIPTOR_TYPE(obj_desc) ==
 
 318                             ACPI_DESC_TYPE_NAMED) {
 
 323                             acpi_ex_check_object_type(ACPI_TYPE_LOCAL_REFERENCE,
 
 324                                                       object_type, obj_desc);
 
 325                         if (ACPI_FAILURE(status)) {
 
 326                                 return_ACPI_STATUS(status);
 
 330                 case ARGI_DATAREFOBJ:   /* Store operator only */
 
 333                          * We don't want to resolve index_op reference objects during
 
 334                          * a store because this would be an implicit de_ref_of operation.
 
 335                          * Instead, we just want to store the reference object.
 
 336                          * -- All others must be resolved below.
 
 338                         if ((opcode == AML_STORE_OP) &&
 
 339                             (ACPI_GET_OBJECT_TYPE(*stack_ptr) ==
 
 340                              ACPI_TYPE_LOCAL_REFERENCE)
 
 341                             && ((*stack_ptr)->reference.class == ACPI_REFCLASS_INDEX)) {
 
 347                         /* All cases covered above */
 
 352                  * Resolve this object to a value
 
 354                 status = acpi_ex_resolve_to_value(stack_ptr, walk_state);
 
 355                 if (ACPI_FAILURE(status)) {
 
 356                         return_ACPI_STATUS(status);
 
 359                 /* Get the resolved object */
 
 361                 obj_desc = *stack_ptr;
 
 364                  * Check the resulting object (value) type
 
 366                 switch (this_arg_type) {
 
 368                          * For the simple cases, only one type of resolved object
 
 373                         /* Need an operand of type ACPI_TYPE_MUTEX */
 
 375                         type_needed = ACPI_TYPE_MUTEX;
 
 380                         /* Need an operand of type ACPI_TYPE_EVENT */
 
 382                         type_needed = ACPI_TYPE_EVENT;
 
 385                 case ARGI_PACKAGE:      /* Package */
 
 387                         /* Need an operand of type ACPI_TYPE_PACKAGE */
 
 389                         type_needed = ACPI_TYPE_PACKAGE;
 
 394                         /* Any operand type will do */
 
 396                         type_needed = ACPI_TYPE_ANY;
 
 401                         /* Need an operand of type ACPI_TYPE_DDB_HANDLE */
 
 403                         type_needed = ACPI_TYPE_LOCAL_REFERENCE;
 
 407                          * The more complex cases allow multiple resolved object types
 
 412                          * Need an operand of type ACPI_TYPE_INTEGER,
 
 413                          * But we can implicitly convert from a STRING or BUFFER
 
 414                          * Aka - "Implicit Source Operand Conversion"
 
 417                             acpi_ex_convert_to_integer(obj_desc, stack_ptr, 16);
 
 418                         if (ACPI_FAILURE(status)) {
 
 419                                 if (status == AE_TYPE) {
 
 421                                                     "Needed [Integer/String/Buffer], found [%s] %p",
 
 422                                                     acpi_ut_get_object_type_name
 
 423                                                     (obj_desc), obj_desc));
 
 425                                         return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
 
 428                                 return_ACPI_STATUS(status);
 
 431                         if (obj_desc != *stack_ptr) {
 
 432                                 acpi_ut_remove_reference(obj_desc);
 
 439                          * Need an operand of type ACPI_TYPE_BUFFER,
 
 440                          * But we can implicitly convert from a STRING or INTEGER
 
 441                          * Aka - "Implicit Source Operand Conversion"
 
 443                         status = acpi_ex_convert_to_buffer(obj_desc, stack_ptr);
 
 444                         if (ACPI_FAILURE(status)) {
 
 445                                 if (status == AE_TYPE) {
 
 447                                                     "Needed [Integer/String/Buffer], found [%s] %p",
 
 448                                                     acpi_ut_get_object_type_name
 
 449                                                     (obj_desc), obj_desc));
 
 451                                         return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
 
 454                                 return_ACPI_STATUS(status);
 
 457                         if (obj_desc != *stack_ptr) {
 
 458                                 acpi_ut_remove_reference(obj_desc);
 
 465                          * Need an operand of type ACPI_TYPE_STRING,
 
 466                          * But we can implicitly convert from a BUFFER or INTEGER
 
 467                          * Aka - "Implicit Source Operand Conversion"
 
 469                         status = acpi_ex_convert_to_string(obj_desc, stack_ptr,
 
 470                                                            ACPI_IMPLICIT_CONVERT_HEX);
 
 471                         if (ACPI_FAILURE(status)) {
 
 472                                 if (status == AE_TYPE) {
 
 474                                                     "Needed [Integer/String/Buffer], found [%s] %p",
 
 475                                                     acpi_ut_get_object_type_name
 
 476                                                     (obj_desc), obj_desc));
 
 478                                         return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
 
 481                                 return_ACPI_STATUS(status);
 
 484                         if (obj_desc != *stack_ptr) {
 
 485                                 acpi_ut_remove_reference(obj_desc);
 
 489                 case ARGI_COMPUTEDATA:
 
 491                         /* Need an operand of type INTEGER, STRING or BUFFER */
 
 493                         switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
 
 494                         case ACPI_TYPE_INTEGER:
 
 495                         case ACPI_TYPE_STRING:
 
 496                         case ACPI_TYPE_BUFFER:
 
 503                                             "Needed [Integer/String/Buffer], found [%s] %p",
 
 504                                             acpi_ut_get_object_type_name
 
 505                                             (obj_desc), obj_desc));
 
 507                                 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
 
 511                 case ARGI_BUFFER_OR_STRING:
 
 513                         /* Need an operand of type STRING or BUFFER */
 
 515                         switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
 
 516                         case ACPI_TYPE_STRING:
 
 517                         case ACPI_TYPE_BUFFER:
 
 522                         case ACPI_TYPE_INTEGER:
 
 524                                 /* Highest priority conversion is to type Buffer */
 
 527                                     acpi_ex_convert_to_buffer(obj_desc,
 
 529                                 if (ACPI_FAILURE(status)) {
 
 530                                         return_ACPI_STATUS(status);
 
 533                                 if (obj_desc != *stack_ptr) {
 
 534                                         acpi_ut_remove_reference(obj_desc);
 
 540                                             "Needed [Integer/String/Buffer], found [%s] %p",
 
 541                                             acpi_ut_get_object_type_name
 
 542                                             (obj_desc), obj_desc));
 
 544                                 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
 
 548                 case ARGI_DATAOBJECT:
 
 550                          * ARGI_DATAOBJECT is only used by the size_of operator.
 
 551                          * Need a buffer, string, package, or ref_of reference.
 
 553                          * The only reference allowed here is a direct reference to
 
 556                         switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
 
 557                         case ACPI_TYPE_PACKAGE:
 
 558                         case ACPI_TYPE_STRING:
 
 559                         case ACPI_TYPE_BUFFER:
 
 560                         case ACPI_TYPE_LOCAL_REFERENCE:
 
 567                                             "Needed [Buffer/String/Package/Reference], found [%s] %p",
 
 568                                             acpi_ut_get_object_type_name
 
 569                                             (obj_desc), obj_desc));
 
 571                                 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
 
 575                 case ARGI_COMPLEXOBJ:
 
 577                         /* Need a buffer or package or (ACPI 2.0) String */
 
 579                         switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
 
 580                         case ACPI_TYPE_PACKAGE:
 
 581                         case ACPI_TYPE_STRING:
 
 582                         case ACPI_TYPE_BUFFER:
 
 589                                             "Needed [Buffer/String/Package], found [%s] %p",
 
 590                                             acpi_ut_get_object_type_name
 
 591                                             (obj_desc), obj_desc));
 
 593                                 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
 
 597                 case ARGI_REGION_OR_BUFFER:     /* Used by Load() only */
 
 599                         /* Need an operand of type REGION or a BUFFER (which could be a resolved region field) */
 
 601                         switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
 
 602                         case ACPI_TYPE_BUFFER:
 
 603                         case ACPI_TYPE_REGION:
 
 610                                             "Needed [Region/Buffer], found [%s] %p",
 
 611                                             acpi_ut_get_object_type_name
 
 612                                             (obj_desc), obj_desc));
 
 614                                 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
 
 618                 case ARGI_DATAREFOBJ:
 
 620                         /* Used by the Store() operator only */
 
 622                         switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
 
 623                         case ACPI_TYPE_INTEGER:
 
 624                         case ACPI_TYPE_PACKAGE:
 
 625                         case ACPI_TYPE_STRING:
 
 626                         case ACPI_TYPE_BUFFER:
 
 627                         case ACPI_TYPE_BUFFER_FIELD:
 
 628                         case ACPI_TYPE_LOCAL_REFERENCE:
 
 629                         case ACPI_TYPE_LOCAL_REGION_FIELD:
 
 630                         case ACPI_TYPE_LOCAL_BANK_FIELD:
 
 631                         case ACPI_TYPE_LOCAL_INDEX_FIELD:
 
 632                         case ACPI_TYPE_DDB_HANDLE:
 
 639                                 if (acpi_gbl_enable_interpreter_slack) {
 
 641                                          * Enable original behavior of Store(), allowing any and all
 
 642                                          * objects as the source operand.  The ACPI spec does not
 
 643                                          * allow this, however.
 
 648                                 if (target_op == AML_DEBUG_OP) {
 
 650                                         /* Allow store of any object to the Debug object */
 
 656                                             "Needed Integer/Buffer/String/Package/Ref/Ddb], found [%s] %p",
 
 657                                             acpi_ut_get_object_type_name
 
 658                                             (obj_desc), obj_desc));
 
 660                                 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
 
 669                                     "Internal - Unknown ARGI (required operand) type %X",
 
 672                         return_ACPI_STATUS(AE_BAD_PARAMETER);
 
 676                  * Make sure that the original object was resolved to the
 
 677                  * required object type (Simple cases only).
 
 679                 status = acpi_ex_check_object_type(type_needed,
 
 681                                                    (*stack_ptr), *stack_ptr);
 
 682                 if (ACPI_FAILURE(status)) {
 
 683                         return_ACPI_STATUS(status);
 
 688                  * If more operands needed, decrement stack_ptr to point
 
 689                  * to next operand on stack
 
 691                 if (GET_CURRENT_ARG_TYPE(arg_types)) {
 
 696         ACPI_DUMP_OPERANDS(walk_state->operands,
 
 697                            acpi_ps_get_opcode_name(opcode),
 
 698                            walk_state->num_operands);
 
 700         return_ACPI_STATUS(status);