hugetlbpage.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 <[email protected]>
  9. * Copyright 2005, Embedded Alley Solutions, Inc.
  10. * Matt Porter <[email protected]>
  11. * Copyright (C) 2008, 2009 Cavium Networks, Inc.
  12. */
  13. #include <linux/fs.h>
  14. #include <linux/mm.h>
  15. #include <linux/hugetlb.h>
  16. #include <linux/pagemap.h>
  17. #include <linux/err.h>
  18. #include <linux/sysctl.h>
  19. #include <asm/mman.h>
  20. #include <asm/tlb.h>
  21. #include <asm/tlbflush.h>
  22. pte_t *huge_pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
  23. unsigned long addr, unsigned long sz)
  24. {
  25. pgd_t *pgd;
  26. p4d_t *p4d;
  27. pud_t *pud;
  28. pte_t *pte = NULL;
  29. pgd = pgd_offset(mm, addr);
  30. p4d = p4d_alloc(mm, pgd, addr);
  31. pud = pud_alloc(mm, p4d, addr);
  32. if (pud)
  33. pte = (pte_t *)pmd_alloc(mm, pud, addr);
  34. return pte;
  35. }
  36. pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr,
  37. unsigned long sz)
  38. {
  39. pgd_t *pgd;
  40. p4d_t *p4d;
  41. pud_t *pud;
  42. pmd_t *pmd = NULL;
  43. pgd = pgd_offset(mm, addr);
  44. if (pgd_present(*pgd)) {
  45. p4d = p4d_offset(pgd, addr);
  46. if (p4d_present(*p4d)) {
  47. pud = pud_offset(p4d, addr);
  48. if (pud_present(*pud))
  49. pmd = pmd_offset(pud, addr);
  50. }
  51. }
  52. return (pte_t *) pmd;
  53. }
  54. int pmd_huge(pmd_t pmd)
  55. {
  56. return (pmd_val(pmd) & _PAGE_HUGE) != 0;
  57. }
  58. int pud_huge(pud_t pud)
  59. {
  60. return (pud_val(pud) & _PAGE_HUGE) != 0;
  61. }