blob: 98d53e59ce5522149685f07e8e0a2dd346b76e86 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: utcopy - Internal to external object translation utilities
4 *
5 *****************************************************************************/
6
7/*
Bob Moorec8100dc2016-01-15 08:17:03 +08008 * Copyright (C) 2000 - 2016, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "acnamesp.h"
Bob Moorecd0b2242008-04-10 19:06:43 +040047
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#define _COMPONENT ACPI_UTILITIES
Len Brown4be44fc2005-08-05 00:44:28 -040050ACPI_MODULE_NAME("utcopy")
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
Robert Moore44f6c012005-04-18 22:49:35 -040052/* Local prototypes */
Len Brown4be44fc2005-08-05 00:44:28 -040053static 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);
Robert Moore44f6c012005-04-18 22:49:35 -040057
58static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040059acpi_ut_copy_ielement_to_ielement(u8 object_type,
60 union acpi_operand_object *source_object,
61 union acpi_generic_state *state,
62 void *context);
Robert Moore44f6c012005-04-18 22:49:35 -040063
64static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040065acpi_ut_copy_ipackage_to_epackage(union acpi_operand_object *internal_object,
66 u8 * buffer, acpi_size * space_used);
Robert Moore44f6c012005-04-18 22:49:35 -040067
68static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040069acpi_ut_copy_esimple_to_isimple(union acpi_object *user_obj,
70 union acpi_operand_object **return_obj);
Robert Moore44f6c012005-04-18 22:49:35 -040071
72static acpi_status
Bob Moore6287ee32007-04-03 19:59:37 -040073acpi_ut_copy_epackage_to_ipackage(union acpi_object *external_object,
74 union acpi_operand_object **internal_object);
75
76static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040077acpi_ut_copy_simple_object(union acpi_operand_object *source_desc,
78 union acpi_operand_object *dest_desc);
Robert Moore44f6c012005-04-18 22:49:35 -040079
80static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040081acpi_ut_copy_ielement_to_eelement(u8 object_type,
82 union acpi_operand_object *source_object,
83 union acpi_generic_state *state,
84 void *context);
Robert Moore44f6c012005-04-18 22:49:35 -040085
86static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040087acpi_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);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
91/*******************************************************************************
92 *
93 * FUNCTION: acpi_ut_copy_isimple_to_esimple
94 *
Robert Moore44f6c012005-04-18 22:49:35 -040095 * PARAMETERS: internal_object - Source object to be copied
96 * external_object - Where to return the copied object
97 * data_space - Where object data is returned (such as
98 * buffer and string data)
99 * buffer_space_used - Length of data_space that was used
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 *
101 * RETURN: Status
102 *
Robert Moore44f6c012005-04-18 22:49:35 -0400103 * DESCRIPTION: This function is called to copy a simple internal object to
104 * an external object.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 *
Robert Moore44f6c012005-04-18 22:49:35 -0400106 * The data_space buffer is assumed to have sufficient space for
107 * the object.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 *
109 ******************************************************************************/
110
111static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400112acpi_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)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
Len Brown4be44fc2005-08-05 00:44:28 -0400116 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
Bob Mooreb229cf92006-04-21 17:15:00 -0400118 ACPI_FUNCTION_TRACE(ut_copy_isimple_to_esimple);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120 *buffer_space_used = 0;
121
122 /*
123 * Check for NULL object case (could be an uninitialized
124 * package element)
125 */
126 if (!internal_object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400127 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128 }
129
130 /* Always clear the external object */
131
Bob Moore4fa46162015-07-01 14:45:11 +0800132 memset(external_object, 0, sizeof(union acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134 /*
135 * In general, the external object will be the same type as
136 * the internal object
137 */
Bob Moore3371c192009-02-18 14:44:03 +0800138 external_object->type = internal_object->common.type;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
140 /* However, only a limited number of external types are supported */
141
Bob Moore3371c192009-02-18 14:44:03 +0800142 switch (internal_object->common.type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 case ACPI_TYPE_STRING:
144
Len Brown4be44fc2005-08-05 00:44:28 -0400145 external_object->string.pointer = (char *)data_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 external_object->string.length = internal_object->string.length;
Len Brown4be44fc2005-08-05 00:44:28 -0400147 *buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD((acpi_size)
148 internal_object->
149 string.
150 length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Bob Moore4fa46162015-07-01 14:45:11 +0800152 memcpy((void *)data_space,
153 (void *)internal_object->string.pointer,
154 (acpi_size) internal_object->string.length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 break;
156
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 case ACPI_TYPE_BUFFER:
158
159 external_object->buffer.pointer = data_space;
160 external_object->buffer.length = internal_object->buffer.length;
Len Brown4be44fc2005-08-05 00:44:28 -0400161 *buffer_space_used =
162 ACPI_ROUND_UP_TO_NATIVE_WORD(internal_object->string.
163 length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Bob Moore4fa46162015-07-01 14:45:11 +0800165 memcpy((void *)data_space,
166 (void *)internal_object->buffer.pointer,
167 internal_object->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 break;
169
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 case ACPI_TYPE_INTEGER:
171
172 external_object->integer.value = internal_object->integer.value;
173 break;
174
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 case ACPI_TYPE_LOCAL_REFERENCE:
176
Bob Moorecd0b2242008-04-10 19:06:43 +0400177 /* This is an object reference. */
178
Bob Moore1044f1f2008-09-27 11:08:41 +0800179 switch (internal_object->reference.class) {
180 case ACPI_REFCLASS_NAME:
Bob Moore1044f1f2008-09-27 11:08:41 +0800181 /*
182 * For namepath, return the object handle ("reference")
183 * We are referring to the namespace node
184 */
Len Brown4be44fc2005-08-05 00:44:28 -0400185 external_object->reference.handle =
186 internal_object->reference.node;
Bob Moorecd0b2242008-04-10 19:06:43 +0400187 external_object->reference.actual_type =
188 acpi_ns_get_type(internal_object->reference.node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189 break;
Bob Moore1044f1f2008-09-27 11:08:41 +0800190
191 default:
192
193 /* All other reference types are unsupported */
194
195 return_ACPI_STATUS(AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 }
197 break;
198
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 case ACPI_TYPE_PROCESSOR:
200
Len Brown4be44fc2005-08-05 00:44:28 -0400201 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 break;
208
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 case ACPI_TYPE_POWER:
210
211 external_object->power_resource.system_level =
Len Brown4be44fc2005-08-05 00:44:28 -0400212 internal_object->power_resource.system_level;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213
214 external_object->power_resource.resource_order =
Len Brown4be44fc2005-08-05 00:44:28 -0400215 internal_object->power_resource.resource_order;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216 break;
217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 default:
219 /*
220 * There is no corresponding external object type
221 */
Bob Mooreb1dd9092008-04-10 19:06:42 +0400222 ACPI_ERROR((AE_INFO,
223 "Unsupported object type, cannot convert to external object: %s",
Bob Moore3371c192009-02-18 14:44:03 +0800224 acpi_ut_get_type_name(internal_object->common.
225 type)));
Bob Mooreb1dd9092008-04-10 19:06:42 +0400226
Len Brown4be44fc2005-08-05 00:44:28 -0400227 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 }
229
Len Brown4be44fc2005-08-05 00:44:28 -0400230 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231}
232
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233/*******************************************************************************
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
Robert Moore44f6c012005-04-18 22:49:35 -0400245static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400246acpi_ut_copy_ielement_to_eelement(u8 object_type,
247 union acpi_operand_object *source_object,
248 union acpi_generic_state *state,
249 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250{
Len Brown4be44fc2005-08-05 00:44:28 -0400251 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
Len Brown4be44fc2005-08-05 00:44:28 -0400257 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Len Brown4be44fc2005-08-05 00:44:28 -0400259 this_index = state->pkg.index;
Bob Moore1fad8732015-12-29 13:54:36 +0800260 target_object = (union acpi_object *)&((union acpi_object *)
261 (state->pkg.dest_object))->
262 package.elements[this_index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
264 switch (object_type) {
265 case ACPI_COPY_TYPE_SIMPLE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 /*
267 * This is a simple or null object
268 */
Len Brown4be44fc2005-08-05 00:44:28 -0400269 status = acpi_ut_copy_isimple_to_esimple(source_object,
270 target_object,
271 info->free_space,
272 &object_space);
273 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274 return (status);
275 }
276 break;
277
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 case ACPI_COPY_TYPE_PACKAGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279 /*
280 * Build the package object
281 */
Len Brown4be44fc2005-08-05 00:44:28 -0400282 target_object->type = ACPI_TYPE_PACKAGE;
283 target_object->package.count = source_object->package.count;
Robert Moore44f6c012005-04-18 22:49:35 -0400284 target_object->package.elements =
Len Brown4be44fc2005-08-05 00:44:28 -0400285 ACPI_CAST_PTR(union acpi_object, info->free_space);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
287 /*
288 * Pass the new package object back to the package walk routine
289 */
290 state->pkg.this_target_obj = target_object;
291
292 /*
293 * Save space for the array of objects (Package elements)
294 * update the buffer length counter
295 */
Len Brown4be44fc2005-08-05 00:44:28 -0400296 object_space = ACPI_ROUND_UP_TO_NATIVE_WORD((acpi_size)
297 target_object->
298 package.count *
299 sizeof(union
300 acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 break;
302
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 default:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000304
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 return (AE_BAD_PARAMETER);
306 }
307
Len Brown4be44fc2005-08-05 00:44:28 -0400308 info->free_space += object_space;
309 info->length += object_space;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700310 return (status);
311}
312
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313/*******************************************************************************
314 *
315 * FUNCTION: acpi_ut_copy_ipackage_to_epackage
316 *
Robert Moore44f6c012005-04-18 22:49:35 -0400317 * PARAMETERS: internal_object - Pointer to the object we are returning
Bob Mooreba494be2012-07-12 09:40:10 +0800318 * buffer - Where the object is returned
Robert Moore44f6c012005-04-18 22:49:35 -0400319 * space_used - Where the object length is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320 *
321 * RETURN: Status
322 *
323 * DESCRIPTION: This function is called to place a package object in a user
Bob Moore90434c12009-12-11 15:02:15 +0800324 * buffer. A package object by definition contains other objects.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325 *
326 * The buffer is assumed to have sufficient space for the object.
Bob Moore90434c12009-12-11 15:02:15 +0800327 * The caller must have verified the buffer length needed using
328 * the acpi_ut_get_object_size function before calling this function.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 *
330 ******************************************************************************/
331
332static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400333acpi_ut_copy_ipackage_to_epackage(union acpi_operand_object *internal_object,
334 u8 * buffer, acpi_size * space_used)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335{
Len Brown4be44fc2005-08-05 00:44:28 -0400336 union acpi_object *external_object;
337 acpi_status status;
338 struct acpi_pkg_info info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
Bob Mooreb229cf92006-04-21 17:15:00 -0400340 ACPI_FUNCTION_TRACE(ut_copy_ipackage_to_epackage);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
342 /*
343 * First package at head of the buffer
344 */
Len Brown4be44fc2005-08-05 00:44:28 -0400345 external_object = ACPI_CAST_PTR(union acpi_object, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347 /*
348 * Free space begins right after the first package
349 */
Len Brown4be44fc2005-08-05 00:44:28 -0400350 info.length = ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object));
Bob Moore1fad8732015-12-29 13:54:36 +0800351 info.free_space = buffer +
352 ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 info.object_space = 0;
354 info.num_packages = 1;
355
Bob Moore3371c192009-02-18 14:44:03 +0800356 external_object->type = internal_object->common.type;
Len Brown4be44fc2005-08-05 00:44:28 -0400357 external_object->package.count = internal_object->package.count;
Bob Moore1fad8732015-12-29 13:54:36 +0800358 external_object->package.elements =
359 ACPI_CAST_PTR(union acpi_object, info.free_space);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360
361 /*
362 * Leave room for an array of ACPI_OBJECTS in the buffer
363 * and move the free space past it
364 */
Len Brown4be44fc2005-08-05 00:44:28 -0400365 info.length += (acpi_size) external_object->package.count *
366 ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700367 info.free_space += external_object->package.count *
Len Brown4be44fc2005-08-05 00:44:28 -0400368 ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
Len Brown4be44fc2005-08-05 00:44:28 -0400370 status = acpi_ut_walk_package_tree(internal_object, external_object,
371 acpi_ut_copy_ielement_to_eelement,
372 &info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
374 *space_used = info.length;
Len Brown4be44fc2005-08-05 00:44:28 -0400375 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376}
377
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378/*******************************************************************************
379 *
380 * FUNCTION: acpi_ut_copy_iobject_to_eobject
381 *
Robert Moore44f6c012005-04-18 22:49:35 -0400382 * PARAMETERS: internal_object - The internal object to be converted
Bob Moore90434c12009-12-11 15:02:15 +0800383 * ret_buffer - Where the object is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 *
385 * RETURN: Status
386 *
Bob Moore90434c12009-12-11 15:02:15 +0800387 * DESCRIPTION: This function is called to build an API object to be returned
388 * to the caller.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389 *
390 ******************************************************************************/
391
392acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400393acpi_ut_copy_iobject_to_eobject(union acpi_operand_object *internal_object,
394 struct acpi_buffer *ret_buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395{
Len Brown4be44fc2005-08-05 00:44:28 -0400396 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Bob Mooreb229cf92006-04-21 17:15:00 -0400398 ACPI_FUNCTION_TRACE(ut_copy_iobject_to_eobject);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399
Bob Moore3371c192009-02-18 14:44:03 +0800400 if (internal_object->common.type == ACPI_TYPE_PACKAGE) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401 /*
402 * Package object: Copy all subobjects (including
403 * nested packages)
404 */
Len Brown4be44fc2005-08-05 00:44:28 -0400405 status = acpi_ut_copy_ipackage_to_epackage(internal_object,
406 ret_buffer->pointer,
407 &ret_buffer->length);
408 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409 /*
410 * Build a simple object (no nested objects)
411 */
Len Brown4be44fc2005-08-05 00:44:28 -0400412 status = acpi_ut_copy_isimple_to_esimple(internal_object,
Bob Moorec51a4de2005-11-17 13:07:00 -0500413 ACPI_CAST_PTR(union
414 acpi_object,
415 ret_buffer->
416 pointer),
417 ACPI_ADD_PTR(u8,
418 ret_buffer->
419 pointer,
420 ACPI_ROUND_UP_TO_NATIVE_WORD
421 (sizeof
422 (union
423 acpi_object))),
Len Brown4be44fc2005-08-05 00:44:28 -0400424 &ret_buffer->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425 /*
426 * build simple does not include the object size in the length
427 * so we add it in here
428 */
Len Brown4be44fc2005-08-05 00:44:28 -0400429 ret_buffer->length += sizeof(union acpi_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430 }
431
Len Brown4be44fc2005-08-05 00:44:28 -0400432 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433}
434
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435/*******************************************************************************
436 *
437 * FUNCTION: acpi_ut_copy_esimple_to_isimple
438 *
Robert Moore44f6c012005-04-18 22:49:35 -0400439 * PARAMETERS: external_object - The external object to be converted
440 * ret_internal_object - Where the internal object is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441 *
442 * RETURN: Status
443 *
444 * DESCRIPTION: This function copies an external object to an internal one.
445 * NOTE: Pointers can be copied, we don't need to copy data.
446 * (The pointers have to be valid in our address space no matter
447 * what we do with them!)
448 *
449 ******************************************************************************/
450
Robert Moore44f6c012005-04-18 22:49:35 -0400451static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400452acpi_ut_copy_esimple_to_isimple(union acpi_object *external_object,
453 union acpi_operand_object **ret_internal_object)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454{
Len Brown4be44fc2005-08-05 00:44:28 -0400455 union acpi_operand_object *internal_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456
Bob Mooreb229cf92006-04-21 17:15:00 -0400457 ACPI_FUNCTION_TRACE(ut_copy_esimple_to_isimple);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
459 /*
460 * Simple types supported are: String, Buffer, Integer
461 */
462 switch (external_object->type) {
463 case ACPI_TYPE_STRING:
464 case ACPI_TYPE_BUFFER:
465 case ACPI_TYPE_INTEGER:
Bob Moorecd0b2242008-04-10 19:06:43 +0400466 case ACPI_TYPE_LOCAL_REFERENCE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
Len Brown4be44fc2005-08-05 00:44:28 -0400468 internal_object = acpi_ut_create_internal_object((u8)
469 external_object->
470 type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 if (!internal_object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400472 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 }
474 break;
475
Bob Moorecd0b2242008-04-10 19:06:43 +0400476 case ACPI_TYPE_ANY: /* This is the case for a NULL object */
477
478 *ret_internal_object = NULL;
479 return_ACPI_STATUS(AE_OK);
480
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 default:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000482
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483 /* All other types are not supported */
484
Bob Mooreb1dd9092008-04-10 19:06:42 +0400485 ACPI_ERROR((AE_INFO,
486 "Unsupported object type, cannot convert to internal object: %s",
487 acpi_ut_get_type_name(external_object->type)));
488
Len Brown4be44fc2005-08-05 00:44:28 -0400489 return_ACPI_STATUS(AE_SUPPORT);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490 }
491
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 /* Must COPY string and buffer contents */
493
494 switch (external_object->type) {
495 case ACPI_TYPE_STRING:
496
497 internal_object->string.pointer =
Bob Mooreec41f192009-02-18 15:03:30 +0800498 ACPI_ALLOCATE_ZEROED((acpi_size)
499 external_object->string.length + 1);
500
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 if (!internal_object->string.pointer) {
502 goto error_exit;
503 }
504
Bob Moore4fa46162015-07-01 14:45:11 +0800505 memcpy(internal_object->string.pointer,
506 external_object->string.pointer,
507 external_object->string.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
509 internal_object->string.length = external_object->string.length;
510 break;
511
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512 case ACPI_TYPE_BUFFER:
513
514 internal_object->buffer.pointer =
Bob Moore83135242006-10-03 00:00:00 -0400515 ACPI_ALLOCATE_ZEROED(external_object->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 if (!internal_object->buffer.pointer) {
517 goto error_exit;
518 }
519
Bob Moore4fa46162015-07-01 14:45:11 +0800520 memcpy(internal_object->buffer.pointer,
521 external_object->buffer.pointer,
522 external_object->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523
524 internal_object->buffer.length = external_object->buffer.length;
Bob Moore24a31572008-04-10 19:06:43 +0400525
526 /* Mark buffer data valid */
527
528 internal_object->buffer.flags |= AOPOBJ_DATA_VALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 break;
530
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531 case ACPI_TYPE_INTEGER:
532
Len Brown4be44fc2005-08-05 00:44:28 -0400533 internal_object->integer.value = external_object->integer.value;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 break;
535
Bob Moorecd0b2242008-04-10 19:06:43 +0400536 case ACPI_TYPE_LOCAL_REFERENCE:
537
Bob Mooreab85e922014-02-08 09:42:32 +0800538 /* An incoming reference is defined to be a namespace node */
Bob Moorecd0b2242008-04-10 19:06:43 +0400539
Bob Mooreab85e922014-02-08 09:42:32 +0800540 internal_object->reference.class = ACPI_REFCLASS_REFOF;
541 internal_object->reference.object =
Bob Moorecd0b2242008-04-10 19:06:43 +0400542 external_object->reference.handle;
543 break;
544
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 default:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000546
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547 /* Other types can't get here */
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000548
Linus Torvalds1da177e2005-04-16 15:20:36 -0700549 break;
550 }
551
552 *ret_internal_object = internal_object;
Len Brown4be44fc2005-08-05 00:44:28 -0400553 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554
Lv Zheng10622bf2013-10-29 09:30:02 +0800555error_exit:
Len Brown4be44fc2005-08-05 00:44:28 -0400556 acpi_ut_remove_reference(internal_object);
557 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558}
559
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560/*******************************************************************************
561 *
562 * FUNCTION: acpi_ut_copy_epackage_to_ipackage
563 *
Bob Moore6287ee32007-04-03 19:59:37 -0400564 * PARAMETERS: external_object - The external object to be converted
565 * internal_object - Where the internal object is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 *
567 * RETURN: Status
568 *
Bob Moore6287ee32007-04-03 19:59:37 -0400569 * DESCRIPTION: Copy an external package object to an internal package.
570 * Handles nested packages.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 *
572 ******************************************************************************/
573
574static acpi_status
Bob Moore6287ee32007-04-03 19:59:37 -0400575acpi_ut_copy_epackage_to_ipackage(union acpi_object *external_object,
576 union acpi_operand_object **internal_object)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577{
Bob Moore6287ee32007-04-03 19:59:37 -0400578 acpi_status status = AE_OK;
579 union acpi_operand_object *package_object;
580 union acpi_operand_object **package_elements;
Bob Moore67a119f2008-06-10 13:42:13 +0800581 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
Bob Mooreb229cf92006-04-21 17:15:00 -0400583 ACPI_FUNCTION_TRACE(ut_copy_epackage_to_ipackage);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584
Bob Moore6287ee32007-04-03 19:59:37 -0400585 /* Create the package object */
586
587 package_object =
588 acpi_ut_create_package_object(external_object->package.count);
589 if (!package_object) {
590 return_ACPI_STATUS(AE_NO_MEMORY);
591 }
592
593 package_elements = package_object->package.elements;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
595 /*
Bob Moore1fad8732015-12-29 13:54:36 +0800596 * Recursive implementation. Probably ok, since nested external
597 * packages as parameters should be very rare.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 */
Bob Moore6287ee32007-04-03 19:59:37 -0400599 for (i = 0; i < external_object->package.count; i++) {
600 status =
601 acpi_ut_copy_eobject_to_iobject(&external_object->package.
602 elements[i],
603 &package_elements[i]);
604 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
Bob Moore6287ee32007-04-03 19:59:37 -0400606 /* Truncate package and delete it */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
Bob Moore67a119f2008-06-10 13:42:13 +0800608 package_object->package.count = i;
Bob Moore6287ee32007-04-03 19:59:37 -0400609 package_elements[i] = NULL;
610 acpi_ut_remove_reference(package_object);
611 return_ACPI_STATUS(status);
612 }
613 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
Bob Moore24a31572008-04-10 19:06:43 +0400615 /* Mark package data valid */
616
617 package_object->package.flags |= AOPOBJ_DATA_VALID;
618
Bob Moore6287ee32007-04-03 19:59:37 -0400619 *internal_object = package_object;
620 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621}
622
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623/*******************************************************************************
624 *
625 * FUNCTION: acpi_ut_copy_eobject_to_iobject
626 *
Bob Moore6287ee32007-04-03 19:59:37 -0400627 * PARAMETERS: external_object - The external object to be converted
628 * internal_object - Where the internal object is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 *
Bob Moore90434c12009-12-11 15:02:15 +0800630 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 *
632 * DESCRIPTION: Converts an external object to an internal object.
633 *
634 ******************************************************************************/
635
636acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400637acpi_ut_copy_eobject_to_iobject(union acpi_object *external_object,
638 union acpi_operand_object **internal_object)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639{
Len Brown4be44fc2005-08-05 00:44:28 -0400640 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
Bob Mooreb229cf92006-04-21 17:15:00 -0400642 ACPI_FUNCTION_TRACE(ut_copy_eobject_to_iobject);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643
644 if (external_object->type == ACPI_TYPE_PACKAGE) {
Bob Moore6287ee32007-04-03 19:59:37 -0400645 status =
646 acpi_ut_copy_epackage_to_ipackage(external_object,
647 internal_object);
648 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 /*
650 * Build a simple object (no nested objects)
651 */
Bob Moore1fad8732015-12-29 13:54:36 +0800652 status = acpi_ut_copy_esimple_to_isimple(external_object,
653 internal_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 }
655
Len Brown4be44fc2005-08-05 00:44:28 -0400656 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657}
658
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659/*******************************************************************************
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 *
Bob Moore90434c12009-12-11 15:02:15 +0800668 * DESCRIPTION: Simple copy of one internal object to another. Reference count
Linus Torvalds1da177e2005-04-16 15:20:36 -0700669 * of the destination object is preserved.
670 *
671 ******************************************************************************/
672
Robert Moore44f6c012005-04-18 22:49:35 -0400673static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400674acpi_ut_copy_simple_object(union acpi_operand_object *source_desc,
675 union acpi_operand_object *dest_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676{
Len Brown4be44fc2005-08-05 00:44:28 -0400677 u16 reference_count;
678 union acpi_operand_object *next_object;
Bob Moore33a1d462009-04-22 10:48:57 +0800679 acpi_status status;
Lin Ming17b82322010-04-27 11:46:25 +0800680 acpi_size copy_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
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
Lin Ming17b82322010-04-27 11:46:25 +0800687 /*
688 * Copy the entire source object over the destination object.
689 * Note: Source can be either an operand object or namespace node.
690 */
691 copy_size = sizeof(union acpi_operand_object);
692 if (ACPI_GET_DESCRIPTOR_TYPE(source_desc) == ACPI_DESC_TYPE_NAMED) {
693 copy_size = sizeof(struct acpi_namespace_node);
694 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
Bob Moore4fa46162015-07-01 14:45:11 +0800696 memcpy(ACPI_CAST_PTR(char, dest_desc),
697 ACPI_CAST_PTR(char, source_desc), copy_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698
699 /* Restore the saved fields */
700
701 dest_desc->common.reference_count = reference_count;
702 dest_desc->common.next_object = next_object;
703
Robert Moore6f42ccf2005-05-13 00:00:00 -0400704 /* New object is not static, regardless of source */
705
706 dest_desc->common.flags &= ~AOPOBJ_STATIC_POINTER;
707
Linus Torvalds1da177e2005-04-16 15:20:36 -0700708 /* Handle the objects with extra data */
709
Bob Moore3371c192009-02-18 14:44:03 +0800710 switch (dest_desc->common.type) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711 case ACPI_TYPE_BUFFER:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 /*
713 * Allocate and copy the actual buffer if and only if:
714 * 1) There is a valid buffer pointer
Robert Moore6f42ccf2005-05-13 00:00:00 -0400715 * 2) The buffer has a length > 0
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 */
717 if ((source_desc->buffer.pointer) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400718 (source_desc->buffer.length)) {
Robert Moore6f42ccf2005-05-13 00:00:00 -0400719 dest_desc->buffer.pointer =
Bob Moore83135242006-10-03 00:00:00 -0400720 ACPI_ALLOCATE(source_desc->buffer.length);
Robert Moore6f42ccf2005-05-13 00:00:00 -0400721 if (!dest_desc->buffer.pointer) {
722 return (AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723 }
Robert Moore6f42ccf2005-05-13 00:00:00 -0400724
725 /* Copy the actual buffer data */
726
Bob Moore4fa46162015-07-01 14:45:11 +0800727 memcpy(dest_desc->buffer.pointer,
728 source_desc->buffer.pointer,
729 source_desc->buffer.length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 }
731 break;
732
733 case ACPI_TYPE_STRING:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 /*
735 * Allocate and copy the actual string if and only if:
736 * 1) There is a valid string pointer
Robert Moore6f42ccf2005-05-13 00:00:00 -0400737 * (Pointer to a NULL string is allowed)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738 */
Robert Moore6f42ccf2005-05-13 00:00:00 -0400739 if (source_desc->string.pointer) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 dest_desc->string.pointer =
Bob Moore83135242006-10-03 00:00:00 -0400741 ACPI_ALLOCATE((acpi_size) source_desc->string.
742 length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 if (!dest_desc->string.pointer) {
744 return (AE_NO_MEMORY);
745 }
746
Robert Moore6f42ccf2005-05-13 00:00:00 -0400747 /* Copy the actual string data */
748
Bob Moore4fa46162015-07-01 14:45:11 +0800749 memcpy(dest_desc->string.pointer,
750 source_desc->string.pointer,
751 (acpi_size) source_desc->string.length + 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 }
753 break;
754
755 case ACPI_TYPE_LOCAL_REFERENCE:
756 /*
757 * We copied the reference object, so we now must add a reference
758 * to the object pointed to by the reference
Lin Mingbc7a36a2008-04-10 19:06:42 +0400759 *
Bob Moore1044f1f2008-09-27 11:08:41 +0800760 * DDBHandle reference (from Load/load_table) is a special reference,
761 * it does not have a Reference.Object, so does not need to
Lin Mingbc7a36a2008-04-10 19:06:42 +0400762 * increase the reference count
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 */
Bob Moore1044f1f2008-09-27 11:08:41 +0800764 if (source_desc->reference.class == ACPI_REFCLASS_TABLE) {
Lin Mingbc7a36a2008-04-10 19:06:42 +0400765 break;
766 }
767
Len Brown4be44fc2005-08-05 00:44:28 -0400768 acpi_ut_add_reference(source_desc->reference.object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769 break;
770
Fiodor Suietov6b366e22007-02-02 19:48:18 +0300771 case ACPI_TYPE_REGION:
772 /*
773 * We copied the Region Handler, so we now must add a reference
774 */
775 if (dest_desc->region.handler) {
776 acpi_ut_add_reference(dest_desc->region.handler);
777 }
778 break;
779
Bob Moore33a1d462009-04-22 10:48:57 +0800780 /*
781 * For Mutex and Event objects, we cannot simply copy the underlying
782 * OS object. We must create a new one.
783 */
784 case ACPI_TYPE_MUTEX:
785
786 status = acpi_os_create_mutex(&dest_desc->mutex.os_mutex);
787 if (ACPI_FAILURE(status)) {
Lv Zheng9c0d7932012-12-19 05:37:21 +0000788 return (status);
Bob Moore33a1d462009-04-22 10:48:57 +0800789 }
790 break;
791
792 case ACPI_TYPE_EVENT:
793
794 status = acpi_os_create_semaphore(ACPI_NO_UNIT_LIMIT, 0,
795 &dest_desc->event.
796 os_semaphore);
797 if (ACPI_FAILURE(status)) {
Lv Zheng9c0d7932012-12-19 05:37:21 +0000798 return (status);
Bob Moore33a1d462009-04-22 10:48:57 +0800799 }
800 break;
801
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 default:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000803
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 /* Nothing to do for other simple objects */
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000805
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 break;
807 }
808
809 return (AE_OK);
810}
811
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812/*******************************************************************************
813 *
814 * FUNCTION: acpi_ut_copy_ielement_to_ielement
815 *
816 * PARAMETERS: acpi_pkg_callback
817 *
818 * RETURN: Status
819 *
820 * DESCRIPTION: Copy one package element to another package element
821 *
822 ******************************************************************************/
823
Robert Moore44f6c012005-04-18 22:49:35 -0400824static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400825acpi_ut_copy_ielement_to_ielement(u8 object_type,
826 union acpi_operand_object *source_object,
827 union acpi_generic_state *state,
828 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829{
Len Brown4be44fc2005-08-05 00:44:28 -0400830 acpi_status status = AE_OK;
831 u32 this_index;
832 union acpi_operand_object **this_target_ptr;
833 union acpi_operand_object *target_object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
Len Brown4be44fc2005-08-05 00:44:28 -0400835 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
Len Brown4be44fc2005-08-05 00:44:28 -0400837 this_index = state->pkg.index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 this_target_ptr = (union acpi_operand_object **)
Len Brown4be44fc2005-08-05 00:44:28 -0400839 &state->pkg.dest_object->package.elements[this_index];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
841 switch (object_type) {
842 case ACPI_COPY_TYPE_SIMPLE:
843
844 /* A null source object indicates a (legal) null package element */
845
846 if (source_object) {
847 /*
848 * This is a simple object, just copy it
849 */
Len Brown4be44fc2005-08-05 00:44:28 -0400850 target_object =
Bob Moore3371c192009-02-18 14:44:03 +0800851 acpi_ut_create_internal_object(source_object->
852 common.type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 if (!target_object) {
854 return (AE_NO_MEMORY);
855 }
856
Len Brown4be44fc2005-08-05 00:44:28 -0400857 status =
858 acpi_ut_copy_simple_object(source_object,
859 target_object);
860 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 goto error_exit;
862 }
863
864 *this_target_ptr = target_object;
Len Brown4be44fc2005-08-05 00:44:28 -0400865 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 /* Pass through a null element */
867
868 *this_target_ptr = NULL;
869 }
870 break;
871
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872 case ACPI_COPY_TYPE_PACKAGE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 /*
874 * This object is a package - go down another nesting level
875 * Create and build the package object
876 */
Len Brown4be44fc2005-08-05 00:44:28 -0400877 target_object =
Bob Moore6287ee32007-04-03 19:59:37 -0400878 acpi_ut_create_package_object(source_object->package.count);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879 if (!target_object) {
880 return (AE_NO_MEMORY);
881 }
882
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 target_object->common.flags = source_object->common.flags;
884
Bob Moore6287ee32007-04-03 19:59:37 -0400885 /* Pass the new package object back to the package walk routine */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
Linus Torvalds1da177e2005-04-16 15:20:36 -0700887 state->pkg.this_target_obj = target_object;
888
Bob Moore6287ee32007-04-03 19:59:37 -0400889 /* Store the object pointer in the parent package object */
890
Linus Torvalds1da177e2005-04-16 15:20:36 -0700891 *this_target_ptr = target_object;
892 break;
893
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 default:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000895
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 return (AE_BAD_PARAMETER);
897 }
898
899 return (status);
900
Lv Zheng10622bf2013-10-29 09:30:02 +0800901error_exit:
Len Brown4be44fc2005-08-05 00:44:28 -0400902 acpi_ut_remove_reference(target_object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903 return (status);
904}
905
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906/*******************************************************************************
907 *
908 * FUNCTION: acpi_ut_copy_ipackage_to_ipackage
909 *
Bob Moore90434c12009-12-11 15:02:15 +0800910 * PARAMETERS: source_obj - Pointer to the source package object
911 * dest_obj - Where the internal object is returned
912 * walk_state - Current Walk state descriptor
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913 *
Bob Moore90434c12009-12-11 15:02:15 +0800914 * RETURN: Status
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915 *
916 * DESCRIPTION: This function is called to copy an internal package object
917 * into another internal package object.
918 *
919 ******************************************************************************/
920
Robert Moore44f6c012005-04-18 22:49:35 -0400921static acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400922acpi_ut_copy_ipackage_to_ipackage(union acpi_operand_object *source_obj,
923 union acpi_operand_object *dest_obj,
924 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925{
Len Brown4be44fc2005-08-05 00:44:28 -0400926 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
Bob Mooreb229cf92006-04-21 17:15:00 -0400928 ACPI_FUNCTION_TRACE(ut_copy_ipackage_to_ipackage);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929
Bob Moore3371c192009-02-18 14:44:03 +0800930 dest_obj->common.type = source_obj->common.type;
Len Brown4be44fc2005-08-05 00:44:28 -0400931 dest_obj->common.flags = source_obj->common.flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 dest_obj->package.count = source_obj->package.count;
933
934 /*
935 * Create the object array and walk the source package tree
936 */
Bob Moore83135242006-10-03 00:00:00 -0400937 dest_obj->package.elements = ACPI_ALLOCATE_ZEROED(((acpi_size)
938 source_obj->package.
939 count +
940 1) * sizeof(void *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941 if (!dest_obj->package.elements) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500942 ACPI_ERROR((AE_INFO, "Package allocation failure"));
Len Brown4be44fc2005-08-05 00:44:28 -0400943 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944 }
945
946 /*
947 * Copy the package element-by-element by walking the package "tree".
948 * This handles nested packages of arbitrary depth.
949 */
Len Brown4be44fc2005-08-05 00:44:28 -0400950 status = acpi_ut_walk_package_tree(source_obj, dest_obj,
951 acpi_ut_copy_ielement_to_ielement,
952 walk_state);
953 if (ACPI_FAILURE(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400954
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 /* On failure, delete the destination package object */
956
Len Brown4be44fc2005-08-05 00:44:28 -0400957 acpi_ut_remove_reference(dest_obj);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 }
959
Len Brown4be44fc2005-08-05 00:44:28 -0400960 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700961}
962
Linus Torvalds1da177e2005-04-16 15:20:36 -0700963/*******************************************************************************
964 *
965 * FUNCTION: acpi_ut_copy_iobject_to_iobject
966 *
Bob Moore90434c12009-12-11 15:02:15 +0800967 * PARAMETERS: source_desc - The internal object to be copied
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 * dest_desc - Where the copied object is returned
Bob Moore90434c12009-12-11 15:02:15 +0800969 * walk_state - Current walk state
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 *
971 * RETURN: Status
972 *
973 * DESCRIPTION: Copy an internal object to a new internal object
974 *
975 ******************************************************************************/
976
977acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400978acpi_ut_copy_iobject_to_iobject(union acpi_operand_object *source_desc,
979 union acpi_operand_object **dest_desc,
980 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981{
Len Brown4be44fc2005-08-05 00:44:28 -0400982 acpi_status status = AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
Bob Mooreb229cf92006-04-21 17:15:00 -0400984 ACPI_FUNCTION_TRACE(ut_copy_iobject_to_iobject);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
986 /* Create the top level object */
987
Bob Moore3371c192009-02-18 14:44:03 +0800988 *dest_desc = acpi_ut_create_internal_object(source_desc->common.type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 if (!*dest_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400990 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 }
992
993 /* Copy the object and possible subobjects */
994
Bob Moore3371c192009-02-18 14:44:03 +0800995 if (source_desc->common.type == ACPI_TYPE_PACKAGE) {
Len Brown4be44fc2005-08-05 00:44:28 -0400996 status =
997 acpi_ut_copy_ipackage_to_ipackage(source_desc, *dest_desc,
998 walk_state);
999 } else {
1000 status = acpi_ut_copy_simple_object(source_desc, *dest_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 }
1002
David E. Box8aa5e562014-07-08 10:05:52 +08001003 /* Delete the allocated object if copy failed */
1004
1005 if (ACPI_FAILURE(status)) {
1006 acpi_ut_remove_reference(*dest_desc);
1007 }
1008
Len Brown4be44fc2005-08-05 00:44:28 -04001009 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010}