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