Home
Support

Knowledge Base

BSPs and drivers
Community resources
Product documentation
Questions?
Contact us

How to allocate a reasonably large buffer located in physically contiguous memory
 
________________________________________________________________________

Applicable Environment
________________________________________________________________________
  • Topic: Allocating physically contiguous memory
  • SDP: 6.4.0
  • Target: Any supported target
________________________________________________________________________

Recommendation
________________________________________________________________________

From our mmap docs for 6.4.0:
http://www.qnx.com/developers/docs/6.4.0/neutrino/lib_ref/m/mmap.html

[snip]
MAP_PHYS
Physical memory is required. The fildes parameter must be NOFD. When used with MAP_PRIVATE or MAP_SHARED, the offset specifies the exact physical address to map (e.g. for video frame buffers), and is equivalent to opening /dev/mem.

If used with MAP_ANON, then physically contiguous memory is allocated.

MAP_NOX64K and MAP_BELOW16M are used to further define the MAP_ANON allocated memory (useful on x86 only).
[snap]

So:
/* Map physically contiguous memory */
if ( ( p = mmap( 0, SIZE, PROT_READ|PROT_WRITE|PROT_NOCACHE, MAP_PHYS|MAP_ANON, NOFD, 0 ) ) == MAP_FAILED )
err( 1, "mmap()" );
--------------------------
if ( mem_offset( p, NOFD, SIZE, &off, 0 ) == -1 )
err( 1, "mem_offset()" );

printf( "Virtual: %p Physical: %08X\n", p, off );

Your driver code would use the 'p' and would give 'off' to some controller.


________________________________________________________________________
NOTE: This entry has been validated against the SDP version listed above. Use caution when considering this advice for any other SDP version. For supported releases, please reach out to QNX Technical Support if you have any questions/concerns.
________________________________________________________________________


Related Attachments
 None Found





Please contact us with your questions or concerns.