1 /******************************************************************************
3 * Module Name: utcopy - Internal to external object translation utilities
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
120 #include "acinterp.h"
121 #include "acnamesp.h"
125 #define _COMPONENT ACPI_UTILITIES
126 MODULE_NAME ("utcopy")
129 /*******************************************************************************
131 * FUNCTION: AcpiUtCopyIsimpleToEsimple
133 * PARAMETERS: *InternalObject - Pointer to the object we are examining
134 * *Buffer - Where the object is returned
135 * *SpaceUsed - Where the data length is returned
139 * DESCRIPTION: This function is called to place a simple object in a user
142 * The buffer is assumed to have sufficient space for the object.
144 ******************************************************************************/
147 AcpiUtCopyIsimpleToEsimple (
148 ACPI_OPERAND_OBJECT *InternalObject,
149 ACPI_OBJECT *ExternalObject,
151 UINT32 *BufferSpaceUsed)
154 ACPI_STATUS Status = AE_OK;
157 FUNCTION_TRACE ("UtCopyIsimpleToEsimple");
161 * Check for NULL object case (could be an uninitialized
167 *BufferSpaceUsed = 0;
168 return_ACPI_STATUS (AE_OK);
171 /* Always clear the external object */
173 MEMSET (ExternalObject, 0, sizeof (ACPI_OBJECT));
176 * In general, the external object will be the same type as
177 * the internal object
180 ExternalObject->Type = InternalObject->Common.Type;
182 /* However, only a limited number of external types are supported */
184 switch (InternalObject->Common.Type)
187 case ACPI_TYPE_STRING:
189 Length = InternalObject->String.Length + 1;
190 ExternalObject->String.Length = InternalObject->String.Length;
191 ExternalObject->String.Pointer = (NATIVE_CHAR *) DataSpace;
192 MEMCPY ((void *) DataSpace, (void *) InternalObject->String.Pointer, Length);
196 case ACPI_TYPE_BUFFER:
198 Length = InternalObject->Buffer.Length;
199 ExternalObject->Buffer.Length = InternalObject->Buffer.Length;
200 ExternalObject->Buffer.Pointer = DataSpace;
201 MEMCPY ((void *) DataSpace, (void *) InternalObject->Buffer.Pointer, Length);
205 case ACPI_TYPE_INTEGER:
207 ExternalObject->Integer.Value= InternalObject->Integer.Value;
211 case INTERNAL_TYPE_REFERENCE:
214 * This is an object reference. Attempt to dereference it.
217 switch (InternalObject->Reference.Opcode)
220 ExternalObject->Type = ACPI_TYPE_INTEGER;
221 ExternalObject->Integer.Value = 0;
225 ExternalObject->Type = ACPI_TYPE_INTEGER;
226 ExternalObject->Integer.Value = 1;
230 ExternalObject->Type = ACPI_TYPE_INTEGER;
231 ExternalObject->Integer.Value = ACPI_INTEGER_MAX;
234 case AML_INT_NAMEPATH_OP:
236 * This is a named reference, get the string. We already know that
237 * we have room for it, use max length
239 Length = MAX_STRING_LENGTH;
240 ExternalObject->Type = ACPI_TYPE_STRING;
241 ExternalObject->String.Pointer = (NATIVE_CHAR *) DataSpace;
242 Status = AcpiNsHandleToPathname ((ACPI_HANDLE *) InternalObject->Reference.Node,
243 &Length, (char *) DataSpace);
245 /* Converted (external) string length is returned from above */
247 ExternalObject->String.Length = Length;
252 * Use the object type of "Any" to indicate a reference
253 * to object containing a handle to an ACPI named object.
255 ExternalObject->Type = ACPI_TYPE_ANY;
256 ExternalObject->Reference.Handle = InternalObject->Reference.Node;
262 case ACPI_TYPE_PROCESSOR:
264 ExternalObject->Processor.ProcId = InternalObject->Processor.ProcId;
265 ExternalObject->Processor.PblkAddress = InternalObject->Processor.Address;
266 ExternalObject->Processor.PblkLength = InternalObject->Processor.Length;
270 case ACPI_TYPE_POWER:
272 ExternalObject->PowerResource.SystemLevel =
273 InternalObject->PowerResource.SystemLevel;
275 ExternalObject->PowerResource.ResourceOrder =
276 InternalObject->PowerResource.ResourceOrder;
282 * There is no corresponding external object type
284 return_ACPI_STATUS (AE_SUPPORT);
289 *BufferSpaceUsed = (UINT32) ROUND_UP_TO_NATIVE_WORD (Length);
291 return_ACPI_STATUS (Status);
295 /*******************************************************************************
297 * FUNCTION: AcpiUtCopyIelementToEelement
299 * PARAMETERS: ACPI_PKG_CALLBACK
303 * DESCRIPTION: Copy one package element to another package element
305 ******************************************************************************/
308 AcpiUtCopyIelementToEelement (
310 ACPI_OPERAND_OBJECT *SourceObject,
311 ACPI_GENERIC_STATE *State,
314 ACPI_STATUS Status = AE_OK;
315 ACPI_PKG_INFO *Info = (ACPI_PKG_INFO *) Context;
318 ACPI_OBJECT *TargetObject;
321 ThisIndex = State->Pkg.Index;
322 TargetObject = (ACPI_OBJECT *)
323 &((ACPI_OBJECT *)(State->Pkg.DestObject))->Package.Elements[ThisIndex];
328 case ACPI_COPY_TYPE_SIMPLE:
331 * This is a simple or null object -- get the size
334 Status = AcpiUtCopyIsimpleToEsimple (SourceObject,
335 TargetObject, Info->FreeSpace, &ObjectSpace);
336 if (ACPI_FAILURE (Status))
343 case ACPI_COPY_TYPE_PACKAGE:
346 * Build the package object
348 TargetObject->Type = ACPI_TYPE_PACKAGE;
349 TargetObject->Package.Count = SourceObject->Package.Count;
350 TargetObject->Package.Elements = (ACPI_OBJECT *) Info->FreeSpace;
353 * Pass the new package object back to the package walk routine
355 State->Pkg.ThisTargetObj = TargetObject;
358 * Save space for the array of objects (Package elements)
359 * update the buffer length counter
361 ObjectSpace = (UINT32) ROUND_UP_TO_NATIVE_WORD (
362 TargetObject->Package.Count * sizeof (ACPI_OBJECT));
366 return (AE_BAD_PARAMETER);
370 Info->FreeSpace += ObjectSpace;
371 Info->Length += ObjectSpace;
377 /*******************************************************************************
379 * FUNCTION: AcpiUtCopyIpackageToEpackage
381 * PARAMETERS: *InternalObject - Pointer to the object we are returning
382 * *Buffer - Where the object is returned
383 * *SpaceUsed - Where the object length is returned
387 * DESCRIPTION: This function is called to place a package object in a user
388 * buffer. A package object by definition contains other objects.
390 * The buffer is assumed to have sufficient space for the object.
391 * The caller must have verified the buffer length needed using the
392 * AcpiUtGetObjectSize function before calling this function.
394 ******************************************************************************/
397 AcpiUtCopyIpackageToEpackage (
398 ACPI_OPERAND_OBJECT *InternalObject,
402 ACPI_OBJECT *ExternalObject;
407 FUNCTION_TRACE ("UtCopyIpackageToEpackage");
411 * First package at head of the buffer
413 ExternalObject = (ACPI_OBJECT *) Buffer;
416 * Free space begins right after the first package
419 Info.ObjectSpace = 0;
420 Info.NumPackages = 1;
421 Info.FreeSpace = Buffer + ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
424 ExternalObject->Type = InternalObject->Common.Type;
425 ExternalObject->Package.Count = InternalObject->Package.Count;
426 ExternalObject->Package.Elements = (ACPI_OBJECT *) Info.FreeSpace;
430 * Build an array of ACPI_OBJECTS in the buffer
431 * and move the free space past it
434 Info.FreeSpace += ExternalObject->Package.Count *
435 ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT));
438 Status = AcpiUtWalkPackageTree (InternalObject, ExternalObject,
439 AcpiUtCopyIelementToEelement, &Info);
441 *SpaceUsed = Info.Length;
443 return_ACPI_STATUS (Status);
447 /*******************************************************************************
449 * FUNCTION: AcpiUtCopyIobjectToEobject
451 * PARAMETERS: *InternalObject - The internal object to be converted
452 * *BufferPtr - Where the object is returned
456 * DESCRIPTION: This function is called to build an API object to be returned to
459 ******************************************************************************/
462 AcpiUtCopyIobjectToEobject (
463 ACPI_OPERAND_OBJECT *InternalObject,
464 ACPI_BUFFER *RetBuffer)
469 FUNCTION_TRACE ("UtCopyIobjectToEobject");
472 if (IS_THIS_OBJECT_TYPE (InternalObject, ACPI_TYPE_PACKAGE))
475 * Package object: Copy all subobjects (including
478 Status = AcpiUtCopyIpackageToEpackage (InternalObject,
479 RetBuffer->Pointer, &RetBuffer->Length);
485 * Build a simple object (no nested objects)
487 Status = AcpiUtCopyIsimpleToEsimple (InternalObject,
488 (ACPI_OBJECT *) RetBuffer->Pointer,
489 ((UINT8 *) RetBuffer->Pointer +
490 ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT))),
493 * build simple does not include the object size in the length
494 * so we add it in here
496 RetBuffer->Length += sizeof (ACPI_OBJECT);
499 return_ACPI_STATUS (Status);
503 /*******************************************************************************
505 * FUNCTION: AcpiUtCopyEsimpleToIsimple
507 * PARAMETERS: *ExternalObject - The external object to be converted
508 * *InternalObject - Where the internal object is returned
512 * DESCRIPTION: This function copies an external object to an internal one.
513 * NOTE: Pointers can be copied, we don't need to copy data.
514 * (The pointers have to be valid in our address space no matter
515 * what we do with them!)
517 ******************************************************************************/
520 AcpiUtCopyEsimpleToIsimple (
521 ACPI_OBJECT *ExternalObject,
522 ACPI_OPERAND_OBJECT *InternalObject)
525 FUNCTION_TRACE ("UtCopyEsimpleToIsimple");
528 InternalObject->Common.Type = (UINT8) ExternalObject->Type;
530 switch (ExternalObject->Type)
533 case ACPI_TYPE_STRING:
535 InternalObject->String.Length = ExternalObject->String.Length;
536 InternalObject->String.Pointer = ExternalObject->String.Pointer;
540 case ACPI_TYPE_BUFFER:
542 InternalObject->Buffer.Length = ExternalObject->Buffer.Length;
543 InternalObject->Buffer.Pointer = ExternalObject->Buffer.Pointer;
547 case ACPI_TYPE_INTEGER:
549 * Number is included in the object itself
551 InternalObject->Integer.Value = ExternalObject->Integer.Value;
556 return_ACPI_STATUS (AE_CTRL_RETURN_VALUE);
561 return_ACPI_STATUS (AE_OK);
565 #ifdef ACPI_FUTURE_IMPLEMENTATION
567 /* Code to convert packages that are parameters to control methods */
569 /*******************************************************************************
571 * FUNCTION: AcpiUtCopyEpackageToIpackage
573 * PARAMETERS: *InternalObject - Pointer to the object we are returning
574 * *Buffer - Where the object is returned
575 * *SpaceUsed - Where the length of the object is returned
577 * RETURN: Status - the status of the call
579 * DESCRIPTION: This function is called to place a package object in a user
580 * buffer. A package object by definition contains other objects.
582 * The buffer is assumed to have sufficient space for the object.
583 * The caller must have verified the buffer length needed using the
584 * AcpiUtGetObjectSize function before calling this function.
586 ******************************************************************************/
589 AcpiUtCopyEpackageToIpackage (
590 ACPI_OPERAND_OBJECT *InternalObject,
595 ACPI_OBJECT *ExternalObject;
598 UINT32 ObjectSpace = 0;
599 ACPI_OPERAND_OBJECT *ThisInternalObj;
600 ACPI_OBJECT *ThisExternalObj;
603 FUNCTION_TRACE ("UtCopyEpackageToIpackage");
607 * First package at head of the buffer
609 ExternalObject = (ACPI_OBJECT *)Buffer;
612 * Free space begins right after the first package
614 FreeSpace = Buffer + sizeof(ACPI_OBJECT);
617 ExternalObject->Type = InternalObject->Common.Type;
618 ExternalObject->Package.Count = InternalObject->Package.Count;
619 ExternalObject->Package.Elements = (ACPI_OBJECT *)FreeSpace;
623 * Build an array of ACPI_OBJECTS in the buffer
624 * and move the free space past it
627 FreeSpace += ExternalObject->Package.Count * sizeof(ACPI_OBJECT);
630 /* Call WalkPackage */
634 #endif /* Future implementation */
637 /*******************************************************************************
639 * FUNCTION: AcpiUtCopyEobjectToIobject
641 * PARAMETERS: *InternalObject - The external object to be converted
642 * *BufferPtr - Where the internal object is returned
644 * RETURN: Status - the status of the call
646 * DESCRIPTION: Converts an external object to an internal object.
648 ******************************************************************************/
651 AcpiUtCopyEobjectToIobject (
652 ACPI_OBJECT *ExternalObject,
653 ACPI_OPERAND_OBJECT *InternalObject)
658 FUNCTION_TRACE ("UtCopyEobjectToIobject");
661 if (ExternalObject->Type == ACPI_TYPE_PACKAGE)
664 * Package objects contain other objects (which can be objects)
665 * buildpackage does it all
667 * TBD: Package conversion must be completed and tested
668 * NOTE: this code converts packages as input parameters to
669 * control methods only. This is a very, very rare case.
672 Status = AcpiUtCopyEpackageToIpackage(InternalObject,
676 DEBUG_PRINTP (ACPI_ERROR, ("Packages as parameters not implemented!\n"));
678 return_ACPI_STATUS (AE_NOT_IMPLEMENTED);
684 * Build a simple object (no nested objects)
686 Status = AcpiUtCopyEsimpleToIsimple (ExternalObject, InternalObject);
688 * build simple does not include the object size in the length
689 * so we add it in here
693 return_ACPI_STATUS (Status);
697 /*******************************************************************************
699 * FUNCTION: AcpiUtCopyIelementToIelement
701 * PARAMETERS: ACPI_PKG_CALLBACK
703 * RETURN: Status - the status of the call
705 * DESCRIPTION: Copy one package element to another package element
707 ******************************************************************************/
710 AcpiUtCopyIelementToIelement (
712 ACPI_OPERAND_OBJECT *SourceObject,
713 ACPI_GENERIC_STATE *State,
716 ACPI_STATUS Status = AE_OK;
718 ACPI_OPERAND_OBJECT **ThisTargetPtr;
719 ACPI_OPERAND_OBJECT *TargetObject;
722 ThisIndex = State->Pkg.Index;
723 ThisTargetPtr = (ACPI_OPERAND_OBJECT **)
724 &State->Pkg.DestObject->Package.Elements[ThisIndex];
731 * This is a simple object, just copy it
733 TargetObject = AcpiUtCreateInternalObject (SourceObject->Common.Type);
736 return (AE_NO_MEMORY);
739 Status = AcpiExStoreObjectToObject (SourceObject, TargetObject,
740 (ACPI_WALK_STATE *) Context);
741 if (ACPI_FAILURE (Status))
746 *ThisTargetPtr = TargetObject;
752 * This object is a package - go down another nesting level
753 * Create and build the package object
755 TargetObject = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
758 /* TBD: must delete package created up to this point */
760 return (AE_NO_MEMORY);
763 TargetObject->Package.Count = SourceObject->Package.Count;
766 * Pass the new package object back to the package walk routine
768 State->Pkg.ThisTargetObj = TargetObject;
771 * Store the object pointer in the parent package object
773 *ThisTargetPtr = TargetObject;
777 return (AE_BAD_PARAMETER);
785 /*******************************************************************************
787 * FUNCTION: AcpiUtCopyIpackageToIpackage
789 * PARAMETERS: *SourceObj - Pointer to the source package object
790 * *DestObj - Where the internal object is returned
792 * RETURN: Status - the status of the call
794 * DESCRIPTION: This function is called to copy an internal package object
795 * into another internal package object.
797 ******************************************************************************/
800 AcpiUtCopyIpackageToIpackage (
801 ACPI_OPERAND_OBJECT *SourceObj,
802 ACPI_OPERAND_OBJECT *DestObj,
803 ACPI_WALK_STATE *WalkState)
805 ACPI_STATUS Status = AE_OK;
807 FUNCTION_TRACE ("UtCopyIpackageToIpackage");
810 DestObj->Common.Type = SourceObj->Common.Type;
811 DestObj->Package.Count = SourceObj->Package.Count;
815 * Create the object array and walk the source package tree
818 DestObj->Package.Elements = AcpiUtCallocate ((SourceObj->Package.Count + 1) *
820 DestObj->Package.NextElement = DestObj->Package.Elements;
822 if (!DestObj->Package.Elements)
825 ("AmlBuildCopyInternalPackageObject: Package allocation failure\n"));
826 return_ACPI_STATUS (AE_NO_MEMORY);
830 Status = AcpiUtWalkPackageTree (SourceObj, DestObj,
831 AcpiUtCopyIelementToIelement, WalkState);
833 return_ACPI_STATUS (Status);