]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/IOCommandGate.h
xnu-792.6.56.tar.gz
[apple/xnu.git] / iokit / IOKit / IOCommandGate.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
ff6e181a
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
11 * file.
1c79356b 12 *
ff6e181a
A
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
1c79356b
A
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
ff6e181a
A
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.
1c79356b
A
20 *
21 * @APPLE_LICENSE_HEADER_END@
22 */
23/*[
24 1999-8-10 Godfrey van der Linden(gvdl)
25 Created.
26]*/
27/*! @language embedded-c++ */
28
29#ifndef _IOKIT_IOCOMMANDGATE_H
30#define _IOKIT_IOCOMMANDGATE_H
31
32#include <IOKit/IOEventSource.h>
33
34/*!
35 @class IOCommandGate : public IOEventSource
36 @abstract Single-threaded work-loop client request mechanism.
37 @discussion An IOCommandGate instance is an extremely light way mechanism
38that executes an action on the driver's work-loop. 'On the work-loop' is
39actually a lie but the work-loop single threaded semantic is maintained for this
40event source. Using the work-loop gate rather than execution by the workloop.
41The command gate tests for a potential self dead lock by checking if the
42runCommand request is made from the work-loop's thread, it doens't check for a
43mutual dead lock though where a pair of work loop's dead lock each other.
44<br><br>
45 The IOCommandGate is a lighter weight version of the IOCommandQueue and
46should be used in preference. Generally use a command queue whenever you need a
47client to submit a request to a work loop. A typical command gate action would
48check if the hardware is active, if so it will add the request to a pending
49queue internal to the device or the device's family. Otherwise if the hardware
50is inactive then this request can be acted upon immediately.
51<br><br>
52 CAUTION: The runAction and runCommand functions can not be called from an interrupt context.
53
54*/
55class IOCommandGate : public IOEventSource
56{
57 OSDeclareDefaultStructors(IOCommandGate)
58
59public:
60/*!
61 @typedef Action
62 @discussion Type and arguments of callout C function that is used when
63a runCommand is executed by a client. Cast to this type when you want a C++
64member function to be used. Note the arg1 - arg3 parameters are straight pass
65through from the runCommand to the action callout.
66 @param owner
67 Target of the function, can be used as a refcon. The owner is set
68during initialisation of the IOCommandGate instance. Note if a C++ function
69was specified this parameter is implicitly the first paramter in the target
70member function's parameter list.
71 @param arg0 Argument to action from run operation.
72 @param arg1 Argument to action from run operation.
73 @param arg2 Argument to action from run operation.
74 @param arg3 Argument to action from run operation.
75*/
76 typedef IOReturn (*Action)(OSObject *owner,
77 void *arg0, void *arg1,
78 void *arg2, void *arg3);
79
80protected:
81/*!
82 @function checkForWork
83 @abstract Not used, $link IOEventSource::checkForWork(). */
84 virtual bool checkForWork();
85
86/*! @struct ExpansionData
87 @discussion This structure will be used to expand the capablilties of the IOWorkLoop in the future.
88 */
89 struct ExpansionData { };
90
91/*! @var reserved
92 Reserved for future use. (Internal use only) */
93 ExpansionData *reserved;
94
95public:
96/*! @function commandGate
97 @abstract Factory method to create and initialise an IOCommandGate, See $link init.
98 @result Returns a pointer to the new command gate if sucessful, 0 otherwise. */
99 static IOCommandGate *commandGate(OSObject *owner, Action action = 0);
100
101/*! @function init
102 @abstract Class initialiser.
103 @discussion Initialiser for IOCommandGate operates only on newly 'newed'
104objects. Shouldn't be used to re-init an existing instance.
105 @param owner Owner of this, newly created, instance of the IOCommandGate. This argument will be used as the first parameter in the action callout.
106 @param action
107 Pointer to a C function that is called whenever a client of the
108IOCommandGate calls runCommand. NB Can be a C++ member function but caller
109must cast the member function to $link IOCommandGate::Action and they will get a
110compiler warning. Defaults to zero, see $link IOEventSource::setAction.
111 @result True if inherited classes initialise successfully. */
112 virtual bool init(OSObject *owner, Action action = 0);
113
114/*! @function runCommand
115 @abstract Single thread a command with the target work-loop.
116 @discussion Client function that causes the current action to be called in
117a single threaded manner. Beware the work-loop's gate is recursive and command
118gates can cause direct or indirect re-entrancy. When the executing on a
119client's thread runCommand will sleep until the work-loop's gate opens for
120execution of client actions, the action is single threaded against all other
121work-loop event sources.
122 @param arg0 Parameter for action of command gate, defaults to 0.
123 @param arg1 Parameter for action of command gate, defaults to 0.
124 @param arg2 Parameter for action of command gate, defaults to 0.
125 @param arg3 Parameter for action of command gate, defaults to 0.
126 @result kIOReturnSuccess if successful. kIOReturnNotPermitted if this
127event source is currently disabled, kIOReturnNoResources if no action available.
128*/
129 virtual IOReturn runCommand(void *arg0 = 0, void *arg1 = 0,
130 void *arg2 = 0, void *arg3 = 0);
131
132/*! @function runAction
133 @abstract Single thread a call to an action with the target work-loop.
134 @discussion Client function that causes the given action to be called in
135a single threaded manner. Beware the work-loop's gate is recursive and command
136gates can cause direct or indirect re-entrancy. When the executing on a
0b4e3aa0 137client's thread runAction will sleep until the work-loop's gate opens for
1c79356b
A
138execution of client actions, the action is single threaded against all other
139work-loop event sources.
140 @param action Pointer to function to be executed in work-loop context.
141 @param arg0 Parameter for action parameter, defaults to 0.
142 @param arg1 Parameter for action parameter, defaults to 0.
143 @param arg2 Parameter for action parameter, defaults to 0.
144 @param arg3 Parameter for action parameter, defaults to 0.
145 @result kIOReturnSuccess if successful. kIOReturnBadArgument if action is not defined, kIOReturnNotPermitted if this event source is currently disabled.
146*/
147 virtual IOReturn runAction(Action action,
148 void *arg0 = 0, void *arg1 = 0,
149 void *arg2 = 0, void *arg3 = 0);
150
151/*! @function attemptCommand
152 @abstract Single thread a command with the target work-loop.
153 @discussion Client function that causes the current action to be called in
154a single threaded manner. Beware the work-loop's gate is recursive and command
155gates can cause direct or indirect re-entrancy. When the executing on a
156client's thread attemptCommand will fail if the work-loop's gate is open.
157 @param arg0 Parameter for action of command gate, defaults to 0.
158 @param arg1 Parameter for action of command gate, defaults to 0.
159 @param arg2 Parameter for action of command gate, defaults to 0.
160 @param arg3 Parameter for action of command gate, defaults to 0.
161 @result kIOReturnSuccess if successful. kIOReturnNotPermitted if this event source is currently disabled, kIOReturnNoResources if no action available, kIOReturnCannotLock if lock attempt fails.
162*/
163 virtual IOReturn attemptCommand(void *arg0 = 0, void *arg1 = 0,
164 void *arg2 = 0, void *arg3 = 0);
165
166/*! @function attemptAction
167 @abstract Single thread a call to an action with the target work-loop.
168 @discussion Client function that causes the given action to be called in
169a single threaded manner. Beware the work-loop's gate is recursive and command
170gates can cause direct or indirect re-entrancy. When the executing on a
171client's thread attemptCommand will fail if the work-loop's gate is open.
172 @param action Pointer to function to be executed in work-loop context.
173 @param arg0 Parameter for action parameter, defaults to 0.
174 @param arg1 Parameter for action parameter, defaults to 0.
175 @param arg2 Parameter for action parameter, defaults to 0.
176 @param arg3 Parameter for action parameter, defaults to 0.
177 @result kIOReturnSuccess if successful. kIOReturnBadArgument if action is not defined, kIOReturnNotPermitted if this event source is currently disabled, kIOReturnCannotLock if lock attempt fails.
178
179*/
180 virtual IOReturn attemptAction(Action action,
181 void *arg0 = 0, void *arg1 = 0,
182 void *arg2 = 0, void *arg3 = 0);
183
184/*! @function commandSleep
185 @abstract Put a thread that is currently holding the command gate to sleep.
186 @discussion Put a thread to sleep waiting for an event but release the gate first. If the event occurs then the commandGate is closed before the returns.
187 @param event Pointer to an address.
188 @param interruptible THREAD_UNINT, THREAD_INTERRUPTIBLE or THREAD_ABORTSAFE, defaults to THREAD_ABORTSAFE.
189 @result THREAD_AWAKENED - normal wakeup, THREAD_TIMED_OUT - timeout expired, THREAD_INTERRUPTED - interrupted by clear_wait, THREAD_RESTART - restart operation entirely, kIOReturnNotPermitted if the calling thread does not hold the command gate. */
190 virtual IOReturn commandSleep(void *event,
191 UInt32 interruptible = THREAD_ABORTSAFE);
192
193/*! @function commandWakeup
194 @abstract Wakeup one or more threads that are asleep on an event.
195 @param event Pointer to an address.
196 @param onlyOneThread true to only wake up at most one thread, false otherwise. */
197 virtual void commandWakeup(void *event, bool oneThread = false);
198
199private:
200 OSMetaClassDeclareReservedUnused(IOCommandGate, 0);
201 OSMetaClassDeclareReservedUnused(IOCommandGate, 1);
202 OSMetaClassDeclareReservedUnused(IOCommandGate, 2);
203 OSMetaClassDeclareReservedUnused(IOCommandGate, 3);
204 OSMetaClassDeclareReservedUnused(IOCommandGate, 4);
205 OSMetaClassDeclareReservedUnused(IOCommandGate, 5);
206 OSMetaClassDeclareReservedUnused(IOCommandGate, 6);
207 OSMetaClassDeclareReservedUnused(IOCommandGate, 7);
208};
209
210#endif /* !_IOKIT_IOCOMMANDGATE_H */