hugetlbpage.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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/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, unsigned long addr,
  23. unsigned long sz)
  24. {
  25. pgd_t *pgd;
  26. pud_t *pud;
  27. pte_t *pte = NULL;
  28. pgd = pgd_offset(mm, addr);
  29. pud = pud_alloc(mm, pgd, addr);
  30. if (pud)
  31. pte = (pte_t *)pmd_alloc(mm, pud, addr);
  32. return pte;
  33. }
  34. pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr)
  35. {
  36. pgd_t *pgd;
  37. pud_t *pud;
  38. pmd_t *pmd = NULL;
  39. pgd = pgd_offset(mm, addr);
  40. if (pgd_present(*pgd)) {
  41. pud = pud_offset(pgd, addr);
  42. if (pud_present(*pud))
  43. pmd = pmd_offset(pud, addr);
  44. }
  45. return (pte_t *) pmd;
  46. }
  47. int huge_pmd_unshare(struct mm_struct *mm, unsigned long *addr, pte_t *ptep)
  48. {
  49. return 0;
  50. }
  51. /*
  52. * This function checks for proper alignment of input addr and len parameters.
  53. */
  54. int is_aligned_hugepage_range(unsigned long addr, unsigned long len)
  55. {
  56. if (len & ~HPAGE_MASK)
  57. return -EINVAL;
  58. if (addr & ~HPAGE_MASK)
  59. return -EINVAL;
  60. return 0;
  61. }
  62. struct page *
  63. follow_huge_addr(struct mm_struct *mm, unsigned long address, int write)
  64. {
  65. return ERR_PTR(-EINVAL);
  66. }
  67. int pmd_huge(pmd_t pmd)
  68. {
  69. return (pmd_val(pmd) & _PAGE_HUGE) != 0;
  70. }
  71. int pud_huge(pud_t pud)
  72. {
  73. return (pud_val(pud) & _PAGE_HUGE) != 0;
  74. }
  75. struct page *
  76. follow_huge_pmd(struct mm_struct *mm, unsigned long address,
  77. pmd_t *pmd, int write)
  78. {
  79. struct page *page;
  80. page = pte_page(*(pte_t *)pmd);
  81. if (page)
  82. page += ((address & ~HPAGE_MASK) >> PAGE_SHIFT);
  83. return page;
  84. }