xref: /haiku/src/add-ons/kernel/bus_managers/acpi/acpica/components/executer/exconvrt.c (revision 39d6c466d8217dcb3004074f29c27c60f0fa1ac1)
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 - 2015, 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 #include "acpi.h"
117 #include "accommon.h"
118 #include "acinterp.h"
119 #include "amlcode.h"
120 
121 
122 #define _COMPONENT          ACPI_EXECUTER
123         ACPI_MODULE_NAME    ("exconvrt")
124 
125 /* Local prototypes */
126 
127 static UINT32
128 AcpiExConvertToAscii (
129     UINT64                  Integer,
130     UINT16                  Base,
131     UINT8                   *String,
132     UINT8                   MaxLength);
133 
134 
135 /*******************************************************************************
136  *
137  * FUNCTION:    AcpiExConvertToInteger
138  *
139  * PARAMETERS:  ObjDesc         - Object to be converted. Must be an
140  *                                Integer, Buffer, or String
141  *              ResultDesc      - Where the new Integer object is returned
142  *              Flags           - Used for string conversion
143  *
144  * RETURN:      Status
145  *
146  * DESCRIPTION: Convert an ACPI Object to an integer.
147  *
148  ******************************************************************************/
149 
150 ACPI_STATUS
151 AcpiExConvertToInteger (
152     ACPI_OPERAND_OBJECT     *ObjDesc,
153     ACPI_OPERAND_OBJECT     **ResultDesc,
154     UINT32                  Flags)
155 {
156     ACPI_OPERAND_OBJECT     *ReturnDesc;
157     UINT8                   *Pointer;
158     UINT64                  Result;
159     UINT32                  i;
160     UINT32                  Count;
161     ACPI_STATUS             Status;
162 
163 
164     ACPI_FUNCTION_TRACE_PTR (ExConvertToInteger, ObjDesc);
165 
166 
167     switch (ObjDesc->Common.Type)
168     {
169     case ACPI_TYPE_INTEGER:
170 
171         /* No conversion necessary */
172 
173         *ResultDesc = ObjDesc;
174         return_ACPI_STATUS (AE_OK);
175 
176     case ACPI_TYPE_BUFFER:
177     case ACPI_TYPE_STRING:
178 
179         /* Note: Takes advantage of common buffer/string fields */
180 
181         Pointer = ObjDesc->Buffer.Pointer;
182         Count   = ObjDesc->Buffer.Length;
183         break;
184 
185     default:
186 
187         return_ACPI_STATUS (AE_TYPE);
188     }
189 
190     /*
191      * Convert the buffer/string to an integer. Note that both buffers and
192      * strings are treated as raw data - we don't convert ascii to hex for
193      * strings.
194      *
195      * There are two terminating conditions for the loop:
196      * 1) The size of an integer has been reached, or
197      * 2) The end of the buffer or string has been reached
198      */
199     Result = 0;
200 
201     /* String conversion is different than Buffer conversion */
202 
203     switch (ObjDesc->Common.Type)
204     {
205     case ACPI_TYPE_STRING:
206         /*
207          * Convert string to an integer - for most cases, the string must be
208          * hexadecimal as per the ACPI specification. The only exception (as
209          * of ACPI 3.0) is that the ToInteger() operator allows both decimal
210          * and hexadecimal strings (hex prefixed with "0x").
211          */
212         Status = AcpiUtStrtoul64 ((char *) Pointer, Flags, &Result);
213         if (ACPI_FAILURE (Status))
214         {
215             return_ACPI_STATUS (Status);
216         }
217         break;
218 
219     case ACPI_TYPE_BUFFER:
220 
221         /* Check for zero-length buffer */
222 
223         if (!Count)
224         {
225             return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
226         }
227 
228         /* Transfer no more than an integer's worth of data */
229 
230         if (Count > AcpiGbl_IntegerByteWidth)
231         {
232             Count = AcpiGbl_IntegerByteWidth;
233         }
234 
235         /*
236          * Convert buffer to an integer - we simply grab enough raw data
237          * from the buffer to fill an integer
238          */
239         for (i = 0; i < Count; i++)
240         {
241             /*
242              * Get next byte and shift it into the Result.
243              * Little endian is used, meaning that the first byte of the buffer
244              * is the LSB of the integer
245              */
246             Result |= (((UINT64) Pointer[i]) << (i * 8));
247         }
248         break;
249 
250     default:
251 
252         /* No other types can get here */
253 
254         break;
255     }
256 
257     /* Create a new integer */
258 
259     ReturnDesc = AcpiUtCreateIntegerObject (Result);
260     if (!ReturnDesc)
261     {
262         return_ACPI_STATUS (AE_NO_MEMORY);
263     }
264 
265     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
266         ACPI_FORMAT_UINT64 (Result)));
267 
268     /* Save the Result */
269 
270     (void) AcpiExTruncateFor32bitTable (ReturnDesc);
271     *ResultDesc = ReturnDesc;
272     return_ACPI_STATUS (AE_OK);
273 }
274 
275 
276 /*******************************************************************************
277  *
278  * FUNCTION:    AcpiExConvertToBuffer
279  *
280  * PARAMETERS:  ObjDesc         - Object to be converted. Must be an
281  *                                Integer, Buffer, or String
282  *              ResultDesc      - Where the new buffer object is returned
283  *
284  * RETURN:      Status
285  *
286  * DESCRIPTION: Convert an ACPI Object to a Buffer
287  *
288  ******************************************************************************/
289 
290 ACPI_STATUS
291 AcpiExConvertToBuffer (
292     ACPI_OPERAND_OBJECT     *ObjDesc,
293     ACPI_OPERAND_OBJECT     **ResultDesc)
294 {
295     ACPI_OPERAND_OBJECT     *ReturnDesc;
296     UINT8                   *NewBuf;
297 
298 
299     ACPI_FUNCTION_TRACE_PTR (ExConvertToBuffer, ObjDesc);
300 
301 
302     switch (ObjDesc->Common.Type)
303     {
304     case ACPI_TYPE_BUFFER:
305 
306         /* No conversion necessary */
307 
308         *ResultDesc = ObjDesc;
309         return_ACPI_STATUS (AE_OK);
310 
311 
312     case ACPI_TYPE_INTEGER:
313         /*
314          * Create a new Buffer object.
315          * Need enough space for one integer
316          */
317         ReturnDesc = AcpiUtCreateBufferObject (AcpiGbl_IntegerByteWidth);
318         if (!ReturnDesc)
319         {
320             return_ACPI_STATUS (AE_NO_MEMORY);
321         }
322 
323         /* Copy the integer to the buffer, LSB first */
324 
325         NewBuf = ReturnDesc->Buffer.Pointer;
326         memcpy (NewBuf,
327                         &ObjDesc->Integer.Value,
328                         AcpiGbl_IntegerByteWidth);
329         break;
330 
331     case ACPI_TYPE_STRING:
332         /*
333          * Create a new Buffer object
334          * Size will be the string length
335          *
336          * NOTE: Add one to the string length to include the null terminator.
337          * The ACPI spec is unclear on this subject, but there is existing
338          * ASL/AML code that depends on the null being transferred to the new
339          * buffer.
340          */
341         ReturnDesc = AcpiUtCreateBufferObject (
342                         (ACPI_SIZE) ObjDesc->String.Length + 1);
343         if (!ReturnDesc)
344         {
345             return_ACPI_STATUS (AE_NO_MEMORY);
346         }
347 
348         /* Copy the string to the buffer */
349 
350         NewBuf = ReturnDesc->Buffer.Pointer;
351         strncpy ((char *) NewBuf, (char *) ObjDesc->String.Pointer,
352             ObjDesc->String.Length);
353         break;
354 
355     default:
356 
357         return_ACPI_STATUS (AE_TYPE);
358     }
359 
360     /* Mark buffer initialized */
361 
362     ReturnDesc->Common.Flags |= AOPOBJ_DATA_VALID;
363     *ResultDesc = ReturnDesc;
364     return_ACPI_STATUS (AE_OK);
365 }
366 
367 
368 /*******************************************************************************
369  *
370  * FUNCTION:    AcpiExConvertToAscii
371  *
372  * PARAMETERS:  Integer         - Value to be converted
373  *              Base            - ACPI_STRING_DECIMAL or ACPI_STRING_HEX
374  *              String          - Where the string is returned
375  *              DataWidth       - Size of data item to be converted, in bytes
376  *
377  * RETURN:      Actual string length
378  *
379  * DESCRIPTION: Convert an ACPI Integer to a hex or decimal string
380  *
381  ******************************************************************************/
382 
383 static UINT32
384 AcpiExConvertToAscii (
385     UINT64                  Integer,
386     UINT16                  Base,
387     UINT8                   *String,
388     UINT8                   DataWidth)
389 {
390     UINT64                  Digit;
391     UINT32                  i;
392     UINT32                  j;
393     UINT32                  k = 0;
394     UINT32                  HexLength;
395     UINT32                  DecimalLength;
396     UINT32                  Remainder;
397     BOOLEAN                 SupressZeros;
398 
399 
400     ACPI_FUNCTION_ENTRY ();
401 
402 
403     switch (Base)
404     {
405     case 10:
406 
407         /* Setup max length for the decimal number */
408 
409         switch (DataWidth)
410         {
411         case 1:
412 
413             DecimalLength = ACPI_MAX8_DECIMAL_DIGITS;
414             break;
415 
416         case 4:
417 
418             DecimalLength = ACPI_MAX32_DECIMAL_DIGITS;
419             break;
420 
421         case 8:
422         default:
423 
424             DecimalLength = ACPI_MAX64_DECIMAL_DIGITS;
425             break;
426         }
427 
428         SupressZeros = TRUE;     /* No leading zeros */
429         Remainder = 0;
430 
431         for (i = DecimalLength; i > 0; i--)
432         {
433             /* Divide by nth factor of 10 */
434 
435             Digit = Integer;
436             for (j = 0; j < i; j++)
437             {
438                 (void) AcpiUtShortDivide (Digit, 10, &Digit, &Remainder);
439             }
440 
441             /* Handle leading zeros */
442 
443             if (Remainder != 0)
444             {
445                 SupressZeros = FALSE;
446             }
447 
448             if (!SupressZeros)
449             {
450                 String[k] = (UINT8) (ACPI_ASCII_ZERO + Remainder);
451                 k++;
452             }
453         }
454         break;
455 
456     case 16:
457 
458         /* HexLength: 2 ascii hex chars per data byte */
459 
460         HexLength = ACPI_MUL_2 (DataWidth);
461         for (i = 0, j = (HexLength-1); i < HexLength; i++, j--)
462         {
463             /* Get one hex digit, most significant digits first */
464 
465             String[k] = (UINT8) AcpiUtHexToAsciiChar (Integer, ACPI_MUL_4 (j));
466             k++;
467         }
468         break;
469 
470     default:
471         return (0);
472     }
473 
474     /*
475      * Since leading zeros are suppressed, we must check for the case where
476      * the integer equals 0
477      *
478      * Finally, null terminate the string and return the length
479      */
480     if (!k)
481     {
482         String [0] = ACPI_ASCII_ZERO;
483         k = 1;
484     }
485 
486     String [k] = 0;
487     return ((UINT32) k);
488 }
489 
490 
491 /*******************************************************************************
492  *
493  * FUNCTION:    AcpiExConvertToString
494  *
495  * PARAMETERS:  ObjDesc         - Object to be converted. Must be an
496  *                                Integer, Buffer, or String
497  *              ResultDesc      - Where the string object is returned
498  *              Type            - String flags (base and conversion type)
499  *
500  * RETURN:      Status
501  *
502  * DESCRIPTION: Convert an ACPI Object to a string
503  *
504  ******************************************************************************/
505 
506 ACPI_STATUS
507 AcpiExConvertToString (
508     ACPI_OPERAND_OBJECT     *ObjDesc,
509     ACPI_OPERAND_OBJECT     **ResultDesc,
510     UINT32                  Type)
511 {
512     ACPI_OPERAND_OBJECT     *ReturnDesc;
513     UINT8                   *NewBuf;
514     UINT32                  i;
515     UINT32                  StringLength = 0;
516     UINT16                  Base = 16;
517     UINT8                   Separator = ',';
518 
519 
520     ACPI_FUNCTION_TRACE_PTR (ExConvertToString, ObjDesc);
521 
522 
523     switch (ObjDesc->Common.Type)
524     {
525     case ACPI_TYPE_STRING:
526 
527         /* No conversion necessary */
528 
529         *ResultDesc = ObjDesc;
530         return_ACPI_STATUS (AE_OK);
531 
532     case ACPI_TYPE_INTEGER:
533 
534         switch (Type)
535         {
536         case ACPI_EXPLICIT_CONVERT_DECIMAL:
537 
538             /* Make room for maximum decimal number */
539 
540             StringLength = ACPI_MAX_DECIMAL_DIGITS;
541             Base = 10;
542             break;
543 
544         default:
545 
546             /* Two hex string characters for each integer byte */
547 
548             StringLength = ACPI_MUL_2 (AcpiGbl_IntegerByteWidth);
549             break;
550         }
551 
552         /*
553          * Create a new String
554          * Need enough space for one ASCII integer (plus null terminator)
555          */
556         ReturnDesc = AcpiUtCreateStringObject ((ACPI_SIZE) StringLength);
557         if (!ReturnDesc)
558         {
559             return_ACPI_STATUS (AE_NO_MEMORY);
560         }
561 
562         NewBuf = ReturnDesc->Buffer.Pointer;
563 
564         /* Convert integer to string */
565 
566         StringLength = AcpiExConvertToAscii (ObjDesc->Integer.Value, Base,
567                             NewBuf, AcpiGbl_IntegerByteWidth);
568 
569         /* Null terminate at the correct place */
570 
571         ReturnDesc->String.Length = StringLength;
572         NewBuf [StringLength] = 0;
573         break;
574 
575     case ACPI_TYPE_BUFFER:
576 
577         /* Setup string length, base, and separator */
578 
579         switch (Type)
580         {
581         case ACPI_EXPLICIT_CONVERT_DECIMAL: /* Used by ToDecimalString */
582             /*
583              * From ACPI: "If Data is a buffer, it is converted to a string of
584              * decimal values separated by commas."
585              */
586             Base = 10;
587 
588             /*
589              * Calculate the final string length. Individual string values
590              * are variable length (include separator for each)
591              */
592             for (i = 0; i < ObjDesc->Buffer.Length; i++)
593             {
594                 if (ObjDesc->Buffer.Pointer[i] >= 100)
595                 {
596                     StringLength += 4;
597                 }
598                 else if (ObjDesc->Buffer.Pointer[i] >= 10)
599                 {
600                     StringLength += 3;
601                 }
602                 else
603                 {
604                     StringLength += 2;
605                 }
606             }
607             break;
608 
609         case ACPI_IMPLICIT_CONVERT_HEX:
610             /*
611              * From the ACPI spec:
612              *"The entire contents of the buffer are converted to a string of
613              * two-character hexadecimal numbers, each separated by a space."
614              */
615             Separator = ' ';
616             StringLength = (ObjDesc->Buffer.Length * 3);
617             break;
618 
619         case ACPI_EXPLICIT_CONVERT_HEX:     /* Used by ToHexString */
620             /*
621              * From ACPI: "If Data is a buffer, it is converted to a string of
622              * hexadecimal values separated by commas."
623              */
624             StringLength = (ObjDesc->Buffer.Length * 3);
625             break;
626 
627         default:
628             return_ACPI_STATUS (AE_BAD_PARAMETER);
629         }
630 
631         /*
632          * Create a new string object and string buffer
633          * (-1 because of extra separator included in StringLength from above)
634          * Allow creation of zero-length strings from zero-length buffers.
635          */
636         if (StringLength)
637         {
638             StringLength--;
639         }
640 
641         ReturnDesc = AcpiUtCreateStringObject ((ACPI_SIZE) StringLength);
642         if (!ReturnDesc)
643         {
644             return_ACPI_STATUS (AE_NO_MEMORY);
645         }
646 
647         NewBuf = ReturnDesc->Buffer.Pointer;
648 
649         /*
650          * Convert buffer bytes to hex or decimal values
651          * (separated by commas or spaces)
652          */
653         for (i = 0; i < ObjDesc->Buffer.Length; i++)
654         {
655             NewBuf += AcpiExConvertToAscii (
656                         (UINT64) ObjDesc->Buffer.Pointer[i], Base,
657                         NewBuf, 1);
658             *NewBuf++ = Separator; /* each separated by a comma or space */
659         }
660 
661         /*
662          * Null terminate the string
663          * (overwrites final comma/space from above)
664          */
665         if (ObjDesc->Buffer.Length)
666         {
667             NewBuf--;
668         }
669         *NewBuf = 0;
670         break;
671 
672     default:
673 
674         return_ACPI_STATUS (AE_TYPE);
675     }
676 
677     *ResultDesc = ReturnDesc;
678     return_ACPI_STATUS (AE_OK);
679 }
680 
681 
682 /*******************************************************************************
683  *
684  * FUNCTION:    AcpiExConvertToTargetType
685  *
686  * PARAMETERS:  DestinationType     - Current type of the destination
687  *              SourceDesc          - Source object to be converted.
688  *              ResultDesc          - Where the converted object is returned
689  *              WalkState           - Current method state
690  *
691  * RETURN:      Status
692  *
693  * DESCRIPTION: Implements "implicit conversion" rules for storing an object.
694  *
695  ******************************************************************************/
696 
697 ACPI_STATUS
698 AcpiExConvertToTargetType (
699     ACPI_OBJECT_TYPE        DestinationType,
700     ACPI_OPERAND_OBJECT     *SourceDesc,
701     ACPI_OPERAND_OBJECT     **ResultDesc,
702     ACPI_WALK_STATE         *WalkState)
703 {
704     ACPI_STATUS             Status = AE_OK;
705 
706 
707     ACPI_FUNCTION_TRACE (ExConvertToTargetType);
708 
709 
710     /* Default behavior */
711 
712     *ResultDesc = SourceDesc;
713 
714     /*
715      * If required by the target,
716      * perform implicit conversion on the source before we store it.
717      */
718     switch (GET_CURRENT_ARG_TYPE (WalkState->OpInfo->RuntimeArgs))
719     {
720     case ARGI_SIMPLE_TARGET:
721     case ARGI_FIXED_TARGET:
722     case ARGI_INTEGER_REF:      /* Handles Increment, Decrement cases */
723 
724         switch (DestinationType)
725         {
726         case ACPI_TYPE_LOCAL_REGION_FIELD:
727             /*
728              * Named field can always handle conversions
729              */
730             break;
731 
732         default:
733 
734             /* No conversion allowed for these types */
735 
736             if (DestinationType != SourceDesc->Common.Type)
737             {
738                 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
739                     "Explicit operator, will store (%s) over existing type (%s)\n",
740                     AcpiUtGetObjectTypeName (SourceDesc),
741                     AcpiUtGetTypeName (DestinationType)));
742                 Status = AE_TYPE;
743             }
744         }
745         break;
746 
747     case ARGI_TARGETREF:
748 
749         switch (DestinationType)
750         {
751         case ACPI_TYPE_INTEGER:
752         case ACPI_TYPE_BUFFER_FIELD:
753         case ACPI_TYPE_LOCAL_BANK_FIELD:
754         case ACPI_TYPE_LOCAL_INDEX_FIELD:
755             /*
756              * These types require an Integer operand. We can convert
757              * a Buffer or a String to an Integer if necessary.
758              */
759             Status = AcpiExConvertToInteger (SourceDesc, ResultDesc,
760                         16);
761             break;
762 
763         case ACPI_TYPE_STRING:
764             /*
765              * The operand must be a String. We can convert an
766              * Integer or Buffer if necessary
767              */
768             Status = AcpiExConvertToString (SourceDesc, ResultDesc,
769                         ACPI_IMPLICIT_CONVERT_HEX);
770             break;
771 
772         case ACPI_TYPE_BUFFER:
773             /*
774              * The operand must be a Buffer. We can convert an
775              * Integer or String if necessary
776              */
777             Status = AcpiExConvertToBuffer (SourceDesc, ResultDesc);
778             break;
779 
780         default:
781 
782             ACPI_ERROR ((AE_INFO, "Bad destination type during conversion: 0x%X",
783                 DestinationType));
784             Status = AE_AML_INTERNAL;
785             break;
786         }
787         break;
788 
789     case ARGI_REFERENCE:
790         /*
791          * CreateXxxxField cases - we are storing the field object into the name
792          */
793         break;
794 
795     default:
796 
797         ACPI_ERROR ((AE_INFO,
798             "Unknown Target type ID 0x%X AmlOpcode 0x%X DestType %s",
799             GET_CURRENT_ARG_TYPE (WalkState->OpInfo->RuntimeArgs),
800             WalkState->Opcode, AcpiUtGetTypeName (DestinationType)));
801         Status = AE_AML_INTERNAL;
802     }
803 
804     /*
805      * Source-to-Target conversion semantics:
806      *
807      * If conversion to the target type cannot be performed, then simply
808      * overwrite the target with the new object and type.
809      */
810     if (Status == AE_TYPE)
811     {
812         Status = AE_OK;
813     }
814 
815     return_ACPI_STATUS (Status);
816 }
817