lkml.org 
[lkml]   [2004]   [Sep]   [16]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: Having problem with mmap system call!!!
On Thu, 16 Sep 2004, Srinivas G. wrote:

> Hi All,
>
> I have a doubt about mmap system call.
>

mmap() works. Otherwise you wouldn't be sending any email.
It is used every time you open an application because that's
how shared libraries work.

You need to return the PHYSICAL address of your camera buffer
to user-space (probably using a driver ioctl()). Then the
user-mode code does ....


#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>

#define HINT 0x20000000
#define PROT (PROT_READ|PROT_WRITE)
#define FLAGS (MAP_FIXED|MAP_SHARED)
#define SHM_FAIL (void *)-1


void *init_shmem(size_t addr, size_t len)
{
int fd;
void *vp;
if((fd = open("/dev/mem", O_RDWR, 0)) < 0)
{
fprintf(stderr, "Can't open memory device\n");
exit(EXIT_FAILURE);
}
if((vp = mmap((caddr_t) HINT, len, PROT, FLAGS, fd, addr)) == SHM_FAIL)
{
fprintf(stderr, "Can't access shared memory\n");
exit(EXIT_FAILURE);
}
(void)close(fd);
return vp;
}

After that, anything the camera writes to its address will
be available in user-mode at the memory-mapped address.
This DOES work. That's how I do direct DMA to user-space
all the time.

Cheers,
Dick Johnson
Penguin : Linux version 2.4.26 on an i686 machine (5570.56 BogoMips).
Note 96.31% of all statistics are fiction.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 14:06    [W:0.058 / U:0.000 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site