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