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