linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* Memory Mapping a char array in User Space
@ 2010-07-26 17:28 Ravi Gupta
  2010-07-26 19:42 ` David Howells
  0 siblings, 1 reply; 3+ messages in thread
From: Ravi Gupta @ 2010-07-26 17:28 UTC (permalink / raw)
  To: linuxppc-dev

[-- 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 --]

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-07-27  7:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-07-26 17:28 Memory Mapping a char array in User Space Ravi Gupta
2010-07-26 19:42 ` David Howells
2010-07-27  7:04   ` Ravi Gupta

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).