]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOPMinformeeList.cpp
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 #include <IOKit/pwr_mgt/IOPM.h>
29 #include <IOKit/pwr_mgt/IOPMinformeeList.h>
30 #include <IOKit/pwr_mgt/IOPMinformee.h>
32 #define super OSObject
33 OSDefineMetaClassAndStructors(IOPMinformeeList
,OSObject
)
35 //*********************************************************************************
38 //*********************************************************************************
39 void IOPMinformeeList::initialize ( void )
45 //******************************************************************************
46 // getSharedRecursiveLock
48 //******************************************************************************
49 IORecursiveLock
*IOPMinformeeList::getSharedRecursiveLock( void )
51 static IORecursiveLock
*sharedListLock
= NULL
;
53 /* A running system could have 50-60+ instances of IOPMInformeeList.
54 * They'll share this lock, since list insertion and removal is relatively
55 * rare, and generally tied to major events like device discovery.
57 * getSharedRecursiveLock() is called from IOStartIOKit to initialize
58 * the sharedListLock before any IOPMinformeeLists are instantiated.
60 * The IOPMinformeeList class will be around for the lifetime of the system,
61 * we don't worry about freeing this lock.
64 if ( NULL
== sharedListLock
)
66 sharedListLock
= IORecursiveLockAlloc();
68 return sharedListLock
;
71 //*********************************************************************************
74 //*********************************************************************************
75 IOPMinformee
*IOPMinformeeList::appendNewInformee ( IOService
* newObject
)
77 IOPMinformee
* newInformee
;
82 newInformee
= IOPMinformee::withObject (newObject
);
87 if( IOPMNoErr
== addToList (newInformee
))
94 //*********************************************************************************
96 // *OBSOLETE* do not call from outside of this file.
97 // Try appendNewInformee() instead
98 //*********************************************************************************
99 IOReturn
IOPMinformeeList::addToList ( IOPMinformee
* newInformee
)
101 IOPMinformee
* nextInformee
;
102 IORecursiveLock
*listLock
= getSharedRecursiveLock();
105 return kIOReturnError
;
107 IORecursiveLockLock(listLock
);
108 nextInformee
= firstItem
;
110 // Is new object already in the list?
111 while ( nextInformee
!= NULL
)
113 if ( nextInformee
->whatObject
== newInformee
->whatObject
)
115 // object is present; just exit
116 goto unlock_and_exit
;
118 nextInformee
= nextInList(nextInformee
);
121 // add it to the front of the list
122 newInformee
->nextInList
= firstItem
;
123 firstItem
= newInformee
;
127 IORecursiveLockUnlock(listLock
);
132 //*********************************************************************************
135 // Find the item in the list, unlink it, and free it.
136 //*********************************************************************************
138 IOReturn
IOPMinformeeList::removeFromList ( IOService
* theItem
)
140 IOPMinformee
* item
= firstItem
;
142 IORecursiveLock
*listLock
= getSharedRecursiveLock();
147 return kIOReturnError
;
149 IORecursiveLockLock( listLock
);
151 if ( item
->whatObject
== theItem
)
153 firstItem
= item
->nextInList
;
156 goto unlock_and_exit
;
159 while ( item
->nextInList
!= NULL
)
161 if ( item
->nextInList
->whatObject
== theItem
)
163 temp
= item
->nextInList
;
164 item
->nextInList
= temp
->nextInList
;
167 goto unlock_and_exit
;
169 item
= item
->nextInList
;
173 IORecursiveLockUnlock(listLock
);
178 //*********************************************************************************
181 //*********************************************************************************
183 IOPMinformee
* IOPMinformeeList::firstInList ( void )
188 //*********************************************************************************
191 //*********************************************************************************
193 IOPMinformee
* IOPMinformeeList::nextInList ( IOPMinformee
* currentItem
)
195 if ( currentItem
!= NULL
) {
196 return (currentItem
->nextInList
);
201 //*********************************************************************************
204 //*********************************************************************************
206 unsigned long IOPMinformeeList::numberOfItems ( void )
211 //*********************************************************************************
214 // Look through the list for the one which points to the object identified
215 // by the parameter. Return a pointer to the list item or NULL.
216 //*********************************************************************************
218 IOPMinformee
* IOPMinformeeList::findItem ( IOService
* driverOrChild
)
220 IOPMinformee
* nextObject
;
222 nextObject
= firstInList();
223 while ( nextObject
!= NULL
) {
224 if ( nextObject
->whatObject
== driverOrChild
) {
227 nextObject
= nextInList(nextObject
);
234 //*********************************************************************************
237 // Free all items in the list, and then free the list itself
238 //*********************************************************************************
240 void IOPMinformeeList::free (void )
242 IOPMinformee
* next
= firstItem
;
244 while ( next
!= NULL
) {
245 firstItem
= next
->nextInList
;