xref: /openbmc/linux/arch/mips/include/asm/hugetlb.h (revision ae075629)
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)3450a41ff2SDavid Daney static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
3550a41ff2SDavid Daney 					    unsigned long addr, pte_t *ptep)
3650a41ff2SDavid Daney {
3750a41ff2SDavid Daney 	pte_t clear;
3850a41ff2SDavid Daney 	pte_t pte = *ptep;
3950a41ff2SDavid Daney 
4050a41ff2SDavid Daney 	pte_val(clear) = (unsigned long)invalid_pte_table;
4150a41ff2SDavid Daney 	set_pte_at(mm, addr, ptep, clear);
4250a41ff2SDavid Daney 	return pte;
4350a41ff2SDavid Daney }
4450a41ff2SDavid Daney 
45fe632225SAlexandre Ghiti #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
huge_ptep_clear_flush(struct vm_area_struct * vma,unsigned long addr,pte_t * ptep)46*ae075629SBaolin Wang static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
4750a41ff2SDavid Daney 					  unsigned long addr, pte_t *ptep)
4850a41ff2SDavid Daney {
49*ae075629SBaolin Wang 	pte_t pte;
50*ae075629SBaolin Wang 
5133ae8f80SBibo Mao 	/*
5233ae8f80SBibo Mao 	 * clear the huge pte entry firstly, so that the other smp threads will
5333ae8f80SBibo Mao 	 * not get old pte entry after finishing flush_tlb_page and before
5433ae8f80SBibo Mao 	 * setting new huge pte entry
5533ae8f80SBibo Mao 	 */
56*ae075629SBaolin Wang 	pte = huge_ptep_get_and_clear(vma->vm_mm, addr, ptep);
5733ae8f80SBibo Mao 	flush_tlb_page(vma, addr);
58*ae075629SBaolin Wang 	return pte;
5950a41ff2SDavid Daney }
6050a41ff2SDavid Daney 
61cae72abcSAlexandre Ghiti #define __HAVE_ARCH_HUGE_PTE_NONE
huge_pte_none(pte_t pte)6250a41ff2SDavid Daney static inline int huge_pte_none(pte_t pte)
6350a41ff2SDavid Daney {
6450a41ff2SDavid Daney 	unsigned long val = pte_val(pte) & ~_PAGE_GLOBAL;
6550a41ff2SDavid Daney 	return !val || (val == (unsigned long)invalid_pte_table);
6650a41ff2SDavid Daney }
6750a41ff2SDavid Daney 
68facf6d5bSAlexandre 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)6950a41ff2SDavid Daney static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
7050a41ff2SDavid Daney 					     unsigned long addr,
7150a41ff2SDavid Daney 					     pte_t *ptep, pte_t pte,
7250a41ff2SDavid Daney 					     int dirty)
7350a41ff2SDavid Daney {
74ac53c4fcSDavid Daney 	int changed = !pte_same(*ptep, pte);
75ac53c4fcSDavid Daney 
76ac53c4fcSDavid Daney 	if (changed) {
77ac53c4fcSDavid Daney 		set_pte_at(vma->vm_mm, addr, ptep, pte);
78ac53c4fcSDavid Daney 		/*
79ac53c4fcSDavid Daney 		 * There could be some standard sized pages in there,
80ac53c4fcSDavid Daney 		 * get them all.
81ac53c4fcSDavid Daney 		 */
82ac53c4fcSDavid Daney 		flush_tlb_range(vma, addr, addr + HPAGE_SIZE);
83ac53c4fcSDavid Daney 	}
84ac53c4fcSDavid Daney 	return changed;
8550a41ff2SDavid Daney }
8650a41ff2SDavid Daney 
871e5f50fcSAlexandre Ghiti #include <asm-generic/hugetlb.h>
881e5f50fcSAlexandre Ghiti 
8950a41ff2SDavid Daney #endif /* __ASM_HUGETLB_H */
90