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