Direct Memory Access - aryanjoshi0823/5143-Operating-System GitHub Wiki

DMA (Direct Memory Access) is a special feature in computer systems that allows data transfer between memory and peripheral devices (e.g., hard drives) without CPU intervention. This method is particularly beneficial for large data transfers, as using the CPU for such tasks, often referred to as Programmed I/O, would be inefficient. Instead, computers offload this task to a DMA controller.


DMA Operation:

To initiate a DMA transfer, the host system performs the following steps:

  1. DMA Command Block Creation:
    The host writes a command block into memory, which contains:

    • A pointer to the source of the data.
    • A pointer to the destination of the data.
    • The number of bytes to be transferred.

    In advanced cases, this block may include a list of non-contiguous source and destination addresses.

  2. CPU Delegation: The CPU writes the address of the DMA command block and then resumes other tasks.

  3. DMA Controller Execution: The DMA controller operates the memory bus directly, placing addresses on it without further CPU intervention.


Communication Between Controllers

The communication between the device controller and the DMA controller occurs via two dedicated wires:

  • DMA Request (DREQ): Signal sent by the device controller when a word of data is ready for transfer.
  • DMA Acknowledge (DACK): Signal sent by the DMA controller to indicate successful data transfer.

Working of DMA Transfer

  1. The device controller raises a signal on the DMA request wire when data is available for transfer.
  2. The DMA controller seizes control of the memory bus and places the destination address on the DMA acknowledge wire.
  3. Upon successful transfer, the device controller receives the DMA acknowledge signal and removes the DMA request signal.
  4. After completing the entire transfer, the DMA controller interrupts the CPU.

Key Concepts in DMA Transfer

  • Cycle Stealing:
    The DMA controller temporarily seizes the memory bus, preventing the CPU from accessing main memory. Although the CPU can still use cached data, this can slow down computation. However, offloading data transfer to the DMA controller typically enhances overall system performance.

  • Physical vs. Virtual Addressing:
    Some computer architectures use physical memory addresses for DMA, while others use virtual addresses, known as Direct Virtual Memory Access (DVMA). DVMA allows data transfer between memory-mapped I/O devices without involving main memory.