From: Ravi Gupta <dceravigupta@gmail.com>
To: linuxppc-dev@lists.ozlabs.org
Subject: Memory Mapping a char array in User Space
Date: Mon, 26 Jul 2010 22:58:30 +0530 [thread overview]
Message-ID: <AANLkTikJJYRP=5yPQ8dG9ofXz3HvWzfQU2kt4PDui7EF@mail.gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 1303 bytes --]
Hi,
I am new to linux device driver development and I'm trying to learn the
memory mapping. Currently I have written a simple device driver(major number
251 and minor number 0) and in its mmap(struct file *file, struct
vm_area_struct *vma) function, I am trying to memory map a global character
array (defined in driver) to user space memory.This is my current
implementation
char map[25];
static int test_mmap(struct file *filp, struct vm_area_struct *vma)
{
strcpy(map, "Hello World!!");
if (remap_pfn_range(vma, vma->vm_start, page_to_pfn(virt_to_page(map)),
vma->vm_end - vma->vm_start, vma->vm_page_prot)) {
return -EAGAIN;
}
return 0;
}*
*
Now after compiling the driver successfully, I created a character device
file /dev/test0 using mknod command (mknod /dev/test c 251 0). And in my C
program I tried to memory map the /dev/test file.
Now what I want is that whenever I map /dev/test, internally that global
char array gets memory mapped to the user space? Also what should I pass as
the length parameter in the mmap() function? Currently I am passing 25(size
of the array). My device gets memory map successfully but when I tried to
read from it I get garbage value. Is there something that I am missing?
Thanks in advance
Ravi Gupta
[-- Attachment #2: Type: text/html, Size: 2531 bytes --]
next reply other threads:[~2010-07-26 17:36 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-07-26 17:28 Ravi Gupta [this message]
2010-07-26 19:42 ` Memory Mapping a char array in User Space David Howells
2010-07-27 7:04 ` Ravi Gupta
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='AANLkTikJJYRP=5yPQ8dG9ofXz3HvWzfQU2kt4PDui7EF@mail.gmail.com' \
--to=dceravigupta@gmail.com \
--cc=linuxppc-dev@lists.ozlabs.org \
/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;
as well as URLs for NNTP newsgroup(s).