blob: 4e9a62b34aeff7e05c626897f5c92e284b6d837c [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 Moore6c9deb72007-02-02 19:48:24 +03008 * Copyright (C) 2000 - 2007, 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
Bob Moore6287ee32007-04-03 19:59:37 -040071acpi_ut_copy_epackage_to_ipackage(union acpi_object *external_object,
72 union acpi_operand_object **internal_object);
73
74static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040075acpi_ut_copy_simple_object(union acpi_operand_object *source_desc,
76 union acpi_operand_object *dest_desc);
Robert Moore44f6c012005-04-18 22:49:35 -040077
78static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040079acpi_ut_copy_ielement_to_eelement(u8 object_type,
80 union acpi_operand_object *source_object,
81 union acpi_generic_state *state,
82 void *context);
Robert Moore44f6c012005-04-18 22:49:35 -040083
84static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040085acpi_ut_copy_ipackage_to_ipackage(union acpi_operand_object *source_obj,
86 union acpi_operand_object *dest_obj,
87 struct acpi_walk_state *walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -070088
89/*******************************************************************************
90 *
91 * FUNCTION: acpi_ut_copy_isimple_to_esimple
92 *
Robert Moore44f6c012005-04-18 22:49:35 -040093 * PARAMETERS: internal_object - Source object to be copied
94 * external_object - Where to return the copied object
95 * data_space - Where object data is returned (such as
96 * buffer and string data)
97 * buffer_space_used - Length of data_space that was used
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 *
99 * RETURN: Status
100 *
Robert Moore44f6c012005-04-18 22:49:35 -0400101 * DESCRIPTION: This function is called to copy a simple internal object to
102 * an external object.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 *
Robert Moore44f6c012005-04-18 22:49:35 -0400104 * The data_space buffer is assumed to have sufficient space for
105 * the object.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 *
107 ******************************************************************************/
108
109static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400110acpi_ut_copy_isimple_to_esimple(union acpi_operand_object *internal_object,
111 union acpi_object *external_object,
112 u8 * data_space, acpi_size * buffer_space_used)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113{
Len Brown4be44fc2005-08-05 00:44:28 -0400114 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
Bob Mooreb229cf92006-04-21 17:15:00 -0400116 ACPI_FUNCTION_TRACE(ut_copy_isimple_to_esimple);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118 *buffer_space_used = 0;
119
120 /*
121 * Check for NULL object case (could be an uninitialized
122 * package element)
123 */
124 if (!internal_object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400125 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 }
127
128 /* Always clear the external object */
129
Len Brown4be44fc2005-08-05 00:44:28 -0400130 ACPI_MEMSET(external_object, 0, sizeof(union acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 /*
133 * In general, the external object will be the same type as
134 * the internal object
135 */
Len Brown4be44fc2005-08-05 00:44:28 -0400136 external_object->type = ACPI_GET_OBJECT_TYPE(internal_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137
138 /* However, only a limited number of external types are supported */
139
Len Brown4be44fc2005-08-05 00:44:28 -0400140 switch (ACPI_GET_OBJECT_TYPE(internal_object)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 case ACPI_TYPE_STRING:
142
Len Brown4be44fc2005-08-05 00:44:28 -0400143 external_object->string.pointer = (char *)data_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 external_object->string.length = internal_object->string.length;
Len Brown4be44fc2005-08-05 00:44:28 -0400145 *buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD((acpi_size)
146 internal_object->
147 string.
148 length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Len Brown4be44fc2005-08-05 00:44:28 -0400150 ACPI_MEMCPY((void *)data_space,
151 (void *)internal_object->string.pointer,
152 (acpi_size) internal_object->string.length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 break;
154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 case ACPI_TYPE_BUFFER:
156
157 external_object->buffer.pointer = data_space;
158 external_object->buffer.length = internal_object->buffer.length;
Len Brown4be44fc2005-08-05 00:44:28 -0400159 *buffer_space_used =
160 ACPI_ROUND_UP_TO_NATIVE_WORD(internal_object->string.
161 length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162
Len Brown4be44fc2005-08-05 00:44:28 -0400163 ACPI_MEMCPY((void *)data_space,
164 (void *)internal_object->buffer.pointer,
165 internal_object->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 break;
167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 case ACPI_TYPE_INTEGER:
169
170 external_object->integer.value = internal_object->integer.value;
171 break;
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 case ACPI_TYPE_LOCAL_REFERENCE:
174
175 /*
176 * This is an object reference. Attempt to dereference it.
177 */
178 switch (internal_object->reference.opcode) {
179 case AML_INT_NAMEPATH_OP:
180
181 /* For namepath, return the object handle ("reference") */
182
183 default:
184 /*
185 * Use the object type of "Any" to indicate a reference
186 * to object containing a handle to an ACPI named object.
187 */
188 external_object->type = ACPI_TYPE_ANY;
Len Brown4be44fc2005-08-05 00:44:28 -0400189 external_object->reference.handle =
190 internal_object->reference.node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 break;
192 }
193 break;
194
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 case ACPI_TYPE_PROCESSOR:
196
Len Brown4be44fc2005-08-05 00:44:28 -0400197 external_object->processor.proc_id =
198 internal_object->processor.proc_id;
199 external_object->processor.pblk_address =
200 internal_object->processor.address;
201 external_object->processor.pblk_length =
202 internal_object->processor.length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 break;
204
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 case ACPI_TYPE_POWER:
206
207 external_object->power_resource.system_level =
Len Brown4be44fc2005-08-05 00:44:28 -0400208 internal_object->power_resource.system_level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
210 external_object->power_resource.resource_order =
Len Brown4be44fc2005-08-05 00:44:28 -0400211 internal_object->power_resource.resource_order;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 break;
213
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 default:
215 /*
216 * There is no corresponding external object type
217 */
Bob Mooreb1dd9092008-04-10 19:06:42 +0400218 ACPI_ERROR((AE_INFO,
219 "Unsupported object type, cannot convert to external object: %s",
220 acpi_ut_get_type_name(ACPI_GET_OBJECT_TYPE
221 (internal_object))));
222
Len Brown4be44fc2005-08-05 00:44:28 -0400223 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 }
225
Len Brown4be44fc2005-08-05 00:44:28 -0400226 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227}
228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229/*******************************************************************************
230 *
231 * FUNCTION: acpi_ut_copy_ielement_to_eelement
232 *
233 * PARAMETERS: acpi_pkg_callback
234 *
235 * RETURN: Status
236 *
237 * DESCRIPTION: Copy one package element to another package element
238 *
239 ******************************************************************************/
240
Robert Moore44f6c012005-04-18 22:49:35 -0400241static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400242acpi_ut_copy_ielement_to_eelement(u8 object_type,
243 union acpi_operand_object *source_object,
244 union acpi_generic_state *state,
245 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246{
Len Brown4be44fc2005-08-05 00:44:28 -0400247 acpi_status status = AE_OK;
248 struct acpi_pkg_info *info = (struct acpi_pkg_info *)context;
249 acpi_size object_space;
250 u32 this_index;
251 union acpi_object *target_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
Len Brown4be44fc2005-08-05 00:44:28 -0400253 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
Len Brown4be44fc2005-08-05 00:44:28 -0400255 this_index = state->pkg.index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 target_object = (union acpi_object *)
Len Brown4be44fc2005-08-05 00:44:28 -0400257 &((union acpi_object *)(state->pkg.dest_object))->package.
258 elements[this_index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
260 switch (object_type) {
261 case ACPI_COPY_TYPE_SIMPLE:
262
263 /*
264 * This is a simple or null object
265 */
Len Brown4be44fc2005-08-05 00:44:28 -0400266 status = acpi_ut_copy_isimple_to_esimple(source_object,
267 target_object,
268 info->free_space,
269 &object_space);
270 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271 return (status);
272 }
273 break;
274
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 case ACPI_COPY_TYPE_PACKAGE:
276
277 /*
278 * Build the package object
279 */
Len Brown4be44fc2005-08-05 00:44:28 -0400280 target_object->type = ACPI_TYPE_PACKAGE;
281 target_object->package.count = source_object->package.count;
Robert Moore44f6c012005-04-18 22:49:35 -0400282 target_object->package.elements =
Len Brown4be44fc2005-08-05 00:44:28 -0400283 ACPI_CAST_PTR(union acpi_object, info->free_space);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285 /*
286 * Pass the new package object back to the package walk routine
287 */
288 state->pkg.this_target_obj = target_object;
289
290 /*
291 * Save space for the array of objects (Package elements)
292 * update the buffer length counter
293 */
Len Brown4be44fc2005-08-05 00:44:28 -0400294 object_space = ACPI_ROUND_UP_TO_NATIVE_WORD((acpi_size)
295 target_object->
296 package.count *
297 sizeof(union
298 acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 break;
300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 default:
302 return (AE_BAD_PARAMETER);
303 }
304
Len Brown4be44fc2005-08-05 00:44:28 -0400305 info->free_space += object_space;
306 info->length += object_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 return (status);
308}
309
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310/*******************************************************************************
311 *
312 * FUNCTION: acpi_ut_copy_ipackage_to_epackage
313 *
Robert Moore44f6c012005-04-18 22:49:35 -0400314 * PARAMETERS: internal_object - Pointer to the object we are returning
315 * Buffer - Where the object is returned
316 * space_used - Where the object length is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 *
318 * RETURN: Status
319 *
320 * DESCRIPTION: This function is called to place a package object in a user
321 * buffer. A package object by definition contains other objects.
322 *
323 * The buffer is assumed to have sufficient space for the object.
324 * The caller must have verified the buffer length needed using the
325 * acpi_ut_get_object_size function before calling this function.
326 *
327 ******************************************************************************/
328
329static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400330acpi_ut_copy_ipackage_to_epackage(union acpi_operand_object *internal_object,
331 u8 * buffer, acpi_size * space_used)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332{
Len Brown4be44fc2005-08-05 00:44:28 -0400333 union acpi_object *external_object;
334 acpi_status status;
335 struct acpi_pkg_info info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
Bob Mooreb229cf92006-04-21 17:15:00 -0400337 ACPI_FUNCTION_TRACE(ut_copy_ipackage_to_epackage);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339 /*
340 * First package at head of the buffer
341 */
Len Brown4be44fc2005-08-05 00:44:28 -0400342 external_object = ACPI_CAST_PTR(union acpi_object, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
344 /*
345 * Free space begins right after the first package
346 */
Len Brown4be44fc2005-08-05 00:44:28 -0400347 info.length = ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object));
348 info.free_space =
349 buffer + ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 info.object_space = 0;
351 info.num_packages = 1;
352
Len Brown4be44fc2005-08-05 00:44:28 -0400353 external_object->type = ACPI_GET_OBJECT_TYPE(internal_object);
354 external_object->package.count = internal_object->package.count;
355 external_object->package.elements = ACPI_CAST_PTR(union acpi_object,
356 info.free_space);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357
358 /*
359 * Leave room for an array of ACPI_OBJECTS in the buffer
360 * and move the free space past it
361 */
Len Brown4be44fc2005-08-05 00:44:28 -0400362 info.length += (acpi_size) external_object->package.count *
363 ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 info.free_space += external_object->package.count *
Len Brown4be44fc2005-08-05 00:44:28 -0400365 ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366
Len Brown4be44fc2005-08-05 00:44:28 -0400367 status = acpi_ut_walk_package_tree(internal_object, external_object,
368 acpi_ut_copy_ielement_to_eelement,
369 &info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700370
371 *space_used = info.length;
Len Brown4be44fc2005-08-05 00:44:28 -0400372 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373}
374
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375/*******************************************************************************
376 *
377 * FUNCTION: acpi_ut_copy_iobject_to_eobject
378 *
Robert Moore44f6c012005-04-18 22:49:35 -0400379 * PARAMETERS: internal_object - The internal object to be converted
380 * buffer_ptr - Where the object is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 *
382 * RETURN: Status
383 *
384 * DESCRIPTION: This function is called to build an API object to be returned to
385 * the caller.
386 *
387 ******************************************************************************/
388
389acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400390acpi_ut_copy_iobject_to_eobject(union acpi_operand_object *internal_object,
391 struct acpi_buffer *ret_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392{
Len Brown4be44fc2005-08-05 00:44:28 -0400393 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394
Bob Mooreb229cf92006-04-21 17:15:00 -0400395 ACPI_FUNCTION_TRACE(ut_copy_iobject_to_eobject);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Len Brown4be44fc2005-08-05 00:44:28 -0400397 if (ACPI_GET_OBJECT_TYPE(internal_object) == ACPI_TYPE_PACKAGE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398 /*
399 * Package object: Copy all subobjects (including
400 * nested packages)
401 */
Len Brown4be44fc2005-08-05 00:44:28 -0400402 status = acpi_ut_copy_ipackage_to_epackage(internal_object,
403 ret_buffer->pointer,
404 &ret_buffer->length);
405 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 /*
407 * Build a simple object (no nested objects)
408 */
Len Brown4be44fc2005-08-05 00:44:28 -0400409 status = acpi_ut_copy_isimple_to_esimple(internal_object,
Bob Moorec51a4de2005-11-17 13:07:00 -0500410 ACPI_CAST_PTR(union
411 acpi_object,
412 ret_buffer->
413 pointer),
414 ACPI_ADD_PTR(u8,
415 ret_buffer->
416 pointer,
417 ACPI_ROUND_UP_TO_NATIVE_WORD
418 (sizeof
419 (union
420 acpi_object))),
Len Brown4be44fc2005-08-05 00:44:28 -0400421 &ret_buffer->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422 /*
423 * build simple does not include the object size in the length
424 * so we add it in here
425 */
Len Brown4be44fc2005-08-05 00:44:28 -0400426 ret_buffer->length += sizeof(union acpi_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427 }
428
Len Brown4be44fc2005-08-05 00:44:28 -0400429 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430}
431
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432/*******************************************************************************
433 *
434 * FUNCTION: acpi_ut_copy_esimple_to_isimple
435 *
Robert Moore44f6c012005-04-18 22:49:35 -0400436 * PARAMETERS: external_object - The external object to be converted
437 * ret_internal_object - Where the internal object is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 *
439 * RETURN: Status
440 *
441 * DESCRIPTION: This function copies an external object to an internal one.
442 * NOTE: Pointers can be copied, we don't need to copy data.
443 * (The pointers have to be valid in our address space no matter
444 * what we do with them!)
445 *
446 ******************************************************************************/
447
Robert Moore44f6c012005-04-18 22:49:35 -0400448static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400449acpi_ut_copy_esimple_to_isimple(union acpi_object *external_object,
450 union acpi_operand_object **ret_internal_object)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451{
Len Brown4be44fc2005-08-05 00:44:28 -0400452 union acpi_operand_object *internal_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Bob Mooreb229cf92006-04-21 17:15:00 -0400454 ACPI_FUNCTION_TRACE(ut_copy_esimple_to_isimple);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455
456 /*
457 * Simple types supported are: String, Buffer, Integer
458 */
459 switch (external_object->type) {
460 case ACPI_TYPE_STRING:
461 case ACPI_TYPE_BUFFER:
462 case ACPI_TYPE_INTEGER:
463
Len Brown4be44fc2005-08-05 00:44:28 -0400464 internal_object = acpi_ut_create_internal_object((u8)
465 external_object->
466 type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467 if (!internal_object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400468 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 }
470 break;
471
472 default:
473 /* All other types are not supported */
474
Bob Mooreb1dd9092008-04-10 19:06:42 +0400475 ACPI_ERROR((AE_INFO,
476 "Unsupported object type, cannot convert to internal object: %s",
477 acpi_ut_get_type_name(external_object->type)));
478
Len Brown4be44fc2005-08-05 00:44:28 -0400479 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480 }
481
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 /* Must COPY string and buffer contents */
483
484 switch (external_object->type) {
485 case ACPI_TYPE_STRING:
486
487 internal_object->string.pointer =
Bob Moore83135242006-10-03 00:00:00 -0400488 ACPI_ALLOCATE_ZEROED((acpi_size) external_object->string.
489 length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 if (!internal_object->string.pointer) {
491 goto error_exit;
492 }
493
Len Brown4be44fc2005-08-05 00:44:28 -0400494 ACPI_MEMCPY(internal_object->string.pointer,
495 external_object->string.pointer,
496 external_object->string.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
498 internal_object->string.length = external_object->string.length;
499 break;
500
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 case ACPI_TYPE_BUFFER:
502
503 internal_object->buffer.pointer =
Bob Moore83135242006-10-03 00:00:00 -0400504 ACPI_ALLOCATE_ZEROED(external_object->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 if (!internal_object->buffer.pointer) {
506 goto error_exit;
507 }
508
Len Brown4be44fc2005-08-05 00:44:28 -0400509 ACPI_MEMCPY(internal_object->buffer.pointer,
510 external_object->buffer.pointer,
511 external_object->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
513 internal_object->buffer.length = external_object->buffer.length;
Bob Moore24a31572008-04-10 19:06:43 +0400514
515 /* Mark buffer data valid */
516
517 internal_object->buffer.flags |= AOPOBJ_DATA_VALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 break;
519
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520 case ACPI_TYPE_INTEGER:
521
Len Brown4be44fc2005-08-05 00:44:28 -0400522 internal_object->integer.value = external_object->integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 break;
524
525 default:
526 /* Other types can't get here */
527 break;
528 }
529
530 *ret_internal_object = internal_object;
Len Brown4be44fc2005-08-05 00:44:28 -0400531 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
Len Brown4be44fc2005-08-05 00:44:28 -0400533 error_exit:
534 acpi_ut_remove_reference(internal_object);
535 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536}
537
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538/*******************************************************************************
539 *
540 * FUNCTION: acpi_ut_copy_epackage_to_ipackage
541 *
Bob Moore6287ee32007-04-03 19:59:37 -0400542 * PARAMETERS: external_object - The external object to be converted
543 * internal_object - Where the internal object is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 *
545 * RETURN: Status
546 *
Bob Moore6287ee32007-04-03 19:59:37 -0400547 * DESCRIPTION: Copy an external package object to an internal package.
548 * Handles nested packages.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 *
550 ******************************************************************************/
551
552static acpi_status
Bob Moore6287ee32007-04-03 19:59:37 -0400553acpi_ut_copy_epackage_to_ipackage(union acpi_object *external_object,
554 union acpi_operand_object **internal_object)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555{
Bob Moore6287ee32007-04-03 19:59:37 -0400556 acpi_status status = AE_OK;
557 union acpi_operand_object *package_object;
558 union acpi_operand_object **package_elements;
559 acpi_native_uint i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560
Bob Mooreb229cf92006-04-21 17:15:00 -0400561 ACPI_FUNCTION_TRACE(ut_copy_epackage_to_ipackage);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562
Bob Moore6287ee32007-04-03 19:59:37 -0400563 /* Create the package object */
564
565 package_object =
566 acpi_ut_create_package_object(external_object->package.count);
567 if (!package_object) {
568 return_ACPI_STATUS(AE_NO_MEMORY);
569 }
570
571 package_elements = package_object->package.elements;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
573 /*
Bob Moore6287ee32007-04-03 19:59:37 -0400574 * Recursive implementation. Probably ok, since nested external packages
575 * as parameters should be very rare.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 */
Bob Moore6287ee32007-04-03 19:59:37 -0400577 for (i = 0; i < external_object->package.count; i++) {
578 status =
579 acpi_ut_copy_eobject_to_iobject(&external_object->package.
580 elements[i],
581 &package_elements[i]);
582 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Bob Moore6287ee32007-04-03 19:59:37 -0400584 /* Truncate package and delete it */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
Bob Moore1d18c052008-04-10 19:06:40 +0400586 package_object->package.count = (u32) i;
Bob Moore6287ee32007-04-03 19:59:37 -0400587 package_elements[i] = NULL;
588 acpi_ut_remove_reference(package_object);
589 return_ACPI_STATUS(status);
590 }
591 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
Bob Moore24a31572008-04-10 19:06:43 +0400593 /* Mark package data valid */
594
595 package_object->package.flags |= AOPOBJ_DATA_VALID;
596
Bob Moore6287ee32007-04-03 19:59:37 -0400597 *internal_object = package_object;
598 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599}
600
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601/*******************************************************************************
602 *
603 * FUNCTION: acpi_ut_copy_eobject_to_iobject
604 *
Bob Moore6287ee32007-04-03 19:59:37 -0400605 * PARAMETERS: external_object - The external object to be converted
606 * internal_object - Where the internal object is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 *
Bob Moore6287ee32007-04-03 19:59:37 -0400608 * RETURN: Status - the status of the call
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 *
610 * DESCRIPTION: Converts an external object to an internal object.
611 *
612 ******************************************************************************/
613
614acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400615acpi_ut_copy_eobject_to_iobject(union acpi_object *external_object,
616 union acpi_operand_object **internal_object)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617{
Len Brown4be44fc2005-08-05 00:44:28 -0400618 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619
Bob Mooreb229cf92006-04-21 17:15:00 -0400620 ACPI_FUNCTION_TRACE(ut_copy_eobject_to_iobject);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621
622 if (external_object->type == ACPI_TYPE_PACKAGE) {
Bob Moore6287ee32007-04-03 19:59:37 -0400623 status =
624 acpi_ut_copy_epackage_to_ipackage(external_object,
625 internal_object);
626 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 /*
628 * Build a simple object (no nested objects)
629 */
Len Brown4be44fc2005-08-05 00:44:28 -0400630 status =
631 acpi_ut_copy_esimple_to_isimple(external_object,
632 internal_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 }
634
Len Brown4be44fc2005-08-05 00:44:28 -0400635 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636}
637
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638/*******************************************************************************
639 *
640 * FUNCTION: acpi_ut_copy_simple_object
641 *
642 * PARAMETERS: source_desc - The internal object to be copied
643 * dest_desc - New target object
644 *
645 * RETURN: Status
646 *
647 * DESCRIPTION: Simple copy of one internal object to another. Reference count
648 * of the destination object is preserved.
649 *
650 ******************************************************************************/
651
Robert Moore44f6c012005-04-18 22:49:35 -0400652static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400653acpi_ut_copy_simple_object(union acpi_operand_object *source_desc,
654 union acpi_operand_object *dest_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655{
Len Brown4be44fc2005-08-05 00:44:28 -0400656 u16 reference_count;
657 union acpi_operand_object *next_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
659 /* Save fields from destination that we don't want to overwrite */
660
661 reference_count = dest_desc->common.reference_count;
662 next_object = dest_desc->common.next_object;
663
Len Brown4be44fc2005-08-05 00:44:28 -0400664 /* Copy the entire source object over the destination object */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665
Len Brown4be44fc2005-08-05 00:44:28 -0400666 ACPI_MEMCPY((char *)dest_desc, (char *)source_desc,
667 sizeof(union acpi_operand_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668
669 /* Restore the saved fields */
670
671 dest_desc->common.reference_count = reference_count;
672 dest_desc->common.next_object = next_object;
673
Robert Moore6f42ccf2005-05-13 00:00:00 -0400674 /* New object is not static, regardless of source */
675
676 dest_desc->common.flags &= ~AOPOBJ_STATIC_POINTER;
677
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 /* Handle the objects with extra data */
679
Len Brown4be44fc2005-08-05 00:44:28 -0400680 switch (ACPI_GET_OBJECT_TYPE(dest_desc)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681 case ACPI_TYPE_BUFFER:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 /*
683 * Allocate and copy the actual buffer if and only if:
684 * 1) There is a valid buffer pointer
Robert Moore6f42ccf2005-05-13 00:00:00 -0400685 * 2) The buffer has a length > 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 */
687 if ((source_desc->buffer.pointer) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400688 (source_desc->buffer.length)) {
Robert Moore6f42ccf2005-05-13 00:00:00 -0400689 dest_desc->buffer.pointer =
Bob Moore83135242006-10-03 00:00:00 -0400690 ACPI_ALLOCATE(source_desc->buffer.length);
Robert Moore6f42ccf2005-05-13 00:00:00 -0400691 if (!dest_desc->buffer.pointer) {
692 return (AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700693 }
Robert Moore6f42ccf2005-05-13 00:00:00 -0400694
695 /* Copy the actual buffer data */
696
Len Brown4be44fc2005-08-05 00:44:28 -0400697 ACPI_MEMCPY(dest_desc->buffer.pointer,
698 source_desc->buffer.pointer,
699 source_desc->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 }
701 break;
702
703 case ACPI_TYPE_STRING:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700704 /*
705 * Allocate and copy the actual string if and only if:
706 * 1) There is a valid string pointer
Robert Moore6f42ccf2005-05-13 00:00:00 -0400707 * (Pointer to a NULL string is allowed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 */
Robert Moore6f42ccf2005-05-13 00:00:00 -0400709 if (source_desc->string.pointer) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700710 dest_desc->string.pointer =
Bob Moore83135242006-10-03 00:00:00 -0400711 ACPI_ALLOCATE((acpi_size) source_desc->string.
712 length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 if (!dest_desc->string.pointer) {
714 return (AE_NO_MEMORY);
715 }
716
Robert Moore6f42ccf2005-05-13 00:00:00 -0400717 /* Copy the actual string data */
718
Len Brown4be44fc2005-08-05 00:44:28 -0400719 ACPI_MEMCPY(dest_desc->string.pointer,
720 source_desc->string.pointer,
721 (acpi_size) source_desc->string.length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 }
723 break;
724
725 case ACPI_TYPE_LOCAL_REFERENCE:
726 /*
727 * We copied the reference object, so we now must add a reference
728 * to the object pointed to by the reference
Lin Mingbc7a36a2008-04-10 19:06:42 +0400729 *
730 * DDBHandle reference (from Load/load_table is a special reference,
731 * it's Reference.Object is the table index, so does not need to
732 * increase the reference count
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 */
Lin Mingbc7a36a2008-04-10 19:06:42 +0400734 if (source_desc->reference.opcode == AML_LOAD_OP) {
735 break;
736 }
737
Len Brown4be44fc2005-08-05 00:44:28 -0400738 acpi_ut_add_reference(source_desc->reference.object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739 break;
740
Fiodor Suietov6b366e22007-02-02 19:48:18 +0300741 case ACPI_TYPE_REGION:
742 /*
743 * We copied the Region Handler, so we now must add a reference
744 */
745 if (dest_desc->region.handler) {
746 acpi_ut_add_reference(dest_desc->region.handler);
747 }
748 break;
749
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 default:
751 /* Nothing to do for other simple objects */
752 break;
753 }
754
755 return (AE_OK);
756}
757
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758/*******************************************************************************
759 *
760 * FUNCTION: acpi_ut_copy_ielement_to_ielement
761 *
762 * PARAMETERS: acpi_pkg_callback
763 *
764 * RETURN: Status
765 *
766 * DESCRIPTION: Copy one package element to another package element
767 *
768 ******************************************************************************/
769
Robert Moore44f6c012005-04-18 22:49:35 -0400770static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400771acpi_ut_copy_ielement_to_ielement(u8 object_type,
772 union acpi_operand_object *source_object,
773 union acpi_generic_state *state,
774 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700775{
Len Brown4be44fc2005-08-05 00:44:28 -0400776 acpi_status status = AE_OK;
777 u32 this_index;
778 union acpi_operand_object **this_target_ptr;
779 union acpi_operand_object *target_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
Len Brown4be44fc2005-08-05 00:44:28 -0400781 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
Len Brown4be44fc2005-08-05 00:44:28 -0400783 this_index = state->pkg.index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784 this_target_ptr = (union acpi_operand_object **)
Len Brown4be44fc2005-08-05 00:44:28 -0400785 &state->pkg.dest_object->package.elements[this_index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786
787 switch (object_type) {
788 case ACPI_COPY_TYPE_SIMPLE:
789
790 /* A null source object indicates a (legal) null package element */
791
792 if (source_object) {
793 /*
794 * This is a simple object, just copy it
795 */
Len Brown4be44fc2005-08-05 00:44:28 -0400796 target_object =
797 acpi_ut_create_internal_object(ACPI_GET_OBJECT_TYPE
798 (source_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 if (!target_object) {
800 return (AE_NO_MEMORY);
801 }
802
Len Brown4be44fc2005-08-05 00:44:28 -0400803 status =
804 acpi_ut_copy_simple_object(source_object,
805 target_object);
806 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 goto error_exit;
808 }
809
810 *this_target_ptr = target_object;
Len Brown4be44fc2005-08-05 00:44:28 -0400811 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 /* Pass through a null element */
813
814 *this_target_ptr = NULL;
815 }
816 break;
817
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 case ACPI_COPY_TYPE_PACKAGE:
819
820 /*
821 * This object is a package - go down another nesting level
822 * Create and build the package object
823 */
Len Brown4be44fc2005-08-05 00:44:28 -0400824 target_object =
Bob Moore6287ee32007-04-03 19:59:37 -0400825 acpi_ut_create_package_object(source_object->package.count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826 if (!target_object) {
827 return (AE_NO_MEMORY);
828 }
829
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830 target_object->common.flags = source_object->common.flags;
831
Bob Moore6287ee32007-04-03 19:59:37 -0400832 /* Pass the new package object back to the package walk routine */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 state->pkg.this_target_obj = target_object;
835
Bob Moore6287ee32007-04-03 19:59:37 -0400836 /* Store the object pointer in the parent package object */
837
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 *this_target_ptr = target_object;
839 break;
840
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841 default:
842 return (AE_BAD_PARAMETER);
843 }
844
845 return (status);
846
Len Brown4be44fc2005-08-05 00:44:28 -0400847 error_exit:
848 acpi_ut_remove_reference(target_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849 return (status);
850}
851
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852/*******************************************************************************
853 *
854 * FUNCTION: acpi_ut_copy_ipackage_to_ipackage
855 *
856 * PARAMETERS: *source_obj - Pointer to the source package object
857 * *dest_obj - Where the internal object is returned
858 *
859 * RETURN: Status - the status of the call
860 *
861 * DESCRIPTION: This function is called to copy an internal package object
862 * into another internal package object.
863 *
864 ******************************************************************************/
865
Robert Moore44f6c012005-04-18 22:49:35 -0400866static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400867acpi_ut_copy_ipackage_to_ipackage(union acpi_operand_object *source_obj,
868 union acpi_operand_object *dest_obj,
869 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870{
Len Brown4be44fc2005-08-05 00:44:28 -0400871 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872
Bob Mooreb229cf92006-04-21 17:15:00 -0400873 ACPI_FUNCTION_TRACE(ut_copy_ipackage_to_ipackage);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874
Len Brown4be44fc2005-08-05 00:44:28 -0400875 dest_obj->common.type = ACPI_GET_OBJECT_TYPE(source_obj);
876 dest_obj->common.flags = source_obj->common.flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 dest_obj->package.count = source_obj->package.count;
878
879 /*
880 * Create the object array and walk the source package tree
881 */
Bob Moore83135242006-10-03 00:00:00 -0400882 dest_obj->package.elements = ACPI_ALLOCATE_ZEROED(((acpi_size)
883 source_obj->package.
884 count +
885 1) * sizeof(void *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886 if (!dest_obj->package.elements) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500887 ACPI_ERROR((AE_INFO, "Package allocation failure"));
Len Brown4be44fc2005-08-05 00:44:28 -0400888 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 }
890
891 /*
892 * Copy the package element-by-element by walking the package "tree".
893 * This handles nested packages of arbitrary depth.
894 */
Len Brown4be44fc2005-08-05 00:44:28 -0400895 status = acpi_ut_walk_package_tree(source_obj, dest_obj,
896 acpi_ut_copy_ielement_to_ielement,
897 walk_state);
898 if (ACPI_FAILURE(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400899
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 /* On failure, delete the destination package object */
901
Len Brown4be44fc2005-08-05 00:44:28 -0400902 acpi_ut_remove_reference(dest_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 }
904
Len Brown4be44fc2005-08-05 00:44:28 -0400905 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906}
907
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908/*******************************************************************************
909 *
910 * FUNCTION: acpi_ut_copy_iobject_to_iobject
911 *
912 * PARAMETERS: walk_state - Current walk state
913 * source_desc - The internal object to be copied
914 * dest_desc - Where the copied object is returned
915 *
916 * RETURN: Status
917 *
918 * DESCRIPTION: Copy an internal object to a new internal object
919 *
920 ******************************************************************************/
921
922acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400923acpi_ut_copy_iobject_to_iobject(union acpi_operand_object *source_desc,
924 union acpi_operand_object **dest_desc,
925 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926{
Len Brown4be44fc2005-08-05 00:44:28 -0400927 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
Bob Mooreb229cf92006-04-21 17:15:00 -0400929 ACPI_FUNCTION_TRACE(ut_copy_iobject_to_iobject);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
931 /* Create the top level object */
932
Len Brown4be44fc2005-08-05 00:44:28 -0400933 *dest_desc =
934 acpi_ut_create_internal_object(ACPI_GET_OBJECT_TYPE(source_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 if (!*dest_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400936 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937 }
938
939 /* Copy the object and possible subobjects */
940
Len Brown4be44fc2005-08-05 00:44:28 -0400941 if (ACPI_GET_OBJECT_TYPE(source_desc) == ACPI_TYPE_PACKAGE) {
942 status =
943 acpi_ut_copy_ipackage_to_ipackage(source_desc, *dest_desc,
944 walk_state);
945 } else {
946 status = acpi_ut_copy_simple_object(source_desc, *dest_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 }
948
Len Brown4be44fc2005-08-05 00:44:28 -0400949 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950}