150a41ff2SDavid Daney /*
250a41ff2SDavid Daney * This file is subject to the terms and conditions of the GNU General Public
350a41ff2SDavid Daney * License. See the file "COPYING" in the main directory of this archive
450a41ff2SDavid Daney * for more details.
550a41ff2SDavid Daney *
650a41ff2SDavid Daney * Copyright (C) 2008, 2009 Cavium Networks, Inc.
750a41ff2SDavid Daney */
850a41ff2SDavid Daney
950a41ff2SDavid Daney #ifndef __ASM_HUGETLB_H
1050a41ff2SDavid Daney #define __ASM_HUGETLB_H
1150a41ff2SDavid Daney
1250a41ff2SDavid Daney #include <asm/page.h>
1350a41ff2SDavid Daney
1478d6e4e8SAlexandre Ghiti #define __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE
prepare_hugepage_range(struct file * file,unsigned long addr,unsigned long len)1550a41ff2SDavid Daney static inline int prepare_hugepage_range(struct file *file,
1650a41ff2SDavid Daney unsigned long addr,
1750a41ff2SDavid Daney unsigned long len)
1850a41ff2SDavid Daney {
1950a41ff2SDavid Daney unsigned long task_size = STACK_TOP;
2050a41ff2SDavid Daney struct hstate *h = hstate_file(file);
2150a41ff2SDavid Daney
2250a41ff2SDavid Daney if (len & ~huge_page_mask(h))
2350a41ff2SDavid Daney return -EINVAL;
2450a41ff2SDavid Daney if (addr & ~huge_page_mask(h))
2550a41ff2SDavid Daney return -EINVAL;
2650a41ff2SDavid Daney if (len > task_size)
2750a41ff2SDavid Daney return -ENOMEM;
2850a41ff2SDavid Daney if (task_size - len < addr)
2950a41ff2SDavid Daney return -EINVAL;
3050a41ff2SDavid Daney return 0;
3150a41ff2SDavid Daney }
3250a41ff2SDavid Daney
33a4d83853SAlexandre Ghiti #define __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR
huge_ptep_get_and_clear(struct mm_struct * mm,unsigned long addr,pte_t * ptep,unsigned long sz)3450a41ff2SDavid Daney static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
35*c04035ceSRyan Roberts unsigned long addr, pte_t *ptep,
36*c04035ceSRyan Roberts unsigned long sz)
3750a41ff2SDavid Daney {
3850a41ff2SDavid Daney pte_t clear;
3950a41ff2SDavid Daney pte_t pte = *ptep;
4050a41ff2SDavid Daney
4150a41ff2SDavid Daney pte_val(clear) = (unsigned long)invalid_pte_table;
4250a41ff2SDavid Daney set_pte_at(mm, addr, ptep, clear);
4350a41ff2SDavid Daney return pte;
4450a41ff2SDavid Daney }
4550a41ff2SDavid Daney
46fe632225SAlexandre Ghiti #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
huge_ptep_clear_flush(struct vm_area_struct * vma,unsigned long addr,pte_t * ptep)47ae075629SBaolin Wang static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
4850a41ff2SDavid Daney unsigned long addr, pte_t *ptep)
4950a41ff2SDavid Daney {
50ae075629SBaolin Wang pte_t pte;
51*c04035ceSRyan Roberts unsigned long sz = huge_page_size(hstate_vma(vma));
52ae075629SBaolin Wang
5333ae8f80SBibo Mao /*
5433ae8f80SBibo Mao * clear the huge pte entry firstly, so that the other smp threads will
5533ae8f80SBibo Mao * not get old pte entry after finishing flush_tlb_page and before
5633ae8f80SBibo Mao * setting new huge pte entry
5733ae8f80SBibo Mao */
58*c04035ceSRyan Roberts pte = huge_ptep_get_and_clear(vma->vm_mm, addr, ptep, sz);
5933ae8f80SBibo Mao flush_tlb_page(vma, addr);
60ae075629SBaolin Wang return pte;
6150a41ff2SDavid Daney }
6250a41ff2SDavid Daney
63cae72abcSAlexandre Ghiti #define __HAVE_ARCH_HUGE_PTE_NONE
huge_pte_none(pte_t pte)6450a41ff2SDavid Daney static inline int huge_pte_none(pte_t pte)
6550a41ff2SDavid Daney {
6650a41ff2SDavid Daney unsigned long val = pte_val(pte) & ~_PAGE_GLOBAL;
6750a41ff2SDavid Daney return !val || (val == (unsigned long)invalid_pte_table);
6850a41ff2SDavid Daney }
6950a41ff2SDavid Daney
70facf6d5bSAlexandre Ghiti #define __HAVE_ARCH_HUGE_PTEP_SET_ACCESS_FLAGS
huge_ptep_set_access_flags(struct vm_area_struct * vma,unsigned long addr,pte_t * ptep,pte_t pte,int dirty)7150a41ff2SDavid Daney static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
7250a41ff2SDavid Daney unsigned long addr,
7350a41ff2SDavid Daney pte_t *ptep, pte_t pte,
7450a41ff2SDavid Daney int dirty)
7550a41ff2SDavid Daney {
76ac53c4fcSDavid Daney int changed = !pte_same(*ptep, pte);
77ac53c4fcSDavid Daney
78ac53c4fcSDavid Daney if (changed) {
79ac53c4fcSDavid Daney set_pte_at(vma->vm_mm, addr, ptep, pte);
80ac53c4fcSDavid Daney /*
81ac53c4fcSDavid Daney * There could be some standard sized pages in there,
82ac53c4fcSDavid Daney * get them all.
83ac53c4fcSDavid Daney */
84ac53c4fcSDavid Daney flush_tlb_range(vma, addr, addr + HPAGE_SIZE);
85ac53c4fcSDavid Daney }
86ac53c4fcSDavid Daney return changed;
8750a41ff2SDavid Daney }
8850a41ff2SDavid Daney
891e5f50fcSAlexandre Ghiti #include <asm-generic/hugetlb.h>
901e5f50fcSAlexandre Ghiti
9150a41ff2SDavid Daney #endif /* __ASM_HUGETLB_H */
92