Mmap problem (VM_DENYWRITE)

From: shanthi kiran pendyala
Date: Mon May 24 2004 - 13:49:44 EST


Hi,

<<I am not subscribed to this list b'cos of the volume of emails. Please
include my email in the reply.>>

I am writing a device driver for a fpga device.
I implemented a dummy char device to gain user space access to the device
registers thru mmap.
The kernel is 2.4.18.
The CPU is sibyte (mips64 cpu) with 40 bits of physical addressing and 44
bits of virtual addressing.

After mmaping in userspace any writes to the mmap region is not working.
I think it is b'cos of the protection field in the vma is set to
VM_DENYWRITE.
The complete prot flag is (VM_READ | VM_WRITE | VM_EXEC | VM_GROWSUP |
VM_DENYWRITE)

Why is this happening? I need to have both read and write access to region.
How do I fix this ?

Thanks for you help

Shanthi kiran


Output after running test program
=================================
building page tables for va 0x2aac5000 phy 0x10940000
vsize 0x20000 psize 0x20000 prot 0xa07


===================================================================
My mmap implementation is as follow

#define FPGA_CSR_ADDR_START 0x10940000
#define FPGA_CSR_ADDR_END 0x1095ffff
#define MMAP_SIZE (FPGA_CSR_ADDR_END + 1 - FPGA_CSR_ADDR_START)

int
fpga_mmap(struct file *filp, struct vm_area_struct *vma) {

unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
unsigned long vsize = vma->vm_end - vma->vm_start;
unsigned long phys = FPGA_CSR_ADDR_START + offset;
unsigned long psize = MMAP_SIZE - offset;

if(vsize > psize)
return -EINVAL;

printk("<1> building page tables for va 0x%lx phy 0x%lx \n",
vma->vm_start, phys);

printk("<1> vsize 0x%lx psize 0x%lx prot 0x%lx\n",
vsize, psize, vma->vm_page_prot.pgprot);

/* build new page tables */
if (remap_page_range(vma->vm_start, phys, vsize, vma->vm_page_prot))
return -EAGAIN;

return 0;
}
================================================================
I try to access to the device memory region with this user space test
program
....
fpga_fd = open(FPGA_DEV_FILE_NAME, O_RDWR);

if(cde_fd < 0) {
printf("can't open %s err %d\n", FPGA_DEV_FILE_NAME, fpga_fd);
goto finish;
}

offset = 0;
fpga_csr_start = mmap(0, MMAP_SIZE,
PROT_READ|PROT_WRITE, MAP_SHARED,
fpga_fd, offset);

if (fpga_csr_start < 0 ) {
printf(" error in mmap errno %d", errno);
goto finish;
}

...
============================================================================

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/