xref: /haiku/src/add-ons/kernel/bus_managers/acpi/acpica/components/executer/exconvrt.c (revision a55deaea91d64802ed655d4ffcb41a3519338144)
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 - 2016, 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,
213             AcpiGbl_IntegerByteWidth, &Result);
214         if (ACPI_FAILURE (Status))
215         {
216             return_ACPI_STATUS (Status);
217         }
218         break;
219 
220     case ACPI_TYPE_BUFFER:
221 
222         /* Check for zero-length buffer */
223 
224         if (!Count)
225         {
226             return_ACPI_STATUS (AE_AML_BUFFER_LIMIT);
227         }
228 
229         /* Transfer no more than an integer's worth of data */
230 
231         if (Count > AcpiGbl_IntegerByteWidth)
232         {
233             Count = AcpiGbl_IntegerByteWidth;
234         }
235 
236         /*
237          * Convert buffer to an integer - we simply grab enough raw data
238          * from the buffer to fill an integer
239          */
240         for (i = 0; i < Count; i++)
241         {
242             /*
243              * Get next byte and shift it into the Result.
244              * Little endian is used, meaning that the first byte of the buffer
245              * is the LSB of the integer
246              */
247             Result |= (((UINT64) Pointer[i]) << (i * 8));
248         }
249         break;
250 
251     default:
252 
253         /* No other types can get here */
254 
255         break;
256     }
257 
258     /* Create a new integer */
259 
260     ReturnDesc = AcpiUtCreateIntegerObject (Result);
261     if (!ReturnDesc)
262     {
263         return_ACPI_STATUS (AE_NO_MEMORY);
264     }
265 
266     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Converted value: %8.8X%8.8X\n",
267         ACPI_FORMAT_UINT64 (Result)));
268 
269     /* Save the Result */
270 
271     (void) AcpiExTruncateFor32bitTable (ReturnDesc);
272     *ResultDesc = ReturnDesc;
273     return_ACPI_STATUS (AE_OK);
274 }
275 
276 
277 /*******************************************************************************
278  *
279  * FUNCTION:    AcpiExConvertToBuffer
280  *
281  * PARAMETERS:  ObjDesc         - Object to be converted. Must be an
282  *                                Integer, Buffer, or String
283  *              ResultDesc      - Where the new buffer object is returned
284  *
285  * RETURN:      Status
286  *
287  * DESCRIPTION: Convert an ACPI Object to a Buffer
288  *
289  ******************************************************************************/
290 
291 ACPI_STATUS
292 AcpiExConvertToBuffer (
293     ACPI_OPERAND_OBJECT     *ObjDesc,
294     ACPI_OPERAND_OBJECT     **ResultDesc)
295 {
296     ACPI_OPERAND_OBJECT     *ReturnDesc;
297     UINT8                   *NewBuf;
298 
299 
300     ACPI_FUNCTION_TRACE_PTR (ExConvertToBuffer, ObjDesc);
301 
302 
303     switch (ObjDesc->Common.Type)
304     {
305     case ACPI_TYPE_BUFFER:
306 
307         /* No conversion necessary */
308 
309         *ResultDesc = ObjDesc;
310         return_ACPI_STATUS (AE_OK);
311 
312 
313     case ACPI_TYPE_INTEGER:
314         /*
315          * Create a new Buffer object.
316          * Need enough space for one integer
317          */
318         ReturnDesc = AcpiUtCreateBufferObject (AcpiGbl_IntegerByteWidth);
319         if (!ReturnDesc)
320         {
321             return_ACPI_STATUS (AE_NO_MEMORY);
322         }
323 
324         /* Copy the integer to the buffer, LSB first */
325 
326         NewBuf = ReturnDesc->Buffer.Pointer;
327         memcpy (NewBuf, &ObjDesc->Integer.Value, AcpiGbl_IntegerByteWidth);
328         break;
329 
330     case ACPI_TYPE_STRING:
331         /*
332          * Create a new Buffer object
333          * Size will be the string length
334          *
335          * NOTE: Add one to the string length to include the null terminator.
336          * The ACPI spec is unclear on this subject, but there is existing
337          * ASL/AML code that depends on the null being transferred to the new
338          * buffer.
339          */
340         ReturnDesc = AcpiUtCreateBufferObject ((ACPI_SIZE)
341             ObjDesc->String.Length + 1);
342         if (!ReturnDesc)
343         {
344             return_ACPI_STATUS (AE_NO_MEMORY);
345         }
346 
347         /* Copy the string to the buffer */
348 
349         NewBuf = ReturnDesc->Buffer.Pointer;
350         strncpy ((char *) NewBuf, (char *) ObjDesc->String.Pointer,
351             ObjDesc->String.Length);
352         break;
353 
354     default:
355 
356         return_ACPI_STATUS (AE_TYPE);
357     }
358 
359     /* Mark buffer initialized */
360 
361     ReturnDesc->Common.Flags |= AOPOBJ_DATA_VALID;
362     *ResultDesc = ReturnDesc;
363     return_ACPI_STATUS (AE_OK);
364 }
365 
366 
367 /*******************************************************************************
368  *
369  * FUNCTION:    AcpiExConvertToAscii
370  *
371  * PARAMETERS:  Integer         - Value to be converted
372  *              Base            - ACPI_STRING_DECIMAL or ACPI_STRING_HEX
373  *              String          - Where the string is returned
374  *              DataWidth       - Size of data item to be converted, in bytes
375  *
376  * RETURN:      Actual string length
377  *
378  * DESCRIPTION: Convert an ACPI Integer to a hex or decimal string
379  *
380  ******************************************************************************/
381 
382 static UINT32
383 AcpiExConvertToAscii (
384     UINT64                  Integer,
385     UINT16                  Base,
386     UINT8                   *String,
387     UINT8                   DataWidth)
388 {
389     UINT64                  Digit;
390     UINT32                  i;
391     UINT32                  j;
392     UINT32                  k = 0;
393     UINT32                  HexLength;
394     UINT32                  DecimalLength;
395     UINT32                  Remainder;
396     BOOLEAN                 SupressZeros;
397 
398 
399     ACPI_FUNCTION_ENTRY ();
400 
401 
402     switch (Base)
403     {
404     case 10:
405 
406         /* Setup max length for the decimal number */
407 
408         switch (DataWidth)
409         {
410         case 1:
411 
412             DecimalLength = ACPI_MAX8_DECIMAL_DIGITS;
413             break;
414 
415         case 4:
416 
417             DecimalLength = ACPI_MAX32_DECIMAL_DIGITS;
418             break;
419 
420         case 8:
421         default:
422 
423             DecimalLength = ACPI_MAX64_DECIMAL_DIGITS;
424             break;
425         }
426 
427         SupressZeros = TRUE;     /* No leading zeros */
428         Remainder = 0;
429 
430         for (i = DecimalLength; i > 0; i--)
431         {
432             /* Divide by nth factor of 10 */
433 
434             Digit = Integer;
435             for (j = 0; j < i; j++)
436             {
437                 (void) AcpiUtShortDivide (Digit, 10, &Digit, &Remainder);
438             }
439 
440             /* Handle leading zeros */
441 
442             if (Remainder != 0)
443             {
444                 SupressZeros = FALSE;
445             }
446 
447             if (!SupressZeros)
448             {
449                 String[k] = (UINT8) (ACPI_ASCII_ZERO + Remainder);
450                 k++;
451             }
452         }
453         break;
454 
455     case 16:
456 
457         /* HexLength: 2 ascii hex chars per data byte */
458 
459         HexLength = ACPI_MUL_2 (DataWidth);
460         for (i = 0, j = (HexLength-1); i < HexLength; i++, j--)
461         {
462             /* Get one hex digit, most significant digits first */
463 
464             String[k] = (UINT8)
465                 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 (
567             ObjDesc->Integer.Value, Base, 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, NewBuf, 1);
657             *NewBuf++ = Separator; /* each separated by a comma or space */
658         }
659 
660         /*
661          * Null terminate the string
662          * (overwrites final comma/space from above)
663          */
664         if (ObjDesc->Buffer.Length)
665         {
666             NewBuf--;
667         }
668         *NewBuf = 0;
669         break;
670 
671     default:
672 
673         return_ACPI_STATUS (AE_TYPE);
674     }
675 
676     *ResultDesc = ReturnDesc;
677     return_ACPI_STATUS (AE_OK);
678 }
679 
680 
681 /*******************************************************************************
682  *
683  * FUNCTION:    AcpiExConvertToTargetType
684  *
685  * PARAMETERS:  DestinationType     - Current type of the destination
686  *              SourceDesc          - Source object to be converted.
687  *              ResultDesc          - Where the converted object is returned
688  *              WalkState           - Current method state
689  *
690  * RETURN:      Status
691  *
692  * DESCRIPTION: Implements "implicit conversion" rules for storing an object.
693  *
694  ******************************************************************************/
695 
696 ACPI_STATUS
697 AcpiExConvertToTargetType (
698     ACPI_OBJECT_TYPE        DestinationType,
699     ACPI_OPERAND_OBJECT     *SourceDesc,
700     ACPI_OPERAND_OBJECT     **ResultDesc,
701     ACPI_WALK_STATE         *WalkState)
702 {
703     ACPI_STATUS             Status = AE_OK;
704 
705 
706     ACPI_FUNCTION_TRACE (ExConvertToTargetType);
707 
708 
709     /* Default behavior */
710 
711     *ResultDesc = SourceDesc;
712 
713     /*
714      * If required by the target,
715      * perform implicit conversion on the source before we store it.
716      */
717     switch (GET_CURRENT_ARG_TYPE (WalkState->OpInfo->RuntimeArgs))
718     {
719     case ARGI_SIMPLE_TARGET:
720     case ARGI_FIXED_TARGET:
721     case ARGI_INTEGER_REF:      /* Handles Increment, Decrement cases */
722 
723         switch (DestinationType)
724         {
725         case ACPI_TYPE_LOCAL_REGION_FIELD:
726             /*
727              * Named field can always handle conversions
728              */
729             break;
730 
731         default:
732 
733             /* No conversion allowed for these types */
734 
735             if (DestinationType != SourceDesc->Common.Type)
736             {
737                 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
738                     "Explicit operator, will store (%s) over existing type (%s)\n",
739                     AcpiUtGetObjectTypeName (SourceDesc),
740                     AcpiUtGetTypeName (DestinationType)));
741                 Status = AE_TYPE;
742             }
743         }
744         break;
745 
746     case ARGI_TARGETREF:
747     case ARGI_STORE_TARGET:
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, 16);
760             break;
761 
762         case ACPI_TYPE_STRING:
763             /*
764              * The operand must be a String. We can convert an
765              * Integer or Buffer if necessary
766              */
767             Status = AcpiExConvertToString (SourceDesc, ResultDesc,
768                 ACPI_IMPLICIT_CONVERT_HEX);
769             break;
770 
771         case ACPI_TYPE_BUFFER:
772             /*
773              * The operand must be a Buffer. We can convert an
774              * Integer or String if necessary
775              */
776             Status = AcpiExConvertToBuffer (SourceDesc, ResultDesc);
777             break;
778 
779         default:
780 
781             ACPI_ERROR ((AE_INFO,
782                 "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