Print this page
update to acpica-unix2-20140114
acpica-unix2-20130823
PANKOVs restructure
   1 /******************************************************************************
   2  *
   3  * Module Name: exconvrt - Object conversion routines
   4  *
   5  *****************************************************************************/
   6 
   7 /*
   8  * Copyright (C) 2000 - 2011, Intel Corp.
   9  * All rights reserved.
  10  *
  11  * Redistribution and use in source and binary forms, with or without
  12  * modification, are permitted provided that the following conditions
  13  * are met:
  14  * 1. Redistributions of source code must retain the above copyright
  15  *    notice, this list of conditions, and the following disclaimer,
  16  *    without modification.
  17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  18  *    substantially similar to the "NO WARRANTY" disclaimer below
  19  *    ("Disclaimer") and any redistribution must be conditioned upon
  20  *    including a substantially similar Disclaimer requirement for further
  21  *    binary redistribution.
  22  * 3. Neither the names of the above-listed copyright holders nor the names
  23  *    of any contributors may be used to endorse or promote products derived
  24  *    from this software without specific prior written permission.
  25  *
  26  * Alternatively, this software may be distributed under the terms of the
  27  * GNU General Public License ("GPL") version 2 as published by the Free
  28  * Software Foundation.


  97 
  98     switch (ObjDesc->Common.Type)
  99     {
 100     case ACPI_TYPE_INTEGER:
 101 
 102         /* No conversion necessary */
 103 
 104         *ResultDesc = ObjDesc;
 105         return_ACPI_STATUS (AE_OK);
 106 
 107     case ACPI_TYPE_BUFFER:
 108     case ACPI_TYPE_STRING:
 109 
 110         /* Note: Takes advantage of common buffer/string fields */
 111 
 112         Pointer = ObjDesc->Buffer.Pointer;
 113         Count   = ObjDesc->Buffer.Length;
 114         break;
 115 
 116     default:

 117         return_ACPI_STATUS (AE_TYPE);
 118     }
 119 
 120     /*
 121      * Convert the buffer/string to an integer. Note that both buffers and
 122      * strings are treated as raw data - we don't convert ascii to hex for
 123      * strings.
 124      *
 125      * There are two terminating conditions for the loop:
 126      * 1) The size of an integer has been reached, or
 127      * 2) The end of the buffer or string has been reached
 128      */
 129     Result = 0;
 130 
 131     /* String conversion is different than Buffer conversion */
 132 
 133     switch (ObjDesc->Common.Type)
 134     {
 135     case ACPI_TYPE_STRING:
 136 
 137         /*
 138          * Convert string to an integer - for most cases, the string must be
 139          * hexadecimal as per the ACPI specification. The only exception (as
 140          * of ACPI 3.0) is that the ToInteger() operator allows both decimal
 141          * and hexadecimal strings (hex prefixed with "0x").
 142          */
 143         Status = AcpiUtStrtoul64 ((char *) Pointer, Flags, &Result);
 144         if (ACPI_FAILURE (Status))
 145         {
 146             return_ACPI_STATUS (Status);
 147         }
 148         break;
 149 
 150 
 151     case ACPI_TYPE_BUFFER:
 152 
 153         /* Check for zero-length buffer */
 154 
 155         if (!Count)
 156         {
 157             return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
 158         }
 159 
 160         /* Transfer no more than an integer's worth of data */
 161 
 162         if (Count > AcpiGbl_IntegerByteWidth)
 163         {
 164             Count = AcpiGbl_IntegerByteWidth;
 165         }
 166 
 167         /*
 168          * Convert buffer to an integer - we simply grab enough raw data
 169          * from the buffer to fill an integer
 170          */
 171         for (i = 0; i < Count; i++)
 172         {
 173             /*
 174              * Get next byte and shift it into the Result.
 175              * Little endian is used, meaning that the first byte of the buffer
 176              * is the LSB of the integer
 177              */
 178             Result |= (((UINT64) Pointer[i]) << (i * 8));
 179         }
 180         break;
 181 
 182 
 183     default:
 184 
 185         /* No other types can get here */

 186         break;
 187     }
 188 
 189     /* Create a new integer */
 190 
 191     ReturnDesc = AcpiUtCreateIntegerObject (Result);
 192     if (!ReturnDesc)
 193     {
 194         return_ACPI_STATUS (AE_NO_MEMORY);
 195     }
 196 
 197     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
 198         ACPI_FORMAT_UINT64 (Result)));
 199 
 200     /* Save the Result */
 201 
 202     AcpiExTruncateFor32bitTable (ReturnDesc);
 203     *ResultDesc = ReturnDesc;
 204     return_ACPI_STATUS (AE_OK);
 205 }
 206 
 207 
 208 /*******************************************************************************
 209  *
 210  * FUNCTION:    AcpiExConvertToBuffer
 211  *
 212  * PARAMETERS:  ObjDesc         - Object to be converted. Must be an
 213  *                                Integer, Buffer, or String
 214  *              ResultDesc      - Where the new buffer object is returned
 215  *
 216  * RETURN:      Status
 217  *
 218  * DESCRIPTION: Convert an ACPI Object to a Buffer
 219  *
 220  ******************************************************************************/
 221 
 222 ACPI_STATUS


 225     ACPI_OPERAND_OBJECT     **ResultDesc)
 226 {
 227     ACPI_OPERAND_OBJECT     *ReturnDesc;
 228     UINT8                   *NewBuf;
 229 
 230 
 231     ACPI_FUNCTION_TRACE_PTR (ExConvertToBuffer, ObjDesc);
 232 
 233 
 234     switch (ObjDesc->Common.Type)
 235     {
 236     case ACPI_TYPE_BUFFER:
 237 
 238         /* No conversion necessary */
 239 
 240         *ResultDesc = ObjDesc;
 241         return_ACPI_STATUS (AE_OK);
 242 
 243 
 244     case ACPI_TYPE_INTEGER:
 245 
 246         /*
 247          * Create a new Buffer object.
 248          * Need enough space for one integer
 249          */
 250         ReturnDesc = AcpiUtCreateBufferObject (AcpiGbl_IntegerByteWidth);
 251         if (!ReturnDesc)
 252         {
 253             return_ACPI_STATUS (AE_NO_MEMORY);
 254         }
 255 
 256         /* Copy the integer to the buffer, LSB first */
 257 
 258         NewBuf = ReturnDesc->Buffer.Pointer;
 259         ACPI_MEMCPY (NewBuf,
 260                         &ObjDesc->Integer.Value,
 261                         AcpiGbl_IntegerByteWidth);
 262         break;
 263 
 264 
 265     case ACPI_TYPE_STRING:
 266 
 267         /*
 268          * Create a new Buffer object
 269          * Size will be the string length
 270          *
 271          * NOTE: Add one to the string length to include the null terminator.
 272          * The ACPI spec is unclear on this subject, but there is existing
 273          * ASL/AML code that depends on the null being transferred to the new
 274          * buffer.
 275          */
 276         ReturnDesc = AcpiUtCreateBufferObject (
 277                         (ACPI_SIZE) ObjDesc->String.Length + 1);
 278         if (!ReturnDesc)
 279         {
 280             return_ACPI_STATUS (AE_NO_MEMORY);
 281         }
 282 
 283         /* Copy the string to the buffer */
 284 
 285         NewBuf = ReturnDesc->Buffer.Pointer;
 286         ACPI_STRNCPY ((char *) NewBuf, (char *) ObjDesc->String.Pointer,
 287             ObjDesc->String.Length);
 288         break;
 289 
 290 
 291     default:

 292         return_ACPI_STATUS (AE_TYPE);
 293     }
 294 
 295     /* Mark buffer initialized */
 296 
 297     ReturnDesc->Common.Flags |= AOPOBJ_DATA_VALID;
 298     *ResultDesc = ReturnDesc;
 299     return_ACPI_STATUS (AE_OK);
 300 }
 301 
 302 
 303 /*******************************************************************************
 304  *
 305  * FUNCTION:    AcpiExConvertToAscii
 306  *
 307  * PARAMETERS:  Integer         - Value to be converted
 308  *              Base            - ACPI_STRING_DECIMAL or ACPI_STRING_HEX
 309  *              String          - Where the string is returned
 310  *              DataWidth       - Size of data item to be converted, in bytes
 311  *


 327     UINT32                  j;
 328     UINT32                  k = 0;
 329     UINT32                  HexLength;
 330     UINT32                  DecimalLength;
 331     UINT32                  Remainder;
 332     BOOLEAN                 SupressZeros;
 333 
 334 
 335     ACPI_FUNCTION_ENTRY ();
 336 
 337 
 338     switch (Base)
 339     {
 340     case 10:
 341 
 342         /* Setup max length for the decimal number */
 343 
 344         switch (DataWidth)
 345         {
 346         case 1:

 347             DecimalLength = ACPI_MAX8_DECIMAL_DIGITS;
 348             break;
 349 
 350         case 4:

 351             DecimalLength = ACPI_MAX32_DECIMAL_DIGITS;
 352             break;
 353 
 354         case 8:
 355         default:

 356             DecimalLength = ACPI_MAX64_DECIMAL_DIGITS;
 357             break;
 358         }
 359 
 360         SupressZeros = TRUE;     /* No leading zeros */
 361         Remainder = 0;
 362 
 363         for (i = DecimalLength; i > 0; i--)
 364         {
 365             /* Divide by nth factor of 10 */
 366 
 367             Digit = Integer;
 368             for (j = 0; j < i; j++)
 369             {
 370                 (void) AcpiUtShortDivide (Digit, 10, &Digit, &Remainder);
 371             }
 372 
 373             /* Handle leading zeros */
 374 
 375             if (Remainder != 0)


 444     ACPI_OPERAND_OBJECT     *ReturnDesc;
 445     UINT8                   *NewBuf;
 446     UINT32                  i;
 447     UINT32                  StringLength = 0;
 448     UINT16                  Base = 16;
 449     UINT8                   Separator = ',';
 450 
 451 
 452     ACPI_FUNCTION_TRACE_PTR (ExConvertToString, ObjDesc);
 453 
 454 
 455     switch (ObjDesc->Common.Type)
 456     {
 457     case ACPI_TYPE_STRING:
 458 
 459         /* No conversion necessary */
 460 
 461         *ResultDesc = ObjDesc;
 462         return_ACPI_STATUS (AE_OK);
 463 
 464 
 465     case ACPI_TYPE_INTEGER:
 466 
 467         switch (Type)
 468         {
 469         case ACPI_EXPLICIT_CONVERT_DECIMAL:
 470 
 471             /* Make room for maximum decimal number */
 472 
 473             StringLength = ACPI_MAX_DECIMAL_DIGITS;
 474             Base = 10;
 475             break;
 476 
 477         default:
 478 
 479             /* Two hex string characters for each integer byte */
 480 
 481             StringLength = ACPI_MUL_2 (AcpiGbl_IntegerByteWidth);
 482             break;
 483         }
 484 


 488          */
 489         ReturnDesc = AcpiUtCreateStringObject ((ACPI_SIZE) StringLength);
 490         if (!ReturnDesc)
 491         {
 492             return_ACPI_STATUS (AE_NO_MEMORY);
 493         }
 494 
 495         NewBuf = ReturnDesc->Buffer.Pointer;
 496 
 497         /* Convert integer to string */
 498 
 499         StringLength = AcpiExConvertToAscii (ObjDesc->Integer.Value, Base,
 500                             NewBuf, AcpiGbl_IntegerByteWidth);
 501 
 502         /* Null terminate at the correct place */
 503 
 504         ReturnDesc->String.Length = StringLength;
 505         NewBuf [StringLength] = 0;
 506         break;
 507 
 508 
 509     case ACPI_TYPE_BUFFER:
 510 
 511         /* Setup string length, base, and separator */
 512 
 513         switch (Type)
 514         {
 515         case ACPI_EXPLICIT_CONVERT_DECIMAL: /* Used by ToDecimalString */
 516             /*
 517              * From ACPI: "If Data is a buffer, it is converted to a string of
 518              * decimal values separated by commas."
 519              */
 520             Base = 10;
 521 
 522             /*
 523              * Calculate the final string length. Individual string values
 524              * are variable length (include separator for each)
 525              */
 526             for (i = 0; i < ObjDesc->Buffer.Length; i++)
 527             {
 528                 if (ObjDesc->Buffer.Pointer[i] >= 100)


 587         for (i = 0; i < ObjDesc->Buffer.Length; i++)
 588         {
 589             NewBuf += AcpiExConvertToAscii (
 590                         (UINT64) ObjDesc->Buffer.Pointer[i], Base,
 591                         NewBuf, 1);
 592             *NewBuf++ = Separator; /* each separated by a comma or space */
 593         }
 594 
 595         /*
 596          * Null terminate the string
 597          * (overwrites final comma/space from above)
 598          */
 599         if (ObjDesc->Buffer.Length)
 600         {
 601             NewBuf--;
 602         }
 603         *NewBuf = 0;
 604         break;
 605 
 606     default:

 607         return_ACPI_STATUS (AE_TYPE);
 608     }
 609 
 610     *ResultDesc = ReturnDesc;
 611     return_ACPI_STATUS (AE_OK);
 612 }
 613 
 614 
 615 /*******************************************************************************
 616  *
 617  * FUNCTION:    AcpiExConvertToTargetType
 618  *
 619  * PARAMETERS:  DestinationType     - Current type of the destination
 620  *              SourceDesc          - Source object to be converted.
 621  *              ResultDesc          - Where the converted object is returned
 622  *              WalkState           - Current method state
 623  *
 624  * RETURN:      Status
 625  *
 626  * DESCRIPTION: Implements "implicit conversion" rules for storing an object.


 646 
 647     /*
 648      * If required by the target,
 649      * perform implicit conversion on the source before we store it.
 650      */
 651     switch (GET_CURRENT_ARG_TYPE (WalkState->OpInfo->RuntimeArgs))
 652     {
 653     case ARGI_SIMPLE_TARGET:
 654     case ARGI_FIXED_TARGET:
 655     case ARGI_INTEGER_REF:      /* Handles Increment, Decrement cases */
 656 
 657         switch (DestinationType)
 658         {
 659         case ACPI_TYPE_LOCAL_REGION_FIELD:
 660             /*
 661              * Named field can always handle conversions
 662              */
 663             break;
 664 
 665         default:

 666             /* No conversion allowed for these types */
 667 
 668             if (DestinationType != SourceDesc->Common.Type)
 669             {
 670                 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
 671                     "Explicit operator, will store (%s) over existing type (%s)\n",
 672                     AcpiUtGetObjectTypeName (SourceDesc),
 673                     AcpiUtGetTypeName (DestinationType)));
 674                 Status = AE_TYPE;
 675             }
 676         }
 677         break;
 678 
 679 
 680     case ARGI_TARGETREF:
 681 
 682         switch (DestinationType)
 683         {
 684         case ACPI_TYPE_INTEGER:
 685         case ACPI_TYPE_BUFFER_FIELD:
 686         case ACPI_TYPE_LOCAL_BANK_FIELD:
 687         case ACPI_TYPE_LOCAL_INDEX_FIELD:
 688             /*
 689              * These types require an Integer operand. We can convert
 690              * a Buffer or a String to an Integer if necessary.
 691              */
 692             Status = AcpiExConvertToInteger (SourceDesc, ResultDesc,
 693                         16);
 694             break;
 695 
 696 
 697         case ACPI_TYPE_STRING:
 698             /*
 699              * The operand must be a String. We can convert an
 700              * Integer or Buffer if necessary
 701              */
 702             Status = AcpiExConvertToString (SourceDesc, ResultDesc,
 703                         ACPI_IMPLICIT_CONVERT_HEX);
 704             break;
 705 
 706 
 707         case ACPI_TYPE_BUFFER:
 708             /*
 709              * The operand must be a Buffer. We can convert an
 710              * Integer or String if necessary
 711              */
 712             Status = AcpiExConvertToBuffer (SourceDesc, ResultDesc);
 713             break;
 714 
 715 
 716         default:

 717             ACPI_ERROR ((AE_INFO, "Bad destination type during conversion: 0x%X",
 718                 DestinationType));
 719             Status = AE_AML_INTERNAL;
 720             break;
 721         }
 722         break;
 723 
 724 
 725     case ARGI_REFERENCE:
 726         /*
 727          * CreateXxxxField cases - we are storing the field object into the name
 728          */
 729         break;
 730 
 731 
 732     default:

 733         ACPI_ERROR ((AE_INFO,
 734             "Unknown Target type ID 0x%X AmlOpcode 0x%X DestType %s",
 735             GET_CURRENT_ARG_TYPE (WalkState->OpInfo->RuntimeArgs),
 736             WalkState->Opcode, AcpiUtGetTypeName (DestinationType)));
 737         Status = AE_AML_INTERNAL;
 738     }
 739 
 740     /*
 741      * Source-to-Target conversion semantics:
 742      *
 743      * If conversion to the target type cannot be performed, then simply
 744      * overwrite the target with the new object and type.
 745      */
 746     if (Status == AE_TYPE)
 747     {
 748         Status = AE_OK;
 749     }
 750 
 751     return_ACPI_STATUS (Status);
 752 }
 753 
 754 
   1 /******************************************************************************
   2  *
   3  * Module Name: exconvrt - Object conversion routines
   4  *
   5  *****************************************************************************/
   6 
   7 /*
   8  * Copyright (C) 2000 - 2014, Intel Corp.
   9  * All rights reserved.
  10  *
  11  * Redistribution and use in source and binary forms, with or without
  12  * modification, are permitted provided that the following conditions
  13  * are met:
  14  * 1. Redistributions of source code must retain the above copyright
  15  *    notice, this list of conditions, and the following disclaimer,
  16  *    without modification.
  17  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
  18  *    substantially similar to the "NO WARRANTY" disclaimer below
  19  *    ("Disclaimer") and any redistribution must be conditioned upon
  20  *    including a substantially similar Disclaimer requirement for further
  21  *    binary redistribution.
  22  * 3. Neither the names of the above-listed copyright holders nor the names
  23  *    of any contributors may be used to endorse or promote products derived
  24  *    from this software without specific prior written permission.
  25  *
  26  * Alternatively, this software may be distributed under the terms of the
  27  * GNU General Public License ("GPL") version 2 as published by the Free
  28  * Software Foundation.


  97 
  98     switch (ObjDesc->Common.Type)
  99     {
 100     case ACPI_TYPE_INTEGER:
 101 
 102         /* No conversion necessary */
 103 
 104         *ResultDesc = ObjDesc;
 105         return_ACPI_STATUS (AE_OK);
 106 
 107     case ACPI_TYPE_BUFFER:
 108     case ACPI_TYPE_STRING:
 109 
 110         /* Note: Takes advantage of common buffer/string fields */
 111 
 112         Pointer = ObjDesc->Buffer.Pointer;
 113         Count   = ObjDesc->Buffer.Length;
 114         break;
 115 
 116     default:
 117 
 118         return_ACPI_STATUS (AE_TYPE);
 119     }
 120 
 121     /*
 122      * Convert the buffer/string to an integer. Note that both buffers and
 123      * strings are treated as raw data - we don't convert ascii to hex for
 124      * strings.
 125      *
 126      * There are two terminating conditions for the loop:
 127      * 1) The size of an integer has been reached, or
 128      * 2) The end of the buffer or string has been reached
 129      */
 130     Result = 0;
 131 
 132     /* String conversion is different than Buffer conversion */
 133 
 134     switch (ObjDesc->Common.Type)
 135     {
 136     case ACPI_TYPE_STRING:

 137         /*
 138          * Convert string to an integer - for most cases, the string must be
 139          * hexadecimal as per the ACPI specification. The only exception (as
 140          * of ACPI 3.0) is that the ToInteger() operator allows both decimal
 141          * and hexadecimal strings (hex prefixed with "0x").
 142          */
 143         Status = AcpiUtStrtoul64 ((char *) Pointer, Flags, &Result);
 144         if (ACPI_FAILURE (Status))
 145         {
 146             return_ACPI_STATUS (Status);
 147         }
 148         break;
 149 

 150     case ACPI_TYPE_BUFFER:
 151 
 152         /* Check for zero-length buffer */
 153 
 154         if (!Count)
 155         {
 156             return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
 157         }
 158 
 159         /* Transfer no more than an integer's worth of data */
 160 
 161         if (Count > AcpiGbl_IntegerByteWidth)
 162         {
 163             Count = AcpiGbl_IntegerByteWidth;
 164         }
 165 
 166         /*
 167          * Convert buffer to an integer - we simply grab enough raw data
 168          * from the buffer to fill an integer
 169          */
 170         for (i = 0; i < Count; i++)
 171         {
 172             /*
 173              * Get next byte and shift it into the Result.
 174              * Little endian is used, meaning that the first byte of the buffer
 175              * is the LSB of the integer
 176              */
 177             Result |= (((UINT64) Pointer[i]) << (i * 8));
 178         }
 179         break;
 180 

 181     default:
 182 
 183         /* No other types can get here */
 184 
 185         break;
 186     }
 187 
 188     /* Create a new integer */
 189 
 190     ReturnDesc = AcpiUtCreateIntegerObject (Result);
 191     if (!ReturnDesc)
 192     {
 193         return_ACPI_STATUS (AE_NO_MEMORY);
 194     }
 195 
 196     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
 197         ACPI_FORMAT_UINT64 (Result)));
 198 
 199     /* Save the Result */
 200 
 201     (void) AcpiExTruncateFor32bitTable (ReturnDesc);
 202     *ResultDesc = ReturnDesc;
 203     return_ACPI_STATUS (AE_OK);
 204 }
 205 
 206 
 207 /*******************************************************************************
 208  *
 209  * FUNCTION:    AcpiExConvertToBuffer
 210  *
 211  * PARAMETERS:  ObjDesc         - Object to be converted. Must be an
 212  *                                Integer, Buffer, or String
 213  *              ResultDesc      - Where the new buffer object is returned
 214  *
 215  * RETURN:      Status
 216  *
 217  * DESCRIPTION: Convert an ACPI Object to a Buffer
 218  *
 219  ******************************************************************************/
 220 
 221 ACPI_STATUS


 224     ACPI_OPERAND_OBJECT     **ResultDesc)
 225 {
 226     ACPI_OPERAND_OBJECT     *ReturnDesc;
 227     UINT8                   *NewBuf;
 228 
 229 
 230     ACPI_FUNCTION_TRACE_PTR (ExConvertToBuffer, ObjDesc);
 231 
 232 
 233     switch (ObjDesc->Common.Type)
 234     {
 235     case ACPI_TYPE_BUFFER:
 236 
 237         /* No conversion necessary */
 238 
 239         *ResultDesc = ObjDesc;
 240         return_ACPI_STATUS (AE_OK);
 241 
 242 
 243     case ACPI_TYPE_INTEGER:

 244         /*
 245          * Create a new Buffer object.
 246          * Need enough space for one integer
 247          */
 248         ReturnDesc = AcpiUtCreateBufferObject (AcpiGbl_IntegerByteWidth);
 249         if (!ReturnDesc)
 250         {
 251             return_ACPI_STATUS (AE_NO_MEMORY);
 252         }
 253 
 254         /* Copy the integer to the buffer, LSB first */
 255 
 256         NewBuf = ReturnDesc->Buffer.Pointer;
 257         ACPI_MEMCPY (NewBuf,
 258                         &ObjDesc->Integer.Value,
 259                         AcpiGbl_IntegerByteWidth);
 260         break;
 261 

 262     case ACPI_TYPE_STRING:

 263         /*
 264          * Create a new Buffer object
 265          * Size will be the string length
 266          *
 267          * NOTE: Add one to the string length to include the null terminator.
 268          * The ACPI spec is unclear on this subject, but there is existing
 269          * ASL/AML code that depends on the null being transferred to the new
 270          * buffer.
 271          */
 272         ReturnDesc = AcpiUtCreateBufferObject (
 273                         (ACPI_SIZE) ObjDesc->String.Length + 1);
 274         if (!ReturnDesc)
 275         {
 276             return_ACPI_STATUS (AE_NO_MEMORY);
 277         }
 278 
 279         /* Copy the string to the buffer */
 280 
 281         NewBuf = ReturnDesc->Buffer.Pointer;
 282         ACPI_STRNCPY ((char *) NewBuf, (char *) ObjDesc->String.Pointer,
 283             ObjDesc->String.Length);
 284         break;
 285 

 286     default:
 287 
 288         return_ACPI_STATUS (AE_TYPE);
 289     }
 290 
 291     /* Mark buffer initialized */
 292 
 293     ReturnDesc->Common.Flags |= AOPOBJ_DATA_VALID;
 294     *ResultDesc = ReturnDesc;
 295     return_ACPI_STATUS (AE_OK);
 296 }
 297 
 298 
 299 /*******************************************************************************
 300  *
 301  * FUNCTION:    AcpiExConvertToAscii
 302  *
 303  * PARAMETERS:  Integer         - Value to be converted
 304  *              Base            - ACPI_STRING_DECIMAL or ACPI_STRING_HEX
 305  *              String          - Where the string is returned
 306  *              DataWidth       - Size of data item to be converted, in bytes
 307  *


 323     UINT32                  j;
 324     UINT32                  k = 0;
 325     UINT32                  HexLength;
 326     UINT32                  DecimalLength;
 327     UINT32                  Remainder;
 328     BOOLEAN                 SupressZeros;
 329 
 330 
 331     ACPI_FUNCTION_ENTRY ();
 332 
 333 
 334     switch (Base)
 335     {
 336     case 10:
 337 
 338         /* Setup max length for the decimal number */
 339 
 340         switch (DataWidth)
 341         {
 342         case 1:
 343 
 344             DecimalLength = ACPI_MAX8_DECIMAL_DIGITS;
 345             break;
 346 
 347         case 4:
 348 
 349             DecimalLength = ACPI_MAX32_DECIMAL_DIGITS;
 350             break;
 351 
 352         case 8:
 353         default:
 354 
 355             DecimalLength = ACPI_MAX64_DECIMAL_DIGITS;
 356             break;
 357         }
 358 
 359         SupressZeros = TRUE;     /* No leading zeros */
 360         Remainder = 0;
 361 
 362         for (i = DecimalLength; i > 0; i--)
 363         {
 364             /* Divide by nth factor of 10 */
 365 
 366             Digit = Integer;
 367             for (j = 0; j < i; j++)
 368             {
 369                 (void) AcpiUtShortDivide (Digit, 10, &Digit, &Remainder);
 370             }
 371 
 372             /* Handle leading zeros */
 373 
 374             if (Remainder != 0)


 443     ACPI_OPERAND_OBJECT     *ReturnDesc;
 444     UINT8                   *NewBuf;
 445     UINT32                  i;
 446     UINT32                  StringLength = 0;
 447     UINT16                  Base = 16;
 448     UINT8                   Separator = ',';
 449 
 450 
 451     ACPI_FUNCTION_TRACE_PTR (ExConvertToString, ObjDesc);
 452 
 453 
 454     switch (ObjDesc->Common.Type)
 455     {
 456     case ACPI_TYPE_STRING:
 457 
 458         /* No conversion necessary */
 459 
 460         *ResultDesc = ObjDesc;
 461         return_ACPI_STATUS (AE_OK);
 462 

 463     case ACPI_TYPE_INTEGER:
 464 
 465         switch (Type)
 466         {
 467         case ACPI_EXPLICIT_CONVERT_DECIMAL:
 468 
 469             /* Make room for maximum decimal number */
 470 
 471             StringLength = ACPI_MAX_DECIMAL_DIGITS;
 472             Base = 10;
 473             break;
 474 
 475         default:
 476 
 477             /* Two hex string characters for each integer byte */
 478 
 479             StringLength = ACPI_MUL_2 (AcpiGbl_IntegerByteWidth);
 480             break;
 481         }
 482 


 486          */
 487         ReturnDesc = AcpiUtCreateStringObject ((ACPI_SIZE) StringLength);
 488         if (!ReturnDesc)
 489         {
 490             return_ACPI_STATUS (AE_NO_MEMORY);
 491         }
 492 
 493         NewBuf = ReturnDesc->Buffer.Pointer;
 494 
 495         /* Convert integer to string */
 496 
 497         StringLength = AcpiExConvertToAscii (ObjDesc->Integer.Value, Base,
 498                             NewBuf, AcpiGbl_IntegerByteWidth);
 499 
 500         /* Null terminate at the correct place */
 501 
 502         ReturnDesc->String.Length = StringLength;
 503         NewBuf [StringLength] = 0;
 504         break;
 505 

 506     case ACPI_TYPE_BUFFER:
 507 
 508         /* Setup string length, base, and separator */
 509 
 510         switch (Type)
 511         {
 512         case ACPI_EXPLICIT_CONVERT_DECIMAL: /* Used by ToDecimalString */
 513             /*
 514              * From ACPI: "If Data is a buffer, it is converted to a string of
 515              * decimal values separated by commas."
 516              */
 517             Base = 10;
 518 
 519             /*
 520              * Calculate the final string length. Individual string values
 521              * are variable length (include separator for each)
 522              */
 523             for (i = 0; i < ObjDesc->Buffer.Length; i++)
 524             {
 525                 if (ObjDesc->Buffer.Pointer[i] >= 100)


 584         for (i = 0; i < ObjDesc->Buffer.Length; i++)
 585         {
 586             NewBuf += AcpiExConvertToAscii (
 587                         (UINT64) ObjDesc->Buffer.Pointer[i], Base,
 588                         NewBuf, 1);
 589             *NewBuf++ = Separator; /* each separated by a comma or space */
 590         }
 591 
 592         /*
 593          * Null terminate the string
 594          * (overwrites final comma/space from above)
 595          */
 596         if (ObjDesc->Buffer.Length)
 597         {
 598             NewBuf--;
 599         }
 600         *NewBuf = 0;
 601         break;
 602 
 603     default:
 604 
 605         return_ACPI_STATUS (AE_TYPE);
 606     }
 607 
 608     *ResultDesc = ReturnDesc;
 609     return_ACPI_STATUS (AE_OK);
 610 }
 611 
 612 
 613 /*******************************************************************************
 614  *
 615  * FUNCTION:    AcpiExConvertToTargetType
 616  *
 617  * PARAMETERS:  DestinationType     - Current type of the destination
 618  *              SourceDesc          - Source object to be converted.
 619  *              ResultDesc          - Where the converted object is returned
 620  *              WalkState           - Current method state
 621  *
 622  * RETURN:      Status
 623  *
 624  * DESCRIPTION: Implements "implicit conversion" rules for storing an object.


 644 
 645     /*
 646      * If required by the target,
 647      * perform implicit conversion on the source before we store it.
 648      */
 649     switch (GET_CURRENT_ARG_TYPE (WalkState->OpInfo->RuntimeArgs))
 650     {
 651     case ARGI_SIMPLE_TARGET:
 652     case ARGI_FIXED_TARGET:
 653     case ARGI_INTEGER_REF:      /* Handles Increment, Decrement cases */
 654 
 655         switch (DestinationType)
 656         {
 657         case ACPI_TYPE_LOCAL_REGION_FIELD:
 658             /*
 659              * Named field can always handle conversions
 660              */
 661             break;
 662 
 663         default:
 664 
 665             /* No conversion allowed for these types */
 666 
 667             if (DestinationType != SourceDesc->Common.Type)
 668             {
 669                 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
 670                     "Explicit operator, will store (%s) over existing type (%s)\n",
 671                     AcpiUtGetObjectTypeName (SourceDesc),
 672                     AcpiUtGetTypeName (DestinationType)));
 673                 Status = AE_TYPE;
 674             }
 675         }
 676         break;
 677 

 678     case ARGI_TARGETREF:
 679 
 680         switch (DestinationType)
 681         {
 682         case ACPI_TYPE_INTEGER:
 683         case ACPI_TYPE_BUFFER_FIELD:
 684         case ACPI_TYPE_LOCAL_BANK_FIELD:
 685         case ACPI_TYPE_LOCAL_INDEX_FIELD:
 686             /*
 687              * These types require an Integer operand. We can convert
 688              * a Buffer or a String to an Integer if necessary.
 689              */
 690             Status = AcpiExConvertToInteger (SourceDesc, ResultDesc,
 691                         16);
 692             break;
 693 

 694         case ACPI_TYPE_STRING:
 695             /*
 696              * The operand must be a String. We can convert an
 697              * Integer or Buffer if necessary
 698              */
 699             Status = AcpiExConvertToString (SourceDesc, ResultDesc,
 700                         ACPI_IMPLICIT_CONVERT_HEX);
 701             break;
 702 

 703         case ACPI_TYPE_BUFFER:
 704             /*
 705              * The operand must be a Buffer. We can convert an
 706              * Integer or String if necessary
 707              */
 708             Status = AcpiExConvertToBuffer (SourceDesc, ResultDesc);
 709             break;
 710 

 711         default:
 712 
 713             ACPI_ERROR ((AE_INFO, "Bad destination type during conversion: 0x%X",
 714                 DestinationType));
 715             Status = AE_AML_INTERNAL;
 716             break;
 717         }
 718         break;
 719 

 720     case ARGI_REFERENCE:
 721         /*
 722          * CreateXxxxField cases - we are storing the field object into the name
 723          */
 724         break;
 725 

 726     default:
 727 
 728         ACPI_ERROR ((AE_INFO,
 729             "Unknown Target type ID 0x%X AmlOpcode 0x%X DestType %s",
 730             GET_CURRENT_ARG_TYPE (WalkState->OpInfo->RuntimeArgs),
 731             WalkState->Opcode, AcpiUtGetTypeName (DestinationType)));
 732         Status = AE_AML_INTERNAL;
 733     }
 734 
 735     /*
 736      * Source-to-Target conversion semantics:
 737      *
 738      * If conversion to the target type cannot be performed, then simply
 739      * overwrite the target with the new object and type.
 740      */
 741     if (Status == AE_TYPE)
 742     {
 743         Status = AE_OK;
 744     }
 745 
 746     return_ACPI_STATUS (Status);
 747 }