]>
git.proxmox.com Git - mirror_ubuntu-zesty-kernel.git/blob - arch/arm/mm/mmap.c
2 * linux/arch/arm/mm/mmap.c
6 #include <linux/mman.h>
8 #include <linux/sched.h>
9 #include <asm/cputype.h>
10 #include <asm/system.h>
12 #define COLOUR_ALIGN(addr,pgoff) \
13 ((((addr)+SHMLBA-1)&~(SHMLBA-1)) + \
14 (((pgoff)<<PAGE_SHIFT) & (SHMLBA-1)))
17 * We need to ensure that shared mappings are correctly aligned to
18 * avoid aliasing issues with VIPT caches. We need to ensure that
19 * a specific page of an object is always mapped at a multiple of
22 * We unconditionally provide this function for all cases, however
23 * in the VIVT case, we optimise out the alignment rules.
26 arch_get_unmapped_area(struct file
*filp
, unsigned long addr
,
27 unsigned long len
, unsigned long pgoff
, unsigned long flags
)
29 struct mm_struct
*mm
= current
->mm
;
30 struct vm_area_struct
*vma
;
31 unsigned long start_addr
;
33 unsigned int cache_type
;
34 int do_align
= 0, aliasing
= 0;
37 * We only need to do colour alignment if either the I or D
38 * caches alias. This is indicated by bits 9 and 21 of the
39 * cache type register.
41 cache_type
= read_cpuid_cachetype();
42 if (cache_type
!= read_cpuid_id()) {
43 aliasing
= (cache_type
| cache_type
>> 12) & (1 << 11);
45 do_align
= filp
|| flags
& MAP_SHARED
;
53 * We enforce the MAP_FIXED case.
55 if (flags
& MAP_FIXED
) {
56 if (aliasing
&& flags
& MAP_SHARED
&& addr
& (SHMLBA
- 1))
66 addr
= COLOUR_ALIGN(addr
, pgoff
);
68 addr
= PAGE_ALIGN(addr
);
70 vma
= find_vma(mm
, addr
);
71 if (TASK_SIZE
- len
>= addr
&&
72 (!vma
|| addr
+ len
<= vma
->vm_start
))
75 if (len
> mm
->cached_hole_size
) {
76 start_addr
= addr
= mm
->free_area_cache
;
78 start_addr
= addr
= TASK_UNMAPPED_BASE
;
79 mm
->cached_hole_size
= 0;
84 addr
= COLOUR_ALIGN(addr
, pgoff
);
86 addr
= PAGE_ALIGN(addr
);
88 for (vma
= find_vma(mm
, addr
); ; vma
= vma
->vm_next
) {
89 /* At this point: (!vma || addr < vma->vm_end). */
90 if (TASK_SIZE
- len
< addr
) {
92 * Start a new search - just in case we missed
95 if (start_addr
!= TASK_UNMAPPED_BASE
) {
96 start_addr
= addr
= TASK_UNMAPPED_BASE
;
97 mm
->cached_hole_size
= 0;
102 if (!vma
|| addr
+ len
<= vma
->vm_start
) {
104 * Remember the place where we stopped the search:
106 mm
->free_area_cache
= addr
+ len
;
109 if (addr
+ mm
->cached_hole_size
< vma
->vm_start
)
110 mm
->cached_hole_size
= vma
->vm_start
- addr
;
113 addr
= COLOUR_ALIGN(addr
, pgoff
);
119 * You really shouldn't be using read() or write() on /dev/mem. This
120 * might go away in the future.
122 int valid_phys_addr_range(unsigned long addr
, size_t size
)
124 if (addr
< PHYS_OFFSET
)
126 if (addr
+ size
> __pa(high_memory
))
133 * We don't use supersection mappings for mmap() on /dev/mem, which
134 * means that we can't map the memory area above the 4G barrier into
137 int valid_mmap_phys_addr_range(unsigned long pfn
, size_t size
)
139 return !(pfn
+ (size
>> PAGE_SHIFT
) > 0x00100000);