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