From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-px0-f179.google.com (mail-px0-f179.google.com [209.85.212.179]) by ozlabs.org (Postfix) with ESMTP id 528E2B70B6 for ; Tue, 27 Jul 2010 03:36:11 +1000 (EST) Received: by pxi2 with SMTP id 2so188449pxi.38 for ; Mon, 26 Jul 2010 10:36:09 -0700 (PDT) MIME-Version: 1.0 Date: Mon, 26 Jul 2010 22:58:30 +0530 Message-ID: Subject: Memory Mapping a char array in User Space From: Ravi Gupta To: linuxppc-dev@lists.ozlabs.org Content-Type: multipart/alternative; boundary=001636457d9496fad1048c4db6f2 List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , --001636457d9496fad1048c4db6f2 Content-Type: text/plain; charset=ISO-8859-1 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 --001636457d9496fad1048c4db6f2 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hi,

I am new to linux device driver development and I'm trying t= o 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, st= ruct vm_area_struct *vma) function, I am trying to memory map a global char= acter array (defined in driver) to user space memory.This is my current imp= lementation

char map[25];
static int test_mmap(struct file *filp, struct vm_area_struct *vma)
{
strcpy(map, "Hello World!!= ");
if (rema= p_pfn_range(vma, vma<= span class=3D"sy0">->vm_start,
page_to_pfn(virt_t= o_page(map)),
vma->vm_end - vma->vm_start, vma->vm_page_prot)) {<= br> return -EAGAIN;
}
return<= /span> 0;
}
Now after compiling the driver successfully, I created a character device f= ile /dev/test0 using mknod command (mknod /dev/test c 251 0). And in my C p= rogram 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 memor= y 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 d= evice gets memory map successfully but when I tried to read from it I get g= arbage value. Is there something that I am missing?

Thanks in advance
Ravi Gupta
--001636457d9496fad1048c4db6f2--