1 /******************************************************************************
3 * Module Name: cmcopy - Internal to external object translation utilities
6 *****************************************************************************/
9 * Copyright (C) 2000, 2001 R. Byron Moore
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33 #define _COMPONENT ACPI_UTILITIES
34 MODULE_NAME ("cmcopy")
37 /*******************************************************************************
39 * FUNCTION: Acpi_cm_copy_isimple_to_esimple
41 * PARAMETERS: *Internal_object - Pointer to the object we are examining
42 * *Buffer - Where the object is returned
43 * *Space_used - Where the data length is returned
47 * DESCRIPTION: This function is called to place a simple object in a user
50 * The buffer is assumed to have sufficient space for the object.
52 ******************************************************************************/
55 acpi_cm_copy_isimple_to_esimple (
56 ACPI_OPERAND_OBJECT
*internal_object
,
57 ACPI_OBJECT
*external_object
,
59 u32
*buffer_space_used
)
62 ACPI_STATUS status
= AE_OK
;
66 * Check for NULL object case (could be an uninitialized
70 if (!internal_object
) {
71 *buffer_space_used
= 0;
75 /* Always clear the external object */
77 MEMSET (external_object
, 0, sizeof (ACPI_OBJECT
));
80 * In general, the external object will be the same type as
84 external_object
->type
= internal_object
->common
.type
;
86 /* However, only a limited number of external types are supported */
88 switch (internal_object
->common
.type
) {
90 case ACPI_TYPE_STRING
:
92 length
= internal_object
->string
.length
+ 1;
93 external_object
->string
.length
= internal_object
->string
.length
;
94 external_object
->string
.pointer
= (NATIVE_CHAR
*) data_space
;
95 MEMCPY ((void *) data_space
, (void *) internal_object
->string
.pointer
, length
);
99 case ACPI_TYPE_BUFFER
:
101 length
= internal_object
->buffer
.length
;
102 external_object
->buffer
.length
= internal_object
->buffer
.length
;
103 external_object
->buffer
.pointer
= data_space
;
104 MEMCPY ((void *) data_space
, (void *) internal_object
->buffer
.pointer
, length
);
108 case ACPI_TYPE_INTEGER
:
110 external_object
->integer
.value
= internal_object
->integer
.value
;
114 case INTERNAL_TYPE_REFERENCE
:
117 * This is an object reference. Attempt to dereference it.
120 switch (internal_object
->reference
.opcode
) {
122 external_object
->type
= ACPI_TYPE_INTEGER
;
123 external_object
->integer
.value
= 0;
127 external_object
->type
= ACPI_TYPE_INTEGER
;
128 external_object
->integer
.value
= 1;
132 external_object
->type
= ACPI_TYPE_INTEGER
;
133 external_object
->integer
.value
= ACPI_INTEGER_MAX
;
136 case AML_NAMEPATH_OP
:
138 * This is a named reference, get the string. We already know that
139 * we have room for it, use max length
141 length
= MAX_STRING_LENGTH
;
142 external_object
->type
= ACPI_TYPE_STRING
;
143 external_object
->string
.pointer
= (NATIVE_CHAR
*) data_space
;
144 status
= acpi_ns_handle_to_pathname ((ACPI_HANDLE
*) internal_object
->reference
.node
,
145 &length
, (char *) data_space
);
147 /* Converted (external) string length is returned from above */
149 external_object
->string
.length
= length
;
154 * Use the object type of "Any" to indicate a reference
155 * to object containing a handle to an ACPI named object.
157 external_object
->type
= ACPI_TYPE_ANY
;
158 external_object
->reference
.handle
= internal_object
->reference
.node
;
164 case ACPI_TYPE_PROCESSOR
:
166 external_object
->processor
.proc_id
= internal_object
->processor
.proc_id
;
167 external_object
->processor
.pblk_address
= internal_object
->processor
.address
;
168 external_object
->processor
.pblk_length
= internal_object
->processor
.length
;
172 case ACPI_TYPE_POWER
:
174 external_object
->power_resource
.system_level
=
175 internal_object
->power_resource
.system_level
;
177 external_object
->power_resource
.resource_order
=
178 internal_object
->power_resource
.resource_order
;
184 * There is no corresponding external object type
191 *buffer_space_used
= (u32
) ROUND_UP_TO_NATIVE_WORD (length
);
197 /*******************************************************************************
199 * FUNCTION: Acpi_cm_copy_ielement_to_eelement
201 * PARAMETERS: ACPI_PKG_CALLBACK
205 * DESCRIPTION: Copy one package element to another package element
207 ******************************************************************************/
210 acpi_cm_copy_ielement_to_eelement (
212 ACPI_OPERAND_OBJECT
*source_object
,
213 ACPI_GENERIC_STATE
*state
,
216 ACPI_STATUS status
= AE_OK
;
217 ACPI_PKG_INFO
*info
= (ACPI_PKG_INFO
*) context
;
220 ACPI_OBJECT
*target_object
;
223 this_index
= state
->pkg
.index
;
224 target_object
= (ACPI_OBJECT
*)
225 &((ACPI_OBJECT
*)(state
->pkg
.dest_object
))->package
.elements
[this_index
];
228 switch (object_type
) {
229 case ACPI_COPY_TYPE_SIMPLE
:
232 * This is a simple or null object -- get the size
235 status
= acpi_cm_copy_isimple_to_esimple (source_object
,
236 target_object
, info
->free_space
, &object_space
);
237 if (ACPI_FAILURE (status
)) {
243 case ACPI_COPY_TYPE_PACKAGE
:
246 * Build the package object
248 target_object
->type
= ACPI_TYPE_PACKAGE
;
249 target_object
->package
.count
= source_object
->package
.count
;
250 target_object
->package
.elements
= (ACPI_OBJECT
*) info
->free_space
;
253 * Pass the new package object back to the package walk routine
255 state
->pkg
.this_target_obj
= target_object
;
258 * Save space for the array of objects (Package elements)
259 * update the buffer length counter
261 object_space
= (u32
) ROUND_UP_TO_NATIVE_WORD (
262 target_object
->package
.count
* sizeof (ACPI_OBJECT
));
266 return (AE_BAD_PARAMETER
);
270 info
->free_space
+= object_space
;
271 info
->length
+= object_space
;
277 /*******************************************************************************
279 * FUNCTION: Acpi_cm_copy_ipackage_to_epackage
281 * PARAMETERS: *Internal_object - Pointer to the object we are returning
282 * *Buffer - Where the object is returned
283 * *Space_used - Where the object length is returned
287 * DESCRIPTION: This function is called to place a package object in a user
288 * buffer. A package object by definition contains other objects.
290 * The buffer is assumed to have sufficient space for the object.
291 * The caller must have verified the buffer length needed using the
292 * Acpi_cm_get_object_size function before calling this function.
294 ******************************************************************************/
297 acpi_cm_copy_ipackage_to_epackage (
298 ACPI_OPERAND_OBJECT
*internal_object
,
302 ACPI_OBJECT
*external_object
;
308 * First package at head of the buffer
310 external_object
= (ACPI_OBJECT
*) buffer
;
313 * Free space begins right after the first package
316 info
.object_space
= 0;
317 info
.num_packages
= 1;
318 info
.free_space
= buffer
+ ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT
));
321 external_object
->type
= internal_object
->common
.type
;
322 external_object
->package
.count
= internal_object
->package
.count
;
323 external_object
->package
.elements
= (ACPI_OBJECT
*) info
.free_space
;
327 * Build an array of ACPI_OBJECTS in the buffer
328 * and move the free space past it
331 info
.free_space
+= external_object
->package
.count
*
332 ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT
));
335 status
= acpi_cm_walk_package_tree (internal_object
, external_object
,
336 acpi_cm_copy_ielement_to_eelement
, &info
);
338 *space_used
= info
.length
;
344 /*******************************************************************************
346 * FUNCTION: Acpi_cm_copy_iobject_to_eobject
348 * PARAMETERS: *Internal_object - The internal object to be converted
349 * *Buffer_ptr - Where the object is returned
353 * DESCRIPTION: This function is called to build an API object to be returned to
356 ******************************************************************************/
359 acpi_cm_copy_iobject_to_eobject (
360 ACPI_OPERAND_OBJECT
*internal_object
,
361 ACPI_BUFFER
*ret_buffer
)
366 if (IS_THIS_OBJECT_TYPE (internal_object
, ACPI_TYPE_PACKAGE
)) {
368 * Package object: Copy all subobjects (including
371 status
= acpi_cm_copy_ipackage_to_epackage (internal_object
,
372 ret_buffer
->pointer
, &ret_buffer
->length
);
377 * Build a simple object (no nested objects)
379 status
= acpi_cm_copy_isimple_to_esimple (internal_object
,
380 (ACPI_OBJECT
*) ret_buffer
->pointer
,
381 ((u8
*) ret_buffer
->pointer
+
382 ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT
))),
383 &ret_buffer
->length
);
385 * build simple does not include the object size in the length
386 * so we add it in here
388 ret_buffer
->length
+= sizeof (ACPI_OBJECT
);
395 /*******************************************************************************
397 * FUNCTION: Acpi_cm_copy_esimple_to_isimple
399 * PARAMETERS: *External_object - The external object to be converted
400 * *Internal_object - Where the internal object is returned
404 * DESCRIPTION: This function copies an external object to an internal one.
405 * NOTE: Pointers can be copied, we don't need to copy data.
406 * (The pointers have to be valid in our address space no matter
407 * what we do with them!)
409 ******************************************************************************/
412 acpi_cm_copy_esimple_to_isimple (
413 ACPI_OBJECT
*external_object
,
414 ACPI_OPERAND_OBJECT
*internal_object
)
418 internal_object
->common
.type
= (u8
) external_object
->type
;
420 switch (external_object
->type
) {
422 case ACPI_TYPE_STRING
:
424 internal_object
->string
.length
= external_object
->string
.length
;
425 internal_object
->string
.pointer
= external_object
->string
.pointer
;
429 case ACPI_TYPE_BUFFER
:
431 internal_object
->buffer
.length
= external_object
->buffer
.length
;
432 internal_object
->buffer
.pointer
= external_object
->buffer
.pointer
;
436 case ACPI_TYPE_INTEGER
:
438 * Number is included in the object itself
440 internal_object
->integer
.value
= external_object
->integer
.value
;
445 return (AE_CTRL_RETURN_VALUE
);
454 #ifdef ACPI_FUTURE_IMPLEMENTATION
456 /* Code to convert packages that are parameters to control methods */
458 /*******************************************************************************
460 * FUNCTION: Acpi_cm_copy_epackage_to_ipackage
462 * PARAMETERS: *Internal_object - Pointer to the object we are returning
463 * *Buffer - Where the object is returned
464 * *Space_used - Where the length of the object is returned
466 * RETURN: Status - the status of the call
468 * DESCRIPTION: This function is called to place a package object in a user
469 * buffer. A package object by definition contains other objects.
471 * The buffer is assumed to have sufficient space for the object.
472 * The caller must have verified the buffer length needed using the
473 * Acpi_cm_get_object_size function before calling this function.
475 ******************************************************************************/
478 acpi_cm_copy_epackage_to_ipackage (
479 ACPI_OPERAND_OBJECT
*internal_object
,
484 ACPI_OBJECT
*external_object
;
487 u32 object_space
= 0;
488 ACPI_OPERAND_OBJECT
*this_internal_obj
;
489 ACPI_OBJECT
*this_external_obj
;
493 * First package at head of the buffer
495 external_object
= (ACPI_OBJECT
*)buffer
;
498 * Free space begins right after the first package
500 free_space
= buffer
+ sizeof(ACPI_OBJECT
);
503 external_object
->type
= internal_object
->common
.type
;
504 external_object
->package
.count
= internal_object
->package
.count
;
505 external_object
->package
.elements
= (ACPI_OBJECT
*)free_space
;
509 * Build an array of ACPI_OBJECTS in the buffer
510 * and move the free space past it
513 free_space
+= external_object
->package
.count
* sizeof(ACPI_OBJECT
);
516 /* Call Walk_package */
520 #endif /* Future implementation */
523 /*******************************************************************************
525 * FUNCTION: Acpi_cm_copy_eobject_to_iobject
527 * PARAMETERS: *Internal_object - The external object to be converted
528 * *Buffer_ptr - Where the internal object is returned
530 * RETURN: Status - the status of the call
532 * DESCRIPTION: Converts an external object to an internal object.
534 ******************************************************************************/
537 acpi_cm_copy_eobject_to_iobject (
538 ACPI_OBJECT
*external_object
,
539 ACPI_OPERAND_OBJECT
*internal_object
)
544 if (external_object
->type
== ACPI_TYPE_PACKAGE
) {
546 * Package objects contain other objects (which can be objects)
547 * buildpackage does it all
549 * TBD: Package conversion must be completed and tested
550 * NOTE: this code converts packages as input parameters to
551 * control methods only. This is a very, very rare case.
554 Status = Acpi_cm_copy_epackage_to_ipackage(Internal_object,
556 &Ret_buffer->Length);
558 return (AE_NOT_IMPLEMENTED
);
563 * Build a simple object (no nested objects)
565 status
= acpi_cm_copy_esimple_to_isimple (external_object
, internal_object
);
567 * build simple does not include the object size in the length
568 * so we add it in here
576 /*******************************************************************************
578 * FUNCTION: Acpi_cm_copy_ielement_to_ielement
580 * PARAMETERS: ACPI_PKG_CALLBACK
582 * RETURN: Status - the status of the call
584 * DESCRIPTION: Copy one package element to another package element
586 ******************************************************************************/
589 acpi_cm_copy_ielement_to_ielement (
591 ACPI_OPERAND_OBJECT
*source_object
,
592 ACPI_GENERIC_STATE
*state
,
595 ACPI_STATUS status
= AE_OK
;
597 ACPI_OPERAND_OBJECT
**this_target_ptr
;
598 ACPI_OPERAND_OBJECT
*target_object
;
601 this_index
= state
->pkg
.index
;
602 this_target_ptr
= (ACPI_OPERAND_OBJECT
**)
603 &state
->pkg
.dest_object
->package
.elements
[this_index
];
605 switch (object_type
) {
609 * This is a simple object, just copy it
611 target_object
= acpi_cm_create_internal_object (source_object
->common
.type
);
612 if (!target_object
) {
613 return (AE_NO_MEMORY
);
616 status
= acpi_aml_store_object_to_object (source_object
, target_object
,
617 (ACPI_WALK_STATE
*) context
);
618 if (ACPI_FAILURE (status
)) {
622 *this_target_ptr
= target_object
;
628 * This object is a package - go down another nesting level
629 * Create and build the package object
631 target_object
= acpi_cm_create_internal_object (ACPI_TYPE_PACKAGE
);
632 if (!target_object
) {
633 /* TBD: must delete package created up to this point */
635 return (AE_NO_MEMORY
);
638 target_object
->package
.count
= source_object
->package
.count
;
641 * Pass the new package object back to the package walk routine
643 state
->pkg
.this_target_obj
= target_object
;
646 * Store the object pointer in the parent package object
648 *this_target_ptr
= target_object
;
652 return (AE_BAD_PARAMETER
);
660 /*******************************************************************************
662 * FUNCTION: Acpi_cm_copy_ipackage_to_ipackage
664 * PARAMETERS: *Source_obj - Pointer to the source package object
665 * *Dest_obj - Where the internal object is returned
667 * RETURN: Status - the status of the call
669 * DESCRIPTION: This function is called to copy an internal package object
670 * into another internal package object.
672 ******************************************************************************/
675 acpi_cm_copy_ipackage_to_ipackage (
676 ACPI_OPERAND_OBJECT
*source_obj
,
677 ACPI_OPERAND_OBJECT
*dest_obj
,
678 ACPI_WALK_STATE
*walk_state
)
680 ACPI_STATUS status
= AE_OK
;
683 dest_obj
->common
.type
= source_obj
->common
.type
;
684 dest_obj
->package
.count
= source_obj
->package
.count
;
688 * Create the object array and walk the source package tree
691 dest_obj
->package
.elements
= acpi_cm_callocate ((source_obj
->package
.count
+ 1) *
693 dest_obj
->package
.next_element
= dest_obj
->package
.elements
;
695 if (!dest_obj
->package
.elements
) {
697 ("Aml_build_copy_internal_package_object: Package allocation failure\n"));
698 return (AE_NO_MEMORY
);
702 status
= acpi_cm_walk_package_tree (source_obj
, dest_obj
,
703 acpi_cm_copy_ielement_to_ielement
, walk_state
);