xref: /linux/arch/loongarch/include/asm/hugetlb.h (revision 94901b7a74d82bfd30420f1d9d00898278fdc8bf)
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_PTE_CLEAR
28 static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr,
29 				  pte_t *ptep, unsigned long sz)
30 {
31 	pte_t clear;
32 
33 	pte_val(clear) = (unsigned long)invalid_pte_table;
34 	set_pte_at(mm, addr, ptep, clear);
35 }
36 
37 #define __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR
38 static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
39 					    unsigned long addr, pte_t *ptep)
40 {
41 	pte_t clear;
42 	pte_t pte = ptep_get(ptep);
43 
44 	pte_val(clear) = (unsigned long)invalid_pte_table;
45 	set_pte_at(mm, addr, ptep, clear);
46 	return pte;
47 }
48 
49 #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
50 static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
51 					  unsigned long addr, pte_t *ptep)
52 {
53 	pte_t pte;
54 
55 	pte = huge_ptep_get_and_clear(vma->vm_mm, addr, ptep);
56 	flush_tlb_page(vma, addr);
57 	return pte;
58 }
59 
60 #define __HAVE_ARCH_HUGE_PTE_NONE
61 static inline int huge_pte_none(pte_t pte)
62 {
63 	unsigned long val = pte_val(pte) & ~_PAGE_GLOBAL;
64 	return !val || (val == (unsigned long)invalid_pte_table);
65 }
66 
67 #define __HAVE_ARCH_HUGE_PTEP_SET_ACCESS_FLAGS
68 static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
69 					     unsigned long addr,
70 					     pte_t *ptep, pte_t pte,
71 					     int dirty)
72 {
73 	int changed = !pte_same(ptep_get(ptep), pte);
74 
75 	if (changed) {
76 		set_pte_at(vma->vm_mm, addr, ptep, pte);
77 		/*
78 		 * There could be some standard sized pages in there,
79 		 * get them all.
80 		 */
81 		flush_tlb_range(vma, addr, addr + HPAGE_SIZE);
82 	}
83 	return changed;
84 }
85 
86 #include <asm-generic/hugetlb.h>
87 
88 #endif /* __ASM_HUGETLB_H */
89