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 <linux/swap.h> 14 #include <linux/swapops.h> 15 #include <asm/page.h> 16 17 #define hugepages_supported() (MACHINE_HAS_EDAT1) 18 19 #define __HAVE_ARCH_HUGE_SET_HUGE_PTE_AT 20 void set_huge_pte_at(struct mm_struct *mm, unsigned long addr, 21 pte_t *ptep, pte_t pte, unsigned long sz); 22 void __set_huge_pte_at(struct mm_struct *mm, unsigned long addr, 23 pte_t *ptep, pte_t pte); 24 #define __HAVE_ARCH_HUGE_PTEP_GET 25 extern pte_t huge_ptep_get(struct mm_struct *mm, unsigned long addr, pte_t *ptep); 26 #define __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR 27 extern pte_t huge_ptep_get_and_clear(struct mm_struct *mm, 28 unsigned long addr, pte_t *ptep); 29 30 static inline void arch_clear_hugetlb_flags(struct folio *folio) 31 { 32 clear_bit(PG_arch_1, &folio->flags); 33 } 34 #define arch_clear_hugetlb_flags arch_clear_hugetlb_flags 35 36 #define __HAVE_ARCH_HUGE_PTE_CLEAR 37 static inline void huge_pte_clear(struct mm_struct *mm, unsigned long addr, 38 pte_t *ptep, unsigned long sz) 39 { 40 if ((pte_val(*ptep) & _REGION_ENTRY_TYPE_MASK) == _REGION_ENTRY_TYPE_R3) 41 set_pte(ptep, __pte(_REGION3_ENTRY_EMPTY)); 42 else 43 set_pte(ptep, __pte(_SEGMENT_ENTRY_EMPTY)); 44 } 45 46 #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH 47 static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma, 48 unsigned long address, pte_t *ptep) 49 { 50 return huge_ptep_get_and_clear(vma->vm_mm, address, ptep); 51 } 52 53 #define __HAVE_ARCH_HUGE_PTEP_SET_ACCESS_FLAGS 54 static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma, 55 unsigned long addr, pte_t *ptep, 56 pte_t pte, int dirty) 57 { 58 int changed = !pte_same(huge_ptep_get(vma->vm_mm, addr, ptep), pte); 59 if (changed) { 60 huge_ptep_get_and_clear(vma->vm_mm, addr, ptep); 61 __set_huge_pte_at(vma->vm_mm, addr, ptep, pte); 62 } 63 return changed; 64 } 65 66 #define __HAVE_ARCH_HUGE_PTEP_SET_WRPROTECT 67 static inline void huge_ptep_set_wrprotect(struct mm_struct *mm, 68 unsigned long addr, pte_t *ptep) 69 { 70 pte_t pte = huge_ptep_get_and_clear(mm, addr, ptep); 71 __set_huge_pte_at(mm, addr, ptep, pte_wrprotect(pte)); 72 } 73 74 #define __HAVE_ARCH_HUGE_PTE_NONE 75 static inline int huge_pte_none(pte_t pte) 76 { 77 return pte_none(pte); 78 } 79 80 #define __HAVE_ARCH_HUGE_PTE_NONE_MOSTLY 81 static inline int huge_pte_none_mostly(pte_t pte) 82 { 83 return huge_pte_none(pte) || is_pte_marker(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