From: "Richard B. Johnson" <root@chaos.analogic.com>
To: "Srinivas G." <srinivasg@esntechnologies.co.in>
Cc: Linux kernel <linux-kernel@vger.kernel.org>
Subject: Re: Having problem with mmap system call!!!
Date: Thu, 16 Sep 2004 10:07:45 -0400 (EDT) [thread overview]
Message-ID: <Pine.LNX.4.53.0409160958070.12146@chaos> (raw)
In-Reply-To: <4EE0CBA31942E547B99B3D4BFAB348111078FE@mail.esn.co.in>
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.
next parent reply other threads:[~2004-09-16 14:08 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <4EE0CBA31942E547B99B3D4BFAB348111078FE@mail.esn.co.in>
2004-09-16 14:07 ` Richard B. Johnson [this message]
2004-09-16 13:31 ` Alan Cox
2004-09-16 14:54 ` Richard B. Johnson
2004-09-16 15:57 ` Alan Cox
2004-09-16 18:13 ` Richard B. Johnson
2004-09-16 20:01 ` Alan Cox
2004-09-16 14:42 Srinivas G.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.53.0409160958070.12146@chaos \
--to=root@chaos.analogic.com \
--cc=linux-kernel@vger.kernel.org \
--cc=srinivasg@esntechnologies.co.in \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®