Bitzenbytes.com

CompuClues Forum

  User  Password
Sunday, July 06, 2008 - 04:58 AM
Search
Main Menu
Who's Online
MEMBERS ONLINE

You are an anonymous user. You can register for free by clicking here
User name
Password
 Remember me
Firefox
Get Firefox 110
Languages
Preferred language:

DMA 101 - CompuClues Arcanum
DMA 101
Date: April 14, 2001
Revised: February 14, 2003
Author: Bob

DMA (in response to a request for information about DMA - Direct Memory Access)...

Direct Memory Access (DMA)   The sequence of events for DMA transfer
Interrupt Handling Processor handling of hardware interrupts is described in this section. 
Interrupt Acknowledge Cycle Many processors allow the interrupting hardware device to identify itself. This speeds up interrupt handling as the processor can directly invoke the interrupt service routine for the right device.
Synchronization Requirements
for
DMA and Interrupts
Software designers need to keep in mind that DMA operations can be triggered at bus cycle boundary while interrupts can only be triggered at instruction boundary.

Direct Memory Access (DMA)

DMA is not a very, uh, basic subject, but deserves to be addressed. In this day of plug and play, most people can remain uninformed about DMA and not suffer much, if at all, in the way of any consequences. Plug and Play was designed to enable a user to add an expansion card without having to worry about configuration let alone configuration to avoid conflicts. We're supposing that most people order the system the way they want it from a vendor, that it will come adequately configured, and they will seldom be tempted to change it. Don't disturb sleeping dogs.

We're also supposing that most, if not all, of the peripheral card components are going to be PCI Plug and Play. Using plug and play devices should require only that the user plug the card in, start the system, and provide disk access to drivers to be installed. In a perfect world, the operating system should read the new device and in consultation with registry entries, configure the new device so that there are no conflicts.

Provided that everybody does their job, and provided that the user doesn't try to make a system do everything under the sun. Newer interfaces such as USB go a long way to avoiding even more potential conflicts.

Keeping a list of things like IRQ's used, I/O ports used, DMA channels assigned, and so forth, and setting up new devices using jumpers, switches, and flash memory programs is greatly diminished to non-existent. Resources, however, are still limited. Not all devices act as advertised. And exclamation points, question marks, and red X's are still with us. If you are adding older cards to a computer, where the older cards require manual intervention, these cards must not conflict with the settings assigned to PNP devices.

This usually means allocating the resources for legacy cards first or as soon as possible. For most people, the best advice is "leave the legacy stuff in the past." The cost of the most common peripheral cards in a PNP version is low in comparison to the potential headaches.

Adding a device, mostly, should require only removal of the item from the box and plunking it down in a bus slot. Experience and the vagarities of design however sometimes dictate some intervention. Information about your configuration for older, non-PNP cards is stored in the registry, and non-PNP or "Forced Hardware" devices get first priority for resource allocation with automatic allocation forced to use what's left. Works, mostly.

ADD NEW HARDWARE (Control Panel) will let you configure devices that Windows doesn't find. Under Windows 9x, DEVICE MANAGER (System Properties) is used to change the properties of installed devices. Users that do not have knowledge of how these resources are allocated are well advised to not mess with the resources allocated, and to seek any free support they are entitled to when attempting to fix a problem. For those inclined to do their own work and for those who's support has run out, this may be informative, but the standard caveat applies: use at own risk.

The Registry contains the information about IRQs, I/O addresses, and DMA channels (used and unused), and this is what Windows reads to discover resources used and resources available for communication with installed and new devices. Windows uses VxDs (virtual device drivers for Intel specific instruction sets) to replace what were real mode MS-DOS device drivers in a former era. VxDs are employed for SCSI drives and SCSI stuff, SMARTDrive, CD-ROM file system, FAT file systems, Network drivers, Network clients, Network transport protocols, Sharing, Mice and other finger pointers, and lots of other stuff. In turn, Windows 98 (and W2K) incorporate a common set of kernel mode interfaces (WDM) based on the Windows NT 4.0 driver model which allows binary compatibility between Windows 98 and W2K. WDM (Win32 Driver Model) is used, typically, to enhance or displace VxDs. Again, disk drives, tape drives, keyboards, mice, displays, serial and parallel port devices, multimedia devices and others can fall into this category. It is WDM that adds the functionality of the IRP_MJ_PNP I/O request.

Plug and Play specifies hardware that will identify itself to the OS and software that can locate and configure device drivers for identified hardware. WDM allows device drivers to discover which devices they belong to and what I/O resources to use. All of this is used to ensure that the user doesn't need to worry about resource allocation. Configuration Manager uses the IRP_MJ_PNP I/O request and an AddDevice function within the driver to administer the Plug and Play software. Ask me no more, I will tell you no lies--I don't write device drivers and I'm not a DMA expert. This arrives by way of filling the void for the first message.

Configuration Manager (CM) looks at all of the installed hardware in the computer and what the possibilities are for meeting the I/O resources (like interrupts, I/O ports, DMA channels, etc.) required by those devices, and then attempts to meet the needs of all devices without causing conflicts.

So if your sound card will only configure on IRQ 5 and your NIC will configure on 5, 10, or 11, then CM gives your sound card 5 and your NIC gets something else that it can use instead. For the event that installation seems to be confused (conflicts arise), your knowledge of this could indicate that one possible action to take toward resolution would be to remove the NIC, configure the sound card, and install the NIC on a second go round.

PC computers have designated I/O devices. These can be hard drives, CD-ROMs, CD-RW drives, DVD players, tape drives, modems, serial ports, keyboards, mice, and many others. Data must be transferred to and from these devices. Primarily, data is transferred by one of the following methods: polling, interrupt handling, and Direct Memory Access (DMA.)

During normal processing of a program, one or more of these I/O devices may need to deliver or receive somewhat large quantities of data that could be related to the foreground program or not.

Let's say you are downloading a file and working on a spreadsheet while the file downloads; you also have your mail program open and periodically it checks the mail server to see if you have new messages. You have a single processor.

Foreground acquisition: The mail program is polling. The processor is switching among programs and executing a few instructions for each program before moving onto the next. When the processor switches to the mail program, it checks the time, and if it is time to check the server, the mail client, as part of its normal processing, polls the server. In other words, it sends a message to the mail server to see if there is data in the form of a message to download. While waiting for a response from the server, the mail program sits there in a loop, waiting. If there is a message waiting, the mail client downloads the message by instructing the processor to do that. The mail client instructs the processor to acquire the data. This is polling. Normal instructions, issued to the processor during normally allocated processing time, perform the action. The action is performed by a routine loaded by the foreground program. This may be a less than clear example. The modem communications part of this equation are probably both interrupt driven and somewhat likely to be employing DMA as well. The point is that the mail client program sits there in a loop waiting for the arrival of data (and checking on arrival status) so that when that data arrives, the CPU can be employed in processing that data.

Background acquisition: For interrupt driven data acquisition, some event within the computer system indicates that a task must be performed. Let's say a data buffer is filled and the incoming data stream requires that this buffer be emptied so that the arrival of more data can be accommodated. On the occurrence of the event, an interrupt is generated. This is a trigger that was generated by hardware detection of a pre-defined condition. The processor looks at the priority of the interrupt and if that priority is higher than the current program being processed, the current program execution is suspended, and the processor is dedicated to handling the interrupt according to a predefined set of rules. In this case the data in the buffer is handled, the buffer is flushed, the buffer is made available for more incoming data, and control of execution is returned for handling the suspended program. An event having nothing to do with the foreground program being processed, caused data to be handled.

In both cases, processor time was dedicated to handling data. In the first case, the processor time was used by design of the foreground program. In the second case, the processor time was demanded by the needs of the system and resulted in a delay in execution for the foreground program.

More Background acquisition: Using DMA, the third case, the DMA controller reads the incoming data stream and stores that data in a memory buffer for later retrieval on demand. The processor is not involved in processing the transfer of data from device to memory. Data is still transferred across the (expansion) bus, but it is transferred only when the bus is not being used for other purposes. DMA transfer of data is typically more efficient than processor control of the data transfer.

DMA transfers, to and from memory, use DMA memory buffers of limited size. Depending on the design of a DMA enabled device, one or more DMA channels may be supported. Typically, for most devices, one channel. Two channels for some sound cards and there are other such devices. Only one device can use a DMA channel at a time. Few devices will share a DMA channel with another device ("OK, I'm not using the DMA channel, so you can") and probably not any that most people would purchase. So mostly, one channel = one use.

Channel -- Data Width -- Standard Description -- Typical Use
--------------------------------------------------------------

0 -- 8 or 16 bit -- Reserved -- Audio (supposedly)
1 -- 8 or 16 bit -- SDLC Controller -- Audio or LAN
2 -- 8 or 16 bit -- Floppy Disk Controller -- FDU Controller
3 -- 8 or 16 bit -- Hard Disk Controller -- ECP/EPP port
4 -- 16 bit -- Cascade DMA channels 0 - 3 -- same
5 -- 16 bit -- Reserved -- LAN
6 -- 16 bit -- Reserved
7 -- 16 bit -- Reserved

If a tech has the standard IRQ chart in his head, there's some likelyhood that this standard DMA chart is in his head also. Maybe.

Here's how DMA works:

  • The device wishing to perform DMA asserts the processor bus request signal
  • The processor completes the current bus cycle & then asserts the bus grant signal to the device
  • The device asserts the bus grant ack signal
  • The processor reads the change in state for the bus grant ack signal & starts listening to the data and address bus for DMA activity
  • The DMA device performs the transfer from the source to destination address
  • During DMA transfers, the processor monitors the addresses on the bus and checks to determine if any location modified during DMA operations is cached in the processor.
    If the processor detects a cached address on the bus, it will perform one of the following actions:
    • The processor invalidates the internal cache entry for the address involved in DMA write operation
    • The processor updates the internal cache when a DMA write is detected
  • When DMA operations are completed, the device releases the bus by asserting the bus release signal
  • The processor acknowledges the bus release & resumes bus cycles from the point where it left off.

For devices that may use DMA, in START - SETTINGS - CONTROL PANEL - SYSTEM - DEVICE MANAGER, right click on COMPUTER and select properties. Click on the DMA radio button. Also in Device Manager, in the properties for devices that are or can use DMA, find a DMA check box under "Options" for each such device.

In Windows 98, go to START - RUN and enter MSINFO32. Under SYSTEM INFORMATION - HARDWARE RESOURCES, click on DMA to see a listing of how Windows 98 thinks your DMA channels are currently configured and used, the devices using them, and the DMA channels that are free. If you are having problems, you can go to the COMPONENTS - PROBLEM DEVICES leaf in the Microsoft System Information (MSINFO32) tree to get information about what Windows thinks is a problem.

About MSINFO32: Microsoft KB Article Q184075

ADDHARDWARE (Control Panel) is used to configure both PNP and non-PNP devices on a Win 98 system.

If you have a conflict with another device that uses the same DMA channel, you usually get no DMA for either device. For pre-PCI, pre-PNP (Plug and Play) devices, ISA devices were manually configured, typically using jumpers or software. If you are using legacy 16 bit cards that employ DMA or you are instructed to disable PnP, you need to address this by forcing the hardware (see URL above).

It would seem like a good idea to employ DMA as much as possible to relieve the CPU of data transfer chores. For some motherboards, BIOS settings will determine how on-board devices (like parallel ports) are handled.

The original DMA chip in the IBM-PC was the 8237A (since then functional compatibility with this chip is incorporated into most chipsets), it supplies 4 DMA channels, and can only address an 8 bit (1 MB) expansion bus. The first channel was reserved for refreshing memory--the other three channels are available on the I/O bus.

In the AT and machines of its class, a second DMA controller was added and was cascaded using one of the 8 DMA channels yielding 7 DMA channels. Four of these channels were 8 bits wide and 3 were 16 bits wide and addressing was limited to 16 MB of memory due to the 24 address lines on the expansion bus.

These two DMA chips are emulated in modern chipsets, often with all of the channels being capable of 16 bits. But then, ISA bus devices are somewhat slow by today's standards. For the most part, the ISA bus is not capable of keeping up with disk controller demands or video, let alone some of the multi-media interfaces. So most all of such memory transfers have been moved to the PCI bus. The number of ISA bus slots on modern motherboards has been diminishing for some time and often there may only be one such slot sharing space with a PCI slot if there is any ISA slot at all. The number of devices using DMA transfers are diminishing as well.

The PCI bus does not allow DMA control as there are no DMA signals allocated. The same memory transfer (without utilizing the CPU) is accomplished through bus-mastering. A bus master acts like a DMA chip. There being no DMA signals on the PCI bus, devices that require DMA have a problem. Signaling on the PCI bus is different than on the ISA bus and this presents further problems. The rules for memory allocation used by PCI are different as well. DMA in PCI systems is implemented through Distributed DMA support.

Distributed DMA uses bus mastering to provide a program interface that supports legacy DMA--sort of DMA emulation. Distributed DMA provides very high performance and frees up significant PCI-bus bandwidth. There are better technical explanations around, but the following will do for this treatment. The PCI bridge has circuitry built-in that functions as a DMA master (which looks like two 8237A DMA chips.) When a DMA transfer is requested, the DMA master intercepts the signal and translates legacy DMA signals into PCI compatible signals. The PCI signals are sent to a DMA slave which may be connected to an ISA bus or a device controller. The DMA Slave interprets the PCI signals and carries out the DMA instructions as if it were a DMA controller. Master-to-slave over (a somewhat faster bus), hence "distributed." The master looks like a DMA controller to your software and the slave looks like a DMA controller to the hardware.

In newer machines, disks, for instance, are designed to use either programmed I/O (PIO) or first-party DMA (bus mastering) on the PCI bus. The standard ISA DMA programming has been abandoned. SCSI cards, NICs, and video cards now pretty much employ bus mastering over the PCI bus. Hard Drives do not employ DMA any more.

DMA channels are single-device resources; one device per channel else conflict. Most devices seem to want to use the 8 bit DMA channels (1 - 3).

For example, let's take the parallel port (LPT1 or whatever). 5 standard modes of operation for Parallel Port’s can be found under IEEE 1284 which has been around for a long time:

1. Compatibility Mode.
2. Nibble Mode.
3. Byte Mode.
4. EPP Mode (Enhanced Parallel Port).
5. ECP Mode (Extended Capabilities Port).

Not to worry about modes 1-3. Today, most Parallel Ports are multi-mode ports:

Printer Mode (Sometimes called Default or Normal Modes)
Standard & Bi-directional (SPP) Mode
EPP1.7 and SPP Mode
EPP1.9 and SPP Mode
ECP Mode
ECP and EPP1.7 Mode
ECP and EPP1.9 Mode

Again, in today's world, this means mostly ECP and maybe EPP (and so it is likely that the charts above are not in anybody's head.) In CMOS, the BIOS settings have an I/O configuration that allows me to specify mode for the parallel port (this is not unusual.) If I pick ECP or ECP+EPP (and I will), I will be prompted to enter a DMA channel for use. Because my Sound Blaster emulation would like DMA channel 1, I select DMA channel 3 to support ECP. If your BIOS offers you the opportunity to select DMA channel 2, don't; your floppy drive will suffer for this. Dedicated circuits handle memory refresh and DMA 0 is typically free, sort of. Except that because traditionally DMA 0 is for system use only, nobody programs for it. At least, I've never seen DMA 0 used for anything, not that I've looked at a whole lot of configurations, but my reading indicates that it can be used, provided that your Operating System (check for Linux which may not) and card will tolerate (is designed for) this. DMA 1 is available for use for sound cards since hard drives no longer require it. The most common DMA conflicts occur with contention for either DMA 1 or DMA 3 (typically with voice modems.) DMA 4 is the cascade and you can't use it. Some sound cards will use DMA channel 5. Some Creative cards will come set for default of DMA 5 but will configure for DMA 6 or 7. Some NICs will use channel 5; NICs will usually configure for other DMA channels if needed. Depending on the card, either may possibly not allow change. Some SCSI controllers use DMA channel 5. Some CD-ROM cards use DMA channel 5. If you are doing data acquisition through a custom or special purpose I/O card that requires DMA, the specs for the card should contain instructions for configuration. Some of these cards will ping-pong DMA 6 and 7. Generally, if there is a conflict and you can reconfigure, you would, for instance, let the SCSI controller have what it wants, and reconfigure DMA use for the sound card. Some number of SCSI controllers use DMA 6. Older, oddball NICs used DMA 6. Your CD-RW may want to use DMA--and you may end up electing to not use it, if it works only when you deselect DMA.

As for me, if there are no conflicts, I don't mess with DMA.

[Printer friendly page | Send to a friend]