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