1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * IBM System z Huge TLB Page Support for Kernel. 4 * 5 * Copyright IBM Corp. 2008 6 * Author(s): Gerald Schaefer <gerald.schaefer@de.ibm.com> 7 */ 8 9 #ifndef _ASM_S390_HUGETLB_H 10 #define _ASM_S390_HUGETLB_H 11 12 #include <linux/pgtable.h> 13 #include <asm/page.h> 14 15 #define hugepages_supported() (MACHINE_HAS_EDAT1) 16 17 #define __HAVE_ARCH_HUGE_SET_HUGE_PTE_AT 18 void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, 19 pte_t *ptep, pte_t pte, unsigned long sz); 20 void __set_huge_pte_at(struct mm_struct *mm, unsigned long addr, 21 pte_t *ptep, pte_t pte); 22 #define __HAVE_ARCH_HUGE_PTEP_GET 23 extern pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep); 24 #define __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR 25 extern pte_t huge_ptep_get_and_clear(struct mm_struct *mm, 26 unsigned long addr, pte_t *ptep); 27 28 static inline void arch_clear_hugetlb_flags(struct folio *folio) 29 { 30 clear_bit(PG_arch_1, &folio->flags); 31 } 32 #define arch_clear_hugetlb_flags arch_clear_hugetlb_flags 33 34 #define __HAVE_ARCH_HUGE_PTE_CLEAR 35 static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr, 36 pte_t *ptep, unsigned long sz) 37 { 38 if ((pte_val(*ptep) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3) 39 set_pte(ptep, __pte(_REGION3_ENTRY_EMPTY)); 40 else 41 set_pte(ptep, __pte(_SEGMENT_ENTRY_EMPTY)); 42 } 43 44 #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH 45 static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, 46 unsigned long address, pte_t *ptep) 47 { 48 return huge_ptep_get_and_clear(vma->vm_mm, address, ptep); 49 } 50 51 #define __HAVE_ARCH_HUGE_PTEP_SET_ACCESS_FLAGS 52 static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma, 53 unsigned long addr, pte_t *ptep, 54 pte_t pte, int dirty) 55 { 56 int changed = !pte_same(huge_ptep_get(vma->vm_mm, addr, ptep), pte); 57 if (changed) { 58 huge_ptep_get_and_clear(vma->vm_mm, addr, ptep); 59 __set_huge_pte_at(vma->vm_mm, addr, ptep, pte); 60 } 61 return changed; 62 } 63 64 #define __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT 65 static inline void huge_ptep_set_wrprotect(struct mm_struct *mm, 66 unsigned long addr, pte_t *ptep) 67 { 68 pte_t pte = huge_ptep_get_and_clear(mm, addr, ptep); 69 __set_huge_pte_at(mm, addr, ptep, pte_wrprotect(pte)); 70 } 71 72 #define __HAVE_ARCH_HUGE_PTE_NONE 73 static inline int huge_pte_none(pte_t pte) 74 { 75 return pte_none(pte); 76 } 77 78 #define __HAVE_ARCH_HUGE_PTE_NONE_MOSTLY 79 static inline int huge_pte_none_mostly(pte_t pte) 80 { 81 return huge_pte_none(pte); 82 } 83 84 #define __HAVE_ARCH_HUGE_PTE_MKUFFD_WP 85 static inline pte_t huge_pte_mkuffd_wp(pte_t pte) 86 { 87 return pte; 88 } 89 90 #define __HAVE_ARCH_HUGE_PTE_CLEAR_UFFD_WP 91 static inline pte_t huge_pte_clear_uffd_wp(pte_t pte) 92 { 93 return pte; 94 } 95 96 #define __HAVE_ARCH_HUGE_PTE_UFFD_WP 97 static inline int huge_pte_uffd_wp(pte_t pte) 98 { 99 return 0; 100 } 101 102 #include <asm-generic/hugetlb.h> 103 104 #endif /* _ASM_S390_HUGETLB_H */ 105