DMA question
DMA question
THere?s one thing I havent been able to figure out about DMA, and that is how to chose where to copy data (if I want to send data to some device). Suppose I know that when I send a command, this device will try to send some data using DMA channel 0. If I set up DMA and enable it, will the hardware do the rest for me? So I dont need to specify which device/ports I?d like to write/read from, just enabling the right DMA channel and the device(which is operating on the channel) will do the work for me and copy the data as soon as the channel is enabled?
The reason for me asking this is because I?m currently writing a floppy driver. Is it enought to just set up DMA, sending a read (for instance) command to the device, enable the channel that the floppy uses, and then the floppy will "sense" that the channel is enabled and then copy the data (and then trigger an IRQ of course)
The reason for me asking this is because I?m currently writing a floppy driver. Is it enought to just set up DMA, sending a read (for instance) command to the device, enable the channel that the floppy uses, and then the floppy will "sense" that the channel is enabled and then copy the data (and then trigger an IRQ of course)
Re:DMA question
You use either DMA or ports. You cannot set a port number for DMA to use. What sort of twisted logic is that?Rolf wrote: THere?s one thing I havent been able to figure out about DMA, and that is how to chose where to copy data (if I want to send data to some device). Suppose I know that when I send a command, this device will try to send some data using DMA channel 0. If I set up DMA and enable it, will the hardware do the rest for me? So I dont need to specify which device/ports I?d like to write/read from, just enabling the right DMA channel and the device(which is operating on the channel) will do the work for me and copy the data as soon as the channel is enabled?
You set up the DMA controller to read from channel X to address A. You set up the floppy drive to read from CHS Z to DMA channel X. That's all.
I'd enable the channel first (the dma chip waits when reading, the floppy drive can't wait when writing). Other than that, seems OKThe reason for me asking this is because I?m currently writing a floppy driver. Is it enought to just set up DMA, sending a read (for instance) command to the device, enable the channel that the floppy uses, and then the floppy will "sense" that the channel is enabled and then copy the data (and then trigger an IRQ of course)
- Pype.Clicker
- Member
- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:DMA question
actually, you need to tell the DMA where (in main memory) data should go/come from and what's the direction of the transfer (plus the size of the transfer).
That being done, the device that is ready to deliver data to memory will issue a bus cycle saying that it has (or is ready to receive) data to the DMA and the DMA controller will do what's needed to move data between the device and the memory.
Port numbers are required when the CPU initiates a cycles because it needs to *address* the device among all possible devices, but for device-initiated DMA cycles, the DMA channel is enough to select the listener among all 'dma channels' in the system.
HTH
That being done, the device that is ready to deliver data to memory will issue a bus cycle saying that it has (or is ready to receive) data to the DMA and the DMA controller will do what's needed to move data between the device and the memory.
Port numbers are required when the CPU initiates a cycles because it needs to *address* the device among all possible devices, but for device-initiated DMA cycles, the DMA channel is enough to select the listener among all 'dma channels' in the system.
HTH
Re:DMA question
Hi,
Without DMA the device would read/write data to/from an IO port. With DMA the data goes directly to/from the DMA controller instead (without any IO ports being used). Each DMA channel is hard-wired to a specific device so you don't need to tell the DMA chip where to get/put data (except for the physical memory address).
You'd configure the correct DMA channel in the DMA controller ready to do the transfer, then send the command to the device. Once the device starts transferring data the DMA chip will do it's thing. During the transfer you can check the DMA count to see how far it's got, and the device usually generates an IRQ when it has completed the transfer.
Cheers,
Brendan
Without DMA the device would read/write data to/from an IO port. With DMA the data goes directly to/from the DMA controller instead (without any IO ports being used). Each DMA channel is hard-wired to a specific device so you don't need to tell the DMA chip where to get/put data (except for the physical memory address).
You'd configure the correct DMA channel in the DMA controller ready to do the transfer, then send the command to the device. Once the device starts transferring data the DMA chip will do it's thing. During the transfer you can check the DMA count to see how far it's got, and the device usually generates an IRQ when it has completed the transfer.
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re:DMA question
Wow - three answers to the same question at the same time! Is this some kind of record?
- Brendan
- Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re:DMA question
seeing as they were all typed concurrently and without regard to each other, I think we all surf this site the same (tabbed browsing, opening all at a time and replying when I feel like it) and started surfing at about 12:20 pm local time here.Brendan wrote: Wow - three answers to the same question at the same time! Is this some kind of record?
- Brendan
Do think this is a record, although I've had a closer one with Pype (believe 18 seconds).
Re:DMA question
;D
One more thing. I read that the DMA chip (and mose devices) only operates in the low memory below 1 MB. Does this mean that the location where I want the data to be copied to (or where I store it before copying it) has to be under that 1 MB limit? If so, is there any other requirements? I?m storing my kernel at 0x1000 I got plenty of space in the kernel (before it goes over 1 MB). Would be great to just declare an array in the kernel.
One more thing. I read that the DMA chip (and mose devices) only operates in the low memory below 1 MB. Does this mean that the location where I want the data to be copied to (or where I store it before copying it) has to be under that 1 MB limit? If so, is there any other requirements? I?m storing my kernel at 0x1000 I got plenty of space in the kernel (before it goes over 1 MB). Would be great to just declare an array in the kernel.
Re:DMA question
Hi,
Cheers,
Brendan
The DMA chip needs to use memory below 16 Mb (not 1 Mb). In addition a transfer can't cross a 64 Kb boundary, so you can transfer 64 Kb from 0x10000 to 0x20000, but not from 0x18000 to 0x28000.Rolf wrote: ;D
One more thing. I read that the DMA chip (and mose devices) only operates in the low memory below 1 MB. Does this mean that the location where I want the data to be copied to (or where I store it before copying it) has to be under that 1 MB limit? If so, is there any other requirements? I?m storing my kernel at 0x1000 I got plenty of space in the kernel (before it goes over 1 MB). Would be great to just declare an array in the kernel.
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re:DMA question
So all I need is to find a location, below 16 MB, which starts at an address that looks like
x * 0x10000
x * 0x10000
Re:DMA question
Hi,
For example, if your floppy disk driver will only transfer a maximum of one complete track at a time, then it'd only need a DMA buffer of 18 Kb (for a 1440 Kb floppy disk). In this case you could have a DMA buffer from 0x10000 to 0x14800, from 0x12345 to 0x16B45, or from 0x1B800 to 0x20000 (as long as it doesn't cross a 64 Kb boundary).
It's also possible for the devices that use ISA DMA to dynamically allocate a buffer of the required size before each transfer. In this case if the user doesn't use a device that needs ISA DMA, then you can use the memory for something more important. Alternatively you could pre-allocate a 64 Kb buffer for each of the 7 DMA channels, which would consume 448 Kb even when it's never used.
Most devices in modern computers don't use the ISA DMA anymore (with the exception of floppy disks). PCI devices have their own DMA (bus mastering) hardware which doesn't have the restrictions of ISA DMA. Some of these even allow DMA to physical pages that are randomly scattered through physical memory. Because of this (and because the floppy is often unused) I probably wouldn't use pre-allocated/static DMA buffers..
Cheers,
Brendan
Possibly, although depending on how your OS does things this restriction can be reduced.Rolf wrote: So all I need is to find a location, below 16 MB, which starts at an address that looks like
x * 0x10000
For example, if your floppy disk driver will only transfer a maximum of one complete track at a time, then it'd only need a DMA buffer of 18 Kb (for a 1440 Kb floppy disk). In this case you could have a DMA buffer from 0x10000 to 0x14800, from 0x12345 to 0x16B45, or from 0x1B800 to 0x20000 (as long as it doesn't cross a 64 Kb boundary).
It's also possible for the devices that use ISA DMA to dynamically allocate a buffer of the required size before each transfer. In this case if the user doesn't use a device that needs ISA DMA, then you can use the memory for something more important. Alternatively you could pre-allocate a 64 Kb buffer for each of the 7 DMA channels, which would consume 448 Kb even when it's never used.
Most devices in modern computers don't use the ISA DMA anymore (with the exception of floppy disks). PCI devices have their own DMA (bus mastering) hardware which doesn't have the restrictions of ISA DMA. Some of these even allow DMA to physical pages that are randomly scattered through physical memory. Because of this (and because the floppy is often unused) I probably wouldn't use pre-allocated/static DMA buffers..
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re:DMA question
Hi,
Cheers,
Brendan
The primary floppy disk controller uses DMA channel 2. The secondary floppy disk controller might use DMA channel 3, or it could share channel 2, or it could be set to something elseRolf wrote: hehe by the way, what DMA channel is the floppy using?
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Re:DMA question
Do you know any tutorials discribing in details DMA in protected mode?
Any links?
Any links?
Re:DMA question
Hi,
http://www.osdever.net/tutorials/howto_ ... ?the_id=63
http://www.inversereality.org/files/dmaprogramming.pdf
http://dsplabs.utt.ro/aces/docs/daq_board/818LCH9.PDF
There's also the datasheet for the DMA controller chip (8237): http://www.stud.fh-hannover.de/~heineman/proginfo.htm
Cheers,
Brendan
Google is good - search for "DMA 8237" or "DMA 8237 tutorial":RMX wrote: Do you know any tutorials discribing in details DMA in protected mode?
Any links?
http://www.osdever.net/tutorials/howto_ ... ?the_id=63
http://www.inversereality.org/files/dmaprogramming.pdf
http://dsplabs.utt.ro/aces/docs/daq_board/818LCH9.PDF
There's also the datasheet for the DMA controller chip (8237): http://www.stud.fh-hannover.de/~heineman/proginfo.htm
Cheers,
Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.