xref: /linux/arch/loongarch/include/asm/hugetlb.h (revision 7f4f3b14e8079ecde096bd734af10e30d40c27b7)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
4  */
5 
6 #ifndef __ASM_HUGETLB_H
7 #define __ASM_HUGETLB_H
8 
9 #include <asm/page.h>
10 
11 uint64_t pmd_to_entrylo(unsigned long pmd_val);
12 
13 #define __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE
14 static inline int prepare_hugepage_range(struct file *file,
15 					 unsigned long addr,
16 					 unsigned long len)
17 {
18 	unsigned long task_size = STACK_TOP;
19 
20 	if (len > task_size)
21 		return -ENOMEM;
22 	if (task_size - len < addr)
23 		return -EINVAL;
24 	return 0;
25 }
26 
27 #define __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR
28 static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
29 					    unsigned long addr, pte_t *ptep)
30 {
31 	pte_t clear;
32 	pte_t pte = ptep_get(ptep);
33 
34 	pte_val(clear) = (unsigned long)invalid_pte_table;
35 	set_pte_at(mm, addr, ptep, clear);
36 	return pte;
37 }
38 
39 #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
40 static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
41 					  unsigned long addr, pte_t *ptep)
42 {
43 	pte_t pte;
44 
45 	pte = huge_ptep_get_and_clear(vma->vm_mm, addr, ptep);
46 	flush_tlb_page(vma, addr);
47 	return pte;
48 }
49 
50 #define __HAVE_ARCH_HUGE_PTE_NONE
51 static inline int huge_pte_none(pte_t pte)
52 {
53 	unsigned long val = pte_val(pte) & ~_PAGE_GLOBAL;
54 	return !val || (val == (unsigned long)invalid_pte_table);
55 }
56 
57 #define __HAVE_ARCH_HUGE_PTEP_SET_ACCESS_FLAGS
58 static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
59 					     unsigned long addr,
60 					     pte_t *ptep, pte_t pte,
61 					     int dirty)
62 {
63 	int changed = !pte_same(ptep_get(ptep), pte);
64 
65 	if (changed) {
66 		set_pte_at(vma->vm_mm, addr, ptep, pte);
67 		/*
68 		 * There could be some standard sized pages in there,
69 		 * get them all.
70 		 */
71 		flush_tlb_range(vma, addr, addr + HPAGE_SIZE);
72 	}
73 	return changed;
74 }
75 
76 #include <asm-generic/hugetlb.h>
77 
78 #endif /* __ASM_HUGETLB_H */
79