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