Page 1 of 1

DMA setup critical region

Posted: Fri Jul 22, 2005 6:33 pm
by pini
It is commonly admitted that the DMA setup (I mean here setting up page, address and count DMA registers for a transfer to come) has to be embedded between

Code: Select all

cli
and

Code: Select all

sti
, so that it cannot be interrupted.

My question is: is this necessary ? what is the risk when being interrupted ?

Thanks in advance

pini

Re:DMA setup critical region

Posted: Sat Jul 23, 2005 4:36 am
by Brendan
Hi,

As far as I can tell, as long as an IRQ (or another thread if an IRQ can cause a thread switch) can't mess with the same DMA channel that you're setting up you may not need to disable interrupts.

There are probably some unusual circumstances (e.g. where a device driver can setup a DMA transfer outside of it's IRQ handler and/or within it's IRQ handler) that could break things. One example would be an IRQ handler that could read a DMA channel's count while it's in the middle of being set.

I guess disabling interrupts is fast and it's good insurance (just to make sure). It's certainly easier than trying to think of all of the problems that could occur, or writing a list of unusual situations that device driver writers need to be careful of. :)


Cheers,

Brendan