1/* 2 * Copyright (c) 1998-2011 Apple Computer, Inc. All rights reserved. 3 * 4 * @APPLE_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. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23/* 24 * HISTORY 25 * 26 */ 27 28/* 29 * IOKit user library 30 */ 31 32#ifndef _IOKIT_IOKITLIB_H 33#define _IOKIT_IOKITLIB_H 34 35#ifdef KERNEL 36#error This file is not for kernel use 37#endif 38 39#include <sys/cdefs.h> 40#include <sys/types.h> 41 42#include <mach/mach_types.h> 43#include <mach/mach_init.h> 44 45#include <CoreFoundation/CFBase.h> 46#include <CoreFoundation/CFDictionary.h> 47#include <CoreFoundation/CFRunLoop.h> 48 49#include <IOKit/IOTypes.h> 50#include <IOKit/IOKitKeys.h> 51 52#include <IOKit/OSMessageNotification.h> 53 54#include <AvailabilityMacros.h> 55 56#include <dispatch/dispatch.h> 57 58__BEGIN_DECLS 59 60/*! @header IOKitLib 61IOKitLib implements non-kernel task access to common IOKit object types - IORegistryEntry, IOService, IOIterator etc. These functions are generic - families may provide API that is more specific.<br> 62IOKitLib represents IOKit objects outside the kernel with the types io_object_t, io_registry_entry_t, io_service_t, & io_connect_t. Function names usually begin with the type of object they are compatible with - eg. IOObjectRelease can be used with any io_object_t. Inside the kernel, the c++ class hierarchy allows the subclasses of each object type to receive the same requests from user level clients, for example in the kernel, IOService is a subclass of IORegistryEntry, which means any of the IORegistryEntryXXX functions in IOKitLib may be used with io_service_t's as well as io_registry_t's. There are functions available to introspect the class of the kernel object which any io_object_t et al. represents. 63IOKit objects returned by all functions should be released with IOObjectRelease. 64*/ 65/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 66 67typedef struct IONotificationPort * IONotificationPortRef; 68 69 70/*! @typedef IOServiceMatchingCallback 71 @abstract Callback function to be notified of IOService publication. 72 @param refcon The refcon passed when the notification was installed. 73 @param iterator The notification iterator which now has new objects. 74*/ 75typedef void 76(*IOServiceMatchingCallback)( 77 void * refcon, 78 io_iterator_t iterator ); 79 80/*! @typedef IOServiceInterestCallback 81 @abstract Callback function to be notified of changes in state of an IOService. 82 @param refcon The refcon passed when the notification was installed. 83 @param service The IOService whose state has changed. 84 @param messageType A messageType enum, defined by IOKit/IOMessage.h or by the IOService's family. 85 @param messageArgument An argument for the message, dependent on the messageType. If the message data is larger than sizeof(void*), then messageArgument contains a pointer to the message data; otherwise, messageArgument contains the message data. 86*/ 87 88typedef void 89(*IOServiceInterestCallback)( 90 void * refcon, 91 io_service_t service, 92 uint32_t messageType, 93 void * messageArgument ); 94 95/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 96 97/*! @const kIOMasterPortDefault 98 @abstract The default mach port used to initiate communication with IOKit. 99 @discussion When specifying a master port to IOKit functions, the NULL argument indicates "use the default". This is a synonym for NULL, if you'd rather use a named constant. 100*/ 101 102extern 103const mach_port_t kIOMasterPortDefault; 104 105/*! @function IOMasterPort 106 @abstract Returns the mach port used to initiate communication with IOKit. 107 @discussion Functions that don't specify an existing object require the IOKit master port to be passed. This function obtains that port. 108 @param bootstrapPort Pass MACH_PORT_NULL for the default. 109 @param masterPort The master port is returned. 110 @result A kern_return_t error code. */ 111 112kern_return_t 113IOMasterPort( mach_port_t bootstrapPort, 114 mach_port_t * masterPort ); 115 116 117/*! @function IONotificationPortCreate 118 @abstract Creates and returns a notification object for receiving IOKit notifications of new devices or state changes. 119 @discussion Creates the notification object to receive notifications from IOKit of new device arrivals or state changes. The notification object can be supply a CFRunLoopSource, or mach_port_t to be used to listen for events. 120 @param masterPort The master port obtained from IOMasterPort(). Pass kIOMasterPortDefault to look up the default master port. 121 @result A reference to the notification object. */ 122 123IONotificationPortRef 124IONotificationPortCreate( 125 mach_port_t masterPort ); 126 127/*! @function IONotificationPortDestroy 128 @abstract Destroys a notification object created with IONotificationPortCreate. 129 Also destroys any mach_port's or CFRunLoopSources obatined from 130 <code>@link IONotificationPortGetRunLoopSource @/link</code> 131 or <code>@link IONotificationPortGetMachPort @/link</code> 132 @param notify A reference to the notification object. */ 133 134void 135IONotificationPortDestroy( 136 IONotificationPortRef notify ); 137 138/*! @function IONotificationPortGetRunLoopSource 139 @abstract Returns a CFRunLoopSource to be used to listen for notifications. 140 @discussion A notification object may deliver notifications to a CFRunLoop 141 by adding the run loop source returned by this function to the run loop. 142 143 The caller should not release this CFRunLoopSource. Just call 144 <code>@link IONotificationPortDestroy @/link</code> to dispose of the 145 IONotificationPortRef and the CFRunLoopSource when done. 146 @param notify The notification object. 147 @result A CFRunLoopSourceRef for the notification object. */ 148 149CFRunLoopSourceRef 150IONotificationPortGetRunLoopSource( 151 IONotificationPortRef notify ); 152 153/*! @function IONotificationPortGetMachPort 154 @abstract Returns a mach_port to be used to listen for notifications. 155 @discussion A notification object may deliver notifications to a mach messaging client 156 if they listen for messages on the port obtained from this function. 157 Callbacks associated with the notifications may be delivered by calling 158 IODispatchCalloutFromMessage with messages received. 159 160 The caller should not release this mach_port_t. Just call 161 <code>@link IONotificationPortDestroy @/link</code> to dispose of the 162 mach_port_t and IONotificationPortRef when done. 163 @param notify The notification object. 164 @result A mach_port for the notification object. */ 165 166mach_port_t 167IONotificationPortGetMachPort( 168 IONotificationPortRef notify ); 169 170/*! @function IONotificationPortSetDispatchQueue 171 @abstract Sets a dispatch queue to be used to listen for notifications. 172 @discussion A notification object may deliver notifications to a dispatch client. 173 @param notify The notification object. 174 @param queue A dispatch queue. */ 175 176void 177IONotificationPortSetDispatchQueue( 178 IONotificationPortRef notify, dispatch_queue_t queue ) 179__OSX_AVAILABLE_STARTING(__MAC_10_6, __IPHONE_4_3); 180 181/*! @function IODispatchCalloutFromMessage 182 @abstract Dispatches callback notifications from a mach message. 183 @discussion A notification object may deliver notifications to a mach messaging client, 184 which should call this function to generate the callbacks associated with the notifications arriving on the port. 185 @param unused Not used, set to zero. 186 @param msg A pointer to the message received. 187 @param reference Pass the IONotificationPortRef for the object. */ 188 189void 190IODispatchCalloutFromMessage( 191 void *unused, 192 mach_msg_header_t *msg, 193 void *reference ); 194 195/*! @function IOCreateReceivePort 196 @abstract Creates and returns a mach port suitable for receiving IOKit messages of the specified type. 197 @discussion In the future IOKit may use specialized messages and ports 198 instead of the standard ports created by mach_port_allocate(). Use this 199 function instead of mach_port_allocate() to ensure compatibility with future 200 revisions of IOKit. 201 @param msgType Type of message to be sent to this port 202 (kOSNotificationMessageID or kOSAsyncCompleteMessageID) 203 @param recvPort The created port is returned. 204 @result A kern_return_t error code. */ 205 206kern_return_t 207IOCreateReceivePort( uint32_t msgType, mach_port_t * recvPort ); 208 209/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 210 211/* 212 * IOObject 213 */ 214 215/*! @function IOObjectRelease 216 @abstract Releases an object handle previously returned by IOKitLib. 217 @discussion All objects returned by IOKitLib should be released with this function when access to them is no longer needed. Using the object after it has been released may or may not return an error, depending on how many references the task has to the same object in the kernel. 218 @param object The IOKit object to release. 219 @result A kern_return_t error code. */ 220 221kern_return_t 222IOObjectRelease( 223 io_object_t object ); 224 225/*! @function IOObjectRetain 226 @abstract Retains an object handle previously returned by IOKitLib. 227 @discussion Gives the caller an additional reference to an existing object handle previously returned by IOKitLib. 228 @param object The IOKit object to retain. 229 @result A kern_return_t error code. */ 230 231kern_return_t 232IOObjectRetain( 233 io_object_t object ); 234 235/*! @function IOObjectGetClass 236 @abstract Return the class name of an IOKit object. 237 @discussion This function uses the OSMetaClass system in the kernel to derive the name of the class the object is an instance of. 238 @param object The IOKit object. 239 @param className Caller allocated buffer to receive the name string. 240 @result A kern_return_t error code. */ 241 242kern_return_t 243IOObjectGetClass( 244 io_object_t object, 245 io_name_t className ); 246 247/*! @function IOObjectCopyClass 248 @abstract Return the class name of an IOKit object. 249 @discussion This function does the same thing as IOObjectGetClass, but returns the result as a CFStringRef. 250 @param object The IOKit object. 251 @result The resulting CFStringRef. This should be released by the caller. If a valid object is not passed in, then NULL is returned.*/ 252 253CFStringRef 254IOObjectCopyClass(io_object_t object) 255AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; 256 257/*! @function IOObjectCopySuperclassForClass 258 @abstract Return the superclass name of the given class. 259 @discussion This function uses the OSMetaClass system in the kernel to derive the name of the superclass of the class. 260 @param classname The name of the class as a CFString. 261 @result The resulting CFStringRef. This should be released by the caller. If there is no superclass, or a valid class name is not passed in, then NULL is returned.*/ 262 263CFStringRef 264IOObjectCopySuperclassForClass(CFStringRef classname) 265AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; 266 267/*! @function IOObjectCopyBundleIdentifierForClass 268 @abstract Return the bundle identifier of the given class. 269 @discussion This function uses the OSMetaClass system in the kernel to derive the name of the kmod, which is the same as the bundle identifier. 270 @param classname The name of the class as a CFString. 271 @result The resulting CFStringRef. This should be released by the caller. If a valid class name is not passed in, then NULL is returned.*/ 272 273CFStringRef 274IOObjectCopyBundleIdentifierForClass(CFStringRef classname) 275AVAILABLE_MAC_OS_X_VERSION_10_4_AND_LATER; 276 277/*! @function IOObjectConformsTo 278 @abstract Performs an OSDynamicCast operation on an IOKit object. 279 @discussion This function uses the OSMetaClass system in the kernel to determine if the object will dynamic cast to a class, specified as a C-string. In other words, if the object is of that class or a subclass. 280 @param object An IOKit object. 281 @param className The name of the class, as a C-string. 282 @result If the object handle is valid, and represents an object in the kernel that dynamic casts to the class true is returned, otherwise false. */ 283 284boolean_t 285IOObjectConformsTo( 286 io_object_t object, 287 const io_name_t className ); 288 289/*! @function IOObjectIsEqualTo 290 @abstract Checks two object handles to see if they represent the same kernel object. 291 @discussion If two object handles are returned by IOKitLib functions, this function will compare them to see if they represent the same kernel object. 292 @param object An IOKit object. 293 @param anObject Another IOKit object. 294 @result If both object handles are valid, and represent the same object in the kernel true is returned, otherwise false. */ 295 296boolean_t 297IOObjectIsEqualTo( 298 io_object_t object, 299 io_object_t anObject ); 300 301/*! @function IOObjectGetKernelRetainCount 302 @abstract Returns kernel retain count of an IOKit object. 303 @discussion This function may be used in diagnostics to determine the current retain count of the kernel object at the kernel level. 304 @param object An IOKit object. 305 @result If the object handle is valid, the kernel objects retain count is returned, otherwise zero is returned. */ 306 307uint32_t 308IOObjectGetKernelRetainCount( 309 io_object_t object ) 310AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER; 311 312/*! @function IOObjectGetUserRetainCount 313 @abstract Returns the retain count for the current process of an IOKit object. 314 @discussion This function may be used in diagnostics to determine the current retain count for the calling process of the kernel object. 315 @param object An IOKit object. 316 @result If the object handle is valid, the objects user retain count is returned, otherwise zero is returned. */ 317 318uint32_t 319IOObjectGetUserRetainCount( 320 io_object_t object ) 321AVAILABLE_MAC_OS_X_VERSION_10_6_AND_LATER; 322 323/*! @function IOObjectGetRetainCount 324 @abstract Returns kernel retain count of an IOKit object. Identical to IOObjectGetKernelRetainCount() but available prior to Mac OS 10.6. 325 @discussion This function may be used in diagnostics to determine the current retain count of the kernel object at the kernel level. 326 @param object An IOKit object. 327 @result If the object handle is valid, the kernel objects retain count is returned, otherwise zero is returned. */ 328 329uint32_t 330IOObjectGetRetainCount( 331 io_object_t object ); 332 333 334/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 335 336/* 337 * IOIterator, subclass of IOObject 338 */ 339 340/*! @function IOIteratorNext 341 @abstract Returns the next object in an iteration. 342 @discussion This function returns the next object in an iteration, or zero if no more remain or the iterator is invalid. 343 @param iterator An IOKit iterator handle. 344 @result If the iterator handle is valid, the next element in the iteration is returned, otherwise zero is returned. The element should be released by the caller when it is finished. */ 345 346io_object_t 347IOIteratorNext( 348 io_iterator_t iterator ); 349 350/*! @function IOIteratorReset 351 @abstract Resets an iteration back to the beginning. 352 @discussion If an iterator is invalid, or if the caller wants to start over, IOIteratorReset will set the iteration back to the beginning. 353 @param iterator An IOKit iterator handle. */ 354 355void 356IOIteratorReset( 357 io_iterator_t iterator ); 358 359/*! @function IOIteratorIsValid 360 @abstract Checks an iterator is still valid. 361 @discussion Some iterators will be made invalid if changes are made to the structure they are iterating over. This function checks the iterator is still valid and should be called when IOIteratorNext returns zero. An invalid iterator can be reset and the iteration restarted. 362 @param iterator An IOKit iterator handle. 363 @result True if the iterator handle is valid, otherwise false is returned. */ 364 365boolean_t 366IOIteratorIsValid( 367 io_iterator_t iterator ); 368 369/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 370 371/* 372 * IOService, subclass of IORegistryEntry 373 */ 374 375/*! 376 @function IOServiceGetMatchingService 377 @abstract Look up a registered IOService object that matches a matching dictionary. 378 @discussion This is the preferred method of finding IOService objects currently registered by IOKit (that is, objects that have had their registerService() methods invoked). To find IOService objects that aren't yet registered, use an iterator as created by IORegistryEntryCreateIterator(). IOServiceAddMatchingNotification can also supply this information and install a notification of new IOServices. The matching information used in the matching dictionary may vary depending on the class of service being looked up. 379 @param masterPort The master port obtained from IOMasterPort(). Pass kIOMasterPortDefault to look up the default master port. 380 @param matching A CF dictionary containing matching information, of which one reference is always consumed by this function (Note prior to the Tiger release there was a small chance that the dictionary might not be released if there was an error attempting to serialize the dictionary). IOKitLib can construct matching dictionaries for common criteria with helper functions such as IOServiceMatching, IOServiceNameMatching, IOBSDNameMatching. 381 @result The first service matched is returned on success. The service must be released by the caller. 382 */ 383 384io_service_t 385IOServiceGetMatchingService( 386 mach_port_t masterPort, 387 CFDictionaryRef matching ); 388 389/*! @function IOServiceGetMatchingServices 390 @abstract Look up registered IOService objects that match a matching dictionary. 391 @discussion This is the preferred method of finding IOService objects currently registered by IOKit (that is, objects that have had their registerService() methods invoked). To find IOService objects that aren't yet registered, use an iterator as created by IORegistryEntryCreateIterator(). IOServiceAddMatchingNotification can also supply this information and install a notification of new IOServices. The matching information used in the matching dictionary may vary depending on the class of service being looked up. 392 @param masterPort The master port obtained from IOMasterPort(). Pass kIOMasterPortDefault to look up the default master port. 393 @param matching A CF dictionary containing matching information, of which one reference is always consumed by this function (Note prior to the Tiger release there was a small chance that the dictionary might not be released if there was an error attempting to serialize the dictionary). IOKitLib can construct matching dictionaries for common criteria with helper functions such as IOServiceMatching, IOServiceNameMatching, IOBSDNameMatching. 394 @param existing An iterator handle is returned on success, and should be released by the caller when the iteration is finished. 395 @result A kern_return_t error code. */ 396 397kern_return_t 398IOServiceGetMatchingServices( 399 mach_port_t masterPort, 400 CFDictionaryRef matching, 401 io_iterator_t * existing ); 402 403 404kern_return_t 405IOServiceAddNotification( 406 mach_port_t masterPort, 407 const io_name_t notificationType, 408 CFDictionaryRef matching, 409 mach_port_t wakePort, 410 uintptr_t reference, 411 io_iterator_t * notification ) DEPRECATED_ATTRIBUTE; 412 413/*! @function IOServiceAddMatchingNotification 414 @abstract Look up registered IOService objects that match a matching dictionary, and install a notification request of new IOServices that match. 415 @discussion This is the preferred method of finding IOService objects that may arrive at any time. The type of notification specifies the state change the caller is interested in, on IOService's that match the match dictionary. Notification types are identified by name, and are defined in IOKitKeys.h. The matching information used in the matching dictionary may vary depending on the class of service being looked up. 416 @param notifyPort A IONotificationPortRef object that controls how messages will be sent when the armed notification is fired. When the notification is delivered, the io_iterator_t representing the notification should be iterated through to pick up all outstanding objects. When the iteration is finished the notification is rearmed. See IONotificationPortCreate. 417 @param notificationType A notification type from IOKitKeys.h 418<br> kIOPublishNotification Delivered when an IOService is registered. 419<br> kIOFirstPublishNotification Delivered when an IOService is registered, but only once per IOService instance. Some IOService's may be reregistered when their state is changed. 420<br> kIOMatchedNotification Delivered when an IOService has had all matching drivers in the kernel probed and started. 421<br> kIOFirstMatchNotification Delivered when an IOService has had all matching drivers in the kernel probed and started, but only once per IOService instance. Some IOService's may be reregistered when their state is changed. 422<br> kIOTerminatedNotification Delivered after an IOService has been terminated. 423 @param matching A CF dictionary containing matching information, of which one reference is always consumed by this function (Note prior to the Tiger release there was a small chance that the dictionary might not be released if there was an error attempting to serialize the dictionary). IOKitLib can construct matching dictionaries for common criteria with helper functions such as IOServiceMatching, IOServiceNameMatching, IOBSDNameMatching. 424 @param callback A callback function called when the notification fires. 425 @param refCon A reference constant for the callbacks use. 426 @param notification An iterator handle is returned on success, and should be released by the caller when the notification is to be destroyed. The notification is armed when the iterator is emptied by calls to IOIteratorNext - when no more objects are returned, the notification is armed. Note the notification is not armed when first created. 427 @result A kern_return_t error code. */ 428 429kern_return_t 430IOServiceAddMatchingNotification( 431 IONotificationPortRef notifyPort, 432 const io_name_t notificationType, 433 CFDictionaryRef matching, 434 IOServiceMatchingCallback callback, 435 void * refCon, 436 io_iterator_t * notification ); 437 438/*! @function IOServiceAddInterestNotification 439 @abstract Register for notification of state changes in an IOService. 440 @discussion IOService objects deliver notifications of their state changes to their clients via the IOService::message API, and to other interested parties including callers of this function. Message type s are defined IOKit/IOMessage.h. 441 @param notifyPort A IONotificationPortRef object that controls how messages will be sent when the notification is fired. See IONotificationPortCreate. 442 @param interestType A notification type from IOKitKeys.h 443<br> kIOGeneralInterest General state changes delivered via the IOService::message API. 444<br> kIOBusyInterest Delivered when the IOService changes its busy state to or from zero. The message argument contains the new busy state causing the notification. 445 @param callback A callback function called when the notification fires, with messageType and messageArgument for the state change. 446 @param refCon A reference constant for the callbacks use. 447 @param notification An object handle is returned on success, and should be released by the caller when the notification is to be destroyed. 448 @result A kern_return_t error code. */ 449 450kern_return_t 451IOServiceAddInterestNotification( 452 IONotificationPortRef notifyPort, 453 io_service_t service, 454 const io_name_t interestType, 455 IOServiceInterestCallback callback, 456 void * refCon, 457 io_object_t * notification ); 458 459/*! @function IOServiceMatchPropertyTable 460 @abstract Match an IOService objects with matching dictionary. 461 @discussion This function calls the matching method of an IOService object and returns the boolean result. 462 @param service The IOService object to match. 463 @param matching A CF dictionary containing matching information. IOKitLib can construct matching dictionaries for common criteria with helper functions such as IOServiceMatching, IOServiceNameMatching, IOBSDNameMatching. 464 @param matches The boolean result is returned. 465 @result A kern_return_t error code. */ 466 467kern_return_t 468IOServiceMatchPropertyTable( 469 io_service_t service, 470 CFDictionaryRef matching, 471 boolean_t * matches ); 472 473/*! @function IOServiceGetBusyState 474 @abstract Returns the busyState of an IOService. 475 @discussion Many activities in IOService are asynchronous. When registration, matching, or termination is in progress on an IOService, its busyState is increased by one. Change in busyState to or from zero also changes the IOService's provider's busyState by one, which means that an IOService is marked busy when any of the above activities is ocurring on it or any of its clients. 476 @param service The IOService whose busyState to return. 477 @param busyState The busyState count is returned. 478 @result A kern_return_t error code. */ 479 480kern_return_t 481IOServiceGetBusyState( 482 io_service_t service, 483 uint32_t * busyState ); 484 485/*! @function IOServiceWaitQuiet 486 @abstract Wait for an IOService's busyState to be zero. 487 @discussion Blocks the caller until an IOService is non busy, see IOServiceGetBusyState. 488 @param service The IOService wait on. 489 @param waitTime Specifies a maximum time to wait. 490 @result Returns an error code if mach synchronization primitives fail, kIOReturnTimeout, or kIOReturnSuccess. */ 491 492kern_return_t 493IOServiceWaitQuiet( 494 io_service_t service, 495 mach_timespec_t * waitTime ); 496 497/*! @function IOKitGetBusyState 498 @abstract Returns the busyState of all IOServices. 499 @discussion Many activities in IOService are asynchronous. When registration, matching, or termination is in progress on an IOService, its busyState is increased by one. Change in busyState to or from zero also changes the IOService's provider's busyState by one, which means that an IOService is marked busy when any of the above activities is ocurring on it or any of its clients. IOKitGetBusyState returns the busy state of the root of the service plane which reflects the busy state of all IOServices. 500 @param masterPort The master port obtained from IOMasterPort(). Pass kIOMasterPortDefault to look up the default master port. 501 @param busyState The busyState count is returned. 502 @result A kern_return_t error code. */ 503 504kern_return_t 505IOKitGetBusyState( 506 mach_port_t masterPort, 507 uint32_t * busyState ); 508 509/*! @function IOKitWaitQuiet 510 @abstract Wait for a all IOServices' busyState to be zero. 511 @discussion Blocks the caller until all IOServices are non busy, see IOKitGetBusyState. 512 @param masterPort The master port obtained from IOMasterPort(). Pass kIOMasterPortDefault to look up the default master port. 513 @param waitTime Specifies a maximum time to wait. 514 @result Returns an error code if mach synchronization primitives fail, kIOReturnTimeout, or kIOReturnSuccess. */ 515 516kern_return_t 517IOKitWaitQuiet( 518 mach_port_t masterPort, 519 mach_timespec_t * waitTime ); 520 521/*! @function IOServiceOpen 522 @abstract A request to create a connection to an IOService. 523 @discussion A non kernel client may request a connection be opened via the IOServiceOpen() library function, which will call IOService::newUserClient in the kernel. The rules & capabilities of user level clients are family dependent, the default IOService implementation returns kIOReturnUnsupported. 524 @param service The IOService object to open a connection to, usually obtained via the IOServiceGetMatchingServices or IOServiceAddNotification APIs. 525 @param owningTask The mach task requesting the connection. 526 @param type A constant specifying the type of connection to be created, interpreted only by the IOService's family. 527 @param connect An io_connect_t handle is returned on success, to be used with the IOConnectXXX APIs. It should be destroyed with IOServiceClose(). 528 @result A return code generated by IOService::newUserClient. */ 529 530kern_return_t 531IOServiceOpen( 532 io_service_t service, 533 task_port_t owningTask, 534 uint32_t type, 535 io_connect_t * connect ); 536 537/*! @function IOServiceRequestProbe 538 @abstract A request to rescan a bus for device changes. 539 @discussion A non kernel client may request a bus or controller rescan for added or removed devices, if the bus family does automatically notice such changes. For example, SCSI bus controllers do not notice device changes. The implementation of this routine is family dependent, and the default IOService implementation returns kIOReturnUnsupported. 540 @param service The IOService object to request a rescan, usually obtained via the IOServiceGetMatchingServices or IOServiceAddNotification APIs. 541 @param options An options mask, interpreted only by the IOService's family. 542 @result A return code generated by IOService::requestProbe. */ 543 544kern_return_t 545IOServiceRequestProbe( 546 io_service_t service, 547 uint32_t options ); 548 549/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 550 551/* 552 * IOService connection 553 */ 554 555/*! @function IOServiceClose 556 @abstract Close a connection to an IOService and destroy the connect handle. 557 @discussion A connection created with the IOServiceOpen should be closed when the connection is no longer to be used with IOServiceClose. 558 @param connect The connect handle created by IOServiceOpen. It will be destroyed by this function, and should not be released with IOObjectRelease. 559 @result A kern_return_t error code. */ 560 561kern_return_t 562IOServiceClose( 563 io_connect_t connect ); 564 565/*! @function IOConnectAddRef 566 @abstract Adds a reference to the connect handle. 567 @discussion Adds a reference to the connect handle. 568 @param connect The connect handle created by IOServiceOpen. 569 @result A kern_return_t error code. */ 570 571kern_return_t 572IOConnectAddRef( 573 io_connect_t connect ); 574 575/*! @function IOConnectRelease 576 @abstract Remove a reference to the connect handle. 577 @discussion Removes a reference to the connect handle. If the last reference is removed an implicit IOServiceClose is performed. 578 @param connect The connect handle created by IOServiceOpen. 579 @result A kern_return_t error code. */ 580 581kern_return_t 582IOConnectRelease( 583 io_connect_t connect ); 584 585/*! @function IOConnectGetService 586 @abstract Returns the IOService a connect handle was opened on. 587 @discussion Finds the service object a connection was opened on. 588 @param connect The connect handle created by IOServiceOpen. 589 @param service On succes, the service handle the connection was opened on, which should be released with IOObjectRelease. 590 @result A kern_return_t error code. */ 591 592kern_return_t 593IOConnectGetService( 594 io_connect_t connect, 595 io_service_t * service ); 596 597/*! @function IOConnectSetNotificationPort 598 @abstract Set a port to receive family specific notifications. 599 @discussion This is a generic method to pass a mach port send right to be be used by family specific notifications. 600 @param connect The connect handle created by IOServiceOpen. 601 @param type The type of notification requested, not interpreted by IOKit and family defined. 602 @param port The port to which to send notifications. 603 @param reference Some families may support passing a reference parameter for the callers use with the notification. 604 @result A kern_return_t error code. */ 605 606kern_return_t 607IOConnectSetNotificationPort( 608 io_connect_t connect, 609 uint32_t type, 610 mach_port_t port, 611 uintptr_t reference ); 612 613/*! @function IOConnectMapMemory 614 @abstract Map hardware or shared memory into the caller's task. 615 @discussion This is a generic method to create a mapping in the callers task. The family will interpret the type parameter to determine what sort of mapping is being requested. Cache modes and placed mappings may be requested by the caller. 616 @param connect The connect handle created by IOServiceOpen. 617 @param memoryType What is being requested to be mapped, not interpreted by IOKit and family defined. The family may support physical hardware or shared memory mappings. 618 @param intoTask The task port for the task in which to create the mapping. This may be different to the task which the opened the connection. 619 @param atAddress An in/out parameter - if the kIOMapAnywhere option is not set, the caller should pass the address where it requests the mapping be created, otherwise nothing need to set on input. The address of the mapping created is passed back on sucess. 620 @param ofSize The size of the mapping created is passed back on success. 621 @result A kern_return_t error code. */ 622 623#if !__LP64__ || defined(IOCONNECT_MAPMEMORY_10_6) 624 625kern_return_t 626IOConnectMapMemory( 627 io_connect_t connect, 628 uint32_t memoryType, 629 task_port_t intoTask, 630 vm_address_t *atAddress, 631 vm_size_t *ofSize, 632 IOOptionBits options ); 633 634#else 635 636kern_return_t 637IOConnectMapMemory( 638 io_connect_t connect, 639 uint32_t memoryType, 640 task_port_t intoTask, 641 mach_vm_address_t *atAddress, 642 mach_vm_size_t *ofSize, 643 IOOptionBits options ); 644 645#endif /* !__LP64__ || defined(IOCONNECT_MAPMEMORY_10_6) */ 646 647 648/*! @function IOConnectMapMemory64 649 @abstract Map hardware or shared memory into the caller's task. 650 @discussion This is a generic method to create a mapping in the callers task. The family will interpret the type parameter to determine what sort of mapping is being requested. Cache modes and placed mappings may be requested by the caller. 651 @param connect The connect handle created by IOServiceOpen. 652 @param memoryType What is being requested to be mapped, not interpreted by IOKit and family defined. The family may support physical hardware or shared memory mappings. 653 @param intoTask The task port for the task in which to create the mapping. This may be different to the task which the opened the connection. 654 @param atAddress An in/out parameter - if the kIOMapAnywhere option is not set, the caller should pass the address where it requests the mapping be created, otherwise nothing need to set on input. The address of the mapping created is passed back on sucess. 655 @param ofSize The size of the mapping created is passed back on success. 656 @result A kern_return_t error code. */ 657 658kern_return_t IOConnectMapMemory64( 659 io_connect_t connect, 660 uint32_t memoryType, 661 task_port_t intoTask, 662 mach_vm_address_t *atAddress, 663 mach_vm_size_t *ofSize, 664 IOOptionBits options ); 665 666/*! @function IOConnectUnmapMemory 667 @abstract Remove a mapping made with IOConnectMapMemory. 668 @discussion This is a generic method to remove a mapping in the callers task. 669 @param connect The connect handle created by IOServiceOpen. 670 @param memoryType The memory type originally requested in IOConnectMapMemory. 671 @param fromTask The task port for the task in which to remove the mapping. This may be different to the task which the opened the connection. 672 @param atAddress The address of the mapping to be removed. 673 @result A kern_return_t error code. */ 674 675#if !__LP64__ || defined(IOCONNECT_MAPMEMORY_10_6) 676 677kern_return_t 678IOConnectUnmapMemory( 679 io_connect_t connect, 680 uint32_t memoryType, 681 task_port_t fromTask, 682 vm_address_t atAddress ); 683 684#else 685 686kern_return_t 687IOConnectUnmapMemory( 688 io_connect_t connect, 689 uint32_t memoryType, 690 task_port_t fromTask, 691 mach_vm_address_t atAddress ); 692 693 694#endif /* !__LP64__ || defined(IOCONNECT_MAPMEMORY_10_6) */ 695 696/*! @function IOConnectUnmapMemory64 697 @abstract Remove a mapping made with IOConnectMapMemory64. 698 @discussion This is a generic method to remove a mapping in the callers task. 699 @param connect The connect handle created by IOServiceOpen. 700 @param memoryType The memory type originally requested in IOConnectMapMemory. 701 @param fromTask The task port for the task in which to remove the mapping. This may be different to the task which the opened the connection. 702 @param atAddress The address of the mapping to be removed. 703 @result A kern_return_t error code. */ 704 705kern_return_t IOConnectUnmapMemory64( 706 io_connect_t connect, 707 uint32_t memoryType, 708 task_port_t fromTask, 709 mach_vm_address_t atAddress ); 710 711 712/*! @function IOConnectSetCFProperties 713 @abstract Set CF container based properties on a connection. 714 @discussion This is a generic method to pass a CF container of properties to the connection. The properties are interpreted by the family and commonly represent configuration settings, but may be interpreted as anything. 715 @param connect The connect handle created by IOServiceOpen. 716 @param properties A CF container - commonly a CFDictionary but this is not enforced. The container should consist of objects which are understood by IOKit - these are currently : CFDictionary, CFArray, CFSet, CFString, CFData, CFNumber, CFBoolean, and are passed in the kernel as the corresponding OSDictionary etc. objects. 717 @result A kern_return_t error code returned by the family. */ 718 719kern_return_t 720IOConnectSetCFProperties( 721 io_connect_t connect, 722 CFTypeRef properties ); 723 724/*! @function IOConnectSetCFProperty 725 @abstract Set a CF container based property on a connection. 726 @discussion This is a generic method to pass a CF property to the connection. The property is interpreted by the family and commonly represent configuration settings, but may be interpreted as anything. 727 @param connect The connect handle created by IOServiceOpen. 728 @param propertyName The name of the property as a CFString. 729 @param property A CF container - should consist of objects which are understood by IOKit - these are currently : CFDictionary, CFArray, CFSet, CFString, CFData, CFNumber, CFBoolean, and are passed in the kernel as the corresponding OSDictionary etc. objects. 730 @result A kern_return_t error code returned by the object. */ 731 732kern_return_t 733IOConnectSetCFProperty( 734 io_connect_t connect, 735 CFStringRef propertyName, 736 CFTypeRef property ); 737 738/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 739 740// Combined LP64 & ILP32 Extended IOUserClient::externalMethod 741 742kern_return_t 743IOConnectCallMethod( 744 mach_port_t connection, // In 745 uint32_t selector, // In 746 const uint64_t *input, // In 747 uint32_t inputCnt, // In 748 const void *inputStruct, // In 749 size_t inputStructCnt, // In 750 uint64_t *output, // Out 751 uint32_t *outputCnt, // In/Out 752 void *outputStruct, // Out 753 size_t *outputStructCnt) // In/Out 754AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER; 755 756kern_return_t 757IOConnectCallAsyncMethod( 758 mach_port_t connection, // In 759 uint32_t selector, // In 760 mach_port_t wake_port, // In 761 uint64_t *reference, // In 762 uint32_t referenceCnt, // In 763 const uint64_t *input, // In 764 uint32_t inputCnt, // In 765 const void *inputStruct, // In 766 size_t inputStructCnt, // In 767 uint64_t *output, // Out 768 uint32_t *outputCnt, // In/Out 769 void *outputStruct, // Out 770 size_t *outputStructCnt) // In/Out 771AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER; 772 773kern_return_t 774IOConnectCallStructMethod( 775 mach_port_t connection, // In 776 uint32_t selector, // In 777 const void *inputStruct, // In 778 size_t inputStructCnt, // In 779 void *outputStruct, // Out 780 size_t *outputStructCnt) // In/Out 781AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER; 782 783kern_return_t 784IOConnectCallAsyncStructMethod( 785 mach_port_t connection, // In 786 uint32_t selector, // In 787 mach_port_t wake_port, // In 788 uint64_t *reference, // In 789 uint32_t referenceCnt, // In 790 const void *inputStruct, // In 791 size_t inputStructCnt, // In 792 void *outputStruct, // Out 793 size_t *outputStructCnt) // In/Out 794AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER; 795 796kern_return_t 797IOConnectCallScalarMethod( 798 mach_port_t connection, // In 799 uint32_t selector, // In 800 const uint64_t *input, // In 801 uint32_t inputCnt, // In 802 uint64_t *output, // Out 803 uint32_t *outputCnt) // In/Out 804AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER; 805 806kern_return_t 807IOConnectCallAsyncScalarMethod( 808 mach_port_t connection, // In 809 uint32_t selector, // In 810 mach_port_t wake_port, // In 811 uint64_t *reference, // In 812 uint32_t referenceCnt, // In 813 const uint64_t *input, // In 814 uint32_t inputCnt, // In 815 uint64_t *output, // Out 816 uint32_t *outputCnt) // In/Out 817AVAILABLE_MAC_OS_X_VERSION_10_5_AND_LATER; 818 819/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 820 821kern_return_t 822IOConnectTrap0(io_connect_t connect, 823 uint32_t index ); 824 825kern_return_t 826IOConnectTrap1(io_connect_t connect, 827 uint32_t index, 828 uintptr_t p1 ); 829 830kern_return_t 831IOConnectTrap2(io_connect_t connect, 832 uint32_t index, 833 uintptr_t p1, 834 uintptr_t p2); 835 836kern_return_t 837IOConnectTrap3(io_connect_t connect, 838 uint32_t index, 839 uintptr_t p1, 840 uintptr_t p2, 841 uintptr_t p3); 842 843kern_return_t 844IOConnectTrap4(io_connect_t connect, 845 uint32_t index, 846 uintptr_t p1, 847 uintptr_t p2, 848 uintptr_t p3, 849 uintptr_t p4); 850 851kern_return_t 852IOConnectTrap5(io_connect_t connect, 853 uint32_t index, 854 uintptr_t p1, 855 uintptr_t p2, 856 uintptr_t p3, 857 uintptr_t p4, 858 uintptr_t p5); 859 860kern_return_t 861IOConnectTrap6(io_connect_t connect, 862 uint32_t index, 863 uintptr_t p1, 864 uintptr_t p2, 865 uintptr_t p3, 866 uintptr_t p4, 867 uintptr_t p5, 868 uintptr_t p6); 869 870/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 871 872/*! @function IOConnectAddClient 873 @abstract Inform a connection of a second connection. 874 @discussion This is a generic method to inform a family connection of a second connection, and is rarely used. 875 @param connect The connect handle created by IOServiceOpen. 876 @param client Another connect handle created by IOServiceOpen. 877 @result A kern_return_t error code returned by the family. */ 878 879kern_return_t 880IOConnectAddClient( 881 io_connect_t connect, 882 io_connect_t client ); 883 884/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 885 886/* 887 * IORegistry accessors 888 */ 889 890/*! @function IORegistryGetRootEntry 891 @abstract Return a handle to the registry root. 892 @discussion This method provides an accessor to the root of the registry for the machine. The root may be passed to a registry iterator when iterating a plane, and contains properties that describe the available planes, and diagnostic information for IOKit. 893 @param masterPort The master port obtained from IOMasterPort(). Pass kIOMasterPortDefault to look up the default master port. 894 @result A handle to the IORegistryEntry root instance, to be released with IOObjectRelease by the caller, or MACH_PORT_NULL on failure. */ 895 896io_registry_entry_t 897IORegistryGetRootEntry( 898 mach_port_t masterPort ); 899 900/*! @function IORegistryEntryFromPath 901 @abstract Looks up a registry entry by path. 902 @discussion This function parses paths to lookup registry entries. The path should begin with '<plane name>:' If there are characters remaining unparsed after an entry has been looked up, this is considered an invalid lookup. Paths are further documented in IORegistryEntry.h 903 @param masterPort The master port obtained from IOMasterPort(). Pass kIOMasterPortDefault to look up the default master port. 904 @param path A C-string path. 905 @result A handle to the IORegistryEntry witch was found with the path, to be released with IOObjectRelease by the caller, or MACH_PORT_NULL on failure. */ 906 907io_registry_entry_t 908IORegistryEntryFromPath( 909 mach_port_t masterPort, 910 const io_string_t path ); 911 912// options for IORegistryCreateIterator(), IORegistryEntryCreateIterator, IORegistryEntrySearchCFProperty() 913enum { 914 kIORegistryIterateRecursively = 0x00000001, 915 kIORegistryIterateParents = 0x00000002 916}; 917 918/*! @function IORegistryCreateIterator 919 @abstract Create an iterator rooted at the registry root. 920 @discussion This method creates an IORegistryIterator in the kernel that is set up with options to iterate children of the registry root entry, and to recurse automatically into entries as they are returned, or only when instructed with calls to IORegistryIteratorEnterEntry. The iterator object keeps track of entries that have been recursed into previously to avoid loops. 921 @param masterPort The master port obtained from IOMasterPort(). Pass kIOMasterPortDefault to look up the default master port. 922 @param plane The name of an existing registry plane. Plane names are defined in IOKitKeys.h, eg. kIOServicePlane. 923 @param options kIORegistryIterateRecursively may be set to recurse automatically into each entry as it is returned from IOIteratorNext calls on the registry iterator. 924 @param iterator A created iterator handle, to be released by the caller when it has finished with it. 925 @result A kern_return_t error code. */ 926 927kern_return_t 928IORegistryCreateIterator( 929 mach_port_t masterPort, 930 const io_name_t plane, 931 IOOptionBits options, 932 io_iterator_t * iterator ); 933 934/*! @function IORegistryEntryCreateIterator 935 @abstract Create an iterator rooted at a given registry entry. 936 @discussion This method creates an IORegistryIterator in the kernel that is set up with options to iterate children or parents of a root entry, and to recurse automatically into entries as they are returned, or only when instructed with calls to IORegistryIteratorEnterEntry. The iterator object keeps track of entries that have been recursed into previously to avoid loops. 937 @param entry The root entry to begin the iteration at. 938 @param plane The name of an existing registry plane. Plane names are defined in IOKitKeys.h, eg. kIOServicePlane. 939 @param options kIORegistryIterateRecursively may be set to recurse automatically into each entry as it is returned from IOIteratorNext calls on the registry iterator. kIORegistryIterateParents may be set to iterate the parents of each entry, by default the children are iterated. 940 @param iterator A created iterator handle, to be released by the caller when it has finished with it. 941 @result A kern_return_t error code. */ 942 943kern_return_t 944IORegistryEntryCreateIterator( 945 io_registry_entry_t entry, 946 const io_name_t plane, 947 IOOptionBits options, 948 io_iterator_t * iterator ); 949 950/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 951 952/* 953 * IORegistryIterator, subclass of IOIterator 954 */ 955 956/*! @function IORegistryIteratorEnterEntry 957 @abstract Recurse into the current entry in the registry iteration. 958 @discussion This method makes the current entry, ie. the last entry returned by IOIteratorNext, the root in a new level of recursion. 959 @result A kern_return_t error code. */ 960 961kern_return_t 962IORegistryIteratorEnterEntry( 963 io_iterator_t iterator ); 964 965/*! @function IORegistryIteratorExitEntry 966 @abstract Exits a level of recursion, restoring the current entry. 967 @discussion This method undoes an IORegistryIteratorEnterEntry, restoring the current entry. If there are no more levels of recursion to exit false is returned, otherwise true is returned. 968 @result kIOReturnSuccess if a level of recursion was undone, kIOReturnNoDevice if no recursive levels are left in the iteration. */ 969 970kern_return_t 971IORegistryIteratorExitEntry( 972 io_iterator_t iterator ); 973 974/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 975 976/* 977 * IORegistryEntry, subclass of IOObject 978 */ 979 980/*! @function IORegistryEntryGetName 981 @abstract Returns a C-string name assigned to a registry entry. 982 @discussion Registry entries can be named in a particular plane, or globally. This function returns the entry's global name. The global name defaults to the entry's meta class name if it has not been named. 983 @param entry The registry entry handle whose name to look up. 984 @param name The caller's buffer to receive the name. 985 @result A kern_return_t error code. */ 986 987kern_return_t 988IORegistryEntryGetName( 989 io_registry_entry_t entry, 990 io_name_t name ); 991 992/*! @function IORegistryEntryGetNameInPlane 993 @abstract Returns a C-string name assigned to a registry entry, in a specified plane. 994 @discussion Registry entries can be named in a particular plane, or globally. This function returns the entry's name in the specified plane or global name if it has not been named in that plane. The global name defaults to the entry's meta class name if it has not been named. 995 @param entry The registry entry handle whose name to look up. 996 @param plane The name of an existing registry plane. Plane names are defined in IOKitKeys.h, eg. kIOServicePlane. 997 @param name The caller's buffer to receive the name. 998 @result A kern_return_t error code. */ 999 1000kern_return_t 1001IORegistryEntryGetNameInPlane( 1002 io_registry_entry_t entry, 1003 const io_name_t plane, 1004 io_name_t name ); 1005 1006/*! @function IORegistryEntryGetLocationInPlane 1007 @abstract Returns a C-string location assigned to a registry entry, in a specified plane. 1008 @discussion Registry entries can given a location string in a particular plane, or globally. If the entry has had a location set in the specified plane that location string will be returned, otherwise the global location string is returned. If no global location string has been set, an error is returned. 1009 @param entry The registry entry handle whose name to look up. 1010 @param plane The name of an existing registry plane. Plane names are defined in IOKitKeys.h, eg. kIOServicePlane. 1011 @param location The caller's buffer to receive the location string. 1012 @result A kern_return_t error code. */ 1013 1014kern_return_t 1015IORegistryEntryGetLocationInPlane( 1016 io_registry_entry_t entry, 1017 const io_name_t plane, 1018 io_name_t location ); 1019 1020/*! @function IORegistryEntryGetPath 1021 @abstract Create a path for a registry entry. 1022 @discussion The path for a registry entry is copied to the caller's buffer. The path describes the entry's attachment in a particular plane, which must be specified. The path begins with the plane name followed by a colon, and then followed by '/' separated path components for each of the entries between the root and the registry entry. An alias may also exist for the entry, and will be returned if available. 1023 @param entry The registry entry handle whose path to look up. 1024 @param plane The name of an existing registry plane. Plane names are defined in IOKitKeys.h, eg. kIOServicePlane. 1025 @param path A char buffer allocated by the caller. 1026 @result IORegistryEntryGetPath will fail if the entry is not attached in the plane, or if the buffer is not large enough to contain the path. */ 1027 1028kern_return_t 1029IORegistryEntryGetPath( 1030 io_registry_entry_t entry, 1031 const io_name_t plane, 1032 io_string_t path ); 1033 1034/*! @function IORegistryEntryGetRegistryEntryID 1035 @abstract Returns an ID for the registry entry that is global to all tasks. 1036 @discussion The entry ID returned by IORegistryEntryGetRegistryEntryID can be used to identify a registry entry across all tasks. A registry entry may be looked up by its entryID by creating a matching dictionary with IORegistryEntryIDMatching() to be used with the IOKit matching functions. The ID is valid only until the machine reboots. 1037 @param entry The registry entry handle whose ID to look up. 1038 @param entryID The resulting ID. 1039 @result A kern_return_t error code. */ 1040 1041kern_return_t 1042IORegistryEntryGetRegistryEntryID( 1043 io_registry_entry_t entry, 1044 uint64_t * entryID ); 1045 1046/*! @function IORegistryEntryCreateCFProperties 1047 @abstract Create a CF dictionary representation of a registry entry's property table. 1048 @discussion This function creates an instantaneous snapshot of a registry entry's property table, creating a CFDictionary analogue in the caller's task. Not every object available in the kernel is represented as a CF container; currently OSDictionary, OSArray, OSSet, OSSymbol, OSString, OSData, OSNumber, OSBoolean are created as their CF counterparts. 1049 @param entry The registry entry handle whose property table to copy. 1050 @param properties A CFDictionary is created and returned the caller on success. The caller should release with CFRelease. 1051 @param allocator The CF allocator to use when creating the CF containers. 1052 @param options No options are currently defined. 1053 @result A kern_return_t error code. */ 1054 1055kern_return_t 1056IORegistryEntryCreateCFProperties( 1057 io_registry_entry_t entry, 1058 CFMutableDictionaryRef * properties, 1059 CFAllocatorRef allocator, 1060 IOOptionBits options ); 1061 1062/*! @function IORegistryEntryCreateCFProperty 1063 @abstract Create a CF representation of a registry entry's property. 1064 @discussion This function creates an instantaneous snapshot of a registry entry property, creating a CF container analogue in the caller's task. Not every object available in the kernel is represented as a CF container; currently OSDictionary, OSArray, OSSet, OSSymbol, OSString, OSData, OSNumber, OSBoolean are created as their CF counterparts. 1065 @param entry The registry entry handle whose property to copy. 1066 @param key A CFString specifying the property name. 1067 @param allocator The CF allocator to use when creating the CF container. 1068 @param options No options are currently defined. 1069 @result A CF container is created and returned the caller on success. The caller should release with CFRelease. */ 1070 1071CFTypeRef 1072IORegistryEntryCreateCFProperty( 1073 io_registry_entry_t entry, 1074 CFStringRef key, 1075 CFAllocatorRef allocator, 1076 IOOptionBits options ); 1077 1078/*! @function IORegistryEntrySearchCFProperty 1079 @abstract Create a CF representation of a registry entry's property. 1080 @discussion This function creates an instantaneous snapshot of a registry entry property, creating a CF container analogue in the caller's task. Not every object available in the kernel is represented as a CF container; currently OSDictionary, OSArray, OSSet, OSSymbol, OSString, OSData, OSNumber, OSBoolean are created as their CF counterparts. 1081This function will search for a property, starting first with specified registry entry's property table, then iterating recusively through either the parent registry entries or the child registry entries of this entry. Once the first occurrence is found, it will lookup and return the value of the property, using the same semantics as IORegistryEntryCreateCFProperty. The iteration keeps track of entries that have been recursed into previously to avoid loops. 1082 @param entry The registry entry at which to start the search. 1083 @param plane The name of an existing registry plane. Plane names are defined in IOKitKeys.h, eg. kIOServicePlane. 1084 @param key A CFString specifying the property name. 1085 @param allocator The CF allocator to use when creating the CF container. 1086 @param options kIORegistryIterateRecursively may be set to recurse automatically into the registry hierarchy. Without this option, this method degenerates into the standard IORegistryEntryCreateCFProperty() call. kIORegistryIterateParents may be set to iterate the parents of the entry, in place of the children. 1087 @result A CF container is created and returned the caller on success. The caller should release with CFRelease. */ 1088 1089CFTypeRef 1090IORegistryEntrySearchCFProperty( 1091 io_registry_entry_t entry, 1092 const io_name_t plane, 1093 CFStringRef key, 1094 CFAllocatorRef allocator, 1095 IOOptionBits options ) CF_RETURNS_RETAINED; 1096 1097/* @function IORegistryEntryGetProperty - deprecated, 1098 use IORegistryEntryCreateCFProperty */ 1099 1100kern_return_t 1101IORegistryEntryGetProperty( 1102 io_registry_entry_t entry, 1103 const io_name_t propertyName, 1104 io_struct_inband_t buffer, 1105 uint32_t * size ); 1106 1107/*! @function IORegistryEntrySetCFProperties 1108 @abstract Set CF container based properties in a registry entry. 1109 @discussion This is a generic method to pass a CF container of properties to an object in the registry. Setting properties in a registry entry is not generally supported, it is more common to support IOConnectSetCFProperties for connection based property setting. The properties are interpreted by the object. 1110 @param entry The registry entry whose properties to set. 1111 @param properties A CF container - commonly a CFDictionary but this is not enforced. The container should consist of objects which are understood by IOKit - these are currently : CFDictionary, CFArray, CFSet, CFString, CFData, CFNumber, CFBoolean, and are passed in the kernel as the corresponding OSDictionary etc. objects. 1112 @result A kern_return_t error code returned by the object. */ 1113 1114kern_return_t 1115IORegistryEntrySetCFProperties( 1116 io_registry_entry_t entry, 1117 CFTypeRef properties ); 1118 1119/*! @function IORegistryEntrySetCFProperty 1120 @abstract Set a CF container based property in a registry entry. 1121 @discussion This is a generic method to pass a CF container as a property to an object in the registry. Setting properties in a registry entry is not generally supported, it is more common to support IOConnectSetCFProperty for connection based property setting. The property is interpreted by the object. 1122 @param entry The registry entry whose property to set. 1123 @param propertyName The name of the property as a CFString. 1124 @param property A CF container - should consist of objects which are understood by IOKit - these are currently : CFDictionary, CFArray, CFSet, CFString, CFData, CFNumber, CFBoolean, and are passed in the kernel as the corresponding OSDictionary etc. objects. 1125 @result A kern_return_t error code returned by the object. */ 1126 1127kern_return_t 1128IORegistryEntrySetCFProperty( 1129 io_registry_entry_t entry, 1130 CFStringRef propertyName, 1131 CFTypeRef property ); 1132 1133/*! @function IORegistryEntryGetChildIterator 1134 @abstract Returns an iterator over an registry entry's child entries in a plane. 1135 @discussion This method creates an iterator which will return each of a registry entry's child entries in a specified plane. 1136 @param entry The registry entry whose children to iterate over. 1137 @param plane The name of an existing registry plane. Plane names are defined in IOKitKeys.h, eg. kIOServicePlane. 1138 @param iterator The created iterator over the children of the entry, on success. The iterator must be released when the iteration is finished. 1139 @result A kern_return_t error code. */ 1140 1141kern_return_t 1142IORegistryEntryGetChildIterator( 1143 io_registry_entry_t entry, 1144 const io_name_t plane, 1145 io_iterator_t * iterator ); 1146 1147/*! @function IORegistryEntryGetChildEntry 1148 @abstract Returns the first child of a registry entry in a plane. 1149 @discussion This function will return the child which first attached to a registry entry in a plane. 1150 @param entry The registry entry whose child to look up. 1151 @param plane The name of an existing registry plane. Plane names are defined in IOKitKeys.h, eg. kIOServicePlane. 1152 @param child The first child of the registry entry, on success. The child must be released by the caller. 1153 @result A kern_return_t error code. */ 1154 1155kern_return_t 1156IORegistryEntryGetChildEntry( 1157 io_registry_entry_t entry, 1158 const io_name_t plane, 1159 io_registry_entry_t * child ); 1160 1161/*! @function IORegistryEntryGetParentIterator 1162 @abstract Returns an iterator over an registry entry's parent entries in a plane. 1163 @discussion This method creates an iterator which will return each of a registry entry's parent entries in a specified plane. 1164 @param entry The registry entry whose parents to iterate over. 1165 @param plane The name of an existing registry plane. Plane names are defined in IOKitKeys.h, eg. kIOServicePlane. 1166 @param iterator The created iterator over the parents of the entry, on success. The iterator must be released when the iteration is finished. 1167 @result A kern_return_t error. */ 1168 1169kern_return_t 1170IORegistryEntryGetParentIterator( 1171 io_registry_entry_t entry, 1172 const io_name_t plane, 1173 io_iterator_t * iterator ); 1174 1175/*! @function IORegistryEntryGetParentEntry 1176 @abstract Returns the first parent of a registry entry in a plane. 1177 @discussion This function will return the parent to which the registry entry was first attached in a plane. 1178 @param entry The registry entry whose parent to look up. 1179 @param plane The name of an existing registry plane. Plane names are defined in IOKitKeys.h, eg. kIOServicePlane. 1180 @param parent The first parent of the registry entry, on success. The parent must be released by the caller. 1181 @result A kern_return_t error code. */ 1182 1183kern_return_t 1184IORegistryEntryGetParentEntry( 1185 io_registry_entry_t entry, 1186 const io_name_t plane, 1187 io_registry_entry_t * parent ); 1188 1189/*! @function IORegistryEntryInPlane 1190 @abstract Determines if the registry entry is attached in a plane. 1191 @discussion This method determines if the entry is attached in a plane to any other entry. 1192 @param entry The registry entry. 1193 @param plane The name of an existing registry plane. Plane names are defined in IOKitKeys.h, eg. kIOServicePlane. 1194 @result If the entry has a parent in the plane, true is returned, otherwise false is returned. */ 1195 1196boolean_t 1197IORegistryEntryInPlane( 1198 io_registry_entry_t entry, 1199 const io_name_t plane ); 1200 1201/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 1202 1203/* 1204 * Matching dictionary creation helpers 1205 */ 1206 1207/*! @function IOServiceMatching 1208 @abstract Create a matching dictionary that specifies an IOService class match. 1209 @discussion A very common matching criteria for IOService is based on its class. IOServiceMatching will create a matching dictionary that specifies any IOService of a class, or its subclasses. The class is specified by C-string name. 1210 @param name The class name, as a const C-string. Class matching is successful on IOService's of this class or any subclass. 1211 @result The matching dictionary created, is returned on success, or zero on failure. The dictionary is commonly passed to IOServiceGetMatchingServices or IOServiceAddNotification which will consume a reference, otherwise it should be released with CFRelease by the caller. */ 1212 1213CFMutableDictionaryRef 1214IOServiceMatching( 1215 const char * name ); 1216 1217/*! @function IOServiceNameMatching 1218 @abstract Create a matching dictionary that specifies an IOService name match. 1219 @discussion A common matching criteria for IOService is based on its name. IOServiceNameMatching will create a matching dictionary that specifies an IOService with a given name. Some IOServices created from the device tree will perform name matching on the standard compatible, name, model properties. 1220 @param name The IOService name, as a const C-string. 1221 @result The matching dictionary created, is returned on success, or zero on failure. The dictionary is commonly passed to IOServiceGetMatchingServices or IOServiceAddNotification which will consume a reference, otherwise it should be released with CFRelease by the caller. */ 1222 1223CFMutableDictionaryRef 1224IOServiceNameMatching( 1225 const char * name ); 1226 1227/*! @function IOBSDNameMatching 1228 @abstract Create a matching dictionary that specifies an IOService match based on BSD device name. 1229 @discussion IOServices that represent BSD devices have an associated BSD name. This function creates a matching dictionary that will match IOService's with a given BSD name. 1230 @param masterPort The master port obtained from IOMasterPort(). Pass kIOMasterPortDefault to look up the default master port. 1231 @param options No options are currently defined. 1232 @param bsdName The BSD name, as a const char *. 1233 @result The matching dictionary created, is returned on success, or zero on failure. The dictionary is commonly passed to IOServiceGetMatchingServices or IOServiceAddNotification which will consume a reference, otherwise it should be released with CFRelease by the caller. */ 1234 1235CFMutableDictionaryRef 1236IOBSDNameMatching( 1237 mach_port_t masterPort, 1238 uint32_t options, 1239 const char * bsdName ); 1240 1241CFMutableDictionaryRef 1242IOOpenFirmwarePathMatching( 1243 mach_port_t masterPort, 1244 uint32_t options, 1245 const char * path ) DEPRECATED_ATTRIBUTE; 1246 1247/*! @function IORegistryEntryIDMatching 1248 @abstract Create a matching dictionary that specifies an IOService match based on a registry entry ID. 1249 @discussion This function creates a matching dictionary that will match a registered, active IOService found with the given registry entry ID. The entry ID for a registry entry is returned by IORegistryEntryGetRegistryEntryID(). 1250 @param entryID The registry entry ID to be found. 1251 @result The matching dictionary created, is returned on success, or zero on failure. The dictionary is commonly passed to IOServiceGetMatchingServices or IOServiceAddNotification which will consume a reference, otherwise it should be released with CFRelease by the caller. */ 1252 1253CFMutableDictionaryRef 1254IORegistryEntryIDMatching( 1255 uint64_t entryID ); 1256 1257/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 1258 1259kern_return_t 1260IOServiceOFPathToBSDName(mach_port_t masterPort, 1261 const io_name_t openFirmwarePath, 1262 io_name_t bsdName) DEPRECATED_ATTRIBUTE; 1263 1264/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 1265 1266/*! @typedef IOAsyncCallback0 1267 @abstract standard callback function for asynchronous I/O requests with 1268 no extra arguments beyond a refcon and result code. 1269 @param refcon The refcon passed into the original I/O request 1270 @param result The result of the I/O operation 1271*/ 1272typedef void (*IOAsyncCallback0)(void *refcon, IOReturn result); 1273 1274/*! @typedef IOAsyncCallback1 1275 @abstract standard callback function for asynchronous I/O requests with 1276 one extra argument beyond a refcon and result code. 1277 This is often a count of the number of bytes transferred 1278 @param refcon The refcon passed into the original I/O request 1279 @param result The result of the I/O operation 1280 @param arg0 Extra argument 1281*/ 1282typedef void (*IOAsyncCallback1)(void *refcon, IOReturn result, void *arg0); 1283 1284/*! @typedef IOAsyncCallback2 1285 @abstract standard callback function for asynchronous I/O requests with 1286 two extra arguments beyond a refcon and result code. 1287 @param refcon The refcon passed into the original I/O request 1288 @param result The result of the I/O operation 1289 @param arg0 Extra argument 1290 @param arg1 Extra argument 1291*/ 1292typedef void (*IOAsyncCallback2)(void *refcon, IOReturn result, void *arg0, void *arg1); 1293 1294/*! @typedef IOAsyncCallback 1295 @abstract standard callback function for asynchronous I/O requests with 1296 lots of extra arguments beyond a refcon and result code. 1297 @param refcon The refcon passed into the original I/O request 1298 @param result The result of the I/O operation 1299 @param args Array of extra arguments 1300 @param numArgs Number of extra arguments 1301*/ 1302typedef void (*IOAsyncCallback)(void *refcon, IOReturn result, void **args, 1303 uint32_t numArgs); 1304 1305 1306/* Internal use */ 1307 1308kern_return_t 1309OSGetNotificationFromMessage( 1310 mach_msg_header_t * msg, 1311 uint32_t index, 1312 uint32_t * type, 1313 uintptr_t * reference, 1314 void ** content, 1315 vm_size_t * size ); 1316 1317/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 1318 1319/* Internal use */ 1320 1321kern_return_t 1322IOCatalogueSendData( 1323 mach_port_t masterPort, 1324 uint32_t flag, 1325 const char *buffer, 1326 uint32_t size ); 1327 1328kern_return_t 1329IOCatalogueTerminate( 1330 mach_port_t masterPort, 1331 uint32_t flag, 1332 io_name_t description ); 1333 1334kern_return_t 1335IOCatalogueGetData( 1336 mach_port_t masterPort, 1337 uint32_t flag, 1338 char **buffer, 1339 uint32_t *size ); 1340 1341kern_return_t 1342IOCatalogueModuleLoaded( 1343 mach_port_t masterPort, 1344 io_name_t name ); 1345 1346/* Use IOCatalogueSendData(), with kIOCatalogResetDrivers, to replace catalogue 1347 * rather than emptying it. Doing so keeps instance counts down by uniquing 1348 * existing personalities. 1349 */ 1350kern_return_t 1351IOCatalogueReset( 1352 mach_port_t masterPort, 1353 uint32_t flag ); 1354 1355/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 1356 1357// obsolete API 1358 1359#if !defined(__LP64__) 1360 1361// for Power Mgt 1362 1363typedef struct IOObject IOObject; 1364 1365// for MacOS.app 1366 1367kern_return_t 1368IORegistryDisposeEnumerator( 1369 io_enumerator_t enumerator ) DEPRECATED_ATTRIBUTE; 1370 1371kern_return_t 1372IOMapMemory( 1373 io_connect_t connect, 1374 uint32_t memoryType, 1375 task_port_t intoTask, 1376 vm_address_t * atAddress, 1377 vm_size_t * ofSize, 1378 uint32_t flags ) DEPRECATED_ATTRIBUTE; 1379 1380// for CGS 1381 1382kern_return_t 1383IOCompatibiltyNumber( 1384 mach_port_t connect, 1385 uint32_t * objectNumber ) DEPRECATED_ATTRIBUTE; 1386 1387// Traditional IOUserClient transport routines 1388kern_return_t 1389IOConnectMethodScalarIScalarO( 1390 io_connect_t connect, 1391 uint32_t index, 1392 IOItemCount scalarInputCount, 1393 IOItemCount scalarOutputCount, 1394 ... ) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_5; 1395 1396kern_return_t 1397IOConnectMethodScalarIStructureO( 1398 io_connect_t connect, 1399 uint32_t index, 1400 IOItemCount scalarInputCount, 1401 IOByteCount * structureSize, 1402 ... ) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_5; 1403 1404kern_return_t 1405IOConnectMethodScalarIStructureI( 1406 io_connect_t connect, 1407 uint32_t index, 1408 IOItemCount scalarInputCount, 1409 IOByteCount structureSize, 1410 ... ) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_5; 1411 1412kern_return_t 1413IOConnectMethodStructureIStructureO( 1414 io_connect_t connect, 1415 uint32_t index, 1416 IOItemCount structureInputSize, 1417 IOByteCount * structureOutputSize, 1418 void * inputStructure, 1419 void * ouputStructure ) AVAILABLE_MAC_OS_X_VERSION_10_0_AND_LATER_BUT_DEPRECATED_IN_MAC_OS_X_VERSION_10_5; 1420 1421// Compatability with earlier Mig interface routines 1422#if IOCONNECT_NO_32B_METHODS 1423 1424kern_return_t 1425io_connect_map_memory( 1426 io_connect_t connect, 1427 uint32_t memoryType, 1428 task_port_t intoTask, 1429 vm_address_t *atAddress, 1430 vm_size_t *ofSize, 1431 IOOptionBits options) DEPRECATED_ATTRIBUTE; 1432 1433kern_return_t 1434io_connect_unmap_memory( 1435 io_connect_t connect, 1436 uint32_t memoryType, 1437 task_port_t fromTask, 1438 vm_address_t atAddress) DEPRECATED_ATTRIBUTE; 1439 1440kern_return_t 1441io_connect_method_scalarI_scalarO( 1442 mach_port_t connection, 1443 int selector, 1444 io_scalar_inband_t input, 1445 mach_msg_type_number_t inputCnt, 1446 io_scalar_inband_t output, 1447 mach_msg_type_number_t *outputCnt) DEPRECATED_ATTRIBUTE; 1448 1449kern_return_t 1450io_connect_method_scalarI_structureO( 1451 mach_port_t connection, 1452 int selector, 1453 io_scalar_inband_t input, 1454 mach_msg_type_number_t inputCnt, 1455 io_struct_inband_t output, 1456 mach_msg_type_number_t *outputCnt) DEPRECATED_ATTRIBUTE; 1457 1458kern_return_t 1459io_connect_method_scalarI_structureI( 1460 mach_port_t connection, 1461 int selector, 1462 io_scalar_inband_t input, 1463 mach_msg_type_number_t inputCnt, 1464 io_struct_inband_t inputStruct, 1465 mach_msg_type_number_t inputStructCnt) DEPRECATED_ATTRIBUTE; 1466 1467kern_return_t 1468io_connect_method_structureI_structureO( 1469 mach_port_t connection, 1470 int selector, 1471 io_struct_inband_t input, 1472 mach_msg_type_number_t inputCnt, 1473 io_struct_inband_t output, 1474 mach_msg_type_number_t *outputCnt) DEPRECATED_ATTRIBUTE; 1475 1476kern_return_t 1477io_async_method_scalarI_scalarO( 1478 mach_port_t connection, 1479 mach_port_t wake_port, 1480 io_async_ref_t reference, 1481 mach_msg_type_number_t referenceCnt, 1482 int selector, 1483 io_scalar_inband_t input, 1484 mach_msg_type_number_t inputCnt, 1485 io_scalar_inband_t output, 1486 mach_msg_type_number_t *outputCnt) DEPRECATED_ATTRIBUTE; 1487 1488kern_return_t 1489io_async_method_scalarI_structureO( 1490 mach_port_t connection, 1491 mach_port_t wake_port, 1492 io_async_ref_t reference, 1493 mach_msg_type_number_t referenceCnt, 1494 int selector, 1495 io_scalar_inband_t input, 1496 mach_msg_type_number_t inputCnt, 1497 io_struct_inband_t output, 1498 mach_msg_type_number_t *outputCnt) DEPRECATED_ATTRIBUTE; 1499 1500kern_return_t 1501io_async_method_scalarI_structureI( 1502 mach_port_t connection, 1503 mach_port_t wake_port, 1504 io_async_ref_t reference, 1505 mach_msg_type_number_t referenceCnt, 1506 int selector, 1507 io_scalar_inband_t input, 1508 mach_msg_type_number_t inputCnt, 1509 io_struct_inband_t inputStruct, 1510 mach_msg_type_number_t inputStructCnt) DEPRECATED_ATTRIBUTE; 1511 1512kern_return_t 1513io_async_method_structureI_structureO( 1514 mach_port_t connection, 1515 mach_port_t wake_port, 1516 io_async_ref_t reference, 1517 mach_msg_type_number_t referenceCnt, 1518 int selector, 1519 io_struct_inband_t input, 1520 mach_msg_type_number_t inputCnt, 1521 io_struct_inband_t output, 1522 mach_msg_type_number_t *outputCnt) DEPRECATED_ATTRIBUTE; 1523#endif // IOCONNECT_NO_32B_METHODS 1524 1525#endif /* defined(__LP64__) */ 1526 1527__END_DECLS 1528 1529#endif /* ! _IOKIT_IOKITLIB_H */ 1530