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