1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44#include <acpi/acpi.h>
45#include "accommon.h"
46#include "acnamesp.h"
47
48
49#define _COMPONENT ACPI_UTILITIES
50ACPI_MODULE_NAME("utcopy")
51
52
53static acpi_status
54acpi_ut_copy_isimple_to_esimple(union acpi_operand_object *internal_object,
55 union acpi_object *external_object,
56 u8 * data_space, acpi_size * buffer_space_used);
57
58static acpi_status
59acpi_ut_copy_ielement_to_ielement(u8 object_type,
60 union acpi_operand_object *source_object,
61 union acpi_generic_state *state,
62 void *context);
63
64static acpi_status
65acpi_ut_copy_ipackage_to_epackage(union acpi_operand_object *internal_object,
66 u8 * buffer, acpi_size * space_used);
67
68static acpi_status
69acpi_ut_copy_esimple_to_isimple(union acpi_object *user_obj,
70 union acpi_operand_object **return_obj);
71
72static acpi_status
73acpi_ut_copy_epackage_to_ipackage(union acpi_object *external_object,
74 union acpi_operand_object **internal_object);
75
76static acpi_status
77acpi_ut_copy_simple_object(union acpi_operand_object *source_desc,
78 union acpi_operand_object *dest_desc);
79
80static acpi_status
81acpi_ut_copy_ielement_to_eelement(u8 object_type,
82 union acpi_operand_object *source_object,
83 union acpi_generic_state *state,
84 void *context);
85
86static acpi_status
87acpi_ut_copy_ipackage_to_ipackage(union acpi_operand_object *source_obj,
88 union acpi_operand_object *dest_obj,
89 struct acpi_walk_state *walk_state);
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111static acpi_status
112acpi_ut_copy_isimple_to_esimple(union acpi_operand_object *internal_object,
113 union acpi_object *external_object,
114 u8 * data_space, acpi_size * buffer_space_used)
115{
116 acpi_status status = AE_OK;
117
118 ACPI_FUNCTION_TRACE(ut_copy_isimple_to_esimple);
119
120 *buffer_space_used = 0;
121
122
123
124
125
126 if (!internal_object) {
127 return_ACPI_STATUS(AE_OK);
128 }
129
130
131
132 ACPI_MEMSET(external_object, 0, sizeof(union acpi_object));
133
134
135
136
137
138 external_object->type = internal_object->common.type;
139
140
141
142 switch (internal_object->common.type) {
143 case ACPI_TYPE_STRING:
144
145 external_object->string.pointer = (char *)data_space;
146 external_object->string.length = internal_object->string.length;
147 *buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD((acpi_size)
148 internal_object->
149 string.
150 length + 1);
151
152 ACPI_MEMCPY((void *)data_space,
153 (void *)internal_object->string.pointer,
154 (acpi_size) internal_object->string.length + 1);
155 break;
156
157 case ACPI_TYPE_BUFFER:
158
159 external_object->buffer.pointer = data_space;
160 external_object->buffer.length = internal_object->buffer.length;
161 *buffer_space_used =
162 ACPI_ROUND_UP_TO_NATIVE_WORD(internal_object->string.
163 length);
164
165 ACPI_MEMCPY((void *)data_space,
166 (void *)internal_object->buffer.pointer,
167 internal_object->buffer.length);
168 break;
169
170 case ACPI_TYPE_INTEGER:
171
172 external_object->integer.value = internal_object->integer.value;
173 break;
174
175 case ACPI_TYPE_LOCAL_REFERENCE:
176
177
178
179 switch (internal_object->reference.class) {
180 case ACPI_REFCLASS_NAME:
181
182
183
184
185
186 external_object->reference.handle =
187 internal_object->reference.node;
188 external_object->reference.actual_type =
189 acpi_ns_get_type(internal_object->reference.node);
190 break;
191
192 default:
193
194
195
196 return_ACPI_STATUS(AE_TYPE);
197 }
198 break;
199
200 case ACPI_TYPE_PROCESSOR:
201
202 external_object->processor.proc_id =
203 internal_object->processor.proc_id;
204 external_object->processor.pblk_address =
205 internal_object->processor.address;
206 external_object->processor.pblk_length =
207 internal_object->processor.length;
208 break;
209
210 case ACPI_TYPE_POWER:
211
212 external_object->power_resource.system_level =
213 internal_object->power_resource.system_level;
214
215 external_object->power_resource.resource_order =
216 internal_object->power_resource.resource_order;
217 break;
218
219 default:
220
221
222
223 ACPI_ERROR((AE_INFO,
224 "Unsupported object type, cannot convert to external object: %s",
225 acpi_ut_get_type_name(internal_object->common.
226 type)));
227
228 return_ACPI_STATUS(AE_SUPPORT);
229 }
230
231 return_ACPI_STATUS(status);
232}
233
234
235
236
237
238
239
240
241
242
243
244
245
246static acpi_status
247acpi_ut_copy_ielement_to_eelement(u8 object_type,
248 union acpi_operand_object *source_object,
249 union acpi_generic_state *state,
250 void *context)
251{
252 acpi_status status = AE_OK;
253 struct acpi_pkg_info *info = (struct acpi_pkg_info *)context;
254 acpi_size object_space;
255 u32 this_index;
256 union acpi_object *target_object;
257
258 ACPI_FUNCTION_ENTRY();
259
260 this_index = state->pkg.index;
261 target_object = (union acpi_object *)
262 &((union acpi_object *)(state->pkg.dest_object))->package.
263 elements[this_index];
264
265 switch (object_type) {
266 case ACPI_COPY_TYPE_SIMPLE:
267
268
269
270
271 status = acpi_ut_copy_isimple_to_esimple(source_object,
272 target_object,
273 info->free_space,
274 &object_space);
275 if (ACPI_FAILURE(status)) {
276 return (status);
277 }
278 break;
279
280 case ACPI_COPY_TYPE_PACKAGE:
281
282
283
284
285 target_object->type = ACPI_TYPE_PACKAGE;
286 target_object->package.count = source_object->package.count;
287 target_object->package.elements =
288 ACPI_CAST_PTR(union acpi_object, info->free_space);
289
290
291
292
293 state->pkg.this_target_obj = target_object;
294
295
296
297
298
299 object_space = ACPI_ROUND_UP_TO_NATIVE_WORD((acpi_size)
300 target_object->
301 package.count *
302 sizeof(union
303 acpi_object));
304 break;
305
306 default:
307 return (AE_BAD_PARAMETER);
308 }
309
310 info->free_space += object_space;
311 info->length += object_space;
312 return (status);
313}
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334static acpi_status
335acpi_ut_copy_ipackage_to_epackage(union acpi_operand_object *internal_object,
336 u8 * buffer, acpi_size * space_used)
337{
338 union acpi_object *external_object;
339 acpi_status status;
340 struct acpi_pkg_info info;
341
342 ACPI_FUNCTION_TRACE(ut_copy_ipackage_to_epackage);
343
344
345
346
347 external_object = ACPI_CAST_PTR(union acpi_object, buffer);
348
349
350
351
352 info.length = ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object));
353 info.free_space =
354 buffer + ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object));
355 info.object_space = 0;
356 info.num_packages = 1;
357
358 external_object->type = internal_object->common.type;
359 external_object->package.count = internal_object->package.count;
360 external_object->package.elements = ACPI_CAST_PTR(union acpi_object,
361 info.free_space);
362
363
364
365
366
367 info.length += (acpi_size) external_object->package.count *
368 ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object));
369 info.free_space += external_object->package.count *
370 ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object));
371
372 status = acpi_ut_walk_package_tree(internal_object, external_object,
373 acpi_ut_copy_ielement_to_eelement,
374 &info);
375
376 *space_used = info.length;
377 return_ACPI_STATUS(status);
378}
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394acpi_status
395acpi_ut_copy_iobject_to_eobject(union acpi_operand_object *internal_object,
396 struct acpi_buffer *ret_buffer)
397{
398 acpi_status status;
399
400 ACPI_FUNCTION_TRACE(ut_copy_iobject_to_eobject);
401
402 if (internal_object->common.type == ACPI_TYPE_PACKAGE) {
403
404
405
406
407 status = acpi_ut_copy_ipackage_to_epackage(internal_object,
408 ret_buffer->pointer,
409 &ret_buffer->length);
410 } else {
411
412
413
414 status = acpi_ut_copy_isimple_to_esimple(internal_object,
415 ACPI_CAST_PTR(union
416 acpi_object,
417 ret_buffer->
418 pointer),
419 ACPI_ADD_PTR(u8,
420 ret_buffer->
421 pointer,
422 ACPI_ROUND_UP_TO_NATIVE_WORD
423 (sizeof
424 (union
425 acpi_object))),
426 &ret_buffer->length);
427
428
429
430
431 ret_buffer->length += sizeof(union acpi_object);
432 }
433
434 return_ACPI_STATUS(status);
435}
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453static acpi_status
454acpi_ut_copy_esimple_to_isimple(union acpi_object *external_object,
455 union acpi_operand_object **ret_internal_object)
456{
457 union acpi_operand_object *internal_object;
458
459 ACPI_FUNCTION_TRACE(ut_copy_esimple_to_isimple);
460
461
462
463
464 switch (external_object->type) {
465 case ACPI_TYPE_STRING:
466 case ACPI_TYPE_BUFFER:
467 case ACPI_TYPE_INTEGER:
468 case ACPI_TYPE_LOCAL_REFERENCE:
469
470 internal_object = acpi_ut_create_internal_object((u8)
471 external_object->
472 type);
473 if (!internal_object) {
474 return_ACPI_STATUS(AE_NO_MEMORY);
475 }
476 break;
477
478 case ACPI_TYPE_ANY:
479
480 *ret_internal_object = NULL;
481 return_ACPI_STATUS(AE_OK);
482
483 default:
484
485
486 ACPI_ERROR((AE_INFO,
487 "Unsupported object type, cannot convert to internal object: %s",
488 acpi_ut_get_type_name(external_object->type)));
489
490 return_ACPI_STATUS(AE_SUPPORT);
491 }
492
493
494
495 switch (external_object->type) {
496 case ACPI_TYPE_STRING:
497
498 internal_object->string.pointer =
499 ACPI_ALLOCATE_ZEROED((acpi_size)
500 external_object->string.length + 1);
501
502 if (!internal_object->string.pointer) {
503 goto error_exit;
504 }
505
506 ACPI_MEMCPY(internal_object->string.pointer,
507 external_object->string.pointer,
508 external_object->string.length);
509
510 internal_object->string.length = external_object->string.length;
511 break;
512
513 case ACPI_TYPE_BUFFER:
514
515 internal_object->buffer.pointer =
516 ACPI_ALLOCATE_ZEROED(external_object->buffer.length);
517 if (!internal_object->buffer.pointer) {
518 goto error_exit;
519 }
520
521 ACPI_MEMCPY(internal_object->buffer.pointer,
522 external_object->buffer.pointer,
523 external_object->buffer.length);
524
525 internal_object->buffer.length = external_object->buffer.length;
526
527
528
529 internal_object->buffer.flags |= AOPOBJ_DATA_VALID;
530 break;
531
532 case ACPI_TYPE_INTEGER:
533
534 internal_object->integer.value = external_object->integer.value;
535 break;
536
537 case ACPI_TYPE_LOCAL_REFERENCE:
538
539
540
541 internal_object->reference.class = ACPI_REFCLASS_NAME;
542 internal_object->reference.node =
543 external_object->reference.handle;
544 break;
545
546 default:
547
548 break;
549 }
550
551 *ret_internal_object = internal_object;
552 return_ACPI_STATUS(AE_OK);
553
554 error_exit:
555 acpi_ut_remove_reference(internal_object);
556 return_ACPI_STATUS(AE_NO_MEMORY);
557}
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573static acpi_status
574acpi_ut_copy_epackage_to_ipackage(union acpi_object *external_object,
575 union acpi_operand_object **internal_object)
576{
577 acpi_status status = AE_OK;
578 union acpi_operand_object *package_object;
579 union acpi_operand_object **package_elements;
580 u32 i;
581
582 ACPI_FUNCTION_TRACE(ut_copy_epackage_to_ipackage);
583
584
585
586 package_object =
587 acpi_ut_create_package_object(external_object->package.count);
588 if (!package_object) {
589 return_ACPI_STATUS(AE_NO_MEMORY);
590 }
591
592 package_elements = package_object->package.elements;
593
594
595
596
597
598 for (i = 0; i < external_object->package.count; i++) {
599 status =
600 acpi_ut_copy_eobject_to_iobject(&external_object->package.
601 elements[i],
602 &package_elements[i]);
603 if (ACPI_FAILURE(status)) {
604
605
606
607 package_object->package.count = i;
608 package_elements[i] = NULL;
609 acpi_ut_remove_reference(package_object);
610 return_ACPI_STATUS(status);
611 }
612 }
613
614
615
616 package_object->package.flags |= AOPOBJ_DATA_VALID;
617
618 *internal_object = package_object;
619 return_ACPI_STATUS(status);
620}
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635acpi_status
636acpi_ut_copy_eobject_to_iobject(union acpi_object *external_object,
637 union acpi_operand_object **internal_object)
638{
639 acpi_status status;
640
641 ACPI_FUNCTION_TRACE(ut_copy_eobject_to_iobject);
642
643 if (external_object->type == ACPI_TYPE_PACKAGE) {
644 status =
645 acpi_ut_copy_epackage_to_ipackage(external_object,
646 internal_object);
647 } else {
648
649
650
651 status =
652 acpi_ut_copy_esimple_to_isimple(external_object,
653 internal_object);
654 }
655
656 return_ACPI_STATUS(status);
657}
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673static acpi_status
674acpi_ut_copy_simple_object(union acpi_operand_object *source_desc,
675 union acpi_operand_object *dest_desc)
676{
677 u16 reference_count;
678 union acpi_operand_object *next_object;
679 acpi_status status;
680
681
682
683 reference_count = dest_desc->common.reference_count;
684 next_object = dest_desc->common.next_object;
685
686
687
688 ACPI_MEMCPY((char *)dest_desc, (char *)source_desc,
689 sizeof(union acpi_operand_object));
690
691
692
693 dest_desc->common.reference_count = reference_count;
694 dest_desc->common.next_object = next_object;
695
696
697
698 dest_desc->common.flags &= ~AOPOBJ_STATIC_POINTER;
699
700
701
702 switch (dest_desc->common.type) {
703 case ACPI_TYPE_BUFFER:
704
705
706
707
708
709 if ((source_desc->buffer.pointer) &&
710 (source_desc->buffer.length)) {
711 dest_desc->buffer.pointer =
712 ACPI_ALLOCATE(source_desc->buffer.length);
713 if (!dest_desc->buffer.pointer) {
714 return (AE_NO_MEMORY);
715 }
716
717
718
719 ACPI_MEMCPY(dest_desc->buffer.pointer,
720 source_desc->buffer.pointer,
721 source_desc->buffer.length);
722 }
723 break;
724
725 case ACPI_TYPE_STRING:
726
727
728
729
730
731 if (source_desc->string.pointer) {
732 dest_desc->string.pointer =
733 ACPI_ALLOCATE((acpi_size) source_desc->string.
734 length + 1);
735 if (!dest_desc->string.pointer) {
736 return (AE_NO_MEMORY);
737 }
738
739
740
741 ACPI_MEMCPY(dest_desc->string.pointer,
742 source_desc->string.pointer,
743 (acpi_size) source_desc->string.length + 1);
744 }
745 break;
746
747 case ACPI_TYPE_LOCAL_REFERENCE:
748
749
750
751
752
753
754
755
756 if (source_desc->reference.class == ACPI_REFCLASS_TABLE) {
757 break;
758 }
759
760 acpi_ut_add_reference(source_desc->reference.object);
761 break;
762
763 case ACPI_TYPE_REGION:
764
765
766
767 if (dest_desc->region.handler) {
768 acpi_ut_add_reference(dest_desc->region.handler);
769 }
770 break;
771
772
773
774
775
776 case ACPI_TYPE_MUTEX:
777
778 status = acpi_os_create_mutex(&dest_desc->mutex.os_mutex);
779 if (ACPI_FAILURE(status)) {
780 return status;
781 }
782 break;
783
784 case ACPI_TYPE_EVENT:
785
786 status = acpi_os_create_semaphore(ACPI_NO_UNIT_LIMIT, 0,
787 &dest_desc->event.
788 os_semaphore);
789 if (ACPI_FAILURE(status)) {
790 return status;
791 }
792 break;
793
794 default:
795
796 break;
797 }
798
799 return (AE_OK);
800}
801
802
803
804
805
806
807
808
809
810
811
812
813
814static acpi_status
815acpi_ut_copy_ielement_to_ielement(u8 object_type,
816 union acpi_operand_object *source_object,
817 union acpi_generic_state *state,
818 void *context)
819{
820 acpi_status status = AE_OK;
821 u32 this_index;
822 union acpi_operand_object **this_target_ptr;
823 union acpi_operand_object *target_object;
824
825 ACPI_FUNCTION_ENTRY();
826
827 this_index = state->pkg.index;
828 this_target_ptr = (union acpi_operand_object **)
829 &state->pkg.dest_object->package.elements[this_index];
830
831 switch (object_type) {
832 case ACPI_COPY_TYPE_SIMPLE:
833
834
835
836 if (source_object) {
837
838
839
840 target_object =
841 acpi_ut_create_internal_object(source_object->
842 common.type);
843 if (!target_object) {
844 return (AE_NO_MEMORY);
845 }
846
847 status =
848 acpi_ut_copy_simple_object(source_object,
849 target_object);
850 if (ACPI_FAILURE(status)) {
851 goto error_exit;
852 }
853
854 *this_target_ptr = target_object;
855 } else {
856
857
858 *this_target_ptr = NULL;
859 }
860 break;
861
862 case ACPI_COPY_TYPE_PACKAGE:
863
864
865
866
867
868 target_object =
869 acpi_ut_create_package_object(source_object->package.count);
870 if (!target_object) {
871 return (AE_NO_MEMORY);
872 }
873
874 target_object->common.flags = source_object->common.flags;
875
876
877
878 state->pkg.this_target_obj = target_object;
879
880
881
882 *this_target_ptr = target_object;
883 break;
884
885 default:
886 return (AE_BAD_PARAMETER);
887 }
888
889 return (status);
890
891 error_exit:
892 acpi_ut_remove_reference(target_object);
893 return (status);
894}
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910static acpi_status
911acpi_ut_copy_ipackage_to_ipackage(union acpi_operand_object *source_obj,
912 union acpi_operand_object *dest_obj,
913 struct acpi_walk_state *walk_state)
914{
915 acpi_status status = AE_OK;
916
917 ACPI_FUNCTION_TRACE(ut_copy_ipackage_to_ipackage);
918
919 dest_obj->common.type = source_obj->common.type;
920 dest_obj->common.flags = source_obj->common.flags;
921 dest_obj->package.count = source_obj->package.count;
922
923
924
925
926 dest_obj->package.elements = ACPI_ALLOCATE_ZEROED(((acpi_size)
927 source_obj->package.
928 count +
929 1) * sizeof(void *));
930 if (!dest_obj->package.elements) {
931 ACPI_ERROR((AE_INFO, "Package allocation failure"));
932 return_ACPI_STATUS(AE_NO_MEMORY);
933 }
934
935
936
937
938
939 status = acpi_ut_walk_package_tree(source_obj, dest_obj,
940 acpi_ut_copy_ielement_to_ielement,
941 walk_state);
942 if (ACPI_FAILURE(status)) {
943
944
945
946 acpi_ut_remove_reference(dest_obj);
947 }
948
949 return_ACPI_STATUS(status);
950}
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966acpi_status
967acpi_ut_copy_iobject_to_iobject(union acpi_operand_object *source_desc,
968 union acpi_operand_object **dest_desc,
969 struct acpi_walk_state *walk_state)
970{
971 acpi_status status = AE_OK;
972
973 ACPI_FUNCTION_TRACE(ut_copy_iobject_to_iobject);
974
975
976
977 *dest_desc = acpi_ut_create_internal_object(source_desc->common.type);
978 if (!*dest_desc) {
979 return_ACPI_STATUS(AE_NO_MEMORY);
980 }
981
982
983
984 if (source_desc->common.type == ACPI_TYPE_PACKAGE) {
985 status =
986 acpi_ut_copy_ipackage_to_ipackage(source_desc, *dest_desc,
987 walk_state);
988 } else {
989 status = acpi_ut_copy_simple_object(source_desc, *dest_desc);
990 }
991
992 return_ACPI_STATUS(status);
993}
994