xref: /xnu-10002.61.3/iokit/IOKit/IOTimerEventSource.h (revision 0f4c859e951fba394238ab619495c4e1d54d0f34)
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  * Copyright (c) 1999 Apple Computer, Inc.  All rights reserved.
30*0f4c859eSApple OSS Distributions  *
31*0f4c859eSApple OSS Distributions  * IOTimerEventSource.h
32*0f4c859eSApple OSS Distributions  *
33*0f4c859eSApple OSS Distributions  * HISTORY
34*0f4c859eSApple OSS Distributions  * 2-Feb-1999		Joe Liu (jliu) created.
35*0f4c859eSApple OSS Distributions  *
36*0f4c859eSApple OSS Distributions  */
37*0f4c859eSApple OSS Distributions 
38*0f4c859eSApple OSS Distributions #ifndef _IOTIMEREVENTSOURCE
39*0f4c859eSApple OSS Distributions #define _IOTIMEREVENTSOURCE
40*0f4c859eSApple OSS Distributions 
41*0f4c859eSApple OSS Distributions #include <sys/cdefs.h>
42*0f4c859eSApple OSS Distributions 
43*0f4c859eSApple OSS Distributions __BEGIN_DECLS
44*0f4c859eSApple OSS Distributions #include <kern/clock.h>
45*0f4c859eSApple OSS Distributions __END_DECLS
46*0f4c859eSApple OSS Distributions 
47*0f4c859eSApple OSS Distributions #include <libkern/c++/OSPtr.h>
48*0f4c859eSApple OSS Distributions #include <IOKit/IOEventSource.h>
49*0f4c859eSApple OSS Distributions #include <IOKit/IOTypes.h>
50*0f4c859eSApple OSS Distributions 
51*0f4c859eSApple OSS Distributions /*!
52*0f4c859eSApple OSS Distributions  *       @enum IOTimerEventSource constructor options
53*0f4c859eSApple OSS Distributions  *       @abstract Constants defining behavior of the IOTimerEventSource.
54*0f4c859eSApple OSS Distributions  *       @constant kIOTimerEventSourceOptionsPriorityHigh Importance above everything but realtime.
55*0f4c859eSApple OSS Distributions  *       Thread calls allocated with this priority execute at extremely high priority,
56*0f4c859eSApple OSS Distributions  *       above everything but realtime threads.  They are generally executed in serial.
57*0f4c859eSApple OSS Distributions  *       Though they may execute concurrently under some circumstances, no fan-out is implied.
58*0f4c859eSApple OSS Distributions  *       These work items should do very small amounts of work or risk disrupting system
59*0f4c859eSApple OSS Distributions  *       responsiveness.
60*0f4c859eSApple OSS Distributions  *       @constant kIOTimerEventSourceOptionsPriorityKernelHigh Importance higher than most kernel
61*0f4c859eSApple OSS Distributions  *       threads.
62*0f4c859eSApple OSS Distributions  *       @constant kIOTimerEventSourceOptionsPriorityKernel Importance similar to that of normal kernel
63*0f4c859eSApple OSS Distributions  *       threads.
64*0f4c859eSApple OSS Distributions  *       @constant kIOTimerEventSourceOptionsPriorityUser Importance similar to that of normal user threads.
65*0f4c859eSApple OSS Distributions  *       @constant kIOTimerEventSourceOptionsPriorityLow Very low importance.
66*0f4c859eSApple OSS Distributions  *       @constant kIOTimerEventSourceOptionsPriorityWorkLoop Run the callout on the thread of the IOWorkLoop
67*0f4c859eSApple OSS Distributions  *       the event source has been added to.
68*0f4c859eSApple OSS Distributions  *       @constant kIOTimerEventSourceOptionsAllowReenter Allow the callout to be rescheduled and potentially
69*0f4c859eSApple OSS Distributions  *       re-entered, if the IOWorkLoop lock has been released (eg. with commandSleep) during its invocation.
70*0f4c859eSApple OSS Distributions  *       @constant kIOTimerEventSourceOptionsDefault Recommended default options.
71*0f4c859eSApple OSS Distributions  */
72*0f4c859eSApple OSS Distributions enum{
73*0f4c859eSApple OSS Distributions 	kIOTimerEventSourceOptionsPriorityMask       = 0x000000ff,
74*0f4c859eSApple OSS Distributions 	kIOTimerEventSourceOptionsPriorityHigh       = 0x00000000,
75*0f4c859eSApple OSS Distributions 	kIOTimerEventSourceOptionsPriorityKernelHigh = 0x00000001,
76*0f4c859eSApple OSS Distributions 	kIOTimerEventSourceOptionsPriorityKernel     = 0x00000002,
77*0f4c859eSApple OSS Distributions 	kIOTimerEventSourceOptionsPriorityUser       = 0x00000003,
78*0f4c859eSApple OSS Distributions 	kIOTimerEventSourceOptionsPriorityLow        = 0x00000004,
79*0f4c859eSApple OSS Distributions 	kIOTimerEventSourceOptionsPriorityWorkLoop   = 0x000000ff,
80*0f4c859eSApple OSS Distributions 
81*0f4c859eSApple OSS Distributions 	kIOTimerEventSourceOptionsAllowReenter       = 0x00000100,
82*0f4c859eSApple OSS Distributions 
83*0f4c859eSApple OSS Distributions 	kIOTimerEventSourceOptionsDefault            = kIOTimerEventSourceOptionsPriorityKernelHigh
84*0f4c859eSApple OSS Distributions };
85*0f4c859eSApple OSS Distributions 
86*0f4c859eSApple OSS Distributions #define IOTIMEREVENTSOURCEOPTIONS_DEFINED       1
87*0f4c859eSApple OSS Distributions 
88*0f4c859eSApple OSS Distributions /*!
89*0f4c859eSApple OSS Distributions  *       @enum IOTimerEventSource setTimeout/wakeAtTime options
90*0f4c859eSApple OSS Distributions  *       @abstract Constants defining behavior of a scheduled call from IOTimerEventSource.
91*0f4c859eSApple OSS Distributions  *       @constant kIOTimeOptionsWithLeeway Use the leeway parameter to the call.
92*0f4c859eSApple OSS Distributions  *       @constant kIOTimeOptionsContinuous Use mach_continuous_time() to generate the callback.
93*0f4c859eSApple OSS Distributions  */
94*0f4c859eSApple OSS Distributions enum{
95*0f4c859eSApple OSS Distributions 	kIOTimeOptionsWithLeeway = 0x00000020,
96*0f4c859eSApple OSS Distributions 	kIOTimeOptionsContinuous = 0x00000100,
97*0f4c859eSApple OSS Distributions };
98*0f4c859eSApple OSS Distributions 
99*0f4c859eSApple OSS Distributions /*!
100*0f4c859eSApple OSS Distributions  *   @class IOTimerEventSource : public IOEventSource
101*0f4c859eSApple OSS Distributions  *   @abstract Time based event source mechanism.
102*0f4c859eSApple OSS Distributions  *   @discussion An event source that implements a simple timer.	 A timeout handler is called once the timeout period expires.  This timeout handler will be called by the work-loop that this event source is attached to.
103*0f4c859eSApple OSS Distributions  *  <br><br>
104*0f4c859eSApple OSS Distributions  *       Usually a timer event source will be used to implement a timeout.  In general when a driver makes a request it will need to setup a call to keep track of when the I/O doesn't complete.  This class is designed to make that somewhat easier.
105*0f4c859eSApple OSS Distributions  *  <br><br>
106*0f4c859eSApple OSS Distributions  *       Remember the system doesn't guarantee the accuracy of the callout.	It is possible that a higher priority thread is running which will delay the execution of the action routine.  In fact the thread will be made runable at the exact requested time, within the accuracy of the CPU's decrementer based interrupt, but the scheduler will then control execution.
107*0f4c859eSApple OSS Distributions  */
108*0f4c859eSApple OSS Distributions 
109*0f4c859eSApple OSS Distributions class IOTimerEventSource : public IOEventSource
110*0f4c859eSApple OSS Distributions {
111*0f4c859eSApple OSS Distributions 	OSDeclareDefaultStructors(IOTimerEventSource);
112*0f4c859eSApple OSS Distributions 
113*0f4c859eSApple OSS Distributions protected:
114*0f4c859eSApple OSS Distributions /*! @var calloutEntry thread_call entry for preregistered thread callouts */
115*0f4c859eSApple OSS Distributions 	void *calloutEntry;
116*0f4c859eSApple OSS Distributions 
117*0f4c859eSApple OSS Distributions /*! @var abstime time to wake up next, see enable. */
118*0f4c859eSApple OSS Distributions 	AbsoluteTime abstime;
119*0f4c859eSApple OSS Distributions 
120*0f4c859eSApple OSS Distributions /*! @struct ExpansionData
121*0f4c859eSApple OSS Distributions  *   @discussion This structure is private to the IOTimerEventSource implementation.
122*0f4c859eSApple OSS Distributions  */
123*0f4c859eSApple OSS Distributions 	struct ExpansionData {
124*0f4c859eSApple OSS Distributions 		SInt32       calloutGeneration;
125*0f4c859eSApple OSS Distributions 		SInt32       calloutGenerationSignaled;
126*0f4c859eSApple OSS Distributions 		IOWorkLoop * workLoop;
127*0f4c859eSApple OSS Distributions 	};
128*0f4c859eSApple OSS Distributions 
129*0f4c859eSApple OSS Distributions /*! @var reserved
130*0f4c859eSApple OSS Distributions  *   Reserved for future use.  (Internal use only)  */
131*0f4c859eSApple OSS Distributions 	APPLE_KEXT_WSHADOW_PUSH;
132*0f4c859eSApple OSS Distributions 	ExpansionData *reserved;
133*0f4c859eSApple OSS Distributions 	APPLE_KEXT_WSHADOW_POP;
134*0f4c859eSApple OSS Distributions 
135*0f4c859eSApple OSS Distributions /*! @function timeout
136*0f4c859eSApple OSS Distributions  *   @abstract Function that routes the call from the OS' timeout mechanism into a work-loop context.
137*0f4c859eSApple OSS Distributions  *   @discussion timeout will normally not be called nor overridden by a subclass.  If the event source is enabled then close the work-loop's gate and call the action routine.
138*0f4c859eSApple OSS Distributions  *   @param self This argument will be cast to an IOTimerEventSource. */
139*0f4c859eSApple OSS Distributions 	static void timeout(void *self);
140*0f4c859eSApple OSS Distributions 
141*0f4c859eSApple OSS Distributions /*! @function setTimeoutFunc
142*0f4c859eSApple OSS Distributions  *   @abstract Set's timeout as the function of calloutEntry.
143*0f4c859eSApple OSS Distributions  *   @discussion IOTimerEventSource is based upon the kern/thread_call.h APIs currently.	 This function allocates the calloutEntry member variable by using thread_call_allocate(timeout, this).	 If you need to write your own subclass of IOTimerEventSource you probably should override this method to allocate an entry that points to your own timeout routine. */
144*0f4c859eSApple OSS Distributions 	virtual void setTimeoutFunc();
145*0f4c859eSApple OSS Distributions 
146*0f4c859eSApple OSS Distributions /*! @function free
147*0f4c859eSApple OSS Distributions  *   @abstract Sub-class implementation of free method, frees calloutEntry */
148*0f4c859eSApple OSS Distributions 	virtual void free() APPLE_KEXT_OVERRIDE;
149*0f4c859eSApple OSS Distributions 
150*0f4c859eSApple OSS Distributions 	virtual void setWorkLoop(IOWorkLoop *workLoop) APPLE_KEXT_OVERRIDE;
151*0f4c859eSApple OSS Distributions 
152*0f4c859eSApple OSS Distributions public:
153*0f4c859eSApple OSS Distributions 
154*0f4c859eSApple OSS Distributions /*! @typedef Action
155*0f4c859eSApple OSS Distributions  *   @discussion 'C' Function pointer defining the callout routine of this event source.
156*0f4c859eSApple OSS Distributions  *   @param owner Owning target object.	Note by a startling coincidence the first parameter in a C callout is currently used to define the target of a C++ member function.
157*0f4c859eSApple OSS Distributions  *   @param sender The object that timed out. */
158*0f4c859eSApple OSS Distributions 	typedef void (*Action)(OSObject *owner, IOTimerEventSource *sender);
159*0f4c859eSApple OSS Distributions 
160*0f4c859eSApple OSS Distributions #ifdef __BLOCKS__
161*0f4c859eSApple OSS Distributions 	typedef void (^ActionBlock)(IOTimerEventSource *sender);
162*0f4c859eSApple OSS Distributions #endif /* __BLOCKS__ */
163*0f4c859eSApple OSS Distributions 
164*0f4c859eSApple OSS Distributions 	static OSPtr<IOTimerEventSource>
165*0f4c859eSApple OSS Distributions 	timerEventSource(OSObject *owner, Action action = NULL);
166*0f4c859eSApple OSS Distributions 
167*0f4c859eSApple OSS Distributions /*! @function timerEventSource
168*0f4c859eSApple OSS Distributions  *   @abstract Allocates and returns an initialized timer instance.
169*0f4c859eSApple OSS Distributions  *   @param options Mask of kIOTimerEventSourceOptions* options.
170*0f4c859eSApple OSS Distributions  *   @param owner The object that that will be passed to the Action callback.
171*0f4c859eSApple OSS Distributions  *   @param action 'C' Function pointer for the callout routine of this event source.
172*0f4c859eSApple OSS Distributions  */
173*0f4c859eSApple OSS Distributions 	static OSPtr<IOTimerEventSource>
174*0f4c859eSApple OSS Distributions 	timerEventSource(uint32_t options, OSObject *owner, Action action = NULL);
175*0f4c859eSApple OSS Distributions 
176*0f4c859eSApple OSS Distributions #ifdef __BLOCKS__
177*0f4c859eSApple OSS Distributions /*! @function timerEventSource
178*0f4c859eSApple OSS Distributions  *   @abstract Allocates and returns an initialized timer instance.
179*0f4c859eSApple OSS Distributions  *   @param options Mask of kIOTimerEventSourceOptions* options.
180*0f4c859eSApple OSS Distributions  *   @param inOwner The object that that will be passed to the Action callback.
181*0f4c859eSApple OSS Distributions  *   @param action Block for the callout routine of this event source.
182*0f4c859eSApple OSS Distributions  */
183*0f4c859eSApple OSS Distributions 	static OSPtr<IOTimerEventSource>
184*0f4c859eSApple OSS Distributions 	timerEventSource(uint32_t options, OSObject *inOwner, ActionBlock action);
185*0f4c859eSApple OSS Distributions #endif /* __BLOCKS__ */
186*0f4c859eSApple OSS Distributions 
187*0f4c859eSApple OSS Distributions #if XNU_KERNEL_PRIVATE
188*0f4c859eSApple OSS Distributions 	__inline__ void invokeAction(IOEventSource::Action action, IOTimerEventSource * ts,
189*0f4c859eSApple OSS Distributions 	    OSObject * owner, IOWorkLoop * workLoop);
190*0f4c859eSApple OSS Distributions #endif /* XNU_KERNEL_PRIVATE */
191*0f4c859eSApple OSS Distributions 
192*0f4c859eSApple OSS Distributions /*! @function init
193*0f4c859eSApple OSS Distributions  *   @abstract Initializes the timer with an owner, and a handler to call when the timeout expires.
194*0f4c859eSApple OSS Distributions  */
195*0f4c859eSApple OSS Distributions 	virtual bool init(OSObject *owner, Action action = NULL);
196*0f4c859eSApple OSS Distributions 
197*0f4c859eSApple OSS Distributions /*! @function enable
198*0f4c859eSApple OSS Distributions  *   @abstract Enables a call to the action.
199*0f4c859eSApple OSS Distributions  *   @discussion Allows the action function to be called.  If the timer event source was disabled while a call was outstanding and the call wasn't cancelled then it will be rescheduled.  So a disable/enable pair will disable calls from this event source. */
200*0f4c859eSApple OSS Distributions 	virtual void enable() APPLE_KEXT_OVERRIDE;
201*0f4c859eSApple OSS Distributions 
202*0f4c859eSApple OSS Distributions /*! @function disable
203*0f4c859eSApple OSS Distributions  *   @abstract Disable a timed callout.
204*0f4c859eSApple OSS Distributions  *   @discussion When disable returns the action will not be called until the next time enable(qv) is called. */
205*0f4c859eSApple OSS Distributions 	virtual void disable() APPLE_KEXT_OVERRIDE;
206*0f4c859eSApple OSS Distributions 
207*0f4c859eSApple OSS Distributions /*! @function checkForWork
208*0f4c859eSApple OSS Distributions  *   @abstract Pure Virtual member function used by IOWorkLoop for issuing a client calls.
209*0f4c859eSApple OSS Distributions  *   @discussion This function called when the work-loop is ready to check for any work to do and then to call out the owner/action.
210*0f4c859eSApple OSS Distributions  *   @result Return true if this function needs to be called again before all its outstanding events have been processed. */
211*0f4c859eSApple OSS Distributions 	virtual bool checkForWork() APPLE_KEXT_OVERRIDE;
212*0f4c859eSApple OSS Distributions 
213*0f4c859eSApple OSS Distributions /*! @function setTimeoutTicks
214*0f4c859eSApple OSS Distributions  *   @abstract Setup a callback at after the delay in scheduler ticks.  See wakeAtTime(AbsoluteTime).
215*0f4c859eSApple OSS Distributions  *   @param ticks Delay from now to wake up, in scheduler ticks, whatever that may be.
216*0f4c859eSApple OSS Distributions  *   @result kIOReturnSuccess if everything is fine, kIOReturnNoResources if action hasn't been declared. */
217*0f4c859eSApple OSS Distributions 	virtual IOReturn setTimeoutTicks(UInt32 ticks);
218*0f4c859eSApple OSS Distributions 
219*0f4c859eSApple OSS Distributions /*! @function setTimeoutMS
220*0f4c859eSApple OSS Distributions  *   @abstract Setup a callback at after the delay in milliseconds.  See wakeAtTime(AbsoluteTime).
221*0f4c859eSApple OSS Distributions  *   @param ms Delay from now to wake up, time in milliseconds.
222*0f4c859eSApple OSS Distributions  *   @result kIOReturnSuccess if everything is fine, kIOReturnNoResources if action hasn't been declared. */
223*0f4c859eSApple OSS Distributions 	virtual IOReturn setTimeoutMS(UInt32 ms);
224*0f4c859eSApple OSS Distributions 
225*0f4c859eSApple OSS Distributions /*! @function setTimeoutUS
226*0f4c859eSApple OSS Distributions  *       @abstract Setup a callback at after the delay in microseconds.	 See wakeAtTime(AbsoluteTime).
227*0f4c859eSApple OSS Distributions  *   @param us Delay from now to wake up, time in microseconds.
228*0f4c859eSApple OSS Distributions  *   @result kIOReturnSuccess if everything is fine, kIOReturnNoResources if action hasn't been declared. */
229*0f4c859eSApple OSS Distributions 	virtual IOReturn setTimeoutUS(UInt32 us);
230*0f4c859eSApple OSS Distributions 
231*0f4c859eSApple OSS Distributions /*! @function setTimeout
232*0f4c859eSApple OSS Distributions  *   @abstract Setup a callback at after the delay in some unit.	 See wakeAtTime(AbsoluteTime).
233*0f4c859eSApple OSS Distributions  *   @param interval Delay from now to wake up in some defined unit.
234*0f4c859eSApple OSS Distributions  *   @param scale_factor Define the unit of interval, default to nanoseconds.
235*0f4c859eSApple OSS Distributions  *   @result kIOReturnSuccess if everything is fine, kIOReturnNoResources if action hasn't been declared. */
236*0f4c859eSApple OSS Distributions 	virtual IOReturn setTimeout(UInt32 interval,
237*0f4c859eSApple OSS Distributions 	    UInt32 scale_factor = kNanosecondScale);
238*0f4c859eSApple OSS Distributions 
239*0f4c859eSApple OSS Distributions #if !defined(__LP64__)
240*0f4c859eSApple OSS Distributions 	virtual IOReturn setTimeout(mach_timespec_t interval)
241*0f4c859eSApple OSS Distributions 	APPLE_KEXT_DEPRECATED;
242*0f4c859eSApple OSS Distributions #endif
243*0f4c859eSApple OSS Distributions 
244*0f4c859eSApple OSS Distributions /*! @function setTimeout
245*0f4c859eSApple OSS Distributions  *   @abstract Setup a callback at after the delay in decrementer ticks.	 See wakeAtTime(AbsoluteTime).
246*0f4c859eSApple OSS Distributions  *   @param interval Delay from now to wake up in decrementer ticks.
247*0f4c859eSApple OSS Distributions  *   @result kIOReturnSuccess if everything is fine, kIOReturnNoResources if action hasn't been declared. */
248*0f4c859eSApple OSS Distributions 	virtual IOReturn setTimeout(AbsoluteTime interval);
249*0f4c859eSApple OSS Distributions 
250*0f4c859eSApple OSS Distributions /*! @function wakeAtTimeTicks
251*0f4c859eSApple OSS Distributions  *   @abstract Setup a callback at this absolute time.  See wakeAtTime(AbsoluteTime).
252*0f4c859eSApple OSS Distributions  *   @param ticks Time to wake up in scheduler quantums, whatever that is?
253*0f4c859eSApple OSS Distributions  *   @result kIOReturnSuccess if everything is fine, kIOReturnNoResources if action hasn't been declared. */
254*0f4c859eSApple OSS Distributions 	virtual IOReturn wakeAtTimeTicks(UInt32 ticks);
255*0f4c859eSApple OSS Distributions 
256*0f4c859eSApple OSS Distributions /*! @function wakeAtTimeMS
257*0f4c859eSApple OSS Distributions  *   @abstract Setup a callback at this absolute time.  See wakeAtTime(AbsoluteTime).
258*0f4c859eSApple OSS Distributions  *   @param ms Time to wake up in milliseconds.
259*0f4c859eSApple OSS Distributions  *   @result kIOReturnSuccess if everything is fine, kIOReturnNoResources if action hasn't been declared. */
260*0f4c859eSApple OSS Distributions 	virtual IOReturn wakeAtTimeMS(UInt32 ms);
261*0f4c859eSApple OSS Distributions 
262*0f4c859eSApple OSS Distributions /*! @function wakeAtTimeUS
263*0f4c859eSApple OSS Distributions  *   @abstract Setup a callback at this absolute time.  See wakeAtTime(AbsoluteTime).
264*0f4c859eSApple OSS Distributions  *   @param us Time to wake up in microseconds.
265*0f4c859eSApple OSS Distributions  *   @result kIOReturnSuccess if everything is fine, kIOReturnNoResources if action hasn't been declared. */
266*0f4c859eSApple OSS Distributions 	virtual IOReturn wakeAtTimeUS(UInt32 us);
267*0f4c859eSApple OSS Distributions 
268*0f4c859eSApple OSS Distributions /*! @function wakeAtTime
269*0f4c859eSApple OSS Distributions  *   @abstract Setup a callback at this absolute time.  See wakeAtTime(AbsoluteTime).
270*0f4c859eSApple OSS Distributions  *   @param abstime Time to wake up in some unit.
271*0f4c859eSApple OSS Distributions  *   @param scale_factor Define the unit of abstime, default to nanoseconds.
272*0f4c859eSApple OSS Distributions  *   @result kIOReturnSuccess if everything is fine, kIOReturnNoResources if action hasn't been declared. */
273*0f4c859eSApple OSS Distributions 	virtual IOReturn wakeAtTime(UInt32 abstime,
274*0f4c859eSApple OSS Distributions 	    UInt32 scale_factor = kNanosecondScale);
275*0f4c859eSApple OSS Distributions 
276*0f4c859eSApple OSS Distributions #if !defined(__LP64__)
277*0f4c859eSApple OSS Distributions 	virtual IOReturn wakeAtTime(mach_timespec_t abstime)
278*0f4c859eSApple OSS Distributions 	APPLE_KEXT_DEPRECATED;
279*0f4c859eSApple OSS Distributions #endif
280*0f4c859eSApple OSS Distributions 
281*0f4c859eSApple OSS Distributions /*! @function wakeAtTime
282*0f4c859eSApple OSS Distributions  *   @abstract Setup a callback at this absolute time.
283*0f4c859eSApple OSS Distributions  *   @discussion Starts the timer, which will expire at abstime. After it expires, the timer will call the 'action' registered in the init() function. This timer is not periodic, a further call is needed to reset and restart the timer after it expires.
284*0f4c859eSApple OSS Distributions  *   @param abstime Absolute Time when to wake up, counted in 'decrementer' units and starts at zero when system boots.
285*0f4c859eSApple OSS Distributions  *   @result kIOReturnSuccess if everything is fine, kIOReturnNoResources if action hasn't been declared by init or IOEventSource::setAction (qqv). */
286*0f4c859eSApple OSS Distributions 	virtual IOReturn wakeAtTime(AbsoluteTime abstime);
287*0f4c859eSApple OSS Distributions 
288*0f4c859eSApple OSS Distributions /*! @function cancelTimeout
289*0f4c859eSApple OSS Distributions  *   @abstract Disable any outstanding calls to this event source.
290*0f4c859eSApple OSS Distributions  *   @discussion Clear down any oustanding calls.  By the time this function completes it is guaranteed that the action will not be called again. */
291*0f4c859eSApple OSS Distributions 	virtual void cancelTimeout();
292*0f4c859eSApple OSS Distributions 
293*0f4c859eSApple OSS Distributions /*! @function init
294*0f4c859eSApple OSS Distributions  *   @abstract Initializes the timer with an owner, and a handler to call when the timeout expires.
295*0f4c859eSApple OSS Distributions  */
296*0f4c859eSApple OSS Distributions 	virtual bool init(uint32_t options, OSObject *inOwner, Action inAction);
297*0f4c859eSApple OSS Distributions 
298*0f4c859eSApple OSS Distributions /*! @function setTimeout
299*0f4c859eSApple OSS Distributions  *   @abstract Setup a callback at after the delay in decrementer ticks.	 See wakeAtTime(AbsoluteTime).
300*0f4c859eSApple OSS Distributions  *   @param options see kIOTimeOptionsWithLeeway and kIOTimeOptionsContinuous
301*0f4c859eSApple OSS Distributions  *   @param interval Delay from now to wake up in decrementer ticks.
302*0f4c859eSApple OSS Distributions  *   @param leeway Allowable leeway to wake time, if the kIOTimeOptionsWithLeeway option is set
303*0f4c859eSApple OSS Distributions  *   @result kIOReturnSuccess if everything is fine, kIOReturnNoResources if action hasn't been declared. */
304*0f4c859eSApple OSS Distributions 	virtual IOReturn setTimeout(uint32_t options, AbsoluteTime interval, AbsoluteTime leeway);
305*0f4c859eSApple OSS Distributions 
306*0f4c859eSApple OSS Distributions /*! @function wakeAtTime
307*0f4c859eSApple OSS Distributions  *   @abstract Setup a callback at this absolute time.
308*0f4c859eSApple OSS Distributions  *   @discussion Starts the timer, which will expire at abstime. After it expires, the timer will call the 'action' registered in the init() function. This timer is not periodic, a further call is needed to reset and restart the timer after it expires.
309*0f4c859eSApple OSS Distributions  *   @param options see kIOTimeOptionsWithLeeway and kIOTimeOptionsContinuous
310*0f4c859eSApple OSS Distributions  *   @param abstime Absolute Time when to wake up, counted in 'decrementer' units and starts at zero when system boots.
311*0f4c859eSApple OSS Distributions  *   @param leeway Allowable leeway to wake time, if the kIOTimeOptionsWithLeeway option is set
312*0f4c859eSApple OSS Distributions  *   @result kIOReturnSuccess if everything is fine, kIOReturnNoResources if action hasn't been declared by init or IOEventSource::setAction (qqv). */
313*0f4c859eSApple OSS Distributions 	virtual IOReturn wakeAtTime(uint32_t options, AbsoluteTime abstime, AbsoluteTime leeway);
314*0f4c859eSApple OSS Distributions 
315*0f4c859eSApple OSS Distributions private:
316*0f4c859eSApple OSS Distributions 	static void timeoutAndRelease(void *self, void *c);
317*0f4c859eSApple OSS Distributions 	static void timeoutSignaled(void *self, void *c);
318*0f4c859eSApple OSS Distributions 
319*0f4c859eSApple OSS Distributions private:
320*0f4c859eSApple OSS Distributions 	OSMetaClassDeclareReservedUsedX86(IOTimerEventSource, 0);
321*0f4c859eSApple OSS Distributions 	OSMetaClassDeclareReservedUsedX86(IOTimerEventSource, 1);
322*0f4c859eSApple OSS Distributions 	OSMetaClassDeclareReservedUsedX86(IOTimerEventSource, 2);
323*0f4c859eSApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOTimerEventSource, 3);
324*0f4c859eSApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOTimerEventSource, 4);
325*0f4c859eSApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOTimerEventSource, 5);
326*0f4c859eSApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOTimerEventSource, 6);
327*0f4c859eSApple OSS Distributions 	OSMetaClassDeclareReservedUnused(IOTimerEventSource, 7);
328*0f4c859eSApple OSS Distributions };
329*0f4c859eSApple OSS Distributions 
330*0f4c859eSApple OSS Distributions #endif /* !_IOTIMEREVENTSOURCE */
331