hugetlbpage.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * arch/arm/mm/hugetlbpage.c
  3. *
  4. * Copyright (C) 2012 ARM Ltd.
  5. *
  6. * Based on arch/x86/include/asm/hugetlb.h and Bill Carson's patches
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, write to the Free Software
  19. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  20. */
  21. #include <linux/init.h>
  22. #include <linux/fs.h>
  23. #include <linux/mm.h>
  24. #include <linux/hugetlb.h>
  25. #include <linux/pagemap.h>
  26. #include <linux/err.h>
  27. #include <linux/sysctl.h>
  28. #include <asm/mman.h>
  29. #include <asm/tlb.h>
  30. #include <asm/tlbflush.h>
  31. #include <asm/pgalloc.h>
  32. /*
  33. * On ARM, huge pages are backed by pmd's rather than pte's, so we do a lot
  34. * of type casting from pmd_t * to pte_t *.
  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. struct page *follow_huge_addr(struct mm_struct *mm, unsigned long address,
  50. int write)
  51. {
  52. return ERR_PTR(-EINVAL);
  53. }
  54. int pud_huge(pud_t pud)
  55. {
  56. return 0;
  57. }
  58. int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
  59. {
  60. return 0;
  61. }
  62. pte_t *huge_pte_alloc(struct mm_struct *mm,
  63. unsigned long addr, unsigned long sz)
  64. {
  65. pgd_t *pgd;
  66. pud_t *pud;
  67. pte_t *pte = NULL;
  68. pgd = pgd_offset(mm, addr);
  69. pud = pud_alloc(mm, pgd, addr);
  70. if (pud)
  71. pte = (pte_t *)pmd_alloc(mm, pud, addr);
  72. return pte;
  73. }
  74. struct page *
  75. follow_huge_pmd(struct mm_struct *mm, unsigned long address,
  76. pmd_t *pmd, int write)
  77. {
  78. struct page *page;
  79. page = pte_page(*(pte_t *)pmd);
  80. if (page)
  81. page += ((address & ~PMD_MASK) >> PAGE_SHIFT);
  82. return page;
  83. }
  84. int pmd_huge(pmd_t pmd)
  85. {
  86. return pmd_val(pmd) && !(pmd_val(pmd) & PMD_TABLE_BIT);
  87. }