From: Hauke Mehrtens Date: Sun, 26 May 2013 19:52:27 +0000 (+0200) Subject: backports: add vm_iomap_memory() X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=0aa997a467ea3e153d652faecd0de20ae022304b;p=openwrt%2Fstaging%2Fblogic.git backports: add vm_iomap_memory() This adds vm_iomap_memory() from: commit b4cbb197c7e7a68dbad0d491242e3ca67420c13e Author: Linus Torvalds Date: Tue Apr 16 13:45:37 2013 -0700 vm: add vm_iomap_memory() helper function Signed-off-by: Hauke Mehrtens Signed-off-by: Luis R. Rodriguez --- diff --git a/backport/backport-include/linux/mm.h b/backport/backport-include/linux/mm.h index 9ba1f00fbe7c..8671d2999204 100644 --- a/backport/backport-include/linux/mm.h +++ b/backport/backport-include/linux/mm.h @@ -20,4 +20,9 @@ #define VM_DONTDUMP VM_NODUMP #endif +#if (LINUX_VERSION_CODE < KERNEL_VERSION(3,8,0)) +#define vm_iomap_memory LINUX_BACKPORT(vm_iomap_memory) +int vm_iomap_memory(struct vm_area_struct *vma, phys_addr_t start, unsigned long len); +#endif + #endif /* __BACKPORT_MM_H */ diff --git a/backport/compat/compat-3.8.c b/backport/compat/compat-3.8.c index 9f5df7d4a5fd..5b1ead9501c3 100644 --- a/backport/compat/compat-3.8.c +++ b/backport/compat/compat-3.8.c @@ -363,3 +363,58 @@ bool hid_ignore(struct hid_device *hdev) return !!hid_match_id(hdev, hid_ignore_list); } EXPORT_SYMBOL_GPL(hid_ignore); + +/** + * Backport this: + * commit b4cbb197c7e7a68dbad0d491242e3ca67420c13e + * Author: Linus Torvalds + * Date: Tue Apr 16 13:45:37 2013 -0700 + * + * vm: add vm_iomap_memory() helper function + */ +/** + * vm_iomap_memory - remap memory to userspace + * @vma: user vma to map to + * @start: start of area + * @len: size of area + * + * This is a simplified io_remap_pfn_range() for common driver use. The + * driver just needs to give us the physical memory range to be mapped, + * we'll figure out the rest from the vma information. + * + * NOTE! Some drivers might want to tweak vma->vm_page_prot first to get + * whatever write-combining details or similar. + */ +int vm_iomap_memory(struct vm_area_struct *vma, phys_addr_t start, unsigned long len) +{ + unsigned long vm_len, pfn, pages; + + /* Check that the physical memory area passed in looks valid */ + if (start + len < start) + return -EINVAL; + /* + * You *really* shouldn't map things that aren't page-aligned, + * but we've historically allowed it because IO memory might + * just have smaller alignment. + */ + len += start & ~PAGE_MASK; + pfn = start >> PAGE_SHIFT; + pages = (len + ~PAGE_MASK) >> PAGE_SHIFT; + if (pfn + pages < pfn) + return -EINVAL; + + /* We start the mapping 'vm_pgoff' pages into the area */ + if (vma->vm_pgoff > pages) + return -EINVAL; + pfn += vma->vm_pgoff; + pages -= vma->vm_pgoff; + + /* Can we fit all of the mapping? */ + vm_len = vma->vm_end - vma->vm_start; + if (vm_len >> PAGE_SHIFT > pages) + return -EINVAL; + + /* Ok, let it rip */ + return io_remap_pfn_range(vma, vma->vm_start, pfn, vm_len, vma->vm_page_prot); +} +EXPORT_SYMBOL(vm_iomap_memory);