Tuesday, April 8, 2014

Direct memory access(DMA)


Describe direct memory access (DMA). Can a user level buffer/pointer be used by kernel or drivers?


Direct Memory is a feature which provides direct access (read/write) to system memory without interaction from the CPU. So, if DMA is available, then processor can route long read or write requests of disk blocks to the DMA and concentrate on other work.

The “DMA Controller” manages this by requesting the System bus access (DMA request) from CPU. The CPU bus is always partly used by the DMA and the rest of the channel is free to use for any other jobs/process to run. This is the key advantage of DMA over I/O.
CPU completes its current task and grants access by asserting DMA acknowledgement signal. Once it gets the access, it reads/writes the data and returns back the system bus to the CPU by asserting the bus release signal. This transfer is faster than the usual transfer by CPU. Between this time CPU is involved with processing task which doesn’t require memory access.
By using DMA, drivers can access the memory allocated to the user level buffer/pointer. Note that, DMA nowadays is obsolete.

DMA vs Memory mapped IO
Memory mapped I/O allows the CPU to control hardware by reading and writing specific memory addresses. Usually this would be used for low-bandwidth operations such as changing control bits.
DMA allows hardware to directly read and write memory without involving the CPU. Usually this would be used for high-bandwidth operations such as disk I/O or camera video input.

DMA vs Cache
DMA is a hardware device that can move to/from memory without using CPU instructions.
For instance, a hardware device (lets say, your PCI sound device) wants audio to play back. You can either:
  1. Write a word at a time via a CPU mov instructions.
  2. Configure the DMA device. You give it a start address, a destination, and the number of bytes to copy. The transfer now occurs while the CPU does something else instead of spoon feeding the audio device.
DMA can be very complex (scatter gather, etc), and varies by bus type and system.




Post a Comment