Home | History | Annotate | Line # | Download | only in utilities
utobject.c revision 1.1.1.4.2.1
      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.1     skrll  * Copyright (C) 2000 - 2015, 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    jruoho         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    jruoho     Object = AcpiUtAllocateObjectDescDbg (ModuleName, LineNumber, ComponentId);
    111          1.1    jruoho     if (!Object)
    112          1.1    jruoho     {
    113          1.1    jruoho         return_PTR (NULL);
    114          1.1    jruoho     }
    115          1.1    jruoho 
    116          1.1    jruoho     switch (Type)
    117          1.1    jruoho     {
    118          1.1    jruoho     case ACPI_TYPE_REGION:
    119          1.1    jruoho     case ACPI_TYPE_BUFFER_FIELD:
    120          1.1    jruoho     case ACPI_TYPE_LOCAL_BANK_FIELD:
    121          1.1    jruoho 
    122          1.1    jruoho         /* These types require a secondary object */
    123          1.1    jruoho 
    124          1.1    jruoho         SecondObject = AcpiUtAllocateObjectDescDbg (ModuleName,
    125          1.1    jruoho                             LineNumber, ComponentId);
    126          1.1    jruoho         if (!SecondObject)
    127          1.1    jruoho         {
    128          1.1    jruoho             AcpiUtDeleteObjectDesc (Object);
    129          1.1    jruoho             return_PTR (NULL);
    130          1.1    jruoho         }
    131          1.1    jruoho 
    132          1.1    jruoho         SecondObject->Common.Type = ACPI_TYPE_LOCAL_EXTRA;
    133          1.1    jruoho         SecondObject->Common.ReferenceCount = 1;
    134          1.1    jruoho 
    135          1.1    jruoho         /* Link the second object to the first */
    136          1.1    jruoho 
    137          1.1    jruoho         Object->Common.NextObject = SecondObject;
    138          1.1    jruoho         break;
    139          1.1    jruoho 
    140          1.1    jruoho     default:
    141      1.1.1.3  christos 
    142          1.1    jruoho         /* All others have no secondary object */
    143          1.1    jruoho         break;
    144          1.1    jruoho     }
    145          1.1    jruoho 
    146          1.1    jruoho     /* Save the object type in the object descriptor */
    147          1.1    jruoho 
    148          1.1    jruoho     Object->Common.Type = (UINT8) Type;
    149          1.1    jruoho 
    150          1.1    jruoho     /* Init the reference count */
    151          1.1    jruoho 
    152          1.1    jruoho     Object->Common.ReferenceCount = 1;
    153          1.1    jruoho 
    154          1.1    jruoho     /* Any per-type initialization should go here */
    155          1.1    jruoho 
    156          1.1    jruoho     return_PTR (Object);
    157          1.1    jruoho }
    158          1.1    jruoho 
    159          1.1    jruoho 
    160          1.1    jruoho /*******************************************************************************
    161          1.1    jruoho  *
    162          1.1    jruoho  * FUNCTION:    AcpiUtCreatePackageObject
    163          1.1    jruoho  *
    164          1.1    jruoho  * PARAMETERS:  Count               - Number of package elements
    165          1.1    jruoho  *
    166          1.1    jruoho  * RETURN:      Pointer to a new Package object, null on failure
    167          1.1    jruoho  *
    168          1.1    jruoho  * DESCRIPTION: Create a fully initialized package object
    169          1.1    jruoho  *
    170          1.1    jruoho  ******************************************************************************/
    171          1.1    jruoho 
    172          1.1    jruoho ACPI_OPERAND_OBJECT *
    173          1.1    jruoho AcpiUtCreatePackageObject (
    174          1.1    jruoho     UINT32                  Count)
    175          1.1    jruoho {
    176          1.1    jruoho     ACPI_OPERAND_OBJECT     *PackageDesc;
    177          1.1    jruoho     ACPI_OPERAND_OBJECT     **PackageElements;
    178          1.1    jruoho 
    179          1.1    jruoho 
    180          1.1    jruoho     ACPI_FUNCTION_TRACE_U32 (UtCreatePackageObject, Count);
    181          1.1    jruoho 
    182          1.1    jruoho 
    183          1.1    jruoho     /* Create a new Package object */
    184          1.1    jruoho 
    185          1.1    jruoho     PackageDesc = AcpiUtCreateInternalObject (ACPI_TYPE_PACKAGE);
    186          1.1    jruoho     if (!PackageDesc)
    187          1.1    jruoho     {
    188          1.1    jruoho         return_PTR (NULL);
    189          1.1    jruoho     }
    190          1.1    jruoho 
    191          1.1    jruoho     /*
    192          1.1    jruoho      * Create the element array. Count+1 allows the array to be null
    193          1.1    jruoho      * terminated.
    194          1.1    jruoho      */
    195          1.1    jruoho     PackageElements = ACPI_ALLOCATE_ZEROED (
    196          1.1    jruoho                         ((ACPI_SIZE) Count + 1) * sizeof (void *));
    197          1.1    jruoho     if (!PackageElements)
    198          1.1    jruoho     {
    199          1.1    jruoho         ACPI_FREE (PackageDesc);
    200          1.1    jruoho         return_PTR (NULL);
    201          1.1    jruoho     }
    202          1.1    jruoho 
    203          1.1    jruoho     PackageDesc->Package.Count = Count;
    204          1.1    jruoho     PackageDesc->Package.Elements = PackageElements;
    205          1.1    jruoho     return_PTR (PackageDesc);
    206          1.1    jruoho }
    207          1.1    jruoho 
    208          1.1    jruoho 
    209          1.1    jruoho /*******************************************************************************
    210          1.1    jruoho  *
    211          1.1    jruoho  * FUNCTION:    AcpiUtCreateIntegerObject
    212          1.1    jruoho  *
    213          1.1    jruoho  * PARAMETERS:  InitialValue        - Initial value for the integer
    214          1.1    jruoho  *
    215          1.1    jruoho  * RETURN:      Pointer to a new Integer object, null on failure
    216          1.1    jruoho  *
    217          1.1    jruoho  * DESCRIPTION: Create an initialized integer object
    218          1.1    jruoho  *
    219          1.1    jruoho  ******************************************************************************/
    220          1.1    jruoho 
    221          1.1    jruoho ACPI_OPERAND_OBJECT *
    222          1.1    jruoho AcpiUtCreateIntegerObject (
    223          1.1    jruoho     UINT64                  InitialValue)
    224          1.1    jruoho {
    225          1.1    jruoho     ACPI_OPERAND_OBJECT     *IntegerDesc;
    226          1.1    jruoho 
    227          1.1    jruoho 
    228          1.1    jruoho     ACPI_FUNCTION_TRACE (UtCreateIntegerObject);
    229          1.1    jruoho 
    230          1.1    jruoho 
    231          1.1    jruoho     /* Create and initialize a new integer object */
    232          1.1    jruoho 
    233          1.1    jruoho     IntegerDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
    234          1.1    jruoho     if (!IntegerDesc)
    235          1.1    jruoho     {
    236          1.1    jruoho         return_PTR (NULL);
    237          1.1    jruoho     }
    238          1.1    jruoho 
    239          1.1    jruoho     IntegerDesc->Integer.Value = InitialValue;
    240          1.1    jruoho     return_PTR (IntegerDesc);
    241          1.1    jruoho }
    242          1.1    jruoho 
    243          1.1    jruoho 
    244          1.1    jruoho /*******************************************************************************
    245          1.1    jruoho  *
    246          1.1    jruoho  * FUNCTION:    AcpiUtCreateBufferObject
    247          1.1    jruoho  *
    248          1.1    jruoho  * PARAMETERS:  BufferSize             - Size of buffer to be created
    249          1.1    jruoho  *
    250          1.1    jruoho  * RETURN:      Pointer to a new Buffer object, null on failure
    251          1.1    jruoho  *
    252          1.1    jruoho  * DESCRIPTION: Create a fully initialized buffer object
    253          1.1    jruoho  *
    254          1.1    jruoho  ******************************************************************************/
    255          1.1    jruoho 
    256          1.1    jruoho ACPI_OPERAND_OBJECT *
    257          1.1    jruoho AcpiUtCreateBufferObject (
    258          1.1    jruoho     ACPI_SIZE               BufferSize)
    259          1.1    jruoho {
    260          1.1    jruoho     ACPI_OPERAND_OBJECT     *BufferDesc;
    261          1.1    jruoho     UINT8                   *Buffer = NULL;
    262          1.1    jruoho 
    263          1.1    jruoho 
    264          1.1    jruoho     ACPI_FUNCTION_TRACE_U32 (UtCreateBufferObject, BufferSize);
    265          1.1    jruoho 
    266          1.1    jruoho 
    267          1.1    jruoho     /* Create a new Buffer object */
    268          1.1    jruoho 
    269          1.1    jruoho     BufferDesc = AcpiUtCreateInternalObject (ACPI_TYPE_BUFFER);
    270          1.1    jruoho     if (!BufferDesc)
    271          1.1    jruoho     {
    272          1.1    jruoho         return_PTR (NULL);
    273          1.1    jruoho     }
    274          1.1    jruoho 
    275          1.1    jruoho     /* Create an actual buffer only if size > 0 */
    276          1.1    jruoho 
    277          1.1    jruoho     if (BufferSize > 0)
    278          1.1    jruoho     {
    279          1.1    jruoho         /* Allocate the actual buffer */
    280          1.1    jruoho 
    281          1.1    jruoho         Buffer = ACPI_ALLOCATE_ZEROED (BufferSize);
    282          1.1    jruoho         if (!Buffer)
    283          1.1    jruoho         {
    284          1.1    jruoho             ACPI_ERROR ((AE_INFO, "Could not allocate size %u",
    285          1.1    jruoho                 (UINT32) BufferSize));
    286          1.1    jruoho             AcpiUtRemoveReference (BufferDesc);
    287          1.1    jruoho             return_PTR (NULL);
    288          1.1    jruoho         }
    289          1.1    jruoho     }
    290          1.1    jruoho 
    291          1.1    jruoho     /* Complete buffer object initialization */
    292          1.1    jruoho 
    293          1.1    jruoho     BufferDesc->Buffer.Flags |= AOPOBJ_DATA_VALID;
    294          1.1    jruoho     BufferDesc->Buffer.Pointer = Buffer;
    295          1.1    jruoho     BufferDesc->Buffer.Length = (UINT32) BufferSize;
    296          1.1    jruoho 
    297          1.1    jruoho     /* Return the new buffer descriptor */
    298          1.1    jruoho 
    299          1.1    jruoho     return_PTR (BufferDesc);
    300          1.1    jruoho }
    301          1.1    jruoho 
    302          1.1    jruoho 
    303          1.1    jruoho /*******************************************************************************
    304          1.1    jruoho  *
    305          1.1    jruoho  * FUNCTION:    AcpiUtCreateStringObject
    306          1.1    jruoho  *
    307          1.1    jruoho  * PARAMETERS:  StringSize          - Size of string to be created. Does not
    308          1.1    jruoho  *                                    include NULL terminator, this is added
    309          1.1    jruoho  *                                    automatically.
    310          1.1    jruoho  *
    311          1.1    jruoho  * RETURN:      Pointer to a new String object
    312          1.1    jruoho  *
    313          1.1    jruoho  * DESCRIPTION: Create a fully initialized string object
    314          1.1    jruoho  *
    315          1.1    jruoho  ******************************************************************************/
    316          1.1    jruoho 
    317          1.1    jruoho ACPI_OPERAND_OBJECT *
    318          1.1    jruoho AcpiUtCreateStringObject (
    319          1.1    jruoho     ACPI_SIZE               StringSize)
    320          1.1    jruoho {
    321          1.1    jruoho     ACPI_OPERAND_OBJECT     *StringDesc;
    322          1.1    jruoho     char                    *String;
    323          1.1    jruoho 
    324          1.1    jruoho 
    325          1.1    jruoho     ACPI_FUNCTION_TRACE_U32 (UtCreateStringObject, StringSize);
    326          1.1    jruoho 
    327          1.1    jruoho 
    328          1.1    jruoho     /* Create a new String object */
    329          1.1    jruoho 
    330          1.1    jruoho     StringDesc = AcpiUtCreateInternalObject (ACPI_TYPE_STRING);
    331          1.1    jruoho     if (!StringDesc)
    332          1.1    jruoho     {
    333          1.1    jruoho         return_PTR (NULL);
    334          1.1    jruoho     }
    335          1.1    jruoho 
    336          1.1    jruoho     /*
    337          1.1    jruoho      * Allocate the actual string buffer -- (Size + 1) for NULL terminator.
    338          1.1    jruoho      * NOTE: Zero-length strings are NULL terminated
    339          1.1    jruoho      */
    340          1.1    jruoho     String = ACPI_ALLOCATE_ZEROED (StringSize + 1);
    341          1.1    jruoho     if (!String)
    342          1.1    jruoho     {
    343          1.1    jruoho         ACPI_ERROR ((AE_INFO, "Could not allocate size %u",
    344          1.1    jruoho             (UINT32) StringSize));
    345          1.1    jruoho         AcpiUtRemoveReference (StringDesc);
    346          1.1    jruoho         return_PTR (NULL);
    347          1.1    jruoho     }
    348          1.1    jruoho 
    349          1.1    jruoho     /* Complete string object initialization */
    350          1.1    jruoho 
    351          1.1    jruoho     StringDesc->String.Pointer = String;
    352          1.1    jruoho     StringDesc->String.Length = (UINT32) StringSize;
    353          1.1    jruoho 
    354          1.1    jruoho     /* Return the new string descriptor */
    355          1.1    jruoho 
    356          1.1    jruoho     return_PTR (StringDesc);
    357          1.1    jruoho }
    358          1.1    jruoho 
    359          1.1    jruoho 
    360          1.1    jruoho /*******************************************************************************
    361          1.1    jruoho  *
    362          1.1    jruoho  * FUNCTION:    AcpiUtValidInternalObject
    363          1.1    jruoho  *
    364          1.1    jruoho  * PARAMETERS:  Object              - Object to be validated
    365          1.1    jruoho  *
    366          1.1    jruoho  * RETURN:      TRUE if object is valid, FALSE otherwise
    367          1.1    jruoho  *
    368      1.1.1.3  christos  * DESCRIPTION: Validate a pointer to be of type ACPI_OPERAND_OBJECT
    369          1.1    jruoho  *
    370          1.1    jruoho  ******************************************************************************/
    371          1.1    jruoho 
    372          1.1    jruoho BOOLEAN
    373          1.1    jruoho AcpiUtValidInternalObject (
    374          1.1    jruoho     void                    *Object)
    375          1.1    jruoho {
    376          1.1    jruoho 
    377          1.1    jruoho     ACPI_FUNCTION_NAME (UtValidInternalObject);
    378          1.1    jruoho 
    379          1.1    jruoho 
    380          1.1    jruoho     /* Check for a null pointer */
    381          1.1    jruoho 
    382          1.1    jruoho     if (!Object)
    383          1.1    jruoho     {
    384          1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "**** Null Object Ptr\n"));
    385          1.1    jruoho         return (FALSE);
    386          1.1    jruoho     }
    387          1.1    jruoho 
    388          1.1    jruoho     /* Check the descriptor type field */
    389          1.1    jruoho 
    390          1.1    jruoho     switch (ACPI_GET_DESCRIPTOR_TYPE (Object))
    391          1.1    jruoho     {
    392          1.1    jruoho     case ACPI_DESC_TYPE_OPERAND:
    393          1.1    jruoho 
    394      1.1.1.3  christos         /* The object appears to be a valid ACPI_OPERAND_OBJECT */
    395          1.1    jruoho 
    396          1.1    jruoho         return (TRUE);
    397          1.1    jruoho 
    398          1.1    jruoho     default:
    399      1.1.1.3  christos 
    400          1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
    401      1.1.1.4  christos                 "%p is not an ACPI operand obj [%s]\n",
    402          1.1    jruoho                 Object, AcpiUtGetDescriptorName (Object)));
    403          1.1    jruoho         break;
    404          1.1    jruoho     }
    405          1.1    jruoho 
    406          1.1    jruoho     return (FALSE);
    407          1.1    jruoho }
    408          1.1    jruoho 
    409          1.1    jruoho 
    410          1.1    jruoho /*******************************************************************************
    411          1.1    jruoho  *
    412          1.1    jruoho  * FUNCTION:    AcpiUtAllocateObjectDescDbg
    413          1.1    jruoho  *
    414          1.1    jruoho  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
    415          1.1    jruoho  *              LineNumber          - Caller's line number (for error output)
    416          1.1    jruoho  *              ComponentId         - Caller's component ID (for error output)
    417          1.1    jruoho  *
    418      1.1.1.3  christos  * RETURN:      Pointer to newly allocated object descriptor. Null on error
    419          1.1    jruoho  *
    420      1.1.1.3  christos  * DESCRIPTION: Allocate a new object descriptor. Gracefully handle
    421          1.1    jruoho  *              error conditions.
    422          1.1    jruoho  *
    423          1.1    jruoho  ******************************************************************************/
    424          1.1    jruoho 
    425          1.1    jruoho void *
    426          1.1    jruoho AcpiUtAllocateObjectDescDbg (
    427          1.1    jruoho     const char              *ModuleName,
    428          1.1    jruoho     UINT32                  LineNumber,
    429          1.1    jruoho     UINT32                  ComponentId)
    430          1.1    jruoho {
    431          1.1    jruoho     ACPI_OPERAND_OBJECT     *Object;
    432          1.1    jruoho 
    433          1.1    jruoho 
    434          1.1    jruoho     ACPI_FUNCTION_TRACE (UtAllocateObjectDescDbg);
    435          1.1    jruoho 
    436          1.1    jruoho 
    437          1.1    jruoho     Object = AcpiOsAcquireObject (AcpiGbl_OperandCache);
    438          1.1    jruoho     if (!Object)
    439          1.1    jruoho     {
    440          1.1    jruoho         ACPI_ERROR ((ModuleName, LineNumber,
    441          1.1    jruoho             "Could not allocate an object descriptor"));
    442          1.1    jruoho 
    443          1.1    jruoho         return_PTR (NULL);
    444          1.1    jruoho     }
    445          1.1    jruoho 
    446          1.1    jruoho     /* Mark the descriptor type */
    447          1.1    jruoho 
    448          1.1    jruoho     ACPI_SET_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_OPERAND);
    449          1.1    jruoho 
    450          1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "%p Size %X\n",
    451          1.1    jruoho             Object, (UINT32) sizeof (ACPI_OPERAND_OBJECT)));
    452          1.1    jruoho 
    453          1.1    jruoho     return_PTR (Object);
    454          1.1    jruoho }
    455          1.1    jruoho 
    456          1.1    jruoho 
    457          1.1    jruoho /*******************************************************************************
    458          1.1    jruoho  *
    459          1.1    jruoho  * FUNCTION:    AcpiUtDeleteObjectDesc
    460          1.1    jruoho  *
    461          1.1    jruoho  * PARAMETERS:  Object          - An Acpi internal object to be deleted
    462          1.1    jruoho  *
    463          1.1    jruoho  * RETURN:      None.
    464          1.1    jruoho  *
    465          1.1    jruoho  * DESCRIPTION: Free an ACPI object descriptor or add it to the object cache
    466          1.1    jruoho  *
    467          1.1    jruoho  ******************************************************************************/
    468          1.1    jruoho 
    469          1.1    jruoho void
    470          1.1    jruoho AcpiUtDeleteObjectDesc (
    471          1.1    jruoho     ACPI_OPERAND_OBJECT     *Object)
    472          1.1    jruoho {
    473          1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (UtDeleteObjectDesc, Object);
    474          1.1    jruoho 
    475          1.1    jruoho 
    476      1.1.1.3  christos     /* Object must be of type ACPI_OPERAND_OBJECT */
    477          1.1    jruoho 
    478          1.1    jruoho     if (ACPI_GET_DESCRIPTOR_TYPE (Object) != ACPI_DESC_TYPE_OPERAND)
    479          1.1    jruoho     {
    480          1.1    jruoho         ACPI_ERROR ((AE_INFO,
    481          1.1    jruoho             "%p is not an ACPI Operand object [%s]", Object,
    482          1.1    jruoho             AcpiUtGetDescriptorName (Object)));
    483          1.1    jruoho         return_VOID;
    484          1.1    jruoho     }
    485          1.1    jruoho 
    486          1.1    jruoho     (void) AcpiOsReleaseObject (AcpiGbl_OperandCache, Object);
    487          1.1    jruoho     return_VOID;
    488          1.1    jruoho }
    489          1.1    jruoho 
    490          1.1    jruoho 
    491          1.1    jruoho /*******************************************************************************
    492          1.1    jruoho  *
    493          1.1    jruoho  * FUNCTION:    AcpiUtGetSimpleObjectSize
    494          1.1    jruoho  *
    495          1.1    jruoho  * PARAMETERS:  InternalObject     - An ACPI operand object
    496          1.1    jruoho  *              ObjLength          - Where the length is returned
    497          1.1    jruoho  *
    498          1.1    jruoho  * RETURN:      Status
    499          1.1    jruoho  *
    500          1.1    jruoho  * DESCRIPTION: This function is called to determine the space required to
    501          1.1    jruoho  *              contain a simple object for return to an external user.
    502          1.1    jruoho  *
    503          1.1    jruoho  *              The length includes the object structure plus any additional
    504          1.1    jruoho  *              needed space.
    505          1.1    jruoho  *
    506          1.1    jruoho  ******************************************************************************/
    507          1.1    jruoho 
    508          1.1    jruoho static ACPI_STATUS
    509          1.1    jruoho AcpiUtGetSimpleObjectSize (
    510          1.1    jruoho     ACPI_OPERAND_OBJECT     *InternalObject,
    511          1.1    jruoho     ACPI_SIZE               *ObjLength)
    512          1.1    jruoho {
    513          1.1    jruoho     ACPI_SIZE               Length;
    514          1.1    jruoho     ACPI_SIZE               Size;
    515          1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    516          1.1    jruoho 
    517          1.1    jruoho 
    518          1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (UtGetSimpleObjectSize, InternalObject);
    519          1.1    jruoho 
    520          1.1    jruoho 
    521          1.1    jruoho     /* Start with the length of the (external) Acpi object */
    522          1.1    jruoho 
    523          1.1    jruoho     Length = sizeof (ACPI_OBJECT);
    524          1.1    jruoho 
    525          1.1    jruoho     /* A NULL object is allowed, can be a legal uninitialized package element */
    526          1.1    jruoho 
    527          1.1    jruoho     if (!InternalObject)
    528          1.1    jruoho     {
    529          1.1    jruoho         /*
    530          1.1    jruoho          * Object is NULL, just return the length of ACPI_OBJECT
    531          1.1    jruoho          * (A NULL ACPI_OBJECT is an object of all zeroes.)
    532          1.1    jruoho          */
    533          1.1    jruoho         *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length);
    534          1.1    jruoho         return_ACPI_STATUS (AE_OK);
    535          1.1    jruoho     }
    536          1.1    jruoho 
    537          1.1    jruoho     /* A Namespace Node should never appear here */
    538          1.1    jruoho 
    539          1.1    jruoho     if (ACPI_GET_DESCRIPTOR_TYPE (InternalObject) == ACPI_DESC_TYPE_NAMED)
    540          1.1    jruoho     {
    541          1.1    jruoho         /* A namespace node should never get here */
    542          1.1    jruoho 
    543          1.1    jruoho         return_ACPI_STATUS (AE_AML_INTERNAL);
    544          1.1    jruoho     }
    545          1.1    jruoho 
    546          1.1    jruoho     /*
    547          1.1    jruoho      * The final length depends on the object type
    548          1.1    jruoho      * Strings and Buffers are packed right up against the parent object and
    549          1.1    jruoho      * must be accessed bytewise or there may be alignment problems on
    550          1.1    jruoho      * certain processors
    551          1.1    jruoho      */
    552          1.1    jruoho     switch (InternalObject->Common.Type)
    553          1.1    jruoho     {
    554          1.1    jruoho     case ACPI_TYPE_STRING:
    555          1.1    jruoho 
    556          1.1    jruoho         Length += (ACPI_SIZE) InternalObject->String.Length + 1;
    557          1.1    jruoho         break;
    558          1.1    jruoho 
    559          1.1    jruoho     case ACPI_TYPE_BUFFER:
    560          1.1    jruoho 
    561          1.1    jruoho         Length += (ACPI_SIZE) InternalObject->Buffer.Length;
    562          1.1    jruoho         break;
    563          1.1    jruoho 
    564          1.1    jruoho     case ACPI_TYPE_INTEGER:
    565          1.1    jruoho     case ACPI_TYPE_PROCESSOR:
    566          1.1    jruoho     case ACPI_TYPE_POWER:
    567          1.1    jruoho 
    568          1.1    jruoho         /* No extra data for these types */
    569          1.1    jruoho 
    570          1.1    jruoho         break;
    571          1.1    jruoho 
    572          1.1    jruoho     case ACPI_TYPE_LOCAL_REFERENCE:
    573          1.1    jruoho 
    574          1.1    jruoho         switch (InternalObject->Reference.Class)
    575          1.1    jruoho         {
    576          1.1    jruoho         case ACPI_REFCLASS_NAME:
    577          1.1    jruoho             /*
    578          1.1    jruoho              * Get the actual length of the full pathname to this object.
    579          1.1    jruoho              * The reference will be converted to the pathname to the object
    580          1.1    jruoho              */
    581          1.1    jruoho             Size = AcpiNsGetPathnameLength (InternalObject->Reference.Node);
    582          1.1    jruoho             if (!Size)
    583          1.1    jruoho             {
    584          1.1    jruoho                 return_ACPI_STATUS (AE_BAD_PARAMETER);
    585          1.1    jruoho             }
    586          1.1    jruoho 
    587          1.1    jruoho             Length += ACPI_ROUND_UP_TO_NATIVE_WORD (Size);
    588          1.1    jruoho             break;
    589          1.1    jruoho 
    590          1.1    jruoho         default:
    591          1.1    jruoho             /*
    592          1.1    jruoho              * No other reference opcodes are supported.
    593          1.1    jruoho              * Notably, Locals and Args are not supported, but this may be
    594          1.1    jruoho              * required eventually.
    595          1.1    jruoho              */
    596          1.1    jruoho             ACPI_ERROR ((AE_INFO, "Cannot convert to external object - "
    597          1.1    jruoho                 "unsupported Reference Class [%s] 0x%X in object %p",
    598          1.1    jruoho                 AcpiUtGetReferenceName (InternalObject),
    599          1.1    jruoho                 InternalObject->Reference.Class, InternalObject));
    600          1.1    jruoho             Status = AE_TYPE;
    601          1.1    jruoho             break;
    602          1.1    jruoho         }
    603          1.1    jruoho         break;
    604          1.1    jruoho 
    605          1.1    jruoho     default:
    606          1.1    jruoho 
    607          1.1    jruoho         ACPI_ERROR ((AE_INFO, "Cannot convert to external object - "
    608          1.1    jruoho             "unsupported type [%s] 0x%X in object %p",
    609          1.1    jruoho             AcpiUtGetObjectTypeName (InternalObject),
    610          1.1    jruoho             InternalObject->Common.Type, InternalObject));
    611          1.1    jruoho         Status = AE_TYPE;
    612          1.1    jruoho         break;
    613          1.1    jruoho     }
    614          1.1    jruoho 
    615          1.1    jruoho     /*
    616          1.1    jruoho      * Account for the space required by the object rounded up to the next
    617      1.1.1.3  christos      * multiple of the machine word size. This keeps each object aligned
    618          1.1    jruoho      * on a machine word boundary. (preventing alignment faults on some
    619          1.1    jruoho      * machines.)
    620          1.1    jruoho      */
    621          1.1    jruoho     *ObjLength = ACPI_ROUND_UP_TO_NATIVE_WORD (Length);
    622          1.1    jruoho     return_ACPI_STATUS (Status);
    623          1.1    jruoho }
    624          1.1    jruoho 
    625          1.1    jruoho 
    626          1.1    jruoho /*******************************************************************************
    627          1.1    jruoho  *
    628          1.1    jruoho  * FUNCTION:    AcpiUtGetElementLength
    629          1.1    jruoho  *
    630          1.1    jruoho  * PARAMETERS:  ACPI_PKG_CALLBACK
    631          1.1    jruoho  *
    632          1.1    jruoho  * RETURN:      Status
    633          1.1    jruoho  *
    634          1.1    jruoho  * DESCRIPTION: Get the length of one package element.
    635          1.1    jruoho  *
    636          1.1    jruoho  ******************************************************************************/
    637          1.1    jruoho 
    638          1.1    jruoho static ACPI_STATUS
    639          1.1    jruoho AcpiUtGetElementLength (
    640          1.1    jruoho     UINT8                   ObjectType,
    641          1.1    jruoho     ACPI_OPERAND_OBJECT     *SourceObject,
    642          1.1    jruoho     ACPI_GENERIC_STATE      *State,
    643          1.1    jruoho     void                    *Context)
    644          1.1    jruoho {
    645          1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    646          1.1    jruoho     ACPI_PKG_INFO           *Info = (ACPI_PKG_INFO *) Context;
    647          1.1    jruoho     ACPI_SIZE               ObjectSpace;
    648          1.1    jruoho 
    649          1.1    jruoho 
    650          1.1    jruoho     switch (ObjectType)
    651          1.1    jruoho     {
    652          1.1    jruoho     case ACPI_COPY_TYPE_SIMPLE:
    653          1.1    jruoho         /*
    654          1.1    jruoho          * Simple object - just get the size (Null object/entry is handled
    655          1.1    jruoho          * here also) and sum it into the running package length
    656          1.1    jruoho          */
    657          1.1    jruoho         Status = AcpiUtGetSimpleObjectSize (SourceObject, &ObjectSpace);
    658          1.1    jruoho         if (ACPI_FAILURE (Status))
    659          1.1    jruoho         {
    660          1.1    jruoho             return (Status);
    661          1.1    jruoho         }
    662          1.1    jruoho 
    663          1.1    jruoho         Info->Length += ObjectSpace;
    664          1.1    jruoho         break;
    665          1.1    jruoho 
    666          1.1    jruoho     case ACPI_COPY_TYPE_PACKAGE:
    667          1.1    jruoho 
    668          1.1    jruoho         /* Package object - nothing much to do here, let the walk handle it */
    669          1.1    jruoho 
    670          1.1    jruoho         Info->NumPackages++;
    671          1.1    jruoho         State->Pkg.ThisTargetObj = NULL;
    672          1.1    jruoho         break;
    673          1.1    jruoho 
    674          1.1    jruoho     default:
    675          1.1    jruoho 
    676          1.1    jruoho         /* No other types allowed */
    677          1.1    jruoho 
    678          1.1    jruoho         return (AE_BAD_PARAMETER);
    679          1.1    jruoho     }
    680          1.1    jruoho 
    681          1.1    jruoho     return (Status);
    682          1.1    jruoho }
    683          1.1    jruoho 
    684          1.1    jruoho 
    685          1.1    jruoho /*******************************************************************************
    686          1.1    jruoho  *
    687          1.1    jruoho  * FUNCTION:    AcpiUtGetPackageObjectSize
    688          1.1    jruoho  *
    689          1.1    jruoho  * PARAMETERS:  InternalObject      - An ACPI internal object
    690          1.1    jruoho  *              ObjLength           - Where the length is returned
    691          1.1    jruoho  *
    692          1.1    jruoho  * RETURN:      Status
    693          1.1    jruoho  *
    694          1.1    jruoho  * DESCRIPTION: This function is called to determine the space required to
    695          1.1    jruoho  *              contain a package object for return to an external user.
    696          1.1    jruoho  *
    697          1.1    jruoho  *              This is moderately complex since a package contains other
    698          1.1    jruoho  *              objects including packages.
    699          1.1    jruoho  *
    700          1.1    jruoho  ******************************************************************************/
    701          1.1    jruoho 
    702          1.1    jruoho static ACPI_STATUS
    703          1.1    jruoho AcpiUtGetPackageObjectSize (
    704          1.1    jruoho     ACPI_OPERAND_OBJECT     *InternalObject,
    705          1.1    jruoho     ACPI_SIZE               *ObjLength)
    706          1.1    jruoho {
    707          1.1    jruoho     ACPI_STATUS             Status;
    708          1.1    jruoho     ACPI_PKG_INFO           Info;
    709          1.1    jruoho 
    710          1.1    jruoho 
    711          1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (UtGetPackageObjectSize, InternalObject);
    712          1.1    jruoho 
    713          1.1    jruoho 
    714          1.1    jruoho     Info.Length      = 0;
    715          1.1    jruoho     Info.ObjectSpace = 0;
    716          1.1    jruoho     Info.NumPackages = 1;
    717          1.1    jruoho 
    718          1.1    jruoho     Status = AcpiUtWalkPackageTree (InternalObject, NULL,
    719      1.1.1.3  christos         AcpiUtGetElementLength, &Info);
    720          1.1    jruoho     if (ACPI_FAILURE (Status))
    721          1.1    jruoho     {
    722          1.1    jruoho         return_ACPI_STATUS (Status);
    723          1.1    jruoho     }
    724          1.1    jruoho 
    725          1.1    jruoho     /*
    726          1.1    jruoho      * We have handled all of the objects in all levels of the package.
    727          1.1    jruoho      * just add the length of the package objects themselves.
    728          1.1    jruoho      * Round up to the next machine word.
    729          1.1    jruoho      */
    730          1.1    jruoho     Info.Length += ACPI_ROUND_UP_TO_NATIVE_WORD (sizeof (ACPI_OBJECT)) *
    731          1.1    jruoho                     (ACPI_SIZE) Info.NumPackages;
    732          1.1    jruoho 
    733          1.1    jruoho     /* Return the total package length */
    734          1.1    jruoho 
    735          1.1    jruoho     *ObjLength = Info.Length;
    736          1.1    jruoho     return_ACPI_STATUS (Status);
    737          1.1    jruoho }
    738          1.1    jruoho 
    739          1.1    jruoho 
    740          1.1    jruoho /*******************************************************************************
    741          1.1    jruoho  *
    742          1.1    jruoho  * FUNCTION:    AcpiUtGetObjectSize
    743          1.1    jruoho  *
    744          1.1    jruoho  * PARAMETERS:  InternalObject      - An ACPI internal object
    745          1.1    jruoho  *              ObjLength           - Where the length will be returned
    746          1.1    jruoho  *
    747          1.1    jruoho  * RETURN:      Status
    748          1.1    jruoho  *
    749          1.1    jruoho  * DESCRIPTION: This function is called to determine the space required to
    750          1.1    jruoho  *              contain an object for return to an API user.
    751          1.1    jruoho  *
    752          1.1    jruoho  ******************************************************************************/
    753          1.1    jruoho 
    754          1.1    jruoho ACPI_STATUS
    755          1.1    jruoho AcpiUtGetObjectSize (
    756          1.1    jruoho     ACPI_OPERAND_OBJECT     *InternalObject,
    757          1.1    jruoho     ACPI_SIZE               *ObjLength)
    758          1.1    jruoho {
    759          1.1    jruoho     ACPI_STATUS             Status;
    760          1.1    jruoho 
    761          1.1    jruoho 
    762          1.1    jruoho     ACPI_FUNCTION_ENTRY ();
    763          1.1    jruoho 
    764          1.1    jruoho 
    765          1.1    jruoho     if ((ACPI_GET_DESCRIPTOR_TYPE (InternalObject) == ACPI_DESC_TYPE_OPERAND) &&
    766          1.1    jruoho         (InternalObject->Common.Type == ACPI_TYPE_PACKAGE))
    767          1.1    jruoho     {
    768          1.1    jruoho         Status = AcpiUtGetPackageObjectSize (InternalObject, ObjLength);
    769          1.1    jruoho     }
    770          1.1    jruoho     else
    771          1.1    jruoho     {
    772          1.1    jruoho         Status = AcpiUtGetSimpleObjectSize (InternalObject, ObjLength);
    773          1.1    jruoho     }
    774          1.1    jruoho 
    775          1.1    jruoho     return (Status);
    776          1.1    jruoho }
    777