Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:03

0001 /******************************************************************************
0002  *
0003  * Module Name: utobject - ACPI object create/delete/size/cache routines
0004  *
0005  *****************************************************************************/
0006 
0007 /******************************************************************************
0008  *
0009  * 1. Copyright Notice
0010  *
0011  * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
0012  * All rights reserved.
0013  *
0014  * 2. License
0015  *
0016  * 2.1. This is your license from Intel Corp. under its intellectual property
0017  * rights. You may have additional license terms from the party that provided
0018  * you this software, covering your right to use that party's intellectual
0019  * property rights.
0020  *
0021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
0022  * copy of the source code appearing in this file ("Covered Code") an
0023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
0024  * base code distributed originally by Intel ("Original Intel Code") to copy,
0025  * make derivatives, distribute, use and display any portion of the Covered
0026  * Code in any form, with the right to sublicense such rights; and
0027  *
0028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
0029  * license (with the right to sublicense), under only those claims of Intel
0030  * patents that are infringed by the Original Intel Code, to make, use, sell,
0031  * offer to sell, and import the Covered Code and derivative works thereof
0032  * solely to the minimum extent necessary to exercise the above copyright
0033  * license, and in no event shall the patent license extend to any additions
0034  * to or modifications of the Original Intel Code. No other license or right
0035  * is granted directly or by implication, estoppel or otherwise;
0036  *
0037  * The above copyright and patent license is granted only if the following
0038  * conditions are met:
0039  *
0040  * 3. Conditions
0041  *
0042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
0043  * Redistribution of source code of any substantial portion of the Covered
0044  * Code or modification with rights to further distribute source must include
0045  * the above Copyright Notice, the above License, this list of Conditions,
0046  * and the following Disclaimer and Export Compliance provision. In addition,
0047  * Licensee must cause all Covered Code to which Licensee contributes to
0048  * contain a file documenting the changes Licensee made to create that Covered
0049  * Code and the date of any change. Licensee must include in that file the
0050  * documentation of any changes made by any predecessor Licensee. Licensee
0051  * must include a prominent statement that the modification is derived,
0052  * directly or indirectly, from Original Intel Code.
0053  *
0054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
0055  * Redistribution of source code of any substantial portion of the Covered
0056  * Code or modification without rights to further distribute source must
0057  * include the following Disclaimer and Export Compliance provision in the
0058  * documentation and/or other materials provided with distribution. In
0059  * addition, Licensee may not authorize further sublicense of source of any
0060  * portion of the Covered Code, and must include terms to the effect that the
0061  * license from Licensee to its licensee is limited to the intellectual
0062  * property embodied in the software Licensee provides to its licensee, and
0063  * not to intellectual property embodied in modifications its licensee may
0064  * make.
0065  *
0066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
0067  * substantial portion of the Covered Code or modification must reproduce the
0068  * above Copyright Notice, and the following Disclaimer and Export Compliance
0069  * provision in the documentation and/or other materials provided with the
0070  * distribution.
0071  *
0072  * 3.4. Intel retains all right, title, and interest in and to the Original
0073  * Intel Code.
0074  *
0075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
0076  * Intel shall be used in advertising or otherwise to promote the sale, use or
0077  * other dealings in products derived from or relating to the Covered Code
0078  * without prior written authorization from Intel.
0079  *
0080  * 4. Disclaimer and Export Compliance
0081  *
0082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
0083  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
0084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
0085  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
0086  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
0087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
0088  * PARTICULAR PURPOSE.
0089  *
0090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
0091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
0092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
0093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
0094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
0095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
0096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
0097  * LIMITED REMEDY.
0098  *
0099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
0100  * software or system incorporating such software without first obtaining any
0101  * required license or other approval from the U. S. Department of Commerce or
0102  * any other agency or department of the United States Government. In the
0103  * event Licensee exports any such software from the United States or
0104  * re-exports any such software from a foreign destination, Licensee shall
0105  * ensure that the distribution and export/re-export of the software is in
0106  * compliance with all laws, regulations, orders, or other restrictions of the
0107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
0108  * any of its subsidiaries will export/re-export any technical data, process,
0109  * software, or service, directly or indirectly, to any country for which the
0110  * United States government or any agency thereof requires an export license,
0111  * other governmental approval, or letter of assurance, without first obtaining
0112  * such license, approval or letter.
0113  *
0114  *****************************************************************************
0115  *
0116  * Alternatively, you may choose to be licensed under the terms of the
0117  * following license:
0118  *
0119  * Redistribution and use in source and binary forms, with or without
0120  * modification, are permitted provided that the following conditions
0121  * are met:
0122  * 1. Redistributions of source code must retain the above copyright
0123  *    notice, this list of conditions, and the following disclaimer,
0124  *    without modification.
0125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
0126  *    substantially similar to the "NO WARRANTY" disclaimer below
0127  *    ("Disclaimer") and any redistribution must be conditioned upon
0128  *    including a substantially similar Disclaimer requirement for further
0129  *    binary redistribution.
0130  * 3. Neither the names of the above-listed copyright holders nor the names
0131  *    of any contributors may be used to endorse or promote products derived
0132  *    from this software without specific prior written permission.
0133  *
0134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0145  *
0146  * Alternatively, you may choose to be licensed under the terms of the
0147  * GNU General Public License ("GPL") version 2 as published by the Free
0148  * Software Foundation.
0149  *
0150  *****************************************************************************/
0151 
0152 #include "acpi.h"
0153 #include "accommon.h"
0154 #include "acnamesp.h"
0155 
0156 
0157 #define _COMPONENT          ACPI_UTILITIES
0158         ACPI_MODULE_NAME    ("utobject")
0159 
0160 /* Local prototypes */
0161 
0162 static ACPI_STATUS
0163 AcpiUtGetSimpleObjectSize (
0164     ACPI_OPERAND_OBJECT     *Obj,
0165     ACPI_SIZE               *ObjLength);
0166 
0167 static ACPI_STATUS
0168 AcpiUtGetPackageObjectSize (
0169     ACPI_OPERAND_OBJECT     *Obj,
0170     ACPI_SIZE               *ObjLength);
0171 
0172 static ACPI_STATUS
0173 AcpiUtGetElementLength (
0174     UINT8                   ObjectType,
0175     ACPI_OPERAND_OBJECT     *SourceObject,
0176     ACPI_GENERIC_STATE      *State,
0177     void                    *Context);
0178 
0179 
0180 /*******************************************************************************
0181  *
0182  * FUNCTION:    AcpiUtCreateInternalObjectDbg
0183  *
0184  * PARAMETERS:  ModuleName          - Source file name of caller
0185  *              LineNumber          - Line number of caller
0186  *              ComponentId         - Component type of caller
0187  *              Type                - ACPI Type of the new object
0188  *
0189  * RETURN:      A new internal object, null on failure
0190  *
0191  * DESCRIPTION: Create and initialize a new internal object.
0192  *
0193  * NOTE:        We always allocate the worst-case object descriptor because
0194  *              these objects are cached, and we want them to be
0195  *              one-size-satisfies-any-request. This in itself may not be
0196  *              the most memory efficient, but the efficiency of the object
0197  *              cache should more than make up for this!
0198  *
0199  ******************************************************************************/
0200 
0201 ACPI_OPERAND_OBJECT  *
0202 AcpiUtCreateInternalObjectDbg (
0203     const char              *ModuleName,
0204     UINT32                  LineNumber,
0205     UINT32                  ComponentId,
0206     ACPI_OBJECT_TYPE        Type)
0207 {
0208     ACPI_OPERAND_OBJECT     *Object;
0209     ACPI_OPERAND_OBJECT     *SecondObject;
0210 
0211 
0212     ACPI_FUNCTION_TRACE_STR (UtCreateInternalObjectDbg,
0213         AcpiUtGetTypeName (Type));
0214 
0215 
0216     /* Allocate the raw object descriptor */
0217 
0218     Object = AcpiUtAllocateObjectDescDbg (
0219         ModuleName, LineNumber, ComponentId);
0220     if (!Object)
0221     {
0222         return_PTR (NULL);
0223     }
0224 
0225     switch (Type)
0226     {
0227     case ACPI_TYPE_REGION:
0228     case ACPI_TYPE_BUFFER_FIELD:
0229     case ACPI_TYPE_LOCAL_BANK_FIELD:
0230 
0231         /* These types require a secondary object */
0232 
0233         SecondObject = AcpiUtAllocateObjectDescDbg (
0234             ModuleName, LineNumber, ComponentId);
0235         if (!SecondObject)
0236         {
0237             AcpiUtDeleteObjectDesc (Object);
0238             return_PTR (NULL);
0239         }
0240 
0241         SecondObject->Common.Type = ACPI_TYPE_LOCAL_EXTRA;
0242         SecondObject->Common.ReferenceCount = 1;
0243 
0244         /* Link the second object to the first */
0245 
0246         Object->Common.NextObject = SecondObject;
0247         break;
0248 
0249     default:
0250 
0251         /* All others have no secondary object */
0252         break;
0253     }
0254 
0255     /* Save the object type in the object descriptor */
0256 
0257     Object->Common.Type = (UINT8) Type;
0258 
0259     /* Init the reference count */
0260 
0261     Object->Common.ReferenceCount = 1;
0262 
0263     /* Any per-type initialization should go here */
0264 
0265     return_PTR (Object);
0266 }
0267 
0268 
0269 /*******************************************************************************
0270  *
0271  * FUNCTION:    AcpiUtCreatePackageObject
0272  *
0273  * PARAMETERS:  Count               - Number of package elements
0274  *
0275  * RETURN:      Pointer to a new Package object, null on failure
0276  *
0277  * DESCRIPTION: Create a fully initialized package object
0278  *
0279  ******************************************************************************/
0280 
0281 ACPI_OPERAND_OBJECT *
0282 AcpiUtCreatePackageObject (
0283     UINT32                  Count)
0284 {
0285     ACPI_OPERAND_OBJECT     *PackageDesc;
0286     ACPI_OPERAND_OBJECT     **PackageElements;
0287 
0288 
0289     ACPI_FUNCTION_TRACE_U32 (UtCreatePackageObject, Count);
0290 
0291 
0292     /* Create a new Package object */
0293 
0294     PackageDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
0295     if (!PackageDesc)
0296     {
0297         return_PTR (NULL);
0298     }
0299 
0300     /*
0301      * Create the element array. Count+1 allows the array to be null
0302      * terminated.
0303      */
0304     PackageElements = ACPI_ALLOCATE_ZEROED (
0305         ((ACPI_SIZE) Count + 1) * sizeof (void *));
0306     if (!PackageElements)
0307     {
0308         ACPI_FREE (PackageDesc);
0309         return_PTR (NULL);
0310     }
0311 
0312     PackageDesc->Package.Count = Count;
0313     PackageDesc->Package.Elements = PackageElements;
0314     return_PTR (PackageDesc);
0315 }
0316 
0317 
0318 /*******************************************************************************
0319  *
0320  * FUNCTION:    AcpiUtCreateIntegerObject
0321  *
0322  * PARAMETERS:  InitialValue        - Initial value for the integer
0323  *
0324  * RETURN:      Pointer to a new Integer object, null on failure
0325  *
0326  * DESCRIPTION: Create an initialized integer object
0327  *
0328  ******************************************************************************/
0329 
0330 ACPI_OPERAND_OBJECT *
0331 AcpiUtCreateIntegerObject (
0332     UINT64                  InitialValue)
0333 {
0334     ACPI_OPERAND_OBJECT     *IntegerDesc;
0335 
0336 
0337     ACPI_FUNCTION_TRACE (UtCreateIntegerObject);
0338 
0339 
0340     /* Create and initialize a new integer object */
0341 
0342     IntegerDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
0343     if (!IntegerDesc)
0344     {
0345         return_PTR (NULL);
0346     }
0347 
0348     IntegerDesc->Integer.Value = InitialValue;
0349     return_PTR (IntegerDesc);
0350 }
0351 
0352 
0353 /*******************************************************************************
0354  *
0355  * FUNCTION:    AcpiUtCreateBufferObject
0356  *
0357  * PARAMETERS:  BufferSize             - Size of buffer to be created
0358  *
0359  * RETURN:      Pointer to a new Buffer object, null on failure
0360  *
0361  * DESCRIPTION: Create a fully initialized buffer object
0362  *
0363  ******************************************************************************/
0364 
0365 ACPI_OPERAND_OBJECT *
0366 AcpiUtCreateBufferObject (
0367     ACPI_SIZE               BufferSize)
0368 {
0369     ACPI_OPERAND_OBJECT     *BufferDesc;
0370     UINT8                   *Buffer = NULL;
0371 
0372 
0373     ACPI_FUNCTION_TRACE_U32 (UtCreateBufferObject, BufferSize);
0374 
0375 
0376     /* Create a new Buffer object */
0377 
0378     BufferDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
0379     if (!BufferDesc)
0380     {
0381         return_PTR (NULL);
0382     }
0383 
0384     /* Create an actual buffer only if size > 0 */
0385 
0386     if (BufferSize > 0)
0387     {
0388         /* Allocate the actual buffer */
0389 
0390         Buffer = ACPI_ALLOCATE_ZEROED (BufferSize);
0391         if (!Buffer)
0392         {
0393             ACPI_ERROR ((AE_INFO, "Could not allocate size %u",
0394                 (UINT32) BufferSize));
0395 
0396             AcpiUtRemoveReference (BufferDesc);
0397             return_PTR (NULL);
0398         }
0399     }
0400 
0401     /* Complete buffer object initialization */
0402 
0403     BufferDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
0404     BufferDesc->Buffer.Pointer = Buffer;
0405     BufferDesc->Buffer.Length = (UINT32) BufferSize;
0406 
0407     /* Return the new buffer descriptor */
0408 
0409     return_PTR (BufferDesc);
0410 }
0411 
0412 
0413 /*******************************************************************************
0414  *
0415  * FUNCTION:    AcpiUtCreateStringObject
0416  *
0417  * PARAMETERS:  StringSize          - Size of string to be created. Does not
0418  *                                    include NULL terminator, this is added
0419  *                                    automatically.
0420  *
0421  * RETURN:      Pointer to a new String object
0422  *
0423  * DESCRIPTION: Create a fully initialized string object
0424  *
0425  ******************************************************************************/
0426 
0427 ACPI_OPERAND_OBJECT *
0428 AcpiUtCreateStringObject (
0429     ACPI_SIZE               StringSize)
0430 {
0431     ACPI_OPERAND_OBJECT     *StringDesc;
0432     char                    *String;
0433 
0434 
0435     ACPI_FUNCTION_TRACE_U32 (UtCreateStringObject, StringSize);
0436 
0437 
0438     /* Create a new String object */
0439 
0440     StringDesc = AcpiUtCreateInternalObject (ACPI_TYPE_STRING);
0441     if (!StringDesc)
0442     {
0443         return_PTR (NULL);
0444     }
0445 
0446     /*
0447      * Allocate the actual string buffer -- (Size + 1) for NULL terminator.
0448      * NOTE: Zero-length strings are NULL terminated
0449      */
0450     String = ACPI_ALLOCATE_ZEROED (StringSize + 1);
0451     if (!String)
0452     {
0453         ACPI_ERROR ((AE_INFO, "Could not allocate size %u",
0454             (UINT32) StringSize));
0455 
0456         AcpiUtRemoveReference (StringDesc);
0457         return_PTR (NULL);
0458     }
0459 
0460     /* Complete string object initialization */
0461 
0462     StringDesc->String.Pointer = String;
0463     StringDesc->String.Length = (UINT32) StringSize;
0464 
0465     /* Return the new string descriptor */
0466 
0467     return_PTR (StringDesc);
0468 }
0469 
0470 
0471 /*******************************************************************************
0472  *
0473  * FUNCTION:    AcpiUtValidInternalObject
0474  *
0475  * PARAMETERS:  Object              - Object to be validated
0476  *
0477  * RETURN:      TRUE if object is valid, FALSE otherwise
0478  *
0479  * DESCRIPTION: Validate a pointer to be of type ACPI_OPERAND_OBJECT
0480  *
0481  ******************************************************************************/
0482 
0483 BOOLEAN
0484 AcpiUtValidInternalObject (
0485     void                    *Object)
0486 {
0487 
0488     ACPI_FUNCTION_NAME (UtValidInternalObject);
0489 
0490 
0491     /* Check for a null pointer */
0492 
0493     if (!Object)
0494     {
0495         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "**** Null Object Ptr\n"));
0496         return (FALSE);
0497     }
0498 
0499     /* Check the descriptor type field */
0500 
0501     switch (ACPI_GET_DESCRIPTOR_TYPE (Object))
0502     {
0503     case ACPI_DESC_TYPE_OPERAND:
0504 
0505         /* The object appears to be a valid ACPI_OPERAND_OBJECT */
0506 
0507         return (TRUE);
0508 
0509     default:
0510 
0511         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
0512             "%p is not an ACPI operand obj [%s]\n",
0513             Object, AcpiUtGetDescriptorName (Object)));
0514         break;
0515     }
0516 
0517     return (FALSE);
0518 }
0519 
0520 
0521 /*******************************************************************************
0522  *
0523  * FUNCTION:    AcpiUtAllocateObjectDescDbg
0524  *
0525  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
0526  *              LineNumber          - Caller's line number (for error output)
0527  *              ComponentId         - Caller's component ID (for error output)
0528  *
0529  * RETURN:      Pointer to newly allocated object descriptor. Null on error
0530  *
0531  * DESCRIPTION: Allocate a new object descriptor. Gracefully handle
0532  *              error conditions.
0533  *
0534  ******************************************************************************/
0535 
0536 void *
0537 AcpiUtAllocateObjectDescDbg (
0538     const char              *ModuleName,
0539     UINT32                  LineNumber,
0540     UINT32                  ComponentId)
0541 {
0542     ACPI_OPERAND_OBJECT     *Object;
0543 
0544 
0545     ACPI_FUNCTION_TRACE (UtAllocateObjectDescDbg);
0546 
0547 
0548     Object = AcpiOsAcquireObject (AcpiGbl_OperandCache);
0549     if (!Object)
0550     {
0551         ACPI_ERROR ((ModuleName, LineNumber,
0552             "Could not allocate an object descriptor"));
0553 
0554         return_PTR (NULL);
0555     }
0556 
0557     /* Mark the descriptor type */
0558 
0559     ACPI_SET_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_OPERAND);
0560 
0561     ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p Size %X\n",
0562         Object, (UINT32) sizeof (ACPI_OPERAND_OBJECT)));
0563 
0564     return_PTR (Object);
0565 }
0566 
0567 
0568 /*******************************************************************************
0569  *
0570  * FUNCTION:    AcpiUtDeleteObjectDesc
0571  *
0572  * PARAMETERS:  Object          - An Acpi internal object to be deleted
0573  *
0574  * RETURN:      None.
0575  *
0576  * DESCRIPTION: Free an ACPI object descriptor or add it to the object cache
0577  *
0578  ******************************************************************************/
0579 
0580 void
0581 AcpiUtDeleteObjectDesc (
0582     ACPI_OPERAND_OBJECT     *Object)
0583 {
0584     ACPI_FUNCTION_TRACE_PTR (UtDeleteObjectDesc, Object);
0585 
0586 
0587     /* Object must be of type ACPI_OPERAND_OBJECT */
0588 
0589     if (ACPI_GET_DESCRIPTOR_TYPE (Object) != ACPI_DESC_TYPE_OPERAND)
0590     {
0591         ACPI_ERROR ((AE_INFO,
0592             "%p is not an ACPI Operand object [%s]", Object,
0593             AcpiUtGetDescriptorName (Object)));
0594         return_VOID;
0595     }
0596 
0597     (void) AcpiOsReleaseObject (AcpiGbl_OperandCache, Object);
0598     return_VOID;
0599 }
0600 
0601 
0602 /*******************************************************************************
0603  *
0604  * FUNCTION:    AcpiUtGetSimpleObjectSize
0605  *
0606  * PARAMETERS:  InternalObject     - An ACPI operand object
0607  *              ObjLength          - Where the length is returned
0608  *
0609  * RETURN:      Status
0610  *
0611  * DESCRIPTION: This function is called to determine the space required to
0612  *              contain a simple object for return to an external user.
0613  *
0614  *              The length includes the object structure plus any additional
0615  *              needed space.
0616  *
0617  ******************************************************************************/
0618 
0619 static ACPI_STATUS
0620 AcpiUtGetSimpleObjectSize (
0621     ACPI_OPERAND_OBJECT     *InternalObject,
0622     ACPI_SIZE               *ObjLength)
0623 {
0624     ACPI_SIZE               Length;
0625     ACPI_SIZE               Size;
0626     ACPI_STATUS             Status = AE_OK;
0627 
0628 
0629     ACPI_FUNCTION_TRACE_PTR (UtGetSimpleObjectSize, InternalObject);
0630 
0631 
0632     /* Start with the length of the (external) Acpi object */
0633 
0634     Length = sizeof (ACPI_OBJECT);
0635 
0636     /* A NULL object is allowed, can be a legal uninitialized package element */
0637 
0638     if (!InternalObject)
0639     {
0640         /*
0641          * Object is NULL, just return the length of ACPI_OBJECT
0642          * (A NULL ACPI_OBJECT is an object of all zeroes.)
0643          */
0644         *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length);
0645         return_ACPI_STATUS (AE_OK);
0646     }
0647 
0648     /* A Namespace Node should never appear here */
0649 
0650     if (ACPI_GET_DESCRIPTOR_TYPE (InternalObject) == ACPI_DESC_TYPE_NAMED)
0651     {
0652         /* A namespace node should never get here */
0653 
0654         ACPI_ERROR ((AE_INFO,
0655             "Received a namespace node [%4.4s] "
0656             "where an operand object is required",
0657             ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, InternalObject)->Name.Ascii));
0658         return_ACPI_STATUS (AE_AML_INTERNAL);
0659     }
0660 
0661     /*
0662      * The final length depends on the object type
0663      * Strings and Buffers are packed right up against the parent object and
0664      * must be accessed bytewise or there may be alignment problems on
0665      * certain processors
0666      */
0667     switch (InternalObject->Common.Type)
0668     {
0669     case ACPI_TYPE_STRING:
0670 
0671         Length += (ACPI_SIZE) InternalObject->String.Length + 1;
0672         break;
0673 
0674     case ACPI_TYPE_BUFFER:
0675 
0676         Length += (ACPI_SIZE) InternalObject->Buffer.Length;
0677         break;
0678 
0679     case ACPI_TYPE_INTEGER:
0680     case ACPI_TYPE_PROCESSOR:
0681     case ACPI_TYPE_POWER:
0682 
0683         /* No extra data for these types */
0684 
0685         break;
0686 
0687     case ACPI_TYPE_LOCAL_REFERENCE:
0688 
0689         switch (InternalObject->Reference.Class)
0690         {
0691         case ACPI_REFCLASS_NAME:
0692             /*
0693              * Get the actual length of the full pathname to this object.
0694              * The reference will be converted to the pathname to the object
0695              */
0696             Size = AcpiNsGetPathnameLength (InternalObject->Reference.Node);
0697             if (!Size)
0698             {
0699                 return_ACPI_STATUS (AE_BAD_PARAMETER);
0700             }
0701 
0702             Length += ACPI_ROUND_UP_TO_NATIVE_WORD (Size);
0703             break;
0704 
0705         default:
0706             /*
0707              * No other reference opcodes are supported.
0708              * Notably, Locals and Args are not supported, but this may be
0709              * required eventually.
0710              */
0711             ACPI_ERROR ((AE_INFO, "Cannot convert to external object - "
0712                 "unsupported Reference Class [%s] 0x%X in object %p",
0713                 AcpiUtGetReferenceName (InternalObject),
0714                 InternalObject->Reference.Class, InternalObject));
0715             Status = AE_TYPE;
0716             break;
0717         }
0718         break;
0719 
0720     default:
0721 
0722         ACPI_ERROR ((AE_INFO, "Cannot convert to external object - "
0723             "unsupported type [%s] 0x%X in object %p",
0724             AcpiUtGetObjectTypeName (InternalObject),
0725             InternalObject->Common.Type, InternalObject));
0726         Status = AE_TYPE;
0727         break;
0728     }
0729 
0730     /*
0731      * Account for the space required by the object rounded up to the next
0732      * multiple of the machine word size. This keeps each object aligned
0733      * on a machine word boundary. (preventing alignment faults on some
0734      * machines.)
0735      */
0736     *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length);
0737     return_ACPI_STATUS (Status);
0738 }
0739 
0740 
0741 /*******************************************************************************
0742  *
0743  * FUNCTION:    AcpiUtGetElementLength
0744  *
0745  * PARAMETERS:  ACPI_PKG_CALLBACK
0746  *
0747  * RETURN:      Status
0748  *
0749  * DESCRIPTION: Get the length of one package element.
0750  *
0751  ******************************************************************************/
0752 
0753 static ACPI_STATUS
0754 AcpiUtGetElementLength (
0755     UINT8                   ObjectType,
0756     ACPI_OPERAND_OBJECT     *SourceObject,
0757     ACPI_GENERIC_STATE      *State,
0758     void                    *Context)
0759 {
0760     ACPI_STATUS             Status = AE_OK;
0761     ACPI_PKG_INFO           *Info = (ACPI_PKG_INFO *) Context;
0762     ACPI_SIZE               ObjectSpace;
0763 
0764 
0765     switch (ObjectType)
0766     {
0767     case ACPI_COPY_TYPE_SIMPLE:
0768         /*
0769          * Simple object - just get the size (Null object/entry is handled
0770          * here also) and sum it into the running package length
0771          */
0772         Status = AcpiUtGetSimpleObjectSize (SourceObject, &ObjectSpace);
0773         if (ACPI_FAILURE (Status))
0774         {
0775             return (Status);
0776         }
0777 
0778         Info->Length += ObjectSpace;
0779         break;
0780 
0781     case ACPI_COPY_TYPE_PACKAGE:
0782 
0783         /* Package object - nothing much to do here, let the walk handle it */
0784 
0785         Info->NumPackages++;
0786         State->Pkg.ThisTargetObj = NULL;
0787         break;
0788 
0789     default:
0790 
0791         /* No other types allowed */
0792 
0793         return (AE_BAD_PARAMETER);
0794     }
0795 
0796     return (Status);
0797 }
0798 
0799 
0800 /*******************************************************************************
0801  *
0802  * FUNCTION:    AcpiUtGetPackageObjectSize
0803  *
0804  * PARAMETERS:  InternalObject      - An ACPI internal object
0805  *              ObjLength           - Where the length is returned
0806  *
0807  * RETURN:      Status
0808  *
0809  * DESCRIPTION: This function is called to determine the space required to
0810  *              contain a package object for return to an external user.
0811  *
0812  *              This is moderately complex since a package contains other
0813  *              objects including packages.
0814  *
0815  ******************************************************************************/
0816 
0817 static ACPI_STATUS
0818 AcpiUtGetPackageObjectSize (
0819     ACPI_OPERAND_OBJECT     *InternalObject,
0820     ACPI_SIZE               *ObjLength)
0821 {
0822     ACPI_STATUS             Status;
0823     ACPI_PKG_INFO           Info;
0824 
0825 
0826     ACPI_FUNCTION_TRACE_PTR (UtGetPackageObjectSize, InternalObject);
0827 
0828 
0829     Info.Length = 0;
0830     Info.ObjectSpace = 0;
0831     Info.NumPackages = 1;
0832 
0833     Status = AcpiUtWalkPackageTree (
0834         InternalObject, NULL, AcpiUtGetElementLength, &Info);
0835     if (ACPI_FAILURE (Status))
0836     {
0837         return_ACPI_STATUS (Status);
0838     }
0839 
0840     /*
0841      * We have handled all of the objects in all levels of the package.
0842      * just add the length of the package objects themselves.
0843      * Round up to the next machine word.
0844      */
0845     Info.Length += ACPI_ROUND_UP_TO_NATIVE_WORD (
0846         sizeof (ACPI_OBJECT)) * (ACPI_SIZE) Info.NumPackages;
0847 
0848     /* Return the total package length */
0849 
0850     *ObjLength = Info.Length;
0851     return_ACPI_STATUS (Status);
0852 }
0853 
0854 
0855 /*******************************************************************************
0856  *
0857  * FUNCTION:    AcpiUtGetObjectSize
0858  *
0859  * PARAMETERS:  InternalObject      - An ACPI internal object
0860  *              ObjLength           - Where the length will be returned
0861  *
0862  * RETURN:      Status
0863  *
0864  * DESCRIPTION: This function is called to determine the space required to
0865  *              contain an object for return to an API user.
0866  *
0867  ******************************************************************************/
0868 
0869 ACPI_STATUS
0870 AcpiUtGetObjectSize (
0871     ACPI_OPERAND_OBJECT     *InternalObject,
0872     ACPI_SIZE               *ObjLength)
0873 {
0874     ACPI_STATUS             Status;
0875 
0876 
0877     ACPI_FUNCTION_ENTRY ();
0878 
0879 
0880     if ((ACPI_GET_DESCRIPTOR_TYPE (InternalObject) ==
0881             ACPI_DESC_TYPE_OPERAND) &&
0882         (InternalObject->Common.Type == ACPI_TYPE_PACKAGE))
0883     {
0884         Status = AcpiUtGetPackageObjectSize (InternalObject, ObjLength);
0885     }
0886     else
0887     {
0888         Status = AcpiUtGetSimpleObjectSize (InternalObject, ObjLength);
0889     }
0890 
0891     return (Status);
0892 }