]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/IOService.h
xnu-123.5.tar.gz
[apple/xnu.git] / iokit / IOKit / IOService.h
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * Copyright (c) 1998,1999 Apple Computer, Inc. All rights reserved.
24 *
25 * HISTORY
26 *
27 */
28
29
30 #ifndef _IOKIT_IOSERVICE_H
31 #define _IOKIT_IOSERVICE_H
32
33 #include <IOKit/IORegistryEntry.h>
34 #include <IOKit/IOReturn.h>
35 #include <IOKit/IODeviceMemory.h>
36 #include <IOKit/IONotifier.h>
37 #include <IOKit/IOLocks.h>
38
39 #include <IOKit/IOKitDebug.h>
40 #include <IOKit/IOInterrupts.h>
41
42 class IOPMinformee;
43 class IOPowerConnection;
44
45 #include <IOKit/pwr_mgt/IOPMpowerState.h>
46 #include <IOKit/IOServicePM.h>
47
48 extern "C" {
49 #include <kern/thread_call.h>
50 }
51
52 enum {
53 kIODefaultProbeScore = 0
54 };
55
56 // masks for getState()
57 enum {
58 kIOServiceInactiveState = 0x00000001,
59 kIOServiceRegisteredState = 0x00000002,
60 kIOServiceMatchedState = 0x00000004,
61 kIOServiceFirstPublishState = 0x00000008,
62 kIOServiceFirstMatchState = 0x00000010
63 };
64
65 // options for registerService()
66 enum {
67 kIOServiceExclusive = 0x00000001,
68 kIOServiceSynchronous = 0x00000002,
69 };
70
71 // options for terminate()
72 enum {
73 kIOServiceRequired = 0x00000001
74 };
75
76 // options for open()
77 enum {
78 kIOServiceSeize = 0x00000001,
79 kIOServiceFamilyOpenOptions = 0xffff0000
80 };
81
82 // options for close()
83 enum {
84 kIOServiceFamilyCloseOptions = 0xffff0000
85 };
86
87 typedef void * IONotificationRef;
88
89 extern const IORegistryPlane * gIOServicePlane;
90 extern const IORegistryPlane * gIOPowerPlane;
91
92 extern const OSSymbol * gIOResourcesKey;
93 extern const OSSymbol * gIOResourceMatchKey;
94 extern const OSSymbol * gIOProviderClassKey;
95 extern const OSSymbol * gIONameMatchKey;
96 extern const OSSymbol * gIONameMatchedKey;
97 extern const OSSymbol * gIOPropertyMatchKey;
98 extern const OSSymbol * gIOLocationMatchKey;
99 extern const OSSymbol * gIOPathMatchKey;
100 extern const OSSymbol * gIOMatchCategoryKey;
101 extern const OSSymbol * gIODefaultMatchCategoryKey;
102 extern const OSSymbol * gIOMatchedServiceCountKey;
103
104 extern const OSSymbol * gIOUserClientClassKey;
105 extern const OSSymbol * gIOKitDebugKey;
106 extern const OSSymbol * gIOServiceKey;
107
108 extern const OSSymbol * gIOCommandPoolSizeKey;
109
110 extern const OSSymbol * gIOPublishNotification;
111 extern const OSSymbol * gIOFirstPublishNotification;
112 extern const OSSymbol * gIOMatchedNotification;
113 extern const OSSymbol * gIOFirstMatchNotification;
114 extern const OSSymbol * gIOTerminatedNotification;
115
116 extern const OSSymbol * gIOGeneralInterest;
117 extern const OSSymbol * gIOBusyInterest;
118 extern const OSSymbol * gIOAppPowerStateInterest;
119
120 extern const OSSymbol * gIODeviceMemoryKey;
121 extern const OSSymbol * gIOInterruptControllersKey;
122 extern const OSSymbol * gIOInterruptSpecifiersKey;
123
124 extern SInt32 IOServiceOrdering( const OSMetaClassBase * inObj1, const OSMetaClassBase * inObj2, void * ref );
125
126 typedef void (*IOInterruptAction)( OSObject * target, void * refCon,
127 IOService * nub, int source );
128
129 /*! @typedef IOServiceNotificationHandler
130 @param target Reference supplied when the notification was registered.
131 @param refCon Reference constant supplied when the notification was registered.
132 @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. */
133
134 typedef bool (*IOServiceNotificationHandler)( void * target, void * refCon,
135 IOService * newService );
136
137 /*! @typedef IOServiceInterestHandler
138 @param target Reference supplied when the notification was registered.
139 @param refCon Reference constant supplied when the notification was registered.
140 @param messageType Type of the message - IOKit defined in IOKit/IOMessage.h or family specific.
141 @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.
142 @param messageArgument An argument for message, dependent on its type.
143 @param argSize Non zero if the argument represents a struct of that size, used when delivering messages outside the kernel. */
144
145 typedef IOReturn (*IOServiceInterestHandler)( void * target, void * refCon,
146 UInt32 messageType, IOService * provider,
147 void * messageArgument, vm_size_t argSize );
148
149 typedef void (*IOServiceApplierFunction)(IOService * service, void * context);
150 typedef void (*OSObjectApplierFunction)(OSObject * object, void * context);
151
152 class IOUserClient;
153 class IOPlatformExpert;
154
155 /*! @class IOService : public IORegistryEntry
156 @abstract The base class for most families, devices and drivers.
157 @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.
158
159 Types of service are specified with a matching dictionary that describes properties of the service. For example, a matching dictionary might describe any IOUSBDevice (or subclass), an IOUSBDevice with a certain class code, or a IOPCIDevice with a set of OpenFirmware matching names or device & vendor IDs. Since the matching dictionary is interpreted by the family which created the service, as well as generically by IOService, the list of properties considered for matching depends on the familiy.
160
161 Matching dictionaries are associated with IOService classes by the catalogue, as driver property tables, and also supplied by clients of the notification APIs.
162
163 IOService provides matching based on c++ class (via OSMetaClass dynamic casting), registry entry name, a registry path to the service (which includes OpenFirmware paths), a name assigned by BSD, or by its location (its point of attachment).
164
165 <br><br>Driver Instantiation by IOService<br><br>
166
167 Drivers are subclasses of IOService, and their availability is managed through the catalogue. They are instantiated based on the publication of an IOService they use (for example, an IOPCIDevice or IOUSBDevice), or when they are added to the catalogue and the IOService(s) they use are already available.
168
169 When an IOService (the "provider") is published with the registerService() 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 kIOProbeScoreKey ("IOProbeScore") property in the dictionary, or supplied with the notification.
170
171 Each entry in the list is then processed in order - for notifications, the notification is delivered, for driver property tables a lot more happens.
172
173 The driver class is instantiated and init() called with its property table. The new driver instance is then attached to the provider, and has its probe() method called with the provider as an argument. The default probe 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).
174
175 When the probing phase is complete, the list consists of successfully probed drivers, in order of their probe score (after adjustment during the probe() call). The list is then divided into categories based on the kIOMatchCategoryKey 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.
176
177 For each category, the highest scoring driver in that category is attached to the provider, and its start() method called. If start() is successful, the rest of the drivers in the same match category are discarded, otherwise the next highest scoring driver is started, and so one.
178
179 The driver should only consider itself in action when the start method is called, meaning it has been selected for use on the provider, and consuming that particular match category. It should also be prepared to be allocated, probed and freed even if the probe was sucessful.
180
181 After the drivers have all synchronously been started, the installed "matched" notifications that match the registered IOService are delivered.
182
183 <br><br>Properties used by IOService<br><br>
184
185 kIOClassKey, extern const OSSymbol * gIOClassKey, "IOClass"
186 <br>
187 Class of the driver to instantiate on matching providers.
188 <br>
189 <br>
190 kIOProviderClassKey, extern const OSSymbol * gIOProviderClassKey, "IOProviderClass"
191 <br>
192 Class of the provider(s) to be considered for matching, checked with OSDynamicCast so subclasses will also match.
193 <br>
194 <br>
195 kIOProbeScoreKey, extern const OSSymbol * gIOProbeScoreKey, "IOProbeScore"
196 <br>
197 The probe score initially used to order multiple matching drivers.
198 <br>
199 <br>
200 kIOMatchCategoryKey, extern const OSSymbol * gIOMatchCategoryKey, "IOMatchCategory"
201 <br>
202 A string defining the driver category for matching purposes. All drivers with no IOMatchCategory property are considered to be in the same default category. Only one driver in a category can be started on each provider.
203 <br>
204 <br>
205 kIONameMatchKey, extern const OSSymbol * gIONameMatchKey, "IONameMatch"
206 <br>
207 A string or collection of strings that match the provider's name. The comparison is implemented with the IORegistryEntry::compareNames 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 kIONameMatchedKey property.
208 <br>
209 Examples
210 <br>
211 &ltkey&gtIONameMatch&lt/key&gt <br>
212 &ltstring&gtpci106b,7&ltstring&gt
213 <br>
214 For a list of possible matching names, a serialized array of strings should used, eg.
215 <br>
216 &ltkey&gtIONameMatch&lt/key&gt <br>
217 &ltarray&gt <br>
218 &ltstring&gtAPPL,happy16&lt/string&gt <br>
219 &ltstring&gtpci106b,7&lt/string&gt <br>
220 &lt/array&gt
221 <br>
222 <br>
223 kIONameMatchedKey, extern const OSSymbol * gIONameMatchedKey, "IONameMatched"
224 <br>
225 The name successfully matched name from the kIONameMatchKey property will be left in the driver's property table as the kIONameMatchedKey property.
226 <br>
227 <br>
228 kIOPropertyMatchKey, extern const OSSymbol * gIOPropertyMatchKey, "IOPropertyMatch"
229 <br>
230 A dictionary of properties that each must exist in the matching IOService and compare sucessfully with the isEqualTo method.
231 &ltkey&gtIOPropertyMatch&lt/key&gt <br>
232 &ltdictionary&gt <br>
233 &ltkey&gtname&lt/key&gt <br>
234 &ltstring&gtAPPL,meek8&lt/string&gt <br>
235 &lt/dictionary&gt
236 <br>
237 <br>
238 kIOUserClientClassKey, extern const OSSymbol * gIOUserClientClassKey, "IOUserClientClass"
239 <br>
240 The class name that the service will attempt to allocate when a user client connection is requested. First the device nub is queried, then the nub's provider is queried by default.
241 <br>
242 <br>
243 kIOKitDebugKey, extern const OSSymbol * gIOKitDebugKey, "IOKitDebug"
244 <br>
245 Set some debug flags for logging the driver loading process. Flags are defined in IOKit/IOKitDebug.h, but 65535 works well.
246
247 */
248
249 class IOService : public IORegistryEntry
250 {
251 OSDeclareDefaultStructors(IOService)
252
253 protected:
254 /*! @struct ExpansionData
255 @discussion This structure will be used to expand the capablilties of this class in the future.
256 */
257 struct ExpansionData { };
258
259 /*! @var reserved
260 Reserved for future use. (Internal use only) */
261 ExpansionData * reserved;
262
263 private:
264 IOService * __provider;
265 SInt32 __providerGeneration;
266 IOService * __owner;
267 IOOptionBits __state[2];
268 IOOptionBits __reserved[4];
269
270 // pointer to private instance variables for power management
271 IOPMpriv * priv;
272
273 protected:
274 // TRUE once PMinit has been called
275 bool initialized;
276 // pointer to protected instance variables for power management
277 IOPMprot * pm_vars;
278
279 private:
280 OSMetaClassDeclareReservedUnused(IOService, 0);
281 OSMetaClassDeclareReservedUnused(IOService, 1);
282 OSMetaClassDeclareReservedUnused(IOService, 2);
283 OSMetaClassDeclareReservedUnused(IOService, 3);
284 OSMetaClassDeclareReservedUnused(IOService, 4);
285 OSMetaClassDeclareReservedUnused(IOService, 5);
286 OSMetaClassDeclareReservedUnused(IOService, 6);
287 OSMetaClassDeclareReservedUnused(IOService, 7);
288 OSMetaClassDeclareReservedUnused(IOService, 8);
289 OSMetaClassDeclareReservedUnused(IOService, 9);
290 OSMetaClassDeclareReservedUnused(IOService, 10);
291 OSMetaClassDeclareReservedUnused(IOService, 11);
292 OSMetaClassDeclareReservedUnused(IOService, 12);
293 OSMetaClassDeclareReservedUnused(IOService, 13);
294 OSMetaClassDeclareReservedUnused(IOService, 14);
295 OSMetaClassDeclareReservedUnused(IOService, 15);
296 OSMetaClassDeclareReservedUnused(IOService, 16);
297 OSMetaClassDeclareReservedUnused(IOService, 17);
298 OSMetaClassDeclareReservedUnused(IOService, 18);
299 OSMetaClassDeclareReservedUnused(IOService, 19);
300 OSMetaClassDeclareReservedUnused(IOService, 20);
301 OSMetaClassDeclareReservedUnused(IOService, 21);
302 OSMetaClassDeclareReservedUnused(IOService, 22);
303 OSMetaClassDeclareReservedUnused(IOService, 23);
304 OSMetaClassDeclareReservedUnused(IOService, 24);
305 OSMetaClassDeclareReservedUnused(IOService, 25);
306 OSMetaClassDeclareReservedUnused(IOService, 26);
307 OSMetaClassDeclareReservedUnused(IOService, 27);
308 OSMetaClassDeclareReservedUnused(IOService, 28);
309 OSMetaClassDeclareReservedUnused(IOService, 29);
310 OSMetaClassDeclareReservedUnused(IOService, 30);
311 OSMetaClassDeclareReservedUnused(IOService, 31);
312 OSMetaClassDeclareReservedUnused(IOService, 32);
313 OSMetaClassDeclareReservedUnused(IOService, 33);
314 OSMetaClassDeclareReservedUnused(IOService, 34);
315 OSMetaClassDeclareReservedUnused(IOService, 35);
316 OSMetaClassDeclareReservedUnused(IOService, 36);
317 OSMetaClassDeclareReservedUnused(IOService, 37);
318 OSMetaClassDeclareReservedUnused(IOService, 38);
319 OSMetaClassDeclareReservedUnused(IOService, 39);
320 OSMetaClassDeclareReservedUnused(IOService, 40);
321 OSMetaClassDeclareReservedUnused(IOService, 41);
322 OSMetaClassDeclareReservedUnused(IOService, 42);
323 OSMetaClassDeclareReservedUnused(IOService, 43);
324 OSMetaClassDeclareReservedUnused(IOService, 44);
325 OSMetaClassDeclareReservedUnused(IOService, 45);
326 OSMetaClassDeclareReservedUnused(IOService, 46);
327 OSMetaClassDeclareReservedUnused(IOService, 47);
328 OSMetaClassDeclareReservedUnused(IOService, 48);
329 OSMetaClassDeclareReservedUnused(IOService, 49);
330 OSMetaClassDeclareReservedUnused(IOService, 50);
331 OSMetaClassDeclareReservedUnused(IOService, 51);
332 OSMetaClassDeclareReservedUnused(IOService, 52);
333 OSMetaClassDeclareReservedUnused(IOService, 53);
334 OSMetaClassDeclareReservedUnused(IOService, 54);
335 OSMetaClassDeclareReservedUnused(IOService, 55);
336 OSMetaClassDeclareReservedUnused(IOService, 56);
337 OSMetaClassDeclareReservedUnused(IOService, 57);
338 OSMetaClassDeclareReservedUnused(IOService, 58);
339 OSMetaClassDeclareReservedUnused(IOService, 59);
340 OSMetaClassDeclareReservedUnused(IOService, 60);
341 OSMetaClassDeclareReservedUnused(IOService, 61);
342 OSMetaClassDeclareReservedUnused(IOService, 62);
343 OSMetaClassDeclareReservedUnused(IOService, 63);
344
345 public:
346 /*! @function getState
347 @abstract Accessor for IOService state bits, not normally needed or used outside IOService.
348 @result State bits for the IOService, eg. kIOServiceInactiveState, kIOServiceRegisteredState. */
349
350 virtual IOOptionBits getState( void ) const;
351
352 /*! @function isInactive
353 @abstract Check the IOService has been terminated, and is in the process of being destroyed.
354 @discussion When an IOService 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.
355 @result Returns true if the IOService has been terminated. */
356
357 inline bool isInactive( void ) const
358 { return( 0 != (kIOServiceInactiveState & getState())); }
359
360 /* Stack creation */
361
362 /*! @function registerService
363 @abstract Start the registration process for a newly discovered IOService.
364 @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 registerService is called.
365 @param options The default zero options mask is recommended & should be used in most cases. The registration process is usually asynchronous, with possible driver probing & notification occurring some time later. kIOServiceSynchronous may be passed to carry out the matching and notification process for currently registered clients before returning to the caller. */
366
367 virtual void registerService( IOOptionBits options = 0 );
368
369 /*! @function probe
370 @abstract During an IOService instantiation probe a matched service to see if it can be used.
371 @discussion The registration process for an IOService (the provider) includes instantiating possible driver clients. The probe 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 probe method can be left unimplemented by IOService subclasses. The client is already attached to the provider when probe is called.
372 @param provider The registered IOService which matches a driver personality's matching dictionary.
373 @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 IOProbeScore property in the drivers property table, or kIODefaultProbeScore if none is specified. The probe method may alter the score to affect start order.
374 @result Returns an IOService instance or zero when the probe is unsuccessful. In almost all cases the value of this 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 start. */
375
376 virtual IOService * probe( IOService * provider,
377 SInt32 * score );
378
379 /*! @function start
380 @abstract During an IOService instantiation, the start method is called when the IOService has been selected to run on the provider.
381 @discussion The registration process for an IOService (the provider) includes instantiating possible driver clients. The start method is called in the client instance when it has been selected (by its probe score and match category) to be the winning client. The client is already attached to the provider when start is called.
382 @result Return true if the start was successful, false otherwise (which will cause the instance to be detached and usually freed). */
383
384 virtual bool start( IOService * provider );
385
386 /*! @function stop
387 @abstract During an IOService termination, the stop method is called in its clients before they are detached & it is destroyed.
388 @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. */
389
390 virtual void stop( IOService * provider );
391
392 /* Open / Close */
393
394 /*! @function open
395 @abstract Request active access to a provider.
396 @discussion IOService provides generic open and close semantics to track clients of a provider that have established an active datapath. The use of open & close, and rules regarding ownership are family defined, and defined by the handleOpen / handleClose methods in the provider. Some families will limit access to a provider based on its open state.
397 @param forClient Designates the client of the provider requesting the open.
398 @param options Options for the open. The provider family may implement options for open; IOService defines only kIOServiceSeize to request the device be withdrawn from its current owner.
399 @result Return true if the open was successful, false otherwise. */
400
401 virtual bool open( IOService * forClient,
402 IOOptionBits options = 0,
403 void * arg = 0 );
404
405 /*! @function close
406 @abstract Release active access to a provider.
407 @discussion IOService provides generic open and close semantics to track clients of a provider that have established an active datapath. The use of open & close, and rules regarding ownership are family defined, and defined by the handleOpen / handleClose methods in the provider.
408 @param forClient Designates the client of the provider requesting the close.
409 @param options Options available for the close. The provider family may implement options for close; IOService defines none.
410 @param arg Family specific arguments, ignored by IOService. */
411
412 virtual void close( IOService * forClient,
413 IOOptionBits options = 0 );
414
415 /*! @function isOpen
416 @abstract Determine whether a specific, or any, client has an IOService open.
417 @discussion Returns the open state of an IOService with respect to the specified client, or when it is open by any client.
418 @param forClient If non-zero, isOpen returns the open state for that client. If zero is passed, isOpen returns the open state for all clients.
419 @result Returns true if the specific, or any, client has the IOService open. */
420
421 virtual bool isOpen( const IOService * forClient = 0 ) const;
422
423 /*! @function handleOpen
424 @abstract Overrideable method to control the open / close behaviour of an IOService.
425 @discussion IOService calls this method in its subclasses in response to the open method, so the subclass may implement the request. The default implementation provides single owner access to an IOService via open. The object is locked via lockForArbitration before handleOpen is called.
426 @param forClient Designates the client of the provider requesting the open.
427 @param options Options for the open, may be interpreted by the implementor of handleOpen.
428 @result Return true if the open was successful, false otherwise. */
429
430 virtual bool handleOpen( IOService * forClient,
431 IOOptionBits options,
432 void * arg );
433
434 /*! @function handleClose
435 @abstract Overrideable method to control the open / close behaviour of an IOService.
436 @discussion IOService calls this method in its subclasses in response to the close method, so the subclass may implement the request. The default implementation provides single owner access to an IOService via open. The object is locked via lockForArbitration before handleClose is called.
437 @param forClient Designates the client of the provider requesting the close.
438 @param options Options for the close, may be interpreted by the implementor of handleOpen. */
439
440 virtual void handleClose( IOService * forClient,
441 IOOptionBits options );
442
443 /*! @function handleIsOpen
444 @abstract Overrideable method to control the open / close behaviour of an IOService.
445 @discussion IOService calls this method in its subclasses in response to the open method, so the subclass may implement the request. The default implementation provides single owner access to an IOService via open. The object is locked via lockForArbitration before handleIsOpen is called.
446 @param forClient If non-zero, isOpen returns the open state for that client. If zero is passed, isOpen returns the open state for all clients.
447 @result Returns true if the specific, or any, client has the IOService open. */
448
449 virtual bool handleIsOpen( const IOService * forClient ) const;
450
451 /* Stacking change */
452
453 /*! @function terminate
454 @abstract Make an IOService inactive and begin its destruction.
455 @discussion Registering an IOService informs possible clients of its existance and instantiates drivers that may be used with it; terminate involves the opposite process of informing clients that an IOService is no longer able to be used and will be destroyed. By default, if any client has the service open, terminate fails. If the kIOServiceRequired flag is passed however, terminate will be sucessful though further progress in the destruction of the IOService 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 message method with a message of type kIOMessageServiceIsTerminated. Both these actions take place on the callers thread. After the IOService is made inactive, further matching or attach calls will fail on it. Each client has its stop method called upon their close of an inactive IOService, or on its termination if they do not have it open. After stop, detach is called in each client. When all clients have been detached, the finalize method is called in the inactive service. The terminate process is inherently asynchronous since it will be deferred until all clients have chosen to close.
456 @param options In most cases no options are needed. kIOServiceSynchronous may be passed to cause terminate to not return until the service is finalized. */
457
458 virtual bool terminate( IOOptionBits options = 0 );
459
460 /*! @function finalize
461 @abstract The last stage in an IOService destruction.
462 @discussion The finalize method is called in an inactive (ie. terminated) IOService after the last client has detached. IOService's implementation will call stop, close, and detach on each provider. When finalize returns, the object's retain count will have no references generated by IOService's registration process.
463 @param options The options passed to the terminate method of the IOService are passed on to finalize.
464 @result Returns true. */
465
466 virtual bool finalize( IOOptionBits options );
467
468 /*! @function lockForArbitration
469 @abstract Locks an IOService against changes in state or ownership.
470 @discussion The registration, termination and open / close functions of IOService use lockForArbtration to single thread access to an IOService. lockForArbitration will grant recursive access to the same thread.
471 @param isSuccessRequired If a request for access to an IOService should be denied if it is terminated, isSuccessRequired should passed as false, otherwise pass true. */
472
473 virtual bool lockForArbitration( bool isSuccessRequired = true );
474
475 /*! @function unlockForArbitration
476 @abstract Unlocks an IOService after a successful lockForArbitration.
477 @discussion A thread granted exclusive access to an IOService should release it with unlockForArbitration. */
478
479 virtual void unlockForArbitration( void );
480
481 /*! @function terminateClient
482 @abstract Passes a termination up the stack.
483 @discussion When an IOService is made inactive the default behaviour 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 a terminated IOService to override this behaviour. Note the client may also override this behaviour by overriding its terminate method.
484 @param client The client of the of the terminated provider.
485 @param options Options originally passed to terminate, plus kIOServiceRecursing.
486 @result result of the terminate request on the client. */
487
488 virtual bool terminateClient( IOService * client, IOOptionBits options );
489
490 /* Busy state indicates discovery, matching or termination is in progress */
491
492 /*! @function getBusyState
493 @abstract Returns the busyState of an IOService.
494 @discussion Many activities in IOService are asynchronous. When registration, matching, or termination is in progress on an IOService, its busyState is increased by one. Change in busyState to or from zero also changes the IOService's provider's busyState by one, which means that an IOService is marked busy when any of the above activities is ocurring on it or any of its clients.
495 @result The busyState. */
496
497 virtual UInt32 getBusyState( void );
498
499 /*! @function adjustBusy
500 @abstract Adjusts the busyState of an IOService.
501 @discussion Applies a delta to an IOService's busyState. A change in the busyState to or from zero will changes the IOService's provider's busyState by one (in the same direction).
502 @param delta The delta to be applied to the IOService busy state. */
503
504 virtual void adjustBusy( SInt32 delta );
505
506 /*! @function waitQuiet
507 @abstract Wait for an IOService's busyState to be zero.
508 @discussion Blocks the caller until an IOService is non busy.
509 @param timeout Specifies a maximum time to wait.
510 @result Returns an error code if mach synchronization primitives fail, kIOReturnTimeout, or kIOReturnSuccess. */
511
512 virtual IOReturn waitQuiet( mach_timespec_t * timeout = 0 );
513
514 /* Matching */
515
516 /*! @function matchPropertyTable
517 @abstract Allows a registered IOService to implement family specific matching.
518 @discussion All matching on an IOService 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 if so. Note that since matching is also carried out by other parts of IOKit, the matching dictionary may contain properties the family does not understand - these should not be considered matching failures.
519 @param table The dictionary of properties to be matched against.
520 @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 IOProbeScore property in the drivers property table, or kIODefaultProbeScore if none is specified.
521 @result Returns false if the family considers the matching dictionary does not match in properties it understands, true otherwise. */
522
523 virtual bool matchPropertyTable( OSDictionary * table,
524 SInt32 * score );
525
526 virtual bool matchPropertyTable( OSDictionary * table );
527
528 /*! @function matchLocation
529 @abstract Allows a registered IOService to direct location matching.
530 @discussion By default, a location matching property will be applied to an IOService's provider. This method allows that behaviour to be overridden by families.
531 @param client The IOService at which matching is taking place.
532 @result Returns the IOService instance to be used for location matching. */
533
534 virtual IOService * matchLocation( IOService * client );
535
536 /* Resource service */
537
538 /*! @function publishResource
539 @abstract Use the resource service to publish a property.
540 @discussion The resource service uses IOService's matching and notification to allow objects to be published and found by any IOKit client by a global name. publishResource makes an object available to anyone waiting for it or looking for it in the future.
541 @param key An OSSymbol key that globally identifies the object.
542 @param The object to be published. */
543
544 static void publishResource( const OSSymbol * key, OSObject * value = 0 );
545
546 /*! @function publishResource
547 @abstract Use the resource service to publish a property.
548 @discussion The resource service uses IOService's matching and notification to allow objects to be published and found by any IOKit client by a global name. publishResource makes an object available to anyone waiting for it or looking for it in the future.
549 @param key A C-string key that globally identifies the object.
550 @param The object to be published. */
551
552 static void publishResource( const char * key, OSObject * value = 0 );
553 virtual bool addNeededResource( const char * key );
554
555 /* Notifications */
556
557 /*! @function addNotification
558 @abstract Add a persistant notification handler to be notified of IOService events.
559 @discussion IOService will deliver notifications of changes in state of an IOService to registered clients. The type of notification is specified by a symbol, for example gIOMatchedNotification or gIOTerminatedNotification, and notifications will only include IOService's that match the supplied matching dictionary. Notifications are ordered by a priority set with addNotification. When the notification is installed, its handler will be called with each of any currently existing IOService's 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. addNotification will consume a retain count on the matching dictionary when the notification is removed.
560 @param type An OSSymbol identifying the type of notification and IOService state:
561 <br> gIOPublishNotification Delivered when an IOService is registered.
562 <br> gIOFirstPublishNotification Delivered when an IOService is registered, but only once per IOService instance. Some IOService's may be reregistered when their state is changed.
563 <br> gIOMatchedNotification Delivered when an IOService has been matched with all client drivers, and they have been probed and started.
564 <br> gIOFirstMatchNotification Delivered when an IOService has been matched with all client drivers, but only once per IOService instance. Some IOService's may be reregistered when their state is changed.
565 <br> gIOTerminatedNotification Delivered after an IOService has been terminated, during its finalize stage.
566 @param matching A matching dictionary to restrict notifications to only matching IOServices. The dictionary will be released when the notification is removed - consuming the passed in reference.
567 @param handler A C-function callback to deliver notifications.
568 @param target An instance reference for the callbacks use.
569 @param ref A reference constant for the callbacks use
570 @param priority A constant ordering all notifications of a each type.
571 @result Returns an instance of an IONotifier object that can be used to control or destroy the notification request. */
572
573 static IONotifier * addNotification(
574 const OSSymbol * type, OSDictionary * matching,
575 IOServiceNotificationHandler handler,
576 void * target, void * ref = 0,
577 SInt32 priority = 0 );
578
579 /*! @function waitForService
580 @abstract Wait for a matching to service to be published.
581 @discussion Provides a method of waiting for an IOService matching the supplied matching dictionary to be registered and fully matched.
582 @param matching The matching dictionary describing the desired IOService. waitForService will consume one reference of the matching dictionary.
583 @param timeout The maximum time to wait.
584 @result A published IOService matching the supplied dictionary. */
585
586 static IOService * waitForService( OSDictionary * matching,
587 mach_timespec_t * timeout = 0);
588
589 /*! @function getMatchingServices
590 @abstract Finds the set of current published IOServices matching a matching dictionary.
591 @discussion Provides a method of finding the current set of published IOServices matching the supplied matching dictionary.
592 @param matching The matching dictionary describing the desired IOServices.
593 @result An instance of an iterator over a set of IOServices. To be released by the caller. */
594
595 static OSIterator * getMatchingServices( OSDictionary * matching );
596
597 /*! @function installNotification
598 @abstract Add a persistant notification handler to be notified of IOService events.
599 @discussion A lower level interface to addNotification that will install a handler and return the current set of IOServices that are in the specified state and match the matching dictionary.
600 @param type See addNotification.
601 @param matching See addNotification.
602 @param handler See addNotification.
603 @param self See addNotification.
604 @param ref See addNotification.
605 @param priority See addNotification.
606 @param existing Returns an iterator over the set of IOServices that are currently in the specified state and match the matching dictionary.
607 @result See addNotification. */
608
609 static IONotifier * installNotification(
610 const OSSymbol * type, OSDictionary * matching,
611 IOServiceNotificationHandler handler,
612 void * target, void * ref,
613 SInt32 priority, OSIterator ** existing );
614
615 /* Helpers to make matching dictionaries for simple cases,
616 * they add keys to an existing dictionary, or create one. */
617
618 /*! @function serviceMatching
619 @abstract Create a matching dictionary, or add matching properties to an existing dictionary, that specify an IOService class match.
620 @discussion A very common matching criteria for IOService is based on its class. serviceMatching will create 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.
621 @param className The class name, as a const C-string. Class matching is successful on IOService's of this class or any subclass.
622 @param table If zero, serviceMatching will create a matching dictionary and return a reference to it, otherwise the matching properties are added to the specified dictionary.
623 @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
624
625 static OSDictionary * serviceMatching( const char * className,
626 OSDictionary * table = 0 );
627
628 /*! @function serviceMatching
629 @abstract Create a matching dictionary, or add matching properties to an existing dictionary, that specify an IOService class match.
630 @discussion A very common matching criteria for IOService is based on its class. serviceMatching will create 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.
631 @param className The class name, as an OSString (which includes OSSymbol). Class matching is successful on IOService's of this class or any subclass.
632 @param table If zero, serviceMatching will create a matching dictionary and return a reference to it, otherwise the matching properties are added to the specified dictionary.
633 @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
634
635 static OSDictionary * serviceMatching( const OSString * className,
636 OSDictionary * table = 0 );
637
638 /*! @function nameMatching
639 @abstract Create a matching dictionary, or add matching properties to an existing dictionary, that specify an IOService name match.
640 @discussion A very common matching criteria for IOService is based on its name. nameMatching will create a matching dictionary that specifies any IOService which respond sucessfully 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.
641 @param name The service's name, as a const C-string. Name matching is successful on IOService's which respond sucessfully to the IORegistryEntry method compareName.
642 @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.
643 @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
644
645 static OSDictionary * nameMatching( const char * name,
646 OSDictionary * table = 0 );
647
648 /*! @function nameMatching
649 @abstract Create a matching dictionary, or add matching properties to an existing dictionary, that specify an IOService name match.
650 @discussion A very common matching criteria for IOService is based on its name. nameMatching will create a matching dictionary that specifies any IOService which respond sucessfully 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.
651 @param name The service's name, as an OSString (which includes OSSymbol). Name matching is successful on IOService's which respond sucessfully to the IORegistryEntry method compareName.
652 @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.
653 @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
654
655 static OSDictionary * nameMatching( const OSString* name,
656 OSDictionary * table = 0 );
657
658 /*! @function resourceMatching
659 @abstract Create a matching dictionary, or add matching properties to an existing dictionary, that specify a resource service match.
660 @discussion IOService maintains a resource service IOResources that allows objects to be published and found globally in IOKit based on a name, using the standard IOService matching and notification calls.
661 @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 publishResource method.
662 @param table If zero, resourceMatching will create a matching dictionary and return a reference to it, otherwise the matching properties are added to the specified dictionary.
663 @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
664
665 static OSDictionary * resourceMatching( const char * name,
666 OSDictionary * table = 0 );
667
668 /*! @function resourceMatching
669 @abstract Create a matching dictionary, or add matching properties to an existing dictionary, that specify a resource service match.
670 @discussion IOService maintains a resource service IOResources that allows objects to be published and found globally in IOKit based on a name, using the standard IOService matching and notification calls.
671 @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 publishResource method.
672 @param table If zero, resourceMatching will create a matching dictionary and return a reference to it, otherwise the matching properties are added to the specified dictionary.
673 @result The matching dictionary created, or passed in, is returned on success, or zero on failure. */
674
675 static OSDictionary * resourceMatching( const OSString * name,
676 OSDictionary * table = 0 );
677
678 /*! @function addLocation
679 @abstract Add a location matching property to an existing dictionary.
680 @discussion This function creates matching properties that specify the location of a IOService, as an embedded matching dictionary. This matching will be successful on an IOService which attached to an IOService which matches this location matching dictionary.
681 @param table The matching properties are added to the specified dictionary, which must be non-zero.
682 @result The location matching dictionary created is returned on success, or zero on failure. */
683
684 static OSDictionary * addLocation( OSDictionary * table );
685
686 /* Helpers for matching dictionaries. */
687
688 /*! @function compareProperty
689 @abstract Utility to compare a property in a matching dictionary with an IOService's property table.
690 @discussion This is a helper function to aid in implementing matchPropertyTable. If the property specified by key exists in the matching dictionary, it is compared with a property of the same name in the IOService's property table. The comparison is performed with the isEqualTo 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.
691 @param matching The matching dictionary, which must be non-zero.
692 @param key The dictionary key specifying the property to be compared, as a C-string.
693 @result If the property does not exist in the matching table, true is returned. 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 isEqualTo method with the IOService property as an argument is returned. */
694
695 virtual bool compareProperty( OSDictionary * matching,
696 const char * key );
697 /*! @function compareProperty
698 @abstract Utility to compare a property in a matching dictionary with an IOService's property table.
699 @discussion This is a helper function to aid in implementing matchPropertyTable. If the property specified by key exists in the matching dictionary, it is compared with a property of the same name in the IOService's property table. The comparison is performed with the isEqualTo 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.
700 @param matching The matching dictionary, which must be non-zero.
701 @param key The dictionary key specifying the property to be compared, as an OSString (which includes OSSymbol).
702 @result If the property does not exist in the matching table, true is returned. 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 isEqualTo method with the IOService property as an argument is returned. */
703
704 virtual bool compareProperty( OSDictionary * matching,
705 const OSString * key );
706
707 /*! @function compareProperties
708 @abstract Utility to compare a set of properties in a matching dictionary with an IOService's property table.
709 @discussion This is a helper function to aid in implementing matchPropertyTable. A collection of dictionary keys specifies properties in a matching dictionary to be compared, with compareProperty, with an IOService property table, if compareProperty returns true for each key, success is return else failure.
710 @param matching The matching dictionary, which must be non-zero.
711 @param keys A collection (eg. OSSet, OSArray, OSDictionary) which should contain OSStrings (or OSSymbols) that specify the property keys to be compared.
712 @result if compareProperty returns true for each key in the collection, success is return else failure. */
713
714 virtual bool compareProperties( OSDictionary * matching,
715 OSCollection * keys );
716
717 /* Client / provider accessors */
718
719 /*! @function attach
720 @abstract Attaches an IOService client to a provider in the registry.
721 @discussion This function called in an IOService client enters the client into the 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 registry will retain both the client and provider until they are detached.
722 @param provider The IOService object which will serve as this objects provider.
723 @result false if the provider is inactive or on a resource failure, otherwise true. */
724
725 virtual bool attach( IOService * provider );
726
727 /*! @function detach
728 @abstract Detaches an IOService client from a provider in the registry.
729 @discussion This function called in an IOService client removes the client as a child of the provider in the service plane of the registry. If the provider is not a parent of the client this is a no-op, otherwise the registry will release both the client and provider.
730 @param provider The IOService object to detach from. */
731
732 virtual void detach( IOService * provider );
733
734 /*! @function getProvider
735 @abstract Returns an IOService's primary provider.
736 @discussion This function called in an IOService client will return the provider to which it was first attached. Since the majority of IOService objects have only one provider, this is a useful simplification and also supports caching of the provider when the registry is unchanged.
737 @result Returns the first provider of the client, or zero if the IOService is not attached into the registry. The provider is retained while the client is attached, and should not be released by the caller. */
738
739 virtual IOService * getProvider( void ) const;
740
741 /*! @function getWorkLoop
742 @abstract Returns the current work loop or provider->getWorkLoop().
743 @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 an entire dedicated thread. This data has to be accessed from a providers 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 providers work loop, i.e. the work loop which will make the completion call outs. In one fell swoop we avoid a potentially nasty deadlock 'cause a work loop's gate is recursive.
744 @result Always returns a work loop, either the current work loop or it walks up the $link getProvider() chain calling getWorkLoop. Eventually it will reach a valid work loop based driver or the root of the io tree where it will return a system wide work loop. Returns 0 if it fails to find (or create) */
745
746 virtual IOWorkLoop * getWorkLoop() const;
747
748 /*! @function getProviderIterator
749 @abstract Returns an iterator over an IOService's providers.
750 @discussion For those few IOService objects that obtain service from multiple providers, this method supplies an iterator over a client's providers.
751 @result Returns 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. */
752
753 virtual OSIterator * getProviderIterator( void ) const;
754
755 /*! @function getOpenProviderIterator
756 @abstract Returns an iterator over an client's providers that are currently opened by the client.
757 @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 lockForArbitration and returning those that have been opened by the client.
758 @result Returns 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 lockForArbitration, protecting it from state changes. */
759
760 virtual OSIterator * getOpenProviderIterator( void ) const;
761
762 /*! @function getClient
763 @abstract Returns an IOService's primary client.
764 @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.
765 @result Returns the first client of the provider, or zero if the IOService is not attached into the registry. The client is retained while it is attached, and should not be released by the caller. */
766
767 virtual IOService * getClient( void ) const;
768
769 /*! @function getClientIterator
770 @abstract Returns an iterator over an IOService's clients.
771 @discussion For IOService objects that may have multiple clients, this method supplies an iterator over a provider's clients.
772 @result Returns 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. */
773
774 virtual OSIterator * getClientIterator( void ) const;
775
776 /*! @function getOpenClientIterator
777 @abstract Returns an iterator over an provider's clients that currently have opened the provider.
778 @discussion For IOService objects that may have multiple clients, this method supplies an iterator over a provider's clients, locking each in turn with lockForArbitration and returning those that have opened the provider.
779 @result Returns an iterator over the clients which the provider 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 lockForArbitration, protecting it from state changes. */
780
781 virtual OSIterator * getOpenClientIterator( void ) const;
782
783 /*! @function callPlatformFunction
784 @abstract Calls the platform function with the given name.
785 @discussion The platform expert or other drivers may implement various functions to control hardware features. callPlatformFunction allows any IOService object to access these functions. Normally callPlatformFunction will be called on a service's provider. The provider will service the request or pass it to it's provider. The systems IOPlatformExpert subclass will catch functions it knows about and redirect them into other parts of the IOService plane. If the IOPlatformExpert subclass can not execute the function, the base class will be called. The IOPlatformExpert base class will attempt to find a service to execute the function by looking up the function name in a IOResources name space. A service may publish a service using publishResource(functionName, this). If no service can be found to execute the function an error will be returned.
786 @param functionName name of the function to be called. When functionName is a c-string, callPlatformFunction will convert the c-string to a OSSymbol and call other OSSymbol version of callPlatformFunction. This process can block and should not be used from an interrupt context.
787 @param waitForFunction if true callPlatformFunction will not return until the function has been called.
788 @result Return an IOReturn code, kIOReturnSuccess if the function was successfully executed, kIOReturnUnsupported if a service to execute the function could not be found. Other return codes may be returned by the function.*/
789
790 virtual IOReturn callPlatformFunction( const OSSymbol * functionName,
791 bool waitForFunction,
792 void *param1, void *param2,
793 void *param3, void *param4 );
794
795 virtual IOReturn callPlatformFunction( const char * functionName,
796 bool waitForFunction,
797 void *param1, void *param2,
798 void *param3, void *param4 );
799
800
801 /* Some accessors */
802
803 /*! @function getPlatform
804 @abstract Returns a pointer to the platform expert instance for the machine.
805 @discussion This method provides an accessor to the platform expert instance for the machine.
806 @result A pointer to the IOPlatformExport instance. It should not be released by the caller. */
807
808 static IOPlatformExpert * getPlatform( void );
809
810 /*! @function getServiceRoot
811 @abstract Returns a pointer to the root of the service plane.
812 @discussion This method provides an accessor to the root of the service plane for the machine.
813 @result A pointer to the IOService instance at the root of the service plane. It should not be released by the caller. */
814
815 static IOService * getServiceRoot( void );
816
817 /* Allocate resources for a matched service */
818
819 /*! @function getResources
820 @abstract Allocate any needed resources for a published IOService before clients attach.
821 @discussion This method is called during the registration process for an IOService object if there are success driver matches, before any clients attach. It allows for lazy allocation of resources to an IOService when a matching driver is found.
822 @result Return an IOReturn code, kIOReturnSuccess is necessary for the IOService to be successfully used, otherwise the registration process for the object is halted. */
823
824 virtual IOReturn getResources( void );
825
826 /* Device memory accessors */
827
828 /*! @function getDeviceMemoryCount
829 @abstract Returns a count of the physical memory ranges available for a device.
830 @discussion This method will return the count of physical memory ranges, each represented by an IODeviceMemory instance, that have been allocated for a memory mapped device.
831 @result An integer count of the number of ranges available. */
832
833 virtual IOItemCount getDeviceMemoryCount( void );
834
835 /*! @function getDeviceMemoryWithIndex
836 @abstract Returns an instance of IODeviceMemory representing one of a device's memory mapped ranges.
837 @discussion This method will return a pointer to an instance of IODeviceMemory for the physical memory range at the given index for a memory mapped device.
838 @param index An index into the array of ranges assigned to the device.
839 @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 mapDeviceMemory() which will create a device memory mapping. */
840
841 virtual IODeviceMemory * getDeviceMemoryWithIndex( unsigned int index );
842
843 /*! @function mapDeviceMemoryWithIndex
844 @abstract Maps a physical range of a device.
845 @discussion This method will create a mapping for the IODeviceMemory at the given index, with IODeviceMemory::map(options). The mapping is represented by the returned instance of IOMemoryMap, which should not be released until the mapping is no longer required.
846 @param index An index into the array of ranges assigned to the device.
847 @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. */
848
849 virtual IOMemoryMap * mapDeviceMemoryWithIndex( unsigned int index,
850 IOOptionBits options = 0 );
851
852 /*! @function getDeviceMemory
853 @abstract Returns the array of IODeviceMemory objects representing a device's memory mapped ranges.
854 @discussion This method will return an array of IODeviceMemory objects representing the physical memory ranges allocated to a memory mapped device.
855 @result An OSArray of IODeviceMemory objects, or zero if none are available. The array is retained by the provider, so is valid while attached. */
856
857 virtual OSArray * getDeviceMemory( void );
858
859 /*! @function setDeviceMemory
860 @abstract Sets the array of IODeviceMemory objects representing a device's memory mapped ranges.
861 @discussion This method will set an array of IODeviceMemory objects representing the physical memory ranges allocated to a memory mapped device.
862 @param array An OSArray of IODeviceMemory objects, or zero if none are available. The array will be retained by the object. */
863
864 virtual void setDeviceMemory( OSArray * array );
865
866 /* Interrupt accessors */
867
868 /*! @function registerInterrupt
869 @abstract Register a C-function interrupt handler for a device supplying interrupts.
870 @discussion This method will install 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 an IOWorkLoop based abstraction for interrupt delivery that may be more appropriate for work loop based drivers.
871 @param source The index of the interrupt source in the device.
872 @param target An object instance to be passed to the interrupt handler.
873 @param handler The C-function to be 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.
874 @param refCon A reference constant for the handler's use.
875 @result An IOReturn code.<br>kIOReturnNoInterrupt is returned if the source is not valid.<br>kIOReturnNoResources is returned if the interrupt already has an installed handler. */
876
877 virtual IOReturn registerInterrupt(int source, OSObject *target,
878 IOInterruptAction handler,
879 void *refCon = 0);
880
881 /*! @function unregisterInterrupt
882 @abstract Remove a C-function interrupt handler for a device supplying hardware interrupts.
883 @discussion This method will remove a C-function interrupt handler previously installed with registerInterrupt.
884 @param source The index of the interrupt source in the device.
885 @result An IOReturn code.<br>kIOReturnNoInterrupt is returned if the source is not valid. */
886
887 virtual IOReturn unregisterInterrupt(int source);
888
889 /*! @function getInterruptType
890 @abstract Return the type of interrupt used for a device supplying hardware interrupts.
891 @discussion This method will return the type of interrupt used by the device.
892 @param source The index of the interrupt source in the device.
893 @param interruptType The interrupt type for the interrupt source will be stored here by getInterruptType.<br> kIOInterruptTypeEdge will be returned for edge trigggered sources.<br> kIOInterruptTypeLevel will be returned for level trigggered sources.
894 @result An IOReturn code.<br>kIOReturnNoInterrupt is returned if the source is not valid. */
895
896 virtual IOReturn getInterruptType(int source, int *interruptType);
897
898 /*! @function enableInterrupt
899 @abstract Enable a device interrupt.
900 @discussion Enable a device interrupt. It is the callers responsiblity to keep track of the enable state of the interrupt source.
901 @param source The index of the interrupt source in the device.
902 @result An IOReturn code.<br>kIOReturnNoInterrupt is returned if the source is not valid. */
903
904 virtual IOReturn enableInterrupt(int source);
905
906 /*! @function disableInterrupt
907 @abstract Disable a device interrupt.
908 @discussion Disable a device interrupt. It is the callers responsiblity to keep track of the enable state of the interrupt source.
909 @param source The index of the interrupt source in the device.
910 @result An IOReturn code.<br>kIOReturnNoInterrupt is returned if the source is not valid. */
911
912 virtual IOReturn disableInterrupt(int source);
913
914 /*! @function causeInterrupt
915 @abstract Cause a device interrupt to occur.
916 @discussion Emulate a hardware interrupt, to be called from task level.
917 @param source The index of the interrupt source in the device.
918 @result An IOReturn code.<br>kIOReturnNoInterrupt is returned if the source is not valid. */
919
920 virtual IOReturn causeInterrupt(int source);
921
922 /*! @function requestProbe
923 @abstract An external request that hardware be re-scanned for devices.
924 @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.
925 @param options Family defined options, not interpreted by IOService.
926 @result An IOReturn code. */
927
928 virtual IOReturn requestProbe( IOOptionBits options );
929
930 /* Generic API for non-data-path upstream calls */
931
932 /*! @function message
933 @abstract Receive a generic message delivered from an attached provider.
934 @discussion A provider may deliver messages via the message method to its clients informing them of state changes, for example kIOMessageServiceIsTerminated or kIOMessageServiceIsSuspended. Certain messages are defined by IOKit in IOMessage.h while others may family dependent. This method is implemented in the client to receive messages.
935 @param type A type defined in IOMessage.h or defined by the provider family.
936 @param provider The provider from which the message originates.
937 @param argument An argument defined by the provider family, not used by IOService.
938 @result An IOReturn code defined by the message type. */
939
940 virtual IOReturn message( UInt32 type, IOService * provider,
941 void * argument = 0 );
942
943 /*! @function messageClient
944 @abstract Send a generic message to an attached client.
945 @discussion A provider may deliver messages via the message method to its clients informing them of state changes, for example kIOMessageServiceIsTerminated or kIOMessageServiceIsSuspended. Certain messages are defined by IOKit in IOMessage.h while others may family dependent. This method may be called in the provider to send a message to the specified client, which may be useful for overrides.
946 @param type A type defined in IOMessage.h or defined by the provider family.
947 @param client A client of the IOService to send the message.
948 @param argument An argument defined by the provider family, not used by IOService.
949 @result The return code from the client message call. */
950
951 virtual IOReturn messageClient( UInt32 messageType, OSObject * client,
952 void * messageArgument = 0, vm_size_t argSize = 0 );
953
954 /*! @function messageClients
955 @abstract Send a generic message to all attached clients.
956 @discussion A provider may deliver messages via the message method to its clients informing them of state changes, for example kIOMessageServiceIsTerminated or kIOMessageServiceIsSuspended. Certain messages are defined by IOKit in IOMessage.h while others may family dependent. This method may be called in the provider to send a message to all the attached clients, via the messageClient method.
957 @param type A type defined in IOMessage.h or defined by the provider family.
958 @param argument An argument defined by the provider family, not used by IOService.
959 @result Any non-kIOReturnSuccess return codes returned by the clients, or kIOReturnSuccess if all return kIOReturnSuccess. */
960
961 virtual IOReturn messageClients( UInt32 type,
962 void * argument = 0, vm_size_t argSize = 0 );
963
964 virtual IONotifier * registerInterest( const OSSymbol * typeOfInterest,
965 IOServiceInterestHandler handler,
966 void * target, void * ref = 0 );
967
968 virtual void applyToProviders( IOServiceApplierFunction applier,
969 void * context );
970
971 virtual void applyToClients( IOServiceApplierFunction applier,
972 void * context );
973
974 virtual void applyToInterested( const OSSymbol * typeOfInterest,
975 OSObjectApplierFunction applier,
976 void * context );
977
978 virtual IOReturn acknowledgeNotification( IONotificationRef notification,
979 IOOptionBits response );
980
981 /* User client create */
982
983 /*! @function newUserClient
984 @abstract A request to create a connection for a non kernel client.
985 @discussion A non kernel client may request a connection be opened via the IOServiceOpen() library function, which will call this method in an IOService. The rules & capabilities of user level clients are family dependent, and use the functions of the IOUserClient class for support. IOService's implementation returns kIOReturnUnsupported, so any family supporting user clients must implement this method.
986 @param owningTask The mach task requesting the connection.
987 @param securityID A token representing the access level for the task.
988 @param type A constant specifying the type of connection to be created, specified by the caller of IOServiceOpen and interpreted only by the family.
989 @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.
990 @param properties A dictionary of additional properties for the connection.
991 @result A return code to be passed back to the caller of IOServiceOpen. */
992
993 virtual IOReturn newUserClient( task_t owningTask, void * securityID,
994 UInt32 type, OSDictionary * properties,
995 IOUserClient ** handler );
996
997 virtual IOReturn newUserClient( task_t owningTask, void * securityID,
998 UInt32 type, IOUserClient ** handler );
999
1000 /* Return code utilities */
1001
1002 /*! @function stringFromReturn
1003 @abstract A utility to supply a programmer friendly string from an IOReturn code.
1004 @discussion Strings are available for the standard return codes in IOReturn.h in IOService, while subclasses may implement this method to interpret family dependent return codes.
1005 @param rtn The IOReturn code.
1006 @result A pointer to a constant string, or zero if the return code is unknown. */
1007
1008 virtual const char * stringFromReturn( IOReturn rtn );
1009
1010 /*! @function errnoFromReturn
1011 @abstract A utility to translate an IOReturn code to a BSD errno.
1012 @discussion BSD defines its own return codes for its functions in sys/errno.h, and IOKit families may need to supply compliant results in BSD shims. Results are available for the standard return codes in IOReturn.h in IOService, while subclasses may implement this method to interpret family dependent return codes.
1013 @param rtn The IOReturn code.
1014 @result The BSD errno or EIO if unknown. */
1015
1016 virtual int errnoFromReturn( IOReturn rtn );
1017
1018 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1019 /* * * * * * * * * * * * Internals * * * * * * * * * * * */
1020 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
1021
1022 public:
1023 int _numInterruptSources;
1024 IOInterruptSource *_interruptSources;
1025
1026 static void initialize( void );
1027
1028 virtual bool serializeProperties( OSSerialize * s ) const;
1029
1030 static void setPlatform( IOPlatformExpert * platform);
1031
1032 static IOReturn catalogNewDrivers( OSOrderedSet * newTables );
1033
1034 static IOService * resources( void );
1035 virtual bool checkResources( void );
1036 virtual bool checkResource( OSObject * matching );
1037
1038 virtual void probeCandidates( OSOrderedSet * matches );
1039 virtual bool startCandidate( IOService * candidate );
1040 virtual IOService * getClientWithCategory( const OSSymbol * category );
1041
1042 virtual bool passiveMatch( OSDictionary * matching, bool changesOK = false);
1043
1044 virtual void startMatching( IOOptionBits options = 0 );
1045 virtual void doServiceMatch( IOOptionBits options );
1046 virtual void doServiceTerminate( IOOptionBits options );
1047
1048 static OSObject * getExistingServices( OSDictionary * matching,
1049 IOOptionBits inState, IOOptionBits options = 0 );
1050
1051 static IONotifier * setNotification(
1052 const OSSymbol * type, OSDictionary * matching,
1053 IOServiceNotificationHandler handler,
1054 void * target, void * ref,
1055 SInt32 priority = 0 );
1056
1057 static IONotifier * doInstallNotification(
1058 const OSSymbol * type, OSDictionary * matching,
1059 IOServiceNotificationHandler handler,
1060 void * target, void * ref,
1061 SInt32 priority, OSIterator ** existing );
1062
1063 static bool syncNotificationHandler( void * target, void * ref,
1064 IOService * newService );
1065
1066 virtual void deliverNotification( const OSSymbol * type,
1067 IOOptionBits orNewState, IOOptionBits andNewState );
1068
1069 bool invokeNotifer( class _IOServiceNotifier * notify );
1070
1071 virtual void unregisterAllInterest( void );
1072
1073 virtual IOReturn waitForState( UInt32 mask, UInt32 value,
1074 mach_timespec_t * timeout = 0 );
1075
1076 virtual IOReturn resolveInterrupt(IOService *nub, int source);
1077 virtual IOReturn lookupInterrupt(int source, bool resolve, IOInterruptController **interruptController);
1078
1079 /* power management */
1080
1081 /*! @function PMinit
1082 A power managment policy-maker for a device calls itself here to initialize its power management.
1083 PMinit allocates and initializes the power management instance variables, and it should be called before any
1084 access to those variables or the power management methods. */
1085 virtual void PMinit (void );
1086
1087 /*! @function PMstop
1088 A power managment policy-maker for a device calls itself here when it resigns its responsibilities as
1089 policy-maker. This typically happens when it is handing off the responsibility to another policy-maker,
1090 or when the device is removed from the system. The power managment variables don't exist after
1091 this call, and the power managment methods in the caller shouldn't be accessed. */
1092 virtual void PMstop ( void );
1093
1094 /*! @function joinPMtree
1095 A policy-maker calls its nub here when initializing, to be attached into
1096 the power management hierarchy. The default function is to call the
1097 platform expert, which knows how to do it. This method is overridden
1098 by a nub subclass which may either know how to do it, or may need
1099 to take other action.
1100
1101 This may be the only "power management" method used in a nub, meaning
1102 it may be called even if the nub is not initialized for power management.
1103
1104 Before the nub returns from this method, the caller will probably be called
1105 at "setPowerParent" and "setAggressiveness" and possibly at "addPowerChild" as it is
1106 added to me hierarchy. */
1107 virtual void joinPMtree ( IOService * driver );
1108
1109 /*! @function registerPowerDriver
1110 A driver calls a policy-maker here to volunteer to control power to the device.
1111 If the policy-maker accepts the volunteer, it adds the volunteer to its list of
1112 interested drivers, and it will call the volunteer at appropriate times to switch
1113 the power state of the device.
1114 @param controllingDriver
1115 This points to the calling driver.
1116 @param powerStates
1117 This is an array of power states which the driver can deal with. If this array
1118 is no less rich than one supplied by an earlier volunteer, then the policy-maker
1119 uses the calling driver as its power-controlling driver.
1120 @param numberOfStates
1121 The number of power states in the array. Power states are defined in
1122 pwr_mgt/IOPMpowerState.h.
1123 @result
1124 IOPMNoErr is returned. There are various error conditions possible which prevent
1125 the policy-maker from accepting the new power state array. These conditions
1126 are logged in the power managment event log, but not returned to the caller. */
1127 virtual IOReturn registerPowerDriver ( IOService* controllingDriver, IOPMPowerState* powerStates, unsigned long numberOfStates );
1128
1129 /*! @function registerInterestedDriver
1130 Some IOService calls a policy-maker here to register interest in the changing
1131 power state of its device.
1132 @param theDriver
1133 The policy-maker adds this pointer to the calling IOService to its list of
1134 interested drivers. It informs drivers on this list pre- and post-power change.
1135 @result
1136 The policy-maker returns flags describing the capability of the device in its
1137 current power state. The policy-maker does not interpret these flags or
1138 understand them; they come from the power state array, and are understood
1139 only by interested drivers and perhaps the power-controlling driver. If the
1140 current power state is not yet defined, zero is returned. This is the case when
1141 the policy-maker is not yet in the power domain hierarchy or when it doesn't
1142 have a power-controlling driver yet. */
1143 virtual IOPMPowerFlags registerInterestedDriver ( IOService* theDriver );
1144
1145 /*! @function deRegisterInterestedDriver
1146 An IOService which has previously registered with a policy-maker as an interested
1147 driver calls the policy-maker here to withdraw its interest. The policy-maker removes
1148 it from its list of interested drivers.
1149 @result
1150 These bits describe the capability of the device in its current power state. They are
1151 not understood by the policy-maker; they come from the capabilityFlags field of the
1152 current power state in the power state array. */
1153 virtual IOReturn deRegisterInterestedDriver ( IOService * theDriver );
1154
1155 /*! @function acknowledgePowerChange
1156 When a device is changing power state, its policy-maker informs interested
1157 parties before and after the change. Interested parties are those which
1158 have registered as interested drivers and also children of the policy-maker
1159 in the case that it is a power domain.
1160 When an object is so informed, it can return an indication that it is prepared
1161 for the change, or it can return an indication that it needs some time to
1162 prepare. In this case it will call this method in the policy-maker when it has
1163 prepared.
1164 @param theDriver
1165 This points to the calling driver. The policy-maker uses it to know if all
1166 interested parties have acknowledged the power state change.
1167 @result
1168 IOPMNoErr is returned. */
1169 virtual IOReturn acknowledgePowerChange ( IOService * whichDriver );
1170
1171 /*! @function acknowledgeSetPowerState
1172 When a policy-maker instructs its controlling driver to switch the state of
1173 the device, the driver can return an indication that the change is complete,
1174 or it can return an indication that it needs some time to make the change.
1175 In this case it will call this method in the policy-maker when it has made the
1176 power state change.
1177 @result
1178 IOPMNoErr is returned. */
1179 virtual IOReturn acknowledgeSetPowerState ( void );
1180
1181 /*! @function powerDomainWillChangeTo
1182 When a power domain changes state, it notifies its children, which
1183 are policy-makers, by calling them at this method. It calls here
1184 before it makes the change, and a called policy-maker can return
1185 IOPMAckImplied to indicate that it is prepared for the change,
1186 or it can return a non-zero number to indicate that it is not prepared
1187 but will prepare and then call the parent at acknowledgePowerChange.
1188
1189 To prepare for a lowering of the power domain, the policy-maker
1190 informs all its interested parties of any resulting change in its device,
1191 and when they have all acknowledged, it calls its controlling driver
1192 to switch the device to an appropriate power state for the imminent
1193 domain state. If any interested driver or the controlling driver does
1194 not acknowledge immediately, then the policy-maker also will not.
1195
1196 To prepare for a raising of the power domain, the policy-maker
1197 informs all its interested parties of any resulting change in its device.
1198 If any do not acknowledge immediately, then the policy-maker also will not.
1199 @param newPowerStateFlags
1200 These flags describe the character of power in the imminent domain state.
1201 They are not understood by the policy-maker. It asks the controlling
1202 driver to translate them into a state number within the power state array.
1203 (The policy-maker for the domain also doesn't understand the bits; they
1204 come from a outputPowerCharacter field of the power state array for
1205 the power domain.)
1206 @param whichParent
1207 This pointer identifies the calling parent. */
1208 IOReturn powerDomainWillChangeTo ( IOPMPowerFlags newPowerStateFlags, IOPowerConnection * whichParent );
1209
1210 /*! @function powerDomainDidChangeTo
1211 When a power domain changes state, it notifies its children, which
1212 are policy-makers, by calling them at this method. It calls here
1213 after the changed power of the power domain has settled at the
1214 new level. A called policy-maker can return
1215 IOPMAckImplied to indicate that it is prepared for the change,
1216 or it can return a non-zero number to indicate that it is not prepared
1217 but will prepare and then call the parent at acknowledgePowerChange.
1218
1219 To prepare for a lowered power domain, the policy-maker
1220 informs all its interested parties of the new power state of its device.
1221 If any do not acknowledge immediately, then the policy-maker also will not.
1222
1223 To prepare for a raised power domain, the policy-maker calls its controlling
1224 driver to switch the device to the appropriate power state for the new
1225 domain state. When that is accomplished, the policy-maker informs
1226 all its interested parties of the new power state. If any interested driver
1227 or the controlling driver does not acknowledge immediately, then the
1228 policy-maker also will not.
1229
1230 @param newPowerStateFlags
1231 These flags describe the character of power in the new domain state.
1232 They are not understood by the policy-maker. It asks the controlling
1233 driver to translate them into a state number within the power state array.
1234 (The policy-maker for the domain also doesn't understand the bits; they
1235 come from a outputPowerCharacter field of the power state array for
1236 the power domain.)
1237 @param whichParent
1238 This pointer identifies the calling parent. */
1239 IOReturn powerDomainDidChangeTo ( IOPMPowerFlags newPowerStateFlags, IOPowerConnection * whichParent );
1240
1241 /*! @function requestPowerDomainState
1242 The child of a power domain calls it parent here to request power of a certain
1243 character. It does this after lowering power in its own device which allows
1244 it to tolerate lower power in the domain, and it does this if it needs more
1245 power for its device than is currently available in the domain.
1246 @param desiredState
1247 These flags describe the power required for some state of the caller's device.
1248 They are not understood by either the child or the parent. They come from
1249 the power state array of the child (in the inputPowerRequirement field), and
1250 the parent compares them to bits in the outputPowerCharacter fields of its
1251 power state array.
1252 @param whichChild
1253 This points to the caller, so the power domain can know which child is requesting.
1254 @param specificationFlags
1255 This value modifies the parent's choice of power state.
1256 If the parameter is IOPMNextHigherState, the parent will choose the lowest state
1257 which matches desiredState and which is higher than the current state.
1258 If the parameter is IOPMHighestState , the parent will choose the highest state
1259 which matches desiredState.
1260 If the parameter is IOPMNextLowerState, the parent will choose the highest state
1261 which matches desiredState and which is lower than the current state.
1262 If the parameter is IOPMLowestState, the parent will choose the lowest state
1263 which matches desiredState.
1264 A state matches desiredState if all the bits set in desiredState are also set in the
1265 outputPowerCharacter field of that state in the parent's power state array.
1266 @result
1267 The power domain parent returns IOPMBadSpecification if specificationFlags
1268 not wellformed. It returns IOPMNoSuchState if no state in its array satisfies
1269 the callers specification. It returns IOPMNotYetInitialized if it has not power
1270 state array yet to compare with. Otherwise it returns IOPMNoErr. In the last
1271 case it will initiate its change to the new state if it has a parent in the hierarchy
1272 (or is the root power domain.) */
1273 virtual IOReturn requestPowerDomainState ( IOPMPowerFlags desiredState, IOPowerConnection * whichChild, unsigned long specificationFlags );
1274
1275 /*! @function makeUsable
1276 Some client of a device is asking that it become usable. Although
1277 this has not come from the policy-maker for the device, treat it exactly
1278 as if it had. In this way, subsequent requests for lower power from
1279 the policy-maker will pre-empt this request.
1280 We treat this as policy-maker request to switch to the highest power state.
1281 @result
1282 The return code reflects the state of the policy-maker's internal queue of power
1283 changes and can be ignored by the caller. */
1284 virtual IOReturn makeUsable ( void );
1285
1286 /*! @function temporaryPowerClampOn
1287 A power domain calls this method to hold itself in the highest power state until it
1288 has children, and at that point the domain state is controlled by the childrens'
1289 requirements.
1290 @result
1291 The return code reflects the state of the policy-maker's internal queue of power
1292 changes and can be ignored by the caller. */
1293 virtual IOReturn temporaryPowerClampOn ( void );
1294
1295 /*! @function changePowerStateTo
1296 The power-controlling driver calls the policy-maker here when it wants the device
1297 switched to a different power state. This is mildly ironic in that it is the controlling
1298 driver which does the switching, but it must do it this way so that the policy-maker
1299 can make sure the power domain is correct and to notify interested parties
1300 pre-change. When appropriate, the policy-maker will call the controlling driver and
1301 have it switch the device to the requested state in the usual way.
1302 This request by the controlling driver is sticky in that the policy-maker will not
1303 switch the device lower than this request, so if the driver needs power raised for
1304 some reason and then gets it and does what it needs, it should then rescind the
1305 request by requesting state zero. This will allow the policy-maker to control the
1306 device as usual.
1307 @param ordinal
1308 This is the number, in the power state array, of the desired power state.
1309 @result
1310 The return code reflects the state of the policy-maker's internal queue of power
1311 changes and can be ignored by the caller. */
1312 virtual IOReturn changePowerStateTo ( unsigned long ordinal );
1313
1314 /*! @function currentCapability
1315 Some object calls a policy-maker here to find out the current capability of a device.
1316 The policy-maker returns a copy of the capabilityFlags field for the current power
1317 state in the power state array. */
1318 virtual IOPMPowerFlags currentCapability ( void );
1319
1320 /*! @function currentPowerConsumption
1321 Some object calls a policy-maker here to find out the current power consumption of a device.
1322 The policy-maker returns a copy of the staticPower field for the current power state in the
1323 power state array. */
1324 virtual unsigned long currentPowerConsumption ( void );
1325
1326 /*! @function activityTickle
1327 A principal function of a policy-maker is deciding when the device is idle and can be
1328 powered down. To do this it needs to know when the device is being used. In some
1329 cases it is in the data path to the device so it knows when it is being used. In others
1330 it is not and must be told. The activityTickle method is provided for objects in the
1331 system to tell a policy-maker that its device is being used.
1332
1333 If the policy-maker is managing the idleness determination totally on its own, the
1334 paramter should be kIOPMSubclassPolicy, and the policy-maker should intercept
1335 the activityTickle call, because the superclass will do nothing with it.
1336
1337 The IOService superclass can manage idleness determination, too, with the simple
1338 mechanism of an idle timer and this activityTickle call. To start this up, the policy-
1339 maker calls its superclass at setIdleTimerPeriod. This starts a timer for the time
1340 interval specified in the call. When the timer expires, the superclass checks to see
1341 if there has been any activity since the last timer expiration. (It checks to see if
1342 activityTickle has been called). If there has been activity, it restarts the timer, and
1343 this process continues. When the timer expires, and there has been no device
1344 activity, the superclass lowers the device power state to the next lower state.
1345 This can continue until the device is in state zero.
1346
1347 After the device has been powered down by at least one power state,
1348 a call to activityTickle will cause the device to be switched to a higher state
1349 required for the activity.
1350
1351 activityTickle in the IOService superclass is meant to be called by sub-classed
1352 policy-makers, because only they understand the paramters. They may implement
1353 an activityTickle for their clients and then call this activityTickle in the superclass.
1354 @param type
1355 activityTickle with parameter kIOPMSubclassPolicy is not handled in IOService
1356 and should be intercepted by the subclass policy-maker.
1357 activityTickle with parameter kIOPMSuperclassPolicy1 causes an activity flag to be set,
1358 and the device state checked. If the device has been powered down, it is powered up again.
1359 @param stateNumber
1360 When the type parameter is kIOPMSuperclassPolicy1, the stateNumber contains
1361 the desired power state ordinal for the activity. If the device is in a lower state,
1362 the superclass will switch it to this state. This is for devices which can handle
1363 some accesses in lower power states than others; the device is powered up only
1364 as far as it needs to be for the activity.
1365 @result
1366 When the type parameter is kIOPMSuperclassPolicy1, the superclass returns true
1367 if the device is currently in the state specified by stateNumber. If it is in a lower
1368 state and must be brought up, it returns false. In this case the superclass will
1369 cause the device to be brought up. */
1370 virtual bool activityTickle ( unsigned long type, unsigned long stateNumber=0 );
1371
1372 /*! @function setAggressiveness
1373 The parent of a policy-maker calls it here while broadcasting an aggressiveness factor
1374 around the power management hierarchy.
1375
1376 A policy-maker may want to intercept this call if it needs to do something with the
1377 new factor, like change its idle timeout, for example. A policy-maker which does
1378 intercept should call setAggressiveness in its superclass, though.
1379 @param type
1380 There are several aggressiveness factors which can be broadcast. One is a general
1381 aggressiveness factor, and the others are specific to parts of the system, like the
1382 hard drive or the display. A policy-maker takes action only on a factor that applies
1383 to its policy. These factor types (e.g. kPMSetGeneralAggressiveness) are defined
1384 in pwr_mgt/IOPM.h.
1385 @param newLevel
1386 This is the aggressiveness factor's new value.
1387 @result
1388 setAggressiveness returns IOPMNoErr. */
1389 virtual IOReturn setAggressiveness ( unsigned long, unsigned long newLevel );
1390
1391 /*! @function getAggressiveness
1392 Return the current aggressiveness value for the given type.
1393 */
1394 virtual IOReturn getAggressiveness ( unsigned long, unsigned long * );
1395
1396 /*! @function systemWake
1397 The parent of a policy-maker calls it here while broadcasting a system wake event.
1398
1399 A policy-maker must intercept this call if its device can wake the system from sleep.
1400 It should check to see if its device did in fact wake the system, and if so, treat the
1401 waking action as activity: it should request power from its parent to keep the system
1402 up until it idles again.
1403
1404 A policy-maker which does intercept should call systemWake in its superclass.
1405 @result
1406 systemWake returns IOPMNoErr. */
1407 virtual IOReturn systemWake ( void );
1408
1409 /*! @function temperatureCriticalForZone
1410 A policy-maker calls its parent power domain to alert it to critical temperature in
1411 some thermal zone.
1412 @param whichZone
1413 This is a pointer to the IOService policy-maker for the thermal zone which has
1414 reported critical temperature.
1415 @result
1416 temperatureCriticalForZone returns IOPMNoErr. */
1417 virtual IOReturn temperatureCriticalForZone ( IOService * whichZone );
1418
1419 /*! @function youAreRoot
1420 The Platform Expert instantiates the root power domain IOService and
1421 calls it here to inform it that it is the root power domain.
1422 (The only difference between the root domain and any other power domain
1423 is that the root has no parent and therefore never calls it. */
1424 virtual IOReturn youAreRoot ( void );
1425
1426 /*! @function setPowerParent
1427 The Platform Expert or some other IOService calls a policy-maker here to
1428 inform it who its parent is in the power management hierarchy. This is
1429 part of the process of attaching a policy-maker into the hierarchy.
1430 @param theParent
1431 This is a pointer to the parent IOService power domain.
1432 @param stateKnown
1433 This is true if the parent knows its power state. (It would not if it doesn't yet
1434 have a parent or a controlling driver)
1435 @param currentState
1436 If the stateKnown parameter is true, these flags describe the character of
1437 power in the power domain. If the policy-maker has a controlling driver,
1438 the policy-maker asks the driver, given this power domain state,
1439 what state it would be in, and then it tells the driver to assume that state. */
1440 virtual IOReturn setPowerParent ( IOPowerConnection * theParent, bool stateKnown, IOPMPowerFlags currentState );
1441
1442 /*! @function addPowerChild
1443 The Platform Expert or some other IOService calls a power domain policy-maker
1444 here to introduce it to a child of it, a member of the domain.
1445 @param theChild
1446 This is a pointer to the child IOService, which is another power domain policy-maker
1447 or a device policy-maker. */
1448 virtual IOReturn addPowerChild ( IOService * theChild );
1449
1450 /*! @function removePowerChild
1451 A power domain policy-maker is called here to tell it that one of its enclosed members
1452 is disappearing. This happens when a device policy-maker hands off its responsibility
1453 to another policy-maker or when its device disappears. */
1454 virtual IOReturn removePowerChild ( IOPowerConnection * theChild );
1455
1456 /* @function command_received
1457 */
1458 virtual void command_received ( void *, void * , void * , void *);
1459
1460 /* @function start_PM_idle_timer
1461 */
1462 virtual void start_PM_idle_timer ( void );
1463
1464 /* @function PM_idle_timer_expiration
1465 */
1466 virtual void PM_idle_timer_expiration ( void );
1467
1468 /* @function PM_Clamp_Timer_Expired
1469 */
1470 virtual void PM_Clamp_Timer_Expired (void);
1471
1472 /*! @function setIdleTimerPeriod
1473 A policy-maker which uses the type 1 idleness determination provided by IOService
1474 calls its superclass here to set or change the idle timer period.
1475
1476 See activityTickle for a description of this idleness determination.
1477 @param period
1478 This is the desired idle timer period in seconds.
1479 @result
1480 The normal return is IOPMNoErr, but it is possible to return kIOReturnError if there
1481 was difficulty creating the timer event or the command queue, for example (which is
1482 done only on the first call.) */
1483 virtual IOReturn setIdleTimerPeriod ( unsigned long );
1484
1485 /*! @function getPMworkloop
1486 */
1487 virtual IOWorkLoop *getPMworkloop ( void );
1488
1489 /* @function ack_timer_ticked
1490 */
1491 void ack_timer_ticked ( void );
1492
1493 /* @function settleTimerExpired
1494 */
1495 void settleTimerExpired ( void );
1496
1497 IOReturn serializedAllowPowerChange2 ( unsigned long );
1498 IOReturn serializedCancelPowerChange2 ( unsigned long );
1499
1500 // implemented by power-controlling driver...
1501
1502 /*! @function setPowerState
1503 A policy-maker (usually its superclass) calls its controlling driver here to change
1504 the power state of its device.
1505 @param powerStateOrdinal
1506 This is the number in the power state array of the state the driver is being
1507 instructed to switch to.
1508 @param whatDevice
1509 This is a pointer to the policy-maker. It is useful when a single power-controlling
1510 driver controls multiple devices and needs to know for which device it is being
1511 called.
1512 @result
1513 The driver returns IOPMAckImplied if it has complied with the request when it
1514 returns. If it has started the process of changing power state but not finished
1515 it, it should return a number of microseconds which is an upper limit of the time
1516 it will need to finish. Then, when it has completed the power switch, it should
1517 call acknowledgeSetPowerState in the policy-maker. */
1518 virtual IOReturn setPowerState ( unsigned long powerStateOrdinal, IOService* whatDevice );
1519
1520 /*! @function clampPowerOn
1521 This method sets the device to the highest power state and ensures it stays there
1522 until a timer of duration length expires.
1523 */
1524 virtual void clampPowerOn (unsigned long duration);
1525
1526 /*! @function maxCapabilityForDomainState
1527 A policy-maker (usually its superclass) calls its controlling driver here to find out
1528 the highest power state possible for a given power domain state. This happens
1529 when the power domain is changing state and the policy-maker wants to find
1530 out what states the device is capable of in the new domain state.
1531 @param domainState
1532 These flags describe the character of domain power in some domain power state.
1533 The flags are not understood by the calling policy-maker; they were passed to it
1534 by its power domain parent. They come from the outputPowerCharacter field
1535 of a state in the power domain's power state array.
1536
1537 This method is implemented in a simple way in IOService. It scans the power state
1538 array looking for the highest state whose inputPowerRequirement field exactly
1539 matches the parameter. If more intelligent determination is required, the
1540 power-controlling driver should implement the method and override the superclass.
1541 @result
1542 A state number is returned. */
1543 virtual unsigned long maxCapabilityForDomainState ( IOPMPowerFlags domainState );
1544
1545 /*! @function initialPowerStateForDomainState
1546 A policy-maker (usually its superclass) calls its controlling driver here to find out
1547 which power state the device is in, given the current power domain state. This
1548 happens once, when the policy-maker is initializing, and the controlling driver
1549 can use this to know what state the device is in initially.
1550 @param domainState
1551 These flags describe the character of domain power in the current state of the
1552 power domain. The flags are not understood by the calling policy-maker; they
1553 were passed to it by its power domain parent. They come from the
1554 outputPowerCharacter field of the current power state in the power domain's
1555 power state array.
1556
1557 This method is implemented in a simple way in IOService. It scans the power state
1558 array looking for the highest state whose inputPowerRequirement field exactly
1559 matches the parameter. If more intelligent determination is required, the
1560 power-controlling driver should implement the method and override the superclass.
1561 @result
1562 A state number is returned. */
1563 virtual unsigned long initialPowerStateForDomainState ( IOPMPowerFlags );
1564
1565 /*! @function powerStateForDomainState
1566 A policy-maker (usually its superclass) calls its controlling driver here to find out
1567 what power state the device would be in for a given power domain state. This
1568 happens when the power domain is changing state and the policy-maker wants
1569 to find out the effect of the change.
1570 @param domainState
1571 These flags describe the character of domain power in some domain power state.
1572 The flags are not understood by the calling policy-maker; they were passed to it
1573 by its power domain parent. They come from the outputPowerCharacter field
1574 of a state in the power domain's power state array.
1575
1576 This method is implemented in a simple way in IOService. It scans the power state
1577 array looking for the highest state whose inputPowerRequirement field exactly
1578 matches the parameter. If more intelligent determination is required, the
1579 power-controlling driver should implement the method and override the superclass.
1580 @result
1581 A state number is returned. */
1582 virtual unsigned long powerStateForDomainState ( IOPMPowerFlags domainState );
1583
1584 /*! @function powerStateWillChangeTo
1585 A policy-maker informs interested parties that its device is about to change to
1586 a different power state. Interested parties are those that have registered for
1587 this notification via registerInterestedDriver and also the power-controlling
1588 driver which is registered as an interested driver automatically when it registers
1589 as the controlling driver.
1590 @param capabilities
1591 These flags describe the capability of the device in the new power state. They
1592 are not understood by the policy-maker; they come from the capabilityFlags field
1593 of the new state in the power state array.
1594 @param stateNumber
1595 This is the number of the state in the state array that the device is switching to.
1596 @param whatDevice
1597 This points to the policy-maker, and it is used by a driver which is receiving power
1598 state change notifications for multiple devices.
1599 @result
1600 The driver returns IOPMAckImplied if it has prepared for the power change when it
1601 returns. If it has started preparing but not finished, it should return a number of
1602 microseconds which is an upper limit of the time it will need to finish preparing.
1603 Then, when it has completed its preparations, it should call acknowledgePowerChange
1604 in the policy-maker. */
1605 virtual IOReturn powerStateWillChangeTo ( IOPMPowerFlags, unsigned long, IOService* );
1606
1607 /*! @function powerStateDidChangeTo
1608 A policy-maker informs interested parties that its device has changed to
1609 a different power state. Interested parties are those that have registered for
1610 this notification via registerInterestedDriver and also the power-controlling
1611 driver which is registered as an interested driver automatically when it registers
1612 as the controlling driver.
1613 @param capabilities
1614 These flags describe the capability of the device in the new power state. They
1615 are not understood by the policy-maker; they come from the capabilityFlags field
1616 of the new state in the power state array.
1617 @param stateNumber
1618 This is the number of the state in the state array that the device has switched to.
1619 @param whatDevice
1620 This points to the policy-maker, and it is used by a driver which is receiving power
1621 state change notifications for multiple devices.
1622 @result
1623 The driver returns IOPMAckImplied if it has prepared for the power change when it
1624 returns. If it has started preparing but not finished, it should return a number of
1625 microseconds which is an upper limit of the time it will need to finish preparing.
1626 Then, when it has completed its preparations, it should call acknowledgePowerChange
1627 in the policy-maker. */
1628 virtual IOReturn powerStateDidChangeTo ( IOPMPowerFlags, unsigned long, IOService* );
1629
1630 /*! @function didYouWakeSystem
1631 A policy-maker calls its power driver here to ask if its device is the one
1632 which just woke the system from sleep.
1633 @result
1634 The driver returns true if it did wake the system and false if it didn't. */
1635 virtual bool didYouWakeSystem ( void );
1636
1637 /*! @function newTemperature
1638 A thermal-zone driver calls its policy-maker here to tell it that the temperature in
1639 the zone has changed. The thermal-zone policy-maker uses this information to
1640 manage its thermal zone.
1641 @param currentTemp
1642 This is the new temperature in the thermal zone.
1643 @param whichZone
1644 This is a pointer to the controlling driver.
1645 */
1646 virtual IOReturn newTemperature ( long currentTemp, IOService * whichZone );
1647
1648 virtual bool askChangeDown ( unsigned long );
1649 virtual bool tellChangeDown ( unsigned long );
1650 virtual void tellNoChangeDown ( unsigned long );
1651 virtual void tellChangeUp ( unsigned long );
1652 virtual IOReturn allowPowerChange ( unsigned long refcon );
1653 virtual IOReturn cancelPowerChange ( unsigned long refcon );
1654
1655 // ...implemented by power-controlling driver
1656
1657 protected:
1658 /*! @function changePowerStateToPriv
1659 A policy-maker calls its superclass here to change the power state of the device.
1660 The superclass takes care of making sure the power domain state is appropriate
1661 and informing interested parties. It calls the controlling driver to make the change.
1662 @param ordinal
1663 This is the number, in the power state array, of the desired power state.
1664 @result
1665 The return code reflects the state of the policy-maker's internal queue of power
1666 changes and can be ignored by the caller.
1667 */
1668 IOReturn changePowerStateToPriv ( unsigned long ordinal );
1669
1670 /*! @function powerOverrideOnPriv
1671 A policy-maker normally keeps its device at the highest state required by itself,
1672 its power-controlling driver, and its children (when the power domain state
1673 allows). There may be times, however, when a policy-maker needs the power
1674 state lower than its driver or its children desire, and when this is the case, it
1675 calls powerOverrideOnPriv in its superclass to enable this override. When the override
1676 is on, the superclass keeps the device in the state desired by the policy-maker
1677 (requested via changePowerStateToPriv), regardless of the children's or driver's desire.
1678 Turning on the override will initiate a power change if the policy-maker's desired
1679 power state is different from the maximum of the controlling driver's desire and
1680 the children's desires.
1681 @result
1682 The return code reflects the state of the policy-maker's internal queue of power
1683 changes and can be ignored by the caller. */
1684 IOReturn powerOverrideOnPriv ( void );
1685
1686 /*! @function powerOverrideOffPriv
1687 When a policy-maker has enabled the override, it can disable it again by calling
1688 this method in its superclass. This will allow the superclass to keep the device
1689 at the highest state required by itself, its power-controlling driver, and its
1690 children (when the power domain state allows). Turning off the override
1691 will initiate a power change if the policy-maker's desired power state is different
1692 from the maximum of the controlling driver's desire and the children's desires.
1693 @result
1694 The return code reflects the state of the policy-maker's internal queue of power
1695 changes and can be ignored by the caller. */
1696 IOReturn powerOverrideOffPriv ( void );
1697
1698 /*! @function powerChangeDone
1699 A policy-maker calls itself here when a power change is completely done, when
1700 all interested parties have acknowledged the powerStateDidChangeTo call.
1701 The implementation here is null; the method is meant to be overridden by
1702 subclassed policy-makers, and that is how one finds out that a power change
1703 it initiated is complete
1704 @param stateNumber
1705 This is the number of the state in the state array that the device has switched to. */
1706 virtual void powerChangeDone ( unsigned long );
1707
1708 bool tellClientsWithResponse ( int messageType );
1709 void tellClients ( int messageType );
1710
1711 private:
1712
1713 IOReturn enqueuePowerChange ( unsigned long, unsigned long, unsigned long, IOPowerConnection * );
1714 IOReturn notifyAll ( bool is_prechange );
1715 bool notifyChild ( IOPowerConnection * nextObject, bool is_prechange );
1716 bool inform ( IOPMinformee * nextObject, bool is_prechange );
1717 void our_prechange_03 ( void );
1718 void our_prechange_05 ( void );
1719 void our_prechange_1 ( void );
1720 void our_prechange_2 ( void );
1721 void our_prechange_3 ( void );
1722 void our_prechange_4 ( void );
1723 IOReturn parent_down_0 ( void );
1724 void parent_down_05 ( void );
1725 IOReturn parent_down_1 ( void );
1726 IOReturn parent_down_2 ( void );
1727 void parent_down_3 ( void );
1728 void parent_down_4 ( void );
1729 void parent_down_5 ( void );
1730 void parent_down_6 ( void );
1731 void parent_up_0 ( void );
1732 IOReturn parent_up_1 ( void );
1733 IOReturn parent_up_2 ( void );
1734 IOReturn parent_up_3 ( void );
1735 void parent_up_4 ( void );
1736 void parent_up_5 ( void );
1737 void parent_up_6 ( void );
1738 void all_done ( void );
1739 void all_acked ( void );
1740 void driver_acked ( void );
1741 void start_ack_timer ( void );
1742 void stop_ack_timer ( void );
1743 unsigned long compute_settle_time ( void );
1744 IOReturn startSettleTimer ( unsigned long delay );
1745 IOReturn changeState ( void );
1746 IOReturn add_child_to_active_change ( IOPowerConnection * );
1747 IOReturn add_driver_to_active_change ( IOPMinformee * );
1748 IOReturn instruct_driver ( unsigned long newState );
1749 bool acquire_lock ( void );
1750 IOReturn start_parent_change ( unsigned long queue_head );
1751 void start_our_change ( unsigned long queue_head );
1752 IOReturn ask_parent ( unsigned long requestedState );
1753 bool checkForDone ( void );
1754 bool responseValid ( unsigned long x );
1755 IOReturn allowCancelCommon ( void );
1756 };
1757
1758 #endif /* ! _IOKIT_IOSERVICE_H */