Home | History | Annotate | Line # | Download | only in utilities
utdelete.c revision 1.1.1.3
      1      1.1    jruoho /*******************************************************************************
      2      1.1    jruoho  *
      3      1.1    jruoho  * Module Name: utdelete - object deletion and reference count utilities
      4      1.1    jruoho  *
      5      1.1    jruoho  ******************************************************************************/
      6      1.1    jruoho 
      7  1.1.1.2    jruoho /*
      8  1.1.1.3  christos  * Copyright (C) 2000 - 2013, 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 #define __UTDELETE_C__
     45      1.1    jruoho 
     46      1.1    jruoho #include "acpi.h"
     47      1.1    jruoho #include "accommon.h"
     48      1.1    jruoho #include "acinterp.h"
     49      1.1    jruoho #include "acnamesp.h"
     50      1.1    jruoho #include "acevents.h"
     51      1.1    jruoho 
     52      1.1    jruoho 
     53      1.1    jruoho #define _COMPONENT          ACPI_UTILITIES
     54      1.1    jruoho         ACPI_MODULE_NAME    ("utdelete")
     55      1.1    jruoho 
     56      1.1    jruoho /* Local prototypes */
     57      1.1    jruoho 
     58      1.1    jruoho static void
     59      1.1    jruoho AcpiUtDeleteInternalObj (
     60      1.1    jruoho     ACPI_OPERAND_OBJECT     *Object);
     61      1.1    jruoho 
     62      1.1    jruoho static void
     63      1.1    jruoho AcpiUtUpdateRefCount (
     64      1.1    jruoho     ACPI_OPERAND_OBJECT     *Object,
     65      1.1    jruoho     UINT32                  Action);
     66      1.1    jruoho 
     67      1.1    jruoho 
     68      1.1    jruoho /*******************************************************************************
     69      1.1    jruoho  *
     70      1.1    jruoho  * FUNCTION:    AcpiUtDeleteInternalObj
     71      1.1    jruoho  *
     72      1.1    jruoho  * PARAMETERS:  Object         - Object to be deleted
     73      1.1    jruoho  *
     74      1.1    jruoho  * RETURN:      None
     75      1.1    jruoho  *
     76      1.1    jruoho  * DESCRIPTION: Low level object deletion, after reference counts have been
     77      1.1    jruoho  *              updated (All reference counts, including sub-objects!)
     78      1.1    jruoho  *
     79      1.1    jruoho  ******************************************************************************/
     80      1.1    jruoho 
     81      1.1    jruoho static void
     82      1.1    jruoho AcpiUtDeleteInternalObj (
     83      1.1    jruoho     ACPI_OPERAND_OBJECT     *Object)
     84      1.1    jruoho {
     85      1.1    jruoho     void                    *ObjPointer = NULL;
     86      1.1    jruoho     ACPI_OPERAND_OBJECT     *HandlerDesc;
     87      1.1    jruoho     ACPI_OPERAND_OBJECT     *SecondDesc;
     88      1.1    jruoho     ACPI_OPERAND_OBJECT     *NextDesc;
     89      1.1    jruoho     ACPI_OPERAND_OBJECT     **LastObjPtr;
     90      1.1    jruoho 
     91      1.1    jruoho 
     92      1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (UtDeleteInternalObj, Object);
     93      1.1    jruoho 
     94      1.1    jruoho 
     95      1.1    jruoho     if (!Object)
     96      1.1    jruoho     {
     97      1.1    jruoho         return_VOID;
     98      1.1    jruoho     }
     99      1.1    jruoho 
    100      1.1    jruoho     /*
    101      1.1    jruoho      * Must delete or free any pointers within the object that are not
    102      1.1    jruoho      * actual ACPI objects (for example, a raw buffer pointer).
    103      1.1    jruoho      */
    104      1.1    jruoho     switch (Object->Common.Type)
    105      1.1    jruoho     {
    106      1.1    jruoho     case ACPI_TYPE_STRING:
    107      1.1    jruoho 
    108      1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "**** String %p, ptr %p\n",
    109      1.1    jruoho             Object, Object->String.Pointer));
    110      1.1    jruoho 
    111      1.1    jruoho         /* Free the actual string buffer */
    112      1.1    jruoho 
    113      1.1    jruoho         if (!(Object->Common.Flags & AOPOBJ_STATIC_POINTER))
    114      1.1    jruoho         {
    115      1.1    jruoho             /* But only if it is NOT a pointer into an ACPI table */
    116      1.1    jruoho 
    117      1.1    jruoho             ObjPointer = Object->String.Pointer;
    118      1.1    jruoho         }
    119      1.1    jruoho         break;
    120      1.1    jruoho 
    121      1.1    jruoho     case ACPI_TYPE_BUFFER:
    122      1.1    jruoho 
    123      1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "**** Buffer %p, ptr %p\n",
    124      1.1    jruoho             Object, Object->Buffer.Pointer));
    125      1.1    jruoho 
    126      1.1    jruoho         /* Free the actual buffer */
    127      1.1    jruoho 
    128      1.1    jruoho         if (!(Object->Common.Flags & AOPOBJ_STATIC_POINTER))
    129      1.1    jruoho         {
    130      1.1    jruoho             /* But only if it is NOT a pointer into an ACPI table */
    131      1.1    jruoho 
    132      1.1    jruoho             ObjPointer = Object->Buffer.Pointer;
    133      1.1    jruoho         }
    134      1.1    jruoho         break;
    135      1.1    jruoho 
    136      1.1    jruoho     case ACPI_TYPE_PACKAGE:
    137      1.1    jruoho 
    138      1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, " **** Package of count %X\n",
    139      1.1    jruoho             Object->Package.Count));
    140      1.1    jruoho 
    141      1.1    jruoho         /*
    142      1.1    jruoho          * Elements of the package are not handled here, they are deleted
    143      1.1    jruoho          * separately
    144      1.1    jruoho          */
    145      1.1    jruoho 
    146      1.1    jruoho         /* Free the (variable length) element pointer array */
    147      1.1    jruoho 
    148      1.1    jruoho         ObjPointer = Object->Package.Elements;
    149      1.1    jruoho         break;
    150      1.1    jruoho 
    151      1.1    jruoho     /*
    152      1.1    jruoho      * These objects have a possible list of notify handlers.
    153      1.1    jruoho      * Device object also may have a GPE block.
    154      1.1    jruoho      */
    155      1.1    jruoho     case ACPI_TYPE_DEVICE:
    156      1.1    jruoho 
    157      1.1    jruoho         if (Object->Device.GpeBlock)
    158      1.1    jruoho         {
    159      1.1    jruoho             (void) AcpiEvDeleteGpeBlock (Object->Device.GpeBlock);
    160      1.1    jruoho         }
    161      1.1    jruoho 
    162      1.1    jruoho         /*lint -fallthrough */
    163      1.1    jruoho 
    164      1.1    jruoho     case ACPI_TYPE_PROCESSOR:
    165      1.1    jruoho     case ACPI_TYPE_THERMAL:
    166      1.1    jruoho 
    167  1.1.1.3  christos         /* Walk the address handler list for this object */
    168      1.1    jruoho 
    169      1.1    jruoho         HandlerDesc = Object->CommonNotify.Handler;
    170      1.1    jruoho         while (HandlerDesc)
    171      1.1    jruoho         {
    172      1.1    jruoho             NextDesc = HandlerDesc->AddressSpace.Next;
    173      1.1    jruoho             AcpiUtRemoveReference (HandlerDesc);
    174      1.1    jruoho             HandlerDesc = NextDesc;
    175      1.1    jruoho         }
    176      1.1    jruoho         break;
    177      1.1    jruoho 
    178      1.1    jruoho     case ACPI_TYPE_MUTEX:
    179      1.1    jruoho 
    180      1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
    181      1.1    jruoho             "***** Mutex %p, OS Mutex %p\n",
    182      1.1    jruoho             Object, Object->Mutex.OsMutex));
    183      1.1    jruoho 
    184      1.1    jruoho         if (Object == AcpiGbl_GlobalLockMutex)
    185      1.1    jruoho         {
    186      1.1    jruoho             /* Global Lock has extra semaphore */
    187      1.1    jruoho 
    188      1.1    jruoho             (void) AcpiOsDeleteSemaphore (AcpiGbl_GlobalLockSemaphore);
    189      1.1    jruoho             AcpiGbl_GlobalLockSemaphore = NULL;
    190      1.1    jruoho 
    191      1.1    jruoho             AcpiOsDeleteMutex (Object->Mutex.OsMutex);
    192      1.1    jruoho             AcpiGbl_GlobalLockMutex = NULL;
    193      1.1    jruoho         }
    194      1.1    jruoho         else
    195      1.1    jruoho         {
    196      1.1    jruoho             AcpiExUnlinkMutex (Object);
    197      1.1    jruoho             AcpiOsDeleteMutex (Object->Mutex.OsMutex);
    198      1.1    jruoho         }
    199      1.1    jruoho         break;
    200      1.1    jruoho 
    201      1.1    jruoho     case ACPI_TYPE_EVENT:
    202      1.1    jruoho 
    203      1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
    204      1.1    jruoho             "***** Event %p, OS Semaphore %p\n",
    205      1.1    jruoho             Object, Object->Event.OsSemaphore));
    206      1.1    jruoho 
    207      1.1    jruoho         (void) AcpiOsDeleteSemaphore (Object->Event.OsSemaphore);
    208      1.1    jruoho         Object->Event.OsSemaphore = NULL;
    209      1.1    jruoho         break;
    210      1.1    jruoho 
    211      1.1    jruoho     case ACPI_TYPE_METHOD:
    212      1.1    jruoho 
    213      1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
    214      1.1    jruoho             "***** Method %p\n", Object));
    215      1.1    jruoho 
    216      1.1    jruoho         /* Delete the method mutex if it exists */
    217      1.1    jruoho 
    218      1.1    jruoho         if (Object->Method.Mutex)
    219      1.1    jruoho         {
    220      1.1    jruoho             AcpiOsDeleteMutex (Object->Method.Mutex->Mutex.OsMutex);
    221      1.1    jruoho             AcpiUtDeleteObjectDesc (Object->Method.Mutex);
    222      1.1    jruoho             Object->Method.Mutex = NULL;
    223      1.1    jruoho         }
    224      1.1    jruoho         break;
    225      1.1    jruoho 
    226      1.1    jruoho     case ACPI_TYPE_REGION:
    227      1.1    jruoho 
    228      1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
    229      1.1    jruoho             "***** Region %p\n", Object));
    230      1.1    jruoho 
    231  1.1.1.3  christos         /*
    232  1.1.1.3  christos          * Update AddressRange list. However, only permanent regions
    233  1.1.1.3  christos          * are installed in this list. (Not created within a method)
    234  1.1.1.3  christos          */
    235  1.1.1.3  christos         if (!(Object->Region.Node->Flags & ANOBJ_TEMPORARY))
    236  1.1.1.3  christos         {
    237  1.1.1.3  christos             AcpiUtRemoveAddressRange (Object->Region.SpaceId,
    238  1.1.1.3  christos                 Object->Region.Node);
    239  1.1.1.3  christos         }
    240  1.1.1.3  christos 
    241      1.1    jruoho         SecondDesc = AcpiNsGetSecondaryObject (Object);
    242      1.1    jruoho         if (SecondDesc)
    243      1.1    jruoho         {
    244      1.1    jruoho             /*
    245      1.1    jruoho              * Free the RegionContext if and only if the handler is one of the
    246      1.1    jruoho              * default handlers -- and therefore, we created the context object
    247      1.1    jruoho              * locally, it was not created by an external caller.
    248      1.1    jruoho              */
    249      1.1    jruoho             HandlerDesc = Object->Region.Handler;
    250      1.1    jruoho             if (HandlerDesc)
    251      1.1    jruoho             {
    252      1.1    jruoho                 NextDesc = HandlerDesc->AddressSpace.RegionList;
    253      1.1    jruoho                 LastObjPtr = &HandlerDesc->AddressSpace.RegionList;
    254      1.1    jruoho 
    255      1.1    jruoho                 /* Remove the region object from the handler's list */
    256      1.1    jruoho 
    257      1.1    jruoho                 while (NextDesc)
    258      1.1    jruoho                 {
    259      1.1    jruoho                     if (NextDesc == Object)
    260      1.1    jruoho                     {
    261      1.1    jruoho                         *LastObjPtr = NextDesc->Region.Next;
    262      1.1    jruoho                         break;
    263      1.1    jruoho                     }
    264      1.1    jruoho 
    265      1.1    jruoho                     /* Walk the linked list of handler */
    266      1.1    jruoho 
    267      1.1    jruoho                     LastObjPtr = &NextDesc->Region.Next;
    268      1.1    jruoho                     NextDesc = NextDesc->Region.Next;
    269      1.1    jruoho                 }
    270      1.1    jruoho 
    271      1.1    jruoho                 if (HandlerDesc->AddressSpace.HandlerFlags &
    272      1.1    jruoho                     ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)
    273      1.1    jruoho                 {
    274      1.1    jruoho                     /* Deactivate region and free region context */
    275      1.1    jruoho 
    276      1.1    jruoho                     if (HandlerDesc->AddressSpace.Setup)
    277      1.1    jruoho                     {
    278      1.1    jruoho                         (void) HandlerDesc->AddressSpace.Setup (Object,
    279      1.1    jruoho                             ACPI_REGION_DEACTIVATE,
    280      1.1    jruoho                             HandlerDesc->AddressSpace.Context,
    281      1.1    jruoho                             &SecondDesc->Extra.RegionContext);
    282      1.1    jruoho                     }
    283      1.1    jruoho                 }
    284      1.1    jruoho 
    285      1.1    jruoho                 AcpiUtRemoveReference (HandlerDesc);
    286      1.1    jruoho             }
    287      1.1    jruoho 
    288      1.1    jruoho             /* Now we can free the Extra object */
    289      1.1    jruoho 
    290      1.1    jruoho             AcpiUtDeleteObjectDesc (SecondDesc);
    291      1.1    jruoho         }
    292      1.1    jruoho         break;
    293      1.1    jruoho 
    294      1.1    jruoho     case ACPI_TYPE_BUFFER_FIELD:
    295      1.1    jruoho 
    296      1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
    297      1.1    jruoho             "***** Buffer Field %p\n", Object));
    298      1.1    jruoho 
    299      1.1    jruoho         SecondDesc = AcpiNsGetSecondaryObject (Object);
    300      1.1    jruoho         if (SecondDesc)
    301      1.1    jruoho         {
    302      1.1    jruoho             AcpiUtDeleteObjectDesc (SecondDesc);
    303      1.1    jruoho         }
    304      1.1    jruoho         break;
    305      1.1    jruoho 
    306      1.1    jruoho     case ACPI_TYPE_LOCAL_BANK_FIELD:
    307      1.1    jruoho 
    308      1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
    309      1.1    jruoho             "***** Bank Field %p\n", Object));
    310      1.1    jruoho 
    311      1.1    jruoho         SecondDesc = AcpiNsGetSecondaryObject (Object);
    312      1.1    jruoho         if (SecondDesc)
    313      1.1    jruoho         {
    314      1.1    jruoho             AcpiUtDeleteObjectDesc (SecondDesc);
    315      1.1    jruoho         }
    316      1.1    jruoho         break;
    317      1.1    jruoho 
    318      1.1    jruoho     default:
    319  1.1.1.3  christos 
    320      1.1    jruoho         break;
    321      1.1    jruoho     }
    322      1.1    jruoho 
    323      1.1    jruoho     /* Free any allocated memory (pointer within the object) found above */
    324      1.1    jruoho 
    325      1.1    jruoho     if (ObjPointer)
    326      1.1    jruoho     {
    327      1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Deleting Object Subptr %p\n",
    328      1.1    jruoho             ObjPointer));
    329      1.1    jruoho         ACPI_FREE (ObjPointer);
    330      1.1    jruoho     }
    331      1.1    jruoho 
    332      1.1    jruoho     /* Now the object can be safely deleted */
    333      1.1    jruoho 
    334      1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Deleting Object %p [%s]\n",
    335      1.1    jruoho         Object, AcpiUtGetObjectTypeName (Object)));
    336      1.1    jruoho 
    337      1.1    jruoho     AcpiUtDeleteObjectDesc (Object);
    338      1.1    jruoho     return_VOID;
    339      1.1    jruoho }
    340      1.1    jruoho 
    341      1.1    jruoho 
    342      1.1    jruoho /*******************************************************************************
    343      1.1    jruoho  *
    344      1.1    jruoho  * FUNCTION:    AcpiUtDeleteInternalObjectList
    345      1.1    jruoho  *
    346      1.1    jruoho  * PARAMETERS:  ObjList         - Pointer to the list to be deleted
    347      1.1    jruoho  *
    348      1.1    jruoho  * RETURN:      None
    349      1.1    jruoho  *
    350      1.1    jruoho  * DESCRIPTION: This function deletes an internal object list, including both
    351      1.1    jruoho  *              simple objects and package objects
    352      1.1    jruoho  *
    353      1.1    jruoho  ******************************************************************************/
    354      1.1    jruoho 
    355      1.1    jruoho void
    356      1.1    jruoho AcpiUtDeleteInternalObjectList (
    357      1.1    jruoho     ACPI_OPERAND_OBJECT     **ObjList)
    358      1.1    jruoho {
    359      1.1    jruoho     ACPI_OPERAND_OBJECT     **InternalObj;
    360      1.1    jruoho 
    361      1.1    jruoho 
    362  1.1.1.3  christos     ACPI_FUNCTION_ENTRY ();
    363      1.1    jruoho 
    364      1.1    jruoho 
    365      1.1    jruoho     /* Walk the null-terminated internal list */
    366      1.1    jruoho 
    367      1.1    jruoho     for (InternalObj = ObjList; *InternalObj; InternalObj++)
    368      1.1    jruoho     {
    369      1.1    jruoho         AcpiUtRemoveReference (*InternalObj);
    370      1.1    jruoho     }
    371      1.1    jruoho 
    372      1.1    jruoho     /* Free the combined parameter pointer list and object array */
    373      1.1    jruoho 
    374      1.1    jruoho     ACPI_FREE (ObjList);
    375  1.1.1.3  christos     return;
    376      1.1    jruoho }
    377      1.1    jruoho 
    378      1.1    jruoho 
    379      1.1    jruoho /*******************************************************************************
    380      1.1    jruoho  *
    381      1.1    jruoho  * FUNCTION:    AcpiUtUpdateRefCount
    382      1.1    jruoho  *
    383      1.1    jruoho  * PARAMETERS:  Object          - Object whose ref count is to be updated
    384  1.1.1.3  christos  *              Action          - What to do (REF_INCREMENT or REF_DECREMENT)
    385      1.1    jruoho  *
    386  1.1.1.3  christos  * RETURN:      None. Sets new reference count within the object
    387      1.1    jruoho  *
    388  1.1.1.3  christos  * DESCRIPTION: Modify the reference count for an internal acpi object
    389      1.1    jruoho  *
    390      1.1    jruoho  ******************************************************************************/
    391      1.1    jruoho 
    392      1.1    jruoho static void
    393      1.1    jruoho AcpiUtUpdateRefCount (
    394      1.1    jruoho     ACPI_OPERAND_OBJECT     *Object,
    395      1.1    jruoho     UINT32                  Action)
    396      1.1    jruoho {
    397  1.1.1.3  christos     UINT16                  OriginalCount;
    398  1.1.1.3  christos     UINT16                  NewCount = 0;
    399  1.1.1.3  christos     ACPI_CPU_FLAGS          LockFlags;
    400      1.1    jruoho 
    401      1.1    jruoho 
    402      1.1    jruoho     ACPI_FUNCTION_NAME (UtUpdateRefCount);
    403      1.1    jruoho 
    404      1.1    jruoho 
    405      1.1    jruoho     if (!Object)
    406      1.1    jruoho     {
    407      1.1    jruoho         return;
    408      1.1    jruoho     }
    409      1.1    jruoho 
    410      1.1    jruoho     /*
    411  1.1.1.3  christos      * Always get the reference count lock. Note: Interpreter and/or
    412  1.1.1.3  christos      * Namespace is not always locked when this function is called.
    413      1.1    jruoho      */
    414  1.1.1.3  christos     LockFlags = AcpiOsAcquireLock (AcpiGbl_ReferenceCountLock);
    415  1.1.1.3  christos     OriginalCount = Object->Common.ReferenceCount;
    416  1.1.1.3  christos 
    417  1.1.1.3  christos     /* Perform the reference count action (increment, decrement) */
    418  1.1.1.3  christos 
    419      1.1    jruoho     switch (Action)
    420      1.1    jruoho     {
    421      1.1    jruoho     case REF_INCREMENT:
    422      1.1    jruoho 
    423  1.1.1.3  christos         NewCount = OriginalCount + 1;
    424      1.1    jruoho         Object->Common.ReferenceCount = NewCount;
    425  1.1.1.3  christos         AcpiOsReleaseLock (AcpiGbl_ReferenceCountLock, LockFlags);
    426  1.1.1.3  christos 
    427  1.1.1.3  christos         /* The current reference count should never be zero here */
    428  1.1.1.3  christos 
    429  1.1.1.3  christos         if (!OriginalCount)
    430  1.1.1.3  christos         {
    431  1.1.1.3  christos             ACPI_WARNING ((AE_INFO,
    432  1.1.1.3  christos                 "Obj %p, Reference Count was zero before increment\n",
    433  1.1.1.3  christos                 Object));
    434  1.1.1.3  christos         }
    435      1.1    jruoho 
    436      1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
    437  1.1.1.3  christos             "Obj %p Type %.2X Refs %.2X [Incremented]\n",
    438  1.1.1.3  christos             Object, Object->Common.Type, NewCount));
    439      1.1    jruoho         break;
    440      1.1    jruoho 
    441      1.1    jruoho     case REF_DECREMENT:
    442      1.1    jruoho 
    443  1.1.1.3  christos         /* The current reference count must be non-zero */
    444      1.1    jruoho 
    445  1.1.1.3  christos         if (OriginalCount)
    446      1.1    jruoho         {
    447  1.1.1.3  christos             NewCount = OriginalCount - 1;
    448  1.1.1.3  christos             Object->Common.ReferenceCount = NewCount;
    449      1.1    jruoho         }
    450      1.1    jruoho 
    451  1.1.1.3  christos         AcpiOsReleaseLock (AcpiGbl_ReferenceCountLock, LockFlags);
    452  1.1.1.3  christos 
    453  1.1.1.3  christos         if (!OriginalCount)
    454      1.1    jruoho         {
    455  1.1.1.3  christos             ACPI_WARNING ((AE_INFO,
    456  1.1.1.3  christos                 "Obj %p, Reference Count is already zero, cannot decrement\n",
    457  1.1.1.3  christos                 Object));
    458      1.1    jruoho         }
    459      1.1    jruoho 
    460  1.1.1.3  christos         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
    461  1.1.1.3  christos             "Obj %p Type %.2X Refs %.2X [Decremented]\n",
    462  1.1.1.3  christos             Object, Object->Common.Type, NewCount));
    463  1.1.1.3  christos 
    464  1.1.1.3  christos         /* Actually delete the object on a reference count of zero */
    465  1.1.1.3  christos 
    466      1.1    jruoho         if (NewCount == 0)
    467      1.1    jruoho         {
    468      1.1    jruoho             AcpiUtDeleteInternalObj (Object);
    469      1.1    jruoho         }
    470      1.1    jruoho         break;
    471      1.1    jruoho 
    472      1.1    jruoho     default:
    473      1.1    jruoho 
    474  1.1.1.3  christos         AcpiOsReleaseLock (AcpiGbl_ReferenceCountLock, LockFlags);
    475  1.1.1.3  christos         ACPI_ERROR ((AE_INFO, "Unknown Reference Count action (0x%X)",
    476  1.1.1.3  christos             Action));
    477  1.1.1.3  christos         return;
    478      1.1    jruoho     }
    479      1.1    jruoho 
    480      1.1    jruoho     /*
    481      1.1    jruoho      * Sanity check the reference count, for debug purposes only.
    482      1.1    jruoho      * (A deleted object will have a huge reference count)
    483      1.1    jruoho      */
    484  1.1.1.3  christos     if (NewCount > ACPI_MAX_REFERENCE_COUNT)
    485      1.1    jruoho     {
    486      1.1    jruoho         ACPI_WARNING ((AE_INFO,
    487  1.1.1.3  christos             "Large Reference Count (0x%X) in object %p, Type=0x%.2X",
    488  1.1.1.3  christos             NewCount, Object, Object->Common.Type));
    489      1.1    jruoho     }
    490      1.1    jruoho }
    491      1.1    jruoho 
    492      1.1    jruoho 
    493      1.1    jruoho /*******************************************************************************
    494      1.1    jruoho  *
    495      1.1    jruoho  * FUNCTION:    AcpiUtUpdateObjectReference
    496      1.1    jruoho  *
    497      1.1    jruoho  * PARAMETERS:  Object              - Increment ref count for this object
    498      1.1    jruoho  *                                    and all sub-objects
    499  1.1.1.3  christos  *              Action              - Either REF_INCREMENT or REF_DECREMENT
    500      1.1    jruoho  *
    501      1.1    jruoho  * RETURN:      Status
    502      1.1    jruoho  *
    503      1.1    jruoho  * DESCRIPTION: Increment the object reference count
    504      1.1    jruoho  *
    505      1.1    jruoho  * Object references are incremented when:
    506      1.1    jruoho  * 1) An object is attached to a Node (namespace object)
    507      1.1    jruoho  * 2) An object is copied (all subobjects must be incremented)
    508      1.1    jruoho  *
    509      1.1    jruoho  * Object references are decremented when:
    510      1.1    jruoho  * 1) An object is detached from an Node
    511      1.1    jruoho  *
    512      1.1    jruoho  ******************************************************************************/
    513      1.1    jruoho 
    514      1.1    jruoho ACPI_STATUS
    515      1.1    jruoho AcpiUtUpdateObjectReference (
    516      1.1    jruoho     ACPI_OPERAND_OBJECT     *Object,
    517      1.1    jruoho     UINT16                  Action)
    518      1.1    jruoho {
    519      1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    520      1.1    jruoho     ACPI_GENERIC_STATE      *StateList = NULL;
    521      1.1    jruoho     ACPI_OPERAND_OBJECT     *NextObject = NULL;
    522  1.1.1.3  christos     ACPI_OPERAND_OBJECT     *PrevObject;
    523      1.1    jruoho     ACPI_GENERIC_STATE      *State;
    524      1.1    jruoho     UINT32                  i;
    525      1.1    jruoho 
    526      1.1    jruoho 
    527  1.1.1.3  christos     ACPI_FUNCTION_NAME (UtUpdateObjectReference);
    528      1.1    jruoho 
    529      1.1    jruoho 
    530      1.1    jruoho     while (Object)
    531      1.1    jruoho     {
    532      1.1    jruoho         /* Make sure that this isn't a namespace handle */
    533      1.1    jruoho 
    534      1.1    jruoho         if (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_NAMED)
    535      1.1    jruoho         {
    536      1.1    jruoho             ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
    537      1.1    jruoho                 "Object %p is NS handle\n", Object));
    538  1.1.1.3  christos             return (AE_OK);
    539      1.1    jruoho         }
    540      1.1    jruoho 
    541      1.1    jruoho         /*
    542      1.1    jruoho          * All sub-objects must have their reference count incremented also.
    543      1.1    jruoho          * Different object types have different subobjects.
    544      1.1    jruoho          */
    545      1.1    jruoho         switch (Object->Common.Type)
    546      1.1    jruoho         {
    547      1.1    jruoho         case ACPI_TYPE_DEVICE:
    548      1.1    jruoho         case ACPI_TYPE_PROCESSOR:
    549      1.1    jruoho         case ACPI_TYPE_POWER:
    550      1.1    jruoho         case ACPI_TYPE_THERMAL:
    551  1.1.1.3  christos             /*
    552  1.1.1.3  christos              * Update the notify objects for these types (if present)
    553  1.1.1.3  christos              * Two lists, system and device notify handlers.
    554  1.1.1.3  christos              */
    555  1.1.1.3  christos             for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
    556  1.1.1.3  christos             {
    557  1.1.1.3  christos                 PrevObject = Object->CommonNotify.NotifyList[i];
    558  1.1.1.3  christos                 while (PrevObject)
    559  1.1.1.3  christos                 {
    560  1.1.1.3  christos                     NextObject = PrevObject->Notify.Next[i];
    561  1.1.1.3  christos                     AcpiUtUpdateRefCount (PrevObject, Action);
    562  1.1.1.3  christos                     PrevObject = NextObject;
    563  1.1.1.3  christos                 }
    564  1.1.1.3  christos             }
    565      1.1    jruoho             break;
    566      1.1    jruoho 
    567      1.1    jruoho         case ACPI_TYPE_PACKAGE:
    568      1.1    jruoho             /*
    569      1.1    jruoho              * We must update all the sub-objects of the package,
    570      1.1    jruoho              * each of whom may have their own sub-objects.
    571      1.1    jruoho              */
    572      1.1    jruoho             for (i = 0; i < Object->Package.Count; i++)
    573      1.1    jruoho             {
    574      1.1    jruoho                 /*
    575  1.1.1.3  christos                  * Null package elements are legal and can be simply
    576  1.1.1.3  christos                  * ignored.
    577      1.1    jruoho                  */
    578  1.1.1.3  christos                 NextObject = Object->Package.Elements[i];
    579  1.1.1.3  christos                 if (!NextObject)
    580      1.1    jruoho                 {
    581  1.1.1.3  christos                     continue;
    582  1.1.1.3  christos                 }
    583  1.1.1.3  christos 
    584  1.1.1.3  christos                 switch (NextObject->Common.Type)
    585  1.1.1.3  christos                 {
    586  1.1.1.3  christos                 case ACPI_TYPE_INTEGER:
    587  1.1.1.3  christos                 case ACPI_TYPE_STRING:
    588  1.1.1.3  christos                 case ACPI_TYPE_BUFFER:
    589  1.1.1.3  christos                     /*
    590  1.1.1.3  christos                      * For these very simple sub-objects, we can just
    591  1.1.1.3  christos                      * update the reference count here and continue.
    592  1.1.1.3  christos                      * Greatly increases performance of this operation.
    593  1.1.1.3  christos                      */
    594  1.1.1.3  christos                     AcpiUtUpdateRefCount (NextObject, Action);
    595  1.1.1.3  christos                     break;
    596  1.1.1.3  christos 
    597  1.1.1.3  christos                 default:
    598  1.1.1.3  christos                     /*
    599  1.1.1.3  christos                      * For complex sub-objects, push them onto the stack
    600  1.1.1.3  christos                      * for later processing (this eliminates recursion.)
    601  1.1.1.3  christos                      */
    602  1.1.1.3  christos                     Status = AcpiUtCreateUpdateStateAndPush (
    603  1.1.1.3  christos                                  NextObject, Action, &StateList);
    604  1.1.1.3  christos                     if (ACPI_FAILURE (Status))
    605  1.1.1.3  christos                     {
    606  1.1.1.3  christos                         goto ErrorExit;
    607  1.1.1.3  christos                     }
    608  1.1.1.3  christos                     break;
    609      1.1    jruoho                 }
    610      1.1    jruoho             }
    611  1.1.1.3  christos             NextObject = NULL;
    612      1.1    jruoho             break;
    613      1.1    jruoho 
    614      1.1    jruoho         case ACPI_TYPE_BUFFER_FIELD:
    615      1.1    jruoho 
    616      1.1    jruoho             NextObject = Object->BufferField.BufferObj;
    617      1.1    jruoho             break;
    618      1.1    jruoho 
    619      1.1    jruoho         case ACPI_TYPE_LOCAL_REGION_FIELD:
    620      1.1    jruoho 
    621      1.1    jruoho             NextObject = Object->Field.RegionObj;
    622      1.1    jruoho             break;
    623      1.1    jruoho 
    624      1.1    jruoho         case ACPI_TYPE_LOCAL_BANK_FIELD:
    625      1.1    jruoho 
    626      1.1    jruoho             NextObject = Object->BankField.BankObj;
    627      1.1    jruoho             Status = AcpiUtCreateUpdateStateAndPush (
    628      1.1    jruoho                         Object->BankField.RegionObj, Action, &StateList);
    629      1.1    jruoho             if (ACPI_FAILURE (Status))
    630      1.1    jruoho             {
    631      1.1    jruoho                 goto ErrorExit;
    632      1.1    jruoho             }
    633      1.1    jruoho             break;
    634      1.1    jruoho 
    635      1.1    jruoho         case ACPI_TYPE_LOCAL_INDEX_FIELD:
    636      1.1    jruoho 
    637      1.1    jruoho             NextObject = Object->IndexField.IndexObj;
    638      1.1    jruoho             Status = AcpiUtCreateUpdateStateAndPush (
    639      1.1    jruoho                         Object->IndexField.DataObj, Action, &StateList);
    640      1.1    jruoho             if (ACPI_FAILURE (Status))
    641      1.1    jruoho             {
    642      1.1    jruoho                 goto ErrorExit;
    643      1.1    jruoho             }
    644      1.1    jruoho             break;
    645      1.1    jruoho 
    646      1.1    jruoho         case ACPI_TYPE_LOCAL_REFERENCE:
    647      1.1    jruoho             /*
    648      1.1    jruoho              * The target of an Index (a package, string, or buffer) or a named
    649      1.1    jruoho              * reference must track changes to the ref count of the index or
    650      1.1    jruoho              * target object.
    651      1.1    jruoho              */
    652      1.1    jruoho             if ((Object->Reference.Class == ACPI_REFCLASS_INDEX) ||
    653      1.1    jruoho                 (Object->Reference.Class== ACPI_REFCLASS_NAME))
    654      1.1    jruoho             {
    655      1.1    jruoho                 NextObject = Object->Reference.Object;
    656      1.1    jruoho             }
    657      1.1    jruoho             break;
    658      1.1    jruoho 
    659      1.1    jruoho         case ACPI_TYPE_REGION:
    660      1.1    jruoho         default:
    661  1.1.1.3  christos 
    662      1.1    jruoho             break; /* No subobjects for all other types */
    663      1.1    jruoho         }
    664      1.1    jruoho 
    665      1.1    jruoho         /*
    666      1.1    jruoho          * Now we can update the count in the main object. This can only
    667      1.1    jruoho          * happen after we update the sub-objects in case this causes the
    668      1.1    jruoho          * main object to be deleted.
    669      1.1    jruoho          */
    670      1.1    jruoho         AcpiUtUpdateRefCount (Object, Action);
    671      1.1    jruoho         Object = NULL;
    672      1.1    jruoho 
    673      1.1    jruoho         /* Move on to the next object to be updated */
    674      1.1    jruoho 
    675      1.1    jruoho         if (NextObject)
    676      1.1    jruoho         {
    677      1.1    jruoho             Object = NextObject;
    678      1.1    jruoho             NextObject = NULL;
    679      1.1    jruoho         }
    680      1.1    jruoho         else if (StateList)
    681      1.1    jruoho         {
    682      1.1    jruoho             State = AcpiUtPopGenericState (&StateList);
    683      1.1    jruoho             Object = State->Update.Object;
    684      1.1    jruoho             AcpiUtDeleteGenericState (State);
    685      1.1    jruoho         }
    686      1.1    jruoho     }
    687      1.1    jruoho 
    688  1.1.1.3  christos     return (AE_OK);
    689      1.1    jruoho 
    690      1.1    jruoho 
    691      1.1    jruoho ErrorExit:
    692      1.1    jruoho 
    693      1.1    jruoho     ACPI_EXCEPTION ((AE_INFO, Status,
    694      1.1    jruoho         "Could not update object reference count"));
    695      1.1    jruoho 
    696      1.1    jruoho     /* Free any stacked Update State objects */
    697      1.1    jruoho 
    698      1.1    jruoho     while (StateList)
    699      1.1    jruoho     {
    700      1.1    jruoho         State = AcpiUtPopGenericState (&StateList);
    701      1.1    jruoho         AcpiUtDeleteGenericState (State);
    702      1.1    jruoho     }
    703      1.1    jruoho 
    704  1.1.1.3  christos     return (Status);
    705      1.1    jruoho }
    706      1.1    jruoho 
    707      1.1    jruoho 
    708      1.1    jruoho /*******************************************************************************
    709      1.1    jruoho  *
    710      1.1    jruoho  * FUNCTION:    AcpiUtAddReference
    711      1.1    jruoho  *
    712      1.1    jruoho  * PARAMETERS:  Object          - Object whose reference count is to be
    713      1.1    jruoho  *                                incremented
    714      1.1    jruoho  *
    715      1.1    jruoho  * RETURN:      None
    716      1.1    jruoho  *
    717      1.1    jruoho  * DESCRIPTION: Add one reference to an ACPI object
    718      1.1    jruoho  *
    719      1.1    jruoho  ******************************************************************************/
    720      1.1    jruoho 
    721      1.1    jruoho void
    722      1.1    jruoho AcpiUtAddReference (
    723      1.1    jruoho     ACPI_OPERAND_OBJECT     *Object)
    724      1.1    jruoho {
    725      1.1    jruoho 
    726  1.1.1.3  christos     ACPI_FUNCTION_NAME (UtAddReference);
    727      1.1    jruoho 
    728      1.1    jruoho 
    729      1.1    jruoho     /* Ensure that we have a valid object */
    730      1.1    jruoho 
    731      1.1    jruoho     if (!AcpiUtValidInternalObject (Object))
    732      1.1    jruoho     {
    733  1.1.1.3  christos         return;
    734      1.1    jruoho     }
    735      1.1    jruoho 
    736      1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
    737      1.1    jruoho         "Obj %p Current Refs=%X [To Be Incremented]\n",
    738      1.1    jruoho         Object, Object->Common.ReferenceCount));
    739      1.1    jruoho 
    740      1.1    jruoho     /* Increment the reference count */
    741      1.1    jruoho 
    742      1.1    jruoho     (void) AcpiUtUpdateObjectReference (Object, REF_INCREMENT);
    743  1.1.1.3  christos     return;
    744      1.1    jruoho }
    745      1.1    jruoho 
    746      1.1    jruoho 
    747      1.1    jruoho /*******************************************************************************
    748      1.1    jruoho  *
    749      1.1    jruoho  * FUNCTION:    AcpiUtRemoveReference
    750      1.1    jruoho  *
    751      1.1    jruoho  * PARAMETERS:  Object         - Object whose ref count will be decremented
    752      1.1    jruoho  *
    753      1.1    jruoho  * RETURN:      None
    754      1.1    jruoho  *
    755      1.1    jruoho  * DESCRIPTION: Decrement the reference count of an ACPI internal object
    756      1.1    jruoho  *
    757      1.1    jruoho  ******************************************************************************/
    758      1.1    jruoho 
    759      1.1    jruoho void
    760      1.1    jruoho AcpiUtRemoveReference (
    761      1.1    jruoho     ACPI_OPERAND_OBJECT     *Object)
    762      1.1    jruoho {
    763      1.1    jruoho 
    764  1.1.1.3  christos     ACPI_FUNCTION_NAME (UtRemoveReference);
    765      1.1    jruoho 
    766      1.1    jruoho 
    767      1.1    jruoho     /*
    768      1.1    jruoho      * Allow a NULL pointer to be passed in, just ignore it. This saves
    769      1.1    jruoho      * each caller from having to check. Also, ignore NS nodes.
    770      1.1    jruoho      */
    771      1.1    jruoho     if (!Object ||
    772      1.1    jruoho         (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_NAMED))
    773      1.1    jruoho 
    774      1.1    jruoho     {
    775  1.1.1.3  christos         return;
    776      1.1    jruoho     }
    777      1.1    jruoho 
    778      1.1    jruoho     /* Ensure that we have a valid object */
    779      1.1    jruoho 
    780      1.1    jruoho     if (!AcpiUtValidInternalObject (Object))
    781      1.1    jruoho     {
    782  1.1.1.3  christos         return;
    783      1.1    jruoho     }
    784      1.1    jruoho 
    785      1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
    786      1.1    jruoho         "Obj %p Current Refs=%X [To Be Decremented]\n",
    787      1.1    jruoho         Object, Object->Common.ReferenceCount));
    788      1.1    jruoho 
    789      1.1    jruoho     /*
    790      1.1    jruoho      * Decrement the reference count, and only actually delete the object
    791      1.1    jruoho      * if the reference count becomes 0. (Must also decrement the ref count
    792      1.1    jruoho      * of all subobjects!)
    793      1.1    jruoho      */
    794      1.1    jruoho     (void) AcpiUtUpdateObjectReference (Object, REF_DECREMENT);
    795  1.1.1.3  christos     return;
    796      1.1    jruoho }
    797