/* * - Function ---------------------------------------------------------------- * * sentric_fpga_mmap * * This function maps the FPGA register block to user space. * * Parameters: * filep Pointer to file struct for this device. * vma Pointer to the virtual memory area struct to map to. * * Returns: * 0 success, -ve number is an error code. * * Notes: * None. * --------------------------------------------------------------------------- */ int sentric_fpga_mmap(struct file *filep, struct vm_area_struct *vma) { unsigned long off; phys_addr_t phys; unsigned long vsize, psize; /* Convert requested offset in units of pages to bytes */ /* This is the offset from base of FPGA regs region, should always be 0 */ off = vma->vm_pgoff << PAGE_SHIFT; /* physical address */ phys = SENTRIC_FPGA_ADDR; /* Check that the user hasn't asked for more than is available */ vsize = vma->vm_end - vma->vm_start; psize = PAGE_SIZE - off; if (vsize > psize) { printk("sentric_fpga:mmap: requested too much i/o space: %ld\n", vsize); return -EINVAL; } /* Use non-cached accesses as this is shared-memory */ vma->vm_page_prot = pgprot_noncached(vma->vm_page_prot); /* Don't try to swap out physical pages.. */ vma->vm_flags |= VM_RESERVED; /* Don't dump addresses that are not real memory to a core file. */ vma->vm_flags |= VM_IO; if (io_remap_page_range64(vma->vm_start, phys, vsize, vma->vm_page_prot)) { return -EAGAIN; } return 0; } /* sentric_fpga_mmap() */