views:

124

answers:

4

Due to some requirements on speed, we need to some computation in-place on internal memory and then DMA the results of the computation to a external memory. The application runs on a TI DM355 processor which is based on ARM926EJ-S core and a set of TI periferals (EDMA, video accelerators etc).

How cleanly can this be done from the application? Is it as simple as mmap'ing the afore said internal memory address into a virtual space and doing the calculation?

Thanks

+1  A: 

I'd think that this would require sone level of kernel and/or driver support. If you're using a Linux distribution that's specific to your platform, there may be something already provided. Check whatever documentation or sample code you might have.

I did find an article on how to actually do the mapping here:

http://www.simtec.co.uk/appnotes/AN0014/

this is for accessing GPIO registers, but the code should be the same for on-chip memory, with a different address. Of course, if something else is already using that space, you're going to crash if you just map it and start modifying it,so some more documentation digging is probably warranted. Do you have a kernel memory map for your system?

Mark Bessey
Thanks. I am using a custom rootfs and kernel. I will try out mmap. Thanks for the link. I have got a better understanding of it now.
Ramakrishnan Muthukrishnan
+3  A: 

You can mmap the /dev/mem device:

int mem_fd = open("/dev/mem", O_RDWR);
void *buffer = mmap(NULL, mem_segment_length, PROT_READ | PROT_WRITE, MAP_SHARED,
                    mem_fd, mem_segment_addr);
close(mem_fd);
/* buffer now points to your device's memory */
/* remember to call msync after writing to this to force changes to write back to
 * /dev/mem */

However, depending on your needs, this may not be sufficient. Another question on here has answers that go more in-depth, but you're probably better off doing this in a kernel module.

LnxPrgr3
Correct, except that `msync` isn't necessary in this particular case (because the backing "file" isn't a file at all). Won't hurt though.
caf
Aaah—good point! I wasn't sure how direct the path to memory was.
LnxPrgr3
Thanks a lot. I will try mmap out.
Ramakrishnan Muthukrishnan
I could get it working with mmap. Thanks very much.
Ramakrishnan Muthukrishnan
A: 

mmap is the way to go on linux

dwelch
A: 

Also, I remember that its possible to pin a page in memory. Correct me if I am wrong.

Algorist