hugetlb: introduce generic version of huge_ptep_get_and_clear()
[muen/linux.git] / arch / mips / include / asm / hugetlb.h
1 /*
2  * This file is subject to the terms and conditions of the GNU General Public
3  * License.  See the file "COPYING" in the main directory of this archive
4  * for more details.
5  *
6  * Copyright (C) 2008, 2009 Cavium Networks, Inc.
7  */
8
9 #ifndef __ASM_HUGETLB_H
10 #define __ASM_HUGETLB_H
11
12 #include <asm/page.h>
13
14 static inline int is_hugepage_only_range(struct mm_struct *mm,
15                                          unsigned long addr,
16                                          unsigned long len)
17 {
18         return 0;
19 }
20
21 static inline int prepare_hugepage_range(struct file *file,
22                                          unsigned long addr,
23                                          unsigned long len)
24 {
25         unsigned long task_size = STACK_TOP;
26         struct hstate *h = hstate_file(file);
27
28         if (len & ~huge_page_mask(h))
29                 return -EINVAL;
30         if (addr & ~huge_page_mask(h))
31                 return -EINVAL;
32         if (len > task_size)
33                 return -ENOMEM;
34         if (task_size - len < addr)
35                 return -EINVAL;
36         return 0;
37 }
38
39 #define __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR
40 static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
41                                             unsigned long addr, pte_t *ptep)
42 {
43         pte_t clear;
44         pte_t pte = *ptep;
45
46         pte_val(clear) = (unsigned long)invalid_pte_table;
47         set_pte_at(mm, addr, ptep, clear);
48         return pte;
49 }
50
51 static inline void huge_ptep_clear_flush(struct vm_area_struct *vma,
52                                          unsigned long addr, pte_t *ptep)
53 {
54         flush_tlb_page(vma, addr & huge_page_mask(hstate_vma(vma)));
55 }
56
57 static inline int huge_pte_none(pte_t pte)
58 {
59         unsigned long val = pte_val(pte) & ~_PAGE_GLOBAL;
60         return !val || (val == (unsigned long)invalid_pte_table);
61 }
62
63 static inline pte_t huge_pte_wrprotect(pte_t pte)
64 {
65         return pte_wrprotect(pte);
66 }
67
68 static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
69                                            unsigned long addr, pte_t *ptep)
70 {
71         ptep_set_wrprotect(mm, addr, ptep);
72 }
73
74 static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
75                                              unsigned long addr,
76                                              pte_t *ptep, pte_t pte,
77                                              int dirty)
78 {
79         int changed = !pte_same(*ptep, pte);
80
81         if (changed) {
82                 set_pte_at(vma->vm_mm, addr, ptep, pte);
83                 /*
84                  * There could be some standard sized pages in there,
85                  * get them all.
86                  */
87                 flush_tlb_range(vma, addr, addr + HPAGE_SIZE);
88         }
89         return changed;
90 }
91
92 static inline pte_t huge_ptep_get(pte_t *ptep)
93 {
94         return *ptep;
95 }
96
97 static inline void arch_clear_hugepage_flags(struct page *page)
98 {
99 }
100
101 #include <asm-generic/hugetlb.h>
102
103 #endif /* __ASM_HUGETLB_H */