Project Home
Project Home
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - using mmap() to get contiguous memory > 4kB: (3 Items)
   
using mmap() to get contiguous memory > 4kB  
I'm currently working on a PCI driver on the following platform:
- QNX 6.3.0 SP3
- mpc8349
- mpc8349mds BSP

I need to allocate some buffers to be used for DMA transfers. then I need contiguous memory. I want to know if the 
system is able to provide me the amount of contiguous memory I requested. To do that I use the allocate_dma_buffer() 
function (see bellow).
My problem is that the system seems not to be able to give me more the 4kB of contiguous memory. Maybe I misunderstood 
something? Am I donig anything wrong?

Thanks for helping,
Armand


int allocate_dma_buffer( size_t const length,
                         void ** const buffer_ptr,
                         off_t * const buffer_paddr)
{
    size_t contiguous_length;

    //----- allocate physically contiguous memory -----
    *buffer_ptr = mmap( NULL,
                        length,
                        PROT_READ|PROT_WRITE|PROT_NOCACHE,
                        MAP_PHYS|MAP_ANON,
                        NOFD,
                        0 );
    if( MAP_FAILED == *buffer_ptr )
    {
        printf("mmap() FAILED: %s\n", strerror(errno) );
        return -1;
    }

    //----- get physical address -----
    if( -1 == mem_offset( *buffer_ptr,
                          NOFD,
                          length,
                          buffer_paddr,
                          &contiguous_length ) )
    {
        printf("mem_offset() FAILED: %s\n", strerror(errno) );
        return -1;
    }

    // mem_offset() always returns with contiguous_length set to 4096
    if( length > contiguous_length )
    {
        printf("mem_offset() FAILED to get physical address for the complete buffer\n");
        return -1;
    }

    return 0;
}
Re: using mmap() to get contiguous memory > 4kB  
The 6.3.0 mem_offset[64]() function never returned a contiguous length
indicator bigger than a page - it didn't have the data structures
to determine anything longer. While 'correct', it's not as nice
as it could have been. If you'd done a mem_offset() for the first
virtual address of the next page and compared the physical addr, you'd
have seen that it was actually contiguous - the mmap() would return MAP_FAILED
if it couldn't get the full amount of storage you requested in one
contiguous piece.

The 6.3.2 memory manager has improved data structures that allows 
mem_offset[64] to report the full contiguous length.

-- 
Brian Stecher (bstecher@qnx.com)        QNX Software Systems
phone: +1 (613) 591-0931 (voice)        175 Terence Matthews Cr.
       +1 (613) 591-3579 (fax)          Kanata, Ontario, Canada K2M 1W8
Re: using mmap() to get contiguous memory > 4kB  
Thanks for the explanation. I will then only use the returned value of mmap() to make sure that I've got the amount of 
contiguous memory I requested and use mem_offset() to get its physical address.