ACPICA 20050708 from Bob Moore <robert.moore@intel.com>
[linux-2.6/verdex.git] / drivers / acpi / utilities / utcopy.c
blob31c30a32e5c9db76fe1cd47472b26d33b13c14fc
1 /******************************************************************************
3 * Module Name: utcopy - Internal to external object translation utilities
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
9 * All rights reserved.
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.
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.
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.
45 #include <acpi/acpi.h>
46 #include <acpi/amlcode.h>
49 #define _COMPONENT ACPI_UTILITIES
50 ACPI_MODULE_NAME ("utcopy")
52 /* Local prototypes */
54 static acpi_status
55 acpi_ut_copy_isimple_to_esimple (
56 union acpi_operand_object *internal_object,
57 union acpi_object *external_object,
58 u8 *data_space,
59 acpi_size *buffer_space_used);
61 static acpi_status
62 acpi_ut_copy_ielement_to_ielement (
63 u8 object_type,
64 union acpi_operand_object *source_object,
65 union acpi_generic_state *state,
66 void *context);
68 static acpi_status
69 acpi_ut_copy_ipackage_to_epackage (
70 union acpi_operand_object *internal_object,
71 u8 *buffer,
72 acpi_size *space_used);
74 static acpi_status
75 acpi_ut_copy_esimple_to_isimple(
76 union acpi_object *user_obj,
77 union acpi_operand_object **return_obj);
79 static acpi_status
80 acpi_ut_copy_simple_object (
81 union acpi_operand_object *source_desc,
82 union acpi_operand_object *dest_desc);
84 static acpi_status
85 acpi_ut_copy_ielement_to_eelement (
86 u8 object_type,
87 union acpi_operand_object *source_object,
88 union acpi_generic_state *state,
89 void *context);
91 static acpi_status
92 acpi_ut_copy_ipackage_to_ipackage (
93 union acpi_operand_object *source_obj,
94 union acpi_operand_object *dest_obj,
95 struct acpi_walk_state *walk_state);
98 /*******************************************************************************
100 * FUNCTION: acpi_ut_copy_isimple_to_esimple
102 * PARAMETERS: internal_object - Source object to be copied
103 * external_object - Where to return the copied object
104 * data_space - Where object data is returned (such as
105 * buffer and string data)
106 * buffer_space_used - Length of data_space that was used
108 * RETURN: Status
110 * DESCRIPTION: This function is called to copy a simple internal object to
111 * an external object.
113 * The data_space buffer is assumed to have sufficient space for
114 * the object.
116 ******************************************************************************/
118 static acpi_status
119 acpi_ut_copy_isimple_to_esimple (
120 union acpi_operand_object *internal_object,
121 union acpi_object *external_object,
122 u8 *data_space,
123 acpi_size *buffer_space_used)
125 acpi_status status = AE_OK;
128 ACPI_FUNCTION_TRACE ("ut_copy_isimple_to_esimple");
131 *buffer_space_used = 0;
134 * Check for NULL object case (could be an uninitialized
135 * package element)
137 if (!internal_object) {
138 return_ACPI_STATUS (AE_OK);
141 /* Always clear the external object */
143 ACPI_MEMSET (external_object, 0, sizeof (union acpi_object));
146 * In general, the external object will be the same type as
147 * the internal object
149 external_object->type = ACPI_GET_OBJECT_TYPE (internal_object);
151 /* However, only a limited number of external types are supported */
153 switch (ACPI_GET_OBJECT_TYPE (internal_object)) {
154 case ACPI_TYPE_STRING:
156 external_object->string.pointer = (char *) data_space;
157 external_object->string.length = internal_object->string.length;
158 *buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD (
159 (acpi_size) internal_object->string.length + 1);
161 ACPI_MEMCPY ((void *) data_space,
162 (void *) internal_object->string.pointer,
163 (acpi_size) internal_object->string.length + 1);
164 break;
167 case ACPI_TYPE_BUFFER:
169 external_object->buffer.pointer = data_space;
170 external_object->buffer.length = internal_object->buffer.length;
171 *buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD (
172 internal_object->string.length);
174 ACPI_MEMCPY ((void *) data_space,
175 (void *) internal_object->buffer.pointer,
176 internal_object->buffer.length);
177 break;
180 case ACPI_TYPE_INTEGER:
182 external_object->integer.value = internal_object->integer.value;
183 break;
186 case ACPI_TYPE_LOCAL_REFERENCE:
189 * This is an object reference. Attempt to dereference it.
191 switch (internal_object->reference.opcode) {
192 case AML_INT_NAMEPATH_OP:
194 /* For namepath, return the object handle ("reference") */
196 default:
198 * Use the object type of "Any" to indicate a reference
199 * to object containing a handle to an ACPI named object.
201 external_object->type = ACPI_TYPE_ANY;
202 external_object->reference.handle = internal_object->reference.node;
203 break;
205 break;
208 case ACPI_TYPE_PROCESSOR:
210 external_object->processor.proc_id = internal_object->processor.proc_id;
211 external_object->processor.pblk_address = internal_object->processor.address;
212 external_object->processor.pblk_length = internal_object->processor.length;
213 break;
216 case ACPI_TYPE_POWER:
218 external_object->power_resource.system_level =
219 internal_object->power_resource.system_level;
221 external_object->power_resource.resource_order =
222 internal_object->power_resource.resource_order;
223 break;
226 default:
228 * There is no corresponding external object type
230 return_ACPI_STATUS (AE_SUPPORT);
233 return_ACPI_STATUS (status);
237 /*******************************************************************************
239 * FUNCTION: acpi_ut_copy_ielement_to_eelement
241 * PARAMETERS: acpi_pkg_callback
243 * RETURN: Status
245 * DESCRIPTION: Copy one package element to another package element
247 ******************************************************************************/
249 static acpi_status
250 acpi_ut_copy_ielement_to_eelement (
251 u8 object_type,
252 union acpi_operand_object *source_object,
253 union acpi_generic_state *state,
254 void *context)
256 acpi_status status = AE_OK;
257 struct acpi_pkg_info *info = (struct acpi_pkg_info *) context;
258 acpi_size object_space;
259 u32 this_index;
260 union acpi_object *target_object;
263 ACPI_FUNCTION_ENTRY ();
266 this_index = state->pkg.index;
267 target_object = (union acpi_object *)
268 &((union acpi_object *)(state->pkg.dest_object))->package.elements[this_index];
270 switch (object_type) {
271 case ACPI_COPY_TYPE_SIMPLE:
274 * This is a simple or null object
276 status = acpi_ut_copy_isimple_to_esimple (source_object,
277 target_object, info->free_space, &object_space);
278 if (ACPI_FAILURE (status)) {
279 return (status);
281 break;
284 case ACPI_COPY_TYPE_PACKAGE:
287 * Build the package object
289 target_object->type = ACPI_TYPE_PACKAGE;
290 target_object->package.count = source_object->package.count;
291 target_object->package.elements =
292 ACPI_CAST_PTR (union acpi_object, info->free_space);
295 * Pass the new package object back to the package walk routine
297 state->pkg.this_target_obj = target_object;
300 * Save space for the array of objects (Package elements)
301 * update the buffer length counter
303 object_space = ACPI_ROUND_UP_TO_NATIVE_WORD (
304 (acpi_size) target_object->package.count *
305 sizeof (union acpi_object));
306 break;
309 default:
310 return (AE_BAD_PARAMETER);
313 info->free_space += object_space;
314 info->length += object_space;
315 return (status);
319 /*******************************************************************************
321 * FUNCTION: acpi_ut_copy_ipackage_to_epackage
323 * PARAMETERS: internal_object - Pointer to the object we are returning
324 * Buffer - Where the object is returned
325 * space_used - Where the object length is returned
327 * RETURN: Status
329 * DESCRIPTION: This function is called to place a package object in a user
330 * buffer. A package object by definition contains other objects.
332 * The buffer is assumed to have sufficient space for the object.
333 * The caller must have verified the buffer length needed using the
334 * acpi_ut_get_object_size function before calling this function.
336 ******************************************************************************/
338 static acpi_status
339 acpi_ut_copy_ipackage_to_epackage (
340 union acpi_operand_object *internal_object,
341 u8 *buffer,
342 acpi_size *space_used)
344 union acpi_object *external_object;
345 acpi_status status;
346 struct acpi_pkg_info info;
349 ACPI_FUNCTION_TRACE ("ut_copy_ipackage_to_epackage");
353 * First package at head of the buffer
355 external_object = ACPI_CAST_PTR (union acpi_object, buffer);
358 * Free space begins right after the first package
360 info.length = ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (union acpi_object));
361 info.free_space = buffer + ACPI_ROUND_UP_TO_NATIVE_WORD (
362 sizeof (union acpi_object));
363 info.object_space = 0;
364 info.num_packages = 1;
366 external_object->type = ACPI_GET_OBJECT_TYPE (internal_object);
367 external_object->package.count = internal_object->package.count;
368 external_object->package.elements = ACPI_CAST_PTR (union acpi_object,
369 info.free_space);
372 * Leave room for an array of ACPI_OBJECTS in the buffer
373 * and move the free space past it
375 info.length += (acpi_size) external_object->package.count *
376 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (union acpi_object));
377 info.free_space += external_object->package.count *
378 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (union acpi_object));
380 status = acpi_ut_walk_package_tree (internal_object, external_object,
381 acpi_ut_copy_ielement_to_eelement, &info);
383 *space_used = info.length;
384 return_ACPI_STATUS (status);
388 /*******************************************************************************
390 * FUNCTION: acpi_ut_copy_iobject_to_eobject
392 * PARAMETERS: internal_object - The internal object to be converted
393 * buffer_ptr - Where the object is returned
395 * RETURN: Status
397 * DESCRIPTION: This function is called to build an API object to be returned to
398 * the caller.
400 ******************************************************************************/
402 acpi_status
403 acpi_ut_copy_iobject_to_eobject (
404 union acpi_operand_object *internal_object,
405 struct acpi_buffer *ret_buffer)
407 acpi_status status;
410 ACPI_FUNCTION_TRACE ("ut_copy_iobject_to_eobject");
413 if (ACPI_GET_OBJECT_TYPE (internal_object) == ACPI_TYPE_PACKAGE) {
415 * Package object: Copy all subobjects (including
416 * nested packages)
418 status = acpi_ut_copy_ipackage_to_epackage (internal_object,
419 ret_buffer->pointer, &ret_buffer->length);
421 else {
423 * Build a simple object (no nested objects)
425 status = acpi_ut_copy_isimple_to_esimple (internal_object,
426 (union acpi_object *) ret_buffer->pointer,
427 ((u8 *) ret_buffer->pointer +
428 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (union acpi_object))),
429 &ret_buffer->length);
431 * build simple does not include the object size in the length
432 * so we add it in here
434 ret_buffer->length += sizeof (union acpi_object);
437 return_ACPI_STATUS (status);
441 /*******************************************************************************
443 * FUNCTION: acpi_ut_copy_esimple_to_isimple
445 * PARAMETERS: external_object - The external object to be converted
446 * ret_internal_object - Where the internal object is returned
448 * RETURN: Status
450 * DESCRIPTION: This function copies an external object to an internal one.
451 * NOTE: Pointers can be copied, we don't need to copy data.
452 * (The pointers have to be valid in our address space no matter
453 * what we do with them!)
455 ******************************************************************************/
457 static acpi_status
458 acpi_ut_copy_esimple_to_isimple (
459 union acpi_object *external_object,
460 union acpi_operand_object **ret_internal_object)
462 union acpi_operand_object *internal_object;
465 ACPI_FUNCTION_TRACE ("ut_copy_esimple_to_isimple");
469 * Simple types supported are: String, Buffer, Integer
471 switch (external_object->type) {
472 case ACPI_TYPE_STRING:
473 case ACPI_TYPE_BUFFER:
474 case ACPI_TYPE_INTEGER:
476 internal_object = acpi_ut_create_internal_object (
477 (u8) external_object->type);
478 if (!internal_object) {
479 return_ACPI_STATUS (AE_NO_MEMORY);
481 break;
483 default:
484 /* All other types are not supported */
486 return_ACPI_STATUS (AE_SUPPORT);
490 /* Must COPY string and buffer contents */
492 switch (external_object->type) {
493 case ACPI_TYPE_STRING:
495 internal_object->string.pointer =
496 ACPI_MEM_CALLOCATE ((acpi_size) external_object->string.length + 1);
497 if (!internal_object->string.pointer) {
498 goto error_exit;
501 ACPI_MEMCPY (internal_object->string.pointer,
502 external_object->string.pointer,
503 external_object->string.length);
505 internal_object->string.length = external_object->string.length;
506 break;
509 case ACPI_TYPE_BUFFER:
511 internal_object->buffer.pointer =
512 ACPI_MEM_CALLOCATE (external_object->buffer.length);
513 if (!internal_object->buffer.pointer) {
514 goto error_exit;
517 ACPI_MEMCPY (internal_object->buffer.pointer,
518 external_object->buffer.pointer,
519 external_object->buffer.length);
521 internal_object->buffer.length = external_object->buffer.length;
522 break;
525 case ACPI_TYPE_INTEGER:
527 internal_object->integer.value = external_object->integer.value;
528 break;
530 default:
531 /* Other types can't get here */
532 break;
535 *ret_internal_object = internal_object;
536 return_ACPI_STATUS (AE_OK);
539 error_exit:
540 acpi_ut_remove_reference (internal_object);
541 return_ACPI_STATUS (AE_NO_MEMORY);
545 #ifdef ACPI_FUTURE_IMPLEMENTATION
546 /* Code to convert packages that are parameters to control methods */
548 /*******************************************************************************
550 * FUNCTION: acpi_ut_copy_epackage_to_ipackage
552 * PARAMETERS: *internal_object - Pointer to the object we are returning
553 * *Buffer - Where the object is returned
554 * *space_used - Where the length of the object is returned
556 * RETURN: Status
558 * DESCRIPTION: This function is called to place a package object in a user
559 * buffer. A package object by definition contains other objects.
561 * The buffer is assumed to have sufficient space for the object.
562 * The caller must have verified the buffer length needed using the
563 * acpi_ut_get_object_size function before calling this function.
565 ******************************************************************************/
567 static acpi_status
568 acpi_ut_copy_epackage_to_ipackage (
569 union acpi_operand_object *internal_object,
570 u8 *buffer,
571 u32 *space_used)
573 u8 *free_space;
574 union acpi_object *external_object;
575 u32 length = 0;
576 u32 this_index;
577 u32 object_space = 0;
578 union acpi_operand_object *this_internal_obj;
579 union acpi_object *this_external_obj;
582 ACPI_FUNCTION_TRACE ("ut_copy_epackage_to_ipackage");
586 * First package at head of the buffer
588 external_object = (union acpi_object *)buffer;
591 * Free space begins right after the first package
593 free_space = buffer + sizeof(union acpi_object);
596 external_object->type = ACPI_GET_OBJECT_TYPE (internal_object);
597 external_object->package.count = internal_object->package.count;
598 external_object->package.elements = (union acpi_object *)free_space;
601 * Build an array of ACPI_OBJECTS in the buffer
602 * and move the free space past it
604 free_space += external_object->package.count * sizeof(union acpi_object);
607 /* Call walk_package */
611 #endif /* Future implementation */
614 /*******************************************************************************
616 * FUNCTION: acpi_ut_copy_eobject_to_iobject
618 * PARAMETERS: *internal_object - The external object to be converted
619 * *buffer_ptr - Where the internal object is returned
621 * RETURN: Status - the status of the call
623 * DESCRIPTION: Converts an external object to an internal object.
625 ******************************************************************************/
627 acpi_status
628 acpi_ut_copy_eobject_to_iobject (
629 union acpi_object *external_object,
630 union acpi_operand_object **internal_object)
632 acpi_status status;
635 ACPI_FUNCTION_TRACE ("ut_copy_eobject_to_iobject");
638 if (external_object->type == ACPI_TYPE_PACKAGE) {
640 * Packages as external input to control methods are not supported,
642 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
643 "Packages as parameters not implemented!\n"));
645 return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
648 else {
650 * Build a simple object (no nested objects)
652 status = acpi_ut_copy_esimple_to_isimple (external_object, internal_object);
655 return_ACPI_STATUS (status);
659 /*******************************************************************************
661 * FUNCTION: acpi_ut_copy_simple_object
663 * PARAMETERS: source_desc - The internal object to be copied
664 * dest_desc - New target object
666 * RETURN: Status
668 * DESCRIPTION: Simple copy of one internal object to another. Reference count
669 * of the destination object is preserved.
671 ******************************************************************************/
673 static acpi_status
674 acpi_ut_copy_simple_object (
675 union acpi_operand_object *source_desc,
676 union acpi_operand_object *dest_desc)
678 u16 reference_count;
679 union acpi_operand_object *next_object;
682 /* Save fields from destination that we don't want to overwrite */
684 reference_count = dest_desc->common.reference_count;
685 next_object = dest_desc->common.next_object;
687 /* Copy the entire source object over the destination object*/
689 ACPI_MEMCPY ((char *) dest_desc, (char *) source_desc,
690 sizeof (union acpi_operand_object));
692 /* Restore the saved fields */
694 dest_desc->common.reference_count = reference_count;
695 dest_desc->common.next_object = next_object;
697 /* New object is not static, regardless of source */
699 dest_desc->common.flags &= ~AOPOBJ_STATIC_POINTER;
701 /* Handle the objects with extra data */
703 switch (ACPI_GET_OBJECT_TYPE (dest_desc)) {
704 case ACPI_TYPE_BUFFER:
706 * Allocate and copy the actual buffer if and only if:
707 * 1) There is a valid buffer pointer
708 * 2) The buffer has a length > 0
710 if ((source_desc->buffer.pointer) &&
711 (source_desc->buffer.length)) {
712 dest_desc->buffer.pointer =
713 ACPI_MEM_ALLOCATE (source_desc->buffer.length);
714 if (!dest_desc->buffer.pointer) {
715 return (AE_NO_MEMORY);
718 /* Copy the actual buffer data */
720 ACPI_MEMCPY (dest_desc->buffer.pointer,
721 source_desc->buffer.pointer,
722 source_desc->buffer.length);
724 break;
726 case ACPI_TYPE_STRING:
728 * Allocate and copy the actual string if and only if:
729 * 1) There is a valid string pointer
730 * (Pointer to a NULL string is allowed)
732 if (source_desc->string.pointer) {
733 dest_desc->string.pointer =
734 ACPI_MEM_ALLOCATE ((acpi_size) source_desc->string.length + 1);
735 if (!dest_desc->string.pointer) {
736 return (AE_NO_MEMORY);
739 /* Copy the actual string data */
741 ACPI_MEMCPY (dest_desc->string.pointer, source_desc->string.pointer,
742 (acpi_size) source_desc->string.length + 1);
744 break;
746 case ACPI_TYPE_LOCAL_REFERENCE:
748 * We copied the reference object, so we now must add a reference
749 * to the object pointed to by the reference
751 acpi_ut_add_reference (source_desc->reference.object);
752 break;
754 default:
755 /* Nothing to do for other simple objects */
756 break;
759 return (AE_OK);
763 /*******************************************************************************
765 * FUNCTION: acpi_ut_copy_ielement_to_ielement
767 * PARAMETERS: acpi_pkg_callback
769 * RETURN: Status
771 * DESCRIPTION: Copy one package element to another package element
773 ******************************************************************************/
775 static acpi_status
776 acpi_ut_copy_ielement_to_ielement (
777 u8 object_type,
778 union acpi_operand_object *source_object,
779 union acpi_generic_state *state,
780 void *context)
782 acpi_status status = AE_OK;
783 u32 this_index;
784 union acpi_operand_object **this_target_ptr;
785 union acpi_operand_object *target_object;
788 ACPI_FUNCTION_ENTRY ();
791 this_index = state->pkg.index;
792 this_target_ptr = (union acpi_operand_object **)
793 &state->pkg.dest_object->package.elements[this_index];
795 switch (object_type) {
796 case ACPI_COPY_TYPE_SIMPLE:
798 /* A null source object indicates a (legal) null package element */
800 if (source_object) {
802 * This is a simple object, just copy it
804 target_object = acpi_ut_create_internal_object (
805 ACPI_GET_OBJECT_TYPE (source_object));
806 if (!target_object) {
807 return (AE_NO_MEMORY);
810 status = acpi_ut_copy_simple_object (source_object, target_object);
811 if (ACPI_FAILURE (status)) {
812 goto error_exit;
815 *this_target_ptr = target_object;
817 else {
818 /* Pass through a null element */
820 *this_target_ptr = NULL;
822 break;
825 case ACPI_COPY_TYPE_PACKAGE:
828 * This object is a package - go down another nesting level
829 * Create and build the package object
831 target_object = acpi_ut_create_internal_object (ACPI_TYPE_PACKAGE);
832 if (!target_object) {
833 return (AE_NO_MEMORY);
836 target_object->package.count = source_object->package.count;
837 target_object->common.flags = source_object->common.flags;
840 * Create the object array
842 target_object->package.elements =
843 ACPI_MEM_CALLOCATE (((acpi_size) source_object->package.count + 1) *
844 sizeof (void *));
845 if (!target_object->package.elements) {
846 status = AE_NO_MEMORY;
847 goto error_exit;
851 * Pass the new package object back to the package walk routine
853 state->pkg.this_target_obj = target_object;
856 * Store the object pointer in the parent package object
858 *this_target_ptr = target_object;
859 break;
862 default:
863 return (AE_BAD_PARAMETER);
866 return (status);
868 error_exit:
869 acpi_ut_remove_reference (target_object);
870 return (status);
874 /*******************************************************************************
876 * FUNCTION: acpi_ut_copy_ipackage_to_ipackage
878 * PARAMETERS: *source_obj - Pointer to the source package object
879 * *dest_obj - Where the internal object is returned
881 * RETURN: Status - the status of the call
883 * DESCRIPTION: This function is called to copy an internal package object
884 * into another internal package object.
886 ******************************************************************************/
888 static acpi_status
889 acpi_ut_copy_ipackage_to_ipackage (
890 union acpi_operand_object *source_obj,
891 union acpi_operand_object *dest_obj,
892 struct acpi_walk_state *walk_state)
894 acpi_status status = AE_OK;
897 ACPI_FUNCTION_TRACE ("ut_copy_ipackage_to_ipackage");
900 dest_obj->common.type = ACPI_GET_OBJECT_TYPE (source_obj);
901 dest_obj->common.flags = source_obj->common.flags;
902 dest_obj->package.count = source_obj->package.count;
905 * Create the object array and walk the source package tree
907 dest_obj->package.elements = ACPI_MEM_CALLOCATE (
908 ((acpi_size) source_obj->package.count + 1) *
909 sizeof (void *));
910 if (!dest_obj->package.elements) {
911 ACPI_REPORT_ERROR (
912 ("aml_build_copy_internal_package_object: Package allocation failure\n"));
913 return_ACPI_STATUS (AE_NO_MEMORY);
917 * Copy the package element-by-element by walking the package "tree".
918 * This handles nested packages of arbitrary depth.
920 status = acpi_ut_walk_package_tree (source_obj, dest_obj,
921 acpi_ut_copy_ielement_to_ielement, walk_state);
922 if (ACPI_FAILURE (status)) {
923 /* On failure, delete the destination package object */
925 acpi_ut_remove_reference (dest_obj);
928 return_ACPI_STATUS (status);
932 /*******************************************************************************
934 * FUNCTION: acpi_ut_copy_iobject_to_iobject
936 * PARAMETERS: walk_state - Current walk state
937 * source_desc - The internal object to be copied
938 * dest_desc - Where the copied object is returned
940 * RETURN: Status
942 * DESCRIPTION: Copy an internal object to a new internal object
944 ******************************************************************************/
946 acpi_status
947 acpi_ut_copy_iobject_to_iobject (
948 union acpi_operand_object *source_desc,
949 union acpi_operand_object **dest_desc,
950 struct acpi_walk_state *walk_state)
952 acpi_status status = AE_OK;
955 ACPI_FUNCTION_TRACE ("ut_copy_iobject_to_iobject");
958 /* Create the top level object */
960 *dest_desc = acpi_ut_create_internal_object (ACPI_GET_OBJECT_TYPE (source_desc));
961 if (!*dest_desc) {
962 return_ACPI_STATUS (AE_NO_MEMORY);
965 /* Copy the object and possible subobjects */
967 if (ACPI_GET_OBJECT_TYPE (source_desc) == ACPI_TYPE_PACKAGE) {
968 status = acpi_ut_copy_ipackage_to_ipackage (source_desc, *dest_desc,
969 walk_state);
971 else {
972 status = acpi_ut_copy_simple_object (source_desc, *dest_desc);
975 return_ACPI_STATUS (status);