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