hugetlbpage.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #include <linux/init.h>
  14. #include <linux/fs.h>
  15. #include <linux/mm.h>
  16. #include <linux/hugetlb.h>
  17. #include <linux/pagemap.h>
  18. #include <linux/smp_lock.h>
  19. #include <linux/slab.h>
  20. #include <linux/err.h>
  21. #include <linux/sysctl.h>
  22. #include <asm/mman.h>
  23. #include <asm/tlb.h>
  24. #include <asm/tlbflush.h>
  25. pte_t *huge_pte_alloc(struct mm_struct *mm, unsigned long addr,
  26. unsigned long sz)
  27. {
  28. pgd_t *pgd;
  29. pud_t *pud;
  30. pte_t *pte = NULL;
  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. return pte;
  36. }
  37. pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr)
  38. {
  39. pgd_t *pgd;
  40. pud_t *pud;
  41. pmd_t *pmd = NULL;
  42. pgd = pgd_offset(mm, addr);
  43. if (pgd_present(*pgd)) {
  44. pud = pud_offset(pgd, addr);
  45. if (pud_present(*pud))
  46. pmd = pmd_offset(pud, addr);
  47. }
  48. return (pte_t *) pmd;
  49. }
  50. int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
  51. {
  52. return 0;
  53. }
  54. /*
  55. * This function checks for proper alignment of input addr and len parameters.
  56. */
  57. int 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. struct page *
  66. follow_huge_addr(struct mm_struct *mm, unsigned long address, int write)
  67. {
  68. return ERR_PTR(-EINVAL);
  69. }
  70. int pmd_huge(pmd_t pmd)
  71. {
  72. return (pmd_val(pmd) & _PAGE_HUGE) != 0;
  73. }
  74. int pud_huge(pud_t pud)
  75. {
  76. return (pud_val(pud) & _PAGE_HUGE) != 0;
  77. }
  78. struct page *
  79. follow_huge_pmd(struct mm_struct *mm, unsigned long address,
  80. pmd_t *pmd, int write)
  81. {
  82. struct page *page;
  83. page = pte_page(*(pte_t *)pmd);
  84. if (page)
  85. page += ((address & ~HPAGE_MASK) >> PAGE_SHIFT);
  86. return page;
  87. }