Home | History | Annotate | Line # | Download | only in utilities
utobject.c revision 1.1.1.4.2.2
      1          1.1    jruoho /******************************************************************************
      2          1.1    jruoho  *
      3          1.1    jruoho  * Module Name: utobject - ACPI object create/delete/size/cache routines
      4          1.1    jruoho  *
      5          1.1    jruoho  *****************************************************************************/
      6          1.1    jruoho 
      7      1.1.1.2    jruoho /*
      8  1.1.1.4.2.2     skrll  * Copyright (C) 2000 - 2016, Intel Corp.
      9          1.1    jruoho  * All rights reserved.
     10          1.1    jruoho  *
     11      1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12      1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13      1.1.1.2    jruoho  * are met:
     14      1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15      1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16      1.1.1.2    jruoho  *    without modification.
     17      1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18      1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19      1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20      1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21      1.1.1.2    jruoho  *    binary redistribution.
     22      1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23      1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24      1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25      1.1.1.2    jruoho  *
     26      1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27      1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28      1.1.1.2    jruoho  * Software Foundation.
     29      1.1.1.2    jruoho  *
     30      1.1.1.2    jruoho  * NO WARRANTY
     31      1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32      1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33      1.1.1.2    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34      1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35      1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36      1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37      1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38      1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39      1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40      1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41      1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42      1.1.1.2    jruoho  */
     43          1.1    jruoho 
     44          1.1    jruoho #include "acpi.h"
     45          1.1    jruoho #include "accommon.h"
     46          1.1    jruoho #include "acnamesp.h"
     47          1.1    jruoho 
     48          1.1    jruoho 
     49          1.1    jruoho #define _COMPONENT          ACPI_UTILITIES
     50          1.1    jruoho         ACPI_MODULE_NAME    ("utobject")
     51          1.1    jruoho 
     52          1.1    jruoho /* Local prototypes */
     53          1.1    jruoho 
     54          1.1    jruoho static ACPI_STATUS
     55          1.1    jruoho AcpiUtGetSimpleObjectSize (
     56          1.1    jruoho     ACPI_OPERAND_OBJECT     *Obj,
     57          1.1    jruoho     ACPI_SIZE               *ObjLength);
     58          1.1    jruoho 
     59          1.1    jruoho static ACPI_STATUS
     60          1.1    jruoho AcpiUtGetPackageObjectSize (
     61          1.1    jruoho     ACPI_OPERAND_OBJECT     *Obj,
     62          1.1    jruoho     ACPI_SIZE               *ObjLength);
     63          1.1    jruoho 
     64          1.1    jruoho static ACPI_STATUS
     65          1.1    jruoho AcpiUtGetElementLength (
     66          1.1    jruoho     UINT8                   ObjectType,
     67          1.1    jruoho     ACPI_OPERAND_OBJECT     *SourceObject,
     68          1.1    jruoho     ACPI_GENERIC_STATE      *State,
     69          1.1    jruoho     void                    *Context);
     70          1.1    jruoho 
     71          1.1    jruoho 
     72          1.1    jruoho /*******************************************************************************
     73          1.1    jruoho  *
     74          1.1    jruoho  * FUNCTION:    AcpiUtCreateInternalObjectDbg
     75          1.1    jruoho  *
     76          1.1    jruoho  * PARAMETERS:  ModuleName          - Source file name of caller
     77          1.1    jruoho  *              LineNumber          - Line number of caller
     78          1.1    jruoho  *              ComponentId         - Component type of caller
     79          1.1    jruoho  *              Type                - ACPI Type of the new object
     80          1.1    jruoho  *
     81          1.1    jruoho  * RETURN:      A new internal object, null on failure
     82          1.1    jruoho  *
     83          1.1    jruoho  * DESCRIPTION: Create and initialize a new internal object.
     84          1.1    jruoho  *
     85          1.1    jruoho  * NOTE:        We always allocate the worst-case object descriptor because
     86          1.1    jruoho  *              these objects are cached, and we want them to be
     87      1.1.1.3  christos  *              one-size-satisifies-any-request. This in itself may not be
     88          1.1    jruoho  *              the most memory efficient, but the efficiency of the object
     89          1.1    jruoho  *              cache should more than make up for this!
     90          1.1    jruoho  *
     91          1.1    jruoho  ******************************************************************************/
     92          1.1    jruoho 
     93          1.1    jruoho ACPI_OPERAND_OBJECT  *
     94          1.1    jruoho AcpiUtCreateInternalObjectDbg (
     95          1.1    jruoho     const char              *ModuleName,
     96          1.1    jruoho     UINT32                  LineNumber,
     97          1.1    jruoho     UINT32                  ComponentId,
     98          1.1    jruoho     ACPI_OBJECT_TYPE        Type)
     99          1.1    jruoho {
    100          1.1    jruoho     ACPI_OPERAND_OBJECT     *Object;
    101          1.1    jruoho     ACPI_OPERAND_OBJECT     *SecondObject;
    102          1.1    jruoho 
    103          1.1    jruoho 
    104          1.1    jruoho     ACPI_FUNCTION_TRACE_STR (UtCreateInternalObjectDbg,
    105  1.1.1.4.2.2     skrll         __UNCONST(AcpiUtGetTypeName (Type)));
    106          1.1    jruoho 
    107          1.1    jruoho 
    108          1.1    jruoho     /* Allocate the raw object descriptor */
    109          1.1    jruoho 
    110  1.1.1.4.2.2     skrll     Object = AcpiUtAllocateObjectDescDbg (
    111  1.1.1.4.2.2     skrll         ModuleName, LineNumber, ComponentId);
    112          1.1    jruoho     if (!Object)
    113          1.1    jruoho     {
    114          1.1    jruoho         return_PTR (NULL);
    115          1.1    jruoho     }
    116          1.1    jruoho 
    117          1.1    jruoho     switch (Type)
    118          1.1    jruoho     {
    119          1.1    jruoho     case ACPI_TYPE_REGION:
    120          1.1    jruoho     case ACPI_TYPE_BUFFER_FIELD:
    121          1.1    jruoho     case ACPI_TYPE_LOCAL_BANK_FIELD:
    122          1.1    jruoho 
    123          1.1    jruoho         /* These types require a secondary object */
    124          1.1    jruoho 
    125  1.1.1.4.2.2     skrll         SecondObject = AcpiUtAllocateObjectDescDbg (
    126  1.1.1.4.2.2     skrll             ModuleName, LineNumber, ComponentId);
    127          1.1    jruoho         if (!SecondObject)
    128          1.1    jruoho         {
    129          1.1    jruoho             AcpiUtDeleteObjectDesc (Object);
    130          1.1    jruoho             return_PTR (NULL);
    131          1.1    jruoho         }
    132          1.1    jruoho 
    133          1.1    jruoho         SecondObject->Common.Type = ACPI_TYPE_LOCAL_EXTRA;
    134          1.1    jruoho         SecondObject->Common.ReferenceCount = 1;
    135          1.1    jruoho 
    136          1.1    jruoho         /* Link the second object to the first */
    137          1.1    jruoho 
    138          1.1    jruoho         Object->Common.NextObject = SecondObject;
    139          1.1    jruoho         break;
    140          1.1    jruoho 
    141          1.1    jruoho     default:
    142      1.1.1.3  christos 
    143          1.1    jruoho         /* All others have no secondary object */
    144          1.1    jruoho         break;
    145          1.1    jruoho     }
    146          1.1    jruoho 
    147          1.1    jruoho     /* Save the object type in the object descriptor */
    148          1.1    jruoho 
    149          1.1    jruoho     Object->Common.Type = (UINT8) Type;
    150          1.1    jruoho 
    151          1.1    jruoho     /* Init the reference count */
    152          1.1    jruoho 
    153          1.1    jruoho     Object->Common.ReferenceCount = 1;
    154          1.1    jruoho 
    155          1.1    jruoho     /* Any per-type initialization should go here */
    156          1.1    jruoho 
    157          1.1    jruoho     return_PTR (Object);
    158          1.1    jruoho }
    159          1.1    jruoho 
    160          1.1    jruoho 
    161          1.1    jruoho /*******************************************************************************
    162          1.1    jruoho  *
    163          1.1    jruoho  * FUNCTION:    AcpiUtCreatePackageObject
    164          1.1    jruoho  *
    165          1.1    jruoho  * PARAMETERS:  Count               - Number of package elements
    166          1.1    jruoho  *
    167          1.1    jruoho  * RETURN:      Pointer to a new Package object, null on failure
    168          1.1    jruoho  *
    169          1.1    jruoho  * DESCRIPTION: Create a fully initialized package object
    170          1.1    jruoho  *
    171          1.1    jruoho  ******************************************************************************/
    172          1.1    jruoho 
    173          1.1    jruoho ACPI_OPERAND_OBJECT *
    174          1.1    jruoho AcpiUtCreatePackageObject (
    175          1.1    jruoho     UINT32                  Count)
    176          1.1    jruoho {
    177          1.1    jruoho     ACPI_OPERAND_OBJECT     *PackageDesc;
    178          1.1    jruoho     ACPI_OPERAND_OBJECT     **PackageElements;
    179          1.1    jruoho 
    180          1.1    jruoho 
    181          1.1    jruoho     ACPI_FUNCTION_TRACE_U32 (UtCreatePackageObject, Count);
    182          1.1    jruoho 
    183          1.1    jruoho 
    184          1.1    jruoho     /* Create a new Package object */
    185          1.1    jruoho 
    186          1.1    jruoho     PackageDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
    187          1.1    jruoho     if (!PackageDesc)
    188          1.1    jruoho     {
    189          1.1    jruoho         return_PTR (NULL);
    190          1.1    jruoho     }
    191          1.1    jruoho 
    192          1.1    jruoho     /*
    193          1.1    jruoho      * Create the element array. Count+1 allows the array to be null
    194          1.1    jruoho      * terminated.
    195          1.1    jruoho      */
    196          1.1    jruoho     PackageElements = ACPI_ALLOCATE_ZEROED (
    197  1.1.1.4.2.2     skrll         ((ACPI_SIZE) Count + 1) * sizeof (void *));
    198          1.1    jruoho     if (!PackageElements)
    199          1.1    jruoho     {
    200          1.1    jruoho         ACPI_FREE (PackageDesc);
    201          1.1    jruoho         return_PTR (NULL);
    202          1.1    jruoho     }
    203          1.1    jruoho 
    204          1.1    jruoho     PackageDesc->Package.Count = Count;
    205          1.1    jruoho     PackageDesc->Package.Elements = PackageElements;
    206          1.1    jruoho     return_PTR (PackageDesc);
    207          1.1    jruoho }
    208          1.1    jruoho 
    209          1.1    jruoho 
    210          1.1    jruoho /*******************************************************************************
    211          1.1    jruoho  *
    212          1.1    jruoho  * FUNCTION:    AcpiUtCreateIntegerObject
    213          1.1    jruoho  *
    214          1.1    jruoho  * PARAMETERS:  InitialValue        - Initial value for the integer
    215          1.1    jruoho  *
    216          1.1    jruoho  * RETURN:      Pointer to a new Integer object, null on failure
    217          1.1    jruoho  *
    218          1.1    jruoho  * DESCRIPTION: Create an initialized integer object
    219          1.1    jruoho  *
    220          1.1    jruoho  ******************************************************************************/
    221          1.1    jruoho 
    222          1.1    jruoho ACPI_OPERAND_OBJECT *
    223          1.1    jruoho AcpiUtCreateIntegerObject (
    224          1.1    jruoho     UINT64                  InitialValue)
    225          1.1    jruoho {
    226          1.1    jruoho     ACPI_OPERAND_OBJECT     *IntegerDesc;
    227          1.1    jruoho 
    228          1.1    jruoho 
    229          1.1    jruoho     ACPI_FUNCTION_TRACE (UtCreateIntegerObject);
    230          1.1    jruoho 
    231          1.1    jruoho 
    232          1.1    jruoho     /* Create and initialize a new integer object */
    233          1.1    jruoho 
    234          1.1    jruoho     IntegerDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
    235          1.1    jruoho     if (!IntegerDesc)
    236          1.1    jruoho     {
    237          1.1    jruoho         return_PTR (NULL);
    238          1.1    jruoho     }
    239          1.1    jruoho 
    240          1.1    jruoho     IntegerDesc->Integer.Value = InitialValue;
    241          1.1    jruoho     return_PTR (IntegerDesc);
    242          1.1    jruoho }
    243          1.1    jruoho 
    244          1.1    jruoho 
    245          1.1    jruoho /*******************************************************************************
    246          1.1    jruoho  *
    247          1.1    jruoho  * FUNCTION:    AcpiUtCreateBufferObject
    248          1.1    jruoho  *
    249          1.1    jruoho  * PARAMETERS:  BufferSize             - Size of buffer to be created
    250          1.1    jruoho  *
    251          1.1    jruoho  * RETURN:      Pointer to a new Buffer object, null on failure
    252          1.1    jruoho  *
    253          1.1    jruoho  * DESCRIPTION: Create a fully initialized buffer object
    254          1.1    jruoho  *
    255          1.1    jruoho  ******************************************************************************/
    256          1.1    jruoho 
    257          1.1    jruoho ACPI_OPERAND_OBJECT *
    258          1.1    jruoho AcpiUtCreateBufferObject (
    259          1.1    jruoho     ACPI_SIZE               BufferSize)
    260          1.1    jruoho {
    261          1.1    jruoho     ACPI_OPERAND_OBJECT     *BufferDesc;
    262          1.1    jruoho     UINT8                   *Buffer = NULL;
    263          1.1    jruoho 
    264          1.1    jruoho 
    265          1.1    jruoho     ACPI_FUNCTION_TRACE_U32 (UtCreateBufferObject, BufferSize);
    266          1.1    jruoho 
    267          1.1    jruoho 
    268          1.1    jruoho     /* Create a new Buffer object */
    269          1.1    jruoho 
    270          1.1    jruoho     BufferDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
    271          1.1    jruoho     if (!BufferDesc)
    272          1.1    jruoho     {
    273          1.1    jruoho         return_PTR (NULL);
    274          1.1    jruoho     }
    275          1.1    jruoho 
    276          1.1    jruoho     /* Create an actual buffer only if size > 0 */
    277          1.1    jruoho 
    278          1.1    jruoho     if (BufferSize > 0)
    279          1.1    jruoho     {
    280          1.1    jruoho         /* Allocate the actual buffer */
    281          1.1    jruoho 
    282          1.1    jruoho         Buffer = ACPI_ALLOCATE_ZEROED (BufferSize);
    283          1.1    jruoho         if (!Buffer)
    284          1.1    jruoho         {
    285          1.1    jruoho             ACPI_ERROR ((AE_INFO, "Could not allocate size %u",
    286          1.1    jruoho                 (UINT32) BufferSize));
    287  1.1.1.4.2.2     skrll 
    288          1.1    jruoho             AcpiUtRemoveReference (BufferDesc);
    289          1.1    jruoho             return_PTR (NULL);
    290          1.1    jruoho         }
    291          1.1    jruoho     }
    292          1.1    jruoho 
    293          1.1    jruoho     /* Complete buffer object initialization */
    294          1.1    jruoho 
    295          1.1    jruoho     BufferDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
    296          1.1    jruoho     BufferDesc->Buffer.Pointer = Buffer;
    297          1.1    jruoho     BufferDesc->Buffer.Length = (UINT32) BufferSize;
    298          1.1    jruoho 
    299          1.1    jruoho     /* Return the new buffer descriptor */
    300          1.1    jruoho 
    301          1.1    jruoho     return_PTR (BufferDesc);
    302          1.1    jruoho }
    303          1.1    jruoho 
    304          1.1    jruoho 
    305          1.1    jruoho /*******************************************************************************
    306          1.1    jruoho  *
    307          1.1    jruoho  * FUNCTION:    AcpiUtCreateStringObject
    308          1.1    jruoho  *
    309          1.1    jruoho  * PARAMETERS:  StringSize          - Size of string to be created. Does not
    310          1.1    jruoho  *                                    include NULL terminator, this is added
    311          1.1    jruoho  *                                    automatically.
    312          1.1    jruoho  *
    313          1.1    jruoho  * RETURN:      Pointer to a new String object
    314          1.1    jruoho  *
    315          1.1    jruoho  * DESCRIPTION: Create a fully initialized string object
    316          1.1    jruoho  *
    317          1.1    jruoho  ******************************************************************************/
    318          1.1    jruoho 
    319          1.1    jruoho ACPI_OPERAND_OBJECT *
    320          1.1    jruoho AcpiUtCreateStringObject (
    321          1.1    jruoho     ACPI_SIZE               StringSize)
    322          1.1    jruoho {
    323          1.1    jruoho     ACPI_OPERAND_OBJECT     *StringDesc;
    324          1.1    jruoho     char                    *String;
    325          1.1    jruoho 
    326          1.1    jruoho 
    327          1.1    jruoho     ACPI_FUNCTION_TRACE_U32 (UtCreateStringObject, StringSize);
    328          1.1    jruoho 
    329          1.1    jruoho 
    330          1.1    jruoho     /* Create a new String object */
    331          1.1    jruoho 
    332          1.1    jruoho     StringDesc = AcpiUtCreateInternalObject (ACPI_TYPE_STRING);
    333          1.1    jruoho     if (!StringDesc)
    334          1.1    jruoho     {
    335          1.1    jruoho         return_PTR (NULL);
    336          1.1    jruoho     }
    337          1.1    jruoho 
    338          1.1    jruoho     /*
    339          1.1    jruoho      * Allocate the actual string buffer -- (Size + 1) for NULL terminator.
    340          1.1    jruoho      * NOTE: Zero-length strings are NULL terminated
    341          1.1    jruoho      */
    342          1.1    jruoho     String = ACPI_ALLOCATE_ZEROED (StringSize + 1);
    343          1.1    jruoho     if (!String)
    344          1.1    jruoho     {
    345          1.1    jruoho         ACPI_ERROR ((AE_INFO, "Could not allocate size %u",
    346          1.1    jruoho             (UINT32) StringSize));
    347  1.1.1.4.2.2     skrll 
    348          1.1    jruoho         AcpiUtRemoveReference (StringDesc);
    349          1.1    jruoho         return_PTR (NULL);
    350          1.1    jruoho     }
    351          1.1    jruoho 
    352          1.1    jruoho     /* Complete string object initialization */
    353          1.1    jruoho 
    354          1.1    jruoho     StringDesc->String.Pointer = String;
    355          1.1    jruoho     StringDesc->String.Length = (UINT32) StringSize;
    356          1.1    jruoho 
    357          1.1    jruoho     /* Return the new string descriptor */
    358          1.1    jruoho 
    359          1.1    jruoho     return_PTR (StringDesc);
    360          1.1    jruoho }
    361          1.1    jruoho 
    362          1.1    jruoho 
    363          1.1    jruoho /*******************************************************************************
    364          1.1    jruoho  *
    365          1.1    jruoho  * FUNCTION:    AcpiUtValidInternalObject
    366          1.1    jruoho  *
    367          1.1    jruoho  * PARAMETERS:  Object              - Object to be validated
    368          1.1    jruoho  *
    369          1.1    jruoho  * RETURN:      TRUE if object is valid, FALSE otherwise
    370          1.1    jruoho  *
    371      1.1.1.3  christos  * DESCRIPTION: Validate a pointer to be of type ACPI_OPERAND_OBJECT
    372          1.1    jruoho  *
    373          1.1    jruoho  ******************************************************************************/
    374          1.1    jruoho 
    375          1.1    jruoho BOOLEAN
    376          1.1    jruoho AcpiUtValidInternalObject (
    377          1.1    jruoho     void                    *Object)
    378          1.1    jruoho {
    379          1.1    jruoho 
    380          1.1    jruoho     ACPI_FUNCTION_NAME (UtValidInternalObject);
    381          1.1    jruoho 
    382          1.1    jruoho 
    383          1.1    jruoho     /* Check for a null pointer */
    384          1.1    jruoho 
    385          1.1    jruoho     if (!Object)
    386          1.1    jruoho     {
    387          1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "**** Null Object Ptr\n"));
    388          1.1    jruoho         return (FALSE);
    389          1.1    jruoho     }
    390          1.1    jruoho 
    391          1.1    jruoho     /* Check the descriptor type field */
    392          1.1    jruoho 
    393          1.1    jruoho     switch (ACPI_GET_DESCRIPTOR_TYPE (Object))
    394          1.1    jruoho     {
    395          1.1    jruoho     case ACPI_DESC_TYPE_OPERAND:
    396          1.1    jruoho 
    397      1.1.1.3  christos         /* The object appears to be a valid ACPI_OPERAND_OBJECT */
    398          1.1    jruoho 
    399          1.1    jruoho         return (TRUE);
    400          1.1    jruoho 
    401          1.1    jruoho     default:
    402      1.1.1.3  christos 
    403          1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
    404  1.1.1.4.2.2     skrll             "%p is not an ACPI operand obj [%s]\n",
    405  1.1.1.4.2.2     skrll             Object, AcpiUtGetDescriptorName (Object)));
    406          1.1    jruoho         break;
    407          1.1    jruoho     }
    408          1.1    jruoho 
    409          1.1    jruoho     return (FALSE);
    410          1.1    jruoho }
    411          1.1    jruoho 
    412          1.1    jruoho 
    413          1.1    jruoho /*******************************************************************************
    414          1.1    jruoho  *
    415          1.1    jruoho  * FUNCTION:    AcpiUtAllocateObjectDescDbg
    416          1.1    jruoho  *
    417          1.1    jruoho  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
    418          1.1    jruoho  *              LineNumber          - Caller's line number (for error output)
    419          1.1    jruoho  *              ComponentId         - Caller's component ID (for error output)
    420          1.1    jruoho  *
    421      1.1.1.3  christos  * RETURN:      Pointer to newly allocated object descriptor. Null on error
    422          1.1    jruoho  *
    423      1.1.1.3  christos  * DESCRIPTION: Allocate a new object descriptor. Gracefully handle
    424          1.1    jruoho  *              error conditions.
    425          1.1    jruoho  *
    426          1.1    jruoho  ******************************************************************************/
    427          1.1    jruoho 
    428          1.1    jruoho void *
    429          1.1    jruoho AcpiUtAllocateObjectDescDbg (
    430          1.1    jruoho     const char              *ModuleName,
    431          1.1    jruoho     UINT32                  LineNumber,
    432          1.1    jruoho     UINT32                  ComponentId)
    433          1.1    jruoho {
    434          1.1    jruoho     ACPI_OPERAND_OBJECT     *Object;
    435          1.1    jruoho 
    436          1.1    jruoho 
    437          1.1    jruoho     ACPI_FUNCTION_TRACE (UtAllocateObjectDescDbg);
    438          1.1    jruoho 
    439          1.1    jruoho 
    440          1.1    jruoho     Object = AcpiOsAcquireObject (AcpiGbl_OperandCache);
    441          1.1    jruoho     if (!Object)
    442          1.1    jruoho     {
    443          1.1    jruoho         ACPI_ERROR ((ModuleName, LineNumber,
    444          1.1    jruoho             "Could not allocate an object descriptor"));
    445          1.1    jruoho 
    446          1.1    jruoho         return_PTR (NULL);
    447          1.1    jruoho     }
    448          1.1    jruoho 
    449          1.1    jruoho     /* Mark the descriptor type */
    450          1.1    jruoho 
    451          1.1    jruoho     ACPI_SET_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_OPERAND);
    452          1.1    jruoho 
    453          1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p Size %X\n",
    454  1.1.1.4.2.2     skrll         Object, (UINT32) sizeof (ACPI_OPERAND_OBJECT)));
    455          1.1    jruoho 
    456          1.1    jruoho     return_PTR (Object);
    457          1.1    jruoho }
    458          1.1    jruoho 
    459          1.1    jruoho 
    460          1.1    jruoho /*******************************************************************************
    461          1.1    jruoho  *
    462          1.1    jruoho  * FUNCTION:    AcpiUtDeleteObjectDesc
    463          1.1    jruoho  *
    464          1.1    jruoho  * PARAMETERS:  Object          - An Acpi internal object to be deleted
    465          1.1    jruoho  *
    466          1.1    jruoho  * RETURN:      None.
    467          1.1    jruoho  *
    468          1.1    jruoho  * DESCRIPTION: Free an ACPI object descriptor or add it to the object cache
    469          1.1    jruoho  *
    470          1.1    jruoho  ******************************************************************************/
    471          1.1    jruoho 
    472          1.1    jruoho void
    473          1.1    jruoho AcpiUtDeleteObjectDesc (
    474          1.1    jruoho     ACPI_OPERAND_OBJECT     *Object)
    475          1.1    jruoho {
    476          1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (UtDeleteObjectDesc, Object);
    477          1.1    jruoho 
    478          1.1    jruoho 
    479      1.1.1.3  christos     /* Object must be of type ACPI_OPERAND_OBJECT */
    480          1.1    jruoho 
    481          1.1    jruoho     if (ACPI_GET_DESCRIPTOR_TYPE (Object) != ACPI_DESC_TYPE_OPERAND)
    482          1.1    jruoho     {
    483          1.1    jruoho         ACPI_ERROR ((AE_INFO,
    484          1.1    jruoho             "%p is not an ACPI Operand object [%s]", Object,
    485          1.1    jruoho             AcpiUtGetDescriptorName (Object)));
    486          1.1    jruoho         return_VOID;
    487          1.1    jruoho     }
    488          1.1    jruoho 
    489          1.1    jruoho     (void) AcpiOsReleaseObject (AcpiGbl_OperandCache, Object);
    490          1.1    jruoho     return_VOID;
    491          1.1    jruoho }
    492          1.1    jruoho 
    493          1.1    jruoho 
    494          1.1    jruoho /*******************************************************************************
    495          1.1    jruoho  *
    496          1.1    jruoho  * FUNCTION:    AcpiUtGetSimpleObjectSize
    497          1.1    jruoho  *
    498          1.1    jruoho  * PARAMETERS:  InternalObject     - An ACPI operand object
    499          1.1    jruoho  *              ObjLength          - Where the length is returned
    500          1.1    jruoho  *
    501          1.1    jruoho  * RETURN:      Status
    502          1.1    jruoho  *
    503          1.1    jruoho  * DESCRIPTION: This function is called to determine the space required to
    504          1.1    jruoho  *              contain a simple object for return to an external user.
    505          1.1    jruoho  *
    506          1.1    jruoho  *              The length includes the object structure plus any additional
    507          1.1    jruoho  *              needed space.
    508          1.1    jruoho  *
    509          1.1    jruoho  ******************************************************************************/
    510          1.1    jruoho 
    511          1.1    jruoho static ACPI_STATUS
    512          1.1    jruoho AcpiUtGetSimpleObjectSize (
    513          1.1    jruoho     ACPI_OPERAND_OBJECT     *InternalObject,
    514          1.1    jruoho     ACPI_SIZE               *ObjLength)
    515          1.1    jruoho {
    516          1.1    jruoho     ACPI_SIZE               Length;
    517          1.1    jruoho     ACPI_SIZE               Size;
    518          1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    519          1.1    jruoho 
    520          1.1    jruoho 
    521          1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (UtGetSimpleObjectSize, InternalObject);
    522          1.1    jruoho 
    523          1.1    jruoho 
    524          1.1    jruoho     /* Start with the length of the (external) Acpi object */
    525          1.1    jruoho 
    526          1.1    jruoho     Length = sizeof (ACPI_OBJECT);
    527          1.1    jruoho 
    528          1.1    jruoho     /* A NULL object is allowed, can be a legal uninitialized package element */
    529          1.1    jruoho 
    530          1.1    jruoho     if (!InternalObject)
    531          1.1    jruoho     {
    532          1.1    jruoho         /*
    533          1.1    jruoho          * Object is NULL, just return the length of ACPI_OBJECT
    534          1.1    jruoho          * (A NULL ACPI_OBJECT is an object of all zeroes.)
    535          1.1    jruoho          */
    536          1.1    jruoho         *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length);
    537          1.1    jruoho         return_ACPI_STATUS (AE_OK);
    538          1.1    jruoho     }
    539          1.1    jruoho 
    540          1.1    jruoho     /* A Namespace Node should never appear here */
    541          1.1    jruoho 
    542          1.1    jruoho     if (ACPI_GET_DESCRIPTOR_TYPE (InternalObject) == ACPI_DESC_TYPE_NAMED)
    543          1.1    jruoho     {
    544          1.1    jruoho         /* A namespace node should never get here */
    545          1.1    jruoho 
    546          1.1    jruoho         return_ACPI_STATUS (AE_AML_INTERNAL);
    547          1.1    jruoho     }
    548          1.1    jruoho 
    549          1.1    jruoho     /*
    550          1.1    jruoho      * The final length depends on the object type
    551          1.1    jruoho      * Strings and Buffers are packed right up against the parent object and
    552          1.1    jruoho      * must be accessed bytewise or there may be alignment problems on
    553          1.1    jruoho      * certain processors
    554          1.1    jruoho      */
    555          1.1    jruoho     switch (InternalObject->Common.Type)
    556          1.1    jruoho     {
    557          1.1    jruoho     case ACPI_TYPE_STRING:
    558          1.1    jruoho 
    559          1.1    jruoho         Length += (ACPI_SIZE) InternalObject->String.Length + 1;
    560          1.1    jruoho         break;
    561          1.1    jruoho 
    562          1.1    jruoho     case ACPI_TYPE_BUFFER:
    563          1.1    jruoho 
    564          1.1    jruoho         Length += (ACPI_SIZE) InternalObject->Buffer.Length;
    565          1.1    jruoho         break;
    566          1.1    jruoho 
    567          1.1    jruoho     case ACPI_TYPE_INTEGER:
    568          1.1    jruoho     case ACPI_TYPE_PROCESSOR:
    569          1.1    jruoho     case ACPI_TYPE_POWER:
    570          1.1    jruoho 
    571          1.1    jruoho         /* No extra data for these types */
    572          1.1    jruoho 
    573          1.1    jruoho         break;
    574          1.1    jruoho 
    575          1.1    jruoho     case ACPI_TYPE_LOCAL_REFERENCE:
    576          1.1    jruoho 
    577          1.1    jruoho         switch (InternalObject->Reference.Class)
    578          1.1    jruoho         {
    579          1.1    jruoho         case ACPI_REFCLASS_NAME:
    580          1.1    jruoho             /*
    581          1.1    jruoho              * Get the actual length of the full pathname to this object.
    582          1.1    jruoho              * The reference will be converted to the pathname to the object
    583          1.1    jruoho              */
    584          1.1    jruoho             Size = AcpiNsGetPathnameLength (InternalObject->Reference.Node);
    585          1.1    jruoho             if (!Size)
    586          1.1    jruoho             {
    587          1.1    jruoho                 return_ACPI_STATUS (AE_BAD_PARAMETER);
    588          1.1    jruoho             }
    589          1.1    jruoho 
    590          1.1    jruoho             Length += ACPI_ROUND_UP_TO_NATIVE_WORD (Size);
    591          1.1    jruoho             break;
    592          1.1    jruoho 
    593          1.1    jruoho         default:
    594          1.1    jruoho             /*
    595          1.1    jruoho              * No other reference opcodes are supported.
    596          1.1    jruoho              * Notably, Locals and Args are not supported, but this may be
    597          1.1    jruoho              * required eventually.
    598          1.1    jruoho              */
    599          1.1    jruoho             ACPI_ERROR ((AE_INFO, "Cannot convert to external object - "
    600          1.1    jruoho                 "unsupported Reference Class [%s] 0x%X in object %p",
    601          1.1    jruoho                 AcpiUtGetReferenceName (InternalObject),
    602          1.1    jruoho                 InternalObject->Reference.Class, InternalObject));
    603          1.1    jruoho             Status = AE_TYPE;
    604          1.1    jruoho             break;
    605          1.1    jruoho         }
    606          1.1    jruoho         break;
    607          1.1    jruoho 
    608          1.1    jruoho     default:
    609          1.1    jruoho 
    610          1.1    jruoho         ACPI_ERROR ((AE_INFO, "Cannot convert to external object - "
    611          1.1    jruoho             "unsupported type [%s] 0x%X in object %p",
    612          1.1    jruoho             AcpiUtGetObjectTypeName (InternalObject),
    613          1.1    jruoho             InternalObject->Common.Type, InternalObject));
    614          1.1    jruoho         Status = AE_TYPE;
    615          1.1    jruoho         break;
    616          1.1    jruoho     }
    617          1.1    jruoho 
    618          1.1    jruoho     /*
    619          1.1    jruoho      * Account for the space required by the object rounded up to the next
    620      1.1.1.3  christos      * multiple of the machine word size. This keeps each object aligned
    621          1.1    jruoho      * on a machine word boundary. (preventing alignment faults on some
    622          1.1    jruoho      * machines.)
    623          1.1    jruoho      */
    624          1.1    jruoho     *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length);
    625          1.1    jruoho     return_ACPI_STATUS (Status);
    626          1.1    jruoho }
    627          1.1    jruoho 
    628          1.1    jruoho 
    629          1.1    jruoho /*******************************************************************************
    630          1.1    jruoho  *
    631          1.1    jruoho  * FUNCTION:    AcpiUtGetElementLength
    632          1.1    jruoho  *
    633          1.1    jruoho  * PARAMETERS:  ACPI_PKG_CALLBACK
    634          1.1    jruoho  *
    635          1.1    jruoho  * RETURN:      Status
    636          1.1    jruoho  *
    637          1.1    jruoho  * DESCRIPTION: Get the length of one package element.
    638          1.1    jruoho  *
    639          1.1    jruoho  ******************************************************************************/
    640          1.1    jruoho 
    641          1.1    jruoho static ACPI_STATUS
    642          1.1    jruoho AcpiUtGetElementLength (
    643          1.1    jruoho     UINT8                   ObjectType,
    644          1.1    jruoho     ACPI_OPERAND_OBJECT     *SourceObject,
    645          1.1    jruoho     ACPI_GENERIC_STATE      *State,
    646          1.1    jruoho     void                    *Context)
    647          1.1    jruoho {
    648          1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    649          1.1    jruoho     ACPI_PKG_INFO           *Info = (ACPI_PKG_INFO *) Context;
    650          1.1    jruoho     ACPI_SIZE               ObjectSpace;
    651          1.1    jruoho 
    652          1.1    jruoho 
    653          1.1    jruoho     switch (ObjectType)
    654          1.1    jruoho     {
    655          1.1    jruoho     case ACPI_COPY_TYPE_SIMPLE:
    656          1.1    jruoho         /*
    657          1.1    jruoho          * Simple object - just get the size (Null object/entry is handled
    658          1.1    jruoho          * here also) and sum it into the running package length
    659          1.1    jruoho          */
    660          1.1    jruoho         Status = AcpiUtGetSimpleObjectSize (SourceObject, &ObjectSpace);
    661          1.1    jruoho         if (ACPI_FAILURE (Status))
    662          1.1    jruoho         {
    663          1.1    jruoho             return (Status);
    664          1.1    jruoho         }
    665          1.1    jruoho 
    666          1.1    jruoho         Info->Length += ObjectSpace;
    667          1.1    jruoho         break;
    668          1.1    jruoho 
    669          1.1    jruoho     case ACPI_COPY_TYPE_PACKAGE:
    670          1.1    jruoho 
    671          1.1    jruoho         /* Package object - nothing much to do here, let the walk handle it */
    672          1.1    jruoho 
    673          1.1    jruoho         Info->NumPackages++;
    674          1.1    jruoho         State->Pkg.ThisTargetObj = NULL;
    675          1.1    jruoho         break;
    676          1.1    jruoho 
    677          1.1    jruoho     default:
    678          1.1    jruoho 
    679          1.1    jruoho         /* No other types allowed */
    680          1.1    jruoho 
    681          1.1    jruoho         return (AE_BAD_PARAMETER);
    682          1.1    jruoho     }
    683          1.1    jruoho 
    684          1.1    jruoho     return (Status);
    685          1.1    jruoho }
    686          1.1    jruoho 
    687          1.1    jruoho 
    688          1.1    jruoho /*******************************************************************************
    689          1.1    jruoho  *
    690          1.1    jruoho  * FUNCTION:    AcpiUtGetPackageObjectSize
    691          1.1    jruoho  *
    692          1.1    jruoho  * PARAMETERS:  InternalObject      - An ACPI internal object
    693          1.1    jruoho  *              ObjLength           - Where the length is returned
    694          1.1    jruoho  *
    695          1.1    jruoho  * RETURN:      Status
    696          1.1    jruoho  *
    697          1.1    jruoho  * DESCRIPTION: This function is called to determine the space required to
    698          1.1    jruoho  *              contain a package object for return to an external user.
    699          1.1    jruoho  *
    700          1.1    jruoho  *              This is moderately complex since a package contains other
    701          1.1    jruoho  *              objects including packages.
    702          1.1    jruoho  *
    703          1.1    jruoho  ******************************************************************************/
    704          1.1    jruoho 
    705          1.1    jruoho static ACPI_STATUS
    706          1.1    jruoho AcpiUtGetPackageObjectSize (
    707          1.1    jruoho     ACPI_OPERAND_OBJECT     *InternalObject,
    708          1.1    jruoho     ACPI_SIZE               *ObjLength)
    709          1.1    jruoho {
    710          1.1    jruoho     ACPI_STATUS             Status;
    711          1.1    jruoho     ACPI_PKG_INFO           Info;
    712          1.1    jruoho 
    713          1.1    jruoho 
    714          1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (UtGetPackageObjectSize, InternalObject);
    715          1.1    jruoho 
    716          1.1    jruoho 
    717  1.1.1.4.2.2     skrll     Info.Length = 0;
    718          1.1    jruoho     Info.ObjectSpace = 0;
    719          1.1    jruoho     Info.NumPackages = 1;
    720          1.1    jruoho 
    721  1.1.1.4.2.2     skrll     Status = AcpiUtWalkPackageTree (
    722  1.1.1.4.2.2     skrll         InternalObject, NULL, AcpiUtGetElementLength, &Info);
    723          1.1    jruoho     if (ACPI_FAILURE (Status))
    724          1.1    jruoho     {
    725          1.1    jruoho         return_ACPI_STATUS (Status);
    726          1.1    jruoho     }
    727          1.1    jruoho 
    728          1.1    jruoho     /*
    729          1.1    jruoho      * We have handled all of the objects in all levels of the package.
    730          1.1    jruoho      * just add the length of the package objects themselves.
    731          1.1    jruoho      * Round up to the next machine word.
    732          1.1    jruoho      */
    733  1.1.1.4.2.2     skrll     Info.Length += ACPI_ROUND_UP_TO_NATIVE_WORD (
    734  1.1.1.4.2.2     skrll         sizeof (ACPI_OBJECT)) * (ACPI_SIZE) Info.NumPackages;
    735          1.1    jruoho 
    736          1.1    jruoho     /* Return the total package length */
    737          1.1    jruoho 
    738          1.1    jruoho     *ObjLength = Info.Length;
    739          1.1    jruoho     return_ACPI_STATUS (Status);
    740          1.1    jruoho }
    741          1.1    jruoho 
    742          1.1    jruoho 
    743          1.1    jruoho /*******************************************************************************
    744          1.1    jruoho  *
    745          1.1    jruoho  * FUNCTION:    AcpiUtGetObjectSize
    746          1.1    jruoho  *
    747          1.1    jruoho  * PARAMETERS:  InternalObject      - An ACPI internal object
    748          1.1    jruoho  *              ObjLength           - Where the length will be returned
    749          1.1    jruoho  *
    750          1.1    jruoho  * RETURN:      Status
    751          1.1    jruoho  *
    752          1.1    jruoho  * DESCRIPTION: This function is called to determine the space required to
    753          1.1    jruoho  *              contain an object for return to an API user.
    754          1.1    jruoho  *
    755          1.1    jruoho  ******************************************************************************/
    756          1.1    jruoho 
    757          1.1    jruoho ACPI_STATUS
    758          1.1    jruoho AcpiUtGetObjectSize (
    759          1.1    jruoho     ACPI_OPERAND_OBJECT     *InternalObject,
    760          1.1    jruoho     ACPI_SIZE               *ObjLength)
    761          1.1    jruoho {
    762          1.1    jruoho     ACPI_STATUS             Status;
    763          1.1    jruoho 
    764          1.1    jruoho 
    765          1.1    jruoho     ACPI_FUNCTION_ENTRY ();
    766          1.1    jruoho 
    767          1.1    jruoho 
    768  1.1.1.4.2.2     skrll     if ((ACPI_GET_DESCRIPTOR_TYPE (InternalObject) ==
    769  1.1.1.4.2.2     skrll             ACPI_DESC_TYPE_OPERAND) &&
    770          1.1    jruoho         (InternalObject->Common.Type == ACPI_TYPE_PACKAGE))
    771          1.1    jruoho     {
    772          1.1    jruoho         Status = AcpiUtGetPackageObjectSize (InternalObject, ObjLength);
    773          1.1    jruoho     }
    774          1.1    jruoho     else
    775          1.1    jruoho     {
    776          1.1    jruoho         Status = AcpiUtGetSimpleObjectSize (InternalObject, ObjLength);
    777          1.1    jruoho     }
    778          1.1    jruoho 
    779          1.1    jruoho     return (Status);
    780          1.1    jruoho }
    781