]> git.saurik.com Git - apple/xnu.git/blame - iokit/Kernel/IOCommandGate.cpp
xnu-792.6.61.tar.gz
[apple/xnu.git] / iokit / Kernel / IOCommandGate.cpp
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
37839358
A
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
1c79356b 11 *
37839358
A
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
37839358
A
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
1c79356b
A
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22#include <IOKit/IOCommandGate.h>
23#include <IOKit/IOWorkLoop.h>
24#include <IOKit/IOReturn.h>
25#include <IOKit/IOTimeStamp.h>
26
27#define super IOEventSource
28
29OSDefineMetaClassAndStructors(IOCommandGate, IOEventSource)
30OSMetaClassDefineReservedUnused(IOCommandGate, 0);
31OSMetaClassDefineReservedUnused(IOCommandGate, 1);
32OSMetaClassDefineReservedUnused(IOCommandGate, 2);
33OSMetaClassDefineReservedUnused(IOCommandGate, 3);
34OSMetaClassDefineReservedUnused(IOCommandGate, 4);
35OSMetaClassDefineReservedUnused(IOCommandGate, 5);
36OSMetaClassDefineReservedUnused(IOCommandGate, 6);
37OSMetaClassDefineReservedUnused(IOCommandGate, 7);
38
39bool IOCommandGate::checkForWork() { return false; }
40
55e303ae 41bool IOCommandGate::init(OSObject *inOwner, Action inAction)
1c79356b
A
42{
43 return super::init(inOwner, (IOEventSource::Action) inAction);
44}
45
46IOCommandGate *
55e303ae 47IOCommandGate::commandGate(OSObject *inOwner, Action inAction)
1c79356b
A
48{
49 IOCommandGate *me = new IOCommandGate;
50
51 if (me && !me->init(inOwner, inAction)) {
55e303ae 52 me->release();
1c79356b
A
53 return 0;
54 }
55
56 return me;
57}
58
55e303ae
A
59IOReturn IOCommandGate::runCommand(void *arg0, void *arg1,
60 void *arg2, void *arg3)
1c79356b
A
61{
62 IOReturn res;
63
64 if (!enabled)
65 return kIOReturnNotPermitted;
66
67 if (!action)
68 return kIOReturnNoResources;
69
70 // closeGate is recursive so don't worry if we already hold the lock.
71 IOTimeStampConstant(IODBG_CMDQ(IOCMDQ_ACTION),
72 (unsigned int) action, (unsigned int) owner);
73
74 closeGate();
75 res = (*(Action) action)(owner, arg0, arg1, arg2, arg3);
76 openGate();
77
78 return res;
79}
80
81IOReturn IOCommandGate::runAction(Action inAction,
55e303ae
A
82 void *arg0, void *arg1,
83 void *arg2, void *arg3)
1c79356b
A
84{
85 IOReturn res;
86
87 if (!enabled)
88 return kIOReturnNotPermitted;
89
90 if (!inAction)
91 return kIOReturnBadArgument;
92
93 IOTimeStampConstant(IODBG_CMDQ(IOCMDQ_ACTION),
94 (unsigned int) inAction, (unsigned int) owner);
95
96 // closeGate is recursive so don't worry if we already hold the lock.
97 closeGate();
98 res = (*inAction)(owner, arg0, arg1, arg2, arg3);
99 openGate();
100
101 return res;
102}
103
55e303ae
A
104IOReturn IOCommandGate::attemptCommand(void *arg0, void *arg1,
105 void *arg2, void *arg3)
1c79356b
A
106{
107 IOReturn res;
108
109 if (!enabled)
110 return kIOReturnNotPermitted;
111
112 if (!action)
113 return kIOReturnNoResources;
114
115 // Try to hold the lock if can't get return immediately.
116 if (!tryCloseGate())
117 return kIOReturnCannotLock;
118
119 // closeGate is recursive so don't worry if we already hold the lock.
120 IOTimeStampConstant(IODBG_CMDQ(IOCMDQ_ACTION),
121 (unsigned int) action, (unsigned int) owner);
122
123 res = (*(Action) action)(owner, arg0, arg1, arg2, arg3);
124 openGate();
125
126 return res;
127}
128
129IOReturn IOCommandGate::attemptAction(Action inAction,
55e303ae
A
130 void *arg0, void *arg1,
131 void *arg2, void *arg3)
1c79356b
A
132{
133 IOReturn res;
134
135 if (!enabled)
136 return kIOReturnNotPermitted;
137
138 if (!inAction)
139 return kIOReturnBadArgument;
140
141 // Try to close the gate if can't get return immediately.
142 if (!tryCloseGate())
143 return kIOReturnCannotLock;
144
145 IOTimeStampConstant(IODBG_CMDQ(IOCMDQ_ACTION),
146 (unsigned int) inAction, (unsigned int) owner);
147
148 res = (*inAction)(owner, arg0, arg1, arg2, arg3);
149 openGate();
150
151 return res;
152}
153
154IOReturn IOCommandGate::commandSleep(void *event, UInt32 interruptible)
155{
1c79356b
A
156 if (!workLoop->inGate())
157 return kIOReturnNotPermitted;
158
159 return sleepGate(event, interruptible);
160}
161
162void IOCommandGate::commandWakeup(void *event, bool oneThread)
163{
164 wakeupGate(event, oneThread);
165}