hugetlbpage.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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/slab.h>
  19. #include <linux/err.h>
  20. #include <linux/sysctl.h>
  21. #include <asm/mman.h>
  22. #include <asm/tlb.h>
  23. #include <asm/tlbflush.h>
  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. pgd = pgd_offset(mm, addr);
  31. pud = pud_alloc(mm, pgd, 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. {
  38. pgd_t *pgd;
  39. pud_t *pud;
  40. pmd_t *pmd = NULL;
  41. pgd = pgd_offset(mm, addr);
  42. if (pgd_present(*pgd)) {
  43. pud = pud_offset(pgd, addr);
  44. if (pud_present(*pud))
  45. pmd = pmd_offset(pud, addr);
  46. }
  47. return (pte_t *) pmd;
  48. }
  49. int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
  50. {
  51. return 0;
  52. }
  53. /*
  54. * This function checks for proper alignment of input addr and len parameters.
  55. */
  56. int is_aligned_hugepage_range(unsigned long addr, unsigned long len)
  57. {
  58. if (len & ~HPAGE_MASK)
  59. return -EINVAL;
  60. if (addr & ~HPAGE_MASK)
  61. return -EINVAL;
  62. return 0;
  63. }
  64. struct page *
  65. follow_huge_addr(struct mm_struct *mm, unsigned long address, int write)
  66. {
  67. return ERR_PTR(-EINVAL);
  68. }
  69. int pmd_huge(pmd_t pmd)
  70. {
  71. return (pmd_val(pmd) & _PAGE_HUGE) != 0;
  72. }
  73. int pud_huge(pud_t pud)
  74. {
  75. return (pud_val(pud) & _PAGE_HUGE) != 0;
  76. }
  77. struct page *
  78. follow_huge_pmd(struct mm_struct *mm, unsigned long address,
  79. pmd_t *pmd, int write)
  80. {
  81. struct page *page;
  82. page = pte_page(*(pte_t *)pmd);
  83. if (page)
  84. page += ((address & ~HPAGE_MASK) >> PAGE_SHIFT);
  85. return page;
  86. }