Merge master.kernel.org:/pub/scm/linux/kernel/git/sam/kbuild
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / acpi / utilities / utcopy.c
1 /******************************************************************************
2 *
3 * Module Name: utcopy - Internal to external object translation utilities
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2005, R. Byron Moore
9 * 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
44
45 #include <acpi/acpi.h>
46 #include <acpi/amlcode.h>
47
48
49 #define _COMPONENT ACPI_UTILITIES
50 ACPI_MODULE_NAME ("utcopy")
51
52 /* Local prototypes */
53
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);
60
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);
67
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);
73
74 static acpi_status
75 acpi_ut_copy_esimple_to_isimple(
76 union acpi_object *user_obj,
77 union acpi_operand_object **return_obj);
78
79 static acpi_status
80 acpi_ut_copy_simple_object (
81 union acpi_operand_object *source_desc,
82 union acpi_operand_object *dest_desc);
83
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);
90
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);
96
97
98 /*******************************************************************************
99 *
100 * FUNCTION: acpi_ut_copy_isimple_to_esimple
101 *
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
107 *
108 * RETURN: Status
109 *
110 * DESCRIPTION: This function is called to copy a simple internal object to
111 * an external object.
112 *
113 * The data_space buffer is assumed to have sufficient space for
114 * the object.
115 *
116 ******************************************************************************/
117
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)
124 {
125 acpi_status status = AE_OK;
126
127
128 ACPI_FUNCTION_TRACE ("ut_copy_isimple_to_esimple");
129
130
131 *buffer_space_used = 0;
132
133 /*
134 * Check for NULL object case (could be an uninitialized
135 * package element)
136 */
137 if (!internal_object) {
138 return_ACPI_STATUS (AE_OK);
139 }
140
141 /* Always clear the external object */
142
143 ACPI_MEMSET (external_object, 0, sizeof (union acpi_object));
144
145 /*
146 * In general, the external object will be the same type as
147 * the internal object
148 */
149 external_object->type = ACPI_GET_OBJECT_TYPE (internal_object);
150
151 /* However, only a limited number of external types are supported */
152
153 switch (ACPI_GET_OBJECT_TYPE (internal_object)) {
154 case ACPI_TYPE_STRING:
155
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);
160
161 ACPI_MEMCPY ((void *) data_space,
162 (void *) internal_object->string.pointer,
163 (acpi_size) internal_object->string.length + 1);
164 break;
165
166
167 case ACPI_TYPE_BUFFER:
168
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);
173
174 ACPI_MEMCPY ((void *) data_space,
175 (void *) internal_object->buffer.pointer,
176 internal_object->buffer.length);
177 break;
178
179
180 case ACPI_TYPE_INTEGER:
181
182 external_object->integer.value = internal_object->integer.value;
183 break;
184
185
186 case ACPI_TYPE_LOCAL_REFERENCE:
187
188 /*
189 * This is an object reference. Attempt to dereference it.
190 */
191 switch (internal_object->reference.opcode) {
192 case AML_INT_NAMEPATH_OP:
193
194 /* For namepath, return the object handle ("reference") */
195
196 default:
197 /*
198 * Use the object type of "Any" to indicate a reference
199 * to object containing a handle to an ACPI named object.
200 */
201 external_object->type = ACPI_TYPE_ANY;
202 external_object->reference.handle = internal_object->reference.node;
203 break;
204 }
205 break;
206
207
208 case ACPI_TYPE_PROCESSOR:
209
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;
214
215
216 case ACPI_TYPE_POWER:
217
218 external_object->power_resource.system_level =
219 internal_object->power_resource.system_level;
220
221 external_object->power_resource.resource_order =
222 internal_object->power_resource.resource_order;
223 break;
224
225
226 default:
227 /*
228 * There is no corresponding external object type
229 */
230 return_ACPI_STATUS (AE_SUPPORT);
231 }
232
233 return_ACPI_STATUS (status);
234 }
235
236
237 /*******************************************************************************
238 *
239 * FUNCTION: acpi_ut_copy_ielement_to_eelement
240 *
241 * PARAMETERS: acpi_pkg_callback
242 *
243 * RETURN: Status
244 *
245 * DESCRIPTION: Copy one package element to another package element
246 *
247 ******************************************************************************/
248
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)
255 {
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;
261
262
263 ACPI_FUNCTION_ENTRY ();
264
265
266 this_index = state->pkg.index;
267 target_object = (union acpi_object *)
268 &((union acpi_object *)(state->pkg.dest_object))->package.elements[this_index];
269
270 switch (object_type) {
271 case ACPI_COPY_TYPE_SIMPLE:
272
273 /*
274 * This is a simple or null object
275 */
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);
280 }
281 break;
282
283
284 case ACPI_COPY_TYPE_PACKAGE:
285
286 /*
287 * Build the package object
288 */
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);
293
294 /*
295 * Pass the new package object back to the package walk routine
296 */
297 state->pkg.this_target_obj = target_object;
298
299 /*
300 * Save space for the array of objects (Package elements)
301 * update the buffer length counter
302 */
303 object_space = ACPI_ROUND_UP_TO_NATIVE_WORD (
304 (acpi_size) target_object->package.count *
305 sizeof (union acpi_object));
306 break;
307
308
309 default:
310 return (AE_BAD_PARAMETER);
311 }
312
313 info->free_space += object_space;
314 info->length += object_space;
315 return (status);
316 }
317
318
319 /*******************************************************************************
320 *
321 * FUNCTION: acpi_ut_copy_ipackage_to_epackage
322 *
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
326 *
327 * RETURN: Status
328 *
329 * DESCRIPTION: This function is called to place a package object in a user
330 * buffer. A package object by definition contains other objects.
331 *
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.
335 *
336 ******************************************************************************/
337
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)
343 {
344 union acpi_object *external_object;
345 acpi_status status;
346 struct acpi_pkg_info info;
347
348
349 ACPI_FUNCTION_TRACE ("ut_copy_ipackage_to_epackage");
350
351
352 /*
353 * First package at head of the buffer
354 */
355 external_object = ACPI_CAST_PTR (union acpi_object, buffer);
356
357 /*
358 * Free space begins right after the first package
359 */
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;
365
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);
370
371 /*
372 * Leave room for an array of ACPI_OBJECTS in the buffer
373 * and move the free space past it
374 */
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));
379
380 status = acpi_ut_walk_package_tree (internal_object, external_object,
381 acpi_ut_copy_ielement_to_eelement, &info);
382
383 *space_used = info.length;
384 return_ACPI_STATUS (status);
385 }
386
387
388 /*******************************************************************************
389 *
390 * FUNCTION: acpi_ut_copy_iobject_to_eobject
391 *
392 * PARAMETERS: internal_object - The internal object to be converted
393 * buffer_ptr - Where the object is returned
394 *
395 * RETURN: Status
396 *
397 * DESCRIPTION: This function is called to build an API object to be returned to
398 * the caller.
399 *
400 ******************************************************************************/
401
402 acpi_status
403 acpi_ut_copy_iobject_to_eobject (
404 union acpi_operand_object *internal_object,
405 struct acpi_buffer *ret_buffer)
406 {
407 acpi_status status;
408
409
410 ACPI_FUNCTION_TRACE ("ut_copy_iobject_to_eobject");
411
412
413 if (ACPI_GET_OBJECT_TYPE (internal_object) == ACPI_TYPE_PACKAGE) {
414 /*
415 * Package object: Copy all subobjects (including
416 * nested packages)
417 */
418 status = acpi_ut_copy_ipackage_to_epackage (internal_object,
419 ret_buffer->pointer, &ret_buffer->length);
420 }
421 else {
422 /*
423 * Build a simple object (no nested objects)
424 */
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);
430 /*
431 * build simple does not include the object size in the length
432 * so we add it in here
433 */
434 ret_buffer->length += sizeof (union acpi_object);
435 }
436
437 return_ACPI_STATUS (status);
438 }
439
440
441 /*******************************************************************************
442 *
443 * FUNCTION: acpi_ut_copy_esimple_to_isimple
444 *
445 * PARAMETERS: external_object - The external object to be converted
446 * ret_internal_object - Where the internal object is returned
447 *
448 * RETURN: Status
449 *
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!)
454 *
455 ******************************************************************************/
456
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)
461 {
462 union acpi_operand_object *internal_object;
463
464
465 ACPI_FUNCTION_TRACE ("ut_copy_esimple_to_isimple");
466
467
468 /*
469 * Simple types supported are: String, Buffer, Integer
470 */
471 switch (external_object->type) {
472 case ACPI_TYPE_STRING:
473 case ACPI_TYPE_BUFFER:
474 case ACPI_TYPE_INTEGER:
475
476 internal_object = acpi_ut_create_internal_object (
477 (u8) external_object->type);
478 if (!internal_object) {
479 return_ACPI_STATUS (AE_NO_MEMORY);
480 }
481 break;
482
483 default:
484 /* All other types are not supported */
485
486 return_ACPI_STATUS (AE_SUPPORT);
487 }
488
489
490 /* Must COPY string and buffer contents */
491
492 switch (external_object->type) {
493 case ACPI_TYPE_STRING:
494
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;
499 }
500
501 ACPI_MEMCPY (internal_object->string.pointer,
502 external_object->string.pointer,
503 external_object->string.length);
504
505 internal_object->string.length = external_object->string.length;
506 break;
507
508
509 case ACPI_TYPE_BUFFER:
510
511 internal_object->buffer.pointer =
512 ACPI_MEM_CALLOCATE (external_object->buffer.length);
513 if (!internal_object->buffer.pointer) {
514 goto error_exit;
515 }
516
517 ACPI_MEMCPY (internal_object->buffer.pointer,
518 external_object->buffer.pointer,
519 external_object->buffer.length);
520
521 internal_object->buffer.length = external_object->buffer.length;
522 break;
523
524
525 case ACPI_TYPE_INTEGER:
526
527 internal_object->integer.value = external_object->integer.value;
528 break;
529
530 default:
531 /* Other types can't get here */
532 break;
533 }
534
535 *ret_internal_object = internal_object;
536 return_ACPI_STATUS (AE_OK);
537
538
539 error_exit:
540 acpi_ut_remove_reference (internal_object);
541 return_ACPI_STATUS (AE_NO_MEMORY);
542 }
543
544
545 #ifdef ACPI_FUTURE_IMPLEMENTATION
546 /* Code to convert packages that are parameters to control methods */
547
548 /*******************************************************************************
549 *
550 * FUNCTION: acpi_ut_copy_epackage_to_ipackage
551 *
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
555 *
556 * RETURN: Status
557 *
558 * DESCRIPTION: This function is called to place a package object in a user
559 * buffer. A package object by definition contains other objects.
560 *
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.
564 *
565 ******************************************************************************/
566
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)
572 {
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;
580
581
582 ACPI_FUNCTION_TRACE ("ut_copy_epackage_to_ipackage");
583
584
585 /*
586 * First package at head of the buffer
587 */
588 external_object = (union acpi_object *)buffer;
589
590 /*
591 * Free space begins right after the first package
592 */
593 free_space = buffer + sizeof(union acpi_object);
594
595
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;
599
600 /*
601 * Build an array of ACPI_OBJECTS in the buffer
602 * and move the free space past it
603 */
604 free_space += external_object->package.count * sizeof(union acpi_object);
605
606
607 /* Call walk_package */
608
609 }
610
611 #endif /* Future implementation */
612
613
614 /*******************************************************************************
615 *
616 * FUNCTION: acpi_ut_copy_eobject_to_iobject
617 *
618 * PARAMETERS: *internal_object - The external object to be converted
619 * *buffer_ptr - Where the internal object is returned
620 *
621 * RETURN: Status - the status of the call
622 *
623 * DESCRIPTION: Converts an external object to an internal object.
624 *
625 ******************************************************************************/
626
627 acpi_status
628 acpi_ut_copy_eobject_to_iobject (
629 union acpi_object *external_object,
630 union acpi_operand_object **internal_object)
631 {
632 acpi_status status;
633
634
635 ACPI_FUNCTION_TRACE ("ut_copy_eobject_to_iobject");
636
637
638 if (external_object->type == ACPI_TYPE_PACKAGE) {
639 /*
640 * Packages as external input to control methods are not supported,
641 */
642 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
643 "Packages as parameters not implemented!\n"));
644
645 return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
646 }
647
648 else {
649 /*
650 * Build a simple object (no nested objects)
651 */
652 status = acpi_ut_copy_esimple_to_isimple (external_object, internal_object);
653 }
654
655 return_ACPI_STATUS (status);
656 }
657
658
659 /*******************************************************************************
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
673 static acpi_status
674 acpi_ut_copy_simple_object (
675 union acpi_operand_object *source_desc,
676 union acpi_operand_object *dest_desc)
677 {
678 u16 reference_count;
679 union acpi_operand_object *next_object;
680
681
682 /* Save fields from destination that we don't want to overwrite */
683
684 reference_count = dest_desc->common.reference_count;
685 next_object = dest_desc->common.next_object;
686
687 /* Copy the entire source object over the destination object*/
688
689 ACPI_MEMCPY ((char *) dest_desc, (char *) source_desc,
690 sizeof (union acpi_operand_object));
691
692 /* Restore the saved fields */
693
694 dest_desc->common.reference_count = reference_count;
695 dest_desc->common.next_object = next_object;
696
697 /* Handle the objects with extra data */
698
699 switch (ACPI_GET_OBJECT_TYPE (dest_desc)) {
700 case ACPI_TYPE_BUFFER:
701
702 dest_desc->buffer.node = NULL;
703 dest_desc->common.flags = source_desc->common.flags;
704
705 /*
706 * Allocate and copy the actual buffer if and only if:
707 * 1) There is a valid buffer pointer
708 * 2) The buffer is not static (not in an ACPI table) (in this case,
709 * the actual pointer was already copied above)
710 */
711 if ((source_desc->buffer.pointer) &&
712 (!(source_desc->common.flags & AOPOBJ_STATIC_POINTER))) {
713 dest_desc->buffer.pointer = NULL;
714
715 /* Create an actual buffer only if length > 0 */
716
717 if (source_desc->buffer.length) {
718 dest_desc->buffer.pointer =
719 ACPI_MEM_ALLOCATE (source_desc->buffer.length);
720 if (!dest_desc->buffer.pointer) {
721 return (AE_NO_MEMORY);
722 }
723
724 /* Copy the actual buffer data */
725
726 ACPI_MEMCPY (dest_desc->buffer.pointer,
727 source_desc->buffer.pointer,
728 source_desc->buffer.length);
729 }
730 }
731 break;
732
733 case ACPI_TYPE_STRING:
734
735 /*
736 * Allocate and copy the actual string if and only if:
737 * 1) There is a valid string pointer
738 * 2) The string is not static (not in an ACPI table) (in this case,
739 * the actual pointer was already copied above)
740 */
741 if ((source_desc->string.pointer) &&
742 (!(source_desc->common.flags & AOPOBJ_STATIC_POINTER))) {
743 dest_desc->string.pointer =
744 ACPI_MEM_ALLOCATE ((acpi_size) source_desc->string.length + 1);
745 if (!dest_desc->string.pointer) {
746 return (AE_NO_MEMORY);
747 }
748
749 ACPI_MEMCPY (dest_desc->string.pointer, source_desc->string.pointer,
750 (acpi_size) source_desc->string.length + 1);
751 }
752 break;
753
754 case ACPI_TYPE_LOCAL_REFERENCE:
755 /*
756 * We copied the reference object, so we now must add a reference
757 * to the object pointed to by the reference
758 */
759 acpi_ut_add_reference (source_desc->reference.object);
760 break;
761
762 default:
763 /* Nothing to do for other simple objects */
764 break;
765 }
766
767 return (AE_OK);
768 }
769
770
771 /*******************************************************************************
772 *
773 * FUNCTION: acpi_ut_copy_ielement_to_ielement
774 *
775 * PARAMETERS: acpi_pkg_callback
776 *
777 * RETURN: Status
778 *
779 * DESCRIPTION: Copy one package element to another package element
780 *
781 ******************************************************************************/
782
783 static acpi_status
784 acpi_ut_copy_ielement_to_ielement (
785 u8 object_type,
786 union acpi_operand_object *source_object,
787 union acpi_generic_state *state,
788 void *context)
789 {
790 acpi_status status = AE_OK;
791 u32 this_index;
792 union acpi_operand_object **this_target_ptr;
793 union acpi_operand_object *target_object;
794
795
796 ACPI_FUNCTION_ENTRY ();
797
798
799 this_index = state->pkg.index;
800 this_target_ptr = (union acpi_operand_object **)
801 &state->pkg.dest_object->package.elements[this_index];
802
803 switch (object_type) {
804 case ACPI_COPY_TYPE_SIMPLE:
805
806 /* A null source object indicates a (legal) null package element */
807
808 if (source_object) {
809 /*
810 * This is a simple object, just copy it
811 */
812 target_object = acpi_ut_create_internal_object (
813 ACPI_GET_OBJECT_TYPE (source_object));
814 if (!target_object) {
815 return (AE_NO_MEMORY);
816 }
817
818 status = acpi_ut_copy_simple_object (source_object, target_object);
819 if (ACPI_FAILURE (status)) {
820 goto error_exit;
821 }
822
823 *this_target_ptr = target_object;
824 }
825 else {
826 /* Pass through a null element */
827
828 *this_target_ptr = NULL;
829 }
830 break;
831
832
833 case ACPI_COPY_TYPE_PACKAGE:
834
835 /*
836 * This object is a package - go down another nesting level
837 * Create and build the package object
838 */
839 target_object = acpi_ut_create_internal_object (ACPI_TYPE_PACKAGE);
840 if (!target_object) {
841 return (AE_NO_MEMORY);
842 }
843
844 target_object->package.count = source_object->package.count;
845 target_object->common.flags = source_object->common.flags;
846
847 /*
848 * Create the object array
849 */
850 target_object->package.elements =
851 ACPI_MEM_CALLOCATE (((acpi_size) source_object->package.count + 1) *
852 sizeof (void *));
853 if (!target_object->package.elements) {
854 status = AE_NO_MEMORY;
855 goto error_exit;
856 }
857
858 /*
859 * Pass the new package object back to the package walk routine
860 */
861 state->pkg.this_target_obj = target_object;
862
863 /*
864 * Store the object pointer in the parent package object
865 */
866 *this_target_ptr = target_object;
867 break;
868
869
870 default:
871 return (AE_BAD_PARAMETER);
872 }
873
874 return (status);
875
876 error_exit:
877 acpi_ut_remove_reference (target_object);
878 return (status);
879 }
880
881
882 /*******************************************************************************
883 *
884 * FUNCTION: acpi_ut_copy_ipackage_to_ipackage
885 *
886 * PARAMETERS: *source_obj - Pointer to the source package object
887 * *dest_obj - Where the internal object is returned
888 *
889 * RETURN: Status - the status of the call
890 *
891 * DESCRIPTION: This function is called to copy an internal package object
892 * into another internal package object.
893 *
894 ******************************************************************************/
895
896 static acpi_status
897 acpi_ut_copy_ipackage_to_ipackage (
898 union acpi_operand_object *source_obj,
899 union acpi_operand_object *dest_obj,
900 struct acpi_walk_state *walk_state)
901 {
902 acpi_status status = AE_OK;
903
904
905 ACPI_FUNCTION_TRACE ("ut_copy_ipackage_to_ipackage");
906
907
908 dest_obj->common.type = ACPI_GET_OBJECT_TYPE (source_obj);
909 dest_obj->common.flags = source_obj->common.flags;
910 dest_obj->package.count = source_obj->package.count;
911
912 /*
913 * Create the object array and walk the source package tree
914 */
915 dest_obj->package.elements = ACPI_MEM_CALLOCATE (
916 ((acpi_size) source_obj->package.count + 1) *
917 sizeof (void *));
918 if (!dest_obj->package.elements) {
919 ACPI_REPORT_ERROR (
920 ("aml_build_copy_internal_package_object: Package allocation failure\n"));
921 return_ACPI_STATUS (AE_NO_MEMORY);
922 }
923
924 /*
925 * Copy the package element-by-element by walking the package "tree".
926 * This handles nested packages of arbitrary depth.
927 */
928 status = acpi_ut_walk_package_tree (source_obj, dest_obj,
929 acpi_ut_copy_ielement_to_ielement, walk_state);
930 if (ACPI_FAILURE (status)) {
931 /* On failure, delete the destination package object */
932
933 acpi_ut_remove_reference (dest_obj);
934 }
935
936 return_ACPI_STATUS (status);
937 }
938
939
940 /*******************************************************************************
941 *
942 * FUNCTION: acpi_ut_copy_iobject_to_iobject
943 *
944 * PARAMETERS: walk_state - Current walk state
945 * source_desc - The internal object to be copied
946 * dest_desc - Where the copied object is returned
947 *
948 * RETURN: Status
949 *
950 * DESCRIPTION: Copy an internal object to a new internal object
951 *
952 ******************************************************************************/
953
954 acpi_status
955 acpi_ut_copy_iobject_to_iobject (
956 union acpi_operand_object *source_desc,
957 union acpi_operand_object **dest_desc,
958 struct acpi_walk_state *walk_state)
959 {
960 acpi_status status = AE_OK;
961
962
963 ACPI_FUNCTION_TRACE ("ut_copy_iobject_to_iobject");
964
965
966 /* Create the top level object */
967
968 *dest_desc = acpi_ut_create_internal_object (ACPI_GET_OBJECT_TYPE (source_desc));
969 if (!*dest_desc) {
970 return_ACPI_STATUS (AE_NO_MEMORY);
971 }
972
973 /* Copy the object and possible subobjects */
974
975 if (ACPI_GET_OBJECT_TYPE (source_desc) == ACPI_TYPE_PACKAGE) {
976 status = acpi_ut_copy_ipackage_to_ipackage (source_desc, *dest_desc,
977 walk_state);
978 }
979 else {
980 status = acpi_ut_copy_simple_object (source_desc, *dest_desc);
981 }
982
983 return_ACPI_STATUS (status);
984 }
985
986