]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOCommandGate.cpp
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
23 #include <IOKit/IOCommandGate.h>
24 #include <IOKit/IOWorkLoop.h>
25 #include <IOKit/IOReturn.h>
26 #include <IOKit/IOTimeStamp.h>
28 #define super IOEventSource
30 OSDefineMetaClassAndStructors(IOCommandGate
, IOEventSource
)
31 OSMetaClassDefineReservedUnused(IOCommandGate
, 0);
32 OSMetaClassDefineReservedUnused(IOCommandGate
, 1);
33 OSMetaClassDefineReservedUnused(IOCommandGate
, 2);
34 OSMetaClassDefineReservedUnused(IOCommandGate
, 3);
35 OSMetaClassDefineReservedUnused(IOCommandGate
, 4);
36 OSMetaClassDefineReservedUnused(IOCommandGate
, 5);
37 OSMetaClassDefineReservedUnused(IOCommandGate
, 6);
38 OSMetaClassDefineReservedUnused(IOCommandGate
, 7);
40 bool IOCommandGate::checkForWork() { return false; }
42 bool IOCommandGate::init(OSObject
*inOwner
, Action inAction
)
44 return super::init(inOwner
, (IOEventSource::Action
) inAction
);
48 IOCommandGate::commandGate(OSObject
*inOwner
, Action inAction
)
50 IOCommandGate
*me
= new IOCommandGate
;
52 if (me
&& !me
->init(inOwner
, inAction
)) {
60 IOReturn
IOCommandGate::runCommand(void *arg0
, void *arg1
,
61 void *arg2
, void *arg3
)
66 return kIOReturnNotPermitted
;
69 return kIOReturnNoResources
;
71 // closeGate is recursive so don't worry if we already hold the lock.
72 IOTimeStampConstant(IODBG_CMDQ(IOCMDQ_ACTION
),
73 (unsigned int) action
, (unsigned int) owner
);
76 res
= (*(Action
) action
)(owner
, arg0
, arg1
, arg2
, arg3
);
82 IOReturn
IOCommandGate::runAction(Action inAction
,
83 void *arg0
, void *arg1
,
84 void *arg2
, void *arg3
)
89 return kIOReturnNotPermitted
;
92 return kIOReturnBadArgument
;
94 IOTimeStampConstant(IODBG_CMDQ(IOCMDQ_ACTION
),
95 (unsigned int) inAction
, (unsigned int) owner
);
97 // closeGate is recursive so don't worry if we already hold the lock.
99 res
= (*inAction
)(owner
, arg0
, arg1
, arg2
, arg3
);
105 IOReturn
IOCommandGate::attemptCommand(void *arg0
, void *arg1
,
106 void *arg2
, void *arg3
)
111 return kIOReturnNotPermitted
;
114 return kIOReturnNoResources
;
116 // Try to hold the lock if can't get return immediately.
118 return kIOReturnCannotLock
;
120 // closeGate is recursive so don't worry if we already hold the lock.
121 IOTimeStampConstant(IODBG_CMDQ(IOCMDQ_ACTION
),
122 (unsigned int) action
, (unsigned int) owner
);
124 res
= (*(Action
) action
)(owner
, arg0
, arg1
, arg2
, arg3
);
130 IOReturn
IOCommandGate::attemptAction(Action inAction
,
131 void *arg0
, void *arg1
,
132 void *arg2
, void *arg3
)
137 return kIOReturnNotPermitted
;
140 return kIOReturnBadArgument
;
142 // Try to close the gate if can't get return immediately.
144 return kIOReturnCannotLock
;
146 IOTimeStampConstant(IODBG_CMDQ(IOCMDQ_ACTION
),
147 (unsigned int) inAction
, (unsigned int) owner
);
149 res
= (*inAction
)(owner
, arg0
, arg1
, arg2
, arg3
);
155 IOReturn
IOCommandGate::commandSleep(void *event
, UInt32 interruptible
)
157 if (!workLoop
->inGate())
158 return kIOReturnNotPermitted
;
160 return sleepGate(event
, interruptible
);
163 void IOCommandGate::commandWakeup(void *event
, bool oneThread
)
165 wakeupGate(event
, oneThread
);