Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / acpi / executer / exconvrt.c
index 04c04e4..e6d52e1 100644 (file)
@@ -5,7 +5,7 @@
  *****************************************************************************/
 
 /*
- * Copyright (C) 2000 - 2004, R. Byron Moore
+ * Copyright (C) 2000 - 2006, R. Byron Moore
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * POSSIBILITY OF SUCH DAMAGES.
  */
 
-
 #include <acpi/acpi.h>
 #include <acpi/acinterp.h>
 #include <acpi/amlcode.h>
 
-
 #define _COMPONENT          ACPI_EXECUTER
-        ACPI_MODULE_NAME    ("exconvrt")
+ACPI_MODULE_NAME("exconvrt")
 
+/* Local prototypes */
+static u32
+acpi_ex_convert_to_ascii(acpi_integer integer,
+                        u16 base, u8 * string, u8 max_length);
 
 /*******************************************************************************
  *
@@ -58,7 +60,7 @@
  * PARAMETERS:  obj_desc        - Object to be converted.  Must be an
  *                                Integer, Buffer, or String
  *              result_desc     - Where the new Integer object is returned
- *              walk_state      - Current method state
+ *              Flags           - Used for string conversion
  *
  * RETURN:      Status
  *
  ******************************************************************************/
 
 acpi_status
-acpi_ex_convert_to_integer (
-       union acpi_operand_object       *obj_desc,
-       union acpi_operand_object       **result_desc,
-       struct acpi_walk_state          *walk_state)
+acpi_ex_convert_to_integer(union acpi_operand_object *obj_desc,
+                          union acpi_operand_object **result_desc, u32 flags)
 {
-       u32                             i;
-       union acpi_operand_object       *ret_desc;
-       u32                             count;
-       u8                              *pointer;
-       acpi_integer                    result;
-       acpi_status                     status;
+       union acpi_operand_object *return_desc;
+       u8 *pointer;
+       acpi_integer result;
+       u32 i;
+       u32 count;
+       acpi_status status;
 
+       ACPI_FUNCTION_TRACE_PTR("ex_convert_to_integer", obj_desc);
 
-       ACPI_FUNCTION_TRACE_PTR ("ex_convert_to_integer", obj_desc);
+       switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
+       case ACPI_TYPE_INTEGER:
 
+               /* No conversion necessary */
 
-       switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
-       case ACPI_TYPE_INTEGER:
                *result_desc = obj_desc;
-               return_ACPI_STATUS (AE_OK);
+               return_ACPI_STATUS(AE_OK);
 
+       case ACPI_TYPE_BUFFER:
        case ACPI_TYPE_STRING:
-               pointer = (u8 *) obj_desc->string.pointer;
-               count   = obj_desc->string.length;
-               break;
 
-       case ACPI_TYPE_BUFFER:
+               /* Note: Takes advantage of common buffer/string fields */
+
                pointer = obj_desc->buffer.pointer;
-               count   = obj_desc->buffer.length;
+               count = obj_desc->buffer.length;
                break;
 
        default:
-               return_ACPI_STATUS (AE_TYPE);
+               return_ACPI_STATUS(AE_TYPE);
        }
 
        /*
@@ -113,34 +113,40 @@ acpi_ex_convert_to_integer (
         */
        result = 0;
 
-       /* Transfer no more than an integer's worth of data */
+       /* String conversion is different than Buffer conversion */
 
-       if (count > acpi_gbl_integer_byte_width) {
-               count = acpi_gbl_integer_byte_width;
-       }
-
-       /*
-        * String conversion is different than Buffer conversion
-        */
-       switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
+       switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
        case ACPI_TYPE_STRING:
 
                /*
-                * Convert string to an integer
-                * String must be hexadecimal as per the ACPI specification
+                * Convert string to an integer - for most cases, the string must be
+                * hexadecimal as per the ACPI specification.  The only exception (as
+                * of ACPI 3.0) is that the to_integer() operator allows both decimal
+                * and hexadecimal strings (hex prefixed with "0x").
                 */
-               status = acpi_ut_strtoul64 ((char *) pointer, 16, &result);
-               if (ACPI_FAILURE (status)) {
-                       return_ACPI_STATUS (status);
+               status = acpi_ut_strtoul64((char *)pointer, flags, &result);
+               if (ACPI_FAILURE(status)) {
+                       return_ACPI_STATUS(status);
                }
                break;
 
-
        case ACPI_TYPE_BUFFER:
 
+               /* Check for zero-length buffer */
+
+               if (!count) {
+                       return_ACPI_STATUS(AE_AML_BUFFER_LIMIT);
+               }
+
+               /* Transfer no more than an integer's worth of data */
+
+               if (count > acpi_gbl_integer_byte_width) {
+                       count = acpi_gbl_integer_byte_width;
+               }
+
                /*
-                * Buffer conversion - we simply grab enough raw data from the
-                * buffer to fill an integer
+                * Convert buffer to an integer - we simply grab enough raw data
+                * from the buffer to fill an integer
                 */
                for (i = 0; i < count; i++) {
                        /*
@@ -152,40 +158,26 @@ acpi_ex_convert_to_integer (
                }
                break;
 
-
        default:
                /* No other types can get here */
                break;
        }
 
-       /*
-        * Create a new integer
-        */
-       ret_desc = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
-       if (!ret_desc) {
-               return_ACPI_STATUS (AE_NO_MEMORY);
+       /* Create a new integer */
+
+       return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
+       if (!return_desc) {
+               return_ACPI_STATUS(AE_NO_MEMORY);
        }
 
        /* Save the Result */
 
-       ret_desc->integer.value = result;
-
-       /*
-        * If we are about to overwrite the original object on the operand stack,
-        * we must remove a reference on the original object because we are
-        * essentially removing it from the stack.
-        */
-       if (*result_desc == obj_desc) {
-               if (walk_state->opcode != AML_STORE_OP) {
-                       acpi_ut_remove_reference (obj_desc);
-               }
-       }
-
-       *result_desc = ret_desc;
-       return_ACPI_STATUS (AE_OK);
+       return_desc->integer.value = result;
+       acpi_ex_truncate_for32bit_table(return_desc);
+       *result_desc = return_desc;
+       return_ACPI_STATUS(AE_OK);
 }
 
-
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ex_convert_to_buffer
@@ -193,7 +185,6 @@ acpi_ex_convert_to_integer (
  * PARAMETERS:  obj_desc        - Object to be converted.  Must be an
  *                                Integer, Buffer, or String
  *              result_desc     - Where the new buffer object is returned
- *              walk_state      - Current method state
  *
  * RETURN:      Status
  *
@@ -202,27 +193,21 @@ acpi_ex_convert_to_integer (
  ******************************************************************************/
 
 acpi_status
-acpi_ex_convert_to_buffer (
-       union acpi_operand_object       *obj_desc,
-       union acpi_operand_object       **result_desc,
-       struct acpi_walk_state          *walk_state)
+acpi_ex_convert_to_buffer(union acpi_operand_object *obj_desc,
+                         union acpi_operand_object **result_desc)
 {
-       union acpi_operand_object       *ret_desc;
-       u32                             i;
-       u8                              *new_buf;
-
+       union acpi_operand_object *return_desc;
+       u8 *new_buf;
 
-       ACPI_FUNCTION_TRACE_PTR ("ex_convert_to_buffer", obj_desc);
+       ACPI_FUNCTION_TRACE_PTR("ex_convert_to_buffer", obj_desc);
 
-
-       switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
+       switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
        case ACPI_TYPE_BUFFER:
 
                /* No conversion necessary */
 
                *result_desc = obj_desc;
-               return_ACPI_STATUS (AE_OK);
-
+               return_ACPI_STATUS(AE_OK);
 
        case ACPI_TYPE_INTEGER:
 
@@ -230,71 +215,64 @@ acpi_ex_convert_to_buffer (
                 * Create a new Buffer object.
                 * Need enough space for one integer
                 */
-               ret_desc = acpi_ut_create_buffer_object (acpi_gbl_integer_byte_width);
-               if (!ret_desc) {
-                       return_ACPI_STATUS (AE_NO_MEMORY);
+               return_desc =
+                   acpi_ut_create_buffer_object(acpi_gbl_integer_byte_width);
+               if (!return_desc) {
+                       return_ACPI_STATUS(AE_NO_MEMORY);
                }
 
-               /* Copy the integer to the buffer */
+               /* Copy the integer to the buffer, LSB first */
 
-               new_buf = ret_desc->buffer.pointer;
-               for (i = 0; i < acpi_gbl_integer_byte_width; i++) {
-                       new_buf[i] = (u8) (obj_desc->integer.value >> (i * 8));
-               }
+               new_buf = return_desc->buffer.pointer;
+               ACPI_MEMCPY(new_buf,
+                           &obj_desc->integer.value,
+                           acpi_gbl_integer_byte_width);
                break;
 
-
        case ACPI_TYPE_STRING:
 
                /*
                 * Create a new Buffer object
                 * Size will be the string length
+                *
+                * NOTE: Add one to the string length to include the null terminator.
+                * The ACPI spec is unclear on this subject, but there is existing
+                * ASL/AML code that depends on the null being transferred to the new
+                * buffer.
                 */
-               ret_desc = acpi_ut_create_buffer_object ((acpi_size) obj_desc->string.length);
-               if (!ret_desc) {
-                       return_ACPI_STATUS (AE_NO_MEMORY);
+               return_desc = acpi_ut_create_buffer_object((acpi_size)
+                                                          obj_desc->string.
+                                                          length + 1);
+               if (!return_desc) {
+                       return_ACPI_STATUS(AE_NO_MEMORY);
                }
 
                /* Copy the string to the buffer */
 
-               new_buf = ret_desc->buffer.pointer;
-               ACPI_STRNCPY ((char *) new_buf, (char *) obj_desc->string.pointer,
-                       obj_desc->string.length);
+               new_buf = return_desc->buffer.pointer;
+               ACPI_STRNCPY((char *)new_buf, (char *)obj_desc->string.pointer,
+                            obj_desc->string.length);
                break;
 
-
        default:
-               return_ACPI_STATUS (AE_TYPE);
+               return_ACPI_STATUS(AE_TYPE);
        }
 
        /* Mark buffer initialized */
 
-       ret_desc->common.flags |= AOPOBJ_DATA_VALID;
-
-       /*
-        * If we are about to overwrite the original object on the operand stack,
-        * we must remove a reference on the original object because we are
-        * essentially removing it from the stack.
-        */
-       if (*result_desc == obj_desc) {
-               if (walk_state->opcode != AML_STORE_OP) {
-                       acpi_ut_remove_reference (obj_desc);
-               }
-       }
-
-       *result_desc = ret_desc;
-       return_ACPI_STATUS (AE_OK);
+       return_desc->common.flags |= AOPOBJ_DATA_VALID;
+       *result_desc = return_desc;
+       return_ACPI_STATUS(AE_OK);
 }
 
-
 /*******************************************************************************
  *
- * FUNCTION:    acpi_ex_convert_ascii
+ * FUNCTION:    acpi_ex_convert_to_ascii
  *
  * PARAMETERS:  Integer         - Value to be converted
- *              Base            - 10 or 16
+ *              Base            - ACPI_STRING_DECIMAL or ACPI_STRING_HEX
  *              String          - Where the string is returned
- *              data_width      - Size of data item to be converted
+ *              data_width      - Size of data item to be converted, in bytes
  *
  * RETURN:      Actual string length
  *
@@ -302,82 +280,83 @@ acpi_ex_convert_to_buffer (
  *
  ******************************************************************************/
 
-u32
-acpi_ex_convert_to_ascii (
-       acpi_integer                    integer,
-       u32                             base,
-       u8                              *string,
-       u8                              data_width)
+static u32
+acpi_ex_convert_to_ascii(acpi_integer integer,
+                        u16 base, u8 * string, u8 data_width)
 {
-       u32                             i;
-       u32                             j;
-       u32                             k = 0;
-       char                            hex_digit;
-       acpi_integer                    digit;
-       u32                             remainder;
-       u32                             length;
-       u8                              leading_zero;
+       acpi_integer digit;
+       acpi_native_uint i;
+       acpi_native_uint j;
+       acpi_native_uint k = 0;
+       acpi_native_uint hex_length;
+       acpi_native_uint decimal_length;
+       u32 remainder;
+       u8 supress_zeros;
 
+       ACPI_FUNCTION_ENTRY();
 
-       ACPI_FUNCTION_ENTRY ();
+       switch (base) {
+       case 10:
 
+               /* Setup max length for the decimal number */
 
-       if (data_width < sizeof (acpi_integer)) {
-               leading_zero = FALSE;
-               length = data_width;
-       }
-       else {
-               leading_zero = TRUE;
-               length = sizeof (acpi_integer);
-       }
+               switch (data_width) {
+               case 1:
+                       decimal_length = ACPI_MAX8_DECIMAL_DIGITS;
+                       break;
 
-       switch (base) {
-       case 10:
+               case 4:
+                       decimal_length = ACPI_MAX32_DECIMAL_DIGITS;
+                       break;
+
+               case 8:
+               default:
+                       decimal_length = ACPI_MAX64_DECIMAL_DIGITS;
+                       break;
+               }
 
+               supress_zeros = TRUE;   /* No leading zeros */
                remainder = 0;
-               for (i = ACPI_MAX_DECIMAL_DIGITS; i > 0; i--) {
+
+               for (i = decimal_length; i > 0; i--) {
                        /* Divide by nth factor of 10 */
 
                        digit = integer;
                        for (j = 0; j < i; j++) {
-                               (void) acpi_ut_short_divide (&digit, 10, &digit, &remainder);
+                               (void)acpi_ut_short_divide(digit, 10, &digit,
+                                                          &remainder);
                        }
 
-                       /* Create the decimal digit */
+                       /* Handle leading zeros */
 
                        if (remainder != 0) {
-                               leading_zero = FALSE;
+                               supress_zeros = FALSE;
                        }
 
-                       if (!leading_zero) {
+                       if (!supress_zeros) {
                                string[k] = (u8) (ACPI_ASCII_ZERO + remainder);
                                k++;
                        }
                }
                break;
 
-
        case 16:
 
-               /* Copy the integer to the buffer */
-
-               for (i = 0, j = ((length * 2) -1); i < (length * 2); i++, j--) {
+               /* hex_length: 2 ascii hex chars per data byte */
 
-                       hex_digit = acpi_ut_hex_to_ascii_char (integer, (j * 4));
-                       if (hex_digit != ACPI_ASCII_ZERO) {
-                               leading_zero = FALSE;
-                       }
+               hex_length = (acpi_native_uint) ACPI_MUL_2(data_width);
+               for (i = 0, j = (hex_length - 1); i < hex_length; i++, j--) {
+                       /* Get one hex digit, most significant digits first */
 
-                       if (!leading_zero) {
-                               string[k] = (u8) hex_digit;
-                               k++;
-                       }
+                       string[k] =
+                           (u8) acpi_ut_hex_to_ascii_char(integer,
+                                                          ACPI_MUL_4(j));
+                       k++;
                }
                break;
 
-
        default:
-               break;
+               return (0);
        }
 
        /*
@@ -387,25 +366,22 @@ acpi_ex_convert_to_ascii (
         * Finally, null terminate the string and return the length
         */
        if (!k) {
-               string [0] = ACPI_ASCII_ZERO;
+               string[0] = ACPI_ASCII_ZERO;
                k = 1;
        }
 
-       string [k] = 0;
-       return (k);
+       string[k] = 0;
+       return ((u32) k);
 }
 
-
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ex_convert_to_string
  *
  * PARAMETERS:  obj_desc        - Object to be converted.  Must be an
- *                                  Integer, Buffer, or String
+ *                                Integer, Buffer, or String
  *              result_desc     - Where the string object is returned
- *              Base            - 10 or 16
- *              max_length      - Max length of the returned string
- *              walk_state      - Current method state
+ *              Type            - String flags (base and conversion type)
  *
  * RETURN:      Status
  *
@@ -414,154 +390,160 @@ acpi_ex_convert_to_ascii (
  ******************************************************************************/
 
 acpi_status
-acpi_ex_convert_to_string (
-       union acpi_operand_object       *obj_desc,
-       union acpi_operand_object       **result_desc,
-       u32                             base,
-       u32                             max_length,
-       struct acpi_walk_state          *walk_state)
+acpi_ex_convert_to_string(union acpi_operand_object * obj_desc,
+                         union acpi_operand_object ** result_desc, u32 type)
 {
-       union acpi_operand_object       *ret_desc;
-       u8                              *new_buf;
-       u8                              *pointer;
-       u32                             string_length;
-       u32                             i;
-
+       union acpi_operand_object *return_desc;
+       u8 *new_buf;
+       u32 i;
+       u32 string_length = 0;
+       u16 base = 16;
+       u8 separator = ',';
 
-       ACPI_FUNCTION_TRACE_PTR ("ex_convert_to_string", obj_desc);
+       ACPI_FUNCTION_TRACE_PTR("ex_convert_to_string", obj_desc);
 
-
-       switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
+       switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
        case ACPI_TYPE_STRING:
 
-               if (max_length >= obj_desc->string.length) {
-                       *result_desc = obj_desc;
-                       return_ACPI_STATUS (AE_OK);
-               }
-               else {
-                       /* Must copy the string first and then truncate it */
-
-                       return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
-               }
+               /* No conversion necessary */
 
+               *result_desc = obj_desc;
+               return_ACPI_STATUS(AE_OK);
 
        case ACPI_TYPE_INTEGER:
 
-               string_length = acpi_gbl_integer_byte_width * 2;
-               if (base == 10) {
+               switch (type) {
+               case ACPI_EXPLICIT_CONVERT_DECIMAL:
+
+                       /* Make room for maximum decimal number */
+
                        string_length = ACPI_MAX_DECIMAL_DIGITS;
+                       base = 10;
+                       break;
+
+               default:
+
+                       /* Two hex string characters for each integer byte */
+
+                       string_length = ACPI_MUL_2(acpi_gbl_integer_byte_width);
+                       break;
                }
 
                /*
                 * Create a new String
+                * Need enough space for one ASCII integer (plus null terminator)
                 */
-               ret_desc = acpi_ut_create_internal_object (ACPI_TYPE_STRING);
-               if (!ret_desc) {
-                       return_ACPI_STATUS (AE_NO_MEMORY);
+               return_desc =
+                   acpi_ut_create_string_object((acpi_size) string_length);
+               if (!return_desc) {
+                       return_ACPI_STATUS(AE_NO_MEMORY);
                }
 
-               /* Need enough space for one ASCII integer plus null terminator */
-
-               new_buf = ACPI_MEM_CALLOCATE ((acpi_size) string_length + 1);
-               if (!new_buf) {
-                       ACPI_REPORT_ERROR
-                               (("ex_convert_to_string: Buffer allocation failure\n"));
-                       acpi_ut_remove_reference (ret_desc);
-                       return_ACPI_STATUS (AE_NO_MEMORY);
-               }
+               new_buf = return_desc->buffer.pointer;
 
-               /* Convert */
+               /* Convert integer to string */
 
-               i = acpi_ex_convert_to_ascii (obj_desc->integer.value, base, new_buf, sizeof (acpi_integer));
+               string_length =
+                   acpi_ex_convert_to_ascii(obj_desc->integer.value, base,
+                                            new_buf,
+                                            acpi_gbl_integer_byte_width);
 
                /* Null terminate at the correct place */
 
-               if (max_length < i) {
-                       new_buf[max_length] = 0;
-                       ret_desc->string.length = max_length;
-               }
-               else {
-                       new_buf [i] = 0;
-                       ret_desc->string.length = i;
-               }
-
-               ret_desc->buffer.pointer = new_buf;
+               return_desc->string.length = string_length;
+               new_buf[string_length] = 0;
                break;
 
-
        case ACPI_TYPE_BUFFER:
 
-               /* Find the string length */
+               /* Setup string length, base, and separator */
 
-               pointer = obj_desc->buffer.pointer;
-               for (string_length = 0; string_length < obj_desc->buffer.length; string_length++) {
-                       /* Exit on null terminator */
+               switch (type) {
+               case ACPI_EXPLICIT_CONVERT_DECIMAL:     /* Used by to_decimal_string */
+                       /*
+                        * From ACPI: "If Data is a buffer, it is converted to a string of
+                        * decimal values separated by commas."
+                        */
+                       base = 10;
 
-                       if (!pointer[string_length]) {
-                               break;
+                       /*
+                        * Calculate the final string length.  Individual string values
+                        * are variable length (include separator for each)
+                        */
+                       for (i = 0; i < obj_desc->buffer.length; i++) {
+                               if (obj_desc->buffer.pointer[i] >= 100) {
+                                       string_length += 4;
+                               } else if (obj_desc->buffer.pointer[i] >= 10) {
+                                       string_length += 3;
+                               } else {
+                                       string_length += 2;
+                               }
                        }
-               }
+                       break;
 
-               if (max_length > ACPI_MAX_STRING_CONVERSION) {
-                       if (string_length > ACPI_MAX_STRING_CONVERSION) {
-                               return_ACPI_STATUS (AE_AML_STRING_LIMIT);
-                       }
+               case ACPI_IMPLICIT_CONVERT_HEX:
+                       /*
+                        * From the ACPI spec:
+                        *"The entire contents of the buffer are converted to a string of
+                        * two-character hexadecimal numbers, each separated by a space."
+                        */
+                       separator = ' ';
+                       string_length = (obj_desc->buffer.length * 3);
+                       break;
+
+               case ACPI_EXPLICIT_CONVERT_HEX: /* Used by to_hex_string */
+                       /*
+                        * From ACPI: "If Data is a buffer, it is converted to a string of
+                        * hexadecimal values separated by commas."
+                        */
+                       string_length = (obj_desc->buffer.length * 3);
+                       break;
+
+               default:
+                       return_ACPI_STATUS(AE_BAD_PARAMETER);
                }
 
                /*
-                * Create a new string object
+                * Create a new string object and string buffer
+                * (-1 because of extra separator included in string_length from above)
                 */
-               ret_desc = acpi_ut_create_internal_object (ACPI_TYPE_STRING);
-               if (!ret_desc) {
-                       return_ACPI_STATUS (AE_NO_MEMORY);
+               return_desc =
+                   acpi_ut_create_string_object((acpi_size)
+                                                (string_length - 1));
+               if (!return_desc) {
+                       return_ACPI_STATUS(AE_NO_MEMORY);
                }
 
-               /* String length is the lesser of the Max or the actual length */
+               new_buf = return_desc->buffer.pointer;
 
-               if (max_length < string_length) {
-                       string_length = max_length;
-               }
-
-               new_buf = ACPI_MEM_CALLOCATE ((acpi_size) string_length + 1);
-               if (!new_buf) {
-                       ACPI_REPORT_ERROR
-                               (("ex_convert_to_string: Buffer allocation failure\n"));
-                       acpi_ut_remove_reference (ret_desc);
-                       return_ACPI_STATUS (AE_NO_MEMORY);
+               /*
+                * Convert buffer bytes to hex or decimal values
+                * (separated by commas or spaces)
+                */
+               for (i = 0; i < obj_desc->buffer.length; i++) {
+                       new_buf += acpi_ex_convert_to_ascii((acpi_integer)
+                                                           obj_desc->buffer.
+                                                           pointer[i], base,
+                                                           new_buf, 1);
+                       *new_buf++ = separator; /* each separated by a comma or space */
                }
 
-               /* Copy the appropriate number of buffer characters */
-
-               ACPI_MEMCPY (new_buf, pointer, string_length);
-
-               /* Null terminate */
-
-               new_buf [string_length] = 0;
-               ret_desc->buffer.pointer = new_buf;
-               ret_desc->string.length = string_length;
+               /*
+                * Null terminate the string
+                * (overwrites final comma/space from above)
+                */
+               new_buf--;
+               *new_buf = 0;
                break;
 
-
        default:
-               return_ACPI_STATUS (AE_TYPE);
+               return_ACPI_STATUS(AE_TYPE);
        }
 
-       /*
-        * If we are about to overwrite the original object on the operand stack,
-        * we must remove a reference on the original object because we are
-        * essentially removing it from the stack.
-        */
-       if (*result_desc == obj_desc) {
-               if (walk_state->opcode != AML_STORE_OP) {
-                       acpi_ut_remove_reference (obj_desc);
-               }
-       }
-
-       *result_desc = ret_desc;
-       return_ACPI_STATUS (AE_OK);
+       *result_desc = return_desc;
+       return_ACPI_STATUS(AE_OK);
 }
 
-
 /*******************************************************************************
  *
  * FUNCTION:    acpi_ex_convert_to_target_type
@@ -578,17 +560,14 @@ acpi_ex_convert_to_string (
  ******************************************************************************/
 
 acpi_status
-acpi_ex_convert_to_target_type (
-       acpi_object_type                destination_type,
-       union acpi_operand_object       *source_desc,
-       union acpi_operand_object       **result_desc,
-       struct acpi_walk_state          *walk_state)
+acpi_ex_convert_to_target_type(acpi_object_type destination_type,
+                              union acpi_operand_object *source_desc,
+                              union acpi_operand_object **result_desc,
+                              struct acpi_walk_state *walk_state)
 {
-       acpi_status                     status = AE_OK;
-
-
-       ACPI_FUNCTION_TRACE ("ex_convert_to_target_type");
+       acpi_status status = AE_OK;
 
+       ACPI_FUNCTION_TRACE("ex_convert_to_target_type");
 
        /* Default behavior */
 
@@ -598,10 +577,10 @@ acpi_ex_convert_to_target_type (
         * If required by the target,
         * perform implicit conversion on the source before we store it.
         */
-       switch (GET_CURRENT_ARG_TYPE (walk_state->op_info->runtime_args)) {
+       switch (GET_CURRENT_ARG_TYPE(walk_state->op_info->runtime_args)) {
        case ARGI_SIMPLE_TARGET:
        case ARGI_FIXED_TARGET:
-       case ARGI_INTEGER_REF:      /* Handles Increment, Decrement cases */
+       case ARGI_INTEGER_REF:  /* Handles Increment, Decrement cases */
 
                switch (destination_type) {
                case ACPI_TYPE_LOCAL_REGION_FIELD:
@@ -613,17 +592,19 @@ acpi_ex_convert_to_target_type (
                default:
                        /* No conversion allowed for these types */
 
-                       if (destination_type != ACPI_GET_OBJECT_TYPE (source_desc)) {
-                               ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
-                                       "Explicit operator, will store (%s) over existing type (%s)\n",
-                                       acpi_ut_get_object_type_name (source_desc),
-                                       acpi_ut_get_type_name (destination_type)));
+                       if (destination_type !=
+                           ACPI_GET_OBJECT_TYPE(source_desc)) {
+                               ACPI_DEBUG_PRINT((ACPI_DB_INFO,
+                                                 "Explicit operator, will store (%s) over existing type (%s)\n",
+                                                 acpi_ut_get_object_type_name
+                                                 (source_desc),
+                                                 acpi_ut_get_type_name
+                                                 (destination_type)));
                                status = AE_TYPE;
                        }
                }
                break;
 
-
        case ARGI_TARGETREF:
 
                switch (destination_type) {
@@ -635,54 +616,52 @@ acpi_ex_convert_to_target_type (
                         * These types require an Integer operand.  We can convert
                         * a Buffer or a String to an Integer if necessary.
                         */
-                       status = acpi_ex_convert_to_integer (source_desc, result_desc, walk_state);
+                       status =
+                           acpi_ex_convert_to_integer(source_desc, result_desc,
+                                                      16);
                        break;
 
-
                case ACPI_TYPE_STRING:
-
                        /*
                         * The operand must be a String.  We can convert an
                         * Integer or Buffer if necessary
                         */
-                       status = acpi_ex_convert_to_string (source_desc, result_desc, 16, ACPI_UINT32_MAX, walk_state);
+                       status =
+                           acpi_ex_convert_to_string(source_desc, result_desc,
+                                                     ACPI_IMPLICIT_CONVERT_HEX);
                        break;
 
-
                case ACPI_TYPE_BUFFER:
-
                        /*
                         * The operand must be a Buffer.  We can convert an
                         * Integer or String if necessary
                         */
-                       status = acpi_ex_convert_to_buffer (source_desc, result_desc, walk_state);
+                       status =
+                           acpi_ex_convert_to_buffer(source_desc, result_desc);
                        break;
 
-
                default:
-                       ACPI_REPORT_ERROR (("Bad destination type during conversion: %X\n",
-                               destination_type));
+                       ACPI_ERROR((AE_INFO,
+                                   "Bad destination type during conversion: %X",
+                                   destination_type));
                        status = AE_AML_INTERNAL;
                        break;
                }
                break;
 
-
        case ARGI_REFERENCE:
                /*
                 * create_xxxx_field cases - we are storing the field object into the name
                 */
                break;
 
-
        default:
-               ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
-                       "Unknown Target type ID 0x%X Op %s dest_type %s\n",
-                       GET_CURRENT_ARG_TYPE (walk_state->op_info->runtime_args),
-                       walk_state->op_info->name, acpi_ut_get_type_name (destination_type)));
-
-               ACPI_REPORT_ERROR (("Bad Target Type (ARGI): %X\n",
-                       GET_CURRENT_ARG_TYPE (walk_state->op_info->runtime_args)))
+               ACPI_ERROR((AE_INFO,
+                           "Unknown Target type ID 0x%X aml_opcode %X dest_type %s",
+                           GET_CURRENT_ARG_TYPE(walk_state->op_info->
+                                                runtime_args),
+                           walk_state->opcode,
+                           acpi_ut_get_type_name(destination_type)));
                status = AE_AML_INTERNAL;
        }
 
@@ -696,7 +675,5 @@ acpi_ex_convert_to_target_type (
                status = AE_OK;
        }
 
-       return_ACPI_STATUS (status);
+       return_ACPI_STATUS(status);
 }
-
-