1*0f4c859eSApple OSS Distributions /* 2*0f4c859eSApple OSS Distributions * Copyright (c) 1998-2019 Apple Inc. All rights reserved. 3*0f4c859eSApple OSS Distributions * 4*0f4c859eSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ 5*0f4c859eSApple OSS Distributions * 6*0f4c859eSApple OSS Distributions * This file contains Original Code and/or Modifications of Original Code 7*0f4c859eSApple OSS Distributions * as defined in and that are subject to the Apple Public Source License 8*0f4c859eSApple OSS Distributions * Version 2.0 (the 'License'). You may not use this file except in 9*0f4c859eSApple OSS Distributions * compliance with the License. The rights granted to you under the License 10*0f4c859eSApple OSS Distributions * may not be used to create, or enable the creation or redistribution of, 11*0f4c859eSApple OSS Distributions * unlawful or unlicensed copies of an Apple operating system, or to 12*0f4c859eSApple OSS Distributions * circumvent, violate, or enable the circumvention or violation of, any 13*0f4c859eSApple OSS Distributions * terms of an Apple operating system software license agreement. 14*0f4c859eSApple OSS Distributions * 15*0f4c859eSApple OSS Distributions * Please obtain a copy of the License at 16*0f4c859eSApple OSS Distributions * http://www.opensource.apple.com/apsl/ and read it before using this file. 17*0f4c859eSApple OSS Distributions * 18*0f4c859eSApple OSS Distributions * The Original Code and all software distributed under the License are 19*0f4c859eSApple OSS Distributions * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 20*0f4c859eSApple OSS Distributions * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 21*0f4c859eSApple OSS Distributions * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 22*0f4c859eSApple OSS Distributions * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 23*0f4c859eSApple OSS Distributions * Please see the License for the specific language governing rights and 24*0f4c859eSApple OSS Distributions * limitations under the License. 25*0f4c859eSApple OSS Distributions * 26*0f4c859eSApple OSS Distributions * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ 27*0f4c859eSApple OSS Distributions */ 28*0f4c859eSApple OSS Distributions 29*0f4c859eSApple OSS Distributions #ifndef __IOKIT_IOWORKLOOP_H 30*0f4c859eSApple OSS Distributions #define __IOKIT_IOWORKLOOP_H 31*0f4c859eSApple OSS Distributions 32*0f4c859eSApple OSS Distributions #include <libkern/c++/OSObject.h> 33*0f4c859eSApple OSS Distributions #include <IOKit/IOReturn.h> 34*0f4c859eSApple OSS Distributions #include <IOKit/IOLib.h> 35*0f4c859eSApple OSS Distributions #include <IOKit/IOLocks.h> 36*0f4c859eSApple OSS Distributions #include <libkern/c++/OSPtr.h> 37*0f4c859eSApple OSS Distributions 38*0f4c859eSApple OSS Distributions #include <IOKit/system.h> 39*0f4c859eSApple OSS Distributions 40*0f4c859eSApple OSS Distributions #if IOKITSTATS 41*0f4c859eSApple OSS Distributions #include <IOKit/IOStatisticsPrivate.h> 42*0f4c859eSApple OSS Distributions #endif 43*0f4c859eSApple OSS Distributions 44*0f4c859eSApple OSS Distributions class IOEventSource; 45*0f4c859eSApple OSS Distributions class IOTimerEventSource; 46*0f4c859eSApple OSS Distributions class IOCommandGate; 47*0f4c859eSApple OSS Distributions 48*0f4c859eSApple OSS Distributions /*! @class IOWorkLoop 49*0f4c859eSApple OSS Distributions * @discussion An IOWorkLoop is a thread of control that is intended to be used to provide single threaded access to hardware. This class has no knowledge of the nature and type of the events that it marshals and forwards. When a device driver successfully starts (see IOService::start), it is expected to create the event sources it will need to receive events. Then a work loop is initialized and the events are added to the work loop for monitoring. In general this set up will be automated by the family superclass of the specific device. 50*0f4c859eSApple OSS Distributions * <br><br> 51*0f4c859eSApple OSS Distributions * The thread main method walks the event source linked list and messages each one requesting a work check. At this point each event source is expected to notify its registered owner that the event has occurred. After each event has been walked and each indicates that another loop isn't required (by setting the 'more' flag to false) the thread will go to sleep on a signaling semaphore. 52*0f4c859eSApple OSS Distributions * <br><br> 53*0f4c859eSApple OSS Distributions * When an event source is registered with a work loop it is informed of the semaphore to use to wake up the loop. 54*0f4c859eSApple OSS Distributions */ 55*0f4c859eSApple OSS Distributions class IOWorkLoop : public OSObject 56*0f4c859eSApple OSS Distributions { 57*0f4c859eSApple OSS Distributions OSDeclareDefaultStructors(IOWorkLoop); 58*0f4c859eSApple OSS Distributions 59*0f4c859eSApple OSS Distributions public: 60*0f4c859eSApple OSS Distributions /*! 61*0f4c859eSApple OSS Distributions * @typedef Action 62*0f4c859eSApple OSS Distributions * @discussion Type and arguments of callout C function that is used when 63*0f4c859eSApple OSS Distributions * a runCommand is executed by a client. Cast to this type when you want a C++ 64*0f4c859eSApple OSS Distributions * member function to be used. Note the arg1 - arg3 parameters are straight pass 65*0f4c859eSApple OSS Distributions * through from the runCommand to the action callout. 66*0f4c859eSApple OSS Distributions * @param target 67*0f4c859eSApple OSS Distributions * Target of the function, can be used as a refcon. Note if a C++ function 68*0f4c859eSApple OSS Distributions * was specified, this parameter is implicitly the first parameter in the target 69*0f4c859eSApple OSS Distributions * member function's parameter list. 70*0f4c859eSApple OSS Distributions * @param arg0 Argument to action from run operation. 71*0f4c859eSApple OSS Distributions * @param arg1 Argument to action from run operation. 72*0f4c859eSApple OSS Distributions * @param arg2 Argument to action from run operation. 73*0f4c859eSApple OSS Distributions * @param arg3 Argument to action from run operation. 74*0f4c859eSApple OSS Distributions */ 75*0f4c859eSApple OSS Distributions typedef IOReturn (*Action)(OSObject *target, 76*0f4c859eSApple OSS Distributions void *arg0, void *arg1, 77*0f4c859eSApple OSS Distributions void *arg2, void *arg3); 78*0f4c859eSApple OSS Distributions 79*0f4c859eSApple OSS Distributions #ifdef __BLOCKS__ 80*0f4c859eSApple OSS Distributions typedef IOReturn (^ActionBlock)(); 81*0f4c859eSApple OSS Distributions #endif /* __BLOCKS__ */ 82*0f4c859eSApple OSS Distributions 83*0f4c859eSApple OSS Distributions enum { 84*0f4c859eSApple OSS Distributions kPreciousStack = 0x00000001, 85*0f4c859eSApple OSS Distributions kTimeLockPanics = 0x00000002, 86*0f4c859eSApple OSS Distributions }; 87*0f4c859eSApple OSS Distributions 88*0f4c859eSApple OSS Distributions private: 89*0f4c859eSApple OSS Distributions /*! @function threadMainContinuation 90*0f4c859eSApple OSS Distributions * @abstract Static function that calls the threadMain function. 91*0f4c859eSApple OSS Distributions */ 92*0f4c859eSApple OSS Distributions static void threadMainContinuation(IOWorkLoop *self); 93*0f4c859eSApple OSS Distributions 94*0f4c859eSApple OSS Distributions /*! @function eventSourcePerformsWork 95*0f4c859eSApple OSS Distributions * @abstract Checks if the event source passed in overrides checkForWork() to perform any work. 96*0f4c859eSApple OSS Distributions * IOWorkLoop uses this to determine if the event source should be polled in runEventSources() or not. 97*0f4c859eSApple OSS Distributions * @param inEventSource The event source to check. 98*0f4c859eSApple OSS Distributions */ 99*0f4c859eSApple OSS Distributions bool eventSourcePerformsWork(IOEventSource *inEventSource); 100*0f4c859eSApple OSS Distributions 101*0f4c859eSApple OSS Distributions /*! @function releaseEventChain 102*0f4c859eSApple OSS Distributions * @abstract Static function that releases the events in a chain and sets 103*0f4c859eSApple OSS Distributions * their work loops to NULL. 104*0f4c859eSApple OSS Distributions */ 105*0f4c859eSApple OSS Distributions static void releaseEventChain(LIBKERN_CONSUMED IOEventSource *eventChain); 106*0f4c859eSApple OSS Distributions 107*0f4c859eSApple OSS Distributions protected: 108*0f4c859eSApple OSS Distributions 109*0f4c859eSApple OSS Distributions /*! @typedef maintCommandEnum 110*0f4c859eSApple OSS Distributions * @discussion Enumeration of commands that _maintCommand can deal with. 111*0f4c859eSApple OSS Distributions * @constant mAddEvent Used to tag a Remove event source command. 112*0f4c859eSApple OSS Distributions * @constant mRemoveEvent Used to tag a Remove event source command. 113*0f4c859eSApple OSS Distributions */ 114*0f4c859eSApple OSS Distributions typedef enum { mAddEvent, mRemoveEvent } maintCommandEnum; 115*0f4c859eSApple OSS Distributions 116*0f4c859eSApple OSS Distributions /*! @var gateLock 117*0f4c859eSApple OSS Distributions * Mutual exclusion lock that is used by close and open Gate functions. 118*0f4c859eSApple OSS Distributions * This is a recursive lock, which allows multiple layers of code to share a single IOWorkLoop without deadlock. This is common in IOKit since threads of execution tend to follow the service plane in the IORegistry, and multiple objects along the call path may acquire the gate for the same (shared) workloop. 119*0f4c859eSApple OSS Distributions */ 120*0f4c859eSApple OSS Distributions IORecursiveLock *gateLock; 121*0f4c859eSApple OSS Distributions 122*0f4c859eSApple OSS Distributions /*! @var eventChain 123*0f4c859eSApple OSS Distributions * Pointer to first event source in linked list. 124*0f4c859eSApple OSS Distributions */ 125*0f4c859eSApple OSS Distributions IOEventSource *eventChain; 126*0f4c859eSApple OSS Distributions 127*0f4c859eSApple OSS Distributions /*! @var controlG 128*0f4c859eSApple OSS Distributions * Internal control gate to maintain event system. 129*0f4c859eSApple OSS Distributions */ 130*0f4c859eSApple OSS Distributions IOCommandGate *controlG; 131*0f4c859eSApple OSS Distributions 132*0f4c859eSApple OSS Distributions /*! @var workToDoLock 133*0f4c859eSApple OSS Distributions * The spin lock that is used to guard the 'workToDo' variable. 134*0f4c859eSApple OSS Distributions */ 135*0f4c859eSApple OSS Distributions IOSimpleLock *workToDoLock; 136*0f4c859eSApple OSS Distributions 137*0f4c859eSApple OSS Distributions /*! @var workThread 138*0f4c859eSApple OSS Distributions * Work loop thread. 139*0f4c859eSApple OSS Distributions */ 140*0f4c859eSApple OSS Distributions IOThread workThread; 141*0f4c859eSApple OSS Distributions 142*0f4c859eSApple OSS Distributions /*! @var workToDo 143*0f4c859eSApple OSS Distributions * Used to to indicate that an interrupt has fired and needs to be processed. 144*0f4c859eSApple OSS Distributions */ 145*0f4c859eSApple OSS Distributions volatile bool workToDo; 146*0f4c859eSApple OSS Distributions 147*0f4c859eSApple OSS Distributions /*! @var loopRestart 148*0f4c859eSApple OSS Distributions * Set if an event chain has been changed and the system has to be rechecked from start. (Internal use only) 149*0f4c859eSApple OSS Distributions */ 150*0f4c859eSApple OSS Distributions bool loopRestart; 151*0f4c859eSApple OSS Distributions 152*0f4c859eSApple OSS Distributions /*! @struct ExpansionData 153*0f4c859eSApple OSS Distributions * @discussion This structure will be used to expand the capablilties of the IOWorkLoop in the future. 154*0f4c859eSApple OSS Distributions */ 155*0f4c859eSApple OSS Distributions struct ExpansionData { 156*0f4c859eSApple OSS Distributions IOOptionBits options; 157*0f4c859eSApple OSS Distributions IOEventSource *passiveEventChain; 158*0f4c859eSApple OSS Distributions #if IOKITSTATS 159*0f4c859eSApple OSS Distributions struct IOWorkLoopCounter *counter; 160*0f4c859eSApple OSS Distributions #else 161*0f4c859eSApple OSS Distributions void *iokitstatsReserved; 162*0f4c859eSApple OSS Distributions #endif 163*0f4c859eSApple OSS Distributions uint64_t lockInterval; 164*0f4c859eSApple OSS Distributions uint64_t lockTime; 165*0f4c859eSApple OSS Distributions }; 166*0f4c859eSApple OSS Distributions 167*0f4c859eSApple OSS Distributions /*! @var reserved 168*0f4c859eSApple OSS Distributions * Reserved for future use. (Internal use only) 169*0f4c859eSApple OSS Distributions */ 170*0f4c859eSApple OSS Distributions ExpansionData *reserved; 171*0f4c859eSApple OSS Distributions 172*0f4c859eSApple OSS Distributions /*! @function _maintRequest 173*0f4c859eSApple OSS Distributions * @abstract Synchronous implementation of addEventSource and removeEventSource functions. 174*0f4c859eSApple OSS Distributions * @discussion This function implements the commands as defined in the maintCommandEnum. It can be subclassed but it isn't an external API in the usual sense. A subclass implementation of _maintRequest would be called synchronously with respect to the work loop and it should be implemented in the usual way that an ioctl would be. 175*0f4c859eSApple OSS Distributions * @return kIOReturnUnsupported if the command given is not implemented, kIOReturnSuccess otherwise. 176*0f4c859eSApple OSS Distributions */ 177*0f4c859eSApple OSS Distributions virtual IOReturn _maintRequest(void *command, void *data, void *, void *); 178*0f4c859eSApple OSS Distributions 179*0f4c859eSApple OSS Distributions /*! @function free 180*0f4c859eSApple OSS Distributions * @discussion Mandatory free of the object independent of the current retain count. If the work loop is running, this method will not return until the thread has successfully terminated. Each event source in the chain will be released and the working semaphore will be destroyed. 181*0f4c859eSApple OSS Distributions * <br><br> 182*0f4c859eSApple OSS Distributions * If the client has some outstanding requests on an event they will never be informed of completion. If an external thread is blocked on any of the event sources they will be awakened with a KERN_INTERUPTED status. 183*0f4c859eSApple OSS Distributions */ 184*0f4c859eSApple OSS Distributions virtual void free() APPLE_KEXT_OVERRIDE; 185*0f4c859eSApple OSS Distributions 186*0f4c859eSApple OSS Distributions /*! @function threadMain 187*0f4c859eSApple OSS Distributions * @discussion Work loop threads main function. This function consists of 3 188*0f4c859eSApple OSS Distributions * loops: the outermost loop is the semaphore clear and wait loop, the middle 189*0f4c859eSApple OSS Distributions * loop terminates when there is no more work, and the inside loop walks the 190*0f4c859eSApple OSS Distributions * event list calling the checkForWork method in each event source. If an 191*0f4c859eSApple OSS Distributions * event source has more work to do, it can set the more flag and the middle 192*0f4c859eSApple OSS Distributions * loop will repeat. When no more work is outstanding the outermost will 193*0f4c859eSApple OSS Distributions * sleep until an event is signalled. 194*0f4c859eSApple OSS Distributions */ 195*0f4c859eSApple OSS Distributions virtual void threadMain(); 196*0f4c859eSApple OSS Distributions 197*0f4c859eSApple OSS Distributions public: 198*0f4c859eSApple OSS Distributions 199*0f4c859eSApple OSS Distributions /*! @function workLoop 200*0f4c859eSApple OSS Distributions * @abstract Factory member function to construct and intialize a work loop. 201*0f4c859eSApple OSS Distributions * @result Returns a workLoop instance if constructed successfully, 0 otherwise. 202*0f4c859eSApple OSS Distributions */ 203*0f4c859eSApple OSS Distributions static OSPtr<IOWorkLoop> workLoop(); 204*0f4c859eSApple OSS Distributions 205*0f4c859eSApple OSS Distributions /*! @function workLoopWithOptions(IOOptionBits options) 206*0f4c859eSApple OSS Distributions * @abstract Factory member function to constuct and intialize a work loop. 207*0f4c859eSApple OSS Distributions * @param options Options - kPreciousStack to avoid stack deallocation on paging path. 208*0f4c859eSApple OSS Distributions * @result Returns a workLoop instance if constructed successfully, 0 otherwise. 209*0f4c859eSApple OSS Distributions */ 210*0f4c859eSApple OSS Distributions static OSPtr<IOWorkLoop> workLoopWithOptions(IOOptionBits options); 211*0f4c859eSApple OSS Distributions 212*0f4c859eSApple OSS Distributions /*! @function init 213*0f4c859eSApple OSS Distributions * @discussion Initializes an instance of the workloop. This method creates and initializes the signaling semaphore, the controller gate lock, and spawns the thread that will continue executing. 214*0f4c859eSApple OSS Distributions * @result Returns true if initialized successfully, false otherwise. 215*0f4c859eSApple OSS Distributions */ 216*0f4c859eSApple OSS Distributions virtual bool init() APPLE_KEXT_OVERRIDE; 217*0f4c859eSApple OSS Distributions 218*0f4c859eSApple OSS Distributions /*! @function getThread 219*0f4c859eSApple OSS Distributions * @abstract Gets the workThread. 220*0f4c859eSApple OSS Distributions * @result Returns workThread. 221*0f4c859eSApple OSS Distributions */ 222*0f4c859eSApple OSS Distributions virtual IOThread getThread() const; 223*0f4c859eSApple OSS Distributions 224*0f4c859eSApple OSS Distributions /*! @function onThread 225*0f4c859eSApple OSS Distributions * @abstract Is the current execution context on the work thread? 226*0f4c859eSApple OSS Distributions * @result Returns true if IOThreadSelf() == workThread. 227*0f4c859eSApple OSS Distributions */ 228*0f4c859eSApple OSS Distributions virtual bool onThread() const; 229*0f4c859eSApple OSS Distributions 230*0f4c859eSApple OSS Distributions /*! @function inGate 231*0f4c859eSApple OSS Distributions * @abstract Is the current execution context holding the work-loop's gate? 232*0f4c859eSApple OSS Distributions * @result Returns true if IOThreadSelf() is gate holder. 233*0f4c859eSApple OSS Distributions */ 234*0f4c859eSApple OSS Distributions virtual bool inGate() const; 235*0f4c859eSApple OSS Distributions 236*0f4c859eSApple OSS Distributions /*! @function addEventSource 237*0f4c859eSApple OSS Distributions * @discussion Add an event source to be monitored by the work loop. This function does not return until the work loop has acknowledged the arrival of the new event source. When a new event has been added the threadMain will always restart its loop and check all outstanding events. The event source is retained by the work loop. 238*0f4c859eSApple OSS Distributions * @param newEvent Pointer to IOEventSource subclass to add. 239*0f4c859eSApple OSS Distributions * @result Always returns kIOReturnSuccess. 240*0f4c859eSApple OSS Distributions */ 241*0f4c859eSApple OSS Distributions virtual IOReturn addEventSource(IOEventSource *newEvent); 242*0f4c859eSApple OSS Distributions 243*0f4c859eSApple OSS Distributions /*! @function removeEventSource 244*0f4c859eSApple OSS Distributions * @discussion Remove an event source from the work loop. This function does not return until the work loop has acknowledged the removal of the event source. When an event has been removed the threadMain will always restart its loop and check all outstanding events. The event source will be released before return. 245*0f4c859eSApple OSS Distributions * @param toRemove Pointer to IOEventSource subclass to remove. 246*0f4c859eSApple OSS Distributions * @result Returns kIOReturnSuccess if successful, kIOReturnBadArgument if toRemove couldn't be found. 247*0f4c859eSApple OSS Distributions */ 248*0f4c859eSApple OSS Distributions virtual IOReturn removeEventSource(IOEventSource *toRemove); 249*0f4c859eSApple OSS Distributions 250*0f4c859eSApple OSS Distributions /*! @function enableAllEventSources 251*0f4c859eSApple OSS Distributions * @abstract Calls enable() in all event sources. 252*0f4c859eSApple OSS Distributions * @discussion For all event sources in eventChain, call enable() function. See IOEventSource::enable(). 253*0f4c859eSApple OSS Distributions */ 254*0f4c859eSApple OSS Distributions virtual void enableAllEventSources() const; 255*0f4c859eSApple OSS Distributions 256*0f4c859eSApple OSS Distributions /*! @function disableAllEventSources 257*0f4c859eSApple OSS Distributions * @abstract Calls disable() in all event sources. 258*0f4c859eSApple OSS Distributions * @discussion For all event sources in eventChain, call disable() function. See IOEventSource::disable(). 259*0f4c859eSApple OSS Distributions */ 260*0f4c859eSApple OSS Distributions virtual void disableAllEventSources() const; 261*0f4c859eSApple OSS Distributions 262*0f4c859eSApple OSS Distributions /*! @function enableAllInterrupts 263*0f4c859eSApple OSS Distributions * @abstract Calls enable() in all interrupt event sources. 264*0f4c859eSApple OSS Distributions * @discussion For all event sources (ES) for which OSDynamicCast(IOInterruptEventSource, ES) is valid, in eventChain call enable() function. See IOEventSource::enable(). 265*0f4c859eSApple OSS Distributions */ 266*0f4c859eSApple OSS Distributions virtual void enableAllInterrupts() const; 267*0f4c859eSApple OSS Distributions 268*0f4c859eSApple OSS Distributions /*! @function disableAllInterrupts 269*0f4c859eSApple OSS Distributions * @abstract Calls disable() in all interrupt event sources. 270*0f4c859eSApple OSS Distributions * @discussion For all event sources (ES) for which OSDynamicCast(IOInterruptEventSource, ES) is valid, in eventChain call disable() function. See IOEventSource::disable(). 271*0f4c859eSApple OSS Distributions */ 272*0f4c859eSApple OSS Distributions virtual void disableAllInterrupts() const; 273*0f4c859eSApple OSS Distributions 274*0f4c859eSApple OSS Distributions 275*0f4c859eSApple OSS Distributions protected: 276*0f4c859eSApple OSS Distributions // Internal APIs used by event sources to control the thread 277*0f4c859eSApple OSS Distributions friend class IOEventSource; 278*0f4c859eSApple OSS Distributions friend class IOTimerEventSource; 279*0f4c859eSApple OSS Distributions friend class IOCommandGate; 280*0f4c859eSApple OSS Distributions #if IOKITSTATS 281*0f4c859eSApple OSS Distributions friend class IOStatistics; 282*0f4c859eSApple OSS Distributions #endif 283*0f4c859eSApple OSS Distributions virtual void signalWorkAvailable(); 284*0f4c859eSApple OSS Distributions virtual void openGate(); 285*0f4c859eSApple OSS Distributions virtual void closeGate(); 286*0f4c859eSApple OSS Distributions virtual bool tryCloseGate(); 287*0f4c859eSApple OSS Distributions virtual int sleepGate(void *event, UInt32 interuptibleType); 288*0f4c859eSApple OSS Distributions virtual void wakeupGate(void *event, bool oneThread); 289*0f4c859eSApple OSS Distributions 290*0f4c859eSApple OSS Distributions public: 291*0f4c859eSApple OSS Distributions /* methods available in Mac OS X 10.1 or later */ 292*0f4c859eSApple OSS Distributions 293*0f4c859eSApple OSS Distributions /*! @function runAction 294*0f4c859eSApple OSS Distributions * @abstract Single thread a call to an action with the work-loop. 295*0f4c859eSApple OSS Distributions * @discussion Client function that causes the given action to be called in a single threaded manner. Beware: the work-loop's gate is recursive and runAction can cause direct or indirect re-entrancy. When executing on a client's thread, runAction will sleep until the work-loop's gate opens for execution of client actions, the action is single threaded against all other work-loop event sources. 296*0f4c859eSApple OSS Distributions * @param action Pointer to function to be executed in work-loop context. 297*0f4c859eSApple OSS Distributions * @param arg0 Parameter for action parameter, defaults to 0. 298*0f4c859eSApple OSS Distributions * @param arg1 Parameter for action parameter, defaults to 0. 299*0f4c859eSApple OSS Distributions * @param arg2 Parameter for action parameter, defaults to 0. 300*0f4c859eSApple OSS Distributions * @param arg3 Parameter for action parameter, defaults to 0. 301*0f4c859eSApple OSS Distributions * @result Returns the value of the Action callout. 302*0f4c859eSApple OSS Distributions */ 303*0f4c859eSApple OSS Distributions virtual IOReturn runAction(Action action, OSObject *target, 304*0f4c859eSApple OSS Distributions void *arg0 = NULL, void *arg1 = NULL, 305*0f4c859eSApple OSS Distributions void *arg2 = NULL, void *arg3 = NULL); 306*0f4c859eSApple OSS Distributions 307*0f4c859eSApple OSS Distributions #ifdef __BLOCKS__ 308*0f4c859eSApple OSS Distributions /*! @function runAction 309*0f4c859eSApple OSS Distributions * @abstract Single thread a call to an action with the work-loop. 310*0f4c859eSApple OSS Distributions * @discussion Client function that causes the given action to be called in a single threaded manner. Beware: the work-loop's gate is recursive and runAction can cause direct or indirect re-entrancy. When executing on a client's thread, runAction will sleep until the work-loop's gate opens for execution of client actions, the action is single threaded against all other work-loop event sources. 311*0f4c859eSApple OSS Distributions * @param action Block to be executed in work-loop context. 312*0f4c859eSApple OSS Distributions * @result Returns the result of the action block. 313*0f4c859eSApple OSS Distributions */ 314*0f4c859eSApple OSS Distributions IOReturn runActionBlock(ActionBlock action); 315*0f4c859eSApple OSS Distributions #endif /* __BLOCKS__ */ 316*0f4c859eSApple OSS Distributions 317*0f4c859eSApple OSS Distributions /*! @function runEventSources 318*0f4c859eSApple OSS Distributions * @discussion Consists of the inner 2 loops of the threadMain function(qv). 319*0f4c859eSApple OSS Distributions * The outer loop terminates when there is no more work, and the inside loop 320*0f4c859eSApple OSS Distributions * walks the event list calling the checkForWork method in each event source. 321*0f4c859eSApple OSS Distributions * If an event source has more work to do, it can set the more flag and the 322*0f4c859eSApple OSS Distributions * outer loop will repeat. 323*0f4c859eSApple OSS Distributions * <br><br> 324*0f4c859eSApple OSS Distributions * This function can be used to clear a priority inversion between the normal 325*0f4c859eSApple OSS Distributions * workloop thread and multimedia's real time threads. The problem is that 326*0f4c859eSApple OSS Distributions * the interrupt action routine is often held off by high priority threads. 327*0f4c859eSApple OSS Distributions * So if they want to get their data now they will have to call us and ask if 328*0f4c859eSApple OSS Distributions * any data is available. The multi-media user client will arrange for this 329*0f4c859eSApple OSS Distributions * function to be called, which causes any pending interrupts to be processed 330*0f4c859eSApple OSS Distributions * and the completion routines called. By the time the function returns all 331*0f4c859eSApple OSS Distributions * outstanding work will have been completed at the real time threads 332*0f4c859eSApple OSS Distributions * priority. 333*0f4c859eSApple OSS Distributions * 334*0f4c859eSApple OSS Distributions * @result Return false if the work loop is shutting down, true otherwise. 335*0f4c859eSApple OSS Distributions */ 336*0f4c859eSApple OSS Distributions virtual bool runEventSources(); 337*0f4c859eSApple OSS Distributions 338*0f4c859eSApple OSS Distributions /*! @function setMaximumLockTime 339*0f4c859eSApple OSS Distributions * @discussion For diagnostics use in DEVELOPMENT kernels, set a time interval which if the work loop lock is held for this time or greater, IOWorkLoop will panic or log a backtrace. 340*0f4c859eSApple OSS Distributions * @param interval An absolute time interval, eg. created with clock_interval_to_absolutetime_interval(). 341*0f4c859eSApple OSS Distributions * @param options Pass IOWorkLoop::kTimeLockPanics to panic when the time is exceeded, otherwise a log will be generated with OSReportWithBacktrace(). 342*0f4c859eSApple OSS Distributions */ 343*0f4c859eSApple OSS Distributions void setMaximumLockTime(uint64_t interval, uint32_t options); 344*0f4c859eSApple OSS Distributions 345*0f4c859eSApple OSS Distributions protected: 346*0f4c859eSApple OSS Distributions // Internal APIs used by event sources to control the thread 347*0f4c859eSApple OSS Distributions virtual int sleepGate(void *event, AbsoluteTime deadline, UInt32 interuptibleType); 348*0f4c859eSApple OSS Distributions 349*0f4c859eSApple OSS Distributions #if XNU_KERNEL_PRIVATE 350*0f4c859eSApple OSS Distributions void lockTime(void); 351*0f4c859eSApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */ 352*0f4c859eSApple OSS Distributions 353*0f4c859eSApple OSS Distributions protected: 354*0f4c859eSApple OSS Distributions #if __LP64__ 355*0f4c859eSApple OSS Distributions OSMetaClassDeclareReservedUnused(IOWorkLoop, 0); 356*0f4c859eSApple OSS Distributions OSMetaClassDeclareReservedUnused(IOWorkLoop, 1); 357*0f4c859eSApple OSS Distributions OSMetaClassDeclareReservedUnused(IOWorkLoop, 2); 358*0f4c859eSApple OSS Distributions #else 359*0f4c859eSApple OSS Distributions OSMetaClassDeclareReservedUsedX86(IOWorkLoop, 0); 360*0f4c859eSApple OSS Distributions OSMetaClassDeclareReservedUsedX86(IOWorkLoop, 1); 361*0f4c859eSApple OSS Distributions OSMetaClassDeclareReservedUsedX86(IOWorkLoop, 2); 362*0f4c859eSApple OSS Distributions #endif 363*0f4c859eSApple OSS Distributions OSMetaClassDeclareReservedUnused(IOWorkLoop, 3); 364*0f4c859eSApple OSS Distributions OSMetaClassDeclareReservedUnused(IOWorkLoop, 4); 365*0f4c859eSApple OSS Distributions OSMetaClassDeclareReservedUnused(IOWorkLoop, 5); 366*0f4c859eSApple OSS Distributions OSMetaClassDeclareReservedUnused(IOWorkLoop, 6); 367*0f4c859eSApple OSS Distributions OSMetaClassDeclareReservedUnused(IOWorkLoop, 7); 368*0f4c859eSApple OSS Distributions }; 369*0f4c859eSApple OSS Distributions 370*0f4c859eSApple OSS Distributions #endif /* !__IOKIT_IOWORKLOOP_H */ 371