hugetlbpage-book3e.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /*
  2. * PPC Huge TLB Page Support for Book3E MMU
  3. *
  4. * Copyright (C) 2009 David Gibson, IBM Corporation.
  5. * Copyright (C) 2011 Becky Bruce, Freescale Semiconductor
  6. *
  7. */
  8. #include <linux/mm.h>
  9. #include <linux/hugetlb.h>
  10. #ifdef CONFIG_PPC_FSL_BOOK3E
  11. #ifdef CONFIG_PPC64
  12. static inline int tlb1_next(void)
  13. {
  14. struct paca_struct *paca = get_paca();
  15. struct tlb_core_data *tcd;
  16. int this, next;
  17. tcd = paca->tcd_ptr;
  18. this = tcd->esel_next;
  19. next = this + 1;
  20. if (next >= tcd->esel_max)
  21. next = tcd->esel_first;
  22. tcd->esel_next = next;
  23. return this;
  24. }
  25. #else
  26. static inline int tlb1_next(void)
  27. {
  28. int index, ncams;
  29. ncams = mfspr(SPRN_TLB1CFG) & TLBnCFG_N_ENTRY;
  30. index = __get_cpu_var(next_tlbcam_idx);
  31. /* Just round-robin the entries and wrap when we hit the end */
  32. if (unlikely(index == ncams - 1))
  33. __get_cpu_var(next_tlbcam_idx) = tlbcam_index;
  34. else
  35. __get_cpu_var(next_tlbcam_idx)++;
  36. return index;
  37. }
  38. #endif /* !PPC64 */
  39. #endif /* FSL */
  40. static inline int mmu_get_tsize(int psize)
  41. {
  42. return mmu_psize_defs[psize].enc;
  43. }
  44. static inline int book3e_tlb_exists(unsigned long ea, unsigned long pid)
  45. {
  46. int found = 0;
  47. mtspr(SPRN_MAS6, pid << 16);
  48. if (mmu_has_feature(MMU_FTR_USE_TLBRSRV)) {
  49. asm volatile(
  50. "li %0,0\n"
  51. "tlbsx. 0,%1\n"
  52. "bne 1f\n"
  53. "li %0,1\n"
  54. "1:\n"
  55. : "=&r"(found) : "r"(ea));
  56. } else {
  57. asm volatile(
  58. "tlbsx 0,%1\n"
  59. "mfspr %0,0x271\n"
  60. "srwi %0,%0,31\n"
  61. : "=&r"(found) : "r"(ea));
  62. }
  63. return found;
  64. }
  65. void book3e_hugetlb_preload(struct vm_area_struct *vma, unsigned long ea,
  66. pte_t pte)
  67. {
  68. unsigned long mas1, mas2;
  69. u64 mas7_3;
  70. unsigned long psize, tsize, shift;
  71. unsigned long flags;
  72. struct mm_struct *mm;
  73. #ifdef CONFIG_PPC_FSL_BOOK3E
  74. int index;
  75. #endif
  76. if (unlikely(is_kernel_addr(ea)))
  77. return;
  78. mm = vma->vm_mm;
  79. #ifdef CONFIG_PPC_MM_SLICES
  80. psize = get_slice_psize(mm, ea);
  81. tsize = mmu_get_tsize(psize);
  82. shift = mmu_psize_defs[psize].shift;
  83. #else
  84. psize = vma_mmu_pagesize(vma);
  85. shift = __ilog2(psize);
  86. tsize = shift - 10;
  87. #endif
  88. /*
  89. * We can't be interrupted while we're setting up the MAS
  90. * regusters or after we've confirmed that no tlb exists.
  91. */
  92. local_irq_save(flags);
  93. if (unlikely(book3e_tlb_exists(ea, mm->context.id))) {
  94. local_irq_restore(flags);
  95. return;
  96. }
  97. #ifdef CONFIG_PPC_FSL_BOOK3E
  98. /* We have to use the CAM(TLB1) on FSL parts for hugepages */
  99. index = tlb1_next();
  100. mtspr(SPRN_MAS0, MAS0_ESEL(index) | MAS0_TLBSEL(1));
  101. #endif
  102. mas1 = MAS1_VALID | MAS1_TID(mm->context.id) | MAS1_TSIZE(tsize);
  103. mas2 = ea & ~((1UL << shift) - 1);
  104. mas2 |= (pte_val(pte) >> PTE_WIMGE_SHIFT) & MAS2_WIMGE_MASK;
  105. mas7_3 = (u64)pte_pfn(pte) << PAGE_SHIFT;
  106. mas7_3 |= (pte_val(pte) >> PTE_BAP_SHIFT) & MAS3_BAP_MASK;
  107. if (!pte_dirty(pte))
  108. mas7_3 &= ~(MAS3_SW|MAS3_UW);
  109. mtspr(SPRN_MAS1, mas1);
  110. mtspr(SPRN_MAS2, mas2);
  111. if (mmu_has_feature(MMU_FTR_USE_PAIRED_MAS)) {
  112. mtspr(SPRN_MAS7_MAS3, mas7_3);
  113. } else {
  114. if (mmu_has_feature(MMU_FTR_BIG_PHYS))
  115. mtspr(SPRN_MAS7, upper_32_bits(mas7_3));
  116. mtspr(SPRN_MAS3, lower_32_bits(mas7_3));
  117. }
  118. asm volatile ("tlbwe");
  119. local_irq_restore(flags);
  120. }
  121. void flush_hugetlb_page(struct vm_area_struct *vma, unsigned long vmaddr)
  122. {
  123. struct hstate *hstate = hstate_file(vma->vm_file);
  124. unsigned long tsize = huge_page_shift(hstate) - 10;
  125. __flush_tlb_page(vma->vm_mm, vmaddr, tsize, 0);
  126. }