1 /****************************************************************************** 2 * 3 * Module Name: exconvrt - Object conversion routines 4 * 5 *****************************************************************************/ 6 7 /****************************************************************************** 8 * 9 * 1. Copyright Notice 10 * 11 * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp. 12 * All rights reserved. 13 * 14 * 2. License 15 * 16 * 2.1. This is your license from Intel Corp. under its intellectual property 17 * rights. You may have additional license terms from the party that provided 18 * you this software, covering your right to use that party's intellectual 19 * property rights. 20 * 21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 22 * copy of the source code appearing in this file ("Covered Code") an 23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the 24 * base code distributed originally by Intel ("Original Intel Code") to copy, 25 * make derivatives, distribute, use and display any portion of the Covered 26 * Code in any form, with the right to sublicense such rights; and 27 * 28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 29 * license (with the right to sublicense), under only those claims of Intel 30 * patents that are infringed by the Original Intel Code, to make, use, sell, 31 * offer to sell, and import the Covered Code and derivative works thereof 32 * solely to the minimum extent necessary to exercise the above copyright 33 * license, and in no event shall the patent license extend to any additions 34 * to or modifications of the Original Intel Code. No other license or right 35 * is granted directly or by implication, estoppel or otherwise; 36 * 37 * The above copyright and patent license is granted only if the following 38 * conditions are met: 39 * 40 * 3. Conditions 41 * 42 * 3.1. Redistribution of Source with Rights to Further Distribute Source. 43 * Redistribution of source code of any substantial portion of the Covered 44 * Code or modification with rights to further distribute source must include 45 * the above Copyright Notice, the above License, this list of Conditions, 46 * and the following Disclaimer and Export Compliance provision. In addition, 47 * Licensee must cause all Covered Code to which Licensee contributes to 48 * contain a file documenting the changes Licensee made to create that Covered 49 * Code and the date of any change. Licensee must include in that file the 50 * documentation of any changes made by any predecessor Licensee. Licensee 51 * must include a prominent statement that the modification is derived, 52 * directly or indirectly, from Original Intel Code. 53 * 54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 55 * Redistribution of source code of any substantial portion of the Covered 56 * Code or modification without rights to further distribute source must 57 * include the following Disclaimer and Export Compliance provision in the 58 * documentation and/or other materials provided with distribution. In 59 * addition, Licensee may not authorize further sublicense of source of any 60 * portion of the Covered Code, and must include terms to the effect that the 61 * license from Licensee to its licensee is limited to the intellectual 62 * property embodied in the software Licensee provides to its licensee, and 63 * not to intellectual property embodied in modifications its licensee may 64 * make. 65 * 66 * 3.3. Redistribution of Executable. Redistribution in executable form of any 67 * substantial portion of the Covered Code or modification must reproduce the 68 * above Copyright Notice, and the following Disclaimer and Export Compliance 69 * provision in the documentation and/or other materials provided with the 70 * distribution. 71 * 72 * 3.4. Intel retains all right, title, and interest in and to the Original 73 * Intel Code. 74 * 75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by 76 * Intel shall be used in advertising or otherwise to promote the sale, use or 77 * other dealings in products derived from or relating to the Covered Code 78 * without prior written authorization from Intel. 79 * 80 * 4. Disclaimer and Export Compliance 81 * 82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 88 * PARTICULAR PURPOSE. 89 * 90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 97 * LIMITED REMEDY. 98 * 99 * 4.3. Licensee shall not export, either directly or indirectly, any of this 100 * software or system incorporating such software without first obtaining any 101 * required license or other approval from the U. S. Department of Commerce or 102 * any other agency or department of the United States Government. In the 103 * event Licensee exports any such software from the United States or 104 * re-exports any such software from a foreign destination, Licensee shall 105 * ensure that the distribution and export/re-export of the software is in 106 * compliance with all laws, regulations, orders, or other restrictions of the 107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor 108 * any of its subsidiaries will export/re-export any technical data, process, 109 * software, or service, directly or indirectly, to any country for which the 110 * United States government or any agency thereof requires an export license, 111 * other governmental approval, or letter of assurance, without first obtaining 112 * such license, approval or letter. 113 * 114 ***************************************************************************** 115 * 116 * Alternatively, you may choose to be licensed under the terms of the 117 * following license: 118 * 119 * Redistribution and use in source and binary forms, with or without 120 * modification, are permitted provided that the following conditions 121 * are met: 122 * 1. Redistributions of source code must retain the above copyright 123 * notice, this list of conditions, and the following disclaimer, 124 * without modification. 125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer 126 * substantially similar to the "NO WARRANTY" disclaimer below 127 * ("Disclaimer") and any redistribution must be conditioned upon 128 * including a substantially similar Disclaimer requirement for further 129 * binary redistribution. 130 * 3. Neither the names of the above-listed copyright holders nor the names 131 * of any contributors may be used to endorse or promote products derived 132 * from this software without specific prior written permission. 133 * 134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 145 * 146 * Alternatively, you may choose to be licensed under the terms of the 147 * GNU General Public License ("GPL") version 2 as published by the Free 148 * Software Foundation. 149 * 150 *****************************************************************************/ 151 152 #include "acpi.h" 153 #include "accommon.h" 154 #include "acinterp.h" 155 #include "amlcode.h" 156 157 158 #define _COMPONENT ACPI_EXECUTER 159 ACPI_MODULE_NAME ("exconvrt") 160 161 /* Local prototypes */ 162 163 static UINT32 164 AcpiExConvertToAscii ( 165 UINT64 Integer, 166 UINT16 Base, 167 UINT8 *String, 168 UINT8 MaxLength); 169 170 171 /******************************************************************************* 172 * 173 * FUNCTION: AcpiExConvertToInteger 174 * 175 * PARAMETERS: ObjDesc - Object to be converted. Must be an 176 * Integer, Buffer, or String 177 * ResultDesc - Where the new Integer object is returned 178 * ImplicitConversion - Used for string conversion 179 * 180 * RETURN: Status 181 * 182 * DESCRIPTION: Convert an ACPI Object to an integer. 183 * 184 ******************************************************************************/ 185 186 ACPI_STATUS 187 AcpiExConvertToInteger ( 188 ACPI_OPERAND_OBJECT *ObjDesc, 189 ACPI_OPERAND_OBJECT **ResultDesc, 190 UINT32 ImplicitConversion) 191 { 192 ACPI_OPERAND_OBJECT *ReturnDesc; 193 UINT8 *Pointer; 194 UINT64 Result; 195 UINT32 i; 196 UINT32 Count; 197 198 199 ACPI_FUNCTION_TRACE_PTR (ExConvertToInteger, ObjDesc); 200 201 202 switch (ObjDesc->Common.Type) 203 { 204 case ACPI_TYPE_INTEGER: 205 206 /* No conversion necessary */ 207 208 *ResultDesc = ObjDesc; 209 return_ACPI_STATUS (AE_OK); 210 211 case ACPI_TYPE_BUFFER: 212 case ACPI_TYPE_STRING: 213 214 /* Note: Takes advantage of common buffer/string fields */ 215 216 Pointer = ObjDesc->Buffer.Pointer; 217 Count = ObjDesc->Buffer.Length; 218 break; 219 220 default: 221 222 return_ACPI_STATUS (AE_TYPE); 223 } 224 225 /* 226 * Convert the buffer/string to an integer. Note that both buffers and 227 * strings are treated as raw data - we don't convert ascii to hex for 228 * strings. 229 * 230 * There are two terminating conditions for the loop: 231 * 1) The size of an integer has been reached, or 232 * 2) The end of the buffer or string has been reached 233 */ 234 Result = 0; 235 236 /* String conversion is different than Buffer conversion */ 237 238 switch (ObjDesc->Common.Type) 239 { 240 case ACPI_TYPE_STRING: 241 /* 242 * Convert string to an integer - for most cases, the string must be 243 * hexadecimal as per the ACPI specification. The only exception (as 244 * of ACPI 3.0) is that the ToInteger() operator allows both decimal 245 * and hexadecimal strings (hex prefixed with "0x"). 246 * 247 * Explicit conversion is used only by ToInteger. 248 * All other string-to-integer conversions are implicit conversions. 249 */ 250 if (ImplicitConversion) 251 { 252 Result = AcpiUtImplicitStrtoul64 (ACPI_CAST_PTR (char, Pointer)); 253 } 254 else 255 { 256 Result = AcpiUtExplicitStrtoul64 (ACPI_CAST_PTR (char, Pointer)); 257 } 258 break; 259 260 case ACPI_TYPE_BUFFER: 261 262 /* Check for zero-length buffer */ 263 264 if (!Count) 265 { 266 return_ACPI_STATUS (AE_AML_BUFFER_LIMIT); 267 } 268 269 /* Transfer no more than an integer's worth of data */ 270 271 if (Count > AcpiGbl_IntegerByteWidth) 272 { 273 Count = AcpiGbl_IntegerByteWidth; 274 } 275 276 /* 277 * Convert buffer to an integer - we simply grab enough raw data 278 * from the buffer to fill an integer 279 */ 280 for (i = 0; i < Count; i++) 281 { 282 /* 283 * Get next byte and shift it into the Result. 284 * Little endian is used, meaning that the first byte of the buffer 285 * is the LSB of the integer 286 */ 287 Result |= (((UINT64) Pointer[i]) << (i * 8)); 288 } 289 break; 290 291 default: 292 293 /* No other types can get here */ 294 295 break; 296 } 297 298 /* Create a new integer */ 299 300 ReturnDesc = AcpiUtCreateIntegerObject (Result); 301 if (!ReturnDesc) 302 { 303 return_ACPI_STATUS (AE_NO_MEMORY); 304 } 305 306 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n", 307 ACPI_FORMAT_UINT64 (Result))); 308 309 /* Save the Result */ 310 311 (void) AcpiExTruncateFor32bitTable (ReturnDesc); 312 *ResultDesc = ReturnDesc; 313 return_ACPI_STATUS (AE_OK); 314 } 315 316 317 /******************************************************************************* 318 * 319 * FUNCTION: AcpiExConvertToBuffer 320 * 321 * PARAMETERS: ObjDesc - Object to be converted. Must be an 322 * Integer, Buffer, or String 323 * ResultDesc - Where the new buffer object is returned 324 * 325 * RETURN: Status 326 * 327 * DESCRIPTION: Convert an ACPI Object to a Buffer 328 * 329 ******************************************************************************/ 330 331 ACPI_STATUS 332 AcpiExConvertToBuffer ( 333 ACPI_OPERAND_OBJECT *ObjDesc, 334 ACPI_OPERAND_OBJECT **ResultDesc) 335 { 336 ACPI_OPERAND_OBJECT *ReturnDesc; 337 UINT8 *NewBuf; 338 339 340 ACPI_FUNCTION_TRACE_PTR (ExConvertToBuffer, ObjDesc); 341 342 343 switch (ObjDesc->Common.Type) 344 { 345 case ACPI_TYPE_BUFFER: 346 347 /* No conversion necessary */ 348 349 *ResultDesc = ObjDesc; 350 return_ACPI_STATUS (AE_OK); 351 352 353 case ACPI_TYPE_INTEGER: 354 /* 355 * Create a new Buffer object. 356 * Need enough space for one integer 357 */ 358 ReturnDesc = AcpiUtCreateBufferObject (AcpiGbl_IntegerByteWidth); 359 if (!ReturnDesc) 360 { 361 return_ACPI_STATUS (AE_NO_MEMORY); 362 } 363 364 /* Copy the integer to the buffer, LSB first */ 365 366 NewBuf = ReturnDesc->Buffer.Pointer; 367 memcpy (NewBuf, &ObjDesc->Integer.Value, AcpiGbl_IntegerByteWidth); 368 break; 369 370 case ACPI_TYPE_STRING: 371 /* 372 * Create a new Buffer object 373 * Size will be the string length 374 * 375 * NOTE: Add one to the string length to include the null terminator. 376 * The ACPI spec is unclear on this subject, but there is existing 377 * ASL/AML code that depends on the null being transferred to the new 378 * buffer. 379 */ 380 ReturnDesc = AcpiUtCreateBufferObject ((ACPI_SIZE) 381 ObjDesc->String.Length + 1); 382 if (!ReturnDesc) 383 { 384 return_ACPI_STATUS (AE_NO_MEMORY); 385 } 386 387 /* Copy the string to the buffer */ 388 389 NewBuf = ReturnDesc->Buffer.Pointer; 390 strncpy ((char *) NewBuf, (char *) ObjDesc->String.Pointer, 391 ObjDesc->String.Length); 392 break; 393 394 default: 395 396 return_ACPI_STATUS (AE_TYPE); 397 } 398 399 /* Mark buffer initialized */ 400 401 ReturnDesc->Common.Flags |= AOPOBJ_DATA_VALID; 402 *ResultDesc = ReturnDesc; 403 return_ACPI_STATUS (AE_OK); 404 } 405 406 407 /******************************************************************************* 408 * 409 * FUNCTION: AcpiExConvertToAscii 410 * 411 * PARAMETERS: Integer - Value to be converted 412 * Base - ACPI_STRING_DECIMAL or ACPI_STRING_HEX 413 * String - Where the string is returned 414 * DataWidth - Size of data item to be converted, in bytes 415 * 416 * RETURN: Actual string length 417 * 418 * DESCRIPTION: Convert an ACPI Integer to a hex or decimal string 419 * 420 ******************************************************************************/ 421 422 static UINT32 423 AcpiExConvertToAscii ( 424 UINT64 Integer, 425 UINT16 Base, 426 UINT8 *String, 427 UINT8 DataWidth) 428 { 429 UINT64 Digit; 430 UINT32 i; 431 UINT32 j; 432 UINT32 k = 0; 433 UINT32 HexLength; 434 UINT32 DecimalLength; 435 UINT32 Remainder; 436 BOOLEAN SupressZeros; 437 438 439 ACPI_FUNCTION_ENTRY (); 440 441 442 switch (Base) 443 { 444 case 10: 445 446 /* Setup max length for the decimal number */ 447 448 switch (DataWidth) 449 { 450 case 1: 451 452 DecimalLength = ACPI_MAX8_DECIMAL_DIGITS; 453 break; 454 455 case 4: 456 457 DecimalLength = ACPI_MAX32_DECIMAL_DIGITS; 458 break; 459 460 case 8: 461 default: 462 463 DecimalLength = ACPI_MAX64_DECIMAL_DIGITS; 464 break; 465 } 466 467 SupressZeros = TRUE; /* No leading zeros */ 468 Remainder = 0; 469 470 for (i = DecimalLength; i > 0; i--) 471 { 472 /* Divide by nth factor of 10 */ 473 474 Digit = Integer; 475 for (j = 0; j < i; j++) 476 { 477 (void) AcpiUtShortDivide (Digit, 10, &Digit, &Remainder); 478 } 479 480 /* Handle leading zeros */ 481 482 if (Remainder != 0) 483 { 484 SupressZeros = FALSE; 485 } 486 487 if (!SupressZeros) 488 { 489 String[k] = (UINT8) (ACPI_ASCII_ZERO + Remainder); 490 k++; 491 } 492 } 493 break; 494 495 case 16: 496 497 /* HexLength: 2 ascii hex chars per data byte */ 498 499 HexLength = ACPI_MUL_2 (DataWidth); 500 for (i = 0, j = (HexLength-1); i < HexLength; i++, j--) 501 { 502 /* Get one hex digit, most significant digits first */ 503 504 String[k] = (UINT8) 505 AcpiUtHexToAsciiChar (Integer, ACPI_MUL_4 (j)); 506 k++; 507 } 508 break; 509 510 default: 511 return (0); 512 } 513 514 /* 515 * Since leading zeros are suppressed, we must check for the case where 516 * the integer equals 0 517 * 518 * Finally, null terminate the string and return the length 519 */ 520 if (!k) 521 { 522 String [0] = ACPI_ASCII_ZERO; 523 k = 1; 524 } 525 526 String [k] = 0; 527 return ((UINT32) k); 528 } 529 530 531 /******************************************************************************* 532 * 533 * FUNCTION: AcpiExConvertToString 534 * 535 * PARAMETERS: ObjDesc - Object to be converted. Must be an 536 * Integer, Buffer, or String 537 * ResultDesc - Where the string object is returned 538 * Type - String flags (base and conversion type) 539 * 540 * RETURN: Status 541 * 542 * DESCRIPTION: Convert an ACPI Object to a string 543 * 544 ******************************************************************************/ 545 546 ACPI_STATUS 547 AcpiExConvertToString ( 548 ACPI_OPERAND_OBJECT *ObjDesc, 549 ACPI_OPERAND_OBJECT **ResultDesc, 550 UINT32 Type) 551 { 552 ACPI_OPERAND_OBJECT *ReturnDesc; 553 UINT8 *NewBuf; 554 UINT32 i; 555 UINT32 StringLength = 0; 556 UINT16 Base = 16; 557 UINT8 Separator = ','; 558 559 560 ACPI_FUNCTION_TRACE_PTR (ExConvertToString, ObjDesc); 561 562 563 switch (ObjDesc->Common.Type) 564 { 565 case ACPI_TYPE_STRING: 566 567 /* No conversion necessary */ 568 569 *ResultDesc = ObjDesc; 570 return_ACPI_STATUS (AE_OK); 571 572 case ACPI_TYPE_INTEGER: 573 574 switch (Type) 575 { 576 case ACPI_EXPLICIT_CONVERT_DECIMAL: 577 578 /* Make room for maximum decimal number */ 579 580 StringLength = ACPI_MAX_DECIMAL_DIGITS; 581 Base = 10; 582 break; 583 584 default: 585 586 /* Two hex string characters for each integer byte */ 587 588 StringLength = ACPI_MUL_2 (AcpiGbl_IntegerByteWidth); 589 break; 590 } 591 592 /* 593 * Create a new String 594 * Need enough space for one ASCII integer (plus null terminator) 595 */ 596 ReturnDesc = AcpiUtCreateStringObject ((ACPI_SIZE) StringLength); 597 if (!ReturnDesc) 598 { 599 return_ACPI_STATUS (AE_NO_MEMORY); 600 } 601 602 NewBuf = ReturnDesc->Buffer.Pointer; 603 604 /* Convert integer to string */ 605 606 StringLength = AcpiExConvertToAscii ( 607 ObjDesc->Integer.Value, Base, NewBuf, AcpiGbl_IntegerByteWidth); 608 609 /* Null terminate at the correct place */ 610 611 ReturnDesc->String.Length = StringLength; 612 NewBuf [StringLength] = 0; 613 break; 614 615 case ACPI_TYPE_BUFFER: 616 617 /* Setup string length, base, and separator */ 618 619 switch (Type) 620 { 621 case ACPI_EXPLICIT_CONVERT_DECIMAL: /* Used by ToDecimalString */ 622 /* 623 * From ACPI: "If Data is a buffer, it is converted to a string of 624 * decimal values separated by commas." 625 */ 626 Base = 10; 627 628 /* 629 * Calculate the final string length. Individual string values 630 * are variable length (include separator for each) 631 */ 632 for (i = 0; i < ObjDesc->Buffer.Length; i++) 633 { 634 if (ObjDesc->Buffer.Pointer[i] >= 100) 635 { 636 StringLength += 4; 637 } 638 else if (ObjDesc->Buffer.Pointer[i] >= 10) 639 { 640 StringLength += 3; 641 } 642 else 643 { 644 StringLength += 2; 645 } 646 } 647 break; 648 649 case ACPI_IMPLICIT_CONVERT_HEX: 650 /* 651 * From the ACPI spec: 652 *"The entire contents of the buffer are converted to a string of 653 * two-character hexadecimal numbers, each separated by a space." 654 */ 655 Separator = ' '; 656 StringLength = (ObjDesc->Buffer.Length * 3); 657 break; 658 659 case ACPI_EXPLICIT_CONVERT_HEX: /* Used by ToHexString */ 660 /* 661 * From ACPI: "If Data is a buffer, it is converted to a string of 662 * hexadecimal values separated by commas." 663 */ 664 StringLength = (ObjDesc->Buffer.Length * 3); 665 break; 666 667 default: 668 return_ACPI_STATUS (AE_BAD_PARAMETER); 669 } 670 671 /* 672 * Create a new string object and string buffer 673 * (-1 because of extra separator included in StringLength from above) 674 * Allow creation of zero-length strings from zero-length buffers. 675 */ 676 if (StringLength) 677 { 678 StringLength--; 679 } 680 681 ReturnDesc = AcpiUtCreateStringObject ((ACPI_SIZE) StringLength); 682 if (!ReturnDesc) 683 { 684 return_ACPI_STATUS (AE_NO_MEMORY); 685 } 686 687 NewBuf = ReturnDesc->Buffer.Pointer; 688 689 /* 690 * Convert buffer bytes to hex or decimal values 691 * (separated by commas or spaces) 692 */ 693 for (i = 0; i < ObjDesc->Buffer.Length; i++) 694 { 695 NewBuf += AcpiExConvertToAscii ( 696 (UINT64) ObjDesc->Buffer.Pointer[i], Base, NewBuf, 1); 697 *NewBuf++ = Separator; /* each separated by a comma or space */ 698 } 699 700 /* 701 * Null terminate the string 702 * (overwrites final comma/space from above) 703 */ 704 if (ObjDesc->Buffer.Length) 705 { 706 NewBuf--; 707 } 708 *NewBuf = 0; 709 break; 710 711 default: 712 713 return_ACPI_STATUS (AE_TYPE); 714 } 715 716 *ResultDesc = ReturnDesc; 717 return_ACPI_STATUS (AE_OK); 718 } 719 720 721 /******************************************************************************* 722 * 723 * FUNCTION: AcpiExConvertToTargetType 724 * 725 * PARAMETERS: DestinationType - Current type of the destination 726 * SourceDesc - Source object to be converted. 727 * ResultDesc - Where the converted object is returned 728 * WalkState - Current method state 729 * 730 * RETURN: Status 731 * 732 * DESCRIPTION: Implements "implicit conversion" rules for storing an object. 733 * 734 ******************************************************************************/ 735 736 ACPI_STATUS 737 AcpiExConvertToTargetType ( 738 ACPI_OBJECT_TYPE DestinationType, 739 ACPI_OPERAND_OBJECT *SourceDesc, 740 ACPI_OPERAND_OBJECT **ResultDesc, 741 ACPI_WALK_STATE *WalkState) 742 { 743 ACPI_STATUS Status = AE_OK; 744 745 746 ACPI_FUNCTION_TRACE (ExConvertToTargetType); 747 748 749 /* Default behavior */ 750 751 *ResultDesc = SourceDesc; 752 753 /* 754 * If required by the target, 755 * perform implicit conversion on the source before we store it. 756 */ 757 switch (GET_CURRENT_ARG_TYPE (WalkState->OpInfo->RuntimeArgs)) 758 { 759 case ARGI_SIMPLE_TARGET: 760 case ARGI_FIXED_TARGET: 761 case ARGI_INTEGER_REF: /* Handles Increment, Decrement cases */ 762 763 switch (DestinationType) 764 { 765 case ACPI_TYPE_LOCAL_REGION_FIELD: 766 /* 767 * Named field can always handle conversions 768 */ 769 break; 770 771 default: 772 773 /* No conversion allowed for these types */ 774 775 if (DestinationType != SourceDesc->Common.Type) 776 { 777 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, 778 "Explicit operator, will store (%s) over existing type (%s)\n", 779 AcpiUtGetObjectTypeName (SourceDesc), 780 AcpiUtGetTypeName (DestinationType))); 781 Status = AE_TYPE; 782 } 783 } 784 break; 785 786 case ARGI_TARGETREF: 787 case ARGI_STORE_TARGET: 788 789 switch (DestinationType) 790 { 791 case ACPI_TYPE_INTEGER: 792 case ACPI_TYPE_BUFFER_FIELD: 793 case ACPI_TYPE_LOCAL_BANK_FIELD: 794 case ACPI_TYPE_LOCAL_INDEX_FIELD: 795 /* 796 * These types require an Integer operand. We can convert 797 * a Buffer or a String to an Integer if necessary. 798 */ 799 Status = AcpiExConvertToInteger (SourceDesc, ResultDesc, 800 ACPI_IMPLICIT_CONVERSION); 801 break; 802 803 case ACPI_TYPE_STRING: 804 /* 805 * The operand must be a String. We can convert an 806 * Integer or Buffer if necessary 807 */ 808 Status = AcpiExConvertToString (SourceDesc, ResultDesc, 809 ACPI_IMPLICIT_CONVERT_HEX); 810 break; 811 812 case ACPI_TYPE_BUFFER: 813 /* 814 * The operand must be a Buffer. We can convert an 815 * Integer or String if necessary 816 */ 817 Status = AcpiExConvertToBuffer (SourceDesc, ResultDesc); 818 break; 819 820 default: 821 822 ACPI_ERROR ((AE_INFO, 823 "Bad destination type during conversion: 0x%X", 824 DestinationType)); 825 Status = AE_AML_INTERNAL; 826 break; 827 } 828 break; 829 830 case ARGI_REFERENCE: 831 /* 832 * CreateXxxxField cases - we are storing the field object into the name 833 */ 834 break; 835 836 default: 837 838 ACPI_ERROR ((AE_INFO, 839 "Unknown Target type ID 0x%X AmlOpcode 0x%X DestType %s", 840 GET_CURRENT_ARG_TYPE (WalkState->OpInfo->RuntimeArgs), 841 WalkState->Opcode, AcpiUtGetTypeName (DestinationType))); 842 Status = AE_AML_INTERNAL; 843 } 844 845 /* 846 * Source-to-Target conversion semantics: 847 * 848 * If conversion to the target type cannot be performed, then simply 849 * overwrite the target with the new object and type. 850 */ 851 if (Status == AE_TYPE) 852 { 853 Status = AE_OK; 854 } 855 856 return_ACPI_STATUS (Status); 857 } 858