Chameleon

Chameleon Svn Source Tree

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

Archive Download this file

Revision: 1466