xref: /haiku/src/add-ons/kernel/bus_managers/acpi/acpica/components/utilities/utdelete.c (revision e6eaad8615c4734498b9b800847d18bbe62782fa)
1 /*******************************************************************************
2  *
3  * Module Name: utdelete - object deletion and reference count utilities
4  *
5  ******************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2013, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights. You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
21  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22  * copy of the source code appearing in this file ("Covered Code") an
23  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24  * base code distributed originally by Intel ("Original Intel Code") to copy,
25  * make derivatives, distribute, use and display any portion of the Covered
26  * Code in any form, with the right to sublicense such rights; and
27  *
28  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29  * license (with the right to sublicense), under only those claims of Intel
30  * patents that are infringed by the Original Intel Code, to make, use, sell,
31  * offer to sell, and import the Covered Code and derivative works thereof
32  * solely to the minimum extent necessary to exercise the above copyright
33  * license, and in no event shall the patent license extend to any additions
34  * to or modifications of the Original Intel Code. No other license or right
35  * is granted directly or by implication, estoppel or otherwise;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
42  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43  * Redistribution of source code of any substantial portion of the Covered
44  * Code or modification with rights to further distribute source must include
45  * the above Copyright Notice, the above License, this list of Conditions,
46  * and the following Disclaimer and Export Compliance provision. In addition,
47  * Licensee must cause all Covered Code to which Licensee contributes to
48  * contain a file documenting the changes Licensee made to create that Covered
49  * Code and the date of any change. Licensee must include in that file the
50  * documentation of any changes made by any predecessor Licensee. Licensee
51  * must include a prominent statement that the modification is derived,
52  * directly or indirectly, from Original Intel Code.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution. In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
75  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76  * Intel shall be used in advertising or otherwise to promote the sale, use or
77  * other dealings in products derived from or relating to the Covered Code
78  * without prior written authorization from Intel.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88  * PARTICULAR PURPOSE.
89  *
90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97  * LIMITED REMEDY.
98  *
99  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100  * software or system incorporating such software without first obtaining any
101  * required license or other approval from the U. S. Department of Commerce or
102  * any other agency or department of the United States Government. In the
103  * event Licensee exports any such software from the United States or
104  * re-exports any such software from a foreign destination, Licensee shall
105  * ensure that the distribution and export/re-export of the software is in
106  * compliance with all laws, regulations, orders, or other restrictions of the
107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108  * any of its subsidiaries will export/re-export any technical data, process,
109  * software, or service, directly or indirectly, to any country for which the
110  * United States government or any agency thereof requires an export license,
111  * other governmental approval, or letter of assurance, without first obtaining
112  * such license, approval or letter.
113  *
114  *****************************************************************************/
115 
116 #define __UTDELETE_C__
117 
118 #include "acpi.h"
119 #include "accommon.h"
120 #include "acinterp.h"
121 #include "acnamesp.h"
122 #include "acevents.h"
123 
124 
125 #define _COMPONENT          ACPI_UTILITIES
126         ACPI_MODULE_NAME    ("utdelete")
127 
128 /* Local prototypes */
129 
130 static void
131 AcpiUtDeleteInternalObj (
132     ACPI_OPERAND_OBJECT     *Object);
133 
134 static void
135 AcpiUtUpdateRefCount (
136     ACPI_OPERAND_OBJECT     *Object,
137     UINT32                  Action);
138 
139 
140 /*******************************************************************************
141  *
142  * FUNCTION:    AcpiUtDeleteInternalObj
143  *
144  * PARAMETERS:  Object         - Object to be deleted
145  *
146  * RETURN:      None
147  *
148  * DESCRIPTION: Low level object deletion, after reference counts have been
149  *              updated (All reference counts, including sub-objects!)
150  *
151  ******************************************************************************/
152 
153 static void
154 AcpiUtDeleteInternalObj (
155     ACPI_OPERAND_OBJECT     *Object)
156 {
157     void                    *ObjPointer = NULL;
158     ACPI_OPERAND_OBJECT     *HandlerDesc;
159     ACPI_OPERAND_OBJECT     *SecondDesc;
160     ACPI_OPERAND_OBJECT     *NextDesc;
161     ACPI_OPERAND_OBJECT     **LastObjPtr;
162 
163 
164     ACPI_FUNCTION_TRACE_PTR (UtDeleteInternalObj, Object);
165 
166 
167     if (!Object)
168     {
169         return_VOID;
170     }
171 
172     /*
173      * Must delete or free any pointers within the object that are not
174      * actual ACPI objects (for example, a raw buffer pointer).
175      */
176     switch (Object->Common.Type)
177     {
178     case ACPI_TYPE_STRING:
179 
180         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "**** String %p, ptr %p\n",
181             Object, Object->String.Pointer));
182 
183         /* Free the actual string buffer */
184 
185         if (!(Object->Common.Flags & AOPOBJ_STATIC_POINTER))
186         {
187             /* But only if it is NOT a pointer into an ACPI table */
188 
189             ObjPointer = Object->String.Pointer;
190         }
191         break;
192 
193     case ACPI_TYPE_BUFFER:
194 
195         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "**** Buffer %p, ptr %p\n",
196             Object, Object->Buffer.Pointer));
197 
198         /* Free the actual buffer */
199 
200         if (!(Object->Common.Flags & AOPOBJ_STATIC_POINTER))
201         {
202             /* But only if it is NOT a pointer into an ACPI table */
203 
204             ObjPointer = Object->Buffer.Pointer;
205         }
206         break;
207 
208     case ACPI_TYPE_PACKAGE:
209 
210         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, " **** Package of count %X\n",
211             Object->Package.Count));
212 
213         /*
214          * Elements of the package are not handled here, they are deleted
215          * separately
216          */
217 
218         /* Free the (variable length) element pointer array */
219 
220         ObjPointer = Object->Package.Elements;
221         break;
222 
223     /*
224      * These objects have a possible list of notify handlers.
225      * Device object also may have a GPE block.
226      */
227     case ACPI_TYPE_DEVICE:
228 
229         if (Object->Device.GpeBlock)
230         {
231             (void) AcpiEvDeleteGpeBlock (Object->Device.GpeBlock);
232         }
233 
234         /*lint -fallthrough */
235 
236     case ACPI_TYPE_PROCESSOR:
237     case ACPI_TYPE_THERMAL:
238 
239         /* Walk the address handler list for this object */
240 
241         HandlerDesc = Object->CommonNotify.Handler;
242         while (HandlerDesc)
243         {
244             NextDesc = HandlerDesc->AddressSpace.Next;
245             AcpiUtRemoveReference (HandlerDesc);
246             HandlerDesc = NextDesc;
247         }
248         break;
249 
250     case ACPI_TYPE_MUTEX:
251 
252         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
253             "***** Mutex %p, OS Mutex %p\n",
254             Object, Object->Mutex.OsMutex));
255 
256         if (Object == AcpiGbl_GlobalLockMutex)
257         {
258             /* Global Lock has extra semaphore */
259 
260             (void) AcpiOsDeleteSemaphore (AcpiGbl_GlobalLockSemaphore);
261             AcpiGbl_GlobalLockSemaphore = NULL;
262 
263             AcpiOsDeleteMutex (Object->Mutex.OsMutex);
264             AcpiGbl_GlobalLockMutex = NULL;
265         }
266         else
267         {
268             AcpiExUnlinkMutex (Object);
269             AcpiOsDeleteMutex (Object->Mutex.OsMutex);
270         }
271         break;
272 
273     case ACPI_TYPE_EVENT:
274 
275         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
276             "***** Event %p, OS Semaphore %p\n",
277             Object, Object->Event.OsSemaphore));
278 
279         (void) AcpiOsDeleteSemaphore (Object->Event.OsSemaphore);
280         Object->Event.OsSemaphore = NULL;
281         break;
282 
283     case ACPI_TYPE_METHOD:
284 
285         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
286             "***** Method %p\n", Object));
287 
288         /* Delete the method mutex if it exists */
289 
290         if (Object->Method.Mutex)
291         {
292             AcpiOsDeleteMutex (Object->Method.Mutex->Mutex.OsMutex);
293             AcpiUtDeleteObjectDesc (Object->Method.Mutex);
294             Object->Method.Mutex = NULL;
295         }
296         break;
297 
298     case ACPI_TYPE_REGION:
299 
300         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
301             "***** Region %p\n", Object));
302 
303         /*
304          * Update AddressRange list. However, only permanent regions
305          * are installed in this list. (Not created within a method)
306          */
307         if (!(Object->Region.Node->Flags & ANOBJ_TEMPORARY))
308         {
309             AcpiUtRemoveAddressRange (Object->Region.SpaceId,
310                 Object->Region.Node);
311         }
312 
313         SecondDesc = AcpiNsGetSecondaryObject (Object);
314         if (SecondDesc)
315         {
316             /*
317              * Free the RegionContext if and only if the handler is one of the
318              * default handlers -- and therefore, we created the context object
319              * locally, it was not created by an external caller.
320              */
321             HandlerDesc = Object->Region.Handler;
322             if (HandlerDesc)
323             {
324                 NextDesc = HandlerDesc->AddressSpace.RegionList;
325                 LastObjPtr = &HandlerDesc->AddressSpace.RegionList;
326 
327                 /* Remove the region object from the handler's list */
328 
329                 while (NextDesc)
330                 {
331                     if (NextDesc == Object)
332                     {
333                         *LastObjPtr = NextDesc->Region.Next;
334                         break;
335                     }
336 
337                     /* Walk the linked list of handler */
338 
339                     LastObjPtr = &NextDesc->Region.Next;
340                     NextDesc = NextDesc->Region.Next;
341                 }
342 
343                 if (HandlerDesc->AddressSpace.HandlerFlags &
344                     ACPI_ADDR_HANDLER_DEFAULT_INSTALLED)
345                 {
346                     /* Deactivate region and free region context */
347 
348                     if (HandlerDesc->AddressSpace.Setup)
349                     {
350                         (void) HandlerDesc->AddressSpace.Setup (Object,
351                             ACPI_REGION_DEACTIVATE,
352                             HandlerDesc->AddressSpace.Context,
353                             &SecondDesc->Extra.RegionContext);
354                     }
355                 }
356 
357                 AcpiUtRemoveReference (HandlerDesc);
358             }
359 
360             /* Now we can free the Extra object */
361 
362             AcpiUtDeleteObjectDesc (SecondDesc);
363         }
364         break;
365 
366     case ACPI_TYPE_BUFFER_FIELD:
367 
368         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
369             "***** Buffer Field %p\n", Object));
370 
371         SecondDesc = AcpiNsGetSecondaryObject (Object);
372         if (SecondDesc)
373         {
374             AcpiUtDeleteObjectDesc (SecondDesc);
375         }
376         break;
377 
378     case ACPI_TYPE_LOCAL_BANK_FIELD:
379 
380         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
381             "***** Bank Field %p\n", Object));
382 
383         SecondDesc = AcpiNsGetSecondaryObject (Object);
384         if (SecondDesc)
385         {
386             AcpiUtDeleteObjectDesc (SecondDesc);
387         }
388         break;
389 
390     default:
391 
392         break;
393     }
394 
395     /* Free any allocated memory (pointer within the object) found above */
396 
397     if (ObjPointer)
398     {
399         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Deleting Object Subptr %p\n",
400             ObjPointer));
401         ACPI_FREE (ObjPointer);
402     }
403 
404     /* Now the object can be safely deleted */
405 
406     ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS, "Deleting Object %p [%s]\n",
407         Object, AcpiUtGetObjectTypeName (Object)));
408 
409     AcpiUtDeleteObjectDesc (Object);
410     return_VOID;
411 }
412 
413 
414 /*******************************************************************************
415  *
416  * FUNCTION:    AcpiUtDeleteInternalObjectList
417  *
418  * PARAMETERS:  ObjList         - Pointer to the list to be deleted
419  *
420  * RETURN:      None
421  *
422  * DESCRIPTION: This function deletes an internal object list, including both
423  *              simple objects and package objects
424  *
425  ******************************************************************************/
426 
427 void
428 AcpiUtDeleteInternalObjectList (
429     ACPI_OPERAND_OBJECT     **ObjList)
430 {
431     ACPI_OPERAND_OBJECT     **InternalObj;
432 
433 
434     ACPI_FUNCTION_ENTRY ();
435 
436 
437     /* Walk the null-terminated internal list */
438 
439     for (InternalObj = ObjList; *InternalObj; InternalObj++)
440     {
441         AcpiUtRemoveReference (*InternalObj);
442     }
443 
444     /* Free the combined parameter pointer list and object array */
445 
446     ACPI_FREE (ObjList);
447     return;
448 }
449 
450 
451 /*******************************************************************************
452  *
453  * FUNCTION:    AcpiUtUpdateRefCount
454  *
455  * PARAMETERS:  Object          - Object whose ref count is to be updated
456  *              Action          - What to do (REF_INCREMENT or REF_DECREMENT)
457  *
458  * RETURN:      None. Sets new reference count within the object
459  *
460  * DESCRIPTION: Modify the reference count for an internal acpi object
461  *
462  ******************************************************************************/
463 
464 static void
465 AcpiUtUpdateRefCount (
466     ACPI_OPERAND_OBJECT     *Object,
467     UINT32                  Action)
468 {
469     UINT16                  OriginalCount;
470     UINT16                  NewCount = 0;
471     ACPI_CPU_FLAGS          LockFlags;
472 
473 
474     ACPI_FUNCTION_NAME (UtUpdateRefCount);
475 
476 
477     if (!Object)
478     {
479         return;
480     }
481 
482     /*
483      * Always get the reference count lock. Note: Interpreter and/or
484      * Namespace is not always locked when this function is called.
485      */
486     LockFlags = AcpiOsAcquireLock (AcpiGbl_ReferenceCountLock);
487     OriginalCount = Object->Common.ReferenceCount;
488 
489     /* Perform the reference count action (increment, decrement) */
490 
491     switch (Action)
492     {
493     case REF_INCREMENT:
494 
495         NewCount = OriginalCount + 1;
496         Object->Common.ReferenceCount = NewCount;
497         AcpiOsReleaseLock (AcpiGbl_ReferenceCountLock, LockFlags);
498 
499         /* The current reference count should never be zero here */
500 
501         if (!OriginalCount)
502         {
503             ACPI_WARNING ((AE_INFO,
504                 "Obj %p, Reference Count was zero before increment\n",
505                 Object));
506         }
507 
508         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
509             "Obj %p Type %.2X Refs %.2X [Incremented]\n",
510             Object, Object->Common.Type, NewCount));
511         break;
512 
513     case REF_DECREMENT:
514 
515         /* The current reference count must be non-zero */
516 
517         if (OriginalCount)
518         {
519             NewCount = OriginalCount - 1;
520             Object->Common.ReferenceCount = NewCount;
521         }
522 
523         AcpiOsReleaseLock (AcpiGbl_ReferenceCountLock, LockFlags);
524 
525         if (!OriginalCount)
526         {
527             ACPI_WARNING ((AE_INFO,
528                 "Obj %p, Reference Count is already zero, cannot decrement\n",
529                 Object));
530         }
531 
532         ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
533             "Obj %p Type %.2X Refs %.2X [Decremented]\n",
534             Object, Object->Common.Type, NewCount));
535 
536         /* Actually delete the object on a reference count of zero */
537 
538         if (NewCount == 0)
539         {
540             AcpiUtDeleteInternalObj (Object);
541         }
542         break;
543 
544     default:
545 
546         AcpiOsReleaseLock (AcpiGbl_ReferenceCountLock, LockFlags);
547         ACPI_ERROR ((AE_INFO, "Unknown Reference Count action (0x%X)",
548             Action));
549         return;
550     }
551 
552     /*
553      * Sanity check the reference count, for debug purposes only.
554      * (A deleted object will have a huge reference count)
555      */
556     if (NewCount > ACPI_MAX_REFERENCE_COUNT)
557     {
558         ACPI_WARNING ((AE_INFO,
559             "Large Reference Count (0x%X) in object %p, Type=0x%.2X",
560             NewCount, Object, Object->Common.Type));
561     }
562 }
563 
564 
565 /*******************************************************************************
566  *
567  * FUNCTION:    AcpiUtUpdateObjectReference
568  *
569  * PARAMETERS:  Object              - Increment ref count for this object
570  *                                    and all sub-objects
571  *              Action              - Either REF_INCREMENT or REF_DECREMENT
572  *
573  * RETURN:      Status
574  *
575  * DESCRIPTION: Increment the object reference count
576  *
577  * Object references are incremented when:
578  * 1) An object is attached to a Node (namespace object)
579  * 2) An object is copied (all subobjects must be incremented)
580  *
581  * Object references are decremented when:
582  * 1) An object is detached from an Node
583  *
584  ******************************************************************************/
585 
586 ACPI_STATUS
587 AcpiUtUpdateObjectReference (
588     ACPI_OPERAND_OBJECT     *Object,
589     UINT16                  Action)
590 {
591     ACPI_STATUS             Status = AE_OK;
592     ACPI_GENERIC_STATE      *StateList = NULL;
593     ACPI_OPERAND_OBJECT     *NextObject = NULL;
594     ACPI_OPERAND_OBJECT     *PrevObject;
595     ACPI_GENERIC_STATE      *State;
596     UINT32                  i;
597 
598 
599     ACPI_FUNCTION_NAME (UtUpdateObjectReference);
600 
601 
602     while (Object)
603     {
604         /* Make sure that this isn't a namespace handle */
605 
606         if (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_NAMED)
607         {
608             ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
609                 "Object %p is NS handle\n", Object));
610             return (AE_OK);
611         }
612 
613         /*
614          * All sub-objects must have their reference count incremented also.
615          * Different object types have different subobjects.
616          */
617         switch (Object->Common.Type)
618         {
619         case ACPI_TYPE_DEVICE:
620         case ACPI_TYPE_PROCESSOR:
621         case ACPI_TYPE_POWER:
622         case ACPI_TYPE_THERMAL:
623             /*
624              * Update the notify objects for these types (if present)
625              * Two lists, system and device notify handlers.
626              */
627             for (i = 0; i < ACPI_NUM_NOTIFY_TYPES; i++)
628             {
629                 PrevObject = Object->CommonNotify.NotifyList[i];
630                 while (PrevObject)
631                 {
632                     NextObject = PrevObject->Notify.Next[i];
633                     AcpiUtUpdateRefCount (PrevObject, Action);
634                     PrevObject = NextObject;
635                 }
636             }
637             break;
638 
639         case ACPI_TYPE_PACKAGE:
640             /*
641              * We must update all the sub-objects of the package,
642              * each of whom may have their own sub-objects.
643              */
644             for (i = 0; i < Object->Package.Count; i++)
645             {
646                 /*
647                  * Null package elements are legal and can be simply
648                  * ignored.
649                  */
650                 NextObject = Object->Package.Elements[i];
651                 if (!NextObject)
652                 {
653                     continue;
654                 }
655 
656                 switch (NextObject->Common.Type)
657                 {
658                 case ACPI_TYPE_INTEGER:
659                 case ACPI_TYPE_STRING:
660                 case ACPI_TYPE_BUFFER:
661                     /*
662                      * For these very simple sub-objects, we can just
663                      * update the reference count here and continue.
664                      * Greatly increases performance of this operation.
665                      */
666                     AcpiUtUpdateRefCount (NextObject, Action);
667                     break;
668 
669                 default:
670                     /*
671                      * For complex sub-objects, push them onto the stack
672                      * for later processing (this eliminates recursion.)
673                      */
674                     Status = AcpiUtCreateUpdateStateAndPush (
675                                  NextObject, Action, &StateList);
676                     if (ACPI_FAILURE (Status))
677                     {
678                         goto ErrorExit;
679                     }
680                     break;
681                 }
682             }
683             NextObject = NULL;
684             break;
685 
686         case ACPI_TYPE_BUFFER_FIELD:
687 
688             NextObject = Object->BufferField.BufferObj;
689             break;
690 
691         case ACPI_TYPE_LOCAL_REGION_FIELD:
692 
693             NextObject = Object->Field.RegionObj;
694             break;
695 
696         case ACPI_TYPE_LOCAL_BANK_FIELD:
697 
698             NextObject = Object->BankField.BankObj;
699             Status = AcpiUtCreateUpdateStateAndPush (
700                         Object->BankField.RegionObj, Action, &StateList);
701             if (ACPI_FAILURE (Status))
702             {
703                 goto ErrorExit;
704             }
705             break;
706 
707         case ACPI_TYPE_LOCAL_INDEX_FIELD:
708 
709             NextObject = Object->IndexField.IndexObj;
710             Status = AcpiUtCreateUpdateStateAndPush (
711                         Object->IndexField.DataObj, Action, &StateList);
712             if (ACPI_FAILURE (Status))
713             {
714                 goto ErrorExit;
715             }
716             break;
717 
718         case ACPI_TYPE_LOCAL_REFERENCE:
719             /*
720              * The target of an Index (a package, string, or buffer) or a named
721              * reference must track changes to the ref count of the index or
722              * target object.
723              */
724             if ((Object->Reference.Class == ACPI_REFCLASS_INDEX) ||
725                 (Object->Reference.Class== ACPI_REFCLASS_NAME))
726             {
727                 NextObject = Object->Reference.Object;
728             }
729             break;
730 
731         case ACPI_TYPE_REGION:
732         default:
733 
734             break; /* No subobjects for all other types */
735         }
736 
737         /*
738          * Now we can update the count in the main object. This can only
739          * happen after we update the sub-objects in case this causes the
740          * main object to be deleted.
741          */
742         AcpiUtUpdateRefCount (Object, Action);
743         Object = NULL;
744 
745         /* Move on to the next object to be updated */
746 
747         if (NextObject)
748         {
749             Object = NextObject;
750             NextObject = NULL;
751         }
752         else if (StateList)
753         {
754             State = AcpiUtPopGenericState (&StateList);
755             Object = State->Update.Object;
756             AcpiUtDeleteGenericState (State);
757         }
758     }
759 
760     return (AE_OK);
761 
762 
763 ErrorExit:
764 
765     ACPI_EXCEPTION ((AE_INFO, Status,
766         "Could not update object reference count"));
767 
768     /* Free any stacked Update State objects */
769 
770     while (StateList)
771     {
772         State = AcpiUtPopGenericState (&StateList);
773         AcpiUtDeleteGenericState (State);
774     }
775 
776     return (Status);
777 }
778 
779 
780 /*******************************************************************************
781  *
782  * FUNCTION:    AcpiUtAddReference
783  *
784  * PARAMETERS:  Object          - Object whose reference count is to be
785  *                                incremented
786  *
787  * RETURN:      None
788  *
789  * DESCRIPTION: Add one reference to an ACPI object
790  *
791  ******************************************************************************/
792 
793 void
794 AcpiUtAddReference (
795     ACPI_OPERAND_OBJECT     *Object)
796 {
797 
798     ACPI_FUNCTION_NAME (UtAddReference);
799 
800 
801     /* Ensure that we have a valid object */
802 
803     if (!AcpiUtValidInternalObject (Object))
804     {
805         return;
806     }
807 
808     ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
809         "Obj %p Current Refs=%X [To Be Incremented]\n",
810         Object, Object->Common.ReferenceCount));
811 
812     /* Increment the reference count */
813 
814     (void) AcpiUtUpdateObjectReference (Object, REF_INCREMENT);
815     return;
816 }
817 
818 
819 /*******************************************************************************
820  *
821  * FUNCTION:    AcpiUtRemoveReference
822  *
823  * PARAMETERS:  Object         - Object whose ref count will be decremented
824  *
825  * RETURN:      None
826  *
827  * DESCRIPTION: Decrement the reference count of an ACPI internal object
828  *
829  ******************************************************************************/
830 
831 void
832 AcpiUtRemoveReference (
833     ACPI_OPERAND_OBJECT     *Object)
834 {
835 
836     ACPI_FUNCTION_NAME (UtRemoveReference);
837 
838 
839     /*
840      * Allow a NULL pointer to be passed in, just ignore it. This saves
841      * each caller from having to check. Also, ignore NS nodes.
842      */
843     if (!Object ||
844         (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_NAMED))
845 
846     {
847         return;
848     }
849 
850     /* Ensure that we have a valid object */
851 
852     if (!AcpiUtValidInternalObject (Object))
853     {
854         return;
855     }
856 
857     ACPI_DEBUG_PRINT ((ACPI_DB_ALLOCATIONS,
858         "Obj %p Current Refs=%X [To Be Decremented]\n",
859         Object, Object->Common.ReferenceCount));
860 
861     /*
862      * Decrement the reference count, and only actually delete the object
863      * if the reference count becomes 0. (Must also decrement the ref count
864      * of all subobjects!)
865      */
866     (void) AcpiUtUpdateObjectReference (Object, REF_DECREMENT);
867     return;
868 }
869