]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
8ad349bb | 4 | * @APPLE_LICENSE_OSREFERENCE_HEADER_START@ |
1c79356b | 5 | * |
8ad349bb 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. 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@ | |
1c79356b A |
29 | */ |
30 | #include <IOKit/IOCommandGate.h> | |
31 | #include <IOKit/IOWorkLoop.h> | |
32 | #include <IOKit/IOReturn.h> | |
33 | #include <IOKit/IOTimeStamp.h> | |
34 | ||
35 | #define super IOEventSource | |
36 | ||
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); | |
46 | ||
47 | bool IOCommandGate::checkForWork() { return false; } | |
48 | ||
55e303ae | 49 | bool IOCommandGate::init(OSObject *inOwner, Action inAction) |
1c79356b A |
50 | { |
51 | return super::init(inOwner, (IOEventSource::Action) inAction); | |
52 | } | |
53 | ||
54 | IOCommandGate * | |
55e303ae | 55 | IOCommandGate::commandGate(OSObject *inOwner, Action inAction) |
1c79356b A |
56 | { |
57 | IOCommandGate *me = new IOCommandGate; | |
58 | ||
59 | if (me && !me->init(inOwner, inAction)) { | |
55e303ae | 60 | me->release(); |
1c79356b A |
61 | return 0; |
62 | } | |
63 | ||
64 | return me; | |
65 | } | |
66 | ||
8ad349bb A |
67 | IOReturn IOCommandGate::runCommand(void *arg0, void *arg1, |
68 | void *arg2, void *arg3) | |
c0fea474 | 69 | { |
8ad349bb | 70 | IOReturn res; |
1c79356b | 71 | |
8ad349bb A |
72 | if (!enabled) |
73 | return kIOReturnNotPermitted; | |
1c79356b | 74 | |
8ad349bb A |
75 | if (!action) |
76 | return kIOReturnNoResources; | |
1c79356b | 77 | |
8ad349bb A |
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); | |
c0fea474 | 81 | |
8ad349bb A |
82 | closeGate(); |
83 | res = (*(Action) action)(owner, arg0, arg1, arg2, arg3); | |
84 | openGate(); | |
c0fea474 | 85 | |
8ad349bb | 86 | return res; |
1c79356b A |
87 | } |
88 | ||
89 | IOReturn IOCommandGate::runAction(Action inAction, | |
55e303ae A |
90 | void *arg0, void *arg1, |
91 | void *arg2, void *arg3) | |
1c79356b | 92 | { |
8ad349bb A |
93 | IOReturn res; |
94 | ||
95 | if (!enabled) | |
96 | return kIOReturnNotPermitted; | |
97 | ||
1c79356b A |
98 | if (!inAction) |
99 | return kIOReturnBadArgument; | |
100 | ||
101 | IOTimeStampConstant(IODBG_CMDQ(IOCMDQ_ACTION), | |
102 | (unsigned int) inAction, (unsigned int) owner); | |
103 | ||
8ad349bb | 104 | // closeGate is recursive so don't worry if we already hold the lock. |
1c79356b | 105 | closeGate(); |
8ad349bb A |
106 | res = (*inAction)(owner, arg0, arg1, arg2, arg3); |
107 | openGate(); | |
1c79356b | 108 | |
8ad349bb A |
109 | return res; |
110 | } | |
111 | ||
112 | IOReturn IOCommandGate::attemptCommand(void *arg0, void *arg1, | |
113 | void *arg2, void *arg3) | |
114 | { | |
1c79356b A |
115 | IOReturn res; |
116 | ||
8ad349bb A |
117 | if (!enabled) |
118 | return kIOReturnNotPermitted; | |
1c79356b | 119 | |
8ad349bb A |
120 | if (!action) |
121 | return kIOReturnNoResources; | |
1c79356b | 122 | |
8ad349bb A |
123 | // Try to hold the lock if can't get return immediately. |
124 | if (!tryCloseGate()) | |
125 | return kIOReturnCannotLock; | |
1c79356b | 126 | |
8ad349bb A |
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); | |
1c79356b | 130 | |
8ad349bb | 131 | res = (*(Action) action)(owner, arg0, arg1, arg2, arg3); |
1c79356b A |
132 | openGate(); |
133 | ||
134 | return res; | |
135 | } | |
136 | ||
137 | IOReturn IOCommandGate::attemptAction(Action inAction, | |
55e303ae A |
138 | void *arg0, void *arg1, |
139 | void *arg2, void *arg3) | |
1c79356b A |
140 | { |
141 | IOReturn res; | |
142 | ||
8ad349bb A |
143 | if (!enabled) |
144 | return kIOReturnNotPermitted; | |
145 | ||
1c79356b A |
146 | if (!inAction) |
147 | return kIOReturnBadArgument; | |
148 | ||
149 | // Try to close the gate if can't get return immediately. | |
150 | if (!tryCloseGate()) | |
151 | return kIOReturnCannotLock; | |
152 | ||
8ad349bb A |
153 | IOTimeStampConstant(IODBG_CMDQ(IOCMDQ_ACTION), |
154 | (unsigned int) inAction, (unsigned int) owner); | |
1c79356b | 155 | |
8ad349bb | 156 | res = (*inAction)(owner, arg0, arg1, arg2, arg3); |
1c79356b A |
157 | openGate(); |
158 | ||
159 | return res; | |
160 | } | |
161 | ||
162 | IOReturn IOCommandGate::commandSleep(void *event, UInt32 interruptible) | |
163 | { | |
1c79356b A |
164 | if (!workLoop->inGate()) |
165 | return kIOReturnNotPermitted; | |
166 | ||
167 | return sleepGate(event, interruptible); | |
168 | } | |
169 | ||
170 | void IOCommandGate::commandWakeup(void *event, bool oneThread) | |
171 | { | |
172 | wakeupGate(event, oneThread); | |
173 | } |