1 /*
2 * MIPS Huge TLB Page Support for Kernel.
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License. See the file "COPYING" in the main directory of this archive
6 * for more details.
7 *
8 * Copyright (C) 2002, Rohit Seth <rohit.seth@intel.com>
9 * Copyright 2005, Embedded Alley Solutions, Inc.
10 * Matt Porter <mporter@embeddedalley.com>
11 * Copyright (C) 2008, 2009 Cavium Networks, Inc.
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
huge_pte_alloc(struct mm_struct * mm,unsigned long addr,unsigned long sz)24 pte_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
huge_pte_offset(struct mm_struct * mm,unsigned long addr,unsigned long sz)39 pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr,
40 unsigned long sz)
41 {
42 pgd_t *pgd;
43 pud_t *pud;
44 pmd_t *pmd = NULL;
45
46 pgd = pgd_offset(mm, addr);
47 if (pgd_present(*pgd)) {
48 pud = pud_offset(pgd, addr);
49 if (pud_present(*pud))
50 pmd = pmd_offset(pud, addr);
51 }
52 return (pte_t *) pmd;
53 }
54
55 /*
56 * This function checks for proper alignment of input addr and len parameters.
57 */
is_aligned_hugepage_range(unsigned long addr,unsigned long len)58 int is_aligned_hugepage_range(unsigned long addr, unsigned long len)
59 {
60 if (len & ~HPAGE_MASK)
61 return -EINVAL;
62 if (addr & ~HPAGE_MASK)
63 return -EINVAL;
64 return 0;
65 }
66
pmd_huge(pmd_t pmd)67 int pmd_huge(pmd_t pmd)
68 {
69 return (pmd_val(pmd) & _PAGE_HUGE) != 0;
70 }
71
pud_huge(pud_t pud)72 int pud_huge(pud_t pud)
73 {
74 return (pud_val(pud) & _PAGE_HUGE) != 0;
75 }
76