2 * linux/arch/arm/mm/mmap.c
6 #include <linux/mman.h>
8 #include <linux/sched.h>
10 #include <linux/personality.h>
11 #include <linux/random.h>
12 #include <asm/cachetype.h>
14 #define COLOUR_ALIGN(addr,pgoff) \
15 ((((addr)+SHMLBA-1)&~(SHMLBA-1)) + \
16 (((pgoff)<<PAGE_SHIFT) & (SHMLBA-1)))
19 * We need to ensure that shared mappings are correctly aligned to
20 * avoid aliasing issues with VIPT caches. We need to ensure that
21 * a specific page of an object is always mapped at a multiple of
24 * We unconditionally provide this function for all cases, however
25 * in the VIVT case, we optimise out the alignment rules.
28 arch_get_unmapped_area(struct file *filp, unsigned long addr,
29 unsigned long len, unsigned long pgoff, unsigned long flags)
31 struct mm_struct *mm = current->mm;
32 struct vm_area_struct *vma;
33 unsigned long start_addr, vm_start;
35 int aliasing = cache_is_vipt_aliasing();
38 * We only need to do colour alignment if either the I or D
42 do_align = filp || (flags & MAP_SHARED);
45 * We enforce the MAP_FIXED case.
47 if (flags & MAP_FIXED) {
48 if (aliasing && flags & MAP_SHARED &&
49 (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))
59 addr = COLOUR_ALIGN(addr, pgoff);
61 addr = PAGE_ALIGN(addr);
63 vma = find_vma(mm, addr);
64 if (TASK_SIZE - len >= addr &&
65 (!vma || addr + len <= vm_start_gap(vma)))
68 if (len > mm->cached_hole_size) {
69 start_addr = addr = mm->free_area_cache;
71 start_addr = addr = TASK_UNMAPPED_BASE;
72 mm->cached_hole_size = 0;
74 /* 8 bits of randomness in 20 address space bits */
75 if ((current->flags & PF_RANDOMIZE) &&
76 !(current->personality & ADDR_NO_RANDOMIZE))
77 addr += (get_random_int() % (1 << 8)) << PAGE_SHIFT;
81 addr = COLOUR_ALIGN(addr, pgoff);
83 addr = PAGE_ALIGN(addr);
85 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
86 /* At this point: (!vma || addr < vma->vm_end). */
87 if (TASK_SIZE - len < addr) {
89 * Start a new search - just in case we missed
92 if (start_addr != TASK_UNMAPPED_BASE) {
93 start_addr = addr = TASK_UNMAPPED_BASE;
94 mm->cached_hole_size = 0;
100 vm_start = vm_start_gap(vma);
101 if (!vma || addr + len <= vm_start) {
103 * Remember the place where we stopped the search:
105 mm->free_area_cache = addr + len;
108 if (addr + mm->cached_hole_size < vm_start)
109 mm->cached_hole_size = vm_start - addr;
112 addr = COLOUR_ALIGN(addr, pgoff);
118 * You really shouldn't be using read() or write() on /dev/mem. This
119 * might go away in the future.
121 int valid_phys_addr_range(unsigned long addr, size_t size)
123 if (addr < PHYS_OFFSET)
125 if (addr + size > __pa(high_memory - 1) + 1)
132 * We don't use supersection mappings for mmap() on /dev/mem, which
133 * means that we can't map the memory area above the 4G barrier into
136 int valid_mmap_phys_addr_range(unsigned long pfn, size_t size)
138 return !(pfn + (size >> PAGE_SHIFT) > 0x00100000);
141 #ifdef CONFIG_STRICT_DEVMEM
143 #include <linux/ioport.h>
146 * devmem_is_allowed() checks to see if /dev/mem access to a certain
147 * address is valid. The argument is a physical page number.
148 * We mimic x86 here by disallowing access to system RAM as well as
149 * device-exclusive MMIO regions. This effectively disable read()/write()
152 int devmem_is_allowed(unsigned long pfn)
154 if (iomem_is_exclusive(pfn << PAGE_SHIFT))
156 if (!page_is_ram(pfn))