DMA setup critical region

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
pini

DMA setup critical region

Post 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
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:DMA setup critical region

Post 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
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply