ISA DMA: Difference between revisions

676 bytes added ,  12 days ago
m
no edit summary
[unchecked revision][unchecked revision]
mNo edit summary
 
(13 intermediate revisions by 10 users not shown)
Line 6:
* Transfers must be physically contiguous, and can only target the lowest 16 MB of physical memory;
* ISA DMA is slow - theoretically 4.77 MB/second, but more like 400 KB/second due to ISA bus protocols;
* ISA DMA frees up CPU resources, but loadsadds an extremely heavy load to the memory bus extremely heavily;
* Very few devices currently use ISA DMA -- only internal floppies, some embedded sound chips, some parallel ports, and some serial ports.
 
Notes:
* Sound Blaster and Sound Blaster PRO only support 8 bit DMA;
* [[Sound Blaster 16]]+ supports both;
* [[Floppy disk controllers]] only support 8 bit DMA and are hardwired to use DMA Channel 2.
 
== There Is More Than One Kind of DMA on a PC ==
Line 23:
 
== ISA DMA Background ==
'''ISA DMA''' (''Industry Standard Architecture Direct Memory Access''), like ISA itself, is an [https://en.wikipedia.org/wiki/Appendix_(anatomy) appendix] for modern PCs. It is used by the
internal floppy disk controller, ISA sound cards, ISA network cards, and parallel ports (if they support ECP mode). Whilst interrupt, keyboard
and timer interface circuits have obvious and relevant uses, the ISA DMA controller and its programming interface are still well and truly stuck in the
Line 62:
== Technical Details ==
Each 8237 DMA chip has 4 DMA channels. DMA0-DMA3 on the first chip and DMA4-DMA7 on the second. The first DMA controller is wired up for 8 bit transfers,
while the second is wired up for 16 bit transfers. On some tutorials or other wiki articles, you will sometimes see the '''second''' DMA chip (channels 4 to 7) labeled as the "'''master'''" controller, and the first (channels 0 to 3) called the "slave". This is highly confusing, and these terms will not be used again, here.
while the second is wired up for 16 bit transfers.
 
DMA Channel 0 is unavailable as it was used for a short time for DRAM memory refresh, and remains reserved because of this (even though modern computers
Line 139:
interrupt when a transfer completes. However, some peripherals may '''not''' send an interrupt if a transfer fails with an error. As always, timeouts
are important.
 
=== The Registers ===
The master and slave DMA controllers are very similar, so (to save space) both of them have been combined into the following table. Please try
not to let this confuse you.
 
Note: for Address and Count Registers on channels 5 to 7, see [[#16 bit issues|16 bit issues]] above.
 
Line 305 ⟶ 304:
 
;Single Channel Mask Registers 0x0A and 0xD4 (Write)
 
{| {{wikitable}}
|-
Line 327 ⟶ 325:
|}
 
 
If you do not want to figure out the mask states of all the other channels, you can mask/unmask one channel at a time with this register.
These registers are used to mask (or unmask) DRQ for a single channel only, on either the master or slave DMA chip.
IfThat is, if you do not want to figure out the mask states of all the other channels, you can mask/unmask DRQ for one channel at a time with this register.
Use the SEL 0 and 1 bits to select the channel, and the MASK_ON bit to set or clear masking for it.
Note that masking DMA channel 4 will mask 7, 6, 5 and 4 due to cascading.
Line 354:
|}
 
Setting the appropriate bits to 0 or 1 allows you to unmask or mask (respecivelyrespectively) DRQ for those channels. Using this register means that your driver needs
to know the desired mask states of ''all'' the channels at that moment. There are several ways to do this, but one is simply to read this register, first.
Note that masking DMA channel 4 will mask 7, 6, 5 and 4 due to cascading.
Line 496:
bus. Real code should separate the two "out 0x4" and "out 0x5" calls with an "out" to some other port.
 
<sourcesyntaxhighlight lang="asm">
initialize_floppy_DMA:
; set DMA channel 2 to transfer data from 0x1000 - 0x33ff in memory
Line 502:
; set the counter to 0x23ff, the length of a track on a 1.44 MiB floppy - 1 (assuming 512 byte sectors)
; transfer length = counter + 1
out 0x0a, 0x050x06 ; mask DMA channel 2 and 0 (assuming 0 is already masked)
out 0x0c, 0xFF ; reset the master flip-flop
out 0x04, 0 ; address to 0 (low byte)
Line 510:
out 0x05, 0x23 ; count to 0x23ff (high byte),
out 0x81, 0 ; external page register to 0 for total address of 00 10 00
out 0x0a, 0x010x02 ; unmask DMA channel 2
ret
</syntaxhighlight>
</source>
 
Once you have set up your start address and transfer length you do not need to touch it again, if you are using autoinit. Once reading or writing
is selected, you don't need to change that, either. To ''change'' selecting reading or writing you use the mode register.
 
<sourcesyntaxhighlight lang="asm">
prepare_for_floppy_DMA_write:
out 0x0a, 0x050x06 ; mask DMA channel 2 and 0 (assuming 0 is already masked)
out 0x0b, 0x5A ; 01011010
; single transfer, address increment, autoinit, write, channel2)
out 0x0a, 0x010x02 ; unmask DMA channel 2
ret
 
prepare_for_floppy_DMA_read:
out 0x0a, 0x050x06 ; mask DMA channel 2 and 0 (assuming 0 is already masked)
out 0x0b, 0x56 ; 01010110
; single transfer, address increment, autoinit, read, channel2)
out 0x0a, 0x010x02 ; unmask DMA channel 2
ret
</syntaxhighlight>
</source>
 
Some hardware, as well as VirtualPC do not support autoinit. You may want to set the Mode registers to 0x4A and 0x46 in the above routines, instead.
Note: Due to problems with autoinit on some real hardware and MS Virtual PC you might want to not use it -- and
set the Mode registers to 0x4A and 0x46 in the above routines, instead.
 
The above routines use single transfer mode for compatibility, but during the initialization of your floppy driver if you detect an "advanced" floppy
Line 543 ⟶ 542:
=== Articles ===
* [[Floppy Disk Controller]]
* [[Sound Blaster 16]]
 
=== External Links ===
* [http://www.intel-assembler.it/PORTALE/4/231466_8237A_DMA.pdf Intel 8237A datasheet]
*[http://bos.asmhackers.net/docs/dma/docs/ http://bos.asmhackers.net/docs/dma/docs/]
 
[[Category:Storage]]
[[de:DMA]]