xref: /xnu-8792.81.2/iokit/IOKit/IOService.h (revision 19c3b8c28c31cb8130e034cfb5df6bf9ba342d90) !
1 /*
2  * Copyright (c) 1998-2020 Apple Inc. All rights reserved.
3  *
4  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5  *
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.
14  *
15  * Please obtain a copy of the License at
16  * http://www.opensource.apple.com/apsl/ and read it before using this file.
17  *
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.
25  *
26  * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27  */
28 /*
29  * Copyright (c) 1998,1999 Apple Computer, Inc.  All rights reserved.
30  *
31  * HISTORY
32  *
33  */
34 /*!
35  *   @header
36  *   This header contains the definition of the IOService class.  IOService is the sole direct subclass of IORegistryEntry and is the base class of almost all I/O Kit family superclasses.  IOService defines methods that support the life cycle of I/O Kit drivers.  For more information on IOService, see {@linkdoc //apple_ref/doc/uid/TP0000011 I/O Kit Fundamentals}.
37  *
38  *   @seealso //apple_ref/doc/header/IORegistryEntry.h IORegistryEntry
39  */
40 
41 #ifndef _IOKIT_IOSERVICE_H
42 #define _IOKIT_IOSERVICE_H
43 
44 #include <IOKit/IORegistryEntry.h>
45 #include <IOKit/IOReturn.h>
46 #include <IOKit/IODeviceMemory.h>
47 #include <IOKit/IONotifier.h>
48 #include <IOKit/IOLocks.h>
49 
50 #include <IOKit/IOKitDebug.h>
51 #include <IOKit/IOInterrupts.h>
52 
53 #include <IOKit/pwr_mgt/IOPMpowerState.h>
54 #include <IOKit/IOServicePM.h>
55 #include <IOKit/IOReportTypes.h>
56 #include <DriverKit/IOService.h>
57 #include <libkern/c++/OSPtr.h>
58 
59 #if __cplusplus >= 201703L
60 extern "C++" {
61 #include <libkern/c++/OSSharedPtr.h>
62 }
63 #endif
64 
65 extern "C" {
66 #include <kern/thread_call.h>
67 }
68 
69 
70 #ifndef UINT64_MAX
71 #define UINT64_MAX        18446744073709551615ULL
72 #endif
73 
74 
75 enum {
76 	kIODefaultProbeScore    = 0
77 };
78 
79 // masks for getState()
80 enum {
81 	kIOServiceInactiveState = 0x00000001,
82 	kIOServiceRegisteredState   = 0x00000002,
83 	kIOServiceMatchedState  = 0x00000004,
84 	kIOServiceFirstPublishState = 0x00000008,
85 	kIOServiceFirstMatchState   = 0x00000010,
86 	kIOServiceReservedMatchState   = 0x80000000,
87 #if XNU_KERNEL_PRIVATE
88 	kIOServiceUserInvisibleMatchState = kIOServiceReservedMatchState,
89 #endif /* XNU_KERNEL_PRIVATE */
90 };
91 
92 enum {
93 	// options for registerService()
94 	kIOServiceExclusive     = 0x00000001,
95 
96 	// options for terminate()
97 	kIOServiceRequired      = 0x00000001,
98 	kIOServiceTerminate     = 0x00000004,
99 	kIOServiceTerminateWithRematch = 0x00000010,
100 	kIOServiceTerminateWithRematchCurrentDext = 0x00000020,
101 
102 	// options for registerService() & terminate()
103 	kIOServiceSynchronous   = 0x00000002,
104 	// options for registerService()
105 	kIOServiceAsynchronous  = 0x00000008
106 };
107 
108 // options for open()
109 enum {
110 	kIOServiceSeize     = 0x00000001,
111 	kIOServiceFamilyOpenOptions = 0xffff0000
112 };
113 
114 // options for close()
115 enum {
116 	kIOServiceFamilyCloseOptions = 0xffff0000
117 };
118 
119 typedef void * IONotificationRef;
120 
121 extern const IORegistryPlane *  gIOServicePlane;
122 extern const IORegistryPlane *  gIOPowerPlane;
123 
124 extern const OSSymbol *     gIOResourcesKey;
125 extern const OSSymbol *     gIOResourceMatchKey;
126 extern const OSSymbol *     gIOResourceMatchedKey;
127 extern const OSSymbol *     gIOResourceIOKitKey;
128 
129 extern const OSSymbol *     gIOProviderClassKey;
130 extern const OSSymbol *     gIONameMatchKey;
131 extern const OSSymbol *     gIONameMatchedKey;
132 extern const OSSymbol *     gIOPropertyMatchKey;
133 extern const OSSymbol *     gIOPropertyExistsMatchKey;
134 extern const OSSymbol *     gIOLocationMatchKey;
135 extern const OSSymbol *     gIOParentMatchKey;
136 extern const OSSymbol *     gIOPathMatchKey;
137 extern const OSSymbol *     gIOMatchCategoryKey;
138 extern const OSSymbol *     gIODefaultMatchCategoryKey;
139 extern const OSSymbol *     gIOMatchedServiceCountKey;
140 extern const OSSymbol *     gIOMatchedPersonalityKey;
141 extern const OSSymbol *     gIORematchPersonalityKey;
142 extern const OSSymbol *     gIORematchCountKey;
143 extern const OSSymbol *     gIODEXTMatchCountKey;
144 
145 extern const OSSymbol *     gIOUserClientClassKey;
146 
147 extern const OSSymbol *     gIOUserClassKey;
148 extern const OSSymbol *     gIOUserClassesKey;
149 extern const OSSymbol *     gIOUserServerClassKey;
150 extern const OSSymbol *     gIOUserServerNameKey;
151 extern const OSSymbol *     gIOUserServerTagKey;
152 extern const OSSymbol *     gIOUserUserClientKey;
153 extern const OSSymbol *     gIOAssociatedServicesKey;
154 extern const OSSymbol *     gIOUserServerPreserveUserspaceRebootKey;
155 
156 extern const OSSymbol *     gIOKitDebugKey;
157 extern const OSSymbol *     gIOServiceKey;
158 
159 extern const OSSymbol *     gIOCommandPoolSizeKey;
160 
161 extern const OSSymbol *     gIOPublishNotification;
162 extern const OSSymbol *     gIOFirstPublishNotification;
163 extern const OSSymbol *     gIOMatchedNotification;
164 extern const OSSymbol *     gIOFirstMatchNotification;
165 extern const OSSymbol *     gIOTerminatedNotification;
166 extern const OSSymbol *     gIOWillTerminateNotification;
167 
168 extern const OSSymbol *     gIOGeneralInterest;
169 extern const OSSymbol *     gIOBusyInterest;
170 extern const OSSymbol *     gIOOpenInterest;
171 extern const OSSymbol *     gIOAppPowerStateInterest;
172 extern const OSSymbol *     gIOPriorityPowerStateInterest;
173 extern const OSSymbol *     gIOConsoleSecurityInterest;
174 
175 extern const OSSymbol *     gIODeviceMemoryKey;
176 extern const OSSymbol *     gIOInterruptControllersKey;
177 extern const OSSymbol *     gIOInterruptSpecifiersKey;
178 
179 extern const OSSymbol *     gIOSupportedPropertiesKey;
180 extern const OSSymbol *     gIOUserServicePropertiesKey;
181 extern const OSSymbol *     gIOCompatibilityMatchKey;
182 extern const OSSymbol *     gIOCompatibilityPropertiesKey;
183 extern const OSSymbol *     gIOPathKey;
184 
185 extern const OSSymbol *     gIOBSDKey;
186 extern const OSSymbol *     gIOBSDNameKey;
187 extern const OSSymbol *     gIOBSDMajorKey;
188 extern const OSSymbol *     gIOBSDMinorKey;
189 extern const OSSymbol *     gIOBSDUnitKey;
190 
191 extern const OSSymbol *     gIOUserClientEntitlementsKey;
192 extern const OSSymbol *     gIODriverKitEntitlementKey;
193 extern const OSSymbol *     gIOServiceDEXTEntitlementsKey;
194 extern const OSSymbol *     gIODriverKitUserClientEntitlementsKey;
195 extern const OSSymbol *     gIODriverKitUserClientEntitlementAllowAnyKey;
196 extern const OSSymbol *     gIODriverKitRequiredEntitlementsKey;
197 extern const OSSymbol *     gIODriverKitTestDriverEntitlementKey;
198 extern const OSSymbol *     gIODriverKitUserClientEntitlementCommunicatesWithDriversKey;
199 extern const OSSymbol *     gIODriverKitUserClientEntitlementAllowThirdPartyUserClientsKey;
200 extern const OSSymbol *     gIOMatchDeferKey;
201 
202 extern const OSSymbol *     gIOAllCPUInitializedKey;
203 
204 #if XNU_KERNEL_PRIVATE && !defined(IOServiceTrace)
205 
206 #include <IOKit/IOTimeStamp.h>
207 #if (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD)
208 #define IOServiceTrace(csc, a, b, c, d) do {                            \
209     if(kIOTraceIOService & gIOKitTrace) {                               \
210 	KERNEL_DEBUG_CONSTANT(IODBG_IOSERVICE(csc), a, b, c, d, 0);     \
211     }                                                                   \
212 } while(0)
213 #else /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
214 #define IOServiceTrace(csc, a, b, c, d) do {    \
215   (void)a;                                      \
216   (void)b;                                      \
217   (void)c;                                      \
218   (void)d;                                      \
219 } while (0)
220 #endif /* (KDEBUG_LEVEL >= KDEBUG_LEVEL_STANDARD) */
221 
222 #endif // XNU_KERNEL_PRIVATE && !IOServiceTrace
223 
224 extern SInt32 IOServiceOrdering( const OSMetaClassBase * inObj1, const OSMetaClassBase * inObj2, void * ref );
225 
226 typedef void (*IOInterruptAction)( OSObject * target, void * refCon,
227     IOService * nub, int source );
228 
229 #ifdef __BLOCKS__
230 typedef void (^IOInterruptActionBlock)(IOService * nub, int source);
231 typedef kern_return_t (^IOStateNotificationHandler)(void);
232 #endif /* __BLOCKS__ */
233 
234 typedef void * IOStateNotificationListenerRef;
235 class IOStateNotificationItem;
236 
237 /*! @typedef IOServiceNotificationHandler
238  *   @param target Reference supplied when the notification was registered.
239  *   @param refCon Reference constant supplied when the notification was registered.
240  *   @param newService The IOService object the notification is delivering. It is retained for the duration of the handler's invocation and doesn't need to be released by the handler. */
241 
242 typedef bool (*IOServiceNotificationHandler)( void * target, void * refCon,
243     IOService * newService );
244 
245 typedef bool (*IOServiceMatchingNotificationHandler)( void * target, void * refCon,
246     IOService * newService,
247     IONotifier * notifier );
248 
249 #ifdef __BLOCKS__
250 typedef bool (^IOServiceMatchingNotificationHandlerBlock)(IOService * newService,
251     IONotifier * notifier );
252 #endif /* __BLOCKS__ */
253 
254 
255 /*! @typedef IOServiceInterestHandler
256  *   @param target Reference supplied when the notification was registered.
257  *   @param refCon Reference constant supplied when the notification was registered.
258  *   @param messageType Type of the message - IOKit defined in IOKit/IOMessage.h or family specific.
259  *   @param provider The IOService object who is delivering the notification. It is retained for the duration of the handler's invocation and doesn't need to be released by the handler.
260  *   @param messageArgument An argument for message, dependent on its type.
261  *   @param argSize Non zero if the argument represents a struct of that size, used when delivering messages outside the kernel. */
262 
263 typedef IOReturn (*IOServiceInterestHandler)( void * target, void * refCon,
264     UInt32 messageType, IOService * provider,
265     void * messageArgument, vm_size_t argSize );
266 
267 #ifdef __BLOCKS__
268 typedef IOReturn (^IOServiceInterestHandlerBlock)( uint32_t messageType, IOService * provider,
269     void   * messageArgument, size_t argSize );
270 #endif /* __BLOCKS__ */
271 
272 typedef void (*IOServiceApplierFunction)(IOService * service, void * context);
273 typedef void (*OSObjectApplierFunction)(OSObject * object, void * context);
274 #ifdef __BLOCKS__
275 typedef void (^IOServiceApplierBlock)(IOService * service);
276 typedef void (^OSObjectApplierBlock)(OSObject * object);
277 #endif /* __BLOCKS__ */
278 
279 
280 class IOUserClient;
281 class IOPlatformExpert;
282 class IOUserServerCheckInToken;
283 
284 /*! @class IOService
285  *   @abstract The base class for most I/O Kit families, devices, and drivers.
286  *   @discussion The IOService base class defines APIs used to publish services, instantiate other services based on the existance of a providing service (ie. driver stacking), destroy a service and its dependent stack, notify interested parties of service state changes, and general utility functions useful across all families.
287  *
288  *  Types of service are specified with a matching dictionary that describes properties of the service. For example, a matching dictionary might describe any IOUSBDevice (or subclass), an IOUSBDevice with a certain class code, or a IOPCIDevice with a set of matching names or device & vendor IDs. Since the matching dictionary is interpreted by the family which created the service, as well as generically by IOService, the list of properties considered for matching depends on the familiy.
289  *
290  *  Matching dictionaries are associated with IOService classes by the catalogue, as driver property tables, and also supplied by clients of the notification APIs.
291  *
292  *  IOService provides matching based on C++ class (via OSMetaClass dynamic casting), registry entry name, a registry path to the service (which includes device tree paths), a name assigned by BSD, or by its location (its point of attachment).
293  *
294  *  <br><br>Driver Instantiation by IOService<br><br>
295  *
296  *  Drivers are subclasses of IOService, and their availability is managed through the catalogue. They are instantiated based on the publication of an IOService they use (for example, an IOPCIDevice or IOUSBDevice), or when they are added to  the catalogue and the IOService(s) they use are already available.
297  *
298  *  When an IOService (the "provider") is published with the @link registerService registerService@/link method, the matching and probing process begins, which is always single threaded per provider. A list of matching dictionaries from the catalog and installed publish notification requests, that successfully match the IOService, is constructed, with ordering supplied by <code>kIOProbeScoreKey</code> ("IOProbeScore") property in the dictionary, or supplied with the notification.
299  *
300  *  Each entry in the list is then processed in order - for notifications, the notification is delivered, for driver property tables a lot more happens.
301  *
302  *  The driver class is instantiated and <code>init()</code> called with its property table. The new driver instance is then attached to the provider, and has its @link probe probe@/link method called with the provider as an argument. The default <code>probe</code> method does nothing but return success, but a driver may implement this method to interrogate the provider to make sure it can work with it. It may also modify its probe score at this time. After probe, the driver is detached and the next in the list is considered (ie. attached, probed, and detached).
303  *
304  *  When the probing phase is complete, the list consists of successfully probed drivers, in order of their probe score (after adjustment during the @link probe probe@/link call). The list is then divided into categories based on the <code>kIOMatchCategoryKey</code> property ("IOMatchCategory"); drivers without a match category are all considered in one default category. Match categories allow multiple clients of a provider to be attached and started, though the provider may also enforce open/close semantics to gain active access to it.
305  *
306  *  For each category, the highest scoring driver in that category is attached to the provider, and its @link start start@/link method called. If <code>start</code> is successful, the rest of the drivers in the same match category are discarded, otherwise the next highest scoring driver is started, and so on.
307  *
308  *  The driver should only consider itself in action when the start method is called, meaning it has been selected for use on the provider, and consuming that particular match category. It should also be prepared to be allocated, probed and freed even if the probe was successful.
309  *
310  *  After the drivers have all synchronously been started, the installed "matched" notifications that match the registered IOService are delivered.
311  *
312  *  <br><br>Properties used by IOService<br><br>
313  *
314  *   <code>kIOClassKey, extern const OSSymbol * gIOClassKey, "IOClass"</code>
315  *  <br>
316  *  <br>
317  *  Class of the driver to instantiate on matching providers.
318  *  <br>
319  *  <br>
320  *   <code>kIOProviderClassKey, extern const OSSymbol * gIOProviderClassKey, "IOProviderClass"</code>
321  *  <br>
322  *  <br>
323  *  Class of the provider(s) to be considered for matching, checked with OSDynamicCast so subclasses will also match.
324  *  <br>
325  *  <br>
326  *   <code>kIOProbeScoreKey, extern const OSSymbol * gIOProbeScoreKey, "IOProbeScore"</code>
327  *  <br>
328  *  <br>
329  *  The probe score initially used to order multiple matching drivers.
330  *  <br>
331  *  <br>
332  *   <code>kIOMatchCategoryKey, extern const OSSymbol * gIOMatchCategoryKey, "IOMatchCategory"</code>
333  *  <br>
334  *  <br>
335  *  A string defining the driver category for matching purposes. All drivers with no <code>IOMatchCategory</code> property are considered to be in the same default category. Only one driver in a category can be started on each provider.
336  *  <br>
337  *  <br>
338  *   <code>kIONameMatchKey, extern const OSSymbol * gIONameMatchKey, "IONameMatch"</code>
339  *  <br>
340  *  A string or collection of strings that match the provider's name. The comparison is implemented with the @link //apple_ref/cpp/instm/IORegistryEntry/compareNames/virtualbool/(OSObject*,OSString**) IORegistryEntry::compareNames@/link method, which supports a single string, or any collection (OSArray, OSSet, OSDictionary etc.) of strings. IOService objects with device tree properties (eg. IOPCIDevice) will also be matched based on that standard's "compatible", "name", "device_type" properties. The matching name will be left in the driver's property table in the <code>kIONameMatchedKey</code> property.
341  *  <br>
342  *  Examples
343  *  <pre>
344  *  @textblock
345  *   <key>IONameMatch</key>
346  *   <string>pci106b,7</string>
347  *  @/textblock
348  *  </pre>
349  *
350  *  For a list of possible matching names, a serialized array of strings should used, eg.
351  *  <pre>
352  *  @textblock
353  *   <key>IONameMatch</key>
354  *   <array>
355  *       <string>APPL,happy16</string>
356  *       <string>pci106b,7</string>
357  *   </array>
358  *  @/textblock
359  *  </pre>
360  *
361  *  <br>
362  *   <code>kIONameMatchedKey, extern const OSSymbol * gIONameMatchedKey, "IONameMatched"</code>
363  *  <br>
364  *  The name successfully matched name from the <code>kIONameMatchKey</code> property will be left in the driver's property table as the <code>kIONameMatchedKey</code> property.
365  *  <br>
366  *  <br>
367  *   <code>kIOPropertyMatchKey, extern const OSSymbol * gIOPropertyMatchKey, "IOPropertyMatch"</code>
368  *  <br>
369  *  A dictionary of properties that each must exist in the matching IOService and compare successfully with the <code>isEqualTo</code> method.
370  *
371  *  <pre>
372  *  @textblock
373  *   <key>IOPropertyMatch</key>
374  *   <dictionary>
375  *       <key>APPL,happy16</key>
376  *       <string>APPL,meek8</string>
377  *   </dictionary>
378  *  @/textblock
379  *  </pre>
380  *
381  *  <br>
382  *   <code>kIOUserClientClassKey, extern const OSSymbol * gIOUserClientClassKey, "IOUserClientClass"</code>
383  *  <br>
384  *  The class name that the service will attempt to allocate when a user client connection is requested.  First the device nub is queried, then the nub's provider is queried by default.
385  *  <br>
386  *  <br>
387  *   <code>kIOKitDebugKey, extern const OSSymbol * gIOKitDebugKey, "IOKitDebug"</code>
388  *  <br>
389  *  Set some debug flags for logging the driver loading process. Flags are defined in <code>IOKit/IOKitDebug.h</code>, but <code>65535</code> works well.*/
390 
391 struct IOInterruptAccountingData;
392 struct IOInterruptAccountingReporter;
393 struct OSObjectUserVars;
394 struct IOServiceStateChangeVars;
395 struct IOInterruptSourcePrivate;
396 
397 class IOService : public IORegistryEntry
398 {
399 	OSDeclareDefaultStructorsWithDispatch(IOService);
400 
401 #if XNU_KERNEL_PRIVATE
402 public:
403 #else
404 protected:
405 #endif  /* XNU_KERNEL_PRIVATE */
406 /*! @struct ExpansionData
407  *   @discussion This structure will be used to expand the capablilties of this class in the future.
408  */
409 	struct ExpansionData {
410 		uint64_t authorizationID;
411 		/*
412 		 * Variables associated with interrupt accounting.  Consists of an array
413 		 * (that pairs reporters with opaque "statistics" objects), the count for
414 		 * the array, and a lock to guard both of the former variables.  The lock
415 		 * is necessary as IOReporting will not update reports in a manner that is
416 		 * synchonized with the service (i.e, on a workloop).
417 		 */
418 		IOLock * interruptStatisticsLock;
419 		IOInterruptAccountingReporter * interruptStatisticsArray;
420 		int interruptStatisticsArrayCount;
421 
422 		OSObjectUserVars * uvars;
423 		IOServiceStateChangeVars * svars;
424 
425 		IOInterruptSourcePrivate * interruptSourcesPrivate;
426 	};
427 
428 /*! @var reserved
429  *   Reserved for future use.  (Internal use only)  */
430 	APPLE_KEXT_WSHADOW_PUSH;
431 	ExpansionData * reserved;
432 	APPLE_KEXT_WSHADOW_POP;
433 
434 private:
435 	IOService *     __provider;
436 	SInt32      __providerGeneration;
437 	IOService *     __owner;
438 	IOOptionBits    __state[2];
439 	uint64_t        __timeBusy;
440 	uint64_t        __accumBusy;
441 	IOServicePM *   pwrMgt;
442 
443 protected:
444 // TRUE once PMinit has been called
445 	bool            initialized;
446 
447 public:
448 // DEPRECATED
449 	void *          pm_vars;
450 
451 public:
452 /* methods available in Mac OS X 10.1 or later */
453 /*! @function requestTerminate
454  *   @abstract Passes a termination up the stack.
455  *   @discussion When an IOService is made inactive the default behavior is to also make any of its clients that have it as their only provider also inactive, in this way recursing the termination up the driver stack. This method allows an IOService object to override this behavior. Returning <code>true</code> from this method when passed a just terminated provider will cause the client to also be terminated.
456  *   @param provider The terminated provider of this object.
457  *   @param options Options originally passed to terminate, plus <code>kIOServiceRecursing</code>.
458  *   @result <code>true</code> if this object should be terminated now that its provider has been. */
459 
460 	virtual bool requestTerminate( IOService * provider, IOOptionBits options );
461 
462 /*! @function willTerminate
463  *   @abstract Passes a termination up the stack.
464  *   @discussion Notification that a provider has been terminated, sent before recursing up the stack, in root-to-leaf order.
465  *   @param provider The terminated provider of this object.
466  *   @param options Options originally passed to terminate.
467  *   @result <code>true</code>. */
468 
469 	virtual bool willTerminate( IOService * provider, IOOptionBits options );
470 
471 /*! @function didTerminate
472  *   @abstract Passes a termination up the stack.
473  *   @discussion Notification that a provider has been terminated, sent after recursing up the stack, in leaf-to-root order.
474  *   @param provider The terminated provider of this object.
475  *   @param options Options originally passed to terminate.
476  *   @param defer If there is pending I/O that requires this object to persist, and the provider is not opened by this object set <code>defer</code> to <code>true</code> and call the <code>IOService::didTerminate()</code> implementation when the I/O completes. Otherwise, leave <code>defer</code> set to its default value of <code>false</code>.
477  *   @result <code>true</code>. */
478 
479 	virtual bool didTerminate( IOService * provider, IOOptionBits options, bool * defer );
480 
481 /*! @function nextIdleTimeout
482  *   @availability Mac OS X v10.4 and later
483  *   @abstract Allows subclasses to customize idle power management behavior.
484  *   @discussion Returns the next time that the device should idle into its next lower power state. Subclasses may override for custom idle behavior.
485  *
486  *   A power managed driver might override this method to provide a more sophisticated idle power off algorithm than the one defined by power management.
487  *   @param currentTime The current time
488  *   @param lastActivity The time of last activity on this device
489  *   @param powerState The device's current power state.
490  *   @result Returns the next time the device should idle off (in seconds, relative to the current time). */
491 
492 	virtual SInt32 nextIdleTimeout(AbsoluteTime currentTime,
493 	    AbsoluteTime lastActivity, unsigned int powerState);
494 
495 /*! @function systemWillShutdown
496  *   @availability Mac OS X v10.5 and later
497  *   @abstract Notifies members of the power plane of system shutdown and restart.
498  *   @discussion This function is called for all members of the power plane in leaf-to-root order. If a subclass needs to wait for a pending I/O, then the call to <code>systemWillShutdown</code> should be postponed until the I/O completes.
499  *
500  *   Any power managed driver (which has called @link joinPMtree joinPMtree@/link to join the power plane) interested in taking action at system shutdown or restart should override this method.
501  *   @param specifier <code>kIOMessageSystemWillPowerOff</code> or <code>kIOMessageSystemWillRestart</code>. */
502 
503 	virtual void systemWillShutdown( IOOptionBits specifier );
504 
505 /*! @function copyClientWithCategory
506  *   @availability Mac OS X v10.6 and later
507  *   @param category An OSSymbol corresponding to an IOMatchCategory matching property.
508  *   @result Returns a reference to the IOService child with the given category. The result should be released by the caller.
509  */
510 
511 	virtual IOService * copyClientWithCategory( const OSSymbol * category );
512 
513 public:
514 /*! @function       configureReport
515  *   @abstract       configure IOReporting channels
516  *   @availability   SPI on OS X v10.9 / iOS 7 and later
517  *
518  *   @param  channels    - channels to configure
519  *   @param  action      - enable/disable/size, etc
520  *   @param  result      - action-specific returned value
521  *   @param  destination - action-specific default destination
522  */
523 	virtual IOReturn configureReport(IOReportChannelList   *channels,
524 	    IOReportConfigureAction action,
525 	    void                  *result,
526 	    void                  *destination);
527 
528 /*! @function       updateReport
529  *   @abstract       request current data for the specified channels
530  *   @availability   SPI on OS X 10.9 / iOS 7 and later
531  *
532  *   @param channels     - channels to be updated
533  *   @param action       - type/style of update
534  *   @param result       - returned details about what was updated
535  *   @param destination  - destination for this update (action-specific)
536  */
537 	virtual IOReturn updateReport(IOReportChannelList      *channels,
538 	    IOReportUpdateAction      action,
539 	    void                     *result,
540 	    void                     *destination);
541 
542 protected:
543 
544 	/* these are helper methods for DriverKit */
545 	IOReturn _ConfigureReport(IOReportChannelList   *channels,
546 	    IOReportConfigureAction action,
547 	    void                  *result,
548 	    void                  *destination);
549 	IOReturn _UpdateReport(IOReportChannelList      *channels,
550 	    IOReportUpdateAction      action,
551 	    void                     *result,
552 	    void                     *destination);
553 
554 private:
555 #if __LP64__
556 	OSMetaClassDeclareReservedUsedX86(IOService, 0);
557 	OSMetaClassDeclareReservedUsedX86(IOService, 1);
558 	OSMetaClassDeclareReservedUnused(IOService, 2);
559 	OSMetaClassDeclareReservedUnused(IOService, 3);
560 	OSMetaClassDeclareReservedUnused(IOService, 4);
561 	OSMetaClassDeclareReservedUnused(IOService, 5);
562 	OSMetaClassDeclareReservedUnused(IOService, 6);
563 	OSMetaClassDeclareReservedUnused(IOService, 7);
564 #else
565 	OSMetaClassDeclareReservedUsedX86(IOService, 0);
566 	OSMetaClassDeclareReservedUsedX86(IOService, 1);
567 	OSMetaClassDeclareReservedUsedX86(IOService, 2);
568 	OSMetaClassDeclareReservedUsedX86(IOService, 3);
569 	OSMetaClassDeclareReservedUsedX86(IOService, 4);
570 	OSMetaClassDeclareReservedUsedX86(IOService, 5);
571 	OSMetaClassDeclareReservedUsedX86(IOService, 6);
572 	OSMetaClassDeclareReservedUsedX86(IOService, 7);
573 #endif
574 
575 	OSMetaClassDeclareReservedUnused(IOService, 8);
576 	OSMetaClassDeclareReservedUnused(IOService, 9);
577 	OSMetaClassDeclareReservedUnused(IOService, 10);
578 	OSMetaClassDeclareReservedUnused(IOService, 11);
579 	OSMetaClassDeclareReservedUnused(IOService, 12);
580 	OSMetaClassDeclareReservedUnused(IOService, 13);
581 	OSMetaClassDeclareReservedUnused(IOService, 14);
582 	OSMetaClassDeclareReservedUnused(IOService, 15);
583 	OSMetaClassDeclareReservedUnused(IOService, 16);
584 	OSMetaClassDeclareReservedUnused(IOService, 17);
585 	OSMetaClassDeclareReservedUnused(IOService, 18);
586 	OSMetaClassDeclareReservedUnused(IOService, 19);
587 	OSMetaClassDeclareReservedUnused(IOService, 20);
588 	OSMetaClassDeclareReservedUnused(IOService, 21);
589 	OSMetaClassDeclareReservedUnused(IOService, 22);
590 	OSMetaClassDeclareReservedUnused(IOService, 23);
591 	OSMetaClassDeclareReservedUnused(IOService, 24);
592 	OSMetaClassDeclareReservedUnused(IOService, 25);
593 	OSMetaClassDeclareReservedUnused(IOService, 26);
594 	OSMetaClassDeclareReservedUnused(IOService, 27);
595 	OSMetaClassDeclareReservedUnused(IOService, 28);
596 	OSMetaClassDeclareReservedUnused(IOService, 29);
597 	OSMetaClassDeclareReservedUnused(IOService, 30);
598 	OSMetaClassDeclareReservedUnused(IOService, 31);
599 	OSMetaClassDeclareReservedUnused(IOService, 32);
600 	OSMetaClassDeclareReservedUnused(IOService, 33);
601 	OSMetaClassDeclareReservedUnused(IOService, 34);
602 	OSMetaClassDeclareReservedUnused(IOService, 35);
603 	OSMetaClassDeclareReservedUnused(IOService, 36);
604 	OSMetaClassDeclareReservedUnused(IOService, 37);
605 	OSMetaClassDeclareReservedUnused(IOService, 38);
606 	OSMetaClassDeclareReservedUnused(IOService, 39);
607 	OSMetaClassDeclareReservedUnused(IOService, 40);
608 	OSMetaClassDeclareReservedUnused(IOService, 41);
609 	OSMetaClassDeclareReservedUnused(IOService, 42);
610 	OSMetaClassDeclareReservedUnused(IOService, 43);
611 	OSMetaClassDeclareReservedUnused(IOService, 44);
612 	OSMetaClassDeclareReservedUnused(IOService, 45);
613 	OSMetaClassDeclareReservedUnused(IOService, 46);
614 	OSMetaClassDeclareReservedUnused(IOService, 47);
615 
616 public:
617 /*! @function getState
618  *   @abstract Accessor for IOService state bits, not normally needed or used outside IOService.
619  *   @result State bits for the IOService, eg. <code>kIOServiceInactiveState</code>, <code>kIOServiceRegisteredState</code>. */
620 
621 	virtual IOOptionBits getState( void ) const;
622 
623 /*! @function isInactive
624  *   @abstract Checks if the IOService object has been terminated, and is in the process of being destroyed.
625  *   @discussion When an IOService object is successfully terminated, it is immediately made inactive, which blocks further attach()es, matching or notifications occuring on the object. It remains inactive until the last client closes, and is then finalized and destroyed.
626  *   @result <code>true</code> if the IOService object has been terminated. */
627 
628 	bool isInactive( void ) const;
629 
630 /* Stack creation */
631 
632 /*! @function registerService
633  *   @abstract Starts the registration process for a newly discovered IOService object.
634  *   @discussion This function allows an IOService subclass to be published and made available to possible clients, by starting the registration process and delivering notifications to registered clients. The object should be completely setup and ready to field requests from clients before <code>registerService</code> is called.
635  *   @param options The default zero options mask is recommended and should be used in most cases. The registration process is usually asynchronous, with possible driver probing and notification occurring some time later. <code>kIOServiceSynchronous</code> may be passed to carry out the matching and notification process for currently registered clients before returning to the caller. */
636 
637 	virtual void registerService( IOOptionBits options = 0 );
638 
639 /*! @function probe
640  *   @abstract During an IOService object's instantiation, probes a matched service to see if it can be used.
641  *   @discussion The registration process for an IOService object (the provider) includes instantiating possible driver clients. The <code>probe</code> method is called in the client instance to check the matched service can be used before the driver is considered to be started. Since matching screens many possible providers, in many cases the <code>probe</code> method can be left unimplemented by IOService subclasses. The client is already attached to the provider when <code>probe</code> is called.
642  *   @param provider The registered IOService object that matches a driver personality's matching dictionary.
643  *   @param score Pointer to the current driver's probe score, which is used to order multiple matching drivers in the same match category. It defaults to the value of the <code>IOProbeScore</code> property in the drivers property table, or <code>kIODefaultProbeScore</code> if none is specified. The <code>probe</code> method may alter the score to affect start order.
644  *   @result An IOService instance or zero when the probe is unsuccessful. In almost all cases the value of <code>this</code> is returned on success. If another IOService object is returned, the probed instance is detached and freed, and the returned instance is used in its stead for <code>start</code>. */
645 
646 	virtual LIBKERN_RETURNS_NOT_RETAINED IOService * probe(  IOService *     provider,
647 	    SInt32    *     score );
648 
649 /*! @function start
650  *   @abstract During an IOService object's instantiation, starts the IOService object that has been selected to run on the provider.
651  *   @discussion The <code>start</code> method of an IOService instance is called by its provider when it has been selected (due to its probe score and match category) as the winning client. The client is already attached to the provider when <code>start</code> is called.<br>Implementations of <code>start</code> must call <code>start</code> on their superclass at an appropriate point. If an implementation of <code>start</code> has already called <code>super::start</code> but subsequently determines that it will fail, it must call <code>super::stop</code> to balance the prior call to <code>super::start</code> and prevent reference leaks.
652  *   @result <code>true</code> if the start was successful; <code>false</code> otherwise (which will cause the instance to be detached and usually freed). */
653 
654 	virtual bool start( IOService * provider );
655 
656 /*! @function stop
657  *   @abstract During an IOService termination, the stop method is called in its clients before they are detached & it is destroyed.
658  *   @discussion The termination process for an IOService (the provider) will call stop in each of its clients, after they have closed the provider if they had it open, or immediately on termination. */
659 
660 	virtual void stop( IOService * provider );
661 
662 /* Open / Close */
663 
664 /*! @function open
665  *   @abstract Requests active access to a provider.
666  *   @discussion IOService provides generic open and close semantics to track clients of a provider that have established an active datapath. The use of <code>open</code> and @link close close@/link, and rules regarding ownership are family defined, and defined by the @link handleOpen handleOpen@/link and @link handleClose handleClose@/link methods in the provider. Some families will limit access to a provider based on its open state.
667  *   @param forClient Designates the client of the provider requesting the open.
668  *   @param options Options for the open. The provider family may implement options for open; IOService defines only <code>kIOServiceSeize</code> to request the device be withdrawn from its current owner.
669  *   @param arg Family specific arguments which are ignored by IOService.
670  *   @result <code>true</code> if the open was successful; <code>false</code> otherwise. */
671 
672 	virtual bool open(   IOService *       forClient,
673 	    IOOptionBits      options = 0,
674 	    void *        arg = NULL );
675 
676 /*! @function close
677  *   @abstract Releases active access to a provider.
678  *   @discussion IOService provides generic open and close semantics to track clients of a provider that have established an active datapath. The use of @link open open@/link and <code>close</code>, and rules regarding ownership are family defined, and defined by the @link handleOpen handleOpen@/link and @link handleClose handleClose@/link methods in the provider.
679  *   @param forClient Designates the client of the provider requesting the close.
680  *   @param options Options available for the close. The provider family may implement options for close; IOService defines none. */
681 
682 	virtual void close(  IOService *       forClient,
683 	    IOOptionBits      options = 0 );
684 
685 /*! @function isOpen
686  *   @abstract Determines whether a specific, or any, client has an IOService object open.
687  *   @discussion Returns the open state of an IOService object with respect to the specified client, or when it is open by any client.
688  *   @param forClient If non-zero, <code>isOpen</code> returns the open state for that client. If zero is passed, <code>isOpen</code> returns the open state for all clients.
689  *   @result <code>true</code> if the specific, or any, client has the IOService object open. */
690 
691 	virtual bool isOpen( const IOService * forClient = NULL ) const;
692 
693 /*! @function handleOpen
694  *   @abstract Controls the open / close behavior of an IOService object (overrideable by subclasses).
695  *   @discussion IOService calls this method in its subclasses in response to the @link open open@/link method, so the subclass may implement the request. The default implementation provides single owner access to an IOService object via <code>open</code>. The object is locked via @link lockForArbitration lockForArbitration@/link before <code>handleOpen</code> is called.
696  *   @param forClient Designates the client of the provider requesting the open.
697  *   @param options Options for the open, may be interpreted by the implementor of <code>handleOpen</code>.
698  *   @result <code>true</code>if the open was successful; <code>false</code> otherwise. */
699 
700 	virtual bool handleOpen(    IOService *   forClient,
701 	    IOOptionBits      options,
702 	    void *        arg );
703 
704 /*! @function handleClose
705  *   @abstract Controls the open / close behavior of an IOService object (overrideable by subclasses).
706  *   @discussion IOService calls this method in its subclasses in response to the @link close close@/link method, so the subclass may implement the request. The default implementation provides single owner access to an IOService object via @link open open@/link. The object is locked via @link lockForArbitration lockForArbitration@/link before <code>handleClose</code> is called.
707  *   @param forClient Designates the client of the provider requesting the close.
708  *   @param options Options for the close, may be interpreted by the implementor of @link handleOpen handleOpen@/link. */
709 
710 	virtual void handleClose(   IOService *       forClient,
711 	    IOOptionBits      options );
712 
713 /*! @function handleIsOpen
714  *   @abstract Controls the open / close behavior of an IOService object (overrideable by subclasses).
715  *   @discussion IOService calls this method in its subclasses in response to the @link open open@/link method, so the subclass may implement the request. The default implementation provides single owner access to an IOService object via @link open open@/link. The object is locked via @link lockForArbitration lockForArbitration@/link before <code>handleIsOpen</code> is called.
716  *   @param forClient If non-zero, <code>isOpen</code> returns the open state for that client. If zero is passed, <code>isOpen</code> returns the open state for all clients.
717  *   @result <code>true</code> if the specific, or any, client has the IOService object open. */
718 
719 	virtual bool handleIsOpen(  const IOService * forClient ) const;
720 
721 /* Stacking change */
722 
723 /*! @function terminate
724  *   @abstract Makes an IOService object inactive and begins its destruction.
725  *   @discussion Registering an IOService object informs possible clients of its existance and instantiates drivers that may be used with it; <code>terminate</code> involves the opposite process of informing clients that an IOService object is no longer able to be used and will be destroyed. By default, if any client has the service open, <code>terminate</code> fails. If the <code>kIOServiceRequired</code> flag is passed however, <code>terminate</code> will be successful though further progress in the destruction of the IOService object will not proceed until the last client has closed it. The service will be made inactive immediately upon successful termination, and all its clients will be notified via their @link message message@/link method with a message of type <code>kIOMessageServiceIsTerminated</code>. Both these actions take place on the caller's thread. After the IOService object is made inactive, further matching or attach calls will fail on it. Each client has its @link stop stop@/link method called upon their close of an inactive IOService object , or on its termination if they do not have it open. After <code>stop</code>, @link detach detach@/link is called in each client. When all clients have been detached, the @link finalize finalize@/link method is called in the inactive service. The termination process is inherently asynchronous because it will be deferred until all clients have chosen to close.
726  *   @param options In most cases no options are needed. <code>kIOServiceSynchronous</code> may be passed to cause <code>terminate</code> to not return until the service is finalized. */
727 
728 	virtual bool terminate( IOOptionBits options = 0 );
729 
730 /*! @function finalize
731  *   @abstract Finalizes the destruction of an IOService object.
732  *   @discussion The <code>finalize</code> method is called in an inactive (ie. terminated) IOService object after the last client has detached. IOService's implementation will call @link stop stop@/link, @link close close@/link, and @link detach detach@/link on each provider. When <code>finalize</code> returns, the object's retain count will have no references generated by IOService's registration process.
733  *   @param options The options passed to the @link terminate terminate@/link method of the IOService object are passed on to <code>finalize</code>.
734  *   @result <code>true</code>. */
735 
736 	virtual bool finalize( IOOptionBits options );
737 
738 /*! @function init
739  *   @abstract Initializes generic IOService data structures (expansion data, etc). */
740 	virtual bool init( OSDictionary * dictionary = NULL ) APPLE_KEXT_OVERRIDE;
741 
742 /*! @function init
743  *   @abstract Initializes generic IOService data structures (expansion data, etc). */
744 	virtual bool init( IORegistryEntry * from,
745 	    const IORegistryPlane * inPlane ) APPLE_KEXT_OVERRIDE;
746 
747 /*! @function free
748  *   @abstract Frees data structures that were allocated when power management was initialized on this service. */
749 
750 	virtual void free( void ) APPLE_KEXT_OVERRIDE;
751 
752 /*! @function lockForArbitration
753  *   @abstract Locks an IOService object against changes in state or ownership.
754  *   @discussion The registration, termination and open / close functions of IOService use <code>lockForArbtration</code> to single-thread access to an IOService object. <code>lockForArbitration</code> grants recursive access to the same thread.
755  *   @param isSuccessRequired If a request for access to an IOService object should be denied if it is terminated, pass <code>false</code>, otherwise pass <code>true</code>. */
756 
757 	virtual bool lockForArbitration( bool isSuccessRequired = true );
758 
759 /*! @function unlockForArbitration
760  *   @abstract Unlocks an IOService obkect after a successful @link lockForArbitration lockForArbitration@/link.
761  *   @discussion A thread granted exclusive access to an IOService object should release it with <code>unlockForArbitration</code>. */
762 
763 	virtual void unlockForArbitration( void );
764 
765 #ifdef XNU_KERNEL_PRIVATE
766 	static uint32_t isLockedForArbitration(IOService * service);
767 #endif /* XNU_KERNEL_PRIVATE */
768 
769 
770 /*! @function terminateClient
771  *   @abstract Passes a termination up the stack.
772  *   @discussion When an IOService object is made inactive the default behavior is to also make any of its clients that have it as their only provider inactive, in this way recursing the termination up the driver stack. This method allows a terminated  IOService object to override this behavior. Note the client may also override this behavior by overriding its @link terminate terminate@/link method.
773  *   @param client The client of the terminated provider.
774  *   @param options Options originally passed to @link terminate terminate@/link, plus <code>kIOServiceRecursing</code>.
775  *   @result result of the terminate request on the client. */
776 
777 	virtual bool terminateClient( IOService * client, IOOptionBits options );
778 
779 /* Busy state indicates discovery, matching or termination is in progress */
780 
781 /*! @function getBusyState
782  *   @abstract Returns the <code>busyState</code> of an IOService object.
783  *   @discussion Many activities in IOService are asynchronous. When registration, matching, or termination is in progress on an IOService object, its <code>busyState</code> is increased by one. Change in <code>busyState</code> to or from zero also changes the IOService object's provider's <code>busyState</code> by one, which means that an IOService object is marked busy when any of the above activities is ocurring on it or any of its clients.
784  *   @result The <code>busyState</code> value. */
785 
786 	virtual UInt32 getBusyState( void );
787 
788 /*! @function adjustBusy
789  *   @abstract Adjusts the <code>busyState</code> of an IOService object.
790  *   @discussion Applies a delta to an IOService object's <code>busyState</code>. A change in the <code>busyState</code> to or from zero will change the IOService object's provider's <code>busyState</code> by one (in the same direction).
791  *   @param delta The delta to be applied to the IOService object's <code>busyState</code>. */
792 
793 	virtual void adjustBusy( SInt32 delta );
794 
795 #ifdef XNU_KERNEL_PRIVATE
796 /*! @function waitQuietWithOptions
797  *   @abstract Waits for an IOService object's <code>busyState</code> to be zero.
798  *   @discussion Blocks the caller until an IOService object is non busy.
799  *   @param timeout The maximum time to wait in nanoseconds. Default is to wait forever.
800  *   @param options Options to configure behavior of this call
801  *   @result Returns an error code if Mach synchronization primitives fail, <code>kIOReturnTimeout</code>, or <code>kIOReturnSuccess</code>. */
802 
803 	IOReturn waitQuietWithOptions(uint64_t timeout = UINT64_MAX, IOOptionBits options = 0);
804 #endif /* XNU_KERNEL_PRIVATE */
805 
806 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
807 	IOReturn waitQuiet(mach_timespec_t * timeout)
808 	APPLE_KEXT_DEPRECATED;
809 
810 /*! @function waitQuiet
811  *   @abstract Waits for an IOService object's <code>busyState</code> to be zero.
812  *   @discussion Blocks the caller until an IOService object is non busy.
813  *   @param timeout The maximum time to wait in nanoseconds. Default is to wait forever.
814  *   @result Returns an error code if Mach synchronization primitives fail, <code>kIOReturnTimeout</code>, or <code>kIOReturnSuccess</code>. */
815 
816 	IOReturn waitQuiet(uint64_t timeout = UINT64_MAX);
817 
818 /* Matching */
819 
820 /*! @function matchPropertyTable
821  *   @abstract Allows a registered IOService object to implement family specific matching.
822  *   @discussion All matching on an IOService object will call this method to allow a family writer to implement matching in addition to the generic methods provided by IOService. The implementer should examine the matching dictionary passed to see if it contains properties the family understands for matching, and use them to match with the IOService object if so. Note that since matching is also carried out by other parts of the I/O Kit, the matching dictionary may contain properties the family does not understand - these should not be considered matching failures.
823  *   @param table The dictionary of properties to be matched against.
824  *   @param score Pointer to the current driver's probe score, which is used to order multiple matching drivers in the same match category. It defaults to the value of the <code>IOProbeScore</code> property in the drivers property table, or <code>kIODefaultProbeScore</code> if none is specified.
825  *   @result <code>false</code> if the family considers the matching dictionary does not match in properties it understands; <code>true</code> otherwise. */
826 
827 	virtual bool matchPropertyTable( OSDictionary * table,
828 	    SInt32       * score );
829 
830 	virtual bool matchPropertyTable( OSDictionary * table );
831 
832 /*! @function matchLocation
833  *   @abstract Allows a registered IOService object to direct location matching.
834  *   @discussion By default, a location matching property will be applied to an IOService object's provider. This method allows that behavior to be overridden by families.
835  *   @param client The IOService object at which matching is taking place.
836  *   @result Returns the IOService instance to be used for location matching. */
837 
838 	virtual LIBKERN_RETURNS_NOT_RETAINED IOService * matchLocation( IOService * client );
839 
840 /* Resource service */
841 
842 /*! @function publishResource
843  *   @abstract Uses the resource service to publish a property.
844  *   @discussion The resource service uses IOService's matching and notification to allow objects to be published and found by any I/O Kit client by a global name. <code>publishResource</code> makes an object available to anyone waiting for it or looking for it in the future.
845  *   @param key An OSSymbol key that globally identifies the object.
846  *   @param value The object to be published. */
847 
848 	static void publishResource( const OSSymbol * key, OSObject * value = NULL );
849 	static void publishUserResource( const OSSymbol * key, OSObject * value = NULL );
850 
851 /*! @function publishResource
852  *   @abstract Uses the resource service to publish a property.
853  *   @discussion The resource service uses IOService object's matching and notification to allow objects to be published and found by any I/O Kit client by a global name. <code>publishResource</code> makes an object available to anyone waiting for it or looking for it in the future.
854  *   @param key A C string key that globally identifies the object.
855  *   @param value The object to be published. */
856 
857 	static void publishResource( const char * key, OSObject * value = NULL );
858 	virtual bool addNeededResource( const char * key );
859 
860 /* Notifications */
861 
862 /*! @function addNotification
863  *   @abstract Deprecated use addMatchingNotification(). Adds a persistant notification handler to be notified of IOService events.
864  *   @discussion IOService will deliver notifications of changes in state of an IOService object to registered clients. The type of notification is specified by a symbol, for example <code>gIOMatchedNotification</code> or <code>gIOTerminatedNotification</code>, and notifications will only include IOService objects that match the supplied matching dictionary. Notifications are ordered by a priority set with <code>addNotification</code>. When the notification is installed, its handler will be called with each of any currently existing IOService objects that are in the correct state (eg. registered) and match the supplied matching dictionary, avoiding races between finding preexisting and new IOService events. The notification request is identified by an instance of an IONotifier object, through which it can be enabled, disabled, or removed. <code>addNotification</code> consumes a retain count on the matching dictionary when the notification is removed.
865  *   @param type An OSSymbol identifying the type of notification and IOService state:
866  *  <br>    <code>gIOPublishNotification</code> Delivered when an IOService object is registered.
867  *  <br>    <code>gIOFirstPublishNotification</code> Delivered when an IOService object is registered, but only once per IOService instance. Some IOService objects may be reregistered when their state is changed.
868  *  <br>    <code>gIOMatchedNotification</code> Delivered when an IOService object has been matched with all client drivers, and they have been probed and started.
869  *  <br>    <code>gIOFirstMatchNotification</code> Delivered when an IOService object has been matched with all client drivers, but only once per IOService instance. Some IOService objects may be reregistered when their state is changed.
870  *  <br>    <code>gIOWillTerminateNotification</code> Delivered after an IOService object has been terminated, during its finalize stage. Delivered after any matching on the service has finished.
871  *  <br>    <code>gIOTerminatedNotification</code> Delivered immediately when an IOService object has been terminated, making it inactive.
872  *   @param matching A matching dictionary to restrict notifications to only matching IOService objects. The dictionary will be released when the notification is removed, consuming the passed-in reference.
873  *   @param handler A C function callback to deliver notifications.
874  *   @param target An instance reference for the callback's use.
875  *   @param ref A reference constant for the callback's use.
876  *   @param priority A constant ordering all notifications of a each type.
877  *   @result An instance of an IONotifier object that can be used to control or destroy the notification request. */
878 
879 	static OSPtr<IONotifier>  addNotification(
880 		const OSSymbol * type, OSDictionary * matching,
881 		IOServiceNotificationHandler handler,
882 		void * target, void * ref = NULL,
883 		SInt32 priority = 0 )
884 	APPLE_KEXT_DEPRECATED;
885 
886 /*! @function addMatchingNotification
887  *   @abstract Adds a persistant notification handler to be notified of IOService events.
888  *   @discussion IOService will deliver notifications of changes in state of an IOService object to registered clients. The type of notification is specified by a symbol, for example <code>gIOMatchedNotification</code> or <code>gIOTerminatedNotification</code>, and notifications will only include IOService objects that match the supplied matching dictionary. Notifications are ordered by a priority set with <code>addNotification</code>. When the notification is installed, its handler will be called with each of any currently existing IOService objects that are in the correct state (eg. registered) and match the supplied matching dictionary, avoiding races between finding preexisting and new IOService events. The notification request is identified by an instance of an IONotifier object, through which it can be enabled, disabled, or removed. <code>addMatchingNotification</code> does not consume a reference on the matching dictionary when the notification is removed, unlike addNotification.
889  *   @param type An OSSymbol identifying the type of notification and IOService state:
890  *  <br>    <code>gIOPublishNotification</code> Delivered when an IOService object is registered.
891  *  <br>    <code>gIOFirstPublishNotification</code> Delivered when an IOService object is registered, but only once per IOService instance. Some IOService objects may be reregistered when their state is changed.
892  *  <br>    <code>gIOMatchedNotification</code> Delivered when an IOService object has been matched with all client drivers, and they have been probed and started.
893  *  <br>    <code>gIOFirstMatchNotification</code> Delivered when an IOService object has been matched with all client drivers, but only once per IOService instance. Some IOService objects may be reregistered when their state is changed.
894  *  <br>    <code>gIOWillTerminateNotification</code> Delivered after an IOService object has been terminated, during its finalize stage. Delivered after any matching on the service has finished.
895  *  <br>    <code>gIOTerminatedNotification</code> Delivered immediately when an IOService object has been terminated, making it inactive.
896  *   @param matching A matching dictionary to restrict notifications to only matching IOService objects. The dictionary is retained while the notification is installed. (Differs from addNotification).
897  *   @param handler A C function callback to deliver notifications.
898  *   @param target An instance reference for the callback's use.
899  *   @param ref A reference constant for the callback's use.
900  *   @param priority A constant ordering all notifications of a each type.
901  *   @result An instance of an IONotifier object that can be used to control or destroy the notification request. */
902 
903 	static IONotifier * addMatchingNotification(
904 		const OSSymbol * type, OSDictionary * matching,
905 		IOServiceMatchingNotificationHandler handler,
906 		void * target, void * ref = NULL,
907 		SInt32 priority = 0 );
908 
909 
910 #ifdef __BLOCKS__
911 	static IONotifier * addMatchingNotification(
912 		const OSSymbol * type, OSDictionary * matching,
913 		SInt32 priority,
914 		IOServiceMatchingNotificationHandlerBlock handler);
915 #endif /* __BLOCKS__ */
916 
917 /*! @function waitForService
918  *   @abstract Deprecated use waitForMatchingService(). Waits for a matching to service to be published.
919  *   @discussion Provides a method of waiting for an IOService object matching the supplied matching dictionary to be registered and fully matched.
920  *   @param matching The matching dictionary describing the desired IOService object. <code>waitForService</code> consumes one reference of the matching dictionary.
921  *   @param timeout The maximum time to wait.
922  *   @result A published IOService object matching the supplied dictionary. */
923 
924 	static LIBKERN_RETURNS_NOT_RETAINED IOService * waitForService(
925 		LIBKERN_CONSUMED OSDictionary * matching,
926 		mach_timespec_t * timeout = NULL);
927 
928 /*! @function waitForMatchingService
929  *   @abstract Waits for a matching to service to be published.
930  *   @discussion Provides a method of waiting for an IOService object matching the supplied matching dictionary to be registered and fully matched.
931  *   @param matching The matching dictionary describing the desired IOService object. (Does not consume a reference of the matching dictionary - differs from waitForService() which does consume a reference on the matching dictionary.)
932  *   @param timeout The maximum time to wait in nanoseconds. Default is to wait forever.
933  *   @result A published IOService object matching the supplied dictionary. waitForMatchingService returns a reference to the IOService which should be released by the caller. (Differs from waitForService() which does not retain the returned object.) */
934 
935 	static OSPtr<IOService>  waitForMatchingService( OSDictionary * matching,
936 	    uint64_t timeout = UINT64_MAX);
937 
938 #ifdef XNU_KERNEL_PRIVATE
939 	static IOService * waitForMatchingServiceWithToken( OSDictionary * matching,
940 	    uint64_t timeout, IOUserServerCheckInToken * token );
941 #endif
942 
943 /*! @function getMatchingServices
944  *   @abstract Finds the set of current published IOService objects matching a matching dictionary.
945  *   @discussion Provides a method of finding the current set of published IOService objects matching the supplied matching dictionary.
946  *   @param matching The matching dictionary describing the desired IOService objects.
947  *   @result An instance of an iterator over a set of IOService objects. To be released by the caller. */
948 
949 	static OSPtr<OSIterator> getMatchingServices( OSDictionary * matching );
950 
951 /*! @function copyMatchingService
952  *   @abstract Finds one of the current published IOService objects matching a matching dictionary.
953  *   @discussion Provides a method to find one member of the set of published IOService objects matching the supplied matching dictionary.
954  *   @param matching The matching dictionary describing the desired IOService object.
955  *   @result The IOService object or NULL. To be released by the caller. */
956 
957 	static OSPtr<IOService>  copyMatchingService( OSDictionary * matching );
958 
959 public:
960 /* Helpers to make matching dictionaries for simple cases,
961  * they add keys to an existing dictionary, or create one. */
962 
963 /*! @function serviceMatching
964  *   @abstract Creates a matching dictionary, or adds matching properties to an existing dictionary, that specify an IOService class match.
965  *   @discussion A very common matching criteria for IOService object is based on its class. <code>serviceMatching</code> creates a matching dictionary that specifies any IOService object of a class, or its subclasses. The class is specified by name, and an existing dictionary may be passed in, in which case the matching properties will be added to that dictionary rather than creating a new one.
966  *   @param className The class name, as a const C string. Class matching is successful on IOService objects of this class or any subclass.
967  *   @param table If zero, <code>serviceMatching</code> creates a matching dictionary and returns a reference to it, otherwise the matching properties are added to the specified dictionary.
968  *   @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
969 
970 	static OSPtr<OSDictionary>  serviceMatching( const char * className,
971 	    OSDictionary * table = NULL );
972 
973 #if __cplusplus >= 201703L
974 /*! @function serviceMatching
975  *   @abstract Creates a matching dictionary, or adds matching properties to an existing dictionary, that specify an IOService class match.
976  *   @discussion A very common matching criteria for IOService object is based on its class. <code>serviceMatching</code> creates a matching dictionary that specifies any IOService object of a class, or its subclasses. The class is specified by name, and an existing dictionary may be passed in, in which case the matching properties will be added to that dictionary rather than creating a new one.
977  *   @param className The class name, as a const C string. Class matching is successful on IOService objects of this class or any subclass.
978  *   @param table If zero, <code>serviceMatching</code> creates a matching dictionary and returns a reference to it, otherwise the matching properties are added to the specified dictionary.
979  *   @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
980 
981 	static OSSharedPtr<OSDictionary> serviceMatching( const char * className,
982 	    OSSharedPtr<OSDictionary> table);
983 #endif
984 
985 /*! @function serviceMatching
986  *   @abstract Creates a matching dictionary, or adds matching properties to an existing dictionary, that specify an IOService class match.
987  *   @discussion A very common matching criteria for IOService object is based on its class. <code>serviceMatching</code> creates a matching dictionary that specifies any IOService of a class, or its subclasses. The class is specified by name, and an existing dictionary may be passed in, in which case the matching properties will be added to that dictionary rather than creating a new one.
988  *   @param className The class name, as an OSString (which includes OSSymbol). Class matching is successful on IOService objects of this class or any subclass.
989  *   @param table If zero, <code>serviceMatching</code> creates a matching dictionary and returns a reference to it, otherwise the matching properties are added to the specified dictionary.
990  *   @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
991 
992 	static OSPtr<OSDictionary>  serviceMatching( const OSString * className,
993 	    OSDictionary * table = NULL );
994 
995 #if __cplusplus >= 201703L
996 /*! @function serviceMatching
997  *   @abstract Creates a matching dictionary, or adds matching properties to an existing dictionary, that specify an IOService class match.
998  *   @discussion A very common matching criteria for IOService object is based on its class. <code>serviceMatching</code> creates a matching dictionary that specifies any IOService of a class, or its subclasses. The class is specified by name, and an existing dictionary may be passed in, in which case the matching properties will be added to that dictionary rather than creating a new one.
999  *   @param className The class name, as an OSString (which includes OSSymbol). Class matching is successful on IOService objects of this class or any subclass.
1000  *   @param table If zero, <code>serviceMatching</code> creates a matching dictionary and returns a reference to it, otherwise the matching properties are added to the specified dictionary.
1001  *   @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
1002 
1003 	static OSSharedPtr<OSDictionary> serviceMatching( const OSString * className,
1004 	    OSSharedPtr<OSDictionary> table);
1005 #endif
1006 
1007 /*! @function nameMatching
1008  *   @abstract Creates a matching dictionary, or adds matching properties to an existing dictionary, that specify an IOService name match.
1009  *   @discussion A very common matching criteria for IOService object is based on its name. <code>nameMatching</code> creates a matching dictionary that specifies any IOService object which responds successfully to the @link //apple_ref/cpp/instm/IORegistryEntry/compareName/virtualbool/(OSString*,OSString**) IORegistryEntry::compareName@/link method. An existing dictionary may be passed in, in which case the matching properties will be added to that dictionary rather than creating a new one.
1010  *   @param name The service's name, as a const C string. Name matching is successful on IOService objects that respond successfully to the <code>IORegistryEntry::compareName</code> method.
1011  *   @param table If zero, <code>nameMatching</code> creates a matching dictionary and returns a reference to it, otherwise the matching properties are added to the specified dictionary.
1012  *   @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
1013 
1014 	static OSPtr<OSDictionary>  nameMatching( const char * name,
1015 	    OSDictionary * table = NULL );
1016 
1017 #if __cplusplus >= 201703L
1018 /*! @function nameMatching
1019  *   @abstract Creates a matching dictionary, or adds matching properties to an existing dictionary, that specify an IOService name match.
1020  *   @discussion A very common matching criteria for IOService object is based on its name. <code>nameMatching</code> creates a matching dictionary that specifies any IOService object which responds successfully to the @link //apple_ref/cpp/instm/IORegistryEntry/compareName/virtualbool/(OSString*,OSString**) IORegistryEntry::compareName@/link method. An existing dictionary may be passed in, in which case the matching properties will be added to that dictionary rather than creating a new one.
1021  *   @param name The service's name, as a const C string. Name matching is successful on IOService objects that respond successfully to the <code>IORegistryEntry::compareName</code> method.
1022  *   @param table If zero, <code>nameMatching</code> creates a matching dictionary and returns a reference to it, otherwise the matching properties are added to the specified dictionary.
1023  *   @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
1024 
1025 	static OSSharedPtr<OSDictionary> nameMatching( const char * name,
1026 	    OSSharedPtr<OSDictionary> table);
1027 #endif
1028 
1029 /*! @function nameMatching
1030  *   @abstract Creates a matching dictionary, or adds matching properties to an existing dictionary, that specify an IOService name match.
1031  *   @discussion A very common matching criteria for IOService object is based on its name. <code>nameMatching</code> creates a matching dictionary that specifies any IOService object which responds successfully to the @link //apple_ref/cpp/instm/IORegistryEntry/compareName/virtualbool/(OSString*,OSString**) IORegistryEntry::compareName@/link method. An existing dictionary may be passed in, in which case the matching properties will be added to that dictionary rather than creating a new one.
1032  *   @param name The service's name, as an OSString (which includes OSSymbol). Name matching is successful on IOService objects that respond successfully to the <code>IORegistryEntry::compareName</code> method.
1033  *   @param table If zero, <code>nameMatching</code> creates a matching dictionary and returns a reference to it, otherwise the matching properties are added to the specified dictionary.
1034  *   @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
1035 
1036 	static OSPtr<OSDictionary>  nameMatching( const OSString* name,
1037 	    OSDictionary * table = NULL );
1038 
1039 #if __cplusplus >= 201703L
1040 /*! @function nameMatching
1041  *   @abstract Creates a matching dictionary, or adds matching properties to an existing dictionary, that specify an IOService name match.
1042  *   @discussion A very common matching criteria for IOService object is based on its name. <code>nameMatching</code> creates a matching dictionary that specifies any IOService object which responds successfully to the @link //apple_ref/cpp/instm/IORegistryEntry/compareName/virtualbool/(OSString*,OSString**) IORegistryEntry::compareName@/link method. An existing dictionary may be passed in, in which case the matching properties will be added to that dictionary rather than creating a new one.
1043  *   @param name The service's name, as an OSString (which includes OSSymbol). Name matching is successful on IOService objects that respond successfully to the <code>IORegistryEntry::compareName</code> method.
1044  *   @param table If zero, <code>nameMatching</code> creates a matching dictionary and returns a reference to it, otherwise the matching properties are added to the specified dictionary.
1045  *   @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
1046 
1047 	static OSSharedPtr<OSDictionary> nameMatching( const OSString* name,
1048 	    OSSharedPtr<OSDictionary> table);
1049 #endif
1050 
1051 /*! @function resourceMatching
1052  *   @abstract Creates a matching dictionary, or adds matching properties to an existing dictionary, that specify a resource service match.
1053  *   @discussion IOService maintains a resource service IOResources that allows objects to be published and found globally in the I/O Kit based on a name, using the standard IOService matching and notification calls.
1054  *   @param name The resource name, as a const C string. Resource matching is successful when an object by that name has been published with the <code>publishResource</code> method.
1055  *   @param table If zero, <code>resourceMatching</code> creates a matching dictionary and returns a reference to it, otherwise the matching properties are added to the specified dictionary.
1056  *   @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
1057 
1058 	static OSPtr<OSDictionary>  resourceMatching( const char * name,
1059 	    OSDictionary * table = NULL );
1060 
1061 #if __cplusplus >= 201703L
1062 /*! @function resourceMatching
1063  *   @abstract Creates a matching dictionary, or adds matching properties to an existing dictionary, that specify a resource service match.
1064  *   @discussion IOService maintains a resource service IOResources that allows objects to be published and found globally in the I/O Kit based on a name, using the standard IOService matching and notification calls.
1065  *   @param name The resource name, as a const C string. Resource matching is successful when an object by that name has been published with the <code>publishResource</code> method.
1066  *   @param table If zero, <code>resourceMatching</code> creates a matching dictionary and returns a reference to it, otherwise the matching properties are added to the specified dictionary.
1067  *   @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
1068 
1069 	static OSSharedPtr<OSDictionary> resourceMatching( const char * name,
1070 	    OSSharedPtr<OSDictionary> table);
1071 #endif
1072 
1073 /*! @function resourceMatching
1074  *   @abstract Creates a matching dictionary, or adds matching properties to an existing dictionary, that specify a resource service match.
1075  *   @discussion IOService maintains a resource service IOResources that allows objects to be published and found globally in the I/O Kit based on a name, using the standard IOService matching and notification calls.
1076  *   @param name The resource name, as an OSString (which includes OSSymbol). Resource matching is successful when an object by that name has been published with the <code>publishResource</code> method.
1077  *   @param table If zero, <code>resourceMatching</code> creates a matching dictionary and returns a reference to it, otherwise the matching properties are added to the specified dictionary.
1078  *   @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
1079 
1080 	static OSPtr<OSDictionary>  resourceMatching( const OSString * name,
1081 	    OSDictionary * table = NULL );
1082 
1083 #if __cplusplus >= 201703L
1084 /*! @function resourceMatching
1085  *   @abstract Creates a matching dictionary, or adds matching properties to an existing dictionary, that specify a resource service match.
1086  *   @discussion IOService maintains a resource service IOResources that allows objects to be published and found globally in the I/O Kit based on a name, using the standard IOService matching and notification calls.
1087  *   @param name The resource name, as an OSString (which includes OSSymbol). Resource matching is successful when an object by that name has been published with the <code>publishResource</code> method.
1088  *   @param table If zero, <code>resourceMatching</code> creates a matching dictionary and returns a reference to it, otherwise the matching properties are added to the specified dictionary.
1089  *   @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
1090 
1091 	static OSSharedPtr<OSDictionary> resourceMatching( const OSString * name,
1092 	    OSSharedPtr<OSDictionary> table);
1093 #endif
1094 
1095 
1096 /*! @function propertyMatching
1097  *   @abstract Creates a matching dictionary, or adds matching properties to an existing dictionary, that specify an IOService phandle match.
1098  *   @discussion TODO A very common matching criteria for IOService is based on its name. nameMatching will create a matching dictionary that specifies any IOService which respond successfully to the IORegistryEntry method compareName. An existing dictionary may be passed in, in which case the matching properties will be added to that dictionary rather than creating a new one.
1099  *   @param key The service's phandle, as a const UInt32. PHandle matching is successful on IOService objects that respond successfully to the IORegistryEntry method compareName.
1100  *   @param value The service's phandle, as a const UInt32. PHandle matching is successful on IOService's which respond successfully to the IORegistryEntry method compareName.
1101  *   @param table If zero, nameMatching will create a matching dictionary and return a reference to it, otherwise the matching properties are added to the specified dictionary.
1102  *   @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
1103 
1104 	static OSPtr<OSDictionary>  propertyMatching( const OSSymbol * key, const OSObject * value,
1105 	    OSDictionary * table = NULL );
1106 
1107 #if __cplusplus >= 201703L
1108 /*! @function propertyMatching
1109  *   @abstract Creates a matching dictionary, or adds matching properties to an existing dictionary, that specify an IOService phandle match.
1110  *   @discussion TODO A very common matching criteria for IOService is based on its name. nameMatching will create a matching dictionary that specifies any IOService which respond successfully to the IORegistryEntry method compareName. An existing dictionary may be passed in, in which case the matching properties will be added to that dictionary rather than creating a new one.
1111  *   @param key The service's phandle, as a const UInt32. PHandle matching is successful on IOService objects that respond successfully to the IORegistryEntry method compareName.
1112  *   @param value The service's phandle, as a const UInt32. PHandle matching is successful on IOService's which respond successfully to the IORegistryEntry method compareName.
1113  *   @param table If zero, nameMatching will create a matching dictionary and return a reference to it, otherwise the matching properties are added to the specified dictionary.
1114  *   @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
1115 
1116 	static OSSharedPtr<OSDictionary>  propertyMatching( const OSSymbol * key, const OSObject * value,
1117 	    OSSharedPtr<OSDictionary> table);
1118 #endif
1119 
1120 /*! @function registryEntryIDMatching
1121  *   @abstract Creates a matching dictionary, or adds matching properties to an existing dictionary, that specify a IORegistryEntryID match.
1122  *   @discussion <code>registryEntryIDMatching</code> creates a matching dictionary that specifies the IOService object with the assigned registry entry ID (returned by <code>IORegistryEntry::getRegistryEntryID()</code>). An existing dictionary may be passed in, in which case the matching properties will be added to that dictionary rather than creating a new one.
1123  *   @param entryID The service's ID. Matching is successful on the IOService object that return that ID from the <code>IORegistryEntry::getRegistryEntryID()</code> method.
1124  *   @param table If zero, <code>registryEntryIDMatching</code> creates a matching dictionary and returns a reference to it, otherwise the matching properties are added to the specified dictionary.
1125  *   @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
1126 
1127 	static OSDictionary * registryEntryIDMatching( uint64_t entryID,
1128 	    OSDictionary * table = NULL );
1129 
1130 #if __cplusplus >= 201703L
1131 /*! @function registryEntryIDMatching
1132  *   @abstract Creates a matching dictionary, or adds matching properties to an existing dictionary, that specify a IORegistryEntryID match.
1133  *   @discussion <code>registryEntryIDMatching</code> creates a matching dictionary that specifies the IOService object with the assigned registry entry ID (returned by <code>IORegistryEntry::getRegistryEntryID()</code>). An existing dictionary may be passed in, in which case the matching properties will be added to that dictionary rather than creating a new one.
1134  *   @param entryID The service's ID. Matching is successful on the IOService object that return that ID from the <code>IORegistryEntry::getRegistryEntryID()</code> method.
1135  *   @param table If zero, <code>registryEntryIDMatching</code> creates a matching dictionary and returns a reference to it, otherwise the matching properties are added to the specified dictionary.
1136  *   @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
1137 
1138 	static OSSharedPtr<OSDictionary> registryEntryIDMatching( uint64_t entryID,
1139 	    OSSharedPtr<OSDictionary> table);
1140 #endif
1141 
1142 
1143 /*! @function addLocation
1144  *   @abstract Adds a location matching property to an existing dictionary.
1145  *   @discussion This function creates matching properties that specify the location of a IOService object, as an embedded matching dictionary. This matching will be successful on an IOService object that attached to an IOService object which matches this location matching dictionary.
1146  *   @param table The matching properties are added to the specified dictionary, which must be non-zero.
1147  *   @result The location matching dictionary created is returned on success, or zero on failure. */
1148 
1149 	static OSPtr<OSDictionary>  addLocation( OSDictionary * table );
1150 
1151 /* Helpers for matching dictionaries. */
1152 
1153 /*! @function compareProperty
1154  *   @abstract Compares a property in a matching dictionary with an IOService object's property table.
1155  *   @discussion This is a helper function to aid in implementing @link matchPropertyTable matchPropertyTable@/link. If the property specified by <code>key</code> exists in the matching dictionary, it is compared with a property of the same name in the IOService object's property table. The comparison is performed with the <code>isEqualTo</code> method. If the property does not exist in the matching table, success is returned. If the property exists in the matching dictionary but not the IOService property table, failure is returned.
1156  *   @param matching The matching dictionary, which must be non-zero.
1157  *   @param key The dictionary key specifying the property to be compared, as a C string.
1158  *   @result <code>true</code> if the property does not exist in the matching table. If the property exists in the matching dictionary but not the IOService property table, failure is returned. Otherwise the result of calling the property from the matching dictionary's <code>isEqualTo</code> method with the IOService property as an argument is returned. */
1159 
1160 	virtual bool compareProperty(   OSDictionary   * matching,
1161 	    const char     * key );
1162 /*! @function compareProperty
1163  *   @abstract Compares a property in a matching dictionary with an IOService object's property table.
1164  *   @discussion This is a helper function to aid in implementing @link matchPropertyTable matchPropertyTable@/link. If the property specified by <code>key</code> exists in the matching dictionary, it is compared with a property of the same name in the IOService object's property table. The comparison is performed with the <code>isEqualTo</code> method. If the property does not exist in the matching table, success is returned. If the property exists in the matching dictionary but not the IOService property table, failure is returned.
1165  *   @param matching The matching dictionary, which must be non-zero.
1166  *   @param key The dictionary key specifying the property to be compared, as an OSString (which includes OSSymbol).
1167  *   @result <code>true</code> if the property does not exist in the matching table. If the property exists in the matching dictionary but not the IOService property table, failure is returned. Otherwise the result of calling the property from the matching dictionary's <code>isEqualTo</code> method with the IOService property as an argument is returned. */
1168 
1169 	virtual bool compareProperty(   OSDictionary   * matching,
1170 	    const OSString * key );
1171 
1172 /*! @function compareProperties
1173  *   @abstract Compares a set of properties in a matching dictionary with an IOService object's property table.
1174  *   @discussion This is a helper function to aid in implementing @link matchPropertyTable matchPropertyTable@/link. A collection of dictionary keys specifies properties in a matching dictionary to be compared, with <code>compareProperty</code>, with an IOService object's property table, if <code>compareProperty</code> returns <code>true</code> for each key, success is returned; otherwise failure.
1175  *   @param matching The matching dictionary, which must be non-zero.
1176  *   @param keys A collection (eg. OSSet, OSArray, OSDictionary) which should contain OSStrings (or OSSymbols) that specify the property keys to be compared.
1177  *   @result Success if <code>compareProperty</code> returns <code>true</code> for each key in the collection; otherwise failure. */
1178 
1179 	virtual bool compareProperties( OSDictionary   * matching,
1180 	    OSCollection   * keys );
1181 
1182 /* Client / provider accessors */
1183 
1184 /*! @function attach
1185  *   @abstract Attaches an IOService client to a provider in the I/O Registry.
1186  *   @discussion This function called in an IOService client enters the client into the I/O Registry as a child of the provider in the service plane. The provider must be active or the attach will fail. Multiple attach calls to the same provider are no-ops and return success. A client may be attached to multiple providers. Entering an object into the I/O Registry retains both the client and provider until they are detached.
1187  *   @param provider The IOService object which will serve as this object's provider.
1188  *   @result <code>false</code> if the provider is inactive or on a resource failure; otherwise <code>true</code>. */
1189 
1190 	virtual bool attach( IOService * provider );
1191 
1192 /*! @function detach
1193  *   @abstract Detaches an IOService client from a provider in the I/O Registry.
1194  *   @discussion This function called in an IOService client removes the client as a child of the provider in the service plane of the I/O Registry. If the provider is not a parent of the client this is a no-op, otherwise the I/O Registry releases both the client and provider.
1195  *   @param provider The IOService object to detach from. */
1196 
1197 	virtual void detach( IOService * provider );
1198 
1199 /*! @function getProvider
1200  *   @abstract Returns an IOService object's primary provider.
1201  *   @discussion This function called in an IOService client will return the provider to which it was first attached. Because the majority of IOService objects have only one provider, this is a useful simplification and also supports caching of the provider when the I/O Registry is unchanged.
1202  *   @result The first provider of the client, or zero if the IOService object is not attached into the I/O Registry. The provider is retained while the client is attached, and should not be released by the caller. */
1203 
1204 	virtual IOService * getProvider( void ) const;
1205 
1206 /*! @function getWorkLoop
1207  *   @abstract Returns the current work loop or <code>provider->getWorkLoop</code>.
1208  *   @discussion This function returns a valid work loop that a client can use to add an IOCommandGate to. The intention is that an IOService client has data that needs to be protected but doesn't want to pay the cost of a dedicated thread. This data has to be accessed from a provider's call-out context as well. So to achieve both of these goals the client creates an IOCommandGate to lock access to his data but he registers it with the provider's work loop, i.e. the work loop which will make the completion call-outs. This avoids a potential deadlock because the work loop gate uses a recursive lock, which allows the same lock to be held multiple times by a single thread.
1209  *   @result A work loop, either the current work loop or it walks up the @link getProvider getProvider@/link chain calling <code>getWorkLoop</code>. Eventually it will reach a valid work loop-based driver or the root of the I/O tree, where it will return a system-wide work loop. Returns 0 if it fails to find (or create) a work loop.*/
1210 
1211 	virtual IOWorkLoop * getWorkLoop() const;
1212 
1213 /*! @function getProviderIterator
1214  *   @abstract Returns an iterator over an IOService object's providers.
1215  *   @discussion For those few IOService objects that obtain service from multiple providers, this method supplies an iterator over a client's providers.
1216  *   @result An iterator over the providers of the client, or zero if there is a resource failure. The iterator must be released when the iteration is finished. All objects returned by the iteration are retained while the iterator is valid, though they may no longer be attached during the iteration. */
1217 
1218 	virtual OSPtr<OSIterator> getProviderIterator( void ) const;
1219 
1220 /*! @function getOpenProviderIterator
1221  *   @abstract Returns an iterator over an client's providers that are currently opened by the client.
1222  *   @discussion For those few IOService objects that obtain service from multiple providers, this method supplies an iterator over a client's providers, locking each in turn with @link lockForArbitration lockForArbitration@/link and returning those that have been opened by the client.
1223  *   @result An iterator over the providers the client has open, or zero if there is a resource failure. The iterator must be released when the iteration is finished. All objects returned by the iteration are retained while the iterator is valid, and the current entry in the iteration is locked with <code>lockForArbitration</code>, protecting it from state changes. */
1224 
1225 	virtual OSPtr<OSIterator> getOpenProviderIterator( void ) const;
1226 
1227 /*! @function getClient
1228  *   @abstract Returns an IOService object's primary client.
1229  *   @discussion This function called in an IOService provider will return the first client to attach to it. For IOService objects which have only only one client, this may be a useful simplification.
1230  *   @result The first client of the provider, or zero if the IOService object is not attached into the I/O Registry. The client is retained while it is attached, and should not be released by the caller. */
1231 
1232 	virtual IOService * getClient( void ) const;
1233 
1234 /*! @function getClientIterator
1235  *   @abstract Returns an iterator over an IOService object's clients.
1236  *   @discussion For IOService objects that may have multiple clients, this method supplies an iterator over a provider's clients.
1237  *   @result An iterator over the clients of the provider, or zero if there is a resource failure. The iterator must be released when the iteration is finished. All objects returned by the iteration are retained while the iterator is valid, though they may no longer be attached during the iteration. */
1238 
1239 	virtual OSPtr<OSIterator> getClientIterator( void ) const;
1240 
1241 /*! @function getOpenClientIterator
1242  *   @abstract Returns an iterator over a provider's clients that currently have opened the provider.
1243  *   @discussion For IOService objects that may have multiple clients, this method supplies an iterator over a provider's clients, locking each in turn with @link lockForArbitration lockForArbitration@/link and returning those that have opened the provider.
1244  *   @result An iterator over the clients that have opened the provider, or zero if there is a resource failure. The iterator must be released when the iteration is finished. All objects returned by the iteration are retained while the iterator is valid, and the current entry in the iteration is locked with <code>lockForArbitration</code>, protecting it from state changes. */
1245 
1246 	virtual OSPtr<OSIterator> getOpenClientIterator( void ) const;
1247 
1248 /*! @function callPlatformFunction
1249  *   @abstract Calls the platform function with the given name.
1250  *   @discussion The platform expert or other drivers may implement various functions to control hardware features.  <code>callPlatformFunction</code> allows any IOService object to access these functions. Normally <code>callPlatformFunction</code> is called on a service's provider. The provider services the request or passes it to its provider. The system's IOPlatformExpert subclass catches functions it knows about and redirects them into other parts of the service plane. If the IOPlatformExpert subclass cannot execute the function, the base class is called. The IOPlatformExpert base class attempts to find a service to execute the function by looking up the function name in an IOResources name space. A service may publish a service using <code>publishResource(functionName, this)</code>. If no service can be found to execute the function an error is returned.
1251  *   @param functionName Name of the function to be called. When <code>functionName</code> is a C string, <code>callPlatformFunction</code> converts the C string to an OSSymbol and calls the OSSymbol version of <code>callPlatformFunction</code>. This process can block and should not be used from an interrupt context.
1252  *   @param waitForFunction If <code>true</code>, <code>callPlatformFunction</code> will not return until the function has been called.
1253  *   @result An IOReturn code; <code>kIOReturnSuccess</code> if the function was successfully executed, <code>kIOReturnUnsupported</code> if a service to execute the function could not be found. Other return codes may be returned by the function.*/
1254 
1255 	virtual IOReturn callPlatformFunction( const OSSymbol * functionName,
1256 	    bool waitForFunction,
1257 	    void *param1, void *param2,
1258 	    void *param3, void *param4 );
1259 
1260 	virtual IOReturn callPlatformFunction( const char * functionName,
1261 	    bool waitForFunction,
1262 	    void *param1, void *param2,
1263 	    void *param3, void *param4 );
1264 
1265 
1266 /* Some accessors */
1267 
1268 /*! @function getPlatform
1269  *   @abstract Returns a pointer to the platform expert instance for the computer.
1270  *   @discussion This method provides an accessor to the platform expert instance for the computer.
1271  *   @result A pointer to the IOPlatformExpert instance. It should not be released by the caller. */
1272 
1273 	static IOPlatformExpert * getPlatform( void );
1274 
1275 /*! @function getPMRootDomain
1276  *   @abstract Returns a pointer to the power management root domain instance for the computer.
1277  *   @discussion This method provides an accessor to the power management root domain instance for the computer.
1278  *   @result A pointer to the power management root domain instance. It should not be released by the caller. */
1279 
1280 	static class IOPMrootDomain * getPMRootDomain( void );
1281 
1282 /*! @function getServiceRoot
1283  *   @abstract Returns a pointer to the root of the service plane.
1284  *   @discussion This method provides an accessor to the root of the service plane for the computer.
1285  *   @result A pointer to the IOService instance at the root of the service plane. It should not be released by the caller. */
1286 
1287 	static IOService * getServiceRoot( void );
1288 
1289 /*! @function getResourceService
1290  *   @abstract Returns a pointer to the IOResources service.
1291  *   @discussion IOService maintains a resource service IOResources that allows objects to be published and found globally in the I/O Kit based on a name, using the standard IOService matching and notification calls.
1292  *   @result A pointer to the IOResources instance. It should not be released by the caller. */
1293 
1294 	static IOService * getResourceService( void );
1295 
1296 	static IOService * getSystemStateNotificationService(void);
1297 
1298 /* Allocate resources for a matched service */
1299 
1300 /*! @function getResources
1301  *   @abstract Allocates any needed resources for a published IOService object before clients attach.
1302  *   @discussion This method is called during the registration process for an IOService object if there are successful driver matches, before any clients attach. It allows for lazy allocation of resources to an IOService object when a matching driver is found.
1303  *   @result An IOReturn code; <code>kIOReturnSuccess</code> is necessary for the IOService object to be successfully used, otherwise the registration process for the object is halted. */
1304 
1305 	virtual IOReturn getResources( void );
1306 
1307 /* Device memory accessors */
1308 
1309 /*! @function getDeviceMemoryCount
1310  *   @abstract Returns a count of the physical memory ranges available for a device.
1311  *   @discussion This method returns the count of physical memory ranges, each represented by an IODeviceMemory instance, that have been allocated for a memory mapped device.
1312  *   @result An integer count of the number of ranges available. */
1313 
1314 	virtual IOItemCount getDeviceMemoryCount( void );
1315 
1316 /*! @function getDeviceMemoryWithIndex
1317  *   @abstract Returns an instance of IODeviceMemory representing one of a device's memory mapped ranges.
1318  *   @discussion This method returns a pointer to an instance of IODeviceMemory for the physical memory range at the given index for a memory mapped device.
1319  *   @param index An index into the array of ranges assigned to the device.
1320  *   @result A pointer to an instance of IODeviceMemory, or zero if the index is beyond the count available. The IODeviceMemory is retained by the provider, so is valid while attached, or while any mappings to it exist. It should not be released by the caller. See also @link mapDeviceMemoryWithIndex mapDeviceMemoryWithIndex@/link, which creates a device memory mapping. */
1321 
1322 	virtual IODeviceMemory * getDeviceMemoryWithIndex( unsigned int index );
1323 
1324 /*! @function mapDeviceMemoryWithIndex
1325  *   @abstract Maps a physical range of a device.
1326  *   @discussion This method creates a mapping for the IODeviceMemory at the given index, with <code>IODeviceMemory::map(options)</code>. The mapping is represented by the returned instance of IOMemoryMap, which should not be released until the mapping is no longer required.
1327  *   @param index An index into the array of ranges assigned to the device.
1328  *   @result An instance of IOMemoryMap, or zero if the index is beyond the count available. The mapping should be released only when access to it is no longer required. */
1329 
1330 	virtual IOMemoryMap * mapDeviceMemoryWithIndex( unsigned int index,
1331 	    IOOptionBits options = 0 );
1332 
1333 /*! @function getDeviceMemory
1334  *   @abstract Returns the array of IODeviceMemory objects representing a device's memory mapped ranges.
1335  *   @discussion This method returns an array of IODeviceMemory objects representing the physical memory ranges allocated to a memory mapped device.
1336  *   @result An OSArray of IODeviceMemory objects, or zero if none are available. The array is retained by the provider, so is valid while attached. */
1337 
1338 	virtual OSArray * getDeviceMemory( void );
1339 
1340 /*! @function setDeviceMemory
1341  *   @abstract Sets the array of IODeviceMemory objects representing a device's memory mapped ranges.
1342  *   @discussion This method sets an array of IODeviceMemory objects representing the physical memory ranges allocated to a memory mapped device.
1343  *   @param array An OSArray of IODeviceMemory objects, or zero if none are available. The array will be retained by the object. */
1344 
1345 	virtual void setDeviceMemory( OSArray * array );
1346 
1347 /* Interrupt accessors */
1348 
1349 /*! @function registerInterrupt
1350  *   @abstract Registers a C function interrupt handler for a device supplying interrupts.
1351  *   @discussion This method installs a C function interrupt handler to be called at primary interrupt time for a device's interrupt. Only one handler may be installed per interrupt source. IOInterruptEventSource provides a work loop based abstraction for interrupt delivery that may be more appropriate for work loop based drivers.
1352  *   @param source The index of the interrupt source in the device.
1353  *   @param target An object instance to be passed to the interrupt handler.
1354  *   @param handler The C function to be called at primary interrupt time when the interrupt occurs. The handler should process the interrupt by clearing the interrupt, or by disabling the source.
1355  *   @param refCon A reference constant for the handler's use.
1356  *   @result An IOReturn code.<br><code>kIOReturnNoInterrupt</code> is returned if the source is not valid; <code>kIOReturnNoResources</code> is returned if the interrupt already has an installed handler. */
1357 
1358 	virtual IOReturn registerInterrupt(int source, OSObject *target,
1359 	    IOInterruptAction handler,
1360 	    void *refCon = NULL);
1361 
1362 #ifdef __BLOCKS__
1363 /*! @function registerInterrupt
1364  *   @abstract Registers a block handler for a device supplying interrupts.
1365  *   @discussion This method installs a C function interrupt handler to be called at primary interrupt time for a device's interrupt. Only one handler may be installed per interrupt source. IOInterruptEventSource provides a work loop based abstraction for interrupt delivery that may be more appropriate for work loop based drivers.
1366  *   @param source The index of the interrupt source in the device.
1367  *   @param target An object instance to be passed to the interrupt handler.
1368  *   @param handler The block to be invoked at primary interrupt time when the interrupt occurs. The handler should process the interrupt by clearing the interrupt, or by disabling the source.
1369  *   @result An IOReturn code.<br><code>kIOReturnNoInterrupt</code> is returned if the source is not valid; <code>kIOReturnNoResources</code> is returned if the interrupt already has an installed handler. */
1370 
1371 	IOReturn registerInterruptBlock(int source, OSObject *target,
1372 	    IOInterruptActionBlock handler);
1373 #endif /* __BLOCKS__ */
1374 
1375 /*! @function unregisterInterrupt
1376  *   @abstract Removes a C function interrupt handler for a device supplying hardware interrupts.
1377  *   @discussion This method removes a C function interrupt handler previously installed with @link registerInterrupt registerInterrupt@/link.
1378  *   @param source The index of the interrupt source in the device.
1379  *   @result An IOReturn code (<code>kIOReturnNoInterrupt</code> is returned if the source is not valid). */
1380 
1381 	virtual IOReturn unregisterInterrupt(int source);
1382 
1383 /*! @function addInterruptStatistics
1384  *   @abstract Adds a statistics object to the IOService for the given interrupt.
1385  *   @discussion This method associates a set of statistics and a reporter for those statistics with an interrupt for this IOService, so that we can interrogate the IOService for statistics pertaining to that interrupt.
1386  *   @param statistics The IOInterruptAccountingData container we wish to associate the IOService with.
1387  *   @param source The index of the interrupt source in the device. */
1388 	IOReturn addInterruptStatistics(IOInterruptAccountingData * statistics, int source);
1389 
1390 /*! @function removeInterruptStatistics
1391  *   @abstract Removes any statistics from the IOService for the given interrupt.
1392  *   @discussion This method disassociates any IOInterruptAccountingData container we may have for the given interrupt from the IOService; this indicates that the the interrupt target (at the moment, likely an IOInterruptEventSource) is being destroyed.
1393  *   @param source The index of the interrupt source in the device. */
1394 	IOReturn removeInterruptStatistics(int source);
1395 
1396 /*! @function getInterruptType
1397  *   @abstract Returns the type of interrupt used for a device supplying hardware interrupts.
1398  *   @param source The index of the interrupt source in the device.
1399  *   @param interruptType The interrupt type for the interrupt source will be stored here by <code>getInterruptType</code>.<br> <code>kIOInterruptTypeEdge</code> will be returned for edge-trigggered sources.<br><code>kIOInterruptTypeLevel</code> will be returned for level-trigggered sources.
1400  *   @result An IOReturn code (<code>kIOReturnNoInterrupt</code> is returned if the source is not valid). */
1401 
1402 	virtual IOReturn getInterruptType(int source, int *interruptType);
1403 
1404 /*! @function enableInterrupt
1405  *   @abstract Enables a device interrupt.
1406  *   @discussion It is the caller's responsiblity to keep track of the enable state of the interrupt source.
1407  *   @param source The index of the interrupt source in the device.
1408  *   @result An IOReturn code (<code>kIOReturnNoInterrupt</code> is returned if the source is not valid). */
1409 
1410 	virtual IOReturn enableInterrupt(int source);
1411 
1412 /*! @function disableInterrupt
1413  *   @abstract Synchronously disables a device interrupt.
1414  *   @discussion If the interrupt routine is running, the call will block until the routine completes. It is the caller's responsiblity to keep track of the enable state of the interrupt source.
1415  *   @param source The index of the interrupt source in the device.
1416  *   @result An IOReturn code (<code>kIOReturnNoInterrupt</code> is returned if the source is not valid). */
1417 
1418 	virtual IOReturn disableInterrupt(int source);
1419 
1420 /*! @function causeInterrupt
1421  *   @abstract Causes a device interrupt to occur.
1422  *   @discussion Emulates a hardware interrupt, to be called from task level.
1423  *   @param source The index of the interrupt source in the device.
1424  *   @result An IOReturn code (<code>kIOReturnNoInterrupt</code> is returned if the source is not valid). */
1425 
1426 	virtual IOReturn causeInterrupt(int source);
1427 
1428 /*! @function requestProbe
1429  *   @abstract Requests that hardware be re-scanned for devices.
1430  *   @discussion For bus families that do not usually detect device addition or removal, this method represents an external request (eg. from a utility application) to rescan and publish or remove found devices.
1431  *   @param options Family defined options, not interpreted by IOService.
1432  *   @result An IOReturn code. */
1433 
1434 	virtual IOReturn requestProbe( IOOptionBits options );
1435 
1436 /* Generic API for non-data-path upstream calls */
1437 
1438 /*! @function message
1439  *   @abstract Receives a generic message delivered from an attached provider.
1440  *   @discussion A provider may deliver messages via the <code>message</code> method to its clients informing them of state changes, such as <code>kIOMessageServiceIsTerminated</code> or <code>kIOMessageServiceIsSuspended</code>. Certain messages are defined by the I/O Kit in <code>IOMessage.h</code> while others may be family dependent. This method is implemented in the client to receive messages.
1441  *   @param type A type defined in <code>IOMessage.h</code> or defined by the provider family.
1442  *   @param provider The provider from which the message originates.
1443  *   @param argument An argument defined by the provider family, not used by IOService.
1444  *   @result An IOReturn code defined by the message type. */
1445 
1446 	virtual IOReturn message( UInt32 type, IOService * provider,
1447 	    void * argument = NULL );
1448 
1449 /*! @function messageClient
1450  *   @abstract Sends a generic message to an attached client.
1451  *   @discussion A provider may deliver messages via the @link message message@/link method to its clients informing them of state changes, such as <code>kIOMessageServiceIsTerminated</code> or <code>kIOMessageServiceIsSuspended</code>. Certain messages are defined by the I/O Kit in <code>IOMessage.h</code> while others may be family dependent. This method may be called in the provider to send a message to the specified client, which may be useful for overrides.
1452  *   @param messageType A type defined in <code>IOMessage.h</code> or defined by the provider family.
1453  *   @param client A client of the IOService to send the message.
1454  *   @param messageArgument An argument defined by the provider family, not used by IOService.
1455  *   @param argSize Specifies the size of messageArgument, in bytes.  If argSize is non-zero, messageArgument is treated as a pointer to argSize bytes of data.  If argSize is 0 (the default), messageArgument is treated as an ordinal and passed by value.
1456  *   @result The return code from the client message call. */
1457 
1458 	virtual IOReturn messageClient( UInt32 messageType, OSObject * client,
1459 	    void * messageArgument = NULL, vm_size_t argSize = 0 );
1460 
1461 /*! @function messageClients
1462  *   @abstract Sends a generic message to all attached clients.
1463  *   @discussion A provider may deliver messages via the @link message message@/link method to its clients informing them of state changes, such as <code>kIOMessageServiceIsTerminated</code> or <code>kIOMessageServiceIsSuspended</code>. Certain messages are defined by the I/O Kit in <code>IOMessage.h</code> while others may be family dependent. This method may be called in the provider to send a message to all the attached clients, via the @link messageClient messageClient@/link method.
1464  *   @param type A type defined in <code>IOMessage.h</code> or defined by the provider family.
1465  *   @param argument An argument defined by the provider family, not used by IOService.
1466  *   @param argSize Specifies the size of argument, in bytes.  If argSize is non-zero, argument is treated as a pointer to argSize bytes of data.  If argSize is 0 (the default), argument is treated as an ordinal and passed by value.
1467  *   @result Any non-<code>kIOReturnSuccess</code> return codes returned by the clients, or <code>kIOReturnSuccess</code> if all return <code>kIOReturnSuccess</code>. */
1468 
1469 	virtual IOReturn messageClients( UInt32 type,
1470 	    void * argument = NULL, vm_size_t argSize = 0 );
1471 
1472 	virtual OSPtr<IONotifier> registerInterest( const OSSymbol * typeOfInterest,
1473 	    IOServiceInterestHandler handler,
1474 	    void * target, void * ref = NULL );
1475 
1476 #ifdef __BLOCKS__
1477 	OSPtr<IONotifier>  registerInterest(const OSSymbol * typeOfInterest,
1478 	    IOServiceInterestHandlerBlock handler);
1479 #endif /* __BLOCKS__ */
1480 
1481 	virtual void applyToProviders( IOServiceApplierFunction applier,
1482 	    void * context );
1483 
1484 	virtual void applyToClients( IOServiceApplierFunction applier,
1485 	    void * context );
1486 
1487 #ifdef __BLOCKS__
1488 	void applyToProviders(IOServiceApplierBlock applier);
1489 	void applyToClients(IOServiceApplierBlock applier);
1490 #endif /* __BLOCKS__ */
1491 
1492 	virtual void applyToInterested( const OSSymbol * typeOfInterest,
1493 	    OSObjectApplierFunction applier,
1494 	    void * context );
1495 
1496 	virtual IOReturn acknowledgeNotification( IONotificationRef notification,
1497 	    IOOptionBits response );
1498 
1499 /* User client create */
1500 
1501 /*! @function newUserClient
1502  *   @abstract Creates a connection for a non kernel client.
1503  *   @discussion A non kernel client may request a connection be opened via the @link //apple_ref/c/func/IOServiceOpen IOServiceOpen@/link library function, which will call this method in an IOService object. The rules and capabilities of user level clients are family dependent, and use the functions of the IOUserClient class for support. IOService's implementation returns <code>kIOReturnUnsupported</code>, so any family supporting user clients must implement this method.
1504  *   @param owningTask The Mach task of the client thread in the process of opening the user client. Note that in Mac OS X, each process is based on a Mach task and one or more Mach threads. For more information on the composition of a Mach task and its relationship with Mach threads, see {@linkdoc //apple_ref/doc/uid/TP30000905-CH209-TPXREF103 "Tasks and Threads"}.
1505  *   @param securityID A token representing the access level for the task.
1506  *   @param type A constant specifying the type of connection to be created, specified by the caller of @link //apple_ref/c/func/IOServiceOpen IOServiceOpen@/link and interpreted only by the family.
1507  *   @param handler An instance of an IOUserClient object to represent the connection, which will be released when the connection is closed, or zero if the connection was not opened.
1508  *   @param properties A dictionary of additional properties for the connection.
1509  *   @result A return code to be passed back to the caller of <code>IOServiceOpen</code>. */
1510 
1511 	virtual IOReturn newUserClient( task_t owningTask, void * securityID,
1512 	    UInt32 type, OSDictionary * properties,
1513 	    LIBKERN_RETURNS_RETAINED IOUserClient ** handler );
1514 
1515 	virtual IOReturn newUserClient( task_t owningTask, void * securityID,
1516 	    UInt32 type,
1517 	    LIBKERN_RETURNS_RETAINED IOUserClient ** handler );
1518 
1519 	IOReturn newUserClient( task_t owningTask, void * securityID,
1520 	    UInt32 type, OSDictionary * properties,
1521 	    OSSharedPtr<IOUserClient>& handler );
1522 
1523 	IOReturn newUserClient( task_t owningTask, void * securityID,
1524 	    UInt32 type,
1525 	    OSSharedPtr<IOUserClient>& handler );
1526 
1527 /* Return code utilities */
1528 
1529 /*! @function stringFromReturn
1530  *   @abstract Supplies a programmer-friendly string from an IOReturn code.
1531  *   @discussion Strings are available for the standard return codes in <code>IOReturn.h</code> in IOService, while subclasses may implement this method to interpret family dependent return codes.
1532  *   @param rtn The IOReturn code.
1533  *   @result A pointer to a constant string, or zero if the return code is unknown. */
1534 
1535 	virtual const char * stringFromReturn( IOReturn rtn );
1536 
1537 /*! @function errnoFromReturn
1538  *   @abstract Translates an IOReturn code to a BSD <code>errno</code>.
1539  *   @discussion BSD defines its own return codes for its functions in <code>sys/errno.h</code>, and I/O Kit families may need to supply compliant results in BSD shims. Results are available for the standard return codes in <code>IOReturn.h</code> in IOService, while subclasses may implement this method to interpret family dependent return codes.
1540  *   @param rtn The IOReturn code.
1541  *   @result The BSD <code>errno</code> or <code>EIO</code> if unknown. */
1542 
1543 	virtual int errnoFromReturn( IOReturn rtn );
1544 
1545 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1546 /* * * * * * * * * * end of IOService API  * * * * * * * */
1547 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1548 
1549 /* for IOInterruptController implementors */
1550 
1551 	int               _numInterruptSources;
1552 	IOInterruptSource *_interruptSources;
1553 
1554 /* overrides */
1555 	virtual bool serializeProperties( OSSerialize * s ) const APPLE_KEXT_OVERRIDE;
1556 
1557 	IOReturn   requireMaxBusStall(UInt32 ns);
1558 	IOReturn   requireMaxInterruptDelay(uint32_t ns);
1559 
1560 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1561 /* * * * * * * * * * * * Internals * * * * * * * * * * * */
1562 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1563 
1564 #ifdef XNU_KERNEL_PRIVATE
1565 public:
1566 // called from other xnu components
1567 	static void initialize( void );
1568 	static void setPlatform( IOPlatformExpert * platform);
1569 	static void setPMRootDomain( class IOPMrootDomain * rootDomain );
1570 	static IOReturn catalogNewDrivers( OSOrderedSet * newTables );
1571 	uint64_t getAccumulatedBusyTime( void );
1572 	static void updateConsoleUsers(OSArray * consoleUsers, IOMessage systemMessage,
1573 	    bool afterUserspaceReboot = false);
1574 	static void consoleLockTimer(thread_call_param_t p0, thread_call_param_t p1);
1575 	void setTerminateDefer(IOService * provider, bool defer);
1576 	uint64_t getAuthorizationID( void );
1577 	IOReturn setAuthorizationID( uint64_t authorizationID );
1578 	void cpusRunning(void);
1579 	void scheduleFinalize(bool now);
1580 	static void willShutdown();
1581 	static void startDeferredMatches();
1582 	static void iokitDaemonLaunched();
1583 	void resetRematchProperties();
1584 	bool hasUserServer() const;
1585 	static void userSpaceWillReboot();
1586 	static void userSpaceDidReboot();
1587 	kern_return_t CopyProperties_Local(OSDictionary ** properties);
1588 
1589 	IOStateNotificationItem * stateNotificationItemCopy(OSString * itemName, OSDictionary * schema);
1590 	kern_return_t stateNotificationListenerAdd(OSArray * items,
1591 	    IOStateNotificationListenerRef * outRef,
1592 	    IOStateNotificationHandler handler);
1593 	kern_return_t stateNotificationListenerRemove(IOStateNotificationListenerRef ref);
1594 
1595 private:
1596 	static IOReturn waitMatchIdle( UInt32 ms );
1597 	static OSPtr<IONotifier>  installNotification(
1598 		const OSSymbol * type, OSDictionary * matching,
1599 		IOServiceMatchingNotificationHandler handler,
1600 		void * target, void * ref,
1601 		SInt32 priority,
1602 		LIBKERN_RETURNS_RETAINED OSIterator ** existing);
1603 #if !defined(__LP64__)
1604 	static OSPtr<IONotifier>  installNotification(
1605 		const OSSymbol * type, OSDictionary * matching,
1606 		IOServiceNotificationHandler handler,
1607 		void * target, void * ref,
1608 		SInt32 priority,
1609 		LIBKERN_RETURNS_RETAINED OSIterator ** existing);
1610 #endif /* !defined(__LP64__) */
1611 #endif
1612 
1613 private:
1614 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
1615 	bool checkResources( void );
1616 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
1617 	bool checkResource( OSObject * matching );
1618 
1619 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
1620 	void probeCandidates( LIBKERN_CONSUMED OSOrderedSet * matches );
1621 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
1622 	bool startCandidate( IOService * candidate );
1623 
1624 public:
1625 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
1626 	IOService * getClientWithCategory( const OSSymbol * category )
1627 	APPLE_KEXT_DEPRECATED;
1628 // copyClientWithCategory is the public replacement
1629 
1630 #ifdef XNU_KERNEL_PRIVATE
1631 /* Callable within xnu source only - but require vtable entries to be visible */
1632 public:
1633 #else
1634 private:
1635 #endif
1636 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
1637 	bool passiveMatch( OSDictionary * matching, bool changesOK = false);
1638 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
1639 	void startMatching( IOOptionBits options = 0 );
1640 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
1641 	void doServiceMatch( IOOptionBits options );
1642 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
1643 	void doServiceTerminate( IOOptionBits options );
1644 
1645 	bool hasParent(IOService * root);
1646 	static void setRootMedia(IOService * root);
1647 	static void publishHiddenMedia(IOService * parent);
1648 	static bool publishHiddenMediaApplier(const OSObject * entry, void * context);
1649 	bool canTerminateForReplacement(IOService * client);
1650 
1651 private:
1652 
1653 	bool matchPassive(OSDictionary * table, uint32_t options);
1654 	bool matchInternal(OSDictionary * table, uint32_t options, unsigned int * did);
1655 	static bool instanceMatch(const OSObject * entry, void * context);
1656 
1657 	static OSPtr<OSObject>  copyExistingServices( OSDictionary * matching,
1658 	    IOOptionBits inState, IOOptionBits options = 0 );
1659 
1660 	static OSPtr<IONotifier>  setNotification(
1661 		const OSSymbol * type, OSDictionary * matching,
1662 		IOServiceMatchingNotificationHandler handler,
1663 		void * target, void * ref,
1664 		SInt32 priority = 0 );
1665 
1666 	static OSPtr<IONotifier>  doInstallNotification(
1667 		const OSSymbol * type, OSDictionary * matching,
1668 		IOServiceMatchingNotificationHandler handler,
1669 		void * target, void * ref,
1670 		SInt32 priority, OSIterator ** existing );
1671 
1672 	static bool syncNotificationHandler( void * target, void * ref,
1673 	    IOService * newService, IONotifier * notifier  );
1674 
1675 	static void userServerCheckInTokenCancellationHandler(
1676 		IOUserServerCheckInToken * token,
1677 		void * ref);
1678 
1679 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
1680 	void deliverNotification( const OSSymbol * type,
1681 	    IOOptionBits orNewState, IOOptionBits andNewState );
1682 
1683 	OSPtr<OSArray>  copyNotifiers(const OSSymbol * type,
1684 	    IOOptionBits orNewState, IOOptionBits andNewState);
1685 
1686 	bool invokeNotifiers(OSArray * willSend[]);
1687 	bool invokeNotifier( class _IOServiceNotifier * notify );
1688 
1689 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
1690 	void unregisterAllInterest( void );
1691 
1692 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
1693 	IOReturn waitForState( UInt32 mask, UInt32 value,
1694 	    mach_timespec_t * timeout = NULL );
1695 
1696 	IOReturn waitForState( UInt32 mask, UInt32 value, uint64_t timeout );
1697 
1698 	UInt32 _adjustBusy( SInt32 delta );
1699 
1700 	bool terminatePhase1( IOOptionBits options = 0 );
1701 	void scheduleTerminatePhase2( IOOptionBits options = 0 );
1702 	void scheduleStop( IOService * provider );
1703 
1704 	static void waitToBecomeTerminateThread( void );
1705 	static void __attribute__((__noreturn__)) terminateThread( void * arg, wait_result_t unused );
1706 	static void terminateWorker( IOOptionBits options );
1707 	static void actionWillTerminate( IOService * victim, IOOptionBits options,
1708 	    OSArray * doPhase2List, bool, void * );
1709 	static void actionDidTerminate( IOService * victim, IOOptionBits options,
1710 	    void *, void *, void *);
1711 
1712 	static void actionWillStop( IOService * victim, IOOptionBits options,
1713 	    void *, void *, void *);
1714 	static void actionDidStop( IOService * victim, IOOptionBits options,
1715 	    void *, void *, void *);
1716 
1717 	static void actionFinalize( IOService * victim, IOOptionBits options,
1718 	    void *, void *, void *);
1719 	static void actionStop( IOService * client, IOService * provider,
1720 	    void *, void *, void *);
1721 
1722 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
1723 	IOReturn resolveInterrupt(IOService *nub, int source);
1724 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
1725 	IOReturn lookupInterrupt(
1726 		int source, bool resolve,
1727 		LIBKERN_RETURNS_NOT_RETAINED IOInterruptController *
1728 		*interruptController);
1729 
1730 #ifdef XNU_KERNEL_PRIVATE
1731 /* end xnu internals */
1732 #endif
1733 
1734 /* power management */
1735 public:
1736 
1737 /*! @function PMinit
1738  *   @abstract Initializes power management for a driver.
1739  *   @discussion <code>PMinit</code> allocates and initializes the power management instance variables, and it should be called before accessing those variables or calling the power management methods. This method should be called inside the driver's <code>start</code> routine and must be paired with a call to @link PMstop PMstop@/link.
1740  *   Most calls to <code>PMinit</code> are followed by calls to @link joinPMtree joinPMtree@/link and @link registerPowerDriver registerPowerDriver@/link. */
1741 
1742 	virtual void PMinit( void );
1743 
1744 /*! @function PMstop
1745  *   @abstract Stop power managing the driver.
1746  *   @discussion Removes the driver from the power plane and stop its power management. This method is synchronous against any power management method invocations (e.g. <code>setPowerState</code> or <code>setAggressiveness</code>), so when this method returns it is guaranteed those power management methods will not be entered. Driver should not call any power management methods after this call.
1747  *   Calling <code>PMstop</code> cleans up for the three power management initialization calls: @link PMinit PMinit@/link, @link joinPMtree joinPMtree@/link, and @link registerPowerDriver registerPowerDriver@/link. */
1748 
1749 	virtual void PMstop( void );
1750 
1751 /*! @function joinPMtree
1752  *   @abstract Joins the driver into the power plane of the I/O Registry.
1753  *   @discussion A driver uses this method to call its nub when initializing (usually in its <code>start</code> routine after calling @link PMinit PMinit@/link), to be attached into the power management hierarchy (i.e., the power plane). A driver usually calls this method on the driver for the device that provides it power (this is frequently the nub).
1754  *   Before this call returns, the caller will probably be called at @link setPowerParent setPowerParent@/link and @link setAggressiveness setAggressiveness@/link and possibly at @link addPowerChild addPowerChild@/link as it is added to the hierarchy. This method may be overridden by a nub subclass.
1755  *   @param driver The driver to be added to the power plane, usually <code>this</code>. */
1756 
1757 	virtual void joinPMtree( IOService * driver );
1758 
1759 /*! @function registerPowerDriver
1760  *   @abstract Registers a set of power states that the driver supports.
1761  *   @discussion A driver defines its array of supported power states with power management in its power management initialization (its <code>start</code> routine). If successful, power management will call the driver to instruct it to change its power state through @link setPowerState setPowerState@/link.
1762  *   Most drivers do not need to override <code>registerPowerDriver</code>. A nub may override <code>registerPowerDriver</code> if it needs to arrange its children in the power plane differently than the default placement, but this is uncommon.
1763  *   @param controllingDriver A pointer to the calling driver, usually <code>this</code>.
1764  *   @param powerStates A driver-defined array of power states that the driver and device support. Power states are defined in <code>pwr_mgt/IOPMpowerState.h</code>.
1765  *   @param numberOfStates The number of power states in the array.
1766  *   @result <code>IOPMNoErr</code>. All errors are logged via <code>kprintf</code>. */
1767 
1768 	virtual IOReturn registerPowerDriver(
1769 		IOService *      controllingDriver,
1770 		IOPMPowerState * powerStates,
1771 		unsigned long    numberOfStates );
1772 
1773 /*! @function registerInterestedDriver
1774  *   @abstract Allows an IOService object to register interest in the changing power state of a power-managed IOService object.
1775  *   @discussion Call <code>registerInterestedDriver</code> on the IOService object you are interested in receiving power state messages from, and pass a pointer to the interested driver (<code>this</code>) as an argument.
1776  *   The interested driver is retained until the power interest is removed by calling <code>deRegisterInterestedDriver</code>.
1777  *   The interested driver should override @link powerStateWillChangeTo powerStateWillChangeTo@/link and @link powerStateDidChangeTo powerStateDidChangeTo@/link to receive these power change messages.
1778  *   Interested drivers must acknowledge power changes in <code>powerStateWillChangeTo</code> or <code>powerStateDidChangeTo</code>, either via return value or later calls to @link acknowledgePowerChange acknowledgePowerChange@/link.
1779  *   @param theDriver The driver of interest adds this pointer to the list of interested drivers. It informs drivers on this list before and after the power change.
1780  *   @result Flags describing the capability of the device in its current power state. If the current power state is not yet defined, zero is returned (this is the case when the driver is not yet in the power domain hierarchy or hasn't fully registered with power management yet). */
1781 
1782 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
1783 	IOPMPowerFlags registerInterestedDriver( IOService * theDriver );
1784 
1785 /*! @function deRegisterInterestedDriver
1786  *   @abstract De-registers power state interest from a previous call to <code>registerInterestedDriver</code>.
1787  *   @discussion The retain from <code>registerInterestedDriver</code> is released. This method is synchronous against any <code>powerStateWillChangeTo</code> or <code>powerStateDidChangeTo</code> call targeting the interested driver, so when this method returns it is guaranteed those interest handlers will not be entered.
1788  *   Most drivers do not need to override <code>deRegisterInterestedDriver</code>.
1789  *   @param theDriver The interested driver previously passed into @link registerInterestedDriver registerInterestedDriver@/link.
1790  *   @result A return code that can be ignored by the caller. */
1791 
1792 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
1793 	IOReturn deRegisterInterestedDriver( IOService * theDriver );
1794 
1795 /*! @function acknowledgePowerChange
1796  *   @abstract Acknowledges an in-progress power state change.
1797  *   @discussion When power management informs an interested object (via @link powerStateWillChangeTo powerStateWillChangeTo@/link or @link powerStateDidChangeTo powerStateDidChangeTo@/link), the object can return an immediate acknowledgement via a return code, or it may return an indication that it will acknowledge later by calling <code>acknowledgePowerChange</code>.
1798  *   Interested objects are those that have registered as interested drivers, as well as power plane children of the power changing driver. A driver that calls @link registerInterestedDriver registerInterestedDriver@/link must call <code>acknowledgePowerChange</code>, or use an immediate acknowledgement return from <code>powerStateWillChangeTo</code> or <code>powerStateDidChangeTo</code>.
1799  *   @param whichDriver A pointer to the calling driver. The called object tracks all interested parties to ensure that all have acknowledged the power state change.
1800  *   @result <code>IOPMNoErr</code>. */
1801 
1802 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
1803 	IOReturn acknowledgePowerChange( IOService * whichDriver );
1804 
1805 /*! @function acknowledgeSetPowerState
1806 *   @abstract Acknowledges the belated completion of a driver's <code>setPowerState</code> power state change.
1807 *   @discussion After power management instructs a driver to change its state via @link setPowerState setPowerState@/link, that driver must acknowledge the change when its device has completed its transition. The acknowledgement may be immediate, via a return code from <code>setPowerState</code>, or delayed, via this call to <code>acknowledgeSetPowerState</code>.
1808 *   Any driver that does not return <code>kIOPMAckImplied</code> from its <code>setPowerState</code> implementation must later call <code>acknowledgeSetPowerState</code>.
1809 *   @result <code>IOPMNoErr</code>. */
1810 
1811 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
1812 	IOReturn acknowledgeSetPowerState( void );
1813 
1814 /*! @function requestPowerDomainState
1815  *   @abstract Tells a driver to adjust its power state.
1816  *   @discussion This call is handled internally by power management. It is not intended to be overridden or called by drivers. */
1817 
1818 	virtual IOReturn requestPowerDomainState(
1819 		IOPMPowerFlags desiredState,
1820 		IOPowerConnection * whichChild,
1821 		unsigned long specificationFlags );
1822 
1823 /*! @function makeUsable
1824  *   @abstract Requests that a device become usable.
1825  *   @discussion This method is called when some client of a device (or the device's own driver) is asking for the device to become usable. Power management responds by telling the object upon which this method is called to change to its highest power state.
1826  *   <code>makeUsable</code> is implemented using @link changePowerStateToPriv changePowerStateToPriv@/link. Subsequent requests for lower power, such as from <code>changePowerStateToPriv</code>, will pre-empt this request.
1827  *   @result A return code that can be ignored by the caller. */
1828 
1829 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
1830 	IOReturn makeUsable( void );
1831 
1832 /*! @function temporaryPowerClampOn
1833  *   @abstract A driver calls this method to hold itself in the highest power state until it has children.
1834  *   @discussion Use <code>temporaryPowerClampOn</code> to hold your driver in its highest power state while waiting for child devices to attach. After children have attached, the clamp is released and the device's power state is controlled by the children's requirements.
1835  *   @result A return code that can be ignored by the caller. */
1836 
1837 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
1838 	IOReturn temporaryPowerClampOn( void );
1839 
1840 /*! @function changePowerStateTo
1841  *   @abstract Sets a driver's power state.
1842  *   @discussion This function is one of several that are used to set a driver's power state. In most circumstances, however, you should call @link changePowerStateToPriv changePowerStateToPriv@/link instead.
1843  *   Calls to <code>changePowerStateTo</code>, <code>changePowerStateToPriv</code>, and a driver's power children all affect the power state of a driver. For legacy design reasons, they have overlapping functionality. Although you should call <code>changePowerStateToPriv</code> to change your device's power state, you might need to call <code>changePowerStateTo</code> in the following circumstances:
1844  *   <ul><li>If a driver will be using <code>changePowerStateToPriv</code> to change its power state, it should call <code>changePowerStateTo(0)</code> in its <code>start</code> routine to eliminate the influence <code>changePowerStateTo</code> has on power state calculations.
1845  *   <li>Call <code>changePowerStateTo</code> in conjunction with @link setIdleTimerPeriod setIdleTimerPeriod@/link and @link activityTickle activityTickle@/link to idle a driver into a low power state. For a driver with 3 power states, for example, <code>changePowerStateTo(1)</code> sets a minimum level of power state 1, such that the idle timer period may not set your device's power any lower than state 1.</ul>
1846  *   @param ordinal The number of the desired power state in the power state array.
1847  *   @result A return code that can be ignored by the caller. */
1848 
1849 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
1850 	IOReturn changePowerStateTo( unsigned long ordinal );
1851 
1852 /*! @function currentCapability
1853  *   @abstract Finds out the capability of a device's current power state.
1854  *   @result A copy of the <code>capabilityFlags</code> field for the current power state in the power state array. */
1855 
1856 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
1857 	IOPMPowerFlags currentCapability( void );
1858 
1859 /*! @function currentPowerConsumption
1860  *   @abstract Finds out the current power consumption of a device.
1861  *   @discussion Most Mac OS X power managed drivers do not report their power consumption via the <code>staticPower</code> field. Thus this call will not accurately reflect power consumption for most drivers.
1862  *   @result A copy of the <code>staticPower</code> field for the current power state in the power state array. */
1863 
1864 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
1865 	unsigned long currentPowerConsumption( void );
1866 
1867 /*! @function activityTickle
1868  *   @abstract Informs power management when a power-managed device is in use, so that power management can track when it is idle and adjust its power state accordingly.
1869  *   @discussion The <code>activityTickle</code> method is provided for objects in the system (or for the driver itself) to tell a driver that its device is being used.
1870  *   The IOService superclass can manage idleness determination with a simple idle timer mechanism and this <code>activityTickle</code> call. To start this up, the driver calls its superclass's <code>setIdleTimerPeriod</code>. This starts a timer for the time interval specified in the call. When the timer expires, the superclass checks to see if there has been any activity since the last timer expiration. (It checks to see if <code>activityTickle</code> has been called). If there has been activity, it restarts the timer, and this process continues. When the timer expires, and there has been no device activity, the superclass lowers the device power state to the next lower state. This can continue until the device is in state zero.
1871  *   After the device has been powered down by at least one power state, a subsequent call to <code>activityTickle</code> causes the device to be switched to a higher state required for the activity.
1872  *   If the driver is managing the idleness determination totally on its own, the value of the <code>type</code> parameter should be <code>kIOPMSubclassPolicy</code>, and the driver should override the <code>activityTickle</code> method. The superclass IOService implementation of <code>activityTickle</code> does nothing with the <code>kIOPMSubclassPolicy</code> argument.
1873  *   @param type When <code>type</code> is <code>kIOPMSubclassPolicy</code>, <code>activityTickle</code> is not handled in IOService and should be intercepted by the subclass. When <code>type</code> is <code>kIOPMSuperclassPolicy1</code>, an activity flag is set and the device state is checked. If the device has been powered down, it is powered up again.
1874  *   @param stateNumber When <code>type</code> is <code>kIOPMSuperclassPolicy1</code>, <code>stateNumber</code> contains the desired power state ordinal for the activity. If the device is in a lower state, the superclass will switch it to this state. This is for devices that can handle some accesses in lower power states; the device is powered up only as far as it needs to be for the activity.
1875  *   @result When <code>type</code> is <code>kIOPMSuperclassPolicy1</code>, the superclass returns <code>true</code> if the device is currently in the state specified by <code>stateNumber</code>. If the device is in a lower state and must be powered up, the superclass returns <code>false</code>; in this case the superclass will initiate a power change to power the device up. */
1876 
1877 	virtual bool activityTickle(
1878 		unsigned long type,
1879 		unsigned long stateNumber = 0 );
1880 
1881 /*! @function setAggressiveness
1882  *   @abstract Broadcasts an aggressiveness factor from the parent of a driver to the driver.
1883  *   @discussion Implement <code>setAggressiveness</code> to receive a notification when an "aggressiveness Aggressiveness factors are a loose set of power management variables that contain values for system sleep timeout, display sleep timeout, whether the system is on battery or AC, and other power management features. There are several aggressiveness factors that can be broadcast and a driver may take action on whichever factors apply to it.
1884  *   A driver that has joined the power plane via @link joinPMtree joinPMtree@/link will receive <code>setAgressiveness</code> calls when aggressiveness factors change.
1885  *   A driver may override this call if it needs to do something with the new factor (such as change its idle timeout). If overridden, the driver must  call its superclass's <code>setAgressiveness</code> method in its own <code>setAgressiveness</code> implementation.
1886  *   Most drivers do not need to implement <code>setAgressiveness</code>.
1887  *   @param type The aggressiveness factor type, such as <code>kPMMinutesToDim</code>, <code>kPMMinutesToSpinDown</code>, <code>kPMMinutesToSleep</code>, and <code>kPMPowerSource</code>. (Aggressiveness factors are defined in <code>pwr_mgt/IOPM.h</code>.)
1888  *   @param newLevel The aggressiveness factor's new value.
1889  *   @result <code>IOPMNoErr</code>. */
1890 
1891 	virtual IOReturn setAggressiveness(
1892 		unsigned long type,
1893 		unsigned long newLevel );
1894 
1895 /*! @function getAggressiveness
1896  *   @abstract Returns the current aggressiveness value for the given type.
1897  *   @param type The aggressiveness factor to query.
1898  *   @param currentLevel Upon successful return, contains the value of aggressiveness factor <code>type</code>.
1899  *   @result <code>kIOReturnSuccess</code> upon success; an I/O Kit error code otherwise. */
1900 
1901 	virtual IOReturn getAggressiveness(
1902 		unsigned long type,
1903 		unsigned long * currentLevel );
1904 
1905 #ifndef __LP64__
1906 /*! @function systemWake
1907  *   @abstract Tells every driver in the power plane that the system is waking up.
1908  *   @discussion This call is handled internally by power management. It is not intended to be overridden or called by drivers. */
1909 
1910 	virtual IOReturn systemWake( void )
1911 	APPLE_KEXT_DEPRECATED;
1912 
1913 /*! @function temperatureCriticalForZone
1914  *   @abstract Alerts a driver to a critical temperature in some thermal zone.
1915  *   @discussion This call is unused by power management. It is not intended to be called or overridden. */
1916 
1917 	virtual IOReturn temperatureCriticalForZone( IOService * whichZone )
1918 	APPLE_KEXT_DEPRECATED;
1919 
1920 /*! @function youAreRoot
1921  *   @abstract Informs power management which IOService object is the power plane root.
1922  *   @discussion This call is handled internally by power management. It is not intended to be overridden or called by drivers. */
1923 
1924 	virtual IOReturn youAreRoot( void )
1925 	APPLE_KEXT_DEPRECATED;
1926 
1927 /*! @function setPowerParent
1928  *   @abstract This call is handled internally by power management. It is not intended to be overridden or called by drivers. */
1929 
1930 	virtual IOReturn setPowerParent(
1931 		IOPowerConnection * parent,
1932 		bool stateKnown,
1933 		IOPMPowerFlags currentState )
1934 	APPLE_KEXT_DEPRECATED;
1935 #endif /* !__LP64__ */
1936 
1937 /*! @function addPowerChild
1938  *   @abstract Informs a driver that it has a new child.
1939  *   @discussion The Platform Expert uses this method to call a driver and introduce it to a new child. This call is handled internally by power management. It is not intended to be overridden or called by drivers.
1940  *   @param theChild A pointer to the child IOService object. */
1941 
1942 	virtual IOReturn addPowerChild( IOService * theChild );
1943 
1944 /*! @function removePowerChild
1945  *   @abstract Informs a power managed driver that one of its power plane childen is disappearing.
1946  *   @discussion This call is handled internally by power management. It is not intended to be overridden or called by drivers. */
1947 
1948 	virtual IOReturn removePowerChild( IOPowerConnection * theChild );
1949 
1950 #ifndef __LP64__
1951 /*! @function command_received
1952  *   @discussion This call is handled internally by power management. It is not intended to be overridden or called by drivers. */
1953 
1954 	virtual void command_received( void *, void *, void *, void * );
1955 #endif
1956 
1957 /*! @function start_PM_idle_timer
1958  *   @discussion This call is handled internally by power management. It is not intended to be overridden or called by drivers. */
1959 
1960 	APPLE_KEXT_COMPATIBILITY_VIRTUAL
1961 	void start_PM_idle_timer( void );
1962 
1963 #ifndef __LP64__
1964 /*! @function PM_idle_timer_expiration
1965  *   @discussion This call is handled internally by power management. It is not intended to be overridden or called by drivers. */
1966 
1967 	virtual void PM_idle_timer_expiration( void )
1968 	APPLE_KEXT_DEPRECATED;
1969 
1970 /*! @function PM_Clamp_Timer_Expired
1971  *   @discussion This call is handled internally by power management. It is not intended to be overridden or called by drivers. */
1972 
1973 	virtual void PM_Clamp_Timer_Expired( void )
1974 	APPLE_KEXT_DEPRECATED;
1975 #endif
1976 
1977 /*! @function setIdleTimerPeriod
1978  *   @abstract Sets or changes the idle timer period.
1979  *   @discussion A driver using the idleness determination provided by IOService calls its superclass with this method to set or change the idle timer period. See @link activityTickle activityTickle@/link for a description of this type of idleness determination.
1980  *   @param period The desired idle timer period in seconds.
1981  *   @result <code>kIOReturnSuccess</code> upon success; an I/O Kit error code otherwise. */
1982 
1983 	virtual IOReturn setIdleTimerPeriod( unsigned long period );
1984 
1985 #ifndef __LP64__
1986 /*! @function getPMworkloop
1987  *   @abstract Returns a pointer to the system-wide power management work loop.
1988  *   @availability Deprecated in Mac OS X version 10.6.
1989  *   @discussion Most drivers should create their own work loops to synchronize their code; drivers should not run arbitrary code on the power management work loop. */
1990 
1991 	virtual IOWorkLoop * getPMworkloop( void )
1992 	APPLE_KEXT_DEPRECATED;
1993 #endif
1994 
1995 /*! @function getPowerState
1996  *   @abstract Determines a device's power state.
1997  *   @discussion A device's "current power state" is updated at the end of each power state transition (e.g. transition from state 1 to state 0, or state 0 to state 2). This transition includes the time spent powering on or off any power plane children. Thus, if a child calls <code>getPowerState</code> on its power parent during system wake from sleep, the call will return the index to the device's off state rather than its on state.
1998  *   @result The current power state's index into the device's power state array. */
1999 
2000 	UInt32 getPowerState( void );
2001 
2002 /*! @function setPowerState
2003  *   @abstract Requests a power managed driver to change the power state of its device.
2004  *   @discussion A power managed driver must override <code>setPowerState</code> to take part in system power management. After a driver is registered with power management, the system uses <code>setPowerState</code> to power the device off and on for system sleep and wake.
2005  *   Calls to @link PMinit PMinit@/link and @link registerPowerDriver registerPowerDriver@/link enable power management to change a device's power state using <code>setPowerState</code>. <code>setPowerState</code> is called in a clean and separate thread context.
2006  *   @param powerStateOrdinal The number in the power state array of the state the driver is being instructed to switch to.
2007  *   @param whatDevice A pointer to the power management object which registered to manage power for this device. In most cases, <code>whatDevice</code> will be equal to your driver's own <code>this</code> pointer.
2008  *   @result The driver must return <code>IOPMAckImplied</code> if it has complied with the request when it returns. Otherwise if it has started the process of changing power state but not finished it, the driver should return a number of microseconds which is an upper limit of the time it will need to finish. Then, when it has completed the power switch, it should call @link acknowledgeSetPowerState acknowledgeSetPowerState@/link. */
2009 
2010 	virtual IOReturn setPowerState(
2011 		unsigned long powerStateOrdinal,
2012 		IOService *   whatDevice );
2013 
2014 #ifndef __LP64__
2015 /*! @function clampPowerOn
2016  *   @abstract Deprecated. Do not use. */
2017 
2018 	virtual void clampPowerOn( unsigned long duration );
2019 #endif
2020 
2021 /*! @function maxCapabilityForDomainState
2022  *   @abstract Determines a driver's highest power state possible for a given power domain state.
2023  *   @discussion This happens when the power domain is changing state and power management needs to determine which state the device is capable of in the new domain state.
2024  *   Most drivers do not need to implement this method, and can rely upon the default IOService implementation. The IOService implementation scans the power state array looking for the highest state whose <code>inputPowerRequirement</code> field exactly matches the value of the <code>domainState</code> parameter. If more intelligent determination is required, the driver itself should implement the method and override the superclass's implementation.
2025  *   @param domainState Flags that describe the character of "domain power"; they represent the <code>outputPowerCharacter</code> field of a state in the power domain's power state array.
2026  *   @result A state number. */
2027 
2028 	virtual unsigned long maxCapabilityForDomainState( IOPMPowerFlags domainState );
2029 
2030 /*! @function initialPowerStateForDomainState
2031  *   @abstract Determines which power state a device is in, given the current power domain state.
2032  *   @discussion Power management calls this method once, when the driver is initializing power management.
2033  *   Most drivers do not need to implement this method, and can rely upon the default IOService implementation. The IOService implementation scans the power state array looking for the highest state whose <code>inputPowerRequirement</code> field exactly matches the value of the <code>domainState</code> parameter. If more intelligent determination is required, the power managed driver should implement the method and override the superclass's implementation.
2034  *   @param domainState Flags that describe the character of "domain power"; they represent the <code>outputPowerCharacter</code> field of a state in the power domain's power state array.
2035  *   @result A state number. */
2036 
2037 	virtual unsigned long initialPowerStateForDomainState( IOPMPowerFlags domainState );
2038 
2039 /*! @function powerStateForDomainState
2040  *   @abstract Determines what power state the device would be in for a given power domain state.
2041  *   @discussion This call is unused by power management. Drivers should override <code>initialPowerStateForDomainState</code> and/or <code>maxCapabilityForDomainState</code> instead to change the default mapping of domain state to driver power state.
2042  *   @param domainState Flags that describe the character of "domain power"; they represent the <code>outputPowerCharacter</code> field of a state in the power domain's power state array.
2043  *   @result A state number. */
2044 
2045 	virtual unsigned long powerStateForDomainState( IOPMPowerFlags domainState );
2046 
2047 /*! @function powerStateWillChangeTo
2048  *   @abstract Informs interested parties that a device is about to change its power state.
2049  *   @discussion Power management informs interested parties that a device is about to change to a different power state. Interested parties are those that have registered for this notification via @link registerInterestedDriver registerInterestedDriver@/link. If you have called <code>registerInterestedDriver</code> on a power managed driver, you must implement <code>powerStateWillChangeTo</code> and @link powerStateDidChangeTo powerStateDidChangeTo@/link to receive the notifications.
2050  *   <code>powerStateWillChangeTo</code> is called in a clean and separate thread context. <code>powerStateWillChangeTo</code> is called before a power state transition takes place; <code>powerStateDidChangeTo</code> is called after the transition has completed.
2051  *   @param capabilities Flags that describe the capability of the device in the new power state (they come from the <code>capabilityFlags</code> field of the new state in the power state array).
2052  *   @param stateNumber The number of the state in the state array that the device is switching to.
2053  *   @param whatDevice A pointer to the driver that is changing. It can be used by a driver that is receiving power state change notifications for multiple devices to distinguish between them.
2054  *   @result The driver returns <code>IOPMAckImplied</code> if it has prepared for the power change when it returns. If it has started preparing but not finished, it should return a number of microseconds which is an upper limit of the time it will need to finish preparing. Then, when it has completed its preparations, it should call @link acknowledgePowerChange acknowledgePowerChange@/link. */
2055 
2056 	virtual IOReturn powerStateWillChangeTo(
2057 		IOPMPowerFlags  capabilities,
2058 		unsigned long   stateNumber,
2059 		IOService *     whatDevice );
2060 
2061 /*! @function powerStateDidChangeTo
2062  *   @abstract Informs interested parties that a device has changed to a different power state.
2063  *   @discussion Power management informs interested parties that a device has changed to a different power state. Interested parties are those that have registered for this notification via @link registerInterestedDriver registerInterestedDriver@/link. If you have called <code>registerInterestedDriver</code> on a power managed driver, you must implemnt @link powerStateWillChangeTo powerStateWillChangeTo@/link and <code>powerStateDidChangeTo</code> to receive the notifications.
2064  *   <code>powerStateDidChangeTo</code> is called in a clean and separate thread context. <code>powerStateWillChangeTo</code> is called before a power state transition takes place; <code>powerStateDidChangeTo</code> is called after the transition has completed.
2065  *   @param capabilities Flags that describe the capability of the device in the new power state (they come from the <code>capabilityFlags</code> field of the new state in the power state array).
2066  *   @param stateNumber The number of the state in the state array that the device is switching to.
2067  *   @param whatDevice A pointer to the driver that is changing. It can be used by a driver that is receiving power state change notifications for multiple devices to distinguish between them.
2068  *   @result The driver returns <code>IOPMAckImplied</code> if it has prepared for the power change when it returns. If it has started preparing but not finished, it should return a number of microseconds which is an upper limit of the time it will need to finish preparing. Then, when it has completed its preparations, it should call @link acknowledgePowerChange acknowledgePowerChange@/link. */
2069 
2070 	virtual IOReturn powerStateDidChangeTo(
2071 		IOPMPowerFlags  capabilities,
2072 		unsigned long   stateNumber,
2073 		IOService *     whatDevice );
2074 
2075 #ifndef __LP64__
2076 /*! @function didYouWakeSystem
2077  *   @abstract Asks a driver if its device is the one that just woke the system from sleep.
2078  *   @availability Deprecated in Mac OS X version 10.6.
2079  *   @discussion Power management calls a power managed driver with this method to ask if its device is the one that just woke the system from sleep. If a device is capable of waking the system from sleep, its driver should implement <code>didYouWakeSystem</code> and return <code>true</code> if its device was responsible for waking the system.
2080  *   @result <code>true</code> if the driver's device woke the system and <code>false</code> otherwise. */
2081 
2082 	virtual bool didYouWakeSystem( void )
2083 	APPLE_KEXT_DEPRECATED;
2084 
2085 /*! @function newTemperature
2086  *   @abstract Tells a power managed driver that the temperature in the thermal zone has changed.
2087  *   @discussion This call is unused by power management. It is not intended to be called or overridden. */
2088 
2089 	virtual IOReturn newTemperature( long currentTemp, IOService * whichZone )
2090 	APPLE_KEXT_DEPRECATED;
2091 #endif
2092 
2093 	virtual bool askChangeDown( unsigned long );
2094 	virtual bool tellChangeDown( unsigned long );
2095 	virtual void tellNoChangeDown( unsigned long );
2096 	virtual void tellChangeUp( unsigned long );
2097 	virtual IOReturn allowPowerChange( unsigned long refcon );
2098 	virtual IOReturn cancelPowerChange( unsigned long refcon );
2099 
2100 protected:
2101 /*! @function changePowerStateToPriv
2102  *   @abstract Tells a driver's superclass to change the power state of its device.
2103  *   @discussion A driver uses this method to tell its superclass to change the power state of the device. This is the recommended way to change the power state of a device.
2104  *   Three things affect driver power state: @link changePowerStateTo changePowerStateTo@/link, <code>changePowerStateToPriv</code>, and the desires of the driver's power plane children. Power management puts the device into the maximum state governed by those three entities.
2105  *   Drivers may eliminate the influence of the <code>changePowerStateTo</code> method on power state one of two ways. See @link powerOverrideOnPriv powerOverrideOnPriv@/link to ignore the method's influence, or call <code>changePowerStateTo(0)</code> in the driver's <code>start</code> routine to remove the <code>changePowerStateTo</code> method's power request.
2106  *   @param ordinal The number of the desired power state in the power state array.
2107  *   @result A return code that can be ignored by the caller. */
2108 public:
2109 	IOReturn changePowerStateToPriv( unsigned long ordinal );
2110 
2111 /*! @function powerOverrideOnPriv
2112  *   @abstract Allows a driver to ignore its children's power management requests and only use changePowerStateToPriv to define its own power state.
2113  *   @discussion Power management normally keeps a device at the highest state required by its requests via @link changePowerStateTo changePowerStateTo@/link, @link changePowerStateToPriv changePowerStateToPriv@/link, and its children. However, a driver may ensure a lower power state than otherwise required by itself and its children using <code>powerOverrideOnPriv</code>. When the override is on, power management keeps the device's power state in the state specified by <code>changePowerStateToPriv</code>. Turning on the override will initiate a power change if the driver's <code>changePowerStateToPriv</code> desired power state is different from the maximum of the <code>changePowerStateTo</code> desired power state and the children's desires.
2114  *   @result A return code that can be ignored by the caller. */
2115 
2116 	IOReturn powerOverrideOnPriv( void );
2117 
2118 /*! @function powerOverrideOffPriv
2119  *   @abstract Allows a driver to disable a power override.
2120  *   @discussion When a driver has enabled an override via @link powerOverrideOnPriv powerOverrideOnPriv@/link, it can disable it again by calling this method in its superclass. Disabling the override reverts to the default algorithm for determining a device's power state. The superclass will now keep the device at the highest state required by <code>changePowerStateTo</code>, <code>changePowerStateToPriv</code>, and its children. Turning off the override will initiate a power change if the driver's desired power state is different from the maximum of the power managed driver's desire and the children's desires.
2121  *   @result A return code that can be ignored by the caller. */
2122 
2123 	IOReturn powerOverrideOffPriv( void );
2124 
2125 /*! @function powerChangeDone
2126  *   @abstract Tells a driver when a power state change is complete.
2127  *   @discussion Power management uses this method to inform a driver when a power change is completely done, when all interested parties have acknowledged the @link powerStateDidChangeTo powerStateDidChangeTo@/link call. The default implementation of this method is null; the method is meant to be overridden by subclassed power managed drivers. A driver should use this method to find out if a power change it initiated is complete.
2128  *   @param stateNumber The number of the state in the state array that the device has switched from. */
2129 
2130 	virtual void powerChangeDone( unsigned long stateNumber );
2131 #ifdef XNU_KERNEL_PRIVATE
2132 /* Power management internals */
2133 public:
2134 	void idleTimerExpired( void );
2135 	void settleTimerExpired( void );
2136 	IOReturn synchronizePowerTree( IOOptionBits options = 0, IOService * notifyRoot = NULL );
2137 	bool assertPMDriverCall( IOPMDriverCallEntry * callEntry, IOOptionBits method, const IOPMinformee * inform = NULL, IOOptionBits options = 0 );
2138 	void deassertPMDriverCall( IOPMDriverCallEntry * callEntry );
2139 	IOReturn changePowerStateWithOverrideTo( IOPMPowerStateIndex ordinal, IOPMRequestTag tag );
2140 	IOReturn changePowerStateWithTagToPriv( IOPMPowerStateIndex ordinal, IOPMRequestTag tag );
2141 	IOReturn changePowerStateWithTagTo( IOPMPowerStateIndex ordinal, IOPMRequestTag tag );
2142 	IOReturn changePowerStateForRootDomain( IOPMPowerStateIndex ordinal );
2143 	IOReturn setIgnoreIdleTimer( bool ignore );
2144 	IOReturn quiescePowerTree( void * target, IOPMCompletionAction action, void * param );
2145 	IOPMPowerStateIndex getPowerStateForClient( const OSSymbol * client );
2146 	static const char * getIOMessageString( uint32_t msg );
2147 	static void setAdvisoryTickleEnable( bool enable );
2148 	void reset_watchdog_timer(IOService *obj, int timeout);
2149 	void start_watchdog_timer( void );
2150 	void stop_watchdog_timer( void );
2151 	void start_watchdog_timer(uint64_t deadline);
2152 	IOReturn registerInterestForNotifier( IONotifier *notify, const OSSymbol * typeOfInterest,
2153 	    IOServiceInterestHandler handler, void * target, void * ref );
2154 
2155 	static IOWorkLoop * getIOPMWorkloop( void );
2156 	bool getBlockingDriverCall(thread_t *thread, const void **callMethod);
2157 	void cancelIdlePowerDown(IOService * service);
2158 
2159 protected:
2160 	bool tellClientsWithResponse( int messageType );
2161 	void tellClients( int messageType );
2162 	void PMDebug( uint32_t event, uintptr_t param1, uintptr_t param2 );
2163 
2164 private:
2165 #ifndef __LP64__
2166 	void ack_timer_ticked( void );
2167 	IOReturn serializedAllowPowerChange2( unsigned long );
2168 	IOReturn serializedCancelPowerChange2( unsigned long );
2169 	IOReturn powerDomainWillChangeTo( IOPMPowerFlags, IOPowerConnection * );
2170 	IOReturn powerDomainDidChangeTo( IOPMPowerFlags, IOPowerConnection * );
2171 #endif
2172 	static void allocPMInitLock( void );
2173 	void PMfree( void );
2174 	bool tellChangeDown1( unsigned long );
2175 	bool tellChangeDown2( unsigned long );
2176 	IOReturn startPowerChange( IOPMPowerChangeFlags, IOPMPowerStateIndex, IOPMPowerFlags, IOPowerConnection *, IOPMPowerFlags );
2177 	void setParentInfo( IOPMPowerFlags, IOPowerConnection *, bool );
2178 	IOReturn notifyAll( uint32_t nextMS );
2179 	bool notifyChild( IOPowerConnection * child );
2180 	IOPMPowerStateIndex getPowerStateForDomainFlags( IOPMPowerFlags flags );
2181 
2182 // power change initiated by driver
2183 	void OurChangeStart( void );
2184 	void OurSyncStart( void );
2185 	void OurChangeTellClientsPowerDown( void );
2186 	void OurChangeTellUserPMPolicyPowerDown( void );
2187 	void OurChangeTellPriorityClientsPowerDown( void );
2188 	void OurChangeTellCapabilityWillChange( void );
2189 	void OurChangeNotifyInterestedDriversWillChange( void );
2190 	void OurChangeSetPowerState( void );
2191 	void OurChangeWaitForPowerSettle( void );
2192 	void OurChangeNotifyInterestedDriversDidChange( void );
2193 	void OurChangeTellCapabilityDidChange( void );
2194 	void OurChangeFinish( void );
2195 
2196 // downward power change initiated by a power parent
2197 	IOReturn ParentChangeStart( void );
2198 	void ParentChangeTellPriorityClientsPowerDown( void );
2199 	void ParentChangeTellCapabilityWillChange( void );
2200 	void ParentChangeNotifyInterestedDriversWillChange( void );
2201 	void ParentChangeSetPowerState( void );
2202 	void ParentChangeWaitForPowerSettle( void );
2203 	void ParentChangeNotifyInterestedDriversDidChange( void );
2204 	void ParentChangeTellCapabilityDidChange( void );
2205 	void ParentChangeAcknowledgePowerChange( void );
2206 	void ParentChangeRootChangeDown( void );
2207 
2208 	void all_done( void );
2209 	void start_ack_timer( void );
2210 	void stop_ack_timer( void );
2211 	void start_ack_timer( UInt32 value, UInt32 scale );
2212 	void startSettleTimer( void );
2213 	void start_spindump_timer( const char * delay_type );
2214 	void stop_spindump_timer( void );
2215 	bool checkForDone( void );
2216 	bool responseValid( uint32_t x, int pid );
2217 	void computeDesiredState( unsigned long tempDesire, bool computeOnly );
2218 	void trackSystemSleepPreventers( IOPMPowerStateIndex, IOPMPowerStateIndex, IOPMPowerChangeFlags );
2219 	void tellSystemCapabilityChange( uint32_t nextMS );
2220 	void restartIdleTimer( void );
2221 
2222 	static void ack_timer_expired( thread_call_param_t, thread_call_param_t );
2223 	static void watchdog_timer_expired( thread_call_param_t arg0, thread_call_param_t arg1 );
2224 	static void spindump_timer_expired( thread_call_param_t arg0, thread_call_param_t arg1 );
2225 	static IOReturn actionAckTimerExpired(OSObject *, void *, void *, void *, void * );
2226 	static IOReturn actionSpinDumpTimerExpired(OSObject *, void *, void *, void *, void * );
2227 
2228 	static IOReturn actionDriverCalloutDone(OSObject *, void *, void *, void *, void * );
2229 	static IOPMRequest * acquirePMRequest( IOService * target, IOOptionBits type, IOPMRequest * active = NULL );
2230 	static void releasePMRequest( IOPMRequest * request );
2231 	static void pmDriverCallout( IOService * from, thread_call_param_t );
2232 	static void pmTellAppWithResponse( OSObject * object, void * context );
2233 	static void pmTellClientWithResponse( OSObject * object, void * context );
2234 	static void pmTellCapabilityAppWithResponse( OSObject * object, void * arg );
2235 	static void pmTellCapabilityClientWithResponse( OSObject * object, void * arg );
2236 	static void submitPMRequest(LIBKERN_CONSUMED IOPMRequest * request );
2237 	static void submitPMRequests( IOPMRequest * requests[], IOItemCount count );
2238 	bool ackTimerTick( void );
2239 	void addPowerChild1( IOPMRequest * request );
2240 	void addPowerChild2( IOPMRequest * request );
2241 	void addPowerChild3( IOPMRequest * request );
2242 	void adjustPowerState( IOPMPowerStateIndex clamp = 0 );
2243 	void handlePMstop( IOPMRequest * request );
2244 	void handleRegisterPowerDriver( IOPMRequest * request );
2245 	bool handleAcknowledgePowerChange( IOPMRequest * request );
2246 	bool handleAcknowledgeSetPowerState( IOPMRequest * request );
2247 	void handlePowerDomainWillChangeTo( IOPMRequest * request );
2248 	void handlePowerDomainDidChangeTo( IOPMRequest * request );
2249 	void handleRequestPowerState( IOPMRequest * request );
2250 	void handlePowerOverrideChanged( IOPMRequest * request );
2251 	bool _activityTickle( unsigned long type, unsigned long stateNumber );
2252 	void handleDeferredActivityTickle( IOPMRequest * request );
2253 	void handleActivityTickle( IOPMRequest * request );
2254 	void handleInterestChanged( IOPMRequest * request );
2255 	void handleSynchronizePowerTree( IOPMRequest * request );
2256 	void executePMRequest( IOPMRequest * request );
2257 	bool actionPMWorkQueueInvoke( IOPMRequest * request, IOPMWorkQueue * queue );
2258 	bool actionPMWorkQueueRetire( IOPMRequest * request, IOPMWorkQueue * queue );
2259 	bool actionPMRequestQueue( IOPMRequest * request, IOPMRequestQueue * queue );
2260 	bool actionPMReplyQueue( IOPMRequest * request, IOPMRequestQueue * queue );
2261 	bool actionPMCompletionQueue( LIBKERN_CONSUMED IOPMRequest * request, IOPMCompletionQueue * queue );
2262 	bool notifyInterestedDrivers( void );
2263 	void notifyInterestedDriversDone( void );
2264 	bool notifyControllingDriver( void );
2265 	void notifyControllingDriverDone( void );
2266 	void driverSetPowerState( void );
2267 	void driverInformPowerChange( void );
2268 	bool isPMBlocked( IOPMRequest * request, int count );
2269 	void notifyChildren( void );
2270 	void notifyChildrenOrdered( void );
2271 	void notifyChildrenDelayed( void );
2272 	void notifyRootDomain( void );
2273 	void notifyRootDomainDone( void );
2274 	void cleanClientResponses( bool logErrors );
2275 	void updatePowerClient( const OSSymbol * client, IOPMPowerStateIndex powerState );
2276 	void removePowerClient( const OSSymbol * client );
2277 	IOReturn requestPowerState( const OSSymbol * client, IOPMPowerStateIndex state, IOPMRequestTag tag = 0 );
2278 	IOReturn requestDomainPower( IOPMPowerStateIndex ourPowerState, IOOptionBits options = 0 );
2279 	IOReturn configurePowerStatesReport( IOReportConfigureAction action, void *result );
2280 	IOReturn updatePowerStatesReport( IOReportConfigureAction action, void *result, void *destination );
2281 	IOReturn configureSimplePowerReport(IOReportConfigureAction action, void *result );
2282 	IOReturn updateSimplePowerReport( IOReportConfigureAction action, void *result, void *destination );
2283 	void waitForPMDriverCall( IOService * target = NULL );
2284 #endif /* XNU_KERNEL_PRIVATE */
2285 };
2286 
2287 #ifdef PRIVATE
2288 
2289 class IOServiceCompatibility : public IOService
2290 {
2291 	OSDeclareDefaultStructors(IOServiceCompatibility);
2292 };
2293 
2294 #endif /* PRIVATE */
2295 
2296 #endif /* ! _IOKIT_IOSERVICE_H */
2297