Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
0002 /******************************************************************************
0003  *
0004  * Module Name: exoparg1 - AML execution - opcodes with 1 argument
0005  *
0006  * Copyright (C) 2000 - 2022, Intel Corp.
0007  *
0008  *****************************************************************************/
0009 
0010 #include <acpi/acpi.h>
0011 #include "accommon.h"
0012 #include "acparser.h"
0013 #include "acdispat.h"
0014 #include "acinterp.h"
0015 #include "amlcode.h"
0016 #include "acnamesp.h"
0017 
0018 #define _COMPONENT          ACPI_EXECUTER
0019 ACPI_MODULE_NAME("exoparg1")
0020 
0021 /*!
0022  * Naming convention for AML interpreter execution routines.
0023  *
0024  * The routines that begin execution of AML opcodes are named with a common
0025  * convention based upon the number of arguments, the number of target operands,
0026  * and whether or not a value is returned:
0027  *
0028  *      AcpiExOpcode_xA_yT_zR
0029  *
0030  * Where:
0031  *
0032  * xA - ARGUMENTS:    The number of arguments (input operands) that are
0033  *                    required for this opcode type (0 through 6 args).
0034  * yT - TARGETS:      The number of targets (output operands) that are required
0035  *                    for this opcode type (0, 1, or 2 targets).
0036  * zR - RETURN VALUE: Indicates whether this opcode type returns a value
0037  *                    as the function return (0 or 1).
0038  *
0039  * The AcpiExOpcode* functions are called via the Dispatcher component with
0040  * fully resolved operands.
0041 !*/
0042 /*******************************************************************************
0043  *
0044  * FUNCTION:    acpi_ex_opcode_0A_0T_1R
0045  *
0046  * PARAMETERS:  walk_state          - Current state (contains AML opcode)
0047  *
0048  * RETURN:      Status
0049  *
0050  * DESCRIPTION: Execute operator with no operands, one return value
0051  *
0052  ******************************************************************************/
0053 acpi_status acpi_ex_opcode_0A_0T_1R(struct acpi_walk_state *walk_state)
0054 {
0055     acpi_status status = AE_OK;
0056     union acpi_operand_object *return_desc = NULL;
0057 
0058     ACPI_FUNCTION_TRACE_STR(ex_opcode_0A_0T_1R,
0059                 acpi_ps_get_opcode_name(walk_state->opcode));
0060 
0061     /* Examine the AML opcode */
0062 
0063     switch (walk_state->opcode) {
0064     case AML_TIMER_OP:  /*  Timer () */
0065 
0066         /* Create a return object of type Integer */
0067 
0068         return_desc =
0069             acpi_ut_create_integer_object(acpi_os_get_timer());
0070         if (!return_desc) {
0071             status = AE_NO_MEMORY;
0072             goto cleanup;
0073         }
0074         break;
0075 
0076     default:        /*  Unknown opcode  */
0077 
0078         ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
0079                 walk_state->opcode));
0080         status = AE_AML_BAD_OPCODE;
0081         break;
0082     }
0083 
0084 cleanup:
0085 
0086     /* Delete return object on error */
0087 
0088     if ((ACPI_FAILURE(status)) || walk_state->result_obj) {
0089         acpi_ut_remove_reference(return_desc);
0090         walk_state->result_obj = NULL;
0091     } else {
0092         /* Save the return value */
0093 
0094         walk_state->result_obj = return_desc;
0095     }
0096 
0097     return_ACPI_STATUS(status);
0098 }
0099 
0100 /*******************************************************************************
0101  *
0102  * FUNCTION:    acpi_ex_opcode_1A_0T_0R
0103  *
0104  * PARAMETERS:  walk_state          - Current state (contains AML opcode)
0105  *
0106  * RETURN:      Status
0107  *
0108  * DESCRIPTION: Execute Type 1 monadic operator with numeric operand on
0109  *              object stack
0110  *
0111  ******************************************************************************/
0112 
0113 acpi_status acpi_ex_opcode_1A_0T_0R(struct acpi_walk_state *walk_state)
0114 {
0115     union acpi_operand_object **operand = &walk_state->operands[0];
0116     acpi_status status = AE_OK;
0117 
0118     ACPI_FUNCTION_TRACE_STR(ex_opcode_1A_0T_0R,
0119                 acpi_ps_get_opcode_name(walk_state->opcode));
0120 
0121     /* Examine the AML opcode */
0122 
0123     switch (walk_state->opcode) {
0124     case AML_RELEASE_OP:    /*  Release (mutex_object) */
0125 
0126         status = acpi_ex_release_mutex(operand[0], walk_state);
0127         break;
0128 
0129     case AML_RESET_OP:  /*  Reset (event_object) */
0130 
0131         status = acpi_ex_system_reset_event(operand[0]);
0132         break;
0133 
0134     case AML_SIGNAL_OP: /*  Signal (event_object) */
0135 
0136         status = acpi_ex_system_signal_event(operand[0]);
0137         break;
0138 
0139     case AML_SLEEP_OP:  /*  Sleep (msec_time) */
0140 
0141         status = acpi_ex_system_do_sleep(operand[0]->integer.value);
0142         break;
0143 
0144     case AML_STALL_OP:  /*  Stall (usec_time) */
0145 
0146         status =
0147             acpi_ex_system_do_stall((u32) operand[0]->integer.value);
0148         break;
0149 
0150     case AML_UNLOAD_OP: /*  Unload (Handle) */
0151 
0152         status = acpi_ex_unload_table(operand[0]);
0153         break;
0154 
0155     default:        /*  Unknown opcode  */
0156 
0157         ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
0158                 walk_state->opcode));
0159         status = AE_AML_BAD_OPCODE;
0160         break;
0161     }
0162 
0163     return_ACPI_STATUS(status);
0164 }
0165 
0166 #ifdef _OBSOLETE_CODE       /* Was originally used for Load() operator */
0167 /*******************************************************************************
0168  *
0169  * FUNCTION:    acpi_ex_opcode_1A_1T_0R
0170  *
0171  * PARAMETERS:  walk_state          - Current state (contains AML opcode)
0172  *
0173  * RETURN:      Status
0174  *
0175  * DESCRIPTION: Execute opcode with one argument, one target, and no
0176  *              return value.
0177  *
0178  ******************************************************************************/
0179 
0180 acpi_status acpi_ex_opcode_1A_1T_0R(struct acpi_walk_state *walk_state)
0181 {
0182     acpi_status status = AE_OK;
0183     union acpi_operand_object **operand = &walk_state->operands[0];
0184 
0185     ACPI_FUNCTION_TRACE_STR(ex_opcode_1A_1T_0R,
0186                 acpi_ps_get_opcode_name(walk_state->opcode));
0187 
0188     /* Examine the AML opcode */
0189 
0190     switch (walk_state->opcode) {
0191 #ifdef _OBSOLETE_CODE
0192     case AML_LOAD_OP:
0193 
0194         status = acpi_ex_load_op(operand[0], operand[1], walk_state);
0195         break;
0196 #endif
0197 
0198     default:        /* Unknown opcode */
0199 
0200         ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
0201                 walk_state->opcode));
0202         status = AE_AML_BAD_OPCODE;
0203         goto cleanup;
0204     }
0205 
0206 cleanup:
0207 
0208     return_ACPI_STATUS(status);
0209 }
0210 #endif
0211 
0212 /*******************************************************************************
0213  *
0214  * FUNCTION:    acpi_ex_opcode_1A_1T_1R
0215  *
0216  * PARAMETERS:  walk_state          - Current state (contains AML opcode)
0217  *
0218  * RETURN:      Status
0219  *
0220  * DESCRIPTION: Execute opcode with one argument, one target, and a
0221  *              return value.
0222  *              January 2022: Added Load operator, with new ACPI 6.4
0223  *              semantics.
0224  *
0225  ******************************************************************************/
0226 
0227 acpi_status acpi_ex_opcode_1A_1T_1R(struct acpi_walk_state *walk_state)
0228 {
0229     acpi_status status = AE_OK;
0230     union acpi_operand_object **operand = &walk_state->operands[0];
0231     union acpi_operand_object *return_desc = NULL;
0232     union acpi_operand_object *return_desc2 = NULL;
0233     u32 temp32;
0234     u32 i;
0235     u64 power_of_ten;
0236     u64 digit;
0237 
0238     ACPI_FUNCTION_TRACE_STR(ex_opcode_1A_1T_1R,
0239                 acpi_ps_get_opcode_name(walk_state->opcode));
0240 
0241     /* Examine the AML opcode */
0242 
0243     switch (walk_state->opcode) {
0244     case AML_BIT_NOT_OP:
0245     case AML_FIND_SET_LEFT_BIT_OP:
0246     case AML_FIND_SET_RIGHT_BIT_OP:
0247     case AML_FROM_BCD_OP:
0248     case AML_LOAD_OP:
0249     case AML_TO_BCD_OP:
0250     case AML_CONDITIONAL_REF_OF_OP:
0251 
0252         /* Create a return object of type Integer for these opcodes */
0253 
0254         return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
0255         if (!return_desc) {
0256             status = AE_NO_MEMORY;
0257             goto cleanup;
0258         }
0259 
0260         switch (walk_state->opcode) {
0261         case AML_BIT_NOT_OP:    /* Not (Operand, Result)  */
0262 
0263             return_desc->integer.value = ~operand[0]->integer.value;
0264             break;
0265 
0266         case AML_FIND_SET_LEFT_BIT_OP:  /* find_set_left_bit (Operand, Result) */
0267 
0268             return_desc->integer.value = operand[0]->integer.value;
0269 
0270             /*
0271              * Acpi specification describes Integer type as a little
0272              * endian unsigned value, so this boundary condition is valid.
0273              */
0274             for (temp32 = 0; return_desc->integer.value &&
0275                  temp32 < ACPI_INTEGER_BIT_SIZE; ++temp32) {
0276                 return_desc->integer.value >>= 1;
0277             }
0278 
0279             return_desc->integer.value = temp32;
0280             break;
0281 
0282         case AML_FIND_SET_RIGHT_BIT_OP: /* find_set_right_bit (Operand, Result) */
0283 
0284             return_desc->integer.value = operand[0]->integer.value;
0285 
0286             /*
0287              * The Acpi specification describes Integer type as a little
0288              * endian unsigned value, so this boundary condition is valid.
0289              */
0290             for (temp32 = 0; return_desc->integer.value &&
0291                  temp32 < ACPI_INTEGER_BIT_SIZE; ++temp32) {
0292                 return_desc->integer.value <<= 1;
0293             }
0294 
0295             /* Since the bit position is one-based, subtract from 33 (65) */
0296 
0297             return_desc->integer.value =
0298                 temp32 ==
0299                 0 ? 0 : (ACPI_INTEGER_BIT_SIZE + 1) - temp32;
0300             break;
0301 
0302         case AML_FROM_BCD_OP:   /* from_bcd (BCDValue, Result) */
0303             /*
0304              * The 64-bit ACPI integer can hold 16 4-bit BCD characters
0305              * (if table is 32-bit, integer can hold 8 BCD characters)
0306              * Convert each 4-bit BCD value
0307              */
0308             power_of_ten = 1;
0309             return_desc->integer.value = 0;
0310             digit = operand[0]->integer.value;
0311 
0312             /* Convert each BCD digit (each is one nybble wide) */
0313 
0314             for (i = 0;
0315                  (i < acpi_gbl_integer_nybble_width) && (digit > 0);
0316                  i++) {
0317 
0318                 /* Get the least significant 4-bit BCD digit */
0319 
0320                 temp32 = ((u32) digit) & 0xF;
0321 
0322                 /* Check the range of the digit */
0323 
0324                 if (temp32 > 9) {
0325                     ACPI_ERROR((AE_INFO,
0326                             "BCD digit too large (not decimal): 0x%X",
0327                             temp32));
0328 
0329                     status = AE_AML_NUMERIC_OVERFLOW;
0330                     goto cleanup;
0331                 }
0332 
0333                 /* Sum the digit into the result with the current power of 10 */
0334 
0335                 return_desc->integer.value +=
0336                     (((u64) temp32) * power_of_ten);
0337 
0338                 /* Shift to next BCD digit */
0339 
0340                 digit >>= 4;
0341 
0342                 /* Next power of 10 */
0343 
0344                 power_of_ten *= 10;
0345             }
0346             break;
0347 
0348         case AML_LOAD_OP:   /* Result1 = Load (Operand[0], Result1) */
0349 
0350             return_desc->integer.value = 0;
0351             status =
0352                 acpi_ex_load_op(operand[0], return_desc,
0353                         walk_state);
0354             if (ACPI_SUCCESS(status)) {
0355 
0356                 /* Return -1 (non-zero) indicates success */
0357 
0358                 return_desc->integer.value = 0xFFFFFFFFFFFFFFFF;
0359             }
0360             break;
0361 
0362         case AML_TO_BCD_OP: /* to_bcd (Operand, Result) */
0363 
0364             return_desc->integer.value = 0;
0365             digit = operand[0]->integer.value;
0366 
0367             /* Each BCD digit is one nybble wide */
0368 
0369             for (i = 0;
0370                  (i < acpi_gbl_integer_nybble_width) && (digit > 0);
0371                  i++) {
0372                 (void)acpi_ut_short_divide(digit, 10, &digit,
0373                                &temp32);
0374 
0375                 /*
0376                  * Insert the BCD digit that resides in the
0377                  * remainder from above
0378                  */
0379                 return_desc->integer.value |=
0380                     (((u64) temp32) << ACPI_MUL_4(i));
0381             }
0382 
0383             /* Overflow if there is any data left in Digit */
0384 
0385             if (digit > 0) {
0386                 ACPI_ERROR((AE_INFO,
0387                         "Integer too large to convert to BCD: 0x%8.8X%8.8X",
0388                         ACPI_FORMAT_UINT64(operand[0]->
0389                                    integer.value)));
0390                 status = AE_AML_NUMERIC_OVERFLOW;
0391                 goto cleanup;
0392             }
0393             break;
0394 
0395         case AML_CONDITIONAL_REF_OF_OP: /* cond_ref_of (source_object, Result) */
0396             /*
0397              * This op is a little strange because the internal return value is
0398              * different than the return value stored in the result descriptor
0399              * (There are really two return values)
0400              */
0401             if ((struct acpi_namespace_node *)operand[0] ==
0402                 acpi_gbl_root_node) {
0403                 /*
0404                  * This means that the object does not exist in the namespace,
0405                  * return FALSE
0406                  */
0407                 return_desc->integer.value = 0;
0408                 goto cleanup;
0409             }
0410 
0411             /* Get the object reference, store it, and remove our reference */
0412 
0413             status = acpi_ex_get_object_reference(operand[0],
0414                                   &return_desc2,
0415                                   walk_state);
0416             if (ACPI_FAILURE(status)) {
0417                 goto cleanup;
0418             }
0419 
0420             status =
0421                 acpi_ex_store(return_desc2, operand[1], walk_state);
0422             acpi_ut_remove_reference(return_desc2);
0423 
0424             /* The object exists in the namespace, return TRUE */
0425 
0426             return_desc->integer.value = ACPI_UINT64_MAX;
0427             goto cleanup;
0428 
0429         default:
0430 
0431             /* No other opcodes get here */
0432 
0433             break;
0434         }
0435         break;
0436 
0437     case AML_STORE_OP:  /* Store (Source, Target) */
0438         /*
0439          * A store operand is typically a number, string, buffer or lvalue
0440          * Be careful about deleting the source object,
0441          * since the object itself may have been stored.
0442          */
0443         status = acpi_ex_store(operand[0], operand[1], walk_state);
0444         if (ACPI_FAILURE(status)) {
0445             return_ACPI_STATUS(status);
0446         }
0447 
0448         /* It is possible that the Store already produced a return object */
0449 
0450         if (!walk_state->result_obj) {
0451             /*
0452              * Normally, we would remove a reference on the Operand[0]
0453              * parameter; But since it is being used as the internal return
0454              * object (meaning we would normally increment it), the two
0455              * cancel out, and we simply don't do anything.
0456              */
0457             walk_state->result_obj = operand[0];
0458             walk_state->operands[0] = NULL; /* Prevent deletion */
0459         }
0460         return_ACPI_STATUS(status);
0461 
0462         /*
0463          * ACPI 2.0 Opcodes
0464          */
0465     case AML_COPY_OBJECT_OP:    /* copy_object (Source, Target) */
0466 
0467         status =
0468             acpi_ut_copy_iobject_to_iobject(operand[0], &return_desc,
0469                             walk_state);
0470         break;
0471 
0472     case AML_TO_DECIMAL_STRING_OP:  /* to_decimal_string (Data, Result) */
0473 
0474         status =
0475             acpi_ex_convert_to_string(operand[0], &return_desc,
0476                           ACPI_EXPLICIT_CONVERT_DECIMAL);
0477         if (return_desc == operand[0]) {
0478 
0479             /* No conversion performed, add ref to handle return value */
0480 
0481             acpi_ut_add_reference(return_desc);
0482         }
0483         break;
0484 
0485     case AML_TO_HEX_STRING_OP:  /* to_hex_string (Data, Result) */
0486 
0487         status =
0488             acpi_ex_convert_to_string(operand[0], &return_desc,
0489                           ACPI_EXPLICIT_CONVERT_HEX);
0490         if (return_desc == operand[0]) {
0491 
0492             /* No conversion performed, add ref to handle return value */
0493 
0494             acpi_ut_add_reference(return_desc);
0495         }
0496         break;
0497 
0498     case AML_TO_BUFFER_OP:  /* to_buffer (Data, Result) */
0499 
0500         status = acpi_ex_convert_to_buffer(operand[0], &return_desc);
0501         if (return_desc == operand[0]) {
0502 
0503             /* No conversion performed, add ref to handle return value */
0504 
0505             acpi_ut_add_reference(return_desc);
0506         }
0507         break;
0508 
0509     case AML_TO_INTEGER_OP: /* to_integer (Data, Result) */
0510 
0511         /* Perform "explicit" conversion */
0512 
0513         status =
0514             acpi_ex_convert_to_integer(operand[0], &return_desc, 0);
0515         if (return_desc == operand[0]) {
0516 
0517             /* No conversion performed, add ref to handle return value */
0518 
0519             acpi_ut_add_reference(return_desc);
0520         }
0521         break;
0522 
0523     case AML_SHIFT_LEFT_BIT_OP: /* shift_left_bit (Source, bit_num) */
0524     case AML_SHIFT_RIGHT_BIT_OP:    /* shift_right_bit (Source, bit_num) */
0525 
0526         /* These are two obsolete opcodes */
0527 
0528         ACPI_ERROR((AE_INFO,
0529                 "%s is obsolete and not implemented",
0530                 acpi_ps_get_opcode_name(walk_state->opcode)));
0531         status = AE_SUPPORT;
0532         goto cleanup;
0533 
0534     default:        /* Unknown opcode */
0535 
0536         ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
0537                 walk_state->opcode));
0538         status = AE_AML_BAD_OPCODE;
0539         goto cleanup;
0540     }
0541 
0542     if (ACPI_SUCCESS(status)) {
0543 
0544         /* Store the return value computed above into the target object */
0545 
0546         status = acpi_ex_store(return_desc, operand[1], walk_state);
0547     }
0548 
0549 cleanup:
0550 
0551     /* Delete return object on error */
0552 
0553     if (ACPI_FAILURE(status)) {
0554         acpi_ut_remove_reference(return_desc);
0555     }
0556 
0557     /* Save return object on success */
0558 
0559     else if (!walk_state->result_obj) {
0560         walk_state->result_obj = return_desc;
0561     }
0562 
0563     return_ACPI_STATUS(status);
0564 }
0565 
0566 /*******************************************************************************
0567  *
0568  * FUNCTION:    acpi_ex_opcode_1A_0T_1R
0569  *
0570  * PARAMETERS:  walk_state          - Current state (contains AML opcode)
0571  *
0572  * RETURN:      Status
0573  *
0574  * DESCRIPTION: Execute opcode with one argument, no target, and a return value
0575  *
0576  ******************************************************************************/
0577 
0578 acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
0579 {
0580     union acpi_operand_object **operand = &walk_state->operands[0];
0581     union acpi_operand_object *temp_desc;
0582     union acpi_operand_object *return_desc = NULL;
0583     acpi_status status = AE_OK;
0584     u32 type;
0585     u64 value;
0586 
0587     ACPI_FUNCTION_TRACE_STR(ex_opcode_1A_0T_1R,
0588                 acpi_ps_get_opcode_name(walk_state->opcode));
0589 
0590     /* Examine the AML opcode */
0591 
0592     switch (walk_state->opcode) {
0593     case AML_LOGICAL_NOT_OP:    /* LNot (Operand) */
0594 
0595         return_desc = acpi_ut_create_integer_object((u64) 0);
0596         if (!return_desc) {
0597             status = AE_NO_MEMORY;
0598             goto cleanup;
0599         }
0600 
0601         /*
0602          * Set result to ONES (TRUE) if Value == 0. Note:
0603          * return_desc->Integer.Value is initially == 0 (FALSE) from above.
0604          */
0605         if (!operand[0]->integer.value) {
0606             return_desc->integer.value = ACPI_UINT64_MAX;
0607         }
0608         break;
0609 
0610     case AML_DECREMENT_OP:  /* Decrement (Operand)  */
0611     case AML_INCREMENT_OP:  /* Increment (Operand)  */
0612         /*
0613          * Create a new integer. Can't just get the base integer and
0614          * increment it because it may be an Arg or Field.
0615          */
0616         return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
0617         if (!return_desc) {
0618             status = AE_NO_MEMORY;
0619             goto cleanup;
0620         }
0621 
0622         /*
0623          * Since we are expecting a Reference operand, it can be either a
0624          * NS Node or an internal object.
0625          */
0626         temp_desc = operand[0];
0627         if (ACPI_GET_DESCRIPTOR_TYPE(temp_desc) ==
0628             ACPI_DESC_TYPE_OPERAND) {
0629 
0630             /* Internal reference object - prevent deletion */
0631 
0632             acpi_ut_add_reference(temp_desc);
0633         }
0634 
0635         /*
0636          * Convert the Reference operand to an Integer (This removes a
0637          * reference on the Operand[0] object)
0638          *
0639          * NOTE:  We use LNOT_OP here in order to force resolution of the
0640          * reference operand to an actual integer.
0641          */
0642         status = acpi_ex_resolve_operands(AML_LOGICAL_NOT_OP,
0643                           &temp_desc, walk_state);
0644         if (ACPI_FAILURE(status)) {
0645             ACPI_EXCEPTION((AE_INFO, status,
0646                     "While resolving operands for [%s]",
0647                     acpi_ps_get_opcode_name(walk_state->
0648                                 opcode)));
0649 
0650             goto cleanup;
0651         }
0652 
0653         /*
0654          * temp_desc is now guaranteed to be an Integer object --
0655          * Perform the actual increment or decrement
0656          */
0657         if (walk_state->opcode == AML_INCREMENT_OP) {
0658             return_desc->integer.value =
0659                 temp_desc->integer.value + 1;
0660         } else {
0661             return_desc->integer.value =
0662                 temp_desc->integer.value - 1;
0663         }
0664 
0665         /* Finished with this Integer object */
0666 
0667         acpi_ut_remove_reference(temp_desc);
0668 
0669         /*
0670          * Store the result back (indirectly) through the original
0671          * Reference object
0672          */
0673         status = acpi_ex_store(return_desc, operand[0], walk_state);
0674         break;
0675 
0676     case AML_OBJECT_TYPE_OP:    /* object_type (source_object) */
0677         /*
0678          * Note: The operand is not resolved at this point because we want to
0679          * get the associated object, not its value. For example, we don't
0680          * want to resolve a field_unit to its value, we want the actual
0681          * field_unit object.
0682          */
0683 
0684         /* Get the type of the base object */
0685 
0686         status =
0687             acpi_ex_resolve_multiple(walk_state, operand[0], &type,
0688                          NULL);
0689         if (ACPI_FAILURE(status)) {
0690             goto cleanup;
0691         }
0692 
0693         /* Allocate a descriptor to hold the type. */
0694 
0695         return_desc = acpi_ut_create_integer_object((u64) type);
0696         if (!return_desc) {
0697             status = AE_NO_MEMORY;
0698             goto cleanup;
0699         }
0700         break;
0701 
0702     case AML_SIZE_OF_OP:    /* size_of (source_object) */
0703         /*
0704          * Note: The operand is not resolved at this point because we want to
0705          * get the associated object, not its value.
0706          */
0707 
0708         /* Get the base object */
0709 
0710         status =
0711             acpi_ex_resolve_multiple(walk_state, operand[0], &type,
0712                          &temp_desc);
0713         if (ACPI_FAILURE(status)) {
0714             goto cleanup;
0715         }
0716 
0717         /*
0718          * The type of the base object must be integer, buffer, string, or
0719          * package. All others are not supported.
0720          *
0721          * NOTE: Integer is not specifically supported by the ACPI spec,
0722          * but is supported implicitly via implicit operand conversion.
0723          * rather than bother with conversion, we just use the byte width
0724          * global (4 or 8 bytes).
0725          */
0726         switch (type) {
0727         case ACPI_TYPE_INTEGER:
0728 
0729             value = acpi_gbl_integer_byte_width;
0730             break;
0731 
0732         case ACPI_TYPE_STRING:
0733 
0734             value = temp_desc->string.length;
0735             break;
0736 
0737         case ACPI_TYPE_BUFFER:
0738 
0739             /* Buffer arguments may not be evaluated at this point */
0740 
0741             status = acpi_ds_get_buffer_arguments(temp_desc);
0742             value = temp_desc->buffer.length;
0743             break;
0744 
0745         case ACPI_TYPE_PACKAGE:
0746 
0747             /* Package arguments may not be evaluated at this point */
0748 
0749             status = acpi_ds_get_package_arguments(temp_desc);
0750             value = temp_desc->package.count;
0751             break;
0752 
0753         default:
0754 
0755             ACPI_ERROR((AE_INFO,
0756                     "Operand must be Buffer/Integer/String/Package"
0757                     " - found type %s",
0758                     acpi_ut_get_type_name(type)));
0759 
0760             status = AE_AML_OPERAND_TYPE;
0761             goto cleanup;
0762         }
0763 
0764         if (ACPI_FAILURE(status)) {
0765             goto cleanup;
0766         }
0767 
0768         /*
0769          * Now that we have the size of the object, create a result
0770          * object to hold the value
0771          */
0772         return_desc = acpi_ut_create_integer_object(value);
0773         if (!return_desc) {
0774             status = AE_NO_MEMORY;
0775             goto cleanup;
0776         }
0777         break;
0778 
0779     case AML_REF_OF_OP: /* ref_of (source_object) */
0780 
0781         status =
0782             acpi_ex_get_object_reference(operand[0], &return_desc,
0783                          walk_state);
0784         if (ACPI_FAILURE(status)) {
0785             goto cleanup;
0786         }
0787         break;
0788 
0789     case AML_DEREF_OF_OP:   /* deref_of (obj_reference | String) */
0790 
0791         /* Check for a method local or argument, or standalone String */
0792 
0793         if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) ==
0794             ACPI_DESC_TYPE_NAMED) {
0795             temp_desc =
0796                 acpi_ns_get_attached_object((struct
0797                              acpi_namespace_node *)
0798                             operand[0]);
0799             if (temp_desc
0800                 && ((temp_desc->common.type == ACPI_TYPE_STRING)
0801                 || (temp_desc->common.type ==
0802                     ACPI_TYPE_LOCAL_REFERENCE))) {
0803                 operand[0] = temp_desc;
0804                 acpi_ut_add_reference(temp_desc);
0805             } else {
0806                 status = AE_AML_OPERAND_TYPE;
0807                 goto cleanup;
0808             }
0809         } else {
0810             switch ((operand[0])->common.type) {
0811             case ACPI_TYPE_LOCAL_REFERENCE:
0812                 /*
0813                  * This is a deref_of (local_x | arg_x)
0814                  *
0815                  * Must resolve/dereference the local/arg reference first
0816                  */
0817                 switch (operand[0]->reference.class) {
0818                 case ACPI_REFCLASS_LOCAL:
0819                 case ACPI_REFCLASS_ARG:
0820 
0821                     /* Set Operand[0] to the value of the local/arg */
0822 
0823                     status =
0824                         acpi_ds_method_data_get_value
0825                         (operand[0]->reference.class,
0826                          operand[0]->reference.value,
0827                          walk_state, &temp_desc);
0828                     if (ACPI_FAILURE(status)) {
0829                         goto cleanup;
0830                     }
0831 
0832                     /*
0833                      * Delete our reference to the input object and
0834                      * point to the object just retrieved
0835                      */
0836                     acpi_ut_remove_reference(operand[0]);
0837                     operand[0] = temp_desc;
0838                     break;
0839 
0840                 case ACPI_REFCLASS_REFOF:
0841 
0842                     /* Get the object to which the reference refers */
0843 
0844                     temp_desc =
0845                         operand[0]->reference.object;
0846                     acpi_ut_remove_reference(operand[0]);
0847                     operand[0] = temp_desc;
0848                     break;
0849 
0850                 default:
0851 
0852                     /* Must be an Index op - handled below */
0853                     break;
0854                 }
0855                 break;
0856 
0857             case ACPI_TYPE_STRING:
0858 
0859                 break;
0860 
0861             default:
0862 
0863                 status = AE_AML_OPERAND_TYPE;
0864                 goto cleanup;
0865             }
0866         }
0867 
0868         if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) !=
0869             ACPI_DESC_TYPE_NAMED) {
0870             if ((operand[0])->common.type == ACPI_TYPE_STRING) {
0871                 /*
0872                  * This is a deref_of (String). The string is a reference
0873                  * to a named ACPI object.
0874                  *
0875                  * 1) Find the owning Node
0876                  * 2) Dereference the node to an actual object. Could be a
0877                  *    Field, so we need to resolve the node to a value.
0878                  */
0879                 status =
0880                     acpi_ns_get_node_unlocked(walk_state->
0881                                   scope_info->scope.
0882                                   node,
0883                                   operand[0]->
0884                                   string.pointer,
0885                                   ACPI_NS_SEARCH_PARENT,
0886                                   ACPI_CAST_INDIRECT_PTR
0887                                   (struct
0888                                    acpi_namespace_node,
0889                                    &return_desc));
0890                 if (ACPI_FAILURE(status)) {
0891                     goto cleanup;
0892                 }
0893 
0894                 status =
0895                     acpi_ex_resolve_node_to_value
0896                     (ACPI_CAST_INDIRECT_PTR
0897                      (struct acpi_namespace_node, &return_desc),
0898                      walk_state);
0899                 goto cleanup;
0900             }
0901         }
0902 
0903         /* Operand[0] may have changed from the code above */
0904 
0905         if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) ==
0906             ACPI_DESC_TYPE_NAMED) {
0907             /*
0908              * This is a deref_of (object_reference)
0909              * Get the actual object from the Node (This is the dereference).
0910              * This case may only happen when a local_x or arg_x is
0911              * dereferenced above, or for references to device and
0912              * thermal objects.
0913              */
0914             switch (((struct acpi_namespace_node *)operand[0])->
0915                 type) {
0916             case ACPI_TYPE_DEVICE:
0917             case ACPI_TYPE_THERMAL:
0918 
0919                 /* These types have no node subobject, return the NS node */
0920 
0921                 return_desc = operand[0];
0922                 break;
0923 
0924             default:
0925                 /* For most types, get the object attached to the node */
0926 
0927                 return_desc = acpi_ns_get_attached_object((struct acpi_namespace_node *)operand[0]);
0928                 acpi_ut_add_reference(return_desc);
0929                 break;
0930             }
0931         } else {
0932             /*
0933              * This must be a reference object produced by either the
0934              * Index() or ref_of() operator
0935              */
0936             switch (operand[0]->reference.class) {
0937             case ACPI_REFCLASS_INDEX:
0938                 /*
0939                  * The target type for the Index operator must be
0940                  * either a Buffer or a Package
0941                  */
0942                 switch (operand[0]->reference.target_type) {
0943                 case ACPI_TYPE_BUFFER_FIELD:
0944 
0945                     temp_desc =
0946                         operand[0]->reference.object;
0947 
0948                     /*
0949                      * Create a new object that contains one element of the
0950                      * buffer -- the element pointed to by the index.
0951                      *
0952                      * NOTE: index into a buffer is NOT a pointer to a
0953                      * sub-buffer of the main buffer, it is only a pointer to a
0954                      * single element (byte) of the buffer!
0955                      *
0956                      * Since we are returning the value of the buffer at the
0957                      * indexed location, we don't need to add an additional
0958                      * reference to the buffer itself.
0959                      */
0960                     return_desc =
0961                         acpi_ut_create_integer_object((u64)
0962                                       temp_desc->buffer.pointer[operand[0]->reference.value]);
0963                     if (!return_desc) {
0964                         status = AE_NO_MEMORY;
0965                         goto cleanup;
0966                     }
0967                     break;
0968 
0969                 case ACPI_TYPE_PACKAGE:
0970                     /*
0971                      * Return the referenced element of the package. We must
0972                      * add another reference to the referenced object, however.
0973                      */
0974                     return_desc =
0975                         *(operand[0]->reference.where);
0976                     if (!return_desc) {
0977                         /*
0978                          * Element is NULL, do not allow the dereference.
0979                          * This provides compatibility with other ACPI
0980                          * implementations.
0981                          */
0982                         return_ACPI_STATUS
0983                             (AE_AML_UNINITIALIZED_ELEMENT);
0984                     }
0985 
0986                     acpi_ut_add_reference(return_desc);
0987                     break;
0988 
0989                 default:
0990 
0991                     ACPI_ERROR((AE_INFO,
0992                             "Unknown Index TargetType 0x%X in reference object %p",
0993                             operand[0]->reference.
0994                             target_type, operand[0]));
0995 
0996                     status = AE_AML_OPERAND_TYPE;
0997                     goto cleanup;
0998                 }
0999                 break;
1000 
1001             case ACPI_REFCLASS_REFOF:
1002 
1003                 return_desc = operand[0]->reference.object;
1004 
1005                 if (ACPI_GET_DESCRIPTOR_TYPE(return_desc) ==
1006                     ACPI_DESC_TYPE_NAMED) {
1007                     return_desc =
1008                         acpi_ns_get_attached_object((struct
1009                                      acpi_namespace_node
1010                                      *)
1011                                     return_desc);
1012                     if (!return_desc) {
1013                         break;
1014                     }
1015 
1016                     /*
1017                      * June 2013:
1018                      * buffer_fields/field_units require additional resolution
1019                      */
1020                     switch (return_desc->common.type) {
1021                     case ACPI_TYPE_BUFFER_FIELD:
1022                     case ACPI_TYPE_LOCAL_REGION_FIELD:
1023                     case ACPI_TYPE_LOCAL_BANK_FIELD:
1024                     case ACPI_TYPE_LOCAL_INDEX_FIELD:
1025 
1026                         status =
1027                             acpi_ex_read_data_from_field
1028                             (walk_state, return_desc,
1029                              &temp_desc);
1030                         if (ACPI_FAILURE(status)) {
1031                             return_ACPI_STATUS
1032                                 (status);
1033                         }
1034 
1035                         return_desc = temp_desc;
1036                         break;
1037 
1038                     default:
1039 
1040                         /* Add another reference to the object */
1041 
1042                         acpi_ut_add_reference
1043                             (return_desc);
1044                         break;
1045                     }
1046                 }
1047                 break;
1048 
1049             default:
1050 
1051                 ACPI_ERROR((AE_INFO,
1052                         "Unknown class in reference(%p) - 0x%2.2X",
1053                         operand[0],
1054                         operand[0]->reference.class));
1055 
1056                 status = AE_TYPE;
1057                 goto cleanup;
1058             }
1059         }
1060         break;
1061 
1062     default:
1063 
1064         ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
1065                 walk_state->opcode));
1066 
1067         status = AE_AML_BAD_OPCODE;
1068         goto cleanup;
1069     }
1070 
1071 cleanup:
1072 
1073     /* Delete return object on error */
1074 
1075     if (ACPI_FAILURE(status)) {
1076         acpi_ut_remove_reference(return_desc);
1077     }
1078 
1079     /* Save return object on success */
1080 
1081     else {
1082         walk_state->result_obj = return_desc;
1083     }
1084 
1085     return_ACPI_STATUS(status);
1086 }