]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOCommandGate.cpp
3c7c228549e1f16cb62412e4779dd45c1f3e88b0
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 #include <IOKit/IOCommandGate.h>
29 #include <IOKit/IOWorkLoop.h>
30 #include <IOKit/IOReturn.h>
31 #include <IOKit/IOTimeStamp.h>
33 #define super IOEventSource
35 OSDefineMetaClassAndStructors(IOCommandGate
, IOEventSource
)
36 OSMetaClassDefineReservedUnused(IOCommandGate
, 0);
37 OSMetaClassDefineReservedUnused(IOCommandGate
, 1);
38 OSMetaClassDefineReservedUnused(IOCommandGate
, 2);
39 OSMetaClassDefineReservedUnused(IOCommandGate
, 3);
40 OSMetaClassDefineReservedUnused(IOCommandGate
, 4);
41 OSMetaClassDefineReservedUnused(IOCommandGate
, 5);
42 OSMetaClassDefineReservedUnused(IOCommandGate
, 6);
43 OSMetaClassDefineReservedUnused(IOCommandGate
, 7);
45 bool IOCommandGate::checkForWork() { return false; }
47 bool IOCommandGate::init(OSObject
*inOwner
, Action inAction
)
49 return super::init(inOwner
, (IOEventSource::Action
) inAction
);
53 IOCommandGate::commandGate(OSObject
*inOwner
, Action inAction
)
55 IOCommandGate
*me
= new IOCommandGate
;
57 if (me
&& !me
->init(inOwner
, inAction
)) {
65 IOReturn
IOCommandGate::runCommand(void *arg0
, void *arg1
,
66 void *arg2
, void *arg3
)
71 return kIOReturnNotPermitted
;
74 return kIOReturnNoResources
;
76 // closeGate is recursive so don't worry if we already hold the lock.
77 IOTimeStampConstant(IODBG_CMDQ(IOCMDQ_ACTION
),
78 (unsigned int) action
, (unsigned int) owner
);
81 res
= (*(Action
) action
)(owner
, arg0
, arg1
, arg2
, arg3
);
87 IOReturn
IOCommandGate::runAction(Action inAction
,
88 void *arg0
, void *arg1
,
89 void *arg2
, void *arg3
)
94 return kIOReturnNotPermitted
;
97 return kIOReturnBadArgument
;
99 IOTimeStampConstant(IODBG_CMDQ(IOCMDQ_ACTION
),
100 (unsigned int) inAction
, (unsigned int) owner
);
102 // closeGate is recursive so don't worry if we already hold the lock.
104 res
= (*inAction
)(owner
, arg0
, arg1
, arg2
, arg3
);
110 IOReturn
IOCommandGate::attemptCommand(void *arg0
, void *arg1
,
111 void *arg2
, void *arg3
)
116 return kIOReturnNotPermitted
;
119 return kIOReturnNoResources
;
121 // Try to hold the lock if can't get return immediately.
123 return kIOReturnCannotLock
;
125 // closeGate is recursive so don't worry if we already hold the lock.
126 IOTimeStampConstant(IODBG_CMDQ(IOCMDQ_ACTION
),
127 (unsigned int) action
, (unsigned int) owner
);
129 res
= (*(Action
) action
)(owner
, arg0
, arg1
, arg2
, arg3
);
135 IOReturn
IOCommandGate::attemptAction(Action inAction
,
136 void *arg0
, void *arg1
,
137 void *arg2
, void *arg3
)
142 return kIOReturnNotPermitted
;
145 return kIOReturnBadArgument
;
147 // Try to close the gate if can't get return immediately.
149 return kIOReturnCannotLock
;
151 IOTimeStampConstant(IODBG_CMDQ(IOCMDQ_ACTION
),
152 (unsigned int) inAction
, (unsigned int) owner
);
154 res
= (*inAction
)(owner
, arg0
, arg1
, arg2
, arg3
);
160 IOReturn
IOCommandGate::commandSleep(void *event
, UInt32 interruptible
)
162 if (!workLoop
->inGate())
163 return kIOReturnNotPermitted
;
165 return sleepGate(event
, interruptible
);
168 void IOCommandGate::commandWakeup(void *event
, bool oneThread
)
170 wakeupGate(event
, oneThread
);