1
2
3
4
5
6
7
8
9
10
11
12
13
14#include <linux/fs.h>
15#include <linux/mm.h>
16#include <linux/hugetlb.h>
17#include <linux/pagemap.h>
18#include <linux/err.h>
19#include <linux/sysctl.h>
20#include <asm/mman.h>
21#include <asm/tlb.h>
22#include <asm/tlbflush.h>
23
24pte_t *huge_pte_alloc(struct mm_struct *mm, unsigned long addr,
25 unsigned long sz)
26{
27 pgd_t *pgd;
28 pud_t *pud;
29 pte_t *pte = NULL;
30
31 pgd = pgd_offset(mm, addr);
32 pud = pud_alloc(mm, pgd, addr);
33 if (pud)
34 pte = (pte_t *)pmd_alloc(mm, pud, addr);
35
36 return pte;
37}
38
39pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr)
40{
41 pgd_t *pgd;
42 pud_t *pud;
43 pmd_t *pmd = NULL;
44
45 pgd = pgd_offset(mm, addr);
46 if (pgd_present(*pgd)) {
47 pud = pud_offset(pgd, addr);
48 if (pud_present(*pud))
49 pmd = pmd_offset(pud, addr);
50 }
51 return (pte_t *) pmd;
52}
53
54
55
56
57int is_aligned_hugepage_range(unsigned long addr, unsigned long len)
58{
59 if (len & ~HPAGE_MASK)
60 return -EINVAL;
61 if (addr & ~HPAGE_MASK)
62 return -EINVAL;
63 return 0;
64}
65
66int pmd_huge(pmd_t pmd)
67{
68 return (pmd_val(pmd) & _PAGE_HUGE) != 0;
69}
70
71int pud_huge(pud_t pud)
72{
73 return (pud_val(pud) & _PAGE_HUGE) != 0;
74}
75