author | Mike Kinghan <mikek@symbian.org> |
Tue, 16 Nov 2010 14:39:21 +0000 | |
branch | GCC_SURGE |
changeset 303 | 9b85206a602c |
parent 139 | 95f71bcdcdb7 |
child 231 | 75252ea6123b |
permissions | -rw-r--r-- |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
1 |
// Copyright (c) 2002-2010 Nokia Corporation and/or its subsidiary(-ies). |
0 | 2 |
// All rights reserved. |
3 |
// This component and the accompanying materials are made available |
|
4 |
// under the terms of the License "Eclipse Public License v1.0" |
|
5 |
// which accompanies this distribution, and is available |
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
// |
|
8 |
// Initial Contributors: |
|
9 |
// Nokia Corporation - initial contribution. |
|
10 |
// |
|
11 |
// Contributors: |
|
12 |
// |
|
13 |
// Description: |
|
14 |
// e32\drivers\dmapil.cpp |
|
15 |
// DMA Platform Independent Layer (PIL) |
|
16 |
// |
|
17 |
// |
|
18 |
||
19 |
#include <drivers/dma.h> |
|
20 |
#include <kernel/kern_priv.h> |
|
21 |
||
22 |
||
23 |
static const char KDmaPanicCat[] = "DMA"; |
|
24 |
||
25 |
NFastMutex DmaChannelMgr::Lock; |
|
26 |
||
27 |
class TDmaCancelInfo : public SDblQueLink |
|
28 |
{ |
|
29 |
public: |
|
30 |
TDmaCancelInfo(); |
|
31 |
void Signal(); |
|
32 |
public: |
|
33 |
NFastSemaphore iSem; |
|
34 |
}; |
|
35 |
||
36 |
TDmaCancelInfo::TDmaCancelInfo() |
|
37 |
: iSem(0) |
|
38 |
{ |
|
39 |
iNext = this; |
|
40 |
iPrev = this; |
|
41 |
} |
|
42 |
||
43 |
void TDmaCancelInfo::Signal() |
|
44 |
{ |
|
45 |
TDmaCancelInfo* p = this; |
|
46 |
FOREVER |
|
47 |
{ |
|
48 |
TDmaCancelInfo* next = (TDmaCancelInfo*)p->iNext; |
|
49 |
if (p!=next) |
|
50 |
p->Deque(); |
|
51 |
NKern::FSSignal(&p->iSem); // Don't dereference p after this |
|
52 |
if (p==next) |
|
53 |
break; |
|
54 |
p = next; |
|
55 |
} |
|
56 |
} |
|
57 |
||
58 |
////////////////////////////////////////////////////////////////////////////// |
|
59 |
||
60 |
#ifdef __DMASIM__ |
|
61 |
#ifdef __WINS__ |
|
62 |
typedef TLinAddr TPhysAddr; |
|
63 |
#endif |
|
64 |
static inline TPhysAddr LinToPhys(TLinAddr aLin) {return aLin;} |
|
65 |
#else |
|
66 |
static inline TPhysAddr LinToPhys(TLinAddr aLin) {return Epoc::LinearToPhysical(aLin);} |
|
67 |
#endif |
|
68 |
||
69 |
// |
|
70 |
// Return minimum of aMaxSize and size of largest physically contiguous block |
|
71 |
// starting at aLinAddr. |
|
72 |
// |
|
73 |
static TInt MaxPhysSize(TLinAddr aLinAddr, const TInt aMaxSize) |
|
74 |
{ |
|
75 |
const TPhysAddr physBase = LinToPhys(aLinAddr); |
|
76 |
TLinAddr lin = aLinAddr; |
|
77 |
TInt size = 0; |
|
78 |
for (;;) |
|
79 |
{ |
|
80 |
// Round up the linear address to the next MMU page boundary |
|
81 |
const TLinAddr linBoundary = Kern::RoundToPageSize(lin + 1); |
|
82 |
size += linBoundary - lin; |
|
83 |
if (size >= aMaxSize) |
|
84 |
return aMaxSize; |
|
85 |
if ((physBase + size) != LinToPhys(linBoundary)) |
|
86 |
return size; |
|
87 |
lin = linBoundary; |
|
88 |
} |
|
89 |
} |
|
90 |
||
91 |
||
92 |
////////////////////////////////////////////////////////////////////////////// |
|
93 |
// TDmac |
|
94 |
||
95 |
TDmac::TDmac(const SCreateInfo& aInfo) |
|
96 |
: iMaxDesCount(aInfo.iDesCount), |
|
97 |
iAvailDesCount(aInfo.iDesCount), |
|
98 |
iDesSize(aInfo.iDesSize), |
|
99 |
iCaps(aInfo.iCaps) |
|
100 |
{ |
|
101 |
__DMA_ASSERTD(iMaxDesCount > 0); |
|
102 |
__DMA_ASSERTD((iCaps & ~KCapsBitHwDes) == 0); // undefined bits set? |
|
103 |
__DMA_ASSERTD(iDesSize > 0); |
|
104 |
} |
|
105 |
||
106 |
// |
|
107 |
// Second-phase c'tor |
|
108 |
// |
|
109 |
||
110 |
TInt TDmac::Create(const SCreateInfo& aInfo) |
|
111 |
{ |
|
112 |
iHdrPool = new SDmaDesHdr[iMaxDesCount]; |
|
113 |
if (iHdrPool == NULL) |
|
114 |
return KErrNoMemory; |
|
115 |
||
116 |
TInt r = AllocDesPool(aInfo.iDesChunkAttribs); |
|
117 |
if (r != KErrNone) |
|
118 |
return KErrNoMemory; |
|
119 |
||
120 |
// Link all descriptor headers together on the free list |
|
121 |
iFreeHdr = iHdrPool; |
|
122 |
TInt i; |
|
123 |
for (i = 0; i < iMaxDesCount - 1; i++) |
|
124 |
iHdrPool[i].iNext = iHdrPool + i + 1; |
|
125 |
iHdrPool[iMaxDesCount-1].iNext = NULL; |
|
126 |
||
127 |
__DMA_INVARIANT(); |
|
128 |
return KErrNone; |
|
129 |
} |
|
130 |
||
131 |
||
132 |
TDmac::~TDmac() |
|
133 |
{ |
|
134 |
__DMA_INVARIANT(); |
|
135 |
||
136 |
FreeDesPool(); |
|
137 |
delete[] iHdrPool; |
|
138 |
} |
|
139 |
||
140 |
||
141 |
// Calling thread must be in CS |
|
142 |
TInt TDmac::AllocDesPool(TUint aAttribs) |
|
143 |
{ |
|
144 |
TInt r; |
|
145 |
if (iCaps & KCapsBitHwDes) |
|
146 |
{ |
|
147 |
TInt size = iMaxDesCount*iDesSize; |
|
148 |
#ifdef __WINS__ |
|
149 |
(void)aAttribs; |
|
150 |
iDesPool = new TUint8[size]; |
|
151 |
r = iDesPool ? KErrNone : KErrNoMemory; |
|
152 |
#else |
|
153 |
// Chunk not mapped as supervisor r/w user none? incorrect mask passed by PSL |
|
154 |
__DMA_ASSERTD((aAttribs & EMapAttrAccessMask) == EMapAttrSupRw); |
|
155 |
TPhysAddr phys; |
|
156 |
r = Epoc::AllocPhysicalRam(size, phys); |
|
157 |
if (r == KErrNone) |
|
158 |
{ |
|
159 |
r = DPlatChunkHw::New(iHwDesChunk, phys, size, aAttribs); |
|
160 |
if (r == KErrNone) |
|
161 |
{ |
|
162 |
iDesPool = (TAny*)iHwDesChunk->LinearAddress(); |
|
163 |
__KTRACE_OPT(KDMA, Kern::Printf("descriptor hw chunk created lin=0x%08X phys=0x%08X, size=0x%X", |
|
164 |
iHwDesChunk->iLinAddr, iHwDesChunk->iPhysAddr, size)); |
|
165 |
} |
|
166 |
else |
|
167 |
Epoc::FreePhysicalRam(phys, size); |
|
168 |
} |
|
169 |
#endif |
|
170 |
} |
|
171 |
else |
|
172 |
{ |
|
173 |
iDesPool = new SDmaPseudoDes[iMaxDesCount]; |
|
174 |
r = iDesPool ? KErrNone : KErrNoMemory; |
|
175 |
} |
|
176 |
return r; |
|
177 |
} |
|
178 |
||
179 |
||
180 |
// Calling thread must be in CS |
|
181 |
void TDmac::FreeDesPool() |
|
182 |
{ |
|
183 |
if (iCaps & KCapsBitHwDes) |
|
184 |
{ |
|
185 |
#ifdef __WINS__ |
|
186 |
delete[] iDesPool; |
|
187 |
#else |
|
188 |
if (iHwDesChunk) |
|
189 |
{ |
|
190 |
TPhysAddr phys = iHwDesChunk->PhysicalAddress(); |
|
191 |
TInt size = iHwDesChunk->iSize; |
|
192 |
iHwDesChunk->Close(NULL); |
|
193 |
Epoc::FreePhysicalRam(phys, size); |
|
194 |
} |
|
195 |
#endif |
|
196 |
} |
|
197 |
else |
|
198 |
Kern::Free(iDesPool); |
|
199 |
} |
|
200 |
||
201 |
||
202 |
/** |
|
203 |
Prealloc the given number of descriptors. |
|
204 |
*/ |
|
205 |
||
206 |
TInt TDmac::ReserveSetOfDes(TInt aCount) |
|
207 |
{ |
|
208 |
__KTRACE_OPT(KDMA, Kern::Printf(">TDmac::ReserveSetOfDes count=%d", aCount)); |
|
209 |
__DMA_ASSERTD(aCount > 0); |
|
210 |
TInt r = KErrTooBig; |
|
211 |
Wait(); |
|
212 |
if (iAvailDesCount - aCount >= 0) |
|
213 |
{ |
|
214 |
iAvailDesCount -= aCount; |
|
215 |
r = KErrNone; |
|
216 |
} |
|
217 |
Signal(); |
|
218 |
__DMA_INVARIANT(); |
|
219 |
__KTRACE_OPT(KDMA, Kern::Printf("<TDmac::ReserveSetOfDes r=%d", r)); |
|
220 |
return r; |
|
221 |
} |
|
222 |
||
223 |
||
224 |
/** |
|
225 |
Return the given number of preallocated descriptors to the free pool. |
|
226 |
*/ |
|
227 |
||
228 |
void TDmac::ReleaseSetOfDes(TInt aCount) |
|
229 |
{ |
|
230 |
__DMA_ASSERTD(aCount >= 0); |
|
231 |
Wait(); |
|
232 |
iAvailDesCount += aCount; |
|
233 |
Signal(); |
|
234 |
__DMA_INVARIANT(); |
|
235 |
} |
|
236 |
||
237 |
||
238 |
/** |
|
239 |
Queue DFC and update word used to communicate with DFC. |
|
240 |
||
241 |
Called in interrupt context by PSL. |
|
242 |
*/ |
|
243 |
||
244 |
void TDmac::HandleIsr(TDmaChannel& aChannel, TBool aIsComplete) |
|
245 |
{ |
|
246 |
//__KTRACE_OPT(KDMA, Kern::Printf("TDmac::HandleIsr channel=%d complete=%d", aChannelIdx, aIsComplete)); |
|
247 |
||
248 |
// Queue DFC if necessary. The possible scenarios are: |
|
249 |
// * no DFC queued --> need to queue DFC |
|
250 |
// * DFC queued (not running yet) --> just need to update iIsrDfc |
|
251 |
// * DFC running / iIsrDfc already reset --> need to requeue DFC |
|
252 |
// * DFC running / iIsrDfc not reset yet --> just need to update iIsrDfc |
|
253 |
// Set error flag if necessary. |
|
254 |
TUint32 inc = aIsComplete ? 1u : TUint32(TDmaChannel::KErrorFlagMask)|1u; |
|
255 |
TUint32 orig = __e32_atomic_tau_ord32(&aChannel.iIsrDfc, TUint32(TDmaChannel::KCancelFlagMask), 0, inc); |
|
256 |
||
257 |
// As transfer should be suspended when an error occurs, we |
|
258 |
// should never get there with the error flag already set. |
|
259 |
__DMA_ASSERTD((orig & inc & (TUint32)TDmaChannel::KErrorFlagMask) == 0); |
|
260 |
||
261 |
if (orig == 0) |
|
262 |
aChannel.iDfc.Add(); |
|
263 |
} |
|
264 |
||
265 |
||
266 |
void TDmac::InitDes(const SDmaDesHdr& aHdr, TUint32 aSrc, TUint32 aDest, TInt aCount, |
|
267 |
TUint aFlags, TUint32 aPslInfo, TUint32 aCookie) |
|
268 |
{ |
|
269 |
if (iCaps & KCapsBitHwDes) |
|
270 |
InitHwDes(aHdr, aSrc, aDest, aCount, aFlags, aPslInfo, aCookie); |
|
271 |
else |
|
272 |
{ |
|
273 |
SDmaPseudoDes& des = HdrToDes(aHdr); |
|
274 |
des.iSrc = aSrc; |
|
275 |
des.iDest = aDest; |
|
276 |
des.iCount = aCount; |
|
277 |
des.iFlags = aFlags; |
|
278 |
des.iPslInfo = aPslInfo; |
|
279 |
des.iCookie = aCookie; |
|
280 |
} |
|
281 |
} |
|
282 |
||
283 |
||
284 |
void TDmac::InitHwDes(const SDmaDesHdr& /*aHdr*/, TUint32 /*aSrc*/, TUint32 /*aDest*/, TInt /*aCount*/, |
|
285 |
TUint /*aFlags*/, TUint32 /*aPslInfo*/, TUint32 /*aCookie*/) |
|
286 |
{ |
|
287 |
// concrete controller must override if KCapsBitHwDes set |
|
288 |
__DMA_CANT_HAPPEN(); |
|
289 |
} |
|
290 |
||
291 |
||
292 |
void TDmac::ChainHwDes(const SDmaDesHdr& /*aHdr*/, const SDmaDesHdr& /*aNextHdr*/) |
|
293 |
{ |
|
294 |
// concrete controller must override if KCapsBitHwDes set |
|
295 |
__DMA_CANT_HAPPEN(); |
|
296 |
} |
|
297 |
||
298 |
||
299 |
void TDmac::AppendHwDes(const TDmaChannel& /*aChannel*/, const SDmaDesHdr& /*aLastHdr*/, |
|
300 |
const SDmaDesHdr& /*aNewHdr*/) |
|
301 |
{ |
|
302 |
// concrete controller must override if KCapsBitHwDes set |
|
303 |
__DMA_CANT_HAPPEN(); |
|
304 |
} |
|
305 |
||
306 |
||
307 |
void TDmac::UnlinkHwDes(const TDmaChannel& /*aChannel*/, SDmaDesHdr& /*aHdr*/) |
|
308 |
{ |
|
309 |
// concrete controller must override if KCapsBitHwDes set |
|
310 |
__DMA_CANT_HAPPEN(); |
|
311 |
} |
|
312 |
||
313 |
||
314 |
TInt TDmac::FailNext(const TDmaChannel& /*aChannel*/) |
|
315 |
{ |
|
316 |
return KErrNotSupported; |
|
317 |
} |
|
318 |
||
319 |
||
320 |
TInt TDmac::MissNextInterrupts(const TDmaChannel& /*aChannel*/, TInt /*aInterruptCount*/) |
|
321 |
{ |
|
322 |
return KErrNotSupported; |
|
323 |
} |
|
324 |
||
325 |
||
326 |
TInt TDmac::Extension(TDmaChannel& /*aChannel*/, TInt /*aCmd*/, TAny* /*aArg*/) |
|
327 |
{ |
|
328 |
// default implementation - NOP |
|
329 |
return KErrNotSupported; |
|
330 |
} |
|
331 |
||
332 |
||
333 |
#ifdef _DEBUG |
|
334 |
||
335 |
void TDmac::Invariant() |
|
336 |
{ |
|
337 |
Wait(); |
|
338 |
__DMA_ASSERTD(0 <= iAvailDesCount && iAvailDesCount <= iMaxDesCount); |
|
339 |
__DMA_ASSERTD(! iFreeHdr || IsValidHdr(iFreeHdr)); |
|
340 |
for (TInt i = 0; i < iMaxDesCount; i++) |
|
341 |
__DMA_ASSERTD(iHdrPool[i].iNext == NULL || IsValidHdr(iHdrPool[i].iNext)); |
|
342 |
Signal(); |
|
343 |
} |
|
344 |
||
345 |
||
346 |
TBool TDmac::IsValidHdr(const SDmaDesHdr* aHdr) |
|
347 |
{ |
|
348 |
return (iHdrPool <= aHdr) && (aHdr < iHdrPool + iMaxDesCount); |
|
349 |
} |
|
350 |
||
351 |
#endif |
|
352 |
||
353 |
////////////////////////////////////////////////////////////////////////////// |
|
354 |
// DDmaRequest |
|
355 |
||
356 |
||
357 |
EXPORT_C DDmaRequest::DDmaRequest(TDmaChannel& aChannel, TCallback aCb, TAny* aCbArg, TInt aMaxTransferSize) |
|
358 |
: iChannel(aChannel), |
|
359 |
iCb(aCb), |
|
360 |
iCbArg(aCbArg), |
|
361 |
iMaxTransferSize(aMaxTransferSize) |
|
362 |
{ |
|
363 |
// iDesCount = 0; |
|
364 |
// iFirstHdr = iLastHdr = NULL; |
|
365 |
// iQueued = EFalse; |
|
366 |
iChannel.iReqCount++; |
|
367 |
__DMA_INVARIANT(); |
|
368 |
} |
|
369 |
||
370 |
||
371 |
||
372 |
EXPORT_C DDmaRequest::~DDmaRequest() |
|
373 |
{ |
|
374 |
__DMA_ASSERTD(!iQueued); |
|
375 |
__DMA_INVARIANT(); |
|
376 |
FreeDesList(); |
|
377 |
iChannel.iReqCount--; |
|
378 |
} |
|
379 |
||
380 |
||
381 |
||
382 |
EXPORT_C TInt DDmaRequest::Fragment(TUint32 aSrc, TUint32 aDest, TInt aCount, TUint aFlags, TUint32 aPslInfo) |
|
383 |
{ |
|
384 |
__KTRACE_OPT(KDMA, Kern::Printf("DDmaRequest::Fragment thread %O " |
|
385 |
"src=0x%08X dest=0x%08X count=%d flags=0x%X psl=0x%08X", |
|
386 |
&Kern::CurrentThread(), aSrc, aDest, aCount, aFlags, aPslInfo)); |
|
387 |
__DMA_ASSERTD(aCount > 0); |
|
388 |
__DMA_ASSERTD(!iQueued); |
|
389 |
||
390 |
const TUint alignMask = iChannel.MemAlignMask(aFlags, aPslInfo); |
|
391 |
const TBool memSrc = aFlags & KDmaMemSrc; |
|
392 |
const TBool memDest = aFlags & KDmaMemDest; |
|
393 |
||
394 |
// Memory buffers must satisfy alignment constraint |
|
395 |
__DMA_ASSERTD(!memSrc || ((aSrc & alignMask) == 0)); |
|
396 |
__DMA_ASSERTD(!memDest || ((aDest & alignMask) == 0)); |
|
397 |
||
398 |
// Ask the PSL what the maximum size possible for this transfer is |
|
399 |
TInt maxTransferSize = iChannel.MaxTransferSize(aFlags, aPslInfo); |
|
400 |
if (!maxTransferSize) |
|
401 |
{ |
|
402 |
__KTRACE_OPT(KPANIC, Kern::Printf("Error: maxTransferSize == 0")); |
|
403 |
return KErrArgument; |
|
404 |
} |
|
405 |
||
406 |
if (iMaxTransferSize) |
|
407 |
{ |
|
408 |
// User has set a size cap |
|
409 |
__DMA_ASSERTA((iMaxTransferSize <= maxTransferSize) || (maxTransferSize == -1)); |
|
410 |
maxTransferSize = iMaxTransferSize; |
|
411 |
} |
|
412 |
else |
|
413 |
{ |
|
414 |
// User doesn't care about max size |
|
415 |
if (maxTransferSize == -1) |
|
416 |
{ |
|
417 |
// No maximum imposed by controller |
|
418 |
maxTransferSize = aCount; |
|
419 |
} |
|
420 |
} |
|
421 |
||
422 |
const TInt maxAlignedSize = (maxTransferSize & ~alignMask); |
|
423 |
__DMA_ASSERTD(maxAlignedSize > 0); // bug in PSL if not true |
|
424 |
||
425 |
FreeDesList(); |
|
426 |
||
427 |
TInt r = KErrNone; |
|
428 |
do |
|
429 |
{ |
|
430 |
// Allocate fragment |
|
431 |
r = ExpandDesList(); |
|
432 |
if (r != KErrNone) |
|
433 |
{ |
|
434 |
FreeDesList(); |
|
435 |
break; |
|
436 |
} |
|
437 |
||
438 |
// Compute fragment size |
|
439 |
TInt c = Min(maxTransferSize, aCount); |
|
440 |
if (memSrc && ((aFlags & KDmaPhysAddrSrc) == 0)) |
|
441 |
c = MaxPhysSize(aSrc, c); |
|
442 |
if (memDest && ((aFlags & KDmaPhysAddrDest) == 0)) |
|
443 |
c = MaxPhysSize(aDest, c); |
|
444 |
if ((memSrc || memDest) && (c < aCount) && (c > maxAlignedSize)) |
|
445 |
{ |
|
446 |
// This is not last fragment of transfer to/from memory. We must |
|
447 |
// round down fragment size so next one is correctly aligned. |
|
448 |
c = maxAlignedSize; |
|
449 |
} |
|
450 |
||
451 |
// Initialise fragment |
|
452 |
__KTRACE_OPT(KDMA, Kern::Printf("fragment: src=0x%08X dest=0x%08X count=%d", aSrc, aDest, c)); |
|
453 |
iChannel.iController->InitDes(*iLastHdr, aSrc, aDest, c, aFlags, aPslInfo, iChannel.PslId()); |
|
454 |
||
455 |
// Update for next iteration |
|
456 |
aCount -= c; |
|
457 |
if (memSrc) |
|
458 |
aSrc += c; |
|
459 |
if (memDest) |
|
460 |
aDest += c; |
|
461 |
} |
|
462 |
while (aCount > 0); |
|
463 |
||
464 |
__DMA_INVARIANT(); |
|
465 |
return r; |
|
466 |
} |
|
467 |
||
468 |
||
469 |
||
470 |
EXPORT_C void DDmaRequest::Queue() |
|
471 |
{ |
|
472 |
__KTRACE_OPT(KDMA, Kern::Printf("DDmaRequest::Queue thread %O", &Kern::CurrentThread())); |
|
473 |
__DMA_ASSERTD(iDesCount > 0); // Not configured? call Fragment() first ! |
|
474 |
__DMA_ASSERTD(!iQueued); |
|
475 |
||
476 |
// append request to queue and link new descriptor list to existing one. |
|
477 |
iChannel.Wait(); |
|
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
478 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
479 |
TUint32 req_count = iChannel.iQueuedRequests++; |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
480 |
if (req_count == 0) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
481 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
482 |
iChannel.Signal(); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
483 |
iChannel.QueuedRequestCountChanged(); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
484 |
iChannel.Wait(); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
485 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
486 |
|
0 | 487 |
if (!(iChannel.iIsrDfc & (TUint32)TDmaChannel::KCancelFlagMask)) |
488 |
{ |
|
489 |
iQueued = ETrue; |
|
490 |
iChannel.iReqQ.Add(&iLink); |
|
491 |
*iChannel.iNullPtr = iFirstHdr; |
|
492 |
iChannel.iNullPtr = &(iLastHdr->iNext); |
|
493 |
iChannel.DoQueue(*this); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
494 |
__DMA_INVARIANT(); |
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
495 |
iChannel.Signal(); |
0 | 496 |
} |
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
497 |
else |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
498 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
499 |
// Someone is cancelling all requests... |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
500 |
req_count = --iChannel.iQueuedRequests; |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
501 |
__DMA_INVARIANT(); |
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
502 |
iChannel.Signal(); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
503 |
if (req_count == 0) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
504 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
505 |
iChannel.QueuedRequestCountChanged(); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
506 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
507 |
} |
0 | 508 |
} |
509 |
||
510 |
EXPORT_C TInt DDmaRequest::ExpandDesList(TInt aCount) |
|
511 |
{ |
|
512 |
__DMA_ASSERTD(!iQueued); |
|
513 |
__DMA_ASSERTD(aCount > 0); |
|
514 |
||
515 |
if (aCount > iChannel.iAvailDesCount) |
|
516 |
return KErrTooBig; |
|
517 |
||
518 |
iChannel.iAvailDesCount -= aCount; |
|
519 |
iDesCount += aCount; |
|
520 |
||
521 |
TDmac& c = *(iChannel.iController); |
|
522 |
c.Wait(); |
|
523 |
||
524 |
if (iFirstHdr == NULL) |
|
525 |
{ |
|
526 |
// handle empty list specially to simplify following loop |
|
527 |
iFirstHdr = iLastHdr = c.iFreeHdr; |
|
528 |
c.iFreeHdr = c.iFreeHdr->iNext; |
|
529 |
--aCount; |
|
530 |
} |
|
531 |
else |
|
532 |
iLastHdr->iNext = c.iFreeHdr; |
|
533 |
||
534 |
// Remove as many descriptors and headers from free pool as necessary and |
|
535 |
// ensure hardware descriptors are chained together. |
|
536 |
while (aCount-- > 0) |
|
537 |
{ |
|
538 |
__DMA_ASSERTD(c.iFreeHdr != NULL); |
|
539 |
if (c.iCaps & TDmac::KCapsBitHwDes) |
|
540 |
c.ChainHwDes(*iLastHdr, *(c.iFreeHdr)); |
|
541 |
iLastHdr = c.iFreeHdr; |
|
542 |
c.iFreeHdr = c.iFreeHdr->iNext; |
|
543 |
} |
|
544 |
||
545 |
c.Signal(); |
|
546 |
||
547 |
iLastHdr->iNext = NULL; |
|
548 |
||
549 |
__DMA_INVARIANT(); |
|
550 |
return KErrNone; |
|
551 |
} |
|
552 |
||
553 |
||
554 |
||
555 |
||
556 |
EXPORT_C void DDmaRequest::FreeDesList() |
|
557 |
{ |
|
558 |
__DMA_ASSERTD(!iQueued); |
|
559 |
if (iDesCount > 0) |
|
560 |
{ |
|
561 |
iChannel.iAvailDesCount += iDesCount; |
|
562 |
TDmac& c = *(iChannel.iController); |
|
563 |
c.Wait(); |
|
564 |
iLastHdr->iNext = c.iFreeHdr; |
|
565 |
c.iFreeHdr = iFirstHdr; |
|
566 |
c.Signal(); |
|
567 |
iFirstHdr = iLastHdr = NULL; |
|
568 |
iDesCount = 0; |
|
569 |
} |
|
570 |
} |
|
571 |
||
572 |
||
573 |
#ifdef _DEBUG |
|
574 |
||
575 |
void DDmaRequest::Invariant() |
|
576 |
{ |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
577 |
// This invariant may be called either with, |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
578 |
// or without the channel lock already held |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
579 |
TBool channelLockAquired=EFalse; |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
580 |
if(!iChannel.iLock.HeldByCurrentThread()) |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
581 |
{ |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
582 |
iChannel.Wait(); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
583 |
channelLockAquired = ETrue; |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
584 |
} |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
585 |
|
0 | 586 |
__DMA_ASSERTD(iChannel.IsOpened()); |
587 |
__DMA_ASSERTD(0 <= iMaxTransferSize); |
|
588 |
__DMA_ASSERTD(0 <= iDesCount && iDesCount <= iChannel.iMaxDesCount); |
|
589 |
if (iDesCount == 0) |
|
590 |
{ |
|
591 |
__DMA_ASSERTD(!iQueued); |
|
592 |
__DMA_ASSERTD(!iFirstHdr && !iLastHdr); |
|
593 |
} |
|
594 |
else |
|
595 |
{ |
|
596 |
__DMA_ASSERTD(iChannel.iController->IsValidHdr(iFirstHdr)); |
|
597 |
__DMA_ASSERTD(iChannel.iController->IsValidHdr(iLastHdr)); |
|
598 |
} |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
599 |
|
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
600 |
if(channelLockAquired) |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
601 |
{ |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
602 |
iChannel.Signal(); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
90
diff
changeset
|
603 |
} |
0 | 604 |
} |
605 |
||
606 |
#endif |
|
607 |
||
608 |
||
609 |
////////////////////////////////////////////////////////////////////////////// |
|
610 |
// TDmaChannel |
|
611 |
||
612 |
||
613 |
EXPORT_C TInt TDmaChannel::StaticExtension(TInt aCmd, TAny* aArg) |
|
614 |
{ |
|
615 |
return DmaChannelMgr::StaticExtension(aCmd, aArg); |
|
616 |
} |
|
617 |
||
618 |
||
619 |
TDmaChannel::TDmaChannel() |
|
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
620 |
: iController(NULL), |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
621 |
iPslId(0), |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
622 |
iCurHdr(NULL), |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
623 |
iNullPtr(&iCurHdr), |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
624 |
iDfc(Dfc, NULL, 0), |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
625 |
iMaxDesCount(0), |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
626 |
iAvailDesCount(0), |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
627 |
iIsrDfc(0), |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
628 |
iReqQ(), |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
629 |
iReqCount(0), |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
630 |
iQueuedRequests(0), |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
631 |
iCancelInfo(NULL) |
0 | 632 |
{ |
633 |
__DMA_INVARIANT(); |
|
634 |
} |
|
635 |
||
636 |
||
637 |
EXPORT_C TInt TDmaChannel::Open(const SCreateInfo& aInfo, TDmaChannel*& aChannel) |
|
638 |
{ |
|
639 |
__KTRACE_OPT(KDMA, Kern::Printf("TDmaChannel::Open thread %O", &Kern::CurrentThread())); |
|
640 |
__DMA_ASSERTD(aInfo.iDfcQ != NULL); |
|
641 |
__DMA_ASSERTD(aInfo.iDfcPriority < KNumDfcPriorities); |
|
642 |
__DMA_ASSERTD(aInfo.iDesCount >= 1); |
|
643 |
||
644 |
aChannel = NULL; |
|
645 |
||
646 |
DmaChannelMgr::Wait(); |
|
647 |
TDmaChannel* pC = DmaChannelMgr::Open(aInfo.iCookie); |
|
648 |
DmaChannelMgr::Signal(); |
|
649 |
if (!pC) |
|
650 |
return KErrInUse; |
|
651 |
||
652 |
TInt r = pC->iController->ReserveSetOfDes(aInfo.iDesCount); |
|
653 |
if (r != KErrNone) |
|
654 |
{ |
|
655 |
pC->Close(); |
|
656 |
return r; |
|
657 |
} |
|
658 |
pC->iAvailDesCount = pC->iMaxDesCount = aInfo.iDesCount; |
|
659 |
||
660 |
new (&pC->iDfc) TDfc(&Dfc, pC, aInfo.iDfcQ, aInfo.iDfcPriority); |
|
661 |
||
662 |
aChannel = pC; |
|
663 |
||
664 |
#ifdef _DEBUG |
|
665 |
pC->Invariant(); |
|
666 |
#endif |
|
667 |
__KTRACE_OPT(KDMA, Kern::Printf("opened channel %d", pC->iPslId)); |
|
668 |
return KErrNone; |
|
669 |
} |
|
670 |
||
671 |
||
672 |
EXPORT_C void TDmaChannel::Close() |
|
673 |
{ |
|
674 |
__KTRACE_OPT(KDMA, Kern::Printf("TDmaChannel::Close %d", iPslId)); |
|
675 |
__DMA_ASSERTD(IsOpened()); |
|
676 |
__DMA_ASSERTD(IsQueueEmpty()); |
|
677 |
__DMA_ASSERTD(iReqCount == 0); |
|
678 |
||
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
679 |
__DMA_ASSERTD(iQueuedRequests == 0); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
680 |
|
0 | 681 |
// descriptor leak? bug in request code |
682 |
__DMA_ASSERTD(iAvailDesCount == iMaxDesCount); |
|
683 |
||
684 |
iController->ReleaseSetOfDes(iMaxDesCount); |
|
685 |
iAvailDesCount = iMaxDesCount = 0; |
|
686 |
||
687 |
DmaChannelMgr::Wait(); |
|
688 |
DmaChannelMgr::Close(this); |
|
689 |
iController = NULL; |
|
690 |
DmaChannelMgr::Signal(); |
|
691 |
||
692 |
__DMA_INVARIANT(); |
|
693 |
} |
|
694 |
||
695 |
||
696 |
EXPORT_C void TDmaChannel::CancelAll() |
|
697 |
{ |
|
698 |
__KTRACE_OPT(KDMA, Kern::Printf("TDmaChannel::CancelAll thread %O channel - %d", |
|
699 |
&Kern::CurrentThread(), iPslId)); |
|
700 |
__DMA_ASSERTD(IsOpened()); |
|
701 |
||
702 |
NThread* nt = NKern::CurrentThread(); |
|
703 |
TBool wait = FALSE; |
|
704 |
TDmaCancelInfo c; |
|
705 |
TDmaCancelInfo* waiters = 0; |
|
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
706 |
|
0 | 707 |
NKern::ThreadEnterCS(); |
708 |
Wait(); |
|
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
709 |
const TUint32 req_count_before = iQueuedRequests; |
0 | 710 |
NThreadBase* dfcnt = iDfc.Thread(); |
711 |
__e32_atomic_store_ord32(&iIsrDfc, (TUint32)KCancelFlagMask); |
|
712 |
// ISRs after this point will not post a DFC, however a DFC may already be queued or running or both |
|
713 |
if (!IsQueueEmpty()) |
|
714 |
{ |
|
715 |
// There is a transfer in progress. It may complete before the DMAC |
|
716 |
// has stopped, but the resulting ISR will not post a DFC. |
|
717 |
// ISR should not happen after this function returns. |
|
718 |
iController->StopTransfer(*this); |
|
719 |
||
720 |
ResetStateMachine(); |
|
721 |
||
722 |
// Clean-up the request queue. |
|
723 |
SDblQueLink* pL; |
|
724 |
while ((pL = iReqQ.GetFirst()) != NULL) |
|
725 |
{ |
|
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
726 |
iQueuedRequests--; |
0 | 727 |
DDmaRequest* pR = _LOFF(pL, DDmaRequest, iLink); |
728 |
pR->OnDeque(); |
|
729 |
} |
|
730 |
} |
|
731 |
if (!dfcnt || dfcnt==nt) |
|
732 |
{ |
|
733 |
// no DFC queue or DFC runs in this thread, so just cancel it and we're finished |
|
734 |
iDfc.Cancel(); |
|
735 |
||
736 |
// if other calls to CancelAll() are waiting for the DFC, release them here |
|
737 |
waiters = iCancelInfo; |
|
738 |
iCancelInfo = 0; |
|
739 |
||
740 |
// reset the ISR count |
|
741 |
__e32_atomic_store_rel32(&iIsrDfc, 0); |
|
742 |
} |
|
743 |
else |
|
744 |
{ |
|
745 |
// DFC runs in another thread. Make sure it's queued and then wait for it to run. |
|
746 |
if (iCancelInfo) |
|
747 |
c.InsertBefore(iCancelInfo); |
|
748 |
else |
|
749 |
iCancelInfo = &c; |
|
750 |
wait = TRUE; |
|
751 |
iDfc.Enque(); |
|
752 |
} |
|
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
753 |
const TUint32 req_count_after = iQueuedRequests; |
0 | 754 |
Signal(); |
755 |
if (waiters) |
|
756 |
waiters->Signal(); |
|
757 |
if (wait) |
|
758 |
NKern::FSWait(&c.iSem); |
|
759 |
NKern::ThreadLeaveCS(); |
|
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
760 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
761 |
// Only call PSL if there were requests queued when we entered AND there |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
762 |
// are now no requests left on the queue. |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
763 |
if ((req_count_before != 0) && (req_count_after == 0)) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
764 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
765 |
QueuedRequestCountChanged(); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
766 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
767 |
|
0 | 768 |
__DMA_INVARIANT(); |
769 |
} |
|
770 |
||
771 |
||
772 |
/** |
|
773 |
DFC callback function (static member). |
|
774 |
*/ |
|
775 |
||
776 |
void TDmaChannel::Dfc(TAny* aArg) |
|
777 |
{ |
|
778 |
((TDmaChannel*)aArg)->DoDfc(); |
|
779 |
} |
|
780 |
||
781 |
||
782 |
void TDmaChannel::DoDfc() |
|
783 |
{ |
|
784 |
Wait(); |
|
785 |
||
786 |
// Atomically fetch and reset the number of DFC queued by ISR and the error |
|
787 |
// flag. Leave the cancel flag alone for now. |
|
788 |
const TUint32 w = __e32_atomic_and_ord32(&iIsrDfc, (TUint32)KCancelFlagMask); |
|
789 |
TUint32 count = w & KDfcCountMask; |
|
790 |
const TBool error = w & (TUint32)KErrorFlagMask; |
|
791 |
TBool stop = w & (TUint32)KCancelFlagMask; |
|
792 |
__DMA_ASSERTD(count>0 || stop); |
|
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
793 |
const TUint32 req_count_before = iQueuedRequests; |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
794 |
TUint32 req_count_after = 0; |
0 | 795 |
|
796 |
while(count && !stop) |
|
797 |
{ |
|
798 |
--count; |
|
799 |
||
800 |
// If an error occurred it must have been reported on the last interrupt since transfers are |
|
801 |
// suspended after an error. |
|
802 |
DDmaRequest::TResult res = (count==0 && error) ? DDmaRequest::EError : DDmaRequest::EOk; |
|
139
95f71bcdcdb7
Revision: 201021
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
109
diff
changeset
|
803 |
__DMA_ASSERTA(!iReqQ.IsEmpty()); |
0 | 804 |
DDmaRequest* pCompletedReq = NULL; |
805 |
DDmaRequest* pCurReq = _LOFF(iReqQ.First(), DDmaRequest, iLink); |
|
806 |
DDmaRequest::TCallback cb = 0; |
|
807 |
TAny* arg = 0; |
|
808 |
||
809 |
if (res == DDmaRequest::EOk) |
|
810 |
{ |
|
811 |
// Update state machine, current fragment, completed fragment and |
|
812 |
// tell DMAC to transfer next fragment if necessary. |
|
813 |
SDmaDesHdr* pCompletedHdr = NULL; |
|
814 |
DoDfc(*pCurReq, pCompletedHdr); |
|
815 |
||
816 |
// If just completed last fragment from current request, switch to next |
|
817 |
// request (if any). |
|
818 |
if (pCompletedHdr == pCurReq->iLastHdr) |
|
819 |
{ |
|
820 |
pCompletedReq = pCurReq; |
|
821 |
pCurReq->iLink.Deque(); |
|
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
822 |
iQueuedRequests--; |
0 | 823 |
if (iReqQ.IsEmpty()) |
824 |
iNullPtr = &iCurHdr; |
|
825 |
pCompletedReq->OnDeque(); |
|
826 |
} |
|
827 |
} |
|
828 |
else if (res == DDmaRequest::EError) |
|
829 |
pCompletedReq = pCurReq; |
|
830 |
else |
|
831 |
__DMA_CANT_HAPPEN(); |
|
832 |
if (pCompletedReq) |
|
833 |
{ |
|
834 |
cb = pCompletedReq->iCb; |
|
835 |
arg = pCompletedReq->iCbArg; |
|
836 |
Signal(); |
|
837 |
__KTRACE_OPT(KDMA, Kern::Printf("notifying DMA client result=%d", res)); |
|
838 |
(*cb)(res,arg); |
|
839 |
Wait(); |
|
840 |
} |
|
841 |
if (pCompletedReq || Flash()) |
|
842 |
stop = __e32_atomic_load_acq32(&iIsrDfc) & (TUint32)KCancelFlagMask; |
|
843 |
} |
|
844 |
||
845 |
// Some interrupts may be missed (double-buffer and scatter-gather |
|
846 |
// controllers only) if two or more transfers complete while interrupts are |
|
847 |
// disabled in the CPU. If this happens, the framework will go out of sync |
|
848 |
// and leave some orphaned requests in the queue. |
|
849 |
// |
|
850 |
// To ensure correctness we handle this case here by checking that the request |
|
851 |
// queue is empty when all transfers have completed and, if not, cleaning up |
|
852 |
// and notifying the client of the completion of the orphaned requests. |
|
853 |
// |
|
854 |
// Note that if some interrupts are missed and the controller raises an |
|
855 |
// error while transferring a subsequent fragment, the error will be reported |
|
856 |
// on a fragment which was successfully completed. There is no easy solution |
|
857 |
// to this problem, but this is okay as the only possible action following a |
|
858 |
// failure is to flush the whole queue. |
|
859 |
if (stop) |
|
860 |
{ |
|
861 |
TDmaCancelInfo* waiters = iCancelInfo; |
|
862 |
iCancelInfo = 0; |
|
863 |
||
864 |
// make sure DFC doesn't run again until a new request completes |
|
865 |
iDfc.Cancel(); |
|
866 |
||
867 |
// reset the ISR count - new requests can now be processed |
|
868 |
__e32_atomic_store_rel32(&iIsrDfc, 0); |
|
869 |
||
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
870 |
req_count_after = iQueuedRequests; |
0 | 871 |
Signal(); |
872 |
||
873 |
// release threads doing CancelAll() |
|
874 |
waiters->Signal(); |
|
875 |
} |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
876 |
#ifndef DISABLE_MISSED_IRQ_RECOVERY |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
877 |
// (iController may be NULL here if the channel was closed in the client callback.) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
878 |
else if (!error && |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
879 |
iController && iController->IsIdle(*this) && |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
880 |
!iReqQ.IsEmpty() && |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
881 |
!iDfc.Queued()) |
0 | 882 |
{ |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
883 |
// Wait for a bit. If during that time the condition goes away then it |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
884 |
// was a 'spurious missed interrupt', in which case we just do nothing. |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
885 |
TBool spurious = EFalse; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
886 |
const TUint32 nano_secs_per_loop = 1000 * 1000; // 1ms |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
887 |
for (TInt i = 5; i > 0; i--) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
888 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
889 |
if (!iController->IsIdle(*this)) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
890 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
891 |
__KTRACE_OPT(KDMA, Kern::Printf("DMAC no longer idle (i = %d)", i)); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
892 |
spurious = ETrue; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
893 |
break; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
894 |
} |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
895 |
else if (iDfc.Queued()) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
896 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
897 |
__KTRACE_OPT(KDMA, Kern::Printf("DFC now queued (i = %d)", i)); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
898 |
spurious = ETrue; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
899 |
break; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
900 |
} |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
901 |
Kern::NanoWait(nano_secs_per_loop); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
902 |
} |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
903 |
if (!spurious) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
904 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
905 |
__KTRACE_OPT(KDMA, |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
906 |
Kern::Printf("Missed interrupt(s) - draining request queue on ch %d", |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
907 |
PslId())); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
908 |
ResetStateMachine(); |
0 | 909 |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
910 |
// Move orphaned requests to temporary queue so channel queue can |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
911 |
// accept new requests. |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
912 |
SDblQue q; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
913 |
q.MoveFrom(&iReqQ); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
914 |
|
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
915 |
SDblQueLink* pL; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
916 |
while ((pL = q.GetFirst()) != NULL) |
0 | 917 |
{ |
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
918 |
iQueuedRequests--; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
919 |
DDmaRequest* pR = _LOFF(pL, DDmaRequest, iLink); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
920 |
__KTRACE_OPT(KDMA, Kern::Printf("Removing request from queue and notifying client")); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
921 |
pR->OnDeque(); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
922 |
DDmaRequest::TCallback cb = pR->iCb; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
923 |
TAny* arg = pR->iCbArg; |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
924 |
if (cb) |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
925 |
{ |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
926 |
Signal(); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
927 |
(*cb)(DDmaRequest::EOk, arg); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
928 |
Wait(); |
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
929 |
} |
0 | 930 |
} |
931 |
} |
|
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
932 |
req_count_after = iQueuedRequests; |
0 | 933 |
Signal(); |
934 |
} |
|
90
947f0dc9f7a8
Revision: 201015
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
36
diff
changeset
|
935 |
#endif // #ifndef DISABLE_MISSED_IRQ_RECOVERY |
0 | 936 |
else |
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
937 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
938 |
req_count_after = iQueuedRequests; |
0 | 939 |
Signal(); |
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
940 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
941 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
942 |
// Only call PSL if there were requests queued when we entered AND there |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
943 |
// are now no requests left on the queue (after also having executed all |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
944 |
// client callbacks). |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
945 |
if ((req_count_before != 0) && (req_count_after == 0)) |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
946 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
947 |
QueuedRequestCountChanged(); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
948 |
} |
0 | 949 |
|
950 |
__DMA_INVARIANT(); |
|
951 |
} |
|
952 |
||
953 |
||
954 |
/** Reset state machine only, request queue is unchanged */ |
|
955 |
||
956 |
void TDmaChannel::ResetStateMachine() |
|
957 |
{ |
|
958 |
DoCancelAll(); |
|
959 |
iCurHdr = NULL; |
|
960 |
iNullPtr = &iCurHdr; |
|
961 |
} |
|
962 |
||
963 |
||
964 |
/** Unlink the last item of a LLI chain from the next chain. |
|
965 |
Default implementation does nothing. This is overridden by scatter-gather channels. */ |
|
966 |
||
967 |
void TDmaChannel::DoUnlink(SDmaDesHdr& /*aHdr*/) |
|
968 |
{ |
|
969 |
} |
|
970 |
||
36
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
971 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
972 |
/** PSL may override */ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
973 |
void TDmaChannel::QueuedRequestCountChanged() |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
974 |
{ |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
975 |
#ifdef _DEBUG |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
976 |
Wait(); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
977 |
__KTRACE_OPT(KDMA, |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
978 |
Kern::Printf("TDmaChannel::QueuedRequestCountChanged() %d", |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
979 |
iQueuedRequests)); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
980 |
__DMA_ASSERTA(iQueuedRequests >= 0); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
981 |
Signal(); |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
982 |
#endif |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
983 |
} |
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
984 |
|
538db54a451d
Revision: 201003
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
985 |
|
0 | 986 |
#ifdef _DEBUG |
987 |
||
988 |
void TDmaChannel::Invariant() |
|
989 |
{ |
|
990 |
Wait(); |
|
991 |
||
992 |
__DMA_ASSERTD(iReqCount >= 0); |
|
993 |
// should always point to NULL pointer ending fragment queue |
|
994 |
__DMA_ASSERTD(*iNullPtr == NULL); |
|
995 |
||
996 |
__DMA_ASSERTD(0 <= iAvailDesCount && iAvailDesCount <= iMaxDesCount); |
|
997 |
||
998 |
__DMA_ASSERTD(iCurHdr == NULL || iController->IsValidHdr(iCurHdr)); |
|
999 |
||
1000 |
if (IsOpened()) |
|
1001 |
{ |
|
1002 |
__DMA_ASSERTD((iCurHdr && !IsQueueEmpty()) || (!iCurHdr && IsQueueEmpty())); |
|
1003 |
if (iCurHdr == NULL) |
|
1004 |
__DMA_ASSERTD(iNullPtr == &iCurHdr); |
|
1005 |
} |
|
1006 |
else |
|
1007 |
{ |
|
1008 |
__DMA_ASSERTD(iCurHdr == NULL); |
|
1009 |
__DMA_ASSERTD(iNullPtr == &iCurHdr); |
|
1010 |
__DMA_ASSERTD(IsQueueEmpty()); |
|
1011 |
} |
|
1012 |
||
1013 |
Signal(); |
|
1014 |
} |
|
1015 |
||
1016 |
#endif |
|
1017 |
||
1018 |
////////////////////////////////////////////////////////////////////////////// |
|
1019 |
// TDmaSbChannel |
|
1020 |
||
1021 |
void TDmaSbChannel::DoQueue(DDmaRequest& /*aReq*/) |
|
1022 |
{ |
|
1023 |
if (!iTransferring) |
|
1024 |
{ |
|
1025 |
iController->Transfer(*this, *iCurHdr); |
|
1026 |
iTransferring = ETrue; |
|
1027 |
} |
|
1028 |
} |
|
1029 |
||
1030 |
||
1031 |
void TDmaSbChannel::DoCancelAll() |
|
1032 |
{ |
|
1033 |
__DMA_ASSERTD(iTransferring); |
|
1034 |
iTransferring = EFalse; |
|
1035 |
} |
|
1036 |
||
1037 |
||
1038 |
void TDmaSgChannel::DoUnlink(SDmaDesHdr& aHdr) |
|
1039 |
{ |
|
1040 |
iController->UnlinkHwDes(*this, aHdr); |
|
1041 |
} |
|
1042 |
||
1043 |
||
1044 |
void TDmaSbChannel::DoDfc(DDmaRequest& /*aCurReq*/, SDmaDesHdr*& aCompletedHdr) |
|
1045 |
{ |
|
1046 |
__DMA_ASSERTD(iTransferring); |
|
1047 |
aCompletedHdr = iCurHdr; |
|
1048 |
iCurHdr = iCurHdr->iNext; |
|
1049 |
if (iCurHdr != NULL) |
|
1050 |
iController->Transfer(*this, *iCurHdr); |
|
1051 |
else |
|
1052 |
iTransferring = EFalse; |
|
1053 |
} |
|
1054 |
||
1055 |
||
1056 |
////////////////////////////////////////////////////////////////////////////// |
|
1057 |
// TDmaDbChannel |
|
1058 |
||
1059 |
void TDmaDbChannel::DoQueue(DDmaRequest& aReq) |
|
1060 |
{ |
|
1061 |
switch (iState) |
|
1062 |
{ |
|
1063 |
case EIdle: |
|
1064 |
iController->Transfer(*this, *iCurHdr); |
|
1065 |
if (iCurHdr->iNext) |
|
1066 |
{ |
|
1067 |
iController->Transfer(*this, *(iCurHdr->iNext)); |
|
1068 |
iState = ETransferring; |
|
1069 |
} |
|
1070 |
else |
|
1071 |
iState = ETransferringLast; |
|
1072 |
break; |
|
1073 |
case ETransferring: |
|
1074 |
// nothing to do |
|
1075 |
break; |
|
1076 |
case ETransferringLast: |
|
1077 |
iController->Transfer(*this, *(aReq.iFirstHdr)); |
|
1078 |
iState = ETransferring; |
|
1079 |
break; |
|
1080 |
default: |
|
1081 |
__DMA_CANT_HAPPEN(); |
|
1082 |
} |
|
1083 |
} |
|
1084 |
||
1085 |
||
1086 |
void TDmaDbChannel::DoCancelAll() |
|
1087 |
{ |
|
1088 |
iState = EIdle; |
|
1089 |
} |
|
1090 |
||
1091 |
||
1092 |
void TDmaDbChannel::DoDfc(DDmaRequest& /*aCurReq*/, SDmaDesHdr*& aCompletedHdr) |
|
1093 |
{ |
|
1094 |
aCompletedHdr = iCurHdr; |
|
1095 |
iCurHdr = iCurHdr->iNext; |
|
1096 |
switch (iState) |
|
1097 |
{ |
|
1098 |
case ETransferringLast: |
|
1099 |
iState = EIdle; |
|
1100 |
break; |
|
1101 |
case ETransferring: |
|
1102 |
if (iCurHdr->iNext == NULL) |
|
1103 |
iState = ETransferringLast; |
|
1104 |
else |
|
1105 |
iController->Transfer(*this, *(iCurHdr->iNext)); |
|
1106 |
break; |
|
1107 |
default: |
|
1108 |
__DMA_CANT_HAPPEN(); |
|
1109 |
} |
|
1110 |
} |
|
1111 |
||
1112 |
||
1113 |
////////////////////////////////////////////////////////////////////////////// |
|
1114 |
// TDmaSgChannel |
|
1115 |
||
1116 |
void TDmaSgChannel::DoQueue(DDmaRequest& aReq) |
|
1117 |
{ |
|
1118 |
if (iTransferring) |
|
1119 |
{ |
|
1120 |
__DMA_ASSERTD(!aReq.iLink.Alone()); |
|
1121 |
DDmaRequest* pReqPrev = _LOFF(aReq.iLink.iPrev, DDmaRequest, iLink); |
|
1122 |
iController->AppendHwDes(*this, *(pReqPrev->iLastHdr), *(aReq.iFirstHdr)); |
|
1123 |
} |
|
1124 |
else |
|
1125 |
{ |
|
1126 |
iController->Transfer(*this, *(aReq.iFirstHdr)); |
|
1127 |
iTransferring = ETrue; |
|
1128 |
} |
|
1129 |
} |
|
1130 |
||
1131 |
||
1132 |
void TDmaSgChannel::DoCancelAll() |
|
1133 |
{ |
|
1134 |
__DMA_ASSERTD(iTransferring); |
|
1135 |
iTransferring = EFalse; |
|
1136 |
} |
|
1137 |
||
1138 |
||
1139 |
void TDmaSgChannel::DoDfc(DDmaRequest& aCurReq, SDmaDesHdr*& aCompletedHdr) |
|
1140 |
{ |
|
1141 |
__DMA_ASSERTD(iTransferring); |
|
1142 |
aCompletedHdr = aCurReq.iLastHdr; |
|
1143 |
iCurHdr = aCompletedHdr->iNext; |
|
1144 |
iTransferring = (iCurHdr != NULL); |
|
1145 |
} |