blob: 919624f123d5ab4e6cb65b8ec23702c0d6d538ab [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>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "acnamesp.h"
Bob Moorecd0b2242008-04-10 19:06:43 +040047
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#define _COMPONENT ACPI_UTILITIES
Len Brown4be44fc2005-08-05 00:44:28 -040050ACPI_MODULE_NAME("utcopy")
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Robert Moore44f6c012005-04-18 22:49:35 -040052/* Local prototypes */
Len Brown4be44fc2005-08-05 00:44:28 -040053static acpi_status
54acpi_ut_copy_isimple_to_esimple(union acpi_operand_object *internal_object,
55 union acpi_object *external_object,
56 u8 * data_space, acpi_size * buffer_space_used);
Robert Moore44f6c012005-04-18 22:49:35 -040057
58static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040059acpi_ut_copy_ielement_to_ielement(u8 object_type,
60 union acpi_operand_object *source_object,
61 union acpi_generic_state *state,
62 void *context);
Robert Moore44f6c012005-04-18 22:49:35 -040063
64static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040065acpi_ut_copy_ipackage_to_epackage(union acpi_operand_object *internal_object,
66 u8 * buffer, acpi_size * space_used);
Robert Moore44f6c012005-04-18 22:49:35 -040067
68static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040069acpi_ut_copy_esimple_to_isimple(union acpi_object *user_obj,
70 union acpi_operand_object **return_obj);
Robert Moore44f6c012005-04-18 22:49:35 -040071
72static acpi_status
Bob Moore6287ee32007-04-03 19:59:37 -040073acpi_ut_copy_epackage_to_ipackage(union acpi_object *external_object,
74 union acpi_operand_object **internal_object);
75
76static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040077acpi_ut_copy_simple_object(union acpi_operand_object *source_desc,
78 union acpi_operand_object *dest_desc);
Robert Moore44f6c012005-04-18 22:49:35 -040079
80static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040081acpi_ut_copy_ielement_to_eelement(u8 object_type,
82 union acpi_operand_object *source_object,
83 union acpi_generic_state *state,
84 void *context);
Robert Moore44f6c012005-04-18 22:49:35 -040085
86static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040087acpi_ut_copy_ipackage_to_ipackage(union acpi_operand_object *source_obj,
88 union acpi_operand_object *dest_obj,
89 struct acpi_walk_state *walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91/*******************************************************************************
92 *
93 * FUNCTION: acpi_ut_copy_isimple_to_esimple
94 *
Robert Moore44f6c012005-04-18 22:49:35 -040095 * PARAMETERS: internal_object - Source object to be copied
96 * external_object - Where to return the copied object
97 * data_space - Where object data is returned (such as
98 * buffer and string data)
99 * buffer_space_used - Length of data_space that was used
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 *
101 * RETURN: Status
102 *
Robert Moore44f6c012005-04-18 22:49:35 -0400103 * DESCRIPTION: This function is called to copy a simple internal object to
104 * an external object.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 *
Robert Moore44f6c012005-04-18 22:49:35 -0400106 * The data_space buffer is assumed to have sufficient space for
107 * the object.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 *
109 ******************************************************************************/
110
111static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400112acpi_ut_copy_isimple_to_esimple(union acpi_operand_object *internal_object,
113 union acpi_object *external_object,
114 u8 * data_space, acpi_size * buffer_space_used)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
Len Brown4be44fc2005-08-05 00:44:28 -0400116 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Bob Mooreb229cf92006-04-21 17:15:00 -0400118 ACPI_FUNCTION_TRACE(ut_copy_isimple_to_esimple);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120 *buffer_space_used = 0;
121
122 /*
123 * Check for NULL object case (could be an uninitialized
124 * package element)
125 */
126 if (!internal_object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400127 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 }
129
130 /* Always clear the external object */
131
Len Brown4be44fc2005-08-05 00:44:28 -0400132 ACPI_MEMSET(external_object, 0, sizeof(union acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134 /*
135 * In general, the external object will be the same type as
136 * the internal object
137 */
Bob Moore3371c192009-02-18 14:44:03 +0800138 external_object->type = internal_object->common.type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
140 /* However, only a limited number of external types are supported */
141
Bob Moore3371c192009-02-18 14:44:03 +0800142 switch (internal_object->common.type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 case ACPI_TYPE_STRING:
144
Len Brown4be44fc2005-08-05 00:44:28 -0400145 external_object->string.pointer = (char *)data_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 external_object->string.length = internal_object->string.length;
Len Brown4be44fc2005-08-05 00:44:28 -0400147 *buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD((acpi_size)
148 internal_object->
149 string.
150 length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Len Brown4be44fc2005-08-05 00:44:28 -0400152 ACPI_MEMCPY((void *)data_space,
153 (void *)internal_object->string.pointer,
154 (acpi_size) internal_object->string.length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 break;
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 case ACPI_TYPE_BUFFER:
158
159 external_object->buffer.pointer = data_space;
160 external_object->buffer.length = internal_object->buffer.length;
Len Brown4be44fc2005-08-05 00:44:28 -0400161 *buffer_space_used =
162 ACPI_ROUND_UP_TO_NATIVE_WORD(internal_object->string.
163 length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Len Brown4be44fc2005-08-05 00:44:28 -0400165 ACPI_MEMCPY((void *)data_space,
166 (void *)internal_object->buffer.pointer,
167 internal_object->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 break;
169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 case ACPI_TYPE_INTEGER:
171
172 external_object->integer.value = internal_object->integer.value;
173 break;
174
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 case ACPI_TYPE_LOCAL_REFERENCE:
176
Bob Moorecd0b2242008-04-10 19:06:43 +0400177 /* This is an object reference. */
178
Bob Moore1044f1f2008-09-27 11:08:41 +0800179 switch (internal_object->reference.class) {
180 case ACPI_REFCLASS_NAME:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181
Bob Moore1044f1f2008-09-27 11:08:41 +0800182 /*
183 * For namepath, return the object handle ("reference")
184 * We are referring to the namespace node
185 */
Len Brown4be44fc2005-08-05 00:44:28 -0400186 external_object->reference.handle =
187 internal_object->reference.node;
Bob Moorecd0b2242008-04-10 19:06:43 +0400188 external_object->reference.actual_type =
189 acpi_ns_get_type(internal_object->reference.node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 break;
Bob Moore1044f1f2008-09-27 11:08:41 +0800191
192 default:
193
194 /* All other reference types are unsupported */
195
196 return_ACPI_STATUS(AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197 }
198 break;
199
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 case ACPI_TYPE_PROCESSOR:
201
Len Brown4be44fc2005-08-05 00:44:28 -0400202 external_object->processor.proc_id =
203 internal_object->processor.proc_id;
204 external_object->processor.pblk_address =
205 internal_object->processor.address;
206 external_object->processor.pblk_length =
207 internal_object->processor.length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 break;
209
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 case ACPI_TYPE_POWER:
211
212 external_object->power_resource.system_level =
Len Brown4be44fc2005-08-05 00:44:28 -0400213 internal_object->power_resource.system_level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214
215 external_object->power_resource.resource_order =
Len Brown4be44fc2005-08-05 00:44:28 -0400216 internal_object->power_resource.resource_order;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 break;
218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 default:
220 /*
221 * There is no corresponding external object type
222 */
Bob Mooreb1dd9092008-04-10 19:06:42 +0400223 ACPI_ERROR((AE_INFO,
224 "Unsupported object type, cannot convert to external object: %s",
Bob Moore3371c192009-02-18 14:44:03 +0800225 acpi_ut_get_type_name(internal_object->common.
226 type)));
Bob Mooreb1dd9092008-04-10 19:06:42 +0400227
Len Brown4be44fc2005-08-05 00:44:28 -0400228 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 }
230
Len Brown4be44fc2005-08-05 00:44:28 -0400231 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232}
233
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234/*******************************************************************************
235 *
236 * FUNCTION: acpi_ut_copy_ielement_to_eelement
237 *
238 * PARAMETERS: acpi_pkg_callback
239 *
240 * RETURN: Status
241 *
242 * DESCRIPTION: Copy one package element to another package element
243 *
244 ******************************************************************************/
245
Robert Moore44f6c012005-04-18 22:49:35 -0400246static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400247acpi_ut_copy_ielement_to_eelement(u8 object_type,
248 union acpi_operand_object *source_object,
249 union acpi_generic_state *state,
250 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251{
Len Brown4be44fc2005-08-05 00:44:28 -0400252 acpi_status status = AE_OK;
253 struct acpi_pkg_info *info = (struct acpi_pkg_info *)context;
254 acpi_size object_space;
255 u32 this_index;
256 union acpi_object *target_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257
Len Brown4be44fc2005-08-05 00:44:28 -0400258 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
Len Brown4be44fc2005-08-05 00:44:28 -0400260 this_index = state->pkg.index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 target_object = (union acpi_object *)
Len Brown4be44fc2005-08-05 00:44:28 -0400262 &((union acpi_object *)(state->pkg.dest_object))->package.
263 elements[this_index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265 switch (object_type) {
266 case ACPI_COPY_TYPE_SIMPLE:
267
268 /*
269 * This is a simple or null object
270 */
Len Brown4be44fc2005-08-05 00:44:28 -0400271 status = acpi_ut_copy_isimple_to_esimple(source_object,
272 target_object,
273 info->free_space,
274 &object_space);
275 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 return (status);
277 }
278 break;
279
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 case ACPI_COPY_TYPE_PACKAGE:
281
282 /*
283 * Build the package object
284 */
Len Brown4be44fc2005-08-05 00:44:28 -0400285 target_object->type = ACPI_TYPE_PACKAGE;
286 target_object->package.count = source_object->package.count;
Robert Moore44f6c012005-04-18 22:49:35 -0400287 target_object->package.elements =
Len Brown4be44fc2005-08-05 00:44:28 -0400288 ACPI_CAST_PTR(union acpi_object, info->free_space);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
290 /*
291 * Pass the new package object back to the package walk routine
292 */
293 state->pkg.this_target_obj = target_object;
294
295 /*
296 * Save space for the array of objects (Package elements)
297 * update the buffer length counter
298 */
Len Brown4be44fc2005-08-05 00:44:28 -0400299 object_space = ACPI_ROUND_UP_TO_NATIVE_WORD((acpi_size)
300 target_object->
301 package.count *
302 sizeof(union
303 acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 break;
305
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 default:
307 return (AE_BAD_PARAMETER);
308 }
309
Len Brown4be44fc2005-08-05 00:44:28 -0400310 info->free_space += object_space;
311 info->length += object_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 return (status);
313}
314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315/*******************************************************************************
316 *
317 * FUNCTION: acpi_ut_copy_ipackage_to_epackage
318 *
Robert Moore44f6c012005-04-18 22:49:35 -0400319 * PARAMETERS: internal_object - Pointer to the object we are returning
320 * Buffer - Where the object is returned
321 * space_used - Where the object length is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 *
323 * RETURN: Status
324 *
325 * DESCRIPTION: This function is called to place a package object in a user
326 * buffer. A package object by definition contains other objects.
327 *
328 * The buffer is assumed to have sufficient space for the object.
329 * The caller must have verified the buffer length needed using the
330 * acpi_ut_get_object_size function before calling this function.
331 *
332 ******************************************************************************/
333
334static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400335acpi_ut_copy_ipackage_to_epackage(union acpi_operand_object *internal_object,
336 u8 * buffer, acpi_size * space_used)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
Len Brown4be44fc2005-08-05 00:44:28 -0400338 union acpi_object *external_object;
339 acpi_status status;
340 struct acpi_pkg_info info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Bob Mooreb229cf92006-04-21 17:15:00 -0400342 ACPI_FUNCTION_TRACE(ut_copy_ipackage_to_epackage);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
344 /*
345 * First package at head of the buffer
346 */
Len Brown4be44fc2005-08-05 00:44:28 -0400347 external_object = ACPI_CAST_PTR(union acpi_object, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348
349 /*
350 * Free space begins right after the first package
351 */
Len Brown4be44fc2005-08-05 00:44:28 -0400352 info.length = ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object));
353 info.free_space =
354 buffer + ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 info.object_space = 0;
356 info.num_packages = 1;
357
Bob Moore3371c192009-02-18 14:44:03 +0800358 external_object->type = internal_object->common.type;
Len Brown4be44fc2005-08-05 00:44:28 -0400359 external_object->package.count = internal_object->package.count;
360 external_object->package.elements = ACPI_CAST_PTR(union acpi_object,
361 info.free_space);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362
363 /*
364 * Leave room for an array of ACPI_OBJECTS in the buffer
365 * and move the free space past it
366 */
Len Brown4be44fc2005-08-05 00:44:28 -0400367 info.length += (acpi_size) external_object->package.count *
368 ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369 info.free_space += external_object->package.count *
Len Brown4be44fc2005-08-05 00:44:28 -0400370 ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371
Len Brown4be44fc2005-08-05 00:44:28 -0400372 status = acpi_ut_walk_package_tree(internal_object, external_object,
373 acpi_ut_copy_ielement_to_eelement,
374 &info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
376 *space_used = info.length;
Len Brown4be44fc2005-08-05 00:44:28 -0400377 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378}
379
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380/*******************************************************************************
381 *
382 * FUNCTION: acpi_ut_copy_iobject_to_eobject
383 *
Robert Moore44f6c012005-04-18 22:49:35 -0400384 * PARAMETERS: internal_object - The internal object to be converted
385 * buffer_ptr - Where the object is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 *
387 * RETURN: Status
388 *
389 * DESCRIPTION: This function is called to build an API object to be returned to
390 * the caller.
391 *
392 ******************************************************************************/
393
394acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400395acpi_ut_copy_iobject_to_eobject(union acpi_operand_object *internal_object,
396 struct acpi_buffer *ret_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397{
Len Brown4be44fc2005-08-05 00:44:28 -0400398 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Bob Mooreb229cf92006-04-21 17:15:00 -0400400 ACPI_FUNCTION_TRACE(ut_copy_iobject_to_eobject);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
Bob Moore3371c192009-02-18 14:44:03 +0800402 if (internal_object->common.type == ACPI_TYPE_PACKAGE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403 /*
404 * Package object: Copy all subobjects (including
405 * nested packages)
406 */
Len Brown4be44fc2005-08-05 00:44:28 -0400407 status = acpi_ut_copy_ipackage_to_epackage(internal_object,
408 ret_buffer->pointer,
409 &ret_buffer->length);
410 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 /*
412 * Build a simple object (no nested objects)
413 */
Len Brown4be44fc2005-08-05 00:44:28 -0400414 status = acpi_ut_copy_isimple_to_esimple(internal_object,
Bob Moorec51a4de2005-11-17 13:07:00 -0500415 ACPI_CAST_PTR(union
416 acpi_object,
417 ret_buffer->
418 pointer),
419 ACPI_ADD_PTR(u8,
420 ret_buffer->
421 pointer,
422 ACPI_ROUND_UP_TO_NATIVE_WORD
423 (sizeof
424 (union
425 acpi_object))),
Len Brown4be44fc2005-08-05 00:44:28 -0400426 &ret_buffer->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 /*
428 * build simple does not include the object size in the length
429 * so we add it in here
430 */
Len Brown4be44fc2005-08-05 00:44:28 -0400431 ret_buffer->length += sizeof(union acpi_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432 }
433
Len Brown4be44fc2005-08-05 00:44:28 -0400434 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435}
436
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437/*******************************************************************************
438 *
439 * FUNCTION: acpi_ut_copy_esimple_to_isimple
440 *
Robert Moore44f6c012005-04-18 22:49:35 -0400441 * PARAMETERS: external_object - The external object to be converted
442 * ret_internal_object - Where the internal object is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 *
444 * RETURN: Status
445 *
446 * DESCRIPTION: This function copies an external object to an internal one.
447 * NOTE: Pointers can be copied, we don't need to copy data.
448 * (The pointers have to be valid in our address space no matter
449 * what we do with them!)
450 *
451 ******************************************************************************/
452
Robert Moore44f6c012005-04-18 22:49:35 -0400453static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400454acpi_ut_copy_esimple_to_isimple(union acpi_object *external_object,
455 union acpi_operand_object **ret_internal_object)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456{
Len Brown4be44fc2005-08-05 00:44:28 -0400457 union acpi_operand_object *internal_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
Bob Mooreb229cf92006-04-21 17:15:00 -0400459 ACPI_FUNCTION_TRACE(ut_copy_esimple_to_isimple);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460
461 /*
462 * Simple types supported are: String, Buffer, Integer
463 */
464 switch (external_object->type) {
465 case ACPI_TYPE_STRING:
466 case ACPI_TYPE_BUFFER:
467 case ACPI_TYPE_INTEGER:
Bob Moorecd0b2242008-04-10 19:06:43 +0400468 case ACPI_TYPE_LOCAL_REFERENCE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
Len Brown4be44fc2005-08-05 00:44:28 -0400470 internal_object = acpi_ut_create_internal_object((u8)
471 external_object->
472 type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 if (!internal_object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400474 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 }
476 break;
477
Bob Moorecd0b2242008-04-10 19:06:43 +0400478 case ACPI_TYPE_ANY: /* This is the case for a NULL object */
479
480 *ret_internal_object = NULL;
481 return_ACPI_STATUS(AE_OK);
482
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 default:
484 /* All other types are not supported */
485
Bob Mooreb1dd9092008-04-10 19:06:42 +0400486 ACPI_ERROR((AE_INFO,
487 "Unsupported object type, cannot convert to internal object: %s",
488 acpi_ut_get_type_name(external_object->type)));
489
Len Brown4be44fc2005-08-05 00:44:28 -0400490 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 }
492
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493 /* Must COPY string and buffer contents */
494
495 switch (external_object->type) {
496 case ACPI_TYPE_STRING:
497
498 internal_object->string.pointer =
Bob Mooreec41f192009-02-18 15:03:30 +0800499 ACPI_ALLOCATE_ZEROED((acpi_size)
500 external_object->string.length + 1);
501
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 if (!internal_object->string.pointer) {
503 goto error_exit;
504 }
505
Len Brown4be44fc2005-08-05 00:44:28 -0400506 ACPI_MEMCPY(internal_object->string.pointer,
507 external_object->string.pointer,
508 external_object->string.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
510 internal_object->string.length = external_object->string.length;
511 break;
512
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 case ACPI_TYPE_BUFFER:
514
515 internal_object->buffer.pointer =
Bob Moore83135242006-10-03 00:00:00 -0400516 ACPI_ALLOCATE_ZEROED(external_object->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 if (!internal_object->buffer.pointer) {
518 goto error_exit;
519 }
520
Len Brown4be44fc2005-08-05 00:44:28 -0400521 ACPI_MEMCPY(internal_object->buffer.pointer,
522 external_object->buffer.pointer,
523 external_object->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524
525 internal_object->buffer.length = external_object->buffer.length;
Bob Moore24a31572008-04-10 19:06:43 +0400526
527 /* Mark buffer data valid */
528
529 internal_object->buffer.flags |= AOPOBJ_DATA_VALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 break;
531
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 case ACPI_TYPE_INTEGER:
533
Len Brown4be44fc2005-08-05 00:44:28 -0400534 internal_object->integer.value = external_object->integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 break;
536
Bob Moorecd0b2242008-04-10 19:06:43 +0400537 case ACPI_TYPE_LOCAL_REFERENCE:
538
539 /* TBD: should validate incoming handle */
540
Bob Moore1044f1f2008-09-27 11:08:41 +0800541 internal_object->reference.class = ACPI_REFCLASS_NAME;
Bob Moorecd0b2242008-04-10 19:06:43 +0400542 internal_object->reference.node =
543 external_object->reference.handle;
544 break;
545
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 default:
547 /* Other types can't get here */
548 break;
549 }
550
551 *ret_internal_object = internal_object;
Len Brown4be44fc2005-08-05 00:44:28 -0400552 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553
Len Brown4be44fc2005-08-05 00:44:28 -0400554 error_exit:
555 acpi_ut_remove_reference(internal_object);
556 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557}
558
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559/*******************************************************************************
560 *
561 * FUNCTION: acpi_ut_copy_epackage_to_ipackage
562 *
Bob Moore6287ee32007-04-03 19:59:37 -0400563 * PARAMETERS: external_object - The external object to be converted
564 * internal_object - Where the internal object is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 *
566 * RETURN: Status
567 *
Bob Moore6287ee32007-04-03 19:59:37 -0400568 * DESCRIPTION: Copy an external package object to an internal package.
569 * Handles nested packages.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 *
571 ******************************************************************************/
572
573static acpi_status
Bob Moore6287ee32007-04-03 19:59:37 -0400574acpi_ut_copy_epackage_to_ipackage(union acpi_object *external_object,
575 union acpi_operand_object **internal_object)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576{
Bob Moore6287ee32007-04-03 19:59:37 -0400577 acpi_status status = AE_OK;
578 union acpi_operand_object *package_object;
579 union acpi_operand_object **package_elements;
Bob Moore67a119f2008-06-10 13:42:13 +0800580 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
Bob Mooreb229cf92006-04-21 17:15:00 -0400582 ACPI_FUNCTION_TRACE(ut_copy_epackage_to_ipackage);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Bob Moore6287ee32007-04-03 19:59:37 -0400584 /* Create the package object */
585
586 package_object =
587 acpi_ut_create_package_object(external_object->package.count);
588 if (!package_object) {
589 return_ACPI_STATUS(AE_NO_MEMORY);
590 }
591
592 package_elements = package_object->package.elements;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593
594 /*
Bob Moore6287ee32007-04-03 19:59:37 -0400595 * Recursive implementation. Probably ok, since nested external packages
596 * as parameters should be very rare.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 */
Bob Moore6287ee32007-04-03 19:59:37 -0400598 for (i = 0; i < external_object->package.count; i++) {
599 status =
600 acpi_ut_copy_eobject_to_iobject(&external_object->package.
601 elements[i],
602 &package_elements[i]);
603 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604
Bob Moore6287ee32007-04-03 19:59:37 -0400605 /* Truncate package and delete it */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
Bob Moore67a119f2008-06-10 13:42:13 +0800607 package_object->package.count = i;
Bob Moore6287ee32007-04-03 19:59:37 -0400608 package_elements[i] = NULL;
609 acpi_ut_remove_reference(package_object);
610 return_ACPI_STATUS(status);
611 }
612 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613
Bob Moore24a31572008-04-10 19:06:43 +0400614 /* Mark package data valid */
615
616 package_object->package.flags |= AOPOBJ_DATA_VALID;
617
Bob Moore6287ee32007-04-03 19:59:37 -0400618 *internal_object = package_object;
619 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620}
621
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622/*******************************************************************************
623 *
624 * FUNCTION: acpi_ut_copy_eobject_to_iobject
625 *
Bob Moore6287ee32007-04-03 19:59:37 -0400626 * PARAMETERS: external_object - The external object to be converted
627 * internal_object - Where the internal object is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 *
Bob Moore6287ee32007-04-03 19:59:37 -0400629 * RETURN: Status - the status of the call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 *
631 * DESCRIPTION: Converts an external object to an internal object.
632 *
633 ******************************************************************************/
634
635acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400636acpi_ut_copy_eobject_to_iobject(union acpi_object *external_object,
637 union acpi_operand_object **internal_object)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638{
Len Brown4be44fc2005-08-05 00:44:28 -0400639 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
Bob Mooreb229cf92006-04-21 17:15:00 -0400641 ACPI_FUNCTION_TRACE(ut_copy_eobject_to_iobject);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642
643 if (external_object->type == ACPI_TYPE_PACKAGE) {
Bob Moore6287ee32007-04-03 19:59:37 -0400644 status =
645 acpi_ut_copy_epackage_to_ipackage(external_object,
646 internal_object);
647 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 /*
649 * Build a simple object (no nested objects)
650 */
Len Brown4be44fc2005-08-05 00:44:28 -0400651 status =
652 acpi_ut_copy_esimple_to_isimple(external_object,
653 internal_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 }
655
Len Brown4be44fc2005-08-05 00:44:28 -0400656 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657}
658
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659/*******************************************************************************
660 *
661 * FUNCTION: acpi_ut_copy_simple_object
662 *
663 * PARAMETERS: source_desc - The internal object to be copied
664 * dest_desc - New target object
665 *
666 * RETURN: Status
667 *
668 * DESCRIPTION: Simple copy of one internal object to another. Reference count
669 * of the destination object is preserved.
670 *
671 ******************************************************************************/
672
Robert Moore44f6c012005-04-18 22:49:35 -0400673static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400674acpi_ut_copy_simple_object(union acpi_operand_object *source_desc,
675 union acpi_operand_object *dest_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676{
Len Brown4be44fc2005-08-05 00:44:28 -0400677 u16 reference_count;
678 union acpi_operand_object *next_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
680 /* Save fields from destination that we don't want to overwrite */
681
682 reference_count = dest_desc->common.reference_count;
683 next_object = dest_desc->common.next_object;
684
Len Brown4be44fc2005-08-05 00:44:28 -0400685 /* Copy the entire source object over the destination object */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
Len Brown4be44fc2005-08-05 00:44:28 -0400687 ACPI_MEMCPY((char *)dest_desc, (char *)source_desc,
688 sizeof(union acpi_operand_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689
690 /* Restore the saved fields */
691
692 dest_desc->common.reference_count = reference_count;
693 dest_desc->common.next_object = next_object;
694
Robert Moore6f42ccf2005-05-13 00:00:00 -0400695 /* New object is not static, regardless of source */
696
697 dest_desc->common.flags &= ~AOPOBJ_STATIC_POINTER;
698
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 /* Handle the objects with extra data */
700
Bob Moore3371c192009-02-18 14:44:03 +0800701 switch (dest_desc->common.type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 case ACPI_TYPE_BUFFER:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 /*
704 * Allocate and copy the actual buffer if and only if:
705 * 1) There is a valid buffer pointer
Robert Moore6f42ccf2005-05-13 00:00:00 -0400706 * 2) The buffer has a length > 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 */
708 if ((source_desc->buffer.pointer) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400709 (source_desc->buffer.length)) {
Robert Moore6f42ccf2005-05-13 00:00:00 -0400710 dest_desc->buffer.pointer =
Bob Moore83135242006-10-03 00:00:00 -0400711 ACPI_ALLOCATE(source_desc->buffer.length);
Robert Moore6f42ccf2005-05-13 00:00:00 -0400712 if (!dest_desc->buffer.pointer) {
713 return (AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714 }
Robert Moore6f42ccf2005-05-13 00:00:00 -0400715
716 /* Copy the actual buffer data */
717
Len Brown4be44fc2005-08-05 00:44:28 -0400718 ACPI_MEMCPY(dest_desc->buffer.pointer,
719 source_desc->buffer.pointer,
720 source_desc->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700721 }
722 break;
723
724 case ACPI_TYPE_STRING:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725 /*
726 * Allocate and copy the actual string if and only if:
727 * 1) There is a valid string pointer
Robert Moore6f42ccf2005-05-13 00:00:00 -0400728 * (Pointer to a NULL string is allowed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729 */
Robert Moore6f42ccf2005-05-13 00:00:00 -0400730 if (source_desc->string.pointer) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731 dest_desc->string.pointer =
Bob Moore83135242006-10-03 00:00:00 -0400732 ACPI_ALLOCATE((acpi_size) source_desc->string.
733 length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 if (!dest_desc->string.pointer) {
735 return (AE_NO_MEMORY);
736 }
737
Robert Moore6f42ccf2005-05-13 00:00:00 -0400738 /* Copy the actual string data */
739
Len Brown4be44fc2005-08-05 00:44:28 -0400740 ACPI_MEMCPY(dest_desc->string.pointer,
741 source_desc->string.pointer,
742 (acpi_size) source_desc->string.length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 }
744 break;
745
746 case ACPI_TYPE_LOCAL_REFERENCE:
747 /*
748 * We copied the reference object, so we now must add a reference
749 * to the object pointed to by the reference
Lin Mingbc7a36a2008-04-10 19:06:42 +0400750 *
Bob Moore1044f1f2008-09-27 11:08:41 +0800751 * DDBHandle reference (from Load/load_table) is a special reference,
752 * it does not have a Reference.Object, so does not need to
Lin Mingbc7a36a2008-04-10 19:06:42 +0400753 * increase the reference count
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 */
Bob Moore1044f1f2008-09-27 11:08:41 +0800755 if (source_desc->reference.class == ACPI_REFCLASS_TABLE) {
Lin Mingbc7a36a2008-04-10 19:06:42 +0400756 break;
757 }
758
Len Brown4be44fc2005-08-05 00:44:28 -0400759 acpi_ut_add_reference(source_desc->reference.object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700760 break;
761
Fiodor Suietov6b366e22007-02-02 19:48:18 +0300762 case ACPI_TYPE_REGION:
763 /*
764 * We copied the Region Handler, so we now must add a reference
765 */
766 if (dest_desc->region.handler) {
767 acpi_ut_add_reference(dest_desc->region.handler);
768 }
769 break;
770
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771 default:
772 /* Nothing to do for other simple objects */
773 break;
774 }
775
776 return (AE_OK);
777}
778
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779/*******************************************************************************
780 *
781 * FUNCTION: acpi_ut_copy_ielement_to_ielement
782 *
783 * PARAMETERS: acpi_pkg_callback
784 *
785 * RETURN: Status
786 *
787 * DESCRIPTION: Copy one package element to another package element
788 *
789 ******************************************************************************/
790
Robert Moore44f6c012005-04-18 22:49:35 -0400791static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400792acpi_ut_copy_ielement_to_ielement(u8 object_type,
793 union acpi_operand_object *source_object,
794 union acpi_generic_state *state,
795 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796{
Len Brown4be44fc2005-08-05 00:44:28 -0400797 acpi_status status = AE_OK;
798 u32 this_index;
799 union acpi_operand_object **this_target_ptr;
800 union acpi_operand_object *target_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700801
Len Brown4be44fc2005-08-05 00:44:28 -0400802 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
Len Brown4be44fc2005-08-05 00:44:28 -0400804 this_index = state->pkg.index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 this_target_ptr = (union acpi_operand_object **)
Len Brown4be44fc2005-08-05 00:44:28 -0400806 &state->pkg.dest_object->package.elements[this_index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807
808 switch (object_type) {
809 case ACPI_COPY_TYPE_SIMPLE:
810
811 /* A null source object indicates a (legal) null package element */
812
813 if (source_object) {
814 /*
815 * This is a simple object, just copy it
816 */
Len Brown4be44fc2005-08-05 00:44:28 -0400817 target_object =
Bob Moore3371c192009-02-18 14:44:03 +0800818 acpi_ut_create_internal_object(source_object->
819 common.type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 if (!target_object) {
821 return (AE_NO_MEMORY);
822 }
823
Len Brown4be44fc2005-08-05 00:44:28 -0400824 status =
825 acpi_ut_copy_simple_object(source_object,
826 target_object);
827 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 goto error_exit;
829 }
830
831 *this_target_ptr = target_object;
Len Brown4be44fc2005-08-05 00:44:28 -0400832 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 /* Pass through a null element */
834
835 *this_target_ptr = NULL;
836 }
837 break;
838
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839 case ACPI_COPY_TYPE_PACKAGE:
840
841 /*
842 * This object is a package - go down another nesting level
843 * Create and build the package object
844 */
Len Brown4be44fc2005-08-05 00:44:28 -0400845 target_object =
Bob Moore6287ee32007-04-03 19:59:37 -0400846 acpi_ut_create_package_object(source_object->package.count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 if (!target_object) {
848 return (AE_NO_MEMORY);
849 }
850
Linus Torvalds1da177e2005-04-16 15:20:36 -0700851 target_object->common.flags = source_object->common.flags;
852
Bob Moore6287ee32007-04-03 19:59:37 -0400853 /* Pass the new package object back to the package walk routine */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855 state->pkg.this_target_obj = target_object;
856
Bob Moore6287ee32007-04-03 19:59:37 -0400857 /* Store the object pointer in the parent package object */
858
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 *this_target_ptr = target_object;
860 break;
861
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862 default:
863 return (AE_BAD_PARAMETER);
864 }
865
866 return (status);
867
Len Brown4be44fc2005-08-05 00:44:28 -0400868 error_exit:
869 acpi_ut_remove_reference(target_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870 return (status);
871}
872
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873/*******************************************************************************
874 *
875 * FUNCTION: acpi_ut_copy_ipackage_to_ipackage
876 *
877 * PARAMETERS: *source_obj - Pointer to the source package object
878 * *dest_obj - Where the internal object is returned
879 *
880 * RETURN: Status - the status of the call
881 *
882 * DESCRIPTION: This function is called to copy an internal package object
883 * into another internal package object.
884 *
885 ******************************************************************************/
886
Robert Moore44f6c012005-04-18 22:49:35 -0400887static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400888acpi_ut_copy_ipackage_to_ipackage(union acpi_operand_object *source_obj,
889 union acpi_operand_object *dest_obj,
890 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891{
Len Brown4be44fc2005-08-05 00:44:28 -0400892 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
Bob Mooreb229cf92006-04-21 17:15:00 -0400894 ACPI_FUNCTION_TRACE(ut_copy_ipackage_to_ipackage);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700895
Bob Moore3371c192009-02-18 14:44:03 +0800896 dest_obj->common.type = source_obj->common.type;
Len Brown4be44fc2005-08-05 00:44:28 -0400897 dest_obj->common.flags = source_obj->common.flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 dest_obj->package.count = source_obj->package.count;
899
900 /*
901 * Create the object array and walk the source package tree
902 */
Bob Moore83135242006-10-03 00:00:00 -0400903 dest_obj->package.elements = ACPI_ALLOCATE_ZEROED(((acpi_size)
904 source_obj->package.
905 count +
906 1) * sizeof(void *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700907 if (!dest_obj->package.elements) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500908 ACPI_ERROR((AE_INFO, "Package allocation failure"));
Len Brown4be44fc2005-08-05 00:44:28 -0400909 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 }
911
912 /*
913 * Copy the package element-by-element by walking the package "tree".
914 * This handles nested packages of arbitrary depth.
915 */
Len Brown4be44fc2005-08-05 00:44:28 -0400916 status = acpi_ut_walk_package_tree(source_obj, dest_obj,
917 acpi_ut_copy_ielement_to_ielement,
918 walk_state);
919 if (ACPI_FAILURE(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400920
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 /* On failure, delete the destination package object */
922
Len Brown4be44fc2005-08-05 00:44:28 -0400923 acpi_ut_remove_reference(dest_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924 }
925
Len Brown4be44fc2005-08-05 00:44:28 -0400926 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927}
928
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929/*******************************************************************************
930 *
931 * FUNCTION: acpi_ut_copy_iobject_to_iobject
932 *
933 * PARAMETERS: walk_state - Current walk state
934 * source_desc - The internal object to be copied
935 * dest_desc - Where the copied object is returned
936 *
937 * RETURN: Status
938 *
939 * DESCRIPTION: Copy an internal object to a new internal object
940 *
941 ******************************************************************************/
942
943acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400944acpi_ut_copy_iobject_to_iobject(union acpi_operand_object *source_desc,
945 union acpi_operand_object **dest_desc,
946 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947{
Len Brown4be44fc2005-08-05 00:44:28 -0400948 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949
Bob Mooreb229cf92006-04-21 17:15:00 -0400950 ACPI_FUNCTION_TRACE(ut_copy_iobject_to_iobject);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951
952 /* Create the top level object */
953
Bob Moore3371c192009-02-18 14:44:03 +0800954 *dest_desc = acpi_ut_create_internal_object(source_desc->common.type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 if (!*dest_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400956 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957 }
958
959 /* Copy the object and possible subobjects */
960
Bob Moore3371c192009-02-18 14:44:03 +0800961 if (source_desc->common.type == ACPI_TYPE_PACKAGE) {
Len Brown4be44fc2005-08-05 00:44:28 -0400962 status =
963 acpi_ut_copy_ipackage_to_ipackage(source_desc, *dest_desc,
964 walk_state);
965 } else {
966 status = acpi_ut_copy_simple_object(source_desc, *dest_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967 }
968
Len Brown4be44fc2005-08-05 00:44:28 -0400969 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970}