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@
29 #include <IOKit/IODMAEventSource.h>
30 #include <IOKit/IOService.h>
32 #include "IOKitKernelInternal.h"
35 #define super IOEventSource
36 OSDefineMetaClassAndStructors(IODMAEventSource
, IOEventSource
);
39 IODMAEventSource::init(OSObject
*inOwner
,
40 IOService
*inProvider
,
42 Action inNotification
,
47 if (!super::init(inOwner
)) {
51 if (inProvider
== 0) {
55 dmaProvider
= inProvider
;
56 dmaIndex
= 0xFFFFFFFF;
57 dmaCompletionAction
= inCompletion
;
58 dmaNotificationAction
= inNotification
;
60 dmaController
= IODMAController::getController(dmaProvider
, inDMAIndex
);
61 if (dmaController
== 0) {
64 dmaController
->retain();
66 result
= dmaController
->initDMAChannel(dmaProvider
, this, &dmaIndex
, inDMAIndex
);
67 if (result
!= kIOReturnSuccess
) {
71 queue_init(&dmaCommandsCompleted
);
72 dmaCommandsCompletedLock
= IOSimpleLockAlloc();
78 IODMAEventSource::free()
80 if (dmaCommandsCompletedLock
!= NULL
) {
81 IOSimpleLockFree(dmaCommandsCompletedLock
);
87 IODMAEventSource::dmaEventSource(OSObject
*inOwner
,
88 IOService
*inProvider
,
90 Action inNotification
,
93 IODMAEventSource
*dmaES
= new IODMAEventSource
;
95 if (dmaES
&& !dmaES
->init(inOwner
, inProvider
, inCompletion
, inNotification
, inDMAIndex
)) {
104 IODMAEventSource::startDMACommand(IODMACommand
*dmaCommand
, IODirection direction
, IOByteCount byteCount
, IOByteCount byteOffset
)
108 if ((dmaController
== 0) || (dmaIndex
== 0xFFFFFFFF)) {
109 return kIOReturnError
;
113 return kIOReturnBusy
;
116 if (dmaCompletionAction
== 0) {
120 result
= dmaController
->startDMACommand(dmaIndex
, dmaCommand
, direction
, byteCount
, byteOffset
);
122 if (result
!= kIOReturnSuccess
) {
123 dmaSynchBusy
= false;
127 while (dmaSynchBusy
) {
128 sleepGate(&dmaSynchBusy
, THREAD_UNINT
);
131 return kIOReturnSuccess
;
135 IODMAEventSource::stopDMACommand(bool flush
, uint64_t timeout
)
137 if ((dmaController
== 0) || (dmaIndex
== 0xFFFFFFFF)) {
138 return kIOReturnError
;
141 return dmaController
->stopDMACommand(dmaIndex
, flush
, timeout
);
146 IODMAEventSource::queryDMACommand(IODMACommand
**dmaCommand
, IOByteCount
*transferCount
, bool waitForIdle
)
148 if ((dmaController
== 0) || (dmaIndex
== 0xFFFFFFFF)) {
149 return kIOReturnError
;
152 return dmaController
->queryDMACommand(dmaIndex
, dmaCommand
, transferCount
, waitForIdle
);
157 IODMAEventSource::getFIFODepth(IODirection direction
)
159 if ((dmaController
== 0) || (dmaIndex
== 0xFFFFFFFF)) {
163 return dmaController
->getFIFODepth(dmaIndex
, direction
);
168 IODMAEventSource::setFIFODepth(IOByteCount depth
)
170 if ((dmaController
== 0) || (dmaIndex
== 0xFFFFFFFF)) {
171 return kIOReturnError
;
174 return dmaController
->setFIFODepth(dmaIndex
, depth
);
179 IODMAEventSource::validFIFODepth(IOByteCount depth
, IODirection direction
)
181 if ((dmaController
== 0) || (dmaIndex
== 0xFFFFFFFF)) {
182 return kIOReturnError
;
185 return dmaController
->validFIFODepth(dmaIndex
, depth
, direction
);
190 IODMAEventSource::setFrameSize(UInt8 byteCount
)
192 if ((dmaController
== 0) || (dmaIndex
== 0xFFFFFFFF)) {
193 return kIOReturnError
;
196 return dmaController
->setFrameSize(dmaIndex
, byteCount
);
202 IODMAEventSource::checkForWork(void)
204 IODMACommand
*dmaCommand
= NULL
;
207 IOSimpleLockLock(dmaCommandsCompletedLock
);
208 work
= !queue_empty(&dmaCommandsCompleted
);
210 queue_remove_first(&dmaCommandsCompleted
, dmaCommand
, IODMACommand
*, fCommandChain
);
211 again
= !queue_empty(&dmaCommandsCompleted
);
215 IOSimpleLockUnlock(dmaCommandsCompletedLock
);
218 (*dmaCompletionAction
)(owner
, this, dmaCommand
, dmaCommand
->reserved
->fStatus
, dmaCommand
->reserved
->fActualByteCount
, dmaCommand
->reserved
->fTimeStamp
);
225 IODMAEventSource::completeDMACommand(IODMACommand
*dmaCommand
)
227 if (dmaCompletionAction
!= 0) {
228 IOSimpleLockLock(dmaCommandsCompletedLock
);
229 queue_enter(&dmaCommandsCompleted
, dmaCommand
, IODMACommand
*, fCommandChain
);
230 IOSimpleLockUnlock(dmaCommandsCompletedLock
);
232 signalWorkAvailable();
234 dmaSynchBusy
= false;
235 wakeupGate(&dmaSynchBusy
, true);
240 IODMAEventSource::notifyDMACommand(IODMACommand
*dmaCommand
, IOReturn status
, IOByteCount actualByteCount
, AbsoluteTime timeStamp
)
242 dmaCommand
->reserved
->fStatus
= status
;
243 dmaCommand
->reserved
->fActualByteCount
= actualByteCount
;
244 dmaCommand
->reserved
->fTimeStamp
= timeStamp
;
246 if (dmaNotificationAction
!= 0) {
247 (*dmaNotificationAction
)(owner
, this, dmaCommand
, status
, actualByteCount
, timeStamp
);
252 IODMAEventSource::setDMAConfig(UInt32 newReqIndex
)
254 return dmaController
->setDMAConfig(dmaIndex
, dmaProvider
, newReqIndex
);
258 IODMAEventSource::validDMAConfig(UInt32 newReqIndex
)
260 return dmaController
->validDMAConfig(dmaIndex
, dmaProvider
, newReqIndex
);