1 /*******************************************************************************
3 * Module Name: cmdelete - object deletion and reference count utilities
6 ******************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999, 2000, 2001, 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 *****************************************************************************/
117 #define __CMDELETE_C__
120 #include "acinterp.h"
121 #include "acnamesp.h"
122 #include "actables.h"
123 #include "acparser.h"
125 #define _COMPONENT MISCELLANEOUS
126 MODULE_NAME ("cmdelete")
129 /*******************************************************************************
131 * FUNCTION: AcpiCmDeleteInternalObj
133 * PARAMETERS: *Object - Pointer to the list to be deleted
137 * DESCRIPTION: Low level object deletion, after reference counts have been
138 * updated (All reference counts, including sub-objects!)
140 ******************************************************************************/
143 AcpiCmDeleteInternalObj (
144 ACPI_OPERAND_OBJECT *Object)
146 void *ObjPointer = NULL;
147 ACPI_OPERAND_OBJECT *HandlerDesc;
150 FUNCTION_TRACE_PTR ("CmDeleteInternalObj", Object);
159 * Must delete or free any pointers within the object that are not
160 * actual ACPI objects (for example, a raw buffer pointer).
163 switch (Object->Common.Type)
166 case ACPI_TYPE_STRING:
168 DEBUG_PRINT (ACPI_INFO,
169 ("CmDeleteInternalObj: **** String %p, ptr %p\n",
170 Object, Object->String.Pointer));
172 /* Free the actual string buffer */
174 ObjPointer = Object->String.Pointer;
178 case ACPI_TYPE_BUFFER:
180 DEBUG_PRINT (ACPI_INFO,
181 ("CmDeleteInternalObj: **** Buffer %p, ptr %p\n",
182 Object, Object->Buffer.Pointer));
184 /* Free the actual buffer */
186 ObjPointer = Object->Buffer.Pointer;
190 case ACPI_TYPE_PACKAGE:
192 DEBUG_PRINT (ACPI_INFO,
193 ("CmDeleteInternalObj: **** Package of count %X\n",
194 Object->Package.Count));
197 * Elements of the package are not handled here, they are deleted
201 /* Free the (variable length) element pointer array */
203 ObjPointer = Object->Package.Elements;
207 case ACPI_TYPE_MUTEX:
209 DEBUG_PRINT (ACPI_INFO,
210 ("CmDeleteInternalObj: ***** Mutex %p, Semaphore %p\n",
211 Object, Object->Mutex.Semaphore));
213 AcpiOsDeleteSemaphore (Object->Mutex.Semaphore);
217 case ACPI_TYPE_EVENT:
219 DEBUG_PRINT (ACPI_INFO,
220 ("CmDeleteInternalObj: ***** Event %p, Semaphore %p\n",
221 Object, Object->Event.Semaphore));
223 AcpiOsDeleteSemaphore (Object->Event.Semaphore);
224 Object->Event.Semaphore = NULL;
228 case ACPI_TYPE_METHOD:
230 DEBUG_PRINT (ACPI_INFO,
231 ("CmDeleteInternalObj: ***** Method %p\n", Object));
233 /* Delete the method semaphore if it exists */
235 if (Object->Method.Semaphore)
237 AcpiOsDeleteSemaphore (Object->Method.Semaphore);
238 Object->Method.Semaphore = NULL;
244 case ACPI_TYPE_REGION:
246 DEBUG_PRINT (ACPI_INFO,
247 ("CmDeleteInternalObj: ***** Region %p\n",
251 if (Object->Region.Extra)
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 == ADDR_HANDLER_DEFAULT_INSTALLED))
262 ObjPointer = Object->Region.Extra->Extra.RegionContext;
265 /* Now we can free the Extra object */
267 AcpiCmDeleteObjectDesc (Object->Region.Extra);
272 case ACPI_TYPE_FIELD_UNIT:
274 DEBUG_PRINT (ACPI_INFO,
275 ("CmDeleteInternalObj: ***** FieldUnit %p\n",
278 if (Object->FieldUnit.Extra)
280 AcpiCmDeleteObjectDesc (Object->FieldUnit.Extra);
290 * Delete any allocated memory found above
295 if (!AcpiTbSystemTablePointer (ObjPointer))
297 DEBUG_PRINT (ACPI_INFO,
298 ("CmDeleteInternalObj: Deleting Obj Ptr %p \n", ObjPointer));
300 AcpiCmFree (ObjPointer);
305 /* Only delete the object if it was dynamically allocated */
307 if (Object->Common.Flags & AOPOBJ_STATIC_ALLOCATION)
309 DEBUG_PRINT (ACPI_INFO,
310 ("CmDeleteInternalObj: Object %p [%s] static allocation, no delete\n",
311 Object, AcpiCmGetTypeName (Object->Common.Type)));
314 if (!(Object->Common.Flags & AOPOBJ_STATIC_ALLOCATION))
316 DEBUG_PRINT (ACPI_INFO,
317 ("CmDeleteInternalObj: Deleting object %p [%s]\n",
318 Object, AcpiCmGetTypeName (Object->Common.Type)));
320 AcpiCmDeleteObjectDesc (Object);
328 /*******************************************************************************
330 * FUNCTION: AcpiCmDeleteInternalObjectList
332 * PARAMETERS: *ObjList - Pointer to the list to be deleted
334 * RETURN: Status - the status of the call
336 * DESCRIPTION: This function deletes an internal object list, including both
337 * simple objects and package objects
339 ******************************************************************************/
342 AcpiCmDeleteInternalObjectList (
343 ACPI_OPERAND_OBJECT **ObjList)
345 ACPI_OPERAND_OBJECT **InternalObj;
348 FUNCTION_TRACE ("CmDeleteInternalObjectList");
351 /* Walk the null-terminated internal list */
353 for (InternalObj = ObjList; *InternalObj; InternalObj++)
356 * Check for a package
357 * Simple objects are simply stored in the array and do not
358 * need to be deleted separately.
361 if (IS_THIS_OBJECT_TYPE ((*InternalObj), ACPI_TYPE_PACKAGE))
363 /* Delete the package */
366 * TBD: [Investigate] This might not be the right thing to do,
367 * depending on how the internal package object was allocated!!!
369 AcpiCmDeleteInternalObj (*InternalObj);
374 /* Free the combined parameter pointer list and object array */
376 AcpiCmFree (ObjList);
378 return_ACPI_STATUS (AE_OK);
382 /*******************************************************************************
384 * FUNCTION: AcpiCmUpdateRefCount
386 * PARAMETERS: *Object - Object whose ref count is to be updated
387 * Action - What to do
389 * RETURN: New ref count
391 * DESCRIPTION: Modify the ref count and return it.
393 ******************************************************************************/
396 AcpiCmUpdateRefCount (
397 ACPI_OPERAND_OBJECT *Object,
410 Count = Object->Common.ReferenceCount;
414 * Reference count action (increment, decrement, or force delete)
423 Object->Common.ReferenceCount = NewCount;
425 DEBUG_PRINT (ACPI_INFO,
426 ("CmUpdateRefCount: Obj %p Refs=%X, [Incremented]\n",
435 DEBUG_PRINT (ACPI_INFO,
436 ("CmUpdateRefCount: Obj %p Refs=%X, can't decrement! (Set to 0)\n",
446 DEBUG_PRINT (ACPI_INFO,
447 ("CmUpdateRefCount: Obj %p Refs=%X, [Decremented]\n",
451 if (Object->Common.Type == ACPI_TYPE_METHOD)
453 DEBUG_PRINT (ACPI_INFO,
454 ("CmUpdateRefCount: Method Obj %p Refs=%X, [Decremented]\n",
458 Object->Common.ReferenceCount = NewCount;
461 AcpiCmDeleteInternalObj (Object);
467 case REF_FORCE_DELETE:
469 DEBUG_PRINT (ACPI_INFO,
470 ("CmUpdateRefCount: Obj %p Refs=%X, Force delete! (Set to 0)\n",
474 Object->Common.ReferenceCount = NewCount;
475 AcpiCmDeleteInternalObj (Object);
481 DEBUG_PRINT (ACPI_ERROR,
482 ("CmUpdateRefCount: Unknown action (%X)\n", Action));
488 * Sanity check the reference count, for debug purposes only.
489 * (A deleted object will have a huge reference count)
492 if (Count > MAX_REFERENCE_COUNT)
495 DEBUG_PRINT (ACPI_ERROR,
496 ("CmUpdateRefCount: **** AE_ERROR **** Invalid Reference Count (%X) in object %p\n\n",
504 /*******************************************************************************
506 * FUNCTION: AcpiCmUpdateObjectReference
508 * PARAMETERS: *Object - Increment ref count for this object
509 * and all sub-objects
510 * Action - Either REF_INCREMENT or REF_DECREMENT or
515 * DESCRIPTION: Increment the object reference count
517 * Object references are incremented when:
518 * 1) An object is attached to a Node (namespace object)
519 * 2) An object is copied (all subobjects must be incremented)
521 * Object references are decremented when:
522 * 1) An object is detached from an Node
524 ******************************************************************************/
527 AcpiCmUpdateObjectReference (
528 ACPI_OPERAND_OBJECT *Object,
533 ACPI_OPERAND_OBJECT *Next;
534 ACPI_OPERAND_OBJECT *New;
535 ACPI_GENERIC_STATE *StateList = NULL;
536 ACPI_GENERIC_STATE *State;
539 FUNCTION_TRACE_PTR ("CmUpdateObjectReference", Object);
542 /* Ignore a null object ptr */
546 return_ACPI_STATUS (AE_OK);
551 * Make sure that this isn't a namespace handle or an AML pointer
554 if (VALID_DESCRIPTOR_TYPE (Object, ACPI_DESC_TYPE_NAMED))
556 DEBUG_PRINT (ACPI_INFO,
557 ("CmUpdateObjectReference: Object %p is NS handle\n",
559 return_ACPI_STATUS (AE_OK);
562 if (AcpiTbSystemTablePointer (Object))
564 DEBUG_PRINT (ACPI_INFO,
565 ("CmUpdateObjectReference: **** Object %p is Pcode Ptr\n",
567 return_ACPI_STATUS (AE_OK);
571 State = AcpiCmCreateUpdateState (Object, Action);
576 Object = State->Update.Object;
577 Action = State->Update.Value;
578 AcpiCmDeleteGenericState (State);
581 * All sub-objects must have their reference count incremented also.
582 * Different object types have different subobjects.
584 switch (Object->Common.Type)
587 case ACPI_TYPE_DEVICE:
589 Status = AcpiCmCreateUpdateStateAndPush (Object->Device.AddrHandler,
591 if (ACPI_FAILURE (Status))
593 return_ACPI_STATUS (Status);
596 AcpiCmUpdateRefCount (Object->Device.SysHandler, Action);
597 AcpiCmUpdateRefCount (Object->Device.DrvHandler, Action);
601 case INTERNAL_TYPE_ADDRESS_HANDLER:
603 /* Must walk list of address handlers */
605 Next = Object->AddrHandler.Next;
608 New = Next->AddrHandler.Next;
609 AcpiCmUpdateRefCount (Next, Action);
616 case ACPI_TYPE_PACKAGE:
619 * We must update all the sub-objects of the package
620 * (Each of whom may have their own sub-objects, etc.
622 for (i = 0; i < Object->Package.Count; i++)
625 * Push each element onto the stack for later processing.
626 * Note: There can be null elements within the package,
627 * these are simply ignored
630 Status = AcpiCmCreateUpdateStateAndPush (
631 Object->Package.Elements[i], Action, &StateList);
632 if (ACPI_FAILURE (Status))
634 return_ACPI_STATUS (Status);
640 case ACPI_TYPE_FIELD_UNIT:
642 Status = AcpiCmCreateUpdateStateAndPush (
643 Object->FieldUnit.Container, Action, &StateList);
645 if (ACPI_FAILURE (Status))
647 return_ACPI_STATUS (Status);
652 case INTERNAL_TYPE_DEF_FIELD:
654 Status = AcpiCmCreateUpdateStateAndPush (
655 Object->Field.Container, Action, &StateList);
656 if (ACPI_FAILURE (Status))
658 return_ACPI_STATUS (Status);
663 case INTERNAL_TYPE_BANK_FIELD:
665 Status = AcpiCmCreateUpdateStateAndPush (
666 Object->BankField.BankSelect, Action, &StateList);
667 if (ACPI_FAILURE (Status))
669 return_ACPI_STATUS (Status);
672 Status = AcpiCmCreateUpdateStateAndPush (
673 Object->BankField.Container, Action, &StateList);
674 if (ACPI_FAILURE (Status))
676 return_ACPI_STATUS (Status);
681 case ACPI_TYPE_REGION:
683 /* TBD: [Investigate]
684 AcpiCmUpdateRefCount (Object->Region.AddrHandler, Action);
688 AcpiCmCreateUpdateStateAndPush (Object->Region.AddrHandler,
690 if (ACPI_FAILURE (Status))
692 return_ACPI_STATUS (Status);
698 case INTERNAL_TYPE_REFERENCE:
705 * Now we can update the count in the main object. This can only
706 * happen after we update the sub-objects in case this causes the
707 * main object to be deleted.
710 AcpiCmUpdateRefCount (Object, Action);
713 /* Move on to the next object to be updated */
715 State = AcpiCmPopGenericState (&StateList);
719 return_ACPI_STATUS (AE_OK);
723 /*******************************************************************************
725 * FUNCTION: AcpiCmAddReference
727 * PARAMETERS: *Object - Object whose reference count is to be
732 * DESCRIPTION: Add one reference to an ACPI object
734 ******************************************************************************/
738 ACPI_OPERAND_OBJECT *Object)
741 FUNCTION_TRACE_PTR ("CmAddReference", Object);
745 * Ensure that we have a valid object
748 if (!AcpiCmValidInternalObject (Object))
754 * We have a valid ACPI internal object, now increment the reference count
757 AcpiCmUpdateObjectReference (Object, REF_INCREMENT);
763 /*******************************************************************************
765 * FUNCTION: AcpiCmRemoveReference
767 * PARAMETERS: *Object - Object whose ref count will be decremented
771 * DESCRIPTION: Decrement the reference count of an ACPI internal object
773 ******************************************************************************/
776 AcpiCmRemoveReference (
777 ACPI_OPERAND_OBJECT *Object)
780 FUNCTION_TRACE_PTR ("CmRemoveReference", Object);
784 * Ensure that we have a valid object
787 if (!AcpiCmValidInternalObject (Object))
792 DEBUG_PRINT (ACPI_INFO, ("CmRemoveReference: Obj %p Refs=%X\n",
793 Object, Object->Common.ReferenceCount));
796 * Decrement the reference count, and only actually delete the object
797 * if the reference count becomes 0. (Must also decrement the ref count
798 * of all subobjects!)
801 AcpiCmUpdateObjectReference (Object, REF_DECREMENT);