]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOCommandGate.cpp
9578feacf2b77a904d5e2ede2903136ca5c3ce46
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
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
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 #include <IOKit/IOCommandGate.h>
31 #include <IOKit/IOWorkLoop.h>
32 #include <IOKit/IOReturn.h>
33 #include <IOKit/IOTimeStamp.h>
35 #define super IOEventSource
37 OSDefineMetaClassAndStructors(IOCommandGate
, IOEventSource
)
38 OSMetaClassDefineReservedUnused(IOCommandGate
, 0);
39 OSMetaClassDefineReservedUnused(IOCommandGate
, 1);
40 OSMetaClassDefineReservedUnused(IOCommandGate
, 2);
41 OSMetaClassDefineReservedUnused(IOCommandGate
, 3);
42 OSMetaClassDefineReservedUnused(IOCommandGate
, 4);
43 OSMetaClassDefineReservedUnused(IOCommandGate
, 5);
44 OSMetaClassDefineReservedUnused(IOCommandGate
, 6);
45 OSMetaClassDefineReservedUnused(IOCommandGate
, 7);
47 bool IOCommandGate::checkForWork() { return false; }
49 bool IOCommandGate::init(OSObject
*inOwner
, Action inAction
)
51 return super::init(inOwner
, (IOEventSource::Action
) inAction
);
55 IOCommandGate::commandGate(OSObject
*inOwner
, Action inAction
)
57 IOCommandGate
*me
= new IOCommandGate
;
59 if (me
&& !me
->init(inOwner
, inAction
)) {
67 IOReturn
IOCommandGate::runCommand(void *arg0
, void *arg1
,
68 void *arg2
, void *arg3
)
73 return kIOReturnNotPermitted
;
76 return kIOReturnNoResources
;
78 // closeGate is recursive so don't worry if we already hold the lock.
79 IOTimeStampConstant(IODBG_CMDQ(IOCMDQ_ACTION
),
80 (unsigned int) action
, (unsigned int) owner
);
83 res
= (*(Action
) action
)(owner
, arg0
, arg1
, arg2
, arg3
);
89 IOReturn
IOCommandGate::runAction(Action inAction
,
90 void *arg0
, void *arg1
,
91 void *arg2
, void *arg3
)
96 return kIOReturnNotPermitted
;
99 return kIOReturnBadArgument
;
101 IOTimeStampConstant(IODBG_CMDQ(IOCMDQ_ACTION
),
102 (unsigned int) inAction
, (unsigned int) owner
);
104 // closeGate is recursive so don't worry if we already hold the lock.
106 res
= (*inAction
)(owner
, arg0
, arg1
, arg2
, arg3
);
112 IOReturn
IOCommandGate::attemptCommand(void *arg0
, void *arg1
,
113 void *arg2
, void *arg3
)
118 return kIOReturnNotPermitted
;
121 return kIOReturnNoResources
;
123 // Try to hold the lock if can't get return immediately.
125 return kIOReturnCannotLock
;
127 // closeGate is recursive so don't worry if we already hold the lock.
128 IOTimeStampConstant(IODBG_CMDQ(IOCMDQ_ACTION
),
129 (unsigned int) action
, (unsigned int) owner
);
131 res
= (*(Action
) action
)(owner
, arg0
, arg1
, arg2
, arg3
);
137 IOReturn
IOCommandGate::attemptAction(Action inAction
,
138 void *arg0
, void *arg1
,
139 void *arg2
, void *arg3
)
144 return kIOReturnNotPermitted
;
147 return kIOReturnBadArgument
;
149 // Try to close the gate if can't get return immediately.
151 return kIOReturnCannotLock
;
153 IOTimeStampConstant(IODBG_CMDQ(IOCMDQ_ACTION
),
154 (unsigned int) inAction
, (unsigned int) owner
);
156 res
= (*inAction
)(owner
, arg0
, arg1
, arg2
, arg3
);
162 IOReturn
IOCommandGate::commandSleep(void *event
, UInt32 interruptible
)
164 if (!workLoop
->inGate())
165 return kIOReturnNotPermitted
;
167 return sleepGate(event
, interruptible
);
170 void IOCommandGate::commandWakeup(void *event
, bool oneThread
)
172 wakeupGate(event
, oneThread
);