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
53 /*******************************************************************************
54 *
55 * FUNCTION: acpi_ut_copy_isimple_to_esimple
56 *
57 * PARAMETERS: *internal_object - Pointer to the object we are examining
58 * *Buffer - Where the object is returned
59 * *space_used - Where the data length is returned
60 *
61 * RETURN: Status
62 *
63 * DESCRIPTION: This function is called to place a simple object in a user
64 * buffer.
65 *
66 * The buffer is assumed to have sufficient space for the object.
67 *
68 ******************************************************************************/
69
70 static acpi_status
71 acpi_ut_copy_isimple_to_esimple (
72 union acpi_operand_object *internal_object,
73 union acpi_object *external_object,
74 u8 *data_space,
75 acpi_size *buffer_space_used)
76 {
77 acpi_status status = AE_OK;
78
79
80 ACPI_FUNCTION_TRACE ("ut_copy_isimple_to_esimple");
81
82
83 *buffer_space_used = 0;
84
85 /*
86 * Check for NULL object case (could be an uninitialized
87 * package element)
88 */
89 if (!internal_object) {
90 return_ACPI_STATUS (AE_OK);
91 }
92
93 /* Always clear the external object */
94
95 ACPI_MEMSET (external_object, 0, sizeof (union acpi_object));
96
97 /*
98 * In general, the external object will be the same type as
99 * the internal object
100 */
101 external_object->type = ACPI_GET_OBJECT_TYPE (internal_object);
102
103 /* However, only a limited number of external types are supported */
104
105 switch (ACPI_GET_OBJECT_TYPE (internal_object)) {
106 case ACPI_TYPE_STRING:
107
108 external_object->string.pointer = (char *) data_space;
109 external_object->string.length = internal_object->string.length;
110 *buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD ((acpi_size) internal_object->string.length + 1);
111
112 ACPI_MEMCPY ((void *) data_space, (void *) internal_object->string.pointer,
113 (acpi_size) internal_object->string.length + 1);
114 break;
115
116
117 case ACPI_TYPE_BUFFER:
118
119 external_object->buffer.pointer = data_space;
120 external_object->buffer.length = internal_object->buffer.length;
121 *buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD (internal_object->string.length);
122
123 ACPI_MEMCPY ((void *) data_space, (void *) internal_object->buffer.pointer,
124 internal_object->buffer.length);
125 break;
126
127
128 case ACPI_TYPE_INTEGER:
129
130 external_object->integer.value = internal_object->integer.value;
131 break;
132
133
134 case ACPI_TYPE_LOCAL_REFERENCE:
135
136 /*
137 * This is an object reference. Attempt to dereference it.
138 */
139 switch (internal_object->reference.opcode) {
140 case AML_INT_NAMEPATH_OP:
141
142 /* For namepath, return the object handle ("reference") */
143
144 default:
145 /*
146 * Use the object type of "Any" to indicate a reference
147 * to object containing a handle to an ACPI named object.
148 */
149 external_object->type = ACPI_TYPE_ANY;
150 external_object->reference.handle = internal_object->reference.node;
151 break;
152 }
153 break;
154
155
156 case ACPI_TYPE_PROCESSOR:
157
158 external_object->processor.proc_id = internal_object->processor.proc_id;
159 external_object->processor.pblk_address = internal_object->processor.address;
160 external_object->processor.pblk_length = internal_object->processor.length;
161 break;
162
163
164 case ACPI_TYPE_POWER:
165
166 external_object->power_resource.system_level =
167 internal_object->power_resource.system_level;
168
169 external_object->power_resource.resource_order =
170 internal_object->power_resource.resource_order;
171 break;
172
173
174 default:
175 /*
176 * There is no corresponding external object type
177 */
178 return_ACPI_STATUS (AE_SUPPORT);
179 }
180
181 return_ACPI_STATUS (status);
182 }
183
184
185 /*******************************************************************************
186 *
187 * FUNCTION: acpi_ut_copy_ielement_to_eelement
188 *
189 * PARAMETERS: acpi_pkg_callback
190 *
191 * RETURN: Status
192 *
193 * DESCRIPTION: Copy one package element to another package element
194 *
195 ******************************************************************************/
196
197 acpi_status
198 acpi_ut_copy_ielement_to_eelement (
199 u8 object_type,
200 union acpi_operand_object *source_object,
201 union acpi_generic_state *state,
202 void *context)
203 {
204 acpi_status status = AE_OK;
205 struct acpi_pkg_info *info = (struct acpi_pkg_info *) context;
206 acpi_size object_space;
207 u32 this_index;
208 union acpi_object *target_object;
209
210
211 ACPI_FUNCTION_ENTRY ();
212
213
214 this_index = state->pkg.index;
215 target_object = (union acpi_object *)
216 &((union acpi_object *)(state->pkg.dest_object))->package.elements[this_index];
217
218 switch (object_type) {
219 case ACPI_COPY_TYPE_SIMPLE:
220
221 /*
222 * This is a simple or null object
223 */
224 status = acpi_ut_copy_isimple_to_esimple (source_object,
225 target_object, info->free_space, &object_space);
226 if (ACPI_FAILURE (status)) {
227 return (status);
228 }
229 break;
230
231
232 case ACPI_COPY_TYPE_PACKAGE:
233
234 /*
235 * Build the package object
236 */
237 target_object->type = ACPI_TYPE_PACKAGE;
238 target_object->package.count = source_object->package.count;
239 target_object->package.elements = ACPI_CAST_PTR (union acpi_object, info->free_space);
240
241 /*
242 * Pass the new package object back to the package walk routine
243 */
244 state->pkg.this_target_obj = target_object;
245
246 /*
247 * Save space for the array of objects (Package elements)
248 * update the buffer length counter
249 */
250 object_space = ACPI_ROUND_UP_TO_NATIVE_WORD (
251 (acpi_size) target_object->package.count * sizeof (union acpi_object));
252 break;
253
254
255 default:
256 return (AE_BAD_PARAMETER);
257 }
258
259 info->free_space += object_space;
260 info->length += object_space;
261 return (status);
262 }
263
264
265 /*******************************************************************************
266 *
267 * FUNCTION: acpi_ut_copy_ipackage_to_epackage
268 *
269 * PARAMETERS: *internal_object - Pointer to the object we are returning
270 * *Buffer - Where the object is returned
271 * *space_used - Where the object length is returned
272 *
273 * RETURN: Status
274 *
275 * DESCRIPTION: This function is called to place a package object in a user
276 * buffer. A package object by definition contains other objects.
277 *
278 * The buffer is assumed to have sufficient space for the object.
279 * The caller must have verified the buffer length needed using the
280 * acpi_ut_get_object_size function before calling this function.
281 *
282 ******************************************************************************/
283
284 static acpi_status
285 acpi_ut_copy_ipackage_to_epackage (
286 union acpi_operand_object *internal_object,
287 u8 *buffer,
288 acpi_size *space_used)
289 {
290 union acpi_object *external_object;
291 acpi_status status;
292 struct acpi_pkg_info info;
293
294
295 ACPI_FUNCTION_TRACE ("ut_copy_ipackage_to_epackage");
296
297
298 /*
299 * First package at head of the buffer
300 */
301 external_object = ACPI_CAST_PTR (union acpi_object, buffer);
302
303 /*
304 * Free space begins right after the first package
305 */
306 info.length = ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (union acpi_object));
307 info.free_space = buffer + ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (union acpi_object));
308 info.object_space = 0;
309 info.num_packages = 1;
310
311 external_object->type = ACPI_GET_OBJECT_TYPE (internal_object);
312 external_object->package.count = internal_object->package.count;
313 external_object->package.elements = ACPI_CAST_PTR (union acpi_object, info.free_space);
314
315 /*
316 * Leave room for an array of ACPI_OBJECTS in the buffer
317 * and move the free space past it
318 */
319 info.length += (acpi_size) external_object->package.count *
320 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (union acpi_object));
321 info.free_space += external_object->package.count *
322 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (union acpi_object));
323
324 status = acpi_ut_walk_package_tree (internal_object, external_object,
325 acpi_ut_copy_ielement_to_eelement, &info);
326
327 *space_used = info.length;
328 return_ACPI_STATUS (status);
329 }
330
331
332 /*******************************************************************************
333 *
334 * FUNCTION: acpi_ut_copy_iobject_to_eobject
335 *
336 * PARAMETERS: *internal_object - The internal object to be converted
337 * *buffer_ptr - Where the object is returned
338 *
339 * RETURN: Status
340 *
341 * DESCRIPTION: This function is called to build an API object to be returned to
342 * the caller.
343 *
344 ******************************************************************************/
345
346 acpi_status
347 acpi_ut_copy_iobject_to_eobject (
348 union acpi_operand_object *internal_object,
349 struct acpi_buffer *ret_buffer)
350 {
351 acpi_status status;
352
353
354 ACPI_FUNCTION_TRACE ("ut_copy_iobject_to_eobject");
355
356
357 if (ACPI_GET_OBJECT_TYPE (internal_object) == ACPI_TYPE_PACKAGE) {
358 /*
359 * Package object: Copy all subobjects (including
360 * nested packages)
361 */
362 status = acpi_ut_copy_ipackage_to_epackage (internal_object,
363 ret_buffer->pointer, &ret_buffer->length);
364 }
365 else {
366 /*
367 * Build a simple object (no nested objects)
368 */
369 status = acpi_ut_copy_isimple_to_esimple (internal_object,
370 (union acpi_object *) ret_buffer->pointer,
371 ((u8 *) ret_buffer->pointer +
372 ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (union acpi_object))),
373 &ret_buffer->length);
374 /*
375 * build simple does not include the object size in the length
376 * so we add it in here
377 */
378 ret_buffer->length += sizeof (union acpi_object);
379 }
380
381 return_ACPI_STATUS (status);
382 }
383
384
385 /*******************************************************************************
386 *
387 * FUNCTION: acpi_ut_copy_esimple_to_isimple
388 *
389 * PARAMETERS: *external_object - The external object to be converted
390 * *internal_object - Where the internal object is returned
391 *
392 * RETURN: Status
393 *
394 * DESCRIPTION: This function copies an external object to an internal one.
395 * NOTE: Pointers can be copied, we don't need to copy data.
396 * (The pointers have to be valid in our address space no matter
397 * what we do with them!)
398 *
399 ******************************************************************************/
400
401 acpi_status
402 acpi_ut_copy_esimple_to_isimple (
403 union acpi_object *external_object,
404 union acpi_operand_object **ret_internal_object)
405 {
406 union acpi_operand_object *internal_object;
407
408
409 ACPI_FUNCTION_TRACE ("ut_copy_esimple_to_isimple");
410
411
412 /*
413 * Simple types supported are: String, Buffer, Integer
414 */
415 switch (external_object->type) {
416 case ACPI_TYPE_STRING:
417 case ACPI_TYPE_BUFFER:
418 case ACPI_TYPE_INTEGER:
419
420 internal_object = acpi_ut_create_internal_object ((u8) external_object->type);
421 if (!internal_object) {
422 return_ACPI_STATUS (AE_NO_MEMORY);
423 }
424 break;
425
426 default:
427 /* All other types are not supported */
428
429 return_ACPI_STATUS (AE_SUPPORT);
430 }
431
432
433 /* Must COPY string and buffer contents */
434
435 switch (external_object->type) {
436 case ACPI_TYPE_STRING:
437
438 internal_object->string.pointer =
439 ACPI_MEM_CALLOCATE ((acpi_size) external_object->string.length + 1);
440 if (!internal_object->string.pointer) {
441 goto error_exit;
442 }
443
444 ACPI_MEMCPY (internal_object->string.pointer,
445 external_object->string.pointer,
446 external_object->string.length);
447
448 internal_object->string.length = external_object->string.length;
449 break;
450
451
452 case ACPI_TYPE_BUFFER:
453
454 internal_object->buffer.pointer =
455 ACPI_MEM_CALLOCATE (external_object->buffer.length);
456 if (!internal_object->buffer.pointer) {
457 goto error_exit;
458 }
459
460 ACPI_MEMCPY (internal_object->buffer.pointer,
461 external_object->buffer.pointer,
462 external_object->buffer.length);
463
464 internal_object->buffer.length = external_object->buffer.length;
465 break;
466
467
468 case ACPI_TYPE_INTEGER:
469
470 internal_object->integer.value = external_object->integer.value;
471 break;
472
473 default:
474 /* Other types can't get here */
475 break;
476 }
477
478 *ret_internal_object = internal_object;
479 return_ACPI_STATUS (AE_OK);
480
481
482 error_exit:
483 acpi_ut_remove_reference (internal_object);
484 return_ACPI_STATUS (AE_NO_MEMORY);
485 }
486
487
488 #ifdef ACPI_FUTURE_IMPLEMENTATION
489
490 /* Code to convert packages that are parameters to control methods */
491
492 /*******************************************************************************
493 *
494 * FUNCTION: acpi_ut_copy_epackage_to_ipackage
495 *
496 * PARAMETERS: *internal_object - Pointer to the object we are returning
497 * *Buffer - Where the object is returned
498 * *space_used - Where the length of the object is returned
499 *
500 * RETURN: Status
501 *
502 * DESCRIPTION: This function is called to place a package object in a user
503 * buffer. A package object by definition contains other objects.
504 *
505 * The buffer is assumed to have sufficient space for the object.
506 * The caller must have verified the buffer length needed using the
507 * acpi_ut_get_object_size function before calling this function.
508 *
509 ******************************************************************************/
510
511 static acpi_status
512 acpi_ut_copy_epackage_to_ipackage (
513 union acpi_operand_object *internal_object,
514 u8 *buffer,
515 u32 *space_used)
516 {
517 u8 *free_space;
518 union acpi_object *external_object;
519 u32 length = 0;
520 u32 this_index;
521 u32 object_space = 0;
522 union acpi_operand_object *this_internal_obj;
523 union acpi_object *this_external_obj;
524
525
526 ACPI_FUNCTION_TRACE ("ut_copy_epackage_to_ipackage");
527
528
529 /*
530 * First package at head of the buffer
531 */
532 external_object = (union acpi_object *)buffer;
533
534 /*
535 * Free space begins right after the first package
536 */
537 free_space = buffer + sizeof(union acpi_object);
538
539
540 external_object->type = ACPI_GET_OBJECT_TYPE (internal_object);
541 external_object->package.count = internal_object->package.count;
542 external_object->package.elements = (union acpi_object *)free_space;
543
544 /*
545 * Build an array of ACPI_OBJECTS in the buffer
546 * and move the free space past it
547 */
548 free_space += external_object->package.count * sizeof(union acpi_object);
549
550
551 /* Call walk_package */
552
553 }
554
555 #endif /* Future implementation */
556
557
558 /*******************************************************************************
559 *
560 * FUNCTION: acpi_ut_copy_eobject_to_iobject
561 *
562 * PARAMETERS: *internal_object - The external object to be converted
563 * *buffer_ptr - Where the internal object is returned
564 *
565 * RETURN: Status - the status of the call
566 *
567 * DESCRIPTION: Converts an external object to an internal object.
568 *
569 ******************************************************************************/
570
571 acpi_status
572 acpi_ut_copy_eobject_to_iobject (
573 union acpi_object *external_object,
574 union acpi_operand_object **internal_object)
575 {
576 acpi_status status;
577
578
579 ACPI_FUNCTION_TRACE ("ut_copy_eobject_to_iobject");
580
581
582 if (external_object->type == ACPI_TYPE_PACKAGE) {
583 /*
584 * Packages as external input to control methods are not supported,
585 */
586 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
587 "Packages as parameters not implemented!\n"));
588
589 return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
590 }
591
592 else {
593 /*
594 * Build a simple object (no nested objects)
595 */
596 status = acpi_ut_copy_esimple_to_isimple (external_object, internal_object);
597 }
598
599 return_ACPI_STATUS (status);
600 }
601
602
603 /*******************************************************************************
604 *
605 * FUNCTION: acpi_ut_copy_simple_object
606 *
607 * PARAMETERS: source_desc - The internal object to be copied
608 * dest_desc - New target object
609 *
610 * RETURN: Status
611 *
612 * DESCRIPTION: Simple copy of one internal object to another. Reference count
613 * of the destination object is preserved.
614 *
615 ******************************************************************************/
616
617 acpi_status
618 acpi_ut_copy_simple_object (
619 union acpi_operand_object *source_desc,
620 union acpi_operand_object *dest_desc)
621 {
622 u16 reference_count;
623 union acpi_operand_object *next_object;
624
625
626 /* Save fields from destination that we don't want to overwrite */
627
628 reference_count = dest_desc->common.reference_count;
629 next_object = dest_desc->common.next_object;
630
631 /* Copy the entire source object over the destination object*/
632
633 ACPI_MEMCPY ((char *) dest_desc, (char *) source_desc,
634 sizeof (union acpi_operand_object));
635
636 /* Restore the saved fields */
637
638 dest_desc->common.reference_count = reference_count;
639 dest_desc->common.next_object = next_object;
640
641 /* Handle the objects with extra data */
642
643 switch (ACPI_GET_OBJECT_TYPE (dest_desc)) {
644 case ACPI_TYPE_BUFFER:
645
646 dest_desc->buffer.node = NULL;
647 dest_desc->common.flags = source_desc->common.flags;
648
649 /*
650 * Allocate and copy the actual buffer if and only if:
651 * 1) There is a valid buffer pointer
652 * 2) The buffer is not static (not in an ACPI table) (in this case,
653 * the actual pointer was already copied above)
654 */
655 if ((source_desc->buffer.pointer) &&
656 (!(source_desc->common.flags & AOPOBJ_STATIC_POINTER))) {
657 dest_desc->buffer.pointer = NULL;
658
659 /* Create an actual buffer only if length > 0 */
660
661 if (source_desc->buffer.length) {
662 dest_desc->buffer.pointer = ACPI_MEM_ALLOCATE (source_desc->buffer.length);
663 if (!dest_desc->buffer.pointer) {
664 return (AE_NO_MEMORY);
665 }
666
667 /* Copy the actual buffer data */
668
669 ACPI_MEMCPY (dest_desc->buffer.pointer, source_desc->buffer.pointer,
670 source_desc->buffer.length);
671 }
672 }
673 break;
674
675 case ACPI_TYPE_STRING:
676
677 /*
678 * Allocate and copy the actual string if and only if:
679 * 1) There is a valid string pointer
680 * 2) The string is not static (not in an ACPI table) (in this case,
681 * the actual pointer was already copied above)
682 */
683 if ((source_desc->string.pointer) &&
684 (!(source_desc->common.flags & AOPOBJ_STATIC_POINTER))) {
685 dest_desc->string.pointer = ACPI_MEM_ALLOCATE ((acpi_size) source_desc->string.length + 1);
686 if (!dest_desc->string.pointer) {
687 return (AE_NO_MEMORY);
688 }
689
690 ACPI_MEMCPY (dest_desc->string.pointer, source_desc->string.pointer,
691 (acpi_size) source_desc->string.length + 1);
692 }
693 break;
694
695 default:
696 /* Nothing to do for other simple objects */
697 break;
698 }
699
700 return (AE_OK);
701 }
702
703
704 /*******************************************************************************
705 *
706 * FUNCTION: acpi_ut_copy_ielement_to_ielement
707 *
708 * PARAMETERS: acpi_pkg_callback
709 *
710 * RETURN: Status
711 *
712 * DESCRIPTION: Copy one package element to another package element
713 *
714 ******************************************************************************/
715
716 acpi_status
717 acpi_ut_copy_ielement_to_ielement (
718 u8 object_type,
719 union acpi_operand_object *source_object,
720 union acpi_generic_state *state,
721 void *context)
722 {
723 acpi_status status = AE_OK;
724 u32 this_index;
725 union acpi_operand_object **this_target_ptr;
726 union acpi_operand_object *target_object;
727
728
729 ACPI_FUNCTION_ENTRY ();
730
731
732 this_index = state->pkg.index;
733 this_target_ptr = (union acpi_operand_object **)
734 &state->pkg.dest_object->package.elements[this_index];
735
736 switch (object_type) {
737 case ACPI_COPY_TYPE_SIMPLE:
738
739 /* A null source object indicates a (legal) null package element */
740
741 if (source_object) {
742 /*
743 * This is a simple object, just copy it
744 */
745 target_object = acpi_ut_create_internal_object (
746 ACPI_GET_OBJECT_TYPE (source_object));
747 if (!target_object) {
748 return (AE_NO_MEMORY);
749 }
750
751 status = acpi_ut_copy_simple_object (source_object, target_object);
752 if (ACPI_FAILURE (status)) {
753 goto error_exit;
754 }
755
756 *this_target_ptr = target_object;
757 }
758 else {
759 /* Pass through a null element */
760
761 *this_target_ptr = NULL;
762 }
763 break;
764
765
766 case ACPI_COPY_TYPE_PACKAGE:
767
768 /*
769 * This object is a package - go down another nesting level
770 * Create and build the package object
771 */
772 target_object = acpi_ut_create_internal_object (ACPI_TYPE_PACKAGE);
773 if (!target_object) {
774 return (AE_NO_MEMORY);
775 }
776
777 target_object->package.count = source_object->package.count;
778 target_object->common.flags = source_object->common.flags;
779
780 /*
781 * Create the object array
782 */
783 target_object->package.elements =
784 ACPI_MEM_CALLOCATE (((acpi_size) source_object->package.count + 1) *
785 sizeof (void *));
786 if (!target_object->package.elements) {
787 status = AE_NO_MEMORY;
788 goto error_exit;
789 }
790
791 /*
792 * Pass the new package object back to the package walk routine
793 */
794 state->pkg.this_target_obj = target_object;
795
796 /*
797 * Store the object pointer in the parent package object
798 */
799 *this_target_ptr = target_object;
800 break;
801
802
803 default:
804 return (AE_BAD_PARAMETER);
805 }
806
807 return (status);
808
809 error_exit:
810 acpi_ut_remove_reference (target_object);
811 return (status);
812 }
813
814
815 /*******************************************************************************
816 *
817 * FUNCTION: acpi_ut_copy_ipackage_to_ipackage
818 *
819 * PARAMETERS: *source_obj - Pointer to the source package object
820 * *dest_obj - Where the internal object is returned
821 *
822 * RETURN: Status - the status of the call
823 *
824 * DESCRIPTION: This function is called to copy an internal package object
825 * into another internal package object.
826 *
827 ******************************************************************************/
828
829 acpi_status
830 acpi_ut_copy_ipackage_to_ipackage (
831 union acpi_operand_object *source_obj,
832 union acpi_operand_object *dest_obj,
833 struct acpi_walk_state *walk_state)
834 {
835 acpi_status status = AE_OK;
836
837
838 ACPI_FUNCTION_TRACE ("ut_copy_ipackage_to_ipackage");
839
840
841 dest_obj->common.type = ACPI_GET_OBJECT_TYPE (source_obj);
842 dest_obj->common.flags = source_obj->common.flags;
843 dest_obj->package.count = source_obj->package.count;
844
845 /*
846 * Create the object array and walk the source package tree
847 */
848 dest_obj->package.elements = ACPI_MEM_CALLOCATE (
849 ((acpi_size) source_obj->package.count + 1) *
850 sizeof (void *));
851 if (!dest_obj->package.elements) {
852 ACPI_REPORT_ERROR (
853 ("aml_build_copy_internal_package_object: Package allocation failure\n"));
854 return_ACPI_STATUS (AE_NO_MEMORY);
855 }
856
857 /*
858 * Copy the package element-by-element by walking the package "tree".
859 * This handles nested packages of arbitrary depth.
860 */
861 status = acpi_ut_walk_package_tree (source_obj, dest_obj,
862 acpi_ut_copy_ielement_to_ielement, walk_state);
863 if (ACPI_FAILURE (status)) {
864 /* On failure, delete the destination package object */
865
866 acpi_ut_remove_reference (dest_obj);
867 }
868
869 return_ACPI_STATUS (status);
870 }
871
872
873 /*******************************************************************************
874 *
875 * FUNCTION: acpi_ut_copy_iobject_to_iobject
876 *
877 * PARAMETERS: walk_state - Current walk state
878 * source_desc - The internal object to be copied
879 * dest_desc - Where the copied object is returned
880 *
881 * RETURN: Status
882 *
883 * DESCRIPTION: Copy an internal object to a new internal object
884 *
885 ******************************************************************************/
886
887 acpi_status
888 acpi_ut_copy_iobject_to_iobject (
889 union acpi_operand_object *source_desc,
890 union acpi_operand_object **dest_desc,
891 struct acpi_walk_state *walk_state)
892 {
893 acpi_status status = AE_OK;
894
895
896 ACPI_FUNCTION_TRACE ("ut_copy_iobject_to_iobject");
897
898
899 /* Create the top level object */
900
901 *dest_desc = acpi_ut_create_internal_object (ACPI_GET_OBJECT_TYPE (source_desc));
902 if (!*dest_desc) {
903 return_ACPI_STATUS (AE_NO_MEMORY);
904 }
905
906 /* Copy the object and possible subobjects */
907
908 if (ACPI_GET_OBJECT_TYPE (source_desc) == ACPI_TYPE_PACKAGE) {
909 status = acpi_ut_copy_ipackage_to_ipackage (source_desc, *dest_desc,
910 walk_state);
911 }
912 else {
913 status = acpi_ut_copy_simple_object (source_desc, *dest_desc);
914 }
915
916 return_ACPI_STATUS (status);
917 }
918
919
920
|
This page was automatically generated by the
LXR engine.
|