Direct Memmory Access

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
User avatar
Holus
Member
Member
Posts: 51
Joined: Thu Jan 27, 2011 5:57 pm

Direct Memmory Access

Post by Holus »

Introduction:
I want to make a modular OS starting with a flexible table based structure design for hardware and software.
Works nice in concept. The control actions look like a TSQL instruction.
(only the instructions are not string("SELECT") but a byte(0x01) for example)

After completion of the basic instructions, I started to normalize the computer and create the first tables. (I'm soooo happy they are flexible by design)


Stupid question:
I bounced to de definition DMA (Direct Memory Access) I already know it but…

Is it possible if I would send data to a device to remap the device DMA-Base address to a memory location. And when it’s finished point it to the next location in RAM. So don’t have to copy memory from one place to another.

Or for read. Move the DMA to a "fresh space" in memory when the buffer is full so I don’t have to take immediately lots of actions when the cards tells me to.

Is this possible or just a stupid thought?
Computer says NOOOO
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Direct Memmory Access

Post by Combuster »

Holus wrote:Is this possible or just a stupid thought?
Both. DMA works the way you want but not the way you said.

DMA works by telling the hardware the location in system memory where it should read or write. It will then do what it needs to do, and when its done it will let you know via an interrupt.

In any case DMA is neither a verb nor an object. You can not move DMA. It's either there or it isn't.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Holus
Member
Member
Posts: 51
Joined: Thu Jan 27, 2011 5:57 pm

Re: Direct Memmory Access

Post by Holus »

Combuster wrote:In any case DMA is neither a verb nor an object. You can not move DMA. It's either there or it isn't.
I still don't get it.
What is DMA it's not clear by reading articles to me.

Makes DMA it possible for hardware to access memory?
Or makes DMA it possible to access memory on the hardware so you can use it like normal RAM?

I always thought DMA is a piece RAM that is the communication area between the hardware and the CPU. Hardware with it’s own processor can access a the RAM so the rest of the computer can communicate with it. Because the hardware has its own controller to execute the command given to the hardware and there is a IRQ-line on the BUS that communicate the status of the command to the CPU.
I can’t get this out of my mind if I read articles.

What is DMA???
Computer says NOOOO
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: Direct Memmory Access

Post by Chandra »

To keep it concise, DMA is the data transmission mechanism between the hardware devices and the Random Access Memory. The concept behind DMA is that data is transmitted directly to/from the Memory Bus without employing the CPU. The data transfer takes place whenever the Memory Bus is free. Of course, you need to setup the respective DMA channels before you could actually perform data transmission. This implies setting up the physical address to transfer, transfer length etc. which implicitly depends upon the DMA standard you're using.
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
User avatar
Holus
Member
Member
Posts: 51
Joined: Thu Jan 27, 2011 5:57 pm

Re: Direct Memmory Access

Post by Holus »

Chandra wrote:To keep it concise, DMA is the data transmission mechanism between the hardware devices and the Random Access Memory. The concept behind DMA is that data is transmitted directly to/from the Memory Bus without employing the CPU. The data transfer takes place whenever the Memory Bus is free. Of course, you need to setup the respective DMA channels before you could actually perform data transmission. This implies setting up the physical address to transfer, transfer length etc. which implicitly depends upon the DMA standard you're using.
I'm maybe stupid or simple minded.
But if I use the DMA channel just like it's set-up. With the physical memory location that's set up. I still have to copy memory to another memory location. So, the CPU is busy to copy memory to memory after all. Can't I just reset the memory location of the DMA channel to a address where the data is??
Computer says NOOOO
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: Direct Memmory Access

Post by Chandra »

I'm maybe stupid or simple minded.
But if I use the DMA channel just like it's set-up. With the physical memory location that's set up. I still have to copy memory to another memory location. So, the CPU is busy to copy memory to memory after all. Can't I just reset the memory location of the DMA channel to a address where the data is??
Which DMA are you using?
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
User avatar
Holus
Member
Member
Posts: 51
Joined: Thu Jan 27, 2011 5:57 pm

Re: Direct Memmory Access

Post by Holus »

Chandra wrote:Which DMA are you using?
PCI Busmastering DMA
Computer says NOOOO
User avatar
Chandra
Member
Member
Posts: 487
Joined: Sat Jul 17, 2010 12:45 am

Re: Direct Memmory Access

Post by Chandra »

Holus wrote: PCI Busmastering DMA
It should be possible then, though I haven't give it a try myself. If it was ISA DMA, you could have only access to 1st 16Mb of Memory. You may want to give some more info about which device you're accessing so that someone else more accustomed to that device can answer your question.

And of course, PCI Busmastering DMA involves the use of PCI Bus, so things are different here.

Cheers!
Programming is not about using a language to solve a problem, it's about using logic to find a solution !
User avatar
Holus
Member
Member
Posts: 51
Joined: Thu Jan 27, 2011 5:57 pm

Re: Direct Memmory Access

Post by Holus »

Chandra wrote:
Holus wrote: PCI Busmastering DMA
It should be possible then, though I haven't give it a try myself. If it was ISA DMA, you could have only access to 1st 16Mb of Memory. You may want to give some more info about which device you're accessing so that someone else more accustomed to that device can answer your question.

And of course, PCI Busmastering DMA involves the use of PCI Bus, so things are different here.

Cheers!
For example the NETWORK and the HARDDISK.
Computer says NOOOO
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Direct Memmory Access

Post by gerryg400 »

Holus wrote:I'm maybe stupid or simple minded.
But if I use the DMA channel just like it's set-up. With the physical memory location that's set up. I still have to copy memory to another memory location. So, the CPU is busy to copy memory to memory after all. Can't I just reset the memory location of the DMA channel to a address where the data is??
You supply the device with a list of physical addresses and sizes and the device reads or writes directly to that memory. For a hard drive those addresses could be your block cache so no further copying will be required.
If a trainstation is where trains stop, what is a workstation ?
Casm
Member
Member
Posts: 221
Joined: Sun Oct 17, 2010 2:21 pm
Location: United Kingdom

Re: Direct Memmory Access

Post by Casm »

DMA copies directly to a buffer in main memory, the address and size of which you specify.

http://www.centrillium-it.com/Projects/idems100.pdf
User avatar
DavidCooper
Member
Member
Posts: 1150
Joined: Wed Oct 27, 2010 4:53 pm
Location: Scotland

Re: Direct Memmory Access

Post by DavidCooper »

Moving data from one place in memory to another using the CPU isn't hugely time-consuming because there are no delays, though I suppose you could save a little time by doing it using DMA, but the real point of DMA is for getting data in (or out) from (or to) slower storage devices or networks where you don't want the CPU wasting time hanging around waiting for bytes to be delivered (or collected), or where you don't want it being repeatedly interrupted whenever it's a suitable time to send or receive a byte. Once the DMA has transferred the whole lot into a buffer, the CPU can move the whole lot in one rapid burst of activity.

I don't know if anyone uses DMA for memory to memory transfers, but if they don't it may be because of the difficulty in working out where the memory actually is - if you're using paged memory, the DMA isn't going to have any idea where the pages are (I assume, perhaps wrongly, that they lack the ability to read the page tables), so you're going to have to program it to transfer little 4KB chunks here and there, scattered about in physical memory, and that would be a nightmare.
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Re: Direct Memmory Access

Post by Combuster »

I don't know if anyone uses DMA for memory to memory transfers, but if they don't it may be because of the difficulty in working out where the memory actually is
No, it's because paging makes memory-to-memory transfers unnecessary. Finding the physical address for a virtual address simply requires a pagewalk so that can't be the problem either.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
DavidCooper
Member
Member
Posts: 1150
Joined: Wed Oct 27, 2010 4:53 pm
Location: Scotland

Re: Direct Memmory Access

Post by DavidCooper »

Combuster wrote:No, it's because paging makes memory-to-memory transfers unnecessary.
I suppose you could move a file to a new memory location just by changing the page table entries, but if you have a large file which is only contiguous and in proper order within a paged environment while actually being scattered around in physical memory, don't you have to move it into a buffer in physically contiguous memory somewhere before you get the DMA to transfer it to a storage device? The alternative would be to set up a whole series of DMA transfers for each contiguous chunk of file until it's all been done, each transfer being set up after the previous one is complete. (I'm obviously still working on the assumption that DMA can't read page tables, so please correct me if I'm behind the times on that point.)
Help the people of Laos by liking - https://www.facebook.com/TheSBInitiative/?ref=py_c

MSB-OS: http://www.magicschoolbook.com/computing/os-project - direct machine code programming
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Direct Memmory Access

Post by gerryg400 »

DavidCooper wrote:... but if you have a large file which is only contiguous and in proper order within a paged environment while actually being scattered around in physical memory, don't you have to move it into a buffer in physically contiguous memory somewhere before you get the DMA to transfer it to a storage device? The alternative would be to set up a whole series of DMA transfers for each contiguous chunk of file until it's all been done, each transfer being set up after the previous one is complete. (I'm obviously still working on the assumption that DMA can't read page tables, so please correct me if I'm behind the times on that point.)
No, you can supply a list of physaddr/length pairs and the controller takes care of scatter/gathering the pieces.
If a trainstation is where trains stop, what is a workstation ?
Post Reply