13446Smrj /******************************************************************************
23446Smrj *
33446Smrj * Module Name: utobject - ACPI object create/delete/size/cache routines
43446Smrj *
53446Smrj *****************************************************************************/
63446Smrj
73446Smrj /******************************************************************************
83446Smrj *
93446Smrj * 1. Copyright Notice
103446Smrj *
119980SDana.Myers@Sun.COM * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
123446Smrj * All rights reserved.
133446Smrj *
143446Smrj * 2. License
153446Smrj *
163446Smrj * 2.1. This is your license from Intel Corp. under its intellectual property
173446Smrj * rights. You may have additional license terms from the party that provided
183446Smrj * you this software, covering your right to use that party's intellectual
193446Smrj * property rights.
203446Smrj *
213446Smrj * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
223446Smrj * copy of the source code appearing in this file ("Covered Code") an
233446Smrj * irrevocable, perpetual, worldwide license under Intel's copyrights in the
243446Smrj * base code distributed originally by Intel ("Original Intel Code") to copy,
253446Smrj * make derivatives, distribute, use and display any portion of the Covered
263446Smrj * Code in any form, with the right to sublicense such rights; and
273446Smrj *
283446Smrj * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
293446Smrj * license (with the right to sublicense), under only those claims of Intel
303446Smrj * patents that are infringed by the Original Intel Code, to make, use, sell,
313446Smrj * offer to sell, and import the Covered Code and derivative works thereof
323446Smrj * solely to the minimum extent necessary to exercise the above copyright
333446Smrj * license, and in no event shall the patent license extend to any additions
343446Smrj * to or modifications of the Original Intel Code. No other license or right
353446Smrj * is granted directly or by implication, estoppel or otherwise;
363446Smrj *
373446Smrj * The above copyright and patent license is granted only if the following
383446Smrj * conditions are met:
393446Smrj *
403446Smrj * 3. Conditions
413446Smrj *
423446Smrj * 3.1. Redistribution of Source with Rights to Further Distribute Source.
433446Smrj * Redistribution of source code of any substantial portion of the Covered
443446Smrj * Code or modification with rights to further distribute source must include
453446Smrj * the above Copyright Notice, the above License, this list of Conditions,
463446Smrj * and the following Disclaimer and Export Compliance provision. In addition,
473446Smrj * Licensee must cause all Covered Code to which Licensee contributes to
483446Smrj * contain a file documenting the changes Licensee made to create that Covered
493446Smrj * Code and the date of any change. Licensee must include in that file the
503446Smrj * documentation of any changes made by any predecessor Licensee. Licensee
513446Smrj * must include a prominent statement that the modification is derived,
523446Smrj * directly or indirectly, from Original Intel Code.
533446Smrj *
543446Smrj * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
553446Smrj * Redistribution of source code of any substantial portion of the Covered
563446Smrj * Code or modification without rights to further distribute source must
573446Smrj * include the following Disclaimer and Export Compliance provision in the
583446Smrj * documentation and/or other materials provided with distribution. In
593446Smrj * addition, Licensee may not authorize further sublicense of source of any
603446Smrj * portion of the Covered Code, and must include terms to the effect that the
613446Smrj * license from Licensee to its licensee is limited to the intellectual
623446Smrj * property embodied in the software Licensee provides to its licensee, and
633446Smrj * not to intellectual property embodied in modifications its licensee may
643446Smrj * make.
653446Smrj *
663446Smrj * 3.3. Redistribution of Executable. Redistribution in executable form of any
673446Smrj * substantial portion of the Covered Code or modification must reproduce the
683446Smrj * above Copyright Notice, and the following Disclaimer and Export Compliance
693446Smrj * provision in the documentation and/or other materials provided with the
703446Smrj * distribution.
713446Smrj *
723446Smrj * 3.4. Intel retains all right, title, and interest in and to the Original
733446Smrj * Intel Code.
743446Smrj *
753446Smrj * 3.5. Neither the name Intel nor any other trademark owned or controlled by
763446Smrj * Intel shall be used in advertising or otherwise to promote the sale, use or
773446Smrj * other dealings in products derived from or relating to the Covered Code
783446Smrj * without prior written authorization from Intel.
793446Smrj *
803446Smrj * 4. Disclaimer and Export Compliance
813446Smrj *
823446Smrj * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
833446Smrj * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
843446Smrj * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
853446Smrj * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
863446Smrj * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
873446Smrj * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
883446Smrj * PARTICULAR PURPOSE.
893446Smrj *
903446Smrj * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
913446Smrj * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
923446Smrj * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
933446Smrj * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
943446Smrj * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
953446Smrj * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
963446Smrj * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
973446Smrj * LIMITED REMEDY.
983446Smrj *
993446Smrj * 4.3. Licensee shall not export, either directly or indirectly, any of this
1003446Smrj * software or system incorporating such software without first obtaining any
1013446Smrj * required license or other approval from the U. S. Department of Commerce or
1023446Smrj * any other agency or department of the United States Government. In the
1033446Smrj * event Licensee exports any such software from the United States or
1043446Smrj * re-exports any such software from a foreign destination, Licensee shall
1053446Smrj * ensure that the distribution and export/re-export of the software is in
1063446Smrj * compliance with all laws, regulations, orders, or other restrictions of the
1073446Smrj * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1083446Smrj * any of its subsidiaries will export/re-export any technical data, process,
1093446Smrj * software, or service, directly or indirectly, to any country for which the
1103446Smrj * United States government or any agency thereof requires an export license,
1113446Smrj * other governmental approval, or letter of assurance, without first obtaining
1123446Smrj * such license, approval or letter.
1133446Smrj *
1143446Smrj *****************************************************************************/
1153446Smrj
1163446Smrj #define __UTOBJECT_C__
1173446Smrj
1183446Smrj #include "acpi.h"
1199980SDana.Myers@Sun.COM #include "accommon.h"
1203446Smrj #include "acnamesp.h"
1213446Smrj
1223446Smrj
1233446Smrj #define _COMPONENT ACPI_UTILITIES
1243446Smrj ACPI_MODULE_NAME ("utobject")
1253446Smrj
1263446Smrj /* Local prototypes */
1273446Smrj
1283446Smrj static ACPI_STATUS
1293446Smrj AcpiUtGetSimpleObjectSize (
1303446Smrj ACPI_OPERAND_OBJECT *Obj,
1313446Smrj ACPI_SIZE *ObjLength);
1323446Smrj
1333446Smrj static ACPI_STATUS
1343446Smrj AcpiUtGetPackageObjectSize (
1353446Smrj ACPI_OPERAND_OBJECT *Obj,
1363446Smrj ACPI_SIZE *ObjLength);
1373446Smrj
1383446Smrj static ACPI_STATUS
1393446Smrj AcpiUtGetElementLength (
1403446Smrj UINT8 ObjectType,
1413446Smrj ACPI_OPERAND_OBJECT *SourceObject,
1423446Smrj ACPI_GENERIC_STATE *State,
1433446Smrj void *Context);
1443446Smrj
1453446Smrj
1463446Smrj /*******************************************************************************
1473446Smrj *
1483446Smrj * FUNCTION: AcpiUtCreateInternalObjectDbg
1493446Smrj *
1503446Smrj * PARAMETERS: ModuleName - Source file name of caller
1513446Smrj * LineNumber - Line number of caller
1523446Smrj * ComponentId - Component type of caller
1533446Smrj * Type - ACPI Type of the new object
1543446Smrj *
1553446Smrj * RETURN: A new internal object, null on failure
1563446Smrj *
1573446Smrj * DESCRIPTION: Create and initialize a new internal object.
1583446Smrj *
1593446Smrj * NOTE: We always allocate the worst-case object descriptor because
1603446Smrj * these objects are cached, and we want them to be
1613446Smrj * one-size-satisifies-any-request. This in itself may not be
1623446Smrj * the most memory efficient, but the efficiency of the object
1633446Smrj * cache should more than make up for this!
1643446Smrj *
1653446Smrj ******************************************************************************/
1663446Smrj
1673446Smrj ACPI_OPERAND_OBJECT *
AcpiUtCreateInternalObjectDbg(const char * ModuleName,UINT32 LineNumber,UINT32 ComponentId,ACPI_OBJECT_TYPE Type)1683446Smrj AcpiUtCreateInternalObjectDbg (
1697851SDana.Myers@Sun.COM const char *ModuleName,
1703446Smrj UINT32 LineNumber,
1713446Smrj UINT32 ComponentId,
1723446Smrj ACPI_OBJECT_TYPE Type)
1733446Smrj {
1743446Smrj ACPI_OPERAND_OBJECT *Object;
1753446Smrj ACPI_OPERAND_OBJECT *SecondObject;
1763446Smrj
1773446Smrj
1783446Smrj ACPI_FUNCTION_TRACE_STR (UtCreateInternalObjectDbg,
1793446Smrj AcpiUtGetTypeName (Type));
1803446Smrj
1813446Smrj
1823446Smrj /* Allocate the raw object descriptor */
1833446Smrj
1843446Smrj Object = AcpiUtAllocateObjectDescDbg (ModuleName, LineNumber, ComponentId);
1853446Smrj if (!Object)
1863446Smrj {
1873446Smrj return_PTR (NULL);
1883446Smrj }
1893446Smrj
1903446Smrj switch (Type)
1913446Smrj {
1923446Smrj case ACPI_TYPE_REGION:
1933446Smrj case ACPI_TYPE_BUFFER_FIELD:
1947851SDana.Myers@Sun.COM case ACPI_TYPE_LOCAL_BANK_FIELD:
1953446Smrj
1963446Smrj /* These types require a secondary object */
1973446Smrj
1983446Smrj SecondObject = AcpiUtAllocateObjectDescDbg (ModuleName,
1993446Smrj LineNumber, ComponentId);
2003446Smrj if (!SecondObject)
2013446Smrj {
2023446Smrj AcpiUtDeleteObjectDesc (Object);
2033446Smrj return_PTR (NULL);
2043446Smrj }
2053446Smrj
2063446Smrj SecondObject->Common.Type = ACPI_TYPE_LOCAL_EXTRA;
2073446Smrj SecondObject->Common.ReferenceCount = 1;
2083446Smrj
2093446Smrj /* Link the second object to the first */
2103446Smrj
2113446Smrj Object->Common.NextObject = SecondObject;
2123446Smrj break;
2133446Smrj
2143446Smrj default:
2153446Smrj /* All others have no secondary object */
2163446Smrj break;
2173446Smrj }
2183446Smrj
2193446Smrj /* Save the object type in the object descriptor */
2203446Smrj
2213446Smrj Object->Common.Type = (UINT8) Type;
2223446Smrj
2233446Smrj /* Init the reference count */
2243446Smrj
2253446Smrj Object->Common.ReferenceCount = 1;
2263446Smrj
2273446Smrj /* Any per-type initialization should go here */
2283446Smrj
2293446Smrj return_PTR (Object);
2303446Smrj }
2313446Smrj
2323446Smrj
2333446Smrj /*******************************************************************************
2343446Smrj *
2357851SDana.Myers@Sun.COM * FUNCTION: AcpiUtCreatePackageObject
2367851SDana.Myers@Sun.COM *
2377851SDana.Myers@Sun.COM * PARAMETERS: Count - Number of package elements
2387851SDana.Myers@Sun.COM *
2397851SDana.Myers@Sun.COM * RETURN: Pointer to a new Package object, null on failure
2407851SDana.Myers@Sun.COM *
2417851SDana.Myers@Sun.COM * DESCRIPTION: Create a fully initialized package object
2427851SDana.Myers@Sun.COM *
2437851SDana.Myers@Sun.COM ******************************************************************************/
2447851SDana.Myers@Sun.COM
2457851SDana.Myers@Sun.COM ACPI_OPERAND_OBJECT *
AcpiUtCreatePackageObject(UINT32 Count)2467851SDana.Myers@Sun.COM AcpiUtCreatePackageObject (
2477851SDana.Myers@Sun.COM UINT32 Count)
2487851SDana.Myers@Sun.COM {
2497851SDana.Myers@Sun.COM ACPI_OPERAND_OBJECT *PackageDesc;
2507851SDana.Myers@Sun.COM ACPI_OPERAND_OBJECT **PackageElements;
2517851SDana.Myers@Sun.COM
2527851SDana.Myers@Sun.COM
2537851SDana.Myers@Sun.COM ACPI_FUNCTION_TRACE_U32 (UtCreatePackageObject, Count);
2547851SDana.Myers@Sun.COM
2557851SDana.Myers@Sun.COM
2567851SDana.Myers@Sun.COM /* Create a new Package object */
2577851SDana.Myers@Sun.COM
2587851SDana.Myers@Sun.COM PackageDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
2597851SDana.Myers@Sun.COM if (!PackageDesc)
2607851SDana.Myers@Sun.COM {
2617851SDana.Myers@Sun.COM return_PTR (NULL);
2627851SDana.Myers@Sun.COM }
2637851SDana.Myers@Sun.COM
2647851SDana.Myers@Sun.COM /*
2657851SDana.Myers@Sun.COM * Create the element array. Count+1 allows the array to be null
2667851SDana.Myers@Sun.COM * terminated.
2677851SDana.Myers@Sun.COM */
2687851SDana.Myers@Sun.COM PackageElements = ACPI_ALLOCATE_ZEROED (
2697851SDana.Myers@Sun.COM ((ACPI_SIZE) Count + 1) * sizeof (void *));
2707851SDana.Myers@Sun.COM if (!PackageElements)
2717851SDana.Myers@Sun.COM {
2727851SDana.Myers@Sun.COM ACPI_FREE (PackageDesc);
2737851SDana.Myers@Sun.COM return_PTR (NULL);
2747851SDana.Myers@Sun.COM }
2757851SDana.Myers@Sun.COM
2767851SDana.Myers@Sun.COM PackageDesc->Package.Count = Count;
2777851SDana.Myers@Sun.COM PackageDesc->Package.Elements = PackageElements;
2787851SDana.Myers@Sun.COM return_PTR (PackageDesc);
2797851SDana.Myers@Sun.COM }
2807851SDana.Myers@Sun.COM
2817851SDana.Myers@Sun.COM
2827851SDana.Myers@Sun.COM /*******************************************************************************
2837851SDana.Myers@Sun.COM *
284*11225SDana.Myers@Sun.COM * FUNCTION: AcpiUtCreateIntegerObject
285*11225SDana.Myers@Sun.COM *
286*11225SDana.Myers@Sun.COM * PARAMETERS: InitialValue - Initial value for the integer
287*11225SDana.Myers@Sun.COM *
288*11225SDana.Myers@Sun.COM * RETURN: Pointer to a new Integer object, null on failure
289*11225SDana.Myers@Sun.COM *
290*11225SDana.Myers@Sun.COM * DESCRIPTION: Create an initialized integer object
291*11225SDana.Myers@Sun.COM *
292*11225SDana.Myers@Sun.COM ******************************************************************************/
293*11225SDana.Myers@Sun.COM
294*11225SDana.Myers@Sun.COM ACPI_OPERAND_OBJECT *
AcpiUtCreateIntegerObject(UINT64 InitialValue)295*11225SDana.Myers@Sun.COM AcpiUtCreateIntegerObject (
296*11225SDana.Myers@Sun.COM UINT64 InitialValue)
297*11225SDana.Myers@Sun.COM {
298*11225SDana.Myers@Sun.COM ACPI_OPERAND_OBJECT *IntegerDesc;
299*11225SDana.Myers@Sun.COM
300*11225SDana.Myers@Sun.COM
301*11225SDana.Myers@Sun.COM ACPI_FUNCTION_TRACE (UtCreateIntegerObject);
302*11225SDana.Myers@Sun.COM
303*11225SDana.Myers@Sun.COM
304*11225SDana.Myers@Sun.COM /* Create and initialize a new integer object */
305*11225SDana.Myers@Sun.COM
306*11225SDana.Myers@Sun.COM IntegerDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
307*11225SDana.Myers@Sun.COM if (!IntegerDesc)
308*11225SDana.Myers@Sun.COM {
309*11225SDana.Myers@Sun.COM return_PTR (NULL);
310*11225SDana.Myers@Sun.COM }
311*11225SDana.Myers@Sun.COM
312*11225SDana.Myers@Sun.COM IntegerDesc->Integer.Value = InitialValue;
313*11225SDana.Myers@Sun.COM return_PTR (IntegerDesc);
314*11225SDana.Myers@Sun.COM }
315*11225SDana.Myers@Sun.COM
316*11225SDana.Myers@Sun.COM
317*11225SDana.Myers@Sun.COM /*******************************************************************************
318*11225SDana.Myers@Sun.COM *
3193446Smrj * FUNCTION: AcpiUtCreateBufferObject
3203446Smrj *
3213446Smrj * PARAMETERS: BufferSize - Size of buffer to be created
3223446Smrj *
3233446Smrj * RETURN: Pointer to a new Buffer object, null on failure
3243446Smrj *
3253446Smrj * DESCRIPTION: Create a fully initialized buffer object
3263446Smrj *
3273446Smrj ******************************************************************************/
3283446Smrj
3293446Smrj ACPI_OPERAND_OBJECT *
AcpiUtCreateBufferObject(ACPI_SIZE BufferSize)3303446Smrj AcpiUtCreateBufferObject (
3313446Smrj ACPI_SIZE BufferSize)
3323446Smrj {
3333446Smrj ACPI_OPERAND_OBJECT *BufferDesc;
3343446Smrj UINT8 *Buffer = NULL;
3353446Smrj
3363446Smrj
3373446Smrj ACPI_FUNCTION_TRACE_U32 (UtCreateBufferObject, BufferSize);
3383446Smrj
3393446Smrj
3403446Smrj /* Create a new Buffer object */
3413446Smrj
3423446Smrj BufferDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
3433446Smrj if (!BufferDesc)
3443446Smrj {
3453446Smrj return_PTR (NULL);
3463446Smrj }
3473446Smrj
3483446Smrj /* Create an actual buffer only if size > 0 */
3493446Smrj
3503446Smrj if (BufferSize > 0)
3513446Smrj {
3523446Smrj /* Allocate the actual buffer */
3533446Smrj
3543446Smrj Buffer = ACPI_ALLOCATE_ZEROED (BufferSize);
3553446Smrj if (!Buffer)
3563446Smrj {
3573446Smrj ACPI_ERROR ((AE_INFO, "Could not allocate size %X",
3583446Smrj (UINT32) BufferSize));
3593446Smrj AcpiUtRemoveReference (BufferDesc);
3603446Smrj return_PTR (NULL);
3613446Smrj }
3623446Smrj }
3633446Smrj
3643446Smrj /* Complete buffer object initialization */
3653446Smrj
3663446Smrj BufferDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
3673446Smrj BufferDesc->Buffer.Pointer = Buffer;
3683446Smrj BufferDesc->Buffer.Length = (UINT32) BufferSize;
3693446Smrj
3703446Smrj /* Return the new buffer descriptor */
3713446Smrj
3723446Smrj return_PTR (BufferDesc);
3733446Smrj }
3743446Smrj
3753446Smrj
3763446Smrj /*******************************************************************************
3773446Smrj *
3783446Smrj * FUNCTION: AcpiUtCreateStringObject
3793446Smrj *
3803446Smrj * PARAMETERS: StringSize - Size of string to be created. Does not
3813446Smrj * include NULL terminator, this is added
3823446Smrj * automatically.
3833446Smrj *
3843446Smrj * RETURN: Pointer to a new String object
3853446Smrj *
3863446Smrj * DESCRIPTION: Create a fully initialized string object
3873446Smrj *
3883446Smrj ******************************************************************************/
3893446Smrj
3903446Smrj ACPI_OPERAND_OBJECT *
AcpiUtCreateStringObject(ACPI_SIZE StringSize)3913446Smrj AcpiUtCreateStringObject (
3923446Smrj ACPI_SIZE StringSize)
3933446Smrj {
3943446Smrj ACPI_OPERAND_OBJECT *StringDesc;
3953446Smrj char *String;
3963446Smrj
3973446Smrj
3983446Smrj ACPI_FUNCTION_TRACE_U32 (UtCreateStringObject, StringSize);
3993446Smrj
4003446Smrj
4013446Smrj /* Create a new String object */
4023446Smrj
4033446Smrj StringDesc = AcpiUtCreateInternalObject (ACPI_TYPE_STRING);
4043446Smrj if (!StringDesc)
4053446Smrj {
4063446Smrj return_PTR (NULL);
4073446Smrj }
4083446Smrj
4093446Smrj /*
4103446Smrj * Allocate the actual string buffer -- (Size + 1) for NULL terminator.
4113446Smrj * NOTE: Zero-length strings are NULL terminated
4123446Smrj */
4133446Smrj String = ACPI_ALLOCATE_ZEROED (StringSize + 1);
4143446Smrj if (!String)
4153446Smrj {
4163446Smrj ACPI_ERROR ((AE_INFO, "Could not allocate size %X",
4173446Smrj (UINT32) StringSize));
4183446Smrj AcpiUtRemoveReference (StringDesc);
4193446Smrj return_PTR (NULL);
4203446Smrj }
4213446Smrj
4223446Smrj /* Complete string object initialization */
4233446Smrj
4243446Smrj StringDesc->String.Pointer = String;
4253446Smrj StringDesc->String.Length = (UINT32) StringSize;
4263446Smrj
4273446Smrj /* Return the new string descriptor */
4283446Smrj
4293446Smrj return_PTR (StringDesc);
4303446Smrj }
4313446Smrj
4323446Smrj
4333446Smrj /*******************************************************************************
4343446Smrj *
4353446Smrj * FUNCTION: AcpiUtValidInternalObject
4363446Smrj *
4373446Smrj * PARAMETERS: Object - Object to be validated
4383446Smrj *
4393446Smrj * RETURN: TRUE if object is valid, FALSE otherwise
4403446Smrj *
4413446Smrj * DESCRIPTION: Validate a pointer to be an ACPI_OPERAND_OBJECT
4423446Smrj *
4433446Smrj ******************************************************************************/
4443446Smrj
4453446Smrj BOOLEAN
AcpiUtValidInternalObject(void * Object)4463446Smrj AcpiUtValidInternalObject (
4473446Smrj void *Object)
4483446Smrj {
4493446Smrj
4503446Smrj ACPI_FUNCTION_NAME (UtValidInternalObject);
4513446Smrj
4523446Smrj
4533446Smrj /* Check for a null pointer */
4543446Smrj
4553446Smrj if (!Object)
4563446Smrj {
4579980SDana.Myers@Sun.COM ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "**** Null Object Ptr\n"));
4583446Smrj return (FALSE);
4593446Smrj }
4603446Smrj
4613446Smrj /* Check the descriptor type field */
4623446Smrj
4633446Smrj switch (ACPI_GET_DESCRIPTOR_TYPE (Object))
4643446Smrj {
4653446Smrj case ACPI_DESC_TYPE_OPERAND:
4663446Smrj
4673446Smrj /* The object appears to be a valid ACPI_OPERAND_OBJECT */
4683446Smrj
4693446Smrj return (TRUE);
4703446Smrj
4713446Smrj default:
4729980SDana.Myers@Sun.COM ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
4733446Smrj "%p is not not an ACPI operand obj [%s]\n",
4743446Smrj Object, AcpiUtGetDescriptorName (Object)));
4753446Smrj break;
4763446Smrj }
4773446Smrj
4783446Smrj return (FALSE);
4793446Smrj }
4803446Smrj
4813446Smrj
4823446Smrj /*******************************************************************************
4833446Smrj *
4843446Smrj * FUNCTION: AcpiUtAllocateObjectDescDbg
4853446Smrj *
4863446Smrj * PARAMETERS: ModuleName - Caller's module name (for error output)
4873446Smrj * LineNumber - Caller's line number (for error output)
4883446Smrj * ComponentId - Caller's component ID (for error output)
4893446Smrj *
4903446Smrj * RETURN: Pointer to newly allocated object descriptor. Null on error
4913446Smrj *
4923446Smrj * DESCRIPTION: Allocate a new object descriptor. Gracefully handle
4933446Smrj * error conditions.
4943446Smrj *
4953446Smrj ******************************************************************************/
4963446Smrj
4973446Smrj void *
AcpiUtAllocateObjectDescDbg(const char * ModuleName,UINT32 LineNumber,UINT32 ComponentId)4983446Smrj AcpiUtAllocateObjectDescDbg (
4997851SDana.Myers@Sun.COM const char *ModuleName,
5003446Smrj UINT32 LineNumber,
5013446Smrj UINT32 ComponentId)
5023446Smrj {
5033446Smrj ACPI_OPERAND_OBJECT *Object;
5043446Smrj
5053446Smrj
5063446Smrj ACPI_FUNCTION_TRACE (UtAllocateObjectDescDbg);
5073446Smrj
5083446Smrj
5093446Smrj Object = AcpiOsAcquireObject (AcpiGbl_OperandCache);
5103446Smrj if (!Object)
5113446Smrj {
5123446Smrj ACPI_ERROR ((ModuleName, LineNumber,
5133446Smrj "Could not allocate an object descriptor"));
5143446Smrj
5153446Smrj return_PTR (NULL);
5163446Smrj }
5173446Smrj
5183446Smrj /* Mark the descriptor type */
5193446Smrj
5203446Smrj ACPI_SET_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_OPERAND);
5213446Smrj
5223446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p Size %X\n",
5233446Smrj Object, (UINT32) sizeof (ACPI_OPERAND_OBJECT)));
5243446Smrj
5253446Smrj return_PTR (Object);
5263446Smrj }
5273446Smrj
5283446Smrj
5293446Smrj /*******************************************************************************
5303446Smrj *
5313446Smrj * FUNCTION: AcpiUtDeleteObjectDesc
5323446Smrj *
5333446Smrj * PARAMETERS: Object - An Acpi internal object to be deleted
5343446Smrj *
5353446Smrj * RETURN: None.
5363446Smrj *
5373446Smrj * DESCRIPTION: Free an ACPI object descriptor or add it to the object cache
5383446Smrj *
5393446Smrj ******************************************************************************/
5403446Smrj
5413446Smrj void
AcpiUtDeleteObjectDesc(ACPI_OPERAND_OBJECT * Object)5423446Smrj AcpiUtDeleteObjectDesc (
5433446Smrj ACPI_OPERAND_OBJECT *Object)
5443446Smrj {
5453446Smrj ACPI_FUNCTION_TRACE_PTR (UtDeleteObjectDesc, Object);
5463446Smrj
5473446Smrj
5483446Smrj /* Object must be an ACPI_OPERAND_OBJECT */
5493446Smrj
5503446Smrj if (ACPI_GET_DESCRIPTOR_TYPE (Object) != ACPI_DESC_TYPE_OPERAND)
5513446Smrj {
5523446Smrj ACPI_ERROR ((AE_INFO,
5533446Smrj "%p is not an ACPI Operand object [%s]", Object,
5543446Smrj AcpiUtGetDescriptorName (Object)));
5553446Smrj return_VOID;
5563446Smrj }
5573446Smrj
5583446Smrj (void) AcpiOsReleaseObject (AcpiGbl_OperandCache, Object);
5593446Smrj return_VOID;
5603446Smrj }
5613446Smrj
5623446Smrj
5633446Smrj /*******************************************************************************
5643446Smrj *
5653446Smrj * FUNCTION: AcpiUtGetSimpleObjectSize
5663446Smrj *
5673446Smrj * PARAMETERS: InternalObject - An ACPI operand object
5683446Smrj * ObjLength - Where the length is returned
5693446Smrj *
5703446Smrj * RETURN: Status
5713446Smrj *
5723446Smrj * DESCRIPTION: This function is called to determine the space required to
5733446Smrj * contain a simple object for return to an external user.
5743446Smrj *
5753446Smrj * The length includes the object structure plus any additional
5763446Smrj * needed space.
5773446Smrj *
5783446Smrj ******************************************************************************/
5793446Smrj
5803446Smrj static ACPI_STATUS
AcpiUtGetSimpleObjectSize(ACPI_OPERAND_OBJECT * InternalObject,ACPI_SIZE * ObjLength)5813446Smrj AcpiUtGetSimpleObjectSize (
5823446Smrj ACPI_OPERAND_OBJECT *InternalObject,
5833446Smrj ACPI_SIZE *ObjLength)
5843446Smrj {
5853446Smrj ACPI_SIZE Length;
5867851SDana.Myers@Sun.COM ACPI_SIZE Size;
5873446Smrj ACPI_STATUS Status = AE_OK;
5883446Smrj
5893446Smrj
5903446Smrj ACPI_FUNCTION_TRACE_PTR (UtGetSimpleObjectSize, InternalObject);
5913446Smrj
5923446Smrj
5937851SDana.Myers@Sun.COM /* Start with the length of the (external) Acpi object */
5947851SDana.Myers@Sun.COM
5957851SDana.Myers@Sun.COM Length = sizeof (ACPI_OBJECT);
5967851SDana.Myers@Sun.COM
5977851SDana.Myers@Sun.COM /* A NULL object is allowed, can be a legal uninitialized package element */
5987851SDana.Myers@Sun.COM
5993446Smrj if (!InternalObject)
6003446Smrj {
6017851SDana.Myers@Sun.COM /*
6027851SDana.Myers@Sun.COM * Object is NULL, just return the length of ACPI_OBJECT
6037851SDana.Myers@Sun.COM * (A NULL ACPI_OBJECT is an object of all zeroes.)
6047851SDana.Myers@Sun.COM */
6057851SDana.Myers@Sun.COM *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length);
6063446Smrj return_ACPI_STATUS (AE_OK);
6073446Smrj }
6083446Smrj
6097851SDana.Myers@Sun.COM /* A Namespace Node should never appear here */
6103446Smrj
6113446Smrj if (ACPI_GET_DESCRIPTOR_TYPE (InternalObject) == ACPI_DESC_TYPE_NAMED)
6123446Smrj {
6137851SDana.Myers@Sun.COM /* A namespace node should never get here */
6143446Smrj
6157851SDana.Myers@Sun.COM return_ACPI_STATUS (AE_AML_INTERNAL);
6163446Smrj }
6173446Smrj
6183446Smrj /*
6193446Smrj * The final length depends on the object type
6203446Smrj * Strings and Buffers are packed right up against the parent object and
6213446Smrj * must be accessed bytewise or there may be alignment problems on
6223446Smrj * certain processors
6233446Smrj */
6249980SDana.Myers@Sun.COM switch (InternalObject->Common.Type)
6253446Smrj {
6263446Smrj case ACPI_TYPE_STRING:
6273446Smrj
6283446Smrj Length += (ACPI_SIZE) InternalObject->String.Length + 1;
6293446Smrj break;
6303446Smrj
6313446Smrj
6323446Smrj case ACPI_TYPE_BUFFER:
6333446Smrj
6343446Smrj Length += (ACPI_SIZE) InternalObject->Buffer.Length;
6353446Smrj break;
6363446Smrj
6373446Smrj
6383446Smrj case ACPI_TYPE_INTEGER:
6393446Smrj case ACPI_TYPE_PROCESSOR:
6403446Smrj case ACPI_TYPE_POWER:
6413446Smrj
6427851SDana.Myers@Sun.COM /* No extra data for these types */
6437851SDana.Myers@Sun.COM
6443446Smrj break;
6453446Smrj
6463446Smrj
6473446Smrj case ACPI_TYPE_LOCAL_REFERENCE:
6483446Smrj
6497851SDana.Myers@Sun.COM switch (InternalObject->Reference.Class)
6503446Smrj {
6517851SDana.Myers@Sun.COM case ACPI_REFCLASS_NAME:
6523446Smrj
6533446Smrj /*
6543446Smrj * Get the actual length of the full pathname to this object.
6553446Smrj * The reference will be converted to the pathname to the object
6563446Smrj */
6577851SDana.Myers@Sun.COM Size = AcpiNsGetPathnameLength (InternalObject->Reference.Node);
6587851SDana.Myers@Sun.COM if (!Size)
6597851SDana.Myers@Sun.COM {
6607851SDana.Myers@Sun.COM return_ACPI_STATUS (AE_BAD_PARAMETER);
6617851SDana.Myers@Sun.COM }
6627851SDana.Myers@Sun.COM
6637851SDana.Myers@Sun.COM Length += ACPI_ROUND_UP_TO_NATIVE_WORD (Size);
6643446Smrj break;
6653446Smrj
6663446Smrj default:
6673446Smrj
6683446Smrj /*
6693446Smrj * No other reference opcodes are supported.
6703446Smrj * Notably, Locals and Args are not supported, but this may be
6713446Smrj * required eventually.
6723446Smrj */
6737851SDana.Myers@Sun.COM ACPI_ERROR ((AE_INFO, "Cannot convert to external object - "
6747851SDana.Myers@Sun.COM "unsupported Reference Class [%s] %X in object %p",
6757851SDana.Myers@Sun.COM AcpiUtGetReferenceName (InternalObject),
6767851SDana.Myers@Sun.COM InternalObject->Reference.Class, InternalObject));
6773446Smrj Status = AE_TYPE;
6783446Smrj break;
6793446Smrj }
6803446Smrj break;
6813446Smrj
6823446Smrj
6833446Smrj default:
6843446Smrj
6857851SDana.Myers@Sun.COM ACPI_ERROR ((AE_INFO, "Cannot convert to external object - "
6867851SDana.Myers@Sun.COM "unsupported type [%s] %X in object %p",
6877851SDana.Myers@Sun.COM AcpiUtGetObjectTypeName (InternalObject),
6889980SDana.Myers@Sun.COM InternalObject->Common.Type, InternalObject));
6893446Smrj Status = AE_TYPE;
6903446Smrj break;
6913446Smrj }
6923446Smrj
6933446Smrj /*
6943446Smrj * Account for the space required by the object rounded up to the next
6953446Smrj * multiple of the machine word size. This keeps each object aligned
6963446Smrj * on a machine word boundary. (preventing alignment faults on some
6973446Smrj * machines.)
6983446Smrj */
6993446Smrj *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length);
7003446Smrj return_ACPI_STATUS (Status);
7013446Smrj }
7023446Smrj
7033446Smrj
7043446Smrj /*******************************************************************************
7053446Smrj *
7063446Smrj * FUNCTION: AcpiUtGetElementLength
7073446Smrj *
7083446Smrj * PARAMETERS: ACPI_PKG_CALLBACK
7093446Smrj *
7103446Smrj * RETURN: Status
7113446Smrj *
7123446Smrj * DESCRIPTION: Get the length of one package element.
7133446Smrj *
7143446Smrj ******************************************************************************/
7153446Smrj
7163446Smrj static ACPI_STATUS
AcpiUtGetElementLength(UINT8 ObjectType,ACPI_OPERAND_OBJECT * SourceObject,ACPI_GENERIC_STATE * State,void * Context)7173446Smrj AcpiUtGetElementLength (
7183446Smrj UINT8 ObjectType,
7193446Smrj ACPI_OPERAND_OBJECT *SourceObject,
7203446Smrj ACPI_GENERIC_STATE *State,
7213446Smrj void *Context)
7223446Smrj {
7233446Smrj ACPI_STATUS Status = AE_OK;
7243446Smrj ACPI_PKG_INFO *Info = (ACPI_PKG_INFO *) Context;
7253446Smrj ACPI_SIZE ObjectSpace;
7263446Smrj
7273446Smrj
7283446Smrj switch (ObjectType)
7293446Smrj {
7303446Smrj case ACPI_COPY_TYPE_SIMPLE:
7313446Smrj
7323446Smrj /*
7333446Smrj * Simple object - just get the size (Null object/entry is handled
7343446Smrj * here also) and sum it into the running package length
7353446Smrj */
7363446Smrj Status = AcpiUtGetSimpleObjectSize (SourceObject, &ObjectSpace);
7373446Smrj if (ACPI_FAILURE (Status))
7383446Smrj {
7393446Smrj return (Status);
7403446Smrj }
7413446Smrj
7423446Smrj Info->Length += ObjectSpace;
7433446Smrj break;
7443446Smrj
7453446Smrj
7463446Smrj case ACPI_COPY_TYPE_PACKAGE:
7473446Smrj
7483446Smrj /* Package object - nothing much to do here, let the walk handle it */
7493446Smrj
7503446Smrj Info->NumPackages++;
7513446Smrj State->Pkg.ThisTargetObj = NULL;
7523446Smrj break;
7533446Smrj
7543446Smrj
7553446Smrj default:
7563446Smrj
7573446Smrj /* No other types allowed */
7583446Smrj
7593446Smrj return (AE_BAD_PARAMETER);
7603446Smrj }
7613446Smrj
7623446Smrj return (Status);
7633446Smrj }
7643446Smrj
7653446Smrj
7663446Smrj /*******************************************************************************
7673446Smrj *
7683446Smrj * FUNCTION: AcpiUtGetPackageObjectSize
7693446Smrj *
7703446Smrj * PARAMETERS: InternalObject - An ACPI internal object
7713446Smrj * ObjLength - Where the length is returned
7723446Smrj *
7733446Smrj * RETURN: Status
7743446Smrj *
7753446Smrj * DESCRIPTION: This function is called to determine the space required to
7763446Smrj * contain a package object for return to an external user.
7773446Smrj *
7783446Smrj * This is moderately complex since a package contains other
7793446Smrj * objects including packages.
7803446Smrj *
7813446Smrj ******************************************************************************/
7823446Smrj
7833446Smrj static ACPI_STATUS
AcpiUtGetPackageObjectSize(ACPI_OPERAND_OBJECT * InternalObject,ACPI_SIZE * ObjLength)7843446Smrj AcpiUtGetPackageObjectSize (
7853446Smrj ACPI_OPERAND_OBJECT *InternalObject,
7863446Smrj ACPI_SIZE *ObjLength)
7873446Smrj {
7883446Smrj ACPI_STATUS Status;
7893446Smrj ACPI_PKG_INFO Info;
7903446Smrj
7913446Smrj
7923446Smrj ACPI_FUNCTION_TRACE_PTR (UtGetPackageObjectSize, InternalObject);
7933446Smrj
7943446Smrj
7953446Smrj Info.Length = 0;
7963446Smrj Info.ObjectSpace = 0;
7973446Smrj Info.NumPackages = 1;
7983446Smrj
7993446Smrj Status = AcpiUtWalkPackageTree (InternalObject, NULL,
8003446Smrj AcpiUtGetElementLength, &Info);
8013446Smrj if (ACPI_FAILURE (Status))
8023446Smrj {
8033446Smrj return_ACPI_STATUS (Status);
8043446Smrj }
8053446Smrj
8063446Smrj /*
8073446Smrj * We have handled all of the objects in all levels of the package.
8083446Smrj * just add the length of the package objects themselves.
8093446Smrj * Round up to the next machine word.
8103446Smrj */
8113446Smrj Info.Length += ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT)) *
8123446Smrj (ACPI_SIZE) Info.NumPackages;
8133446Smrj
8143446Smrj /* Return the total package length */
8153446Smrj
8163446Smrj *ObjLength = Info.Length;
8173446Smrj return_ACPI_STATUS (Status);
8183446Smrj }
8193446Smrj
8203446Smrj
8213446Smrj /*******************************************************************************
8223446Smrj *
8233446Smrj * FUNCTION: AcpiUtGetObjectSize
8243446Smrj *
8253446Smrj * PARAMETERS: InternalObject - An ACPI internal object
8263446Smrj * ObjLength - Where the length will be returned
8273446Smrj *
8283446Smrj * RETURN: Status
8293446Smrj *
8303446Smrj * DESCRIPTION: This function is called to determine the space required to
8313446Smrj * contain an object for return to an API user.
8323446Smrj *
8333446Smrj ******************************************************************************/
8343446Smrj
8353446Smrj ACPI_STATUS
AcpiUtGetObjectSize(ACPI_OPERAND_OBJECT * InternalObject,ACPI_SIZE * ObjLength)8363446Smrj AcpiUtGetObjectSize (
8373446Smrj ACPI_OPERAND_OBJECT *InternalObject,
8383446Smrj ACPI_SIZE *ObjLength)
8393446Smrj {
8403446Smrj ACPI_STATUS Status;
8413446Smrj
8423446Smrj
8433446Smrj ACPI_FUNCTION_ENTRY ();
8443446Smrj
8453446Smrj
8463446Smrj if ((ACPI_GET_DESCRIPTOR_TYPE (InternalObject) == ACPI_DESC_TYPE_OPERAND) &&
8479980SDana.Myers@Sun.COM (InternalObject->Common.Type == ACPI_TYPE_PACKAGE))
8483446Smrj {
8493446Smrj Status = AcpiUtGetPackageObjectSize (InternalObject, ObjLength);
8503446Smrj }
8513446Smrj else
8523446Smrj {
8533446Smrj Status = AcpiUtGetSimpleObjectSize (InternalObject, ObjLength);
8543446Smrj }
8553446Smrj
8563446Smrj return (Status);
8573446Smrj }
8583446Smrj
8593446Smrj
860