OMAP: Add new function to check wether there is irq pending
[linux-ginger.git] / arch / sh / mm / mmap.c
blob931f4d003fa07fc66b2c4b9e14c53ac1e972c616
1 /*
2 * arch/sh/mm/mmap.c
4 * Copyright (C) 2008 Paul Mundt
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
8 * for more details.
9 */
10 #include <linux/io.h>
11 #include <linux/mm.h>
12 #include <linux/mman.h>
13 #include <linux/module.h>
14 #include <asm/page.h>
15 #include <asm/processor.h>
17 #ifdef CONFIG_MMU
18 unsigned long shm_align_mask = PAGE_SIZE - 1; /* Sane caches */
19 EXPORT_SYMBOL(shm_align_mask);
22 * To avoid cache aliases, we map the shared page with same color.
24 #define COLOUR_ALIGN(addr, pgoff) \
25 ((((addr) + shm_align_mask) & ~shm_align_mask) + \
26 (((pgoff) << PAGE_SHIFT) & shm_align_mask))
28 unsigned long 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;
34 int do_colour_align;
36 if (flags & MAP_FIXED) {
37 /* We do not accept a shared mapping if it would violate
38 * cache aliasing constraints.
40 if ((flags & MAP_SHARED) && (addr & shm_align_mask))
41 return -EINVAL;
42 return addr;
45 if (unlikely(len > TASK_SIZE))
46 return -ENOMEM;
48 do_colour_align = 0;
49 if (filp || (flags & MAP_SHARED))
50 do_colour_align = 1;
52 if (addr) {
53 if (do_colour_align)
54 addr = COLOUR_ALIGN(addr, pgoff);
55 else
56 addr = PAGE_ALIGN(addr);
58 vma = find_vma(mm, addr);
59 if (TASK_SIZE - len >= addr &&
60 (!vma || addr + len <= vma->vm_start))
61 return addr;
64 if (len > mm->cached_hole_size) {
65 start_addr = addr = mm->free_area_cache;
66 } else {
67 mm->cached_hole_size = 0;
68 start_addr = addr = TASK_UNMAPPED_BASE;
71 full_search:
72 if (do_colour_align)
73 addr = COLOUR_ALIGN(addr, pgoff);
74 else
75 addr = PAGE_ALIGN(mm->free_area_cache);
77 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
78 /* At this point: (!vma || addr < vma->vm_end). */
79 if (unlikely(TASK_SIZE - len < addr)) {
81 * Start a new search - just in case we missed
82 * some holes.
84 if (start_addr != TASK_UNMAPPED_BASE) {
85 start_addr = addr = TASK_UNMAPPED_BASE;
86 mm->cached_hole_size = 0;
87 goto full_search;
89 return -ENOMEM;
91 if (likely(!vma || addr + len <= vma->vm_start)) {
93 * Remember the place where we stopped the search:
95 mm->free_area_cache = addr + len;
96 return addr;
98 if (addr + mm->cached_hole_size < vma->vm_start)
99 mm->cached_hole_size = vma->vm_start - addr;
101 addr = vma->vm_end;
102 if (do_colour_align)
103 addr = COLOUR_ALIGN(addr, pgoff);
106 #endif /* CONFIG_MMU */
109 * You really shouldn't be using read() or write() on /dev/mem. This
110 * might go away in the future.
112 int valid_phys_addr_range(unsigned long addr, size_t count)
114 if (addr < __MEMORY_START)
115 return 0;
116 if (addr + count > __pa(high_memory))
117 return 0;
119 return 1;
122 int valid_mmap_phys_addr_range(unsigned long pfn, size_t size)
124 return 1;