2 * hugetlb.h, ARM Huge Tlb Page support.
4 * Copyright (c) Bill Carson
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #ifndef __ASM_HUGETLB_H
22 #define __ASM_HUGETLB_H
25 #include <asm/pgtable-2level.h>
29 /* 2M and 16M hugepage linux ptes are stored in mmu_context_t->huge_linux_pte
33 * one huge linux pte caters to two HW ptes,
37 * one huge linux pte caters for sixteen HW ptes,
39 * The number of huge linux ptes depends on PAGE_OFFSET configuration
40 * which is defined as following:
42 #define HUGE_LINUX_PTE_COUNT ( PAGE_OFFSET >> HPAGE_SHIFT)
43 #define HUGE_LINUX_PTE_SIZE (HUGE_LINUX_PTE_COUNT * sizeof(pte_t *))
44 #define HUGE_LINUX_PTE_INDEX(addr) (addr >> HPAGE_SHIFT)
46 static inline int is_hugepage_only_range(struct mm_struct *mm,
53 static inline int prepare_hugepage_range(struct file *file,
57 struct hstate *h = hstate_file(file);
58 /* addr/len should be aligned with huge page size */
59 if (len & ~huge_page_mask(h))
61 if (addr & ~huge_page_mask(h))
67 static inline void hugetlb_prefault_arch_hook(struct mm_struct *mm)
71 static inline void hugetlb_free_pgd_range(struct mmu_gather *tlb,
72 unsigned long addr, unsigned long end,
73 unsigned long floor, unsigned long ceiling)
77 static inline void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
78 pte_t *ptep, pte_t pte)
83 pte_t *linuxpte = mm->context.huge_linux_pte;
85 BUG_ON(linuxpte == NULL);
86 BUG_ON(HUGE_LINUX_PTE_INDEX(addr) >= HUGE_LINUX_PTE_COUNT);
87 BUG_ON(ptep != &linuxpte[HUGE_LINUX_PTE_INDEX(addr)]);
89 /* set huge linux pte first */
92 /* then set hardware pte */
94 pgd = pgd_offset(mm, addr);
95 pud = pud_offset(pgd, addr);
96 pmd = pmd_offset(pud, addr);
97 set_hugepte_at(mm, addr, pmd, pte);
100 static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
101 unsigned long addr, pte_t *ptep)
104 pte_t fake = L_PTE_YOUNG;
109 /* clear linux pte */
112 /* let set_hugepte_at clear HW entry */
114 pgd = pgd_offset(mm, addr);
115 pud = pud_offset(pgd, addr);
116 pmd = pmd_offset(pud, addr);
117 set_hugepte_at(mm, addr, pmd, fake);
121 static inline void huge_ptep_clear_flush(struct vm_area_struct *vma,
122 unsigned long addr, pte_t *ptep)
124 if (HPAGE_SHIFT == SUPERSECTION_SHIFT)
125 flush_tlb_page(vma, addr & SUPERSECTION_MASK);
127 flush_tlb_page(vma, addr & SECTION_MASK);
128 flush_tlb_page(vma, (addr & SECTION_MASK)^0x100000);
132 static inline int huge_pte_none(pte_t pte)
134 return pte_none(pte);
137 static inline pte_t huge_pte_wrprotect(pte_t pte)
139 return pte_wrprotect(pte);
142 static inline void huge_ptep_set_wrprotect(struct mm_struct *mm,
143 unsigned long addr, pte_t *ptep)
145 pte_t old_pte = *ptep;
146 set_huge_pte_at(mm, addr, ptep, pte_wrprotect(old_pte));
149 static inline pte_t huge_ptep_get(pte_t *ptep)
154 static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
156 pte_t *ptep, pte_t pte,
159 int changed = !pte_same(huge_ptep_get(ptep), pte);
161 set_huge_pte_at(vma->vm_mm, addr, ptep, pte);
162 huge_ptep_clear_flush(vma, addr, &pte);
168 static inline int arch_prepare_hugepage(struct page *page)
173 static inline void arch_release_hugepage(struct page *page)
177 #endif /* __ASM_HUGETLB_H */