Skip navigation.
Home
The QNX Community Portal

View topic - Aligning RAM for DMA access

Aligning RAM for DMA access

For discussion of realtime and/or embedded programming.

Aligning RAM for DMA access

Postby ian_turner » Mon Jun 28, 2010 8:10 am

I need to allocate blocks of memory on a 16 byte boundary for DMA access by a PCI card. Obviously memalign is the solution. Except that this would be in Process memory and therefore useless (i am assuming this is why the system resets when I pass the addresses to the pci card and it attempts DMA).
So is there a method of aligning mmapped memory ?
If i use memalign and then pass the resultant address as the location to map to in mmap will this work or do I have to resort to the method previously used of adding 16 to the memory size required and then adding 15 to the resulting address and masking out the bottom 4 bits which requires keeping two addresses.
ian_turner
Active Member
 
Posts: 12
Joined: Fri Oct 30, 2009 9:36 am

RE: Aligning RAM for DMA access

Postby maschoen » Mon Jun 28, 2010 4:39 pm

Memory returned from mmap() should be page aligned, so of course it will also be 16 byte aligned.
maschoen
QNX Master
 
Posts: 2644
Joined: Wed Jun 25, 2003 5:18 pm

RE: Aligning RAM for DMA access

Postby mario » Mon Jun 28, 2010 8:09 pm

I don't think there anything in the specs what says so, at least not that I could find. It's probably best to check the physical address of the block of memory and add an offset if need be.
mario
QNX Master
 
Posts: 4132
Joined: Sun Sep 01, 2002 1:04 am

RE: Aligning RAM for DMA access

Postby ian_turner » Wed Jun 30, 2010 2:03 pm

It seems memalign was good enough. I was getting confused by the mem_offset help description that mentioned mapped memory and assumed this meant mmapped. If i memalign then use the address from that in an mmap call then it seems to corrupt the previous block of memory I allocated for a completely different object as it generates a SIGSEV error if I do a free of the other block immediately after the mmap call suggesting it may be overwriting the block descriptor for the previous block somehow.
This seems to suggest that memalign and mmap take different amounts of memory for the same size value.
Or possibly it's something more complicated.
Anyway problem solved.
ian_turner
Active Member
 
Posts: 12
Joined: Fri Oct 30, 2009 9:36 am


Return to Realtime and Embedded

Who is online

Users browsing this forum: No registered users and 2 guests

cron