## MMPM/2 Device Driver Reference

[prev][next][parent][TOC]

### Data Transfers

Following are the two methods of transferring data:

Direct Memory Access (DMA) The most efficient way to transfer data from the host system to the audio adapter's memory is through direct memory access ( DMA). This is a technique for moving data directly between main storage without requiring processing of the data by the CPU. To accomplish this, we create a DMA buffer within the device driver to transfer the data. As the device driver receives the stream buffer data, it copies the stream buffer data into the DMA buffer at interrupt time. When the DMA buffer is full, it can be sent directly to the audio device. A preferable (but unproven) method would be to DMA directly from the stream buffer. Currently, however, a copy operation (which requires time and CPU utilization) is required to get data into the AUDIODD DMA buffer.

To perform direct memory access, you are essentially programming the DMA microcontroller on the system board. For each direct memory access, you can DMA transfer data up to the limit of the DMA channel that the audio adapter is using:

- 64KB for the 8-bit DMA channels 0, 1, and 3

- 128KB for the 16-bit DMA channels 5, 6, and 7

Note that this DMA transfer must always be from the same buffer pointer. Unless you decide to change the buffer pointer, you would have to reprogram the microcontroller from the beginning.

Therefore, if you want to DMA directly from the stream buffer, your device driver would always require a different pointer which means reprogramming the DMA controller at each interrupt. So, each time you get a new buffer from the stream handler, you would have to look at the pointer, reprogram the DMA controller, and then start the DMA transfer. At this stage, most developers state that there is not enough time to reprogram the DMA controller during interrupt time. Therefore, they are creating one DMA buffer when the device driver is initialized at system startup. The developer programs the DMA controller at that point, informs the controller that this is the pointer, and tells it how much data the device driver is going to transfer. The value is set for the lifetime of the driver.

Dual DMA Buffers

MMPM/2's stream handler implementation uses two DMA buffers or dual DMA buffers to ensure a smooth flow of audio data.

In this implementation, the amplifier-mixer (ampmix) device issues a request through the OS/2 kernel to the audio PDD for it to prepare to process audio data. The audio PDD informs the stream handler that it needs the audio data, and the stream handler informs the file system PDD to fill two 4KB DMA buffers with the appropriate audio data.

When the audio PDD processes the first 4KB buffer, it issues a hardware interrupt that signals the file system PDD to replace the first 4KB buffer with the next 4KB of audio data. Meanwhile, the audio PDD is processing the second 4KB buffer. When the audio PDD processes the second 4KB buffer, it issues a hardware interrupt again and the process is repeated.

With this process, you only have to track two DMA buffers and the stream handler ensures a smooth flow of audio data to the audio PDD. The following illustration provides an overview of this process.

                    1st 4KB DMA    2nd 4KB DMA

                   /---------------------------\

              /---|             |             |

              |    |             |             |

              |    \---------------------------/

              |

    /----------------------\     \---------------The audio PDD

    |                      |                     issues hardware

    | /-----------------\  |                     interrupts when it

    | | Stream Handler  |  |                     finishes processing

    | \---- - ------- - ---- /    |                         each   4KB   DMA   block .

    |         |         |          |

    |     |    |         |    |      |

    |     |                 |      |        The   stream   handler   manages

    |   / - - ----- \    / ---- - -- \   |        the   process   of   the   audio

    |   | Audio    |    | File     |   |        PDD   processing   4KB   DMA

    |   | PDD      |    | System   |   |        blocks   and   the   file   system

    |   |         |    | PDD      |   |        PDD   replacing   the   block   as

    |   \ ------- /    \ ------- /   |        it   is   processed .

    \ ---------- ---------- -- /

Programmed I/O Programmed I/O involves copying the stream buffer's data directly to the adapter's buffer.