QNX 6.1.0.A
What I would like to do is allocate an area of physically contiguous shared
memory that:
- the resource manager can use for dma transfer of image data from the pci
card and
- the client can subsequently access for processing/display.
The code I have used to try and do this is shown below.
client_process.c
int sh_mem;
sh_mem = shm_open("/imagemem", O_RDWR | O_CREAT , 0777);
if (sh_mem == -1)
printf(“Problem with shared memory\n”);
else
printf(“Shared memory created OK\n”);
// Allocate physically contiguous shared memory
image_buf = (unsigned short*) mmap( 0, bufsize,
PROT_READ|PROT_WRITE|PROT_NOCACHE, MAP_SHARED|MAP_PHYS|MAP_ANON, sh_mem,
0 );
resmgr.c
int sh_mem;
sh_mem = shm_open("/imagemem", O_RDWR , 0777);
if (sh_mem == -1)
printf(“problem with sh mem\n”);
dmabuf = (unsigned short*) mmap( 0, bufsize,
PROT_READ|PROT_WRITE|PROT_NOCACHE, MAP_SHARED|MAP_PHYS|MAP_ANON, sh_mem,
0 );
if (dmabuf == MAP_FAILED)
{
printf(“mmap for dmabuf failed: %s\n”, strerror(errno));
exit(EXIT_FAILURE);
}
// Get physical address of dmabuf to use for dma transfer
if (mem_offset(dmabuf, NOFD, 1, &phys_addr, NULL) != 0)
exit(EXIT_FAILURE);
The problem is that mmap is returning MAP_FAILED with the error “invalid
argument”. However there is no problem if I change the line to:
dmabuf = (unsigned short*) mmap( 0, bufsize,
PROT_READ|PROT_WRITE|PROT_NOCACHE, MAP_SHARED|MAP_PHYS|MAP_ANON, NOFD, 0 );
but then the mapped memory is not shared. What arguments should I pass to
mmap() to create a shared, physically contiguous area?
Paul.