hugetlb.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 2008, 2009 Cavium Networks, Inc.
  7. */
  8. #ifndef __ASM_HUGETLB_H
  9. #define __ASM_HUGETLB_H
  10. #include <asm/page.h>
  11. #define __HAVE_ARCH_PREPARE_HUGEPAGE_RANGE
  12. static inline int prepare_hugepage_range(struct file *file,
  13. unsigned long addr,
  14. unsigned long len)
  15. {
  16. unsigned long task_size = STACK_TOP;
  17. struct hstate *h = hstate_file(file);
  18. if (len & ~huge_page_mask(h))
  19. return -EINVAL;
  20. if (addr & ~huge_page_mask(h))
  21. return -EINVAL;
  22. if (len > task_size)
  23. return -ENOMEM;
  24. if (task_size - len < addr)
  25. return -EINVAL;
  26. return 0;
  27. }
  28. #define __HAVE_ARCH_HUGE_PTEP_GET_AND_CLEAR
  29. static inline pte_t huge_ptep_get_and_clear(struct mm_struct *mm,
  30. unsigned long addr, pte_t *ptep)
  31. {
  32. pte_t clear;
  33. pte_t pte = *ptep;
  34. pte_val(clear) = (unsigned long)invalid_pte_table;
  35. set_pte_at(mm, addr, ptep, clear);
  36. return pte;
  37. }
  38. #define __HAVE_ARCH_HUGE_PTEP_CLEAR_FLUSH
  39. static inline pte_t huge_ptep_clear_flush(struct vm_area_struct *vma,
  40. unsigned long addr, pte_t *ptep)
  41. {
  42. pte_t pte;
  43. /*
  44. * clear the huge pte entry firstly, so that the other smp threads will
  45. * not get old pte entry after finishing flush_tlb_page and before
  46. * setting new huge pte entry
  47. */
  48. pte = huge_ptep_get_and_clear(vma->vm_mm, addr, ptep);
  49. flush_tlb_page(vma, addr);
  50. return pte;
  51. }
  52. #define __HAVE_ARCH_HUGE_PTE_NONE
  53. static inline int huge_pte_none(pte_t pte)
  54. {
  55. unsigned long val = pte_val(pte) & ~_PAGE_GLOBAL;
  56. return !val || (val == (unsigned long)invalid_pte_table);
  57. }
  58. #define __HAVE_ARCH_HUGE_PTEP_SET_ACCESS_FLAGS
  59. static inline int huge_ptep_set_access_flags(struct vm_area_struct *vma,
  60. unsigned long addr,
  61. pte_t *ptep, pte_t pte,
  62. int dirty)
  63. {
  64. int changed = !pte_same(*ptep, pte);
  65. if (changed) {
  66. set_pte_at(vma->vm_mm, addr, ptep, pte);
  67. /*
  68. * There could be some standard sized pages in there,
  69. * get them all.
  70. */
  71. flush_tlb_range(vma, addr, addr + HPAGE_SIZE);
  72. }
  73. return changed;
  74. }
  75. #include <asm-generic/hugetlb.h>
  76. #endif /* __ASM_HUGETLB_H */