]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/IOService.h
xnu-1699.22.73.tar.gz
[apple/xnu.git] / iokit / IOKit / IOService.h
1 /*
2 * Copyright (c) 1998-2009 Apple Computer, 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
56 extern "C" {
57 #include <kern/thread_call.h>
58 }
59
60 #ifndef UINT64_MAX
61 #define UINT64_MAX 18446744073709551615ULL
62 #endif
63
64 enum {
65 kIODefaultProbeScore = 0
66 };
67
68 // masks for getState()
69 enum {
70 kIOServiceInactiveState = 0x00000001,
71 kIOServiceRegisteredState = 0x00000002,
72 kIOServiceMatchedState = 0x00000004,
73 kIOServiceFirstPublishState = 0x00000008,
74 kIOServiceFirstMatchState = 0x00000010
75 };
76
77 enum {
78 // options for registerService()
79 kIOServiceExclusive = 0x00000001,
80
81 // options for terminate()
82 kIOServiceRequired = 0x00000001,
83 kIOServiceTerminate = 0x00000004,
84
85 // options for registerService() & terminate()
86 kIOServiceSynchronous = 0x00000002,
87 // options for registerService()
88 kIOServiceAsynchronous = 0x00000008
89 };
90
91 // options for open()
92 enum {
93 kIOServiceSeize = 0x00000001,
94 kIOServiceFamilyOpenOptions = 0xffff0000
95 };
96
97 // options for close()
98 enum {
99 kIOServiceFamilyCloseOptions = 0xffff0000
100 };
101
102 typedef void * IONotificationRef;
103
104 extern const IORegistryPlane * gIOServicePlane;
105 extern const IORegistryPlane * gIOPowerPlane;
106
107 extern const OSSymbol * gIOResourcesKey;
108 extern const OSSymbol * gIOResourceMatchKey;
109 extern const OSSymbol * gIOProviderClassKey;
110 extern const OSSymbol * gIONameMatchKey;
111 extern const OSSymbol * gIONameMatchedKey;
112 extern const OSSymbol * gIOPropertyMatchKey;
113 extern const OSSymbol * gIOLocationMatchKey;
114 extern const OSSymbol * gIOParentMatchKey;
115 extern const OSSymbol * gIOPathMatchKey;
116 extern const OSSymbol * gIOMatchCategoryKey;
117 extern const OSSymbol * gIODefaultMatchCategoryKey;
118 extern const OSSymbol * gIOMatchedServiceCountKey;
119
120 extern const OSSymbol * gIOUserClientClassKey;
121 extern const OSSymbol * gIOKitDebugKey;
122 extern const OSSymbol * gIOServiceKey;
123
124 extern const OSSymbol * gIOCommandPoolSizeKey;
125
126 extern const OSSymbol * gIOPublishNotification;
127 extern const OSSymbol * gIOFirstPublishNotification;
128 extern const OSSymbol * gIOMatchedNotification;
129 extern const OSSymbol * gIOFirstMatchNotification;
130 extern const OSSymbol * gIOTerminatedNotification;
131
132 extern const OSSymbol * gIOGeneralInterest;
133 extern const OSSymbol * gIOBusyInterest;
134 extern const OSSymbol * gIOOpenInterest;
135 extern const OSSymbol * gIOAppPowerStateInterest;
136 extern const OSSymbol * gIOPriorityPowerStateInterest;
137 extern const OSSymbol * gIOConsoleSecurityInterest;
138
139 extern const OSSymbol * gIODeviceMemoryKey;
140 extern const OSSymbol * gIOInterruptControllersKey;
141 extern const OSSymbol * gIOInterruptSpecifiersKey;
142
143 extern SInt32 IOServiceOrdering( const OSMetaClassBase * inObj1, const OSMetaClassBase * inObj2, void * ref );
144
145 typedef void (*IOInterruptAction)( OSObject * target, void * refCon,
146 IOService * nub, int source );
147
148 /*! @typedef IOServiceNotificationHandler
149 @param target Reference supplied when the notification was registered.
150 @param refCon Reference constant supplied when the notification was registered.
151 @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. */
152
153 typedef bool (*IOServiceNotificationHandler)( void * target, void * refCon,
154 IOService * newService );
155
156 typedef bool (*IOServiceMatchingNotificationHandler)( void * target, void * refCon,
157 IOService * newService,
158 IONotifier * notifier );
159
160 /*! @typedef IOServiceInterestHandler
161 @param target Reference supplied when the notification was registered.
162 @param refCon Reference constant supplied when the notification was registered.
163 @param messageType Type of the message - IOKit defined in IOKit/IOMessage.h or family specific.
164 @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.
165 @param messageArgument An argument for message, dependent on its type.
166 @param argSize Non zero if the argument represents a struct of that size, used when delivering messages outside the kernel. */
167
168 typedef IOReturn (*IOServiceInterestHandler)( void * target, void * refCon,
169 UInt32 messageType, IOService * provider,
170 void * messageArgument, vm_size_t argSize );
171
172 typedef void (*IOServiceApplierFunction)(IOService * service, void * context);
173 typedef void (*OSObjectApplierFunction)(OSObject * object, void * context);
174
175 class IOUserClient;
176 class IOPlatformExpert;
177
178 /*! @class IOService
179 @abstract The base class for most I/O Kit families, devices, and drivers.
180 @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.
181
182 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 OpenFirmware 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.
183
184 Matching dictionaries are associated with IOService classes by the catalogue, as driver property tables, and also supplied by clients of the notification APIs.
185
186 IOService provides matching based on C++ class (via OSMetaClass dynamic casting), registry entry name, a registry path to the service (which includes OpenFirmware paths), a name assigned by BSD, or by its location (its point of attachment).
187
188 <br><br>Driver Instantiation by IOService<br><br>
189
190 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.
191
192 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.
193
194 Each entry in the list is then processed in order - for notifications, the notification is delivered, for driver property tables a lot more happens.
195
196 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).
197
198 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.
199
200 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.
201
202 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.
203
204 After the drivers have all synchronously been started, the installed "matched" notifications that match the registered IOService are delivered.
205
206 <br><br>Properties used by IOService<br><br>
207
208 <code>kIOClassKey, extern const OSSymbol * gIOClassKey, "IOClass"</code>
209 <br>
210 <br>
211 Class of the driver to instantiate on matching providers.
212 <br>
213 <br>
214 <code>kIOProviderClassKey, extern const OSSymbol * gIOProviderClassKey, "IOProviderClass"</code>
215 <br>
216 <br>
217 Class of the provider(s) to be considered for matching, checked with OSDynamicCast so subclasses will also match.
218 <br>
219 <br>
220 <code>kIOProbeScoreKey, extern const OSSymbol * gIOProbeScoreKey, "IOProbeScore"</code>
221 <br>
222 <br>
223 The probe score initially used to order multiple matching drivers.
224 <br>
225 <br>
226 <code>kIOMatchCategoryKey, extern const OSSymbol * gIOMatchCategoryKey, "IOMatchCategory"</code>
227 <br>
228 <br>
229 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.
230 <br>
231 <br>
232 <code>kIONameMatchKey, extern const OSSymbol * gIONameMatchKey, "IONameMatch"</code>
233 <br>
234 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 OpenFirmware 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.
235 <br>
236 Examples
237 <pre>
238 @textblock
239 <key>IONameMatch</key>
240 <string>pci106b,7</string>
241 @/textblock
242 </pre>
243
244 For a list of possible matching names, a serialized array of strings should used, eg.
245 <pre>
246 @textblock
247 <key>IONameMatch</key>
248 <array>
249 <string>APPL,happy16</string>
250 <string>pci106b,7</string>
251 </array>
252 @/textblock
253 </pre>
254
255 <br>
256 <code>kIONameMatchedKey, extern const OSSymbol * gIONameMatchedKey, "IONameMatched"</code>
257 <br>
258 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.
259 <br>
260 <br>
261 <code>kIOPropertyMatchKey, extern const OSSymbol * gIOPropertyMatchKey, "IOPropertyMatch"</code>
262 <br>
263 A dictionary of properties that each must exist in the matching IOService and compare successfully with the <code>isEqualTo</code> method.
264
265 <pre>
266 @textblock
267 <key>IOPropertyMatch</key>
268 <dictionary>
269 <key>APPL,happy16</key>
270 <string>APPL,meek8</string>
271 </dictionary>
272 @/textblock
273 </pre>
274
275 <br>
276 <code>kIOUserClientClassKey, extern const OSSymbol * gIOUserClientClassKey, "IOUserClientClass"</code>
277 <br>
278 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.
279 <br>
280 <br>
281 <code>kIOKitDebugKey, extern const OSSymbol * gIOKitDebugKey, "IOKitDebug"</code>
282 <br>
283 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.*/
284
285 class IOService : public IORegistryEntry
286 {
287 OSDeclareDefaultStructors(IOService)
288
289 protected:
290 /*! @struct ExpansionData
291 @discussion This structure will be used to expand the capablilties of this class in the future.
292 */
293 struct ExpansionData { };
294
295 /*! @var reserved
296 Reserved for future use. (Internal use only) */
297 ExpansionData * reserved;
298
299 private:
300 IOService * __provider;
301 SInt32 __providerGeneration;
302 IOService * __owner;
303 IOOptionBits __state[2];
304 uint64_t __timeBusy;
305 uint64_t __accumBusy;
306 IOServicePM * pwrMgt;
307
308 protected:
309 // TRUE once PMinit has been called
310 bool initialized;
311
312 public:
313 // DEPRECATED
314 void * pm_vars;
315
316 public:
317 /* methods available in Mac OS X 10.1 or later */
318 /*! @function requestTerminate
319 @abstract Passes a termination up the stack.
320 @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.
321 @param provider The terminated provider of this object.
322 @param options Options originally passed to terminate, plus <code>kIOServiceRecursing</code>.
323 @result <code>true</code> if this object should be terminated now that its provider has been. */
324
325 virtual bool requestTerminate( IOService * provider, IOOptionBits options );
326
327 /*! @function willTerminate
328 @abstract Passes a termination up the stack.
329 @discussion Notification that a provider has been terminated, sent before recursing up the stack, in root-to-leaf order.
330 @param provider The terminated provider of this object.
331 @param options Options originally passed to terminate.
332 @result <code>true</code>. */
333
334 virtual bool willTerminate( IOService * provider, IOOptionBits options );
335
336 /*! @function didTerminate
337 @abstract Passes a termination up the stack.
338 @discussion Notification that a provider has been terminated, sent after recursing up the stack, in leaf-to-root order.
339 @param provider The terminated provider of this object.
340 @param options Options originally passed to terminate.
341 @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>.
342 @result <code>true</code>. */
343
344 virtual bool didTerminate( IOService * provider, IOOptionBits options, bool * defer );
345
346 /*! @function nextIdleTimeout
347 @availability Mac OS X v10.4 and later
348 @abstract Allows subclasses to customize idle power management behavior.
349 @discussion Returns the next time that the device should idle into its next lower power state. Subclasses may override for custom idle behavior.
350
351 A power managed driver might override this method to provide a more sophisticated idle power off algorithm than the one defined by power management.
352 @param currentTime The current time
353 @param lastActivity The time of last activity on this device
354 @param powerState The device's current power state.
355 @result Returns the next time the device should idle off (in seconds, relative to the current time). */
356
357 virtual SInt32 nextIdleTimeout(AbsoluteTime currentTime,
358 AbsoluteTime lastActivity, unsigned int powerState);
359
360 /*! @function systemWillShutdown
361 @availability Mac OS X v10.5 and later
362 @abstract Notifies members of the power plane of system shutdown and restart.
363 @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.
364
365 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.
366 @param specifier <code>kIOMessageSystemWillPowerOff</code> or <code>kIOMessageSystemWillRestart</code>. */
367
368 virtual void systemWillShutdown( IOOptionBits specifier );
369
370 /*! @function copyClientWithCategory
371 @availability Mac OS X v10.6 and later
372 @param category An OSSymbol corresponding to an IOMatchCategory matching property.
373 @result Returns a reference to the IOService child with the given category. The result should be released by the caller.
374 */
375
376 virtual IOService * copyClientWithCategory( const OSSymbol * category );
377
378 private:
379 #if __LP64__
380 OSMetaClassDeclareReservedUnused(IOService, 0);
381 OSMetaClassDeclareReservedUnused(IOService, 1);
382 OSMetaClassDeclareReservedUnused(IOService, 2);
383 OSMetaClassDeclareReservedUnused(IOService, 3);
384 OSMetaClassDeclareReservedUnused(IOService, 4);
385 OSMetaClassDeclareReservedUnused(IOService, 5);
386 #else
387 OSMetaClassDeclareReservedUsed(IOService, 0);
388 OSMetaClassDeclareReservedUsed(IOService, 1);
389 OSMetaClassDeclareReservedUsed(IOService, 2);
390 OSMetaClassDeclareReservedUsed(IOService, 3);
391 OSMetaClassDeclareReservedUsed(IOService, 4);
392 OSMetaClassDeclareReservedUsed(IOService, 5);
393 #endif
394
395 OSMetaClassDeclareReservedUnused(IOService, 6);
396 OSMetaClassDeclareReservedUnused(IOService, 7);
397 OSMetaClassDeclareReservedUnused(IOService, 8);
398 OSMetaClassDeclareReservedUnused(IOService, 9);
399 OSMetaClassDeclareReservedUnused(IOService, 10);
400 OSMetaClassDeclareReservedUnused(IOService, 11);
401 OSMetaClassDeclareReservedUnused(IOService, 12);
402 OSMetaClassDeclareReservedUnused(IOService, 13);
403 OSMetaClassDeclareReservedUnused(IOService, 14);
404 OSMetaClassDeclareReservedUnused(IOService, 15);
405 OSMetaClassDeclareReservedUnused(IOService, 16);
406 OSMetaClassDeclareReservedUnused(IOService, 17);
407 OSMetaClassDeclareReservedUnused(IOService, 18);
408 OSMetaClassDeclareReservedUnused(IOService, 19);
409 OSMetaClassDeclareReservedUnused(IOService, 20);
410 OSMetaClassDeclareReservedUnused(IOService, 21);
411 OSMetaClassDeclareReservedUnused(IOService, 22);
412 OSMetaClassDeclareReservedUnused(IOService, 23);
413 OSMetaClassDeclareReservedUnused(IOService, 24);
414 OSMetaClassDeclareReservedUnused(IOService, 25);
415 OSMetaClassDeclareReservedUnused(IOService, 26);
416 OSMetaClassDeclareReservedUnused(IOService, 27);
417 OSMetaClassDeclareReservedUnused(IOService, 28);
418 OSMetaClassDeclareReservedUnused(IOService, 29);
419 OSMetaClassDeclareReservedUnused(IOService, 30);
420 OSMetaClassDeclareReservedUnused(IOService, 31);
421 OSMetaClassDeclareReservedUnused(IOService, 32);
422 OSMetaClassDeclareReservedUnused(IOService, 33);
423 OSMetaClassDeclareReservedUnused(IOService, 34);
424 OSMetaClassDeclareReservedUnused(IOService, 35);
425 OSMetaClassDeclareReservedUnused(IOService, 36);
426 OSMetaClassDeclareReservedUnused(IOService, 37);
427 OSMetaClassDeclareReservedUnused(IOService, 38);
428 OSMetaClassDeclareReservedUnused(IOService, 39);
429 OSMetaClassDeclareReservedUnused(IOService, 40);
430 OSMetaClassDeclareReservedUnused(IOService, 41);
431 OSMetaClassDeclareReservedUnused(IOService, 42);
432 OSMetaClassDeclareReservedUnused(IOService, 43);
433 OSMetaClassDeclareReservedUnused(IOService, 44);
434 OSMetaClassDeclareReservedUnused(IOService, 45);
435 OSMetaClassDeclareReservedUnused(IOService, 46);
436 OSMetaClassDeclareReservedUnused(IOService, 47);
437
438 public:
439 /*! @function getState
440 @abstract Accessor for IOService state bits, not normally needed or used outside IOService.
441 @result State bits for the IOService, eg. <code>kIOServiceInactiveState</code>, <code>kIOServiceRegisteredState</code>. */
442
443 virtual IOOptionBits getState( void ) const;
444
445 /*! @function isInactive
446 @abstract Checks if the IOService object has been terminated, and is in the process of being destroyed.
447 @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.
448 @result <code>true</code> if the IOService object has been terminated. */
449
450 bool isInactive( void ) const;
451
452 /* Stack creation */
453
454 /*! @function registerService
455 @abstract Starts the registration process for a newly discovered IOService object.
456 @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.
457 @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. */
458
459 virtual void registerService( IOOptionBits options = 0 );
460
461 /*! @function probe
462 @abstract During an IOService object's instantiation, probes a matched service to see if it can be used.
463 @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.
464 @param provider The registered IOService object that matches a driver personality's matching dictionary.
465 @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.
466 @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>. */
467
468 virtual IOService * probe( IOService * provider,
469 SInt32 * score );
470
471 /*! @function start
472 @abstract During an IOService object's instantiation, starts the IOService object that has been selected to run on the provider.
473 @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.
474 @result <code>true</code> if the start was successful; <code>false</code> otherwise (which will cause the instance to be detached and usually freed). */
475
476 virtual bool start( IOService * provider );
477
478 /*! @function stop
479 @abstract During an IOService termination, the stop method is called in its clients before they are detached & it is destroyed.
480 @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. */
481
482 virtual void stop( IOService * provider );
483
484 /* Open / Close */
485
486 /*! @function open
487 @abstract Requests active access to a provider.
488 @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.
489 @param forClient Designates the client of the provider requesting the open.
490 @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.
491 @result <code>true</code> if the open was successful; <code>false</code> otherwise. */
492
493 virtual bool open( IOService * forClient,
494 IOOptionBits options = 0,
495 void * arg = 0 );
496
497 /*! @function close
498 @abstract Releases active access to a provider.
499 @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.
500 @param forClient Designates the client of the provider requesting the close.
501 @param options Options available for the close. The provider family may implement options for close; IOService defines none.
502 @param arg Family specific arguments which are ignored by IOService. */
503
504 virtual void close( IOService * forClient,
505 IOOptionBits options = 0 );
506
507 /*! @function isOpen
508 @abstract Determines whether a specific, or any, client has an IOService object open.
509 @discussion Returns the open state of an IOService object with respect to the specified client, or when it is open by any client.
510 @param forClient If non-zero, <codeisOpen</code returns the open state for that client. If zero is passed, <codeisOpen</code returns the open state for all clients.
511 @result <codetrue</code if the specific, or any, client has the IOService object open. */
512
513 virtual bool isOpen( const IOService * forClient = 0 ) const;
514
515 /*! @function handleOpen
516 @abstract Controls the open / close behavior of an IOService object (overrideable by subclasses).
517 @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.
518 @param forClient Designates the client of the provider requesting the open.
519 @param options Options for the open, may be interpreted by the implementor of <code>handleOpen</code>.
520 @result <code>true</code>if the open was successful; <code>false</code> otherwise. */
521
522 virtual bool handleOpen( IOService * forClient,
523 IOOptionBits options,
524 void * arg );
525
526 /*! @function handleClose
527 @abstract Controls the open / close behavior of an IOService object (overrideable by subclasses).
528 @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.
529 @param forClient Designates the client of the provider requesting the close.
530 @param options Options for the close, may be interpreted by the implementor of @link handleOpen handleOpen@/link. */
531
532 virtual void handleClose( IOService * forClient,
533 IOOptionBits options );
534
535 /*! @function handleIsOpen
536 @abstract Controls the open / close behavior of an IOService object (overrideable by subclasses).
537 @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.
538 @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.
539 @result <code>true</code> if the specific, or any, client has the IOService object open. */
540
541 virtual bool handleIsOpen( const IOService * forClient ) const;
542
543 /* Stacking change */
544
545 /*! @function terminate
546 @abstract Makes an IOService object inactive and begins its destruction.
547 @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.
548 @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. */
549
550 virtual bool terminate( IOOptionBits options = 0 );
551
552 /*! @function finalize
553 @abstract Finalizes the destruction of an IOService object.
554 @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.
555 @param options The options passed to the @link terminate terminate@/link method of the IOService object are passed on to <code>finalize</code>.
556 @result <code>true</code>. */
557
558 virtual bool finalize( IOOptionBits options );
559
560 /*! @function free
561 @abstract Frees data structures that were allocated when power management was initialized on this service. */
562
563 virtual void free( void );
564
565 /*! @function lockForArbitration
566 @abstract Locks an IOService object against changes in state or ownership.
567 @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.
568 @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>. */
569
570 virtual bool lockForArbitration( bool isSuccessRequired = true );
571
572 /*! @function unlockForArbitration
573 @abstract Unlocks an IOService obkect after a successful @link lockForArbitration lockForArbitration@/link.
574 @discussion A thread granted exclusive access to an IOService object should release it with <code>unlockForArbitration</code>. */
575
576 virtual void unlockForArbitration( void );
577
578 /*! @function terminateClient
579 @abstract Passes a termination up the stack.
580 @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.
581 @param client The client of the terminated provider.
582 @param options Options originally passed to @link terminate terminate@/link, plus <code>kIOServiceRecursing</code>.
583 @result result of the terminate request on the client. */
584
585 virtual bool terminateClient( IOService * client, IOOptionBits options );
586
587 /* Busy state indicates discovery, matching or termination is in progress */
588
589 /*! @function getBusyState
590 @abstract Returns the <code>busyState</code> of an IOService object.
591 @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.
592 @result The <code>busyState</code> value. */
593
594 virtual UInt32 getBusyState( void );
595
596 /*! @function adjustBusy
597 @abstract Adjusts the <code>busyState</code> of an IOService object.
598 @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).
599 @param delta The delta to be applied to the IOService object's <code>busyState</code>. */
600
601 virtual void adjustBusy( SInt32 delta );
602
603 APPLE_KEXT_COMPATIBILITY_VIRTUAL
604 IOReturn waitQuiet(mach_timespec_t * timeout)
605 APPLE_KEXT_DEPRECATED;
606
607 /*! @function waitQuiet
608 @abstract Waits for an IOService object's <code>busyState</code> to be zero.
609 @discussion Blocks the caller until an IOService object is non busy.
610 @param timeout The maximum time to wait in nanoseconds. Default is to wait forever.
611 @result Returns an error code if Mach synchronization primitives fail, <code>kIOReturnTimeout</code>, or <code>kIOReturnSuccess</code>. */
612
613 IOReturn waitQuiet(uint64_t timeout = UINT64_MAX);
614
615 /* Matching */
616
617 /*! @function matchPropertyTable
618 @abstract Allows a registered IOService object to implement family specific matching.
619 @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.
620 @param table The dictionary of properties to be matched against.
621 @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.
622 @result <code>false</code> if the family considers the matching dictionary does not match in properties it understands; <code>true</code> otherwise. */
623
624 virtual bool matchPropertyTable( OSDictionary * table,
625 SInt32 * score );
626
627 virtual bool matchPropertyTable( OSDictionary * table );
628
629 /*! @function matchLocation
630 @abstract Allows a registered IOService object to direct location matching.
631 @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.
632 @param client The IOService object at which matching is taking place.
633 @result Returns the IOService instance to be used for location matching. */
634
635 virtual IOService * matchLocation( IOService * client );
636
637 /* Resource service */
638
639 /*! @function publishResource
640 @abstract Uses the resource service to publish a property.
641 @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.
642 @param key An OSSymbol key that globally identifies the object.
643 @param The object to be published. */
644
645 static void publishResource( const OSSymbol * key, OSObject * value = 0 );
646
647 /*! @function publishResource
648 @abstract Uses the resource service to publish a property.
649 @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.
650 @param key A C string key that globally identifies the object.
651 @param The object to be published. */
652
653 static void publishResource( const char * key, OSObject * value = 0 );
654 virtual bool addNeededResource( const char * key );
655
656 /* Notifications */
657
658 /*! @function addNotification
659 @abstract Deprecated use addMatchingNotification(). Adds a persistant notification handler to be notified of IOService events.
660 @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.
661 @param type An OSSymbol identifying the type of notification and IOService state:
662 <br> <code>gIOPublishNotification</code> Delivered when an IOService object is registered.
663 <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.
664 <br> <code>gIOMatchedNotification</code> Delivered when an IOService object has been matched with all client drivers, and they have been probed and started.
665 <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.
666 <br> <code>gIOTerminatedNotification</code> Delivered after an IOService object has been terminated, during its finalize stage.
667 @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.
668 @param handler A C function callback to deliver notifications.
669 @param target An instance reference for the callback's use.
670 @param ref A reference constant for the callback's use.
671 @param priority A constant ordering all notifications of a each type.
672 @result An instance of an IONotifier object that can be used to control or destroy the notification request. */
673
674 static IONotifier * addNotification(
675 const OSSymbol * type, OSDictionary * matching,
676 IOServiceNotificationHandler handler,
677 void * target, void * ref = 0,
678 SInt32 priority = 0 )
679 APPLE_KEXT_DEPRECATED;
680
681 /*! @function addMatchingNotification
682 @abstract Adds a persistant notification handler to be notified of IOService events.
683 @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.
684 @param type An OSSymbol identifying the type of notification and IOService state:
685 <br> <code>gIOPublishNotification</code> Delivered when an IOService object is registered.
686 <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.
687 <br> <code>gIOMatchedNotification</code> Delivered when an IOService object has been matched with all client drivers, and they have been probed and started.
688 <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.
689 <br> <code>gIOTerminatedNotification</code> Delivered after an IOService object has been terminated, during its finalize stage.
690 @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).
691 @param handler A C function callback to deliver notifications.
692 @param target An instance reference for the callback's use.
693 @param ref A reference constant for the callback's use.
694 @param priority A constant ordering all notifications of a each type.
695 @result An instance of an IONotifier object that can be used to control or destroy the notification request. */
696
697 static IONotifier * addMatchingNotification(
698 const OSSymbol * type, OSDictionary * matching,
699 IOServiceMatchingNotificationHandler handler,
700 void * target, void * ref = 0,
701 SInt32 priority = 0 );
702
703 /*! @function waitForService
704 @abstract Deprecated use waitForMatchingService(). Waits for a matching to service to be published.
705 @discussion Provides a method of waiting for an IOService object matching the supplied matching dictionary to be registered and fully matched.
706 @param matching The matching dictionary describing the desired IOService object. <code>waitForService</code> consumes one reference of the matching dictionary.
707 @param timeout The maximum time to wait.
708 @result A published IOService object matching the supplied dictionary. */
709
710 static IOService * waitForService( OSDictionary * matching,
711 mach_timespec_t * timeout = 0);
712
713 /*! @function waitForMatchingService
714 @abstract Waits for a matching to service to be published.
715 @discussion Provides a method of waiting for an IOService object matching the supplied matching dictionary to be registered and fully matched.
716 @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.)
717 @param timeout The maximum time to wait in nanoseconds. Default is to wait forever.
718 @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.) */
719
720 static IOService * waitForMatchingService( OSDictionary * matching,
721 uint64_t timeout = UINT64_MAX);
722
723 /*! @function getMatchingServices
724 @abstract Finds the set of current published IOService objects matching a matching dictionary.
725 @discussion Provides a method of finding the current set of published IOService objects matching the supplied matching dictionary.
726 @param matching The matching dictionary describing the desired IOService objects.
727 @result An instance of an iterator over a set of IOService objects. To be released by the caller. */
728
729 static OSIterator * getMatchingServices( OSDictionary * matching );
730
731 public:
732 /* Helpers to make matching dictionaries for simple cases,
733 * they add keys to an existing dictionary, or create one. */
734
735 /*! @function serviceMatching
736 @abstract Creates a matching dictionary, or adds matching properties to an existing dictionary, that specify an IOService class match.
737 @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.
738 @param className The class name, as a const C string. Class matching is successful on IOService objects of this class or any subclass.
739 @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.
740 @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
741
742 static OSDictionary * serviceMatching( const char * className,
743 OSDictionary * table = 0 );
744
745 /*! @function serviceMatching
746 @abstract Creates a matching dictionary, or adds matching properties to an existing dictionary, that specify an IOService class match.
747 @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.
748 @param className The class name, as an OSString (which includes OSSymbol). Class matching is successful on IOService objects of this class or any subclass.
749 @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.
750 @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
751
752 static OSDictionary * serviceMatching( const OSString * className,
753 OSDictionary * table = 0 );
754
755 /*! @function nameMatching
756 @abstract Creates a matching dictionary, or adds matching properties to an existing dictionary, that specify an IOService name match.
757 @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.
758 @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.
759 @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.
760 @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
761
762 static OSDictionary * nameMatching( const char * name,
763 OSDictionary * table = 0 );
764
765 /*! @function nameMatching
766 @abstract Creates a matching dictionary, or adds matching properties to an existing dictionary, that specify an IOService name match.
767 @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.
768 @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.
769 @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.
770 @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
771
772 static OSDictionary * nameMatching( const OSString* name,
773 OSDictionary * table = 0 );
774
775 /*! @function resourceMatching
776 @abstract Creates a matching dictionary, or adds matching properties to an existing dictionary, that specify a resource service match.
777 @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.
778 @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.
779 @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.
780 @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
781
782 static OSDictionary * resourceMatching( const char * name,
783 OSDictionary * table = 0 );
784
785 /*! @function resourceMatching
786 @abstract Creates a matching dictionary, or adds matching properties to an existing dictionary, that specify a resource service match.
787 @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.
788 @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.
789 @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.
790 @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
791
792 static OSDictionary * resourceMatching( const OSString * name,
793 OSDictionary * table = 0 );
794
795
796 /*! @function propertyMatching
797 @abstract Creates a matching dictionary, or adds matching properties to an existing dictionary, that specify an IOService phandle match.
798 @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.
799 @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.
800 @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.
801 @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.
802 @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
803
804 static OSDictionary * propertyMatching( const OSSymbol * key, const OSObject * value,
805 OSDictionary * table = 0 );
806
807 /*! @function registryEntryIDMatching
808 @abstract Creates a matching dictionary, or adds matching properties to an existing dictionary, that specify a IORegistryEntryID match.
809 @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.
810 @param name The service's ID. Matching is successful on the IOService object that return that ID from the <code>IORegistryEntry::getRegistryEntryID()</code> method.
811 @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.
812 @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
813
814 static OSDictionary * registryEntryIDMatching( uint64_t entryID,
815 OSDictionary * table = 0 );
816
817
818 /*! @function addLocation
819 @abstract Adds a location matching property to an existing dictionary.
820 @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.
821 @param table The matching properties are added to the specified dictionary, which must be non-zero.
822 @result The location matching dictionary created is returned on success, or zero on failure. */
823
824 static OSDictionary * addLocation( OSDictionary * table );
825
826 /* Helpers for matching dictionaries. */
827
828 /*! @function compareProperty
829 @abstract Compares a property in a matching dictionary with an IOService object's property table.
830 @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.
831 @param matching The matching dictionary, which must be non-zero.
832 @param key The dictionary key specifying the property to be compared, as a C string.
833 @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. */
834
835 virtual bool compareProperty( OSDictionary * matching,
836 const char * key );
837 /*! @function compareProperty
838 @abstract Compares a property in a matching dictionary with an IOService object's property table.
839 @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.
840 @param matching The matching dictionary, which must be non-zero.
841 @param key The dictionary key specifying the property to be compared, as an OSString (which includes OSSymbol).
842 @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. */
843
844 virtual bool compareProperty( OSDictionary * matching,
845 const OSString * key );
846
847 /*! @function compareProperties
848 @abstract Compares a set of properties in a matching dictionary with an IOService object's property table.
849 @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.
850 @param matching The matching dictionary, which must be non-zero.
851 @param keys A collection (eg. OSSet, OSArray, OSDictionary) which should contain OSStrings (or OSSymbols) that specify the property keys to be compared.
852 @result Success if <code>compareProperty</code> returns <code>true</code> for each key in the collection; otherwise failure. */
853
854 virtual bool compareProperties( OSDictionary * matching,
855 OSCollection * keys );
856
857 /* Client / provider accessors */
858
859 /*! @function attach
860 @abstract Attaches an IOService client to a provider in the I/O Registry.
861 @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.
862 @param provider The IOService object which will serve as this object's provider.
863 @result <code>false</code> if the provider is inactive or on a resource failure; otherwise <code>true</code>. */
864
865 virtual bool attach( IOService * provider );
866
867 /*! @function detach
868 @abstract Detaches an IOService client from a provider in the I/O Registry.
869 @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.
870 @param provider The IOService object to detach from. */
871
872 virtual void detach( IOService * provider );
873
874 /*! @function getProvider
875 @abstract Returns an IOService object's primary provider.
876 @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.
877 @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. */
878
879 virtual IOService * getProvider( void ) const;
880
881 /*! @function getWorkLoop
882 @abstract Returns the current work loop or <code>provider->getWorkLoop</code>.
883 @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.
884 @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.*/
885
886 virtual IOWorkLoop * getWorkLoop() const;
887
888 /*! @function getProviderIterator
889 @abstract Returns an iterator over an IOService object's providers.
890 @discussion For those few IOService objects that obtain service from multiple providers, this method supplies an iterator over a client's providers.
891 @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. */
892
893 virtual OSIterator * getProviderIterator( void ) const;
894
895 /*! @function getOpenProviderIterator
896 @abstract Returns an iterator over an client's providers that are currently opened by the client.
897 @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.
898 @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. */
899
900 virtual OSIterator * getOpenProviderIterator( void ) const;
901
902 /*! @function getClient
903 @abstract Returns an IOService object's primary client.
904 @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.
905 @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. */
906
907 virtual IOService * getClient( void ) const;
908
909 /*! @function getClientIterator
910 @abstract Returns an iterator over an IOService object's clients.
911 @discussion For IOService objects that may have multiple clients, this method supplies an iterator over a provider's clients.
912 @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. */
913
914 virtual OSIterator * getClientIterator( void ) const;
915
916 /*! @function getOpenClientIterator
917 @abstract Returns an iterator over a provider's clients that currently have opened the provider.
918 @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.
919 @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. */
920
921 virtual OSIterator * getOpenClientIterator( void ) const;
922
923 /*! @function callPlatformFunction
924 @abstract Calls the platform function with the given name.
925 @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.
926 @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.
927 @param waitForFunction If <code>true</code>, <code>callPlatformFunction</code> will not return until the function has been called.
928 @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.*/
929
930 virtual IOReturn callPlatformFunction( const OSSymbol * functionName,
931 bool waitForFunction,
932 void *param1, void *param2,
933 void *param3, void *param4 );
934
935 virtual IOReturn callPlatformFunction( const char * functionName,
936 bool waitForFunction,
937 void *param1, void *param2,
938 void *param3, void *param4 );
939
940
941 /* Some accessors */
942
943 /*! @function getPlatform
944 @abstract Returns a pointer to the platform expert instance for the computer.
945 @discussion This method provides an accessor to the platform expert instance for the computer.
946 @result A pointer to the IOPlatformExport instance. It should not be released by the caller. */
947
948 static IOPlatformExpert * getPlatform( void );
949
950 /*! @function getPMRootDomain
951 @abstract Returns a pointer to the power management root domain instance for the computer.
952 @discussion This method provides an accessor to the power management root domain instance for the computer.
953 @result A pointer to the power management root domain instance. It should not be released by the caller. */
954
955 static class IOPMrootDomain * getPMRootDomain( void );
956
957 /*! @function getServiceRoot
958 @abstract Returns a pointer to the root of the service plane.
959 @discussion This method provides an accessor to the root of the service plane for the computer.
960 @result A pointer to the IOService instance at the root of the service plane. It should not be released by the caller. */
961
962 static IOService * getServiceRoot( void );
963
964 /*! @function getResourceService
965 @abstract Returns a pointer to the IOResources service.
966 @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.
967 @result A pointer to the IOResources instance. It should not be released by the caller. */
968
969 static IOService * getResourceService( void );
970
971 /* Allocate resources for a matched service */
972
973 /*! @function getResources
974 @abstract Allocates any needed resources for a published IOService object before clients attach.
975 @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.
976 @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. */
977
978 virtual IOReturn getResources( void );
979
980 /* Device memory accessors */
981
982 /*! @function getDeviceMemoryCount
983 @abstract Returns a count of the physical memory ranges available for a device.
984 @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.
985 @result An integer count of the number of ranges available. */
986
987 virtual IOItemCount getDeviceMemoryCount( void );
988
989 /*! @function getDeviceMemoryWithIndex
990 @abstract Returns an instance of IODeviceMemory representing one of a device's memory mapped ranges.
991 @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.
992 @param index An index into the array of ranges assigned to the device.
993 @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. */
994
995 virtual IODeviceMemory * getDeviceMemoryWithIndex( unsigned int index );
996
997 /*! @function mapDeviceMemoryWithIndex
998 @abstract Maps a physical range of a device.
999 @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.
1000 @param index An index into the array of ranges assigned to the device.
1001 @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. */
1002
1003 virtual IOMemoryMap * mapDeviceMemoryWithIndex( unsigned int index,
1004 IOOptionBits options = 0 );
1005
1006 /*! @function getDeviceMemory
1007 @abstract Returns the array of IODeviceMemory objects representing a device's memory mapped ranges.
1008 @discussion This method returns an array of IODeviceMemory objects representing the physical memory ranges allocated to a memory mapped device.
1009 @result An OSArray of IODeviceMemory objects, or zero if none are available. The array is retained by the provider, so is valid while attached. */
1010
1011 virtual OSArray * getDeviceMemory( void );
1012
1013 /*! @function setDeviceMemory
1014 @abstract Sets the array of IODeviceMemory objects representing a device's memory mapped ranges.
1015 @discussion This method sets an array of IODeviceMemory objects representing the physical memory ranges allocated to a memory mapped device.
1016 @param array An OSArray of IODeviceMemory objects, or zero if none are available. The array will be retained by the object. */
1017
1018 virtual void setDeviceMemory( OSArray * array );
1019
1020 /* Interrupt accessors */
1021
1022 /*! @function registerInterrupt
1023 @abstract Registers a C function interrupt handler for a device supplying interrupts.
1024 @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.
1025 @param source The index of the interrupt source in the device.
1026 @param target An object instance to be passed to the interrupt handler.
1027 @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.
1028 @param refCon A reference constant for the handler's use.
1029 @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. */
1030
1031 virtual IOReturn registerInterrupt(int source, OSObject *target,
1032 IOInterruptAction handler,
1033 void *refCon = 0);
1034
1035 /*! @function unregisterInterrupt
1036 @abstract Removes a C function interrupt handler for a device supplying hardware interrupts.
1037 @discussion This method removes a C function interrupt handler previously installed with @link registerInterrupt registerInterrupt@/link.
1038 @param source The index of the interrupt source in the device.
1039 @result An IOReturn code (<code>kIOReturnNoInterrupt</code> is returned if the source is not valid). */
1040
1041 virtual IOReturn unregisterInterrupt(int source);
1042
1043 /*! @function getInterruptType
1044 @abstract Returns the type of interrupt used for a device supplying hardware interrupts.
1045 @param source The index of the interrupt source in the device.
1046 @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.
1047 @result An IOReturn code (<code>kIOReturnNoInterrupt</code> is returned if the source is not valid). */
1048
1049 virtual IOReturn getInterruptType(int source, int *interruptType);
1050
1051 /*! @function enableInterrupt
1052 @abstract Enables a device interrupt.
1053 @discussion It is the caller's responsiblity to keep track of the enable state of the interrupt source.
1054 @param source The index of the interrupt source in the device.
1055 @result An IOReturn code (<code>kIOReturnNoInterrupt</code> is returned if the source is not valid). */
1056
1057 virtual IOReturn enableInterrupt(int source);
1058
1059 /*! @function disableInterrupt
1060 @abstract Synchronously disables a device interrupt.
1061 @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.
1062 @param source The index of the interrupt source in the device.
1063 @result An IOReturn code (<code>kIOReturnNoInterrupt</code> is returned if the source is not valid). */
1064
1065 virtual IOReturn disableInterrupt(int source);
1066
1067 /*! @function causeInterrupt
1068 @abstract Causes a device interrupt to occur.
1069 @discussion Emulates a hardware interrupt, to be called from task level.
1070 @param source The index of the interrupt source in the device.
1071 @result An IOReturn code (<code>kIOReturnNoInterrupt</code> is returned if the source is not valid). */
1072
1073 virtual IOReturn causeInterrupt(int source);
1074
1075 /*! @function requestProbe
1076 @abstract Requests that hardware be re-scanned for devices.
1077 @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.
1078 @param options Family defined options, not interpreted by IOService.
1079 @result An IOReturn code. */
1080
1081 virtual IOReturn requestProbe( IOOptionBits options );
1082
1083 /* Generic API for non-data-path upstream calls */
1084
1085 /*! @function message
1086 @abstract Receives a generic message delivered from an attached provider.
1087 @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.
1088 @param type A type defined in <code>IOMessage.h</code> or defined by the provider family.
1089 @param provider The provider from which the message originates.
1090 @param argument An argument defined by the provider family, not used by IOService.
1091 @result An IOReturn code defined by the message type. */
1092
1093 virtual IOReturn message( UInt32 type, IOService * provider,
1094 void * argument = 0 );
1095
1096 /*! @function messageClient
1097 @abstract Sends a generic message to an attached client.
1098 @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.
1099 @param messageType A type defined in <code>IOMessage.h</code> or defined by the provider family.
1100 @param client A client of the IOService to send the message.
1101 @param messageArgument An argument defined by the provider family, not used by IOService.
1102 @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.
1103 @result The return code from the client message call. */
1104
1105 virtual IOReturn messageClient( UInt32 messageType, OSObject * client,
1106 void * messageArgument = 0, vm_size_t argSize = 0 );
1107
1108 /*! @function messageClients
1109 @abstract Sends a generic message to all attached clients.
1110 @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.
1111 @param type A type defined in <code>IOMessage.h</code> or defined by the provider family.
1112 @param argument An argument defined by the provider family, not used by IOService.
1113 @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.
1114 @result Any non-<code>kIOReturnSuccess</code> return codes returned by the clients, or <code>kIOReturnSuccess</code> if all return <code>kIOReturnSuccess</code>. */
1115
1116 virtual IOReturn messageClients( UInt32 type,
1117 void * argument = 0, vm_size_t argSize = 0 );
1118
1119 virtual IONotifier * registerInterest( const OSSymbol * typeOfInterest,
1120 IOServiceInterestHandler handler,
1121 void * target, void * ref = 0 );
1122
1123 virtual void applyToProviders( IOServiceApplierFunction applier,
1124 void * context );
1125
1126 virtual void applyToClients( IOServiceApplierFunction applier,
1127 void * context );
1128
1129 virtual void applyToInterested( const OSSymbol * typeOfInterest,
1130 OSObjectApplierFunction applier,
1131 void * context );
1132
1133 virtual IOReturn acknowledgeNotification( IONotificationRef notification,
1134 IOOptionBits response );
1135
1136 /* User client create */
1137
1138 /*! @function newUserClient
1139 @abstract Creates a connection for a non kernel client.
1140 @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.
1141 @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"}.
1142 @param securityID A token representing the access level for the task.
1143 @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.
1144 @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.
1145 @param properties A dictionary of additional properties for the connection.
1146 @result A return code to be passed back to the caller of <code>IOServiceOpen</code>. */
1147
1148 virtual IOReturn newUserClient( task_t owningTask, void * securityID,
1149 UInt32 type, OSDictionary * properties,
1150 IOUserClient ** handler );
1151
1152 virtual IOReturn newUserClient( task_t owningTask, void * securityID,
1153 UInt32 type, IOUserClient ** handler );
1154
1155 /* Return code utilities */
1156
1157 /*! @function stringFromReturn
1158 @abstract Supplies a programmer-friendly string from an IOReturn code.
1159 @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.
1160 @param rtn The IOReturn code.
1161 @result A pointer to a constant string, or zero if the return code is unknown. */
1162
1163 virtual const char * stringFromReturn( IOReturn rtn );
1164
1165 /*! @function errnoFromReturn
1166 @abstract Translates an IOReturn code to a BSD <code>errno</code>.
1167 @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.
1168 @param rtn The IOReturn code.
1169 @result The BSD <code>errno</code> or <code>EIO</code> if unknown. */
1170
1171 virtual int errnoFromReturn( IOReturn rtn );
1172
1173 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1174 /* * * * * * * * * * end of IOService API * * * * * * * */
1175 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1176
1177 /* for IOInterruptController implementors */
1178
1179 int _numInterruptSources;
1180 IOInterruptSource *_interruptSources;
1181
1182 /* overrides */
1183 virtual bool serializeProperties( OSSerialize * s ) const;
1184
1185 #ifdef KERNEL_PRIVATE
1186 /* Apple only SPI to control CPU low power modes */
1187 void setCPUSnoopDelay(UInt32 ns);
1188 UInt32 getCPUSnoopDelay();
1189 #endif
1190 void requireMaxBusStall(UInt32 ns);
1191 void requireMaxInterruptDelay(uint32_t ns);
1192
1193 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1194 /* * * * * * * * * * * * Internals * * * * * * * * * * * */
1195 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1196
1197 #ifdef XNU_KERNEL_PRIVATE
1198 public:
1199 // called from other xnu components
1200 static void initialize( void );
1201 static void setPlatform( IOPlatformExpert * platform);
1202 static void setPMRootDomain( class IOPMrootDomain * rootDomain );
1203 static IOReturn catalogNewDrivers( OSOrderedSet * newTables );
1204 uint64_t getAccumulatedBusyTime( void );
1205 static void updateConsoleUsers(OSArray * consoleUsers, IOMessage systemMessage);
1206 static void consoleLockTimer(thread_call_param_t p0, thread_call_param_t p1);
1207
1208 private:
1209 static IOReturn waitMatchIdle( UInt32 ms );
1210 static IONotifier * installNotification(
1211 const OSSymbol * type, OSDictionary * matching,
1212 IOServiceMatchingNotificationHandler handler,
1213 void * target, void * ref,
1214 SInt32 priority, OSIterator ** existing );
1215 #if !defined(__LP64__)
1216 static IONotifier * installNotification(
1217 const OSSymbol * type, OSDictionary * matching,
1218 IOServiceNotificationHandler handler,
1219 void * target, void * ref,
1220 SInt32 priority, OSIterator ** existing);
1221 #endif /* !defined(__LP64__) */
1222 #endif
1223
1224 private:
1225 APPLE_KEXT_COMPATIBILITY_VIRTUAL
1226 bool checkResources( void );
1227 APPLE_KEXT_COMPATIBILITY_VIRTUAL
1228 bool checkResource( OSObject * matching );
1229
1230 APPLE_KEXT_COMPATIBILITY_VIRTUAL
1231 void probeCandidates( OSOrderedSet * matches );
1232 APPLE_KEXT_COMPATIBILITY_VIRTUAL
1233 bool startCandidate( IOService * candidate );
1234
1235 public:
1236 APPLE_KEXT_COMPATIBILITY_VIRTUAL
1237 IOService * getClientWithCategory( const OSSymbol * category )
1238 APPLE_KEXT_DEPRECATED;
1239 // copyClientWithCategory is the public replacement
1240
1241 #ifdef XNU_KERNEL_PRIVATE
1242 /* Callable within xnu source only - but require vtable entries to be visible */
1243 public:
1244 #else
1245 private:
1246 #endif
1247 APPLE_KEXT_COMPATIBILITY_VIRTUAL
1248 bool passiveMatch( OSDictionary * matching, bool changesOK = false);
1249 APPLE_KEXT_COMPATIBILITY_VIRTUAL
1250 void startMatching( IOOptionBits options = 0 );
1251 APPLE_KEXT_COMPATIBILITY_VIRTUAL
1252 void doServiceMatch( IOOptionBits options );
1253 APPLE_KEXT_COMPATIBILITY_VIRTUAL
1254 void doServiceTerminate( IOOptionBits options );
1255
1256 private:
1257 static OSObject * copyExistingServices( OSDictionary * matching,
1258 IOOptionBits inState, IOOptionBits options = 0 );
1259
1260 static IONotifier * setNotification(
1261 const OSSymbol * type, OSDictionary * matching,
1262 IOServiceMatchingNotificationHandler handler,
1263 void * target, void * ref,
1264 SInt32 priority = 0 );
1265
1266 static IONotifier * doInstallNotification(
1267 const OSSymbol * type, OSDictionary * matching,
1268 IOServiceMatchingNotificationHandler handler,
1269 void * target, void * ref,
1270 SInt32 priority, OSIterator ** existing );
1271
1272 static bool syncNotificationHandler( void * target, void * ref,
1273 IOService * newService, IONotifier * notifier );
1274
1275 APPLE_KEXT_COMPATIBILITY_VIRTUAL
1276 void deliverNotification( const OSSymbol * type,
1277 IOOptionBits orNewState, IOOptionBits andNewState );
1278
1279 bool invokeNotifer( class _IOServiceNotifier * notify );
1280
1281 APPLE_KEXT_COMPATIBILITY_VIRTUAL
1282 void unregisterAllInterest( void );
1283
1284 APPLE_KEXT_COMPATIBILITY_VIRTUAL
1285 IOReturn waitForState( UInt32 mask, UInt32 value,
1286 mach_timespec_t * timeout = 0 );
1287
1288 IOReturn waitForState( UInt32 mask, UInt32 value, uint64_t timeout );
1289
1290 UInt32 _adjustBusy( SInt32 delta );
1291
1292 bool terminatePhase1( IOOptionBits options = 0 );
1293 void scheduleTerminatePhase2( IOOptionBits options = 0 );
1294 void scheduleStop( IOService * provider );
1295 void scheduleFinalize( void );
1296 static void terminateThread( void * arg, wait_result_t unused );
1297 static void terminateWorker( IOOptionBits options );
1298 static void actionWillTerminate( IOService * victim, IOOptionBits options,
1299 OSArray * doPhase2List, void*, void * );
1300 static void actionDidTerminate( IOService * victim, IOOptionBits options,
1301 void *, void *, void *);
1302 static void actionFinalize( IOService * victim, IOOptionBits options,
1303 void *, void *, void *);
1304 static void actionStop( IOService * client, IOService * provider,
1305 void *, void *, void *);
1306
1307 APPLE_KEXT_COMPATIBILITY_VIRTUAL
1308 IOReturn resolveInterrupt(IOService *nub, int source);
1309 APPLE_KEXT_COMPATIBILITY_VIRTUAL
1310 IOReturn lookupInterrupt(int source, bool resolve, IOInterruptController **interruptController);
1311
1312 #ifdef XNU_KERNEL_PRIVATE
1313 /* end xnu internals */
1314 #endif
1315
1316 /* power management */
1317 public:
1318
1319 /*! @function PMinit
1320 @abstract Initializes power management for a driver.
1321 @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.
1322 Most calls to <code>PMinit</code> are followed by calls to @link joinPMtree joinPMtree@/link and @link registerPowerDriver registerPowerDriver@/link. */
1323
1324 virtual void PMinit( void );
1325
1326 /*! @function PMstop
1327 @abstract Stop power managing the driver.
1328 @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.
1329 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. */
1330
1331 virtual void PMstop( void );
1332
1333 /*! @function joinPMtree
1334 @abstract Joins the driver into the power plane of the I/O Registry.
1335 @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).
1336 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.
1337 @param driver The driver to be added to the power plane, usually <code>this</code>. */
1338
1339 virtual void joinPMtree( IOService * driver );
1340
1341 /*! @function registerPowerDriver
1342 @abstract Registers a set of power states that the driver supports.
1343 @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.
1344 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.
1345 @param controllingDriver A pointer to the calling driver, usually <code>this</code>.
1346 @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>.
1347 @param numberOfStates The number of power states in the array.
1348 @result </code>IOPMNoErr</code>. All errors are logged via <code>kprintf</code>. */
1349
1350 virtual IOReturn registerPowerDriver(
1351 IOService * controllingDriver,
1352 IOPMPowerState * powerStates,
1353 unsigned long numberOfStates );
1354
1355 /*! @function registerInterestedDriver
1356 @abstract Allows an IOService object to register interest in the changing power state of a power-managed IOService object.
1357 @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.
1358 The interested driver is retained until the power interest is removed by calling <code>deRegisterInterestedDriver</code>.
1359 The interested driver should override @link powerStateWillChangeTo powerStateWillChangeTo@/link and @link powerStateDidChangeTo powerStateDidChangeTo@/link to receive these power change messages.
1360 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.
1361 @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.
1362 @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). */
1363
1364 APPLE_KEXT_COMPATIBILITY_VIRTUAL
1365 IOPMPowerFlags registerInterestedDriver( IOService * theDriver );
1366
1367 /*! @function deRegisterInterestedDriver
1368 @abstract De-registers power state interest from a previous call to <code>registerInterestedDriver</code>.
1369 @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.
1370 Most drivers do not need to override <code>deRegisterInterestedDriver</code>.
1371 @param theDriver The interested driver previously passed into @link registerInterestedDriver registerInterestedDriver@/link.
1372 @result A return code that can be ignored by the caller. */
1373
1374 APPLE_KEXT_COMPATIBILITY_VIRTUAL
1375 IOReturn deRegisterInterestedDriver( IOService * theDriver );
1376
1377 /*! @function acknowledgePowerChange
1378 @abstract Acknowledges an in-progress power state change.
1379 @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>.
1380 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>.
1381 @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.
1382 @result <code>IOPMNoErr</code>. */
1383
1384 APPLE_KEXT_COMPATIBILITY_VIRTUAL
1385 IOReturn acknowledgePowerChange( IOService * whichDriver );
1386
1387 /*! @function acknowledgeSetPowerState
1388 @abstract Acknowledges the belated completion of a driver's <code>setPowerState</code> power state change.
1389 @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>.
1390 Any driver that does not return <code>kIOPMAckImplied</code> from its <code>setPowerState</code> implementation must later call <code>acknowledgeSetPowerState</code>.
1391 @result <code>IOPMNoErr</code>. */
1392
1393 APPLE_KEXT_COMPATIBILITY_VIRTUAL
1394 IOReturn acknowledgeSetPowerState( void );
1395
1396 /*! @function requestPowerDomainState
1397 @abstract Tells a driver to adjust its power state.
1398 @discussion This call is handled internally by power management. It is not intended to be overridden or called by drivers. */
1399
1400 virtual IOReturn requestPowerDomainState(
1401 IOPMPowerFlags desiredState,
1402 IOPowerConnection * whichChild,
1403 unsigned long specificationFlags );
1404
1405 /*! @function makeUsable
1406 @abstract Requests that a device become usable.
1407 @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.
1408 <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.
1409 @result A return code that can be ignored by the caller. */
1410
1411 APPLE_KEXT_COMPATIBILITY_VIRTUAL
1412 IOReturn makeUsable( void );
1413
1414 /*! @function temporaryPowerClampOn
1415 @abstract A driver calls this method to hold itself in the highest power state until it has children.
1416 @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.
1417 @result A return code that can be ignored by the caller. */
1418
1419 APPLE_KEXT_COMPATIBILITY_VIRTUAL
1420 IOReturn temporaryPowerClampOn( void );
1421
1422 /*! @function changePowerStateTo
1423 @abstract Sets a driver's power state.
1424 @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.
1425 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:
1426 <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.
1427 <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>
1428 @param ordinal The number of the desired power state in the power state array.
1429 @result A return code that can be ignored by the caller. */
1430
1431 APPLE_KEXT_COMPATIBILITY_VIRTUAL
1432 IOReturn changePowerStateTo( unsigned long ordinal );
1433
1434 /*! @function currentCapability
1435 @abstract Finds out the capability of a device's current power state.
1436 @result A copy of the <code>capabilityFlags</code> field for the current power state in the power state array. */
1437
1438 APPLE_KEXT_COMPATIBILITY_VIRTUAL
1439 IOPMPowerFlags currentCapability( void );
1440
1441 /*! @function currentPowerConsumption
1442 @abstract Finds out the current power consumption of a device.
1443 @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.
1444 @result A copy of the <code>staticPower</code> field for the current power state in the power state array. */
1445
1446 APPLE_KEXT_COMPATIBILITY_VIRTUAL
1447 unsigned long currentPowerConsumption( void );
1448
1449 /*! @function activityTickle
1450 @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.
1451 @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.
1452 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.
1453 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.
1454 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.
1455 @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.
1456 @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.
1457 @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. */
1458
1459 virtual bool activityTickle(
1460 unsigned long type,
1461 unsigned long stateNumber = 0 );
1462
1463 /*! @function setAggressiveness
1464 @abstract Broadcasts an aggressiveness factor from the parent of a driver to the driver.
1465 @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.
1466 A driver that has joined the power plane via @link joinPMtree joinPMtree@/link will receive <code>setAgressiveness</code> calls when aggressiveness factors change.
1467 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.
1468 Most drivers do not need to implement <code>setAgressiveness</code>.
1469 @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>.)
1470 @param newLevel The aggressiveness factor's new value.
1471 @result <code>IOPMNoErr</code>. */
1472
1473 virtual IOReturn setAggressiveness(
1474 unsigned long type,
1475 unsigned long newLevel );
1476
1477 /*! @function getAggressiveness
1478 @abstract Returns the current aggressiveness value for the given type.
1479 @param type The aggressiveness factor to query.
1480 @param currentLevel Upon successful return, contains the value of aggressiveness factor <code>type</code>.
1481 @result <code>kIOReturnSuccess</code> upon success; an I/O Kit error code otherwise. */
1482
1483 virtual IOReturn getAggressiveness(
1484 unsigned long type,
1485 unsigned long * currentLevel );
1486
1487 #ifndef __LP64__
1488 /*! @function systemWake
1489 @abstract Tells every driver in the power plane that the system is waking up.
1490 @discussion This call is handled internally by power management. It is not intended to be overridden or called by drivers. */
1491
1492 virtual IOReturn systemWake( void )
1493 APPLE_KEXT_DEPRECATED;
1494
1495 /*! @function temperatureCriticalForZone
1496 @abstract Alerts a driver to a critical temperature in some thermal zone.
1497 @discussion This call is unused by power management. It is not intended to be called or overridden. */
1498
1499 virtual IOReturn temperatureCriticalForZone( IOService * whichZone )
1500 APPLE_KEXT_DEPRECATED;
1501
1502 /*! @function youAreRoot
1503 @abstract Informs power management which IOService object is the power plane root.
1504 @discussion This call is handled internally by power management. It is not intended to be overridden or called by drivers. */
1505
1506 virtual IOReturn youAreRoot( void )
1507 APPLE_KEXT_DEPRECATED;
1508
1509 /*! @function setPowerParent
1510 @abstract This call is handled internally by power management. It is not intended to be overridden or called by drivers. */
1511
1512 virtual IOReturn setPowerParent(
1513 IOPowerConnection * parent,
1514 bool stateKnown,
1515 IOPMPowerFlags currentState )
1516 APPLE_KEXT_DEPRECATED;
1517 #endif /* !__LP64__ */
1518
1519 /*! @function addPowerChild
1520 @abstract Informs a driver that it has a new child.
1521 @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.
1522 @param theChild A pointer to the child IOService object. */
1523
1524 virtual IOReturn addPowerChild( IOService * theChild );
1525
1526 /*! @function removePowerChild
1527 @abstract Informs a power managed driver that one of its power plane childen is disappearing.
1528 @discussion This call is handled internally by power management. It is not intended to be overridden or called by drivers. */
1529
1530 virtual IOReturn removePowerChild( IOPowerConnection * theChild );
1531
1532 #ifndef __LP64__
1533 /*! @function command_received
1534 @discussion This call is handled internally by power management. It is not intended to be overridden or called by drivers. */
1535
1536 virtual void command_received( void *, void * , void * , void * );
1537 #endif
1538
1539 /*! @function start_PM_idle_timer
1540 @discussion This call is handled internally by power management. It is not intended to be overridden or called by drivers. */
1541
1542 APPLE_KEXT_COMPATIBILITY_VIRTUAL
1543 void start_PM_idle_timer( void );
1544
1545 #ifndef __LP64__
1546 /*! @function PM_idle_timer_expiration
1547 @discussion This call is handled internally by power management. It is not intended to be overridden or called by drivers. */
1548
1549 virtual void PM_idle_timer_expiration( void )
1550 APPLE_KEXT_DEPRECATED;
1551
1552 /*! @function PM_Clamp_Timer_Expired
1553 @discussion This call is handled internally by power management. It is not intended to be overridden or called by drivers. */
1554
1555 virtual void PM_Clamp_Timer_Expired( void )
1556 APPLE_KEXT_DEPRECATED;
1557 #endif
1558
1559 /*! @function setIdleTimerPeriod
1560 @abstract Sets or changes the idle timer period.
1561 @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.
1562 @param period The desired idle timer period in seconds.
1563 @result <code>kIOReturnSuccess</code> upon success; an I/O Kit error code otherwise. */
1564
1565 virtual IOReturn setIdleTimerPeriod( unsigned long );
1566
1567 #ifndef __LP64__
1568 /*! @function getPMworkloop
1569 @abstract Returns a pointer to the system-wide power management work loop.
1570 @availability Deprecated in Mac OS X version 10.6.
1571 @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. */
1572
1573 virtual IOWorkLoop * getPMworkloop( void )
1574 APPLE_KEXT_DEPRECATED;
1575 #endif
1576
1577 /*! @function getPowerState
1578 @abstract Determines a device's power state.
1579 @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.
1580 @result The current power state's index into the device's power state array. */
1581
1582 UInt32 getPowerState( void );
1583
1584 /*! @function setPowerState
1585 @abstract Requests a power managed driver to change the power state of its device.
1586 @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.
1587 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.
1588 @param powerStateOrdinal The number in the power state array of the state the driver is being instructed to switch to.
1589 @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.
1590 @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. */
1591
1592 virtual IOReturn setPowerState(
1593 unsigned long powerStateOrdinal,
1594 IOService * whatDevice );
1595
1596 #ifndef __LP64__
1597 /*! @function clampPowerOn
1598 @abstract Deprecated. Do not use. */
1599
1600 virtual void clampPowerOn( unsigned long duration );
1601 #endif
1602
1603 /*! @function maxCapabilityForDomainState
1604 @abstract Determines a driver's highest power state possible for a given power domain state.
1605 @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.
1606 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.
1607 @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.
1608 @result A state number. */
1609
1610 virtual unsigned long maxCapabilityForDomainState( IOPMPowerFlags domainState );
1611
1612 /*! @function initialPowerStateForDomainState
1613 @abstract Determines which power state a device is in, given the current power domain state.
1614 @discussion Power management calls this method once, when the driver is initializing power management.
1615 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.
1616 @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.
1617 @result A state number. */
1618
1619 virtual unsigned long initialPowerStateForDomainState( IOPMPowerFlags domainState );
1620
1621 /*! @function powerStateForDomainState
1622 @abstract Determines what power state the device would be in for a given power domain state.
1623 @discussion Power management calls a driver with this method to find out what power state the device would be in for a given power domain state. This happens when the power domain is changing state and power management needs to determine the effect of the change.
1624 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.
1625 @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.
1626 @result A state number. */
1627
1628 virtual unsigned long powerStateForDomainState( IOPMPowerFlags domainState );
1629
1630 /*! @function powerStateWillChangeTo
1631 @abstract Informs interested parties that a device is about to change its power state.
1632 @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.
1633 <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.
1634 @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).
1635 @param stateNumber The number of the state in the state array that the device is switching to.
1636 @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.
1637 @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. */
1638
1639 virtual IOReturn powerStateWillChangeTo(
1640 IOPMPowerFlags capabilities,
1641 unsigned long stateNumber,
1642 IOService * whatDevice );
1643
1644 /*! @function powerStateDidChangeTo
1645 @abstract Informs interested parties that a device has changed to a different power state.
1646 @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.
1647 <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.
1648 @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).
1649 @param stateNumber The number of the state in the state array that the device is switching to.
1650 @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.
1651 @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. */
1652
1653 virtual IOReturn powerStateDidChangeTo(
1654 IOPMPowerFlags capabilities,
1655 unsigned long stateNumber,
1656 IOService * whatDevice );
1657
1658 #ifndef __LP64__
1659 /*! @function didYouWakeSystem
1660 @abstract Asks a driver if its device is the one that just woke the system from sleep.
1661 @availability Deprecated in Mac OS X version 10.6.
1662 @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.
1663 @result <code>true</code> if the driver's device woke the system and <code>false</code> otherwise. */
1664
1665 virtual bool didYouWakeSystem( void )
1666 APPLE_KEXT_DEPRECATED;
1667
1668 /*! @function newTemperature
1669 @abstract Tells a power managed driver that the temperature in the thermal zone has changed.
1670 @discussion This call is unused by power management. It is not intended to be called or overridden. */
1671
1672 virtual IOReturn newTemperature( long currentTemp, IOService * whichZone )
1673 APPLE_KEXT_DEPRECATED;
1674 #endif
1675
1676 virtual bool askChangeDown( unsigned long );
1677 virtual bool tellChangeDown( unsigned long );
1678 virtual void tellNoChangeDown ( unsigned long );
1679 virtual void tellChangeUp( unsigned long );
1680 virtual IOReturn allowPowerChange( unsigned long refcon );
1681 virtual IOReturn cancelPowerChange( unsigned long refcon );
1682
1683 protected:
1684 /*! @function changePowerStateToPriv
1685 @abstract Tells a driver's superclass to change the power state of its device.
1686 @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.
1687 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.
1688 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.
1689 @param ordinal The number of the desired power state in the power state array.
1690 @result A return code that can be ignored by the caller. */
1691
1692 IOReturn changePowerStateToPriv( unsigned long ordinal );
1693
1694 /*! @function powerOverrideOnPriv
1695 @abstract Allows a driver to ignore its children's power management requests and only use changePowerStateToPriv to define its own power state.
1696 @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.
1697 @result A return code that can be ignored by the caller. */
1698
1699 IOReturn powerOverrideOnPriv( void );
1700
1701 /*! @function powerOverrideOffPriv
1702 @abstract Allows a driver to disable a power override.
1703 @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.
1704 @result A return code that can be ignored by the caller. */
1705
1706 IOReturn powerOverrideOffPriv( void );
1707
1708 /*! @function powerChangeDone
1709 @abstract Tells a driver when a power state change is complete.
1710 @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.
1711 @param stateNumber The number of the state in the state array that the device has switched from. */
1712
1713 virtual void powerChangeDone( unsigned long stateNumber );
1714 #ifdef XNU_KERNEL_PRIVATE
1715 /* Power management internals */
1716 public:
1717 void idleTimerExpired( void );
1718 void settleTimerExpired( void );
1719 IOReturn synchronizePowerTree( IOOptionBits options = 0, IOService * notifyRoot = 0 );
1720 bool assertPMDriverCall( IOPMDriverCallEntry * callEntry, IOOptionBits options = 0, IOPMinformee * inform = 0 );
1721 void deassertPMDriverCall( IOPMDriverCallEntry * callEntry );
1722 IOReturn changePowerStateWithOverrideTo( unsigned long ordinal );
1723 static const char * getIOMessageString( uint32_t msg );
1724
1725 #ifdef __LP64__
1726 static IOWorkLoop * getPMworkloop( void );
1727 #endif
1728
1729 protected:
1730 bool tellClientsWithResponse( int messageType );
1731 void tellClients( int messageType );
1732
1733 private:
1734 #ifndef __LP64__
1735 void ack_timer_ticked ( void );
1736 IOReturn serializedAllowPowerChange2 ( unsigned long );
1737 IOReturn serializedCancelPowerChange2 ( unsigned long );
1738 IOReturn powerDomainWillChangeTo( IOPMPowerFlags, IOPowerConnection * );
1739 IOReturn powerDomainDidChangeTo( IOPMPowerFlags, IOPowerConnection * );
1740 #endif
1741 void PMfree( void );
1742 bool tellChangeDown1 ( unsigned long );
1743 bool tellChangeDown2 ( unsigned long );
1744 IOReturn startPowerChange( IOPMPowerChangeFlags, IOPMPowerStateIndex, IOPMPowerFlags, IOPowerConnection *, IOPMPowerFlags );
1745 void setParentInfo ( IOPMPowerFlags, IOPowerConnection *, bool );
1746 IOReturn notifyAll ( uint32_t nextMS );
1747 bool notifyChild ( IOPowerConnection * child );
1748
1749 // power change initiated by driver
1750 void OurChangeStart( void );
1751 void OurSyncStart ( void );
1752 void OurChangeTellClientsPowerDown ( void );
1753 void OurChangeTellPriorityClientsPowerDown ( void );
1754 void OurChangeTellCapabilityWillChange ( void );
1755 void OurChangeNotifyInterestedDriversWillChange ( void );
1756 void OurChangeSetPowerState ( void );
1757 void OurChangeWaitForPowerSettle ( void );
1758 void OurChangeNotifyInterestedDriversDidChange ( void );
1759 void OurChangeTellCapabilityDidChange ( void );
1760 void OurChangeFinish ( void );
1761
1762 // downward power change initiated by a power parent
1763 IOReturn ParentChangeStart( void );
1764 void ParentChangeTellPriorityClientsPowerDown ( void );
1765 void ParentChangeTellCapabilityWillChange ( void );
1766 void ParentChangeNotifyInterestedDriversWillChange ( void );
1767 void ParentChangeSetPowerState ( void );
1768 void ParentChangeWaitForPowerSettle ( void );
1769 void ParentChangeNotifyInterestedDriversDidChange ( void );
1770 void ParentChangeTellCapabilityDidChange ( void );
1771 void ParentChangeAcknowledgePowerChange ( void );
1772
1773 void all_done ( void );
1774 void start_ack_timer ( void );
1775 void stop_ack_timer ( void );
1776 void startSettleTimer( void );
1777 bool checkForDone ( void );
1778 bool responseValid ( uint32_t x, int pid );
1779 void computeDesiredState ( unsigned long tempDesire = 0 );
1780 void rebuildChildClampBits ( void );
1781 void tellSystemCapabilityChange( uint32_t nextMS );
1782
1783 static void ack_timer_expired( thread_call_param_t, thread_call_param_t );
1784 static IOReturn actionAckTimerExpired(OSObject *, void *, void *, void *, void * );
1785 static IOReturn actionDriverCalloutDone(OSObject *, void *, void *, void *, void * );
1786 static IOPMRequest * acquirePMRequest( IOService * target, IOOptionBits type, IOPMRequest * active = 0 );
1787 static void releasePMRequest( IOPMRequest * request );
1788 static void pmDriverCallout( IOService * from );
1789 static void pmTellAppWithResponse( OSObject * object, void * context );
1790 static void pmTellClientWithResponse( OSObject * object, void * context );
1791 static void pmTellCapabilityAppWithResponse ( OSObject * object, void * arg );
1792 static void pmTellCapabilityClientWithResponse( OSObject * object, void * arg );
1793 bool ackTimerTick( void );
1794 void addPowerChild1( IOPMRequest * request );
1795 void addPowerChild2( IOPMRequest * request );
1796 void addPowerChild3( IOPMRequest * request );
1797 void adjustPowerState( uint32_t clamp = 0 );
1798 void start_ack_timer( UInt32 value, UInt32 scale );
1799 void handlePMstop( IOPMRequest * request );
1800 void handleRegisterPowerDriver( IOPMRequest * request );
1801 bool handleAcknowledgePowerChange( IOPMRequest * request );
1802 void handlePowerDomainWillChangeTo( IOPMRequest * request );
1803 void handlePowerDomainDidChangeTo( IOPMRequest * request );
1804 void handleRequestPowerState( IOPMRequest * request );
1805 void handlePowerOverrideChanged( IOPMRequest * request );
1806 void handleActivityTickle( IOPMRequest * request );
1807 void handleInterestChanged( IOPMRequest * request );
1808 void handleSynchronizePowerTree( IOPMRequest * request );
1809 void submitPMRequest( IOPMRequest * request );
1810 void submitPMRequest( IOPMRequest ** request, IOItemCount count );
1811 void executePMRequest( IOPMRequest * request );
1812 bool servicePMRequest( IOPMRequest * request, IOPMWorkQueue * queue );
1813 bool retirePMRequest( IOPMRequest * request, IOPMWorkQueue * queue );
1814 bool servicePMRequestQueue( IOPMRequest * request, IOPMRequestQueue * queue );
1815 bool servicePMReplyQueue( IOPMRequest * request, IOPMRequestQueue * queue );
1816 bool servicePMFreeQueue( IOPMRequest * request, IOPMCompletionQueue * queue );
1817 bool notifyInterestedDrivers( void );
1818 void notifyInterestedDriversDone( void );
1819 bool notifyControllingDriver( void );
1820 void notifyControllingDriverDone( void );
1821 void driverSetPowerState( void );
1822 void driverInformPowerChange( void );
1823 bool isPMBlocked( IOPMRequest * request, int count );
1824 void notifyChildren( void );
1825 void notifyChildrenOrdered( void );
1826 void notifyChildrenDelayed( void );
1827 void cleanClientResponses ( bool logErrors );
1828 void updatePowerClient( const OSSymbol * client, uint32_t powerState );
1829 void removePowerClient( const OSSymbol * client );
1830 uint32_t getPowerStateForClient( const OSSymbol * client );
1831 IOReturn requestPowerState( const OSSymbol * client, uint32_t state );
1832 IOReturn requestDomainPower( IOPMPowerStateIndex ourPowerState, IOOptionBits options = 0 );
1833 void waitForPMDriverCall( IOService * target = 0 );
1834 #endif /* XNU_KERNEL_PRIVATE */
1835 };
1836
1837 #endif /* ! _IOKIT_IOSERVICE_H */