blob: 5b2f7c27b705f2714c9fce18f997837ff8bdf6f3 [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/*
Len Brown75a44ce2008-04-23 23:00:13 -04008 * Copyright (C) 2000 - 2008, Intel Corp.
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>
Bob Moorecd0b2242008-04-10 19:06:43 +040045#include <acpi/acnamesp.h>
46
Linus Torvalds1da177e2005-04-16 15:20:36 -070047
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define _COMPONENT ACPI_UTILITIES
Len Brown4be44fc2005-08-05 00:44:28 -040049ACPI_MODULE_NAME("utcopy")
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Robert Moore44f6c012005-04-18 22:49:35 -040051/* Local prototypes */
Len Brown4be44fc2005-08-05 00:44:28 -040052static acpi_status
53acpi_ut_copy_isimple_to_esimple(union acpi_operand_object *internal_object,
54 union acpi_object *external_object,
55 u8 * data_space, acpi_size * buffer_space_used);
Robert Moore44f6c012005-04-18 22:49:35 -040056
57static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040058acpi_ut_copy_ielement_to_ielement(u8 object_type,
59 union acpi_operand_object *source_object,
60 union acpi_generic_state *state,
61 void *context);
Robert Moore44f6c012005-04-18 22:49:35 -040062
63static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040064acpi_ut_copy_ipackage_to_epackage(union acpi_operand_object *internal_object,
65 u8 * buffer, acpi_size * space_used);
Robert Moore44f6c012005-04-18 22:49:35 -040066
67static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040068acpi_ut_copy_esimple_to_isimple(union acpi_object *user_obj,
69 union acpi_operand_object **return_obj);
Robert Moore44f6c012005-04-18 22:49:35 -040070
71static acpi_status
Bob Moore6287ee32007-04-03 19:59:37 -040072acpi_ut_copy_epackage_to_ipackage(union acpi_object *external_object,
73 union acpi_operand_object **internal_object);
74
75static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040076acpi_ut_copy_simple_object(union acpi_operand_object *source_desc,
77 union acpi_operand_object *dest_desc);
Robert Moore44f6c012005-04-18 22:49:35 -040078
79static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040080acpi_ut_copy_ielement_to_eelement(u8 object_type,
81 union acpi_operand_object *source_object,
82 union acpi_generic_state *state,
83 void *context);
Robert Moore44f6c012005-04-18 22:49:35 -040084
85static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040086acpi_ut_copy_ipackage_to_ipackage(union acpi_operand_object *source_obj,
87 union acpi_operand_object *dest_obj,
88 struct acpi_walk_state *walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90/*******************************************************************************
91 *
92 * FUNCTION: acpi_ut_copy_isimple_to_esimple
93 *
Robert Moore44f6c012005-04-18 22:49:35 -040094 * PARAMETERS: internal_object - Source object to be copied
95 * external_object - Where to return the copied object
96 * data_space - Where object data is returned (such as
97 * buffer and string data)
98 * buffer_space_used - Length of data_space that was used
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 *
100 * RETURN: Status
101 *
Robert Moore44f6c012005-04-18 22:49:35 -0400102 * DESCRIPTION: This function is called to copy a simple internal object to
103 * an external object.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700104 *
Robert Moore44f6c012005-04-18 22:49:35 -0400105 * The data_space buffer is assumed to have sufficient space for
106 * the object.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 *
108 ******************************************************************************/
109
110static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400111acpi_ut_copy_isimple_to_esimple(union acpi_operand_object *internal_object,
112 union acpi_object *external_object,
113 u8 * data_space, acpi_size * buffer_space_used)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114{
Len Brown4be44fc2005-08-05 00:44:28 -0400115 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
Bob Mooreb229cf92006-04-21 17:15:00 -0400117 ACPI_FUNCTION_TRACE(ut_copy_isimple_to_esimple);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119 *buffer_space_used = 0;
120
121 /*
122 * Check for NULL object case (could be an uninitialized
123 * package element)
124 */
125 if (!internal_object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400126 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 }
128
129 /* Always clear the external object */
130
Len Brown4be44fc2005-08-05 00:44:28 -0400131 ACPI_MEMSET(external_object, 0, sizeof(union acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
133 /*
134 * In general, the external object will be the same type as
135 * the internal object
136 */
Len Brown4be44fc2005-08-05 00:44:28 -0400137 external_object->type = ACPI_GET_OBJECT_TYPE(internal_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
139 /* However, only a limited number of external types are supported */
140
Len Brown4be44fc2005-08-05 00:44:28 -0400141 switch (ACPI_GET_OBJECT_TYPE(internal_object)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 case ACPI_TYPE_STRING:
143
Len Brown4be44fc2005-08-05 00:44:28 -0400144 external_object->string.pointer = (char *)data_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 external_object->string.length = internal_object->string.length;
Len Brown4be44fc2005-08-05 00:44:28 -0400146 *buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD((acpi_size)
147 internal_object->
148 string.
149 length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150
Len Brown4be44fc2005-08-05 00:44:28 -0400151 ACPI_MEMCPY((void *)data_space,
152 (void *)internal_object->string.pointer,
153 (acpi_size) internal_object->string.length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 break;
155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 case ACPI_TYPE_BUFFER:
157
158 external_object->buffer.pointer = data_space;
159 external_object->buffer.length = internal_object->buffer.length;
Len Brown4be44fc2005-08-05 00:44:28 -0400160 *buffer_space_used =
161 ACPI_ROUND_UP_TO_NATIVE_WORD(internal_object->string.
162 length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163
Len Brown4be44fc2005-08-05 00:44:28 -0400164 ACPI_MEMCPY((void *)data_space,
165 (void *)internal_object->buffer.pointer,
166 internal_object->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 break;
168
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 case ACPI_TYPE_INTEGER:
170
171 external_object->integer.value = internal_object->integer.value;
172 break;
173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 case ACPI_TYPE_LOCAL_REFERENCE:
175
Bob Moorecd0b2242008-04-10 19:06:43 +0400176 /* This is an object reference. */
177
Bob Moore1044f1f2008-09-27 11:08:41 +0800178 switch (internal_object->reference.class) {
179 case ACPI_REFCLASS_NAME:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180
Bob Moore1044f1f2008-09-27 11:08:41 +0800181 /*
182 * For namepath, return the object handle ("reference")
183 * We are referring to the namespace node
184 */
Len Brown4be44fc2005-08-05 00:44:28 -0400185 external_object->reference.handle =
186 internal_object->reference.node;
Bob Moorecd0b2242008-04-10 19:06:43 +0400187 external_object->reference.actual_type =
188 acpi_ns_get_type(internal_object->reference.node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 break;
Bob Moore1044f1f2008-09-27 11:08:41 +0800190
191 default:
192
193 /* All other reference types are unsupported */
194
195 return_ACPI_STATUS(AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 }
197 break;
198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 case ACPI_TYPE_PROCESSOR:
200
Len Brown4be44fc2005-08-05 00:44:28 -0400201 external_object->processor.proc_id =
202 internal_object->processor.proc_id;
203 external_object->processor.pblk_address =
204 internal_object->processor.address;
205 external_object->processor.pblk_length =
206 internal_object->processor.length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 break;
208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 case ACPI_TYPE_POWER:
210
211 external_object->power_resource.system_level =
Len Brown4be44fc2005-08-05 00:44:28 -0400212 internal_object->power_resource.system_level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214 external_object->power_resource.resource_order =
Len Brown4be44fc2005-08-05 00:44:28 -0400215 internal_object->power_resource.resource_order;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 break;
217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 default:
219 /*
220 * There is no corresponding external object type
221 */
Bob Mooreb1dd9092008-04-10 19:06:42 +0400222 ACPI_ERROR((AE_INFO,
223 "Unsupported object type, cannot convert to external object: %s",
224 acpi_ut_get_type_name(ACPI_GET_OBJECT_TYPE
225 (internal_object))));
226
Len Brown4be44fc2005-08-05 00:44:28 -0400227 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 }
229
Len Brown4be44fc2005-08-05 00:44:28 -0400230 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231}
232
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233/*******************************************************************************
234 *
235 * FUNCTION: acpi_ut_copy_ielement_to_eelement
236 *
237 * PARAMETERS: acpi_pkg_callback
238 *
239 * RETURN: Status
240 *
241 * DESCRIPTION: Copy one package element to another package element
242 *
243 ******************************************************************************/
244
Robert Moore44f6c012005-04-18 22:49:35 -0400245static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400246acpi_ut_copy_ielement_to_eelement(u8 object_type,
247 union acpi_operand_object *source_object,
248 union acpi_generic_state *state,
249 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250{
Len Brown4be44fc2005-08-05 00:44:28 -0400251 acpi_status status = AE_OK;
252 struct acpi_pkg_info *info = (struct acpi_pkg_info *)context;
253 acpi_size object_space;
254 u32 this_index;
255 union acpi_object *target_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
Len Brown4be44fc2005-08-05 00:44:28 -0400257 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Len Brown4be44fc2005-08-05 00:44:28 -0400259 this_index = state->pkg.index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 target_object = (union acpi_object *)
Len Brown4be44fc2005-08-05 00:44:28 -0400261 &((union acpi_object *)(state->pkg.dest_object))->package.
262 elements[this_index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
264 switch (object_type) {
265 case ACPI_COPY_TYPE_SIMPLE:
266
267 /*
268 * This is a simple or null object
269 */
Len Brown4be44fc2005-08-05 00:44:28 -0400270 status = acpi_ut_copy_isimple_to_esimple(source_object,
271 target_object,
272 info->free_space,
273 &object_space);
274 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 return (status);
276 }
277 break;
278
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 case ACPI_COPY_TYPE_PACKAGE:
280
281 /*
282 * Build the package object
283 */
Len Brown4be44fc2005-08-05 00:44:28 -0400284 target_object->type = ACPI_TYPE_PACKAGE;
285 target_object->package.count = source_object->package.count;
Robert Moore44f6c012005-04-18 22:49:35 -0400286 target_object->package.elements =
Len Brown4be44fc2005-08-05 00:44:28 -0400287 ACPI_CAST_PTR(union acpi_object, info->free_space);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
289 /*
290 * Pass the new package object back to the package walk routine
291 */
292 state->pkg.this_target_obj = target_object;
293
294 /*
295 * Save space for the array of objects (Package elements)
296 * update the buffer length counter
297 */
Len Brown4be44fc2005-08-05 00:44:28 -0400298 object_space = ACPI_ROUND_UP_TO_NATIVE_WORD((acpi_size)
299 target_object->
300 package.count *
301 sizeof(union
302 acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 break;
304
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 default:
306 return (AE_BAD_PARAMETER);
307 }
308
Len Brown4be44fc2005-08-05 00:44:28 -0400309 info->free_space += object_space;
310 info->length += object_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 return (status);
312}
313
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314/*******************************************************************************
315 *
316 * FUNCTION: acpi_ut_copy_ipackage_to_epackage
317 *
Robert Moore44f6c012005-04-18 22:49:35 -0400318 * PARAMETERS: internal_object - Pointer to the object we are returning
319 * Buffer - Where the object is returned
320 * space_used - Where the object length is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700321 *
322 * RETURN: Status
323 *
324 * DESCRIPTION: This function is called to place a package object in a user
325 * buffer. A package object by definition contains other objects.
326 *
327 * The buffer is assumed to have sufficient space for the object.
328 * The caller must have verified the buffer length needed using the
329 * acpi_ut_get_object_size function before calling this function.
330 *
331 ******************************************************************************/
332
333static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400334acpi_ut_copy_ipackage_to_epackage(union acpi_operand_object *internal_object,
335 u8 * buffer, acpi_size * space_used)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336{
Len Brown4be44fc2005-08-05 00:44:28 -0400337 union acpi_object *external_object;
338 acpi_status status;
339 struct acpi_pkg_info info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
Bob Mooreb229cf92006-04-21 17:15:00 -0400341 ACPI_FUNCTION_TRACE(ut_copy_ipackage_to_epackage);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343 /*
344 * First package at head of the buffer
345 */
Len Brown4be44fc2005-08-05 00:44:28 -0400346 external_object = ACPI_CAST_PTR(union acpi_object, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347
348 /*
349 * Free space begins right after the first package
350 */
Len Brown4be44fc2005-08-05 00:44:28 -0400351 info.length = ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object));
352 info.free_space =
353 buffer + ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 info.object_space = 0;
355 info.num_packages = 1;
356
Len Brown4be44fc2005-08-05 00:44:28 -0400357 external_object->type = ACPI_GET_OBJECT_TYPE(internal_object);
358 external_object->package.count = internal_object->package.count;
359 external_object->package.elements = ACPI_CAST_PTR(union acpi_object,
360 info.free_space);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361
362 /*
363 * Leave room for an array of ACPI_OBJECTS in the buffer
364 * and move the free space past it
365 */
Len Brown4be44fc2005-08-05 00:44:28 -0400366 info.length += (acpi_size) external_object->package.count *
367 ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 info.free_space += external_object->package.count *
Len Brown4be44fc2005-08-05 00:44:28 -0400369 ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
Len Brown4be44fc2005-08-05 00:44:28 -0400371 status = acpi_ut_walk_package_tree(internal_object, external_object,
372 acpi_ut_copy_ielement_to_eelement,
373 &info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374
375 *space_used = info.length;
Len Brown4be44fc2005-08-05 00:44:28 -0400376 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377}
378
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379/*******************************************************************************
380 *
381 * FUNCTION: acpi_ut_copy_iobject_to_eobject
382 *
Robert Moore44f6c012005-04-18 22:49:35 -0400383 * PARAMETERS: internal_object - The internal object to be converted
384 * buffer_ptr - Where the object is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 *
386 * RETURN: Status
387 *
388 * DESCRIPTION: This function is called to build an API object to be returned to
389 * the caller.
390 *
391 ******************************************************************************/
392
393acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400394acpi_ut_copy_iobject_to_eobject(union acpi_operand_object *internal_object,
395 struct acpi_buffer *ret_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396{
Len Brown4be44fc2005-08-05 00:44:28 -0400397 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Bob Mooreb229cf92006-04-21 17:15:00 -0400399 ACPI_FUNCTION_TRACE(ut_copy_iobject_to_eobject);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400
Len Brown4be44fc2005-08-05 00:44:28 -0400401 if (ACPI_GET_OBJECT_TYPE(internal_object) == ACPI_TYPE_PACKAGE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 /*
403 * Package object: Copy all subobjects (including
404 * nested packages)
405 */
Len Brown4be44fc2005-08-05 00:44:28 -0400406 status = acpi_ut_copy_ipackage_to_epackage(internal_object,
407 ret_buffer->pointer,
408 &ret_buffer->length);
409 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 /*
411 * Build a simple object (no nested objects)
412 */
Len Brown4be44fc2005-08-05 00:44:28 -0400413 status = acpi_ut_copy_isimple_to_esimple(internal_object,
Bob Moorec51a4de2005-11-17 13:07:00 -0500414 ACPI_CAST_PTR(union
415 acpi_object,
416 ret_buffer->
417 pointer),
418 ACPI_ADD_PTR(u8,
419 ret_buffer->
420 pointer,
421 ACPI_ROUND_UP_TO_NATIVE_WORD
422 (sizeof
423 (union
424 acpi_object))),
Len Brown4be44fc2005-08-05 00:44:28 -0400425 &ret_buffer->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 /*
427 * build simple does not include the object size in the length
428 * so we add it in here
429 */
Len Brown4be44fc2005-08-05 00:44:28 -0400430 ret_buffer->length += sizeof(union acpi_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431 }
432
Len Brown4be44fc2005-08-05 00:44:28 -0400433 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434}
435
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436/*******************************************************************************
437 *
438 * FUNCTION: acpi_ut_copy_esimple_to_isimple
439 *
Robert Moore44f6c012005-04-18 22:49:35 -0400440 * PARAMETERS: external_object - The external object to be converted
441 * ret_internal_object - Where the internal object is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700442 *
443 * RETURN: Status
444 *
445 * DESCRIPTION: This function copies an external object to an internal one.
446 * NOTE: Pointers can be copied, we don't need to copy data.
447 * (The pointers have to be valid in our address space no matter
448 * what we do with them!)
449 *
450 ******************************************************************************/
451
Robert Moore44f6c012005-04-18 22:49:35 -0400452static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400453acpi_ut_copy_esimple_to_isimple(union acpi_object *external_object,
454 union acpi_operand_object **ret_internal_object)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455{
Len Brown4be44fc2005-08-05 00:44:28 -0400456 union acpi_operand_object *internal_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
Bob Mooreb229cf92006-04-21 17:15:00 -0400458 ACPI_FUNCTION_TRACE(ut_copy_esimple_to_isimple);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459
460 /*
461 * Simple types supported are: String, Buffer, Integer
462 */
463 switch (external_object->type) {
464 case ACPI_TYPE_STRING:
465 case ACPI_TYPE_BUFFER:
466 case ACPI_TYPE_INTEGER:
Bob Moorecd0b2242008-04-10 19:06:43 +0400467 case ACPI_TYPE_LOCAL_REFERENCE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
Len Brown4be44fc2005-08-05 00:44:28 -0400469 internal_object = acpi_ut_create_internal_object((u8)
470 external_object->
471 type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 if (!internal_object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400473 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 }
475 break;
476
Bob Moorecd0b2242008-04-10 19:06:43 +0400477 case ACPI_TYPE_ANY: /* This is the case for a NULL object */
478
479 *ret_internal_object = NULL;
480 return_ACPI_STATUS(AE_OK);
481
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 default:
483 /* All other types are not supported */
484
Bob Mooreb1dd9092008-04-10 19:06:42 +0400485 ACPI_ERROR((AE_INFO,
486 "Unsupported object type, cannot convert to internal object: %s",
487 acpi_ut_get_type_name(external_object->type)));
488
Len Brown4be44fc2005-08-05 00:44:28 -0400489 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 }
491
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 /* Must COPY string and buffer contents */
493
494 switch (external_object->type) {
495 case ACPI_TYPE_STRING:
496
497 internal_object->string.pointer =
Bob Moore83135242006-10-03 00:00:00 -0400498 ACPI_ALLOCATE_ZEROED((acpi_size) external_object->string.
499 length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 if (!internal_object->string.pointer) {
501 goto error_exit;
502 }
503
Len Brown4be44fc2005-08-05 00:44:28 -0400504 ACPI_MEMCPY(internal_object->string.pointer,
505 external_object->string.pointer,
506 external_object->string.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
508 internal_object->string.length = external_object->string.length;
509 break;
510
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511 case ACPI_TYPE_BUFFER:
512
513 internal_object->buffer.pointer =
Bob Moore83135242006-10-03 00:00:00 -0400514 ACPI_ALLOCATE_ZEROED(external_object->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 if (!internal_object->buffer.pointer) {
516 goto error_exit;
517 }
518
Len Brown4be44fc2005-08-05 00:44:28 -0400519 ACPI_MEMCPY(internal_object->buffer.pointer,
520 external_object->buffer.pointer,
521 external_object->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522
523 internal_object->buffer.length = external_object->buffer.length;
Bob Moore24a31572008-04-10 19:06:43 +0400524
525 /* Mark buffer data valid */
526
527 internal_object->buffer.flags |= AOPOBJ_DATA_VALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 break;
529
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 case ACPI_TYPE_INTEGER:
531
Len Brown4be44fc2005-08-05 00:44:28 -0400532 internal_object->integer.value = external_object->integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533 break;
534
Bob Moorecd0b2242008-04-10 19:06:43 +0400535 case ACPI_TYPE_LOCAL_REFERENCE:
536
537 /* TBD: should validate incoming handle */
538
Bob Moore1044f1f2008-09-27 11:08:41 +0800539 internal_object->reference.class = ACPI_REFCLASS_NAME;
Bob Moorecd0b2242008-04-10 19:06:43 +0400540 internal_object->reference.node =
541 external_object->reference.handle;
542 break;
543
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 default:
545 /* Other types can't get here */
546 break;
547 }
548
549 *ret_internal_object = internal_object;
Len Brown4be44fc2005-08-05 00:44:28 -0400550 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551
Len Brown4be44fc2005-08-05 00:44:28 -0400552 error_exit:
553 acpi_ut_remove_reference(internal_object);
554 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555}
556
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557/*******************************************************************************
558 *
559 * FUNCTION: acpi_ut_copy_epackage_to_ipackage
560 *
Bob Moore6287ee32007-04-03 19:59:37 -0400561 * PARAMETERS: external_object - The external object to be converted
562 * internal_object - Where the internal object is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563 *
564 * RETURN: Status
565 *
Bob Moore6287ee32007-04-03 19:59:37 -0400566 * DESCRIPTION: Copy an external package object to an internal package.
567 * Handles nested packages.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 *
569 ******************************************************************************/
570
571static acpi_status
Bob Moore6287ee32007-04-03 19:59:37 -0400572acpi_ut_copy_epackage_to_ipackage(union acpi_object *external_object,
573 union acpi_operand_object **internal_object)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574{
Bob Moore6287ee32007-04-03 19:59:37 -0400575 acpi_status status = AE_OK;
576 union acpi_operand_object *package_object;
577 union acpi_operand_object **package_elements;
Bob Moore67a119f2008-06-10 13:42:13 +0800578 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
Bob Mooreb229cf92006-04-21 17:15:00 -0400580 ACPI_FUNCTION_TRACE(ut_copy_epackage_to_ipackage);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
Bob Moore6287ee32007-04-03 19:59:37 -0400582 /* Create the package object */
583
584 package_object =
585 acpi_ut_create_package_object(external_object->package.count);
586 if (!package_object) {
587 return_ACPI_STATUS(AE_NO_MEMORY);
588 }
589
590 package_elements = package_object->package.elements;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
592 /*
Bob Moore6287ee32007-04-03 19:59:37 -0400593 * Recursive implementation. Probably ok, since nested external packages
594 * as parameters should be very rare.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 */
Bob Moore6287ee32007-04-03 19:59:37 -0400596 for (i = 0; i < external_object->package.count; i++) {
597 status =
598 acpi_ut_copy_eobject_to_iobject(&external_object->package.
599 elements[i],
600 &package_elements[i]);
601 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Bob Moore6287ee32007-04-03 19:59:37 -0400603 /* Truncate package and delete it */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
Bob Moore67a119f2008-06-10 13:42:13 +0800605 package_object->package.count = i;
Bob Moore6287ee32007-04-03 19:59:37 -0400606 package_elements[i] = NULL;
607 acpi_ut_remove_reference(package_object);
608 return_ACPI_STATUS(status);
609 }
610 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
Bob Moore24a31572008-04-10 19:06:43 +0400612 /* Mark package data valid */
613
614 package_object->package.flags |= AOPOBJ_DATA_VALID;
615
Bob Moore6287ee32007-04-03 19:59:37 -0400616 *internal_object = package_object;
617 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618}
619
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620/*******************************************************************************
621 *
622 * FUNCTION: acpi_ut_copy_eobject_to_iobject
623 *
Bob Moore6287ee32007-04-03 19:59:37 -0400624 * PARAMETERS: external_object - The external object to be converted
625 * internal_object - Where the internal object is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626 *
Bob Moore6287ee32007-04-03 19:59:37 -0400627 * RETURN: Status - the status of the call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 *
629 * DESCRIPTION: Converts an external object to an internal object.
630 *
631 ******************************************************************************/
632
633acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400634acpi_ut_copy_eobject_to_iobject(union acpi_object *external_object,
635 union acpi_operand_object **internal_object)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636{
Len Brown4be44fc2005-08-05 00:44:28 -0400637 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Bob Mooreb229cf92006-04-21 17:15:00 -0400639 ACPI_FUNCTION_TRACE(ut_copy_eobject_to_iobject);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
641 if (external_object->type == ACPI_TYPE_PACKAGE) {
Bob Moore6287ee32007-04-03 19:59:37 -0400642 status =
643 acpi_ut_copy_epackage_to_ipackage(external_object,
644 internal_object);
645 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 /*
647 * Build a simple object (no nested objects)
648 */
Len Brown4be44fc2005-08-05 00:44:28 -0400649 status =
650 acpi_ut_copy_esimple_to_isimple(external_object,
651 internal_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 }
653
Len Brown4be44fc2005-08-05 00:44:28 -0400654 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655}
656
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657/*******************************************************************************
658 *
659 * FUNCTION: acpi_ut_copy_simple_object
660 *
661 * PARAMETERS: source_desc - The internal object to be copied
662 * dest_desc - New target object
663 *
664 * RETURN: Status
665 *
666 * DESCRIPTION: Simple copy of one internal object to another. Reference count
667 * of the destination object is preserved.
668 *
669 ******************************************************************************/
670
Robert Moore44f6c012005-04-18 22:49:35 -0400671static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400672acpi_ut_copy_simple_object(union acpi_operand_object *source_desc,
673 union acpi_operand_object *dest_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674{
Len Brown4be44fc2005-08-05 00:44:28 -0400675 u16 reference_count;
676 union acpi_operand_object *next_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677
678 /* Save fields from destination that we don't want to overwrite */
679
680 reference_count = dest_desc->common.reference_count;
681 next_object = dest_desc->common.next_object;
682
Len Brown4be44fc2005-08-05 00:44:28 -0400683 /* Copy the entire source object over the destination object */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684
Len Brown4be44fc2005-08-05 00:44:28 -0400685 ACPI_MEMCPY((char *)dest_desc, (char *)source_desc,
686 sizeof(union acpi_operand_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
688 /* Restore the saved fields */
689
690 dest_desc->common.reference_count = reference_count;
691 dest_desc->common.next_object = next_object;
692
Robert Moore6f42ccf2005-05-13 00:00:00 -0400693 /* New object is not static, regardless of source */
694
695 dest_desc->common.flags &= ~AOPOBJ_STATIC_POINTER;
696
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 /* Handle the objects with extra data */
698
Len Brown4be44fc2005-08-05 00:44:28 -0400699 switch (ACPI_GET_OBJECT_TYPE(dest_desc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 case ACPI_TYPE_BUFFER:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 /*
702 * Allocate and copy the actual buffer if and only if:
703 * 1) There is a valid buffer pointer
Robert Moore6f42ccf2005-05-13 00:00:00 -0400704 * 2) The buffer has a length > 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 */
706 if ((source_desc->buffer.pointer) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400707 (source_desc->buffer.length)) {
Robert Moore6f42ccf2005-05-13 00:00:00 -0400708 dest_desc->buffer.pointer =
Bob Moore83135242006-10-03 00:00:00 -0400709 ACPI_ALLOCATE(source_desc->buffer.length);
Robert Moore6f42ccf2005-05-13 00:00:00 -0400710 if (!dest_desc->buffer.pointer) {
711 return (AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 }
Robert Moore6f42ccf2005-05-13 00:00:00 -0400713
714 /* Copy the actual buffer data */
715
Len Brown4be44fc2005-08-05 00:44:28 -0400716 ACPI_MEMCPY(dest_desc->buffer.pointer,
717 source_desc->buffer.pointer,
718 source_desc->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719 }
720 break;
721
722 case ACPI_TYPE_STRING:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 /*
724 * Allocate and copy the actual string if and only if:
725 * 1) There is a valid string pointer
Robert Moore6f42ccf2005-05-13 00:00:00 -0400726 * (Pointer to a NULL string is allowed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700727 */
Robert Moore6f42ccf2005-05-13 00:00:00 -0400728 if (source_desc->string.pointer) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 dest_desc->string.pointer =
Bob Moore83135242006-10-03 00:00:00 -0400730 ACPI_ALLOCATE((acpi_size) source_desc->string.
731 length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732 if (!dest_desc->string.pointer) {
733 return (AE_NO_MEMORY);
734 }
735
Robert Moore6f42ccf2005-05-13 00:00:00 -0400736 /* Copy the actual string data */
737
Len Brown4be44fc2005-08-05 00:44:28 -0400738 ACPI_MEMCPY(dest_desc->string.pointer,
739 source_desc->string.pointer,
740 (acpi_size) source_desc->string.length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 }
742 break;
743
744 case ACPI_TYPE_LOCAL_REFERENCE:
745 /*
746 * We copied the reference object, so we now must add a reference
747 * to the object pointed to by the reference
Lin Mingbc7a36a2008-04-10 19:06:42 +0400748 *
Bob Moore1044f1f2008-09-27 11:08:41 +0800749 * DDBHandle reference (from Load/load_table) is a special reference,
750 * it does not have a Reference.Object, so does not need to
Lin Mingbc7a36a2008-04-10 19:06:42 +0400751 * increase the reference count
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 */
Bob Moore1044f1f2008-09-27 11:08:41 +0800753 if (source_desc->reference.class == ACPI_REFCLASS_TABLE) {
Lin Mingbc7a36a2008-04-10 19:06:42 +0400754 break;
755 }
756
Len Brown4be44fc2005-08-05 00:44:28 -0400757 acpi_ut_add_reference(source_desc->reference.object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 break;
759
Fiodor Suietov6b366e22007-02-02 19:48:18 +0300760 case ACPI_TYPE_REGION:
761 /*
762 * We copied the Region Handler, so we now must add a reference
763 */
764 if (dest_desc->region.handler) {
765 acpi_ut_add_reference(dest_desc->region.handler);
766 }
767 break;
768
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 default:
770 /* Nothing to do for other simple objects */
771 break;
772 }
773
774 return (AE_OK);
775}
776
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777/*******************************************************************************
778 *
779 * FUNCTION: acpi_ut_copy_ielement_to_ielement
780 *
781 * PARAMETERS: acpi_pkg_callback
782 *
783 * RETURN: Status
784 *
785 * DESCRIPTION: Copy one package element to another package element
786 *
787 ******************************************************************************/
788
Robert Moore44f6c012005-04-18 22:49:35 -0400789static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400790acpi_ut_copy_ielement_to_ielement(u8 object_type,
791 union acpi_operand_object *source_object,
792 union acpi_generic_state *state,
793 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794{
Len Brown4be44fc2005-08-05 00:44:28 -0400795 acpi_status status = AE_OK;
796 u32 this_index;
797 union acpi_operand_object **this_target_ptr;
798 union acpi_operand_object *target_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799
Len Brown4be44fc2005-08-05 00:44:28 -0400800 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
Len Brown4be44fc2005-08-05 00:44:28 -0400802 this_index = state->pkg.index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803 this_target_ptr = (union acpi_operand_object **)
Len Brown4be44fc2005-08-05 00:44:28 -0400804 &state->pkg.dest_object->package.elements[this_index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
806 switch (object_type) {
807 case ACPI_COPY_TYPE_SIMPLE:
808
809 /* A null source object indicates a (legal) null package element */
810
811 if (source_object) {
812 /*
813 * This is a simple object, just copy it
814 */
Len Brown4be44fc2005-08-05 00:44:28 -0400815 target_object =
816 acpi_ut_create_internal_object(ACPI_GET_OBJECT_TYPE
817 (source_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 if (!target_object) {
819 return (AE_NO_MEMORY);
820 }
821
Len Brown4be44fc2005-08-05 00:44:28 -0400822 status =
823 acpi_ut_copy_simple_object(source_object,
824 target_object);
825 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 goto error_exit;
827 }
828
829 *this_target_ptr = target_object;
Len Brown4be44fc2005-08-05 00:44:28 -0400830 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 /* Pass through a null element */
832
833 *this_target_ptr = NULL;
834 }
835 break;
836
Linus Torvalds1da177e2005-04-16 15:20:36 -0700837 case ACPI_COPY_TYPE_PACKAGE:
838
839 /*
840 * This object is a package - go down another nesting level
841 * Create and build the package object
842 */
Len Brown4be44fc2005-08-05 00:44:28 -0400843 target_object =
Bob Moore6287ee32007-04-03 19:59:37 -0400844 acpi_ut_create_package_object(source_object->package.count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700845 if (!target_object) {
846 return (AE_NO_MEMORY);
847 }
848
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 target_object->common.flags = source_object->common.flags;
850
Bob Moore6287ee32007-04-03 19:59:37 -0400851 /* Pass the new package object back to the package walk routine */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 state->pkg.this_target_obj = target_object;
854
Bob Moore6287ee32007-04-03 19:59:37 -0400855 /* Store the object pointer in the parent package object */
856
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 *this_target_ptr = target_object;
858 break;
859
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 default:
861 return (AE_BAD_PARAMETER);
862 }
863
864 return (status);
865
Len Brown4be44fc2005-08-05 00:44:28 -0400866 error_exit:
867 acpi_ut_remove_reference(target_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868 return (status);
869}
870
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871/*******************************************************************************
872 *
873 * FUNCTION: acpi_ut_copy_ipackage_to_ipackage
874 *
875 * PARAMETERS: *source_obj - Pointer to the source package object
876 * *dest_obj - Where the internal object is returned
877 *
878 * RETURN: Status - the status of the call
879 *
880 * DESCRIPTION: This function is called to copy an internal package object
881 * into another internal package object.
882 *
883 ******************************************************************************/
884
Robert Moore44f6c012005-04-18 22:49:35 -0400885static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400886acpi_ut_copy_ipackage_to_ipackage(union acpi_operand_object *source_obj,
887 union acpi_operand_object *dest_obj,
888 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889{
Len Brown4be44fc2005-08-05 00:44:28 -0400890 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891
Bob Mooreb229cf92006-04-21 17:15:00 -0400892 ACPI_FUNCTION_TRACE(ut_copy_ipackage_to_ipackage);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
Len Brown4be44fc2005-08-05 00:44:28 -0400894 dest_obj->common.type = ACPI_GET_OBJECT_TYPE(source_obj);
895 dest_obj->common.flags = source_obj->common.flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 dest_obj->package.count = source_obj->package.count;
897
898 /*
899 * Create the object array and walk the source package tree
900 */
Bob Moore83135242006-10-03 00:00:00 -0400901 dest_obj->package.elements = ACPI_ALLOCATE_ZEROED(((acpi_size)
902 source_obj->package.
903 count +
904 1) * sizeof(void *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 if (!dest_obj->package.elements) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500906 ACPI_ERROR((AE_INFO, "Package allocation failure"));
Len Brown4be44fc2005-08-05 00:44:28 -0400907 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908 }
909
910 /*
911 * Copy the package element-by-element by walking the package "tree".
912 * This handles nested packages of arbitrary depth.
913 */
Len Brown4be44fc2005-08-05 00:44:28 -0400914 status = acpi_ut_walk_package_tree(source_obj, dest_obj,
915 acpi_ut_copy_ielement_to_ielement,
916 walk_state);
917 if (ACPI_FAILURE(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400918
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 /* On failure, delete the destination package object */
920
Len Brown4be44fc2005-08-05 00:44:28 -0400921 acpi_ut_remove_reference(dest_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700922 }
923
Len Brown4be44fc2005-08-05 00:44:28 -0400924 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925}
926
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927/*******************************************************************************
928 *
929 * FUNCTION: acpi_ut_copy_iobject_to_iobject
930 *
931 * PARAMETERS: walk_state - Current walk state
932 * source_desc - The internal object to be copied
933 * dest_desc - Where the copied object is returned
934 *
935 * RETURN: Status
936 *
937 * DESCRIPTION: Copy an internal object to a new internal object
938 *
939 ******************************************************************************/
940
941acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400942acpi_ut_copy_iobject_to_iobject(union acpi_operand_object *source_desc,
943 union acpi_operand_object **dest_desc,
944 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945{
Len Brown4be44fc2005-08-05 00:44:28 -0400946 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947
Bob Mooreb229cf92006-04-21 17:15:00 -0400948 ACPI_FUNCTION_TRACE(ut_copy_iobject_to_iobject);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
950 /* Create the top level object */
951
Len Brown4be44fc2005-08-05 00:44:28 -0400952 *dest_desc =
953 acpi_ut_create_internal_object(ACPI_GET_OBJECT_TYPE(source_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954 if (!*dest_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400955 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 }
957
958 /* Copy the object and possible subobjects */
959
Len Brown4be44fc2005-08-05 00:44:28 -0400960 if (ACPI_GET_OBJECT_TYPE(source_desc) == ACPI_TYPE_PACKAGE) {
961 status =
962 acpi_ut_copy_ipackage_to_ipackage(source_desc, *dest_desc,
963 walk_state);
964 } else {
965 status = acpi_ut_copy_simple_object(source_desc, *dest_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966 }
967
Len Brown4be44fc2005-08-05 00:44:28 -0400968 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969}