1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3 * Copyright (c) 2022 Huawei Device Co., Ltd.
4 */
5
6 #ifndef __MM_PURGEABLE_MEM_H
7 #define __MM_PURGEABLE_MEM_H
8
9 #ifdef CONFIG_MEM_PURGEABLE
10
11 void mm_init_uxpgd(struct mm_struct *mm);
12 void mm_clear_uxpgd(struct mm_struct *mm);
13 bool lock_uxpte(struct vm_area_struct *vma, unsigned long addr);
14 void unlock_uxpte(struct vm_area_struct *vma, unsigned long addr);
15 vm_fault_t do_uxpte_page_fault(struct vm_fault *vmf, pte_t *entry);
16 bool uxpte_set_present(struct vm_area_struct *vma, unsigned long addr);
17 void uxpte_clear_present(struct vm_area_struct *vma, unsigned long addr);
18
19 /*
20 * mm_purg_pages_info: get purgeable pages count of @mm
21 * @mm: [in] pointer to mm
22 * @total_purg_pages: [out] total purgeable pages of @mm
23 * @pined_purg_pages: [out] pined purgeable pages of @mm
24 * If @mm is NULL, return with doing nothing.
25 * If @total_purg_pages and @pined_purg_pages are both NULL, return with doing nothing.
26 * If one of @total_purg_pages and @pined_purg_pages is NULL, other one will be counted.
27 */
28 void mm_purg_pages_info(struct mm_struct *mm, unsigned long *total_purg_pages,
29 unsigned long *pined_purg_pages);
30
31 /*
32 * purg_pages_info: get global purgeable pages in system
33 * @total_purg_pages: [out] total purgeable pages in system
34 * @pined_purg_pages: [out] pined purgeable pages in system
35 * If @total_purg_pages and @pined_purg_pages are both NULL, return with doing nothing.
36 * If one of @total_purg_pages and @pined_purg_pages is NULL, other one will be counted.
37 */
38 void purg_pages_info(unsigned long *total_purg_pages, unsigned long *pined_purg_pages);
39
40 #else /* CONFIG_MEM_PURGEABLE */
41
mm_init_uxpgd(struct mm_struct * mm)42 static inline void mm_init_uxpgd(struct mm_struct *mm) {}
43
mm_clear_uxpgd(struct mm_struct * mm)44 static inline void mm_clear_uxpgd(struct mm_struct *mm) {}
45
lock_uxpte(struct vm_area_struct * vma,unsigned long addr)46 static inline bool lock_uxpte(struct vm_area_struct *vma,
47 unsigned long addr)
48 {
49 return false;
50 }
51
unlock_uxpte(struct vm_area_struct * vma,unsigned long addr)52 static inline void unlock_uxpte(struct vm_area_struct *vma,
53 unsigned long addr) {}
54
do_uxpte_page_fault(struct vm_fault * vmf,pte_t * entry)55 static inline vm_fault_t do_uxpte_page_fault(struct vm_fault *vmf,
56 pte_t *entry)
57 {
58 return 0;
59 }
60
uxpte_set_present(struct vm_area_struct * vma,unsigned long addr)61 static inline bool uxpte_set_present(struct vm_area_struct *vma,
62 unsigned long addr)
63 {
64 return false;
65 }
66
uxpte_clear_present(struct vm_area_struct * vma,unsigned long addr)67 static inline void uxpte_clear_present(struct vm_area_struct *vma,
68 unsigned long addr) {}
69
mm_purg_pages_info(struct mm_struct * mm,unsigned long * total_purg_pages,unsigned long * pined_purg_pages)70 static inline void mm_purg_pages_info(struct mm_struct *mm,
71 unsigned long *total_purg_pages, unsigned long *pined_purg_pages) {}
72
purg_pages_info(unsigned long * total_purg_pages,unsigned long * pined_purg_pages)73 static inline void purg_pages_info(unsigned long *total_purg_pages,
74 unsigned long *pined_purg_pages) {}
75 #endif /* CONFIG_MEM_PURGEABLE */
76 #endif /* __MM_PURGEABLE_MEM_H */
77
78