Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: utcopy - Internal to external object translation utilities | |
4 | * | |
5 | *****************************************************************************/ | |
6 | ||
7 | /* | |
c8100dc4 | 8 | * Copyright (C) 2000 - 2016, 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> |
e2f7a777 LB |
45 | #include "accommon.h" |
46 | #include "acnamesp.h" | |
cd0b2248 | 47 | |
1da177e4 | 48 | |
1da177e4 | 49 | #define _COMPONENT ACPI_UTILITIES |
4be44fcd | 50 | ACPI_MODULE_NAME("utcopy") |
1da177e4 | 51 | |
44f6c012 | 52 | /* Local prototypes */ |
44f6c012 | 53 | static acpi_status |
4be44fcd LB |
54 | acpi_ut_copy_isimple_to_esimple(union acpi_operand_object *internal_object, |
55 | union acpi_object *external_object, | |
f5c1e1c5 | 56 | u8 *data_space, acpi_size *buffer_space_used); |
44f6c012 RM |
57 | |
58 | static acpi_status | |
4be44fcd LB |
59 | acpi_ut_copy_ielement_to_ielement(u8 object_type, |
60 | union acpi_operand_object *source_object, | |
61 | union acpi_generic_state *state, | |
62 | void *context); | |
44f6c012 RM |
63 | |
64 | static acpi_status | |
4be44fcd | 65 | acpi_ut_copy_ipackage_to_epackage(union acpi_operand_object *internal_object, |
f5c1e1c5 | 66 | u8 *buffer, acpi_size *space_used); |
44f6c012 RM |
67 | |
68 | static acpi_status | |
4be44fcd LB |
69 | acpi_ut_copy_esimple_to_isimple(union acpi_object *user_obj, |
70 | union acpi_operand_object **return_obj); | |
44f6c012 | 71 | |
6287ee32 BM |
72 | static acpi_status |
73 | acpi_ut_copy_epackage_to_ipackage(union acpi_object *external_object, | |
74 | union acpi_operand_object **internal_object); | |
75 | ||
44f6c012 | 76 | static acpi_status |
4be44fcd LB |
77 | acpi_ut_copy_simple_object(union acpi_operand_object *source_desc, |
78 | union acpi_operand_object *dest_desc); | |
44f6c012 RM |
79 | |
80 | static acpi_status | |
4be44fcd LB |
81 | acpi_ut_copy_ielement_to_eelement(u8 object_type, |
82 | union acpi_operand_object *source_object, | |
83 | union acpi_generic_state *state, | |
84 | void *context); | |
44f6c012 RM |
85 | |
86 | static acpi_status | |
4be44fcd LB |
87 | acpi_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); | |
1da177e4 LT |
90 | |
91 | /******************************************************************************* | |
92 | * | |
93 | * FUNCTION: acpi_ut_copy_isimple_to_esimple | |
94 | * | |
44f6c012 RM |
95 | * 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 | |
1da177e4 LT |
100 | * |
101 | * RETURN: Status | |
102 | * | |
44f6c012 RM |
103 | * DESCRIPTION: This function is called to copy a simple internal object to |
104 | * an external object. | |
1da177e4 | 105 | * |
44f6c012 RM |
106 | * The data_space buffer is assumed to have sufficient space for |
107 | * the object. | |
1da177e4 LT |
108 | * |
109 | ******************************************************************************/ | |
110 | ||
111 | static acpi_status | |
4be44fcd LB |
112 | acpi_ut_copy_isimple_to_esimple(union acpi_operand_object *internal_object, |
113 | union acpi_object *external_object, | |
f5c1e1c5 | 114 | u8 *data_space, acpi_size *buffer_space_used) |
1da177e4 | 115 | { |
4be44fcd | 116 | acpi_status status = AE_OK; |
1da177e4 | 117 | |
b229cf92 | 118 | ACPI_FUNCTION_TRACE(ut_copy_isimple_to_esimple); |
1da177e4 LT |
119 | |
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) { | |
4be44fcd | 127 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
128 | } |
129 | ||
130 | /* Always clear the external object */ | |
131 | ||
4fa4616e | 132 | memset(external_object, 0, sizeof(union acpi_object)); |
1da177e4 LT |
133 | |
134 | /* | |
135 | * In general, the external object will be the same type as | |
136 | * the internal object | |
137 | */ | |
3371c19c | 138 | external_object->type = internal_object->common.type; |
1da177e4 LT |
139 | |
140 | /* However, only a limited number of external types are supported */ | |
141 | ||
3371c19c | 142 | switch (internal_object->common.type) { |
1da177e4 LT |
143 | case ACPI_TYPE_STRING: |
144 | ||
4be44fcd | 145 | external_object->string.pointer = (char *)data_space; |
1da177e4 | 146 | external_object->string.length = internal_object->string.length; |
4be44fcd LB |
147 | *buffer_space_used = ACPI_ROUND_UP_TO_NATIVE_WORD((acpi_size) |
148 | internal_object-> | |
149 | string. | |
150 | length + 1); | |
151 | ||
4fa4616e BM |
152 | memcpy((void *)data_space, |
153 | (void *)internal_object->string.pointer, | |
f5c1e1c5 | 154 | (acpi_size)internal_object->string.length + 1); |
1da177e4 LT |
155 | break; |
156 | ||
1da177e4 LT |
157 | case ACPI_TYPE_BUFFER: |
158 | ||
159 | external_object->buffer.pointer = data_space; | |
160 | external_object->buffer.length = internal_object->buffer.length; | |
4be44fcd LB |
161 | *buffer_space_used = |
162 | ACPI_ROUND_UP_TO_NATIVE_WORD(internal_object->string. | |
163 | length); | |
1da177e4 | 164 | |
4fa4616e BM |
165 | memcpy((void *)data_space, |
166 | (void *)internal_object->buffer.pointer, | |
167 | internal_object->buffer.length); | |
1da177e4 LT |
168 | break; |
169 | ||
1da177e4 LT |
170 | case ACPI_TYPE_INTEGER: |
171 | ||
172 | external_object->integer.value = internal_object->integer.value; | |
173 | break; | |
174 | ||
1da177e4 LT |
175 | case ACPI_TYPE_LOCAL_REFERENCE: |
176 | ||
cd0b2248 BM |
177 | /* This is an object reference. */ |
178 | ||
1044f1f6 BM |
179 | switch (internal_object->reference.class) { |
180 | case ACPI_REFCLASS_NAME: | |
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", | |
3371c19c BM |
224 | acpi_ut_get_type_name(internal_object->common. |
225 | type))); | |
b1dd9096 | 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 | 245 | static acpi_status |
4be44fcd LB |
246 | acpi_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; |
1fad8738 BM |
260 | target_object = (union acpi_object *)&((union acpi_object *) |
261 | (state->pkg.dest_object))-> | |
262 | package.elements[this_index]; | |
1da177e4 LT |
263 | |
264 | switch (object_type) { | |
265 | case ACPI_COPY_TYPE_SIMPLE: | |
1da177e4 LT |
266 | /* |
267 | * This is a simple or null object | |
268 | */ | |
4be44fcd LB |
269 | status = acpi_ut_copy_isimple_to_esimple(source_object, |
270 | target_object, | |
271 | info->free_space, | |
272 | &object_space); | |
273 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
274 | return (status); |
275 | } | |
276 | break; | |
277 | ||
1da177e4 | 278 | case ACPI_COPY_TYPE_PACKAGE: |
1da177e4 LT |
279 | /* |
280 | * Build the package object | |
281 | */ | |
4be44fcd LB |
282 | target_object->type = ACPI_TYPE_PACKAGE; |
283 | target_object->package.count = source_object->package.count; | |
44f6c012 | 284 | target_object->package.elements = |
4be44fcd | 285 | ACPI_CAST_PTR(union acpi_object, info->free_space); |
1da177e4 LT |
286 | |
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 | */ | |
4be44fcd LB |
296 | object_space = ACPI_ROUND_UP_TO_NATIVE_WORD((acpi_size) |
297 | target_object-> | |
298 | package.count * | |
299 | sizeof(union | |
300 | acpi_object)); | |
1da177e4 LT |
301 | break; |
302 | ||
1da177e4 | 303 | default: |
1d1ea1b7 | 304 | |
1da177e4 LT |
305 | return (AE_BAD_PARAMETER); |
306 | } | |
307 | ||
4be44fcd LB |
308 | info->free_space += object_space; |
309 | info->length += object_space; | |
1da177e4 LT |
310 | return (status); |
311 | } | |
312 | ||
1da177e4 LT |
313 | /******************************************************************************* |
314 | * | |
315 | * FUNCTION: acpi_ut_copy_ipackage_to_epackage | |
316 | * | |
44f6c012 | 317 | * PARAMETERS: internal_object - Pointer to the object we are returning |
ba494bee | 318 | * buffer - Where the object is returned |
44f6c012 | 319 | * space_used - Where the object length is returned |
1da177e4 LT |
320 | * |
321 | * RETURN: Status | |
322 | * | |
323 | * DESCRIPTION: This function is called to place a package object in a user | |
90434c1c | 324 | * buffer. A package object by definition contains other objects. |
1da177e4 LT |
325 | * |
326 | * The buffer is assumed to have sufficient space for the object. | |
90434c1c BM |
327 | * The caller must have verified the buffer length needed using |
328 | * the acpi_ut_get_object_size function before calling this function. | |
1da177e4 LT |
329 | * |
330 | ******************************************************************************/ | |
331 | ||
332 | static acpi_status | |
4be44fcd | 333 | acpi_ut_copy_ipackage_to_epackage(union acpi_operand_object *internal_object, |
f5c1e1c5 | 334 | u8 *buffer, acpi_size *space_used) |
1da177e4 | 335 | { |
4be44fcd LB |
336 | union acpi_object *external_object; |
337 | acpi_status status; | |
338 | struct acpi_pkg_info info; | |
1da177e4 | 339 | |
b229cf92 | 340 | ACPI_FUNCTION_TRACE(ut_copy_ipackage_to_epackage); |
1da177e4 LT |
341 | |
342 | /* | |
343 | * First package at head of the buffer | |
344 | */ | |
4be44fcd | 345 | external_object = ACPI_CAST_PTR(union acpi_object, buffer); |
1da177e4 LT |
346 | |
347 | /* | |
348 | * Free space begins right after the first package | |
349 | */ | |
4be44fcd | 350 | info.length = ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object)); |
1fad8738 BM |
351 | info.free_space = buffer + |
352 | ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object)); | |
1da177e4 LT |
353 | info.object_space = 0; |
354 | info.num_packages = 1; | |
355 | ||
3371c19c | 356 | external_object->type = internal_object->common.type; |
4be44fcd | 357 | external_object->package.count = internal_object->package.count; |
1fad8738 BM |
358 | external_object->package.elements = |
359 | ACPI_CAST_PTR(union acpi_object, info.free_space); | |
1da177e4 LT |
360 | |
361 | /* | |
362 | * Leave room for an array of ACPI_OBJECTS in the buffer | |
363 | * and move the free space past it | |
364 | */ | |
f5c1e1c5 | 365 | info.length += (acpi_size)external_object->package.count * |
4be44fcd | 366 | ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object)); |
1da177e4 | 367 | info.free_space += external_object->package.count * |
4be44fcd | 368 | ACPI_ROUND_UP_TO_NATIVE_WORD(sizeof(union acpi_object)); |
1da177e4 | 369 | |
4be44fcd LB |
370 | status = acpi_ut_walk_package_tree(internal_object, external_object, |
371 | acpi_ut_copy_ielement_to_eelement, | |
372 | &info); | |
1da177e4 LT |
373 | |
374 | *space_used = info.length; | |
4be44fcd | 375 | return_ACPI_STATUS(status); |
1da177e4 LT |
376 | } |
377 | ||
1da177e4 LT |
378 | /******************************************************************************* |
379 | * | |
380 | * FUNCTION: acpi_ut_copy_iobject_to_eobject | |
381 | * | |
44f6c012 | 382 | * PARAMETERS: internal_object - The internal object to be converted |
90434c1c | 383 | * ret_buffer - Where the object is returned |
1da177e4 LT |
384 | * |
385 | * RETURN: Status | |
386 | * | |
90434c1c BM |
387 | * DESCRIPTION: This function is called to build an API object to be returned |
388 | * to the caller. | |
1da177e4 LT |
389 | * |
390 | ******************************************************************************/ | |
391 | ||
392 | acpi_status | |
4be44fcd LB |
393 | acpi_ut_copy_iobject_to_eobject(union acpi_operand_object *internal_object, |
394 | struct acpi_buffer *ret_buffer) | |
1da177e4 | 395 | { |
4be44fcd | 396 | acpi_status status; |
1da177e4 | 397 | |
b229cf92 | 398 | ACPI_FUNCTION_TRACE(ut_copy_iobject_to_eobject); |
1da177e4 | 399 | |
3371c19c | 400 | if (internal_object->common.type == ACPI_TYPE_PACKAGE) { |
1da177e4 LT |
401 | /* |
402 | * Package object: Copy all subobjects (including | |
403 | * nested packages) | |
404 | */ | |
4be44fcd LB |
405 | status = acpi_ut_copy_ipackage_to_epackage(internal_object, |
406 | ret_buffer->pointer, | |
407 | &ret_buffer->length); | |
408 | } else { | |
1da177e4 LT |
409 | /* |
410 | * Build a simple object (no nested objects) | |
411 | */ | |
4be44fcd | 412 | status = acpi_ut_copy_isimple_to_esimple(internal_object, |
c51a4de8 BM |
413 | 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))), | |
4be44fcd | 424 | &ret_buffer->length); |
1da177e4 LT |
425 | /* |
426 | * build simple does not include the object size in the length | |
427 | * so we add it in here | |
428 | */ | |
4be44fcd | 429 | ret_buffer->length += sizeof(union acpi_object); |
1da177e4 LT |
430 | } |
431 | ||
4be44fcd | 432 | return_ACPI_STATUS(status); |
1da177e4 LT |
433 | } |
434 | ||
1da177e4 LT |
435 | /******************************************************************************* |
436 | * | |
437 | * FUNCTION: acpi_ut_copy_esimple_to_isimple | |
438 | * | |
44f6c012 RM |
439 | * PARAMETERS: external_object - The external object to be converted |
440 | * ret_internal_object - Where the internal object is returned | |
1da177e4 LT |
441 | * |
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 | ||
44f6c012 | 451 | static acpi_status |
4be44fcd LB |
452 | acpi_ut_copy_esimple_to_isimple(union acpi_object *external_object, |
453 | union acpi_operand_object **ret_internal_object) | |
1da177e4 | 454 | { |
4be44fcd | 455 | union acpi_operand_object *internal_object; |
1da177e4 | 456 | |
b229cf92 | 457 | ACPI_FUNCTION_TRACE(ut_copy_esimple_to_isimple); |
1da177e4 LT |
458 | |
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: | |
cd0b2248 | 466 | case ACPI_TYPE_LOCAL_REFERENCE: |
1da177e4 | 467 | |
4be44fcd LB |
468 | internal_object = acpi_ut_create_internal_object((u8) |
469 | external_object-> | |
470 | type); | |
1da177e4 | 471 | if (!internal_object) { |
4be44fcd | 472 | return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4 LT |
473 | } |
474 | break; | |
475 | ||
cd0b2248 BM |
476 | 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 | ||
1da177e4 | 481 | default: |
1d1ea1b7 | 482 | |
1da177e4 LT |
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 = | |
ec41f193 BM |
498 | ACPI_ALLOCATE_ZEROED((acpi_size) |
499 | external_object->string.length + 1); | |
500 | ||
1da177e4 LT |
501 | if (!internal_object->string.pointer) { |
502 | goto error_exit; | |
503 | } | |
504 | ||
4fa4616e BM |
505 | memcpy(internal_object->string.pointer, |
506 | external_object->string.pointer, | |
507 | external_object->string.length); | |
1da177e4 LT |
508 | |
509 | internal_object->string.length = external_object->string.length; | |
510 | break; | |
511 | ||
1da177e4 LT |
512 | case ACPI_TYPE_BUFFER: |
513 | ||
514 | internal_object->buffer.pointer = | |
8313524a | 515 | ACPI_ALLOCATE_ZEROED(external_object->buffer.length); |
1da177e4 LT |
516 | if (!internal_object->buffer.pointer) { |
517 | goto error_exit; | |
518 | } | |
519 | ||
4fa4616e BM |
520 | memcpy(internal_object->buffer.pointer, |
521 | external_object->buffer.pointer, | |
522 | external_object->buffer.length); | |
1da177e4 LT |
523 | |
524 | internal_object->buffer.length = external_object->buffer.length; | |
24a3157a BM |
525 | |
526 | /* Mark buffer data valid */ | |
527 | ||
528 | internal_object->buffer.flags |= AOPOBJ_DATA_VALID; | |
1da177e4 LT |
529 | break; |
530 | ||
1da177e4 LT |
531 | case ACPI_TYPE_INTEGER: |
532 | ||
4be44fcd | 533 | internal_object->integer.value = external_object->integer.value; |
1da177e4 LT |
534 | break; |
535 | ||
cd0b2248 BM |
536 | case ACPI_TYPE_LOCAL_REFERENCE: |
537 | ||
ab85e928 | 538 | /* An incoming reference is defined to be a namespace node */ |
cd0b2248 | 539 | |
ab85e928 BM |
540 | internal_object->reference.class = ACPI_REFCLASS_REFOF; |
541 | internal_object->reference.object = | |
cd0b2248 BM |
542 | external_object->reference.handle; |
543 | break; | |
544 | ||
1da177e4 | 545 | default: |
1d1ea1b7 | 546 | |
1da177e4 | 547 | /* Other types can't get here */ |
1d1ea1b7 | 548 | |
1da177e4 LT |
549 | break; |
550 | } | |
551 | ||
552 | *ret_internal_object = internal_object; | |
4be44fcd | 553 | return_ACPI_STATUS(AE_OK); |
1da177e4 | 554 | |
10622bf8 | 555 | error_exit: |
4be44fcd LB |
556 | acpi_ut_remove_reference(internal_object); |
557 | return_ACPI_STATUS(AE_NO_MEMORY); | |
1da177e4 LT |
558 | } |
559 | ||
1da177e4 LT |
560 | /******************************************************************************* |
561 | * | |
562 | * FUNCTION: acpi_ut_copy_epackage_to_ipackage | |
563 | * | |
6287ee32 BM |
564 | * PARAMETERS: external_object - The external object to be converted |
565 | * internal_object - Where the internal object is returned | |
1da177e4 LT |
566 | * |
567 | * RETURN: Status | |
568 | * | |
6287ee32 BM |
569 | * DESCRIPTION: Copy an external package object to an internal package. |
570 | * Handles nested packages. | |
1da177e4 LT |
571 | * |
572 | ******************************************************************************/ | |
573 | ||
574 | static acpi_status | |
6287ee32 BM |
575 | acpi_ut_copy_epackage_to_ipackage(union acpi_object *external_object, |
576 | union acpi_operand_object **internal_object) | |
1da177e4 | 577 | { |
6287ee32 BM |
578 | acpi_status status = AE_OK; |
579 | union acpi_operand_object *package_object; | |
580 | union acpi_operand_object **package_elements; | |
67a119f9 | 581 | u32 i; |
1da177e4 | 582 | |
b229cf92 | 583 | ACPI_FUNCTION_TRACE(ut_copy_epackage_to_ipackage); |
1da177e4 | 584 | |
6287ee32 | 585 | /* Create the package object */ |
1da177e4 | 586 | |
6287ee32 BM |
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 | } | |
1da177e4 | 592 | |
6287ee32 | 593 | package_elements = package_object->package.elements; |
1da177e4 LT |
594 | |
595 | /* | |
1fad8738 BM |
596 | * Recursive implementation. Probably ok, since nested external |
597 | * packages as parameters should be very rare. | |
1da177e4 | 598 | */ |
6287ee32 BM |
599 | 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)) { | |
1da177e4 | 605 | |
6287ee32 | 606 | /* Truncate package and delete it */ |
1da177e4 | 607 | |
67a119f9 | 608 | package_object->package.count = i; |
6287ee32 BM |
609 | package_elements[i] = NULL; |
610 | acpi_ut_remove_reference(package_object); | |
611 | return_ACPI_STATUS(status); | |
612 | } | |
613 | } | |
1da177e4 | 614 | |
24a3157a BM |
615 | /* Mark package data valid */ |
616 | ||
617 | package_object->package.flags |= AOPOBJ_DATA_VALID; | |
618 | ||
6287ee32 BM |
619 | *internal_object = package_object; |
620 | return_ACPI_STATUS(status); | |
621 | } | |
1da177e4 LT |
622 | |
623 | /******************************************************************************* | |
624 | * | |
625 | * FUNCTION: acpi_ut_copy_eobject_to_iobject | |
626 | * | |
6287ee32 BM |
627 | * PARAMETERS: external_object - The external object to be converted |
628 | * internal_object - Where the internal object is returned | |
1da177e4 | 629 | * |
90434c1c | 630 | * RETURN: Status |
1da177e4 LT |
631 | * |
632 | * DESCRIPTION: Converts an external object to an internal object. | |
633 | * | |
634 | ******************************************************************************/ | |
635 | ||
636 | acpi_status | |
4be44fcd LB |
637 | acpi_ut_copy_eobject_to_iobject(union acpi_object *external_object, |
638 | union acpi_operand_object **internal_object) | |
1da177e4 | 639 | { |
4be44fcd | 640 | acpi_status status; |
1da177e4 | 641 | |
b229cf92 | 642 | ACPI_FUNCTION_TRACE(ut_copy_eobject_to_iobject); |
1da177e4 LT |
643 | |
644 | if (external_object->type == ACPI_TYPE_PACKAGE) { | |
6287ee32 BM |
645 | status = |
646 | acpi_ut_copy_epackage_to_ipackage(external_object, | |
647 | internal_object); | |
648 | } else { | |
1da177e4 LT |
649 | /* |
650 | * Build a simple object (no nested objects) | |
651 | */ | |
1fad8738 BM |
652 | status = acpi_ut_copy_esimple_to_isimple(external_object, |
653 | internal_object); | |
1da177e4 LT |
654 | } |
655 | ||
4be44fcd | 656 | return_ACPI_STATUS(status); |
1da177e4 LT |
657 | } |
658 | ||
1da177e4 LT |
659 | /******************************************************************************* |
660 | * | |
661 | * FUNCTION: acpi_ut_copy_simple_object | |
662 | * | |
663 | * PARAMETERS: source_desc - The internal object to be copied | |
664 | * dest_desc - New target object | |
665 | * | |
666 | * RETURN: Status | |
667 | * | |
90434c1c | 668 | * DESCRIPTION: Simple copy of one internal object to another. Reference count |
1da177e4 LT |
669 | * of the destination object is preserved. |
670 | * | |
671 | ******************************************************************************/ | |
672 | ||
44f6c012 | 673 | static acpi_status |
4be44fcd LB |
674 | acpi_ut_copy_simple_object(union acpi_operand_object *source_desc, |
675 | union acpi_operand_object *dest_desc) | |
1da177e4 | 676 | { |
4be44fcd LB |
677 | u16 reference_count; |
678 | union acpi_operand_object *next_object; | |
33a1d461 | 679 | acpi_status status; |
17b82327 | 680 | acpi_size copy_size; |
1da177e4 LT |
681 | |
682 | /* Save fields from destination that we don't want to overwrite */ | |
683 | ||
684 | reference_count = dest_desc->common.reference_count; | |
685 | next_object = dest_desc->common.next_object; | |
686 | ||
17b82327 LM |
687 | /* |
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 | } | |
1da177e4 | 695 | |
4fa4616e BM |
696 | memcpy(ACPI_CAST_PTR(char, dest_desc), |
697 | ACPI_CAST_PTR(char, source_desc), copy_size); | |
1da177e4 LT |
698 | |
699 | /* Restore the saved fields */ | |
700 | ||
701 | dest_desc->common.reference_count = reference_count; | |
702 | dest_desc->common.next_object = next_object; | |
703 | ||
6f42ccf2 RM |
704 | /* New object is not static, regardless of source */ |
705 | ||
706 | dest_desc->common.flags &= ~AOPOBJ_STATIC_POINTER; | |
707 | ||
1da177e4 LT |
708 | /* Handle the objects with extra data */ |
709 | ||
3371c19c | 710 | switch (dest_desc->common.type) { |
1da177e4 | 711 | case ACPI_TYPE_BUFFER: |
1da177e4 LT |
712 | /* |
713 | * Allocate and copy the actual buffer if and only if: | |
714 | * 1) There is a valid buffer pointer | |
6f42ccf2 | 715 | * 2) The buffer has a length > 0 |
1da177e4 LT |
716 | */ |
717 | if ((source_desc->buffer.pointer) && | |
4be44fcd | 718 | (source_desc->buffer.length)) { |
6f42ccf2 | 719 | dest_desc->buffer.pointer = |
8313524a | 720 | ACPI_ALLOCATE(source_desc->buffer.length); |
6f42ccf2 RM |
721 | if (!dest_desc->buffer.pointer) { |
722 | return (AE_NO_MEMORY); | |
723 | } | |
1da177e4 | 724 | |
6f42ccf2 | 725 | /* Copy the actual buffer data */ |
1da177e4 | 726 | |
4fa4616e BM |
727 | memcpy(dest_desc->buffer.pointer, |
728 | source_desc->buffer.pointer, | |
729 | source_desc->buffer.length); | |
1da177e4 LT |
730 | } |
731 | break; | |
732 | ||
733 | case ACPI_TYPE_STRING: | |
1da177e4 LT |
734 | /* |
735 | * Allocate and copy the actual string if and only if: | |
736 | * 1) There is a valid string pointer | |
6f42ccf2 | 737 | * (Pointer to a NULL string is allowed) |
1da177e4 | 738 | */ |
6f42ccf2 | 739 | if (source_desc->string.pointer) { |
1da177e4 | 740 | dest_desc->string.pointer = |
f5c1e1c5 | 741 | ACPI_ALLOCATE((acpi_size)source_desc->string. |
8313524a | 742 | length + 1); |
1da177e4 LT |
743 | if (!dest_desc->string.pointer) { |
744 | return (AE_NO_MEMORY); | |
745 | } | |
746 | ||
6f42ccf2 RM |
747 | /* Copy the actual string data */ |
748 | ||
4fa4616e BM |
749 | memcpy(dest_desc->string.pointer, |
750 | source_desc->string.pointer, | |
f5c1e1c5 | 751 | (acpi_size)source_desc->string.length + 1); |
1da177e4 LT |
752 | } |
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 | |
bc7a36ab | 759 | * |
1044f1f6 BM |
760 | * DDBHandle reference (from Load/load_table) is a special reference, |
761 | * it does not have a Reference.Object, so does not need to | |
bc7a36ab | 762 | * increase the reference count |
1da177e4 | 763 | */ |
1044f1f6 | 764 | if (source_desc->reference.class == ACPI_REFCLASS_TABLE) { |
bc7a36ab LM |
765 | break; |
766 | } | |
767 | ||
4be44fcd | 768 | acpi_ut_add_reference(source_desc->reference.object); |
1da177e4 LT |
769 | break; |
770 | ||
6b366e2f FS |
771 | 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 | ||
33a1d461 BM |
780 | /* |
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)) { | |
9c0d7939 | 788 | return (status); |
33a1d461 BM |
789 | } |
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)) { | |
9c0d7939 | 798 | return (status); |
33a1d461 BM |
799 | } |
800 | break; | |
801 | ||
1da177e4 | 802 | default: |
1d1ea1b7 | 803 | |
1da177e4 | 804 | /* Nothing to do for other simple objects */ |
1d1ea1b7 | 805 | |
1da177e4 LT |
806 | break; |
807 | } | |
808 | ||
809 | return (AE_OK); | |
810 | } | |
811 | ||
1da177e4 LT |
812 | /******************************************************************************* |
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 | ||
44f6c012 | 824 | static acpi_status |
4be44fcd LB |
825 | acpi_ut_copy_ielement_to_ielement(u8 object_type, |
826 | union acpi_operand_object *source_object, | |
827 | union acpi_generic_state *state, | |
828 | void *context) | |
1da177e4 | 829 | { |
4be44fcd LB |
830 | acpi_status status = AE_OK; |
831 | u32 this_index; | |
832 | union acpi_operand_object **this_target_ptr; | |
833 | union acpi_operand_object *target_object; | |
1da177e4 | 834 | |
4be44fcd | 835 | ACPI_FUNCTION_ENTRY(); |
1da177e4 | 836 | |
4be44fcd | 837 | this_index = state->pkg.index; |
1da177e4 | 838 | this_target_ptr = (union acpi_operand_object **) |
4be44fcd | 839 | &state->pkg.dest_object->package.elements[this_index]; |
1da177e4 LT |
840 | |
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 | */ | |
4be44fcd | 850 | target_object = |
3371c19c BM |
851 | acpi_ut_create_internal_object(source_object-> |
852 | common.type); | |
1da177e4 LT |
853 | if (!target_object) { |
854 | return (AE_NO_MEMORY); | |
855 | } | |
856 | ||
4be44fcd LB |
857 | status = |
858 | acpi_ut_copy_simple_object(source_object, | |
859 | target_object); | |
860 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
861 | goto error_exit; |
862 | } | |
863 | ||
864 | *this_target_ptr = target_object; | |
4be44fcd | 865 | } else { |
1da177e4 LT |
866 | /* Pass through a null element */ |
867 | ||
868 | *this_target_ptr = NULL; | |
869 | } | |
870 | break; | |
871 | ||
1da177e4 | 872 | case ACPI_COPY_TYPE_PACKAGE: |
1da177e4 LT |
873 | /* |
874 | * This object is a package - go down another nesting level | |
875 | * Create and build the package object | |
876 | */ | |
4be44fcd | 877 | target_object = |
6287ee32 | 878 | acpi_ut_create_package_object(source_object->package.count); |
1da177e4 LT |
879 | if (!target_object) { |
880 | return (AE_NO_MEMORY); | |
881 | } | |
882 | ||
1da177e4 LT |
883 | target_object->common.flags = source_object->common.flags; |
884 | ||
6287ee32 | 885 | /* Pass the new package object back to the package walk routine */ |
1da177e4 | 886 | |
1da177e4 LT |
887 | state->pkg.this_target_obj = target_object; |
888 | ||
6287ee32 BM |
889 | /* Store the object pointer in the parent package object */ |
890 | ||
1da177e4 LT |
891 | *this_target_ptr = target_object; |
892 | break; | |
893 | ||
1da177e4 | 894 | default: |
1d1ea1b7 | 895 | |
1da177e4 LT |
896 | return (AE_BAD_PARAMETER); |
897 | } | |
898 | ||
899 | return (status); | |
900 | ||
10622bf8 | 901 | error_exit: |
4be44fcd | 902 | acpi_ut_remove_reference(target_object); |
1da177e4 LT |
903 | return (status); |
904 | } | |
905 | ||
1da177e4 LT |
906 | /******************************************************************************* |
907 | * | |
908 | * FUNCTION: acpi_ut_copy_ipackage_to_ipackage | |
909 | * | |
90434c1c BM |
910 | * 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 | |
1da177e4 | 913 | * |
90434c1c | 914 | * RETURN: Status |
1da177e4 LT |
915 | * |
916 | * DESCRIPTION: This function is called to copy an internal package object | |
917 | * into another internal package object. | |
918 | * | |
919 | ******************************************************************************/ | |
920 | ||
44f6c012 | 921 | static acpi_status |
4be44fcd LB |
922 | acpi_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) | |
1da177e4 | 925 | { |
4be44fcd | 926 | acpi_status status = AE_OK; |
1da177e4 | 927 | |
b229cf92 | 928 | ACPI_FUNCTION_TRACE(ut_copy_ipackage_to_ipackage); |
1da177e4 | 929 | |
3371c19c | 930 | dest_obj->common.type = source_obj->common.type; |
4be44fcd | 931 | dest_obj->common.flags = source_obj->common.flags; |
1da177e4 LT |
932 | dest_obj->package.count = source_obj->package.count; |
933 | ||
934 | /* | |
935 | * Create the object array and walk the source package tree | |
936 | */ | |
8313524a BM |
937 | dest_obj->package.elements = ACPI_ALLOCATE_ZEROED(((acpi_size) |
938 | source_obj->package. | |
939 | count + | |
940 | 1) * sizeof(void *)); | |
1da177e4 | 941 | if (!dest_obj->package.elements) { |
b8e4d893 | 942 | ACPI_ERROR((AE_INFO, "Package allocation failure")); |
4be44fcd | 943 | return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4 LT |
944 | } |
945 | ||
946 | /* | |
947 | * Copy the package element-by-element by walking the package "tree". | |
948 | * This handles nested packages of arbitrary depth. | |
949 | */ | |
4be44fcd LB |
950 | 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)) { | |
52fc0b02 | 954 | |
1da177e4 LT |
955 | /* On failure, delete the destination package object */ |
956 | ||
4be44fcd | 957 | acpi_ut_remove_reference(dest_obj); |
1da177e4 LT |
958 | } |
959 | ||
4be44fcd | 960 | return_ACPI_STATUS(status); |
1da177e4 LT |
961 | } |
962 | ||
1da177e4 LT |
963 | /******************************************************************************* |
964 | * | |
965 | * FUNCTION: acpi_ut_copy_iobject_to_iobject | |
966 | * | |
90434c1c | 967 | * PARAMETERS: source_desc - The internal object to be copied |
1da177e4 | 968 | * dest_desc - Where the copied object is returned |
90434c1c | 969 | * walk_state - Current walk state |
1da177e4 LT |
970 | * |
971 | * RETURN: Status | |
972 | * | |
973 | * DESCRIPTION: Copy an internal object to a new internal object | |
974 | * | |
975 | ******************************************************************************/ | |
976 | ||
977 | acpi_status | |
4be44fcd LB |
978 | acpi_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) | |
1da177e4 | 981 | { |
4be44fcd | 982 | acpi_status status = AE_OK; |
1da177e4 | 983 | |
b229cf92 | 984 | ACPI_FUNCTION_TRACE(ut_copy_iobject_to_iobject); |
1da177e4 LT |
985 | |
986 | /* Create the top level object */ | |
987 | ||
3371c19c | 988 | *dest_desc = acpi_ut_create_internal_object(source_desc->common.type); |
1da177e4 | 989 | if (!*dest_desc) { |
4be44fcd | 990 | return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4 LT |
991 | } |
992 | ||
993 | /* Copy the object and possible subobjects */ | |
994 | ||
3371c19c | 995 | if (source_desc->common.type == ACPI_TYPE_PACKAGE) { |
4be44fcd LB |
996 | 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); | |
1da177e4 LT |
1001 | } |
1002 | ||
8aa5e56e DB |
1003 | /* Delete the allocated object if copy failed */ |
1004 | ||
1005 | if (ACPI_FAILURE(status)) { | |
1006 | acpi_ut_remove_reference(*dest_desc); | |
1007 | } | |
1008 | ||
4be44fcd | 1009 | return_ACPI_STATUS(status); |
1da177e4 | 1010 | } |