1 /*******************************************************************************
3 * Module Name: utdelete - object deletion and reference count utilities
6 ******************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
116 /* $DragonFly: src/sys/contrib/dev/acpica/Attic/utdelete.c,v 1.1 2003/09/24 03:32:16 drhodus Exp $ */
118 #define __UTDELETE_C__
121 #include "acinterp.h"
122 #include "acnamesp.h"
124 #define _COMPONENT ACPI_UTILITIES
125 ACPI_MODULE_NAME ("utdelete")
128 /*******************************************************************************
130 * FUNCTION: AcpiUtDeleteInternalObj
132 * PARAMETERS: *Object - Pointer to the list to be deleted
136 * DESCRIPTION: Low level object deletion, after reference counts have been
137 * updated (All reference counts, including sub-objects!)
139 ******************************************************************************/
142 AcpiUtDeleteInternalObj (
143 ACPI_OPERAND_OBJECT *Object)
145 void *ObjPointer = NULL;
146 ACPI_OPERAND_OBJECT *HandlerDesc;
147 ACPI_OPERAND_OBJECT *SecondDesc;
150 ACPI_FUNCTION_TRACE_PTR ("UtDeleteInternalObj", Object);
159 * Must delete or free any pointers within the object that are not
160 * actual ACPI objects (for example, a raw buffer pointer).
162 switch (ACPI_GET_OBJECT_TYPE (Object))
164 case ACPI_TYPE_STRING:
166 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "**** String %p, ptr %p\n",
167 Object, Object->String.Pointer));
169 /* Free the actual string buffer */
171 if (!(Object->Common.Flags & AOPOBJ_STATIC_POINTER))
173 /* But only if it is NOT a pointer into an ACPI table */
175 ObjPointer = Object->String.Pointer;
180 case ACPI_TYPE_BUFFER:
182 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "**** Buffer %p, ptr %p\n",
183 Object, Object->Buffer.Pointer));
185 /* Free the actual buffer */
187 if (!(Object->Common.Flags & AOPOBJ_STATIC_POINTER))
189 /* But only if it is NOT a pointer into an ACPI table */
191 ObjPointer = Object->Buffer.Pointer;
196 case ACPI_TYPE_PACKAGE:
198 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, " **** Package of count %X\n",
199 Object->Package.Count));
202 * Elements of the package are not handled here, they are deleted
206 /* Free the (variable length) element pointer array */
208 ObjPointer = Object->Package.Elements;
212 case ACPI_TYPE_MUTEX:
214 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Mutex %p, Semaphore %p\n",
215 Object, Object->Mutex.Semaphore));
217 AcpiExUnlinkMutex (Object);
218 (void) AcpiOsDeleteSemaphore (Object->Mutex.Semaphore);
222 case ACPI_TYPE_EVENT:
224 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Event %p, Semaphore %p\n",
225 Object, Object->Event.Semaphore));
227 (void) AcpiOsDeleteSemaphore (Object->Event.Semaphore);
228 Object->Event.Semaphore = NULL;
232 case ACPI_TYPE_METHOD:
234 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Method %p\n", Object));
236 /* Delete the method semaphore if it exists */
238 if (Object->Method.Semaphore)
240 (void) AcpiOsDeleteSemaphore (Object->Method.Semaphore);
241 Object->Method.Semaphore = NULL;
246 case ACPI_TYPE_REGION:
248 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Region %p\n", Object));
250 SecondDesc = AcpiNsGetSecondaryObject (Object);
254 * Free the RegionContext if and only if the handler is one of the
255 * default handlers -- and therefore, we created the context object
256 * locally, it was not created by an external caller.
258 HandlerDesc = Object->Region.AddrHandler;
260 (HandlerDesc->AddrHandler.Hflags == ACPI_ADDR_HANDLER_DEFAULT_INSTALLED))
262 ObjPointer = SecondDesc->Extra.RegionContext;
265 /* Now we can free the Extra object */
267 AcpiUtDeleteObjectDesc (SecondDesc);
272 case ACPI_TYPE_BUFFER_FIELD:
274 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "***** Buffer Field %p\n", Object));
276 SecondDesc = AcpiNsGetSecondaryObject (Object);
279 AcpiUtDeleteObjectDesc (SecondDesc);
289 /* Free any allocated memory (pointer within the object) found above */
293 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Deleting Object Subptr %p\n",
295 ACPI_MEM_FREE (ObjPointer);
298 /* Now the object can be safely deleted */
300 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Deleting Object %p [%s]\n",
301 Object, AcpiUtGetObjectTypeName (Object)));
303 AcpiUtDeleteObjectDesc (Object);
308 /*******************************************************************************
310 * FUNCTION: AcpiUtDeleteInternalObjectList
312 * PARAMETERS: *ObjList - Pointer to the list to be deleted
316 * DESCRIPTION: This function deletes an internal object list, including both
317 * simple objects and package objects
319 ******************************************************************************/
322 AcpiUtDeleteInternalObjectList (
323 ACPI_OPERAND_OBJECT **ObjList)
325 ACPI_OPERAND_OBJECT **InternalObj;
328 ACPI_FUNCTION_TRACE ("UtDeleteInternalObjectList");
331 /* Walk the null-terminated internal list */
333 for (InternalObj = ObjList; *InternalObj; InternalObj++)
335 AcpiUtRemoveReference (*InternalObj);
338 /* Free the combined parameter pointer list and object array */
340 ACPI_MEM_FREE (ObjList);
345 /*******************************************************************************
347 * FUNCTION: AcpiUtUpdateRefCount
349 * PARAMETERS: *Object - Object whose ref count is to be updated
350 * Action - What to do
352 * RETURN: New ref count
354 * DESCRIPTION: Modify the ref count and return it.
356 ******************************************************************************/
359 AcpiUtUpdateRefCount (
360 ACPI_OPERAND_OBJECT *Object,
367 ACPI_FUNCTION_NAME ("UtUpdateRefCount");
375 Count = Object->Common.ReferenceCount;
379 * Reference count action (increment, decrement, or force delete)
387 Object->Common.ReferenceCount = NewCount;
389 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Obj %p Refs=%X, [Incremented]\n",
398 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Obj %p Refs=%X, can't decrement! (Set to 0)\n",
407 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Obj %p Refs=%X, [Decremented]\n",
411 if (ACPI_GET_OBJECT_TYPE (Object) == ACPI_TYPE_METHOD)
413 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Method Obj %p Refs=%X, [Decremented]\n",
417 Object->Common.ReferenceCount = NewCount;
420 AcpiUtDeleteInternalObj (Object);
426 case REF_FORCE_DELETE:
428 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Obj %p Refs=%X, Force delete! (Set to 0)\n",
432 Object->Common.ReferenceCount = NewCount;
433 AcpiUtDeleteInternalObj (Object);
439 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown action (%X)\n", Action));
444 * Sanity check the reference count, for debug purposes only.
445 * (A deleted object will have a huge reference count)
447 if (Count > ACPI_MAX_REFERENCE_COUNT)
450 ACPI_DEBUG_PRINT ((ACPI_DB_WARN,
451 "**** Warning **** Large Reference Count (%X) in object %p\n\n",
459 /*******************************************************************************
461 * FUNCTION: AcpiUtUpdateObjectReference
463 * PARAMETERS: *Object - Increment ref count for this object
464 * and all sub-objects
465 * Action - Either REF_INCREMENT or REF_DECREMENT or
470 * DESCRIPTION: Increment the object reference count
472 * Object references are incremented when:
473 * 1) An object is attached to a Node (namespace object)
474 * 2) An object is copied (all subobjects must be incremented)
476 * Object references are decremented when:
477 * 1) An object is detached from an Node
479 ******************************************************************************/
482 AcpiUtUpdateObjectReference (
483 ACPI_OPERAND_OBJECT *Object,
488 ACPI_OPERAND_OBJECT *Next;
489 ACPI_OPERAND_OBJECT *New;
490 ACPI_GENERIC_STATE *StateList = NULL;
491 ACPI_GENERIC_STATE *State;
494 ACPI_FUNCTION_TRACE_PTR ("UtUpdateObjectReference", Object);
497 /* Ignore a null object ptr */
501 return_ACPI_STATUS (AE_OK);
505 * Make sure that this isn't a namespace handle
507 if (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_NAMED)
509 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Object %p is NS handle\n", Object));
510 return_ACPI_STATUS (AE_OK);
513 State = AcpiUtCreateUpdateState (Object, Action);
517 Object = State->Update.Object;
518 Action = State->Update.Value;
519 AcpiUtDeleteGenericState (State);
522 * All sub-objects must have their reference count incremented also.
523 * Different object types have different subobjects.
525 switch (ACPI_GET_OBJECT_TYPE (Object))
527 case ACPI_TYPE_DEVICE:
529 Status = AcpiUtCreateUpdateStateAndPush (Object->Device.AddrHandler,
531 if (ACPI_FAILURE (Status))
536 AcpiUtUpdateRefCount (Object->Device.SysHandler, Action);
537 AcpiUtUpdateRefCount (Object->Device.DrvHandler, Action);
541 case ACPI_TYPE_LOCAL_ADDRESS_HANDLER:
543 /* Must walk list of address handlers */
545 Next = Object->AddrHandler.Next;
548 New = Next->AddrHandler.Next;
549 AcpiUtUpdateRefCount (Next, Action);
556 case ACPI_TYPE_PACKAGE:
559 * We must update all the sub-objects of the package
560 * (Each of whom may have their own sub-objects, etc.
562 for (i = 0; i < Object->Package.Count; i++)
565 * Push each element onto the stack for later processing.
566 * Note: There can be null elements within the package,
567 * these are simply ignored
569 Status = AcpiUtCreateUpdateStateAndPush (
570 Object->Package.Elements[i], Action, &StateList);
571 if (ACPI_FAILURE (Status))
579 case ACPI_TYPE_BUFFER_FIELD:
581 Status = AcpiUtCreateUpdateStateAndPush (
582 Object->BufferField.BufferObj, Action, &StateList);
583 if (ACPI_FAILURE (Status))
590 case ACPI_TYPE_LOCAL_REGION_FIELD:
592 Status = AcpiUtCreateUpdateStateAndPush (
593 Object->Field.RegionObj, Action, &StateList);
594 if (ACPI_FAILURE (Status))
601 case ACPI_TYPE_LOCAL_BANK_FIELD:
603 Status = AcpiUtCreateUpdateStateAndPush (
604 Object->BankField.BankObj, Action, &StateList);
605 if (ACPI_FAILURE (Status))
610 Status = AcpiUtCreateUpdateStateAndPush (
611 Object->BankField.RegionObj, Action, &StateList);
612 if (ACPI_FAILURE (Status))
619 case ACPI_TYPE_LOCAL_INDEX_FIELD:
621 Status = AcpiUtCreateUpdateStateAndPush (
622 Object->IndexField.IndexObj, Action, &StateList);
623 if (ACPI_FAILURE (Status))
628 Status = AcpiUtCreateUpdateStateAndPush (
629 Object->IndexField.DataObj, Action, &StateList);
630 if (ACPI_FAILURE (Status))
637 case ACPI_TYPE_REGION:
638 case ACPI_TYPE_LOCAL_REFERENCE:
646 * Now we can update the count in the main object. This can only
647 * happen after we update the sub-objects in case this causes the
648 * main object to be deleted.
650 AcpiUtUpdateRefCount (Object, Action);
652 /* Move on to the next object to be updated */
654 State = AcpiUtPopGenericState (&StateList);
657 return_ACPI_STATUS (AE_OK);
662 ACPI_REPORT_ERROR (("Could not update object reference count, %s\n",
663 AcpiFormatException (Status)));
665 return_ACPI_STATUS (Status);
669 /*******************************************************************************
671 * FUNCTION: AcpiUtAddReference
673 * PARAMETERS: *Object - Object whose reference count is to be
678 * DESCRIPTION: Add one reference to an ACPI object
680 ******************************************************************************/
684 ACPI_OPERAND_OBJECT *Object)
687 ACPI_FUNCTION_TRACE_PTR ("UtAddReference", Object);
691 * Ensure that we have a valid object
693 if (!AcpiUtValidInternalObject (Object))
699 * We have a valid ACPI internal object, now increment the reference count
701 (void) AcpiUtUpdateObjectReference (Object, REF_INCREMENT);
706 /*******************************************************************************
708 * FUNCTION: AcpiUtRemoveReference
710 * PARAMETERS: *Object - Object whose ref count will be decremented
714 * DESCRIPTION: Decrement the reference count of an ACPI internal object
716 ******************************************************************************/
719 AcpiUtRemoveReference (
720 ACPI_OPERAND_OBJECT *Object)
723 ACPI_FUNCTION_TRACE_PTR ("UtRemoveReference", Object);
726 * Allow a NULL pointer to be passed in, just ignore it. This saves
727 * each caller from having to check. Also, ignore NS nodes.
731 (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_NAMED))
738 * Ensure that we have a valid object
740 if (!AcpiUtValidInternalObject (Object))
745 ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Obj %p Refs=%X\n",
746 Object, Object->Common.ReferenceCount));
749 * Decrement the reference count, and only actually delete the object
750 * if the reference count becomes 0. (Must also decrement the ref count
751 * of all subobjects!)
753 (void) AcpiUtUpdateObjectReference (Object, REF_DECREMENT);