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