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/cpufeature.h> 13 #include <linux/pgtable.h> 14 #include <linux/swap.h> 15 #include <linux/swapops.h> 16 #include <asm/page.h> 17 18 #define hugepages_supported() cpu_has_edat1() 19 20 #define __HAVE_ARCH_HUGE_SET_HUGE_PTE_AT 21 void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, 22 pte_t *ptep, pte_t pte, unsigned long sz); 23 void __set_huge_pte_at(struct mm_struct *mm, unsigned long addr, 24 pte_t *ptep, pte_t pte); 25 26 #define __HAVE_ARCH_HUGE_PTEP_GET 27 pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep); 28 29 pte_t __huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr, 30 pte_t *ptep); 31 32 #define __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR 33 static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm, 34 unsigned long addr, pte_t *ptep, 35 unsigned long sz) 36 { 37 return __huge_ptep_get_and_clear(mm, addr, ptep); 38 } 39 40 static inline void arch_clear_hugetlb_flags(struct folio *folio) 41 { 42 clear_bit(PG_arch_1, &folio->flags); 43 } 44 #define arch_clear_hugetlb_flags arch_clear_hugetlb_flags 45 46 #define __HAVE_ARCH_HUGE_PTE_CLEAR 47 static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr, 48 pte_t *ptep, unsigned long sz) 49 { 50 if ((pte_val(*ptep) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3) 51 set_pte(ptep, __pte(_REGION3_ENTRY_EMPTY)); 52 else 53 set_pte(ptep, __pte(_SEGMENT_ENTRY_EMPTY)); 54 } 55 56 #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH 57 static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, 58 unsigned long address, pte_t *ptep) 59 { 60 return __huge_ptep_get_and_clear(vma->vm_mm, address, ptep); 61 } 62 63 #define __HAVE_ARCH_HUGE_PTEP_SET_ACCESS_FLAGS 64 static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma, 65 unsigned long addr, pte_t *ptep, 66 pte_t pte, int dirty) 67 { 68 int changed = !pte_same(huge_ptep_get(vma->vm_mm, addr, ptep), pte); 69 70 if (changed) { 71 __huge_ptep_get_and_clear(vma->vm_mm, addr, ptep); 72 __set_huge_pte_at(vma->vm_mm, addr, ptep, pte); 73 } 74 return changed; 75 } 76 77 #define __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT 78 static inline void huge_ptep_set_wrprotect(struct mm_struct *mm, 79 unsigned long addr, pte_t *ptep) 80 { 81 pte_t pte = __huge_ptep_get_and_clear(mm, addr, ptep); 82 83 __set_huge_pte_at(mm, addr, ptep, pte_wrprotect(pte)); 84 } 85 86 #define __HAVE_ARCH_HUGE_PTE_MKUFFD_WP 87 static inline pte_t huge_pte_mkuffd_wp(pte_t pte) 88 { 89 return pte; 90 } 91 92 #define __HAVE_ARCH_HUGE_PTE_CLEAR_UFFD_WP 93 static inline pte_t huge_pte_clear_uffd_wp(pte_t pte) 94 { 95 return pte; 96 } 97 98 #define __HAVE_ARCH_HUGE_PTE_UFFD_WP 99 static inline int huge_pte_uffd_wp(pte_t pte) 100 { 101 return 0; 102 } 103 104 #include <asm-generic/hugetlb.h> 105 106 #endif /* _ASM_S390_HUGETLB_H */ 107