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
_______________________________________________
Linuxppc-dev mailing list
Linuxppc-dev@lists.ozlabs.org
https://lists.ozlabs.org/listinfo/linuxppc-dev

Reply via email to