blob: df2d32096b72363e6a46301b41bdec19ae85c3b5 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: utcopy - Internal to external object translation utilities
4 *
5 *****************************************************************************/
6
7/*
Bob Moore4a90c7e2006-01-13 16:22:00 -05008 * Copyright (C) 2000 - 2006, R. Byron Moore
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
45#include <acpi/amlcode.h>
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047#define _COMPONENT ACPI_UTILITIES
Len Brown4be44fc2005-08-05 00:44:28 -040048ACPI_MODULE_NAME("utcopy")
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Robert Moore44f6c012005-04-18 22:49:35 -040050/* Local prototypes */
Len Brown4be44fc2005-08-05 00:44:28 -040051static acpi_status
52acpi_ut_copy_isimple_to_esimple(union acpi_operand_object *internal_object,
53 union acpi_object *external_object,
54 u8 * data_space, acpi_size * buffer_space_used);
Robert Moore44f6c012005-04-18 22:49:35 -040055
56static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040057acpi_ut_copy_ielement_to_ielement(u8 object_type,
58 union acpi_operand_object *source_object,
59 union acpi_generic_state *state,
60 void *context);
Robert Moore44f6c012005-04-18 22:49:35 -040061
62static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040063acpi_ut_copy_ipackage_to_epackage(union acpi_operand_object *internal_object,
64 u8 * buffer, acpi_size * space_used);
Robert Moore44f6c012005-04-18 22:49:35 -040065
66static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040067acpi_ut_copy_esimple_to_isimple(union acpi_object *user_obj,
68 union acpi_operand_object **return_obj);
Robert Moore44f6c012005-04-18 22:49:35 -040069
70static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040071acpi_ut_copy_simple_object(union acpi_operand_object *source_desc,
72 union acpi_operand_object *dest_desc);
Robert Moore44f6c012005-04-18 22:49:35 -040073
74static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040075acpi_ut_copy_ielement_to_eelement(u8 object_type,
76 union acpi_operand_object *source_object,
77 union acpi_generic_state *state,
78 void *context);
Robert Moore44f6c012005-04-18 22:49:35 -040079
80static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040081acpi_ut_copy_ipackage_to_ipackage(union acpi_operand_object *source_obj,
82 union acpi_operand_object *dest_obj,
83 struct acpi_walk_state *walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070084
85/*******************************************************************************
86 *
87 * FUNCTION: acpi_ut_copy_isimple_to_esimple
88 *
Robert Moore44f6c012005-04-18 22:49:35 -040089 * PARAMETERS: internal_object - Source object to be copied
90 * external_object - Where to return the copied object
91 * data_space - Where object data is returned (such as
92 * buffer and string data)
93 * buffer_space_used - Length of data_space that was used
Linus Torvalds1da177e2005-04-16 15:20:36 -070094 *
95 * RETURN: Status
96 *
Robert Moore44f6c012005-04-18 22:49:35 -040097 * DESCRIPTION: This function is called to copy a simple internal object to
98 * an external object.
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 *
Robert Moore44f6c012005-04-18 22:49:35 -0400100 * The data_space buffer is assumed to have sufficient space for
101 * the object.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 *
103 ******************************************************************************/
104
105static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400106acpi_ut_copy_isimple_to_esimple(union acpi_operand_object *internal_object,
107 union acpi_object *external_object,
108 u8 * data_space, acpi_size * buffer_space_used)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109{
Len Brown4be44fc2005-08-05 00:44:28 -0400110 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111
Len Brown4be44fc2005-08-05 00:44:28 -0400112 ACPI_FUNCTION_TRACE("ut_copy_isimple_to_esimple");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113
114 *buffer_space_used = 0;
115
116 /*
117 * Check for NULL object case (could be an uninitialized
118 * package element)
119 */
120 if (!internal_object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400121 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 }
123
124 /* Always clear the external object */
125
Len Brown4be44fc2005-08-05 00:44:28 -0400126 ACPI_MEMSET(external_object, 0, sizeof(union acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128 /*
129 * In general, the external object will be the same type as
130 * the internal object
131 */
Len Brown4be44fc2005-08-05 00:44:28 -0400132 external_object->type = ACPI_GET_OBJECT_TYPE(internal_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134 /* However, only a limited number of external types are supported */
135
Len Brown4be44fc2005-08-05 00:44:28 -0400136 switch (ACPI_GET_OBJECT_TYPE(internal_object)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 case ACPI_TYPE_STRING:
138
Len Brown4be44fc2005-08-05 00:44:28 -0400139 external_object->string.pointer = (char *)data_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 external_object->string.length = internal_object->string.length;
Len Brown4be44fc2005-08-05 00:44:28 -0400141 *buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD((acpi_size)
142 internal_object->
143 string.
144 length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Len Brown4be44fc2005-08-05 00:44:28 -0400146 ACPI_MEMCPY((void *)data_space,
147 (void *)internal_object->string.pointer,
148 (acpi_size) internal_object->string.length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 break;
150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 case ACPI_TYPE_BUFFER:
152
153 external_object->buffer.pointer = data_space;
154 external_object->buffer.length = internal_object->buffer.length;
Len Brown4be44fc2005-08-05 00:44:28 -0400155 *buffer_space_used =
156 ACPI_ROUND_UP_TO_NATIVE_WORD(internal_object->string.
157 length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Len Brown4be44fc2005-08-05 00:44:28 -0400159 ACPI_MEMCPY((void *)data_space,
160 (void *)internal_object->buffer.pointer,
161 internal_object->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 break;
163
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164 case ACPI_TYPE_INTEGER:
165
166 external_object->integer.value = internal_object->integer.value;
167 break;
168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 case ACPI_TYPE_LOCAL_REFERENCE:
170
171 /*
172 * This is an object reference. Attempt to dereference it.
173 */
174 switch (internal_object->reference.opcode) {
175 case AML_INT_NAMEPATH_OP:
176
177 /* For namepath, return the object handle ("reference") */
178
179 default:
180 /*
181 * Use the object type of "Any" to indicate a reference
182 * to object containing a handle to an ACPI named object.
183 */
184 external_object->type = ACPI_TYPE_ANY;
Len Brown4be44fc2005-08-05 00:44:28 -0400185 external_object->reference.handle =
186 internal_object->reference.node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 break;
188 }
189 break;
190
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 case ACPI_TYPE_PROCESSOR:
192
Len Brown4be44fc2005-08-05 00:44:28 -0400193 external_object->processor.proc_id =
194 internal_object->processor.proc_id;
195 external_object->processor.pblk_address =
196 internal_object->processor.address;
197 external_object->processor.pblk_length =
198 internal_object->processor.length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 break;
200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 case ACPI_TYPE_POWER:
202
203 external_object->power_resource.system_level =
Len Brown4be44fc2005-08-05 00:44:28 -0400204 internal_object->power_resource.system_level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206 external_object->power_resource.resource_order =
Len Brown4be44fc2005-08-05 00:44:28 -0400207 internal_object->power_resource.resource_order;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 break;
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 default:
211 /*
212 * There is no corresponding external object type
213 */
Len Brown4be44fc2005-08-05 00:44:28 -0400214 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 }
216
Len Brown4be44fc2005-08-05 00:44:28 -0400217 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218}
219
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220/*******************************************************************************
221 *
222 * FUNCTION: acpi_ut_copy_ielement_to_eelement
223 *
224 * PARAMETERS: acpi_pkg_callback
225 *
226 * RETURN: Status
227 *
228 * DESCRIPTION: Copy one package element to another package element
229 *
230 ******************************************************************************/
231
Robert Moore44f6c012005-04-18 22:49:35 -0400232static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400233acpi_ut_copy_ielement_to_eelement(u8 object_type,
234 union acpi_operand_object *source_object,
235 union acpi_generic_state *state,
236 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237{
Len Brown4be44fc2005-08-05 00:44:28 -0400238 acpi_status status = AE_OK;
239 struct acpi_pkg_info *info = (struct acpi_pkg_info *)context;
240 acpi_size object_space;
241 u32 this_index;
242 union acpi_object *target_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243
Len Brown4be44fc2005-08-05 00:44:28 -0400244 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245
Len Brown4be44fc2005-08-05 00:44:28 -0400246 this_index = state->pkg.index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 target_object = (union acpi_object *)
Len Brown4be44fc2005-08-05 00:44:28 -0400248 &((union acpi_object *)(state->pkg.dest_object))->package.
249 elements[this_index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250
251 switch (object_type) {
252 case ACPI_COPY_TYPE_SIMPLE:
253
254 /*
255 * This is a simple or null object
256 */
Len Brown4be44fc2005-08-05 00:44:28 -0400257 status = acpi_ut_copy_isimple_to_esimple(source_object,
258 target_object,
259 info->free_space,
260 &object_space);
261 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 return (status);
263 }
264 break;
265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 case ACPI_COPY_TYPE_PACKAGE:
267
268 /*
269 * Build the package object
270 */
Len Brown4be44fc2005-08-05 00:44:28 -0400271 target_object->type = ACPI_TYPE_PACKAGE;
272 target_object->package.count = source_object->package.count;
Robert Moore44f6c012005-04-18 22:49:35 -0400273 target_object->package.elements =
Len Brown4be44fc2005-08-05 00:44:28 -0400274 ACPI_CAST_PTR(union acpi_object, info->free_space);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
276 /*
277 * Pass the new package object back to the package walk routine
278 */
279 state->pkg.this_target_obj = target_object;
280
281 /*
282 * Save space for the array of objects (Package elements)
283 * update the buffer length counter
284 */
Len Brown4be44fc2005-08-05 00:44:28 -0400285 object_space = ACPI_ROUND_UP_TO_NATIVE_WORD((acpi_size)
286 target_object->
287 package.count *
288 sizeof(union
289 acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 break;
291
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 default:
293 return (AE_BAD_PARAMETER);
294 }
295
Len Brown4be44fc2005-08-05 00:44:28 -0400296 info->free_space += object_space;
297 info->length += object_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298 return (status);
299}
300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301/*******************************************************************************
302 *
303 * FUNCTION: acpi_ut_copy_ipackage_to_epackage
304 *
Robert Moore44f6c012005-04-18 22:49:35 -0400305 * PARAMETERS: internal_object - Pointer to the object we are returning
306 * Buffer - Where the object is returned
307 * space_used - Where the object length is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 *
309 * RETURN: Status
310 *
311 * DESCRIPTION: This function is called to place a package object in a user
312 * buffer. A package object by definition contains other objects.
313 *
314 * The buffer is assumed to have sufficient space for the object.
315 * The caller must have verified the buffer length needed using the
316 * acpi_ut_get_object_size function before calling this function.
317 *
318 ******************************************************************************/
319
320static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400321acpi_ut_copy_ipackage_to_epackage(union acpi_operand_object *internal_object,
322 u8 * buffer, acpi_size * space_used)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323{
Len Brown4be44fc2005-08-05 00:44:28 -0400324 union acpi_object *external_object;
325 acpi_status status;
326 struct acpi_pkg_info info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
Len Brown4be44fc2005-08-05 00:44:28 -0400328 ACPI_FUNCTION_TRACE("ut_copy_ipackage_to_epackage");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
330 /*
331 * First package at head of the buffer
332 */
Len Brown4be44fc2005-08-05 00:44:28 -0400333 external_object = ACPI_CAST_PTR(union acpi_object, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
335 /*
336 * Free space begins right after the first package
337 */
Len Brown4be44fc2005-08-05 00:44:28 -0400338 info.length = ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object));
339 info.free_space =
340 buffer + ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 info.object_space = 0;
342 info.num_packages = 1;
343
Len Brown4be44fc2005-08-05 00:44:28 -0400344 external_object->type = ACPI_GET_OBJECT_TYPE(internal_object);
345 external_object->package.count = internal_object->package.count;
346 external_object->package.elements = ACPI_CAST_PTR(union acpi_object,
347 info.free_space);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
349 /*
350 * Leave room for an array of ACPI_OBJECTS in the buffer
351 * and move the free space past it
352 */
Len Brown4be44fc2005-08-05 00:44:28 -0400353 info.length += (acpi_size) external_object->package.count *
354 ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 info.free_space += external_object->package.count *
Len Brown4be44fc2005-08-05 00:44:28 -0400356 ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
Len Brown4be44fc2005-08-05 00:44:28 -0400358 status = acpi_ut_walk_package_tree(internal_object, external_object,
359 acpi_ut_copy_ielement_to_eelement,
360 &info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
362 *space_used = info.length;
Len Brown4be44fc2005-08-05 00:44:28 -0400363 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364}
365
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366/*******************************************************************************
367 *
368 * FUNCTION: acpi_ut_copy_iobject_to_eobject
369 *
Robert Moore44f6c012005-04-18 22:49:35 -0400370 * PARAMETERS: internal_object - The internal object to be converted
371 * buffer_ptr - Where the object is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 *
373 * RETURN: Status
374 *
375 * DESCRIPTION: This function is called to build an API object to be returned to
376 * the caller.
377 *
378 ******************************************************************************/
379
380acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400381acpi_ut_copy_iobject_to_eobject(union acpi_operand_object *internal_object,
382 struct acpi_buffer *ret_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383{
Len Brown4be44fc2005-08-05 00:44:28 -0400384 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Len Brown4be44fc2005-08-05 00:44:28 -0400386 ACPI_FUNCTION_TRACE("ut_copy_iobject_to_eobject");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387
Len Brown4be44fc2005-08-05 00:44:28 -0400388 if (ACPI_GET_OBJECT_TYPE(internal_object) == ACPI_TYPE_PACKAGE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 /*
390 * Package object: Copy all subobjects (including
391 * nested packages)
392 */
Len Brown4be44fc2005-08-05 00:44:28 -0400393 status = acpi_ut_copy_ipackage_to_epackage(internal_object,
394 ret_buffer->pointer,
395 &ret_buffer->length);
396 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 /*
398 * Build a simple object (no nested objects)
399 */
Len Brown4be44fc2005-08-05 00:44:28 -0400400 status = acpi_ut_copy_isimple_to_esimple(internal_object,
Bob Moorec51a4de2005-11-17 13:07:00 -0500401 ACPI_CAST_PTR(union
402 acpi_object,
403 ret_buffer->
404 pointer),
405 ACPI_ADD_PTR(u8,
406 ret_buffer->
407 pointer,
408 ACPI_ROUND_UP_TO_NATIVE_WORD
409 (sizeof
410 (union
411 acpi_object))),
Len Brown4be44fc2005-08-05 00:44:28 -0400412 &ret_buffer->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 /*
414 * build simple does not include the object size in the length
415 * so we add it in here
416 */
Len Brown4be44fc2005-08-05 00:44:28 -0400417 ret_buffer->length += sizeof(union acpi_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418 }
419
Len Brown4be44fc2005-08-05 00:44:28 -0400420 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421}
422
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423/*******************************************************************************
424 *
425 * FUNCTION: acpi_ut_copy_esimple_to_isimple
426 *
Robert Moore44f6c012005-04-18 22:49:35 -0400427 * PARAMETERS: external_object - The external object to be converted
428 * ret_internal_object - Where the internal object is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 *
430 * RETURN: Status
431 *
432 * DESCRIPTION: This function copies an external object to an internal one.
433 * NOTE: Pointers can be copied, we don't need to copy data.
434 * (The pointers have to be valid in our address space no matter
435 * what we do with them!)
436 *
437 ******************************************************************************/
438
Robert Moore44f6c012005-04-18 22:49:35 -0400439static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400440acpi_ut_copy_esimple_to_isimple(union acpi_object *external_object,
441 union acpi_operand_object **ret_internal_object)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442{
Len Brown4be44fc2005-08-05 00:44:28 -0400443 union acpi_operand_object *internal_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444
Len Brown4be44fc2005-08-05 00:44:28 -0400445 ACPI_FUNCTION_TRACE("ut_copy_esimple_to_isimple");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446
447 /*
448 * Simple types supported are: String, Buffer, Integer
449 */
450 switch (external_object->type) {
451 case ACPI_TYPE_STRING:
452 case ACPI_TYPE_BUFFER:
453 case ACPI_TYPE_INTEGER:
454
Len Brown4be44fc2005-08-05 00:44:28 -0400455 internal_object = acpi_ut_create_internal_object((u8)
456 external_object->
457 type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 if (!internal_object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400459 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460 }
461 break;
462
463 default:
464 /* All other types are not supported */
465
Len Brown4be44fc2005-08-05 00:44:28 -0400466 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 }
468
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 /* Must COPY string and buffer contents */
470
471 switch (external_object->type) {
472 case ACPI_TYPE_STRING:
473
474 internal_object->string.pointer =
Len Brown4be44fc2005-08-05 00:44:28 -0400475 ACPI_MEM_CALLOCATE((acpi_size) external_object->string.
476 length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 if (!internal_object->string.pointer) {
478 goto error_exit;
479 }
480
Len Brown4be44fc2005-08-05 00:44:28 -0400481 ACPI_MEMCPY(internal_object->string.pointer,
482 external_object->string.pointer,
483 external_object->string.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
485 internal_object->string.length = external_object->string.length;
486 break;
487
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 case ACPI_TYPE_BUFFER:
489
490 internal_object->buffer.pointer =
Len Brown4be44fc2005-08-05 00:44:28 -0400491 ACPI_MEM_CALLOCATE(external_object->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 if (!internal_object->buffer.pointer) {
493 goto error_exit;
494 }
495
Len Brown4be44fc2005-08-05 00:44:28 -0400496 ACPI_MEMCPY(internal_object->buffer.pointer,
497 external_object->buffer.pointer,
498 external_object->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
500 internal_object->buffer.length = external_object->buffer.length;
501 break;
502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 case ACPI_TYPE_INTEGER:
504
Len Brown4be44fc2005-08-05 00:44:28 -0400505 internal_object->integer.value = external_object->integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506 break;
507
508 default:
509 /* Other types can't get here */
510 break;
511 }
512
513 *ret_internal_object = internal_object;
Len Brown4be44fc2005-08-05 00:44:28 -0400514 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Len Brown4be44fc2005-08-05 00:44:28 -0400516 error_exit:
517 acpi_ut_remove_reference(internal_object);
518 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519}
520
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521#ifdef ACPI_FUTURE_IMPLEMENTATION
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522/* Code to convert packages that are parameters to control methods */
523
524/*******************************************************************************
525 *
526 * FUNCTION: acpi_ut_copy_epackage_to_ipackage
527 *
528 * PARAMETERS: *internal_object - Pointer to the object we are returning
529 * *Buffer - Where the object is returned
530 * *space_used - Where the length of the object is returned
531 *
532 * RETURN: Status
533 *
534 * DESCRIPTION: This function is called to place a package object in a user
535 * buffer. A package object by definition contains other objects.
536 *
537 * The buffer is assumed to have sufficient space for the object.
538 * The caller must have verified the buffer length needed using the
539 * acpi_ut_get_object_size function before calling this function.
540 *
541 ******************************************************************************/
542
543static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400544acpi_ut_copy_epackage_to_ipackage(union acpi_operand_object *internal_object,
545 u8 * buffer, u32 * space_used)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546{
Len Brown4be44fc2005-08-05 00:44:28 -0400547 u8 *free_space;
548 union acpi_object *external_object;
549 u32 length = 0;
550 u32 this_index;
551 u32 object_space = 0;
552 union acpi_operand_object *this_internal_obj;
553 union acpi_object *this_external_obj;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
Len Brown4be44fc2005-08-05 00:44:28 -0400555 ACPI_FUNCTION_TRACE("ut_copy_epackage_to_ipackage");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556
557 /*
558 * First package at head of the buffer
559 */
560 external_object = (union acpi_object *)buffer;
561
562 /*
563 * Free space begins right after the first package
564 */
565 free_space = buffer + sizeof(union acpi_object);
566
Len Brown4be44fc2005-08-05 00:44:28 -0400567 external_object->type = ACPI_GET_OBJECT_TYPE(internal_object);
568 external_object->package.count = internal_object->package.count;
569 external_object->package.elements = (union acpi_object *)free_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570
571 /*
572 * Build an array of ACPI_OBJECTS in the buffer
573 * and move the free space past it
574 */
Len Brown4be44fc2005-08-05 00:44:28 -0400575 free_space +=
576 external_object->package.count * sizeof(union acpi_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
578 /* Call walk_package */
579
580}
581
Len Brown4be44fc2005-08-05 00:44:28 -0400582#endif /* Future implementation */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
584/*******************************************************************************
585 *
586 * FUNCTION: acpi_ut_copy_eobject_to_iobject
587 *
588 * PARAMETERS: *internal_object - The external object to be converted
589 * *buffer_ptr - Where the internal object is returned
590 *
591 * RETURN: Status - the status of the call
592 *
593 * DESCRIPTION: Converts an external object to an internal object.
594 *
595 ******************************************************************************/
596
597acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400598acpi_ut_copy_eobject_to_iobject(union acpi_object *external_object,
599 union acpi_operand_object **internal_object)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600{
Len Brown4be44fc2005-08-05 00:44:28 -0400601 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Len Brown4be44fc2005-08-05 00:44:28 -0400603 ACPI_FUNCTION_TRACE("ut_copy_eobject_to_iobject");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
605 if (external_object->type == ACPI_TYPE_PACKAGE) {
606 /*
607 * Packages as external input to control methods are not supported,
608 */
Bob Mooreb8e4d892006-01-27 16:43:00 -0500609 ACPI_ERROR((AE_INFO,
610 "Packages as parameters not implemented!"));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
Len Brown4be44fc2005-08-05 00:44:28 -0400612 return_ACPI_STATUS(AE_NOT_IMPLEMENTED);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 }
614
615 else {
616 /*
617 * Build a simple object (no nested objects)
618 */
Len Brown4be44fc2005-08-05 00:44:28 -0400619 status =
620 acpi_ut_copy_esimple_to_isimple(external_object,
621 internal_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 }
623
Len Brown4be44fc2005-08-05 00:44:28 -0400624 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625}
626
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627/*******************************************************************************
628 *
629 * FUNCTION: acpi_ut_copy_simple_object
630 *
631 * PARAMETERS: source_desc - The internal object to be copied
632 * dest_desc - New target object
633 *
634 * RETURN: Status
635 *
636 * DESCRIPTION: Simple copy of one internal object to another. Reference count
637 * of the destination object is preserved.
638 *
639 ******************************************************************************/
640
Robert Moore44f6c012005-04-18 22:49:35 -0400641static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400642acpi_ut_copy_simple_object(union acpi_operand_object *source_desc,
643 union acpi_operand_object *dest_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644{
Len Brown4be44fc2005-08-05 00:44:28 -0400645 u16 reference_count;
646 union acpi_operand_object *next_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
648 /* Save fields from destination that we don't want to overwrite */
649
650 reference_count = dest_desc->common.reference_count;
651 next_object = dest_desc->common.next_object;
652
Len Brown4be44fc2005-08-05 00:44:28 -0400653 /* Copy the entire source object over the destination object */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
Len Brown4be44fc2005-08-05 00:44:28 -0400655 ACPI_MEMCPY((char *)dest_desc, (char *)source_desc,
656 sizeof(union acpi_operand_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
658 /* Restore the saved fields */
659
660 dest_desc->common.reference_count = reference_count;
661 dest_desc->common.next_object = next_object;
662
Robert Moore6f42ccf2005-05-13 00:00:00 -0400663 /* New object is not static, regardless of source */
664
665 dest_desc->common.flags &= ~AOPOBJ_STATIC_POINTER;
666
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 /* Handle the objects with extra data */
668
Len Brown4be44fc2005-08-05 00:44:28 -0400669 switch (ACPI_GET_OBJECT_TYPE(dest_desc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 case ACPI_TYPE_BUFFER:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700671 /*
672 * Allocate and copy the actual buffer if and only if:
673 * 1) There is a valid buffer pointer
Robert Moore6f42ccf2005-05-13 00:00:00 -0400674 * 2) The buffer has a length > 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 */
676 if ((source_desc->buffer.pointer) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400677 (source_desc->buffer.length)) {
Robert Moore6f42ccf2005-05-13 00:00:00 -0400678 dest_desc->buffer.pointer =
Len Brown4be44fc2005-08-05 00:44:28 -0400679 ACPI_MEM_ALLOCATE(source_desc->buffer.length);
Robert Moore6f42ccf2005-05-13 00:00:00 -0400680 if (!dest_desc->buffer.pointer) {
681 return (AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 }
Robert Moore6f42ccf2005-05-13 00:00:00 -0400683
684 /* Copy the actual buffer data */
685
Len Brown4be44fc2005-08-05 00:44:28 -0400686 ACPI_MEMCPY(dest_desc->buffer.pointer,
687 source_desc->buffer.pointer,
688 source_desc->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 }
690 break;
691
692 case ACPI_TYPE_STRING:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 /*
694 * Allocate and copy the actual string if and only if:
695 * 1) There is a valid string pointer
Robert Moore6f42ccf2005-05-13 00:00:00 -0400696 * (Pointer to a NULL string is allowed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 */
Robert Moore6f42ccf2005-05-13 00:00:00 -0400698 if (source_desc->string.pointer) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 dest_desc->string.pointer =
Len Brown4be44fc2005-08-05 00:44:28 -0400700 ACPI_MEM_ALLOCATE((acpi_size) source_desc->string.
701 length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 if (!dest_desc->string.pointer) {
703 return (AE_NO_MEMORY);
704 }
705
Robert Moore6f42ccf2005-05-13 00:00:00 -0400706 /* Copy the actual string data */
707
Len Brown4be44fc2005-08-05 00:44:28 -0400708 ACPI_MEMCPY(dest_desc->string.pointer,
709 source_desc->string.pointer,
710 (acpi_size) source_desc->string.length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 }
712 break;
713
714 case ACPI_TYPE_LOCAL_REFERENCE:
715 /*
716 * We copied the reference object, so we now must add a reference
717 * to the object pointed to by the reference
718 */
Len Brown4be44fc2005-08-05 00:44:28 -0400719 acpi_ut_add_reference(source_desc->reference.object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720 break;
721
722 default:
723 /* Nothing to do for other simple objects */
724 break;
725 }
726
727 return (AE_OK);
728}
729
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730/*******************************************************************************
731 *
732 * FUNCTION: acpi_ut_copy_ielement_to_ielement
733 *
734 * PARAMETERS: acpi_pkg_callback
735 *
736 * RETURN: Status
737 *
738 * DESCRIPTION: Copy one package element to another package element
739 *
740 ******************************************************************************/
741
Robert Moore44f6c012005-04-18 22:49:35 -0400742static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400743acpi_ut_copy_ielement_to_ielement(u8 object_type,
744 union acpi_operand_object *source_object,
745 union acpi_generic_state *state,
746 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747{
Len Brown4be44fc2005-08-05 00:44:28 -0400748 acpi_status status = AE_OK;
749 u32 this_index;
750 union acpi_operand_object **this_target_ptr;
751 union acpi_operand_object *target_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752
Len Brown4be44fc2005-08-05 00:44:28 -0400753 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
Len Brown4be44fc2005-08-05 00:44:28 -0400755 this_index = state->pkg.index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 this_target_ptr = (union acpi_operand_object **)
Len Brown4be44fc2005-08-05 00:44:28 -0400757 &state->pkg.dest_object->package.elements[this_index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
759 switch (object_type) {
760 case ACPI_COPY_TYPE_SIMPLE:
761
762 /* A null source object indicates a (legal) null package element */
763
764 if (source_object) {
765 /*
766 * This is a simple object, just copy it
767 */
Len Brown4be44fc2005-08-05 00:44:28 -0400768 target_object =
769 acpi_ut_create_internal_object(ACPI_GET_OBJECT_TYPE
770 (source_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 if (!target_object) {
772 return (AE_NO_MEMORY);
773 }
774
Len Brown4be44fc2005-08-05 00:44:28 -0400775 status =
776 acpi_ut_copy_simple_object(source_object,
777 target_object);
778 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 goto error_exit;
780 }
781
782 *this_target_ptr = target_object;
Len Brown4be44fc2005-08-05 00:44:28 -0400783 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 /* Pass through a null element */
785
786 *this_target_ptr = NULL;
787 }
788 break;
789
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 case ACPI_COPY_TYPE_PACKAGE:
791
792 /*
793 * This object is a package - go down another nesting level
794 * Create and build the package object
795 */
Len Brown4be44fc2005-08-05 00:44:28 -0400796 target_object =
797 acpi_ut_create_internal_object(ACPI_TYPE_PACKAGE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 if (!target_object) {
799 return (AE_NO_MEMORY);
800 }
801
802 target_object->package.count = source_object->package.count;
803 target_object->common.flags = source_object->common.flags;
804
805 /*
806 * Create the object array
807 */
808 target_object->package.elements =
Len Brown4be44fc2005-08-05 00:44:28 -0400809 ACPI_MEM_CALLOCATE(((acpi_size) source_object->package.
810 count + 1) * sizeof(void *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 if (!target_object->package.elements) {
812 status = AE_NO_MEMORY;
813 goto error_exit;
814 }
815
816 /*
817 * Pass the new package object back to the package walk routine
818 */
819 state->pkg.this_target_obj = target_object;
820
821 /*
822 * Store the object pointer in the parent package object
823 */
824 *this_target_ptr = target_object;
825 break;
826
Linus Torvalds1da177e2005-04-16 15:20:36 -0700827 default:
828 return (AE_BAD_PARAMETER);
829 }
830
831 return (status);
832
Len Brown4be44fc2005-08-05 00:44:28 -0400833 error_exit:
834 acpi_ut_remove_reference(target_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700835 return (status);
836}
837
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838/*******************************************************************************
839 *
840 * FUNCTION: acpi_ut_copy_ipackage_to_ipackage
841 *
842 * PARAMETERS: *source_obj - Pointer to the source package object
843 * *dest_obj - Where the internal object is returned
844 *
845 * RETURN: Status - the status of the call
846 *
847 * DESCRIPTION: This function is called to copy an internal package object
848 * into another internal package object.
849 *
850 ******************************************************************************/
851
Robert Moore44f6c012005-04-18 22:49:35 -0400852static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400853acpi_ut_copy_ipackage_to_ipackage(union acpi_operand_object *source_obj,
854 union acpi_operand_object *dest_obj,
855 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856{
Len Brown4be44fc2005-08-05 00:44:28 -0400857 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858
Len Brown4be44fc2005-08-05 00:44:28 -0400859 ACPI_FUNCTION_TRACE("ut_copy_ipackage_to_ipackage");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860
Len Brown4be44fc2005-08-05 00:44:28 -0400861 dest_obj->common.type = ACPI_GET_OBJECT_TYPE(source_obj);
862 dest_obj->common.flags = source_obj->common.flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863 dest_obj->package.count = source_obj->package.count;
864
865 /*
866 * Create the object array and walk the source package tree
867 */
Len Brown4be44fc2005-08-05 00:44:28 -0400868 dest_obj->package.elements = ACPI_MEM_CALLOCATE(((acpi_size)
869 source_obj->package.
870 count +
871 1) * sizeof(void *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 if (!dest_obj->package.elements) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500873 ACPI_ERROR((AE_INFO, "Package allocation failure"));
Len Brown4be44fc2005-08-05 00:44:28 -0400874 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 }
876
877 /*
878 * Copy the package element-by-element by walking the package "tree".
879 * This handles nested packages of arbitrary depth.
880 */
Len Brown4be44fc2005-08-05 00:44:28 -0400881 status = acpi_ut_walk_package_tree(source_obj, dest_obj,
882 acpi_ut_copy_ielement_to_ielement,
883 walk_state);
884 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 /* On failure, delete the destination package object */
886
Len Brown4be44fc2005-08-05 00:44:28 -0400887 acpi_ut_remove_reference(dest_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 }
889
Len Brown4be44fc2005-08-05 00:44:28 -0400890 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891}
892
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893/*******************************************************************************
894 *
895 * FUNCTION: acpi_ut_copy_iobject_to_iobject
896 *
897 * PARAMETERS: walk_state - Current walk state
898 * source_desc - The internal object to be copied
899 * dest_desc - Where the copied object is returned
900 *
901 * RETURN: Status
902 *
903 * DESCRIPTION: Copy an internal object to a new internal object
904 *
905 ******************************************************************************/
906
907acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400908acpi_ut_copy_iobject_to_iobject(union acpi_operand_object *source_desc,
909 union acpi_operand_object **dest_desc,
910 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911{
Len Brown4be44fc2005-08-05 00:44:28 -0400912 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
Len Brown4be44fc2005-08-05 00:44:28 -0400914 ACPI_FUNCTION_TRACE("ut_copy_iobject_to_iobject");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
916 /* Create the top level object */
917
Len Brown4be44fc2005-08-05 00:44:28 -0400918 *dest_desc =
919 acpi_ut_create_internal_object(ACPI_GET_OBJECT_TYPE(source_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 if (!*dest_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400921 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 }
923
924 /* Copy the object and possible subobjects */
925
Len Brown4be44fc2005-08-05 00:44:28 -0400926 if (ACPI_GET_OBJECT_TYPE(source_desc) == ACPI_TYPE_PACKAGE) {
927 status =
928 acpi_ut_copy_ipackage_to_ipackage(source_desc, *dest_desc,
929 walk_state);
930 } else {
931 status = acpi_ut_copy_simple_object(source_desc, *dest_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 }
933
Len Brown4be44fc2005-08-05 00:44:28 -0400934 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935}