13446Smrj /*******************************************************************************
23446Smrj *
33446Smrj * Module Name: utdelete - object deletion and reference count utilities
43446Smrj *
53446Smrj ******************************************************************************/
63446Smrj
73446Smrj /******************************************************************************
83446Smrj *
93446Smrj * 1. Copyright Notice
103446Smrj *
11*9980SDana.Myers@Sun.COM * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
123446Smrj * All rights reserved.
133446Smrj *
143446Smrj * 2. License
153446Smrj *
163446Smrj * 2.1. This is your license from Intel Corp. under its intellectual property
173446Smrj * rights. You may have additional license terms from the party that provided
183446Smrj * you this software, covering your right to use that party's intellectual
193446Smrj * property rights.
203446Smrj *
213446Smrj * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
223446Smrj * copy of the source code appearing in this file ("Covered Code") an
233446Smrj * irrevocable, perpetual, worldwide license under Intel's copyrights in the
243446Smrj * base code distributed originally by Intel ("Original Intel Code") to copy,
253446Smrj * make derivatives, distribute, use and display any portion of the Covered
263446Smrj * Code in any form, with the right to sublicense such rights; and
273446Smrj *
283446Smrj * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
293446Smrj * license (with the right to sublicense), under only those claims of Intel
303446Smrj * patents that are infringed by the Original Intel Code, to make, use, sell,
313446Smrj * offer to sell, and import the Covered Code and derivative works thereof
323446Smrj * solely to the minimum extent necessary to exercise the above copyright
333446Smrj * license, and in no event shall the patent license extend to any additions
343446Smrj * to or modifications of the Original Intel Code. No other license or right
353446Smrj * is granted directly or by implication, estoppel or otherwise;
363446Smrj *
373446Smrj * The above copyright and patent license is granted only if the following
383446Smrj * conditions are met:
393446Smrj *
403446Smrj * 3. Conditions
413446Smrj *
423446Smrj * 3.1. Redistribution of Source with Rights to Further Distribute Source.
433446Smrj * Redistribution of source code of any substantial portion of the Covered
443446Smrj * Code or modification with rights to further distribute source must include
453446Smrj * the above Copyright Notice, the above License, this list of Conditions,
463446Smrj * and the following Disclaimer and Export Compliance provision. In addition,
473446Smrj * Licensee must cause all Covered Code to which Licensee contributes to
483446Smrj * contain a file documenting the changes Licensee made to create that Covered
493446Smrj * Code and the date of any change. Licensee must include in that file the
503446Smrj * documentation of any changes made by any predecessor Licensee. Licensee
513446Smrj * must include a prominent statement that the modification is derived,
523446Smrj * directly or indirectly, from Original Intel Code.
533446Smrj *
543446Smrj * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
553446Smrj * Redistribution of source code of any substantial portion of the Covered
563446Smrj * Code or modification without rights to further distribute source must
573446Smrj * include the following Disclaimer and Export Compliance provision in the
583446Smrj * documentation and/or other materials provided with distribution. In
593446Smrj * addition, Licensee may not authorize further sublicense of source of any
603446Smrj * portion of the Covered Code, and must include terms to the effect that the
613446Smrj * license from Licensee to its licensee is limited to the intellectual
623446Smrj * property embodied in the software Licensee provides to its licensee, and
633446Smrj * not to intellectual property embodied in modifications its licensee may
643446Smrj * make.
653446Smrj *
663446Smrj * 3.3. Redistribution of Executable. Redistribution in executable form of any
673446Smrj * substantial portion of the Covered Code or modification must reproduce the
683446Smrj * above Copyright Notice, and the following Disclaimer and Export Compliance
693446Smrj * provision in the documentation and/or other materials provided with the
703446Smrj * distribution.
713446Smrj *
723446Smrj * 3.4. Intel retains all right, title, and interest in and to the Original
733446Smrj * Intel Code.
743446Smrj *
753446Smrj * 3.5. Neither the name Intel nor any other trademark owned or controlled by
763446Smrj * Intel shall be used in advertising or otherwise to promote the sale, use or
773446Smrj * other dealings in products derived from or relating to the Covered Code
783446Smrj * without prior written authorization from Intel.
793446Smrj *
803446Smrj * 4. Disclaimer and Export Compliance
813446Smrj *
823446Smrj * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
833446Smrj * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
843446Smrj * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
853446Smrj * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
863446Smrj * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
873446Smrj * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
883446Smrj * PARTICULAR PURPOSE.
893446Smrj *
903446Smrj * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
913446Smrj * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
923446Smrj * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
933446Smrj * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
943446Smrj * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
953446Smrj * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
963446Smrj * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
973446Smrj * LIMITED REMEDY.
983446Smrj *
993446Smrj * 4.3. Licensee shall not export, either directly or indirectly, any of this
1003446Smrj * software or system incorporating such software without first obtaining any
1013446Smrj * required license or other approval from the U. S. Department of Commerce or
1023446Smrj * any other agency or department of the United States Government. In the
1033446Smrj * event Licensee exports any such software from the United States or
1043446Smrj * re-exports any such software from a foreign destination, Licensee shall
1053446Smrj * ensure that the distribution and export/re-export of the software is in
1063446Smrj * compliance with all laws, regulations, orders, or other restrictions of the
1073446Smrj * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1083446Smrj * any of its subsidiaries will export/re-export any technical data, process,
1093446Smrj * software, or service, directly or indirectly, to any country for which the
1103446Smrj * United States government or any agency thereof requires an export license,
1113446Smrj * other governmental approval, or letter of assurance, without first obtaining
1123446Smrj * such license, approval or letter.
1133446Smrj *
1143446Smrj *****************************************************************************/
1153446Smrj
1163446Smrj #define __UTDELETE_C__
1173446Smrj
1183446Smrj #include "acpi.h"
119*9980SDana.Myers@Sun.COM #include "accommon.h"
1203446Smrj #include "acinterp.h"
1213446Smrj #include "acnamesp.h"
1223446Smrj #include "acevents.h"
1237851SDana.Myers@Sun.COM
1243446Smrj
1253446Smrj #define _COMPONENT ACPI_UTILITIES
1263446Smrj ACPI_MODULE_NAME ("utdelete")
1273446Smrj
1283446Smrj /* Local prototypes */
1293446Smrj
1303446Smrj static void
1313446Smrj AcpiUtDeleteInternalObj (
1323446Smrj ACPI_OPERAND_OBJECT *Object);
1333446Smrj
1343446Smrj static void
1353446Smrj AcpiUtUpdateRefCount (
1363446Smrj ACPI_OPERAND_OBJECT *Object,
1373446Smrj UINT32 Action);
1383446Smrj
1393446Smrj
1403446Smrj /*******************************************************************************
1413446Smrj *
1423446Smrj * FUNCTION: AcpiUtDeleteInternalObj
1433446Smrj *
1443446Smrj * PARAMETERS: Object - Object to be deleted
1453446Smrj *
1463446Smrj * RETURN: None
1473446Smrj *
1483446Smrj * DESCRIPTION: Low level object deletion, after reference counts have been
1493446Smrj * updated (All reference counts, including sub-objects!)
1503446Smrj *
1513446Smrj ******************************************************************************/
1523446Smrj
1533446Smrj static void
AcpiUtDeleteInternalObj(ACPI_OPERAND_OBJECT * Object)1543446Smrj AcpiUtDeleteInternalObj (
1553446Smrj ACPI_OPERAND_OBJECT *Object)
1563446Smrj {
1573446Smrj void *ObjPointer = NULL;
1583446Smrj ACPI_OPERAND_OBJECT *HandlerDesc;
1593446Smrj ACPI_OPERAND_OBJECT *SecondDesc;
1603446Smrj ACPI_OPERAND_OBJECT *NextDesc;
161*9980SDana.Myers@Sun.COM ACPI_OPERAND_OBJECT **LastObjPtr;
1623446Smrj
1633446Smrj
1643446Smrj ACPI_FUNCTION_TRACE_PTR (UtDeleteInternalObj, Object);
1653446Smrj
1663446Smrj
1673446Smrj if (!Object)
1683446Smrj {
1693446Smrj return_VOID;
1703446Smrj }
1713446Smrj
1723446Smrj /*
1733446Smrj * Must delete or free any pointers within the object that are not
1743446Smrj * actual ACPI objects (for example, a raw buffer pointer).
1753446Smrj */
176*9980SDana.Myers@Sun.COM switch (Object->Common.Type)
1773446Smrj {
1783446Smrj case ACPI_TYPE_STRING:
1793446Smrj
1803446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "**** String %p, ptr %p\n",
1813446Smrj Object, Object->String.Pointer));
1823446Smrj
1833446Smrj /* Free the actual string buffer */
1843446Smrj
1853446Smrj if (!(Object->Common.Flags & AOPOBJ_STATIC_POINTER))
1863446Smrj {
1873446Smrj /* But only if it is NOT a pointer into an ACPI table */
1883446Smrj
1893446Smrj ObjPointer = Object->String.Pointer;
1903446Smrj }
1913446Smrj break;
1923446Smrj
1933446Smrj
1943446Smrj case ACPI_TYPE_BUFFER:
1953446Smrj
1963446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "**** Buffer %p, ptr %p\n",
1973446Smrj Object, Object->Buffer.Pointer));
1983446Smrj
1993446Smrj /* Free the actual buffer */
2003446Smrj
2013446Smrj if (!(Object->Common.Flags & AOPOBJ_STATIC_POINTER))
2023446Smrj {
2033446Smrj /* But only if it is NOT a pointer into an ACPI table */
2043446Smrj
2053446Smrj ObjPointer = Object->Buffer.Pointer;
2063446Smrj }
2073446Smrj break;
2083446Smrj
2093446Smrj
2103446Smrj case ACPI_TYPE_PACKAGE:
2113446Smrj
2123446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, " **** Package of count %X\n",
2133446Smrj Object->Package.Count));
2143446Smrj
2153446Smrj /*
2163446Smrj * Elements of the package are not handled here, they are deleted
2173446Smrj * separately
2183446Smrj */
2193446Smrj
2203446Smrj /* Free the (variable length) element pointer array */
2213446Smrj
2223446Smrj ObjPointer = Object->Package.Elements;
2233446Smrj break;
2243446Smrj
2253446Smrj
2267851SDana.Myers@Sun.COM /*
2277851SDana.Myers@Sun.COM * These objects have a possible list of notify handlers.
2287851SDana.Myers@Sun.COM * Device object also may have a GPE block.
2297851SDana.Myers@Sun.COM */
2303446Smrj case ACPI_TYPE_DEVICE:
2313446Smrj
2323446Smrj if (Object->Device.GpeBlock)
2333446Smrj {
2343446Smrj (void) AcpiEvDeleteGpeBlock (Object->Device.GpeBlock);
2353446Smrj }
2363446Smrj
2377851SDana.Myers@Sun.COM /*lint -fallthrough */
2383446Smrj
2397851SDana.Myers@Sun.COM case ACPI_TYPE_PROCESSOR:
2407851SDana.Myers@Sun.COM case ACPI_TYPE_THERMAL:
2417851SDana.Myers@Sun.COM
2427851SDana.Myers@Sun.COM /* Walk the notify handler list for this object */
2437851SDana.Myers@Sun.COM
2447851SDana.Myers@Sun.COM HandlerDesc = Object->CommonNotify.Handler;
2453446Smrj while (HandlerDesc)
2463446Smrj {
2473446Smrj NextDesc = HandlerDesc->AddressSpace.Next;
2483446Smrj AcpiUtRemoveReference (HandlerDesc);
2493446Smrj HandlerDesc = NextDesc;
2503446Smrj }
2513446Smrj break;
2523446Smrj
2533446Smrj
2543446Smrj case ACPI_TYPE_MUTEX:
2553446Smrj
2563446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
2573446Smrj "***** Mutex %p, OS Mutex %p\n",
2583446Smrj Object, Object->Mutex.OsMutex));
2593446Smrj
2607851SDana.Myers@Sun.COM if (Object == AcpiGbl_GlobalLockMutex)
2613446Smrj {
2623446Smrj /* Global Lock has extra semaphore */
2633446Smrj
2643446Smrj (void) AcpiOsDeleteSemaphore (AcpiGbl_GlobalLockSemaphore);
2653446Smrj AcpiGbl_GlobalLockSemaphore = NULL;
2663446Smrj
2673446Smrj AcpiOsDeleteMutex (Object->Mutex.OsMutex);
2683446Smrj AcpiGbl_GlobalLockMutex = NULL;
2693446Smrj }
2703446Smrj else
2713446Smrj {
2723446Smrj AcpiExUnlinkMutex (Object);
2733446Smrj AcpiOsDeleteMutex (Object->Mutex.OsMutex);
2743446Smrj }
2753446Smrj break;
2763446Smrj
2773446Smrj
2783446Smrj case ACPI_TYPE_EVENT:
2793446Smrj
2803446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
2813446Smrj "***** Event %p, OS Semaphore %p\n",
2823446Smrj Object, Object->Event.OsSemaphore));
2833446Smrj
2843446Smrj (void) AcpiOsDeleteSemaphore (Object->Event.OsSemaphore);
2853446Smrj Object->Event.OsSemaphore = NULL;
2863446Smrj break;
2873446Smrj
2883446Smrj
2893446Smrj case ACPI_TYPE_METHOD:
2903446Smrj
2913446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
2923446Smrj "***** Method %p\n", Object));
2933446Smrj
2943446Smrj /* Delete the method mutex if it exists */
2953446Smrj
2963446Smrj if (Object->Method.Mutex)
2973446Smrj {
2983446Smrj AcpiOsDeleteMutex (Object->Method.Mutex->Mutex.OsMutex);
2993446Smrj AcpiUtDeleteObjectDesc (Object->Method.Mutex);
3003446Smrj Object->Method.Mutex = NULL;
3013446Smrj }
3023446Smrj break;
3033446Smrj
3043446Smrj
3053446Smrj case ACPI_TYPE_REGION:
3063446Smrj
3073446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
3083446Smrj "***** Region %p\n", Object));
3093446Smrj
3103446Smrj SecondDesc = AcpiNsGetSecondaryObject (Object);
3113446Smrj if (SecondDesc)
3123446Smrj {
3133446Smrj /*
3143446Smrj * Free the RegionContext if and only if the handler is one of the
3153446Smrj * default handlers -- and therefore, we created the context object
3163446Smrj * locally, it was not created by an external caller.
3173446Smrj */
3183446Smrj HandlerDesc = Object->Region.Handler;
3193446Smrj if (HandlerDesc)
3203446Smrj {
321*9980SDana.Myers@Sun.COM NextDesc = HandlerDesc->AddressSpace.RegionList;
322*9980SDana.Myers@Sun.COM LastObjPtr = &HandlerDesc->AddressSpace.RegionList;
323*9980SDana.Myers@Sun.COM
324*9980SDana.Myers@Sun.COM /* Remove the region object from the handler's list */
325*9980SDana.Myers@Sun.COM
326*9980SDana.Myers@Sun.COM while (NextDesc)
327*9980SDana.Myers@Sun.COM {
328*9980SDana.Myers@Sun.COM if (NextDesc == Object)
329*9980SDana.Myers@Sun.COM {
330*9980SDana.Myers@Sun.COM *LastObjPtr = NextDesc->Region.Next;
331*9980SDana.Myers@Sun.COM break;
332*9980SDana.Myers@Sun.COM }
333*9980SDana.Myers@Sun.COM
334*9980SDana.Myers@Sun.COM /* Walk the linked list of handler */
335*9980SDana.Myers@Sun.COM
336*9980SDana.Myers@Sun.COM LastObjPtr = &NextDesc->Region.Next;
337*9980SDana.Myers@Sun.COM NextDesc = NextDesc->Region.Next;
338*9980SDana.Myers@Sun.COM }
339*9980SDana.Myers@Sun.COM
3403446Smrj if (HandlerDesc->AddressSpace.HandlerFlags &
3413446Smrj ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)
3423446Smrj {
3433446Smrj /* Deactivate region and free region context */
3443446Smrj
3453446Smrj if (HandlerDesc->AddressSpace.Setup)
3463446Smrj {
3473446Smrj (void) HandlerDesc->AddressSpace.Setup (Object,
3483446Smrj ACPI_REGION_DEACTIVATE,
3493446Smrj HandlerDesc->AddressSpace.Context,
3503446Smrj &SecondDesc->Extra.RegionContext);
3513446Smrj }
3523446Smrj }
3533446Smrj
3543446Smrj AcpiUtRemoveReference (HandlerDesc);
3553446Smrj }
3563446Smrj
3573446Smrj /* Now we can free the Extra object */
3583446Smrj
3593446Smrj AcpiUtDeleteObjectDesc (SecondDesc);
3603446Smrj }
3613446Smrj break;
3623446Smrj
3633446Smrj
3643446Smrj case ACPI_TYPE_BUFFER_FIELD:
3653446Smrj
3663446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
3673446Smrj "***** Buffer Field %p\n", Object));
3683446Smrj
3693446Smrj SecondDesc = AcpiNsGetSecondaryObject (Object);
3703446Smrj if (SecondDesc)
3713446Smrj {
3723446Smrj AcpiUtDeleteObjectDesc (SecondDesc);
3733446Smrj }
3743446Smrj break;
3753446Smrj
3763446Smrj
3777851SDana.Myers@Sun.COM case ACPI_TYPE_LOCAL_BANK_FIELD:
3787851SDana.Myers@Sun.COM
3797851SDana.Myers@Sun.COM ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
3807851SDana.Myers@Sun.COM "***** Bank Field %p\n", Object));
3817851SDana.Myers@Sun.COM
3827851SDana.Myers@Sun.COM SecondDesc = AcpiNsGetSecondaryObject (Object);
3837851SDana.Myers@Sun.COM if (SecondDesc)
3847851SDana.Myers@Sun.COM {
3857851SDana.Myers@Sun.COM AcpiUtDeleteObjectDesc (SecondDesc);
3867851SDana.Myers@Sun.COM }
3877851SDana.Myers@Sun.COM break;
3887851SDana.Myers@Sun.COM
3897851SDana.Myers@Sun.COM
3903446Smrj default:
3913446Smrj break;
3923446Smrj }
3933446Smrj
3943446Smrj /* Free any allocated memory (pointer within the object) found above */
3953446Smrj
3963446Smrj if (ObjPointer)
3973446Smrj {
3983446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Deleting Object Subptr %p\n",
3993446Smrj ObjPointer));
4003446Smrj ACPI_FREE (ObjPointer);
4013446Smrj }
4023446Smrj
4033446Smrj /* Now the object can be safely deleted */
4043446Smrj
4053446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Deleting Object %p [%s]\n",
4063446Smrj Object, AcpiUtGetObjectTypeName (Object)));
4073446Smrj
4083446Smrj AcpiUtDeleteObjectDesc (Object);
4093446Smrj return_VOID;
4103446Smrj }
4113446Smrj
4123446Smrj
4133446Smrj /*******************************************************************************
4143446Smrj *
4153446Smrj * FUNCTION: AcpiUtDeleteInternalObjectList
4163446Smrj *
4173446Smrj * PARAMETERS: ObjList - Pointer to the list to be deleted
4183446Smrj *
4193446Smrj * RETURN: None
4203446Smrj *
4213446Smrj * DESCRIPTION: This function deletes an internal object list, including both
4223446Smrj * simple objects and package objects
4233446Smrj *
4243446Smrj ******************************************************************************/
4253446Smrj
4263446Smrj void
AcpiUtDeleteInternalObjectList(ACPI_OPERAND_OBJECT ** ObjList)4273446Smrj AcpiUtDeleteInternalObjectList (
4283446Smrj ACPI_OPERAND_OBJECT **ObjList)
4293446Smrj {
4303446Smrj ACPI_OPERAND_OBJECT **InternalObj;
4313446Smrj
4323446Smrj
4333446Smrj ACPI_FUNCTION_TRACE (UtDeleteInternalObjectList);
4343446Smrj
4353446Smrj
4363446Smrj /* Walk the null-terminated internal list */
4373446Smrj
4383446Smrj for (InternalObj = ObjList; *InternalObj; InternalObj++)
4393446Smrj {
4403446Smrj AcpiUtRemoveReference (*InternalObj);
4413446Smrj }
4423446Smrj
4433446Smrj /* Free the combined parameter pointer list and object array */
4443446Smrj
4453446Smrj ACPI_FREE (ObjList);
4463446Smrj return_VOID;
4473446Smrj }
4483446Smrj
4493446Smrj
4503446Smrj /*******************************************************************************
4513446Smrj *
4523446Smrj * FUNCTION: AcpiUtUpdateRefCount
4533446Smrj *
4543446Smrj * PARAMETERS: Object - Object whose ref count is to be updated
4553446Smrj * Action - What to do
4563446Smrj *
4573446Smrj * RETURN: New ref count
4583446Smrj *
4593446Smrj * DESCRIPTION: Modify the ref count and return it.
4603446Smrj *
4613446Smrj ******************************************************************************/
4623446Smrj
4633446Smrj static void
AcpiUtUpdateRefCount(ACPI_OPERAND_OBJECT * Object,UINT32 Action)4643446Smrj AcpiUtUpdateRefCount (
4653446Smrj ACPI_OPERAND_OBJECT *Object,
4663446Smrj UINT32 Action)
4673446Smrj {
4683446Smrj UINT16 Count;
4693446Smrj UINT16 NewCount;
4703446Smrj
4713446Smrj
4723446Smrj ACPI_FUNCTION_NAME (UtUpdateRefCount);
4733446Smrj
4743446Smrj
4753446Smrj if (!Object)
4763446Smrj {
4773446Smrj return;
4783446Smrj }
4793446Smrj
4803446Smrj Count = Object->Common.ReferenceCount;
4813446Smrj NewCount = Count;
4823446Smrj
4833446Smrj /*
4843446Smrj * Perform the reference count action (increment, decrement, force delete)
4853446Smrj */
4863446Smrj switch (Action)
4873446Smrj {
4883446Smrj case REF_INCREMENT:
4893446Smrj
4903446Smrj NewCount++;
4913446Smrj Object->Common.ReferenceCount = NewCount;
4923446Smrj
4933446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
4943446Smrj "Obj %p Refs=%X, [Incremented]\n",
4953446Smrj Object, NewCount));
4963446Smrj break;
4973446Smrj
4983446Smrj case REF_DECREMENT:
4993446Smrj
5003446Smrj if (Count < 1)
5013446Smrj {
5023446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
5033446Smrj "Obj %p Refs=%X, can't decrement! (Set to 0)\n",
5043446Smrj Object, NewCount));
5053446Smrj
5063446Smrj NewCount = 0;
5073446Smrj }
5083446Smrj else
5093446Smrj {
5103446Smrj NewCount--;
5113446Smrj
5123446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
5133446Smrj "Obj %p Refs=%X, [Decremented]\n",
5143446Smrj Object, NewCount));
5153446Smrj }
5163446Smrj
517*9980SDana.Myers@Sun.COM if (Object->Common.Type == ACPI_TYPE_METHOD)
5183446Smrj {
5193446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
5203446Smrj "Method Obj %p Refs=%X, [Decremented]\n", Object, NewCount));
5213446Smrj }
5223446Smrj
5233446Smrj Object->Common.ReferenceCount = NewCount;
5243446Smrj if (NewCount == 0)
5253446Smrj {
5263446Smrj AcpiUtDeleteInternalObj (Object);
5273446Smrj }
5283446Smrj break;
5293446Smrj
5303446Smrj case REF_FORCE_DELETE:
5313446Smrj
5323446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
5333446Smrj "Obj %p Refs=%X, Force delete! (Set to 0)\n", Object, Count));
5343446Smrj
5353446Smrj NewCount = 0;
5363446Smrj Object->Common.ReferenceCount = NewCount;
5373446Smrj AcpiUtDeleteInternalObj (Object);
5383446Smrj break;
5393446Smrj
5403446Smrj default:
5413446Smrj
5423446Smrj ACPI_ERROR ((AE_INFO, "Unknown action (%X)", Action));
5433446Smrj break;
5443446Smrj }
5453446Smrj
5463446Smrj /*
5473446Smrj * Sanity check the reference count, for debug purposes only.
5483446Smrj * (A deleted object will have a huge reference count)
5493446Smrj */
5503446Smrj if (Count > ACPI_MAX_REFERENCE_COUNT)
5513446Smrj {
5523446Smrj ACPI_WARNING ((AE_INFO,
5533446Smrj "Large Reference Count (%X) in object %p", Count, Object));
5543446Smrj }
5553446Smrj }
5563446Smrj
5573446Smrj
5583446Smrj /*******************************************************************************
5593446Smrj *
5603446Smrj * FUNCTION: AcpiUtUpdateObjectReference
5613446Smrj *
5623446Smrj * PARAMETERS: Object - Increment ref count for this object
5633446Smrj * and all sub-objects
5643446Smrj * Action - Either REF_INCREMENT or REF_DECREMENT or
5653446Smrj * REF_FORCE_DELETE
5663446Smrj *
5673446Smrj * RETURN: Status
5683446Smrj *
5693446Smrj * DESCRIPTION: Increment the object reference count
5703446Smrj *
5713446Smrj * Object references are incremented when:
5723446Smrj * 1) An object is attached to a Node (namespace object)
5733446Smrj * 2) An object is copied (all subobjects must be incremented)
5743446Smrj *
5753446Smrj * Object references are decremented when:
5763446Smrj * 1) An object is detached from an Node
5773446Smrj *
5783446Smrj ******************************************************************************/
5793446Smrj
5803446Smrj ACPI_STATUS
AcpiUtUpdateObjectReference(ACPI_OPERAND_OBJECT * Object,UINT16 Action)5813446Smrj AcpiUtUpdateObjectReference (
5823446Smrj ACPI_OPERAND_OBJECT *Object,
5833446Smrj UINT16 Action)
5843446Smrj {
5853446Smrj ACPI_STATUS Status = AE_OK;
5863446Smrj ACPI_GENERIC_STATE *StateList = NULL;
5873446Smrj ACPI_OPERAND_OBJECT *NextObject = NULL;
5883446Smrj ACPI_GENERIC_STATE *State;
5897851SDana.Myers@Sun.COM UINT32 i;
5903446Smrj
5913446Smrj
5923446Smrj ACPI_FUNCTION_TRACE_PTR (UtUpdateObjectReference, Object);
5933446Smrj
5943446Smrj
5953446Smrj while (Object)
5963446Smrj {
5973446Smrj /* Make sure that this isn't a namespace handle */
5983446Smrj
5993446Smrj if (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_NAMED)
6003446Smrj {
6013446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
6023446Smrj "Object %p is NS handle\n", Object));
6033446Smrj return_ACPI_STATUS (AE_OK);
6043446Smrj }
6053446Smrj
6063446Smrj /*
6073446Smrj * All sub-objects must have their reference count incremented also.
6083446Smrj * Different object types have different subobjects.
6093446Smrj */
610*9980SDana.Myers@Sun.COM switch (Object->Common.Type)
6113446Smrj {
6123446Smrj case ACPI_TYPE_DEVICE:
6133446Smrj case ACPI_TYPE_PROCESSOR:
6143446Smrj case ACPI_TYPE_POWER:
6153446Smrj case ACPI_TYPE_THERMAL:
6163446Smrj
6173446Smrj /* Update the notify objects for these types (if present) */
6183446Smrj
6193446Smrj AcpiUtUpdateRefCount (Object->CommonNotify.SystemNotify, Action);
6203446Smrj AcpiUtUpdateRefCount (Object->CommonNotify.DeviceNotify, Action);
6213446Smrj break;
6223446Smrj
6233446Smrj case ACPI_TYPE_PACKAGE:
6243446Smrj /*
6253446Smrj * We must update all the sub-objects of the package,
6263446Smrj * each of whom may have their own sub-objects.
6273446Smrj */
6283446Smrj for (i = 0; i < Object->Package.Count; i++)
6293446Smrj {
6303446Smrj /*
6313446Smrj * Push each element onto the stack for later processing.
6323446Smrj * Note: There can be null elements within the package,
6333446Smrj * these are simply ignored
6343446Smrj */
6353446Smrj Status = AcpiUtCreateUpdateStateAndPush (
6363446Smrj Object->Package.Elements[i], Action, &StateList);
6373446Smrj if (ACPI_FAILURE (Status))
6383446Smrj {
6393446Smrj goto ErrorExit;
6403446Smrj }
6413446Smrj }
6423446Smrj break;
6433446Smrj
6443446Smrj case ACPI_TYPE_BUFFER_FIELD:
6453446Smrj
6463446Smrj NextObject = Object->BufferField.BufferObj;
6473446Smrj break;
6483446Smrj
6493446Smrj case ACPI_TYPE_LOCAL_REGION_FIELD:
6503446Smrj
6513446Smrj NextObject = Object->Field.RegionObj;
6523446Smrj break;
6533446Smrj
6543446Smrj case ACPI_TYPE_LOCAL_BANK_FIELD:
6553446Smrj
6563446Smrj NextObject = Object->BankField.BankObj;
6573446Smrj Status = AcpiUtCreateUpdateStateAndPush (
6583446Smrj Object->BankField.RegionObj, Action, &StateList);
6593446Smrj if (ACPI_FAILURE (Status))
6603446Smrj {
6613446Smrj goto ErrorExit;
6623446Smrj }
6633446Smrj break;
6643446Smrj
6653446Smrj case ACPI_TYPE_LOCAL_INDEX_FIELD:
6663446Smrj
6673446Smrj NextObject = Object->IndexField.IndexObj;
6683446Smrj Status = AcpiUtCreateUpdateStateAndPush (
6693446Smrj Object->IndexField.DataObj, Action, &StateList);
6703446Smrj if (ACPI_FAILURE (Status))
6713446Smrj {
6723446Smrj goto ErrorExit;
6733446Smrj }
6743446Smrj break;
6753446Smrj
6763446Smrj case ACPI_TYPE_LOCAL_REFERENCE:
6773446Smrj /*
6787851SDana.Myers@Sun.COM * The target of an Index (a package, string, or buffer) or a named
6797851SDana.Myers@Sun.COM * reference must track changes to the ref count of the index or
6807851SDana.Myers@Sun.COM * target object.
6813446Smrj */
6827851SDana.Myers@Sun.COM if ((Object->Reference.Class == ACPI_REFCLASS_INDEX) ||
6837851SDana.Myers@Sun.COM (Object->Reference.Class== ACPI_REFCLASS_NAME))
6843446Smrj {
6853446Smrj NextObject = Object->Reference.Object;
6863446Smrj }
6873446Smrj break;
6883446Smrj
6893446Smrj case ACPI_TYPE_REGION:
6903446Smrj default:
6913446Smrj break; /* No subobjects for all other types */
6923446Smrj }
6933446Smrj
6943446Smrj /*
6953446Smrj * Now we can update the count in the main object. This can only
6963446Smrj * happen after we update the sub-objects in case this causes the
6973446Smrj * main object to be deleted.
6983446Smrj */
6993446Smrj AcpiUtUpdateRefCount (Object, Action);
7003446Smrj Object = NULL;
7013446Smrj
7023446Smrj /* Move on to the next object to be updated */
7033446Smrj
7043446Smrj if (NextObject)
7053446Smrj {
7063446Smrj Object = NextObject;
7073446Smrj NextObject = NULL;
7083446Smrj }
7093446Smrj else if (StateList)
7103446Smrj {
7113446Smrj State = AcpiUtPopGenericState (&StateList);
7123446Smrj Object = State->Update.Object;
7133446Smrj AcpiUtDeleteGenericState (State);
7143446Smrj }
7153446Smrj }
7163446Smrj
7173446Smrj return_ACPI_STATUS (AE_OK);
7183446Smrj
719*9980SDana.Myers@Sun.COM
7203446Smrj ErrorExit:
7213446Smrj
7223446Smrj ACPI_EXCEPTION ((AE_INFO, Status,
7233446Smrj "Could not update object reference count"));
7243446Smrj
725*9980SDana.Myers@Sun.COM /* Free any stacked Update State objects */
726*9980SDana.Myers@Sun.COM
727*9980SDana.Myers@Sun.COM while (StateList)
728*9980SDana.Myers@Sun.COM {
729*9980SDana.Myers@Sun.COM State = AcpiUtPopGenericState (&StateList);
730*9980SDana.Myers@Sun.COM AcpiUtDeleteGenericState (State);
731*9980SDana.Myers@Sun.COM }
732*9980SDana.Myers@Sun.COM
7333446Smrj return_ACPI_STATUS (Status);
7343446Smrj }
7353446Smrj
7363446Smrj
7373446Smrj /*******************************************************************************
7383446Smrj *
7393446Smrj * FUNCTION: AcpiUtAddReference
7403446Smrj *
7413446Smrj * PARAMETERS: Object - Object whose reference count is to be
7423446Smrj * incremented
7433446Smrj *
7443446Smrj * RETURN: None
7453446Smrj *
7463446Smrj * DESCRIPTION: Add one reference to an ACPI object
7473446Smrj *
7483446Smrj ******************************************************************************/
7493446Smrj
7503446Smrj void
AcpiUtAddReference(ACPI_OPERAND_OBJECT * Object)7513446Smrj AcpiUtAddReference (
7523446Smrj ACPI_OPERAND_OBJECT *Object)
7533446Smrj {
7543446Smrj
7553446Smrj ACPI_FUNCTION_TRACE_PTR (UtAddReference, Object);
7563446Smrj
7573446Smrj
7583446Smrj /* Ensure that we have a valid object */
7593446Smrj
7603446Smrj if (!AcpiUtValidInternalObject (Object))
7613446Smrj {
7623446Smrj return_VOID;
7633446Smrj }
7643446Smrj
7653446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
7663446Smrj "Obj %p Current Refs=%X [To Be Incremented]\n",
7673446Smrj Object, Object->Common.ReferenceCount));
7683446Smrj
7693446Smrj /* Increment the reference count */
7703446Smrj
7713446Smrj (void) AcpiUtUpdateObjectReference (Object, REF_INCREMENT);
7723446Smrj return_VOID;
7733446Smrj }
7743446Smrj
7753446Smrj
7763446Smrj /*******************************************************************************
7773446Smrj *
7783446Smrj * FUNCTION: AcpiUtRemoveReference
7793446Smrj *
7803446Smrj * PARAMETERS: Object - Object whose ref count will be decremented
7813446Smrj *
7823446Smrj * RETURN: None
7833446Smrj *
7843446Smrj * DESCRIPTION: Decrement the reference count of an ACPI internal object
7853446Smrj *
7863446Smrj ******************************************************************************/
7873446Smrj
7883446Smrj void
AcpiUtRemoveReference(ACPI_OPERAND_OBJECT * Object)7893446Smrj AcpiUtRemoveReference (
7903446Smrj ACPI_OPERAND_OBJECT *Object)
7913446Smrj {
7923446Smrj
7933446Smrj ACPI_FUNCTION_TRACE_PTR (UtRemoveReference, Object);
7943446Smrj
7953446Smrj
7963446Smrj /*
7973446Smrj * Allow a NULL pointer to be passed in, just ignore it. This saves
7983446Smrj * each caller from having to check. Also, ignore NS nodes.
7993446Smrj *
8003446Smrj */
8013446Smrj if (!Object ||
8023446Smrj (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_NAMED))
8033446Smrj
8043446Smrj {
8053446Smrj return_VOID;
8063446Smrj }
8073446Smrj
8083446Smrj /* Ensure that we have a valid object */
8093446Smrj
8103446Smrj if (!AcpiUtValidInternalObject (Object))
8113446Smrj {
8123446Smrj return_VOID;
8133446Smrj }
8143446Smrj
8153446Smrj ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
8163446Smrj "Obj %p Current Refs=%X [To Be Decremented]\n",
8173446Smrj Object, Object->Common.ReferenceCount));
8183446Smrj
8193446Smrj /*
8203446Smrj * Decrement the reference count, and only actually delete the object
8213446Smrj * if the reference count becomes 0. (Must also decrement the ref count
8223446Smrj * of all subobjects!)
8233446Smrj */
8243446Smrj (void) AcpiUtUpdateObjectReference (Object, REF_DECREMENT);
8253446Smrj return_VOID;
8263446Smrj }
8273446Smrj
8283446Smrj
829