2 * arch/arm/include/asm/hugetlb-2level.h
4 * Copyright (C) 2012 ARM Ltd.
6 * Based on arch/x86/include/asm/hugetlb.h and Bill Carson's patches
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License version 2 as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #ifndef _ASM_ARM_HUGETLB_2LEVEL_H
23 #define _ASM_ARM_HUGETLB_2LEVEL_H
26 static inline pte_t huge_ptep_get(pte_t *ptep)
28 pmd_t pmd = *((pmd_t *)ptep);
29 u32 pmdval = pmd_val(pmd);
35 retval = __pte((pteval_t) (pmd_val(pmd) & HPAGE_MASK)
36 | (pmdval & 0x0c) | ((pmdval >> 8) & 0x10)
37 | L_PTE_PRESENT | L_PTE_USER | L_PTE_VALID);
40 retval = pte_mkexec(retval);
42 retval = pte_mknexec(retval);
45 retval = pte_mkyoung(retval);
47 retval = pte_mkold(retval);
50 retval = pte_mkdirty(retval);
52 retval = pte_mkclean(retval);
55 retval = pte_mkwrite(retval);
57 retval = pte_wrprotect(retval);
62 static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
63 pte_t *ptep, pte_t pte)
65 pmdval_t pmdval = (pmdval_t) pte_val(pte);
66 pmd_t *pmdp = (pmd_t *) ptep;
68 /* take the target address bits from the pte only */
72 * now use pmd_modify to translate the permission bits from the pte
73 * and set the memory type information.
75 pmdval = pmd_val(pmd_modify(__pmd(pmdval), __pgprot(pte_val(pte))));
77 __sync_icache_dcache(pte);
79 set_pmd_at(mm, addr, pmdp, __pmd(pmdval));
82 static inline pte_t pte_mkhuge(pte_t pte) { return pte; }
84 static inline void huge_ptep_clear_flush(struct vm_area_struct *vma,
85 unsigned long addr, pte_t *ptep)
87 pmd_t *pmdp = (pmd_t *)ptep;
89 flush_tlb_range(vma, addr, addr + HPAGE_SIZE);
92 static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
93 unsigned long addr, pte_t *ptep)
95 pmd_t *pmdp = (pmd_t *) ptep;
96 set_pmd_at(mm, addr, pmdp, pmd_wrprotect(*pmdp));
100 static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
101 unsigned long addr, pte_t *ptep)
103 pmd_t *pmdp = (pmd_t *)ptep;
104 pte_t pte = huge_ptep_get(ptep);
110 static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
111 unsigned long addr, pte_t *ptep,
112 pte_t pte, int dirty)
114 int changed = !pte_same(huge_ptep_get(ptep), pte);
116 set_huge_pte_at(vma->vm_mm, addr, ptep, pte);
117 flush_tlb_range(vma, addr, addr + HPAGE_SIZE);
123 #endif /* _ASM_ARM_HUGETLB_2LEVEL_H */