aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arc/mm
diff options
context:
space:
mode:
authorVineet Gupta <vgupta@synopsys.com>2013-05-09 09:50:43 -0400
committerVineet Gupta <vgupta@synopsys.com>2013-05-09 12:30:57 -0400
commit5bba49f5397c012d873c73860ad7b50c526e613b (patch)
treebcea4107858b117c7bd063ca3e90c0cc1773f636 /arch/arc/mm
parentde2a852cc0d4c4d6a9c22a597c9cc231f2e6ceb4 (diff)
ARC: [mm] Aliasing VIPT dcache support 4/4
Enforce congruency of userspace shared mappings Signed-off-by: Vineet Gupta <vgupta@synopsys.com>
Diffstat (limited to 'arch/arc/mm')
-rw-r--r--arch/arc/mm/Makefile2
-rw-r--r--arch/arc/mm/mmap.c78
2 files changed, 79 insertions, 1 deletions
diff --git a/arch/arc/mm/Makefile b/arch/arc/mm/Makefile
index 168dc146a8f6..ac95cc239c1e 100644
--- a/arch/arc/mm/Makefile
+++ b/arch/arc/mm/Makefile
@@ -7,4 +7,4 @@
7# 7#
8 8
9obj-y := extable.o ioremap.o dma.o fault.o init.o 9obj-y := extable.o ioremap.o dma.o fault.o init.o
10obj-y += tlb.o tlbex.o cache_arc700.o 10obj-y += tlb.o tlbex.o cache_arc700.o mmap.o
diff --git a/arch/arc/mm/mmap.c b/arch/arc/mm/mmap.c
new file mode 100644
index 000000000000..2e06d56e987b
--- /dev/null
+++ b/arch/arc/mm/mmap.c
@@ -0,0 +1,78 @@
1/*
2 * ARC700 mmap
3 *
4 * (started from arm version - for VIPT alias handling)
5 *
6 * Copyright (C) 2013 Synopsys, Inc. (www.synopsys.com)
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
11 */
12
13#include <linux/fs.h>
14#include <linux/mm.h>
15#include <linux/mman.h>
16#include <linux/sched.h>
17#include <asm/cacheflush.h>
18
19#define COLOUR_ALIGN(addr, pgoff) \
20 ((((addr) + SHMLBA - 1) & ~(SHMLBA - 1)) + \
21 (((pgoff) << PAGE_SHIFT) & (SHMLBA - 1)))
22
23/*
24 * Ensure that shared mappings are correctly aligned to
25 * avoid aliasing issues with VIPT caches.
26 * We need to ensure that
27 * a specific page of an object is always mapped at a multiple of
28 * SHMLBA bytes.
29 */
30unsigned long
31arch_get_unmapped_area(struct file *filp, unsigned long addr,
32 unsigned long len, unsigned long pgoff, unsigned long flags)
33{
34 struct mm_struct *mm = current->mm;
35 struct vm_area_struct *vma;
36 int do_align = 0;
37 int aliasing = cache_is_vipt_aliasing();
38 struct vm_unmapped_area_info info;
39
40 /*
41 * We only need to do colour alignment if D cache aliases.
42 */
43 if (aliasing)
44 do_align = filp || (flags & MAP_SHARED);
45
46 /*
47 * We enforce the MAP_FIXED case.
48 */
49 if (flags & MAP_FIXED) {
50 if (aliasing && flags & MAP_SHARED &&
51 (addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1))
52 return -EINVAL;
53 return addr;
54 }
55
56 if (len > TASK_SIZE)
57 return -ENOMEM;
58
59 if (addr) {
60 if (do_align)
61 addr = COLOUR_ALIGN(addr, pgoff);
62 else
63 addr = PAGE_ALIGN(addr);
64
65 vma = find_vma(mm, addr);
66 if (TASK_SIZE - len >= addr &&
67 (!vma || addr + len <= vma->vm_start))
68 return addr;
69 }
70
71 info.flags = 0;
72 info.length = len;
73 info.low_limit = mm->mmap_base;
74 info.high_limit = TASK_SIZE;
75 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
76 info.align_offset = pgoff << PAGE_SHIFT;
77 return vm_unmapped_area(&info);
78}