hugetlbpage.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. /*
  2. * SPARC64 Huge TLB page support.
  3. *
  4. * Copyright (C) 2002, 2003 David S. Miller (davem@redhat.com)
  5. */
  6. #include <linux/config.h>
  7. #include <linux/init.h>
  8. #include <linux/module.h>
  9. #include <linux/fs.h>
  10. #include <linux/mm.h>
  11. #include <linux/hugetlb.h>
  12. #include <linux/pagemap.h>
  13. #include <linux/smp_lock.h>
  14. #include <linux/slab.h>
  15. #include <linux/sysctl.h>
  16. #include <asm/mman.h>
  17. #include <asm/pgalloc.h>
  18. #include <asm/tlb.h>
  19. #include <asm/tlbflush.h>
  20. #include <asm/cacheflush.h>
  21. #include <asm/mmu_context.h>
  22. pte_t *huge_pte_alloc(struct mm_struct *mm, unsigned long addr)
  23. {
  24. pgd_t *pgd;
  25. pud_t *pud;
  26. pmd_t *pmd;
  27. pte_t *pte = NULL;
  28. pgd = pgd_offset(mm, addr);
  29. if (pgd) {
  30. pud = pud_offset(pgd, addr);
  31. if (pud) {
  32. pmd = pmd_alloc(mm, pud, addr);
  33. if (pmd)
  34. pte = pte_alloc_map(mm, pmd, addr);
  35. }
  36. }
  37. return pte;
  38. }
  39. pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr)
  40. {
  41. pgd_t *pgd;
  42. pud_t *pud;
  43. pmd_t *pmd;
  44. pte_t *pte = NULL;
  45. pgd = pgd_offset(mm, addr);
  46. if (pgd) {
  47. pud = pud_offset(pgd, addr);
  48. if (pud) {
  49. pmd = pmd_offset(pud, addr);
  50. if (pmd)
  51. pte = pte_offset_map(pmd, addr);
  52. }
  53. }
  54. return pte;
  55. }
  56. #define mk_pte_huge(entry) do { pte_val(entry) |= _PAGE_SZHUGE; } while (0)
  57. void set_huge_pte_at(struct mm_struct *mm, unsigned long addr,
  58. pte_t *ptep, pte_t entry)
  59. {
  60. int i;
  61. for (i = 0; i < (1 << HUGETLB_PAGE_ORDER); i++) {
  62. set_pte_at(mm, addr, ptep, entry);
  63. ptep++;
  64. addr += PAGE_SIZE;
  65. pte_val(entry) += PAGE_SIZE;
  66. }
  67. }
  68. pte_t huge_ptep_get_and_clear(struct mm_struct *mm, unsigned long addr,
  69. pte_t *ptep)
  70. {
  71. pte_t entry;
  72. int i;
  73. entry = *ptep;
  74. for (i = 0; i < (1 << HUGETLB_PAGE_ORDER); i++) {
  75. pte_clear(mm, addr, ptep);
  76. addr += PAGE_SIZE;
  77. ptep++;
  78. }
  79. return entry;
  80. }
  81. /*
  82. * This function checks for proper alignment of input addr and len parameters.
  83. */
  84. int is_aligned_hugepage_range(unsigned long addr, unsigned long len)
  85. {
  86. if (len & ~HPAGE_MASK)
  87. return -EINVAL;
  88. if (addr & ~HPAGE_MASK)
  89. return -EINVAL;
  90. return 0;
  91. }
  92. struct page *follow_huge_addr(struct mm_struct *mm,
  93. unsigned long address, int write)
  94. {
  95. return ERR_PTR(-EINVAL);
  96. }
  97. int pmd_huge(pmd_t pmd)
  98. {
  99. return 0;
  100. }
  101. struct page *follow_huge_pmd(struct mm_struct *mm, unsigned long address,
  102. pmd_t *pmd, int write)
  103. {
  104. return NULL;
  105. }
  106. static void context_reload(void *__data)
  107. {
  108. struct mm_struct *mm = __data;
  109. if (mm == current->mm)
  110. load_secondary_context(mm);
  111. }
  112. void hugetlb_prefault_arch_hook(struct mm_struct *mm)
  113. {
  114. /* On UltraSPARC-III+ and later, configure the second half of
  115. * the Data-TLB for huge pages.
  116. */
  117. if (tlb_type == cheetah_plus) {
  118. unsigned long ctx;
  119. spin_lock(&ctx_alloc_lock);
  120. ctx = mm->context.sparc64_ctx_val;
  121. ctx &= ~CTX_PGSZ_MASK;
  122. ctx |= CTX_PGSZ_BASE << CTX_PGSZ0_SHIFT;
  123. ctx |= CTX_PGSZ_HUGE << CTX_PGSZ1_SHIFT;
  124. if (ctx != mm->context.sparc64_ctx_val) {
  125. /* When changing the page size fields, we
  126. * must perform a context flush so that no
  127. * stale entries match. This flush must
  128. * occur with the original context register
  129. * settings.
  130. */
  131. do_flush_tlb_mm(mm);
  132. /* Reload the context register of all processors
  133. * also executing in this address space.
  134. */
  135. mm->context.sparc64_ctx_val = ctx;
  136. on_each_cpu(context_reload, mm, 0, 0);
  137. }
  138. spin_unlock(&ctx_alloc_lock);
  139. }
  140. }