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