[ACPI] whitespace
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / acpi / utilities / utcopy.c
CommitLineData
1da177e4
LT
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
44f6c012
RM
52/* Local prototypes */
53
54static acpi_status
55acpi_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
61static acpi_status
62acpi_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
68static acpi_status
69acpi_ut_copy_ipackage_to_epackage (
70 union acpi_operand_object *internal_object,
71 u8 *buffer,
72 acpi_size *space_used);
73
74static acpi_status
75acpi_ut_copy_esimple_to_isimple(
76 union acpi_object *user_obj,
77 union acpi_operand_object **return_obj);
78
79static acpi_status
80acpi_ut_copy_simple_object (
81 union acpi_operand_object *source_desc,
82 union acpi_operand_object *dest_desc);
83
84static acpi_status
85acpi_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
91static acpi_status
92acpi_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
1da177e4
LT
97
98/*******************************************************************************
99 *
100 * FUNCTION: acpi_ut_copy_isimple_to_esimple
101 *
44f6c012
RM
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
1da177e4
LT
107 *
108 * RETURN: Status
109 *
44f6c012
RM
110 * DESCRIPTION: This function is called to copy a simple internal object to
111 * an external object.
1da177e4 112 *
44f6c012
RM
113 * The data_space buffer is assumed to have sufficient space for
114 * the object.
1da177e4
LT
115 *
116 ******************************************************************************/
117
118static acpi_status
119acpi_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;
44f6c012
RM
158 *buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD (
159 (acpi_size) internal_object->string.length + 1);
1da177e4 160
44f6c012
RM
161 ACPI_MEMCPY ((void *) data_space,
162 (void *) internal_object->string.pointer,
163 (acpi_size) internal_object->string.length + 1);
1da177e4
LT
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;
44f6c012
RM
171 *buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD (
172 internal_object->string.length);
1da177e4 173
44f6c012
RM
174 ACPI_MEMCPY ((void *) data_space,
175 (void *) internal_object->buffer.pointer,
176 internal_object->buffer.length);
1da177e4
LT
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
44f6c012 249static acpi_status
1da177e4
LT
250acpi_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 *)
44f6c012 268 &((union acpi_object *)(state->pkg.dest_object))->package.elements[this_index];
1da177e4
LT
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;
44f6c012
RM
291 target_object->package.elements =
292 ACPI_CAST_PTR (union acpi_object, info->free_space);
1da177e4
LT
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 (
44f6c012
RM
304 (acpi_size) target_object->package.count *
305 sizeof (union acpi_object));
1da177e4
LT
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 *
44f6c012
RM
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
1da177e4
LT
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
338static acpi_status
339acpi_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));
44f6c012
RM
361 info.free_space = buffer + ACPI_ROUND_UP_TO_NATIVE_WORD (
362 sizeof (union acpi_object));
1da177e4
LT
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;
44f6c012
RM
368 external_object->package.elements = ACPI_CAST_PTR (union acpi_object,
369 info.free_space);
1da177e4
LT
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 *
44f6c012
RM
392 * PARAMETERS: internal_object - The internal object to be converted
393 * buffer_ptr - Where the object is returned
1da177e4
LT
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
402acpi_status
403acpi_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,
44f6c012
RM
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);
1da177e4
LT
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 *
44f6c012
RM
445 * PARAMETERS: external_object - The external object to be converted
446 * ret_internal_object - Where the internal object is returned
1da177e4
LT
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
44f6c012 457static acpi_status
1da177e4
LT
458acpi_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
44f6c012
RM
476 internal_object = acpi_ut_create_internal_object (
477 (u8) external_object->type);
1da177e4
LT
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
539error_exit:
540 acpi_ut_remove_reference (internal_object);
541 return_ACPI_STATUS (AE_NO_MEMORY);
542}
543
544
545#ifdef ACPI_FUTURE_IMPLEMENTATION
1da177e4
LT
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
567static acpi_status
568acpi_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
627acpi_status
628acpi_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
44f6c012 673static acpi_status
1da177e4
LT
674acpi_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
6f42ccf2
RM
697 /* New object is not static, regardless of source */
698
699 dest_desc->common.flags &= ~AOPOBJ_STATIC_POINTER;
700
1da177e4
LT
701 /* Handle the objects with extra data */
702
703 switch (ACPI_GET_OBJECT_TYPE (dest_desc)) {
704 case ACPI_TYPE_BUFFER:
1da177e4
LT
705 /*
706 * Allocate and copy the actual buffer if and only if:
707 * 1) There is a valid buffer pointer
6f42ccf2 708 * 2) The buffer has a length > 0
1da177e4
LT
709 */
710 if ((source_desc->buffer.pointer) &&
6f42ccf2
RM
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);
716 }
1da177e4 717
6f42ccf2 718 /* Copy the actual buffer data */
1da177e4 719
6f42ccf2
RM
720 ACPI_MEMCPY (dest_desc->buffer.pointer,
721 source_desc->buffer.pointer,
722 source_desc->buffer.length);
1da177e4
LT
723 }
724 break;
725
726 case ACPI_TYPE_STRING:
1da177e4
LT
727 /*
728 * Allocate and copy the actual string if and only if:
729 * 1) There is a valid string pointer
6f42ccf2 730 * (Pointer to a NULL string is allowed)
1da177e4 731 */
6f42ccf2 732 if (source_desc->string.pointer) {
1da177e4
LT
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);
737 }
738
6f42ccf2
RM
739 /* Copy the actual string data */
740
1da177e4
LT
741 ACPI_MEMCPY (dest_desc->string.pointer, source_desc->string.pointer,
742 (acpi_size) source_desc->string.length + 1);
743 }
744 break;
745
746 case ACPI_TYPE_LOCAL_REFERENCE:
747 /*
748 * We copied the reference object, so we now must add a reference
749 * to the object pointed to by the reference
750 */
751 acpi_ut_add_reference (source_desc->reference.object);
752 break;
753
754 default:
755 /* Nothing to do for other simple objects */
756 break;
757 }
758
759 return (AE_OK);
760}
761
762
763/*******************************************************************************
764 *
765 * FUNCTION: acpi_ut_copy_ielement_to_ielement
766 *
767 * PARAMETERS: acpi_pkg_callback
768 *
769 * RETURN: Status
770 *
771 * DESCRIPTION: Copy one package element to another package element
772 *
773 ******************************************************************************/
774
44f6c012 775static acpi_status
1da177e4
LT
776acpi_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)
781{
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;
786
787
788 ACPI_FUNCTION_ENTRY ();
789
790
791 this_index = state->pkg.index;
792 this_target_ptr = (union acpi_operand_object **)
793 &state->pkg.dest_object->package.elements[this_index];
794
795 switch (object_type) {
796 case ACPI_COPY_TYPE_SIMPLE:
797
798 /* A null source object indicates a (legal) null package element */
799
800 if (source_object) {
801 /*
802 * This is a simple object, just copy it
803 */
804 target_object = acpi_ut_create_internal_object (
805 ACPI_GET_OBJECT_TYPE (source_object));
806 if (!target_object) {
807 return (AE_NO_MEMORY);
808 }
809
810 status = acpi_ut_copy_simple_object (source_object, target_object);
811 if (ACPI_FAILURE (status)) {
812 goto error_exit;
813 }
814
815 *this_target_ptr = target_object;
816 }
817 else {
818 /* Pass through a null element */
819
820 *this_target_ptr = NULL;
821 }
822 break;
823
824
825 case ACPI_COPY_TYPE_PACKAGE:
826
827 /*
828 * This object is a package - go down another nesting level
829 * Create and build the package object
830 */
831 target_object = acpi_ut_create_internal_object (ACPI_TYPE_PACKAGE);
832 if (!target_object) {
833 return (AE_NO_MEMORY);
834 }
835
836 target_object->package.count = source_object->package.count;
837 target_object->common.flags = source_object->common.flags;
838
839 /*
840 * Create the object array
841 */
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;
848 }
849
850 /*
851 * Pass the new package object back to the package walk routine
852 */
853 state->pkg.this_target_obj = target_object;
854
855 /*
856 * Store the object pointer in the parent package object
857 */
858 *this_target_ptr = target_object;
859 break;
860
861
862 default:
863 return (AE_BAD_PARAMETER);
864 }
865
866 return (status);
867
868error_exit:
869 acpi_ut_remove_reference (target_object);
870 return (status);
871}
872
873
874/*******************************************************************************
875 *
876 * FUNCTION: acpi_ut_copy_ipackage_to_ipackage
877 *
878 * PARAMETERS: *source_obj - Pointer to the source package object
879 * *dest_obj - Where the internal object is returned
880 *
881 * RETURN: Status - the status of the call
882 *
883 * DESCRIPTION: This function is called to copy an internal package object
884 * into another internal package object.
885 *
886 ******************************************************************************/
887
44f6c012 888static acpi_status
1da177e4
LT
889acpi_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)
893{
894 acpi_status status = AE_OK;
895
896
897 ACPI_FUNCTION_TRACE ("ut_copy_ipackage_to_ipackage");
898
899
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;
903
904 /*
905 * Create the object array and walk the source package tree
906 */
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);
914 }
915
916 /*
917 * Copy the package element-by-element by walking the package "tree".
918 * This handles nested packages of arbitrary depth.
919 */
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 */
924
925 acpi_ut_remove_reference (dest_obj);
926 }
927
928 return_ACPI_STATUS (status);
929}
930
931
932/*******************************************************************************
933 *
934 * FUNCTION: acpi_ut_copy_iobject_to_iobject
935 *
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
939 *
940 * RETURN: Status
941 *
942 * DESCRIPTION: Copy an internal object to a new internal object
943 *
944 ******************************************************************************/
945
946acpi_status
947acpi_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)
951{
952 acpi_status status = AE_OK;
953
954
955 ACPI_FUNCTION_TRACE ("ut_copy_iobject_to_iobject");
956
957
958 /* Create the top level object */
959
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);
963 }
964
965 /* Copy the object and possible subobjects */
966
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);
970 }
971 else {
972 status = acpi_ut_copy_simple_object (source_desc, *dest_desc);
973 }
974
975 return_ACPI_STATUS (status);
976}
977
978